Java Code Examples for javax.xml.datatype.DatatypeFactory

The following are top voted examples for showing how to use javax.xml.datatype.DatatypeFactory. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: oscm   File: ResellerShareResultAssembler.java   Source Code and License 11 votes vote down vote up
private Period preparePeriod(long periodStartTime, long periodEndTime)
        throws DatatypeConfigurationException {

    Period period = new Period();

    DatatypeFactory df = DatatypeFactory.newInstance();
    GregorianCalendar gc = new GregorianCalendar();

    // start date
    period.setStartDate(BigInteger.valueOf(periodStartTime));
    gc.setTimeInMillis(periodStartTime);
    period.setStartDateIsoFormat(df.newXMLGregorianCalendar(gc).normalize());

    // end date
    period.setEndDate(BigInteger.valueOf(periodEndTime));
    gc.setTimeInMillis(periodEndTime);
    period.setEndDateIsoFormat(df.newXMLGregorianCalendar(gc).normalize());

    return period;
}
 
Example 2
Project: FHIR-CQL-ODM-service   File: FhirService.java   Source Code and License 7 votes vote down vote up
private XMLGregorianCalendar getXMLGregorianCalendarNow()
		throws DatatypeConfigurationException {
	GregorianCalendar gregorianCalendar = new GregorianCalendar();
	DatatypeFactory datatypeFactory = DatatypeFactory.newInstance();
	XMLGregorianCalendar now = datatypeFactory
			.newXMLGregorianCalendar(gregorianCalendar);
	return now;
}
 
Example 3
Project: openjdk-jdk10   File: CalendarDuration1097Test.java   Source Code and License 7 votes vote down vote up
/**
 * main method.
 *
 * @param args Standard args.
 */
public static void main(String[] args) {
    try {
        String dateTimeString = "0001-01-01T00:00:00.0000000-05:00";
        DatatypeFactory dtf = DatatypeFactory.newInstance();
        XMLGregorianCalendar cal = dtf.newXMLGregorianCalendar( dateTimeString );
        System.out.println( "Expected: 0001-01-01T00:00:00.0000000-05:00");
        System.out.println( "Actual:" + cal.toString() );
        System.out.println( "toXMLFormat:" + cal.toXMLFormat() );
        String test = cal.toString();
        if (test.indexOf("E-7") > -1) {
            throw new RuntimeException("Expected: 0001-01-01T00:00:00.0000000-05:00");
        }
    } catch (DatatypeConfigurationException ex) {
        throw new RuntimeException(ex.getMessage());
    }
}
 
Example 4
Project: oscm   File: GregorianCalendars.java   Source Code and License 6 votes vote down vote up
/**
 * 
 * @return An object of type XMLGregorianCalendar containing the current
 *         system time and date
 * @throws DatatypeConfigurationException
 *             If the instantiation of the DatatypeFactory fails
 */
public static XMLGregorianCalendar newXMLGregorianCalendarSystemTime()
        throws DatatypeConfigurationException {
    GregorianCalendar gregorianCalendar = new GregorianCalendar();
    DatatypeFactory datatypeFactory = DatatypeFactory.newInstance();
    XMLGregorianCalendar now = datatypeFactory
            .newXMLGregorianCalendar(gregorianCalendar);
    return now;
}
 
Example 5
Project: oscm   File: BrokerShareResultAssemblerTest.java   Source Code and License 6 votes vote down vote up
@BeforeClass
public static void setup() throws Exception {
    SharesDataRetrievalServiceLocal sharesRetrievalService = mock(SharesDataRetrievalServiceLocal.class);
    BillingDataRetrievalServiceLocal billingRetrievalService = mock(BillingDataRetrievalServiceLocal.class);
    brokerShareAssembler = spy(new BrokerShareResultAssembler(
            sharesRetrievalService, billingRetrievalService));

    // create test data
    createBillingResults();

    // mock service methods
    mockGetBrokerData();
    mockGetBrokerRevenueSharePercentage();
    mockGetOrgData(NUMBER_SUPPLIERS);
    mockGetOrgData(NUMBER_CUSTOMER);
    mockGetSupplierKeyForSubscription();
    mockGetProductHistoryData();
    mockGetSubscriptionHistoryData();
    mockGetBillingResults();
    mockXmlSearch();
    datatypeFactory = DatatypeFactory.newInstance();
}
 
Example 6
Project: oscm   File: ResellerShareResultAssemblerTest.java   Source Code and License 6 votes vote down vote up
@Before
public void setup() throws Exception {
    SharesDataRetrievalServiceLocal sharesRetrievalService = mock(SharesDataRetrievalServiceLocal.class);
    BillingDataRetrievalServiceLocal billingRetrievalService = mock(BillingDataRetrievalServiceLocal.class);
    resellerShareAssembler = spy(new ResellerShareResultAssembler(
            sharesRetrievalService, billingRetrievalService));

    // create test data
    createBillingResults();

    // mock service methods
    mockGetResellerData();
    mockGetResellerRevenueSharePercentage();
    mockGetOrgData(NUMBER_SUPPLIERS);
    mockGetOrgData(NUMBER_CUSTOMER);
    mockGetSupplierKeyForSubscription();
    mockGetProductHistoryData();
    mockGetSubscriptionHistoryData();
    mockGetBillingResults();
    mockXmlSearch();
    datatypeFactory = DatatypeFactory.newInstance();
}
 
Example 7
Project: oscm   File: SupplierShareResultAssemblerTest.java   Source Code and License 6 votes vote down vote up
@BeforeClass
public static void setup() throws Exception {
    SharesDataRetrievalServiceLocal billingRetrievalService = mock(SharesDataRetrievalServiceLocal.class);
    when(
            billingRetrievalService.loadOrganizationHistoryRoles(anyLong(),
                    anyLong())).thenReturn(
            Arrays.asList(new OrganizationRole(
                    OrganizationRoleType.SUPPLIER)));
    supplierShareAssembler = spy(new SupplierShareResultAssembler(
            billingRetrievalService));

    createBillingResults();

    mockOrganizationData();
    mockOrganizationHistoryRoles();
    mockGetMarketplaceRevenueSharePercentage();
    mockGetOperatorRevenueSharePercentage();
    mockGetSellerRevenueSharePercentage();
    mockGetProductHistoryData();
    mockGetSubscriptionHistoryData();
    mockGetBillingResults();
    mockFindMarketplaceHistory();
    mockGetOrgData(CUSTOMER);
    mockXmlSearch();
    datatypeFactory = DatatypeFactory.newInstance();
}
 
Example 8
Project: oscm   File: BrokerShareResultAssembler.java   Source Code and License 6 votes vote down vote up
void setPeriod(long periodStartTime, long periodEndTime)
        throws DatatypeConfigurationException {
    this.periodEndTime = periodEndTime;

    Period period = new Period();

    DatatypeFactory df = DatatypeFactory.newInstance();
    GregorianCalendar gc = new GregorianCalendar();

    // start date
    period.setStartDate(BigInteger.valueOf(periodStartTime));
    gc.setTimeInMillis(periodStartTime);
    period.setStartDateIsoFormat(df.newXMLGregorianCalendar(gc).normalize());

    // end date
    period.setEndDate(BigInteger.valueOf(periodEndTime));
    gc.setTimeInMillis(periodEndTime);
    period.setEndDateIsoFormat(df.newXMLGregorianCalendar(gc).normalize());

    result.setPeriod(period);
}
 
Example 9
Project: oscm   File: MpOwnerShareResultAssembler.java   Source Code and License 6 votes vote down vote up
void setPeriod(long periodStartTime, long periodEndTime)
        throws DatatypeConfigurationException {

    this.periodStartTime = periodStartTime;
    this.periodEndTime = periodEndTime;

    Period period = new Period();

    DatatypeFactory df = DatatypeFactory.newInstance();
    GregorianCalendar gc = new GregorianCalendar();

    // start date
    period.setStartDate(BigInteger.valueOf(periodStartTime));
    gc.setTimeInMillis(periodStartTime);
    period.setStartDateIsoFormat(df.newXMLGregorianCalendar(gc).normalize());

    // end date
    period.setEndDate(BigInteger.valueOf(periodEndTime));
    gc.setTimeInMillis(periodEndTime);
    period.setEndDateIsoFormat(df.newXMLGregorianCalendar(gc).normalize());

    result.setPeriod(period);
}
 
Example 10
Project: oscm   File: SupplierShareResultAssembler.java   Source Code and License 6 votes vote down vote up
private Period preparePeriod(long periodStartTime, long periodEndTime)
        throws DatatypeConfigurationException {

    Period period = new Period();

    DatatypeFactory df = DatatypeFactory.newInstance();
    GregorianCalendar gc = new GregorianCalendar();

    period.setStartDate(BigInteger.valueOf(periodStartTime));
    gc.setTimeInMillis(periodStartTime);
    period.setStartDateIsoFormat(df.newXMLGregorianCalendar(gc).normalize());

    period.setEndDate(BigInteger.valueOf(periodEndTime));
    gc.setTimeInMillis(periodEndTime);
    period.setEndDateIsoFormat(df.newXMLGregorianCalendar(gc).normalize());

    return period;
}
 
Example 11
Project: docx4j-template   File: Docx4j_创建批注_S3_Test.java   Source Code and License 6 votes vote down vote up
public XMLGregorianCalendar toXMLCalendar(Date d) throws Exception {  
    GregorianCalendar gc = new GregorianCalendar();  
    gc.setTime(d);  
    XMLGregorianCalendar xml = DatatypeFactory.newInstance()  
            .newXMLGregorianCalendar();  
    xml.setYear(gc.get(Calendar.YEAR));  
    xml.setMonth(gc.get(Calendar.MONTH) + 1);  
    xml.setDay(gc.get(Calendar.DAY_OF_MONTH));  
    xml.setHour(gc.get(Calendar.HOUR_OF_DAY));  
    xml.setMinute(gc.get(Calendar.MINUTE));  
    xml.setSecond(gc.get(Calendar.SECOND));  
    return xml;  
}
 
Example 12
Project: OpenJSharp   File: DatatypeConverterImpl.java   Source Code and License 6 votes vote down vote up
public static DatatypeFactory getDatatypeFactory() {
    ClassLoader tccl = AccessController.doPrivileged(new PrivilegedAction<ClassLoader>() {
        public ClassLoader run() {
            return Thread.currentThread().getContextClassLoader();
        }
    });
    DatatypeFactory df = DF_CACHE.get(tccl);
    if (df == null) {
        synchronized (DatatypeConverterImpl.class) {
            df = DF_CACHE.get(tccl);
            if (df == null) { // to prevent multiple initialization
                try {
                    df = DatatypeFactory.newInstance();
                } catch (DatatypeConfigurationException e) {
                    throw new Error(Messages.FAILED_TO_INITIALE_DATATYPE_FACTORY.format(),e);
                }
                DF_CACHE.put(tccl, df);
            }
        }
    }
    return df;
}
 
Example 13
Project: OperatieBRP   File: VrijBerichtClientServiceImpl.java   Source Code and License 6 votes vote down vote up
private void vulStuurgegevens(final VrijBericht vrijBericht, final VrijBerichtStuurVrijBericht verzoek, final PartijCode zendendePartij)
        throws DatatypeConfigurationException {
    final GroepBerichtStuurgegevens stuurgegevens = objectFactory.createGroepBerichtStuurgegevens();
    stuurgegevens.setCommunicatieID(UUID.randomUUID().toString());
    final SysteemNaam zendendeSysteem = new SysteemNaam();
    final Referentienummer referentieNummer = new Referentienummer();
    final DatumTijd tijdstipVerzending = new DatumTijd();
    zendendeSysteem.setValue("BRP");
    referentieNummer.setValue(UUID.randomUUID().toString());
    final GregorianCalendar c = new GregorianCalendar();
    final XMLGregorianCalendar xmlDate = DatatypeFactory.newInstance().newXMLGregorianCalendar(c);
    c.setTime(vrijBericht.getTijdstipRegistratie());
    tijdstipVerzending.setValue(xmlDate);
    stuurgegevens.setZendendePartij(objectFactory.createGroepBerichtStuurgegevensZendendePartij(zendendePartij));
    stuurgegevens.setZendendeSysteem(objectFactory.createGroepBerichtStuurgegevensZendendeSysteem(zendendeSysteem));
    stuurgegevens.setReferentienummer(objectFactory.createGroepBerichtStuurgegevensReferentienummer(referentieNummer));
    stuurgegevens.setTijdstipVerzending(objectFactory.createGroepBerichtStuurgegevensTijdstipVerzending(tijdstipVerzending));
    verzoek.setStuurgegevens(objectFactory.createObjecttypeBerichtStuurgegevens(stuurgegevens));
}
 
Example 14
Project: jdk8u-jdk   File: TestXMLGregorianCalendarTimeZone.java   Source Code and License 6 votes vote down vote up
private static void test(int offsetMinutes)
        throws DatatypeConfigurationException {
    XMLGregorianCalendar calendar = DatatypeFactory.newInstance().
            newXMLGregorianCalendar();
    calendar.setTimezone(60 + offsetMinutes);
    TimeZone timeZone = calendar.getTimeZone(DatatypeConstants.FIELD_UNDEFINED);
    String expected = (offsetMinutes < 10 ? "GMT+01:0" : "GMT+01:")
            + offsetMinutes;
    if (!timeZone.getID().equals(expected)) {
        throw new RuntimeException("Test failed: expected timezone: " +
                expected + " Actual: " + timeZone.getID());
    }
}
 
