final XPath xPath = XPathFactory.newInstance().newXPath(); final ErrorHandler errorHandler = new ErrorHandler(options); document.setUserData(ERROR_HANDLER_KEY, errorHandler, null); errorHandler.checkIfShouldExit(); errorHandler.checkIfShouldExit(); errorHandler.checkIfShouldExit();
/** * Handle an error condition as consequence of parsing. * * @param node that is the context of the warning. * @param msg associated with the error. */ public static void handleError(final Node node, final String msg) { final ErrorHandler handler = (ErrorHandler)node.getOwnerDocument().getUserData(ERROR_HANDLER_KEY); if (handler == null) { throw new IllegalStateException("ERROR: " + formatLocationInfo(node) + msg); } else { handler.error(formatLocationInfo(node) + msg); } }
/** * Handle a warning condition as a consequence of parsing. * * @param node as the context for the warning. * @param msg associated with the warning. */ public static void handleWarning(final Node node, final String msg) { final ErrorHandler handler = (ErrorHandler)node.getOwnerDocument().getUserData(ERROR_HANDLER_KEY); if (handler == null) { throw new IllegalStateException("WARNING: " + formatLocationInfo(node) + msg); } else { handler.warning(formatLocationInfo(node) + msg); } }
final ErrorHandler handler = new ErrorHandler(options); parseTestXmlAddToMap(map, "/types/set", testXmlString, handler); assertThat(valueOf(handler.errorCount()), is(valueOf(3))); assertThat(valueOf(handler.warningCount()), is(valueOf(33)));
private static Map<String, Type> parseTestXmlWithMap(final String xPathExpr, final String xml) throws ParserConfigurationException, XPathExpressionException, IOException, SAXException { final Document document = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse( new ByteArrayInputStream(xml.getBytes())); final XPath xPath = XPathFactory.newInstance().newXPath(); final NodeList list = (NodeList)xPath.compile(xPathExpr).evaluate(document, XPathConstants.NODESET); final Map<String, Type> map = new HashMap<>(); final ParserOptions options = ParserOptions.builder().stopOnError(true).suppressOutput(true).build(); document.setUserData(XmlSchemaParser.ERROR_HANDLER_KEY, new ErrorHandler(options), null); for (int i = 0, size = list.getLength(); i < size; i++) { final Type t = new CompositeType(list.item(i)); map.put(t.name(), t); } return map; } }
private static Map<String, Type> parseTestXmlWithMap(final String xPathExpr, final String xml) throws ParserConfigurationException, XPathExpressionException, IOException, SAXException { final Document document = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse( new ByteArrayInputStream(xml.getBytes())); final XPath xPath = XPathFactory.newInstance().newXPath(); final NodeList list = (NodeList)xPath.compile(xPathExpr).evaluate(document, XPathConstants.NODESET); final Map<String, Type> map = new HashMap<>(); final ParserOptions options = ParserOptions.builder().stopOnError(true).suppressOutput(true).build(); document.setUserData(XmlSchemaParser.ERROR_HANDLER_KEY, new ErrorHandler(options), null); for (int i = 0, size = list.getLength(); i < size; i++) { final Type t = new EncodedDataType(list.item(i)); map.put(t.name(), t); } return map; } }
/** * Take an {@link InputStream} and parse it generating map of template ID to Message objects, types, and schema * Input could be from {@link java.io.FileInputStream}, {@link java.io.ByteArrayInputStream}, etc. * Exceptions are passed back up for any problems. * * @param in stream from which schema is read. * @param options to be applied during parsing. * @return {@link MessageSchema} encoding for the schema. * @throws Exception on parsing error. */ public static MessageSchema parse(final InputStream in, final ParserOptions options) throws Exception { final DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); final Document document = factory.newDocumentBuilder().parse(in); final XPath xPath = XPathFactory.newInstance().newXPath(); final ErrorHandler errorHandler = new ErrorHandler(options); document.setUserData(ERROR_HANDLER_KEY, errorHandler, null); final Map<String, Type> typeByNameMap = findTypes(document, xPath); errorHandler.checkIfShouldExit(); final Map<Long, Message> messageByIdMap = findMessages(document, xPath, typeByNameMap); errorHandler.checkIfShouldExit(); final Node schemaNode = (Node)xPath.compile(MESSAGE_SCHEMA_XPATH_EXPR).evaluate(document, XPathConstants.NODE); final MessageSchema messageSchema = new MessageSchema(schemaNode, typeByNameMap, messageByIdMap); errorHandler.checkIfShouldExit(); return messageSchema; }
private static Map<String, Type> parseTestXmlWithMap(final String xPathExpr, final String xml) throws ParserConfigurationException, XPathExpressionException, IOException, SAXException { final Document document = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse( new ByteArrayInputStream(xml.getBytes())); final XPath xPath = XPathFactory.newInstance().newXPath(); final NodeList list = (NodeList)xPath.compile(xPathExpr).evaluate(document, XPathConstants.NODESET); final Map<String, Type> map = new HashMap<>(); final ParserOptions options = ParserOptions.builder() .stopOnError(true) .suppressOutput(true) .warningsFatal(true) .build(); document.setUserData(XmlSchemaParser.ERROR_HANDLER_KEY, new ErrorHandler(options), null); for (int i = 0, size = list.getLength(); i < size; i++) { final Type t = new SetType(list.item(i)); map.put(t.name(), t); } return map; } }
/** * Handle an error condition as consequence of parsing. * * @param node that is the context of the warning. * @param msg associated with the error. */ public static void handleError(final Node node, final String msg) { final ErrorHandler handler = (ErrorHandler)node.getOwnerDocument().getUserData(ERROR_HANDLER_KEY); if (handler == null) { throw new IllegalStateException("ERROR: " + formatLocationInfo(node) + msg); } else { handler.error(formatLocationInfo(node) + msg); } }
/** * Handle a warning condition as a consequence of parsing. * * @param node as the context for the warning. * @param msg associated with the warning. */ public static void handleWarning(final Node node, final String msg) { final ErrorHandler handler = (ErrorHandler)node.getOwnerDocument().getUserData(ERROR_HANDLER_KEY); if (handler == null) { throw new IllegalStateException("WARNING: " + formatLocationInfo(node) + msg); } else { handler.warning(formatLocationInfo(node) + msg); } }
final XPath xPath = XPathFactory.newInstance().newXPath(); final ErrorHandler errorHandler = new ErrorHandler(options); document.setUserData(ERROR_HANDLER_KEY, errorHandler, null); errorHandler.checkIfShouldExit(); errorHandler.checkIfShouldExit(); errorHandler.checkIfShouldExit();
private static Map<String, Type> parseTestXmlWithMap(final String xPathExpr, final String xml) throws ParserConfigurationException, XPathExpressionException, IOException, SAXException { final Document document = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse( new ByteArrayInputStream(xml.getBytes())); final XPath xPath = XPathFactory.newInstance().newXPath(); final NodeList list = (NodeList)xPath.compile(xPathExpr).evaluate(document, XPathConstants.NODESET); final Map<String, Type> map = new HashMap<>(); final ParserOptions options = ParserOptions.builder() .stopOnError(true) .suppressOutput(true) .warningsFatal(true) .build(); document.setUserData(XmlSchemaParser.ERROR_HANDLER_KEY, new ErrorHandler(options), null); for (int i = 0, size = list.getLength(); i < size; i++) { final Type t = new EnumType(list.item(i)); map.put(t.name(), t); } return map; } }
/** * Handle an error condition as consequence of parsing. * * @param node that is the context of the warning. * @param msg associated with the error. */ public static void handleError(final Node node, final String msg) { final ErrorHandler handler = (ErrorHandler)node.getOwnerDocument().getUserData(ERROR_HANDLER_KEY); if (handler == null) { throw new IllegalStateException("ERROR: " + formatLocationInfo(node) + msg); } else { handler.error(formatLocationInfo(node) + msg); } }
/** * Handle a warning condition as a consequence of parsing. * * @param node as the context for the warning. * @param msg associated with the warning. */ public static void handleWarning(final Node node, final String msg) { final ErrorHandler handler = (ErrorHandler)node.getOwnerDocument().getUserData(ERROR_HANDLER_KEY); if (handler == null) { throw new IllegalStateException("WARNING: " + formatLocationInfo(node) + msg); } else { handler.warning(formatLocationInfo(node) + msg); } }
final XPath xPath = XPathFactory.newInstance().newXPath(); final ErrorHandler errorHandler = new ErrorHandler(options); document.setUserData(ERROR_HANDLER_KEY, errorHandler, null); errorHandler.checkIfShouldExit(); errorHandler.checkIfShouldExit(); errorHandler.checkIfShouldExit();
/** * Handle an error condition as consequence of parsing. * * @param node that is the context of the warning. * @param msg associated with the error. */ public static void handleError(final Node node, final String msg) { final ErrorHandler handler = (ErrorHandler)node.getOwnerDocument().getUserData(ERROR_HANDLER_KEY); if (handler == null) { throw new IllegalStateException("ERROR: " + formatLocationInfo(node) + msg); } else { handler.error(formatLocationInfo(node) + msg); } }
/** * Handle a warning condition as a consequence of parsing. * * @param node as the context for the warning. * @param msg associated with the warning. */ public static void handleWarning(final Node node, final String msg) { final ErrorHandler handler = (ErrorHandler)node.getOwnerDocument().getUserData(ERROR_HANDLER_KEY); if (handler == null) { throw new IllegalStateException("WARNING: " + formatLocationInfo(node) + msg); } else { handler.warning(formatLocationInfo(node) + msg); } }