Example usage for org.w3c.dom Attr getNodeValue

List of usage examples for org.w3c.dom Attr getNodeValue

Introduction

In this page you can find the example usage for org.w3c.dom Attr getNodeValue.

Prototype

public String getNodeValue() throws DOMException;

Source Link

Document

The value of this node, depending on its type; see the table above.

Usage

From source file:org.apache.xml.security.utils.resolver.implementations.ResolverFragment.java

/**
 * Method engineCanResolve//from   ww  w .  j  a va2s  .  co m
 * @inheritDoc
 * @param uri
 * @param baseURI
 */
public boolean engineCanResolve(Attr uri, String baseURI) {
    if (uri == null) {
        if (log.isDebugEnabled()) {
            log.debug("Quick fail for null uri");
        }
        return false;
    }

    String uriNodeValue = uri.getNodeValue();
    if (uriNodeValue.equals("") || ((uriNodeValue.charAt(0) == '#')
            && !((uriNodeValue.charAt(1) == 'x') && uriNodeValue.startsWith("#xpointer(")))) {
        if (log.isDebugEnabled()) {
            log.debug("State I can resolve reference: \"" + uriNodeValue + "\"");
        }
        return true;
    }
    if (log.isDebugEnabled()) {
        log.debug("Do not seem to be able to resolve reference: \"" + uriNodeValue + "\"");
    }
    return false;
}

From source file:org.apache.xml.security.utils.resolver.implementations.ResolverLocalFilesystem.java

/**
 * @inheritDoc/*from   w  w  w  .  j ava2s  . c  om*/
 */
public XMLSignatureInput engineResolve(Attr uri, String baseURI) throws ResourceResolverException {
    try {
        // calculate new URI
        URI uriNew = getNewURI(uri.getNodeValue(), baseURI);

        String fileName = ResolverLocalFilesystem.translateUriToFilename(uriNew.toString());
        FileInputStream inputStream = new FileInputStream(fileName);
        XMLSignatureInput result = new XMLSignatureInput(inputStream);

        result.setSourceURI(uriNew.toString());

        return result;
    } catch (Exception e) {
        throw new ResourceResolverException("generic.EmptyMessage", e, uri, baseURI);
    }
}

From source file:org.apache.xml.security.utils.resolver.implementations.ResolverLocalFilesystem.java

/**
 * @inheritDoc//from   ww  w . j  a v a  2  s  .  c o m
 */
public boolean engineCanResolve(Attr uri, String baseURI) {
    if (uri == null) {
        return false;
    }

    String uriNodeValue = uri.getNodeValue();

    if (uriNodeValue.equals("") || (uriNodeValue.charAt(0) == '#') || uriNodeValue.startsWith("http:")) {
        return false;
    }

    try {
        if (log.isDebugEnabled()) {
            log.debug("I was asked whether I can resolve " + uriNodeValue);
        }

        if (uriNodeValue.startsWith("file:") || baseURI.startsWith("file:")) {
            if (log.isDebugEnabled()) {
                log.debug("I state that I can resolve " + uriNodeValue);
            }
            return true;
        }
    } catch (Exception e) {
        if (log.isDebugEnabled()) {
            log.debug(e);
        }
    }

    if (log.isDebugEnabled()) {
        log.debug("But I can't");
    }

    return false;
}

From source file:org.apache.xml.security.utils.resolver.implementations.ResolverXPointer.java

/**
 * @inheritDoc/*from  w ww  .  j av  a 2  s.c  o  m*/
 */
public XMLSignatureInput engineResolve(Attr uri, String baseURI) throws ResourceResolverException {

    Node resultNode = null;
    Document doc = uri.getOwnerElement().getOwnerDocument();

    String uriStr = uri.getNodeValue();
    if (isXPointerSlash(uriStr)) {
        resultNode = doc;
    } else if (isXPointerId(uriStr)) {
        String id = getXPointerId(uriStr);
        resultNode = IdResolver.getElementById(doc, id);

        if (resultNode == null) {
            Object exArgs[] = { id };

            throw new ResourceResolverException("signature.Verification.MissingID", exArgs, uri, baseURI);
        }
    }

    XMLSignatureInput result = new XMLSignatureInput(resultNode);

    result.setMIMEType("text/xml");
    if (baseURI != null && baseURI.length() > 0) {
        result.setSourceURI(baseURI.concat(uri.getNodeValue()));
    } else {
        result.setSourceURI(uri.getNodeValue());
    }

    return result;
}