Example 15
Project: openjdk-jdk10   File: CalendarDuration1243Test.java   Source Code and License 6 votes vote down vote up
/**
 * main method.
 *
 * @param args Standard args.
 */
public static void main(String[] args) {
    try {
        String dateTimeString = "2006-11-22T00:00:00.0+01:02";
        DatatypeFactory dtf = DatatypeFactory.newInstance();
        XMLGregorianCalendar cal = dtf.newXMLGregorianCalendar( dateTimeString );
        System.out.println( "XMLGregCal:" + cal.toString() );
        System.out.println( "GregCal:" + cal.toGregorianCalendar() );
        String toGCal = cal.toGregorianCalendar().toString();
        if (toGCal.indexOf("GMT+12:00") > -1) {
            throw new RuntimeException("Expected GMT+01:02");
        }
    } catch (DatatypeConfigurationException ex) {
        throw new RuntimeException(ex.getMessage());
    }
}
 
Example 16
Project: openjdk-jdk10   File: DatatypeConverterImpl.java   Source Code and License 6 votes vote down vote up
public static DatatypeFactory getDatatypeFactory() {
    ClassLoader tccl = AccessController.doPrivileged(new PrivilegedAction<ClassLoader>() {
        public ClassLoader run() {
            return Thread.currentThread().getContextClassLoader();
        }
    });
    DatatypeFactory df = DF_CACHE.get(tccl);
    if (df == null) {
        synchronized (DatatypeConverterImpl.class) {
            df = DF_CACHE.get(tccl);
            if (df == null) { // to prevent multiple initialization
                try {
                    df = DatatypeFactory.newInstance();
                } catch (DatatypeConfigurationException e) {
                    throw new Error(Messages.FAILED_TO_INITIALE_DATATYPE_FACTORY.format(),e);
                }
                DF_CACHE.put(tccl, df);
            }
        }
    }
    return df;
}
 
Example 17
Project: openjdk-jdk10   File: FactoryFindTest.java   Source Code and License 6 votes vote down vote up
@Test
public void testFactoryFind() throws Exception {
    DatatypeFactory factory = DatatypeFactory.newInstance();
    Assert.assertTrue(factory.getClass().getClassLoader() == null);

    runWithAllPerm(() -> Thread.currentThread().setContextClassLoader(null));

    factory = DatatypeFactory.newInstance();
    Assert.assertTrue(factory.getClass().getClassLoader() == null);

    runWithAllPerm(() -> Thread.currentThread().setContextClassLoader(new MyClassLoader()));
    factory = DatatypeFactory.newInstance();
    if (System.getSecurityManager() == null)
        Assert.assertTrue(myClassLoaderUsed);
    else
        Assert.assertFalse(myClassLoaderUsed);
}
 
Example 18
Project: openjdk-jdk10   File: DurationTest.java   Source Code and License 6 votes vote down vote up
@Test
public void testDurationSubtract() {
    try {
        Duration bigDur = DatatypeFactory.newInstance().newDuration(20000);
        Duration smallDur = DatatypeFactory.newInstance().newDuration(10000);
        if (smallDur.subtract(bigDur).getSign() != -1) {
            Assert.fail("smallDur.subtract(bigDur).getSign() is not -1");
        }
        if (bigDur.subtract(smallDur).getSign() != 1) {
            Assert.fail("bigDur.subtract(smallDur).getSign() is not 1");
        }
        if (smallDur.subtract(smallDur).getSign() != 0) {
            Assert.fail("smallDur.subtract(smallDur).getSign() is not 0");
        }
    } catch (DatatypeConfigurationException e) {
        e.printStackTrace();
    }
}
 
Example 19
Project: openjdk-jdk10   File: DurationTest.java   Source Code and License 6 votes vote down vote up
@Test
public void testDurationMultiply() {
    int num = 5000; // millisends. 5 seconds
    int factor = 2;
    try {
        Duration dur = DatatypeFactory.newInstance().newDuration(num);
        if (dur.multiply(factor).getSeconds() != 10) {
            Assert.fail("duration.multiply() return wrong value");
        }
        // factor is 2*10^(-1)
        if (dur.multiply(new BigDecimal(new BigInteger("2"), 1)).getSeconds() != 1) {
            Assert.fail("duration.multiply() return wrong value");
        }
        if (dur.subtract(DatatypeFactory.newInstance().newDuration(1000)).multiply(new BigDecimal(new BigInteger("2"), 1)).getSeconds() != 0) {
            Assert.fail("duration.multiply() return wrong value");
        }
    } catch (DatatypeConfigurationException e) {
        e.printStackTrace();
    }
}
 
Example 20
Project: openjdk-jdk10   File: DurationTest.java   Source Code and License 6 votes vote down vote up
@Test
public void testDurationAndCalendar1() {
    int year = 1;
    int month = 2;
    int day = 3;
    int hour = 4;
    int min = 5;
    int sec = 6;
    String lexicalRepresentation = "P" + year + "Y" + month + "M" + day + "DT" + hour + "H" + min + "M" + sec + "S";
    try {
        Duration dur = DatatypeFactory.newInstance().newDuration(lexicalRepresentation);
        System.out.println(dur.toString());
        AssertJUnit.assertTrue("year should be 1", dur.getYears() == year);
        AssertJUnit.assertTrue("month should be 2", dur.getMonths() == month);
        AssertJUnit.assertTrue("day should be 3", dur.getDays() == day);
        AssertJUnit.assertTrue("hour should be 4", dur.getHours() == hour);
        AssertJUnit.assertTrue("minute should be 5", dur.getMinutes() == min);
        AssertJUnit.assertTrue("second should be 6", dur.getSeconds() == sec);
    } catch (DatatypeConfigurationException e) {
        e.printStackTrace();
    }
}
 
Example 21
Project: openjdk-jdk10   File: DurationTest.java   Source Code and License 6 votes vote down vote up
@Test
public void testDurationAndCalendar3() {
    try {
        Calendar cal = new GregorianCalendar();
        cal.set(Calendar.SECOND, 59);
        DatatypeFactory.newInstance().newDuration(10000).addTo(cal);
        AssertJUnit.assertTrue("sec will be 9", cal.get(Calendar.SECOND) == 9);

        Date date = new Date();
        date.setSeconds(59);
        DatatypeFactory.newInstance().newDuration(10000).addTo(date);
        AssertJUnit.assertTrue("sec will be 9", date.getSeconds() == 9);
    } catch (DatatypeConfigurationException e) {
        e.printStackTrace();
    }
}
 
