Package org.jahia.services.render.scripting

Examples of org.jahia.services.render.scripting.Script


        Set<String> servedFromCache = (Set<String>) renderContext.getRequest().getAttribute("servedFromCache");
        if (servedFromCache == null) {
            servedFromCache = new HashSet<String>();
            renderContext.getRequest().setAttribute("servedFromCache", servedFromCache);
        }
        final Script script = (Script) renderContext.getRequest().getAttribute("script");
        boolean isBinded = resource.getNode().isNodeType("jmix:bindedComponent");
        if (script != null) {
            chain.pushAttribute(renderContext.getRequest(), "cache.perUser", Boolean.valueOf(
                    script.getView().getProperties().getProperty("cache.perUser", "false")));
            if(isBinded) {
                chain.pushAttribute(renderContext.getRequest(), "cache.mainResource", Boolean.TRUE);
            } else {
                chain.pushAttribute(renderContext.getRequest(), "cache.mainResource", Boolean.valueOf(
                    script.getView().getProperties().getProperty("cache.mainResource", "false")));
            }
            if (Boolean.valueOf(script.getView().getProperties().getProperty(
                    "cache.additional.key.useMainResourcePath", "false"))) {
                resource.getModuleParams().put("module.cache.additional.key",
                        renderContext.getMainResource().getNode().getPath());
            }
        }
