Java Code Examples for javax.xml.catalog.CatalogManager#catalogResolver()
The following examples show how to use
javax.xml.catalog.CatalogManager#catalogResolver() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CatalogTest.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
@Test public void testInvalidCatalog() throws Exception { String expectedMsgId = "JAXP09040001"; URI catalog = getClass().getResource("catalog_invalid.xml").toURI(); try { CatalogResolver resolver = CatalogManager.catalogResolver( CatalogFeatures.defaults(), catalog); String actualSystemId = resolver.resolveEntity( null, "http://remote/xml/dtd/sys/alice/docAlice.dtd") .getSystemId(); } catch (Exception e) { String msg = e.getMessage(); if (msg != null) { Assert.assertTrue(msg.contains(expectedMsgId), "Message shall contain the corrent message ID " + expectedMsgId); } } }
Example 2
Source File: MCREntityResolver.java From mycore with GNU General Public License v3.0 | 6 votes |
private MCREntityResolver() { Enumeration<URL> systemResources; try { systemResources = MCRClassTools.getClassLoader().getResources("catalog.xml"); } catch (IOException e) { throw new ExceptionInInitializerError(e); } URI[] catalogURIs = MCRStreamUtils.asStream(systemResources) .map(URL::toString) .peek(c -> LOGGER.info("Using XML catalog: {}", c)) .map(URI::create) .toArray(URI[]::new); catalogResolver = CatalogManager.catalogResolver(CatalogFeatures.defaults(), catalogURIs); int cacheSize = MCRConfiguration2.getInt(CONFIG_PREFIX + "StaticFiles.CacheSize").orElse(100); bytesCache = new MCRCache<>(cacheSize, "EntityResolver Resources"); }
Example 3
Source File: CatalogTest.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
@Test public void testIgnoreInvalidCatalog() { String catalog = getClass().getResource("catalog_invalid.xml").toExternalForm(); CatalogFeatures f = CatalogFeatures.builder() .with(Feature.FILES, catalog) .with(Feature.PREFER, "public") .with(Feature.DEFER, "true") .with(Feature.RESOLVE, "ignore") .build(); String test = "testInvalidCatalog"; try { CatalogResolver resolver = CatalogManager.catalogResolver(f); String actualSystemId = resolver.resolveEntity( null, "http://remote/xml/dtd/sys/alice/docAlice.dtd") .getSystemId(); System.out.println("testIgnoreInvalidCatalog: expected [null]"); System.out.println("testIgnoreInvalidCatalog: expected [null]"); System.out.println("actual [" + actualSystemId + "]"); Assert.assertEquals(actualSystemId, null); } catch (Exception e) { Assert.fail(e.getMessage()); } }
Example 4
Source File: CatalogTest.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
@Test(dataProvider = "hierarchyOfCatFilesData") public void hierarchyOfCatFiles2(String systemId, String expectedUri) { String file1 = getClass().getResource("first_cat.xml").toExternalForm(); String file2 = getClass().getResource("second_cat.xml").toExternalForm(); String files = file1 + ";" + file2; try { setSystemProperty(KEY_FILES, files); CatalogResolver catalogResolver = CatalogManager.catalogResolver(CatalogFeatures.defaults()); String sysId = catalogResolver.resolveEntity(null, systemId).getSystemId(); Assert.assertEquals(sysId, Paths.get(filepath + expectedUri).toUri().toString().replace("///", "/"), "System ID match not right"); } finally { clearSystemProperty(KEY_FILES); } }
Example 5
Source File: CatalogTest.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
@Test(dataProvider = "catalog") public void testCatalogResolver(String test, String expected, String catalogFile, String xml, SAXParser saxParser) throws Exception { URI catalog = null; if (catalogFile != null) { catalog = getClass().getResource(catalogFile).toURI(); } String url = getClass().getResource(xml).getFile(); try { CatalogResolver cr = CatalogManager.catalogResolver(CatalogFeatures.defaults(), catalog); XMLReader reader = saxParser.getXMLReader(); reader.setEntityResolver(cr); MyHandler handler = new MyHandler(saxParser); reader.setContentHandler(handler); reader.parse(url); System.out.println(test + ": expected [" + expected + "] <> actual [" + handler.getResult() + "]"); Assert.assertEquals(handler.getResult(), expected); } catch (SAXException | IOException e) { Assert.fail(e.getMessage()); } }
Example 6
Source File: CatalogTest.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
/** * @bug 8146237 * PREFER from Features API taking precedence over catalog file */ @Test public void testJDK8146237() throws Exception { URI catalogFile = getClass().getResource("JDK8146237_catalog.xml").toURI(); try { CatalogFeatures features = CatalogFeatures.builder() .with(CatalogFeatures.Feature.PREFER, "system") .build(); Catalog catalog = CatalogManager.catalog(features, catalogFile); CatalogResolver catalogResolver = CatalogManager.catalogResolver(catalog); String actualSystemId = catalogResolver.resolveEntity( "-//FOO//DTD XML Dummy V0.0//EN", "http://www.oracle.com/alt1sys.dtd") .getSystemId(); Assert.assertTrue(actualSystemId.contains("dummy.dtd"), "Resulting id should contain dummy.dtd, indicating a match by publicId"); } catch (Exception e) { Assert.fail(e.getMessage()); } }
Example 7
Source File: CatalogFileInputTest.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
@Test(dataProvider = "acceptedURI") public void testMatch(String uri, String sysId, String pubId, String expectedId, String msg) throws Exception { CatalogResolver cr = CatalogManager.catalogResolver(FEATURES, URI.create(uri)); InputSource is = cr.resolveEntity(pubId, sysId); Assert.assertNotNull(is, msg); Assert.assertEquals(expectedId, is.getSystemId(), msg); }
Example 8
Source File: XmlCatalogUtil.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
/** * Instantiate catalog resolver using new catalog API (javax.xml.catalog.*) * added in JDK9. Usage of new API removes dependency on internal API * (com.sun.org.apache.xml.internal) for modular runtime. */ private static EntityResolver createCatalogResolver(ArrayList<URL> urls) throws Exception { // Prepare array of catalog URIs URI[] uris = urls.stream() .map(u -> URI.create(u.toExternalForm())) .toArray(URI[]::new); //Create CatalogResolver with new JDK9+ API return (EntityResolver) CatalogManager.catalogResolver(CATALOG_FEATURES, uris); }
Example 9
Source File: CatalogTest.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
@Test(dataProvider = "supportXMLResolver") public void supportEntityResolver(URI catalogFile, String xml, String expected) throws Exception { String xmlSource = getClass().getResource(xml).getFile(); CatalogResolver cr = CatalogManager.catalogResolver(CatalogFeatures.defaults(), catalogFile); MyCatalogHandler handler = new MyCatalogHandler(cr, elementInSystem); SAXParser parser = getSAXParser(false, true, null); parser.parse(xmlSource, handler); Assert.assertEquals(handler.getResult().trim(), expected); }
Example 10
Source File: CatalogFileInputTest.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
@Test(dataProvider = "invalidCatalog") public void testCatalogResolverWEmptyCatalog1(String uri, String publicId, String msg) { CatalogResolver cr = CatalogManager.catalogResolver( CatalogFeatures.builder().with(CatalogFeatures.Feature.RESOLVE, "continue").build(), uri != null? URI.create(uri) : null); Assert.assertNull(cr.resolveEntity(publicId, ""), msg); }
Example 11
Source File: CatalogTest.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
@Test public void testRewriteSystem() throws Exception { URI catalog = getClass().getResource("rewriteCatalog.xml").toURI(); try { CatalogResolver resolver = CatalogManager.catalogResolver(CatalogFeatures.defaults(), catalog); String actualSystemId = resolver.resolveEntity(null, "http://remote.com/dtd/book.dtd").getSystemId(); Assert.assertTrue(!actualSystemId.contains("//"), "result contains duplicate slashes"); } catch (Exception e) { Assert.fail(e.getMessage()); } }
Example 12
Source File: CatalogFileInputTest.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
@Test(dataProvider = "invalidCatalog", expectedExceptions = CatalogException.class) public void testCatalogResolverWEmptyCatalog(String uri, String publicId, String msg) { CatalogResolver cr = CatalogManager.catalogResolver( CatalogFeatures.builder().with(CatalogFeatures.Feature.RESOLVE, "strict").build(), uri != null? URI.create(uri) : null); InputSource is = cr.resolveEntity(publicId, ""); }
Example 13
Source File: CatalogTest.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
@Test(dataProvider = "resolveUri") public void testMatch1(String cFile, String href, String expectedFile, String expectedUri, String msg) throws Exception { URI catalogFile = getClass().getResource(cFile).toURI(); CatalogResolver cur = CatalogManager.catalogResolver(CatalogFeatures.defaults(), catalogFile); Source source = cur.resolve(href, null); Assert.assertNotNull(source, "Source returned is null"); Assert.assertEquals(expectedUri, source.getSystemId(), msg); }
Example 14
Source File: CatalogTest.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
@Test(dataProvider = "resolveEntity") public void testMatch1(String cfile, String prefer, String sysId, String pubId, String expectedUri, String expectedFile, String msg) throws Exception { URI catalogFile = getClass().getResource(cfile).toURI(); CatalogFeatures features = CatalogFeatures.builder().with(CatalogFeatures.Feature.PREFER, prefer).build(); CatalogResolver catalogResolver = CatalogManager.catalogResolver(features, catalogFile); InputSource is = catalogResolver.resolveEntity(pubId, sysId); Assert.assertNotNull(is, msg); String expected = (expectedUri == null) ? expectedFile : expectedUri; Assert.assertEquals(expected, is.getSystemId(), msg); }
Example 15
Source File: CatalogTest.java From openjdk-jdk9 with GNU General Public License v2.0 | 4 votes |
@Test(expectedExceptions = NullPointerException.class) public void sysIdCantBeNull() { CatalogResolver catalogResolver = CatalogManager.catalogResolver(CatalogFeatures.defaults()); InputSource is = catalogResolver.resolveEntity("-//FOO//DTD XML Dummy V0.0//EN", null); }
Example 16
Source File: CatalogTest.java From openjdk-jdk9 with GNU General Public License v2.0 | 4 votes |
@Test(expectedExceptions = NullPointerException.class) public void testFeatureNull() { CatalogResolver resolver = CatalogManager.catalogResolver(null, null); }
Example 17
Source File: CatalogFileInputTest.java From openjdk-jdk9 with GNU General Public License v2.0 | 4 votes |
@Test(dataProvider = "invalidInput", expectedExceptions = IllegalArgumentException.class) public void testInvalidUri(String file) { CatalogResolver cr = CatalogManager.catalogResolver(FEATURES, file != null? URI.create(file) : null); }
Example 18
Source File: CatalogTestUtils.java From openjdk-jdk9 with GNU General Public License v2.0 | 4 votes |
static CatalogResolver catalogResolver(CatalogFeatures features, String... catalogName) { return (catalogName == null) ? CatalogManager.catalogResolver(features) : CatalogManager.catalogResolver(features, getCatalogPaths(catalogName)); }
Example 19
Source File: CatalogUtil.java From openjdk-jdk9 with GNU General Public License v2.0 | 4 votes |
static EntityResolver getCatalog(EntityResolver entityResolver, File catalogFile, ArrayList<URI> catalogUrls) throws IOException { return CatalogManager.catalogResolver( CATALOG_FEATURES, catalogUrls.stream().toArray(URI[]::new)); }
Example 20
Source File: CatalogTest.java From openjdk-jdk9 with GNU General Public License v2.0 | 3 votes |
@Test(dataProvider = "supportLSResourceResolver") public void supportLSResourceResolver(URI catalogFile, Source schemaSource) throws SAXException { CatalogResolver cr = CatalogManager.catalogResolver(CatalogFeatures.defaults(), catalogFile); SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); factory.setResourceResolver(cr); Schema schema = factory.newSchema(schemaSource); }