List of usage examples for javax.xml.datatype DatatypeFactory newInstance
public static DatatypeFactory newInstance() throws DatatypeConfigurationException
From source file:ebay.dts.client.BulkDataExchangeActions.java
private static XMLGregorianCalendar parseDateTime(String cal) throws DatatypeConfigurationException { DatatypeFactory factory1 = DatatypeFactory.newInstance(); XMLGregorianCalendar calendar1 = factory1.newXMLGregorianCalendar(); String[] dateItems;//from ww w. j a va2s. com try { // df.parse(cal); if (cal.indexOf("_") == -1) { dateItems = cal.split("-"); calendar1.setYear(Integer.parseInt(dateItems[0])); calendar1.setMonth(Integer.parseInt(dateItems[1])); calendar1.setDay(Integer.parseInt(dateItems[2])); // calendar1.setTime(00, 00, 00,000); calendar1.setTime(00, 00, 00); } else { String[] parts = cal.split("_"); dateItems = parts[0].split("-"); String[] timeItems = parts[1].split(":"); calendar1.setYear(Integer.parseInt(dateItems[0])); calendar1.setMonth(Integer.parseInt(dateItems[1])); calendar1.setDay(Integer.parseInt(dateItems[2])); if (timeItems.length != 0) { switch (timeItems.length) { case 1: { calendar1.setTime(Integer.parseInt(timeItems[0]), 00, 00, 000); break; } case 2: { calendar1.setTime(Integer.parseInt(timeItems[0]), Integer.parseInt(timeItems[1]), 00, 000); break; } case 3: { calendar1.setTime(Integer.parseInt(timeItems[0]), Integer.parseInt(timeItems[1]), Integer.parseInt(timeItems[2]), 000); break; } case 4: { calendar1.setTime(Integer.parseInt(timeItems[0]), Integer.parseInt(timeItems[1]), Integer.parseInt(timeItems[2]), Integer.parseInt(timeItems[3])); break; } } } } // get here and we know the format is correct } catch (java.lang.NumberFormatException e) { logger.error("NumberFormatException caught when parse the DateTime string: " + cal); return null; } calendar1.setTimezone(0); logger.debug(calendar1.toXMLFormat()); return calendar1; }
From source file:be.fedict.eid.applet.service.signer.facets.XAdESSignatureFacet.java
/** * Main constructor.//from w w w .j a v a2s . c om * * @param clock * the clock to be used for determining the xades:SigningTime * @param digestAlgorithm * the digest algorithm to be used for all required XAdES digest * operations. Possible values: "SHA-1", "SHA-256", or "SHA-512". * @param signaturePolicyService * the optional signature policy service used for XAdES-EPES. */ public XAdESSignatureFacet(Clock clock, DigestAlgo digestAlgorithm, SignaturePolicyService signaturePolicyService) { this.clock = clock; this.digestAlgorithm = digestAlgorithm; this.signaturePolicyService = signaturePolicyService; try { this.datatypeFactory = DatatypeFactory.newInstance(); } catch (DatatypeConfigurationException e) { throw new RuntimeException("datatype config error: " + e.getMessage(), e); } this.xadesObjectFactory = new ObjectFactory(); this.xmldsigObjectFactory = new be.fedict.eid.applet.service.signer.jaxb.xmldsig.ObjectFactory(); this.xadesNamespacePrefixMapper = new XAdESNamespacePrefixMapper(); try { JAXBContext jaxbContext = JAXBContext.newInstance(ObjectFactory.class); this.marshaller = jaxbContext.createMarshaller(); this.marshaller.setProperty("com.sun.xml.bind.namespacePrefixMapper", this.xadesNamespacePrefixMapper); } catch (JAXBException e) { throw new RuntimeException("JAXB error: " + e.getMessage(), e); } this.dataObjectFormatMimeTypes = new HashMap<String, String>(); }
From source file:eu.dasish.annotation.backend.dao.impl.JdbcAnnotationDaoTest.java
/** * * Test of getAnnotationWithoutTargetsAndPemissions method, of class * JdbcAnnotationDao. Annotation getAnnotation(Number annotationlID) *///from w w w . j a va2 s. co m @Test public void getAnnotationWithoutTargetsAndPermisions() throws DatatypeConfigurationException { System.out.println("test getAnnotationWithoutTargetsAndPermissions"); jdbcAnnotationDao.setResourcePath("/api/annotations/"); final Annotation result = jdbcAnnotationDao.getAnnotationWithoutTargetsAndPemissionList(1); assertEquals("Sagrada Famiglia", result.getHeadline()); assertEquals("<html><body>some html 1</body></html>", result.getBody().getTextBody().getBody()); assertEquals("text/html", result.getBody().getTextBody().getMimeType()); assertEquals("00000000-0000-0000-0000-000000000021", result.getId()); assertEquals("/api/annotations/00000000-0000-0000-0000-000000000021", result.getHref()); assertEquals(DatatypeFactory.newInstance().newXMLGregorianCalendar("2013-08-12T09:25:00.383000Z"), result.getLastModified()); assertEquals(Access.WRITE, result.getPermissions().getPublic()); }
From source file:com.intellij.tasks.fogbugz.FogBugzRepository.java
@Nonnull private static Date parseDate(@Nonnull String string) { try {//from ww w. jav a 2 s . co m return DatatypeFactory.newInstance().newXMLGregorianCalendar(string).toGregorianCalendar().getTime(); } catch (DatatypeConfigurationException e) { throw new RuntimeException("Error configuring datatype factory", e); } }
From source file:net.authorize.api.controller.test.ApiCoreTestBase.java
@Before public void setUp() throws Exception { mockContext = new Mockery(); //initialize counter counter = random.nextInt((int) Math.pow(2, 24)); counterStr = getRandomString(""); now = Calendar.getInstance().getTime(); nowString = DateUtil.getFormattedDate(now, ReportingDetails.DATE_FORMAT); datatypeFactory = DatatypeFactory.newInstance(); //TODO add / subtract relative pastDate = new GregorianCalendar(2010, 01, 01); nowDate = new GregorianCalendar(); futureDate = new GregorianCalendar(2020, 12, 31); merchantAuthenticationType = new MerchantAuthenticationType(); merchantAuthenticationType.setName(apiLoginIdKey); merchantAuthenticationType.setTransactionKey(transactionKey); // merchantAuthenticationType.setSessionToken(getRandomString("SessionToken")); // merchantAuthenticationType.setPassword(getRandomString("Password")); // merchantAuthenticationType.setMobileDeviceId(getRandomString("MobileDevice")); // ImpersonationAuthenticationType impersonationAuthenticationType = new ImpersonationAuthenticationType(); // impersonationAuthenticationType.setPartnerLoginId(CnpApiLoginIdKey); // impersonationAuthenticationType.setPartnerTransactionKey(CnpTransactionKey); // merchantAuthenticationType.setImpersonationAuthentication(impersonationAuthenticationType); customerProfileType = new CustomerProfileType(); customerProfileType.setMerchantCustomerId(getRandomString("Customer")); customerProfileType.setDescription(getRandomString("CustomerDescription")); customerProfileType.setEmail(counterStr + ".customerProfileType@test.anet.net"); //make sure these elements are initialized by calling get as it uses lazy initialization //List<CustomerPaymentProfileType> paymentProfiles = customerProfileType.getPaymentProfiles(); //List<CustomerAddressType> addresses = customerProfileType.getShipToList(); //XXX HIDE CreditCardType creditCardOne = new CreditCardType(); creditCardOne.setCardNumber("4111111111111111"); creditCardOne.setExpirationDate("2038-12"); // creditCardOne.setCardCode(""); //XXX HIDE BankAccountType bankAccountOne = new BankAccountType(); bankAccountOne.setAccountType(BankAccountTypeEnum.SAVINGS); bankAccountOne.setRoutingNumber("125000000"); bankAccountOne.setAccountNumber(getRandomString("A/C#")); bankAccountOne.setNameOnAccount((getRandomString("A/CName"))); bankAccountOne.setEcheckType(EcheckTypeEnum.WEB); bankAccountOne.setBankName(getRandomString("Bank")); bankAccountOne.setCheckNumber(counterStr); //XXX HIDE CreditCardTrackType trackDataOne = new CreditCardTrackType(); trackDataOne.setTrack1(getRandomString("Track1")); trackDataOne.setTrack2(getRandomString("Track2")); //XXX HIDE EncryptedTrackDataType encryptedTrackDataOne = new EncryptedTrackDataType(); KeyBlock keyBlock = new KeyBlock(); //keyBlock.setValue(value); encryptedTrackDataOne.setFormOfPayment(keyBlock); payPalOne = new PayPalType(); payPalOne.setSuccessUrl(getRandomString("https://success.anet.net")); payPalOne.setCancelUrl(getRandomString("https://cancel.anet.net")); payPalOne.setPaypalLc(getRandomString("Lc")); payPalOne.setPaypalHdrImg(getRandomString("Hdr")); payPalOne.setPaypalPayflowcolor(getRandomString("flowClr")); payPalOne.setPayerID(getRandomString("PayerId")); paymentOne = new PaymentType(); paymentOne.setCreditCard(creditCardOne); //paymentOne.setBankAccount(bankAccountOne); //paymentOne.setTrackData(trackDataOne); //paymentOne.setEncryptedTrackData(encryptedTrackDataOne); //paymentOne.setPayPal( payPalOne); // driversLicenseOne = new DriversLicenseType(); // driversLicenseOne.setNumber(getRandomString("DLNumber")); // driversLicenseOne.setState(getRandomString("WA")); // driversLicenseOne.setDateOfBirth(nowString); customerAddressOne = new CustomerAddressType(); customerAddressOne.setFirstName(getRandomString("FName")); customerAddressOne.setLastName(getRandomString("LName")); customerAddressOne.setCompany(getRandomString("Company")); customerAddressOne.setAddress(getRandomString("StreetAdd")); customerAddressOne.setCity("Bellevue"); customerAddressOne.setState("WA"); customerAddressOne.setZip("98000"); customerAddressOne.setCountry("USA"); customerAddressOne.setPhoneNumber(formatToPhone(counter)); customerAddressOne.setFaxNumber(formatToPhone(counter + 1)); customerPaymentProfileOne = new CustomerPaymentProfileType(); customerPaymentProfileOne.setCustomerType(CustomerTypeEnum.INDIVIDUAL); customerPaymentProfileOne.setPayment(paymentOne); // customerPaymentProfileOne.setBillTo(customerAddressOne); // customerPaymentProfileOne.setDriversLicense(driversLicenseOne); // customerPaymentProfileOne.setTaxId(getRandomString("XX")); customerOne = new CustomerType(); customerOne.setType(CustomerTypeEnum.INDIVIDUAL); customerOne.setId(getRandomString("Id")); customerOne.setEmail(counterStr + ".customerOne@test.anet.net"); customerOne.setPhoneNumber(formatToPhone(counter)); customerOne.setFaxNumber(formatToPhone(counter + 1)); customerOne.setDriversLicense(driversLicenseOne); customerOne.setTaxId("911011011");//"123-45-6789");//TODO customerTwo = new CustomerType(); PaymentScheduleType.Interval interval = new PaymentScheduleType.Interval(); interval.setLength((short) 1); interval.setUnit(ARBSubscriptionUnitEnum.MONTHS); orderType = new OrderType(); //TODO ADD VALIDATION ON INVOICE LENGTH orderType.setInvoiceNumber(getRandomString("Inv:")); orderType.setDescription(getRandomString("Description")); nameAndAddressTypeOne = new NameAndAddressType(); nameAndAddressTypeOne.setFirstName(getRandomString("FName")); nameAndAddressTypeOne.setLastName(getRandomString("LName")); nameAndAddressTypeOne.setCompany(getRandomString("Company")); nameAndAddressTypeOne.setAddress(getRandomString("Address")); nameAndAddressTypeOne.setCity(getRandomString("City")); nameAndAddressTypeOne.setState(getRandomString("State")); nameAndAddressTypeOne.setZip("98004"); nameAndAddressTypeOne.setCountry("USA"); nameAndAddressTypeTwo = new NameAndAddressType(); nameAndAddressTypeTwo.setFirstName(getRandomString("FName")); nameAndAddressTypeTwo.setLastName(getRandomString("LName")); nameAndAddressTypeTwo.setCompany(getRandomString("Company")); nameAndAddressTypeTwo.setAddress(getRandomString("Address")); nameAndAddressTypeTwo.setCity(getRandomString("City")); nameAndAddressTypeTwo.setState(getRandomString("State")); nameAndAddressTypeTwo.setZip("98004"); nameAndAddressTypeTwo.setCountry("USA"); paymentScheduleTypeOne = new PaymentScheduleType(); paymentScheduleTypeOne.setInterval(interval); paymentScheduleTypeOne.setStartDate(datatypeFactory.newXMLGregorianCalendar(nowDate)); paymentScheduleTypeOne.setTotalOccurrences((short) 5); paymentScheduleTypeOne.setTrialOccurrences((short) 0); arbSubscriptionOne = new ARBSubscriptionType(); arbSubscriptionOne.setAmount(setValidSubscriptionAmount(counter)); arbSubscriptionOne.setBillTo(nameAndAddressTypeOne); arbSubscriptionOne.setCustomer(customerOne); arbSubscriptionOne.setName(getRandomString("Name")); arbSubscriptionOne.setOrder(orderType); arbSubscriptionOne.setPayment(paymentOne); arbSubscriptionOne.setPaymentSchedule(paymentScheduleTypeOne); arbSubscriptionOne.setShipTo(nameAndAddressTypeOne); arbSubscriptionOne.setTrialAmount(setValidSubscriptionAmount(0)); customerDataOne = new CustomerDataType(); customerDataOne.setDriversLicense(customerOne.getDriversLicense()); customerDataOne.setEmail(customerOne.getEmail()); customerDataOne.setId(customerOne.getId()); customerDataOne.setTaxId(customerOne.getTaxId()); customerDataOne.setType(customerOne.getType()); refId = counterStr;//from w ww . j a v a 2 s . c o m }
From source file:com.fusesource.example.camel.process.camel.ProcessorRouteBuilderTest.java
@Test @DirtiesContext/*from ww w . j a va2 s .co m*/ public void testRecoverableExternalServiceException() throws Exception { configureProcessRecordFailure(3, true); context.start(); DatatypeFactory dtf = DatatypeFactory.newInstance(); output.setExpectedMessageCount(1); dlq.setExpectedMessageCount(0); RecordType recordType = new RecordType(); recordType.setId("1"); recordType.setDate(dtf.newXMLGregorianCalendar(new GregorianCalendar())); recordType.setDescription("Record number: 1"); trigger.sendBody(recordType); output.assertIsSatisfied(); dlq.assertIsSatisfied(10000); }
From source file:com.evolveum.midpoint.web.page.admin.configuration.dto.SystemConfigurationDto.java
public SystemConfigurationType getNewObject() throws DatatypeConfigurationException { SystemConfigurationType newObject = oldObject.clone(); if (StringUtils.isNotBlank(getPassPolicyDto().getOid())) { ObjectReferenceType globalPassPolicyRef = ObjectTypeUtil.createObjectRef(getPassPolicyDto().getOid(), ObjectTypes.PASSWORD_POLICY); newObject.setGlobalPasswordPolicyRef(globalPassPolicyRef); } else {//ww w. j ava 2 s .co m newObject.setGlobalPasswordPolicyRef(null); } if (StringUtils.isNotBlank(getSecurityPolicyDto().getOid())) { ObjectReferenceType globalSecurityPolicyRef = ObjectTypeUtil.createObjectRef( getSecurityPolicyDto().getOid(), WebMiscUtil.createPolyFromOrigString(getSecurityPolicyDto().getName()), ObjectTypes.SECURITY_POLICY); newObject.setGlobalSecurityPolicyRef(globalSecurityPolicyRef); } else { newObject.setGlobalSecurityPolicyRef(null); } AssignmentPolicyEnforcementType globalAEP = AEPlevel.toAEPValueType(getAepLevel()); if (globalAEP != null) { ProjectionPolicyType projectionPolicy = new ProjectionPolicyType(); projectionPolicy.setAssignmentPolicyEnforcement(globalAEP); newObject.setGlobalAccountSynchronizationSettings(projectionPolicy); } Duration auditCleanupDuration = DatatypeFactory.newInstance().newDuration(getAuditCleanupValue()); Duration cleanupTaskDuration = DatatypeFactory.newInstance().newDuration(getTaskCleanupValue()); CleanupPolicyType auditCleanup = new CleanupPolicyType(); CleanupPolicyType taskCleanup = new CleanupPolicyType(); auditCleanup.setMaxAge(auditCleanupDuration); taskCleanup.setMaxAge(cleanupTaskDuration); CleanupPoliciesType cleanupPolicies = new CleanupPoliciesType(); cleanupPolicies.setAuditRecords(auditCleanup); cleanupPolicies.setClosedTasks(taskCleanup); newObject.setCleanupPolicy(cleanupPolicies); SystemConfigurationTypeUtil.setEnableExperimentalCode(newObject, getEnableExperimentalCode()); newObject.setLogging(loggingConfig.getNewObject()); newObject.setNotificationConfiguration(notificationConfig.getNewObject(newObject)); newObject.setProfilingConfiguration(profilingDto.getNewObejct()); ClassLoggerConfigurationType profilingClassLogger = profilingDto.getProfilingClassLogerConfig(); if (newObject.getLogging() != null) { newObject.getLogging().getClassLogger().add(profilingClassLogger); } else { LoggingConfigurationType profLogging = new LoggingConfigurationType(); profLogging.getClassLogger().add(profilingClassLogger); newObject.setLogging(profLogging); } return newObject; }
From source file:be.fedict.eid.tsl.TrustServiceList.java
protected TrustServiceList() { super();//from w ww . j a va 2s. c o m this.changed = true; this.changeListeners = new LinkedList<ChangeListener>(); this.objectFactory = new ObjectFactory(); this.xadesObjectFactory = new be.fedict.eid.tsl.jaxb.xades.ObjectFactory(); this.xmldsigObjectFactory = new be.fedict.eid.tsl.jaxb.xmldsig.ObjectFactory(); this.tslxObjectFactory = new be.fedict.eid.tsl.jaxb.tslx.ObjectFactory(); try { this.datatypeFactory = DatatypeFactory.newInstance(); } catch (DatatypeConfigurationException e) { throw new RuntimeException("datatype config error: " + e.getMessage(), e); } }
From source file:be.fedict.eid.applet.service.signer.facets.XAdESXLSignatureFacet.java
/** * Main constructor.//from w w w. j av a 2 s .c om * * @param timeStampService * the time-stamp service used for XAdES-T and XAdES-X. * @param revocationDataService * the optional revocation data service used for XAdES-C and * XAdES-X-L. When <code>null</code> the signature will be * limited to XAdES-T only. * @param digestAlgorithm * the digest algorithm to be used for construction of the * XAdES-X-L elements. */ public XAdESXLSignatureFacet(TimeStampService timeStampService, RevocationDataService revocationDataService, DigestAlgo digestAlgorithm) { this.objectFactory = new ObjectFactory(); this.c14nAlgoId = CanonicalizationMethod.EXCLUSIVE; this.digestAlgorithm = digestAlgorithm; this.timeStampService = timeStampService; this.revocationDataService = revocationDataService; this.xmldsigObjectFactory = new be.fedict.eid.applet.service.signer.jaxb.xmldsig.ObjectFactory(); this.xades141ObjectFactory = new be.fedict.eid.applet.service.signer.jaxb.xades141.ObjectFactory(); try { JAXBContext context = JAXBContext .newInstance(be.fedict.eid.applet.service.signer.jaxb.xades141.ObjectFactory.class); this.marshaller = context.createMarshaller(); this.marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); this.marshaller.setProperty("com.sun.xml.bind.namespacePrefixMapper", new XAdESNamespacePrefixMapper()); } catch (JAXBException e) { throw new RuntimeException("JAXB error: " + e.getMessage(), e); } try { this.certificateFactory = CertificateFactory.getInstance("X.509"); } catch (CertificateException e) { throw new RuntimeException("X509 JCA error: " + e.getMessage(), e); } try { this.datatypeFactory = DatatypeFactory.newInstance(); } catch (DatatypeConfigurationException e) { throw new RuntimeException("datatype config error: " + e.getMessage(), e); } }