View Full Code Here


    }

    public String execute(String previousOut, RenderContext renderContext, Resource resource, RenderChain chain)
            throws Exception {
        boolean isBinded = resource.getNode().isNodeType("jmix:bindedComponent");
        final Script script = (Script) renderContext.getRequest().getAttribute("script");
        if (script != null) {
            chain.pushAttribute(renderContext.getRequest(), "cache.perUser", Boolean.valueOf(
                    script.getView().getProperties().getProperty("cache.perUser", "false")));
            if(isBinded) {
                chain.pushAttribute(renderContext.getRequest(), "cache.mainResource", Boolean.TRUE);
            } else {
                chain.pushAttribute(renderContext.getRequest(), "cache.mainResource", Boolean.valueOf(
                    script.getView().getProperties().getProperty("cache.mainResource", "false")));
            }
        }
        resource.getDependencies().add(resource.getNode().getPath());
        String key = cacheProvider.getKeyGenerator().generate(resource, renderContext);
        @SuppressWarnings("unchecked")
        Set<String> servedFromCache = (Set<String>) renderContext.getRequest().getAttribute("servedFromCache");
        if (servedFromCache.contains(key)) {
            return previousOut;
        }
        if (key.contains("_mr_")) {
            resource.getDependencies().add(renderContext.getMainResource().getNode().getPath());
            if (script != null && Boolean.valueOf(script.getView().getProperties().getProperty(
                    "cache.mainResource.flushParent", "false"))) {
                try {
                    resource.getDependencies().add(renderContext.getMainResource().getNode().getParent().getPath());
                } catch (ItemNotFoundException e) {
                }
            }
        }
        boolean cacheable = !notCacheableFragment.contains(key);
        if(renderContext.isLoggedIn() && renderContext.getRequest().getParameter("v")!=null){
            cacheable = false;
        }
        if (renderContext.getRequest().getParameter("ec") != null && renderContext.getRequest().getParameter(
                "ec").equals(resource.getNode().getIdentifier())) {
            cacheable = false;
        }
        final Cache cache = cacheProvider.getCache();
        boolean debugEnabled = logger.isDebugEnabled();
        boolean displayCacheInfo = Boolean.valueOf(renderContext.getRequest().getParameter("cacheinfo"));
        String perUserKey = key.replaceAll(DefaultCacheKeyGenerator.PER_USER, renderContext.getUser().getUsername()).replaceAll("_mr_",
                renderContext.getMainResource().getNode().getPath() +
                renderContext.getMainResource().getResolvedTemplate());
        /*if (Boolean.TRUE.equals(renderContext.getRequest().getAttribute("cache.dynamicRolesAcls"))) {
            key = cacheProvider.getKeyGenerator().replaceField(key, "acls", "dynamicRolesAcls");
            chain.pushAttribute(renderContext.getRequest(), "cache.dynamicRolesAcls", Boolean.FALSE);
        }*/
        if (debugEnabled) {
            logger.debug("Generating content for node: {}", perUserKey);
        }
        try {
            if (cacheable) {
                String perUser = (String) renderContext.getRequest().getAttribute("perUser");
                if (perUser != null) {
                    // This content must be cached by user as it is defined in the options panel
                    // The value of the node property from the mixin jmix:cache are only checked in the TemplatesAttributesFilter
                    // So we need to recalculate the key as we were not aware that this content needed to be cached by user
                    // We need to store content with the previously calculate dcache to avoid lock up.
                    cache.put(new Element(perUserKey, null));
                    key = cacheProvider.getKeyGenerator().replaceField(key, "acls", DefaultCacheKeyGenerator.PER_USER);
                    perUserKey = key.replaceAll(DefaultCacheKeyGenerator.PER_USER, renderContext.getUser().getUsername()).replaceAll("_mr_",
                            renderContext.getMainResource().getNode().getPath() +
                            renderContext.getMainResource().getResolvedTemplate());
                }
                String cacheAttribute = (String) renderContext.getRequest().getAttribute("expiration");
                Long expiration = cacheAttribute != null ? Long.valueOf(cacheAttribute) : Long.valueOf(
                        script != null ? script.getView().getProperties().getProperty("cache.expiration",
                                "-1") : "-1");
                final Cache dependenciesCache = cacheProvider.getDependenciesCache();
                Set<String> depNodeWrappers = resource.getDependencies();
                for (String path : depNodeWrappers) {
                    Element element1 = dependenciesCache.get(path);
View Full Code Here

    private ModuleCacheProvider cacheProvider;
    private ModuleGeneratorQueue generatorQueue;

    public String prepare(RenderContext renderContext, Resource resource, RenderChain chain) throws Exception {
        if (!(resource.getNode() instanceof JCRFrozenNodeAsRegular)) {
            final Script script = (Script) renderContext.getRequest().getAttribute("script");
            boolean isBinded = resource.getNode().isNodeType("jmix:bindedComponent");
            if (script != null) {
                chain.pushAttribute(renderContext.getRequest(), "cache.perUser", Boolean.valueOf(
                        script.getView().getProperties().getProperty("cache.perUser", "false")));
                if (isBinded) {
                    chain.pushAttribute(renderContext.getRequest(), "cache.mainResource", Boolean.TRUE);
                } else {
                    chain.pushAttribute(renderContext.getRequest(), "cache.mainResource", Boolean.valueOf(
                            script.getView().getProperties().getProperty("cache.mainResource", "false")));
                }
            }
            boolean debugEnabled = logger.isDebugEnabled();
            boolean displayCacheInfo = Boolean.valueOf(renderContext.getRequest().getParameter("cacheinfo"));
            String key = cacheProvider.getKeyGenerator().generate(resource, renderContext);
View Full Code Here

    }

    public String execute(String previousOut, RenderContext renderContext, Resource resource, RenderChain chain)
            throws Exception {
        if (!(resource.getNode() instanceof JCRFrozenNodeAsRegular)) {
            final Script script = (Script) renderContext.getRequest().getAttribute("script");
            boolean isBinded = resource.getNode().isNodeType("jmix:bindedComponent");
            if (script!=null) {
                chain.pushAttribute(renderContext.getRequest(), "cache.perUser",
                        Boolean.valueOf(script.getView().getProperties().getProperty("cache.perUser", "false")));
                if (isBinded) {
                    chain.pushAttribute(renderContext.getRequest(), "cache.mainResource", Boolean.TRUE);
                } else {
                    chain.pushAttribute(renderContext.getRequest(), "cache.mainResource", Boolean.valueOf(
                            script.getView().getProperties().getProperty("cache.mainResource", "false")));
                }
            }
            resource.getDependencies().add(resource.getNode().getPath());
            Map<String, Map<String, Integer>> templatesCacheExpiration = renderContext.getTemplatesCacheExpiration();
            boolean debugEnabled = logger.isDebugEnabled();
            boolean displayCacheInfo = Boolean.valueOf(renderContext.getRequest().getParameter("cacheinfo"));
            String key = cacheProvider.getKeyGenerator().generate(resource, renderContext);
            if(key.contains("_mr_")) {
                resource.getDependencies().add(renderContext.getMainResource().getNode().getPath());
                if(script!=null && Boolean.valueOf(
                    script.getView().getProperties().getProperty("cache.mainResource.flushParent", "false"))) {
                    try {
                        resource.getDependencies().add(renderContext.getMainResource().getNode().getParent().getPath());
                    } catch (ItemNotFoundException e) {                      
                    }
                }
            }
            JCRNodeWrapper areaResource = (JCRNodeWrapper) renderContext.getRequest().getAttribute("areaResource");
            if(areaResource !=null) {
                resource.getDependencies().add(areaResource.getPath());
            }
            String perUserKey = key.replaceAll("_perUser_", renderContext.getUser().getUsername()).replaceAll("_mr_",renderContext.getMainResource().getNode().getPath()+renderContext.getMainResource().getResolvedTemplate());
            if (debugEnabled) {
                logger.debug("Generating content for node : " + perUserKey);
            }

            String cacheAttribute = (String) renderContext.getRequest().getAttribute("expiration");
            Long expiration = cacheAttribute != null ? Long.valueOf(cacheAttribute) :
                    Long.valueOf(script!=null?script.getView().getProperties().getProperty("cache.expiration", "-1"):"-1");
            Cache dependenciesCache = cacheProvider.getDependenciesCache();
            Set<String> depNodeWrappers = resource.getDependencies();
            for (String path : depNodeWrappers) {
                Long lowestExpiration = 0L;
                Map<String, Integer> cachesExpiration = templatesCacheExpiration.get(path);
View Full Code Here

        final HttpServletRequest request = context.getRequest();

        request.setAttribute("renderContext", context);
        try {
            final Script script = service.resolveScript(resource, context);
            chain.pushAttribute(request, "script", script);
            chain.pushAttribute(request, "scriptInfo", script.getView().getInfo());
        } catch (TemplateNotFoundException e) {
            chain.pushAttribute(request, "script", null);
            chain.pushAttribute(request, "scriptInfo", null);
        }
        chain.pushAttribute(request, "workspace", node.getSession().getWorkspace().getName());
View Full Code Here

        if (profiler != null) {
            profiler.start("render template " + resource.getResolvedTemplate());
        }

        HttpServletRequest request = renderContext.getRequest();
        Script script = (Script) request.getAttribute("script");
        renderContext.getResourcesStack().push(resource);
        StringBuffer output = new StringBuffer();
        try {
            if (logger.isDebugEnabled()) {
                logger.debug("Render " + script.getView().getPath() + " for resource: " + resource);
                if(renderContext.getRequest().getAttribute("previousTemplate")!=null) {
                    logger.debug("previousTemplate object for rendering before script: "+((Template) renderContext.getRequest().getAttribute("previousTemplate")).serialize());
                } else {
                    logger.debug("previousTemplate object for rendering before script is null.");
                }
                if(renderContext.getRequest().getAttribute("usedTemplate")!=null) {
                    logger.debug("usedTemplate object for rendering before script: "+((Template) renderContext.getRequest().getAttribute("usedTemplate")).serialize());
                } else {
                    logger.debug("usedTemplate object for rendering before script is null.");
                }
            }
            long start = 0;
            if (SettingsBean.getInstance().isDevelopmentMode() && Boolean.valueOf(renderContext.getRequest().getParameter("moduleinfo")) && !resource.getNode().isNodeType("jnt:pageTemplate")) {
                output.append("\n<fieldset> ");
                start = System.currentTimeMillis();
            }
            output.append(script.execute(resource, renderContext));

            if (logger.isDebugEnabled()) {
                if(renderContext.getRequest().getAttribute("previousTemplate")!=null) {
                    logger.debug("Current previousTemplate object for rendering after script: "+((Template) renderContext.getRequest().getAttribute("previousTemplate")).serialize());
                } else {
                    logger.debug("previousTemplate object for rendering after script is null.");
                }
                if(renderContext.getRequest().getAttribute("usedTemplate")!=null) {
                    logger.debug("Current usedTemplate object for rendering after script: "+((Template) renderContext.getRequest().getAttribute("usedTemplate")).serialize());
                } else {
                    logger.debug("usedTemplate object for rendering after script is null.");
                }
            }

            if (SettingsBean.getInstance().isDevelopmentMode() && Boolean.valueOf(renderContext.getRequest().getParameter("moduleinfo")) && !resource.getNode().isNodeType("jnt:pageTemplate")) {
                output.append("<legend>")
                        .append("<img src=\"")
                        .append(renderContext.getURLGenerator().getContext())
                        .append("/modules/default/images/icons/information.png")
                        .append("\" title=\"").append(script.getView().getInfo()).append(" node : ").append(resource.getNode().getPath())
                        .append(" in ").append(System.currentTimeMillis() - start).append( "ms")
                        .append("\"/></legend>");
                output.append("</fieldset> ");
            }

        } catch (RenderException e) {
            output.append(handleError(script.getView().getInfo(), e, renderContext, resource));
        } finally {
            renderContext.getResourcesStack().pop();
        }
        return output.toString().trim();
    }
View Full Code Here

*
*/
public class TemplatePermissionCheckFilter extends AbstractFilter {

    public String prepare(RenderContext renderContext, final Resource resource, RenderChain chain) throws Exception {
        Script script = (Script) renderContext.getRequest().getAttribute("script");
        JCRNodeWrapper node = resource.getNode();
        if (script != null) {
            String requirePermissions = script.getView().getProperties().getProperty("requirePermissions");
            if (requirePermissions != null) {
                chain.pushAttribute(renderContext.getRequest(),"cache.dynamicRolesAcls",Boolean.TRUE);
                String[] perms = requirePermissions.split(" ");
                for (String perm : perms) {
                    if (!node.hasPermission(perm)) {
View Full Code Here

        if (!resource.getContextConfiguration().equals(Resource.CONFIGURATION_INCLUDE)) {
            chain.pushAttribute(request, "moduleMap", new HashMap());
        }

        Script script = (Script) request.getAttribute("script");
        chain.pushAttribute(context.getRequest(), Config.FMT_LOCALIZATION_CONTEXT + ".request", new LocalizationContext(
                new JahiaResourceBundle(resource.getLocale(), script.getView().getModule().getName()),
                resource.getLocale()));
        return null;
    }
View Full Code Here

     * @throws RepositoryException
     * @throws IOException
     */
    public Script resolveScript(Resource resource, RenderContext context) throws RepositoryException, TemplateNotFoundException {
        for (ScriptResolver scriptResolver : scriptResolvers) {
            Script s = scriptResolver.resolveScript(resource, context);
            if (s != null) {
                return s;
            }
        }
        return null;
View Full Code Here

TOP

Related Classes of org.jahia.services.render.scripting.Script

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.