12005
|
1 |
/*
|
|
2 |
* Copyright (c) 2000, 2005, Oracle and/or its affiliates. All rights reserved.
|
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
|
4 |
*
|
|
5 |
* This code is free software; you can redistribute it and/or modify it
|
|
6 |
* under the terms of the GNU General Public License version 2 only, as
|
|
7 |
* published by the Free Software Foundation. Oracle designates this
|
|
8 |
* particular file as subject to the "Classpath" exception as provided
|
|
9 |
* by Oracle in the LICENSE file that accompanied this code.
|
|
10 |
*
|
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT
|
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that
|
|
15 |
* accompanied this code).
|
|
16 |
*
|
|
17 |
* You should have received a copy of the GNU General Public License version
|
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation,
|
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
20 |
*
|
|
21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
|
22 |
* or visit www.oracle.com if you need additional information or have any
|
|
23 |
* questions.
|
|
24 |
*/
|
|
25 |
|
|
26 |
// SAX entity resolver.
|
|
27 |
// http://www.saxproject.org
|
|
28 |
// No warranty; no copyright -- use this as you will.
|
|
29 |
// $Id: EntityResolver.java,v 1.2 2004/11/03 22:44:52 jsuttor Exp $
|
|
30 |
|
|
31 |
package org.xml.sax;
|
|
32 |
|
|
33 |
import java.io.IOException;
|
|
34 |
|
|
35 |
|
|
36 |
/**
|
|
37 |
* Basic interface for resolving entities.
|
|
38 |
*
|
|
39 |
* <blockquote>
|
|
40 |
* <em>This module, both source code and documentation, is in the
|
|
41 |
* Public Domain, and comes with <strong>NO WARRANTY</strong>.</em>
|
|
42 |
* See <a href='http://www.saxproject.org'>http://www.saxproject.org</a>
|
|
43 |
* for further information.
|
|
44 |
* </blockquote>
|
|
45 |
*
|
|
46 |
* <p>If a SAX application needs to implement customized handling
|
|
47 |
* for external entities, it must implement this interface and
|
|
48 |
* register an instance with the SAX driver using the
|
|
49 |
* {@link org.xml.sax.XMLReader#setEntityResolver setEntityResolver}
|
|
50 |
* method.</p>
|
|
51 |
*
|
|
52 |
* <p>The XML reader will then allow the application to intercept any
|
|
53 |
* external entities (including the external DTD subset and external
|
|
54 |
* parameter entities, if any) before including them.</p>
|
|
55 |
*
|
|
56 |
* <p>Many SAX applications will not need to implement this interface,
|
|
57 |
* but it will be especially useful for applications that build
|
|
58 |
* XML documents from databases or other specialised input sources,
|
|
59 |
* or for applications that use URI types other than URLs.</p>
|
|
60 |
*
|
|
61 |
* <p>The following resolver would provide the application
|
|
62 |
* with a special character stream for the entity with the system
|
|
63 |
* identifier "http://www.myhost.com/today":</p>
|
|
64 |
*
|
|
65 |
* <pre>
|
|
66 |
* import org.xml.sax.EntityResolver;
|
|
67 |
* import org.xml.sax.InputSource;
|
|
68 |
*
|
|
69 |
* public class MyResolver implements EntityResolver {
|
|
70 |
* public InputSource resolveEntity (String publicId, String systemId)
|
|
71 |
* {
|
|
72 |
* if (systemId.equals("http://www.myhost.com/today")) {
|
|
73 |
* // return a special input source
|
|
74 |
* MyReader reader = new MyReader();
|
|
75 |
* return new InputSource(reader);
|
|
76 |
* } else {
|
|
77 |
* // use the default behaviour
|
|
78 |
* return null;
|
|
79 |
* }
|
|
80 |
* }
|
|
81 |
* }
|
|
82 |
* </pre>
|
|
83 |
*
|
|
84 |
* <p>The application can also use this interface to redirect system
|
|
85 |
* identifiers to local URIs or to look up replacements in a catalog
|
|
86 |
* (possibly by using the public identifier).</p>
|
|
87 |
*
|
25262
|
88 |
* @since 1.4, SAX 1.0
|
12005
|
89 |
* @author David Megginson
|
|
90 |
* @see org.xml.sax.XMLReader#setEntityResolver
|
|
91 |
* @see org.xml.sax.InputSource
|
|
92 |
*/
|
|
93 |
public interface EntityResolver {
|
|
94 |
|
|
95 |
|
|
96 |
/**
|
|
97 |
* Allow the application to resolve external entities.
|
|
98 |
*
|
|
99 |
* <p>The parser will call this method before opening any external
|
|
100 |
* entity except the top-level document entity. Such entities include
|
|
101 |
* the external DTD subset and external parameter entities referenced
|
|
102 |
* within the DTD (in either case, only if the parser reads external
|
|
103 |
* parameter entities), and external general entities referenced
|
|
104 |
* within the document element (if the parser reads external general
|
|
105 |
* entities). The application may request that the parser locate
|
|
106 |
* the entity itself, that it use an alternative URI, or that it
|
|
107 |
* use data provided by the application (as a character or byte
|
|
108 |
* input stream).</p>
|
|
109 |
*
|
|
110 |
* <p>Application writers can use this method to redirect external
|
|
111 |
* system identifiers to secure and/or local URIs, to look up
|
|
112 |
* public identifiers in a catalogue, or to read an entity from a
|
|
113 |
* database or other input source (including, for example, a dialog
|
|
114 |
* box). Neither XML nor SAX specifies a preferred policy for using
|
|
115 |
* public or system IDs to resolve resources. However, SAX specifies
|
|
116 |
* how to interpret any InputSource returned by this method, and that
|
|
117 |
* if none is returned, then the system ID will be dereferenced as
|
|
118 |
* a URL. </p>
|
|
119 |
*
|
|
120 |
* <p>If the system identifier is a URL, the SAX parser must
|
|
121 |
* resolve it fully before reporting it to the application.</p>
|
|
122 |
*
|
|
123 |
* @param publicId The public identifier of the external entity
|
|
124 |
* being referenced, or null if none was supplied.
|
|
125 |
* @param systemId The system identifier of the external entity
|
|
126 |
* being referenced.
|
|
127 |
* @return An InputSource object describing the new input source,
|
|
128 |
* or null to request that the parser open a regular
|
|
129 |
* URI connection to the system identifier.
|
|
130 |
* @exception org.xml.sax.SAXException Any SAX exception, possibly
|
|
131 |
* wrapping another exception.
|
|
132 |
* @exception java.io.IOException A Java-specific IO exception,
|
|
133 |
* possibly the result of creating a new InputStream
|
|
134 |
* or Reader for the InputSource.
|
|
135 |
* @see org.xml.sax.InputSource
|
|
136 |
*/
|
|
137 |
public abstract InputSource resolveEntity (String publicId,
|
|
138 |
String systemId)
|
|
139 |
throws SAXException, IOException;
|
|
140 |
|
|
141 |
}
|
|
142 |
|
|
143 |
// end of EntityResolver.java
|