Example usage for javax.xml.datatype DatatypeConstants FIELD_UNDEFINED

List of usage examples for javax.xml.datatype DatatypeConstants FIELD_UNDEFINED

Introduction

In this page you can find the example usage for javax.xml.datatype DatatypeConstants FIELD_UNDEFINED.

Prototype

int FIELD_UNDEFINED

To view the source code for javax.xml.datatype DatatypeConstants FIELD_UNDEFINED.

Click Source Link

Document

Designation that an "int" field is not set.

Usage

From source file:Main.java

/**
 * Converts an XMLGregorianCalendar to a Date.
 *
 * @param xmlDate//ww  w .  j  a  va  2  s.c  o  m
 *            XMLGregorianCalendar to convert.
 * @return corresponding date object.
 */
public static Date getDate(final XMLGregorianCalendar xmlDate) {
    // TODO: is this equivalent to getDate(String) processing above??

    // start with UTC, i.e. no daylight savings time.
    TimeZone timezone = TimeZone.getTimeZone("GMT");

    // adjust timezone to match xmldate
    int offsetMinutes = xmlDate.getTimezone();
    if (offsetMinutes != DatatypeConstants.FIELD_UNDEFINED) {
        timezone.setRawOffset(
                // convert minutes to milliseconds
                offsetMinutes * 60 // seconds per minute
                        * 1000 // milliseconds per second
        );
    }

    // use calendar so parsed date will be UTC
    Calendar calendar = Calendar.getInstance(timezone);
    calendar.clear();
    calendar.set(xmlDate.getYear(),
            // xmlcalendar is 1 based, calender is 0 based
            xmlDate.getMonth() - 1, xmlDate.getDay(), xmlDate.getHour(), xmlDate.getMinute(),
            xmlDate.getSecond());
    Date date = calendar.getTime();
    int millis = xmlDate.getMillisecond();
    if (millis != DatatypeConstants.FIELD_UNDEFINED) {
        calendar.setTimeInMillis(calendar.getTimeInMillis() + millis);
    }

    return date;
}

From source file:Main.java

public static XMLGregorianCalendar getXMLDate(final Calendar calendar) {
    GregorianCalendar c;/*  w w  w . j a v  a 2 s .  c o m*/
    if (calendar instanceof GregorianCalendar) {
        c = (GregorianCalendar) calendar;
    } else {
        c = new GregorianCalendar();
        c.setTimeZone(UTC);
        c.setTime(calendar.getTime());
    }

    try {
        XMLGregorianCalendar ret = DatatypeFactory.newInstance().newXMLGregorianCalendar(c);
        ret.setMillisecond(DatatypeConstants.FIELD_UNDEFINED);
        return ret;
    } catch (DatatypeConfigurationException e) {
        return null;
    }
}

From source file:Main.java

public static XMLGregorianCalendar getXMLDate(final Date dateAndTime) {
    GregorianCalendar c = new GregorianCalendar();
    c.setTimeZone(UTC);/* ww w.j  a v  a2 s  .  c  om*/
    c.setTime(dateAndTime);

    try {
        XMLGregorianCalendar ret = DatatypeFactory.newInstance().newXMLGregorianCalendar(c);
        ret.setMillisecond(DatatypeConstants.FIELD_UNDEFINED);
        return ret;
    } catch (DatatypeConfigurationException e) {
        return null;
    }
}

From source file:name.persistent.behaviours.PURLValidationSupport.java

private XMLGregorianCalendar today() throws DatatypeConfigurationException {
    GregorianCalendar cal;/*from   w w w .  j  ava  2  s .co m*/
    XMLGregorianCalendar today;
    int n = DatatypeConstants.FIELD_UNDEFINED;
    DatatypeFactory f = DatatypeFactory.newInstance();
    cal = new GregorianCalendar(TimeZone.getTimeZone("UTC"));
    today = f.newXMLGregorianCalendar(cal);
    today.setTime(n, n, n, n);
    return today;
}

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

