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

📄 althtmlwriter.java

📁 Memoranda( 从前以jNotes2而闻名) 是一个日志管理和个人项目管理工具
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
    }    /**     * Determines if the HTML.Tag associated with the     * element is a block tag.     *     * @param attr  an AttributeSet     * @return  true if tag is block tag, false otherwise.     */    protected boolean isBlockTag(AttributeSet attr) {        Object o = attr.getAttribute(StyleConstants.NameAttribute);        if (o instanceof HTML.Tag) {            HTML.Tag name = (HTML.Tag) o;            return name.isBlock();        }        return false;    }    /**     * Writes out a start tag for the element.     * Ignores all synthesized elements.     *     * @param elem   an Element     * @exception IOException on any I/O error     */    protected void startTag(Element elem) throws IOException, BadLocationException {        if (synthesizedElement(elem)) {            return;        }        // Determine the name, as an HTML.Tag.        AttributeSet attr = elem.getAttributes();        Object nameAttribute = attr.getAttribute(StyleConstants.NameAttribute);        HTML.Tag name;        if (nameAttribute instanceof HTML.Tag) {            name = (HTML.Tag) nameAttribute;        }        else {            name = null;        }        if (name == HTML.Tag.PRE) {            inPre = true;            preEndOffset = elem.getEndOffset();        }        // write out end tags for item on stack        closeOutUnwantedEmbeddedTags(attr);        if (inContent) {            writeLineSeparator();            inContent = false;            newlineOutputed = false;        }        if (completeDoc && name == HTML.Tag.BODY && !wroteHead) {            // If the head has not been output, output it and the styles.            wroteHead = true;            indent();            write("<head>");            writeLineSeparator();            incrIndent();            writeAdditionalComments();            writeLineSeparator();            if (encoding != null) {                writeLineSeparator();                write("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=" + encoding + "\">");            }            writeStyles(((HTMLDocument) getDocument()).getStyleSheet());            writeLineSeparator();            //System.out.println(getDocument().getProperty(Document.TitleProperty));            write("<title>" + getDocument().getProperty(Document.TitleProperty) + "</title>");            decrIndent();            writeLineSeparator();            indent();            write("</head>");            writeLineSeparator();        }        indent();        write('<');        write(elem.getName());        writeAttributes(attr);        write('>');        if (name != HTML.Tag.PRE) {            writeLineSeparator();        }        if (name == HTML.Tag.TEXTAREA) {            textAreaContent(elem.getAttributes());        }        else if (name == HTML.Tag.SELECT) {            selectContent(elem.getAttributes());        }      //  else if (completeDoc && name == HTML.Tag.BODY) {            // Write out the maps, which is not stored as Elements in            // the Document.            //writeMaps(((HTMLDocument)getDocument()).getMaps());      //  }        else if (name == HTML.Tag.HEAD) {            indent();            writeAdditionalComments();            if (encoding != null) {                indent();                write("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=" + encoding + "\">");            }            writeLineSeparator();            wroteHead = true;        }    }    /**     * Writes out text that is contained in a TEXTAREA form     * element.     *     * @param attr  an AttributeSet     * @exception IOException on any I/O error     * @exception BadLocationException if pos represents an invalid     *            location within the document.     */    protected void textAreaContent(AttributeSet attr) throws BadLocationException, IOException {        Document doc = (Document) attr.getAttribute(StyleConstants.ModelAttribute);        if (doc != null && doc.getLength() > 0) {            if (segment == null) {                segment = new Segment();            }            doc.getText(0, doc.getLength(), segment);            if (segment.count > 0) {                inTextArea = true;                incrIndent();                indent();                setCanWrapLines(true);                replaceEntities = true;                write(segment.array, segment.offset, segment.count);                replaceEntities = false;                setCanWrapLines(false);                writeLineSeparator();                inTextArea = false;                decrIndent();            }        }    }    /**     * Writes out text.  If a range is specified when the constructor     * is invoked, then only the appropriate range of text is written     * out.     *     * @param elem   an Element     * @exception IOException on any I/O error     * @exception BadLocationException if pos represents an invalid     *            location within the document.     */    protected void text(Element elem) throws BadLocationException, IOException {        int start = Math.max(getStartOffset(), elem.getStartOffset());        int end = Math.min(getEndOffset(), elem.getEndOffset());        if (start < end) {            if (segment == null) {                segment = new Segment();            }            getDocument().getText(start, end - start, segment);            newlineOutputed = false;            if (segment.count > 0) {                if (segment.array[segment.offset + segment.count - 1] == '\n') {                    newlineOutputed = true;                }                if (inPre && end == preEndOffset) {                    if (segment.count > 1) {                        segment.count--;                    }                    else {                        return;                    }                }                replaceEntities = true;                setCanWrapLines(!inPre);                write(segment.array, segment.offset, segment.count);                setCanWrapLines(false);                replaceEntities = false;            }        }    }    /**     * Writes out the content of the SELECT form element.     *     * @param attr the AttributeSet associated with the form element     * @exception IOException on any I/O error     */    protected void selectContent(AttributeSet attr) throws IOException {        Object model = attr.getAttribute(StyleConstants.ModelAttribute);        incrIndent();        if (model instanceof OptionListModel) {            OptionListModel listModel = (OptionListModel) model;            int size = listModel.getSize();            for (int i = 0; i < size; i++) {                Option option = (Option) listModel.getElementAt(i);                writeOption(option);            }        }        else if (model instanceof OptionComboBoxModel) {            OptionComboBoxModel comboBoxModel = (OptionComboBoxModel) model;            int size = comboBoxModel.getSize();            for (int i = 0; i < size; i++) {                Option option = (Option) comboBoxModel.getElementAt(i);                writeOption(option);            }        }        decrIndent();    }    /**     * Writes out the content of the Option form element.     * @param option  an Option     * @exception IOException on any I/O error     *     */    protected void writeOption(Option option) throws IOException {        indent();        write('<');        write("option");        // PENDING: should this be changed to check for null first?        Object value = option.getAttributes().getAttribute(HTML.Attribute.VALUE);        if (value != null) {            write(" value=" + value);        }        if (option.isSelected()) {            write(" selected");        }        write('>');        if (option.getLabel() != null) {            write(option.getLabel());        }        writeLineSeparator();    }    /**     * Writes out an end tag for the element.     *     * @param elem    an Element     * @exception IOException on any I/O error     */    protected void endTag(Element elem) throws IOException {        if (synthesizedElement(elem)) {            return;        }        if (matchNameAttribute(elem.getAttributes(), HTML.Tag.PRE)) {            inPre = false;        }        // write out end tags for item on stack        closeOutUnwantedEmbeddedTags(elem.getAttributes());        if (inContent) {            if (!newlineOutputed) {                writeLineSeparator();            }            newlineOutputed = false;            inContent = false;        }        indent();        write('<');        write('/');        write(elem.getName());        write('>');        writeLineSeparator();    }    /**     * Writes out comments.     *     * @param elem    an Element     * @exception IOException on any I/O error     * @exception BadLocationException if pos represents an invalid     *            location within the document.     */    protected void comment(Element elem) throws BadLocationException, IOException {        AttributeSet as = elem.getAttributes();        if (matchNameAttribute(as, HTML.Tag.COMMENT)) {            Object comment = as.getAttribute(HTML.Attribute.COMMENT);            if (comment instanceof String) {                writeComment((String) comment);            }            else {                writeComment(null);            }        }    }    /**     * Writes out comment string.     *     * @param string   the comment     * @exception IOException on any I/O error     * @exception BadLocationException if pos represents an invalid     *            location within the document.     */    void writeComment(String string) throws IOException {        write("<!--");        if (string != null) {            write(string);        }        write("-->");        writeLineSeparator();    }    /**     * Writes out any additional comments (comments outside of the body)     * stored under the property HTMLDocument.AdditionalComments.     */    void writeAdditionalComments() throws IOException {        Object comments = getDocument().getProperty(HTMLDocument.AdditionalComments);        if (comments == null) return;         if (comments instanceof Vector) {            Vector v = (Vector) comments;            for (int counter = 0, maxCounter = v.size(); counter < maxCounter; counter++) {                writeComment(v.elementAt(counter).toString());            }        }        //[alex] I've add the following 'else' for single comments:        else            writeComment(comments.toString());        // end add    }    /**     * Returns true if the element is a     * synthesized element.  Currently we are only testing     * for the p-implied tag.     */    protected boolean synthesizedElement(Element elem) {        if (matchNameAttribute(elem.getAttributes(), HTML.Tag.IMPLIED)) {            return true;        }        return false;    }    /**     * Returns true if the StyleConstants.NameAttribute is     * equal to the tag that is passed in as a parameter.     */    protected boolean matchNameAttribute(AttributeSet attr, HTML.Tag tag) {        Object o = attr.getAttribute(StyleConstants.NameAttribute);        if (o instanceof HTML.Tag) {            HTML.Tag name = (HTML.Tag) o;            if (name == tag) {                return true;            }        }        return false;    }    /**     * Searches for embedded tags in the AttributeSet     * and writes them out.  It also stores these tags in a vector     * so that when appropriate the corresponding end tags can be     * written out.     *     * @exception IOException on any I/O error     */    protected void writeEmbeddedTags(AttributeSet attr) throws IOException {        // translate css attributes to html        attr = convertToHTML(attr, oConvAttr);

⌨️ 快捷键说明

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