< prev index next >

src/java.xml/share/classes/javax/xml/catalog/CatalogImpl.java

Print this page

        

*** 29,38 **** --- 29,39 ---- import java.net.MalformedURLException; import java.net.URI; import java.net.URISyntaxException; import java.net.URL; import java.util.ArrayList; + import java.util.HashMap; import java.util.Iterator; import java.util.List; import java.util.NoSuchElementException; import java.util.Spliterator; import java.util.Spliterators;
*** 70,82 **** int current = 0; //System Id for this catalog String systemId; - //The parent - CatalogImpl parent = null; - /* A list of catalog entry files from the input, excluding the current catalog. Paths in the List are normalized. */ List<String> inputFiles; --- 71,80 ----
*** 105,125 **** * @param file The path to a catalog file. * @throws CatalogException If an error happens while parsing the specified * catalog file. */ public CatalogImpl(CatalogImpl parent, CatalogFeatures f, String... file) throws CatalogException { ! super(CatalogEntryType.CATALOG); if (f == null) { throw new NullPointerException( formatMessage(CatalogMessages.ERR_NULL_ARGUMENT, new Object[]{"CatalogFeatures"})); } if (file.length > 0) { CatalogMessages.reportNPEOnNull("The path to the catalog file", file[0]); } ! init(parent, f); //Path of catalog files String[] catalogFile = file; if (level == 0 && file.length == 0) { String files = features.get(Feature.FILES); --- 103,123 ---- * @param file The path to a catalog file. * @throws CatalogException If an error happens while parsing the specified * catalog file. */ public CatalogImpl(CatalogImpl parent, CatalogFeatures f, String... file) throws CatalogException { ! super(CatalogEntryType.CATALOG, parent); if (f == null) { throw new NullPointerException( formatMessage(CatalogMessages.ERR_NULL_ARGUMENT, new Object[]{"CatalogFeatures"})); } if (file.length > 0) { CatalogMessages.reportNPEOnNull("The path to the catalog file", file[0]); } ! init(f); //Path of catalog files String[] catalogFile = file; if (level == 0 && file.length == 0) { String files = features.get(Feature.FILES);
*** 157,179 **** if (catalogFile[i] != null) { inputFiles.add(catalogFile[i]); } } } if (systemId != null) { parse(systemId); } } } ! private void init(CatalogImpl parent, CatalogFeatures f) { ! this.parent = parent; if (parent == null) { level = 0; } else { level = parent.level + 1; } if (f == null) { this.features = CatalogFeatures.defaults(); } else { this.features = f; --- 155,192 ---- if (catalogFile[i] != null) { inputFiles.add(catalogFile[i]); } } } + } + } + /** + * Loads the catalog + */ + void load() { if (systemId != null) { parse(systemId); } + + //save this catalog before loading the next + loadedCatalogs.put(systemId, this); + + //Load delegate and alternative catalogs if defer is false. + if (!isDeferred()) { + loadDelegateCatalogs(); + loadNextCatalogs(); } } ! private void init(CatalogFeatures f) { if (parent == null) { level = 0; } else { level = parent.level + 1; + this.loadedCatalogs = parent.loadedCatalogs; + this.catalogsSearched = parent.catalogsSearched; } if (f == null) { this.features = CatalogFeatures.defaults(); } else { this.features = f;
*** 194,208 **** catalogsSearched.clear(); } entries.stream().filter((entry) -> (entry.type == CatalogEntryType.GROUP)).forEach((entry) -> { ((GroupEntry) entry).reset(); }); - - if (parent != null) { - this.loadedCatalogs = parent.loadedCatalogs; - this.catalogsSearched = parent.catalogsSearched; - } } /** * Returns whether this Catalog instance is the top (main) Catalog. * --- 207,216 ----
*** 419,438 **** * Loads all alternative catalogs. */ void loadNextCatalogs() { //loads catalogs specified in nextCatalogs if (nextCatalogs != null) { ! for (NextCatalog next : nextCatalogs) { getCatalog(next.getCatalogURI()); ! } } //loads catalogs from the input list if (inputFiles != null) { ! for (String file : inputFiles) { getCatalog(getSystemId(file)); ! } } } /** * Returns a Catalog object by the specified path. --- 427,446 ---- * Loads all alternative catalogs. */ void loadNextCatalogs() { //loads catalogs specified in nextCatalogs if (nextCatalogs != null) { ! nextCatalogs.stream().forEach((next) -> { getCatalog(next.getCatalogURI()); ! }); } //loads catalogs from the input list if (inputFiles != null) { ! inputFiles.stream().forEach((file) -> { getCatalog(getSystemId(file)); ! }); } } /** * Returns a Catalog object by the specified path.
*** 443,460 **** Catalog getCatalog(URI uri) { if (uri == null) { return null; } ! Catalog c = null; String path = uri.toASCIIString(); if (verifyCatalogFile(uri)) { c = getLoadedCatalog(path); if (c == null) { c = new CatalogImpl(this, features, path); ! saveLoadedCatalog(path, c); } } return c; } --- 451,468 ---- Catalog getCatalog(URI uri) { if (uri == null) { return null; } ! CatalogImpl c = null; String path = uri.toASCIIString(); if (verifyCatalogFile(uri)) { c = getLoadedCatalog(path); if (c == null) { c = new CatalogImpl(this, features, path); ! c.load(); } } return c; }
*** 462,472 **** * Saves a loaded Catalog. * * @param catalogId the catalogId associated with the Catalog object * @param c the Catalog to be saved */ ! void saveLoadedCatalog(String catalogId, Catalog c) { loadedCatalogs.put(catalogId, c); } /** * Returns a count of all loaded catalogs, including delegate catalogs. --- 470,480 ---- * Saves a loaded Catalog. * * @param catalogId the catalogId associated with the Catalog object * @param c the Catalog to be saved */ ! void saveLoadedCatalog(String catalogId, CatalogImpl c) { loadedCatalogs.put(catalogId, c); } /** * Returns a count of all loaded catalogs, including delegate catalogs.
< prev index next >