/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/**
* {@link XMLFilterImpl} that does indentation to SAX events.
*
* @author Kohsuke Kawaguchi
*/
public IndentingXMLFilter() {
}
}
}
return lexical;
}
}
/**
* Return the current indent step.
*
* <p>Return the current indent step: each start tag will be
* indented by this number of spaces times the number of
* ancestors that the element has.</p>
*
* @return The number of spaces in each indentation step,
* or 0 or less for no indentation.
* @see #setIndentStep(int)
*
* @deprecated
* Only return the length of the indent string.
*/
public int getIndentStep ()
{
return indentStep.length();
}
/**
* Set the current indent step.
*
* @param indentStep The new indent step (0 or less for no
* indentation).
* @see #getIndentStep()
*
* @deprecated
* Should use the version that takes string.
*/
{
StringBuilder s = new StringBuilder();
setIndentStep(s.toString());
}
this.indentStep = s;
}
////////////////////////////////////////////////////////////////////
// Override methods from XMLWriter.
////////////////////////////////////////////////////////////////////
/**
* Write a start tag.
*
* <p>Each tag will begin on a new line, and will be
* indented by the current indent step times the number
* of ancestors that the element has.</p>
*
* <p>The newline and indentation will be passed on down
* the filter chain through regular characters events.</p>
*
* @param uri The element's Namespace URI.
* @param localName The element's local name.
* @param qName The element's qualified (prefixed) name.
* @param atts The element's attribute list.
* @exception org.xml.sax.SAXException If there is an error
* writing the start tag, or if a filter further
* down the chain raises an exception.
* @see XMLWriter#startElement(String, String, String,Attributes)
*/
throws SAXException {
if (depth > 0) {
writeNewLine();
}
doIndent();
depth++;
}
}
/**
* Write an end tag.
*
* <p>If the element has contained other elements, the tag
* will appear indented on a new line; otherwise, it will
* appear immediately following whatever came before.</p>
*
* <p>The newline and indentation will be passed on down
* the filter chain through regular characters events.</p>
*
* @param uri The element's Namespace URI.
* @param localName The element's local name.
* @param qName The element's qualified (prefixed) name.
* @exception org.xml.sax.SAXException If there is an error
* writing the end tag, or if a filter further
* down the chain raises an exception.
* @see XMLWriter#endElement(String, String, String)
*/
throws SAXException
{
depth--;
if (state == SEEN_ELEMENT) {
writeNewLine();
doIndent();
}
}
// /**
// * Write a empty element tag.
// *
// * <p>Each tag will appear on a new line, and will be
// * indented by the current indent step times the number
// * of ancestors that the element has.</p>
// *
// * <p>The newline and indentation will be passed on down
// * the filter chain through regular characters events.</p>
// *
// * @param uri The element's Namespace URI.
// * @param localName The element's local name.
// * @param qName The element's qualified (prefixed) name.
// * @param atts The element's attribute list.
// * @exception org.xml.sax.SAXException If there is an error
// * writing the empty tag, or if a filter further
// * down the chain raises an exception.
// * @see XMLWriter#emptyElement(String, String, String, Attributes)
// */
// public void emptyElement (String uri, String localName,
// String qName, Attributes atts)
// throws SAXException
// {
// state = SEEN_ELEMENT;
// if (depth > 0) {
// super.characters("\n");
// }
// doIndent();
// super.emptyElement(uri, localName, qName, atts);
// }
/**
* Write a sequence of characters.
*
* @param ch The characters to write.
* @param start The starting position in the array.
* @param length The number of characters to use.
* @exception org.xml.sax.SAXException If there is an error
* writing the characters, or if a filter further
* down the chain raises an exception.
* @see XMLWriter#characters(char[], int, int)
*/
throws SAXException
{
}
if (depth > 0) {
writeNewLine();
}
doIndent();
}
}
}
}
}
}
}
////////////////////////////////////////////////////////////////////
// Internal methods.
////////////////////////////////////////////////////////////////////
/**
* Print indentation for the current level.
*
* @exception org.xml.sax.SAXException If there is an error
* writing the indentation characters, or if a filter
* further down the chain raises an exception.
*/
private void doIndent ()
throws SAXException
{
if (depth > 0) {
for( int i=0; i<depth; i++ )
}
}
////////////////////////////////////////////////////////////////////
// Constants.
////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////
// Internal state.
////////////////////////////////////////////////////////////////////
}