Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/src/java.xml/share/classes/org/xml/sax/EntityResolver.java
40948 views
1
/*
2
* Copyright (c) 2000, 2020, 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
package org.xml.sax;
27
28
import java.io.IOException;
29
30
31
/**
32
* Basic interface for resolving entities.
33
*
34
* <p>If a SAX application needs to implement customized handling
35
* for external entities, it must implement this interface and
36
* register an instance with the SAX driver using the
37
* {@link org.xml.sax.XMLReader#setEntityResolver setEntityResolver}
38
* method.</p>
39
*
40
* <p>The XML reader will then allow the application to intercept any
41
* external entities (including the external DTD subset and external
42
* parameter entities, if any) before including them.</p>
43
*
44
* <p>Many SAX applications will not need to implement this interface,
45
* but it will be especially useful for applications that build
46
* XML documents from databases or other specialised input sources,
47
* or for applications that use URI types other than URLs.</p>
48
*
49
* <p>The following resolver would provide the application
50
* with a special character stream for the entity with the system
51
* identifier "http://www.myhost.com/today":</p>
52
*
53
* <pre>
54
* import org.xml.sax.EntityResolver;
55
* import org.xml.sax.InputSource;
56
*
57
* public class MyResolver implements EntityResolver {
58
* public InputSource resolveEntity (String publicId, String systemId)
59
* {
60
* if (systemId.equals("http://www.myhost.com/today")) {
61
* // return a special input source
62
* MyReader reader = new MyReader();
63
* return new InputSource(reader);
64
* } else {
65
* // use the default behaviour
66
* return null;
67
* }
68
* }
69
* }
70
* </pre>
71
*
72
* <p>The application can also use this interface to redirect system
73
* identifiers to local URIs or to look up replacements in a catalog
74
* (possibly by using the public identifier).</p>
75
*
76
* @since 1.4, SAX 1.0
77
* @author David Megginson
78
* @see org.xml.sax.XMLReader#setEntityResolver
79
* @see org.xml.sax.InputSource
80
*/
81
public interface EntityResolver {
82
83
84
/**
85
* Allow the application to resolve external entities.
86
*
87
* <p>The parser will call this method before opening any external
88
* entity except the top-level document entity. Such entities include
89
* the external DTD subset and external parameter entities referenced
90
* within the DTD (in either case, only if the parser reads external
91
* parameter entities), and external general entities referenced
92
* within the document element (if the parser reads external general
93
* entities). The application may request that the parser locate
94
* the entity itself, that it use an alternative URI, or that it
95
* use data provided by the application (as a character or byte
96
* input stream).</p>
97
*
98
* <p>Application writers can use this method to redirect external
99
* system identifiers to secure and/or local URIs, to look up
100
* public identifiers in a catalogue, or to read an entity from a
101
* database or other input source (including, for example, a dialog
102
* box). Neither XML nor SAX specifies a preferred policy for using
103
* public or system IDs to resolve resources. However, SAX specifies
104
* how to interpret any InputSource returned by this method, and that
105
* if none is returned, then the system ID will be dereferenced as
106
* a URL. </p>
107
*
108
* <p>If the system identifier is a URL, the SAX parser must
109
* resolve it fully before reporting it to the application.</p>
110
*
111
* @param publicId The public identifier of the external entity
112
* being referenced, or null if none was supplied.
113
* @param systemId The system identifier of the external entity
114
* being referenced.
115
* @return An InputSource object describing the new input source,
116
* or null to request that the parser open a regular
117
* URI connection to the system identifier.
118
* @throws org.xml.sax.SAXException Any SAX exception, possibly
119
* wrapping another exception.
120
* @throws java.io.IOException A Java-specific IO exception,
121
* possibly the result of creating a new InputStream
122
* or Reader for the InputSource.
123
* @see org.xml.sax.InputSource
124
*/
125
public abstract InputSource resolveEntity (String publicId,
126
String systemId)
127
throws SAXException, IOException;
128
129
}
130
131
// end of EntityResolver.java
132
133