📄 outputformat.java
字号:
/* * Copyright 2001 (C) MetaStuff, Ltd. All Rights Reserved. * * This software is open source. * See the bottom of this file for the licence. * * $Id: OutputFormat.java,v 1.9 2002/05/20 08:14:16 jstrachan Exp $ */package org.dom4j.io;/** <p><code>OutputFormat</code> represents the format configuration * used by {@link XMLWriter} and its base classes to format the XML output * * @author <a href="mailto:james.strachan@metastuff.com">James Strachan</a> * @version $Revision: 1.9 $ */public class OutputFormat implements Cloneable { /** standard value to indent by, if we are indenting **/ protected static final String STANDARD_INDENT = " "; /** Whether or not to suppress the XML declaration - default is <code>false</code> */ private boolean suppressDeclaration = false; /** The encoding format */ private String encoding = "UTF-8"; /** Whether or not to output the encoding in the XML declaration - default is <code>false</code> */ private boolean omitEncoding = false; /** The default indent is no spaces (as original document) */ private String indent = null; /** Whether or not to expand empty elements to <tagName></tagName> - default is <code>false</code> */ private boolean expandEmptyElements = false; /** The default new line flag, set to do new lines only as in original document */ private boolean newlines = false; /** New line separator */ private String lineSeparator = "\n"; /** should we preserve whitespace or not in text nodes? */ private boolean trimText = false; /** pad string-element boundaries with whitespace **/ private boolean padText = false; /** Whether or not to use XHTML standard. */ private boolean doXHTML = false; /** Controls when to output a line.separtor every so many tags in case of no lines and total text trimming.*/ private int newLineAfterNTags = 0; //zero means don't bother. /** Creates an <code>OutputFormat</code> with * no additional whitespace (indent or new lines) added. * The whitespace from the element text content is fully preserved. */ public OutputFormat() { } /** Creates an <code>OutputFormat</code> with the given indent added but * no new lines added. All whitespace from element text will be included. * * @param indent is the indent string to be used for indentation * (usually a number of spaces). */ public OutputFormat(String indent) { this.indent = indent; } /** Creates an <code>OutputFormat</code> with the given indent added * with optional newlines between the Elements. * All whitespace from element text will be included. * * @param indent is the indent string to be used for indentation * (usually a number of spaces). * @param newlines whether new lines are added to layout the */ public OutputFormat(String indent, boolean newlines) { this.indent = indent; this.newlines = newlines; } /** Creates an <code>OutputFormat</code> with the given indent added * with optional newlines between the Elements * and the given encoding format. * * @param indent is the indent string to be used for indentation * (usually a number of spaces). * @param newlines whether new lines are added to layout the * @param encoding is the text encoding to use for writing the XML */ public OutputFormat(String indent, boolean newlines, String encoding) { this.indent = indent; this.newlines = newlines; this.encoding = encoding; } public String getLineSeparator() { return lineSeparator; } /** <p>This will set the new-line separator. The default is * <code>\n</code>. Note that if the "newlines" property is * false, this value is irrelevant. To make it output the system * default line ending string, call * <code>setLineSeparator(System.getProperty("line.separator"))</code> * </p> * @see #setNewlines(boolean) * @param separator <code>String</code> line separator to use. */ public void setLineSeparator(String separator) { lineSeparator = separator; } public boolean isNewlines() { return newlines; } /** @see #setLineSeparator(String) * @param newlines <code>true</code> indicates new lines should be * printed, else new lines are ignored (compacted). */ public void setNewlines(boolean newlines) { this.newlines = newlines; } public String getEncoding() { return encoding; } /** @param encoding encoding format */ public void setEncoding(String encoding) { this.encoding = encoding; } public boolean isOmitEncoding() { return omitEncoding; } /** <p> This will set whether the XML declaration * (<code><?xml version="1.0" encoding="UTF-8"?></code>) * includes the encoding of the document. * It is common to suppress this in protocols such as WML and SOAP.</p> * * @param omitEncoding <code>boolean</code> indicating whether or not * the XML declaration should indicate the document encoding. */ public void setOmitEncoding(boolean omitEncoding) { this.omitEncoding = omitEncoding; } /** <p> This will set whether the XML declaration * (<code><?xml version="1.0" encoding="UTF-8"?></code>) * is included or not. * It is common to suppress this in protocols such as WML and SOAP.</p> * * @param suppressDeclaration <code>boolean</code> indicating whether or not * the XML declaration should be suppressed. */ public void setSuppressDeclaration(boolean suppressDeclaration) { this.suppressDeclaration = suppressDeclaration; } /** @return true if the output of the XML declaration * (<code><?xml version="1.0"?></code>) should be suppressed else false. */ public boolean isSuppressDeclaration() { return suppressDeclaration; } public boolean isExpandEmptyElements() { return expandEmptyElements; } /** <p>This will set whether empty elements are expanded from * <code><tagName></code> to * <code><tagName></tagName></code>.</p> * * @param expandEmptyElements <code>boolean</code> indicating whether or not * empty elements should be expanded. */ public void setExpandEmptyElements(boolean expandEmptyElements) { this.expandEmptyElements = expandEmptyElements; } public boolean isTrimText() { return trimText; } /** <p> This will set whether the text is output verbatim (false) * or with whitespace stripped as per <code>{@link * org.dom4j.Element#getTextTrim()}</code>.<p> * * <p>Default: false </p> * * @param trimText <code>boolean</code> true=>trim the whitespace, false=>use 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). *
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -