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

📄 a_cmsxmlcontent.java

📁 内容管理
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
                            }
                        }
                    }
                }
            }
        }
        return result.toString();
    }

    /**
     * Looks up a user defined method requested by a "METHOD" tag.
     * The method is searched in the Object callingObject.
     * @param methodName Name of the user method
     * @param callingObject Object that requested the processing of the XML document
     * @return user method
     * @throws NoSuchMethodException
     */
    private Method getUserMethod(String methodName, Object callingObject) throws NoSuchMethodException {
        if (methodName == null || "".equals(methodName)) {

            // no valid user method name
            throw (new NoSuchMethodException("method name is null or empty"));
        }
        return callingObject.getClass().getMethod(methodName, C_PARAMTYPES_USER_METHODS);
    }

    /**
     * Gets the XML parsed content of this template file as a DOM document.
     * <P>
     * <em>WARNING: The returned value is the original DOM document, not a clone.
     * Any changes will take effect to the behaviour of this class.
     * Especially datablocks are concerned by this!</em>
     *
     * @return the content of this template file.
     */
    protected Document getXmlDocument() {
        return m_content;
    }

    /**
     * This method should be implemented by every extending class.
     * It returns the name of the XML document tag to scan for.
     * @return name of the XML document tag.
     */
    abstract public String getXmlDocumentTagName();

    /**
     * Gets the currently used XML Parser.
     * @return currently used parser.
     */
    public static I_CmsXmlParser getXmlParser() {
        return parser;
    }

    /**
     * Prints the XML parsed content to a String
     * @return String with XML content
     */
    public String getXmlText() {
        StringWriter writer = new StringWriter();
        getXmlText(writer);
        return writer.toString();
    }

    /**
     * Prints the XML parsed content of this template file
     * to the given Writer.
     *
     * @param out Writer to print to.
     */
    public void getXmlText(Writer out) {
        parser.getXmlText(m_content, out);
    }

    /**
     * Prints the XML parsed content of the given Node and
     * its subnodes to the given Writer.
     *
     * @param out Writer to print to.
     * @param n Node that should be printed.
     */
    public void getXmlText(Writer out, Node n) {
        Document tempDoc = (Document) m_content.cloneNode(false);
        tempDoc.appendChild(parser.importNode(tempDoc, n));
        parser.getXmlText(tempDoc, out);
    }

    public void getXmlText(OutputStream out) {
        parser.getXmlText(m_content, out, m_newEncoding);
    }

    public void getXmlText(OutputStream out, Node n) {
        Document tempDoc = (Document) m_content.cloneNode(false);
        tempDoc.appendChild(parser.importNode(tempDoc, n));
        parser.getXmlText(tempDoc, out, m_newEncoding);
    }

    /**
     * Prints the XML parsed content of a given node and
     * its subnodes to a String
     * @param n Node that should be printed.
     * @return String with XML content
     */
    public String getXmlText(Node n) {
        StringWriter writer = new StringWriter();
        getXmlText(writer, n);
        return writer.toString();
    }

    /**
     * This method is just a hack so that the Eclise IDE will not show the methods listed here 
     * as warnings when the "unused private methods" option is selected, 
     * since they are called only using reclection API.
     * Do not use this method. 
     * 
     * @throws CmsException 
     */
    protected void callAllUncalledMethodsSoThatEclipseDoesntComplainAboutThem() throws CmsException {
        this.handleDataTag(null, null, null);
        this.handleIncludeTag(null, null, null);
        this.handleLinkTag(null, null, null);
        this.handleMethodTag(null, null, null);
        this.handleMethodTag(null, null, null);
        this.handleMethodTagForSure(null, null, null);
        this.handleProcessTag(null, null, null);
        this.replaceTagByComment(null, null, null);
    }

    /**
     * Handling of "DATA" tags and unknown tags.
     * A reference to each data tag ist stored in an internal hashtable with
     * the name of the datablock as key.
     * Nested datablocks are stored with names like outername.innername
     *
     * @param n XML element containing the <code>&lt;DATA&gt;</code> tag.
     * @param callingObject Reference to the object requesting the node processing.
     * @param userObj Customizable user object that will be passed through to handling and user methods.
     */
    private void handleDataTag(Element n, Object callingObject, Object userObj) {
        String blockname;
        String bestFit = null;
        String parentname = null;
        Node parent = n.getParentNode();
        while (parent != null && parent.getNodeType() == Node.ELEMENT_NODE) {

            // check if this datablock is part of a datablock

            // hierarchy like 'language.de.btn_yes'

            // look for the best fitting hierarchy name part, too
            if (parent.getNodeName().equals("DATA")) {
                blockname = ((Element) parent).getAttribute("name");
            }
            else {
                blockname = parent.getNodeName();
                String secondName = ((Element) parent).getAttribute("name");
                if (!"".equals(secondName)) {
                    blockname = blockname + "." + secondName;
                }
            }
            blockname = blockname.toLowerCase();
            if (parentname == null) {
                parentname = blockname;
            }
            else {
                parentname = blockname + "." + parentname;
            }
            if (m_blocks.containsKey(parentname)) {
                bestFit = parentname;
            }
            parent = parent.getParentNode();
        }

        // bestFit now contains the best fitting name part

        // next, look for the tag name (the part behind the last ".")
        if (n.getNodeName().equals("DATA")) {
            blockname = n.getAttribute("name");
        }
        else {
            blockname = n.getNodeName();
            String secondName = n.getAttribute("name");
            if (!"".equals(secondName)) {
                blockname = blockname + "." + secondName;
            }
        }
        blockname = blockname.toLowerCase();

        // now we can build the complete datablock name
        if (bestFit != null) {
            blockname = bestFit + "." + blockname;
        }
        if (I_CmsLogChannels.C_PREPROCESSOR_IS_LOGGING && A_OpenCms.isLogging() && C_DEBUG) {
            A_OpenCms.log(C_OPENCMS_DEBUG, "Reading datablock " + blockname);
        }

        // finally we cat put the new datablock into the hashtable
        m_blocks.put(blockname, n);

        //return null;
    }

    /**
     * Handling of "INCLUDE" tags.
     * @param n XML element containing the <code>&lt;INCLUDE&gt;</code> tag.
     * @param callingObject Reference to the object requesting the node processing.
     * @param userObj Customizable user object that will be passed through to handling and user methods.
     */
    private Object handleIncludeTag(Element n, Object callingObject, Object userObj) throws CmsException {
        A_CmsXmlContent include = null;
        String tagcontent = getTagValue(n);
        include = readIncludeFile(tagcontent);
        return include.getXmlDocument().getDocumentElement().getChildNodes();
    }

    /**
     * Handling of "LINK" tags.
     * @param n XML element containing the <code>&lt;LINK&gt;</code> tag.
     * @param callingObject Reference to the object requesting the node processing.
     * @param userObj Customizable user object that will be passed through to handling and user methods.
     */
    private Object handleLinkTag(Element n, Object callingObject, Object userObj) throws CmsException {
        // get the string and call the getLinkSubstitution method
        Element dBlock = (Element) n.cloneNode(true);
        processNode(dBlock, m_mainProcessTags, null, callingObject, userObj, null);
        String link = getTagValue(dBlock);
        return m_cms.getLinkSubstitution(link);
    }

    /**
     * Handling of the "METHOD name=..." tags.
     * Name attribute and value of the element are read and the user method
     * 'name' is invoked with the element value as parameter.
     *
     * @param n XML element containing the <code>&lt;METHOD&gt;</code> tag.
     * @param callingObject Reference to the object requesting the node processing.
     * @param userObj Customizable user object that will be passed through to handling and user methods.
     * @return Object returned by the user method
     * @throws CmsException
     */
    private Object handleMethodTag(Element n, Object callingObject, Object userObj) throws CmsException {
        processNode(n, m_mainProcessTags, null, callingObject, userObj);
        String tagcontent = getTagValue(n);
        String method = n.getAttribute("name");
        Object result = null;
        try {
            result = callUserMethod(method, tagcontent, callingObject, userObj, false);
        }
        catch (Throwable e1) {
            if (e1 instanceof CmsException) {
                throw (CmsException) e1;
            }
            else {
                throwException("handleMethodTag() received an exception from callUserMethod() while calling \"" + method + "\" requested by class " + callingObject.getClass().getName() + ": " + e1);
            }
        }
        return result;
    }

    /**
     * Handling of the "METHOD name=..." tags.
     * In contrast to the method handleMethodTag this method resolves
     * every method even if it has it own CacheDirectives. It is used only for
     * getProcessedDataValue.
     * Name attribute and value of the element are read and the user method
     * 'name' is invoked with the element value as parameter.
     *
     * @param n XML element containing the <code>&lt;METHOD&gt;</code> tag.
     * @param callingObject Reference to the object requesting the node processing.
     * @param userObj Customizable user object that will be passed through to handling and user methods.
     * @return Object returned by the user method
     * @throws CmsException
     */
    private Object handleMethodTagForSure(Element n, Object callingObject, Object userObj) throws CmsException {
        processNode(n, m_mainProcessTags, null, callingObject, userObj);
        String tagcontent = getTagValue(n);
        String method = n.getAttribute("name");
        Object result = null;
        try {
            result = callUserMethod(method, tagcontent, callingObject, userObj, true);
        }
        catch (Throwable e1) {
            if (e1 instanceof CmsException) {
                throw (CmsException) e1;
            }
            else {
                throwException("handleMethodTagForSure() received an exception from callUserMethod() while calling \"" + method + "\" requested by class " + callingObject.getClass().getName() + ": " + e1);
            }
        }
        return result;
    }

    /**
     * Handling of the "PROCESS" tags.
     * Looks up the requested datablocks in the internal hashtable and
     * returns its subnodes.
     *
     * @param n XML element containing the <code>&lt;PROCESS&gt;</code> tag.
     * @param callingObject Reference to the object requesting the node processing.
     * @param userObj Customizable user object that will be passed through to handling and user methods.
     */
    private Object handleProcessTag(Element n, Object callingObject, Object userObj) {
        String blockname = getTagValue(n).toLowerCase();
        Element datablock = null;
        if (I_CmsLogChannels.C_PREPROCESSOR_IS_LOGGING && A_OpenCms.isLogging() && C_DEBUG) {
            A_OpenCms.log(C_OPENCMS_DEBUG, getClassName() + "handleProcessTag() started. Request for datablock \"" + blockname + "\".");

⌨️ 快捷键说明

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