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

/**
 *
 * @param elmnt/* w w w.  j  a v  a  2  s.  c  om*/
 * @param xsltSource
 * @param cls
 * @return
 * @throws TransformerConfigurationException
 * @throws JAXBException
 * @throws TransformerException
 */
public static synchronized Object deserialize(Element elmnt, InputStream xsltSource, Class cls)
        throws TransformerConfigurationException, JAXBException, TransformerException {
    Object obj = null;
    JAXBContext jc = JAXBContext.newInstance(cls);

    if (xsltSource != null) {
        TransformerFactory factory = TransformerFactory.newInstance();
        Transformer transformer;
        transformer = factory.newTransformer(new StreamSource(xsltSource));

        JAXBResult result = new JAXBResult(jc);
        transformer.transform(new DOMSource(elmnt), result);
        obj = result.getResult();
    } else {
        obj = jc.createUnmarshaller().unmarshal(elmnt);
    }
    return obj;
}

From source file:edu.wisc.hrs.dao.absbal.SoapAbsenceBalanceDaoTest.java

@Test
@Override//from ww w .j  ava 2 s. com
public void testGetAbsenceBalance() throws Exception {
    final WebServiceMessage webServiceMessage = setupWebServiceMessageSender();

    when(webServiceMessage.getPayloadSource())
            .thenReturn(new StreamSource(this.getClass().getResourceAsStream("/hrs/absbal.xml")))
            .thenReturn(new StreamSource(this.getClass().getResourceAsStream("/hrs/person.xml")));

    super.testGetAbsenceBalance();
}

From source file:edu.wisc.hrs.dao.abshis.SoapAbsenceHistoryDaoTest.java

@Test
@Override/*from w w w .  j av  a2s . co  m*/
public void testAbsenceHistory() throws Exception {
    final WebServiceMessage webServiceMessage = setupWebServiceMessageSender();

    when(webServiceMessage.getPayloadSource())
            .thenReturn(new StreamSource(this.getClass().getResourceAsStream("/hrs/abshis.xml")))
            .thenReturn(new StreamSource(this.getClass().getResourceAsStream("/hrs/person.xml")));

    super.testAbsenceHistory();
}

From source file:edu.wisc.hrs.dao.tlpayable.SoapTimeLeavePayableDaoTest.java

@Test
@Override/*from   w  w w  . ja  v  a2 s.  com*/
public void testGetTimeSheets() throws Exception {
    final WebServiceMessage webServiceMessage = setupWebServiceMessageSender();

    when(webServiceMessage.getPayloadSource())
            .thenReturn(new StreamSource(this.getClass().getResourceAsStream("/hrs/tlpaybl.xml")))
            .thenReturn(new StreamSource(this.getClass().getResourceAsStream("/hrs/person.xml")));

    super.testGetTimeSheets();
}

From source file:com.qualinsight.plugins.sonarqube.badges.ws.SVGImageMinimizer.java

/**
 * IoC constructor/*w ww . j a va 2 s.  c  o  m*/
 *
 * @throws SVGImageMinimizerException if a problem occurs during initialization
 */
public SVGImageMinimizer() throws SVGImageMinimizerException {
    try {
        InputStream xslInputStream = null;
        try {
            xslInputStream = getClass().getClassLoader()
                    .getResourceAsStream("com/qualinsight/plugins/sonarqube/badges/ws/svg-minimizer.xsl");
            final TransformerFactory transformerFactory = TransformerFactory.newInstance();
            this.transformer = transformerFactory.newTransformer(new StreamSource(xslInputStream));
        } finally {
            if (null != xslInputStream) {
                xslInputStream.close();
            }
        }
        final DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance();
        builderFactory.setValidating(false);
        builderFactory.setNamespaceAware(true);
        builderFactory.setFeature("http://xml.org/sax/features/namespaces", false);
        builderFactory.setFeature("http://xml.org/sax/features/validation", false);
        builderFactory.setFeature("http://apache.org/xml/features/nonvalidating/load-dtd-grammar", false);
        builderFactory.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false);
        this.builder = builderFactory.newDocumentBuilder();
    } catch (final IOException | TransformerConfigurationException | ParserConfigurationException e) {
        throw new SVGImageMinimizerException(e);
    }
}

