Java Code Examples for org.alfresco.service.cmr.repository.ContentData#getLocale()
The following examples show how to use
org.alfresco.service.cmr.repository.ContentData#getLocale() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: NodeContentData.java From alfresco-repository with GNU Lesser General Public License v3.0 | 5 votes |
/** * Construct */ public NodeContentData(NodeRef nodeRef, ContentData contentData) { super(contentData.getContentUrl(), contentData.getMimetype(), contentData.getSize(), contentData.getEncoding(), contentData.getLocale()); this.nodeRef = nodeRef; }
Example 2
Source File: DecryptingContentReaderFacade.java From alfresco-simple-content-stores with Apache License 2.0 | 5 votes |
/** * {@inheritDoc} */ @Override public ContentData getContentData() { final ContentData contentData = super.getContentData(); // correct size final ContentData updatedData = new ContentData(contentData.getContentUrl(), contentData.getMimetype(), this.unencryptedSize, contentData.getEncoding(), contentData.getLocale()); return updatedData; }
Example 3
Source File: AbstractContentDataDAOImpl.java From alfresco-repository with GNU Lesser General Public License v3.0 | 4 votes |
/** * Translates the {@link ContentData} into persistable values using the helper DAOs */ protected ContentDataEntity createContentDataEntity(ContentData contentData) { // Resolve the content URL Long contentUrlId = null; String contentUrl = contentData.getContentUrl(); long size = contentData.getSize(); if (contentUrl != null) { ContentUrlEntity contentUrlEntity = new ContentUrlEntity(); contentUrlEntity.setContentUrl(contentUrl); contentUrlEntity.setSize(size); Pair<Long, ContentUrlEntity> pair = contentUrlCache.createOrGetByValue(contentUrlEntity, controlDAO); contentUrlId = pair.getFirst(); } // Resolve the mimetype Long mimetypeId = null; String mimetype = contentData.getMimetype(); if (mimetype != null) { mimetypeId = mimetypeDAO.getOrCreateMimetype(mimetype).getFirst(); } // Resolve the encoding Long encodingId = null; String encoding = contentData.getEncoding(); if (encoding != null) { encodingId = encodingDAO.getOrCreateEncoding(encoding).getFirst(); } // Resolve the locale Long localeId = null; Locale locale = contentData.getLocale(); if (locale != null) { localeId = localeDAO.getOrCreateLocalePair(locale).getFirst(); } // Create ContentDataEntity ContentDataEntity contentDataEntity = createContentDataEntity(contentUrlId, mimetypeId, encodingId, localeId); // Done return contentDataEntity; }
Example 4
Source File: AbstractContentDataDAOImpl.java From alfresco-repository with GNU Lesser General Public License v3.0 | 4 votes |
/** * Translates the {@link ContentData} into persistable values using the helper DAOs */ protected int updateContentDataEntity(ContentDataEntity contentDataEntity, ContentData contentData) { // Resolve the content URL Long oldContentUrlId = contentDataEntity.getContentUrlId(); ContentUrlEntity contentUrlEntity = null; if(oldContentUrlId != null) { Pair<Long, ContentUrlEntity> entityPair = contentUrlCache.getByKey(oldContentUrlId); if (entityPair == null) { throw new DataIntegrityViolationException("No ContentUrl value exists for ID " + oldContentUrlId); } contentUrlEntity = entityPair.getSecond(); } String oldContentUrl = (contentUrlEntity != null ? contentUrlEntity.getContentUrl() : null); String newContentUrl = contentData.getContentUrl(); if (!EqualsHelper.nullSafeEquals(oldContentUrl, newContentUrl)) { if (oldContentUrl != null) { // We have a changed value. The old content URL has been dereferenced. registerDereferencedContentUrl(oldContentUrl); } if (newContentUrl != null) { if(contentUrlEntity == null) { contentUrlEntity = new ContentUrlEntity(); contentUrlEntity.setContentUrl(newContentUrl); } Pair<Long, ContentUrlEntity> pair = contentUrlCache.getOrCreateByValue(contentUrlEntity); Long newContentUrlId = pair.getFirst(); contentUrlEntity.setId(newContentUrlId); contentDataEntity.setContentUrlId(newContentUrlId); } else { contentDataEntity.setId(null); contentDataEntity.setContentUrlId(null); } } // Resolve the mimetype Long mimetypeId = null; String mimetype = contentData.getMimetype(); if (mimetype != null) { mimetypeId = mimetypeDAO.getOrCreateMimetype(mimetype).getFirst(); } // Resolve the encoding Long encodingId = null; String encoding = contentData.getEncoding(); if (encoding != null) { encodingId = encodingDAO.getOrCreateEncoding(encoding).getFirst(); } // Resolve the locale Long localeId = null; Locale locale = contentData.getLocale(); if (locale != null) { localeId = localeDAO.getOrCreateLocalePair(locale).getFirst(); } contentDataEntity.setMimetypeId(mimetypeId); contentDataEntity.setEncodingId(encodingId); contentDataEntity.setLocaleId(localeId); return updateContentDataEntity(contentDataEntity); }
Example 5
Source File: NodesImpl.java From alfresco-remote-api with GNU Lesser General Public License v3.0 | 4 votes |
@Override public BinaryResource getContent(NodeRef nodeRef, Parameters parameters, boolean recordActivity) { if (!nodeMatches(nodeRef, Collections.singleton(ContentModel.TYPE_CONTENT), null, false)) { throw new InvalidArgumentException("NodeId of content is expected: " + nodeRef.getId()); } Map<QName, Serializable> nodeProps = nodeService.getProperties(nodeRef); ContentData cd = (ContentData) nodeProps.get(ContentModel.PROP_CONTENT); String name = (String) nodeProps.get(ContentModel.PROP_NAME); org.alfresco.rest.framework.resource.content.ContentInfo ci = null; String mimeType = null; if (cd != null) { mimeType = cd.getMimetype(); ci = new org.alfresco.rest.framework.resource.content.ContentInfoImpl(mimeType, cd.getEncoding(), cd.getSize(), cd.getLocale()); } // By default set attachment header (with filename) unless attachment=false *and* content type is pre-configured as non-attach boolean attach = true; String attachment = parameters.getParameter("attachment"); if (attachment != null) { Boolean a = Boolean.valueOf(attachment); if (!a) { if (nonAttachContentTypes.contains(mimeType)) { attach = false; } else { logger.warn("Ignored attachment=false for "+nodeRef.getId()+" since "+mimeType+" is not in the whitelist for non-attach content types"); } } } String attachFileName = (attach ? name : null); if (recordActivity) { final ActivityInfo activityInfo = getActivityInfo(getParentNodeRef(nodeRef), nodeRef); postActivity(Activity_Type.DOWNLOADED, activityInfo, true); } return new NodeBinaryResource(nodeRef, ContentModel.PROP_CONTENT, ci, attachFileName); }
Example 6
Source File: RenditionsImpl.java From alfresco-remote-api with GNU Lesser General Public License v3.0 | 4 votes |
private BinaryResource getContentImpl(NodeRef nodeRef, String renditionId, Parameters parameters) { NodeRef renditionNodeRef = getRenditionByName(nodeRef, renditionId, parameters); // By default set attachment header (with rendition Id) unless attachment=false boolean attach = true; String attachment = parameters.getParameter(PARAM_ATTACHMENT); if (attachment != null) { attach = Boolean.valueOf(attachment); } final String attachFileName = (attach ? renditionId : null); if (renditionNodeRef == null) { boolean isPlaceholder = Boolean.valueOf(parameters.getParameter(PARAM_PLACEHOLDER)); if (!isPlaceholder) { throw new NotFoundException("Thumbnail was not found for [" + renditionId + ']'); } String sourceNodeMimeType = null; try { sourceNodeMimeType = (nodeRef != null ? getMimeType(nodeRef) : null); } catch (InvalidArgumentException e) { // No content for node, e.g. ASSOC_AVATAR rather than ASSOC_PREFERENCE_IMAGE } // resource based on the content's mimeType and rendition id String phPath = scriptThumbnailService.getMimeAwarePlaceHolderResourcePath(renditionId, sourceNodeMimeType); if (phPath == null) { // 404 since no thumbnail was found throw new NotFoundException("Thumbnail was not found and no placeholder resource available for [" + renditionId + ']'); } else { if (logger.isDebugEnabled()) { logger.debug("Retrieving content from resource path [" + phPath + ']'); } // get extension of resource String ext = ""; int extIndex = phPath.lastIndexOf('.'); if (extIndex != -1) { ext = phPath.substring(extIndex); } try { final String resourcePath = "classpath:" + phPath; InputStream inputStream = resourceLoader.getResource(resourcePath).getInputStream(); // create temporary file File file = TempFileProvider.createTempFile(inputStream, "RenditionsApi-", ext); return new FileBinaryResource(file, attachFileName); } catch (Exception ex) { if (logger.isErrorEnabled()) { logger.error("Couldn't load the placeholder." + ex.getMessage()); } throw new ApiException("Couldn't load the placeholder."); } } } Map<QName, Serializable> nodeProps = nodeService.getProperties(renditionNodeRef); ContentData contentData = (ContentData) nodeProps.get(ContentModel.PROP_CONTENT); Date modified = (Date) nodeProps.get(ContentModel.PROP_MODIFIED); org.alfresco.rest.framework.resource.content.ContentInfo contentInfo = null; if (contentData != null) { contentInfo = new ContentInfoImpl(contentData.getMimetype(), contentData.getEncoding(), contentData.getSize(), contentData.getLocale()); } // add cache settings CacheDirective cacheDirective = new CacheDirective.Builder() .setNeverCache(false) .setMustRevalidate(false) .setLastModified(modified) .setETag(modified != null ? Long.toString(modified.getTime()) : null) .setMaxAge(Long.valueOf(31536000))// one year (in seconds) .build(); return new NodeBinaryResource(renditionNodeRef, ContentModel.PROP_CONTENT, contentInfo, attachFileName, cacheDirective); }