KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > xerces > jaxp > validation > Util


1 /*
2  * Copyright 2005 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16
17 package org.apache.xerces.jaxp.validation;
18
19 import javax.xml.transform.stream.StreamSource JavaDoc;
20
21 import org.apache.xerces.xni.XNIException;
22 import org.apache.xerces.xni.parser.XMLInputSource;
23 import org.apache.xerces.xni.parser.XMLParseException;
24 import org.xml.sax.SAXException JavaDoc;
25 import org.xml.sax.SAXParseException JavaDoc;
26
27 /**
28  * <p>Static utility methods for the Validation API implementation.</p>
29  *
30  * @author Kohsuke Kawaguchi (kohsuke.kawaguchi@sun.com)
31  * @version $Id: Util.java,v 1.2 2005/06/05 19:24:56 mrglavas Exp $
32  */

33 final class Util {
34     
35     /**
36      * Creates a proper {@link XMLInputSource} from a {@link StreamSource}.
37      *
38      * @return always return non-null valid object.
39      */

40     public static final XMLInputSource toXMLInputSource( StreamSource JavaDoc in ) {
41         if( in.getReader()!=null )
42             return new XMLInputSource(
43             in.getPublicId(), in.getSystemId(), in.getSystemId(),
44             in.getReader(), null );
45         if( in.getInputStream()!=null )
46             return new XMLInputSource(
47             in.getPublicId(), in.getSystemId(), in.getSystemId(),
48             in.getInputStream(), null );
49         
50         return new XMLInputSource(
51         in.getPublicId(), in.getSystemId(), in.getSystemId() );
52     }
53     
54     /**
55      * Reconstructs {@link SAXException} from XNIException.
56      */

57     public static SAXException JavaDoc toSAXException(XNIException e) {
58         if(e instanceof XMLParseException)
59             return toSAXParseException((XMLParseException)e);
60         if( e.getException() instanceof SAXException JavaDoc )
61             return (SAXException JavaDoc)e.getException();
62         return new SAXException JavaDoc(e.getMessage(),e.getException());
63     }
64     
65     public static SAXParseException JavaDoc toSAXParseException( XMLParseException e ) {
66         if( e.getException() instanceof SAXParseException JavaDoc )
67             return (SAXParseException JavaDoc)e.getException();
68         return new SAXParseException JavaDoc( e.getMessage(),
69         e.getPublicId(), e.getExpandedSystemId(),
70         e.getLineNumber(), e.getColumnNumber(),
71         e.getException() );
72     }
73     
74 } // Util
75
Popular Tags