Example usage for javax.xml.transform.dom DOMResult getNode

List of usage examples for javax.xml.transform.dom DOMResult getNode

Introduction

In this page you can find the example usage for javax.xml.transform.dom DOMResult getNode.

Prototype

public Node getNode() 

Source Link

Document

Get the node that will contain the result DOM tree.

Usage

From source file:org.brekka.phalanx.client.services.impl.PhalanxServiceClient.java

/**
 * @param e// w w w  . j ava 2s . com
 */
private static void identifyFault(final SoapFaultClientException e) {
    Result result = e.getSoapFault().getFaultDetail().getResult();
    OperationFault fault = null;
    if (result instanceof DOMResult) {
        DOMResult domResult = (DOMResult) result;
        Node node = domResult.getNode().getFirstChild();
        XmlCursor cursor = null;
        try {
            XmlObject object = XmlObject.Factory.parse(node);
            cursor = object.newCursor();
            while (cursor.hasNextToken()) {
                XmlObject xml = cursor.getObject();
                if (xml instanceof OperationFault) {
                    fault = (OperationFault) xml;
                    break;
                }
                cursor.toNextToken();
            }
        } catch (XmlException xmlex) {
            // Never mind
        } finally {
            if (cursor != null) {
                cursor.dispose();
            }
        }
    }
    if (fault != null) {
        PhalanxErrorCode errorCode = PhalanxErrorCode.valueOf(fault.getCode());
        throw new PhalanxException(errorCode, fault.getMessage());
    }
}

From source file:com.evolveum.midpoint.testing.model.client.sample.Main.java

private static QueryType createUserQuery2(String username) throws JAXBException {
    QueryType query = new QueryType();

    SearchFilterType filter = new SearchFilterType();

    PropertyComplexValueFilterClauseType fc = new PropertyComplexValueFilterClauseType();
    ItemPathType path = new ItemPathType();
    path.setValue("declare namespace c=\"http://midpoint.evolveum.com/xml/ns/public/common/common-3\"; c:name");
    fc.setPath(path);//from w  w w  .  j  av a  2s  . co m
    fc.setValue(username);

    ObjectFactory factory = new ObjectFactory();
    JAXBElement<PropertyComplexValueFilterClauseType> equal = factory.createEqual(fc);

    JAXBContext jaxbContext = JAXBContext.newInstance("com.evolveum.midpoint.xml.ns._public.common.api_types_3:"
            + "com.evolveum.midpoint.xml.ns._public.common.common_3:"
            + "com.evolveum.prism.xml.ns._public.annotation_3:" + "com.evolveum.prism.xml.ns._public.query_3:"
            + "com.evolveum.prism.xml.ns._public.types_3:");
    Marshaller marshaller = jaxbContext.createMarshaller();
    DOMResult result = new DOMResult();
    marshaller.marshal(equal, result);
    filter.setFilterClause(((Document) result.getNode()).getDocumentElement());

    query.setFilter(filter);
    return query;
}

From source file:cz.cas.lib.proarc.common.export.mets.JhoveUtility.java

/**
 * Merges the mix from the device and from the image
 *
 * @param source/*from   ww w.  java  2 s  .  co m*/
 * @param deviceMix
 */
public static void mergeMix(Mix source, MixType deviceMix) {
    if (deviceMix != null) {
        if (deviceMix.getImageCaptureMetadata() != null) {
            DOMResult domResult = new DOMResult();
            MixUtils.marshal(domResult, new JAXBElement<ImageCaptureMetadataType>(new QName("uri", "local"),
                    ImageCaptureMetadataType.class, deviceMix.getImageCaptureMetadata()), true);
            ImageCaptureMetadataType imageCaptureMtd = MixUtils.unmarshal(new DOMSource(domResult.getNode()),
                    ImageCaptureMetadataType.class);
            source.setImageCaptureMetadata(imageCaptureMtd);
        }
    }

}

From source file:cz.cas.lib.proarc.common.export.mets.JhoveUtility.java

/**
 * Adds the photometric information to the mix
 *
 *
 * @param jhoveOutput//from   ww w .  ja v  a  2 s.  c o m
 * @param photometricInterpretation
 */
