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:ucar.unidata.idv.ui.ImageGenerator.java

/**
 * process the given node/*w w  w . j ava 2s.c om*/
 *
 * @param node Node to process
 *
 * @return keep going
 *
 * @throws Throwable On badness
 */
protected boolean processTagForeach(Element node) throws Throwable {
    pushProperties();
    List allValues = new ArrayList();
    int numElements = 0;
    int cnt = 1;
    NamedNodeMap attrs = node.getAttributes();
    if (attrs == null) {
        return error("No values in foreach tag");
    }

    for (int i = 0; i < attrs.getLength(); i++) {
        Attr attr = (Attr) attrs.item(i);
        String var = attr.getNodeName();
        String values = applyMacros(attr.getNodeValue());
        List tokens;
        //Check if it starts with file:, if so read the contents and split on new line
        if (values.startsWith("file:")) {
            String filename = applyMacros(values.substring("file:".length()));
            values = IOUtil.readContents(filename, getClass()).trim();
            tokens = StringUtil.split(values, "\n");
        } else {
            tokens = StringUtil.split(values, ",");
        }

        if (allValues.size() == 0) {
            numElements = tokens.size();
        } else if (numElements != tokens.size()) {
            return error("Bad number of tokens (" + tokens.size() + " should be:" + numElements
                    + ") in foreach argument:\n" + var + "=" + tokens);
        }
        allValues.add(new Object[] { var, tokens });
        cnt++;
    }
    for (int tokIdx = 0; tokIdx < numElements; tokIdx++) {
        for (int valueIdx = 0; valueIdx < allValues.size(); valueIdx++) {
            Object[] tuple = (Object[]) allValues.get(valueIdx);
            putProperty(tuple[0], ((List) tuple[1]).get(tokIdx));
        }
        try {
            if (!processChildren(node)) {
                return false;
            }
        } catch (MyBreakException be) {
            break;
        } catch (MyContinueException ce) {
        }
    }
    popProperties();
    return true;
}

From source file:us.derfers.tribex.rapids.Loader.java

/**
 * Starts loading the GUI. Sets Swing look and feel, then loads the GUI using the GUI_Swing object.
 * @param escapedFile The content .rsm file to load UI elements from.
 * @param parent The (optional) parent Object, Eg, a JFrame or JPanel.
 * @param engine The JavaScript engine to pass to GUI_Swing
 *///from   www .  j a  v  a  2  s . c  om
public void loadAll(String escapedFile) {

    //Attempt to load .rsm file filePath
    try {

        //Parse filePath
        Document doc = Utilities.XMLStringToDocument(escapedFile);

        //Stabilize parsed document
        doc.normalize();

        //Get body element
        NodeList mainNodeList = doc.getElementsByTagName("rsm");

        //Make sure there is only ONE body element
        if (mainNodeList.getLength() == 1) {
            debugMsg("Parsing Main Element", 4);
            //Get rsm Element
            Element mainElement = (Element) mainNodeList.item(0);

            debugMsg("Setting Theme", 4);
            //If the mainElement has the attribute "theme"
            if (mainElement.getAttributeNode("theme") != null) {
                //Get the value of the attribute theme for the body element
                Attr swing_Theme = mainElement.getAttributeNode("theme");

                //See if the rsm file specifies a theme other than camo
                if (swing_Theme != null && !swing_Theme.getNodeValue().equalsIgnoreCase("camo")) {
                    try {
                        //Split the theme into the jarfile and the classname (JARFILE.jar : com.stuff.stuff.theme)
                        String[] splitTheme = swing_Theme.getNodeValue().split(":");

                        System.out.println(splitTheme[0].trim() + "**" + splitTheme[1].trim());
                        //Attempt to dynamically load the specified jarfile
                        Sys.addJarToClasspath(Globals.getCWD(splitTheme[0].trim()));

                        //Attempt to set the look'n'feel to the theme specified by the file
                        UIManager.setLookAndFeel(splitTheme[1].trim());

                        debugMsg("Look and Feel set to '" + swing_Theme.getNodeValue() + "'.", 3);

                    } catch (Exception e) {
                        //If unable to set to .rsm's theme, use the system look'n'feel
                        try {
                            UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
                        } catch (Exception a) {
                            UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName());
                        }
                        Utilities.showError(
                                "Error loading Look and Feel Specified, Look and Feel set to System");
                        e.printStackTrace();

                    }
                } else {
                    //If swing_Theme == camo or is not set, use the system look'n'feel
                    try {
                        UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
                    } catch (Exception a) {
                        a.printStackTrace();
                        UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName());
                    }
                    debugMsg("Look and Feel (Swing) set to System", 3);
                }
            } else {
                //If swing_Theme == camo or is not set, use the system look'n'feel
                try {
                    UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
                } catch (Exception a) {
                    a.printStackTrace();
                    UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName());
                }
                debugMsg("Look and Feel (Swing) set to System", 3);

            }

            //Parse styles
            for (int i = 0; i < mainElement.getElementsByTagName("style").getLength(); i++) {
                Element styleElement = (Element) mainElement.getElementsByTagName("style").item(i);
                //Load all styles from the style tags
                if (styleElement.getAttributeNode("href") != null) {
                    loadStyles(null, styleElement.getTextContent());
                } else {
                    loadStyles(styleElement.getTextContent(), null);

                }
            }

            //Parse links
            for (int i = 0; i < mainElement.getElementsByTagName("link").getLength(); i++) {
                Element linkElement = (Element) mainElement.getElementsByTagName("link").item(i);
                parseLinks(linkElement, engine);
            }

            //Parse JavaScript in <script> tags
            Main.loader.loadJS(escapedFile, engine);

            //Parse GUI
            for (int i = 0; i < mainElement.getElementsByTagName("window").getLength(); i++) {
                GUI.loadWindow((Element) mainElement.getElementsByTagName("window").item(i), engine);
            }

        } else { //There was more than one body tag, or 0 body tags

            //Display Error and quit, as we cannot recover from an abnormally formatted file
            Utilities.showError("Error: More or less than one <rsm> tag in '" + escapedFile + "'.\n\n"
                    + "Please add ONE <rsm> tag to '" + escapedFile + "'.");
            System.exit(1);
        }

    } catch (Exception e) {
        e.printStackTrace();
        System.exit(1);
    }

}

