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

📄 cmsxmltemplateeditor.java

📁 OpenCms 是一个J2EE的产品
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
    }

    /**
     * Gets the content of a defined section in a given template file and its subtemplates
     * with the given parameters.
     *
     * @see #getContent(CmsObject, String, String, Hashtable, String)
     * @param cms CmsObject Object for accessing system resources.
     * @param templateFile Filename of the template file.
     * @param elementName Element name of this template in our parent template.
     * @param parameters Hashtable with all template class parameters.
     * @param templateSelector template section that should be processed.
     */
    public byte[] getContent(CmsObject cms, String templateFile, String elementName,
            Hashtable parameters, String templateSelector) throws CmsException {
        CmsRequestContext reqCont = cms.getRequestContext();
        HttpServletRequest orgReq = CmsXmlTemplateLoader.getRequest(reqCont).getOriginalRequest();
        I_CmsSession session = CmsXmlTemplateLoader.getSession(cms.getRequestContext(), true);

        // get the temporary file projectid
        int tempProject = 0;
        try{
            tempProject = OpenCms.getWorkplaceManager().getTempFileProjectId();
        }catch(Exception e){
            throw new CmsLegacyException("Can not read projectId of tempfileproject for creating temporary file for editing! "+e.toString());
        }
        if(tempProject == 0){
            throw new CmsLegacyException("Can not create temporary file for editing!");
        }
        int curProject = cms.getRequestContext().currentProject().getId();

        // Get the user's browser
        String browser = orgReq.getHeader("user-agent");
        String hostName = orgReq.getScheme() + "://" + orgReq.getServerName() + ":" + orgReq.getServerPort();

        // Get all URL parameters
        String content = (String)parameters.get(CmsWorkplaceDefault.C_PARA_CONTENT);        
        if(content == null){
            // try to get the value from the session because we might come from errorpage
            content = (String)session.getValue(CmsWorkplaceDefault.C_PARA_CONTENT);
            session.removeValue(CmsWorkplaceDefault.C_PARA_CONTENT);
        }
        
        String body = (String)parameters.get("body");
        if(body == null){
            // try to get the value from the session because we might come from errorpage
            body = (String)session.getValue("body");
            session.removeValue("body");
        }
        String file = (String)parameters.get(CmsWorkplaceDefault.C_PARA_RESOURCE);
        if(file == null){
            // try to get the value from the session because we might come from errorpage
            file = (String)session.getValue(CmsWorkplaceDefault.C_PARA_RESOURCE);
            session.removeValue(CmsWorkplaceDefault.C_PARA_RESOURCE);
        }
        String editor = (String)parameters.get("editor");
        if((editor == null) || "".equals(editor)){
            // try to get the value from the session because we might come from errorpage
            editor = (String)session.getValue("editor");
            if(editor != null){
                parameters.put("editor", editor);
            }
            session.removeValue("editor");
        }
        String title = (String)parameters.get(CmsWorkplaceDefault.C_PARA_TITLE);
        if(title == null){
            // try to get the value from the session because we might come from errorpage
            title = (String)session.getValue(CmsWorkplaceDefault.C_PARA_TITLE);
            session.removeValue(CmsWorkplaceDefault.C_PARA_TITLE);
        }
        String bodytitle = (String)parameters.get("bodytitle");
        if(bodytitle == null){
            // try to get the value from the session because we might come from errorpage
            bodytitle = (String)session.getValue("bodytitle");
            session.removeValue("bodytitle");
        }
        String layoutTemplateFilename = (String)parameters.get("template");
        if(layoutTemplateFilename == null){
            // try to get the value from the session because we might come from errorpage
            layoutTemplateFilename = (String)session.getValue("template");
            session.removeValue("template");
        }
        String layoutTemplatFilenameRelative = layoutTemplateFilename;
        layoutTemplateFilename = CmsLinkManager.getAbsoluteUri(layoutTemplateFilename, file);
        String bodyElementClassName = (String)parameters.get("bodyclass");
        if(bodyElementClassName == null){
            // try to get the value from the session because we might come from errorpage
            bodyElementClassName = (String)session.getValue("bodyclass");
            session.removeValue("bodyclass");
        }
        String bodyElementFilename = (String)parameters.get("bodyfile");
        if(bodyElementFilename == null){
            // try to get the value from the session because we might come from errorpage
            bodyElementFilename = (String)session.getValue("bodyfile");
            session.removeValue("bodyfile");
        }
        String action = (String)parameters.get(CmsWorkplaceDefault.C_PARA_ACTION);

        String startView = (String)parameters.get("startview");
        if((startView == null) || ("".equals(startView))){
            // try to get the value from the session because we might come from errorpage
            startView = (String)session.getValue("startview");
            session.removeValue("startview");
        }

        // Get all session parameters
        String oldEdit = (String)session.getValue("te_oldedit");
        String oldLayoutFilename = (String)session.getValue("te_oldlayout");
        String oldTitle = (String)session.getValue("te_title");
        String oldBody = (String)session.getValue("te_oldbody");
        String oldBodytitle = (String)session.getValue("te_oldbodytitle");
        String layoutTemplateClassName = (String)session.getValue("te_templateclass");
        String tempPageFilename = (String)session.getValue("te_temppagefile");
        String tempBodyFilename = (String)session.getValue("te_tempbodyfile");
        String style = (String)session.getValue("te_stylesheet");

        boolean existsContentParam = content != null;
        boolean existsFileParam = (file != null && (!"".equals(file)));
        boolean saveRequested = ((action != null) && (CmsWorkplaceDefault.C_EDIT_ACTION_SAVE.equals(action) || CmsWorkplaceDefault.C_EDIT_ACTION_SAVEEXIT.equals(action)));
        boolean exitRequested = ((action != null) && (CmsWorkplaceDefault.C_EDIT_ACTION_EXIT.equals(action) || CmsWorkplaceDefault.C_EDIT_ACTION_SAVEEXIT.equals(action)));
        boolean bodychangeRequested = ((oldBody != null) && (body != null) && (!(oldBody.equals(body))));
        boolean templatechangeRequested = (oldLayoutFilename != null && layoutTemplateFilename != null
               && (!(oldLayoutFilename.equals(layoutTemplateFilename))));
        boolean titlechangeRequested = (oldTitle != null && title != null && (!(oldTitle.equals(title))));
        boolean newbodyRequested = ((action != null) && "newbody".equals(action));
        boolean previewRequested = ((action != null) && "preview".equals(action));
        boolean bodytitlechangeRequested = (oldBodytitle != null && bodytitle != null && (!(oldBodytitle.equals(bodytitle))));

        String saveerror = "";

        // Check if there is a file parameter in the request
        if(!existsFileParam) {
            throwException("No \"file\" parameter given. Don't know which file should be edited.");
        }

        // If there is no content parameter this seems to be
        // a new request of the page editor.
        // So we have to read all files and set some initial values.
        parameters.put("root.pagetype", OpenCms.getResourceManager().getResourceType(cms.readResource(file).getTypeId()).getTypeName());
        parameters.put("filename_for_relative_template", file);
        
        // Simple page support
        String templateProp = cms.readProperty(file, CmsPropertyDefinition.PROPERTY_TEMPLATE);
        boolean isSimplePage = (templateProp != null);

        // Check, if the selected page file is locked
        CmsResource pageFileResource = cms.readResource(file);
        CmsLock lock = cms.getLock(file);
        if(lock.isNullLock()) {
            cms.lockResource(file);
        }
                                        
        if(!existsContentParam) {
            
            if (isSimplePage) {
                
                bodyElementClassName = CmsCompatibleCheck.XML_CONTROL_DEFAULT_CLASS;
                bodyElementFilename = file;
                layoutTemplateClassName = CmsCompatibleCheck.XML_CONTROL_DEFAULT_CLASS;
                layoutTemplateFilename = templateProp;
                layoutTemplatFilenameRelative = templateProp;
                
            } else {             
                
                CmsXmlControlFile originalControlFile = new CmsXmlControlFile(cms, file);
                if(originalControlFile.isElementClassDefined(C_BODY_ELEMENT)) {
                    bodyElementClassName = originalControlFile.getElementClass(C_BODY_ELEMENT);
                }
                if(originalControlFile.isElementTemplateDefined(C_BODY_ELEMENT)) {
                    bodyElementFilename = originalControlFile.getElementTemplate(C_BODY_ELEMENT);
                    bodyElementFilename = originalControlFile.validateBodyPath(cms, bodyElementFilename, cms.readResource(file));
                }
                if((bodyElementClassName == null) || (bodyElementFilename == null)) {
                    // Either the template class or the template file
                    // for the body element could not be determined.
                    // BUG: Send error here
                }

                // The content file must be locked before editing
                //CmsResource contentFileResource = cms.readFileHeader(bodyElementFilename);
                lock = cms.getLock(bodyElementFilename);
                if(lock.isNullLock()) {
                    cms.lockResource(bodyElementFilename);
                }
                // Now get the currently selected master template file
                layoutTemplateFilename = originalControlFile.getMasterTemplate();
                layoutTemplatFilenameRelative = layoutTemplateFilename;
                layoutTemplateFilename = CmsLinkManager.getAbsoluteUri(layoutTemplateFilename, originalControlFile.getAbsoluteFilename());
                layoutTemplateClassName = originalControlFile.getTemplateClass();            
            } 
            
            int browserId;
            if(browser.indexOf("MSIE") > -1) {
                browserId = 0;
            }else {
                browserId = 1;
            }

            if(editor == null || "".equals(editor)) {
                if(startView == null || "".equals(startView)){
                    editor = CmsMSDHtmlEditor.SELECTBOX_EDITORVIEWS[CmsWorkplaceDefault.C_SELECTBOX_EDITORVIEWS_DEFAULT[browserId]];
                } else {
                    editor = startView;
                }
                session.putValue("te_pageeditor", editor);
                parameters.put("editor", editor);
            }

            // And finally the document title
            title = cms.readProperty(file, CmsPropertyDefinition.PROPERTY_TITLE);
            if(title == null) {
                title = "";
            }

            // Okay. All values are initialized. Now we can create
            // the temporary files.
            // if the parameter noactivex is set the temp file was already created,
            // so read the filename from the session
            String noactivex = (String)parameters.get("noactivex");
            
            if(noactivex == null || "".equals(noactivex.trim())){
                tempPageFilename = createTemporaryFile(cms, pageFileResource, tempProject, curProject);
            } else {
                tempPageFilename = (String)session.getValue("te_temppagefile");
            }
            
            cms.getRequestContext().setCurrentProject(cms.readProject(curProject));
            if (isSimplePage) {
                tempBodyFilename = tempPageFilename;
            } else {
                tempBodyFilename = CmsCompatibleCheck.VFS_PATH_BODIES.substring(0, CmsCompatibleCheck.VFS_PATH_BODIES.length()-1) + tempPageFilename;
            }
            
            session.putValue("te_temppagefile", tempPageFilename);
            session.putValue("te_tempbodyfile", tempBodyFilename);
        }
        // Get the XML parsed content of the layout file.
        // This can be done by calling the getOwnTemplateFile() method of the
        // layout's template class.
        // The content is needed to determine the HTML style of the body element.

⌨️ 快捷键说明

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