Example usage for org.w3c.dom Document importNode

List of usage examples for org.w3c.dom Document importNode

Introduction

In this page you can find the example usage for org.w3c.dom Document importNode.

Prototype

public Node importNode(Node importedNode, boolean deep) throws DOMException;

Source Link

Document

Imports a node from another document to this document, without altering or removing the source node from the original document; this method creates a new copy of the source node.

Usage

From source file:org.ojbc.web.portal.controllers.SubscriptionsController.java

private Document getSubscriptionResponseDocFromSoapEnvDoc(Document soapEnvDoc) throws Exception {

    if (soapEnvDoc == null) {
        throw new Exception("Cannot get subscription response Document from null soap envelope document");
    }//from   ww  w.j  a  v  a  2s .  co m

    Document rDocument = null;

    Node rootSubRespNode = null;

    if (SubscriptionResponseProcessor.isSubscriptionSuccessResponse(soapEnvDoc)) {

        rootSubRespNode = XmlUtils.xPathNodeSearch(soapEnvDoc, "//b-2:SubscribeResponse");

    } else if (SubscriptionResponseProcessor.isUnsubscriptionAccessDenialResponse(soapEnvDoc)) {

        rootSubRespNode = XmlUtils.xPathNodeSearch(soapEnvDoc, "//b-2:UnableToDestroySubscriptionFault");

    } else if (SubscriptionResponseProcessor.isSubscriptionFaultResponse(soapEnvDoc)) {

        rootSubRespNode = XmlUtils.xPathNodeSearch(soapEnvDoc, "//b-2:SubscribeCreationFailedFault");

    } else {
        throw new Exception("Unknown Subscription Type");
    }

    if (rootSubRespNode != null) {

        rDocument = getDocBuilder().newDocument();

        Node importedNode = rDocument.importNode(rootSubRespNode, true);

        rDocument.appendChild(importedNode);

    } else {
        throw new Exception("Could not recognize subscription response");
    }

    return rDocument;
}

From source file:org.ojbc.web.portal.controllers.SubscriptionsController.java

boolean getValidIndicatorFromValidateResponse(FaultableSoapResponse faultableSoapResponse) throws Exception {

    boolean isValidated = false;

    if (faultableSoapResponse == null) {
        throw new Exception("FaultableSoapResponse param was null");
    }// w  w  w . ja  v a2s  .  c  o  m

    Document soapBodyDoc = faultableSoapResponse.getSoapBodyDoc();

    Document validateResponseDoc = null;

    Node rootValidRespNodeFromSoapEnvDoc = XmlUtils.xPathNodeSearch(soapBodyDoc, "//b-2:ValidateResponse");

    if (rootValidRespNodeFromSoapEnvDoc != null) {

        validateResponseDoc = getDocBuilder().newDocument();

        Node importedValidRespNodeFromSoapEnvDoc = validateResponseDoc
                .importNode(rootValidRespNodeFromSoapEnvDoc, true);

        validateResponseDoc.appendChild(importedValidRespNodeFromSoapEnvDoc);

    } else {
        throw new Exception("Could not recognize validate response message root node");
    }

    SubscriptionValidationResponseProcessor validateResponseProcessor = new SubscriptionValidationResponseProcessor();

    SubscriptionValidationResponse subValidResponse = validateResponseProcessor
            .processResponse(validateResponseDoc);

    isValidated = subValidResponse.isSubscriptionValidated();

    return isValidated;
}

From source file:org.opencastproject.metadata.dublincore.DublinCoreCatalogList.java

/**
 * Serializes list to XML.//from   w w  w.ja va 2  s  .  c o m
 * 
 * @return serialized array as XML string
 * @throws IOException
 *           if serialization cannot be properly performed
 */
public String getResultsAsXML() throws IOException {
    try {
        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
        DocumentBuilder builder = factory.newDocumentBuilder();
        DOMImplementation impl = builder.getDOMImplementation();

        Document doc = impl.createDocument(null, null, null);
        Element root = doc.createElement("dublincorelist");
        root.setAttribute("totalCount", String.valueOf(totalCatalogCount));
        doc.appendChild(root);
        for (DublinCoreCatalog series : catalogList) {
            Node node = doc.importNode(series.toXml().getDocumentElement(), true);
            root.appendChild(node);
        }

        Transformer tf = TransformerFactory.newInstance().newTransformer();
        DOMSource xmlSource = new DOMSource(doc);
        StringWriter out = new StringWriter();
        tf.transform(xmlSource, new StreamResult(out));
        return out.toString();
    } catch (Exception e) {
        throw new IOException(e);
    }
}

From source file:org.openehealth.coms.cc.web_frontend.consentcreator.service.DocumentFactory.java

