Example usage for org.w3c.dom Element setTextContent

List of usage examples for org.w3c.dom Element setTextContent

Introduction

In this page you can find the example usage for org.w3c.dom Element setTextContent.

Prototype

public void setTextContent(String textContent) throws DOMException;

Source Link

Document

This attribute returns the text content of this node and its descendants.

Usage

From source file:org.apache.axis2.description.AxisService.java

private void setPortAddress(Definition definition, String requestIP) throws AxisFault {
    Iterator serviceItr = definition.getServices().values().iterator();
    while (serviceItr.hasNext()) {
        Service serviceElement = (Service) serviceItr.next();
        Iterator portItr = serviceElement.getPorts().values().iterator();
        while (portItr.hasNext()) {
            Port port = (Port) portItr.next();
            AxisEndpoint endpoint = getAxisEndpoint(port.getName());
            List list = port.getExtensibilityElements();
            for (int i = 0; i < list.size(); i++) {
                Object extensibilityEle = list.get(i);
                if (extensibilityEle instanceof SOAPAddress) {
                    SOAPAddress soapAddress = (SOAPAddress) extensibilityEle;
                    String existingAddress = soapAddress.getLocationURI();
                    if (existingAddress == null || existingAddress.equals("REPLACE_WITH_ACTUAL_URL")) {
                        if (endpoint != null) {
                            ((SOAPAddress) extensibilityEle)
                                    .setLocationURI(endpoint.calculateEndpointURL(requestIP));
                        } else {
                            ((SOAPAddress) extensibilityEle).setLocationURI(getEPRs()[0]);
                        }/*  w ww  . ja va2s  .  c o m*/
                    } else {
                        if (requestIP == null) {
                            if (endpoint != null) {
                                ((SOAPAddress) extensibilityEle)
                                        .setLocationURI(endpoint.calculateEndpointURL());
                            } else {
                                ((SOAPAddress) extensibilityEle)
                                        .setLocationURI(getLocationURI(getEPRs(), existingAddress));
                            }
                        } else {
                            if (endpoint != null) {
                                ((SOAPAddress) extensibilityEle)
                                        .setLocationURI(endpoint.calculateEndpointURL(requestIP));
                            } else {
                                ((SOAPAddress) extensibilityEle).setLocationURI(
                                        getLocationURI(calculateEPRs(requestIP), existingAddress));
                            }
                        }
                    }
                } else if (extensibilityEle instanceof SOAP12Address) {
                    SOAP12Address soapAddress = (SOAP12Address) extensibilityEle;
                    String exsistingAddress = soapAddress.getLocationURI();
                    if (requestIP == null) {
                        if (endpoint != null) {
                            ((SOAP12Address) extensibilityEle).setLocationURI(endpoint.calculateEndpointURL());

                        } else {
                            ((SOAP12Address) extensibilityEle)
                                    .setLocationURI(getLocationURI(getEPRs(), exsistingAddress));
                        }
                    } else {
                        if (endpoint != null) {
                            ((SOAP12Address) extensibilityEle)
                                    .setLocationURI(endpoint.calculateEndpointURL(requestIP));
                        } else {
                            ((SOAP12Address) extensibilityEle)
                                    .setLocationURI(getLocationURI(calculateEPRs(requestIP), exsistingAddress));

                        }
                    }
                } else if (extensibilityEle instanceof HTTPAddress) {
                    HTTPAddress httpAddress = (HTTPAddress) extensibilityEle;
                    String exsistingAddress = httpAddress.getLocationURI();
                    if (requestIP == null) {
                        if (endpoint != null) {
                            ((HTTPAddress) extensibilityEle).setLocationURI(endpoint.calculateEndpointURL());
                        } else {
                            ((HTTPAddress) extensibilityEle)
                                    .setLocationURI(getLocationURI(getEPRs(), exsistingAddress));
                        }
                    } else {
                        if (endpoint != null) {
                            ((HTTPAddress) extensibilityEle)
                                    .setLocationURI(endpoint.calculateEndpointURL(requestIP));
                        } else {
                            ((HTTPAddress) extensibilityEle)
                                    .setLocationURI(getLocationURI(calculateEPRs(requestIP), exsistingAddress));
                        }
                    }
                } else if (extensibilityEle instanceof UnknownExtensibilityElement) {
                    UnknownExtensibilityElement unknownExtensibilityElement = (UnknownExtensibilityElement) extensibilityEle;
                    Element element = unknownExtensibilityElement.getElement();
                    if (AddressingConstants.ENDPOINT_REFERENCE.equals(element.getLocalName())) {
                        NodeList nodeList = element.getChildNodes();
                        Node node = null;
                        Element currentElement = null;
                        for (int j = 0; j < nodeList.getLength(); j++) {
                            node = nodeList.item(j);
                            if (node instanceof Element) {
                                currentElement = (Element) node;
                                if (AddressingConstants.EPR_ADDRESS.equals(currentElement.getLocalName())) {
                                    String exsistingAddress = currentElement.getTextContent();
                                    if (requestIP == null) {
                                        if (endpoint != null) {
                                            currentElement.setTextContent(endpoint.calculateEndpointURL());
                                        } else {
                                            currentElement.setTextContent(
                                                    getLocationURI(getEPRs(), exsistingAddress));
                                        }
                                    } else {
                                        if (endpoint != null) {
                                            currentElement
                                                    .setTextContent(endpoint.calculateEndpointURL(requestIP));
                                        } else {
                                            currentElement.setTextContent(
                                                    getLocationURI(calculateEPRs(requestIP), exsistingAddress));
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}

From source file:org.apache.camel.component.xmlsecurity.api.XAdESSignatureProperties.java

protected void addCommitmentTypeIndication(Element signedDataObjectProperties, Document doc, Input input)
        throws SAXException, IOException, ParserConfigurationException, XmlSignatureException {
    if (!isAddCommitmentType()) {
        return;//from www  .ja v  a  2s.c  o  m
    }
    Element commitmentTypeIndication = createElement("CommitmentTypeIndication", doc, input);
    signedDataObjectProperties.appendChild(commitmentTypeIndication);
    Element commitmentTypeIdEl = createElement("CommitmentTypeId", doc, input);
    commitmentTypeIndication.appendChild(commitmentTypeIdEl);
    Element identifier = createElement("Identifier", doc, input);
    commitmentTypeIdEl.appendChild(identifier);
    identifier.setTextContent(getCommitmentTypeId());
    if (getCommitmentTypeIdQualifier() != null && !getCommitmentTypeIdQualifier().isEmpty()) {
        setAttribute(identifier, "Qualifier", getCommitmentTypeIdQualifier());
    }
    if (getCommitmentTypeIdDescription() != null && !getCommitmentTypeIdDescription().isEmpty()) {
        Element description = createElement("Description", doc, input);
        commitmentTypeIdEl.appendChild(description);
        description.setTextContent(getCommitmentTypeIdDescription());
    }
    if (!getCommitmentTypeIdDocumentationReferences().isEmpty()) {
        Element documentationReferences = createElement("DocumentationReferences", doc, input);
        commitmentTypeIdEl.appendChild(documentationReferences);
        List<String> docReferences = getCommitmentTypeIdDocumentationReferences();
        for (String documentationReferenceValue : docReferences) {
            Element documentationReference = createElement("DocumentationReference", doc, input);
            documentationReferences.appendChild(documentationReference);
            documentationReference.setTextContent(documentationReferenceValue);
        }
    }
    Element allSignedDataObjects = createElement("AllSignedDataObjects", doc, input);
    commitmentTypeIndication.appendChild(allSignedDataObjects);

    List<String> qualifiers = getCommitmentTypeQualifiers();
    if (!qualifiers.isEmpty()) {
        Element qualifiersEl = createElement("CommitmentTypeQualifiers", doc, input);
        commitmentTypeIndication.appendChild(qualifiersEl);
        String errorMessage = "The XAdES confguration is invalid. The list of the commitment type qualifiers contains the invalid entry '%s'. An entry must either be a text or an XML fragment "
                + "with the root element '%s' with the namespace '%s'.";
        for (String qualifier : getCommitmentTypeQualifiers()) {
            Element qualifierEl = createChildFromXmlFragmentOrText(doc, input, "CommitmentTypeQualifier",
                    errorMessage, qualifier);
            qualifiersEl.appendChild(qualifierEl);
        }
    }
}

From source file:org.apache.camel.component.xmlsecurity.api.XAdESSignatureProperties.java

protected String addDataObjectFormat(Element signedDataObjectProperties, Document doc, Input input)
        throws XmlSignatureException {
    if (!isAddDataObjectFormat()) {
        return null;
    }/*from w  w w  .j  a  v a  2s  .  c om*/
    Element dataObjectFormat = createElement("DataObjectFormat", doc, input);
    signedDataObjectProperties.appendChild(dataObjectFormat);
    String contentReferenceId = "_" + UUID.randomUUID().toString();
    setAttribute(dataObjectFormat, "ObjectReference", contentReferenceId);

    if (getDataObjectFormatDescription() != null && !getDataObjectFormatDescription().isEmpty()) {
        Element description = createElement("Description", doc, input);
        dataObjectFormat.appendChild(description);
        description.setTextContent(getDataObjectFormatDescription());
    }
    if (getDataObjectFormatIdentifier() != null && !getDataObjectFormatIdentifier().isEmpty()) {
        Element objectIdentifier = createElement("ObjectIdentifier", doc, input);
        dataObjectFormat.appendChild(objectIdentifier);
        Element identifier = createElement("Identifier", doc, input);
        objectIdentifier.appendChild(identifier);

        identifier.setTextContent(getDataObjectFormatIdentifier());
        if (getDataObjectFormatIdentifierQualifier() != null
                && !getDataObjectFormatIdentifierQualifier().isEmpty()) {
            setAttribute(identifier, "Qualifier", getDataObjectFormatIdentifierQualifier());
        }
        if (getDataObjectFormatIdentifierDescription() != null
                && !getDataObjectFormatIdentifierDescription().isEmpty()) {
            Element description = createElement("Description", doc, input);
            objectIdentifier.appendChild(description);
            description.setTextContent(getDataObjectFormatIdentifierDescription());
        }
        if (!getDataObjectFormatIdentifierDocumentationReferences().isEmpty()) {
            Element documentationReferences = createElement("DocumentationReferences", doc, input);
            objectIdentifier.appendChild(documentationReferences);
            List<String> docReferences = getDataObjectFormatIdentifierDocumentationReferences();
            for (String documentationReferenceValue : docReferences) {
                Element documentationReference = createElement("DocumentationReference", doc, input);
                documentationReferences.appendChild(documentationReference);
                documentationReference.setTextContent(documentationReferenceValue);
            }
        }

    }
    if (getDataObjectFormatMimeType() != null && !getDataObjectFormatMimeType().isEmpty()) {
        Element mimeType = createElement("MimeType", doc, input);
        dataObjectFormat.appendChild(mimeType);
        mimeType.setTextContent(getDataObjectFormatMimeType());
    }
    String encoding = input.getMessage()
            .getHeader(XmlSignatureConstants.HEADER_XADES_DATA_OBJECT_FORMAT_ENCODING, String.class);
    if (encoding != null && !encoding.isEmpty()) {
        Element encodingEl = createElement("Encoding", doc, input);
        dataObjectFormat.appendChild(encodingEl);
        encodingEl.setTextContent(encoding);
    }
    return contentReferenceId;
}

From source file:org.apache.camel.component.xmlsecurity.api.XAdESSignatureProperties.java

protected void addSignatureProductionPlace(Document doc, Element signedSignatureProperties, Input input) {
    if (!isAddSignatureProductionPlace()) {
        return;/*from w  w w  .j a  v a 2  s  .c o  m*/
    }
    Element signatureProductionPlace = createElement("SignatureProductionPlace", doc, input);
    signedSignatureProperties.appendChild(signatureProductionPlace);
    if (getSignatureProductionPlaceCity() != null && !getSignatureProductionPlaceCity().isEmpty()) {
        LOG.debug("Adding production city");
        Element city = createElement("City", doc, input);
        signatureProductionPlace.appendChild(city);
        city.setTextContent(getSignatureProductionPlaceCity());
    }
    if (getSignatureProductionPlaceStateOrProvince() != null
            && !getSignatureProductionPlaceStateOrProvince().isEmpty()) {
        LOG.debug("Adding production state or province");
        Element stateOrProvince = createElement("StateOrProvince", doc, input);
        signatureProductionPlace.appendChild(stateOrProvince);
        stateOrProvince.setTextContent(getSignatureProductionPlaceStateOrProvince());
    }
    if (getSignatureProductionPlacePostalCode() != null && !getSignatureProductionPlacePostalCode().isEmpty()) {
        LOG.debug("Adding production postal code");
        Element postalCode = createElement("PostalCode", doc, input);
        signatureProductionPlace.appendChild(postalCode);
        postalCode.setTextContent(getSignatureProductionPlacePostalCode());
    }
    if (getSignatureProductionPlaceCountryName() != null
            && !getSignatureProductionPlaceCountryName().isEmpty()) {
        LOG.debug("Adding production country name");
        Element countryName = createElement("CountryName", doc, input);
        signatureProductionPlace.appendChild(countryName);
        countryName.setTextContent(getSignatureProductionPlaceCountryName());
    }
}

From source file:org.apache.camel.component.xmlsecurity.api.XAdESSignatureProperties.java

protected void addSignerRole(Document doc, Element signedSignatureProperties, Input input)
        throws XmlSignatureException, SAXException, IOException, ParserConfigurationException {
    if (!isAddSignerRole()) {
        return;/*  w  w  w. j a va 2s . c  o m*/
    }
    Element signerRole = createElement("SignerRole", doc, input);
    signedSignatureProperties.appendChild(signerRole);
    List<String> claimedRoles = getSignerClaimedRoles();
    if (!claimedRoles.isEmpty()) {
        LOG.debug("Adding claimed roles");
        Element claimedRolesEl = createElement("ClaimedRoles", doc, input);
        signerRole.appendChild(claimedRolesEl);
        String errorMessage = "The XAdES confguration is invalid. The list of the claimed roles contains the invalid entry '%s'."
                + " An entry must either be a text or an XML fragment with the root element '%s' with the namespace '%s'.";
        for (String claimedRole : claimedRoles) {
            Element claimedRoleEl = createChildFromXmlFragmentOrText(doc, input, "ClaimedRole", errorMessage,
                    claimedRole);
            claimedRolesEl.appendChild(claimedRoleEl);
        }
    }
    List<XAdESEncapsulatedPKIData> certifiedRoles = getSignerCertifiedRoles();
    if (!certifiedRoles.isEmpty()) {
        LOG.debug("Adding certified roles");
        Element certifiedRolesEl = createElement("CertifiedRoles", doc, input);
        signerRole.appendChild(certifiedRolesEl);
        for (XAdESEncapsulatedPKIData certifiedRole : certifiedRoles) {
            Element certifiedRoleEl = createElement("CertifiedRole", doc, input);
            certifiedRolesEl.appendChild(certifiedRoleEl);
            certifiedRoleEl.setTextContent(certifiedRole.getBase64Conent());
            if (certifiedRole.getEncoding() != null && !certifiedRole.getEncoding().isEmpty()) {
                setAttribute(certifiedRoleEl, "Encoding", certifiedRole.getEncoding());
            }
            if (certifiedRole.getId() != null && !certifiedRole.getId().isEmpty()) {
                setAttribute(certifiedRoleEl, "Id", certifiedRole.getId());
                certifiedRoleEl.setIdAttribute("Id", true);
            }
        }
    }

}

From source file:org.apache.camel.component.xmlsecurity.api.XAdESSignatureProperties.java

protected void addSignaturePolicyIdentifier(Document doc, Element signedProperties, Input input)
        throws XmlSignatureException, SAXException, IOException, ParserConfigurationException {
    if (!isAddSignaturePolicy()) {
        return;/*from   w  w  w. j a  v a  2  s .co m*/
    }
    Element signaturePolicyIdentifier = createElement("SignaturePolicyIdentifier", doc, input);
    signedProperties.appendChild(signaturePolicyIdentifier);
    if (SIG_POLICY_IMPLIED.equals(getSignaturePolicy())) {
        LOG.debug("Adding implied signature policy");
        Element implied = createElement("SignaturePolicyImplied", doc, input);
        signaturePolicyIdentifier.appendChild(implied);
    } else if (SIG_POLICY_EXPLICIT_ID.equals(getSignaturePolicy())) {
        LOG.debug("Adding signatue policy ID");
        Element id = createElement("SignaturePolicyId", doc, input);
        signaturePolicyIdentifier.appendChild(id);
        Element sigPolicyId = createElement("SigPolicyId", doc, input);
        id.appendChild(sigPolicyId);
        Element identifier = createElement("Identifier", doc, input);
        sigPolicyId.appendChild(identifier);
        if (getSigPolicyId() == null || getSigPolicyId().isEmpty()) {
            throw new XmlSignatureException(
                    "The XAdES-EPES confguration is invalid. The signature policy identifier is missing.");
        }
        identifier.setTextContent(getSigPolicyId());
        if (getSigPolicyIdQualifier() != null && !getSigPolicyIdQualifier().isEmpty()) {
            setAttribute(identifier, "Qualifier", getSigPolicyIdQualifier());
        }
        if (getSigPolicyIdDescription() != null && !getSigPolicyIdDescription().isEmpty()) {
            Element description = createElement("Description", doc, input);
            sigPolicyId.appendChild(description);
            description.setTextContent(getSigPolicyIdDescription());
        }
        if (!getSigPolicyIdDocumentationReferences().isEmpty()) {
            Element documentationReferences = createElement("DocumentationReferences", doc, input);
            sigPolicyId.appendChild(documentationReferences);
            List<String> docReferences = getSigPolicyIdDocumentationReferences();
            for (String documentationReferenceValue : docReferences) {
                Element documentationReference = createElement("DocumentationReference", doc, input);
                documentationReferences.appendChild(documentationReference);
                documentationReference.setTextContent(documentationReferenceValue);
            }
        }
        //here we could introduce the transformations for the signature policy, which we do not yet support
        Element sigPolicyHash = createElement("SigPolicyHash", doc, input);
        id.appendChild(sigPolicyHash);
        if (getSignaturePolicyDigestAlgorithm() == null || getSignaturePolicyDigestAlgorithm().isEmpty()) {
            throw new XmlSignatureException(
                    "The XAdES-EPES confguration is invalid. The digest algorithm for the signature policy is missing.");
        }
        Element digestMethod = createDigSigElement("DigestMethod", doc,
                input.getPrefixForXmlSignatureNamespace());
        sigPolicyHash.appendChild(digestMethod);
        setAttribute(digestMethod, "Algorithm", getSignaturePolicyDigestAlgorithm());
        if (getSignaturePolicyDigestValue() == null || getSignaturePolicyDigestValue().isEmpty()) {
            throw new XmlSignatureException(
                    "The XAdES-EPES confguration is invalid. The digest value for the signature policy is missing.");
        }
        Element digestValue = createDigSigElement("DigestValue", doc,
                input.getPrefixForXmlSignatureNamespace());
        sigPolicyHash.appendChild(digestValue);
        digestValue.setTextContent(getSignaturePolicyDigestValue());

        List<String> qualifiers = getSigPolicyQualifiers();
        if (!qualifiers.isEmpty()) {
            Element qualifiersEl = createElement("SigPolicyQualifiers", doc, input);
            id.appendChild(qualifiersEl);
            String errorMessage = "The XAdES confguration is invalid. The list of the signatue policy qualifiers contains the invalid entry '%s'."
                    + " An entry must either be a text or an XML fragment with the root element '%s' with the namespace '%s'.";
            for (String elementOrText : getSigPolicyQualifiers()) {
                Element child = createChildFromXmlFragmentOrText(doc, input, "SigPolicyQualifier", errorMessage,
                        elementOrText);
                qualifiersEl.appendChild(child);
            }
        }
    } else {
        // cannot happen
        throw new IllegalStateException(String.format(
                "Invalid value '%s' for parameter 'SignaturePolicy'. Possible values are: 'None', 'Implied', and 'ExplictId'.",
                getSignaturePolicy()));
    }

}

From source file:org.apache.camel.component.xmlsecurity.api.XAdESSignatureProperties.java

protected Element createChildFromXmlFragmentOrText(Document doc, Input input, String localElementName,
        String errorMessage, String elementOrText)
        throws IOException, ParserConfigurationException, XmlSignatureException {
    String ending = localElementName + ">";
    Element child;
    if (elementOrText.startsWith("<") && elementOrText.endsWith(ending)) {
        try {/*from   w ww .  ja va 2 s  . co m*/
            // assume xml
            InputSource source = new InputSource(new StringReader(elementOrText));
            source.setEncoding("UTF-8");
            Document parsedDoc = XmlSignatureHelper.newDocumentBuilder(Boolean.TRUE).parse(source);
            replacePrefixes(parsedDoc, input);
            child = (Element) doc.adoptNode(parsedDoc.getDocumentElement());
            // check for correct namespace
            String ns = findNamespace(input.getMessage());
            if (!ns.equals(child.getNamespaceURI())) {
                throw new XmlSignatureException(String.format(
                        "The XAdES confguration is invalid. The root element '%s' of the provided XML fragment '%s' has the invalid namespace '%s'. The correct namespace is '%s'.",
                        child.getLocalName(), elementOrText, child.getNamespaceURI(), ns));
            }
        } catch (SAXException e) {
            throw new XmlSignatureException(
                    String.format(errorMessage, elementOrText, localElementName, namespace), e);
        }
    } else {
        child = createElement(localElementName, doc, input);
        child.setTextContent(elementOrText);
    }
    return child;
}

From source file:org.apache.camel.component.xmlsecurity.api.XAdESSignatureProperties.java

protected void addSigningTime(Document doc, Element signedProperties, Input input) {
    if (isAddSigningTime()) {
        LOG.debug("Adding signing time");
        //signing time
        Element signingTime = createElement("SigningTime", doc, input);
        signedProperties.appendChild(signingTime);
        Date current = new Date();
        signingTime.setTextContent(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssXXX").format(current));
    }/*  ww w .j  a  v  a 2s . c  om*/
}

From source file:org.apache.camel.component.xmlsecurity.api.XAdESSignatureProperties.java

protected void addCertificate(X509Certificate cert, Element signedCertificate, Document doc, int index,
        Input input) throws CertificateEncodingException, NoSuchAlgorithmException, XmlSignatureException {
    Element elCert = createElement("Cert", doc, input);
    signedCertificate.appendChild(elCert);

    String algorithm = getMessageDigestAlgorithm(getDigestAlgorithmForSigningCertificate(),
            "The digest algorithm '%s' for the signing certificate is invalid");
    String digest = calculateDigest(algorithm, cert.getEncoded());
    Element certDigest = createElement("CertDigest", doc, input);
    elCert.appendChild(certDigest);/*from w  w w  .  j a  va 2s  .  c  o m*/
    Element digestMethod = createDigSigElement("DigestMethod", doc, input.getPrefixForXmlSignatureNamespace());
    certDigest.appendChild(digestMethod);
    setAttribute(digestMethod, "Algorithm", getDigestAlgorithmForSigningCertificate());
    Element digestValue = createDigSigElement("DigestValue", doc, input.getPrefixForXmlSignatureNamespace());
    certDigest.appendChild(digestValue);
    digestValue.setTextContent(digest);

    Element issuerSerial = createElement("IssuerSerial", doc, input);
    elCert.appendChild(issuerSerial);
    Element x509IssuerName = createDigSigElement("X509IssuerName", doc,
            input.getPrefixForXmlSignatureNamespace());
    issuerSerial.appendChild(x509IssuerName);
    x509IssuerName.setTextContent(cert.getIssuerX500Principal().getName(X500Principal.RFC2253));
    Element x509SerialNumber = createDigSigElement("X509SerialNumber", doc,
            input.getPrefixForXmlSignatureNamespace());
    issuerSerial.appendChild(x509SerialNumber);
    x509SerialNumber.setTextContent(cert.getSerialNumber().toString());

    List<String> uris = getSigningCertificateURIs();
    if (!uris.isEmpty() && uris.size() > index) {
        String uri = uris.get(index);
        if (uri != null && !uri.isEmpty()) {
            setAttribute(elCert, "URI", uri);
        }
    }
}

From source file:org.apache.hadoop.gateway.filter.rewrite.impl.xml.XmlFilterReader.java

private void processBufferedElement(Level level, UrlRewriteFilterGroupDescriptor config)
        throws XPathExpressionException {
    for (UrlRewriteFilterPathDescriptor selector : config.getSelectors()) {
        if (selector instanceof UrlRewriteFilterApplyDescriptor) {
            XPathExpression path = (XPathExpression) selector.compiledPath(XPATH_COMPILER);
            Object node = path.evaluate(level.scopeNode, XPathConstants.NODE);
            if (node != null) {
                UrlRewriteFilterApplyDescriptor apply = (UrlRewriteFilterApplyDescriptor) selector;
                if (node instanceof Element) {
                    Element element = (Element) node;
                    String value = element.getTextContent();
                    value = filterText(extractQName(element), value, apply.rule());
                    element.setTextContent(value);
                } else if (node instanceof Text) {
                    Text text = (Text) node;
                    String value = text.getWholeText();
                    value = filterText(extractQName(text.getParentNode()), value, apply.rule());
                    text.replaceWholeText(value);
                } else if (node instanceof Attr) {
                    Attr attr = (Attr) node;
                    String value = attr.getValue();
                    value = filterAttribute(extractQName(attr.getOwnerElement()), extractQName(attr), value,
                            apply.rule());
                    attr.setValue(value);
                } else {
                    throw new IllegalArgumentException(RES.unexpectedSelectedNodeType(node));
                }/*from  w  ww  .j a  va2  s.c  o m*/
            }
        } else if (selector instanceof UrlRewriteFilterDetectDescriptor) {
            XPathExpression path = (XPathExpression) selector.compiledPath(XPATH_COMPILER);
            Object node = path.evaluate(level.scopeNode, XPathConstants.NODE);
            if (node != null) {
                UrlRewriteFilterDetectDescriptor detect = (UrlRewriteFilterDetectDescriptor) selector;
                String value = null;
                if (node instanceof Element) {
                    Element element = (Element) node;
                    value = element.getTextContent();
                } else if (node instanceof Text) {
                    Text text = (Text) node;
                    value = text.getWholeText();
                } else if (node instanceof Attr) {
                    Attr attr = (Attr) node;
                    value = attr.getValue();
                } else {
                    throw new IllegalArgumentException(RES.unexpectedSelectedNodeType(node));
                }
                if (detect.compiledValue(REGEX_COMPILER).matcher(value).matches()) {
                    processBufferedElement(level, detect);
                }
            }
        } else {
            throw new IllegalArgumentException(RES.unexpectedRewritePathSelector(selector));
        }
    }
}