From source file:xsul.dsig.globus.security.authentication.SOAPBodyIdResolver.java

public XMLSignatureInput engineResolve(Attr uri, String BaseURI) throws ResourceResolverException {
    String uriNodeValue = uri.getNodeValue();
    NodeList resultNodes = null;/*from   w  w w . j  a  v a  2  s . co  m*/
    Document doc = uri.getOwnerDocument();

    // this must be done so that Xalan can catch ALL namespaces
    XMLUtils.circumventBug2650(doc);

    CachedXPathAPI cXPathAPI = new CachedXPathAPI();

    /*
     * URI="#chapter1"
     * Identifies a node-set containing the element with ID attribute
     * value 'chapter1' of the XML resource containing the signature.
     * XML Signature (and its applications) modify this node-set to
     * include the element plus all descendents including namespaces and
     * attributes -- but not comments.
     */
    String id = uriNodeValue.substring(1);

    Element selectedElem = WSSecurityUtil.findFirstBodyElement(doc);

    if (selectedElem == null) {
        throw new ResourceResolverException("generic.EmptyMessage", new Object[] { "Body element not found" },
                uri, BaseURI);
    }

    String cId = selectedElem.getAttributeNS(WSConstants.WSU_NS, "Id");

    if ((cId == null) || (cId.length() == 0)) {
        cId = selectedElem.getAttributeNS(WSConstants.SOAP_SEC_NS, "id");
    }

    if (!id.equals(cId)) {
        selectedElem = (Element) selectedElem.getParentNode();
        cId = selectedElem.getAttributeNS(WSConstants.WSU_NS, "Id");

        if ((cId == null) || (cId.length() == 0)) {
            cId = selectedElem.getAttributeNS(WSConstants.SOAP_SEC_NS, "id");
        }

        if (!id.equals(cId)) {
            throw new ResourceResolverException("generic.EmptyMessage", new Object[] { "Id not found" }, uri,
                    BaseURI);
        }
    }

    try {
        resultNodes = cXPathAPI.selectNodeList(selectedElem, Canonicalizer.XPATH_C14N_WITH_COMMENTS_SINGLE_NODE//.XPATH_C14N_OMIT_COMMENTS_SINGLE_NODE
        );
    } catch (javax.xml.transform.TransformerException ex) {
        throw new ResourceResolverException("generic.EmptyMessage", ex, uri, BaseURI);
    }

    Set resultSet = XMLUtils.convertNodelistToSet(resultNodes);
    XMLSignatureInput result = new XMLSignatureInput(resultSet);//, cXPathAPI);

    result.setMIMEType("text/xml");

    try {
        URI uriNew = new URI(new URI(BaseURI), uri.getNodeValue());
        result.setSourceURI(uriNew.toString());
    } catch (URI.MalformedURIException ex) {
        result.setSourceURI(BaseURI);
    }

    return result;
}

From source file:xsul.dsig.globus.security.authentication.SOAPBodyIdResolver.java

public boolean engineCanResolve(Attr uri, String BaseURI) {
    if (uri == null) {
        return false;
    }//  w w  w .j av a 2  s .c  o m

    String uriNodeValue = uri.getNodeValue();

    return uriNodeValue.startsWith("#");
}