public static void addPhotometricInformation(JHoveOutput jhoveOutput,
        PhotometricInterpretation photometricInterpretation) {
    if (photometricInterpretation != null) {
        if (jhoveOutput.getMix().getBasicImageInformation() == null) {
            jhoveOutput.getMix().setBasicImageInformation(new BasicImageInformationType());
        }
        if (jhoveOutput.getMix().getBasicImageInformation().getBasicImageCharacteristics() == null) {
            jhoveOutput.getMix().getBasicImageInformation()
                    .setBasicImageCharacteristics(new BasicImageInformationType.BasicImageCharacteristics());
        }
        if (jhoveOutput.getMix().getBasicImageInformation().getBasicImageCharacteristics()
                .getPhotometricInterpretation() == null) {

            DOMResult photometricResult = new DOMResult();
            MixUtils.marshal(photometricResult,
                    new JAXBElement<PhotometricInterpretation>(new QName("uri", "local"),
                            PhotometricInterpretation.class, photometricInterpretation),
                    true);

            PhotometricInterpretation photometricInterpretationNew = MixUtils
                    .unmarshal(new DOMSource(photometricResult.getNode()), PhotometricInterpretation.class);
            jhoveOutput.getMix().getBasicImageInformation().getBasicImageCharacteristics()
                    .setPhotometricInterpretation(photometricInterpretationNew);
        }
    }
}

From source file:net.javacrumbs.airline.server.VanillaTest.java

private Document getDocument(String name) throws TransformerException {

    DOMResult result = new DOMResult();
    new TransformerHelper().transform(new StreamSource(getStream(name)), result);
    return (Document) result.getNode();

}

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. ja v  a  2  s  .co  m
    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:no.digipost.signature.client.asice.signature.CreateXAdESProperties.java

public Document createPropertiesToSign(final List<ASiCEAttachable> files, final X509Certificate certificate) {
    byte[] certificateDigestValue;
    try {//  w w w.  j av a 2 s .c om
        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.digipost.api.SdpMeldingSigner.java

public Document sign(final StandardBusinessDocument sbd) {
    try {//from   w  w  w .ja v a  2s . co  m
        PrivateKey privateKey = keystoreInfo.getPrivateKey();
        X509Certificate certificate = keystoreInfo.getCertificate();

        DOMResult result = new DOMResult();
        Marshalling.marshal(marshaller, sbd, result);
        Document doc = (Document) result.getNode();
        Marshalling.trimNamespaces(doc);

        XMLSignatureFactory fac = XMLSignatureFactory.getInstance("DOM");
        Reference ref = fac.newReference("", fac.newDigestMethod(DigestMethod.SHA256, null),
                Collections.singletonList(fac.newTransform(Transform.ENVELOPED, (TransformParameterSpec) null)),
                null, null);

        SignedInfo si = fac.newSignedInfo(
                fac.newCanonicalizationMethod(CanonicalizationMethod.EXCLUSIVE, (C14NMethodParameterSpec) null),
                fac.newSignatureMethod(Constants.RSA_SHA256, null), Collections.singletonList(ref));
        KeyInfoFactory kif = fac.getKeyInfoFactory();
        X509Data xd = kif.newX509Data(Collections.singletonList(certificate));
        KeyInfo ki = kif.newKeyInfo(Collections.singletonList(xd));
        XMLSignature signature = fac.newXMLSignature(si, ki);

        Node digitalPostNode = doc.getDocumentElement().getFirstChild().getNextSibling();
        Node avsenderNode = digitalPostNode.getFirstChild();

        DOMSignContext dsc = new DOMSignContext(privateKey, digitalPostNode, avsenderNode);
        signature.sign(dsc);

        doc.normalizeDocument();
        return doc;
    } catch (NoSuchAlgorithmException e) {
        throw new RuntimeException(e);
    } catch (UnrecoverableKeyException e) {
        throw new RuntimeException(e);
    } catch (XMLSignatureException e) {
        throw new RuntimeException(e);
    } catch (InvalidAlgorithmParameterException e) {
        throw new RuntimeException(e);
    } catch (KeyStoreException e) {
        throw new RuntimeException(e);
    } catch (MarshalException e) {
        throw new RuntimeException(e);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}

From source file:edu.wisc.hrs.dao.BaseHrsSoapDao.java

protected Node getNode(Source source) {
    if (source instanceof DOMSource) {
        return ((DOMSource) source).getNode();
    }/*from   ww w .ja v 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:net.javacrumbs.springws.test.util.DefaultXmlUtil.java

public Document loadDocument(Source source) {
    DOMResult messageContent = new DOMResult();
    transform(source, messageContent);//from  w w  w  .  java 2s .  c  om
    return (Document) messageContent.getNode();
}