/**
 * Constructs a CDA Consent for the given user.
 * // w ww.  j a v a 2  s  .  c  o m
 * @param user
 * @param policySet
 *            - null if either the participation should end or if a new
 *            PolicySet should be created.
 * @param author
 * @param participation
 *            - true if the user wants to participate, else false
 * @param out
 *            - The OutputStream on which the generated PDF presentation
 *            will be written
 * @return - The generated CDA file.
 * 
 */
public Document constructCDA(User user, Document policySet, User author, boolean participation,
        OutputStream out) {

    DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
    Document domCDA = null;
    Document domAssignedAuthor = null;
    Document domScanningDevice = null;
    Document domDataEnterer = null;
    Document domCustodian = null;
    Document domLegalAuthenticator = null;
    String cdaAsString = "";

    DocumentBuilder db = null;
    try {
        db = dbf.newDocumentBuilder();

        domCDA = db.parse(urlCdaSkeleton);
        domAssignedAuthor = db.parse(urlAssignedAuthor);
        domScanningDevice = db.parse(urlScanningDevice);
        domDataEnterer = db.parse(urlDataEnterer);
        domCustodian = db.parse(urlCustodian);
        domLegalAuthenticator = db.parse(urlLegalAuthenticator);

    } catch (Exception e) {
        Logger.getLogger(this.getClass()).error(e);
    }

    Date d = new Date();

    String uniqueID = RandomStringUtils.randomNumeric(64);

    domCDA.getElementsByTagName("id").item(0).getAttributes().item(0).setNodeValue(uniqueID);
    domCDA.getElementsByTagName("id").item(0).getAttributes().item(1)
            .setNodeValue("1.2.276.0.76.3.1.78.1.0.10.40");

    SimpleDateFormat sd = new SimpleDateFormat("yyyyMMddHHmmssZ");

    domCDA.getElementsByTagName("effectiveTime").item(0).getAttributes().item(0).setTextContent(sd.format(d));

    Node title = domCDA.getElementsByTagName("title").item(0);

    if (participation) {
        title.setTextContent("Dies ist die Einwilligungserklrung fr die Teilnahme an ISIS von "
                + user.getForename() + " " + user.getName());
    } else {
        title.setTextContent("Dieses Dokument erklrt den Verzicht von " + user.getForename() + " "
                + user.getName() + " auf die Teilnahme an ISIS.");
    }

    Node pR = domCDA.getElementsByTagName("patientRole").item(0);

    NodeList prChildren = pR.getChildNodes();

    Node id = prChildren.item(1);

    // extension
    id.getAttributes().item(0).setNodeValue(user.getID()); // PID
    // root
    id.getAttributes().item(1).setNodeValue("1.2.276.0.76.3.1.78.1.0.10.20"); // Assigning
    // Authority

    NodeList addr = prChildren.item(3).getChildNodes();

    addr.item(1).setTextContent(user.getStreet());
    addr.item(3).setTextContent(user.getCity());
    addr.item(5).setTextContent("");//Hier knnte das Bundesland
    // stehen!

    addr.item(7).setTextContent(String.valueOf(user.getZipcode()));
    addr.item(9).setTextContent("Deutschland");// Es sollte nicht
    // standardmig Deutschland
    // gesetzt werden!

    NodeList pat = prChildren.item(5).getChildNodes();

    NodeList name = pat.item(1).getChildNodes();

    if (user.getGender().equalsIgnoreCase("male")) {
        name.item(1).setTextContent("Herr");
        pat.item(3).getAttributes().item(0).setTextContent("M");
    } else {
        name.item(1).setTextContent("Frau");
        pat.item(3).getAttributes().item(0).setTextContent("F");
    }
    name.item(3).setTextContent(user.getForename());
    name.item(5).setTextContent(user.getName());

    SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMdd");

    pat.item(5).getAttributes().item(0).setTextContent(formatter.format(user.getBirthdate()));

    if (policySet == null) {
        policySet = getSkeletonPolicySet(participation, user);

    }
    Document doc = db.newDocument();

    Element root = doc.createElement("component");
    doc.appendChild(root);

    Node copy = doc.importNode(policySet.getDocumentElement(), true);
    root.appendChild(copy);

    NodeList list = domCDA.getElementsByTagName("structuredBody");

    Node f = domCDA.importNode(doc.getDocumentElement(), true);

    list.item(0).appendChild(f);

    Node docuOfNode = domCDA.getElementsByTagName("documentationOf").item(0);

    if (author == user) {

        domAssignedAuthor.getElementsByTagName("time").item(0).getAttributes().item(0)
                .setNodeValue(sd.format(d));

        domAssignedAuthor.getElementsByTagName("id").item(0).getAttributes().item(0)
                .setNodeValue(author.getID()); // ID
        domAssignedAuthor.getElementsByTagName("id").item(0).getAttributes().item(1)
                .setNodeValue("1.2.276.0.76.3.1.78.1.0.10.20");// MPI-assigning
        // authority

        if (user.getGender().equalsIgnoreCase("male")) {
            domAssignedAuthor.getElementsByTagName("prefix").item(0).setTextContent("Herr");
        } else {
            name.item(1).setTextContent("Frau");
            domAssignedAuthor.getElementsByTagName("prefix").item(0).setTextContent("Frau");
        }

        // suffix Wert setzen
        // domAssignedAuthor.getElementsByTagName("suffix").item(0).getAttributes().item(0).setNodeValue("");

        domAssignedAuthor.getElementsByTagName("given").item(0).setTextContent(author.getForename());
        domAssignedAuthor.getElementsByTagName("family").item(0).setTextContent(author.getName());

        // TODO Werte setzen assignedPerson oder Werte loeschen
    } else if (author != user && author != null) {
        // Zukunft: Erzeugung durch Dritte
    } else {
        // Std values from AssignedAuthor.xml
    }

    Node copyAssignedAuthorNode = domCDA.importNode(domAssignedAuthor.getDocumentElement(), true);
    Node copyScanningDeviceNode = domCDA.importNode(domScanningDevice.getDocumentElement(), true);
    Node copyDataEntererNode = domCDA.importNode(domDataEnterer.getDocumentElement(), true);
    Node copyCustodianNode = domCDA.importNode(domCustodian.getDocumentElement(), true);
    Node copyLegalAuthenticator = domCDA.importNode(domLegalAuthenticator.getDocumentElement(), true);

    sd.applyPattern("yyyyMMdd");

    domCDA.getElementsByTagName("low").item(0).getAttributes().item(0).setNodeValue(sd.format(d));

    Date d2 = new Date((long) (d.getTime() + 30 * 3.1556926 * Math.pow(10, 10)));

    domCDA.getElementsByTagName("high").item(0).getAttributes().item(0).setNodeValue(sd.format(d2));

    copyAssignedAuthorNode.getChildNodes().item(3).getAttributes().item(0).setNodeValue(sd.format(d));

    Node clinicalDocumentNode = domCDA.getElementsByTagName("ClinicalDocument").item(0);

    clinicalDocumentNode.insertBefore(copyAssignedAuthorNode, docuOfNode);
    clinicalDocumentNode.insertBefore(copyScanningDeviceNode, docuOfNode);
    clinicalDocumentNode.insertBefore(copyDataEntererNode, docuOfNode);
    clinicalDocumentNode.insertBefore(copyCustodianNode, docuOfNode);
    clinicalDocumentNode.insertBefore(copyLegalAuthenticator, docuOfNode);

    Document noNSCDA = (Document) domCDA.cloneNode(true);

    NodeList l = noNSCDA.getElementsByTagName("ClinicalDocument");

    NamedNodeMap attributes = l.item(0).getAttributes();
    attributes.removeNamedItem("xmlns");
    attributes.removeNamedItem("xmlns:voc");
    attributes.removeNamedItem("xmlns:xsi");
    attributes.removeNamedItem("xsi:schemaLocation");

    l = noNSCDA.getElementsByTagName("PolicySet");
    attributes = l.item(0).getAttributes();
    attributes.removeNamedItem("xmlns");
    attributes.removeNamedItem("PolicyCombiningAlgId");
    attributes.removeNamedItem("xmlns:xsi");
    attributes.removeNamedItem("xsi:schemaLocation");
    attributes.removeNamedItem("PolicySetId");

    formatter = new SimpleDateFormat("dd.MM.yyyy");

    noNSCDA.getElementsByTagName("birthTime").item(0).getAttributes().item(0)
            .setTextContent(formatter.format(user.getBirthdate()));

    cdaAsString = getStringFromDocument(noNSCDA);
    Document nonXMLBody = constructPDF(cdaAsString, out);

    Node copyNode = domCDA.importNode(nonXMLBody.getDocumentElement(), true);

    Node component = domCDA.getElementsByTagName("component").item(0);

    Node structBody = component.getChildNodes().item(1);

    component.insertBefore(copyNode, structBody);

    NamedNodeMap nlm = domCDA.getDocumentElement().getElementsByTagName("PolicySet").item(0).getAttributes();
    // nlm.removeNamedItem("xmlns:xsi");
    // nlm.removeNamedItem("xsi:schemaLocation");

    return domCDA;
}

From source file:org.openehealth.coms.cc.web_frontend.consentcreator.service.DocumentFactory.java

/**
 * Creates a PolicySet for the given user under the aspect whether he wants
 * to participate or not.//  w ww. jav  a  2  s. c  om
 * 
 * @param participation
 * @param user
 * @return
 */
public Document getSkeletonPolicySet(boolean participation, User user) {

    DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();

    Document domPolicySet = null;

    String document = urlPolicySetSkeleton.toString();
    String rule = "";
    String text = "";

    if (participation) {
        text = "Dies ist die Einwilligungserklrung von " + user.getForename() + " " + user.getName();
        rule = urlRuleBasicParticipation.toString();
    } else {
        text = user.getForename() + " " + user.getName()
                + " verweigert mit diesem Dokument die Teilnahme an ISIS";
        rule = urlRuleDenyParticipation.toString();
    }

    try {
        DocumentBuilder db = dbf.newDocumentBuilder();

        domPolicySet = db.parse(document);

        NodeList listDesc = domPolicySet.getDocumentElement().getElementsByTagName("Description");

        listDesc.item(0).setTextContent(text);

        Document rdw = db.parse(rule);

        Node nm = rdw.getFirstChild();

        Element el = (Element) nm;

        Date k = new Date();

        el.setAttribute("RuleId", "urn:oasis:names:tc:xacml:2.0:example:ruleid:" + k.getTime());

        NodeList t = rdw.getElementsByTagName("AttributeValue");

        String value = getResources().get(0).getIdentifier();

        t.item(0).setNodeValue(value);

        Node f = domPolicySet.importNode(rdw.getDocumentElement(), true);

        NodeList l = domPolicySet.getElementsByTagName("Policy");

        l.item(3).appendChild(f);

        domPolicySet.getElementsByTagName("AttributeValue").item(1).setTextContent(value);

        if (!participation) {

            l.item(0).getParentNode().removeChild(l.item(0));
            l.item(0).getParentNode().removeChild(l.item(0));
            l.item(0).getParentNode().removeChild(l.item(0));
        }

    } catch (Exception e) {
        Logger.getLogger(this.getClass()).error(e);
    }

    return domPolicySet;
}

From source file:org.openehealth.coms.cc.web_frontend.consentcreator.service.DocumentFactory.java

/**
 * Adds a Document Rule to the given PolicySet.
 * //from   ww w .j  a  va  2s.  co  m
 * @param policySet
 * @param rule
 * @param ruleType
 *            - defines to which Policy the rule will be added.
 * @return
 */
public Document addRuleToPolicySet(Document policySet, Document rule, int ruleType) {

    NodeList policies = policySet.getElementsByTagName("Policy");

    Node policy = policies.item(ruleType - 1);

    Vector<Node> ruleList = new Vector<Node>();

    for (int i = 0; i < policy.getChildNodes().getLength(); i++) {

        if (policy.getChildNodes().item(i).getNodeName().equalsIgnoreCase("Rule")) {

            ruleList.add(policy.getChildNodes().item(i));

        }
    }

    if (ruleList.size() > 0) {

        int ruleListLength = ruleList.size();

        String subjectOrgaNewRule = rule.getElementsByTagName("AttributeValue").item(0).getTextContent();

        String subjectPersonelNewRule = rule.getElementsByTagName("AttributeValue").item(1).getTextContent();

        String resourceNewRule = rule.getElementsByTagName("AttributeValue").item(2).getTextContent();

        int i = ruleListLength - 1;

        while (i >= 0) {

            String subjectOrgaRule = ruleList.elementAt(i).getChildNodes().item(3).getChildNodes().item(1)
                    .getChildNodes().item(1).getChildNodes().item(1).getChildNodes().item(1).getTextContent();
            String subjectPersonelRule = ruleList.elementAt(i).getChildNodes().item(3).getChildNodes().item(1)
                    .getChildNodes().item(1).getChildNodes().item(3).getChildNodes().item(1).getTextContent();
            String resourceRule = ruleList.elementAt(i).getChildNodes().item(3).getChildNodes().item(3)
                    .getChildNodes().item(1).getChildNodes().item(1).getChildNodes().item(1).getTextContent();

            if (getOIDLength(resourceRule) > getOIDLength(resourceNewRule)) {

                if (i == ruleListLength - 1) {

                    Node copy = policySet.importNode(rule.getDocumentElement(), true);

                    policy.appendChild(copy);
                } else {

                    Node copy = policySet.importNode(rule.getDocumentElement(), true);

                    policy.insertBefore(copy, ruleList.elementAt(i + 1));
                }
                i = -1;
            } else if (getOIDLength(resourceRule) == getOIDLength(resourceNewRule)) {

                if (getOIDLength(subjectOrgaRule) > getOIDLength(subjectOrgaNewRule)) {

                    Node copy = policySet.importNode(rule.getDocumentElement(), true);

                    if (i == ruleListLength - 1) {
                        policy.appendChild(copy);
                    } else {
                        policy.insertBefore(copy, ruleList.elementAt(i + 1));

                    }
                } else if (getOIDLength(subjectOrgaRule) == getOIDLength(subjectOrgaNewRule)) {

                    if (subjectPersonelRule.length() > subjectPersonelNewRule.length()) {

                        if (i == ruleListLength - 1) {

                            Node copy = policySet.importNode(rule.getDocumentElement(), true);

                            policy.appendChild(copy);
                        } else {

                            Node copy = policySet.importNode(rule.getDocumentElement(), true);

                            policy.insertBefore(copy, ruleList.elementAt(i + 1));
                        }
                        i = -1;

                    } else {

                        Node copy = policySet.importNode(rule.getDocumentElement(), true);
                        policy.insertBefore(copy, ruleList.elementAt(i));
                        i = -1;
                    }

                } else {

                    if (i == 0) {
                        Node copy = policySet.importNode(rule.getDocumentElement(), true);
                        policy.insertBefore(copy, ruleList.elementAt(i));
                        i = -1;
                    } else {
                        boolean added = false;

                        for (int t = i; t >= 0; t--) {

                            System.out.println(ruleList.elementAt(t).getChildNodes().item(3).getChildNodes()
                                    .item(1).getChildNodes().item(1).getChildNodes().item(1).getChildNodes()
                                    .item(1).getTextContent());

                            if (getOIDLength(resourceNewRule) == getOIDLength(ruleList.elementAt(t)
                                    .getChildNodes().item(3).getChildNodes().item(3).getChildNodes().item(1)
                                    .getChildNodes().item(1).getChildNodes().item(1).getTextContent())) {
                                // Grer gleich?
                                if (!(getOIDLength(subjectOrgaNewRule) > getOIDLength(ruleList.elementAt(t)
                                        .getChildNodes().item(3).getChildNodes().item(1).getChildNodes().item(1)
                                        .getChildNodes().item(1).getChildNodes().item(1).getTextContent()))) {

                                    if (!(subjectPersonelNewRule.length() > getOIDLength(
                                            ruleList.elementAt(t).getChildNodes().item(3).getChildNodes()
                                                    .item(1).getChildNodes().item(1).getChildNodes().item(3)
                                                    .getChildNodes().item(1).getTextContent()))) {

                                        if (t == ruleListLength - 1) {

                                            Node copy = policySet.importNode(rule.getDocumentElement(), true);

                                            policy.appendChild(copy);
                                        } else {

                                            Node copy = policySet.importNode(rule.getDocumentElement(), true);

                                            policy.insertBefore(copy, ruleList.elementAt(t + 1));
                                        }
                                        added = true;
                                        t = -1;

                                    } else {

                                        Node copy = policySet.importNode(rule.getDocumentElement(), true);
                                        policy.insertBefore(copy, ruleList.elementAt(t + 1));
                                        t = -1;
                                        added = true;
                                    }
                                }
                            } else {
                                Node copy = policySet.importNode(rule.getDocumentElement(), true);
                                policy.insertBefore(copy, ruleList.elementAt(t + 1));
                                t = -1;
                                added = true;
                            }
                        }
                        if (!added) {
                            Node copy = policySet.importNode(rule.getDocumentElement(), true);
                            policy.insertBefore(copy, ruleList.elementAt(0));
                            i = -1;
                        }
                    }
                }
                i = -1;
            } else if (getOIDLength(resourceRule) < getOIDLength(resourceNewRule) && i == 0) {

                Node copy = policySet.importNode(rule.getDocumentElement(), true);

                policy.insertBefore(copy, policy.getChildNodes().item(2));
                i = -1;
            }
            i--;
        }

    } else {
        Node copy = policySet.importNode(rule.getDocumentElement(), true);
        policy.appendChild(copy);
    }
    return policySet;
}

From source file:org.openehealth.coms.cc.web_frontend.consentcreator.service.DocumentFactory.java

/**
 * // www  . j a  v  a2 s.c om
 * Constructs a rule using the given data that represents an access rule.
 * 
 * @param organisation
 *            - String representing the full name of the organisation
 *            affected by this rule.
 * @param persons
 *            - The String representation of the persons affected by this
 *            rule.
 * @param affectedOID
 *            - The OID of the persons affected by this rule. If persons
 *            equals ALL then this is simply the OID of the organisation,
 *            else it is the OID of the group of persons affected, e.g.
 *            physicians.
 * @param documents
 *            - The String representation of the affected documents, can be
 *            ALL or a specific documenttype, e.g. lab results.
 * @param documentsOID
 *            - The OID of the affected documents, can either be the
 *            patients whole record or a a documenttype.
 * @param accessType
 *            - read, write or readwrite.
 * @param grantAccess
 *            - true if access is granted, else false.
 * @return
 */
public Document constructRule(String organisation, String persons, String affectedOID, String documents,
        String documentsOID, String accessType, boolean grantAccess) {

    Document rule = getRuleSkeleton();

    String ruleEffect = "";

    String description = "";

    String subjectMatchOrga = affectedOID.split("\\^")[0];

    String subjectMatchPersonel = "";

    if (affectedOID.contains("^")) {

        subjectMatchPersonel = affectedOID.split("\\^")[1];
    }

    String resourceMatch = "";

    String action = "";

    if (documentsOID.equalsIgnoreCase(allOID)) {
        documents = "ALL";
    }

    // Rules on organisation level covering all documents of a patient
    if (persons.equalsIgnoreCase("ALL") && !affectedOID.equalsIgnoreCase("")
            && documents.equalsIgnoreCase("ALL") && !documentsOID.equalsIgnoreCase("")
            && accessType.equalsIgnoreCase("write") && grantAccess) {

        ruleEffect = "Permit";

        description = "Die Organisation " + organisation + " darf alle meine Dokumente in ISIS einstellen.";

        resourceMatch = documentsOID;

        action = accessType;

    } else if (persons.equalsIgnoreCase("ALL") && !affectedOID.equalsIgnoreCase("")
            && documents.equalsIgnoreCase("ALL") && !documentsOID.equalsIgnoreCase("")
            && accessType.equalsIgnoreCase("write") && !grantAccess) {

        ruleEffect = "Deny";

        description = "Die Organisation " + organisation + " darf keine meiner Dokumente in ISIS einstellen.";

        resourceMatch = documentsOID;

        action = accessType;

    } else if (persons.equalsIgnoreCase("ALL") && !affectedOID.equalsIgnoreCase("")
            && documents.equalsIgnoreCase("ALL") && !documentsOID.equalsIgnoreCase("")
            && accessType.equalsIgnoreCase("read") && grantAccess) {

        ruleEffect = "Permit";

        description = "Die Organisation " + organisation + " darf alle meine Dokumente in ISIS lesen.";

        resourceMatch = documentsOID;

        action = accessType;

    } else if (persons.equalsIgnoreCase("ALL") && !affectedOID.equalsIgnoreCase("")
            && documents.equalsIgnoreCase("ALL") && !documentsOID.equalsIgnoreCase("")
            && accessType.equalsIgnoreCase("read") && !grantAccess) {

        ruleEffect = "Deny";

        description = "Die Organisation " + organisation + " darf keine meiner Dokumente in ISIS lesen.";

        resourceMatch = documentsOID;

        action = accessType;

    } else if (persons.equalsIgnoreCase("ALL") && !affectedOID.equalsIgnoreCase("")
            && documents.equalsIgnoreCase("ALL") && !documentsOID.equalsIgnoreCase("")
            && accessType.equalsIgnoreCase("readwrite") && grantAccess) {

        ruleEffect = "Permit";

        description = "Die Organisation " + organisation
                + " darf alle meine Dokumente in ISIS einstellen und alle in ISIS verfgbaren Dokumente lesen.";

        resourceMatch = documentsOID;

        action = accessType;

    } else if (persons.equalsIgnoreCase("ALL") && !affectedOID.equalsIgnoreCase("")
            && documents.equalsIgnoreCase("ALL") && !documentsOID.equalsIgnoreCase("")
            && accessType.equalsIgnoreCase("readwrite") && !grantAccess) {

        ruleEffect = "Deny";

        description = "Die Organisation " + organisation
                + " darf weder meine Dokumente in ISIS einstellen und noch in ISIS verfgbare Dokumente lesen.";

        resourceMatch = documentsOID;

        action = accessType;

    }
    // Rules on organisation level covering a specific documenttype.
    else if (persons.equalsIgnoreCase("ALL") && !affectedOID.equalsIgnoreCase("")
            && !documents.equalsIgnoreCase("ALL") && !documentsOID.equalsIgnoreCase("")
            && accessType.equalsIgnoreCase("read") && grantAccess) {

        ruleEffect = "Permit";

        description = "Die Organisation " + organisation + " darf meine, in ISIS verfgbaren, " + documents
                + " lesen.";

        resourceMatch = documentsOID;

        action = accessType;

    } else if (persons.equalsIgnoreCase("ALL") && !affectedOID.equalsIgnoreCase("")
            && !documents.equalsIgnoreCase("ALL") && !documentsOID.equalsIgnoreCase("")
            && accessType.equalsIgnoreCase("read") && !grantAccess) {

        ruleEffect = "Deny";

        description = "Die Organisation " + organisation + " darf meine, in ISIS verfgbaren, " + documents
                + " nicht lesen.";

        resourceMatch = documentsOID;

        action = accessType;

    } else if (persons.equalsIgnoreCase("ALL") && !affectedOID.equalsIgnoreCase("")
            && !documents.equalsIgnoreCase("ALL") && !documentsOID.equalsIgnoreCase("")
            && accessType.equalsIgnoreCase("write") && grantAccess) {

        ruleEffect = "Permit";

        description = "Die Organisation " + organisation + " darf meine " + documents + " in ISIS einstellen.";

        resourceMatch = documentsOID;

        action = accessType;

    } else if (persons.equalsIgnoreCase("ALL") && !affectedOID.equalsIgnoreCase("")
            && !documents.equalsIgnoreCase("ALL") && !documentsOID.equalsIgnoreCase("")
            && accessType.equalsIgnoreCase("write") && !grantAccess) {

        ruleEffect = "Deny";

        description = "Die Organisation " + organisation + " darf meine " + documents
                + " nicht in ISIS einstellen.";

        resourceMatch = documentsOID;

        action = accessType;

    } else if (persons.equalsIgnoreCase("ALL") && !affectedOID.equalsIgnoreCase("")
            && !documents.equalsIgnoreCase("ALL") && !documentsOID.equalsIgnoreCase("")
            && accessType.equalsIgnoreCase("readwrite") && grantAccess) {

        ruleEffect = "Permit";

        description = "Die Organisation " + organisation + " darf meine, in ISIS verfgbaren " + documents
                + " lesen und anfallende Dokumente diesen Types in ISIS einstellen.";

        resourceMatch = documentsOID;

        action = accessType;

    } else if (persons.equalsIgnoreCase("ALL") && !affectedOID.equalsIgnoreCase("")
            && !documents.equalsIgnoreCase("ALL") && !documentsOID.equalsIgnoreCase("")
            && accessType.equalsIgnoreCase("readwrite") && !grantAccess) {

        ruleEffect = "Deny";

        description = "Die Organisation " + organisation + " darf meine, in ISIS verfgbaren, " + documents
                + " weder lesen noch anfallende Dokumente diesen Types in ISIS einstellen.";

        resourceMatch = documentsOID;

        action = accessType;

    }
    // Rules on staff level covering all documents
    else if (!persons.equalsIgnoreCase("ALL") && !affectedOID.equalsIgnoreCase("")
            && documents.equalsIgnoreCase("ALL") && !documentsOID.equalsIgnoreCase("")
            && accessType.equalsIgnoreCase("read") && grantAccess) {

        ruleEffect = "Permit";

        description = "Alle " + persons + " der Organisation " + organisation
                + " drfen meine, in ISIS verfgbaren, Dokumente lesen.";

        resourceMatch = documentsOID;

        action = accessType;

    } else if (!persons.equalsIgnoreCase("ALL") && !affectedOID.equalsIgnoreCase("")
            && documents.equalsIgnoreCase("ALL") && !documentsOID.equalsIgnoreCase("")
            && accessType.equalsIgnoreCase("read") && !grantAccess) {

        ruleEffect = "Deny";

        description = "Alle " + persons + " der Organisation " + organisation
                + " drfen meine, in ISIS verfgbaren, Dokumente nicht lesen.";

        resourceMatch = documentsOID;

        action = accessType;

    }
    // Rules on staff level covering a specific documenttype.
    else if (!persons.equalsIgnoreCase("ALL") && !affectedOID.equalsIgnoreCase("")
            && !documents.equalsIgnoreCase("ALL") && !documentsOID.equalsIgnoreCase("")
            && accessType.equalsIgnoreCase("read") && grantAccess) {

        ruleEffect = "Permit";

        description = "Alle " + persons + " der Organisation " + organisation
                + " drfen alle meine, in ISIS verfgbaren, " + documents + " lesen.";

        resourceMatch = documentsOID;

        action = accessType;

    } else if (!persons.equalsIgnoreCase("ALL") && !affectedOID.equalsIgnoreCase("")
            && !documents.equalsIgnoreCase("ALL") && !documentsOID.equalsIgnoreCase("")
            && accessType.equalsIgnoreCase("read") && !grantAccess) {

        ruleEffect = "Deny";

        description = "Alle " + persons + " der Organisation " + organisation
                + " drfen alle meine, in ISIS verfgbaren, " + documents + " nicht lesen.";

        resourceMatch = documentsOID;

        action = accessType;

    } else {
        description = "Nicht untersttzte Anfrage";
    }

    // Setting up the rule skeleton
    rule.getDocumentElement().setAttribute("Effect", ruleEffect);

    rule.getElementsByTagName("Description").item(0).setTextContent(description);

    rule.getElementsByTagName("AttributeValue").item(0).setTextContent(subjectMatchOrga);

    rule.getElementsByTagName("AttributeValue").item(1).setTextContent(subjectMatchPersonel);

    rule.getElementsByTagName("AttributeValue").item(2).setTextContent(resourceMatch);

    Document readAction = null;
    Document writeAction = null;

    try {
        readAction = DocumentBuilderFactory.newInstance().newDocumentBuilder()
                .parse(new InputSource(new java.io.StringReader(
                        "<Action><ActionMatch MatchId=\"urn:oasis:names:tc:xacml:1.0:function:string-equal\"><AttributeValue DataType=\"http://www.w3.org/2001/XMLSchema#string\">read</AttributeValue><ActionAttributeDesignator AttributeId=\"urn:oasis:names:tc:xacml:1.0:action:action-id\" DataType=\"http://www.w3.org/2001/XMLSchema#string\"/></ActionMatch></Action>")));

        writeAction = DocumentBuilderFactory.newInstance().newDocumentBuilder()
                .parse(new InputSource(new java.io.StringReader(
                        "<Action><ActionMatch MatchId=\"urn:oasis:names:tc:xacml:1.0:function:string-equal\"><AttributeValue DataType=\"http://www.w3.org/2001/XMLSchema#string\">write</AttributeValue><ActionAttributeDesignator AttributeId=\"urn:oasis:names:tc:xacml:1.0:action:action-id\" DataType=\"http://www.w3.org/2001/XMLSchema#string\"/></ActionMatch></Action>")));

    } catch (Exception e) {
        Logger.getLogger(DocumentFactory.class).error(e.getMessage());
    }

    if (action.equalsIgnoreCase("readwrite")) {

        Node copy = rule.importNode(readAction.getDocumentElement(), true);
        rule.getElementsByTagName("Actions").item(0).appendChild(copy);

        Node copy2 = rule.importNode(writeAction.getDocumentElement(), true);
        rule.getElementsByTagName("Actions").item(0).appendChild(copy2);
    } else if (action.equalsIgnoreCase("read")) {

        Node copy = rule.importNode(readAction.getDocumentElement(), true);
        rule.getElementsByTagName("Actions").item(0).appendChild(copy);
    } else if (action.equalsIgnoreCase("write")) {

        Node copy2 = rule.importNode(writeAction.getDocumentElement(), true);
        rule.getElementsByTagName("Actions").item(0).appendChild(copy2);
    }
    rule.getElementsByTagName("Rule").item(0).getAttributes().item(1)
            .setTextContent(Long.toString(new Date().getTime()));

    return rule;
}

