Example usage for javax.xml.datatype DatatypeFactory newInstance

List of usage examples for javax.xml.datatype DatatypeFactory newInstance

Introduction

In this page you can find the example usage for javax.xml.datatype DatatypeFactory newInstance.

Prototype

public static DatatypeFactory newInstance() throws DatatypeConfigurationException 

Source Link

Document

Obtain a new instance of a DatatypeFactory .

Usage

From source file:core.nipr.NiprClient.java

public Map<String, LicenseInternal> getSpecificReport(GregorianCalendar aInDate, AtomicBoolean aOutFailure,
        StringBuilder aInOutErrors) {

    Map<String, LicenseInternal> lAllLicenses = new HashMap<String, LicenseInternal>();
    aOutFailure.set(false);//  www. jav a 2  s  . c om
    ReceiveSpecificReport lRequest = new ReceiveSpecificReport();
    /*
    Date lDate = new Date();
    GregorianCalendar c = new GregorianCalendar();
    c.setTime(lDate);
    */
    String formatted = CalenderUtils.getFormattedDate(aInDate);
    System.out.println("Getting Record for ====================== " + formatted);

    try {
        XMLGregorianCalendar lXmlDate = DatatypeFactory.newInstance().newXMLGregorianCalendar(aInDate);
        lRequest.setReportDate(lXmlDate);

        Object lSoapResponse = getWebServiceTemplate().marshalSendAndReceive(lRequest,
                new SoapActionCallback(getDefaultUri().replace("/services", "") + "/receiveSpecificReport"));

        System.out.println("NIPR soap api SUCCESS ++++++++++++ " + formatted);

        ReceiveSpecificReportResponse lResponse = (ReceiveSpecificReportResponse) lSoapResponse;
        AlertsReportType lType = lResponse.getAlertsReport();
        DataHandler lHandler = lType.getAlertsReport();
        //String theString = IOUtils.toString(lHandler.getInputStream(), "utf-8");
        //System.out.println("Response " + theString);
        lAllLicenses = parseReport(lType.getAlertsReport().getInputStream(), lXmlDate);
        System.out.println("Total NIPR Liceses for " + formatted + " are " + lAllLicenses.size());
    } catch (SoapFaultClientException e) {
        aOutFailure.set(true);
        try {
            PdbAlertsFaultType lFaultType = getDetailedFault(e);
            if (lFaultType != null) {
                System.out.println("NiprSoapApi error from server " + lFaultType.getMessage());
                if (lFaultType.getErrorCode() == 5) {
                    aOutFailure.set(false);
                    System.out.println(
                            "Treating no Nipr alerts for the day " + formatted + " as SUCCESS ++++++++++");
                }
            }
        } catch (Exception ex) {
            aOutFailure.set(true);
            String lMsg = "NiprSoapApi SoapFaultClientException error in parsing the exception "
                    + ex.getMessage();
            WebUtils.appendline(lMsg, aInOutErrors);
            System.out.println(lMsg);
        }
    } catch (Exception e) {
        aOutFailure.set(true);
        e.printStackTrace();
        String lMsg = "NiprSoapApi generic exception  " + e.getMessage();
        WebUtils.appendline(lMsg, aInOutErrors);
        System.out.println(lMsg);
    }

    return lAllLicenses;
}

From source file:com.tenforce.lodms.extractors.CkanHarvester.java

private static XMLGregorianCalendar getXMLNow() throws DatatypeConfigurationException {
    GregorianCalendar gregorianCalendar = new GregorianCalendar();
    DatatypeFactory datatypeFactory;
    datatypeFactory = DatatypeFactory.newInstance();
    return datatypeFactory.newXMLGregorianCalendar(gregorianCalendar);
}

From source file:com.labs64.utils.swid.support.JAXBUtils.java

/**
 * Convert {@link Date} to {@link XMLGregorianCalendar}.
 * /* w  w  w. j  a v  a2  s.  c o m*/
 * @param date
 *            XML entity
 */
public static XMLGregorianCalendar convertDateToXMLGregorianCalendar(final Date date) {
    try {
        GregorianCalendar cal = new GregorianCalendar();
        cal.setTime(date);
        XMLGregorianCalendar calXml = DatatypeFactory.newInstance().newXMLGregorianCalendar(
                cal.get(Calendar.YEAR), cal.get(Calendar.MONTH) + 1, cal.get(Calendar.DAY_OF_MONTH),
                cal.get(Calendar.HOUR_OF_DAY), cal.get(Calendar.MINUTE), cal.get(Calendar.SECOND),
                cal.get(Calendar.MILLISECOND), 0);
        return calXml;
    } catch (DatatypeConfigurationException e) {
        throw new SwidException("Cannot convert date", e);
    }
}

From source file:com.fusesource.example.camel.ingest.FileIngestorRouteBuilderTest.java

@Test
public void testPositive() throws Exception {
    context.start();// w  w w  .ja  va2 s .  c  o m

    DatatypeFactory dtf = DatatypeFactory.newInstance();

    Set<String> expectedIds = new HashSet<String>();
    AggregateRecordType agt = new AggregateRecordType();
    agt.setDate(dtf.newXMLGregorianCalendar(new GregorianCalendar()));

    output.setExpectedMessageCount(10);

    for (int i = 0; i < 10; i++) {
        RecordType recordType = new RecordType();
        recordType.setId(String.valueOf(i));
        recordType.setDate(dtf.newXMLGregorianCalendar(new GregorianCalendar()));
        recordType.setDescription("Record number: " + i);
        agt.getRecord().add(recordType);
        expectedIds.add(String.valueOf(i));
    }

    createAndMoveFile(agt);

    output.assertIsSatisfied();
    validateFileMove(false);

    for (Exchange exchange : output.getReceivedExchanges()) {
        assertTrue(expectedIds.remove(exchange.getIn().getBody(RecordType.class).getId()));
    }

    assertTrue(expectedIds.isEmpty());
}

From source file:ca.phon.session.io.xml.v12.XMLSessionWriter_v12.java

/**
 * Create a new jaxb version of the session
 * //ww w.j  ava 2  s  .c  o m
 * @param session
 * @return an version of the session use-able by jaxb 
 */
private JAXBElement<SessionType> toSessionType(Session session) throws IOException {
    final ObjectFactory factory = new ObjectFactory();
    final SessionType retVal = factory.createSessionType();

    // header data
    retVal.setVersion("PB1.2");
    retVal.setId(session.getName());
    retVal.setCorpus(session.getCorpus());

    final HeaderType headerData = factory.createHeaderType();
    if (session.getMediaLocation() != null && session.getMediaLocation().length() > 0) {
        headerData.setMedia(session.getMediaLocation());
    }
    final LocalDate date = (session.getDate() == null ? LocalDate.now() : session.getDate());
    try {
        final DatatypeFactory df = DatatypeFactory.newInstance();
        final XMLGregorianCalendar cal = df
                .newXMLGregorianCalendar(GregorianCalendar.from(date.atStartOfDay(ZoneId.systemDefault())));
        cal.setTimezone(DatatypeConstants.FIELD_UNDEFINED);
        headerData.setDate(cal);
    } catch (DatatypeConfigurationException e) {
        LOGGER.log(Level.WARNING, e.getMessage(), e);
    }
    final String lang = session.getLanguage();
    if (lang != null && lang.length() > 0) {
        final String langs[] = lang.split("\\p{Space}");
        for (String l : langs) {
            headerData.getLanguage().add(l);
        }
    }
    retVal.setHeader(headerData);

    final TranscriptType transcript = factory.createTranscriptType();
    // commets
    for (int i = 0; i < session.getMetadata().getNumberOfComments(); i++) {
        final Comment c = session.getMetadata().getComment(i);
        final CommentType ct = copyComment(factory, c);
        transcript.getUOrComment().add(ct);
    }

    // participants
    final ParticipantsType parts = factory.createParticipantsType();
    for (int i = 0; i < session.getParticipantCount(); i++) {
        final Participant part = session.getParticipant(i);
        final ParticipantType pt = copyParticipant(factory, part);
        parts.getParticipant().add(pt);
    }
    retVal.setParticipants(parts);

    // transcribers
    final TranscribersType tt = factory.createTranscribersType();
    for (int i = 0; i < session.getTranscriberCount(); i++) {
        final Transcriber tr = session.getTranscriber(i);
        final TranscriberType trt = copyTranscriber(factory, tr);
        tt.getTranscriber().add(trt);
    }
    retVal.setTranscribers(tt);

    // tier info/ordering
    final UserTiersType utt = factory.createUserTiersType();
    for (int i = 0; i < session.getUserTierCount(); i++) {
        final TierDescription td = session.getUserTier(i);
        final UserTierType tierType = copyTierDescription(factory, td);
        utt.getUserTier().add(tierType);
    }
    retVal.setUserTiers(utt);

    final TierOrderType tot = factory.createTierOrderType();
    for (TierViewItem tvi : session.getTierView()) {
        final TvType tvt = copyTierViewItem(factory, tvi);
        tot.getTier().add(tvt);
    }
    retVal.setTierOrder(tot);

    // session data
    for (int i = 0; i < session.getRecordCount(); i++) {
        final Record record = session.getRecord(i);

        // insert comments first
        for (int j = 0; j < record.getNumberOfComments(); j++) {
            final Comment com = record.getComment(j);
            final CommentType ct = copyComment(factory, com);
            transcript.getUOrComment().add(ct);
        }

        // copy record data
        final RecordType rt = copyRecord(factory, retVal, record);

        rt.setId(record.getUuid().toString());

        if (record.isExcludeFromSearches())
            rt.setExcludeFromSearches(record.isExcludeFromSearches());

        // setup participant
        if (record.getSpeaker() != null) {
            for (ParticipantType pt : parts.getParticipant()) {
                if (pt.getId().equals(record.getSpeaker().getId())) {
                    rt.setSpeaker(pt);
                    break;
                }
            }
        }

        transcript.getUOrComment().add(rt);
    }
    retVal.setTranscript(transcript);

    return factory.createSession(retVal);
}

