KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > hp > hpl > jena > rdf > arp > ARP


1 /*
2  * (c) Copyright 2001, 2002, 2003, 2004, 2005 Hewlett-Packard Development Company, LP
3  * (c) Copyright 2003, Plugged In Software
4  *
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  * 1. Redistributions of source code must retain the above copyright
11  * notice, this list of conditions and the following disclaimer.
12  * 2. Redistributions in binary form must reproduce the above copyright
13  * notice, this list of conditions and the following disclaimer in the
14  * documentation and/or other materials provided with the distribution.
15  * 3. The name of the author may not be used to endorse or promote products
16  * derived from this software without specific prior written permission.
17
18  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28  *
29    $Id: ARP.java,v 1.19 2005/04/11 11:54:24 jeremy_carroll Exp $
30    AUTHOR: Jeremy J. Carroll
31    with modification from PI Software
32 */

33 /*
34  * ARP.java
35  *
36  * Created on June 22, 2001, 6:20 AM
37     *
38     * *
39     *Possible options
40     *
41     * embedded RDF
42     *
43     *
44     *
45  */

46
47 package com.hp.hpl.jena.rdf.arp;
48 import org.xml.sax.ErrorHandler JavaDoc;
49 import org.xml.sax.SAXException JavaDoc;
50 import java.io.IOException JavaDoc;
51 import org.xml.sax.InputSource JavaDoc;
52 import org.xml.sax.Locator JavaDoc;
53 import java.io.InputStream JavaDoc;
54 import java.io.Reader JavaDoc;
55
56
57 /** Another RDF Parser.
58  * To load an RDF file:
59  * <ol>
60  * <li>Create an ARP.</li>
61  * <li>Set its handlers, by calling the {@link #getHandlers}
62  * method, and then.</li>
63  * <ul>
64  * <li>Setting the statement handler.</li>
65  * <li>Optionally setting the other handlers.</li>
66  * </ul>
67  *
68  * </li>
69  * <li>Call a load method.</li>
70  * </ol>
71  * <p>
72  * Xerces is used for parsing the XML.
73  * The SAXEvents generated by Xerces are then
74  * analysed as RDF by ARP.
75  * Errors may occur
76  * in either the XML or the RDF part, see
77  * {@link ARPHandlers#setErrorHandler} for details
78  * of how to distinguish between them.</p>
79  * <p>
80  * For very large files, ARP does not use any additional
81  * memory except when either the {@link ExtendedHandler#discardNodesWithNodeID}
82  * returns false or when the {@link AResource#setUserData} method has been
83  * used. In these cases ARP needs to remember the <code>rdf:nodeID</code>
84  * usage through the file life time. </p>
85  * <p>See <a HREF="../../../../../../../ARP/index.html">ARP documentation</a> for more information.</p>
86  * @author Jeremy Carroll with contributions from Simon Raboczi
87  * and Andrew Newman
88  */

