Java Code Examples for org.alfresco.model.ContentModel.PROP_CONTENT
The following are Jave code examples for showing how to use
PROP_CONTENT of the
org.alfresco.model.ContentModel
class.
You can vote up the examples you like. Your votes will be used in our system to get
more good examples.
+ Save this method
Example 1
Project: alfresco-remote-api File: ContentInfo.java View Source Code | 7 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 2
Project: alfresco-remote-api File: QuickShareContentGet.java View Source Code | 7 votes |
protected void executeImpl(NodeRef nodeRef, Map<String, String> templateVars, WebScriptRequest req, WebScriptResponse res, Map<String, Object> model) 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); } } // determine attachment boolean attach = Boolean.valueOf(req.getParameter("a")); // Stream the content streamContentLocal(req, res, nodeRef, attach, propertyQName, model); }
Example 3
Project: alfresco-repository File: RhinoScriptProcessor.java View Source Code | 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 4
Project: alfresco-repository File: GetChildrenCannedQuery.java View Source Code | 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 5
Project: alfresco-remote-api File: ContentGet.java View Source Code | 5 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 6
Project: alfresco-repository File: UpdateThumbnailActionExecuter.java View Source Code | 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 7
Project: alfresco-repository File: ContentStreamMimetypeProperty.java View Source Code | 4 votes |
protected QName getQNameForExists() { return ContentModel.PROP_CONTENT; }
Example 8
Project: alfresco-repository File: AbstractRenderingEngineTest.java View Source Code | 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 9
Project: alfresco-data-model File: ContentStreamMimetypeLuceneBuilder.java View Source Code | 4 votes |
@Override protected QName getQNameForExists() { return ContentModel.PROP_CONTENT; }
Example 10
Project: alfresco-data-model File: ContentStreamLengthLuceneBuilder.java View Source Code | 4 votes |
@Override protected QName getQNameForExists() { return ContentModel.PROP_CONTENT; }
Example 11
Project: alfresco-remote-api File: NodesImpl.java View Source Code | 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); }