/** * Parse the message schema specification. * * @param sbeSchemaFilename file containing the SBE specification for the * @return the parsed {@link MessageSchema} for the specification found in the file. * @throws Exception if an error occurs when parsing the specification. */ public static MessageSchema parseSchema(final String sbeSchemaFilename) throws Exception { final ParserOptions.Builder optionsBuilder = ParserOptions.builder() .xsdFilename(System.getProperty(VALIDATION_XSD)) .xIncludeAware(Boolean.parseBoolean(System.getProperty(XINCLUDE_AWARE))) .stopOnError(Boolean.parseBoolean(System.getProperty(VALIDATION_STOP_ON_ERROR))) .warningsFatal(Boolean.parseBoolean(System.getProperty(VALIDATION_WARNINGS_FATAL))) .suppressOutput(Boolean.parseBoolean(System.getProperty(VALIDATION_SUPPRESS_OUTPUT))); try (InputStream in = new BufferedInputStream(Files.newInputStream(Paths.get(sbeSchemaFilename)))) { return XmlSchemaParser.parse(in, optionsBuilder.build()); } }
/** * Validate the SBE Schema against the XSD. * * @param sbeSchemaFilename to be validated * @param xsdFilename XSD against which to validate * @throws Exception if an error occurs while validating */ public static void validateAgainstSchema(final String sbeSchemaFilename, final String xsdFilename) throws Exception { final ParserOptions.Builder optionsBuilder = ParserOptions.builder() .xsdFilename(System.getProperty(VALIDATION_XSD)) .xIncludeAware(Boolean.parseBoolean(System.getProperty(XINCLUDE_AWARE))) .stopOnError(Boolean.parseBoolean(System.getProperty(VALIDATION_STOP_ON_ERROR))) .warningsFatal(Boolean.parseBoolean(System.getProperty(VALIDATION_WARNINGS_FATAL))) .suppressOutput(Boolean.parseBoolean(System.getProperty(VALIDATION_SUPPRESS_OUTPUT))); try (InputStream in = new BufferedInputStream(Files.newInputStream(Paths.get(sbeSchemaFilename)))) { XmlSchemaParser.validate(xsdFilename, in, optionsBuilder.build()); } }
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; } }
/** * Validate the SBE Schema against the XSD. * * @param sbeSchemaFilename to be validated * @param xsdFilename XSD against which to validate * @throws Exception if an error occurs while validating */ public static void validateAgainstSchema(final String sbeSchemaFilename, final String xsdFilename) throws Exception { final ParserOptions.Builder optionsBuilder = ParserOptions.builder() .xsdFilename(System.getProperty(VALIDATION_XSD)) .xIncludeAware(Boolean.parseBoolean(System.getProperty(XINCLUDE_AWARE))) .stopOnError(Boolean.parseBoolean(System.getProperty(VALIDATION_STOP_ON_ERROR))) .warningsFatal(Boolean.parseBoolean(System.getProperty(VALIDATION_WARNINGS_FATAL))) .suppressOutput(Boolean.parseBoolean(System.getProperty(VALIDATION_SUPPRESS_OUTPUT))); try (InputStream in = new BufferedInputStream(Files.newInputStream(Paths.get(sbeSchemaFilename)))) { XmlSchemaParser.validate(xsdFilename, in, optionsBuilder.build()); } }
/** * Validate the SBE Schema against the XSD. * * @param sbeSchemaFilename to be validated * @param xsdFilename XSD against which to validate * @throws Exception if an error occurs while validating */ public static void validateAgainstSchema(final String sbeSchemaFilename, final String xsdFilename) throws Exception { final ParserOptions.Builder optionsBuilder = ParserOptions.builder() .xsdFilename(System.getProperty(VALIDATION_XSD)) .xIncludeAware(Boolean.parseBoolean(System.getProperty(XINCLUDE_AWARE))) .stopOnError(Boolean.parseBoolean(System.getProperty(VALIDATION_STOP_ON_ERROR))) .warningsFatal(Boolean.parseBoolean(System.getProperty(VALIDATION_WARNINGS_FATAL))) .suppressOutput(Boolean.parseBoolean(System.getProperty(VALIDATION_SUPPRESS_OUTPUT))); try (InputStream in = new BufferedInputStream(Files.newInputStream(Paths.get(sbeSchemaFilename)))) { XmlSchemaParser.validate(xsdFilename, in, optionsBuilder.build()); } }
/** * Parse the message schema specification. * * @param sbeSchemaFilename file containing the SBE specification for the * @return the parsed {@link MessageSchema} for the specification found in the file. * @throws Exception if an error occurs when parsing the specification. */ public static MessageSchema parseSchema(final String sbeSchemaFilename) throws Exception { final ParserOptions.Builder optionsBuilder = ParserOptions .builder() .xsdFilename(System.getProperty(SbeTool.VALIDATION_XSD)) .stopOnError(Boolean.parseBoolean(System.getProperty(SbeTool.VALIDATION_STOP_ON_ERROR))) .warningsFatal(Boolean.parseBoolean(System.getProperty(SbeTool.VALIDATION_WARNINGS_FATAL))) .suppressOutput(Boolean.parseBoolean(System.getProperty(SbeTool.VALIDATION_SUPPRESS_OUTPUT))); try (final BufferedInputStream in = new BufferedInputStream(new FileInputStream(sbeSchemaFilename))) { return XmlSchemaParser.parse(in, optionsBuilder.build()); } }
/** * Parse the message schema specification. * * @param sbeSchemaFilename file containing the SBE specification for the * @return the parsed {@link MessageSchema} for the specification found in the file. * @throws Exception if an error occurs when parsing the specification. */ public static MessageSchema parseSchema(final String sbeSchemaFilename) throws Exception { final ParserOptions.Builder optionsBuilder = ParserOptions.builder() .xsdFilename(System.getProperty(VALIDATION_XSD)) .xIncludeAware(Boolean.parseBoolean(System.getProperty(XINCLUDE_AWARE))) .stopOnError(Boolean.parseBoolean(System.getProperty(VALIDATION_STOP_ON_ERROR))) .warningsFatal(Boolean.parseBoolean(System.getProperty(VALIDATION_WARNINGS_FATAL))) .suppressOutput(Boolean.parseBoolean(System.getProperty(VALIDATION_SUPPRESS_OUTPUT))); try (InputStream in = new BufferedInputStream(Files.newInputStream(Paths.get(sbeSchemaFilename)))) { return XmlSchemaParser.parse(in, optionsBuilder.build()); } }
/** * Parse the message schema specification. * * @param sbeSchemaFilename file containing the SBE specification for the * @return the parsed {@link MessageSchema} for the specification found in the file. * @throws Exception if an error occurs when parsing the specification. */ public static MessageSchema parseSchema(final String sbeSchemaFilename) throws Exception { final ParserOptions.Builder optionsBuilder = ParserOptions.builder() .xsdFilename(System.getProperty(VALIDATION_XSD)) .xIncludeAware(Boolean.parseBoolean(System.getProperty(XINCLUDE_AWARE))) .stopOnError(Boolean.parseBoolean(System.getProperty(VALIDATION_STOP_ON_ERROR))) .warningsFatal(Boolean.parseBoolean(System.getProperty(VALIDATION_WARNINGS_FATAL))) .suppressOutput(Boolean.parseBoolean(System.getProperty(VALIDATION_SUPPRESS_OUTPUT))); try (InputStream in = new BufferedInputStream(Files.newInputStream(Paths.get(sbeSchemaFilename)))) { return XmlSchemaParser.parse(in, optionsBuilder.build()); } }
final ParserOptions options = ParserOptions.builder().suppressOutput(true).build(); final ErrorHandler handler = new ErrorHandler(options);
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; } }
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; } }
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; } }
@Test public void shouldExitAfterTypesWhenCompositeOffsetsIncorrect() throws Exception { exceptionRule.expect(IllegalStateException.class); exceptionRule.expectMessage("had 2 errors"); final ParserOptions options = ParserOptions.builder().suppressOutput(true).warningsFatal(true).build(); parse(TestUtil.getLocalResource("error-handler-invalid-composite-offsets-schema.xml"), options); }
@Test public void shouldExitAfterMessageWhenDupMessageIdsDefined() throws Exception { exceptionRule.expect(IllegalStateException.class); exceptionRule.expectMessage("had 1 errors"); final ParserOptions options = ParserOptions.builder().suppressOutput(true).warningsFatal(true).build(); parse(TestUtil.getLocalResource("error-handler-dup-message-schema.xml"), options); }
@Test public void shouldExitAfterTypes() throws Exception { exceptionRule.expect(IllegalStateException.class); exceptionRule.expectMessage("had 2 errors"); final ParserOptions options = ParserOptions.builder().suppressOutput(true).build(); parse(TestUtil.getLocalResource("error-handler-types-schema.xml"), options); }
@Test public void shouldExitAfterMessageWhenGroupDimensionsNotComposite() throws Exception { exceptionRule.expect(IllegalStateException.class); exceptionRule.expectMessage("had 1 errors"); final ParserOptions options = ParserOptions.builder().suppressOutput(true).warningsFatal(true).build(); parse(TestUtil.getLocalResource("error-handler-group-dimensions-schema.xml"), options); }
@Test public void shouldExitAfterMessage() throws Exception { exceptionRule.expect(IllegalStateException.class); exceptionRule.expectMessage("had 13 errors"); final ParserOptions options = ParserOptions.builder().suppressOutput(true).warningsFatal(true).build(); parse(TestUtil.getLocalResource("error-handler-message-schema.xml"), options); }
@Test public void shouldTestForCyclicRefs() throws Exception { exceptionRule.expect(IllegalStateException.class); exceptionRule.expectMessage("ref types cannot create circular dependencies"); final ParserOptions options = ParserOptions.builder().suppressOutput(true).warningsFatal(true).build(); parse(TestUtil.getLocalResource("cyclic-refs-schema.xml"), options); } }
@Test public void shouldExitInvalidFieldNames() throws Exception { exceptionRule.expect(IllegalStateException.class); exceptionRule.expectMessage("had 16 warnings"); final ParserOptions options = ParserOptions.builder().suppressOutput(true).warningsFatal(true).build(); parse(TestUtil.getLocalResource("error-handler-invalid-name.xml"), options); }
@Test public void shouldExitAfterTypesWhenDupTypesDefined() throws Exception { exceptionRule.expect(IllegalStateException.class); exceptionRule.expectMessage("had 1 warnings"); final ParserOptions options = ParserOptions.builder().suppressOutput(true).warningsFatal(true).build(); parse(TestUtil.getLocalResource("error-handler-types-dup-schema.xml"), options); }