Example 22
Project: weixinpay   File: DateUtil.java   Source Code and License 6 votes vote down vote up
public static XMLGregorianCalendar convertDateToXMLGregorianCalendar(Date date) {
    GregorianCalendar c = new GregorianCalendar();
    c.setTime(date);
    int year = c.get(Calendar.YEAR);
    int month = c.get(Calendar.MONTH);
    int day = c.get(Calendar.DAY_OF_MONTH);

    XMLGregorianCalendar xt = null;
    try {
        xt = DatatypeFactory.newInstance().newXMLGregorianCalendar(year, month + 1, day, 0, 0, 0, 0, 0);
    } catch (DatatypeConfigurationException e) {
        e.printStackTrace();
    }

    return xt;
}
 
Example 23
Project: openjdk9   File: CalendarDuration1243Test.java   Source Code and License 6 votes vote down vote up
/**
 * main method.
 *
 * @param args Standard args.
 */
public static void main(String[] args) {
    try {
        String dateTimeString = "2006-11-22T00:00:00.0+01:02";
        DatatypeFactory dtf = DatatypeFactory.newInstance();
        XMLGregorianCalendar cal = dtf.newXMLGregorianCalendar( dateTimeString );
        System.out.println( "XMLGregCal:" + cal.toString() );
        System.out.println( "GregCal:" + cal.toGregorianCalendar() );
        String toGCal = cal.toGregorianCalendar().toString();
        if (toGCal.indexOf("GMT+12:00") > -1) {
            throw new RuntimeException("Expected GMT+01:02");
        }
    } catch (DatatypeConfigurationException ex) {
        throw new RuntimeException(ex.getMessage());
    }
}
 
Example 24
Project: ade   File: LastSeenLoggingScorerContinuous.java   Source Code and License 6 votes vote down vote up
/**
 * Creates variables used by this class for tracking last seen messages. 
 * m_prevIntervalTimelineMap contains the previous timeline (milliseconds from epoch time)
 * for each message ID. m_alreadySeen contains the message IDs of those messages that were seen
 * previously. 
 * @throws AdeException
 */
private final void createUsageVariables() throws AdeException {
    String dataObjectName = getAnalysisGroup() + "." + getName() + ".m_prevIntervalTimelineMap";
    Object tmp = Ade.getAde().getDataStore().models().getModelDataObject(dataObjectName);
    instantiateTimelineAndAlreadySeen(dataObjectName,tmp);

    dataObjectName = getAnalysisGroup() + "." + getName() + ".m_alreadySeen";
    tmp = Ade.getAde().getDataStore().models().getModelDataObject(dataObjectName);
    instantiateTimelineAndAlreadySeen(dataObjectName,tmp);

    if (m_dataTypeFactory == null) {
        try {
            m_dataTypeFactory = DatatypeFactory.newInstance();
        } catch (DatatypeConfigurationException e) {
            throw new AdeInternalException("Failed to instantiate data factory for calendar", e);
        }
    }

    if (m_gc == null) {
        final TimeZone outputTimeZone = Ade.getAde().getConfigProperties().getOutputTimeZone();
        m_gc = new GregorianCalendar(outputTimeZone);
    }
}
 
Example 25
Project: openjdk9   File: DatatypeConverterImpl.java   Source Code and License 6 votes vote down vote up
public static DatatypeFactory getDatatypeFactory() {
    ClassLoader tccl = AccessController.doPrivileged(new PrivilegedAction<ClassLoader>() {
        public ClassLoader run() {
            return Thread.currentThread().getContextClassLoader();
        }
    });
    DatatypeFactory df = DF_CACHE.get(tccl);
    if (df == null) {
        synchronized (DatatypeConverterImpl.class) {
            df = DF_CACHE.get(tccl);
            if (df == null) { // to prevent multiple initialization
                try {
                    df = DatatypeFactory.newInstance();
                } catch (DatatypeConfigurationException e) {
                    throw new Error(Messages.FAILED_TO_INITIALE_DATATYPE_FACTORY.format(),e);
                }
                DF_CACHE.put(tccl, df);
            }
        }
    }
    return df;
}
 
Example 26
Project: Open-Clinica-Data-Uploader   File: SoapUtils.java   Source Code and License 6 votes vote down vote up
public static XMLGregorianCalendar getFullXmlDate(String dateString) {
    try {
        Calendar calendar = GregorianCalendar.getInstance();
        if (! StringUtils.isEmpty(dateString)) {
            DateFormat dateFormat = new SimpleDateFormat("dd-MM-yyyy");
            Date date = dateFormat.parse(dateString);
            calendar.setTime(date);
        }
        return DatatypeFactory.newInstance().newXMLGregorianCalendarDate(calendar.get(Calendar.YEAR),
                calendar.get(Calendar.MONTH) + 1, calendar.get(Calendar.DAY_OF_MONTH), DatatypeConstants.FIELD_UNDEFINED);
    }
    catch (Exception e) {
        e.printStackTrace();
        return null;
    }
}
 
Example 27
Project: openjdk9   File: FactoryFindTest.java   Source Code and License 6 votes vote down vote up
@Test
public void testFactoryFind() {
    try {
        // System.setProperty("jaxp.debug", "true");

        DatatypeFactory factory = DatatypeFactory.newInstance();
        Assert.assertTrue(factory.getClass().getClassLoader() == null);

        Thread.currentThread().setContextClassLoader(null);
        factory = DatatypeFactory.newInstance();
        Assert.assertTrue(factory.getClass().getClassLoader() == null);

        Thread.currentThread().setContextClassLoader(new MyClassLoader());
        factory = DatatypeFactory.newInstance();
        if (System.getSecurityManager() == null)
            Assert.assertTrue(myClassLoaderUsed);
        else
            Assert.assertFalse(myClassLoaderUsed);
    } catch (Exception ex) {
    }

}
 
Example 28
Project: eSDK_IVS_Java   File: DateUtils.java   Source Code and License 6 votes vote down vote up
/**
 * 获取UTC时间
 * @return
 */
public static XMLGregorianCalendar getCurrentUTCTime()
{
    Date date = new Date();
    GregorianCalendar nowGregorianCalendar = new GregorianCalendar();
    XMLGregorianCalendar xmlDatetime = null;
    try
    {
        nowGregorianCalendar.setTime(date);
        xmlDatetime = DatatypeFactory.newInstance()
                .newXMLGregorianCalendar(nowGregorianCalendar);
    }
    catch (DatatypeConfigurationException e)
    {
        LOGGER.error("", e);
    }
    return xmlDatetime;
}
 