From source file:org.openehealth.coms.cc.web_frontend.consentcreator.service.DocumentFactory.java

/**
 * Checks whether or not the given Document contains a valid XML Signature
 * and if it has the exact same content as the original.
 * /*ww w  . j  a  v  a  2 s . co m*/
 * @param cdaFile
 * @param originalCDA
 * @return
 */
public boolean isXMLSignatureValid(Document cdaFile, Document originalCDA) {

    boolean coreValidity = false;

    try {

        DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
        DocumentBuilder db = dbf.newDocumentBuilder();

        Document checkCDA = db.newDocument();

        Node copy = checkCDA.importNode(cdaFile.getDocumentElement(), true);
        checkCDA.appendChild(copy);

        if (!isCDAoriginal(checkCDA, originalCDA)) {
            return false;
        }

        // Find Signature element
        NodeList nl = cdaFile.getElementsByTagNameNS(XMLSignature.XMLNS, "Signature");
        if (nl.getLength() == 0) {
            return false;
        }

        // Create a DOM XMLSignatureFactory that will be used to unmarshal
        // the
        // document containing the XMLSignature
        XMLSignatureFactory fac = XMLSignatureFactory.getInstance("DOM");

        // Create a DOMValidateContext and specify a KeyValue KeySelector
        // and document context
        DOMValidateContext valContext = new DOMValidateContext(new X509KeySelector(), nl.item(0));

        // unmarshal the XMLSignature
        XMLSignature signature = fac.unmarshalXMLSignature(valContext);

        // Validate the XMLSignature (generated above)
        coreValidity = signature.validate(valContext);

        // Check core validation status
        if (coreValidity) {
            return true;
        }
    } catch (Exception e) {
        Logger.getLogger(this.getClass()).error(e);
    }
    return coreValidity;
}

