List of usage examples for javax.xml.datatype DatatypeFactory newInstance
public static DatatypeFactory newInstance() throws DatatypeConfigurationException
From source file:Main.java
public static void main(final String[] args) throws Exception { GregorianCalendar gcal = (GregorianCalendar) GregorianCalendar.getInstance(); XMLGregorianCalendar xgcal = DatatypeFactory.newInstance().newXMLGregorianCalendar(gcal); System.out.println(xgcal);//from w w w . ja v a 2s .c o m }
From source file:Main.java
public static void main(String[] args) throws Exception { JAXBContext jc = JAXBContext.newInstance(Root.class); Root root = new Root(); DatatypeFactory dtf = DatatypeFactory.newInstance(); root.month = dtf.newXMLGregorianCalendar("--11"); Marshaller marshaller = jc.createMarshaller(); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); marshaller.marshal(root, System.out); }
From source file:DatatypeAPIUsage.java
public static void main(String[] args) { try {/* w ww . j a va 2 s .co m*/ DatatypeFactory df = DatatypeFactory.newInstance(); // my work number in milliseconds: Duration myPhone = df.newDuration(9054133519l); Duration myLife = df.newDuration(true, 29, 2, 15, 13, 45, 0); int compareVal = myPhone.compare(myLife); switch (compareVal) { case DatatypeConstants.LESSER: System.out.println("There are fewer milliseconds in my phone number than my lifespan."); break; case DatatypeConstants.EQUAL: System.out.println("The same number of milliseconds are in my phone number and my lifespan."); break; case DatatypeConstants.GREATER: System.out.println("There are more milliseconds in my phone number than my lifespan."); break; case DatatypeConstants.INDETERMINATE: System.out.println("The comparison could not be carried out."); } // create a yearMonthDuration Duration ymDuration = df.newDurationYearMonth("P12Y10M"); System.out.println("P12Y10M is of type: " + ymDuration.getXMLSchemaType()); // create a dayTimeDuration (really this time) Duration dtDuration = df.newDurationDayTime("P10DT10H12M0S"); System.out.println("P10DT10H12M0S is of type: " + dtDuration.getXMLSchemaType()); // try to fool the factory! try { ymDuration = df.newDurationYearMonth("P12Y10M1D"); } catch (IllegalArgumentException e) { System.out.println("'duration': P12Y10M1D is not 'yearMonthDuration'!!!"); } XMLGregorianCalendar xgc = df.newXMLGregorianCalendar(); xgc.setYear(1975); xgc.setMonth(DatatypeConstants.AUGUST); xgc.setDay(11); xgc.setHour(6); xgc.setMinute(44); xgc.setSecond(0); xgc.setMillisecond(0); xgc.setTimezone(5); xgc.add(myPhone); System.out.println("The approximate end of the number of milliseconds in my phone number was " + xgc); // adding a duration to XMLGregorianCalendar xgc.add(myLife); System.out.println("Adding the duration myLife to the above calendar:" + xgc); // create a new XMLGregorianCalendar using the string format of xgc. XMLGregorianCalendar xgcCopy = df.newXMLGregorianCalendar(xgc.toXMLFormat()); // should be equal-if not what happened!! if (xgcCopy.compare(xgc) != DatatypeConstants.EQUAL) { System.out.println("oooops!"); } else { System.out.println("Very good: " + xgc + " is equal to " + xgcCopy); } } catch (DatatypeConfigurationException dce) { System.err.println("error: Datatype error occurred - " + dce.getMessage()); dce.printStackTrace(System.err); } }
From source file:ScheduleCampaign.java
public static void main(String[] args) { System.out.println("Executing Schedule Campaign"); try {/*from w ww . j a v a 2 s .co m*/ URL marketoSoapEndPoint = new URL("CHANGE ME" + "?WSDL"); String marketoUserId = "CHANGE ME"; String marketoSecretKey = "CHANGE ME"; QName serviceName = new QName("http://www.marketo.com/mktows/", "MktMktowsApiService"); MktMktowsApiService service = new MktMktowsApiService(marketoSoapEndPoint, serviceName); MktowsPort port = service.getMktowsApiSoapPort(); // Create Signature DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ"); String text = df.format(new Date()); String requestTimestamp = text.substring(0, 22) + ":" + text.substring(22); String encryptString = requestTimestamp + marketoUserId; SecretKeySpec secretKey = new SecretKeySpec(marketoSecretKey.getBytes(), "HmacSHA1"); Mac mac = Mac.getInstance("HmacSHA1"); mac.init(secretKey); byte[] rawHmac = mac.doFinal(encryptString.getBytes()); char[] hexChars = Hex.encodeHex(rawHmac); String signature = new String(hexChars); // Set Authentication Header AuthenticationHeader header = new AuthenticationHeader(); header.setMktowsUserId(marketoUserId); header.setRequestTimestamp(requestTimestamp); header.setRequestSignature(signature); // Create Request ParamsScheduleCampaign request = new ParamsScheduleCampaign(); request.setProgramName("Trav-Demo-Program"); request.setCampaignName("Batch Campaign Example"); // Create setCampaignRunAt timestamp GregorianCalendar gc = new GregorianCalendar(); gc.setTimeInMillis(new Date().getTime()); DatatypeFactory factory = DatatypeFactory.newInstance(); ObjectFactory objectFactory = new ObjectFactory(); JAXBElement<XMLGregorianCalendar> setCampaignRunAtValue = objectFactory .createParamsScheduleCampaignCampaignRunAt(factory.newXMLGregorianCalendar(gc)); request.setCampaignRunAt(setCampaignRunAtValue); request.setCloneToProgramName("TestProgramCloneFromSOAP"); ArrayOfAttrib aoa = new ArrayOfAttrib(); Attrib attrib = new Attrib(); attrib.setName("{{my.message}}"); attrib.setValue("Updated message"); aoa.getAttribs().add(attrib); JAXBElement<ArrayOfAttrib> arrayOfAttrib = objectFactory .createParamsScheduleCampaignProgramTokenList(aoa); request.setProgramTokenList(arrayOfAttrib); SuccessScheduleCampaign result = port.scheduleCampaign(request, header); JAXBContext context = JAXBContext.newInstance(SuccessScheduleCampaign.class); Marshaller m = context.createMarshaller(); m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); m.marshal(result, System.out); } catch (Exception e) { e.printStackTrace(); } }
From source file:GetLeadChanges.java
public static void main(String[] args) { System.out.println("Executing Get Lead Changes"); try {/*from ww w . j a va 2s .c o m*/ URL marketoSoapEndPoint = new URL("CHANGE ME" + "?WSDL"); String marketoUserId = "CHANGE ME"; String marketoSecretKey = "CHANGE ME"; QName serviceName = new QName("http://www.marketo.com/mktows/", "MktMktowsApiService"); MktMktowsApiService service = new MktMktowsApiService(marketoSoapEndPoint, serviceName); MktowsPort port = service.getMktowsApiSoapPort(); // Create Signature DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ"); String text = df.format(new Date()); String requestTimestamp = text.substring(0, 22) + ":" + text.substring(22); String encryptString = requestTimestamp + marketoUserId; SecretKeySpec secretKey = new SecretKeySpec(marketoSecretKey.getBytes(), "HmacSHA1"); Mac mac = Mac.getInstance("HmacSHA1"); mac.init(secretKey); byte[] rawHmac = mac.doFinal(encryptString.getBytes()); char[] hexChars = Hex.encodeHex(rawHmac); String signature = new String(hexChars); // Set Authentication Header AuthenticationHeader header = new AuthenticationHeader(); header.setMktowsUserId(marketoUserId); header.setRequestTimestamp(requestTimestamp); header.setRequestSignature(signature); // Create Request ParamsGetLeadChanges request = new ParamsGetLeadChanges(); ObjectFactory objectFactory = new ObjectFactory(); JAXBElement<Integer> batchSize = objectFactory.createParamsGetLeadActivityBatchSize(10); request.setBatchSize(batchSize); ArrayOfString activities = new ArrayOfString(); activities.getStringItems().add("Visit Webpage"); activities.getStringItems().add("Click Link"); JAXBElement<ArrayOfString> activityFilter = objectFactory .createParamsGetLeadChangesActivityNameFilter(activities); request.setActivityNameFilter(activityFilter); // Create oldestCreateAt timestamp from 5 days ago GregorianCalendar gc = new GregorianCalendar(); gc.setTimeInMillis(new Date().getTime()); gc.add(GregorianCalendar.DAY_OF_YEAR, -5); DatatypeFactory factory = DatatypeFactory.newInstance(); JAXBElement<XMLGregorianCalendar> oldestCreateAtValue = objectFactory .createStreamPositionOldestCreatedAt(factory.newXMLGregorianCalendar(gc)); StreamPosition sp = new StreamPosition(); sp.setOldestCreatedAt(oldestCreateAtValue); request.setStartPosition(sp); SuccessGetLeadChanges result = port.getLeadChanges(request, header); JAXBContext context = JAXBContext.newInstance(SuccessGetLeadChanges.class); Marshaller m = context.createMarshaller(); m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); m.marshal(result, System.out); } catch (Exception e) { e.printStackTrace(); } }
From source file:Main.java
public static XMLGregorianCalendar getXMLGregorianCalendarTimestamp() { try {/*from w w w . j av a 2s. c o m*/ DatatypeFactory dtf = DatatypeFactory.newInstance(); GregorianCalendar gc = new GregorianCalendar(); return dtf.newXMLGregorianCalendar(gc); } catch (DatatypeConfigurationException e) { e.printStackTrace(); return null; } }
From source file:Main.java
public static XMLGregorianCalendar toXmlDate(Date from) { GregorianCalendar gc = new GregorianCalendar(); gc.setTime(from);//from ww w . ja v a 2 s.co m try { return DatatypeFactory.newInstance().newXMLGregorianCalendar(gc); } catch (Exception e) { throw new RuntimeException(e); } }
From source file:Main.java
public static GregorianCalendar toGregorianCalendar(String date) { try {//from w ww. j a v a2 s .com XMLGregorianCalendar xmlDate = DatatypeFactory.newInstance().newXMLGregorianCalendar(date); return xmlDate.toGregorianCalendar(); } catch (DatatypeConfigurationException dtce) { throw new UnsupportedOperationException("Nemohu prevest " + "GregorianCalendar na XMLGregorianCalendar", dtce); } }
From source file:Main.java
public static XMLGregorianCalendar toXmlDate(GregorianCalendar date) { try {// www . ja v a 2s . c o m return DatatypeFactory.newInstance().newXMLGregorianCalendar(date); } catch (DatatypeConfigurationException dtce) { throw new UnsupportedOperationException("Nemohu prevest " + "GregorianCalendar na XMLGregorianCalendar", dtce); } }
From source file:Main.java
public static XMLGregorianCalendar convertDate(Date date) { try {/*w w w .j a v a 2 s . c o m*/ Calendar c = new GregorianCalendar(); c.setTime(date); XMLGregorianCalendar xmlGregorianCalendar = DatatypeFactory.newInstance().newXMLGregorianCalendar(); xmlGregorianCalendar.setDay(c.get(Calendar.DAY_OF_MONTH)); xmlGregorianCalendar.setMonth(c.get(Calendar.MONTH)); xmlGregorianCalendar.setYear(c.get(Calendar.YEAR)); return xmlGregorianCalendar; } catch (DatatypeConfigurationException e) { throw new RuntimeException(e); } }