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

📄 cmsxmltemplateeditor.java

📁 一个cms内容管理平台
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
        Object tempObj = null;
        CmsXmlTemplateFile layoutTemplateFile = null;
        if (isSimplePage) {
            StringBuffer layoutBuffer = new StringBuffer(512);            
            layoutBuffer.append("<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n<xmltemplate>\n<stylesheet>");
            layoutBuffer.append("none");
            layoutBuffer.append("</stylesheet>\n<template><element name=\"jsptemplate\"/></template>\n<elementdef name=\"jsptemplate\">\n<class>com.opencms.flex.CmsJspTemplate</class>\n<template>");
            layoutBuffer.append(templateFile);
            layoutBuffer.append("</template>\n</elementdef>\n</xmltemplate>\n");
            layoutTemplateFile = new CmsXmlTemplateFile(cms, templateFile + com.opencms.core.I_CmsConstants.C_XML_CONTROL_FILE_SUFFIX, layoutBuffer.toString());
        } else {
            tempObj = CmsTemplateClassManager.getClassInstance(layoutTemplateClassName);
            CmsXmlTemplate layoutTemplateClassObject = (CmsXmlTemplate)tempObj;
            layoutTemplateFile = layoutTemplateClassObject.getOwnTemplateFile(cms,
                    layoutTemplateFilename, null, parameters, null);
        }
        
        // Get the XML parsed content of the body file.
        // This can be done by calling the getOwnTemplateFile() method of the
        // body's template class.
        tempObj = CmsTemplateClassManager.getClassInstance(bodyElementClassName);
        CmsXmlTemplate bodyElementClassObject = (CmsXmlTemplate)tempObj;
        CmsXmlTemplateFile bodyTemplateFile = bodyElementClassObject.getOwnTemplateFile(cms,
                tempBodyFilename, C_BODY_ELEMENT, parameters, null);

        // Get the temporary page file object
        CmsXmlControlFile temporaryControlFile = null;
        if (! isSimplePage) temporaryControlFile = new CmsXmlControlFile(cms, tempPageFilename);
        if(!existsContentParam) {
            Vector allBodys = bodyTemplateFile.getAllSections();
            if(allBodys == null || allBodys.size() == 0) {
                body = "";
            }else {
                body = (String)allBodys.elementAt(0);
            }
            bodytitle = body.equals("(default)") ? "" : body;
            if (isSimplePage) {
                style = cms.readProperty(layoutTemplateFilename, CmsPropertyDefinition.PROPERTY_TEMPLATE);
                if (style != null) {
                    style =  hostName + OpenCms.getSystemInfo().getOpenCmsContext() + style;
                } else {
                    style = "";
                }
            } else {
                temporaryControlFile.setElementTemplSelector(C_BODY_ELEMENT, body);
                temporaryControlFile.setElementTemplate(C_BODY_ELEMENT, tempBodyFilename);
                // change the current project to temp file project
                cms.getRequestContext().setCurrentProject(cms.readProject(tempProject));
                temporaryControlFile.write();
                cms.getRequestContext().setCurrentProject(cms.readProject(curProject));
                try {
                    style = getStylesheet(cms, null, layoutTemplateFile, null);
                } catch (Exception e) {
                    style = "";
                }
                if(style != null && !"".equals(style)) {
                    style = hostName + style;
                }                                   
            }         
            session.putValue("te_stylesheet", style);
        } else {
            // There exists a content parameter.
            // We have to check all possible changes requested by the user.
            if(titlechangeRequested) {
                // The user entered a new document title
                try {
                    cms.getRequestContext().setCurrentProject(cms.readProject(tempProject));
                    cms.writeProperty(tempPageFilename, CmsPropertyDefinition.PROPERTY_TITLE, title);
                    cms.getRequestContext().setCurrentProject(cms.readProject(curProject));
                }catch(CmsException e) {
                    cms.getRequestContext().setCurrentProject(cms.readProject(curProject));
                    if(CmsLog.getLog(this).isErrorEnabled() ) {
                        CmsLog.getLog(this).error("Could not write property " + CmsPropertyDefinition.PROPERTY_TITLE + " for file " + file, e);
                    }
                }
            }
            if(templatechangeRequested) {
                // The user requested a change of the layout template
                if (isSimplePage) {
                    cms.getRequestContext().setCurrentProject(cms.readProject(tempProject));
                    cms.writeProperty(tempPageFilename, CmsPropertyDefinition.PROPERTY_TEMPLATE, layoutTemplatFilenameRelative);
                    cms.getRequestContext().setCurrentProject(cms.readProject(curProject));         
                    style = cms.readProperty(layoutTemplateFilename, CmsPropertyDefinition.PROPERTY_TEMPLATE);    
                    if (style != null) {
                        style = hostName + OpenCms.getSystemInfo().getOpenCmsContext() + style;
                    } else {
                        style = "";
                    }
                } else { 
                    temporaryControlFile.setMasterTemplate(layoutTemplatFilenameRelative );
                    try {
                        style = getStylesheet(cms, null, layoutTemplateFile, null);
                    }catch(Exception e) {
                        style = "";
                    }
                    if(style != null && !"".equals(style)) {
                        style = hostName + style;
                    }   
                }             
                session.putValue("te_stylesheet", style);
            }
            if(bodytitlechangeRequested) {
                // The user entered a new title for the current body
                if((!oldBody.equals("(default)")) && (!oldBody.equals("script"))) {
                    if(bodytitle.toLowerCase().equals("script")) {
                        bodytitle = "script";
                    }
                    try {
                        bodyTemplateFile.renameSection(oldBody, bodytitle);
                        oldBody = bodytitle;
                        if(!bodychangeRequested) {
                            body = bodytitle;
                        }
                    }catch(Exception e) {
                        bodytitle = oldBodytitle;
                    }
                    if(bodytitle.equals("script")) {
                        session.putValue("te_pageeditor", editor);
                        editor = CmsMSDHtmlEditor.SELECTBOX_EDITORVIEWS[1];
                        parameters.put("editor", editor);
                    }
                }else {
                    bodytitle = oldBodytitle;
                }
            }
            if(bodychangeRequested) {
                if (! isSimplePage) temporaryControlFile.setElementTemplSelector(C_BODY_ELEMENT, body);
                bodytitle = body.equals("(default)") ? "" : body;
                if(body.equals("script")) {
                    // User wants to edit javascript code
                    // Select text editor
                    session.putValue("te_pageeditor", editor);
                    editor = CmsMSDHtmlEditor.SELECTBOX_EDITORVIEWS[1];
                    parameters.put("editor", editor);
                }else {
                    if(oldBody.equals("script")) {
                        // User wants to switch back from javascript mode
                        // Select old editor
                        editor = (String)session.getValue("te_pageeditor");
                        parameters.put("editor", editor);
                    }
                }
            }
            if(newbodyRequested) {
                body = C_BODY_ELEMENT + bodyTemplateFile.createNewSection(C_BODY_ELEMENT);
                bodytitle = body;
                if (! isSimplePage) {
                    temporaryControlFile.setElementTemplSelector(C_BODY_ELEMENT, body);
                    temporaryControlFile.setElementTemplate(C_BODY_ELEMENT, tempBodyFilename);
                }
            }
            
            // check for C_PROPERTY_RELATIVEROOT property (with directory search)
            String relativeRoot = cms.readProperty(file, org.opencms.file.CmsPropertyDefinition.PROPERTY_RELATIVEROOT, true);
            
            // save file contents to our temporary file.
            content = CmsEncoder.unescape(content, CmsEncoder.ENCODING_UTF_8);
            if (! CmsEncoder.ENCODING_UTF_8.equalsIgnoreCase(cms.getRequestContext().getEncoding())) {			
                content = CmsEncoder.escapeNonAscii(content);
            }          
			
            if((!exitRequested) || saveRequested) {
                bodyTemplateFile.setEditedTemplateContent(cms, content, oldBody, oldEdit.equals(CmsMSDHtmlEditor.SELECTBOX_EDITORVIEWS[0]), file, relativeRoot);
            }
            cms.getRequestContext().setCurrentProject(cms.readProject(tempProject));
            bodyTemplateFile.write();
            if (! isSimplePage) temporaryControlFile.write();
            cms.getRequestContext().setCurrentProject(cms.readProject(curProject));
        }

        // If the user requested a preview then send a redirect
        // to the temporary page file.
        if(previewRequested) {
            preview(tempPageFilename, reqCont);
            return "".getBytes();
        }

        // If the user requested a "save" expilitly by pressing one of
        // the "save" buttons, copy all informations of the temporary
        // files to the original files.
        if(saveRequested) {
            try{
                commitTemporaryFile(cms, bodyElementFilename, tempBodyFilename, tempProject, curProject);
                cms.getRequestContext().setCurrentProject(cms.readProject(tempProject));
                title = cms.readProperty(tempPageFilename, CmsPropertyDefinition.PROPERTY_TITLE);
                cms.getRequestContext().setCurrentProject(cms.readProject(curProject));
                if(title != null && !"".equals(title)) {
                    cms.writeProperty(file, CmsPropertyDefinition.PROPERTY_TITLE, title);
                }
                if (! isSimplePage) {
                    CmsXmlControlFile originalControlFile = new CmsXmlControlFile(cms, file);
                    originalControlFile.setMasterTemplate(temporaryControlFile.getMasterTemplate());
                    originalControlFile.write();
                }
            } catch (CmsException e){
                // there was an exception while the file should be saved
                // return to the editor and show the exception so the user can save the changes
                saveerror = e.getMessage();
                if(content != null){
                    session.putValue(CmsWorkplaceDefault.C_PARA_CONTENT, content);
                }
                if(body != null){
                    session.putValue("body", body);
                }
                if(file != null){
                    session.putValue(CmsWorkplaceDefault.C_PARA_RESOURCE, file);
                }
                if(editor != null){
                    session.putValue("editor", editor);
                }
                if(title != null){
                    session.putValue(CmsWorkplaceDefault.C_PARA_TITLE, title);
                }
                if(bodytitle != null){
                    session.putValue("bodytitle", bodytitle);
                }
                if(layoutTemplatFilenameRelative != null){
                    session.putValue("template", layoutTemplatFilenameRelative);
                }
                if(bodyElementClassName != null){
                    session.putValue("bodyclass", bodyElementClassName);
                }
                if(bodyElementFilename != null){
                    session.putValue("bodyfile", bodyElementFilename);
                }
                if(startView != null){
                    session.putValue("startview", startView);
                }
            }
        }

        // Check if we should leave th editor instead of start processing
        if(exitRequested && ((saveerror == null) || "".equals(saveerror))) {

            // First delete temporary files
            if (! isSimplePage) temporaryControlFile.removeFromFileCache();
            bodyTemplateFile.removeFromFileCache();
            // deleting the pagefile will delete the bodyfile too
            cms.getRequestContext().setCurrentProject(cms.readProject(tempProject));
            cms.deleteResource(tempPageFilename, org.opencms.file.CmsResource.DELETE_PRESERVE_SIBLINGS);

⌨️ 快捷键说明

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