Class OoxmlFacade
- java.lang.Object
-
- com.github.oowekyala.ooxml.messages.OoxmlFacade
-
public final class OoxmlFacade extends java.lang.ObjectMain entry point of the API. Example usage:public AppConfig parseConfigFile(Path path) throws IOException, XmlException { DocumentBuilder builder; try { builder = DocumentBuilderFactory.newInstance().newDocumentBuilder(); } catch (ParserConfigurationException e) { throw new IllegalStateException("Platform does not support XML", e); } PositionedXmlDoc doc; try (Reader reader = Files.newBufferedReader(path)) { // configure the input source's system ID to have // a file path in the messages InputSource iSource = new InputSource(); iSource.setSystemId(path.toString()); iSource.setCharacterStream(reader); // Here we go doc = new OoxmlFacade().parse(builder, iSource); } // This is the object that maps DOM nodes to file // positions XmlPositioner positioner = doc.getPositioner(); // Create the reporter, which you can use during parsing // to report messages on specific nodes XmlErrorReporter reporter = new DefaultXmlErrorReporter(XmlMessageHandler.SYSTEM_ERR, positioner)); return appSpecificParsing(doc.getDocument(), reporter); }
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private classOoxmlFacade.MyErrorHandler
-
Field Summary
Fields Modifier and Type Field Description private NiceXmlMessageFormatterformatterprivate intnumContextLinesprivate XmlMessageHandlerprinterprivate booleanuseAnsiColors
-
Constructor Summary
Constructors Constructor Description OoxmlFacade()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description NiceXmlMessageFormattergetFormatter()intgetNumContextLines()XmlMessageHandlergetPrinter()booleanisUseAnsiColors()PositionedXmlDocparse(javax.xml.parsers.DocumentBuilder domBuilder, org.xml.sax.InputSource inputSource)Parses an XML document and creates an associatedXmlPositioner.private PositionedXmlDocparseImpl(javax.xml.parsers.DocumentBuilder builder, SpyInputSource isource)private static SpyInputSourcespyOn(org.xml.sax.InputSource inputSource)OoxmlFacadewithAnsiColors(boolean useAnsiColors)OoxmlFacadewithContextLines(int numContextLines)OoxmlFacadewithFormatter(NiceXmlMessageFormatter formatter)OoxmlFacadewithPrinter(XmlMessageHandler printer)
-
-
-
Field Detail
-
printer
private XmlMessageHandler printer
-
formatter
private NiceXmlMessageFormatter formatter
-
useAnsiColors
private boolean useAnsiColors
-
numContextLines
private int numContextLines
-
-
Method Detail
-
withFormatter
public OoxmlFacade withFormatter(NiceXmlMessageFormatter formatter)
-
withPrinter
public OoxmlFacade withPrinter(XmlMessageHandler printer)
-
withAnsiColors
public OoxmlFacade withAnsiColors(boolean useAnsiColors)
-
withContextLines
public OoxmlFacade withContextLines(int numContextLines)
-
getFormatter
public NiceXmlMessageFormatter getFormatter()
-
getPrinter
public XmlMessageHandler getPrinter()
-
isUseAnsiColors
public boolean isUseAnsiColors()
-
getNumContextLines
public int getNumContextLines()
-
parse
public PositionedXmlDoc parse(javax.xml.parsers.DocumentBuilder domBuilder, org.xml.sax.InputSource inputSource) throws XmlException, java.io.IOException
Parses an XML document and creates an associatedXmlPositioner. Exceptions thrown by the parser (eg because of invalid XML syntax) are reported using the given message handler. Their position is recovered on a best-effort basis. Only fatal parsing exceptions are thrown, but even them are passed to the givenXmlMessageHandler.To validate the document against a schema, you must use either
setValidatingorsetSchemaon the document builder factory. Text positions cannot be recovered by aValidatorafter the fact (this is a limitation ofjava.xml). Note that setting both may result in duplicate messages.For best messages back your
InputSourcewith anInputStream, or better, aReader.- Parameters:
domBuilder- Preconfigured DOM builder, the error handler is set by this method.inputSource- Source for the XML document. The system ID should be set for better error messages.- Throws:
java.io.IOException- If reading from the input source throws an IOExceptionXmlException- If the parser throws a fatal exception
-
parseImpl
private PositionedXmlDoc parseImpl(javax.xml.parsers.DocumentBuilder builder, SpyInputSource isource) throws XmlException, java.io.IOException
- Throws:
XmlExceptionjava.io.IOException
-
spyOn
private static SpyInputSource spyOn(org.xml.sax.InputSource inputSource) throws java.io.IOException
- Throws:
java.io.IOException
-
-