Example usage for javax.xml.transform.sax SAXSource setInputSource

List of usage examples for javax.xml.transform.sax SAXSource setInputSource

Introduction

In this page you can find the example usage for javax.xml.transform.sax SAXSource setInputSource.

Prototype

public void setInputSource(InputSource inputSource) 

Source Link

Document

Set the SAX InputSource to be used for the Source.

Usage

From source file:Main.java

/**
 * @param reader// ww  w.j a v  a2 s  . co m
 * @param parser
 * @param output
 * @throws TransformerConfigurationException
 * @throws TransformerFactoryConfigurationError
 * @throws TransformerException
 */
public static void write(Reader reader, XMLReader parser, Result output)
        throws TransformerConfigurationException, TransformerFactoryConfigurationError, TransformerException {
    SAXSource input = new SAXSource();
    InputSource inputSource = new InputSource();
    inputSource.setCharacterStream(reader);
    input.setInputSource(inputSource);
    input.setXMLReader(parser);
    write(input, output);
}

From source file:com.rest4j.generator.Generator.java

@Override
public Source resolve(String href, String base) throws TransformerException {
    String uri = href;/*from www  .  j  a va 2s .c  o m*/
    URL found = tryFind(href);
    if (found == null) {
        try {
            URL url;

            if (base == null) {
                found = new URL(uri);
            } else {
                URL baseURL = new URL(base);
                found = (href.length() == 0 ? baseURL : new URL(baseURL, uri));
            }
        } catch (java.net.MalformedURLException mue) {
            // try to make an absolute URI from the current base
            String absBase = makeAbsolute(base);
            if (!absBase.equals(base)) {
                // don't bother if the absBase isn't different!
                return resolve(href, absBase);
            } else {
                throw new TransformerException("Malformed URL " + href + "(base " + base + ")", mue);
            }
        }
    }

    SAXSource source = new SAXSource();
    source.setInputSource(new InputSource(found.toString()));
    return source;
}

From source file:org.springframework.oxm.support.AbstractMarshaller.java

/**
 * Template method for handling {@code SAXSource}s.
 * <p>This implementation delegates to {@code unmarshalSaxReader}.
 * @param saxSource the {@code SAXSource}
 * @return the object graph/* ww  w  . java 2s . com*/
 * @throws XmlMappingException if the given source cannot be mapped to an object
 * @throws IOException if an I/O Exception occurs
 * @see #unmarshalSaxReader(org.xml.sax.XMLReader, org.xml.sax.InputSource)
 */
protected Object unmarshalSaxSource(SAXSource saxSource) throws XmlMappingException, IOException {
    if (saxSource.getXMLReader() == null) {
        try {
            saxSource.setXMLReader(createXmlReader());
        } catch (SAXException ex) {
            throw new UnmarshallingFailureException("Could not create XMLReader for SAXSource", ex);
        }
    }
    if (saxSource.getInputSource() == null) {
        saxSource.setInputSource(new InputSource());
    }
    try {
        return unmarshalSaxReader(saxSource.getXMLReader(), saxSource.getInputSource());
    } catch (NullPointerException ex) {
        if (!isSupportDtd()) {
            throw new UnmarshallingFailureException(
                    "NPE while unmarshalling. " + "This can happen on JDK 1.6 due to the presence of DTD "
                            + "declarations, which are disabled.");
        }
        throw ex;
    }
}