/**
 * Create a new jaxb version of the session
 * //from  www  .j  a v a2 s .  com
 * @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:com.kcs.core.utilities.Utility.java

public static XMLGregorianCalendar getXMLGregorianCalendarDate(Date date)
        throws DatatypeConfigurationException {
    if (Utility.isNotNull(date)) {
        GregorianCalendar arrgCtrDate = new GregorianCalendar();
        arrgCtrDate.setTime(date);//w  w  w . j  a  v  a2 s .  c o m
        DatatypeFactory datatypeFactory = DatatypeFactory.newInstance();
        XMLGregorianCalendar xmlGregorianCalendar = datatypeFactory.newXMLGregorianCalendarDate(
                arrgCtrDate.get(Calendar.YEAR), arrgCtrDate.get(Calendar.MONTH) + 1,
                arrgCtrDate.get(Calendar.DAY_OF_MONTH), DatatypeConstants.FIELD_UNDEFINED);
        return xmlGregorianCalendar;
    }
    return null;
}

From source file:fr.xebia.springframework.jms.support.converter.JaxbMessageConverterSpringTest.java

@Test
public void testFromMessage() throws Exception {

    String xml = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>" + "<Employee>" + "<id>1</id>"
            + "<lastName>Le Clerc</lastName>" + "<firstName>Cyrille</firstName>" + "<gender>MALE</gender>"
            + "<birthdate>1976-01-05</birthdate>" + "</Employee>";
    Message message = session.createTextMessage(xml);

    Employee expected = new Employee(1, "Cyrille", "Le Clerc", Gender.MALE, DatatypeFactory.newInstance()
            .newXMLGregorianCalendarDate(1976, 01, 05, DatatypeConstants.FIELD_UNDEFINED));

    Employee actual = (Employee) jaxbMessageConverter.fromMessage(message);

    Assert.assertEquals(expected, actual);
}

From source file:fr.xebia.springframework.jms.support.converter.JaxbMessageConverterTest.java

@Test
public void testFromMessage() throws Exception {

    JaxbMessageConverter jaxbMessageConverter = createJaxbMessageConverter(Employee.class, Gender.class);

    String xml = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>" + "<Employee>" + "<id>1</id>"
            + "<lastName>Le Clerc</lastName>" + "<firstName>Cyrille</firstName>" + "<gender>MALE</gender>"
            + "<birthdate>1976-01-05</birthdate>" + "</Employee>";
    Message message = session.createTextMessage(xml);

    Employee expected = new Employee(1, "Cyrille", "Le Clerc", Gender.MALE, DatatypeFactory.newInstance()
            .newXMLGregorianCalendarDate(1976, 01, 05, DatatypeConstants.FIELD_UNDEFINED));

    Employee actual = (Employee) jaxbMessageConverter.fromMessage(message);

    Assert.assertEquals(expected, actual);
}

From source file:gov.nih.nci.cabig.caaers.api.InvestigatorMigratorServiceTest.java

private void modifyDates(Staff staff) throws Exception {

    DatatypeFactory df = DatatypeFactory.newInstance();
    Calendar gcNow = GregorianCalendar.getInstance();
    int year = gcNow.get(Calendar.YEAR);
    int month = gcNow.get(Calendar.MONTH) + 1;
    int day = gcNow.get(Calendar.DAY_OF_MONTH);
    int tz = DatatypeConstants.FIELD_UNDEFINED;

    XMLGregorianCalendar currXmlCal = df.newXMLGregorianCalendarDate(year, month, day, tz);
    XMLGregorianCalendar furXmlCal = df.newXMLGregorianCalendarDate(year + 1, month, day, tz);

    if (staff != null) {
        List<InvestigatorType> investigatorTypeList = staff.getInvestigator();
        for (InvestigatorType investigatorType : investigatorTypeList) {
            for (SiteInvestigatorType siType : investigatorType.getSiteInvestigator()) {
                siType.setStartDate(currXmlCal);
                siType.setEndDate(furXmlCal);
            }/*from ww w  .j a va2 s . c  om*/
        }
    }

}

From source file:fr.xebia.springframework.jms.support.converter.JaxbMessageConverterSpringTest.java

@Test
public void testToMessage() throws Exception {

    Employee employee = new Employee(1, "Cyrille", "Le Clerc", Gender.MALE, DatatypeFactory.newInstance()
            .newXMLGregorianCalendarDate(1976, 01, 05, DatatypeConstants.FIELD_UNDEFINED));

    TextMessage actualMessage = (TextMessage) jaxbMessageConverter.toMessage(employee, session);

    String actual = actualMessage.getText();
    String expected = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>" + "<Employee>"
            + "<id>1</id>" + "<lastName>Le Clerc</lastName>" + "<firstName>Cyrille</firstName>"
            + "<gender>MALE</gender>" + "<birthdate>1976-01-05</birthdate>" + "</Employee>";

    Assert.assertEquals(expected, actual);
}