Java Code Examples for org.alfresco.service.cmr.repository.ContentData#getEncoding()
The following examples show how to use
org.alfresco.service.cmr.repository.ContentData#getEncoding() .
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: Document.java From alfresco-remote-api with GNU Lesser General Public License v3.0 | 6 votes |
public Document(NodeRef nodeRef, NodeRef parentNodeRef, Map<QName, Serializable> nodeProps, Map<String, UserInfo> mapUserInfo, ServiceRegistry sr) { super(nodeRef, parentNodeRef, nodeProps, mapUserInfo, sr); Serializable val = nodeProps.get(ContentModel.PROP_CONTENT); if ((val != null) && (val instanceof ContentData)) { ContentData cd = (ContentData)val; String mimeType = cd.getMimetype(); String mimeTypeName = sr.getMimetypeService().getDisplaysByMimetype().get(mimeType); contentInfo = new ContentInfo(mimeType, mimeTypeName, cd.getSize(), cd.getEncoding()); } setIsFolder(false); setIsFile(true); }
Example 2
Source File: RenditionsImpl.java From alfresco-remote-api with GNU Lesser General Public License v3.0 | 6 votes |
protected Rendition toApiRendition(NodeRef renditionNodeRef) { Rendition apiRendition = new Rendition(); String renditionName = (String) nodeService.getProperty(renditionNodeRef, ContentModel.PROP_NAME); apiRendition.setId(renditionName); ContentData contentData = getContentData(renditionNodeRef, false); ContentInfo contentInfo = null; if (contentData != null) { contentInfo = new ContentInfo(contentData.getMimetype(), getMimeTypeDisplayName(contentData.getMimetype()), contentData.getSize(), contentData.getEncoding()); } apiRendition.setContent(contentInfo); apiRendition.setStatus(RenditionStatus.CREATED); return apiRendition; }
Example 3
Source File: NodeResourceHelper.java From alfresco-repository with GNU Lesser General Public License v3.0 | 5 votes |
public ContentInfo getContentInfo(Map<QName, Serializable> props) { final Serializable content = props.get(ContentModel.PROP_CONTENT); ContentInfo contentInfo = null; if ((content instanceof ContentData)) { ContentData cd = (ContentData) content; contentInfo = new ContentInfo(cd.getMimetype(), cd.getSize(), cd.getEncoding()); } return contentInfo; }
Example 4
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 5
Source File: ContentDataPart.java From alfresco-repository with GNU Lesser General Public License v3.0 | 5 votes |
/** * ContentDataPart * @param contentService content service * @param partName String * @param data data */ public ContentDataPart(ContentService contentService, String partName, ContentData data) { super(partName, data.getMimetype(), data.getEncoding(), null); this.contentService = contentService; this.data = data; this.filename = partName; }
Example 6
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 7
Source File: EventsServiceImpl.java From alfresco-repository with GNU Lesser General Public License v3.0 | 4 votes |
@Override public void contentWrite(NodeRef nodeRef, QName propertyQName, ContentData value) { NodeInfo nodeInfo = getNodeInfo(nodeRef, NodeContentPutEvent.EVENT_TYPE); if(nodeInfo.checkNodeInfo()) { String username = AuthenticationUtil.getFullyAuthenticatedUser(); String networkId = TenantUtil.getCurrentDomain(); String name = nodeInfo.getName(); String objectId = nodeInfo.getNodeId(); String siteId = nodeInfo.getSiteId(); String txnId = AlfrescoTransactionSupport.getTransactionId(); List<String> nodePaths = nodeInfo.getPaths(); List<List<String>> pathNodeIds = nodeInfo.getParentNodeIds(); long timestamp = System.currentTimeMillis(); Long modificationTime = nodeInfo.getModificationTimestamp(); long size; String mimeType; String encoding; if (value != null) { size = value.getSize(); mimeType = value.getMimetype(); encoding = value.getEncoding(); } else { size = 0; mimeType = ""; encoding = ""; } String nodeType = nodeInfo.getType().toPrefixString(namespaceService); Client alfrescoClient = getAlfrescoClient(nodeInfo.getClient()); Set<String> aspects = nodeInfo.getAspectsAsStrings(); Map<String, Serializable> properties = nodeInfo.getProperties(); Event event = new NodeContentPutEvent(nextSequenceNumber(), name, txnId, timestamp, networkId, siteId, objectId, nodeType, nodePaths, pathNodeIds, username, modificationTime, size, mimeType, encoding, alfrescoClient, aspects, properties); sendEvent(event); } }
Example 8
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 9
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 10
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 11
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); }