01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17:
18: package org.apache.xerces.jaxp.validation;
19:
20: import javax.xml.transform.stream.StreamSource;
21:
22: import org.apache.xerces.xni.XNIException;
23: import org.apache.xerces.xni.parser.XMLInputSource;
24: import org.apache.xerces.xni.parser.XMLParseException;
25: import org.xml.sax.SAXException;
26: import org.xml.sax.SAXParseException;
27:
28: /**
29: * <p>Static utility methods for the Validation API implementation.</p>
30: *
31: * @author Kohsuke Kawaguchi (kohsuke.kawaguchi@sun.com)
32: * @version $Id: Util.java 447235 2006-09-18 05:01:44Z mrglavas $
33: */
34: final class Util {
35:
36: /**
37: * Creates a proper {@link XMLInputSource} from a {@link StreamSource}.
38: *
39: * @return always return non-null valid object.
40: */
41: public static final XMLInputSource toXMLInputSource(StreamSource in) {
42: if (in.getReader() != null)
43: return new XMLInputSource(in.getPublicId(), in
44: .getSystemId(), in.getSystemId(), in.getReader(),
45: null);
46: if (in.getInputStream() != null)
47: return new XMLInputSource(in.getPublicId(), in
48: .getSystemId(), in.getSystemId(), in
49: .getInputStream(), null);
50:
51: return new XMLInputSource(in.getPublicId(), in.getSystemId(),
52: in.getSystemId());
53: }
54:
55: /**
56: * Reconstructs {@link SAXException} from XNIException.
57: */
58: public static SAXException toSAXException(XNIException e) {
59: if (e instanceof XMLParseException)
60: return toSAXParseException((XMLParseException) e);
61: if (e.getException() instanceof SAXException)
62: return (SAXException) e.getException();
63: return new SAXException(e.getMessage(), e.getException());
64: }
65:
66: public static SAXParseException toSAXParseException(
67: XMLParseException e) {
68: if (e.getException() instanceof SAXParseException)
69: return (SAXParseException) e.getException();
70: return new SAXParseException(e.getMessage(), e.getPublicId(), e
71: .getExpandedSystemId(), e.getLineNumber(), e
72: .getColumnNumber(), e.getException());
73: }
74:
75: } // Util
|