Example 29
Project: openjdk9   File: DurationTest.java   Source Code and License 6 votes vote down vote up
@Test
public void testDurationSubtract() {
    try {
        Duration bigDur = DatatypeFactory.newInstance().newDuration(20000);
        Duration smallDur = DatatypeFactory.newInstance().newDuration(10000);
        if (smallDur.subtract(bigDur).getSign() != -1) {
            Assert.fail("smallDur.subtract(bigDur).getSign() is not -1");
        }
        if (bigDur.subtract(smallDur).getSign() != 1) {
            Assert.fail("bigDur.subtract(smallDur).getSign() is not 1");
        }
        if (smallDur.subtract(smallDur).getSign() != 0) {
            Assert.fail("smallDur.subtract(smallDur).getSign() is not 0");
        }
    } catch (DatatypeConfigurationException e) {
        e.printStackTrace();
    }
}
 
Example 30
Project: openjdk9   File: DurationTest.java   Source Code and License 6 votes vote down vote up
@Test
public void testDurationAndCalendar3() {
    try {
        Calendar cal = new GregorianCalendar();
        cal.set(Calendar.SECOND, 59);
        DatatypeFactory.newInstance().newDuration(10000).addTo(cal);
        AssertJUnit.assertTrue("sec will be 9", cal.get(Calendar.SECOND) == 9);

        Date date = new Date();
        date.setSeconds(59);
        DatatypeFactory.newInstance().newDuration(10000).addTo(date);
        AssertJUnit.assertTrue("sec will be 9", date.getSeconds() == 9);
    } catch (DatatypeConfigurationException e) {
        e.printStackTrace();
    }
}
 
Example 31
Project: iws   File: CommonMapper.java   Source Code and License 6 votes vote down vote up
private static XMLGregorianCalendar map(final java.util.Date date) {
    XMLGregorianCalendar converted = null;

    if (date != null) {
        final GregorianCalendar calendar = new GregorianCalendar();
        // Throws a NullPointerException without the null check
        calendar.setTime(date);

        try {
            converted = DatatypeFactory.newInstance().newXMLGregorianCalendar(calendar);
        } catch (DatatypeConfigurationException e) {
            throw new IWSException(IWSErrors.ERROR, e.getMessage(), e);
        }
    }

    return converted;
}
 
Example 32
Project: eSDK_IVS_Java   File: DateUtils.java   Source Code and License 6 votes vote down vote up
/**
 * 将时间转换为格林威治时间格式的字符串
 * 
 * @param date 需要格式化的时间
 * @return 格式化后的时间格式
 */
public static String date2GregorianFormat(Date date)
{
    if (null == date)
    {
     return "";   
    }
    try
    {
        DatatypeFactory factory = DatatypeFactory.newInstance();
        GregorianCalendar gCal = (GregorianCalendar) GregorianCalendar
                .getInstance();
        gCal.setTime(date);
        String result = factory.newXMLGregorianCalendar(gCal).toString();

        return result;
    }
    catch (DatatypeConfigurationException e)
    {
        LOGGER.error("date2GregorianFromatd error", e);
        return date.toString();
    }
}
 
Example 33
Project: rm-common-service   File: DateTimeUtil.java   Source Code and License 6 votes vote down vote up
/**
 * To get a XMLGregorianCalendar for now
 * @return a XMLGregorianCalendar for now
 * @throws DatatypeConfigurationException if it can't create a calendar
 */
public static XMLGregorianCalendar giveMeCalendarForNow() throws DatatypeConfigurationException {
  GregorianCalendar gregorianCalendar = new GregorianCalendar();
  gregorianCalendar.setTime(new Date());

  XMLGregorianCalendar result = null;
  DatatypeFactory factory = DatatypeFactory.newInstance();
  result = factory.newXMLGregorianCalendar(
          gregorianCalendar.get(GregorianCalendar.YEAR),
          gregorianCalendar.get(GregorianCalendar.MONTH) + 1,
          gregorianCalendar.get(GregorianCalendar.DAY_OF_MONTH),
          gregorianCalendar.get(GregorianCalendar.HOUR_OF_DAY),
          gregorianCalendar.get(GregorianCalendar.MINUTE),
          gregorianCalendar.get(GregorianCalendar.SECOND),
          gregorianCalendar.get(GregorianCalendar.MILLISECOND), 0);
  return result;
}
 
Example 34
Project: eSDK_IVS_Java   File: DurationUtils.java   Source Code and License 6 votes vote down vote up
/**
 * 输入以分钟为单位的数据,返回duration类型数据
 * * @param dur
/** * @return
 */
public static Duration durationInt2dur(Integer dur)
{
    Duration duration = null;
    try
    {
        if (0<=dur)
        {
            duration = DatatypeFactory.newInstance().newDuration("PT"+Math.abs(dur)+"M");
        }else {
            duration = DatatypeFactory.newInstance().newDuration("-PT"+Math.abs(dur)+"M");
        }
       
    }
    catch (DatatypeConfigurationException e)
    {
        e.printStackTrace();
    }
    return duration;
}
 
Example 35
Project: eSDK_EC_SDK_Java   File: DateUtils.java   Source Code and License 6 votes vote down vote up
/**
 * Date类型转XMLGregorianCalendar类型 * @param date * @return 用于预约周期会议返回的情况
 */
public static XMLGregorianCalendar toGregorianCalendarDateSMC(Date date)
{

    if (null == date)
    {
        return null;
    }
    GregorianCalendar nowGregorianCalendar = new GregorianCalendar();
    XMLGregorianCalendar xmlDatetime = null;
    try
    {
        nowGregorianCalendar.setTime(date);
        xmlDatetime = DatatypeFactory.newInstance()
                .newXMLGregorianCalendar(nowGregorianCalendar);
    }
    catch (DatatypeConfigurationException e)
    {
        LOGGER.error("", e);
    }
    return xmlDatetime;
}
 
Example 36
Project: Tazbot   File: Youtube.java   Source Code and License 6 votes vote down vote up
public static int getDuration(String id) throws IOException, JSONException, QuotaExceededException {
	try {
		String apiString = "https://www.googleapis.com/youtube/v3/videos?part=contentDetails&id=" + id + "&key=" + key;
		String response = WebUtil.getWebPage(apiString); //siteToString(new URL(apiString));
		JSONObject js = new JSONObject(response);
		Duration dur = DatatypeFactory.newInstance().newDuration(
				js.getJSONArray("items").getJSONObject(0).getJSONObject("contentDetails").getString("duration"));
		int hours = dur.getHours();
		int minutes = dur.getMinutes();
		int seconds = dur.getSeconds();
		int totalSeconds = (hours * 3600) + (minutes * 60) + seconds;
		return totalSeconds;
	} catch (DatatypeConfigurationException e) {
		e.printStackTrace();
	}
	return -1;
}
 
