| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 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 |
|
| 20 |
|
| 21 |
|
| 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 |
|
| 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 |
|