From source file:org.apache.xml.security.utils.resolver.implementations.ResolverXPointer.java

/**
 * @inheritDoc//from  w ww  .ja va2  s  .c om
 */
public boolean engineCanResolve(Attr uri, String baseURI) {
    if (uri == null) {
        return false;
    }
    String uriStr = uri.getNodeValue();
    if (isXPointerSlash(uriStr) || isXPointerId(uriStr)) {
        return true;
    }

    return false;
}

From source file:org.apache.xml.security.utils.resolver.ResourceResolver.java

/**
 * Method getInstance//from  ww w  . j a  va  2s  . c o m
 *
 * @param uri
 * @param baseURI
 * @return the instance
 *
 * @throws ResourceResolverException
 */
public static final ResourceResolver getInstance(Attr uri, String baseURI) throws ResourceResolverException {
    synchronized (resolverList) {
        for (ResourceResolver resolver : resolverList) {
            ResourceResolver resolverTmp = resolver;
            if (!resolver.resolverSpi.engineIsThreadSafe()) {
                try {
                    resolverTmp = new ResourceResolver(resolver.resolverSpi.getClass().newInstance());
                } catch (InstantiationException e) {
                    throw new ResourceResolverException("", e, uri, baseURI);
                } catch (IllegalAccessException e) {
                    throw new ResourceResolverException("", e, uri, baseURI);
                }
            }

            if (log.isDebugEnabled()) {
                log.debug("check resolvability by class " + resolverTmp.getClass().getName());
            }

            if ((resolverTmp != null) && resolverTmp.canResolve(uri, baseURI)) {
                return resolverTmp;
            }
        }
    }

    Object exArgs[] = { ((uri != null) ? uri.getNodeValue() : "null"), baseURI };

    throw new ResourceResolverException("utils.resolver.noClass", exArgs, uri, baseURI);
}

From source file:org.apache.xml.security.utils.XMLUtils.java

/**
 * This is the work horse for {@link #circumventBug2650}.
 *
 * @param node//w  w w.  j a  v  a 2s  .  co m
 * @see <A HREF="http://nagoya.apache.org/bugzilla/show_bug.cgi?id=2650">
 * Namespace axis resolution is not XPath compliant </A>
 */
private static void circumventBug2650internal(Node node) {
    Node parent = null;
    Node sibling = null;
    final String namespaceNs = Constants.NamespaceSpecNS;
    do {
        switch (node.getNodeType()) {
        case Node.ELEMENT_NODE:
            Element element = (Element) node;
            if (!element.hasChildNodes()) {
                break;
            }
            if (element.hasAttributes()) {
                NamedNodeMap attributes = element.getAttributes();
                int attributesLength = attributes.getLength();

                for (Node child = element.getFirstChild(); child != null; child = child.getNextSibling()) {

                    if (child.getNodeType() != Node.ELEMENT_NODE) {
                        continue;
                    }
                    Element childElement = (Element) child;

                    for (int i = 0; i < attributesLength; i++) {
                        Attr currentAttr = (Attr) attributes.item(i);
                        if (!namespaceNs.equals(currentAttr.getNamespaceURI()))
                            continue;
                        if (childElement.hasAttributeNS(namespaceNs, currentAttr.getLocalName())) {
                            continue;
                        }
                        childElement.setAttributeNS(namespaceNs, currentAttr.getName(),
                                currentAttr.getNodeValue());
                    }
                }
            }
        case Node.ENTITY_REFERENCE_NODE:
            parent = node;
            sibling = node.getFirstChild();
            break;
        case Node.DOCUMENT_NODE:
            parent = node;
            sibling = node.getFirstChild();
            break;
        }
        while ((sibling == null) && (parent != null)) {
            sibling = parent.getNextSibling();
            parent = parent.getParentNode();
        }
        if (sibling == null) {
            return;
        }

        node = sibling;
        sibling = node.getNextSibling();
    } while (true);
}

From source file:org.apereo.portal.layout.dlm.ParameterEditManager.java

/**
 * Attempt to apply a single channel parameter edit command and return true
 * if it succeeds or false otherwise. If the edit is disallowed or the
 * target element no longer exists in the document the edit command fails
 * and returns false./*from   w ww  .  j  ava  2  s  . c o m*/
 * @throws Exception
 */