From source file:cz.cas.lib.proarc.common.export.mets.MetsUtils.java

/**
 * Retuns an XMLGregorianCalendar representation of current date
 *
 * @return//from ww  w  . j a  va 2s  .c  o m
 * @throws MetsExportException
 */
public static XMLGregorianCalendar getCurrentDate() throws MetsExportException {
    GregorianCalendar gregory = new GregorianCalendar();
    gregory.setTime(new Date());

    XMLGregorianCalendar calendar;
    try {
        calendar = DatatypeFactory.newInstance().newXMLGregorianCalendar(gregory);
    } catch (DatatypeConfigurationException e1) {
        throw new MetsExportException("Unable to create XMLGregorianDate", false, e1);
    }
    return calendar;
}

From source file:com.inmobi.grill.server.metastore.JAXBUtils.java

public static XMLGregorianCalendar getXMLGregorianCalendar(Date d) {
    if (d == null) {
        return null;
    }/*w ww  .  j  a v a 2s  . c o  m*/

    GregorianCalendar c1 = new GregorianCalendar();
    c1.setTime(d);
    try {
        return DatatypeFactory.newInstance().newXMLGregorianCalendar(c1);
    } catch (DatatypeConfigurationException e) {
        LOG.warn("Error converting date " + d, e);
        return null;
    }
}

From source file:cz.cas.lib.proarc.common.export.archive.PackageBuilder.java

public PackageBuilder(File targetFolder) {
    this.parentFolder = targetFolder;
    this.pid2PhysicalDiv = new HashMap<String, DivType>();
    try {/*from  ww  w .j  ava 2 s. c om*/
        this.xmlTypes = DatatypeFactory.newInstance();
        this.domTransformer = TransformerFactory.newInstance().newTransformer();
        this.domTransformer.setOutputProperty(OutputKeys.INDENT, "yes");
        this.domTransformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "4");
    } catch (DatatypeConfigurationException ex) {
        throw new IllegalStateException(ex);
    } catch (TransformerConfigurationException ex) {
        throw new IllegalStateException(ex);
    }
}

From source file:com.fusesource.example.camel.ingest.SimpleFileIngestorRouteBuilderTest.java

@Test
@DirtiesContext/*w w w . j av  a  2  s. c o  m*/
public void testPositive() throws Exception {
    context.start();

    DatatypeFactory dtf = DatatypeFactory.newInstance();

    Set<String> expectedIds = new HashSet<String>();
    AggregateRecordType agt = new AggregateRecordType();
    agt.setDate(dtf.newXMLGregorianCalendar(new GregorianCalendar()));

    output.setExpectedMessageCount(10);
    output.setResultWaitTime(15000);

    for (int i = 0; i < 10; i++) {
        RecordType recordType = new RecordType();
        recordType.setId(String.valueOf(i));
        recordType.setDate(dtf.newXMLGregorianCalendar(new GregorianCalendar()));
        recordType.setDescription("Record number: " + i);
        agt.getRecord().add(recordType);
        expectedIds.add(String.valueOf(i));
    }

    createAndMoveFile(agt);

    output.assertIsSatisfied();
    validateFileMove(false);

    for (Exchange exchange : output.getReceivedExchanges()) {
        assertTrue(expectedIds.remove(exchange.getIn().getBody(Record.class).getId()));
    }

    assertTrue(expectedIds.isEmpty());
}

From source file:eu.europa.ec.markt.dss.signature.xades.XAdESProfileC.java

/**
 * The default constructor for XAdESProfileT.
 * /*from   w w  w  . j  a v a2  s.co  m*/
 * @throws DatatypeConfigurationException
 */
public XAdESProfileC() {
    super();
    Init.init();

    try {
        datatypeFactory = DatatypeFactory.newInstance();
    } catch (DatatypeConfigurationException e) {
        throw new RuntimeException(e);
    }

}