Example 37
Project: irsclient   File: InterceptorUtils.java   Source Code and License 6 votes vote down vote up
static XMLGregorianCalendar getTimeNowAsXMLGregorianCalendar() {
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
    /*
     Most important. Please check your machine's/workstations/VM's time if WS-Security header error TPE1122 occurs.
     For unix/linux you can use ntp or run below command.
     sudo date -s "$(wget -qSO- --max-redirect=0 google.com 2>&1 | grep Date: | cut -d' ' -f5-8)Z"
    */

    sdf.setTimeZone(TimeZone.getTimeZone("UTC"));
    String date = sdf.format(new Date());

    XMLGregorianCalendar xMLGregorianCalendar = null;
    try {
        xMLGregorianCalendar = DatatypeFactory.newInstance().newXMLGregorianCalendar(date);
    } catch (DatatypeConfigurationException e) {
        LOG.error("Error: ", e);
    }
    return xMLGregorianCalendar;
}
 
Example 38
Project: Reer   File: DefaultClassLoaderFactory.java   Source Code and License 5 votes vote down vote up
@Override
public ClassLoader createFilteringClassLoader(ClassLoader parent, FilteringClassLoader.Spec spec) {
    // See the comment for {@link #createIsolatedClassLoader} above
    FilteringClassLoader.Spec classLoaderSpec = new FilteringClassLoader.Spec(spec);
    if (needJaxpImpl()) {
        makeServiceVisible(systemClassLoaderServiceLocator, classLoaderSpec, SAXParserFactory.class);
        makeServiceVisible(systemClassLoaderServiceLocator, classLoaderSpec, DocumentBuilderFactory.class);
        makeServiceVisible(systemClassLoaderServiceLocator, classLoaderSpec, DatatypeFactory.class);
    }
    return doCreateFilteringClassLoader(parent, classLoaderSpec);
}
 
Example 39
Project: GitHub   File: CalendarCodec.java   Source Code and License 5 votes vote down vote up
public XMLGregorianCalendar createXMLGregorianCalendar(Calendar calendar) {
    if (dateFactory == null) {
        try {
            dateFactory = DatatypeFactory.newInstance();
        } catch (DatatypeConfigurationException e) {
            throw new IllegalStateException("Could not obtain an instance of DatatypeFactory.", e);
        }
    }
    return dateFactory.newXMLGregorianCalendar((GregorianCalendar) calendar);
}
 
Example 40
Project: GitHub   File: Issue1023.java   Source Code and License 5 votes vote down vote up
public void test_for_issue() throws Exception {
    Date now = new Date();

    GregorianCalendar gregorianCalendar = (GregorianCalendar) GregorianCalendar.getInstance();
    gregorianCalendar.setTime(now);

    XMLGregorianCalendar calendar = DatatypeFactory.newInstance().newXMLGregorianCalendar(gregorianCalendar);

    String jsonString = JSON.toJSONString(calendar);
    // success
    calendar = JSON.parseObject(jsonString, XMLGregorianCalendar.class);

    Object toJSON1 = JSON.toJSON(calendar); // debug看到是 Long 类型
    // 所以这里会报错:
    // error: java.lang.ClassCastException: java.lang.Long cannot be cast to com.alibaba.fastjson.JSONObject
    //JSONObject jsonObject = (JSONObject) JSON.toJSON(calendar);
    // 所以 这里肯定会报错, 因为 jsonObject 不是JSONObject类型
    //calendar = jsonObject.toJavaObject(XMLGregorianCalendar.class);

    List<XMLGregorianCalendar> calendarList = new ArrayList<XMLGregorianCalendar>();
    calendarList.add(calendar);
    calendarList.add(calendar);
    calendarList.add(calendar);

    Object toJSON2 = JSON.toJSON(calendarList); // debug 看到是 JSONArray 类型

    // success: 通过 JSONArray.parseArray 方法可以正确转换
    JSONArray jsonArray = (JSONArray) JSON.toJSON(calendarList);
    jsonString = jsonArray.toJSONString();
    List<XMLGregorianCalendar> calendarList1 = JSONArray.parseArray(jsonString, XMLGregorianCalendar.class);

    // 通过 jsonArray.toJavaList 无法转换
    // error: com.alibaba.fastjson.JSONException: can not cast to : javax.xml.datatype.XMLGregorianCalendar
    List<XMLGregorianCalendar> calendarList2 = jsonArray.toJavaList(XMLGregorianCalendar.class);
    assertNotNull(calendarList2);
    assertEquals(3, calendarList2.size());
}
 
Example 41
Project: rapidminer   File: XMLTools.java   Source Code and License 5 votes vote down vote up
public static XMLGregorianCalendar getXMLGregorianCalendar(Date date) {
	if (date == null) {
		return null;
	}
	// Calendar calendar = Calendar.getInstance();
	// calendar.setTimeInMillis(date.getTime());
	DatatypeFactory datatypeFactory;
	try {
		datatypeFactory = DatatypeFactory.newInstance();
	} catch (DatatypeConfigurationException e) {
		throw new RuntimeException("Failed to create XMLGregorianCalendar: " + e, e);
	}
	GregorianCalendar c = new GregorianCalendar();
	c.setTime(date);
	return datatypeFactory.newXMLGregorianCalendar(c);
	//
	// XMLGregorianCalendar xmlGregorianCalendar = datatypeFactory.newXMLGregorianCalendar();
	// xmlGregorianCalendar.setYear(calendar.get(Calendar.YEAR));
	// xmlGregorianCalendar.setMonth(calendar.get(Calendar.MONTH) + 1);
	// xmlGregorianCalendar.setDay(calendar.get(Calendar.DAY_OF_MONTH));
	// xmlGregorianCalendar.setHour(calendar.get(Calendar.HOUR_OF_DAY));
	// xmlGregorianCalendar.setMinute(calendar.get(Calendar.MINUTE));
	// xmlGregorianCalendar.setSecond(calendar.get(Calendar.SECOND));
	// xmlGregorianCalendar.setMillisecond(calendar.get(Calendar.MILLISECOND));
	// //
	// xmlGregorianCalendar.setTimezone(calendar.get(((Calendar.DST_OFFSET)+calendar.get(Calendar.ZONE_OFFSET))/(60*1000)));
	// return xmlGregorianCalendar;
}
 
Example 42
Project: cim-processor   File: ModelParser.java   Source Code and License 5 votes vote down vote up
public AppliedOutages applyOutages(Calendar calendar, boolean assumeConnected) {
	appliedOutages = ModelParser.applyOutages(calendar, rdfModel, assumeConnected);
	GregorianCalendar gregorianCalendar = new GregorianCalendar();
	gregorianCalendar.setTime(appliedOutages.getEffectiveEnd().getTime());
	try {
		DatatypeFactory factory = DatatypeFactory.newInstance();
		endDate = factory.newXMLGregorianCalendar(gregorianCalendar);
		Duration oneSecond = factory.newDuration("PT1S");
		endDate.add(oneSecond);
	} catch (DatatypeConfigurationException e) {
		// do nothing
	}
	return appliedOutages;
}
 
