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

📄 cmsxmltemplatefile.java

📁 内容管理
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
        int endOpeningBodyTag = xmlString.indexOf(">", endOpeningDocTag + 1) + 1;
        int startClosingDocTag = xmlString.lastIndexOf("<");
        int startClosingBodyTag = xmlString.lastIndexOf("<", startClosingDocTag - 1);
        if(startClosingBodyTag <= endOpeningBodyTag) {
            xmlString = "";
        }else {
            xmlString = xmlString.substring(endOpeningBodyTag, startClosingBodyTag);
            xmlString = xmlString.trim();
        }
        if(html) {
            int cdataStart = xmlString.indexOf("<![CDATA[");
            int currentPos = 0;
            int loop = 0;
            result.append("<HTML>\n<HEAD>\n");
            result.append("<link rel=stylesheet type=\"text/css\" href=\"" + style + "\">\n");
            result.append("</HEAD>\n");
            result.append("<BASE href=\"");
            I_CmsRequest req = m_cms.getRequestContext().getRequest();
            result.append(req.getScheme() + "://" + req.getServerName() + ":" + req.getServerPort() + req.getServletUrl() + (String)parameters.get("file"));
            result.append("\"></BASE>");
            result.append("<BODY " + getProcessedDataValue("bodytag", callingObject, parameters) + ">\n");
            while(cdataStart != -1) {
                String tempString = xmlString.substring(currentPos, cdataStart);
                tempString = replaceBack(tempString);
                //result.append(xmlString.substring(currentPos, cdataStart).replace('<', '[').replace('>', ']'));
                result.append(tempString);
                result.append((String)cdatas.elementAt(loop++));
                cdataStart = xmlString.indexOf("<![CDATA[", cdataStart + 1);
                currentPos = xmlString.indexOf("]]>", currentPos + 1) + 3;
            }
            String tempString = xmlString.substring(currentPos);
            tempString = replaceBack(tempString);
            //result.append(xmlString.substring(currentPos).replace('<', '[').replace('>', ']'));
            result.append(tempString);
            result.append("\n</BODY>\n</HTML>");
            xmlString = result.toString();
        }else {
            // We are in text mode.
            // Check, if there is any content in this body.
            // Otherwise, set empty CDATA blocks.
            if(xmlString.trim().equals("")) {
                xmlString = "<![CDATA[\n]]>";
            }
        }
        return xmlString;
    }

    /**
     * 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 Vector 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 = (Node)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(I_CmsLogChannels.C_PREPROCESSOR_IS_LOGGING && A_OpenCms.isLogging() ) {
                            A_OpenCms.log(C_OPENCMS_CRITICAL, "[CmsXmlControlFile] unnamed <" + n.getNodeName() + "> found in OpenCms control file " + getAbsoluteFilename() + ".");
                        }
                        throw new CmsException("Unnamed \"" + n.getNodeName() + "\" found in OpenCms control file " + getAbsoluteFilename() + ".", CmsException.C_XML_TAG_MISSING);
                    }
                }
                collectNames.addElement(name);
            }
        }
        return collectNames;
    }

    /**
     * Gets the value of a single parameter of a given subelement definition.
     * @param elementName Name of the subelement.
     * @param parameterName Name of the requested parameter.
     */
    public String getParameter(String elementName, String parameterName) throws CmsException {
        return getDataValue("ELEMENTDEF." + elementName + ".PARAMETER." + parameterName);
    }

    /**
     * Gets an enumeration of all parameter names of a given subelement definition.
     * @param elementName Name of the subelement.
     * @return Vector of all names.
     * @throws CmsException
     */
    public Vector getParameterNames(String elementName) throws CmsException {
        if(hasData("elementdef." + elementName)) {
            Element elementDefinition = getData("elementdef." + elementName);
            NodeList parameterTags = elementDefinition.getChildNodes();
            return getNamesFromNodeList(parameterTags, "PARAMETER", false);
        }
        else {
            return null;
        }
    }

    /**
     * Get a hashtable containing all parameters and thies values of a given subelement definition.
     * @param elementName Name of the subelement.
     * @return Enumeration of all names.
     * @throws CmsException
     */
    public Hashtable getParameters(String elementName) throws CmsException {
        Hashtable result = new Hashtable();
        if(hasData("elementdef." + elementName)) {
            Element elementDefinition = getData("elementdef." + elementName);
            NodeList parameterTags = elementDefinition.getChildNodes();

            int numElements = parameterTags.getLength();
            for(int i = 0;i < numElements;i++) {
                Node n = (Node)parameterTags.item(i);
                if(n.getNodeType() == Node.ELEMENT_NODE && n.getNodeName().toLowerCase().equals("parameter")) {
                    String name = ((Element)n).getAttribute("name");
                    if(name != null && !"".equals(name)) {
                        result.put(name, getTagValue((Element)n));
                    }
                }
            }
        }
        return result;
    }

    /**
     * Gets a processed datablock from the datablock hashtable.
     *
     * @param tag Key for the datablocks hashtable.
     * @return Processed datablock for the given key.
     * @throws CmsException
     */
    public Element getProcessedData(String tag) throws CmsException {
        return super.getProcessedData(tag);
    }

    /**
     * Gets a processed datablock from the datablock hashtable.
     *
     * @param tag Key for the datablocks hashtable.
     * @param callingObject Object that should be used to look up user methods.
     * @return Processed datablock for the given key.
     * @throws CmsException
     */
    public Element getProcessedData(String tag, Object callingObject) throws CmsException {
        return super.getProcessedData(tag, callingObject);
    }

    /**
     * Gets a processed datablock from the datablock hashtable.
     * <P>
     * The userObj Object is passed to all called user methods.
     * By using this, the initiating class can pass customized data to its methods.
     *
     * @param tag Key for the datablocks hashtable.
     * @param callingObject Object that should be used to look up user methods.
     * @param userObj any object that should be passed to user methods
     * @return Processed datablock for the given key.
     * @throws CmsException
     */
    public Element getProcessedData(String tag, Object callingObject, Object userObj) throws CmsException {
        return super.getProcessedData(tag, callingObject, userObj);
    }

    /**
     * Gets the text and CDATA content of a processed datablock from the
     * datablock hashtable.
     *
     * @param tag Key for the datablocks hashtable.
     * @return Processed datablock for the given key.
     * @throws CmsException
     */
    public String getProcessedDataValue(String tag) throws CmsException {
        return super.getProcessedDataValue(tag);
    }

    /**
     * Gets the text and CDATA content of a processed datablock from the
     * datablock hashtable.
     *
     * @param tag Key for the datablocks hashtable.
     * @param callingObject Object that should be used to look up user methods.
     * @return Processed datablock for the given key.
     * @throws CmsException
     */
    public String getProcessedDataValue(String tag, Object callingObject) throws CmsException {
        return super.getProcessedDataValue(tag, callingObject);
    }

    /**
     * Gets the text and CDATA content of a processed datablock from the
     * datablock hashtable.
     * <P>
     * The userObj Object is passed to all called user methods.
     * By using this, the initiating class can pass customized data to its methods.
     *
     * @param tag Key for the datablocks hashtable.
     * @param callingObject Object that should be used to look up user methods.
     * @param userObj any object that should be passed to user methods
     * @return Processed datablock for the given key.
     * @throws CmsException
     */
    public String getProcessedDataValue(String tag, Object callingObject, Object userObj) throws CmsException {
        return super.getProcessedDataValue(tag, callingObject, userObj);
    }

    /**
     * Gets the text and CDATA content of a processed datablock from the
     * datablock hashtable. An eventually given output stream is user for streaming
     * the generated result directly to the response output stream while processing.
     * <P>
     * The userObj Object is passed to all called user methods.
     * By using this, the initiating class can pass customized data to its methods.
     *
     * @param tag Key for the datablocks hashtable.
     * @param callingObject Object that should be used to look up user methods.
     * @param userObj any object that should be passed to user methods
     * @param stream OutputStream that may be used for directly streaming the results or null.
     * @return Processed datablock for the given key.
     * @throws CmsException
     */
    public String getProcessedDataValue(String tag, Object callingObject, Object userObj, OutputStream stream) throws CmsException {
        return super.getProcessedDataValue(tag, callingObject, userObj, stream);
    }

    /**
     * Gets the processed data of the default <code>&lt;TEMPLATE&gt;</code> section of
     * this workplace template file.
     * <P>
     * The correct datablock name for the template datablock will be taken
     * from <code>getTemplateDatablockName</code>.
     *
     * @param callingObject reference to the calling object. Used to look up user methods while processing.
     * @param parameters hashtable containing all user parameters.
     * @return Processed template data.
     * @throws CmsException
     */
    public String getProcessedTemplateContent(Object callingObject, Hashtable parameters) throws CmsException {
        return getProcessedTemplateContent(callingObject, parameters, null);
    }

    /**
     * Gets the processed data of the appropriate <code>&lt;TEMPLATE&gt;</code> section of
     * this workplace template file.
     * <P>
     * The correct datablock name for the template datablock will be taken
     * from <code>getTemplateDatablockName</code>.
     *
     * @param callingObject reference to the calling object. Used to look up user methods while processing.
     * @param parameters hashtable containing all user parameters.
     * @param templateSelector Name of the template section or null if the default section is requested.
     * @return Processed template data.
     * @throws CmsException
     */
    public String getProcessedTemplateContent(Object callingObject, Hashtable parameters, String templateSelector) throws CmsException {
        OutputStream os = null;

        if(m_cms.getRequestContext().isStreaming()) {
            if(I_CmsLogChannels.C_PREPROCESSOR_IS_LOGGING && A_OpenCms.isLogging() ) {
                A_OpenCms.log(C_OPENCMS_STREAMING, getClassName() + "Entering streaming mode for file: " + getAbsoluteFilename());
            }
            try {
                os = m_cms.getRequestContext().getResponse().getOutputStream();
            } catch (Exception e) {
                throw new CmsException(CmsException.C_UNKNOWN_EXCEPTION, e);
            }
        } else {
            if(I_CmsLogChannels.C_PREPROCESSOR_IS_LOGGING && A_OpenCms.isLogging() ) {

⌨️ 快捷键说明

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