Debian Codegraph @

net/sf/saxon/trans/XmlCatalogResolver.java

raw symbols SCIP
1 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2 // Copyright (c) 2018 Saxonica Limited.
3 // This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
4 // If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
5 // This Source Code Form is "Incompatible With Secondary Licenses", as defined by the Mozilla Public License, v. 2.0.
6 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
7
8 package net.sf.saxon.trans;
9
10
11 import net.sf.saxon.Configuration;
12 import net.sf.saxon.Version;
13 import org.apache.xml.resolver.CatalogManager;
14 import org.apache.xml.resolver.helpers.Debug;
15
16 import javax.xml.transform.TransformerException;
17
18 /**
19 * Provides the interface to the Apache catalog resolver. This is in a separate class to ensure that no failure
20 * occurs if the resolver code is not on the classpath, unless catalog resolution is explicitly requested.
21 * The catalog file we assume is a URI
22 */
23
24 public class XmlCatalogResolver {
25
26 public static void setCatalog(String catalog, final Configuration config, boolean isTracing) throws XPathException {
27 System.setProperty("xml.catalog.files", catalog);
28 Version.platform.setDefaultSAXParserFactory(config);
29 if (isTracing) {
30 // Customize the resolver to write messages to the Saxon logging destination
31 CatalogManager.getStaticManager().debug = new Debug() {
32 @Override
33 public void message(int level, String message) {
34 if (level <= getDebug()) {
35 config.getStandardErrorOutput().println(message);
36 }
37 }
38
39 @Override
40 public void message(int level, String message, String spec) {
41 if (level <= getDebug()) {
42 config.getStandardErrorOutput().println(message + ": " + spec);
43 }
44 }
45
46 @Override
47 public void message(int level, String message, String spec1, String spec2) {
48 if (level <= getDebug()) {
49 config.getStandardErrorOutput().println(message + ": " + spec1);
50 config.getStandardErrorOutput().println("\t" + spec2);
51 }
52 }
53 };
54 if (CatalogManager.getStaticManager().getVerbosity() < 2) {
55 CatalogManager.getStaticManager().setVerbosity(2);
56 }
57 }
58 config.setSourceParserClass("org.apache.xml.resolver.tools.ResolvingXMLReader");
59 config.setStyleParserClass("org.apache.xml.resolver.tools.ResolvingXMLReader");
60 try {
61 config.setURIResolver(config.makeURIResolver("org.apache.xml.resolver.tools.CatalogResolver"));
62 } catch (TransformerException err) {
63 throw XPathException.makeXPathException(err);
64 }
65 }
66 }
67