Example 43
Project: camunda-util-demo-data-generator   File: TimeAwareDemoGenerator.java   Source Code and License 5 votes vote down vote up
public TimeAwareDemoGenerator(ProcessEngine engine, ProcessApplicationReference originalProcessApplicationReference,
    ProcessApplicationReference simulatingProcessApplicationReference) {
  this.engine = engine;
  this.originalProcessApplication = originalProcessApplicationReference;
  this.simulatingProcessApplication = simulatingProcessApplicationReference;
  try {
    datatypeFactory = DatatypeFactory.newInstance();
  } catch (DatatypeConfigurationException e) {
    throw new RuntimeException(e);
  }
}
 
Example 44
Project: stroom-stats   File: StatisticsHelper.java   Source Code and License 5 votes vote down vote up
private static Statistics.Statistic buildStatistic(ZonedDateTime time, TagType... tagValues) {
    ObjectFactory objectFactory = new ObjectFactory();
    Statistics.Statistic statistic = objectFactory.createStatisticsStatistic();
    Statistics.Statistic.Tags tagsObj = new Statistics.Statistic.Tags();
    tagsObj.getTag().addAll(Arrays.asList(tagValues));
    statistic.setTags(tagsObj);
    GregorianCalendar gregorianCalendar = GregorianCalendar.from(time);
    try {
        statistic.setTime(DatatypeFactory.newInstance().newXMLGregorianCalendar(gregorianCalendar));
    } catch (DatatypeConfigurationException e) {
        throw new RuntimeException(String.format("Error converting time %s to a gregorian calendar", time), e);
    }
    return statistic;
}
 
Example 45
Project: alfresco-repository   File: CMISConnector.java   Source Code and License 5 votes vote down vote up
private String convertAspectPropertyValue(Object value)
{
    if (value instanceof Date)
    {
        GregorianCalendar cal = new GregorianCalendar(TimeZone.getTimeZone("GMT"));
        cal.setTime((Date) value);
        value = cal;
    }

    if (value instanceof GregorianCalendar)
    {
        DatatypeFactory df;
        try
        {
            df = DatatypeFactory.newInstance();
        }
        catch (DatatypeConfigurationException e)
        {
            throw new IllegalArgumentException("Aspect conversation exception: " + e.getMessage(), e);
        }
        return df.newXMLGregorianCalendar((GregorianCalendar) value).toXMLFormat();
    }

    // MNT-12496 MNT-15044
    // Filter for AtomPub and Web services bindings only. Browser/json binding already encodes.
    if (AlfrescoCmisServiceCall.get() != null &&
            (CallContext.BINDING_ATOMPUB.equals(AlfrescoCmisServiceCall.get().getBinding()) ||
             CallContext.BINDING_WEBSERVICES.equals(AlfrescoCmisServiceCall.get().getBinding())))
    {
    	return filterXmlRestrictedCharacters(value.toString());
    }
    else
    {
    	return value.toString();
    }
}
 
Example 46
Project: css-elasticsearch   File: DateUtil.java   Source Code and License 5 votes vote down vote up
/**
 * <pre>
 * 描述:日期转XMLGregorianCalendar
 * 作者:ZhangYi
 * 时间:2016年5月5日 下午4:13:36
 * 参数:(参数列表)
 * @param date	日期
 * @return
 * </pre>
 */
public static XMLGregorianCalendar getXMLCalendar(Date date) {
	DatatypeFactory datatypeFactory = null;
	try {
		datatypeFactory = DatatypeFactory.newInstance();
	} catch (DatatypeConfigurationException e) {
		logger.error("获取时间转换工厂时发生错误", e);
	}
	GregorianCalendar calendar = new GregorianCalendar();
	calendar.setTime(date);
	XMLGregorianCalendar datetime = datatypeFactory.newXMLGregorianCalendar(calendar);
	return datetime;
}
 
Example 47
Project: the-vigilantes   File: Value.java   Source Code and License 5 votes vote down vote up
public void setDateTime(GregorianCalendar value) throws DatatypeConfigurationException {
    if (this.dtf == null) {
        this.dtf = DatatypeFactory.newInstance();
    }
    this.objValue = this.dtf.newXMLGregorianCalendar(value);
    this.objType = TYPE_dateTime_iso8601;
}
 
Example 48
Project: the-vigilantes   File: Value.java   Source Code and License 5 votes vote down vote up
public void setDateTime(String value) throws DatatypeConfigurationException {
    if (this.dtf == null) {
        this.dtf = DatatypeFactory.newInstance();
    }
    this.objValue = this.dtf.newXMLGregorianCalendar(value);
    this.objType = TYPE_dateTime_iso8601;
}
 
Example 49
Project: airsonic   File: JAXBWriter.java   Source Code and License 5 votes vote down vote up
public JAXBWriter() {
    try {
        jaxbContext = JAXBContext.newInstance(Response.class);
        datatypeFactory = DatatypeFactory.newInstance();
        restProtocolVersion = getRESTProtocolVersion();
    } catch (Exception x) {
        throw new RuntimeException(x);
    }
}
 
Example 50
Project: xitk   File: XmlUtil.java   Source Code and License 5 votes vote down vote up
public static XMLGregorianCalendar getXmlDate(Date dateAndTime) {
    ParamUtil.requireNonNull("dateAndTime", dateAndTime);
    GregorianCalendar cal = new GregorianCalendar();
    cal.setTimeZone(UTC);
    cal.setTime(dateAndTime);

    try {
        XMLGregorianCalendar ret = DatatypeFactory.newInstance().newXMLGregorianCalendar(cal);
        ret.setMillisecond(DatatypeConstants.FIELD_UNDEFINED);
        return ret;
    } catch (DatatypeConfigurationException ex) {
        return null;
    }
}
 
Example 51
Project: oscm   File: ObjectFactoryTest.java   Source Code and License 5 votes vote down vote up
private Object getInputArgument(Class<?> clazz,
        boolean testSettersAndGetters) throws Exception {

    if (clazz.isAssignableFrom(String.class)) {
        return new String("Dummy Value String");
    } else if (clazz.isAssignableFrom(XMLGregorianCalendar.class)) {
        return DatatypeFactory.newInstance().newXMLGregorianCalendar();
    } else if (clazz.isAssignableFrom(Boolean.class)) {
        return new Boolean(true);
    } else if (clazz.isAssignableFrom(Integer.class)) {
        return new Integer(5);
    } else if (clazz.isAssignableFrom(BigInteger.class)) {
        return new BigInteger("5");
    } else if (clazz.isAssignableFrom(byte[].class)) {
        return new byte[5];
    } else if (clazz.isAssignableFrom(Duration.class)) {
        return DatatypeFactory.newInstance().newDuration(100L);
    } else if (clazz.isEnum()) {
        return clazz.getEnumConstants()[0];
    } else {
        Object typeObject = createTypeFromObjectFactory(clazz);
        if (testSettersAndGetters) {
            testSettersAndGetters(typeObject);
        }
        return typeObject;
    }
}
 
