List of usage examples for javax.xml.datatype DatatypeFactory newInstance
public static DatatypeFactory newInstance() throws DatatypeConfigurationException
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 w w w . j a va2 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 {/*from ww w . j a v a 2 s . com*/ 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.j av a 2 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.contenthandler.ImportContentHandler.java
public ImportContentHandler(ImportContext importContext, Class<T> resultType, Deserializer deserializer) { this.importContext = importContext; this.resultType = resultType; this.deserializer = deserializer; try {/*from w ww. j a va 2s .c o m*/ df = DatatypeFactory.newInstance(); } catch (DatatypeConfigurationException e) { throw new CmsException(e); } }
From source file:org.betaconceptframework.astroboa.engine.jcr.io.SerializationBean.java
private String generateXMLRepresentationOfCalendar(Calendar calendar) { if (calendar == null) { calendar = Calendar.getInstance(); }/* ww w.j a v a 2 s .c o 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.betaconceptframework.astroboa.engine.jcr.io.Serializer.java
public Serializer(OutputStream out, CmsRepositoryEntityUtils cmsRepositoryEntityUtils, Session session, SerializationConfiguration serializationConfiguration) throws Exception { this.serializationConfiguration = serializationConfiguration; if (this.serializationConfiguration == null) { //Default value to avoid NPE this.serializationConfiguration = SerializationConfiguration.repository().build(); }/*from ww w . j a v a 2 s.co m*/ createNewExportContentHandler(out); this.cmsRepositoryEntityUtils = cmsRepositoryEntityUtils; this.session = session; if (this.session == null) { throw new CmsException("Cannot initialize serializer because no JCR session has been provided"); } if (df == null) { try { df = DatatypeFactory.newInstance(); } catch (DatatypeConfigurationException e) { throw new CmsException(e); } } }
From source file:org.betaconceptframework.astroboa.model.jaxb.adapter.BinaryChannelAdapter.java
public BinaryChannelAdapter(boolean marshallBinaryContent) { this.marshallBinaryContent = marshallBinaryContent; try {/*from www. ja v a2s. c o m*/ df = DatatypeFactory.newInstance(); } catch (DatatypeConfigurationException e) { throw new CmsException(e); } }
From source file:org.betaconceptframework.astroboa.model.jaxb.visitor.ContentObjectMarshalVisitor.java
public void initialize(ContentObjectType contentObjectType, boolean marshallBinaryContent, boolean marshallAllProperties) { logger.debug("Initializing marshalling visitor."); this.marshallBinaryContent = marshallBinaryContent; this.marshallAllProperties = marshallAllProperties; if (this.xsiSchemaLocationMap == null) { this.xsiSchemaLocationMap = new HashMap<QName, String>(); }// w w w.ja v a2 s. c o m logger.debug("Current schema locations {}", this.xsiSchemaLocationMap); try { this.cmsPropertyPathsToMarshall = (List<String>) marshaller .getProperty(AstroboaMarshaller.CMS_PROPERTIES_TO_BE_MARSHALLED); } catch (PropertyException e1) { throw new CmsException(e1); } if (df == null) { try { df = DatatypeFactory.newInstance(); } catch (DatatypeConfigurationException e) { throw new CmsException(e); } } contentObjectMarshalContext = new ContentObjectMarshalContext(contentObjectType); contentObjectMarshalContext.addComplexCmsPropertyInfoToQueue(createRootComplexCmsPropertyInfo()); }
From source file:org.betaconceptframework.astroboa.test.engine.AbstractRepositoryTest.java
protected void preSetup() throws Exception { astroboaVersion = System.getProperty("astroboaVersion"); TestLogPolicy.setLevelForLogger(Level.ERROR, ContentDefinitionConfiguration.class.getName()); TestLogPolicy.setLevelForLogger(Level.ERROR, CmsEntitySerialization.class.getName()); TestLogPolicy.setLevelForLogger(Level.ERROR, JackrabbitIdentityStoreDao.class.getName()); //If debug is enabled for this test then pretty print is enabled as well. prettyPrint = LoggerFactory.getLogger("org.betaconceptframework.astroboa.engine.AbstractRepositoryTest") .isDebugEnabled();/*from w w w .j a va 2s .c om*/ if (df == null) { try { df = DatatypeFactory.newInstance(); } catch (DatatypeConfigurationException e) { throw new CmsException(e); } } }
From source file:org.bibsonomy.rest.renderer.impl.JAXBRenderer.java
protected JAXBRenderer(final UrlRenderer urlRenderer) { final RestProperties properties = RestProperties.getInstance(); this.urlRenderer = urlRenderer; try {/*from ww w . j av a2s . c om*/ this.datatypeFactory = DatatypeFactory.newInstance(); } catch (final DatatypeConfigurationException ex) { throw new RuntimeException("Could not instantiate data type factory.", ex); } this.validateXMLInput = "true".equals(properties.get(VALIDATE_XML_INPUT)); this.validateXMLOutput = "true".equals(properties.get(VALIDATE_XML_OUTPUT)); ModelFactory.getInstance().setModelValidator(properties.getModelValidator()); // we only need to load the XML schema if we validate input or output if (this.validateXMLInput || this.validateXMLOutput) { try { schema = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI) .newSchema(this.getClass().getClassLoader().getResource("xschema.xsd")); } catch (final Exception e) { log.error("Failed to load XML schema", e); schema = null; } } else { schema = null; } }