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

📄 cmsxmlcontrolfile.java

📁 cms是开源的框架
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
                + getAbsoluteFilename()
                + ".", CmsLegacyException.C_XML_TAG_MISSING);
        }
        return result;
    }

    /**
     * Gets the value of a single parameter of the master template.
     * @param parameterName Name of the requested parameter.
     * @return the parameter value
     * @throws CmsException if something goes wrong
     */
    public String getParameter(String parameterName) throws CmsException {

        return getDataValue("PARAMETER." + parameterName);
    }

    /**
     * Gets an enumeration of all parameter names of the master template.
     * @return Enumeration of all names.
     * @throws CmsException if something goes wrong
     */
    public Enumeration getParameterNames() throws CmsException {

        NodeList parameterTags = getXmlDocument().getDocumentElement().getChildNodes();
        return getNamesFromNodeList(parameterTags, "PARAMETER", false);
    }

    /**
     * Gets the template class defined in the body file.
     * @return Name of the template class.
     * @throws CmsException if something goes wrong
     */
    public String getTemplateClass() throws CmsException {

        return getDataValue("class");
    }

    /**
     * Gets the expected tagname for the XML documents of this content type.<p>
     * 
     * @return Expected XML tagname.
     */
    public String getXmlDocumentTagName() {

        return "PAGE";
    }

    /**
     * Checks if the body file contains a definition of the
     * template class name for a given subelement definition.
     * @param elementName Name of the subelement.
     * @return <code>true</code> if a definition exists, <code>false</code> otherwise.
     */
    public boolean isElementClassDefined(String elementName) {

        return this.hasData("ELEMENTDEF." + elementName + ".CLASS");
    }

    /**
     * Checks if the body file contains a definition of the
     * template file name for a given subelement definition.
     * @param elementName Name of the subelement.
     * @return <code>true</code> if a definition exists, <code>false</code> otherwise.
     */
    public boolean isElementTemplateDefined(String elementName) {

        return this.hasData("ELEMENTDEF." + elementName + ".TEMPLATE");
    }

    /**
     * Checks if the body file contains a definition of the
     * template selector for a given subelement definition.
     * @param elementName Name of the subelement.
     * @return <code>true</code> if a definition exists, <code>false</code> otherwise.
     */
    public boolean isElementTemplSelectorDefined(String elementName) {

        return this.hasData("ELEMENTDEF." + elementName + ".TEMPLATESELECTOR");
    }

    /**
     * Sets the template class of a given subelement definition.
     * @param elementName Name of the subelement.
     * @param classname Classname to be set.
     */
    public void setElementClass(String elementName, String classname) {

        createElementDef(elementName);
        setData("ELEMENTDEF." + elementName + ".CLASS", classname);
    }

    /**
     * Set the value of a single parameter of a given subelement definition.
     * @param elementName Name of the subelement.
     * @param parameterName Name of the requested parameter.
     * @param parameterValue Value to be set
     */
    public void setElementParameter(String elementName, String parameterName, String parameterValue) {

        createElementDef(elementName);
        if (!hasData("ELEMENTDEF." + elementName + ".PARAMETER." + parameterName)) {
            Document doc = getXmlDocument();
            Element e = doc.createElement("PARAMETER");
            e.setAttribute("name", parameterName);
            e.appendChild(doc.createTextNode(parameterValue));
            setData("ELEMENTDEF." + elementName + ".PARAMETER." + parameterName, e);
        } else {
            setData("ELEMENTDEF." + elementName + ".PARAMETER." + parameterName, parameterValue);
        }
    }

    /**
     * Sets the filename of the master template file of a given subelement definition.
     * @param elementName Name of the subelement.
     * @param filename Filename to be set.
     */
    public void setElementTemplate(String elementName, String filename) {

        createElementDef(elementName);
        setData("ELEMENTDEF." + elementName + ".TEMPLATE", filename);
    }

    /**
     * Sets the filename of the master template file of a given subelement definition.
     * @param elementName Name of the subelement.
     * @param templateSelector Template selector to be set.
     */
    public void setElementTemplSelector(String elementName, String templateSelector) {

        createElementDef(elementName);
        setData("ELEMENTDEF." + elementName + ".TEMPLATESELECTOR", templateSelector);
    }

    /**
     * Sets the filename of the master template file defined in
     * the body file.
     * @param template Filename of the template file.
     */
    public void setMasterTemplate(String template) {

        setData("masterTemplate", template);
    }

    /**
     * Set the value of a single parameter of the master template.
     * @param parameterName Name of the requested parameter.
     * @param parameterValue Value to be set
     */
    public void setParameter(String parameterName, String parameterValue) {

        if (!hasData("PARAMETER." + parameterName)) {
            Document doc = getXmlDocument();
            Element e = doc.createElement("PARAMETER");
            e.setAttribute("name", parameterName);
            e.appendChild(doc.createTextNode(parameterValue));
            setData("PARAMETER." + parameterName, e);
        } else {
            setData("PARAMETER." + parameterName, parameterValue);
        }
    }

    /**
     * Set the template class used for the master Template.<p>
     * 
     * @param templateClass Name of the template class.
     */
    public void setTemplateClass(String templateClass) {

        setData("class", templateClass);
    }

    /**
     * Validates a given body path.<p>
     * 
     * After a folder is moved or renamed, the XML control files still contain the old body path.
     * This method first tries to read the given body path from the XML control file. If this path
     * is invalid, it tries to read the body file in "/system/bodies/" + current folder + filename.
     * 
     * @param cms the user's CmsObject instance
     * @param bodyPath the body path that gets validated
     * @param page the page of which the body path gets validated
     * @return the original body path if it valid, or "/system/bodies/" + current folder + filename
     */
    public String validateBodyPath(CmsObject cms, String bodyPath, CmsResource page) {

        String validatedBodyPath = null;

        if (bodyPath == null || "".equals(bodyPath)) {
            return bodyPath;
        }

        try {
            cms.readResource(bodyPath, CmsResourceFilter.ALL);
            validatedBodyPath = bodyPath;
        } catch (CmsException e) {
            if ((e instanceof CmsLegacyException)
                && (((CmsLegacyException)e).getType() == CmsLegacyException.C_NOT_FOUND)) {

                String defaultBodyPath = CmsCompatibleCheck.VFS_PATH_BODIES
                    + CmsResource.getParentFolder(cms.getSitePath(page)).substring(1)
                    + page.getName();
                try {
                    cms.readResource(defaultBodyPath, CmsResourceFilter.ALL);
                    validatedBodyPath = defaultBodyPath;
                    setElementTemplate(CmsXmlTemplate.C_BODY_ELEMENT, validatedBodyPath);
                } catch (CmsException e1) {
                    validatedBodyPath = null;
                }
            }
        }

        return validatedBodyPath;
    }

    /**
     * Used for setting element definition values.
     * Checks if the requested element definition already exists.
     * If so, nothing will happen. If not, a corresponding section
     * will be created using a hierarchical datablock tag
     * <code>&lt;ELEMENTDEF name="..."/&gt;</code>
     *
     * @param name Name of the element definition section.
     */
    private void createElementDef(String name) {

        if (!hasData("ELEMENTDEF." + name)) {
            Document doc = getXmlDocument();
            Element e = doc.createElement("ELEMENTDEF");
            e.setAttribute("name", name);
            setData("elementdef." + name, e);
        }
    }

    /**
     * Internal utility method to extract the values of the "name" attribute
     * from defined nodes of a given nodelist.
     * @param nl NodeList to extract.
     * @param tag Name of the tag whose "name" attribute should be extracted
     * @param unnamedAllowed Indicates if unnamed tags are allowed or an exception should
     * be thrown.
     * @return Enumeration of all "name" attributes.
     * @throws CmsException
     */
    private Enumeration getNamesFromNodeList(NodeList nl, String tag, boolean unnamedAllowed) throws CmsException {

        int numElements = nl.getLength();
        Vector collectNames = new Vector();
        for (int i = 0; i < numElements; i++) {
            Node n = nl.item(i);
            if (n.getNodeType() == Node.ELEMENT_NODE && n.getNodeName().toLowerCase().equals(tag.toLowerCase())) {
                String name = ((Element)n).getAttribute("name");
                if (name == null || "".equals(name)) {

                    // unnamed element found.
                    if (unnamedAllowed) {
                        name = "(default)";
                    } else {
                        if (CmsLog.getLog(this).isErrorEnabled()) {
                            CmsLog.getLog(this).error(
                                "Unnamed <"
                                    + n.getNodeName()
                                    + "> found in OpenCms control file "
                                    + getAbsoluteFilename());
                        }
                        throw new CmsLegacyException("Unnamed \""
                            + n.getNodeName()
                            + "\" found in OpenCms control file "
                            + getAbsoluteFilename(), CmsLegacyException.C_XML_TAG_MISSING);
                    }
                }
                collectNames.addElement(name);
            }
        }
        return collectNames.elements();
    }

}

⌨️ 快捷键说明

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