private static boolean applyEdit(Element edit, Document ilf) {
    String nodeID = edit.getAttribute(Constants.ATT_TARGET);

    Element channel = ilf.getElementById(nodeID);

    if (channel == null)
        return false;

    // now get the name of the parameter to be edited and find that element
    String parmName = edit.getAttribute(Constants.ATT_NAME);
    String parmValue = edit.getAttribute(Constants.ATT_USER_VALUE);
    NodeList ilfParms = channel.getChildNodes();
    Element targetParm = null;

    for (int i = 0; i < ilfParms.getLength(); i++) {
        Element ilfParm = (Element) ilfParms.item(i);
        if (ilfParm.getAttribute(Constants.ATT_NAME).equals(parmName)) {
            targetParm = ilfParm;
            break;
        }
    }
    if (targetParm == null) // parameter not found so we are free to set
    {
        Element parameter = ilf.createElement("parameter");
        parameter.setAttribute("name", parmName);
        parameter.setAttribute("value", parmValue);
        parameter.setAttribute("override", "yes");
        channel.appendChild(parameter);
        return true;
    }
    /* TODO Add support for fragments to set dlm:editAllowed attribute for
     * channel parameters. (2005.11.04 mboyd)
     * 
     * In the commented code below, the check for editAllowed will never be 
     * seen on a parameter element in the 
     * current database schema approach used by DLM. This is because 
     * parameters are second class citizens of the layout structure. They
     * are not found in the up_layout_struct table but only in the 
     * up_layout_param table. DLM functionality like dlm:editAllowed,
     * dlm:moveAllowed, dlm:deleteAllowed, and dlm:addChildAllowed were 
     * implemented without schema changes by adding these as parameters to
     * structural elements and upon loading any parameter that begins with
     * 'dlm:' is placed as an attribute on the containing structural 
     * element. So any channel parameter entry with dlm:editAllowed has that
     * value placed as an attribute on the containing channel not on the 
     * parameter that was meant to have it.
     * 
     * The only solution would be to add special dlm:parm children below
     * channels that would get the editAllowed value and then when creating
     * the DOM don't create those as child elements but use them to set the
     * attribute on the corresponding parameter by having the name of the
     * dlm:parm element be the name of the parameter to which it is to be 
     * related.
     * 
     * The result of this lack of functionality is that fragments can't 
     * mark any channel parameters as dlm:editAllowed='false' thereby
     * further restricting which channel parameters can be edited beyond 
     * what the channel definition specifies during publishing.  
     */
    //Attr editAllowed = targetParm.getAttributeNode( Constants.ATT_EDIT_ALLOWED );
    //if ( editAllowed != null && editAllowed.getNodeValue().equals("false"))
    //    return false;

    // target parm found. See if channel definition will still allow changes.

    Attr override = targetParm.getAttributeNode(Constants.ATT_OVERRIDE);
    if (override != null && !override.getNodeValue().equals(Constants.CAN_OVERRIDE))
        return false;

    // now see if the change is still needed
    if (targetParm.getAttribute(Constants.ATT_VALUE).equals(parmValue))
        return false; // user's edit same as fragment or chan def

    targetParm.setAttribute("value", parmValue);
    return true;
}

From source file:org.bibsonomy.recommender.tags.simple.MetaInfoTagRecommender.java

/**
 * Parses html file at given url and returns keywords from its meta informations.
 * @param url file's url//from   w w  w.j a  va  2s .  c om
 * @return keywords as given in html file if present, empty string otherwise.
 */
private String getKeywordsForUrl(String url) {
    String keywordsStr = "";
    try {
        final Document document = XmlUtils.getDOM(new URL(url));

        final NodeList metaList = document.getElementsByTagName("meta");
        for (int i = 0; i < metaList.getLength(); i++) {
            final Element metaElement = (Element) metaList.item(i);

            Attr nameAttr = metaElement.getAttributeNode("name");
            if ((nameAttr != null) && (nameAttr.getNodeValue().equalsIgnoreCase("keywords"))) {
                keywordsStr += metaElement.getAttribute("content");
                log.debug("KEYWORDS for URL " + url.toString() + ":" + keywordsStr);
            }
        }
    } catch (IOException ex) {
        // ignore exceptions silently
    }
    return keywordsStr;
}

From source file:org.dita.dost.module.BranchFilterModule.java

private boolean isDitaFormat(final Attr formatAttr) {
    return formatAttr == null || ATTR_FORMAT_VALUE_DITA.equals(formatAttr.getNodeValue())
            || ATTR_FORMAT_VALUE_DITAMAP.equals(formatAttr.getNodeValue());
}