01: /*
02: * This file is part of the WfMOpen project.
03: * Copyright (C) 2001-2003 Danet GmbH (www.danet.de), GS-AN.
04: * All rights reserved.
05: *
06: * This program is free software; you can redistribute it and/or modify
07: * it under the terms of the GNU General Public License as published by
08: * the Free Software Foundation; either version 2 of the License, or
09: * (at your option) any later version.
10: *
11: * This program 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
14: * GNU General Public License for more details.
15: *
16: * You should have received a copy of the GNU General Public License
17: * along with this program; if not, write to the Free Software
18: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19: *
20: * $Id: JAREntityResolver.java,v 1.2 2006/09/29 12:32:10 drmlipp Exp $
21: *
22: * $Log: JAREntityResolver.java,v $
23: * Revision 1.2 2006/09/29 12:32:10 drmlipp
24: * Consistently using WfMOpen as projct name now.
25: *
26: * Revision 1.1.1.1 2003/06/30 20:05:17 drmlipp
27: * Initial import
28: *
29: * Revision 1.7 2003/06/27 08:51:44 lipp
30: * Fixed copyright/license information.
31: *
32: * Revision 1.6 2003/03/31 16:50:28 huaiyang
33: * Logging using common-logging.
34: *
35: * Revision 1.5 2002/08/14 07:45:29 lipp
36: * Better log message.
37: *
38: * Revision 1.4 2002/07/08 19:37:06 lipp
39: * Improved error logging.
40: *
41: * Revision 1.3 2001/10/12 14:17:05 montag
42: * Can now parse the test example.
43: *
44: *
45: *
46: */
47: package de.danet.an.workflow.util;
48:
49: import java.io.InputStream;
50:
51: import org.xml.sax.EntityResolver;
52: import org.xml.sax.InputSource;
53:
54: /**
55: * Resolve an entity description from a jar archive.
56: * For example, if there is a file push_abo_data.dtd
57: * in the jar file, a sax or dom parser reading xml content
58: * refering to that dtd must have this entitiyresolver.<p>
59: * The resolver is set via the <code>setEntityResolver()</code>
60: * method.
61: */
62: public class JAREntityResolver implements EntityResolver {
63:
64: private static final org.apache.commons.logging.Log logger = org.apache.commons.logging.LogFactory
65: .getLog(JAREntityResolver.class);
66:
67: /**
68: * Allow to resolve external entities.
69: * @param publicId The public identifier of the external entity being
70: * referenced, or null if none was supplied.
71: * @param systemId The system identifier of the external entity being
72: * referenced.
73: * @return An InputSource object describing the new input source, or null
74: * to request that the parser open a regular URI connection to the system
75: * identifier.
76: */
77: public InputSource resolveEntity(String publicId, String systemId) {
78: // determine dtdname from given path
79: if (systemId == null) {
80: logger
81: .warn("Cannot resolve entity without systemId (publicId: \""
82: + publicId + "\")");
83: return null;
84: }
85: String dtdName = systemId.substring(systemId.lastIndexOf("/"));
86: InputStream is = getClass().getResourceAsStream(dtdName);
87: if (is == null) {
88: logger.warn("Cannot resolve " + publicId + ", " + systemId);
89: return null;
90: }
91: return new InputSource(is);
92: }
93:
94: }
|