89 public class ARP implements ARPConfig
90 {
91
92     final private SingleThreadedParser arpf;
93     
94 /** Creates a new RDF Parser.
95  * Can parse one file at a time.
96  */

97     public ARP() {
98         arpf = SingleThreadedParser.create();
99     }
100     /**
101  * When parsing a file, this returns a Locator giving the
102  * position of the last XML event processed by ARP.
103  * This may return null or misleading results before any
104  * tokens have been processed.
105  * @return Locator
106  */

107     public Locator JavaDoc getLocator() {
108         return arpf.getLocator();
109     }
110     
111 /** Load RDF/XML from a Reader.
112  * @param in The input XML document.
113  * @param xmlBase The base URI for the document.
114  * @throws SAXException More serious error during XML or RDF processing; or thrown from the fatalError method of the ErrorHandler.
115  * @throws IOException Occurring during XML processing.
116  */

117     public void load(Reader JavaDoc in,String JavaDoc xmlBase) throws SAXException JavaDoc, IOException JavaDoc {
118         InputSource JavaDoc inputS = new InputSource JavaDoc(in);
119         inputS.setSystemId(xmlBase);
120          arpf.parse(inputS);
121     }
122     void load(InputSource JavaDoc is) throws SAXException JavaDoc, IOException JavaDoc {
123         arpf.parse(is);
124     }
125 /** Load RDF/XML from an InputStream.
126  * @param in The input XML document.
127  * @param xmlBase The base URI for the document.
128  * @throws SAXException More serious error during XML or RDF processing; or thrown from the fatalError method of the ErrorHandler.
129  * @throws IOException Occurring during XML processing.
130  */

131     public void load(InputStream JavaDoc in,String JavaDoc xmlBase) throws SAXException JavaDoc,
132 IOException JavaDoc {
133         //load(new InputStreamReader(in),xmlBase);
134
InputSource JavaDoc inputS = new InputSource JavaDoc(in);
135         inputS.setSystemId(xmlBase);
136         arpf.parse(inputS, xmlBase);
137     }
138 /** Load RDF/XML from an InputStream, using base URL http://unknown.org/.
139  * @param in The input XML document.
140  * @throws SAXException More serious error during XML or RDF processing; or thrown from the fatalError method of the ErrorHandler.
141  * @throws IOException Occurring during XML processing.
142  */

143     public void load(InputStream JavaDoc in)
144      throws SAXException JavaDoc, IOException JavaDoc {
145         load(in,"");
146     }
147 /** Load RDF/XML from a Reader, using base URL http://unknown.org/.
148  * @param in The input XML document.
149  * @throws SAXException More serious error during XML or RDF processing; or thrown from the fatalError method of the ErrorHandler.
150  * @throws IOException Occurring during XML processing.
151  */

152     public void load(Reader JavaDoc in) throws SAXException JavaDoc, IOException JavaDoc {
153         load(in,"");
154     }
155     /**
156      * The handlers used during parsing.
157      * The handlers can be changed by calling this method
158      * and then using the <code>set..Handler</code> methods
159      * in {@link ARPHandlers}.
160      * The handlers can be copied onto another ARP instance
161      * using the {@link #setHandlersWith} method.
162      * @see ARPHandlers#setStatementHandler(StatementHandler)
163      * @see ARPHandlers#setErrorHandler(ErrorHandler)
164      * @see ARPHandlers#setExtendedHandler(ExtendedHandler)
165      * @see ARPHandlers#setNamespaceHandler(NamespaceHandler)
166      * @see #setHandlersWith
167      * @return The handlers used during parsing.
168      */

169     public ARPHandlers getHandlers() {
170         return arpf.getHandlers();
171     }
172     /**
173      * Copies the handlers from the argument
174      * to be used by this instance.
175      * To make further modifications it is necessary
176      * to call {@link #getHandlers} to retrieve this
177      * instance's copy of the handler information.
178      * @param handlers The new values to use.
179      */

180     public void setHandlersWith(ARPHandlers handlers){
181         arpf.setHandlersWith(handlers);
182     }
183     /**
184      * The options used during parsing.
185      * The options can be changed by calling this method
186      * and then using the <code>set..</code> methods
187      * in {@link ARPOptions}.
188      * The options can be copied onto another ARP instance
189      * using the {@link #setOptionsWith} method.
190      * @see ARPOptions#setDefaultErrorMode()
191      * @see ARPOptions#setLaxErrorMode()
192      * @see ARPOptions#setStrictErrorMode()
193      * @see ARPOptions#setStrictErrorMode(int)
194      * @see ARPOptions#setEmbedding(boolean)
195      * @see ARPOptions#setErrorMode(int, int)
196      *
197      * @see #setOptionsWith
198      * @return The handlers used during parsing.
199      */

200     
201     public ARPOptions getOptions(){
202         return arpf.getOptions();
203     }
204
205     /**
206      * Copies the options from the argument
207      * to be used by this instance.
208      * To make further modifications it is necessary
209      * to call {@link #getOptions} to retrieve this
210      * instance's copy of the options.
211      * @param opts The new values to use.
212      */

213     public void setOptionsWith(ARPOptions opts){
214         arpf.setOptionsWith(opts);
215     }
216     /**
217     @deprecated Use {@link #getHandlers}.{@link ARPHandlers#setExtendedHandler setExtendedHandler(eh)}
218      */

219     public ExtendedHandler setExtendedHandler(ExtendedHandler eh) {
220         
221         return getHandlers().setExtendedHandler(eh);
222     }
223     /**
224     @deprecated Use {@link #getHandlers}.{@link ARPHandlers#setNamespaceHandler setNamespaceHandler(nh)}
225      */

226     public NamespaceHandler setNamespaceHandler(NamespaceHandler nh) {
227
228         return getHandlers().setNamespaceHandler(nh);
229     }
230     /**
231     @deprecated Use {@link #getHandlers}.{@link ARPHandlers#setStatementHandler setStatementHandler(sh)}
232      */

233     public StatementHandler setStatementHandler(StatementHandler sh) {
234         
235         return getHandlers().setStatementHandler(sh);
236     }
237     /**
238     @deprecated Use {@link #getHandlers}.{@link ARPHandlers#setErrorHandler setErrorHandler(eh)}
239      */

240     public void setErrorHandler(ErrorHandler JavaDoc eh) {
241         getHandlers().setErrorHandler(eh);
242     }
243     /**
244     @deprecated Use {@link #getOptions}.{@link ARPOptions#setErrorMode(int,int) setErrorMode(errno,mode)}
245      */

246     public int setErrorMode(int errno, int mode) {
247         return
248         getOptions().setErrorMode(errno,mode);
249
250     }
251     /**
252     @deprecated Use {@link #getOptions}.{@link ARPOptions#setDefaultErrorMode() setDefaultErrorMode()}
253      */

254     public void setDefaultErrorMode() {
255
256         getOptions().setDefaultErrorMode();
257     }
258     /**
259     @deprecated Use {@link #getOptions}.{@link ARPOptions#setLaxErrorMode() setLaxErrorMode()}
260      */

261     public void setLaxErrorMode() {
262
263         getOptions().setLaxErrorMode();
264     }
265     /**
266     @deprecated Use {@link #getOptions}.{@link ARPOptions#setStrictErrorMode() setStrictErrorMode()}
267      */

268     public void setStrictErrorMode() {
269
270         getOptions().setStrictErrorMode();
271     }
272     /**
273     @deprecated Use {@link #getOptions}.{@link ARPOptions#setStrictErrorMode(int) setStrictErrorMode(nonErrorMode)}
274      */

275     public void setStrictErrorMode(int nonErrorMode) {
276
277         getOptions().setStrictErrorMode(nonErrorMode);
278     }
279     /**
280      @deprecated Use {@link #getOptions}.{@link ARPOptions#setEmbedding(boolean) setEmbedding(embed)}
281      */

282     public void setEmbedding(boolean embed) {
283         
284         getOptions().setEmbedding(embed);
285     }
286 }
287
Popular Tags