286N/A/*
286N/A * reserved comment block
286N/A * DO NOT REMOVE OR ALTER!
286N/A */
286N/A/*
286N/A * Copyright 2005 The Apache Software Foundation.
286N/A *
286N/A * Licensed under the Apache License, Version 2.0 (the "License");
286N/A * you may not use this file except in compliance with the License.
286N/A * You may obtain a copy of the License at
286N/A *
286N/A * http://www.apache.org/licenses/LICENSE-2.0
286N/A *
286N/A * Unless required by applicable law or agreed to in writing, software
286N/A * distributed under the License is distributed on an "AS IS" BASIS,
286N/A * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
286N/A * See the License for the specific language governing permissions and
286N/A * limitations under the License.
286N/A */
286N/A
286N/Apackage com.sun.org.apache.xerces.internal.jaxp.validation;
286N/A
286N/Aimport javax.xml.transform.stream.StreamSource;
286N/A
286N/Aimport com.sun.org.apache.xerces.internal.xni.XNIException;
286N/Aimport com.sun.org.apache.xerces.internal.xni.parser.XMLInputSource;
286N/Aimport com.sun.org.apache.xerces.internal.xni.parser.XMLParseException;
286N/Aimport org.xml.sax.SAXException;
286N/Aimport org.xml.sax.SAXParseException;
286N/A
286N/A/**
286N/A * <p>Static utility methods for the Validation API implementation.</p>
286N/A *
286N/A * @author Kohsuke Kawaguchi (kohsuke.kawaguchi@sun.com)
286N/A */
286N/Afinal class Util {
286N/A
286N/A /**
286N/A * Creates a proper {@link XMLInputSource} from a {@link StreamSource}.
286N/A *
286N/A * @return always return non-null valid object.
286N/A */
286N/A public static final XMLInputSource toXMLInputSource( StreamSource in ) {
286N/A if( in.getReader()!=null )
286N/A return new XMLInputSource(
286N/A in.getPublicId(), in.getSystemId(), in.getSystemId(),
286N/A in.getReader(), null );
286N/A if( in.getInputStream()!=null )
286N/A return new XMLInputSource(
286N/A in.getPublicId(), in.getSystemId(), in.getSystemId(),
286N/A in.getInputStream(), null );
286N/A
286N/A return new XMLInputSource(
286N/A in.getPublicId(), in.getSystemId(), in.getSystemId() );
286N/A }
286N/A
286N/A /**
286N/A * Reconstructs {@link SAXException} from XNIException.
286N/A */
286N/A public static SAXException toSAXException(XNIException e) {
286N/A if(e instanceof XMLParseException)
286N/A return toSAXParseException((XMLParseException)e);
286N/A if( e.getException() instanceof SAXException )
286N/A return (SAXException)e.getException();
286N/A return new SAXException(e.getMessage(),e.getException());
286N/A }
286N/A
286N/A public static SAXParseException toSAXParseException( XMLParseException e ) {
286N/A if( e.getException() instanceof SAXParseException )
286N/A return (SAXParseException)e.getException();
286N/A return new SAXParseException( e.getMessage(),
286N/A e.getPublicId(), e.getExpandedSystemId(),
286N/A e.getLineNumber(), e.getColumnNumber(),
286N/A e.getException() );
286N/A }
286N/A
286N/A} // Util