@Test public void testParseCatalog() throws Exception { URL file = TestData.url(this, "commonSchemas_new.oasis.xml"); ResolvingXMLReader reader = new ResolvingXMLReader(); Catalog catalog = reader.getCatalog(); catalog.getCatalogManager().setVerbosity(9); catalog.parseCatalog(file); final URL baseUri = new URL("http://schemas.opengis.net/gml/"); // the system override defined in the catalog final URL override = new URL("file:///schemas/gml/trunk/gml/"); final String extraPath = "3.1.1/basicTypes.xsd"; final String uri = new URL(baseUri, extraPath).toExternalForm(); final String expected = new URL(override, extraPath).toExternalForm(); String resolved = catalog.resolveSystem(uri); assertNotNull(resolved); final String actual = new URL(resolved).toExternalForm(); assertEquals(expected, actual); } }
/** * Resolves WSDL URIs using Apache Commons Resolver API. * * @param importURI a URI specifying the document to import * @param parent a URI specifying the location of the parent document doing * the importing * @return the resolved import location, or null if no indirection is performed */ public String getRedirectedURI(String importURI, String parent) { String resolvedImportLocation = null; try { resolvedImportLocation = this.catalogResolver.resolveSystem(importURI); if (resolvedImportLocation == null) { resolvedImportLocation = catalogResolver.resolveURI(importURI); } if (resolvedImportLocation == null) { resolvedImportLocation = catalogResolver.resolvePublic(importURI, parent); } } catch (IOException e) { throw new RuntimeException("Catalog resolution failed", e); } return resolvedImportLocation; }
catalog.setCatalogManager(this); catalog.setupReaders(); catalog.loadSystemCatalogs();
@Before public void setUp() throws Exception { catalog = new Catalog(); catalog.setupReaders(); }
for (int count = 0; count < catalogFiles.size(); count++) { String file = (String) catalogFiles.elementAt(count); resolver.parseCatalog(file); if (systemId != null) { System.out.println(" system id: " + systemId); } if (uri != null) { System.out.println(" uri: " + uri); } result = resolver.resolveDoctype(name, publicId, systemId); } else if (resType == Catalog.DOCUMENT) { System.out.println("Resolve DOCUMENT ():"); result = resolver.resolveDocument(); } else if (resType == Catalog.ENTITY) { System.out.println("Resolve ENTITY (name, publicid, systemid):"); if (publicId != null) { System.out.println(" public id: " + publicId); } if (systemId != null) { System.out.println(" system id: " + systemId); } result = resolver.resolveEntity(name, publicId, systemId); } else if (resType == Catalog.NOTATION) { System.out.println("Resolve NOTATION (name, publicid, systemid):"); if (publicId != null) { System.out.println(" public id: " + publicId); } if (systemId != null) { System.out.println(" system id: " + systemId); } result = resolver.resolveNotation(name, publicId, systemId); } else if (resType == Catalog.PUBLIC) { System.out.println("Resolve PUBLIC (publicid, systemid):"); if (publicId != null) { System.out.println(" public id: " + publicId); } if (systemId != null) { System.out.println(" system id: " + systemId); } result = resolver.resolvePublic(publicId, systemId); } else if (resType == Catalog.SYSTEM) { System.out.println("Resolve SYSTEM (systemid):");
String resolvedLocation = null; try { resolvedLocation = catalog.resolveURI(location); } catch (Exception e) { throw new RuntimeException(e); input = (new URL(resolvedLocation)).openStream();
public final void loadCatalog(URL catalogURL) throws IOException { if (!loadedCatalogs.contains(catalogURL.toString())) { if ("file".equals(catalogURL.getProtocol())) { try { File file = new File(catalogURL.toURI()); if (!file.exists()) { throw new FileNotFoundException(file.getAbsolutePath()); } } catch (URISyntaxException e) { //just process as is } } if (catalog == null) { LOG.log(Level.WARNING, "Catalog found at {0} but no org.apache.xml.resolver.CatalogManager was found." + " Check the classpatch for an xmlresolver jar.", catalogURL.toString()); } else { ((Catalog)catalog).parseCatalog(catalogURL); loadedCatalogs.add(catalogURL.toString()); } } }
Enumeration en = catalogEntries.elements(); while (en.hasMoreElements()) { CatalogEntry e = (CatalogEntry) en.nextElement(); en = catalogEntries.elements(); String startString = null; String prefix = null; en = catalogEntries.elements(); String suffixString = null; String suffixURI = null; Enumeration enCats = delCats.elements(); if (catalogManager.debug.getDebug() > 1) { catalogManager.debug.message(2, "Switching to delegated catalog(s):"); while (enCats.hasMoreElements()) { String delegatedCatalog = (String) enCats.nextElement(); catalogManager.debug.message(2, "\t" + delegatedCatalog); Catalog dcat = newCatalog(); enCats = delCats.elements(); while (enCats.hasMoreElements()) { String delegatedCatalog = (String) enCats.nextElement(); dcat.parseCatalog(delegatedCatalog); return dcat.resolveURI(uri);
publicId = publicId.substring(0, publicId.length()-1); String resolvedString = catalog.resolveEntity(filePath.toString(), publicId, publicId); if (resolvedString != null) { getLog().debug("-------------------"); getLog().debug("Resolved namespace/schemaLocation "+namespaceOrLocation+" to "+resolvedString+" using catalog "+catalog); URL resolvedUrl = new URL(resolvedString); String resolvedPathString = resolvedUrl.getPath(); Path resolvedPath = new File(resolvedPathString).toPath(); Path workDirPath = workDir.toPath();
c = (Resolver) catalogs.elementAt(catPos); } catch (ClassCastException e) { String catfile = (String) catalogs.elementAt(catPos); c = (Resolver) newCatalog(); c.parseCatalog(catfile); } catch (MalformedURLException mue) { catalogManager.debug.message(1, "Malformed Catalog URL", catfile); } catch (FileNotFoundException fnfe) { catalogManager.debug.message(1, "Failed to load catalog, file not found", catfile); } catch (IOException ioe) { catalogManager.debug.message(1, "Failed to load catalog, I/O error", catfile); resolved = c.resolveDoctype(entityName, publicId, systemId); resolved = c.resolveDocument(); if (resolved != null) { resolved = c.resolveEntity(entityName, publicId, systemId); resolved = c.resolveNotation(entityName, publicId, systemId);
/** * Build a private {@link Catalog}, that is, not the static instance that {@link CatalogManager} * returns by default. * * <p>Care must be taken to use only private {@link Catalog} instances if there will ever be * more than one OASIS Catalog used in a single class loader (i.e. a single maven test run), * otherwise {@link Catalog} contents will be an amalgam of the entries of both OASIS Catalog * files, with likely unintended or incorrect results. See GEOT-2497. * * @param catalogLocation URL of OASIS Catalog * @return a private Catalog */ static Catalog buildPrivateCatalog(URL catalogLocation) { CatalogManager catalogManager = new CatalogManager(); catalogManager.setUseStaticCatalog(false); catalogManager.setVerbosity(0); catalogManager.setIgnoreMissingProperties(true); Catalog catalog = catalogManager.getCatalog(); try { catalog.parseCatalog(catalogLocation); } catch (IOException e) { throw new RuntimeException( "Error trying to load OASIS catalog from URL " + catalogLocation.toString(), e); } return catalog; }
String resolved = resolveLocalSystem(systemId); if (resolved != null) { return resolved; Enumeration en = catalogEntries.elements(); while (en.hasMoreElements()) { CatalogEntry e = (CatalogEntry) en.nextElement(); en = catalogEntries.elements(); Vector delCats = new Vector(); while (en.hasMoreElements()) { CatalogEntry e = (CatalogEntry) en.nextElement(); Enumeration enCats = delCats.elements(); Catalog dcat = newCatalog(); enCats = delCats.elements(); while (enCats.hasMoreElements()) { String delegatedCatalog = (String) enCats.nextElement(); dcat.parseCatalog(delegatedCatalog); return dcat.resolvePublic(publicId, null);
for (int count = 0; count < catalogs.size(); count++) { catalogFiles.addElement(catalogs.elementAt(count)); String catfile = (String) catalogFiles.lastElement(); catalogFiles.removeElement(catfile); parseCatalog(catfile);
boolean showWarnings = (debuglevel > 2); boolean showErrors = true; Vector catalogFiles = new Vector(); catalogFiles.add(args[i]); continue; debuglevel = Integer.parseInt(debugstr); if (debuglevel >= 0) { debug.setDebug(debuglevel); showWarnings = (debuglevel > 2); Catalog catalog = reader.getCatalog(); for (int count = 0; count < catalogFiles.size(); count++) { String file = (String) catalogFiles.elementAt(count); catalog.parseCatalog(file);
for (int catPos = 0; catPos < catalogs.size(); catPos++) { Catalog c = null; c = (Catalog) catalogs.elementAt(catPos); } catch (ClassCastException e) { String catfile = (String) catalogs.elementAt(catPos); c = newCatalog(); c.parseCatalog(catfile); catalogs.setElementAt(c, catPos); c.parseAllCatalogs(); || e.getEntryType() == DELEGATE_SYSTEM || e.getEntryType() == DELEGATE_URI) { Catalog dcat = newCatalog(); dcat.parseCatalog(e.getEntryArg(1));
c = (Catalog) catalogs.elementAt(catPos); } catch (ClassCastException e) { String catfile = (String) catalogs.elementAt(catPos); c = newCatalog(); c.parseCatalog(catfile); } catch (MalformedURLException mue) { catalogManager.debug.message(1, "Malformed Catalog URL", catfile); } catch (FileNotFoundException fnfe) { catalogManager.debug.message(1, "Failed to load catalog, file not found", catfile); } catch (IOException ioe) { catalogManager.debug.message(1, "Failed to load catalog, I/O error", catfile); resolved = c.resolveDoctype(entityName, publicId, systemId); } else if (entityType == DOCUMENT) { resolved = c.resolveDocument(); } else if (entityType == ENTITY) { resolved = c.resolveEntity(entityName, publicId, systemId); } else if (entityType == NOTATION) { resolved = c.resolveNotation(entityName, publicId, systemId); } else if (entityType == PUBLIC) { resolved = c.resolvePublic(publicId, systemId);
/** * Parse a catalog */ protected void parseCatalog(String uri) { if (this.getLogger().isDebugEnabled()) { this.getLogger().debug("Additional Catalog is " + uri); } final Resource resource = this.resourceLoader.getResource(uri); try { this.catalogResolver.getCatalog().parseCatalog(this.correctUri(resource.getURL().toExternalForm())); } catch (Exception e) { this.getLogger().warn("Could not get Catalog file. Trying again: " + uri, e); // try it again try { this.catalogResolver.getCatalog().parseCatalog("text/plain", resource.getInputStream()); } catch (Exception ex) { this.getLogger().warn("Could not get Catalog file: " + uri, ex); } } }
throws MalformedURLException, IOException { String resolved = super.resolveURI(uri); if (resolved != null) { return resolved; Enumeration en = catalogEntries.elements(); while (en.hasMoreElements()) { CatalogEntry e = (CatalogEntry) en.nextElement(); return resolveSubordinateCatalogs(Catalog.URI, null, null,
throws MalformedURLException, IOException { String resolved = super.resolveSystem(systemId); if (resolved != null) { return resolved; Enumeration en = catalogEntries.elements(); while (en.hasMoreElements()) { CatalogEntry e = (CatalogEntry) en.nextElement(); return resolveSubordinateCatalogs(Catalog.SYSTEM, null, null,