From source file:com.qualinsight.plugins.sonarqube.badges.internal.SVGImageFontReplacer.java

/**
 * IoC constructor// w ww.j  a v a 2s  . com
 *
 * @throws SVGImageFontReplacementException if a problem occurs during initialization
 */
public SVGImageFontReplacer() throws SVGImageFontReplacementException {
    try {
        InputStream xslInputStream = null;
        try {
            xslInputStream = getClass().getClassLoader()
                    .getResourceAsStream("com/qualinsight/plugins/sonarqube/badges/internal/svg.xsl");
            final TransformerFactory transformerFactory = TransformerFactory.newInstance();
            this.transformer = transformerFactory.newTransformer(new StreamSource(xslInputStream));
        } finally {
            if (null != xslInputStream) {
                xslInputStream.close();
            }
        }
        final DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance();
        builderFactory.setValidating(false);
        builderFactory.setNamespaceAware(true);
        builderFactory.setFeature("http://xml.org/sax/features/namespaces", false);
        builderFactory.setFeature("http://xml.org/sax/features/validation", false);
        builderFactory.setFeature("http://apache.org/xml/features/nonvalidating/load-dtd-grammar", false);
        builderFactory.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false);
        this.builder = builderFactory.newDocumentBuilder();
    } catch (final IOException | TransformerConfigurationException | ParserConfigurationException e) {
        throw new SVGImageFontReplacementException(e);
    }
}

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

@RequestMapping(method = RequestMethod.POST, value = "/suite/{suiteId}/tests")
String addTest(Model model, @RequestBody String body, @PathVariable("suiteId") int suiteId) {
    // TODO implement XML controller

    Source source = new StreamSource(new StringReader(body));
    Test test = (Test) jaxb2Mashaller.unmarshal(source);

    // Save to database

    // Set database id
    test.setId(1L);//from   w  ww .j  a  v a2 s  .c  om

    model.addAttribute(test);
    return view;
}

From source file:se.inera.intyg.intygstjanst.web.service.impl.SendMessageToCareServiceImplTest.java

private SendMessageToCare loadFromFile(String fileName) throws Exception {
    JAXBContext jaxbContext = JAXBContext.newInstance(SendMessageToCareType.class);
    Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
    SendMessageToCareType sendMessageToCareType = unmarshaller
            .unmarshal(new StreamSource(new ClassPathResource(fileName).getInputStream()),
                    SendMessageToCareType.class)
            .getValue();/* www .  ja  v a2 s.com*/
    return new SendMessageToCareConverter().convertSendMessageToCare(sendMessageToCareType);
}

From source file:com.geewhiz.pacify.managers.EntityManager.java

public EntityManager(File startPath) {
    this.startPath = startPath;

    try {/*  w  ww  .j a  va 2 s  .c  o m*/
        jaxbContext = JAXBContext.newInstance(ObjectFactory.class);

        SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
        schema = factory.newSchema(
                new StreamSource(EntityManager.class.getClassLoader().getResourceAsStream("pacify.xsd")));
    } catch (Exception e) {
        throw new RuntimeException("Couldn't instanciate jaxb.", e);
    }
}

From source file:com.zergiu.tvman.shows.tvrage.TVRageShowLoaderJob.java

@Override
public void execute(JobExecutionContext context) throws JobExecutionException {
    log.debug("Starting the InitialTVLoader Job");
    log.debug("Job : " + context.getJobDetail().getJobBuilder().toString());
    TVShow show = getShow(context);//from   www . j  av  a 2s .c  o  m
    Unmarshaller unmarshaler = getUnmarshaller();

    //http://services.tvrage.com/feeds/full_show_info.php?sid=<series id>
    try (InputStream in = getShowDataStream(
            "http://services.tvrage.com/feeds/full_show_info.php?sid=" + show.getProviderSeriesId())) {
        TVRageShow tvRageShow = (TVRageShow) unmarshaler.unmarshal(new StreamSource(in));
        merge(show, tvRageShow);
    } catch (Exception ex) {
        log.error(ex.getMessage(), ex);
        ex.printStackTrace();
    }

    log.debug("got show:" + show);
}