2 * Copyright (C) 2008 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
6 * The contents of this file are subject to the Mozilla Public License Version 1.1
7 * See LICENSE.TXT at the top of this package for the full license terms.
10 package eu
.etaxonomy
.cdm
.io
.jaxb
;
12 import java
.io
.IOException
;
13 import java
.util
.Properties
;
15 import org
.apache
.commons
.logging
.Log
;
16 import org
.apache
.commons
.logging
.LogFactory
;
17 import org
.apache
.xml
.resolver
.CatalogManager
;
18 import org
.apache
.xml
.resolver
.tools
.CatalogResolver
;
19 import org
.w3c
.dom
.ls
.LSInput
;
20 import org
.w3c
.dom
.ls
.LSResourceResolver
;
21 import org
.xml
.sax
.InputSource
;
24 * Copied from CATE (@author ben.clark). Not used at this point.
26 public class CdmResourceResolver
implements LSResourceResolver
{
27 private final CatalogResolver catalogResolver
;
28 private static Log log
= LogFactory
.getLog(CdmResourceResolver
.class);
30 public CdmResourceResolver() throws IOException
{
31 Properties properties
= new Properties();
32 if(log
.isInfoEnabled()) {
33 log
.info("Loading /CatalogManager.properties");
35 properties
.load(this.getClass().getResourceAsStream("/CatalogManager.properties"));
37 String
[] catalogFileNames
= properties
.getProperty("catalogs").split(",");
39 CatalogManager catalogManager
= new CatalogManager();
40 catalogManager
.setRelativeCatalogs(true);
41 catalogResolver
= new CatalogResolver(catalogManager
);
43 for(String catalogFileName
: catalogFileNames
) {
44 if(log
.isInfoEnabled()) {
45 log
.info("Parsing " + catalogFileName
);
47 catalogResolver
.getCatalog().parseCatalog(this.getClass().getResource(catalogFileName
));
51 public LSInput
resolveResource(String type
, String namespaceURI
, String publicId
, String systemId
, String baseURI
) {
53 if(log
.isInfoEnabled()) {
54 log
.info("Resolving " + namespaceURI
+ " with systemId " + systemId
+ ", trying " + systemId
);
56 InputSource inputSource
= catalogResolver
.resolveEntity( publicId
, systemId
);
57 if ( inputSource
== null ) {
58 if(log
.isInfoEnabled()) {
59 log
.info("Not found in filesystem: Looking in jar files for /schema/cdm/" + systemId
);
61 inputSource
= new InputSource(this.getClass().getResourceAsStream("/schema/cdm/" + systemId
));
63 if(inputSource
== null) {
64 if(log
.isWarnEnabled()) {
65 log
.warn(namespaceURI
+ " not found");
71 if(log
.isInfoEnabled()) {
72 // log.info("Resource found");
74 LsInputImpl lsInput
= new LsInputImpl();
75 lsInput
.setByteStream( inputSource
.getByteStream() );
76 lsInput
.setCharacterStream( inputSource
.getCharacterStream() );
77 lsInput
.setPublicId( inputSource
.getPublicId() );
78 lsInput
.setSystemId( inputSource
.getSystemId() );
79 lsInput
.setEncoding( inputSource
.getEncoding() );