📄 outputformat.java
字号:
* text verbatim
*/
public void setTrimText(boolean trimText) {
this.trimText = trimText;
}
public boolean isPadText() {
return padText;
}
/**
* <p>
* Ensure that text immediately preceded by or followed by an element will
* be "padded" with a single space. This is used to allow make
* browser-friendly HTML, avoiding trimText's transformation of, e.g.,
* <code>The quick <b>brown</b> fox</code> into <code>The
* quick<b>brown</b>fox</code>
* (the latter will run the three separate words together into a single
* word). This setting is not too useful if you haven't also called
* {@link #setTrimText}.
* </p>
*
* <p>
* The padding string will only be added if the text itself starts or ends
* with some whitespace characters.
* </p>
*
* <p>
* Default: false
* </p>
*
* @param padText
* <code>boolean</code> if true, pad string-element boundaries
*/
public void setPadText(boolean padText) {
this.padText = padText;
}
public String getIndent() {
return indent;
}
/**
* <p>
* This will set the indent <code>String</code> to use; this is usually a
* <code>String</code> of empty spaces. If you pass null, or the empty
* string (""), then no indentation will happen.
* </p>
* Default: none (null)
*
* @param indent
* <code>String</code> to use for indentation.
*/
public void setIndent(String indent) {
// nullify empty string to void unnecessary indentation code
if ((indent != null) && (indent.length() <= 0)) {
indent = null;
}
this.indent = indent;
}
/**
* Set the indent on or off. If setting on, will use the value of
* STANDARD_INDENT, which is usually two spaces.
*
* @param doIndent
* if true, set indenting on; if false, set indenting off
*/
public void setIndent(boolean doIndent) {
if (doIndent) {
this.indent = STANDARD_INDENT;
} else {
this.indent = null;
}
}
/**
* <p>
* This will set the indent <code>String</code>'s size; an indentSize of
* 4 would result in the indention being equivalent to the
* <code>String</code> " " (four space characters).
* </p>
*
* @param indentSize
* <code>int</code> number of spaces in indentation.
*/
public void setIndentSize(int indentSize) {
StringBuffer indentBuffer = new StringBuffer();
for (int i = 0; i < indentSize; i++) {
indentBuffer.append(" ");
}
this.indent = indentBuffer.toString();
}
/**
* <p>
* Whether or not to use the XHTML standard: like HTML but passes an XML
* parser with real, closed tags. Also, XHTML CDATA sections will be output
* with the CDATA delimiters: ( " <b><![CDATA[ </b>" and "
* <b>]]> </b>" ) otherwise, the class HTMLWriter will output the
* CDATA text, but not the delimiters.
* </p>
*
* <p>
* Default is <code>false</code>
* </p>
*
* @return DOCUMENT ME!
*/
public boolean isXHTML() {
return doXHTML;
}
/**
* <p>
* This will set whether or not to use the XHTML standard: like HTML but
* passes an XML parser with real, closed tags. Also, XHTML CDATA sections
* will be output with the CDATA delimiters: ( " <b><[CDATA[
* </b>" and " <b>]]< </b>) otherwise, the class HTMLWriter
* will output the CDATA text, but not the delimiters.
* </p>
*
* <p>
* Default: false
* </p>
*
* @param xhtml
* <code>boolean</code> true=>conform to XHTML, false=>conform
* to HTML, can have unclosed tags, etc.
*/
public void setXHTML(boolean xhtml) {
doXHTML = xhtml;
}
public int getNewLineAfterNTags() {
return newLineAfterNTags;
}
/**
* Controls output of a line.separator every tagCount tags when isNewlines
* is false. If tagCount equals zero, it means don't do anything special. If
* greater than zero, then a line.separator will be output after tagCount
* tags have been output. Used when you would like to squeeze the html as
* much as possible, but some browsers don't like really long lines. A tag
* count of 10 would produce a line.separator in the output after 10 close
* tags (including single tags).
*
* @param tagCount
* DOCUMENT ME!
*/
public void setNewLineAfterNTags(int tagCount) {
newLineAfterNTags = tagCount;
}
public char getAttributeQuoteCharacter() {
return attributeQuoteChar;
}
/**
* Sets the character used to quote attribute values. The specified
* character must be a valid XML attribute quote character, otherwise an
* <code>IllegalArgumentException</code> will be thrown.
*
* @param quoteChar
* The character to use when quoting attribute values.
*
* @throws IllegalArgumentException
* If the specified character is not a valid XML attribute quote
* character.
*/
public void setAttributeQuoteCharacter(char quoteChar) {
if ((quoteChar == '\'') || (quoteChar == '"')) {
attributeQuoteChar = quoteChar;
} else {
throw new IllegalArgumentException("Invalid attribute quote "
+ "character (" + quoteChar + ")");
}
}
/**
* Parses command line arguments of the form <code>-omitEncoding
* -indentSize 3 -newlines -trimText</code>
*
* @param args
* is the array of command line arguments
* @param i
* is the index in args to start parsing options
*
* @return the index of first parameter that we didn't understand
*/
public int parseOptions(String[] args, int i) {
for (int size = args.length; i < size; i++) {
if (args[i].equals("-suppressDeclaration")) {
setSuppressDeclaration(true);
} else if (args[i].equals("-omitEncoding")) {
setOmitEncoding(true);
} else if (args[i].equals("-indent")) {
setIndent(args[++i]);
} else if (args[i].equals("-indentSize")) {
setIndentSize(Integer.parseInt(args[++i]));
} else if (args[i].startsWith("-expandEmpty")) {
setExpandEmptyElements(true);
} else if (args[i].equals("-encoding")) {
setEncoding(args[++i]);
} else if (args[i].equals("-newlines")) {
setNewlines(true);
} else if (args[i].equals("-lineSeparator")) {
setLineSeparator(args[++i]);
} else if (args[i].equals("-trimText")) {
setTrimText(true);
} else if (args[i].equals("-padText")) {
setPadText(true);
} else if (args[i].startsWith("-xhtml")) {
setXHTML(true);
} else {
return i;
}
}
return i;
}
/**
* A static helper method to create the default pretty printing format. This
* format consists of an indent of 2 spaces, newlines after each element and
* all other whitespace trimmed, and XMTML is false.
*
* @return DOCUMENT ME!
*/
public static OutputFormat createPrettyPrint() {
OutputFormat format = new OutputFormat();
format.setIndentSize(2);
format.setNewlines(true);
format.setTrimText(true);
format.setPadText(true);
return format;
}
/**
* A static helper method to create the default compact format. This format
* does not have any indentation or newlines after an alement and all other
* whitespace trimmed
*
* @return DOCUMENT ME!
*/
public static OutputFormat createCompactFormat() {
OutputFormat format = new OutputFormat();
format.setIndent(false);
format.setNewlines(false);
format.setTrimText(true);
return format;
}
}
/*
* Redistribution and use of this software and associated documentation
* ("Software"), with or without modification, are permitted provided that the
* following conditions are met:
*
* 1. Redistributions of source code must retain copyright statements and
* notices. Redistributions must also contain a copy of this document.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* 3. The name "DOM4J" must not be used to endorse or promote products derived
* from this Software without prior written permission of MetaStuff, Ltd. For
* written permission, please contact dom4j-info@metastuff.com.
*
* 4. Products derived from this Software may not be called "DOM4J" nor may
* "DOM4J" appear in their names without prior written permission of MetaStuff,
* Ltd. DOM4J is a registered trademark of MetaStuff, Ltd.
*
* 5. Due credit should be given to the DOM4J Project - http://www.dom4j.org
*
* THIS SOFTWARE IS PROVIDED BY METASTUFF, LTD. AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL METASTUFF, LTD. OR ITS CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* Copyright 2001-2005 (C) MetaStuff, Ltd. All Rights Reserved.
*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -