⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 jpublishwrapper.java

📁 国外的一套开源CRM
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
        render(path, request, response, writer);
        try {                    
            content = writer.toString();
            writer.close();
        } catch (IOException e) {
            throw new GeneralException("Problems closing the Writer", e);
        }
        return content;
    }
    
    public void render(String path, HttpServletRequest request, HttpServletResponse response, Writer writer) throws GeneralException {
        render(path, request, response, writer, null, false);
    }
    
    public void render(String path, HttpServletRequest request, HttpServletResponse response, Writer writer, OutputStream outputStream) throws GeneralException {
        render(path, request, response, writer, outputStream, false);
    }

    public void render(String path, HttpServletRequest request, HttpServletResponse response, Writer writer, OutputStream outputStream, boolean allowRedirect) throws GeneralException {
        HttpSession session = request.getSession();
        ActionManager actionManager = siteContext.getActionManager();
        //String path = servletContext.getRealPath(pagePath);
        //Debug.logError("Path:" + path, module);

        // get the character encoding map
        CharacterEncodingMap characterEncodingMap = siteContext.getCharacterEncodingManager().getMap(path);

        // put standard servlet stuff into the context
        JPublishContext context = new JPublishContext(this);
        context.put("request", request);
        context.put("response", response);
        context.put("session", session);
        context.put("application", servletContext);

        // add the character encoding map to the context
        context.put("characterEncodingMap", characterEncodingMap);

        // add the URLUtilities to the context
        URLUtilities urlUtilities = new URLUtilities(request, response);
        context.put("urlUtilities", urlUtilities);

        // add the DateUtilities to the context
        context.put("dateUtilities", DateUtilities.getInstance());

        // add the NumberUtilities to the context
        context.put("numberUtilities", NumberUtilities.getInstance());

        // add the messages log to the context
        context.put("syslog", SiteContext.syslog);

        // expose the SiteContext
        context.put("site", siteContext);

        if (siteContext.isProtectReservedNames()) {
            context.enableCheckReservedNames(this);
        }

        // add the repositories to the context
        Iterator repositories = siteContext.getRepositories().iterator();
        while (repositories.hasNext()) {
            Repository repository = (Repository) repositories.next();
            context.put(repository.getName(), new RepositoryWrapper(repository, context));
            // add the fs_repository also as the name 'pages' so we can use existing logic in pages
            // note this is a hack and we should look at doing this a different way; but first need
            // to investigate how to get content from different repositories
            if (repository.getName().equals("fs_repository")) {
                context.put("pages", new RepositoryWrapper(repository, context));
            }
        }

        try {
            if (executePreEvaluationActions(request, response, context, path))
                return;

            // if the page is static
            StaticResourceManager staticResourceManager = siteContext.getStaticResourceManager();
            if (staticResourceManager.resourceExists(path)) {
                if (outputStream != null) {                
                    // execute the global actions
                    if (executeGlobalActions(request, response, context, path, allowRedirect))
                        return;

                    // execute path actions
                    if (executePathActions(request, response, context, path, allowRedirect))
                        return;
    
                    // execute parameter actions
                    if (executeParameterActions(request, response, context, path, allowRedirect))
                        return;

                    // load and return the static resource                                    
                    staticResourceManager.load(path, outputStream);
                    outputStream.flush();
                    return;
                } else {
                    throw new GeneralException("Cannot load static resource with a null OutputStream");
                }
            }
            
            // check and make sure we have a writer
            if (writer == null)
                throw new GeneralException("Cannot load dynamic content with a null Writer");

            // load the page          
            PageInstance pageInstance = siteContext.getPageManager().getPage(path);
            Page page = new Page(pageInstance);

            context.disableCheckReservedNames(this);

            // expose the page in the context
            context.put("page", page);

            // expose components in the context
            context.put("components", new ComponentMap(context));

            if (siteContext.isProtectReservedNames()) {
                context.enableCheckReservedNames(this);
            }

            // execute the global actions
            if (executeGlobalActions(request, response, context, path, allowRedirect))
                return;

            // execute path actions
            if (executePathActions(request, response, context, path, allowRedirect))
                return;

            // execute parameter actions
            if (executeParameterActions(request, response, context, path, allowRedirect))
                return;

            // execute the page actions           
            if (optionalRedirect(page.executeActions(context), path, response, allowRedirect))
                return;

            // get the template
            Template template = siteContext.getTemplateManager().getTemplate(page.getFullTemplateName());
           
            // merge the template           
            template.merge(context, page, writer);
            writer.flush();            
        } catch (FileNotFoundException e) {
            throw new GeneralException("File not found", e);
        } catch (Exception e) {
            throw new GeneralException("JPublish execution error", e);
        } finally {
            try {
                executePostEvaluationActions(request, response, context, path);
            } catch (Exception e) {
                throw new GeneralException("Error executing JPublish post evaluation actions", e);
            }
        }
    }

    /**      
     * Privleged action for setting the class path.  This is used to get around
     * the Java security system to set the class path so scripts have full 
     * access to all loaded Java classes.
     *  
     * <p>Note: This functionality is untested.</p>
     *   
     *  @author Anthony Eden
     */
    class SetClassPathAction implements PrivilegedAction {
        private String classPath;

        /** 
         * Construct the action to set the class path.        
         *   @param classPath The new class path
         */
        public SetClassPathAction(String classPath) {
            this.classPath = classPath;
        }

        /** 
         * Set the "java.class.path" property.               
         * @return Returns null
         */
        public Object run() {
            System.setProperty("java.class.path", classPath);
            return null; // nothing to return
        }
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -