Example usage for javax.xml.transform.stream StreamSource StreamSource

List of usage examples for javax.xml.transform.stream StreamSource StreamSource

Introduction

In this page you can find the example usage for javax.xml.transform.stream StreamSource StreamSource.

Prototype

public StreamSource(File f) 

Source Link

Document

Construct a StreamSource from a File.

Usage

From source file:Main.java

private static Templates loadTemplates(String name) throws TransformerException {
    ClassLoader cl = Thread.currentThread().getContextClassLoader();
    return transfomerFactory().newTemplates(new StreamSource(cl.getResource(name).toString()));
}

From source file:com.camp.web.converter.XMLConverter.java

public Object convertFromXMLToObject(Resource resource) throws IOException {

    FileInputStream fileStream = null;
    try {//from w  ww.jav  a2s  .c o  m
        File file = resource.getFile();
        fileStream = new FileInputStream(file);
        return getUnmarshaller().unmarshal(new StreamSource(fileStream));
    } finally {
        if (null != fileStream) {
            fileStream.close();
        }
    }
}

From source file:ch.sourcepond.maven.plugin.jenkins.process.xslt.StreamFactoryImpl.java

@Override
public Source newSource(final InputStream pIn) {
    return new StreamSource(pIn);
}

From source file:org.osmtools.api.SchemaService.java

public Osm fromStream(InputStream inputStream) {
    try {/*  ww w . j a va 2 s  .com*/
        JAXBElement<Osm> jaxbElement = createOsmUnmarshaller().unmarshal(new StreamSource(inputStream),
                Osm.class);
        return jaxbElement.getValue();
    } catch (JAXBException e) {
        throw new RuntimeException(e);
    }
}

From source file:cz.muni.fi.pb138.cvmanager.service.PDFgenerator.java

/**
 * Translates .xml curriculum vitae document into .tex file
 * @param username name of user whose is the CV
 * @param lang language to export (sk/en)
 * @throws TransformerException/*from   w w  w . j av  a2 s .com*/
 * @throws ParserConfigurationException
 * @throws IOException
 * @throws SAXException
 */
public void xmlToLatex(String username, String lang)
        throws TransformerException, ParserConfigurationException, IOException, SAXException {
    TransformerFactory tf = TransformerFactory.newInstance();

    Transformer xsltProc = (lang.equals("sk"))
            ? tf.newTransformer(new StreamSource(new File("src/main/resources/xslt/XmlToLatex_sk.xsl")))
            : tf.newTransformer(new StreamSource(new File("src/main/resources/xslt/XmlToLatex_en.xsl")));
    DOMSource source = new DOMSource(xmlService.createDocument(xmlService.loadFromXml(username)));
    xsltProc.transform(source, new StreamResult(new File("cvxml/" + username + "_cv.tex")));
}

From source file:com.elsevier.xml.XQueryProcessor.java

/**
 * Apply the xqueryExpression to the specified string and return a
 * serialized response./*  w w  w.j a va  2s.  c o m*/
 * 
 * @param content
 *            String to which the xqueryExpression will be applied
 * @param xqueryExpression
 *            XQuery expression to apply to the content
 * 
 * @return Serialized response from the evaluation. If an error, the response will be "<error/>".
 */
public static String evaluateString(String content, String xqueryExpression) {

    try {

        return evaluate(new StreamSource(IOUtils.toInputStream(content, CharEncoding.UTF_8)), xqueryExpression);

    } catch (IOException e) {

        log.error("Problems processing the content.  " + e.getMessage(), e);
        return "<error/>";

    }

}

From source file:com.ebay.jetstream.event.processor.esper.raw.EsperTestConfigurationValidator.java

public boolean validate(String instance, String schema) {
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();

    try {//  w  w w .  j av  a2s. c  o  m
        warnings = 0;
        errors = 0;
        fatalErrors = 0;
        try {
            //Set the validation feature
            factory.setFeature("http://xml.org/sax/features/validation", true);

            //Set the schema validation feature
            factory.setFeature("http://apache.org/xml/features/validation/schema", true);

            //Set schema full grammar checking
            factory.setFeature("http://apache.org/xml/features/validation/schema-full-checking", true);

            // If there is an external schema set it
            if (schema != null) {
                SchemaFactory sf = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
                Schema s = sf.newSchema(new StreamSource(schema));
                factory.setSchema(s);
            }
            DocumentBuilder parser = factory.newDocumentBuilder();
            parser.setErrorHandler(this);
            // Parse and validate
            parser.parse(instance);
            // Return true if we made it this far with no errors
            return ((errors == 0) && (fatalErrors == 0));
        } catch (SAXException e) {
            log.error("Could not activate validation features - " + e.getMessage());
        }
    } catch (Exception e) {
        log.error(e.getMessage());
    }
    return false;
}

From source file:com.lohika.alp.reporter.fe.controller.SuiteCotroller.java

@RequestMapping(method = RequestMethod.POST, value = "/suite")
String addSuite(Model model, @RequestBody String body) {
    // TODO implement XML controller

    Source source = new StreamSource(new StringReader(body));
    Suite suite = (Suite) jaxb2Mashaller.unmarshal(source);

    // Save to database

    // Set database id
    suite.setId(1L);//from   www.jav a 2 s  .c  om

    model.addAttribute(suite);
    return view;
}

From source file:com.thistech.spotlink.AbstractSpotlinkTest.java

protected Object unmarshal(Class clazz, String filename) {
    try {//from w  ww  . ja  va 2s .  c o  m

        Object object = this.jaxbContext.createUnmarshaller().unmarshal(
                new StreamSource(new InputStreamReader(clazz.getResourceAsStream(filename), "UTF-8")));
        if (object instanceof JAXBElement) {
            return ((JAXBElement) object).getValue();
        }
        return object;
    } catch (Exception e) {
        return null;
    }
}

From source file:at.ac.tuwien.auto.sewoa.xslt.XsltTransformer.java

public XsltTransformer(String xsltFile) {
    try {//from  w  w w.j a va 2 s  .co  m
        String xslt = Resources.toString(this.getClass().getResource("/" + xsltFile), Charset.defaultCharset());
        this.xsltSource = new StreamSource(new StringReader(xslt));
    } catch (IOException e) {
        e.printStackTrace();
    }
}