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

📄 cmsxmltemplateeditor.java

📁 内容管理
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
            try{
                commitTemporaryFile(cms, bodyElementFilename, tempBodyFilename, tempProject, curProject);
                cms.getRequestContext().setCurrentProject(tempProject);
                title = cms.readProperty(tempPageFilename, C_PROPERTY_TITLE);
                cms.getRequestContext().setCurrentProject(curProject);
                if(title != null && !"".equals(title)) {
                    cms.writeProperty(file, C_PROPERTY_TITLE, title);
                }
                CmsXmlControlFile originalControlFile = new CmsXmlControlFile(cms, file);
                originalControlFile.setMasterTemplate(temporaryControlFile.getMasterTemplate());
                originalControlFile.write();
                // here we care about the linkmanagement
                CmsPageLinks linkObject = cms.getPageLinks(file);
                cms.createLinkEntrys(linkObject.getResourceId(), linkObject.getLinkTargets());
            } 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.getShortException();
                if(content != null){
                    session.putValue(C_PARA_CONTENT, content);
                }
                if(body != null){
                    session.putValue("body", body);
                }
                if(file != null){
                    session.putValue(C_PARA_FILE, file.trim());
                }
                if(editor != null){
                    session.putValue("editor", editor);
                }
                if(title != null){
                    session.putValue(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
            temporaryControlFile.removeFromFileCache();
            bodyTemplateFile.removeFromFileCache();
            // deleting the pagefile will delete the bodyfile too
            cms.getRequestContext().setCurrentProject(tempProject);
            cms.deleteResource(tempPageFilename);
            cms.getRequestContext().setCurrentProject(curProject);
            try {
                cms.getRequestContext().getResponse().sendCmsRedirect("/system/workplace/action/index.html");
            }catch(IOException e) {
                throwException("Could not send redirect to workplace main screen.", e);
            }
            return null;
        }

        // Include the datablocks of the layout file into the body file.
        // So the "bodytag" and "style" data can be accessed by the body file.
        Element bodyTag = layoutTemplateFile.getBodyTag();
        bodyTemplateFile.setBodyTag(bodyTag);
		
		// Load the body!
		content = bodyTemplateFile.getEditableTemplateContent(this, parameters, body, editor.equals(C_SELECTBOX_EDITORVIEWS[0]), style);
		
		// set the context & servlet path in editor content
		content = CmsStringSubstitution.substitute(content, C_MACRO_OPENCMS_CONTEXT + "/", A_OpenCms.getOpenCmsContext());
        
        // escape content
        content = Encoder.escapeWBlanks(content, Encoder.C_URI_ENCODING);
        
        parameters.put(C_PARA_CONTENT, content);

        // put the body parameter so that the selectbox can set the correct current value
        parameters.put("body", body);
        parameters.put("bodyfile", bodyElementFilename);
        parameters.put("bodyclass", bodyElementClassName);
        parameters.put("template", layoutTemplateFilename);

        // remove all parameters that could be relevant for the
        // included editor.
        parameters.remove(C_PARA_FILE);
        parameters.remove(C_PARA_ACTION);
        int numEditors = C_SELECTBOX_EDITORVIEWS.length;
        for(int i = 0;i < numEditors;i++) {
            if(editor.equals(C_SELECTBOX_EDITORVIEWS[i])) {
                parameters.put("editor._CLASS_", C_SELECTBOX_EDITORVIEWS_CLASSES[i]);
                parameters.put("editor._TEMPLATE_", "/system/workplace/templates/" + C_SELECTBOX_EDITORVIEWS_TEMPLATES[i]);
            }
        }
        session.putValue("te_file", file);
        session.putValue("te_oldedit", editor);
        session.putValue("te_oldbody", body);
        session.putValue("te_oldbodytitle", bodytitle);
        session.putValue("te_oldlayout", layoutTemplateFilename);
        if(title != null) {
            session.putValue("te_title", title);
        }else {
            session.putValue("te_title", "");
        }
        session.putValue("te_templateclass", layoutTemplateClassName);
        CmsXmlWpTemplateFile xmlTemplateDocument = (CmsXmlWpTemplateFile)getOwnTemplateFile(cms,
                templateFile, elementName, parameters, templateSelector);
        xmlTemplateDocument.setData("editor", editor);
        xmlTemplateDocument.setData("bodyfile", bodyElementFilename);
        xmlTemplateDocument.setData("bodyclass", bodyElementClassName);
        xmlTemplateDocument.setData("editorframe", (String)parameters.get("root.editorframe"));
        if (bodytitle != null) {
            xmlTemplateDocument.setData("bodytitle", bodytitle);
        }

        // Put the "file" datablock for processing in the template file.
        // It will be inserted in a hidden input field and given back when submitting.
        xmlTemplateDocument.setData(C_PARA_FILE, file);
        if(!"".equals(saveerror)){
            templateSelector = "errorsave";
            xmlTemplateDocument.setData("errordetail", saveerror);
            xmlTemplateDocument.setData("errorlasturl", xmlTemplateDocument.getFilename()+".html");
        }
        return startProcessing(cms, xmlTemplateDocument, elementName, parameters, templateSelector);
    }

    /** Gets all editor views available in the template editor screens.
     * <P>
     * The given vectors <code>names</code> and <code>values</code> will
     * be filled with the appropriate information to be used for building
     * a select box.
     * <P>
     * Used to build font select boxes in editors.
     *
     * @param cms CmsObject Object for accessing system resources.
     * @param lang reference to the currently valid language file
     * @param names Vector to be filled with the appropriate values in this method.
     * @param values Vector to be filled with the appropriate values in this method.
     * @param parameters Hashtable containing all user parameters <em>(not used here)</em>.
     * @return Index representing the user's current workplace view in the vectors.
     * @throws CmsException
     */

    public Integer getEditorViews(CmsObject cms, CmsXmlLanguageFile lang, Vector names, Vector values,
            Hashtable parameters) throws CmsException {
        Vector names2 = new Vector();
        Vector values2 = new Vector();
        getConstantSelectEntries(names2, values2, C_SELECTBOX_EDITORVIEWS, lang);
        int browserId;
        CmsRequestContext reqCont = cms.getRequestContext();
        HttpServletRequest orgReq = (HttpServletRequest)reqCont.getRequest().getOriginalRequest();
        String browser = orgReq.getHeader("user-agent");
        if(browser.indexOf("MSIE") > -1) {
            browserId = 0;
        }
        else {
            browserId = 1;
        }
        int loop = 1;
        int allowedEditors = C_SELECTBOX_EDITORVIEWS_ALLOWED[browserId];
        if(((String)parameters.get("body")).equals("script")) {
            allowedEditors = allowedEditors & 510;
        }
        for(int i = 0;i < names2.size();i++) {
            if((allowedEditors & loop) > 0) {
                values.addElement(values2.elementAt(i));
                names.addElement(names2.elementAt(i));
            }
            loop <<= 1;
        }
        int currentIndex = values.indexOf((String)parameters.get("editor"));
        return new Integer(currentIndex);
    }

    /**
     * Indicates if the results of this class are cacheable.
     *
     * @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.
     * @return <EM>true</EM> if cacheable, <EM>false</EM> otherwise.
     */

    public boolean isCacheable(CmsObject cms, String templateFile, String elementName,
            Hashtable parameters, String templateSelector) {
        return false;
    }

    protected void preview(String previewPath, CmsRequestContext reqCont) throws CmsException {
        String servletPath = reqCont.getRequest().getServletUrl();
        try {
            reqCont.getResponse().sendCmsRedirect(previewPath);
        }
        catch(IOException e) {
            throwException("Could not send redirect preview file " + servletPath + previewPath, e);
        }
    }

    /**
     * User method to generate an URL for a preview.
     * The currently selected temporary file name will be considered.
     * <P>
     * In the editor template file, this method can be invoked by
     * <code>&lt;METHOD name="previewUrl"/&gt;</code>.
     *
     * @param cms CmsObject Object for accessing system resources.
     * @param tagcontent Unused in this special case of a user method. Can be ignored.
     * @param doc Reference to the A_CmsXmlContent object of the initiating XLM document <em>(not used here)</em>.
     * @param userObj Hashtable with parameters <em>(not used here)</em>.
     * @return String with the pics URL.
     * @throws CmsException
     */

    public Object previewUrl(CmsObject cms, String tagcontent, A_CmsXmlContent doc, Object userObj) throws CmsException {
        String servletPath = cms.getRequestContext().getRequest().getServletUrl();
        I_CmsSession session = cms.getRequestContext().getSession(true);
        String tempPath = (String)session.getValue("te_temppagefile");
        String result = servletPath + tempPath;
        return result;
    }

    /**
     * Pre-Sets the value of the body title input field.
     * This method is directly called by the content definiton.
     * @param Cms The CmsObject.
     * @param lang The language file.
     * @param parameters User parameters.
     * @return Value that is pre-set into the title field.
     * @throws CmsExeption if something goes wrong.
     */

    public String setBodyTitle(CmsObject cms, CmsXmlLanguageFile lang, Hashtable parameters) throws CmsException {
        I_CmsSession session = cms.getRequestContext().getSession(true);
        String title = (String)session.getValue("te_oldbodytitle");
        return Encoder.escapeXml(title);
    }
    
    public Object getCharset(CmsObject cms, String tagcontent, A_CmsXmlContent doc, Object userObj) {
        // Try to find property on file and all parent folders
        String prop = null;
        try {
            I_CmsSession session = cms.getRequestContext().getSession(true);
            String file = (String)session.getValue("te_file");
            prop = cms.readProperty(file, C_PROPERTY_CONTENT_ENCODING);
            while ((prop == null) && (! "".equals(file))) {
                file = file.substring(0, file.lastIndexOf("/"));
                prop = cms.readProperty(file + "/", C_PROPERTY_CONTENT_ENCODING);
            } 
        } catch (Exception e) {}
        if (prop == null) prop = OpenCms.getDefaultEncoding();
        return prop;
    }
    
    public Object setText(CmsObject cms, String tagcontent, A_CmsXmlContent doc, Object userObj) throws CmsException {
        Hashtable parameters = (Hashtable)userObj;

        String content = (String)parameters.get(C_PARA_CONTENT);
        boolean existsContentParam = (content != null && (!"".equals(content)));

        // Check the existance of the "file" parameter
        if(!existsContentParam) {
            String errorMessage = getClassName() + "No content found.";
            if(I_CmsLogChannels.C_PREPROCESSOR_IS_LOGGING && A_OpenCms.isLogging() ) {
                A_OpenCms.log(C_OPENCMS_CRITICAL, errorMessage);
            }
            content = "";
        }

        // Escape the text for including it in HTML text
        return content;
    }

    /**
     * Pre-Sets the value of the title input field.
     * This method is directly called by the content definiton.
     * @param Cms The CmsObject.
     * @param lang The language file.
     * @param parameters User parameters.
     * @return Value that is pre-set into the title field.
     * @throws CmsExeption if something goes wrong.
     */

    public String setTitle(CmsObject cms, CmsXmlLanguageFile lang,
            Hashtable parameters) throws CmsException {
        I_CmsSession session = cms.getRequestContext().getSession(true);
        String name = (String)session.getValue("te_title");
        return Encoder.escapeXml(name);
    }
}

⌨️ 快捷键说明

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