Example usage for javax.xml.bind Unmarshaller unmarshal

List of usage examples for javax.xml.bind Unmarshaller unmarshal

Introduction

In this page you can find the example usage for javax.xml.bind Unmarshaller unmarshal.

Prototype

public Object unmarshal(javax.xml.stream.XMLEventReader reader) throws JAXBException;

Source Link

Document

Unmarshal XML data from the specified pull parser and return the resulting content tree.

Usage

From source file:com.healthcit.cacure.export.ExportToExcel.java

@Test
public void export() throws JAXBException, TransformerException {
    JAXBContext jc = JAXBContext.newInstance("com.healthcit.cacure.export.model");
    File iFile = new File("C:\\temp\\moduleTest1.xml");
    //File iFile = new File("C:\\temp\\formExportTest.xml");
    //File iFile = new File("C:\\temp\\section1.1.xml");
    //File iFile = new File("C:\\temp\\complexSkip2.xml");
    //File iFile = new File("C:\\temp\\section3.1.xml");
    File oFile = new File("C:\\temp\\Book2.xml");
    Unmarshaller m = jc.createUnmarshaller();
    Cure xml = (Cure) m.unmarshal(iFile);
    StreamSource xslSource = new StreamSource("src//main//resources//xls.xsl");
    //long formId = 9979;

    //Cure xml = dataExporter.constructFormXML(formId);
    JAXBSource xmlSource = new JAXBSource(jc, xml);
    Transformer transformer = TransformerFactory.newInstance().newTransformer(xslSource);
    transformer.transform(xmlSource, new StreamResult(oFile));
}

From source file:fish.payara.examples.jdays2016.springboot.DataLoaderServiceImpl.java

@Override
public long parseFile(File file) {
    JAXBContext jc;//from  w  ww.  j a  v a  2s  . co  m
    int count = 0;
    try {
        jc = JAXBContext.newInstance("fish.payara.examples.jdays2016.jaxb");
        Unmarshaller um = jc.createUnmarshaller();
        HaPlannedRoadworks rw = (HaPlannedRoadworks) um.unmarshal(file);
        for (HaPlannedRoadworks.HaPlannedWorks works : rw.getHaPlannedWorks()) {
            PlannedWorks pw = new PlannedWorks(works);
            repo.save(pw);
            count++;
        }
    } catch (JAXBException ex) {
        Logger.getLogger(DataLoaderServlet.class.getName()).log(Level.SEVERE, null, ex);
    }
    return count;

}

From source file:com.tremolosecurity.openunison.util.OpenUnisonUtils.java

private static TremoloType loadTremoloType(String unisonXMLFile) throws Exception {
    JAXBContext jc = JAXBContext.newInstance("com.tremolosecurity.config.xml");
    Unmarshaller unmarshaller = jc.createUnmarshaller();
    FileInputStream in = new FileInputStream(unisonXMLFile);

    Object obj = unmarshaller.unmarshal(in);

    JAXBElement<TremoloType> cfg = (JAXBElement<TremoloType>) obj;
    return cfg.getValue();
}

From source file:fr.mael.microrss.xml.RSSFeedParser.java

@Override
public Feed parseFeedInfo(Feed feed) throws Exception {
    JAXBContext jc = JAXBContext.newInstance("fr.mael.microrss.xml.rss");
    Unmarshaller unmarshaller = jc.createUnmarshaller();
    Rss rss = (Rss) unmarshaller.unmarshal(new URL(feed.getUrl()).openStream());
    String link = XMLUtil.readProperty("link", rss.getChannel().getTitleOrLinkOrDescription());
    feed.setIcon(Tools.getImage(Tools.getBaseUrl(link) + "/favicon.ico"));
    feed.setTitle(XMLUtil.readProperty("title", rss.getChannel().getTitleOrLinkOrDescription()));
    return feed;/*ww w .j  ava2  s .c om*/
}

From source file:org.fcrepo.integration.auth.oauth.api.TestBinding.java

