01: /*
02: OctopusEntityResolver - Class used for validating XML files using schema.
03:
04: Copyright (C) 2002-2003 Together
05:
06: This library is free software; you can redistribute it and/or
07: modify it under the terms of the GNU Lesser General Public
08: License as published by the Free Software Foundation; either
09: version 2.1 of the License, or (at your option) any later version.
10:
11: This library is distributed in the hope that it will be useful,
12: but WITHOUT ANY WARRANTY; without even the implied warranty of
13: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14: Lesser General Public License for more details.
15:
16: You should have received a copy of the GNU Lesser General Public
17: License along with this library; if not, write to the Free Software
18: Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19:
20: OctopusEntityResolver.java
21: Date: 25.6.2004.
22: @version 1.0
23: @author: Zeljko Kovacevic zeljko@prozone.co.yu
24: */
25:
26: package org.webdocwf.util.loader;
27:
28: import java.io.File;
29: import java.io.FileInputStream;
30: import java.io.FileNotFoundException;
31:
32: import org.xml.sax.EntityResolver;
33: import org.xml.sax.InputSource;
34:
35: /**
36: * OctopusEntityResolver
37: * @author Zeljko Kovacevic
38: * @version 1.0
39: */
40: public class OctopusEntityResolver implements EntityResolver {
41:
42: //constructor
43: public OctopusEntityResolver() {
44: }
45:
46: public InputSource resolveEntity(String publicId, String systemId) {
47: if (true) {
48: // for first mapping
49: String OCTOPUS_HOME = System.getProperty("OCTOPUS_HOME");
50: if (OCTOPUS_HOME == null) {
51: return new InputSource(getClass().getClassLoader()
52: .getResourceAsStream(
53: "xml/xmlschema/loaderJob.xsd"));
54: } else {
55: try {
56: return new InputSource(
57: new FileInputStream(
58: new File(
59: OCTOPUS_HOME
60: + "/XmlTransform/xml/xmlschema/loaderJob.xsd")));
61: } catch (Exception e) {
62: try {
63: return new InputSource(getClass()
64: .getClassLoader().getResourceAsStream(
65: "xml/xmlschema/loaderJob.xsd"));
66: } catch (Exception ex) {
67: return null;
68: }
69: }
70: }
71: }
72:
73: else {
74: // use the default behaviour
75: return null;
76: }
77: }
78: }
|