01: /*
02: * $Id: StaxEntityResolverWrapper.java,v 1.2 2006/04/01 06:01:47 jeffsuttor Exp $
03: */
04:
05: /*
06: * The contents of this file are subject to the terms
07: * of the Common Development and Distribution License
08: * (the License). You may not use this file except in
09: * compliance with the License.
10: *
11: * You can obtain a copy of the license at
12: * https://glassfish.dev.java.net/public/CDDLv1.0.html.
13: * See the License for the specific language governing
14: * permissions and limitations under the License.
15: *
16: * When distributing Covered Code, include this CDDL
17: * Header Notice in each file and include the License file
18: * at https://glassfish.dev.java.net/public/CDDLv1.0.html.
19: * If applicable, add the following below the CDDL Header,
20: * with the fields enclosed by brackets [] replaced by
21: * you own identifying information:
22: * "Portions Copyrighted [year] [name of copyright owner]"
23: *
24: * [Name of File] [ver.__] [Date]
25: *
26: * Copyright 2006 Sun Microsystems Inc. All Rights Reserved
27: */
28:
29: package com.sun.xml.stream;
30:
31: import java.io.InputStream;
32: import javax.xml.stream.XMLEventReader;
33: import javax.xml.stream.XMLResolver;
34: import javax.xml.stream.XMLStreamException;
35: import javax.xml.stream.XMLStreamReader;
36: import com.sun.xml.stream.xerces.xni.XMLResourceIdentifier;
37: import com.sun.xml.stream.xerces.xni.XNIException;
38: import com.sun.xml.stream.xerces.xni.parser.XMLInputSource;
39:
40: /**
41: *
42: * @author Neeraj Bajaj
43: */
44: public class StaxEntityResolverWrapper {
45:
46: XMLResolver fStaxResolver;
47:
48: /** Creates a new instance of StaxEntityResolverWrapper */
49: public StaxEntityResolverWrapper(XMLResolver resolver) {
50: fStaxResolver = resolver;
51: }
52:
53: public void setStaxEntityResolver(XMLResolver resolver) {
54: fStaxResolver = resolver;
55: }
56:
57: public XMLResolver getStaxEntityResolver() {
58: return fStaxResolver;
59: }
60:
61: public StaxXMLInputSource resolveEntity(
62: XMLResourceIdentifier resourceIdentifier)
63: throws XNIException, java.io.IOException {
64: Object object = null;
65: try {
66: object = fStaxResolver.resolveEntity(resourceIdentifier
67: .getPublicId(), resourceIdentifier
68: .getLiteralSystemId(), resourceIdentifier
69: .getBaseSystemId(), null);
70: return getStaxInputSource(object);
71: } catch (XMLStreamException streamException) {
72: throw new XNIException(streamException);
73: }
74: }
75:
76: StaxXMLInputSource getStaxInputSource(Object object) {
77: if (object == null)
78: return null;
79:
80: if (object instanceof java.io.InputStream) {
81: return new StaxXMLInputSource(new XMLInputSource(null,
82: null, null, (InputStream) object, null));
83: } else if (object instanceof XMLStreamReader) {
84: return new StaxXMLInputSource((XMLStreamReader) object);
85: } else if (object instanceof XMLEventReader) {
86: return new StaxXMLInputSource((XMLEventReader) object);
87: }
88:
89: return null;
90: }
91: }//class StaxEntityResolverWrapper
|