@Test
public void testBinding() throws JAXBException {
    LOGGER.trace("Executing testBinding()");
    final JAXBContext context = JAXBContext.newInstance(WebAppConfig.class);
    final Unmarshaller u = context.createUnmarshaller();
    final WebAppConfig o = (WebAppConfig) u.unmarshal(getClass().getResourceAsStream("/web.xml"));
    Assert.assertEquals("Fedora-on-ModeShape", o.displayName());
    Assert.assertTrue(o.contextParams()//from  ww  w  . ja v a 2s. c  om
            .contains(new ContextParam("contextConfigLocation", "classpath:spring-test/rest.xml; "
                    + "classpath:spring-test/repo.xml; " + "classpath:spring-test/security.xml")));
    Assert.assertTrue(o.listeners()
            .contains(new Listener(null, "org.springframework.web.context.ContextLoaderListener")));
    final ServletMapping sm = o.servletMappings("jersey-servlet").iterator().next();
    Assert.assertNotNull(sm);
    Assert.assertEquals("/*", sm.urlPattern());

    FilterMapping fm = o.filterMappings("TokenFilter").iterator().next();
    Assert.assertNotNull(fm);
    Assert.assertEquals("/token", fm.urlPattern());

    fm = o.filterMappings("OpFilter").iterator().next();
    Assert.assertNotNull(fm);
    Assert.assertEquals("/rest/objects/authenticated/*", fm.urlPattern());

}

From source file:org.fcrepo.auth.oauth.integration.api.TestBinding.java

@Test
public void testBinding() throws JAXBException {
    LOGGER.trace("Executing testBinding()");
    final JAXBContext context = JAXBContext.newInstance(WebAppConfig.class);
    final Unmarshaller u = context.createUnmarshaller();
    final WebAppConfig o = (WebAppConfig) u.unmarshal(getClass().getResourceAsStream("/web.xml"));
    assertEquals("Fedora-on-ModeShape", o.displayName());
    assertTrue(o.contextParams()/*w  w  w . j a  v  a  2s.  com*/
            .contains(new ContextParam("contextConfigLocation", "classpath:spring-test/rest.xml; "
                    + "classpath:spring-test/repo.xml; " + "classpath:spring-test/security.xml")));
    assertTrue(o.listeners()
            .contains(new Listener(null, "org.springframework.web.context.ContextLoaderListener")));
    final ServletMapping sm = o.servletMappings("jersey-servlet").iterator().next();
    assertNotNull(sm);
    assertEquals("/*", sm.urlPattern());

    FilterMapping fm = o.filterMappings("TokenFilter").iterator().next();
    assertNotNull(fm);
    assertEquals("/token", fm.urlPattern());

    fm = o.filterMappings("OpFilter").iterator().next();
    assertNotNull(fm);
    assertEquals("/rest/objects/authenticated/*", fm.urlPattern());

}

From source file:org.hisp.dhis.dxf2.importsummary.ImportSummaryTest.java

@Test
public void unMarshallImportSummary() throws Exception {
    ClassPathResource resource = new ClassPathResource("importSummary.xml");
    JAXBContext jaxbContext = JAXBContext.newInstance(ImportSummary.class);

    Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
    ImportSummary importSummary = (ImportSummary) jaxbUnmarshaller.unmarshal(resource.getInputStream());
    assertEquals(3, importSummary.getDataValueCount().getImported());
    assertEquals(0, importSummary.getDataValueCount().getUpdated());
    assertEquals(1, importSummary.getDataValueCount().getIgnored());
}

From source file:org.omg.dmn.tck.marshaller._20160719.TestCasesTest.java

@SuppressWarnings({ "unchecked" })
protected final TestCases load(InputStream inputStream) throws JAXBException {
    JAXBContext context = JAXBContext.newInstance(TestCases.class);
    Unmarshaller um = context.createUnmarshaller();

    Object obj = um.unmarshal(inputStream);
    if (obj instanceof JAXBElement<?>) {
        return ((JAXBElement<TestCases>) obj).getValue();
    } else {//from   www  . j  a v a 2 s.  c o  m
        return (TestCases) obj;
    }
}

From source file:com.wso2telco.core.config.ConfigLoader.java

/**
 * Inits the loa config./*from ww  w.  j a  v  a  2  s.c o m*/
 *
 * @return the LOA config
 * @throws JAXBException the JAXB exception
 */
private LOAConfig initLoaConfig() throws JAXBException {
    String configPath = CarbonUtils.getCarbonConfigDirPath() + File.separator + "LOA.xml";
    File file = new File(configPath);
    JAXBContext ctx = JAXBContext.newInstance(LOAConfig.class);
    Unmarshaller um = ctx.createUnmarshaller();
    return (LOAConfig) um.unmarshal(file);
}

From source file:org.jasig.portlet.campuslife.athletics.dao.AthleticsDaoMockImpl.java

@Override
public void afterPropertiesSet() throws Exception {
    try {/* ww w.j  av  a 2  s.  c o m*/
        JAXBContext jaxbContext = JAXBContext.newInstance(AthleticsFeed.class);
        Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
        this.feed = (AthleticsFeed) unmarshaller.unmarshal(mockData.getInputStream());
    } catch (IOException e) {
        log.error("Failed to read mock data", e);
    } catch (JAXBException e) {
        log.error("Failed to unmarshall mock data", e);
    }
}