|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.xml.sax.helpers.DefaultHandler
org.xml.sax.ext.DefaultHandler2
org.foray.xml.FOrayPretty
public class FOrayPretty
Command-line application that reads an XML file and writes a pretty-printed version of it.
| Field Summary | |
|---|---|
static byte |
STATUS_COMMAND_LINE_ERROR
Command-line status constant indicating that the command line itself was not properly formed. |
static byte |
STATUS_FILE_NOT_FOUND
Command-line return status constant indicating that a file was not found. |
static byte |
STATUS_PARSING_ERROR
Command-line return status constant indicating that there was an error parsing the input file. |
| Constructor Summary | |
|---|---|
FOrayPretty(InputSource input,
OutputStream output,
String catalog)
Constructor. |
|
| Method Summary | |
|---|---|
void |
characters(char[] buffer,
int offset,
int length)
|
void |
comment(char[] buffer,
int offset,
int length)
|
XMLReader |
createParser()
Creates a SAX parser. |
void |
elementDecl(String name,
String model)
|
void |
endDocument()
|
void |
endDTD()
|
void |
endElement(String uri,
String local,
String qName)
|
void |
endEntity(String name)
|
org.apache.commons.logging.Log |
getLogger()
Returns the logger. |
void |
ignorableWhitespace(char[] buffer,
int offset,
int length)
|
static void |
main(String[] args)
Command-line interface for pretty-printing an XML document. |
void |
processingInstruction(String target,
String data)
|
void |
setBreakPCDATA(boolean breakPCDATA)
Set this configuration parameter to true if whitespace within PCDATA can be interchanged. |
void |
setDesiredLineLength(int desiredLineLength)
Use this configuration parameter to set the desired maximum line length, in characters, for the pretty-printed document. |
void |
setDocumentLocator(Locator locator)
|
void |
setIndent(int indent)
Use this configuration parameter to set the number of spaces that each successive block level of the document should be indented. |
void |
setIndentBlocksInsideMixedContent(boolean indent)
Set this configuration parameter to true if blocks that are inside of mixed content should be indented. |
void |
setLineTerminator(String lineTerminator)
Use this configuration parameter to set the text that should be used to delimit lines in the pretty-printed document. |
void |
setOutputEncoding(String outputEncoding)
Use this configuration parameter to set the output encoding for the pretty-printed document. |
void |
setPostRootText(String postRootText)
Use this configuration parameter to control the text that is written right after the close of the root element. |
void |
setPreRootText(String preRootText)
Use this configuration parameter to control the text that is written right before the root element. |
void |
setXmlDeclaration(String xmlDeclaration)
Use this configuration parameter to set the value of the XML Declaration at the beginning of the pretty-printed document. |
void |
start()
Intantiates parser and starts parsing of input. |
void |
startDocument()
|
void |
startDTD(String name,
String publicId,
String systemId)
|
void |
startElement(String uri,
String local,
String qName,
Attributes attributes)
|
void |
startEntity(String name)
|
| Methods inherited from class org.xml.sax.ext.DefaultHandler2 |
|---|
attributeDecl, endCDATA, externalEntityDecl, getExternalSubset, internalEntityDecl, resolveEntity, resolveEntity, startCDATA |
| Methods inherited from class org.xml.sax.helpers.DefaultHandler |
|---|
endPrefixMapping, error, fatalError, notationDecl, skippedEntity, startPrefixMapping, unparsedEntityDecl, warning |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public static final byte STATUS_COMMAND_LINE_ERROR
public static final byte STATUS_FILE_NOT_FOUND
public static final byte STATUS_PARSING_ERROR
| Constructor Detail |
|---|
public FOrayPretty(InputSource input,
OutputStream output,
String catalog)
input - The input source encapsulating the document to be pretty-printed.output - The output stream to which the pretty-printed document should be sent.catalog - The location of a catalog file that should be used to find the DTD for this document.
This may be null.| Method Detail |
|---|
public void start()
throws IOException,
SAXException,
ParserConfigurationException
IOException - For I/O Errors.
SAXException - For parsing errors.
ParserConfigurationException - For errors configuring parser.
public XMLReader createParser()
throws SAXException,
ParserConfigurationException
SAXException - For error creating parser.
ParserConfigurationException - For error configuring parser.public void setDocumentLocator(Locator locator)
setDocumentLocator in interface ContentHandlersetDocumentLocator in class org.xml.sax.helpers.DefaultHandlerpublic void startDocument()
startDocument in interface ContentHandlerstartDocument in class org.xml.sax.helpers.DefaultHandlerpublic void endDocument()
endDocument in interface ContentHandlerendDocument in class org.xml.sax.helpers.DefaultHandler
public void startElement(String uri,
String local,
String qName,
Attributes attributes)
startElement in interface ContentHandlerstartElement in class org.xml.sax.helpers.DefaultHandler
public void endElement(String uri,
String local,
String qName)
endElement in interface ContentHandlerendElement in class org.xml.sax.helpers.DefaultHandler
public void characters(char[] buffer,
int offset,
int length)
characters in interface ContentHandlercharacters in class org.xml.sax.helpers.DefaultHandler
public void processingInstruction(String target,
String data)
processingInstruction in interface ContentHandlerprocessingInstruction in class org.xml.sax.helpers.DefaultHandler
public void ignorableWhitespace(char[] buffer,
int offset,
int length)
ignorableWhitespace in interface ContentHandlerignorableWhitespace in class org.xml.sax.helpers.DefaultHandler
public void comment(char[] buffer,
int offset,
int length)
comment in interface LexicalHandlercomment in class DefaultHandler2
public void startDTD(String name,
String publicId,
String systemId)
startDTD in interface LexicalHandlerstartDTD in class DefaultHandler2public void endDTD()
endDTD in interface LexicalHandlerendDTD in class DefaultHandler2public void startEntity(String name)
startEntity in interface LexicalHandlerstartEntity in class DefaultHandler2public void endEntity(String name)
endEntity in interface LexicalHandlerendEntity in class DefaultHandler2
public void elementDecl(String name,
String model)
elementDecl in interface DeclHandlerelementDecl in class DefaultHandler2public org.apache.commons.logging.Log getLogger()
public void setBreakPCDATA(boolean breakPCDATA)
breakPCDATA - The new value.public void setXmlDeclaration(String xmlDeclaration)
<?xml version="1.0" encoding="UTF-8">
xmlDeclaration - The new value.public void setLineTerminator(String lineTerminator)
lineTerminator - The new value.public void setOutputEncoding(String outputEncoding)
outputEncoding - The new value.public void setPreRootText(String preRootText)
preRootText - The new value.public void setPostRootText(String postRootText)
postRootText - The new value.public void setIndent(int indent)
indent - The new value.public void setDesiredLineLength(int desiredLineLength)
desiredLineLength - The new value.public void setIndentBlocksInsideMixedContent(boolean indent)
indent - The new value.public static void main(String[] args)
Design Note: We use files instead of URLs here to more easily integrate with desktop tools such as XML editors, which typically know how to pass parameters for local files, but not how to convert them to URLs. If URLs are needed, additional flags probably need to be added to the command-line interface to designate that.
Return status is one of:
args - command-line arguments.
Argument 1 is the location of the input file.
Argument 2 is the location of the output file.
Argument 3 is an optional location of an OASIS-compliant catalog file
that can be used to locate local DTDs.
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||