Java Code Examples for org.alfresco.model.ContentModel#PROP_CONTENT
The following examples show how to use
org.alfresco.model.ContentModel#PROP_CONTENT .
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: ScriptNodeTest.java From alfresco-repository with GNU Lesser General Public License v3.0 | 6 votes |
/** * https://issues.alfresco.com/jira/browse/MNT-19682 * Test that mimetype is correctly set according to the content */ @Test public void testWriteContentWithMimetypeAndWithoutFilename() { createTestContent(true); ScriptNode scriptNode = new ScriptNode(testNode, SERVICE_REGISTRY); scriptNode.setScope(getScope()); ScriptContentData scd = scriptNode.new ScriptContentData(null, ContentModel.PROP_CONTENT); InputStream inputStream = getClass().getClassLoader().getResourceAsStream(TEST_CONTENT_MODEL); InputStreamContent inputStreamContent = new InputStreamContent(inputStream, MimetypeMap.MIMETYPE_APPLICATION_PS, "UTF-8"); scd.write(inputStreamContent, true, false); assertEquals(MimetypeMap.MIMETYPE_APPLICATION_PS, scriptNode.getMimetype()); }
Example 2
Source File: ScriptNodeTest.java From alfresco-repository with GNU Lesser General Public License v3.0 | 6 votes |
/** * https://issues.alfresco.com/jira/browse/MNT-19682 * Test that mimetype is correctly set according to the filename */ @Test public void testWriteContentWithMimetypeAndFilename() { createTestContent(true); ScriptNode scriptNode = new ScriptNode(testNode, SERVICE_REGISTRY); scriptNode.setScope(getScope()); ScriptContentData scd = scriptNode.new ScriptContentData(null, ContentModel.PROP_CONTENT); InputStream inputStream = getClass().getClassLoader().getResourceAsStream(TEST_CONTENT_MODEL); InputStreamContent inputStreamContent = new InputStreamContent(inputStream, MimetypeMap.MIMETYPE_APPLICATION_PS, "UTF-8"); scd.write(inputStreamContent, true, false, "test.ai"); assertEquals(MimetypeMap.MIMETYPE_APPLICATION_ILLUSTRATOR, scriptNode.getMimetype()); }
Example 3
Source File: ContentInfo.java From alfresco-remote-api with GNU Lesser General Public License v3.0 | 6 votes |
@Override public void execute(WebScriptRequest req, WebScriptResponse res) throws IOException { // create empty map of args Map<String, String> args = new HashMap<String, String>(0, 1.0f); // create map of template vars Map<String, String> templateVars = req.getServiceMatch().getTemplateVars(); // create object reference from url ObjectReference reference = createObjectReferenceFromUrl(args, templateVars); NodeRef nodeRef = reference.getNodeRef(); if (nodeRef == null) { throw new WebScriptException(HttpServletResponse.SC_NOT_FOUND, "Unable to find " + reference.toString()); } // render content QName propertyQName = ContentModel.PROP_CONTENT; // Stream the content streamContent(req, res, nodeRef, propertyQName, false, null, null); }
Example 4
Source File: QuickShareContentGet.java From alfresco-remote-api with GNU Lesser General Public License v3.0 | 6 votes |
protected void executeImpl(NodeRef nodeRef, Map<String, String> templateVars, WebScriptRequest req, WebScriptResponse res, Map<String, Object> model, boolean attach) throws IOException { // render content QName propertyQName = ContentModel.PROP_CONTENT; String contentPart = templateVars.get("property"); if (contentPart.length() > 0 && contentPart.charAt(0) == ';') { if (contentPart.length() < 2) { throw new WebScriptException(HttpServletResponse.SC_BAD_REQUEST, "Content property malformed"); } String propertyName = contentPart.substring(1); if (propertyName.length() > 0) { propertyQName = QName.createQName(propertyName, namespaceService); } } // Stream the content streamContentLocal(req, res, nodeRef, attach, propertyQName, model); }
Example 5
Source File: RhinoScriptProcessor.java From alfresco-repository with GNU Lesser General Public License v3.0 | 5 votes |
/** * @see org.alfresco.service.cmr.repository.ScriptProcessor#execute(org.alfresco.service.cmr.repository.NodeRef, org.alfresco.service.namespace.QName, java.util.Map) */ public Object execute(NodeRef nodeRef, QName contentProp, Map<String, Object> model) { try { if (this.services.getNodeService().exists(nodeRef) == false) { throw new AlfrescoRuntimeException("Script Node does not exist: " + nodeRef); } if (contentProp == null) { contentProp = ContentModel.PROP_CONTENT; } ContentReader cr = this.services.getContentService().getReader(nodeRef, contentProp); if (cr == null || cr.exists() == false) { throw new AlfrescoRuntimeException("Script Node content not found: " + nodeRef); } // compile the script based on the node content Script script; Context cx = Context.enter(); try { script = cx.compileString(resolveScriptImports(cr.getContentString()), nodeRef.toString(), 1, null); } finally { Context.exit(); } return executeScriptImpl(script, model, false, nodeRef.toString()); } catch (Throwable err) { throw new ScriptException("Failed to execute script '" + nodeRef.toString() + "': " + err.getMessage(), err); } }
Example 6
Source File: GetChildrenCannedQuery.java From alfresco-repository with GNU Lesser General Public License v3.0 | 5 votes |
private Long getQNameId(QName sortPropQName) { if (sortPropQName.equals(SORT_QNAME_CONTENT_SIZE) || sortPropQName.equals(SORT_QNAME_CONTENT_MIMETYPE)) { sortPropQName = ContentModel.PROP_CONTENT; } Pair<Long, QName> qnamePair = qnameDAO.getQName(sortPropQName); return (qnamePair == null ? null : qnamePair.getFirst()); }
Example 7
Source File: UpdateThumbnailActionExecuter.java From alfresco-repository with GNU Lesser General Public License v3.0 | 4 votes |
/** * @see org.alfresco.repo.action.executer.ActionExecuterAbstractBase#executeImpl(org.alfresco.service.cmr.action.Action, org.alfresco.service.cmr.repository.NodeRef) */ @Override protected void executeImpl(Action action, NodeRef actionedUponNodeRef) { // Check if thumbnailing is generally disabled if (!thumbnailService.getThumbnailsEnabled()) { if (logger.isDebugEnabled()) { logger.debug("Thumbnail transformations are not enabled"); } return; } // Get the thumbnail NodeRef thumbnailNodeRef = (NodeRef)action.getParameterValue(PARAM_THUMBNAIL_NODE); if (thumbnailNodeRef == null) { thumbnailNodeRef = actionedUponNodeRef; } if (this.nodeService.exists(thumbnailNodeRef) == true && renditionService.isRendition(thumbnailNodeRef)) { // Get the thumbnail Name ChildAssociationRef parent = renditionService.getSourceNode(thumbnailNodeRef); String thumbnailName = parent.getQName().getLocalName(); // Get the details of the thumbnail ThumbnailRegistry registry = this.thumbnailService.getThumbnailRegistry(); ThumbnailDefinition details = registry.getThumbnailDefinition(thumbnailName); if (details == null) { throw new AlfrescoRuntimeException("The thumbnail name '" + thumbnailName + "' is not registered"); } // Get the content property QName contentProperty = (QName)action.getParameterValue(PARAM_CONTENT_PROPERTY); if (contentProperty == null) { contentProperty = ContentModel.PROP_CONTENT; } Serializable contentProp = nodeService.getProperty(actionedUponNodeRef, contentProperty); if (contentProp == null) { logger.info("Creation of thumbnail, null content for " + details.getName()); return; } if(contentProp instanceof ContentData) { ContentData content = (ContentData)contentProp; String mimetype = content.getMimetype(); if (mimetypeMaxSourceSizeKBytes != null) { Long maxSourceSizeKBytes = mimetypeMaxSourceSizeKBytes.get(mimetype); if (maxSourceSizeKBytes != null && maxSourceSizeKBytes >= 0 && maxSourceSizeKBytes < (content.getSize()/1024L)) { logger.debug("Unable to create thumbnail '" + details.getName() + "' for " + mimetype + " as content is too large ("+(content.getSize()/1024L)+"K > "+maxSourceSizeKBytes+"K)"); return; //avoid transform } } } // Create the thumbnail this.thumbnailService.updateThumbnail(thumbnailNodeRef, details.getTransformationOptions()); } }
Example 8
Source File: ContentStreamMimetypeProperty.java From alfresco-repository with GNU Lesser General Public License v3.0 | 4 votes |
protected QName getQNameForExists() { return ContentModel.PROP_CONTENT; }
Example 9
Source File: AbstractRenderingEngineTest.java From alfresco-repository with GNU Lesser General Public License v3.0 | 4 votes |
@SuppressWarnings({"unchecked" , "rawtypes"}) public void testCreateRenditionNodeAssoc() throws Exception { QName assocType = RenditionModel.ASSOC_RENDITION; when(nodeService.exists(source)).thenReturn(true); QName nodeType = ContentModel.TYPE_CONTENT; ChildAssociationRef renditionAssoc = makeRenditionAssoc(); RenditionDefinition definition = makeRenditionDefinition(renditionAssoc); // Stub the createNode() method to return renditionAssoc. when(nodeService.createNode(eq(source), eq(assocType), any(QName.class), any(QName.class), anyMap())) .thenReturn(renditionAssoc); engine.execute(definition, source); // Check the createNode method was called with the correct parameters. // Check the nodeType defaults to cm:content. ArgumentCaptor<Map> captor = ArgumentCaptor.forClass(Map.class); verify(nodeService).createNode(eq(source), eq(assocType), any(QName.class), eq(nodeType), captor.capture()); Map<String, Serializable> props = captor.getValue(); // Check the node name is set to match teh rendition name local name. assertEquals(renditionAssoc.getQName().getLocalName(), props.get(ContentModel.PROP_NAME)); // Check content property name defaults to cm:content assertEquals(ContentModel.PROP_CONTENT, props.get(ContentModel.PROP_CONTENT_PROPERTY_NAME)); // Check the returned result is the association created by the call to // nodeServcie.createNode(). Serializable result = definition.getParameterValue(ActionExecuter.PARAM_RESULT); assertEquals("The returned rendition association is not the one created by the node service!", renditionAssoc, result); // Check that setting the default content property and default node type // on the rendition engine works. nodeType = QName.createQName("url", "someNodeType"); QName contentPropName = QName.createQName("url", "someContentProp"); engine.setDefaultRenditionContentProp(contentPropName.toString()); engine.setDefaultRenditionNodeType(nodeType.toString()); engine.execute(definition, source); verify(nodeService).createNode(eq(source), eq(assocType), any(QName.class), eq(nodeType), captor.capture()); props = captor.getValue(); assertEquals(contentPropName, props.get(ContentModel.PROP_CONTENT_PROPERTY_NAME)); // Check that setting the rendition node type param works. nodeType = ContentModel.TYPE_THUMBNAIL; contentPropName = ContentModel.PROP_CONTENT; definition.setParameterValue(RenditionService.PARAM_RENDITION_NODETYPE, nodeType); definition.setParameterValue(AbstractRenderingEngine.PARAM_TARGET_CONTENT_PROPERTY, contentPropName); engine.execute(definition, source); verify(nodeService).createNode(eq(source), eq(assocType), any(QName.class), eq(nodeType), captor.capture()); props = captor.getValue(); assertEquals(contentPropName, props.get(ContentModel.PROP_CONTENT_PROPERTY_NAME)); }
Example 10
Source File: ContentStreamMimetypeLuceneBuilder.java From alfresco-data-model with GNU Lesser General Public License v3.0 | 4 votes |
@Override protected QName getQNameForExists() { return ContentModel.PROP_CONTENT; }
Example 11
Source File: ContentStreamLengthLuceneBuilder.java From alfresco-data-model with GNU Lesser General Public License v3.0 | 4 votes |
@Override protected QName getQNameForExists() { return ContentModel.PROP_CONTENT; }
Example 12
Source File: StreamContent.java From alfresco-remote-api with GNU Lesser General Public License v3.0 | 4 votes |
/** * @see org.springframework.extensions.webscripts.WebScript#execute(org.springframework.extensions.webscripts.WebScriptRequest, org.springframework.extensions.webscripts.WebScriptResponse) */ public void execute(WebScriptRequest req, WebScriptResponse res) throws IOException { // retrieve requested format String format = req.getFormat(); try { // construct model for script / template Status status = new Status(); Cache cache = new Cache(getDescription().getRequiredCache()); Map<String, Object> model = executeImpl(req, status, cache); if (model == null) { model = new HashMap<String, Object>(8, 1.0f); } model.put("status", status); model.put("cache", cache); // execute script if it exists ScriptDetails executeScript = getExecuteScript(req.getContentType()); if (executeScript != null) { if (logger.isDebugEnabled()) logger.debug("Executing script " + executeScript.getContent().getPathDescription()); Map<String, Object> scriptModel = createScriptParameters(req, res, executeScript, model); // add return model allowing script to add items to template model Map<String, Object> returnModel = new HashMap<String, Object>(8, 1.0f); scriptModel.put("model", returnModel); executeScript(executeScript.getContent(), scriptModel); mergeScriptModelIntoTemplateModel(executeScript.getContent().getPath(), returnModel, model); } // is a redirect to a status specific template required? if (status.getRedirect()) { // create model for template rendering Map<String, Object> templateModel = createTemplateParameters(req, res, model); sendStatus(req, res, status, cache, format, templateModel); } else { // Get the attachement property value Boolean attachBoolean = (Boolean)model.get("attach"); boolean attach = false; if (attachBoolean != null) { attach = attachBoolean.booleanValue(); } String contentPath = (String)model.get("contentPath"); if (contentPath == null) { // Get the content parameters from the model NodeRef nodeRef = (NodeRef)model.get("contentNode"); if (nodeRef == null) { throw new WebScriptException( "The content node was not specified so the content cannot be streamed to the client: " + executeScript.getContent().getPathDescription()); } QName propertyQName = null; String contentProperty = (String)model.get("contentProperty"); if (contentProperty == null) { // default to the standard content property propertyQName = ContentModel.PROP_CONTENT; } else { propertyQName = QName.createQName(contentProperty); } // Stream the content delegate.streamContent(req, res, nodeRef, propertyQName, attach, null, model); } else { // Stream the content delegate.streamContent(req, res, contentPath, attach, model); } } } catch(Throwable e) { throw createStatusException(e, req, res); } }
Example 13
Source File: ContentGet.java From alfresco-remote-api with GNU Lesser General Public License v3.0 | 4 votes |
/** * @see org.springframework.extensions.webscripts.WebScript#execute(WebScriptRequest, WebScriptResponse) */ public void execute(WebScriptRequest req, WebScriptResponse res) throws IOException { // create map of args String[] names = req.getParameterNames(); Map<String, String> args = new HashMap<String, String>(names.length, 1.0f); for (String name : names) { args.put(name, req.getParameter(name)); } // create map of template vars Map<String, String> templateVars = req.getServiceMatch().getTemplateVars(); // create object reference from url ObjectReference reference = createObjectReferenceFromUrl(args, templateVars); NodeRef nodeRef = reference.getNodeRef(); if (nodeRef == null) { throw new WebScriptException(HttpServletResponse.SC_NOT_FOUND, "Unable to find " + reference.toString()); } // determine attachment boolean attach = Boolean.valueOf(req.getParameter("a")); // render content QName propertyQName = ContentModel.PROP_CONTENT; String contentPart = templateVars.get("property"); if (contentPart.length() > 0 && contentPart.charAt(0) == ';') { if (contentPart.length() < 2) { throw new WebScriptException(HttpServletResponse.SC_BAD_REQUEST, "Content property malformed"); } String propertyName = contentPart.substring(1); if (propertyName.length() > 0) { propertyQName = QName.createQName(propertyName, namespaceService); } } // Stream the content streamContentLocal(req, res, nodeRef, attach, propertyQName, null); }
Example 14
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 15
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); }