From: <svn...@os...> - 2012-04-24 06:36:52
|
Author: ang05a Date: 2012-04-23 23:36:40 -0700 (Mon, 23 Apr 2012) New Revision: 38688 Modified: trunk/modules/extension/app-schema/app-schema-resolver/src/main/java/org/geotools/xml/AppSchemaValidator.java trunk/modules/extension/app-schema/app-schema-resolver/src/test/java/org/geotools/xml/AppSchemaValidatorTest.java Log: Enable using catalog in AppSchemaValidator for app-schema-test. Modified: trunk/modules/extension/app-schema/app-schema-resolver/src/main/java/org/geotools/xml/AppSchemaValidator.java =================================================================== --- trunk/modules/extension/app-schema/app-schema-resolver/src/main/java/org/geotools/xml/AppSchemaValidator.java 2012-04-23 03:17:54 UTC (rev 38687) +++ trunk/modules/extension/app-schema/app-schema-resolver/src/main/java/org/geotools/xml/AppSchemaValidator.java 2012-04-24 06:36:40 UTC (rev 38688) @@ -21,6 +21,8 @@ import java.io.IOException; import java.io.InputStream; import java.io.UnsupportedEncodingException; +import java.net.MalformedURLException; +import java.net.URL; import java.util.ArrayList; import java.util.Collections; import java.util.List; @@ -91,6 +93,17 @@ private AppSchemaValidator(AppSchemaResolver resolver) { this.resolver = resolver; } + + /** + * Construct an {@link AppSchemaValidator} that performs schema validation against schemas found + * using an {@link AppSchemaResolver} with a {@link AppSchemaCatalog}. + * + * @param catalog + * AppSchemaCatalog + */ + private AppSchemaValidator(AppSchemaCatalog catalog) { + this(new AppSchemaResolver(catalog)); + } /** * Return the list of failures found during parsing. @@ -212,6 +225,17 @@ public static AppSchemaValidator buildValidator(AppSchemaResolver resolver) { return new AppSchemaValidator(resolver); } + + /** + * Construct an {@link AppSchemaValidator} that performs schema validation against schemas found + * using an {@link AppSchemaResolver} with a {@link AppSchemaCatalog}. + * + * @param catalog + * AppSchemaCatalog + */ + public static AppSchemaValidator buildValidator(AppSchemaCatalog catalog) { + return new AppSchemaValidator(catalog); + } /** * @@ -225,12 +249,14 @@ * * @param name * resource name of XML instance document + * @param catalog + * AppSchemaCatalog to aide local schema resolution or null */ - public static void validateResource(String name) { + public static void validateResource(String name, AppSchemaCatalog catalog) { InputStream input = null; try { input = AppSchemaValidator.class.getResourceAsStream(name); - validate(input); + validate(input, catalog); } finally { if (input != null) { try { @@ -254,8 +280,10 @@ * * @param xml * string containing XML instance document + * @param catalog + * AppSchemaCatalog to aide local schema resolution or null */ - public static void validate(String xml) { + public static void validate(String xml, AppSchemaCatalog catalog) { byte[] bytes = null; String encoding = getEncoding(xml); if (encoding != null) { @@ -273,7 +301,7 @@ InputStream input = null; try { input = new ByteArrayInputStream(bytes); - validate(input); + validate(input, catalog); } finally { if (input != null) { try { @@ -314,9 +342,11 @@ * * @param input * stream providing XML instance document + * @param catalog + * AppSchemaCatalog file to aide local schema resolution or null */ - public static void validate(InputStream input) { - AppSchemaValidator validator = buildValidator(); + public static void validate(InputStream input, AppSchemaCatalog catalog) { + AppSchemaValidator validator = buildValidator(catalog); validator.parse(input); validator.checkForFailures(); } Modified: trunk/modules/extension/app-schema/app-schema-resolver/src/test/java/org/geotools/xml/AppSchemaValidatorTest.java =================================================================== --- trunk/modules/extension/app-schema/app-schema-resolver/src/test/java/org/geotools/xml/AppSchemaValidatorTest.java 2012-04-23 03:17:54 UTC (rev 38687) +++ trunk/modules/extension/app-schema/app-schema-resolver/src/test/java/org/geotools/xml/AppSchemaValidatorTest.java 2012-04-24 06:36:40 UTC (rev 38688) @@ -39,7 +39,7 @@ */ @Test public void validateErMineralOccurrence() { - AppSchemaValidator.validateResource("/test-data/er_MineralOccurrence.xml"); + AppSchemaValidator.validateResource("/test-data/er_MineralOccurrence.xml", null); } /** @@ -49,7 +49,7 @@ @Test public void validateErMineralOccurrenceWithErrors() { try { - AppSchemaValidator.validateResource("/test-data/er_MineralOccurrence_with_errors.xml"); + AppSchemaValidator.validateResource("/test-data/er_MineralOccurrence_with_errors.xml", null); Assert.fail("Unexpected schema validation success for known-invalid XML instance document"); } catch (Exception e) { Assert.assertTrue( @@ -65,7 +65,7 @@ */ @Test public void validateWfs20Example01() { - AppSchemaValidator.validateResource("/test-data/Example01.xml"); + AppSchemaValidator.validateResource("/test-data/Example01.xml", null); } /** @@ -104,7 +104,7 @@ int count = input.read(bytes); Assert.assertEquals("Unexpected read underrun", bytes.length, count); String xml = new String(bytes); - AppSchemaValidator.validate(xml); + AppSchemaValidator.validate(xml, null); } catch (IOException e) { throw new RuntimeException(e); } finally { @@ -164,7 +164,7 @@ + "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" " // + "xsi:schemaLocation=\"" // + "http://www.opengis.net/wfs http://schemas.opengis.net/wfs/1.1.0/wfs.xsd" // - + "\"><wfs:Query typeName=\"test\"/></wfs:GetFeature>"); + + "\"><wfs:Query typeName=\"test\"/></wfs:GetFeature>", null); } /** @@ -175,7 +175,7 @@ try { AppSchemaValidator.validate("<wfs:GetFeature " // + "xmlns:wfs=\"http://www.opengis.net/wfs\">" // - + "<wfs:Query typeName=\"test\"/></wfs:GetFeature>"); + + "<wfs:Query typeName=\"test\"/></wfs:GetFeature>", null); Assert.fail("Unexpected validation success for GetFeature with missing schemaLocation"); } catch (Exception e) { Assert.assertEquals(e.getMessage(), "Schema validation failure caused by " |