Fields Summary |
---|
private String | errorCode |
private boolean | zeus_ErrorCodeSet |
private String | exceptionType |
private boolean | zeus_ExceptionTypeSet |
private String | location |
private boolean | zeus_LocationSet |
private String | id |
private boolean | zeus_IdSet |
private String | docTypeStringAny DOCTYPE reference/statements. |
private String | outputEncodingThe encoding for the output document |
private Unmarshallable | zeus_currentUNodeThe current node in unmarshalling |
private Unmarshallable | zeus_parentUNodeThe parent node in unmarshalling |
private boolean | zeus_thisNodeHandledWhether this node has been handled |
private boolean | hasDTDWhether a DTD exists for an unmarshal call |
private boolean | validateWhether validation is occurring |
private Map | namespaceMappingsThe namespace mappings on this element |
private static EntityResolver | entityResolverThe EntityResolver for SAX parsing to use |
private static ErrorHandler | errorHandlerThe ErrorHandler for SAX parsing to use |
private boolean | zeus_inErrorCodeIndicates if we are in the errorCode element |
private boolean | zeus_inExceptionTypeIndicates if we are in the exceptionType element |
private boolean | zeus_inLocationIndicates if we are in the location element |
Methods Summary |
---|
public void | characters(char[] ch, int start, int len)
// Feed this to the correct ContentHandler
Unmarshallable current = getCurrentUNode();
if (current != this) {
current.characters(ch, start, len);
return;
}
String text = new String(ch, start, len);
text = text.trim();
if (zeus_inErrorCode) {
if (this.errorCode == null) {
this.errorCode = text;
} else {
this.errorCode = new StringBuffer(this.errorCode).append(text).toString();
}
return;
}
if (zeus_inExceptionType) {
if (this.exceptionType == null) {
this.exceptionType = text;
} else {
this.exceptionType = new StringBuffer(this.exceptionType).append(text).toString();
}
return;
}
if (zeus_inLocation) {
if (this.location == null) {
this.location = text;
} else {
this.location = new StringBuffer(this.location).append(text).toString();
}
return;
}
|
public void | comment(char[] ch, int start, int len)
// Currently no-op
|
public void | endCDATA()
// Currently no-op
|
public void | endDTD()
// Currently no-op
|
public void | endElement(java.lang.String namespaceURI, java.lang.String localName, java.lang.String qName)
Unmarshallable current = getCurrentUNode();
if (current != this) {
current.endElement(namespaceURI, localName, qName);
return;
}
if (localName.equals("error-code")) {
this.zeus_inErrorCode = false;
return;
}
if (localName.equals("exception-type")) {
this.zeus_inExceptionType = false;
return;
}
if (localName.equals("location")) {
this.zeus_inLocation = false;
return;
}
Unmarshallable parent = getCurrentUNode().getParentUNode();
if (parent != null) {
parent.setCurrentUNode(parent);
}
|
public void | endEntity(java.lang.String name)
// Currently no-op
|
public void | error(org.xml.sax.SAXParseException e)
if ((validate) && (!hasDTD)) {
throw new SAXException("Validation is turned on, but no DTD has been specified in the input XML document. Please supply a DTD through a DOCTYPE reference.");
}
if (errorHandler != null) {
errorHandler.error(e);
}
|
private java.lang.String | escapeAttributeValue(java.lang.String attributeValue)
String returnValue = attributeValue;
for (int i = 0; i < returnValue.length(); i++) {
char ch = returnValue.charAt(i);
if (ch == '"") {
returnValue = new StringBuffer()
.append(returnValue.substring(0, i))
.append(""")
.append(returnValue.substring(i+1))
.toString();
}
}
return returnValue;
|
private java.lang.String | escapeTextValue(java.lang.String textValue)
String returnValue = textValue;
for (int i = 0; i < returnValue.length(); i++) {
char ch = returnValue.charAt(i);
if (ch == '<") {
returnValue = new StringBuffer()
.append(returnValue.substring(0, i))
.append("<")
.append(returnValue.substring(i+1))
.toString();
} else if (ch == '>") {
returnValue = new StringBuffer()
.append(returnValue.substring(0, i))
.append(">")
.append(returnValue.substring(i+1))
.toString();
}
}
return returnValue;
|
public void | fatalError(org.xml.sax.SAXParseException e)
if ((validate) && (!hasDTD)) {
throw new SAXException("Validation is turned on, but no DTD has been specified in the input XML document. Please supply a DTD through a DOCTYPE reference.");
}
if (errorHandler != null) {
errorHandler.fatalError(e);
}
|
public Unmarshallable | getCurrentUNode()
return zeus_currentUNode;
|
public java.lang.String | getErrorCode()
return errorCode;
|
public java.lang.String | getExceptionType()
return exceptionType;
|
public java.lang.String | getId()
return id;
|
public java.lang.String | getLocation()
return location;
|
public Unmarshallable | getParentUNode()
return zeus_parentUNode;
|
public void | marshal(java.io.File file)
// Delegate to the marshal(Writer) method
marshal(new FileWriter(file));
|
public void | marshal(java.io.OutputStream outputStream)
// Delegate to the marshal(Writer) method
marshal(new OutputStreamWriter(outputStream));
|
public void | marshal(java.io.Writer writer)
// Write out the XML declaration
writer.write("<?xml version=\"1.0\" ");
if (outputEncoding != null) {
writer.write("encoding=\"");
writer.write(outputEncoding);
writer.write("\"?>\n\n");
} else {
writer.write("encoding=\"UTF-8\"?>\n\n");
}
// Handle DOCTYPE declaration
writer.write(docTypeString);
writer.write("\n");
// Now start the recursive writing
writeXMLRepresentation(writer, "");
// Close up
writer.flush();
writer.close();
|
public void | setCurrentUNode(Unmarshallable currentUNode)
this.zeus_currentUNode = currentUNode;
|
public void | setDocType(java.lang.String name, java.lang.String publicID, java.lang.String systemID)
try {
startDTD(name, publicID, systemID);
} catch (SAXException neverHappens) { }
|
public void | setDocumentLocator(org.xml.sax.Locator locator)
// no-op
|
public static void | setEntityResolver(org.xml.sax.EntityResolver resolver)
This sets a SAX EntityResolver for this unmarshalling process.
entityResolver = resolver;
|
public void | setErrorCode(java.lang.String errorCode)
this.errorCode = errorCode;
zeus_ErrorCodeSet = true;
|
public static void | setErrorHandler(org.xml.sax.ErrorHandler handler)
This sets a SAX ErrorHandler for this unmarshalling process.
errorHandler = handler;
|
public void | setExceptionType(java.lang.String exceptionType)
this.exceptionType = exceptionType;
zeus_ExceptionTypeSet = true;
|
public void | setId(java.lang.String id)
this.id = id;
zeus_IdSet = true;
|
public void | setLocation(java.lang.String location)
this.location = location;
zeus_LocationSet = true;
|
public void | setOutputEncoding(java.lang.String outputEncoding)
this.outputEncoding = outputEncoding;
|
public void | setParentUNode(Unmarshallable parentUNode)
this.zeus_parentUNode = parentUNode;
|
public void | setValidating(boolean validate)
this.validate = validate;
|
public void | startCDATA()
// Currently no-op
|
public void | startDTD(java.lang.String name, java.lang.String publicID, java.lang.String systemID)
if ((name == null) || (name.equals(""))) {
docTypeString = "";
return;
}
hasDTD = true;
StringBuffer docTypeSB = new StringBuffer();
boolean hasPublic = false;
docTypeSB.append("<!DOCTYPE ")
.append(name);
if ((publicID != null) && (!publicID.equals(""))) {
docTypeSB.append(" PUBLIC \"")
.append(publicID)
.append("\"");
hasPublic = true;
}
if ((systemID != null) && (!systemID.equals(""))) {
if (!hasPublic) {
docTypeSB.append(" SYSTEM");
}
docTypeSB.append(" \"")
.append(systemID)
.append("\"");
}
docTypeSB.append(">");
docTypeString = docTypeSB.toString();
|
public void | startDocument()
// no-op
|
public void | startElement(java.lang.String namespaceURI, java.lang.String localName, java.lang.String qName, org.xml.sax.Attributes atts)
// Feed this to the correct ContentHandler
Unmarshallable current = getCurrentUNode();
if (current != this) {
current.startElement(namespaceURI, localName, qName, atts);
return;
}
// See if we handle, or we delegate
if ((localName.equals("error-page")) && (!zeus_thisNodeHandled)) {
// Handle ourselves
for (int i=0, len=atts.getLength(); i<len; i++) {
String attName= atts.getLocalName(i);
String attValue = atts.getValue(i);
if (attName.equals("id")) {
setId(attValue);
}
}
zeus_thisNodeHandled = true;
return;
} else {
// Delegate handling
if (localName.equals("error-code")) {
this.zeus_inErrorCode = true;
return;
}
if (localName.equals("exception-type")) {
this.zeus_inExceptionType = true;
return;
}
if (localName.equals("location")) {
this.zeus_inLocation = true;
return;
}
}
|
public void | startEntity(java.lang.String name)
// Currently no-op
|
public void | startPrefixMapping(java.lang.String prefix, java.lang.String uri)
namespaceMappings.put(prefix, uri);
|
public static ErrorPage | unmarshal(java.io.File file)
// Delegate to the unmarshal(Reader) method
return unmarshal(new FileReader(file));
|
public static ErrorPage | unmarshal(java.io.File file, boolean validate)
// Delegate to the unmarshal(Reader) method
return unmarshal(new FileReader(file), validate);
|
public static ErrorPage | unmarshal(java.io.InputStream inputStream)
// Delegate to the unmarshal(Reader) method
return unmarshal(new InputStreamReader(inputStream));
|
public static ErrorPage | unmarshal(java.io.InputStream inputStream, boolean validate)
// Delegate to the unmarshal(Reader) method
return unmarshal(new InputStreamReader(inputStream), validate);
|
public static ErrorPage | unmarshal(java.io.Reader reader)
// Delegate with default validation value
return unmarshal(reader, false);
|
public static ErrorPage | unmarshal(java.io.Reader reader, boolean validate)
ErrorPageImpl errorPage = new ErrorPageImpl();
errorPage.setValidating(validate);
errorPage.setCurrentUNode(errorPage);
errorPage.setParentUNode(null);
// Load the XML parser
XMLReader parser = null;
String parserClass = System.getProperty("org.xml.sax.driver",
"org.apache.xerces.parsers.SAXParser");
try {
parser = XMLReaderFactory.createXMLReader(parserClass);
// Set entity resolver, if needed
if (entityResolver != null) {
parser.setEntityResolver(entityResolver);
}
// Set error handler
parser.setErrorHandler(errorPage);
// Register lexical handler
parser.setProperty("http://xml.org/sax/properties/lexical-handler", errorPage);
// Register content handler
parser.setContentHandler(errorPage);
} catch (SAXException e) {
throw new IOException("Could not load XML parser: " +
e.getMessage());
}
InputSource inputSource = new InputSource(reader);
try {
parser.setFeature("http://xml.org/sax/features/validation", new Boolean(validate).booleanValue());
parser.setFeature("http://xml.org/sax/features/namespaces", true);
parser.setFeature("http://xml.org/sax/features/namespace-prefixes", false);
parser.parse(inputSource);
} catch (SAXException e) {
throw new IOException("Error parsing XML document: " +
e.getMessage());
}
// Return the resultant object
return errorPage;
|
public void | warning(org.xml.sax.SAXParseException e)
if (errorHandler != null) {
errorHandler.warning(e);
}
|
protected void | writeXMLRepresentation(java.io.Writer writer, java.lang.String indent)
writer.write(indent);
writer.write("<error-page");
// Handle namespace mappings (if needed)
for (Iterator i = namespaceMappings.keySet().iterator(); i.hasNext(); ) {
String prefix = (String)i.next();
String uri = (String)namespaceMappings.get(prefix);
writer.write(" xmlns");
if (!prefix.trim().equals("")) {
writer.write(":");
writer.write(prefix);
}
writer.write("=\"");
writer.write(uri);
writer.write("\"\n ");
}
// Handle attributes (if needed)
if (zeus_IdSet) {
writer.write(" id=\"");
writer.write(escapeAttributeValue(id));
writer.write("\"");
}
writer.write(">");
writer.write("\n");
// Handle child elements
if (errorCode != null) {
writer.write(new StringBuffer(indent).append(" ").toString());
writer.write("<error-code>");
writer.write(this.errorCode);
writer.write("</error-code>\n");
}
if (exceptionType != null) {
writer.write(new StringBuffer(indent).append(" ").toString());
writer.write("<exception-type>");
writer.write(this.exceptionType);
writer.write("</exception-type>\n");
}
if (location != null) {
writer.write(new StringBuffer(indent).append(" ").toString());
writer.write("<location>");
writer.write(this.location);
writer.write("</location>\n");
}
writer.write(indent);
writer.write("</error-page>\n");
|