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

📄 cmshtmlconverter.java

📁 OpenCms 是一个J2EE的产品
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
                /* continue, if block is not replaced */
                if (replaceBlock == -1) {
                    /* replace end tag and discard inline tags */
                    if (replaceTag != -1) {
                        m_tagObject = (CmsHtmlConverterObjectReplaceTags)m_configuration.getReplaceTags().get(
                            replaceTag);
                        if (!m_tagObject.getInline()) {
                            String tempReplaceString = m_tagObject.getReplaceEndTag();
                            /* if parameter is used, get it from node attribute value,
                             insert it into replaceString */
                            if (!m_tagObject.getParameter().equals("")) {
                                String valueParam = m_tools.scanNodeAttrs(node, m_tagObject.getParameter());
                                tempReplaceString = m_tools.replaceString(tempReplaceString, "$parameter$", valueParam);
                            }
                            m_tempString.append(tempReplaceString);
                        }
                        /* remove temporary object from ArrayList replaceTags */
                        if (replaceTag > (m_numberReplaceTags - 1)) {
                            m_configuration.removeObjectReplaceTag(replaceTag);
                        }
                    } else {
                        /* catch inline tags and discard them */
                        if (!m_tools.checkTag(node.getNodeName(), m_configuration.getInlineTags())) {
                            m_tempString.append("</");
                            m_tempString.append(node.getNodeName());
                            m_tempString.append(">");
                            // append a "\n" to output String
                            if (m_configuration.getGlobalAddEveryLine()) {
                                // check if a "\n" can be added to output
                                boolean added = false;
                                for (int i = 0; i < m_enterTags.size(); i++) {
                                    if (!added && node.getNodeName().equalsIgnoreCase((String)m_enterTags.elementAt(i))) {
                                        m_tempString.append(m_configuration.getGlobalSuffix()
                                            + "\n"
                                            + m_configuration.getGlobalPrefix());
                                        added = true;
                                    }
                                    // if tag was found, return
                                    if (added) {
                                        return;
                                    }
                                }
                            } else {
                                // check if a "\n" can be added to output
                                boolean added = false;
                                for (int i = 0; i < m_enterTags.size(); i++) {
                                    if (!added && node.getNodeName().equalsIgnoreCase((String)m_enterTags.elementAt(i))) {
                                        m_tempString.append("\n");
                                        added = true;
                                    }
                                    // if tag was found, return
                                    if (added) {
                                        return;
                                    }
                                }
                            }
                        }
                    }
                }
            } // end of removetag
        } // end of removeblock
    }

    /**
     * Private method to transform output at end of document.<p>
     */
    private void transformEndDocument() {

        m_tempString.append(m_configuration.getGlobalSuffix());
    }

    /**
     * Private method to transform text nodes.<p>
     * 
     * @param node actual text node
     */
    private void transformTextNode(Node node) {

        String helpString = node.getNodeValue();
        /* do not scan text nodes between <script> tags! */
        if (!node.getParentNode().getNodeName().equalsIgnoreCase("script")
            && !node.getParentNode().getNodeName().equalsIgnoreCase("style")) {
            helpString = m_tools.scanChar(helpString, m_configuration.getReplaceExtendedChars());
        }
        /* replace quotationsmarks if configured */
        if (m_configuration.getEncodeQuotationmarks()) {
            helpString = m_tools.replaceString(helpString, "\"", m_configuration.getQuotationmark());
        }
        /* test if prefix and suffix have to be added every new line */
        if (m_configuration.getGlobalAddEveryLine()) {
            helpString = m_tools.replaceString(
                helpString,
                "\n",
                (m_configuration.getGlobalSuffix() + "\n" + m_configuration.getGlobalPrefix()));
        }
        m_tempString.append(helpString);
    }

    /**
     * Private method to delete empty "prefix+suffix" lines in output String.<p>
     * 
     * @param cleanString string for cleaning up
     * @return the cleaned string
     */
    private String cleanOutput(String cleanString) {

        if (m_configuration.getGlobalAddEveryLine()) {
            cleanString += "\n";
            String cutString = m_configuration.getGlobalPrefix() + m_configuration.getGlobalSuffix() + "\n";
            /* delete empty "prefix-suffix" lines if suffix and prefix are not empty */
            if (!m_configuration.getGlobalPrefix().equals("") && !m_configuration.getGlobalSuffix().equals("")) {
                cleanString = m_tools.replaceString(cleanString, cutString, "");
            }
        }
        return cleanString;
    }

    /**
     * Tests if specified tag has to be replaced and, if it is found,
     * delivers index of hit in ArrayLis.<p>
     * 
     * @param node DOM Node which might be replaced
     * @return "-1" if tag is not found, otherwise index of list with hit
     */
    private int indexReplaceTag(Node node) {

        ArrayList replaceTags = m_configuration.getReplaceTags();
        NamedNodeMap attrs = node.getAttributes();
        CmsHtmlConverterObjectReplaceTags testObject = new CmsHtmlConverterObjectReplaceTags();
        for (int index = 0; index < replaceTags.size(); index++) {
            testObject = (CmsHtmlConverterObjectReplaceTags)(replaceTags.get(index));
            // cw 09.09.2003 added general qualifier *
            if (node.getNodeName().equals(testObject.getTagName()) || "*".equals(testObject.getTagName())) {
                /* if no identifier attribute is defined, replace all nodes */
                if (testObject.getTagAttrib().equals("")) {
                    /* test if replaceStrings have to be retrieved from attributes */
                    if (testObject.getReplaceFromAttrs()) {
                        return scanTagElementAttrs(node, testObject);
                    }
                    return index;
                }
                for (int i = attrs.getLength() - 1; i >= 0; i--) {
                    if (attrs.item(i).getNodeName().equals(testObject.getTagAttrib())
                        && (attrs.item(i).getNodeValue().equals(testObject.getTagAttribValue()) || testObject.getTagAttribValue().equals(
                            ""))) {
                        /* test if replaceStrings have to be retrieved from attributes */
                        if (testObject.getReplaceFromAttrs()) {
                            return scanTagElementAttrs(node, testObject);
                        }
                        return index;
                    }
                }
            }
        }
        return -1;
    }

    /**
     * Scans node attributes and creates new CmsHtmlConverterObjectReplaceTags.<p>
     * 
     * @param node DOM node which is scanned
     * @param testObject parent replaceTag object
     * @return index of new object in ArrayList replaceTags
     */
    private int scanTagElementAttrs(Node node, CmsHtmlConverterObjectReplaceTags testObject) {

        NamedNodeMap attrs = node.getAttributes();
        String prefix = testObject.getPrefix();
        String suffix = testObject.getSuffix();
        String name = testObject.getTagName();
        String attrib = testObject.getTagAttrib();
        String attrValue = testObject.getTagAttribValue();
        String startAttribute = testObject.getStartAttribute();
        String endAttribute = testObject.getEndAttribute();
        String replaceStartTag = "";
        String replaceEndTag = "";
        String parameter = testObject.getParameter();
        String attrName = "";
        boolean replaceParamAttr = testObject.getReplaceParamAttr();
        /* scan attributes for replaceStrings */
        for (int i = 0; i < attrs.getLength(); i++) {
            attrName = attrs.item(i).getNodeName();
            if (attrName.equalsIgnoreCase(startAttribute)) {
                replaceStartTag = attrs.item(i).getNodeValue();
            }
            if (attrName.equalsIgnoreCase(endAttribute)) {
                replaceEndTag = attrs.item(i).getNodeValue();
            }
        }
        /* replace encoded brackets if defined */
        if (m_configuration.getUseBrackets()) {
            replaceStartTag = m_configuration.scanBrackets(replaceStartTag);
            replaceEndTag = m_configuration.scanBrackets(replaceEndTag);
        }
        /* add temporary object to ArrayList replaceTags */
        m_configuration.addObjectReplaceTag(
            prefix,
            name,
            attrib,
            attrValue,
            replaceStartTag,
            replaceEndTag,
            suffix,
            false,
            "",
            "",
            parameter,
            replaceParamAttr);
        return m_configuration.getReplaceTags().size() - 1;
    }

    /**
     * Tests if specified block has to be replaced and, if it is found,
     * delivers index of hit in ArrayList.<p>
     * 
     * @param node DOM Node which might be replaced
     * @return "-1" if tag is not found, otherwise index of list with hit
     */
    private int indexReplaceBlock(Node node) {

        ArrayList replaceBlocks = m_configuration.getReplaceBlocks();
        NamedNodeMap attrs = node.getAttributes();
        CmsHtmlConverterObjectReplaceBlocks testObject = new CmsHtmlConverterObjectReplaceBlocks();
        for (int index = 0; index < replaceBlocks.size(); index++) {
            testObject = (CmsHtmlConverterObjectReplaceBlocks)(replaceBlocks.get(index));
            // cw 09.09.2003 added general qualifier *
            if (node.getNodeName().equals(testObject.getTagName()) || "*".equals(testObject.getTagName())) {
                if (testObject.getTagAttrib().equals("")) {
                    /* test if replaceStrings has to be retrieved from attributes */
                    if (testObject.getReplaceFromAttrs()) {
                        return scanBlockElementAttrs(node, testObject);
                    }
                    return index;
                }
                for (int i = (attrs.getLength() - 1); i >= 0; i--) {
                    if (attrs.item(i).getNodeName().equals(testObject.getTagAttrib())
                        && (attrs.item(i).getNodeValue().equals(testObject.getTagAttribValue()) || testObject.getTagAttribValue().equals(
                            ""))) {
                        /* test if replaceString has to be retrieved from attributes */
                        if (testObject.getReplaceFromAttrs()) {
                            return scanBlockElementAttrs(node, testObject);
                        }
                        return index;
                    }
                }
            }
        }
        return -1;
    }

    /**
     * Scans node attributes and creates new CmsHtmlConverterObjectReplaceBlocks.<p>
     * 
     * @param node DOM node which is scanned
     * @param testObject parent replaceBlock object
     * @return index of new object in ArrayList replaceBlocks
     */
    private int scanBlockElementAttrs(Node node, CmsHtmlConverterObjectReplaceBlocks testObject) {

        NamedNodeMap attrs = node.getAttributes();
        String prefix = testObject.getPrefix();
        String suffix = testObject.getSuffix();
        String name = testObject.getTagName();
        String attrib = testObject.getTagAttrib();
        String attrValue = testObject.getTagAttribValue();
        String replaceString = "";
        String replaceAttribute = testObject.getReplaceAttribute();
        String attrName = "";
        String parameter = testObject.getParameter();
        /* scan attributes for replaceString */
        for (int i = 0; i < attrs.getLength(); i++) {
            attrName = attrs.item(i).getNodeName();
            if (attrName.equalsIgnoreCase(replaceAttribute)) {
                replaceString = attrs.item(i).getNodeValue();
            }
        }
        /* replace encoded brackets if defined */
        if (m_configuration.getUseBrackets()) {
            replaceString = m_configuration.scanBrackets(replaceString);
        }
        /* add temporary object to ArrayList replaceBlocks */
        m_configuration.addObjectReplaceBlock(
            prefix,
            name,
            attrib,
            attrValue,
            replaceString,
            suffix,
            false,
            "",
            parameter);
        return m_configuration.getReplaceBlocks().size() - 1;
    }
}

⌨️ 快捷键说明

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