Example 52
Project: lemon   File: DeadlineHumanTaskListener.java   Source Code and License 5 votes vote down vote up
@Override
public void onCreate(TaskInfo taskInfo) {
    String taskDefinitionKey = taskInfo.getCode();

    String processDefinitionId = taskInfo.getProcessDefinitionId();
    List<DeadlineDTO> deadlines = taskDefinitionConnector.findDeadlines(
            taskDefinitionKey, processDefinitionId);

    for (DeadlineDTO deadline : deadlines) {
        try {
            String durationText = deadline.getDuration();

            Date now = new Date();
            Calendar calendar = Calendar.getInstance();
            calendar.setTime(now);

            DatatypeFactory datatypeFactory = DatatypeFactory.newInstance();
            Duration duration = datatypeFactory.newDuration(durationText);
            duration.addTo(calendar);

            Date deadlineTime = calendar.getTime();
            TaskDeadline taskDeadline = new TaskDeadline();
            taskDeadline.setTaskInfo(taskInfo);
            taskDeadline.setType(deadline.getType());
            taskDeadline.setDeadlineTime(deadlineTime);
            taskDeadline
                    .setNotificationType(deadline.getNotificationType());
            taskDeadline.setNotificationTemplateCode(deadline
                    .getNotificationTemplateCode());
            taskDeadline.setNotificationReceiver(deadline
                    .getNotificationReceiver());
            taskDeadlineManager.save(taskDeadline);
        } catch (Exception ex) {
            logger.error(ex.getMessage(), ex);
        }
    }
}
 
Example 53
Project: spr   File: SqlSelects.java   Source Code and License 5 votes vote down vote up
public static List<Plan> selectAllPlanes() throws SQLException, DatatypeConfigurationException{
 	 	Connection conect=ConnectionConfiguration.conectar();String query = " select * from plan";
 Statement statement = null; ResultSet rs=null;
 List<Plan> objetos = new ArrayList<Plan>();

try {
	statement = conect.createStatement();
	rs=statement.executeQuery(query);
	
	while(rs.next()){
		GregorianCalendar c = new GregorianCalendar();c.setTime(rs.getDate("fecha_inicio"));
		XMLGregorianCalendar fini = DatatypeFactory.newInstance().newXMLGregorianCalendar(c);
		GregorianCalendar c2 = new GregorianCalendar();c2.setTime(rs.getDate("fecha_fin"));
		XMLGregorianCalendar ffin = DatatypeFactory.newInstance().newXMLGregorianCalendar(c2);
		Plan objeto = new Plan();
		objeto.setCodigoPlan(rs.getShort("id"));
		objeto.setEntidadResponsable(rs.getString("entidad_responsable"));
		objeto.setPlanNombre(rs.getString("nombre"));
		objeto.setPlanDescripcion(rs.getString("descripcion"));
		objeto.setPlanDetalle(rs.getString("detalle"));
		objeto.setPlanDesde(fini);
		objeto.setPlanHasta(ffin);
		
		objetos.add(objeto);
	}
}
catch (SQLException e) {e.printStackTrace();}
finally{
	if (statement != null) {statement.close();}
	if (conect != null) {conect.close();}
}
return objetos;
 }
 
Example 54
Project: cxf-spring-cloud-netflix-docker   File: GetCityForecastByZIPOutMapper.java   Source Code and License 5 votes vote down vote up
private static XMLGregorianCalendar generateCalendarFromNow() {
	GregorianCalendar gregCal = GregorianCalendar.from(ZonedDateTime.now());
	XMLGregorianCalendar xmlGregCal = null;
	try {
		xmlGregCal = DatatypeFactory.newInstance().newXMLGregorianCalendar(gregCal);
	} catch (DatatypeConfigurationException exception) {
		LOG.info("Calendermapping not working, but it´s ok here: {}", exception.getMessage());
	}
	return xmlGregCal;
}
 
Example 55
Project: dotwebstack-framework   File: Rdf4jValueBackendTest.java   Source Code and License 5 votes vote down vote up
private XMLGregorianCalendar getCurrentDateTime() {
  GregorianCalendar gc = new GregorianCalendar();
  DatatypeFactory dtf = null;
  try {
    dtf = DatatypeFactory.newInstance();
  } catch (DatatypeConfigurationException ex) {
    ex.printStackTrace();
  }
  return dtf.newXMLGregorianCalendar(gc);
}
 
Example 56
Project: mpay24-java   File: SdkMdxiMapper.java   Source Code and License 5 votes vote down vote up
private XMLGregorianCalendar getCalendarDate(Date date) {
	if (date == null)
		return null;
	try {
		GregorianCalendar c = new GregorianCalendar();
		c.setTime(date);
		return DatatypeFactory.newInstance().newXMLGregorianCalendar(c);
	} catch (Exception e) {
		logger.error("Invalid date '" + date.toString() + "'. Exception: " + e.getMessage());
		return null;
	}
}
 
Example 57
Project: OpenVertretung   File: Value.java   Source Code and License 5 votes vote down vote up
public void setDateTime(GregorianCalendar value) throws DatatypeConfigurationException {
    if (this.dtf == null) {
        this.dtf = DatatypeFactory.newInstance();
    }
    this.objValue = this.dtf.newXMLGregorianCalendar(value);
    this.objType = TYPE_dateTime_iso8601;
}
 
Example 58
Project: OpenVertretung   File: Value.java   Source Code and License 5 votes vote down vote up
public void setDateTime(String value) throws DatatypeConfigurationException {
    if (this.dtf == null) {
        this.dtf = DatatypeFactory.newInstance();
    }
    this.objValue = this.dtf.newXMLGregorianCalendar(value);
    this.objType = TYPE_dateTime_iso8601;
}
 
Example 59
Project: java-kdb-communication   File: ConvertersTest.java   Source Code and License 5 votes vote down vote up
@Test
public void testDurationToTimespanReturnsDurationMillisInNanoseconds() throws DatatypeConfigurationException {
	Duration duration = DatatypeFactory.newInstance().newDuration(12345);
	Timespan timespan = Converters.durationToTimespan(duration);
	
	assertThat(timespan, is(not(nullValue())));
	assertThat(timespan.j / 1000000, is(equalTo(12345l)));
}
 
Example 60
Project: lams   File: Value.java   Source Code and License 5 votes vote down vote up
public void setDateTime(GregorianCalendar value) throws DatatypeConfigurationException {
    if (this.dtf == null) {
        this.dtf = DatatypeFactory.newInstance();
    }
    this.objValue = this.dtf.newXMLGregorianCalendar(value);
    this.objType = TYPE_dateTime_iso8601;
}