List of usage examples for javax.xml.transform.dom DOMResult DOMResult
public DOMResult()
From source file:org.ojbc.xslt.ProbationToSubscriptionTransformerServiceTest.java
private Document transformCaseInitiationToSubscription(Document caseInitiation) throws Exception { TransformerFactory transformerFactory = TransformerFactory.newInstance(); Transformer transformer = transformerFactory.newTransformer(subscriptionXSLT); DOMResult domResult = new DOMResult(); DOMSource inDocDomSource = new DOMSource(caseInitiation); transformer.transform(inDocDomSource, domResult); Document resultDoc = (Document) domResult.getNode(); return resultDoc; }
From source file:org.ojbc.xslt.ProbationToSubscriptionTransformerServiceTest.java
private Document transformCaseTerminationToUnsubscription(Document caseTermination) throws Exception { TransformerFactory transformerFactory = TransformerFactory.newInstance(); Transformer transformer = transformerFactory.newTransformer(unSubscriptionXSLT); DOMResult domResult = new DOMResult(); DOMSource inDocDomSource = new DOMSource(caseTermination); transformer.transform(inDocDomSource, domResult); Document resultDoc = (Document) domResult.getNode(); return resultDoc; }
From source file:org.openengsb.core.common.remote.XmlMethodCallMarshalOutgoingFilter.java
private Document serializeRequest(MethodCallMessage result) { DOMResult domResult = new DOMResult(); try {/* www .j a v a2s. com*/ @SuppressWarnings("unchecked") List<Class<?>> classes = ClassUtils.convertClassNamesToClasses(result.getMethodCall().getClasses()); if (classes.contains(null)) { throw new FilterException("Could not load all required classes. Require: " + result.getMethodCall().getClasses() + " got: " + classes); } classes.add(MethodCallMessage.class); JAXBContext jaxbContext = JAXBContext.newInstance(classes.toArray(new Class<?>[classes.size()])); Marshaller marshaller = jaxbContext.createMarshaller(); marshaller .marshal(new JAXBElement<MethodCallMessage>(new QName(MethodCallMessage.class.getSimpleName()), MethodCallMessage.class, result), domResult); } catch (JAXBException e) { throw new FilterException(e); } return (Document) domResult.getNode(); }
From source file:org.qi4j.valueserialization.stax.StaxValueDeserializer.java
@Override protected Node readObjectTree(XMLEventReader input) throws Exception { XMLEvent peek = input.peek(); if (peek.isStartElement() && "null".equals(peek.asStartElement().getName().getLocalPart())) { input.nextTag();// <null> input.nextTag();// </null> return null; }//w ww.ja v a 2s .c om String elementBody = readElementBody(input); Transformer transformer = transformerFactory.newTransformer(); DOMResult domResult = new DOMResult(); transformer.transform(new StreamSource(new StringReader(elementBody)), domResult); return ((Document) domResult.getNode()).getDocumentElement(); }
From source file:org.rimudb.configuration.AbstractXmlLoader.java
/** * @param document/*from w w w . j a va 2 s.c om*/ * @param compoundDbSchemaUrl * @return SAXParseException * @throws Exception */ protected SAXParseException validate(Document document, String compoundDbSchemaUrl) throws Exception { // Compile a schema for the XSD SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); // Look up the schema URL and find it's local resource file URL schemaURL = null; String schemaPath = RimuDBNamespace.lookupInternalSchema(compoundDbSchemaUrl); if (schemaPath != null) { schemaURL = getClass().getClassLoader().getResource(schemaPath); } else { schemaURL = new URL(compoundDbSchemaUrl); } Schema schema = schemaFactory.newSchema(schemaURL); // Validate the document against the schema Validator validator = schema.newValidator(); validator.setErrorHandler(new StrictErrorHandler()); try { validator.validate(new DOMSource(document), new DOMResult()); } catch (SAXParseException e) { return e; } return null; }
From source file:org.sakaiproject.tags.impl.job.MeshTagsSyncJob.java
public synchronized void syncAllTags() { long start = System.currentTimeMillis(); if (log.isInfoEnabled()) { log.info("Starting MESH Tag Collection synchronization"); }//from ww w.j a v a 2 s. c om try { XMLInputFactory factory = XMLInputFactory.newInstance(); XMLStreamReader xsr = factory.createXMLStreamReader(getTagsXmlInputStream()); xsr.next(); xsr.nextTag(); TransformerFactory tf = TransformerFactory.newInstance(); Transformer t = tf.newTransformer(); while (xsr.nextTag() == XMLStreamConstants.START_ELEMENT) { DOMResult result = new DOMResult(); t.transform(new StAXSource(xsr), result); Node nNode = result.getNode(); Element element = ((Document) nNode).getDocumentElement(); String tagLabel = "undefined"; counterTotal++; try { Element descriptorName = (Element) element.getElementsByTagName("DescriptorName").item(0); tagLabel = getString("String", descriptorName); String externalId = getString("DescriptorUI", element); String description = getString("Annotation", element); long externalCreationDate = xmlDateToMs(element.getElementsByTagName("DateCreated").item(0), externalId); long lastUpdateDateInExternalSystem = xmlDateToMs( element.getElementsByTagName("DateRevised").item(0), externalId); String externalHierarchyCode = xmlTreeToString( element.getElementsByTagName("TreeNumberList").item(0), externalId); String externalType = element.getAttribute("DescriptorClass"); String alternativeLabels = xmlToAlternativeLabels( element.getElementsByTagName("ConceptList").item(0), externalId); updateOrCreateTagWithExternalSourceName(externalId, "MESH", tagLabel, description, alternativeLabels, externalCreationDate, lastUpdateDateInExternalSystem, null, externalHierarchyCode, externalType, null); counterSuccess++; lastSuccessfulLabel = tagLabel; } catch (Exception e) { log.warn("Mesh XML can't be processed for this Label: " + tagLabel + ". If the value is undefined, then, the previous successful label was: " + lastSuccessfulLabel, e); sendStatusMail(2, e.getMessage()); } if (counterTotal % 1000 == 0) { log.info(counterSuccess + "/" + counterTotal + " labels processed correctly... and still processing. " + (counterTotal - counterSuccess) + " errors by the moment"); } } // end while xsr.close(); updateTagCollectionSynchronization("MESH", 0L); deleteTagsOlderThanDateFromCollection("MESH", start); sendStatusMail(1, "Imported from MESH finished. Num of labels processed successfully " + counterSuccess + "of" + counterTotal); } catch (XMLStreamException ex) { log.warn("Mesh XML can't be processed", ex); } catch (Exception e) { log.warn("Mesh XML can't be processed", e); sendStatusMail(2, e.getMessage()); } if (log.isInfoEnabled()) { log.info("Finished Mesh Tags synchronization in " + (System.currentTimeMillis() - start) + " ms"); } counterTotal = 0; counterSuccess = 0; lastSuccessfulLabel = ""; }
From source file:org.sakaiproject.tags.impl.job.TagsExportedXMLSyncJob.java
public synchronized void syncAllTags() { long start = System.currentTimeMillis(); if (log.isInfoEnabled()) { log.info("Starting Full XML Tag Collection synchronization"); }/*from w w w .ja v a 2 s . c om*/ try { XMLInputFactory factory = XMLInputFactory.newInstance(); XMLStreamReader xsr = factory.createXMLStreamReader(getTagsXmlInputStream()); xsr.next(); TransformerFactory tf = TransformerFactory.newInstance(); Transformer t = tf.newTransformer(); while (xsr.nextTag() == XMLStreamConstants.START_ELEMENT) { DOMResult result = new DOMResult(); t.transform(new StAXSource(xsr), result); Node nNode = result.getNode(); Element element = ((Document) nNode).getDocumentElement(); String tagLabel = getString("tagLabel", element); String tagId = getString("tagId", element); String externalId = getString("externalId", element); String description = getString("description", element); long externalCreationDate = stringToLong(getString("externalCreationDate", element), 0L); long lastUpdateDateInExternalSystem = stringToLong( getString("lastUpdateDateInExternalSystem", element), 0L); String externalHierarchyCode = getString("externalHierarchyCode", element); String externalType = getString("externalType", element); String alternativeLabels = getString("alternativeLabels", element); String tagCollectionId = getString("tagCollectionId", element); if (collectionToUpdate != null && !collectionToUpdateMoreThanOne) { if (!(collectionToUpdate.equals(tagCollectionId))) { collectionToUpdateMoreThanOne = true; } } else { collectionToUpdate = tagCollectionId; } String data = getString("data", element); String parentId = getString("parentId", element); if (tagId != null && tagId.length() == VALID_ID_LENGTH) { if (tagWithIdIsPresent(tagId)) { updateLabelWithId(tagId, externalId, tagCollectionId, tagLabel, description, alternativeLabels, externalCreationDate, lastUpdateDateInExternalSystem, parentId, externalHierarchyCode, externalType, data); } else { updateOrCreateTagWithCollectionId(externalId, tagCollectionId, tagLabel, description, alternativeLabels, externalCreationDate, lastUpdateDateInExternalSystem, parentId, externalHierarchyCode, externalType, data); } } else { updateOrCreateTagWithCollectionId(externalId, tagCollectionId, tagLabel, description, alternativeLabels, externalCreationDate, lastUpdateDateInExternalSystem, parentId, externalHierarchyCode, externalType, data); } } updateTagCollectionSynchronizationWithCollectionId(collectionToUpdate, 0L); //We will delete the old ones when there is only one collectionID in the file. if (collectionToUpdate != null && !collectionToUpdateMoreThanOne) { deleteTagsOlderThanDateFromCollectionWithCollectionId(collectionToUpdate, start); } sendStatusMail(1, ""); } catch (Exception e) { log.warn("Full Tags XML can't be processed", e); sendStatusMail(2, e.getMessage()); } String collectionToUpdate = null; Boolean collectionToUpdateMoreThanOne = false; if (log.isInfoEnabled()) { log.info("Finished Full XML Tags synchronization in " + (System.currentTimeMillis() - start) + " ms"); } }
From source file:org.sakaiproject.tags.impl.job.TagsSyncJob.java
public synchronized void syncAllTags() { long start = System.currentTimeMillis(); if (log.isInfoEnabled()) { log.info("Starting Tag Collection synchronization"); }/* w w w . j av a 2 s .c o m*/ try { XMLInputFactory factory = XMLInputFactory.newInstance(); XMLStreamReader xsr = factory.createXMLStreamReader(getTagCollectionssXmlInputStream()); xsr.next(); TransformerFactory tf = TransformerFactory.newInstance(); Transformer t = tf.newTransformer(); while (xsr.nextTag() == XMLStreamConstants.START_ELEMENT) { DOMResult result = new DOMResult(); t.transform(new StAXSource(xsr), result); Node nNode = result.getNode(); Element element = ((Document) nNode).getDocumentElement(); String name = getString("Name", element); log.debug("Found name: " + name); String description = getString("Description", element); log.debug("Found description : " + description); String externalSourceName = getString("ExternalSourceName", element); log.debug("externalSourceName: " + externalSourceName); String externalSourceDescription = getString("ExternalSourceDescription", element); log.debug("externalSourceDescription: " + externalSourceDescription); long lastUpdateDateInExternalSystem = xmlDateToMs( element.getElementsByTagName("DateRevised").item(0), name); log.debug("lastUpdateDateInExternalSystem: " + lastUpdateDateInExternalSystem); updateOrCreateTagCollection(name, description, externalSourceName, externalSourceDescription, lastUpdateDateInExternalSystem); } sendStatusMail(1, ""); } catch (Exception e) { log.warn("Error Synchronizing the Tags from an xml file:", e); sendStatusMail(2, e.getMessage()); } try { XMLInputFactory factory = XMLInputFactory.newInstance(); XMLStreamReader xsr = factory.createXMLStreamReader(getTagsXmlInputStream()); xsr.next(); TransformerFactory tf = TransformerFactory.newInstance(); Transformer t = tf.newTransformer(); while (xsr.nextTag() == XMLStreamConstants.START_ELEMENT) { DOMResult result = new DOMResult(); t.transform(new StAXSource(xsr), result); Node nNode = result.getNode(); Element element = ((Document) nNode).getDocumentElement(); String action = element.getAttribute("Action"); String tagLabel = getString("TagLabel", element); log.debug("Found tagLabel: " + tagLabel); String externalId = getString("ExternalId", element); log.debug("Found externalId: " + externalId); String description = getString("Description", element); log.debug("Found description : " + description); long externalCreationDate = xmlDateToMs(element.getElementsByTagName("DateCreated").item(0), tagLabel); log.debug("externalCreationDate: " + externalCreationDate); long lastUpdateDateInExternalSystem = xmlDateToMs( element.getElementsByTagName("DateRevised").item(0), tagLabel); log.debug("lastUpdateDateInExternalSystem: " + lastUpdateDateInExternalSystem); String externalHierarchyCode = getString("HierarchyCode", element); log.debug("externalHierarchyCode: " + externalHierarchyCode); String externalType = getString("Type", element); log.debug("externalType: " + externalType); String alternativeLabels = getString("AlternativeLabels", element); log.debug("alternativeLabels: " + alternativeLabels); String externalSourceName = getString("ExternalSourceName", element); log.debug("externalSourceName: " + externalSourceName); String data = getString("Data", element); log.debug("data: " + data); String parentId = getString("ParentId", element); log.debug("parentId: " + parentId); if (Objects.equals(action, "delete")) { deleteTagFromExternalCollection(externalId, externalSourceName); } else { updateOrCreateTagWithExternalSourceName(externalId, externalSourceName, tagLabel, description, alternativeLabels, externalCreationDate, lastUpdateDateInExternalSystem, parentId, externalHierarchyCode, externalType, data); } updateTagCollectionSynchronization(externalSourceName, 0L); } sendStatusMail(1, ""); } catch (Exception e) { log.warn("Error Synchronizing the Tags from an xml file:", e); sendStatusMail(2, e.getMessage()); } if (log.isInfoEnabled()) { log.info("Finished Tags synchronization in " + (System.currentTimeMillis() - start) + " ms"); } }
From source file:org.springframework.ws.wsdl.wsdl11.provider.InliningXsdSchemaTypesProvider.java
private Element getSchemaElement(XsdSchema schema) { try {/*ww w. j a v a 2 s . c o m*/ DOMResult result = new DOMResult(); transform(schema.getSource(), result); Document schemaDocument = (Document) result.getNode(); return schemaDocument.getDocumentElement(); } catch (TransformerException e) { throw new WsdlDefinitionException("Could not transform schema source to Document"); } }
From source file:org.trancecode.xml.saxon.Saxon.java
public static Document asDomDocument(final XdmNode node, final Processor processor) { try {//from www .j a v a 2 s . c o m final Document document = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument(); final DOMResult domResult = new DOMResult(); final XsltTransformer transformer = processor.newXsltCompiler().compile(null).load(); transformer.setSource(node.asSource()); transformer.setDestination(new DOMDestination(document)); transformer.transform(); return (Document) domResult.getNode(); } catch (final Exception e) { throw new IllegalStateException(e); } }