public ActionResult Index() { var contentData = new ContentData(); contentData.ContentDataA = "Hello"; contentData.ContentDataB = "World"; ViewData.Add("contentData", contentData); }
/** * Construct */ public NodeContentData(NodeRef nodeRef, ContentData contentData) { super(contentData.getContentUrl(), contentData.getMimetype(), contentData.getSize(), contentData.getEncoding(), contentData.getLocale()); this.nodeRef = nodeRef; }
@Override public void onContentPropertyUpdate(NodeRef nodeRef, QName propertyQName, ContentData beforeValue, ContentData afterValue) { boolean hasContentBefore = ContentData.hasContent(beforeValue) && beforeValue.getSize() > 0; boolean hasContentAfter = ContentData.hasContent(afterValue) && afterValue.getSize() > 0; // There are some shortcuts here if (!hasContentBefore && !hasContentAfter) { // Really, nothing happened return; } else if (EqualsHelper.nullSafeEquals(beforeValue, afterValue)) { // Still, nothing happening return; } eventsService.contentWrite(nodeRef, propertyQName, afterValue); }
/** * 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; }
private ContentData sanitizeMimetype(ContentData contentData) { String mimetype = contentData.getMimetype(); if (mimetype != null) { mimetype = mimetype.toLowerCase(); contentData = ContentData.setMimetype(contentData, mimetype); } return contentData; }
if (contentData != null) String mimetype = contentData.getMimetype(); if (mimetype == null) contentData = ContentData.setMimetype(contentData, determineDefaultMimetype(data)); if (contentData != null) contentData = ContentData.setMimetype(contentData, determineDefaultMimetype(data)); contentData = ContentData.setMimetype(contentData, mimetypeEncoding.getMimetype()); contentData = ContentData.setEncoding(contentData, mimetypeEncoding.getEncoding());
@Override protected Map<String, Object> getTransientValues(NodeRef item) { Map<String, Object> values = new HashMap<String, Object>(3); ContentData contentData = getContentData(item); if (contentData != null) { values.put(EncodingFieldProcessor.KEY, contentData.getEncoding()); values.put(MimetypeFieldProcessor.KEY, contentData.getMimetype()); values.put(SizeFieldProcessor.KEY, contentData.getSize()); } return values; }
ContentData contentData = DefaultTypeConverter.INSTANCE.convert(ContentData.class, value); if (ContentData.hasContent(contentData)) String mimetype = contentData.getMimetype(); List<ThumbnailDefinition> thumbnailDefinitions = thumbnailService.getThumbnailRegistry().getThumbnailDefinitions(mimetype, contentData.getSize()); for (ThumbnailDefinition thumbnailDefinition : thumbnailDefinitions)
writer.setMimetype(contentData.getMimetype()); writer.setEncoding(contentData.getEncoding()); writer.setLocale(contentData.getLocale());
public void testUpdate() throws Exception { ContentData contentData = getContentData(); Pair<Long, ContentData> resultPair = create(contentData); Long id = resultPair.getFirst(); // Update contentData = ContentData.setMimetype(contentData, "TEXT/HTML"); // Note the upper case mimetype contentData = ContentData.setEncoding(contentData, "UTF-16"); // Don't update the content itself update(id, contentData); // Check Pair<Long, ContentData> result = getAndCheck(id, contentData); // Check the mimetype has been lowercased assertEquals("text/html", result.getSecond().getMimetype()); }
/** * Ensure that upper and lowercase URLs don't clash * @throws Exception */ public void testEnsureCaseSensitiveStorage() throws Exception { ContentData contentData = getContentData(); String contentUrlUpper = contentData.getContentUrl().toUpperCase(); ContentData contentDataUpper = new ContentData( contentUrlUpper, MimetypeMap.MIMETYPE_TEXT_PLAIN, 0L, "UTF-8", new Locale("FR")); String contentUrlLower = contentData.getContentUrl().toLowerCase(); ContentData contentDataLower = new ContentData( contentUrlLower, MimetypeMap.MIMETYPE_TEXT_PLAIN, 0L, "utf-8", new Locale("fr")); Pair<Long, ContentData> resultPairUpper = create(contentDataUpper); getAndCheck(resultPairUpper.getFirst(), contentDataUpper); Pair<Long, ContentData> resultPairLower = create(contentDataLower); getAndCheck(resultPairLower.getFirst(), contentDataLower); }
public Serializable getValueInternal(CMISNodeInfo nodeInfo) { ContentData contentData = getContentData(nodeInfo); if (contentData != null) { return contentData.getContentUrl(); } return null; } }
public void setMimetype(String mimetype) { mimetype = mimetype.toLowerCase(); this.contentData = ContentData.setMimetype(this.contentData, mimetype); services.getNodeService().setProperty(nodeRef, this.property, this.contentData); updateContentData(false); }
@Override protected void contentImpl(NodeRef nodeRef, QName property, InputStream content, ContentData contentData, int index) { size = size + contentData.getSize(); fileCount = fileCount + 1; }
@Override public Void execute() throws Throwable { NodeRef shuffledNodeRef = getNodeForPath(testConnection, TEST_DIR + "\\" + FILE_NAME); Map<QName, Serializable> props = nodeService.getProperties(shuffledNodeRef); ContentData data = (ContentData)props.get(ContentModel.PROP_CONTENT); assertNotNull("data is null", data); assertEquals("size is wrong", 26112, data.getSize()); assertEquals("mimeType is wrong", "application/msword",data.getMimetype()); return null; } };
/** * Returns the hash code of the source node's content url. As transformations may be returned in a different * sequences to which they were requested, this is used work out if a rendition should be replaced. */ private int getSourceContentHashCode(NodeRef sourceNodeRef) { int hashCode = SOURCE_HAS_NO_CONTENT; ContentData contentData = DefaultTypeConverter.INSTANCE.convert(ContentData.class, nodeService.getProperty(sourceNodeRef, PROP_CONTENT)); if (contentData != null) { // Originally we used the contentData URL, but that is not enough if the mimetype changes. String contentString = contentData.getContentUrl()+contentData.getMimetype(); if (contentString != null) { hashCode = contentString.hashCode(); } } return hashCode; }
Serializable value = this.nodeService.getProperty(nodeRef, ContentModel.PROP_CONTENT); ContentData contentData = DefaultTypeConverter.INSTANCE.convert(ContentData.class, value); if (!ContentData.hasContent(contentData)) return null; if (!registry.isThumbnailDefinitionAvailable(contentData.getContentUrl(), nodeMimeType, getSize(), nodeRef, details))
public String getEncoding() { return contentData.getEncoding(); }
public Serializable getValueInternal(CMISNodeInfo nodeInfo) { ContentData contentData = getContentData(nodeInfo); if (contentData != null) { return contentData.getMimetype(); } return null; }
/** * Persists the given field data as the encoding property * * @param nodeRef The NodeRef to update the encoding for * @param fieldData The data representing the new encoding value * @param propsToPersist Map of properties to be persisted */ protected void processEncodingPropertyPersist(NodeRef nodeRef, FieldData fieldData, Map<QName, Serializable> propsToPersist) { ContentData contentData = (ContentData) propsToPersist.get(ContentModel.PROP_CONTENT); if (contentData == null) { // content data has not been persisted yet so get it from the node contentData = (ContentData) this.nodeService.getProperty(nodeRef, ContentModel.PROP_CONTENT); } if (contentData != null) { // update content data if we found the property contentData = ContentData.setEncoding(contentData, (String) fieldData.getValue()); propsToPersist.put(ContentModel.PROP_CONTENT, contentData); } }