From source file:org.openengsb.openengsbplugin.base.ConfiguredMojo.java

private void importNodesFromNodeList(Document doc, Element parentElement, NodeList nodes) {
    for (int i = 0; i < nodes.getLength(); i++) {
        Node importedNode = doc.importNode(nodes.item(i), true);
        parentElement.appendChild(importedNode);
        LOG.trace(String.format("importing node (parent=%s): %s", parentElement.getLocalName(),
                importedNode.getNodeName()));
    }//from  w w  w .j  av  a  2  s  .  c o m
}

From source file:org.openengsb.openengsbplugin.base.ConfiguredMojo.java

private void insertConfigProfileIntoOrigPom(Document originalPom, Document mojoConfiguration,
        String profileName) throws XPathExpressionException {
    Node profileNode = mojoConfiguration.getFirstChild();

    Node idNode = mojoConfiguration.createElementNS(POM_NS_URI, "id");
    idNode.setTextContent(profileName);// w  w  w  . j a  v a2 s  .  c  o m
    profileNode.insertBefore(idNode, profileNode.getFirstChild());

    Node importedProfileNode = originalPom.importNode(profileNode, true);

    Tools.insertDomNode(originalPom, importedProfileNode, POM_PROFILE_XPATH, NS_CONTEXT);
}