List of usage examples for javax.xml.datatype DatatypeFactory newXMLGregorianCalendar
public abstract XMLGregorianCalendar newXMLGregorianCalendar(final GregorianCalendar cal);
From source file:org.artificer.integration.artifactbuilder.WsdlDocumentArtifactBuilderTest.java
@Test public void testHumanTaskWsdl() throws Exception { DatatypeFactory dtFactory = DatatypeFactory.newInstance(); WsdlDocumentArtifactBuilder builder = new WsdlDocumentArtifactBuilder(); WsdlDocument testSrcArtifact = new WsdlDocument(); testSrcArtifact.setArtifactType(BaseArtifactEnum.WSDL_DOCUMENT); testSrcArtifact.setUuid(UUID.randomUUID().toString()); testSrcArtifact.setName("ws-humantask-api.wsdl"); testSrcArtifact.setVersion("200803"); testSrcArtifact.setContentEncoding("UTF-8"); testSrcArtifact.setContentType("application/xml"); testSrcArtifact.setContentSize(92779L); testSrcArtifact.setCreatedBy("anonymous"); XMLGregorianCalendar xmlGC = dtFactory.newXMLGregorianCalendar(new GregorianCalendar()); testSrcArtifact.setCreatedTimestamp(xmlGC); testSrcArtifact.setDescription("Human Task WSDL."); testSrcArtifact.setLastModifiedBy("anonymous"); testSrcArtifact.setLastModifiedTimestamp(xmlGC); InputStream testSrcContent = null; try {/*from ww w.j a v a 2 s.c o m*/ testSrcContent = getClass().getResourceAsStream("/sample-files/wsdl/ws-humantask-api.wsdl"); Collection<BaseArtifactType> derivedArtifacts = builder .buildArtifacts(testSrcArtifact, new ArtifactContent("ws-humantask-api.wsdl", testSrcContent)) .getDerivedArtifacts(); Assert.assertNotNull(derivedArtifacts); Assert.assertEquals(850, derivedArtifacts.size()); } finally { IOUtils.closeQuietly(testSrcContent); } }
From source file:org.artificer.integration.artifactbuilder.XsdDocumentArtifactBuilderTest.java
@Test public void testDerive() throws Exception { DatatypeFactory dtFactory = DatatypeFactory.newInstance(); XsdDocumentArtifactBuilder builder = new XsdDocumentArtifactBuilder(); XsdDocument testSrcArtifact = new XsdDocument(); testSrcArtifact.setArtifactType(BaseArtifactEnum.XSD_DOCUMENT); testSrcArtifact.setUuid(UUID.randomUUID().toString()); testSrcArtifact.setName("ws-humantask.xsd"); testSrcArtifact.setVersion("1.0"); testSrcArtifact.setContentEncoding("UTF-8"); testSrcArtifact.setContentType("application/xml"); testSrcArtifact.setContentSize(31723L); testSrcArtifact.setCreatedBy("anonymous"); XMLGregorianCalendar xmlGC = dtFactory.newXMLGregorianCalendar(new GregorianCalendar()); testSrcArtifact.setCreatedTimestamp(xmlGC); testSrcArtifact.setDescription("Hello world."); testSrcArtifact.setLastModifiedBy("anonymous"); testSrcArtifact.setLastModifiedTimestamp(xmlGC); InputStream testSrcContent = null; try {// ww w . j av a 2 s . c o m testSrcContent = getClass().getResourceAsStream("/sample-files/xsd/ws-humantask.xsd"); Collection<BaseArtifactType> derivedArtifacts = builder .buildArtifacts(testSrcArtifact, new ArtifactContent("ws-humantask.xsd", testSrcContent)) .getDerivedArtifacts(); Assert.assertNotNull(derivedArtifacts); Assert.assertEquals(83, derivedArtifacts.size()); int numElements = 0; int numAttributes = 0; int numSimpleTypes = 0; int numComplexTypes = 0; Set<String> elementNames = new HashSet<String>(); Set<String> attributeNames = new HashSet<String>(); Set<String> simpleTypeNames = new HashSet<String>(); Set<String> complexTypeNames = new HashSet<String>(); for (BaseArtifactType derivedArtifact : derivedArtifacts) { DerivedArtifactType dat = (DerivedArtifactType) derivedArtifact; Assert.assertEquals(testSrcArtifact.getUuid(), dat.getRelatedDocument().getValue()); Assert.assertEquals(DocumentArtifactEnum.XSD_DOCUMENT, dat.getRelatedDocument().getArtifactType()); if (dat instanceof ElementDeclaration) { numElements++; elementNames.add(((ElementDeclaration) dat).getNCName()); } else if (dat instanceof AttributeDeclaration) { numAttributes++; attributeNames.add(((AttributeDeclaration) dat).getNCName()); } else if (dat instanceof SimpleTypeDeclaration) { numSimpleTypes++; simpleTypeNames.add(((SimpleTypeDeclaration) dat).getNCName()); } else if (dat instanceof ComplexTypeDeclaration) { numComplexTypes++; complexTypeNames.add(((ComplexTypeDeclaration) dat).getNCName()); } } // Verify the counts Assert.assertEquals(17, numElements); Assert.assertEquals(0, numAttributes); Assert.assertEquals(5, numSimpleTypes); Assert.assertEquals(61, numComplexTypes); Assert.assertEquals(83, numElements + numAttributes + numSimpleTypes + numComplexTypes); // Verify the names Assert.assertEquals(EXPECTED_ELEMENT_NAMES, elementNames); Assert.assertEquals(EXPECTED_ATTRIBUTE_NAMES, attributeNames); Assert.assertEquals(EXPECTED_SIMPLE_TYPE_NAMES, simpleTypeNames); Assert.assertEquals(EXPECTED_COMPLEX_TYPE_NAMES, complexTypeNames); } finally { IOUtils.closeQuietly(testSrcContent); } }
From source file:org.artificer.test.server.atom.services.AuditResourceTest.java
@Test public void testCreate() throws Exception { Document pdf = addPdf();/*from www . ja v a2 s . c o m*/ DatatypeFactory dtFactory = DatatypeFactory.newInstance(); // Create another audit entry ClientRequest request = clientRequest("/s-ramp/audit/artifact/" + pdf.getUuid()); XMLGregorianCalendar now = dtFactory.newXMLGregorianCalendar((GregorianCalendar) Calendar.getInstance()); AuditEntry auditEntry = new AuditEntry(); auditEntry.setType("junit:test1"); auditEntry.setWhen(now); auditEntry.setWho(getUsername()); AuditItemType item = AuditUtils.getOrCreateAuditItem(auditEntry, "junit:item"); AuditUtils.setAuditItemProperty(item, "foo", "bar"); AuditUtils.setAuditItemProperty(item, "hello", "world"); request.body(MediaType.APPLICATION_AUDIT_ENTRY_XML_TYPE, auditEntry); ClientResponse<Entry> response = request.post(Entry.class); Entry entry = response.getEntity(); AuditEntry re = ArtificerAtomUtils.unwrap(entry, AuditEntry.class); Assert.assertNotNull(re); Assert.assertNotNull(re.getUuid()); Assert.assertEquals(getUsername(), re.getWho()); Assert.assertEquals(1, re.getAuditItem().size()); Assert.assertEquals("junit:item", re.getAuditItem().iterator().next().getType()); Assert.assertEquals(2, re.getAuditItem().iterator().next().getProperty().size()); // List all the audit entries request = clientRequest("/s-ramp/audit/artifact/" + pdf.getUuid()); Feed auditEntryFeed = request.get(Feed.class).getEntity(); Assert.assertNotNull(auditEntryFeed); List<Entry> entries = auditEntryFeed.getEntries(); Assert.assertEquals(2, entries.size()); // Get just the custom entry we created request = clientRequest("/s-ramp/audit/artifact/" + pdf.getUuid() + "/" + re.getUuid()); response = request.get(Entry.class); entry = response.getEntity(); re = ArtificerAtomUtils.unwrap(entry, AuditEntry.class); Assert.assertNotNull(re); Assert.assertNotNull(re.getUuid()); Assert.assertEquals(getUsername(), re.getWho()); Assert.assertEquals(1, re.getAuditItem().size()); Assert.assertEquals("junit:item", re.getAuditItem().iterator().next().getType()); Assert.assertEquals(2, re.getAuditItem().iterator().next().getProperty().size()); }
From source file:org.betaconceptframework.astroboa.engine.jcr.io.SerializationBean.java
private String generateXMLRepresentationOfCalendar(Calendar calendar) { if (calendar == null) { calendar = Calendar.getInstance(); }//from w ww. j a va 2 s .co m try { DatatypeFactory df = DatatypeFactory.newInstance(); GregorianCalendar gregCalendar = new GregorianCalendar(calendar.getTimeZone()); gregCalendar.setTimeInMillis(calendar.getTimeInMillis()); return df.newXMLGregorianCalendar(gregCalendar).toXMLFormat(); } catch (DatatypeConfigurationException e) { return null; } }
From source file:org.callimachusproject.behaviours.AuthenticationManagerSupport.java
private XMLGregorianCalendar now() { try {/* w ww. j av a 2 s. c o m*/ TimeZone utc = TimeZone.getTimeZone("UTC"); DatatypeFactory df = DatatypeFactory.newInstance(); return df.newXMLGregorianCalendar(new GregorianCalendar(utc)); } catch (DatatypeConfigurationException e) { throw new AssertionError(e); } }
From source file:org.fosstrak.epcis.repository.query.QueryOperationsBackendSQL.java
/** * Creates a new XMLGregorianCalendar from the given milliseconds time. * /*w ww. j ava2s .c om*/ * @param time * The time in ms to convert. * @return The XML calendar object representing the given timestamp. * @throws ImplementationExceptionResponse * If an error occurred when parsing the given timestamp into a * calendar instance. */ private XMLGregorianCalendar timeToXmlCalendar(long time) throws ImplementationExceptionResponse { try { DatatypeFactory factory = DatatypeFactory.newInstance(); Calendar cal = GregorianCalendar.getInstance(); cal.setTimeInMillis(time); return factory.newXMLGregorianCalendar((GregorianCalendar) cal); } catch (DatatypeConfigurationException e) { String msg = "Unable to instantiate an XML representation for a date/time datatype."; ImplementationException iex = new ImplementationException(); iex.setReason(msg); iex.setSeverity(ImplementationExceptionSeverity.SEVERE); throw new ImplementationExceptionResponse(msg, iex, e); } }
From source file:org.jrecruiter.common.CalendarUtils.java
/** * Get a XML-date representation (ISO 8601) of the provided calendar object. * * For more details @see http://www.w3.org/TR/xmlschema-2/#dateTime * * @return XML-date as String/*from www .ja va2s.com*/ */ public static String getXmlFormatedDate(final Calendar calendar) { if (calendar == null) { throw new IllegalArgumentException("Calendar is a required parameter"); } final GregorianCalendar gregorianCalendar = new GregorianCalendar(calendar.getTimeZone()); gregorianCalendar.setTime(calendar.getTime()); final DatatypeFactory dataTypeFactory; try { dataTypeFactory = DatatypeFactory.newInstance(); } catch (DatatypeConfigurationException e) { throw new IllegalStateException(e.getMessage(), e); } final XMLGregorianCalendar xmlCalendar = dataTypeFactory.newXMLGregorianCalendar(gregorianCalendar); return xmlCalendar.toXMLFormat(); }
From source file:org.kitodo.dataformat.access.MetsXmlElementAccess.java
/** * Creates an object of class XMLGregorianCalendar. Creating this * JAXB-specific class is quite complicated and has therefore been * outsourced to a separate method./*from w w w . j ava 2 s. c o m*/ * * @param gregorianCalendar * value of the calendar * @return an object of class XMLGregorianCalendar */ private static XMLGregorianCalendar convertDate(GregorianCalendar gregorianCalendar) { DatatypeFactory datatypeFactory; try { datatypeFactory = DatatypeFactory.newInstance(); } catch (DatatypeConfigurationException e) { String message = e.getMessage(); throw new NoClassDefFoundError(message != null ? message : "Implementation of DatatypeFactory not available or cannot be instantiated."); } return datatypeFactory.newXMLGregorianCalendar(gregorianCalendar); }
From source file:org.opencds.dss.evaluate.EvaluationImpl.java
/** * /*from w w w .j av a2 s. c o m*/ * @param date as long * @return XMLGregorianCalendar */ private static XMLGregorianCalendar long2Gregorian(long date) { DatatypeFactory dataTypeFactory; try { dataTypeFactory = DatatypeFactory.newInstance(); } catch (DatatypeConfigurationException e) { throw new RuntimeException(e); } GregorianCalendar gc = new GregorianCalendar(); gc.setTimeInMillis(date); return dataTypeFactory.newXMLGregorianCalendar(gc); }
From source file:org.orcid.utils.DateUtils.java
public static XMLGregorianCalendar convertToXMLGregorianCalendar(String dateString, boolean tidy) { String tidyDateString = dateString; if (tidy) {/* w ww. j av a2s. c o m*/ tidyDateString = tidy(dateString); } if (tidyDateString == null) { return null; } DatatypeFactory dataTypeFactory = createDataTypeFactory(); try { return dataTypeFactory.newXMLGregorianCalendar(tidyDateString); } catch (IllegalArgumentException e) { return null; } }