Search in sources :

Example 1 with BaseScopableProcessorExtension

use of org.alfresco.repo.jscript.BaseScopableProcessorExtension in project alfresco-remote-api by Alfresco.

the class QuickShareThumbnailContentGet method executeImpl.

@Override
protected void executeImpl(NodeRef nodeRef, Map<String, String> templateVars, WebScriptRequest req, WebScriptResponse res, Map<String, Object> model) throws IOException {
    String thumbnailName = templateVars.get("thumbnailname");
    if (thumbnailName == null) {
        logger.error("Thumbnail name was not provided: " + nodeRef);
        throw new WebScriptException(HttpServletResponse.SC_NOT_FOUND, "Unable to find " + nodeRef);
    }
    // the latest thumbnail image.
    if (model == null) {
        model = new HashMap<String, Object>(1);
    }
    if (req.getParameter("lastModified") != null) {
        // note: must be String not boolean
        model.put("allowBrowserToCache", "true");
    } else {
        // note: must be String not boolean
        model.put("allowBrowserToCache", "false");
    }
    NodeRef thumbnailNodeRef = thumbnailService.getThumbnailByName(nodeRef, ContentModel.PROP_CONTENT, thumbnailName);
    if (thumbnailNodeRef == null) {
        // Get the queue/force create setting
        boolean qc = false;
        boolean fc = false;
        String c = req.getParameter("c");
        if (c != null) {
            if (c.equals("queue")) {
                qc = true;
            } else if (c.equals("force")) {
                fc = true;
            }
        }
        // Get the place holder flag
        boolean ph = false;
        String phString = req.getParameter("ph");
        if (phString != null) {
            ph = new Boolean(phString);
        }
        // note: required for ValueConverter (collection)
        Scriptable scope = new BaseScopableProcessorExtension().getScope();
        ScriptNode node = new ScriptNode(nodeRef, serviceRegistry, scope);
        // Queue the creation of the thumbnail if appropriate
        if (fc) {
            ScriptNode thumbnailNode = node.createThumbnail(thumbnailName, false);
            if (thumbnailNode != null) {
                thumbnailNodeRef = thumbnailNode.getNodeRef();
            }
        } else {
            if (qc) {
                node.createThumbnail(thumbnailName, true);
            }
        }
        if (thumbnailNodeRef == null) {
            if (ph == true) {
                // Try and get the place holder resource. We use a method in the thumbnail service
                // that by default gives us a resource based on the content's mime type.
                String phPath = null;
                ContentData contentData = (ContentData) this.serviceRegistry.getNodeService().getProperty(nodeRef, ContentModel.PROP_CONTENT);
                if (contentData != null) {
                    phPath = scriptThumbnailService.getMimeAwarePlaceHolderResourcePath(thumbnailName, contentData.getMimetype());
                }
                if (phPath == null) {
                    // 404 since no thumbnail was found
                    throw new WebScriptException(HttpServletResponse.SC_NOT_FOUND, "Thumbnail was not found and no place holder resource set for '" + thumbnailName + "'");
                } else {
                    // Set the resouce path in the model ready for the content stream to send back to the client
                    model.put("contentPath", phPath);
                }
            } else {
                // 404 since no thumbnail was found
                throw new WebScriptException(HttpServletResponse.SC_NOT_FOUND, "Thumbnail was not found");
            }
        }
    }
    super.executeImpl(thumbnailNodeRef, templateVars, req, res, model);
    if (logger.isDebugEnabled()) {
        logger.debug("QuickShare - retrieved thumbnail content: " + thumbnailNodeRef + " [" + nodeRef + "," + thumbnailName + "]");
    }
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) ContentData(org.alfresco.service.cmr.repository.ContentData) WebScriptException(org.springframework.extensions.webscripts.WebScriptException) BaseScopableProcessorExtension(org.alfresco.repo.jscript.BaseScopableProcessorExtension) Scriptable(org.mozilla.javascript.Scriptable) ScriptNode(org.alfresco.repo.jscript.ScriptNode)

Aggregations

BaseScopableProcessorExtension (org.alfresco.repo.jscript.BaseScopableProcessorExtension)1 ScriptNode (org.alfresco.repo.jscript.ScriptNode)1 ContentData (org.alfresco.service.cmr.repository.ContentData)1 NodeRef (org.alfresco.service.cmr.repository.NodeRef)1 Scriptable (org.mozilla.javascript.Scriptable)1 WebScriptException (org.springframework.extensions.webscripts.WebScriptException)1