1 /* 2 * Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. Oracle designates this 8 * particular file as subject to the "Classpath" exception as provided 9 * by Oracle in the LICENSE file that accompanied this code. 10 * 11 * This code is distributed in the hope that it will be useful, but WITHOUT 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 * version 2 for more details (a copy is included in the LICENSE file that 15 * accompanied this code). 16 * 17 * You should have received a copy of the GNU General Public License version 18 * 2 along with this work; if not, write to the Free Software Foundation, 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 */ 25 package javax.xml.catalog; 26 27 28 /** 29 * The Catalog Manager manages the creation of XML Catalogs and Catalog Resolvers. 30 * 31 * @since 9 32 */ 33 public final class CatalogManager { 34 /** 35 * Creating CatalogManager instance is not allowed. 36 */ 37 private CatalogManager() { 38 } 39 40 /** 41 * Creates a {@code Catalog} object using the specified feature settings and 42 * path to one or more catalog files. 43 * <p> 44 * If {@code paths} is empty, system property {@code javax.xml.catalog.files} 45 * will be read to locate the initial list of catalog files. 46 * <p> 47 * If more than one catalog files are specified through the paths argument or 48 * {@code javax.xml.catalog.files} property, the first entry is considered 49 * the main catalog, while others are treated as alternative catalogs after 50 * those referenced by the {@code nextCatalog} elements in the main catalog. 51 * <p> 52 * As specified in 53 * <a href="https://www.oasis-open.org/committees/download.php/14809/xml-catalogs.html#s.res.fail"> 54 * XML Catalogs, OASIS Standard V1.1</a>, invalid path entries will be ignored. 55 * No error will be reported. In case all entries are invalid, the resolver 56 * will return as no mapping is found. 57 * 58 * @param features the catalog features 59 * @param paths path(s) to one or more catalogs. 60 * 61 * @return an instance of a {@code Catalog} 62 * @throws CatalogException If an error occurs while parsing the catalog 63 */ 64 public static Catalog catalog(CatalogFeatures features, String... paths) { 65 CatalogImpl catalog = new CatalogImpl(features, paths); 66 catalog.load(); 67 return catalog; 68 } 69 70 /** 71 * Creates an instance of a {@code CatalogResolver} using the specified catalog. 72 * 73 * @param catalog the catalog instance 74 * @return an instance of a {@code CatalogResolver} 75 */ 76 public static CatalogResolver catalogResolver(Catalog catalog) { 77 if (catalog == null) CatalogMessages.reportNPEOnNull("catalog", null); 78 return new CatalogResolverImpl(catalog); 79 } 80 81 /** 82 * Creates an instance of a {@code CatalogResolver} using the specified feature 83 * settings and path to one or more catalog files. 84 * <p> 85 * If {@code paths} is empty, system property {@code javax.xml.catalog.files} 86 * will be read to locate the initial list of catalog files. 87 * <p> 88 * If more than one catalog files are specified through the paths argument or 89 * {@code javax.xml.catalog.files} property, the first entry is considered 90 * the main catalog, while others are treated as alternative catalogs after 91 * those referenced by the {@code nextCatalog} elements in the main catalog. 92 * <p> 93 * As specified in 94 * <a href="https://www.oasis-open.org/committees/download.php/14809/xml-catalogs.html#s.res.fail"> 95 * XML Catalogs, OASIS Standard V1.1</a>, invalid path entries will be ignored. 96 * No error will be reported. In case all entries are invalid, the resolver 97 * will return as no mapping is found. 98 * 99 * @param features the catalog features 100 * @param paths the path(s) to one or more catalogs 101 * 102 * @return an instance of a {@code CatalogResolver} 103 * @throws CatalogException If an error occurs while parsing the catalog 104 */ 105 public static CatalogResolver catalogResolver(CatalogFeatures features, String... paths) { 106 Catalog catalog = catalog(features, paths); 107 return new CatalogResolverImpl(catalog); 108 } 109 }