author | joehw |
Thu, 21 Dec 2017 17:08:05 -0800 | |
changeset 48412 | d4412e380f6b |
parent 47216 | 71c04702a3d5 |
permissions | -rw-r--r-- |
6 | 1 |
/* |
2 |
* reserved comment block |
|
3 |
* DO NOT REMOVE OR ALTER! |
|
4 |
*/ |
|
5 |
/* |
|
44797
8b3b3b911b8a
8162572: Update License Header for all JAXP sources
joehw
parents:
39080
diff
changeset
|
6 |
* Licensed to the Apache Software Foundation (ASF) under one or more |
8b3b3b911b8a
8162572: Update License Header for all JAXP sources
joehw
parents:
39080
diff
changeset
|
7 |
* contributor license agreements. See the NOTICE file distributed with |
8b3b3b911b8a
8162572: Update License Header for all JAXP sources
joehw
parents:
39080
diff
changeset
|
8 |
* this work for additional information regarding copyright ownership. |
8b3b3b911b8a
8162572: Update License Header for all JAXP sources
joehw
parents:
39080
diff
changeset
|
9 |
* The ASF licenses this file to You under the Apache License, Version 2.0 |
8b3b3b911b8a
8162572: Update License Header for all JAXP sources
joehw
parents:
39080
diff
changeset
|
10 |
* (the "License"); you may not use this file except in compliance with |
8b3b3b911b8a
8162572: Update License Header for all JAXP sources
joehw
parents:
39080
diff
changeset
|
11 |
* the License. You may obtain a copy of the License at |
6 | 12 |
* |
13 |
* http://www.apache.org/licenses/LICENSE-2.0 |
|
14 |
* |
|
15 |
* Unless required by applicable law or agreed to in writing, software |
|
16 |
* distributed under the License is distributed on an "AS IS" BASIS, |
|
17 |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
18 |
* See the License for the specific language governing permissions and |
|
19 |
* limitations under the License. |
|
20 |
*/ |
|
21 |
||
22 |
package com.sun.org.apache.xerces.internal.jaxp.validation; |
|
23 |
||
24 |
import javax.xml.transform.stream.StreamSource; |
|
25 |
||
26 |
import com.sun.org.apache.xerces.internal.xni.XNIException; |
|
27 |
import com.sun.org.apache.xerces.internal.xni.parser.XMLInputSource; |
|
28 |
import com.sun.org.apache.xerces.internal.xni.parser.XMLParseException; |
|
29 |
import org.xml.sax.SAXException; |
|
30 |
import org.xml.sax.SAXParseException; |
|
31 |
||
32 |
/** |
|
33 |
* <p>Static utility methods for the Validation API implementation.</p> |
|
34 |
* |
|
48412 | 35 |
* @author Kohsuke Kawaguchi |
6 | 36 |
*/ |
37 |
final class Util { |
|
38 |
||
39 |
/** |
|
40 |
* Creates a proper {@link XMLInputSource} from a {@link StreamSource}. |
|
41 |
* |
|
42 |
* @return always return non-null valid object. |
|
43 |
*/ |
|
44 |
public static final XMLInputSource toXMLInputSource( StreamSource in ) { |
|
45 |
if( in.getReader()!=null ) |
|
46 |
return new XMLInputSource( |
|
47 |
in.getPublicId(), in.getSystemId(), in.getSystemId(), |
|
48 |
in.getReader(), null ); |
|
49 |
if( in.getInputStream()!=null ) |
|
50 |
return new XMLInputSource( |
|
51 |
in.getPublicId(), in.getSystemId(), in.getSystemId(), |
|
52 |
in.getInputStream(), null ); |
|
53 |
||
54 |
return new XMLInputSource( |
|
39080
57563e513b11
8158204: accessExternalSchema property handling is inconsistent and differs from spec.
joehw
parents:
25868
diff
changeset
|
55 |
in.getPublicId(), in.getSystemId(), in.getSystemId(), false ); |
6 | 56 |
} |
57 |
||
58 |
/** |
|
59 |
* Reconstructs {@link SAXException} from XNIException. |
|
60 |
*/ |
|
61 |
public static SAXException toSAXException(XNIException e) { |
|
62 |
if(e instanceof XMLParseException) |
|
63 |
return toSAXParseException((XMLParseException)e); |
|
64 |
if( e.getException() instanceof SAXException ) |
|
65 |
return (SAXException)e.getException(); |
|
66 |
return new SAXException(e.getMessage(),e.getException()); |
|
67 |
} |
|
68 |
||
69 |
public static SAXParseException toSAXParseException( XMLParseException e ) { |
|
70 |
if( e.getException() instanceof SAXParseException ) |
|
71 |
return (SAXParseException)e.getException(); |
|
72 |
return new SAXParseException( e.getMessage(), |
|
73 |
e.getPublicId(), e.getExpandedSystemId(), |
|
74 |
e.getLineNumber(), e.getColumnNumber(), |
|
75 |
e.getException() ); |
|
76 |
} |
|
77 |
||
78 |
} // Util |