List of usage examples for javax.xml.transform.dom DOMResult DOMResult
public DOMResult()
From source file:no.digipost.signature.client.asice.signature.CreateXAdESProperties.java
public Document createPropertiesToSign(final List<ASiCEAttachable> files, final X509Certificate certificate) { byte[] certificateDigestValue; try {//from w w w . ja v a 2 s . c o m certificateDigestValue = sha1(certificate.getEncoded()); } catch (CertificateEncodingException e) { throw new CertificateException("Unable to get encoded from of certificate", e); } DigestAlgAndValueType certificateDigest = new DigestAlgAndValueType(sha1DigestMethod, certificateDigestValue); X509IssuerSerialType certificateIssuer = new X509IssuerSerialType(certificate.getIssuerDN().getName(), certificate.getSerialNumber()); SigningCertificate signingCertificate = new SigningCertificate( singletonList(new CertIDType(certificateDigest, certificateIssuer, null))); Date now = new Date(); SignedSignatureProperties signedSignatureProperties = new SignedSignatureProperties(now, signingCertificate, null, null, null, null); SignedDataObjectProperties signedDataObjectProperties = new SignedDataObjectProperties( dataObjectFormats(files), null, null, null, null); SignedProperties signedProperties = new SignedProperties(signedSignatureProperties, signedDataObjectProperties, "SignedProperties"); QualifyingProperties qualifyingProperties = new QualifyingProperties(signedProperties, null, "#Signature", null); DOMResult domResult = new DOMResult(); marshaller.marshal(qualifyingProperties, domResult); Document document = (Document) domResult.getNode(); // Explicitly mark the SignedProperties Id as an Document ID attribute, so that it will be eligble as a reference for signature. // If not, it will not be treated as something to sign. markAsIdProperty(document, "SignedProperties", "Id"); return document; }
From source file:no.difi.sdp.client.asice.signature.CreateXAdESProperties.java
public Document createPropertiesToSign(List<AsicEAttachable> files, Sertifikat sertifikat) { X509Certificate certificate = sertifikat.getX509Certificate(); byte[] certificateDigestValue = sha1(sertifikat.getEncoded()); DigestAlgAndValueType certificateDigest = new DigestAlgAndValueType(sha1DigestMethod, certificateDigestValue);/* w ww . j a v a 2 s. c om*/ X509IssuerSerialType certificateIssuer = new X509IssuerSerialType(certificate.getIssuerDN().getName(), certificate.getSerialNumber()); SigningCertificate signingCertificate = new SigningCertificate( singletonList(new CertIDType(certificateDigest, certificateIssuer, null))); DateTime now = DateTime.now(DateTimeZone.UTC); SignedSignatureProperties signedSignatureProperties = new SignedSignatureProperties(now, signingCertificate, null, null, null, null); SignedDataObjectProperties signedDataObjectProperties = new SignedDataObjectProperties( dataObjectFormats(files), null, null, null, null); SignedProperties signedProperties = new SignedProperties(signedSignatureProperties, signedDataObjectProperties, "SignedProperties"); QualifyingProperties qualifyingProperties = new QualifyingProperties(signedProperties, null, "#Signature", null); DOMResult domResult = new DOMResult(); marshaller.marshal(qualifyingProperties, domResult); Document document = (Document) domResult.getNode(); // Explicitly mark the SignedProperties Id as an Document ID attribute, so that it will be eligble as a reference for signature. // If not, it will not be treated as something to sign. markAsIdProperty(document, "SignedProperties", "Id"); return document; }
From source file:com.cisco.dvbu.ps.common.adapters.util.XmlUtils.java
public static Document xslTransform(Node xmlData, StreamSource xslSource) throws Exception { TransformerFactory tFactory = new TransformerFactoryImpl(); Transformer transformer;/*from w w w .j a v a 2 s. c o m*/ DOMResult domRes; Document doc = null; try { transformer = tFactory.newTransformer(xslSource); domRes = new DOMResult(); // perform transformation transformer.transform(new DOMSource(xmlData), domRes); doc = (Document) domRes.getNode(); // log.debug(XmlUtils.nodeToString(doc)); } catch (Exception e) { log.error("Xslt Transformation error! " + e.getMessage()); throw e; } return doc; }
From source file:com.example.switchyard.sap.Transformers.java
private Element toElement(String xml) { DOMResult dom = new DOMResult(); try {//from w ww. ja v a 2s . c om TransformerFactory.newInstance().newTransformer().transform(new StreamSource(new StringReader(xml)), dom); } catch (Exception ex) { ex.printStackTrace(); } return ((Document) dom.getNode()).getDocumentElement(); }
From source file:com.predic8.membrane.core.interceptor.schemavalidation.SchematronValidator.java
public SchematronValidator(ResolverMap resourceResolver, String schematron, ValidatorInterceptor.FailureHandler failureHandler, Router router, BeanFactory beanFactory) throws Exception { this.failureHandler = failureHandler; //works as standalone "com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl" TransformerFactory fac;/*from w ww .jav a 2 s. c o m*/ try { fac = beanFactory.getBean("transformerFactory", TransformerFactory.class); } catch (NoSuchBeanDefinitionException e) { throw new RuntimeException( "Please define a bean called 'transformerFactory' in monitor-beans.xml, e.g. with " + "<spring:bean id=\"transformerFactory\" class=\"com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl\" />", e); } fac.setURIResolver(new URIResolver() { @Override public Source resolve(String href, String base) throws TransformerException { return new StreamSource(SchematronValidator.class.getResourceAsStream(href)); } }); Transformer t = fac.newTransformer( new StreamSource(SchematronValidator.class.getResourceAsStream("conformance1-5.xsl"))); // transform schematron-XML into XSLT DOMResult r = new DOMResult(); t.transform(new StreamSource(router.getResolverMap().resolve(schematron)), r); // build XSLT transformers fac.setURIResolver(null); int concurrency = Runtime.getRuntime().availableProcessors() * 2; transformers = new ArrayBlockingQueue<Transformer>(concurrency); for (int i = 0; i < concurrency; i++) { Transformer transformer = fac.newTransformer(new DOMSource(r.getNode())); transformer.setErrorListener(new NullErrorListener()); // silence console logging transformers.put(transformer); } xmlInputFactory = XMLInputFactory.newInstance(); xmlInputFactory.setProperty(XMLInputFactory.IS_REPLACING_ENTITY_REFERENCES, false); xmlInputFactory.setProperty(XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES, false); }
From source file:org.esigate.xml.XsltRenderer.java
/** {@inheritDoc} */ @Override//www . j a v a 2 s . co m public void render(DriverRequest httpRequest, String src, Writer out) throws IOException { try { HtmlDocumentBuilder htmlDocumentBuilder = new HtmlDocumentBuilder(); htmlDocumentBuilder.setDoctypeExpectation(DoctypeExpectation.NO_DOCTYPE_ERRORS); Document document = htmlDocumentBuilder.parse(new InputSource(new StringReader(src))); Source source = new DOMSource(document); DOMResult result = new DOMResult(); transformer.transform(source, result); XhtmlSerializer serializer = new XhtmlSerializer(out); Dom2Sax dom2Sax = new Dom2Sax(serializer, serializer); dom2Sax.parse(result.getNode()); } catch (TransformerException e) { throw new ProcessingFailedException("Failed to transform source", e); } catch (SAXException e) { throw new ProcessingFailedException("Failed serialize transformation result", e); } }
From source file:cz.cas.lib.proarc.common.export.cejsh.CejshBuilderTest.java
@Test public void testCreateCejshXml_TitleVolumeIssue() throws Exception { CejshConfig conf = new CejshConfig(); CejshBuilder cb = new CejshBuilder(conf); Document articleDoc = cb.getDocumentBuilder() .parse(CejshBuilderTest.class.getResource("article_mods.xml").toExternalForm()); // issn must match some cejsh_journals.xml/cejsh/journal[@issn=$issn] final String pkgIssn = "0231-5955"; Issue issue = new Issue(); issue.setIssn(pkgIssn);/*w w w. ja v a 2 s . c o m*/ issue.setIssueId("uuid-issue"); issue.setIssueNumber("issue1"); Volume volume = new Volume(); volume.setVolumeId("uuid-volume"); volume.setVolumeNumber("volume1"); volume.setYear("1985"); Article article = new Article(null, articleDoc.getDocumentElement(), null); cb.setIssue(issue); cb.setVolume(volume); Document articleCollectionDoc = cb.mergeElements(Collections.singletonList(article)); DOMSource cejshSource = new DOMSource(articleCollectionDoc); DOMResult cejshResult = new DOMResult(); // dump(cejshSource); TransformErrorListener xslError = cb.createCejshXml(cejshSource, cejshResult); assertEquals(Collections.emptyList(), xslError.getErrors()); final Node cejshRootNode = cejshResult.getNode(); // dump(new DOMSource(cejshRootNode)); List<String> errors = cb.validateCejshXml(new DOMSource(cejshRootNode)); assertEquals(Collections.emptyList(), errors); XPath xpath = ProarcXmlUtils.defaultXPathFactory().newXPath(); xpath.setNamespaceContext(new SimpleNamespaceContext().add("b", CejshBuilder.NS_BWMETA105)); assertNotNull( xpath.evaluate("/b:bwmeta/b:element[@id='bwmeta1.element.ebfd7bf2-169d-476e-a230-0cc39f01764c']", cejshRootNode, XPathConstants.NODE)); assertEquals("volume1", xpath.evaluate("/b:bwmeta/b:element[@id='bwmeta1.element.uuid-volume']/b:name", cejshRootNode, XPathConstants.STRING)); assertEquals("issue1", xpath.evaluate("/b:bwmeta/b:element[@id='bwmeta1.element.uuid-issue']/b:name", cejshRootNode, XPathConstants.STRING)); assertEquals("1985", xpath.evaluate( "/b:bwmeta/b:element[@id='bwmeta1.element.9358223b-b135-388f-a71e-24ac2c8422c7-1985']/b:name", cejshRootNode, XPathConstants.STRING)); }
From source file:edu.wisc.hrs.dao.BaseHrsSoapDao.java
protected Node getNode(Source source) { if (source instanceof DOMSource) { return ((DOMSource) source).getNode(); }/*from w w w . jav a2s.c o m*/ //Not a DOM source, transform into a DOM node try { final TransformerFactory transformerFactory = TransformerFactory.newInstance(); final Transformer transformer = transformerFactory.newTransformer(); final DOMResult domResult = new DOMResult(); transformer.transform(source, domResult); return domResult.getNode(); } catch (TransformerConfigurationException tce) { //ignore this SoapFaultDetailElement since sadly it could not be converted to a DOM Node return null; } catch (TransformerException te) { //ignore this SoapFaultDetailElement since sadly it could not be converted to a DOM Node return null; } }
From source file:it.tidalwave.northernwind.core.impl.filter.XsltMacroFilter.java
/******************************************************************************************************************* * ******************************************************************************************************************/ @Override//from ww w . j a va 2 s .c o m @Nonnull public String filter(final @Nonnull String text, final @Nonnull String mimeType) { if (!mimeType.equals("application/xhtml+xml")) { log.debug("Cannot filter resources not in XHTML: {}", mimeType); return text; } // FIXME: buggy and cumbersome if (!initialized) { try { synchronized (this) { if (!initialized) { initialize(); initialized = true; } } } catch (IOException | NotFoundException e) { throw new RuntimeException(e); } } try { final DOMResult result = new DOMResult(); final Transformer transformer = createTransformer(); // Fix for NW-100 transformer.transform(new DOMSource(stringToNode(text.replace("xml:lang", "xml_lang"))), result); final StringWriter stringWriter = new StringWriter(); if (text.startsWith(DOCTYPE_HTML)) { stringWriter.append(DOCTYPE_HTML).append("\n"); } // Fix for NW-96 final XhtmlMarkupSerializer xhtmlSerializer = new XhtmlMarkupSerializer(stringWriter); xhtmlSerializer.serialize(result.getNode()); return stringWriter.toString().replace("xml_lang", "xml:lang").replace(" xmlns=\"\"", ""); // FIXME: } catch (SAXParseException e) { log.error("XML parse error: {} at l{}:c{}", e.getMessage(), e.getLineNumber(), e.getColumnNumber()); log.error(text); throw new RuntimeException(e); } catch (TransformerException e) { log.error("XSL error: {} at {}", e.toString(), e.getLocationAsString()); log.error(xslt); throw new RuntimeException(e); } catch (IOException | SAXException | ParserConfigurationException e) { throw new RuntimeException(e); } }
From source file:TransformThread.java
/** Initialize the results (m_outResult) according * to RESULT_FLAVOR// w w w .j a v a 2 s. co m */ private void initResult() { try { for (int i = 0; i < NUM_TRANSFORMATIONS; i++) { switch (RESULT_FLAVOR) { case STREAM: OutputStream outStream = new FileOutputStream( FILE_OUT_BASE + "thread_" + m_thrdNum + "_transformation_" + i + FILE_OUT_EXT); m_outResult[i] = new StreamResult(outStream); break; case SAX: DefaultHandler defaultHandler = new DefaultHandler(); m_outResult[i] = new SAXResult(defaultHandler); break; case DOM: m_outResult[i] = new DOMResult(); break; } } } catch (Exception e) { e.printStackTrace(); System.exit(1); } }