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:com.prowidesoftware.swift.model.mx.BusinessHeader.java

/**
 * Returns a gregorian calendar for current moment in UTC time zone
 * @return created calendar or null if DatatypeFactory fails to create the calendar instance
 */// w ww .  j a  v a 2  s . c o m
private static XMLGregorianCalendar now() {
    GregorianCalendar c = new GregorianCalendar();
    c.setTime(Calendar.getInstance(TimeZone.getTimeZone("UTC")).getTime());
    XMLGregorianCalendar creationDate = null;
    try {
        /*
         * important: cannot create XMLGregorianCalendar directly from Calendar object, 
         * specific format must be used for the unmarshalled XML to pass XSD validation.
         */
        creationDate = DatatypeFactory.newInstance()
                .newXMLGregorianCalendar(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'").format(c.getTime()));
    } catch (DatatypeConfigurationException e) {
        log.log(Level.WARNING, "error initializing header creation date", e);
    }
    return creationDate;
}

From source file:org.eclipse.lyo.oslc.v3.sample.BugContainer.java

private Date getDate(Statement s) {
    if (s == null || !s.getObject().isLiteral()) {
        return null;
    }//from  ww w .j av a2 s. co m

    try {
        return DatatypeFactory.newInstance().newXMLGregorianCalendar(s.getString()).toGregorianCalendar()
                .getTime();
    } catch (IllegalArgumentException e) {
        logger.warn(String.format("Invalid date format <%s>" + s.getString()), e);
        return null;
    } catch (DatatypeConfigurationException e) {
        logger.error("Error initializing datatype factory", e);
        throw new WebApplicationException(Status.INTERNAL_SERVER_ERROR);
    }
}

From source file:gov.nih.nci.integration.caaers.CaAERSAdverseEventServiceClientIntegrationTest.java

private AdverseEventType getAdverseEvent1() throws DatatypeConfigurationException {
    final GregorianCalendar gcal0 = new GregorianCalendar(2012, 06, 10);
    final XMLGregorianCalendar xgcal0 = DatatypeFactory.newInstance().newXMLGregorianCalendar(gcal0);
    final GregorianCalendar gcal1 = new GregorianCalendar(2012, 06, 11);
    final XMLGregorianCalendar xgcal1 = DatatypeFactory.newInstance().newXMLGregorianCalendar(gcal1);
    final AdverseEventType event1 = new AdverseEventType();
    event1.setVerbatim("Event1 Verbatim");
    // event1.setCtepCode("10001367");// code for 'Adrenal insufficiency'
    event1.getAdverseEventCtepTerm().setCtepCode("10001367");
    event1.setGrade(3);/*from w w  w. j  a v  a2  s. co  m*/
    event1.setStartDate(xgcal0);
    event1.setEndDate(xgcal1);
    event1.setExpected(true);
    event1.setAttributionSummary(AttributionType.POSSIBLE);
    final OutcomeType outcomeType1 = new OutcomeType();
    outcomeType1.setOutComeEnumType(OutComeEnumType.LIFE_THREATENING);
    final OutcomeType outcomeType2 = new OutcomeType();
    outcomeType2.setOutComeEnumType(OutComeEnumType.HOSPITALIZATION);
    event1.getOutcome().add(outcomeType1);
    event1.getOutcome().add(outcomeType2);
    return event1;
}

From source file:gov.nih.nci.integration.caaers.CaAERSAdverseEventServiceClientIntegrationTest.java

private AdverseEventType getAdverseEvent2() throws DatatypeConfigurationException {
    final GregorianCalendar gcal0 = new GregorianCalendar(2012, 06, 10);
    final XMLGregorianCalendar xgcal0 = DatatypeFactory.newInstance().newXMLGregorianCalendar(gcal0);
    final GregorianCalendar gcal1 = new GregorianCalendar(2012, 06, 11);
    final XMLGregorianCalendar xgcal1 = DatatypeFactory.newInstance().newXMLGregorianCalendar(gcal1);
    final AdverseEventType event2 = new AdverseEventType();
    event2.setVerbatim("Event2 Verbatim");
    // event2.setCtepCode("10014004");// code for 'Ear disorder'
    event2.getAdverseEventCtepTerm().setCtepCode("10014004");
    event2.setGrade(4);//from  ww w .ja  v a  2  s  . c o  m
    event2.setStartDate(xgcal0);
    event2.setEndDate(xgcal1);
    event2.setExpected(true);
    event2.setAttributionSummary(AttributionType.DEFINITE);
    final OutcomeType outcomeType3 = new OutcomeType();
    outcomeType3.setOutComeEnumType(OutComeEnumType.CONGENITAL_ANOMALY);
    final OutcomeType outcomeType4 = new OutcomeType();
    outcomeType4.setOutComeEnumType(OutComeEnumType.OTHER_SERIOUS);
    event2.getOutcome().add(outcomeType3);
    event2.getOutcome().add(outcomeType4);
    return event2;
}

From source file:org.jasig.portlet.calendar.adapter.ExchangeCalendarAdapter.java

/**
 * Get an XMLGregorianCalendar for the specified date.
 *
 * @param date//w ww .  j  a v  a2s .  c o  m
 * @return
 * @throws DatatypeConfigurationException
 */
protected XMLGregorianCalendar getXmlDate(DateTime date) throws DatatypeConfigurationException {
    // construct an XMLGregorianCalendar
    DatatypeFactory datatypeFactory = DatatypeFactory.newInstance();
    XMLGregorianCalendar start = datatypeFactory.newXMLGregorianCalendar();
    start.setYear(date.getYear());
    start.setMonth(date.getMonthOfYear());
    start.setTime(date.getHourOfDay(), date.getMinuteOfHour(), date.getSecondOfMinute(),
            date.getMillisOfSecond());
    start.setDay(date.getDayOfMonth());
    return start;
}

From source file:de.unikassel.puma.openaccess.sword.MetsBibTexMLGenerator.java

public String generateMets() {
    /*//from   w  w  w  . java  2 s.  c  o  m
     * Helfer
     */

    final StringWriter sw = new StringWriter();
    final ObjectFactory objectFactory = new ObjectFactory();

    /*
     * METS
     */
    final Mets mets = objectFactory.createMets();
    mets.setID("sort-mets_mets");
    mets.setOBJID("sword-mets");
    mets.setLABEL("DSpace SWORD Item");
    mets.setPROFILE("DSpace METS SIP Profile 1.0");

    //mets xmlns=\"http://www.loc.gov/METS/\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" xsi:schemaLocation=\"http://www.loc.gov/METS/ http://www.loc.gov/standards/mets/mets.xsd\">\n";

    /*
     * METS Hdr
     */

    final MetsHdr metsHdr = objectFactory.createMetsTypeMetsHdr();

    GregorianCalendar c = new GregorianCalendar();
    XMLGregorianCalendar currentDate;
    try {
        currentDate = DatatypeFactory.newInstance().newXMLGregorianCalendar(c);
        metsHdr.setCREATEDATE(currentDate);
    } catch (DatatypeConfigurationException e) {
        log.warn("DatatypeConfigurationException");
    }

    mets.setMetsHdr(metsHdr);

    final List<Agent> metsHdrAgentList = metsHdr.getAgent();
    final Agent metsHdrAgent = new Agent();
    metsHdrAgent.setROLE("CUSTODIAN");
    metsHdrAgent.setTYPE("ORGANIZATION");
    metsHdrAgent.setName("PUMA");

    metsHdrAgentList.add(metsHdrAgent);

    final List<MdSecType> dmdSec = mets.getDmdSec();

    final MdSecType mdSec = objectFactory.createMdSecType();
    mdSec.setID("sword-mets-dmd-1");
    mdSec.setGROUPID("sword-mets-dmd-1_group-1");
    dmdSec.add(mdSec);

    final MdWrap mdWrap = objectFactory.createMdSecTypeMdWrap();
    mdWrap.setMIMETYPE("text/xml");
    mdWrap.setMDTYPE("OTHER");
    mdWrap.setOTHERMDTYPE("BIBTEXML");
    mdSec.setMdWrap(mdWrap);

    final XmlData xmlData = objectFactory.createMdSecTypeMdWrapXmlData();
    mdWrap.setXmlData(xmlData);

    /*
     * METS FileSec
     */

    final FileSec metsFileSec = objectFactory.createMetsTypeFileSec();
    mets.setFileSec(metsFileSec);

    final FileGrp metsFileSecFileGrp = objectFactory.createMetsTypeFileSecFileGrp();
    List<FileType> fileItemList = new ArrayList<FileType>();

    metsFileSecFileGrp.setID("sword-mets-fgrp-1");
    metsFileSecFileGrp.setUSE("CONTENT");
    Integer filenumber = 0;
    for (Document doc : _post.getPost().getResource().getDocuments()) {
        FileType fileItem = new FileType();
        //         fileItem.setGROUPID("sword-mets-fgid-0");
        fileItem.setID("sword-mets-file-".concat(filenumber.toString()));
        // TODO: if file is not pdf, set MIMEtype to something like binary data
        fileItem.setMIMETYPE("application/pdf");

        FLocat fileLocat = new FLocat();
        fileLocat.setLOCTYPE("URL");
        fileLocat.setHref(doc.getFileName());
        fileItem.getFLocat().add(fileLocat);

        // add fileitem to filepointerlist for struct section
        fileItemList.add(fileItem);

        metsFileSecFileGrp.getFile().add(fileItem);
        filenumber++;
    }

    metsFileSec.getFileGrp().add(metsFileSecFileGrp);

    /*
     * METS structMap
     */

    final StructMapType structMap = new StructMapType();

    structMap.setID("sword-mets-struct-1");
    structMap.setLABEL("structure");
    structMap.setTYPE("LOGICAL");

    final DivType div1 = new DivType();
    div1.setID("sword-mets-div-1");
    div1.getDMDID().add(mdSec); // TODO check if msSec is correct, or this must be a string?
    div1.setTYPE("SWORD Object");

    final DivType div2 = new DivType();
    div2.setID("sword-mets-div-2");
    div2.setTYPE("File");

    for (FileType fItem : fileItemList) {
        Fptr fptr = new Fptr();
        fptr.setFILEID(fItem);

        div2.getFptr().add(fptr);
    }
    //xmlDocument += "<div ID=\"sword-mets-div-1\" DMDID=\"sword-mets-dmd-1\" TYPE=\"SWORD Object\">\n";
    // fptr
    //xmlDocument += "<fptr FILEID=\"sword-mets-file-1\"/>\n";

    div1.getDiv().add(div2);

    structMap.setDiv(div1);

    mets.getStructMap().add(structMap);

    /*
     * unser Post
     */
    final PumaPost pumaPost = xmlRenderer.createPumaPost(_post, _user);

    //derPost.set
    //"puma", "http://puma.uni-kassel.de/2010/11/PUMA-SWORD"

    xmlData.getAny().add(pumaPost);

    xmlRenderer.serializeMets(sw, mets);

    // DEBUG
    log.debug(sw.toString());

    return XmlUtils.removeXmlControlCharacters(sw.toString());

}

From source file:com.modelsolv.kaboom.serializer.SerializerTest.java

private XMLGregorianCalendar getXmlDate() {
    try {//from  w w w.ja  v  a  2s  .  c  o m
        XMLGregorianCalendar date = DatatypeFactory.newInstance().newXMLGregorianCalendarDate(2013, 12, 31, -6);
        return date;
    } catch (Exception e) {
        throw new RuntimeException("Could not build XMLGregorianCalendar.", e);
    }
}

From source file:eu.dasish.annotation.backend.dao.impl.JdbcAnnotationDaoTest.java

@Test
public void testGetAnnotationInfoWithoutTargetsAndOwner() throws DatatypeConfigurationException {
    System.out.println("test getAnnotationInfoWithoutTargets");
    jdbcAnnotationDao.setResourcePath("/api/annotations/");
    final AnnotationInfo result = jdbcAnnotationDao.getAnnotationInfoWithoutTargetsAndOwner(1);

    assertEquals("Sagrada Famiglia", result.getHeadline());
    assertEquals("/api/annotations/00000000-0000-0000-0000-000000000021", result.getHref());
    assertEquals(DatatypeFactory.newInstance().newXMLGregorianCalendar("2013-08-12T09:25:00.383000Z"),
            result.getLastModified());// w  w w.j a  va2 s  .  c om
}

From source file:org.apache.lens.regression.util.Util.java

public static XMLGregorianCalendar getGregorianCalendar(String date, String format)
        throws ParseException, DatatypeConfigurationException {
    GregorianCalendar cal = new GregorianCalendar();
    cal.setTime(new SimpleDateFormat(format).parse(date));
    cal.setTimeZone(TimeZone.getTimeZone("UTC"));
    XMLGregorianCalendar calendar = DatatypeFactory.newInstance().newXMLGregorianCalendar(cal);
    return calendar;
}