Example usage for org.w3c.dom Element getAttributeNode

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

Introduction

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

Prototype

public Attr getAttributeNode(String name);

Source Link

Document

Retrieves an attribute node by name.

Usage

From source file:org.kepler.sms.util.OntologyConfiguration.java

public boolean isTagBarOntology(String filepath) {
    if (_document == null || filepath == null)
        return false;

    // get the root
    Element root = _document.getDocumentElement();
    if (root == null)
        return false;
    // iterate to find the ontology with filepath
    NodeList lst = root.getElementsByTagName("ontology");
    for (int i = 0; i < lst.getLength(); i++) {
        Element elem = (Element) lst.item(i);
        Attr att = elem.getAttributeNode("filename");
        if (att != null) {
            String filename = att.getValue();
            if (filepath.equals(getAbsoluteOntologyPath(filename))) {
                Attr libatt = elem.getAttributeNode("tagbar");
                if (libatt != null) {
                    String library = libatt.getValue();
                    if (library != null && library.equals("false")) {
                        return false;
                    }// w w  w . j a  v  a 2  s  .  c  o  m
                }
            }
        }
    }
    return true;
}

From source file:org.kuali.test.handlers.parameter.SelectEditDocumentLookupHandler.java

private String getDocumentIdFromColumn(Element column) {
    String retval = null;/*from   ww  w .  jav  a 2s  .c  o m*/

    Element anchor = getAnchor(column);

    if (anchor != null) {
        Node hrefatt = anchor.getAttributeNode(Constants.HTML_TAG_ATTRIBUTE_HREF);

        if (hrefatt != null) {
            try {
                List<NameValuePair> nvplist = Utils.getNameValueParameterListFromUrl(retval);

                if (nvplist != null) {
                    for (NameValuePair nvp : nvplist) {
                        if (isDocumentIdParameter(nvp)) {
                            retval = nvp.getValue();
                            break;
                        }
                    }
                }
            }

            catch (UnsupportedEncodingException ex) {
                LOG.error(ex.toString(), ex);
            }
        }
    }

    return retval;
}

From source file:org.methodize.nntprss.admin.AdminServlet.java

private void cmdImportNntpRssChannelConfig(HttpServletResponse response, MultiPartRequest mpRequest)
        throws ServletException, IOException {

    Writer writer = response.getWriter();
    writeHeader(writer, TAB_CONFIG);/*from   w ww  . j a va 2s.c o m*/

    ChannelManager channelManager = (ChannelManager) getServletContext()
            .getAttribute(AdminServer.SERVLET_CTX_RSS_MANAGER);

    writer.write("<b>Import status</b><p>");

    List errors = new ArrayList();
    int channelsAdded = 0;

    // Parse XML
    try {
        DocumentBuilder db = AppConstants.newDocumentBuilder();
        Document doc = db.parse(mpRequest.getInputStream("file"));
        Element docElm = doc.getDocumentElement();
        NodeList channels = docElm.getElementsByTagName("channel");

        for (int channelCount = 0; channelCount < channels.getLength(); channelCount++) {
            Element chanElm = (Element) channels.item(channelCount);

            String name = chanElm.getAttribute("name");
            String urlString = chanElm.getAttribute("url");
            boolean historical = false;
            Node historicalNode = chanElm.getAttributeNode("historical");
            if (historicalNode != null) {
                historical = historicalNode.getNodeValue().equalsIgnoreCase("true");
            }

            long expiration = Channel.EXPIRATION_KEEP;
            Node expirationNode = chanElm.getAttributeNode("expiration");
            if (expirationNode != null) {
                expiration = Long.parseLong(expirationNode.getNodeValue());
            } else {
                expiration = historical ? Channel.EXPIRATION_KEEP : 0;
            }

            String categoryName = chanElm.getAttribute("category");

            // Check name...
            List currentErrors = new ArrayList();
            Channel existingChannel = channelManager.channelByName(name);

            if (name.length() == 0) {
                currentErrors.add("Channel with empty name - URL=" + urlString);
            } else if (name.indexOf(' ') > -1) {
                currentErrors.add("Channel name cannot contain spaces - name=" + name);
            } else if (existingChannel != null) {
                currentErrors.add("Channel name " + name + " is already is use");
            }

            if (urlString.length() == 0) {
                currentErrors.add("URL cannot be empty, channel name=" + name);
            } else if (urlString.equals("http://") || urlString.equals("https://")) {
                currentErrors.add("You must specify a URL, channel name=" + name);
            } else if (!urlString.startsWith("http://") && !urlString.startsWith("https://")) {
                currentErrors.add("Only URLs starting http:// or https:// are supported, channel name=" + name
                        + ", url=" + urlString);
            }

            if (existingChannel == null) {

                Channel newChannel = null;
                if (currentErrors.size() == 0) {
                    try {
                        newChannel = new Channel(name, urlString);
                        //                     newChannel.setHistorical(historical);
                        newChannel.setExpiration(expiration);
                        channelManager.addChannel(newChannel);
                        channelsAdded++;
                    } catch (MalformedURLException me) {
                        errors.add("Channel " + name + " - URL (" + urlString + ") is malformed");
                    }
                }

                if (categoryName.length() > 0) {
                    //Handle category...
                    Category category = channelManager.categoryByName(categoryName);
                    if (category == null) {
                        // Need to create category...
                        category = new Category();
                        category.setName(categoryName);
                        channelManager.addCategory(category);
                    }
                    category.addChannel(newChannel);
                    newChannel.setCategory(category);
                    newChannel.save();
                }

                // Removed channel validation... channels will be validated
                // on next iteration of channel poller - will be highlighted
                // in channel list if invalid
                // Validate channel...
                //               if(Channel.isValid(new URL(urlString))) {
                //// Add channel...
                //                  Channel newChannel = null;
                //                  if(currentErrors.size() == 0) {
                //                     try {
                //                        newChannel = new Channel(name, urlString);
                //                        newChannel.setHistorical(historical);
                //                        channelManager.addChannel(newChannel);
                //                        channelsAdded++;
                //                     } catch(MalformedURLException me) {
                //                        errors.add("Channel " + name + " - URL (" 
                //                           + urlString + ") is malformed");
                //                     }
                //                  }            
                //                  
                //               } else {
                //// URL points to invalid document
                //                  errors.add("Channel " + name + "'s URL (" + urlString + ") "
                //                     + "points to an invalid document");
                //               }
            }

            errors.addAll(currentErrors);

        }
    } catch (SAXException se) {
        errors.add("There was an error parsing your channel file:<br>" + se.getMessage());
    } catch (ParserConfigurationException pce) {
        errors.add("There was a problem reading your channelf file:<br>" + pce.getMessage());
    }

    // Display any errors encountered during parsing...
    if (errors.size() > 0) {
        writer.write("Problems were encountered while adding channels.<p>");
        writeErrors(writer, errors);

        if (channelsAdded > 0) {
            writer.write("<p>" + channelsAdded + " channel(s) were successfully imported.");
        }
    } else {
        if (channelsAdded > 0) {
            writer.write("<p>" + channelsAdded + " channel(s) were successfully imported.");
        } else {
            writer.write("The configuration file did not contain any channels!");
        }
    }

    writeFooter(writer);
    writer.flush();

}

From source file:org.mule.config.spring.parsers.AbstractMuleBeanDefinitionParser.java

protected void checkElementNameUnique(Element element) {
    if (null != element.getAttributeNode(ATTRIBUTE_NAME)) {
        String name = element.getAttribute(ATTRIBUTE_NAME);
        if (getRegistry().containsBeanDefinition(name)) {
            throw new IllegalArgumentException("A service named " + name + " already exists.");
        }/*from  ww w.jav  a2 s.  com*/
    }
}

From source file:org.nuxeo.runtime.jboss.deployer.structure.DeploymentStructureReader.java

public DeploymentStructure read(VirtualFile vhome, InputStream in) throws Exception {
    DeploymentStructure md = new DeploymentStructure(vhome);
    DocumentBuilder docBuilder = dbfac.newDocumentBuilder();
    Document doc = docBuilder.parse(in);
    Element root = doc.getDocumentElement();
    Attr attr = root.getAttributeNode("children");
    if (attr != null) {
        String[] ar = Utils.split(attr.getValue().trim(), ':', true);
        md.setChildren(ar);//from  www  .  jav  a  2s  .c om
    }
    attr = root.getAttributeNode("bundles");
    if (attr != null) {
        String[] ar = Utils.split(attr.getValue().trim(), ':', true);
        md.setBundles(ar);
    }
    Node node = root.getFirstChild();
    while (node != null) {
        if (node.getNodeType() == Node.ELEMENT_NODE) {
            String name = node.getNodeName().toLowerCase();
            if ("context".equalsIgnoreCase(name)) {
                readContext((Element) node, md);
            } else if ("properties".equals(name)) {
                readProperties(vhome, (Element) node, md);
            } else if ("preprocessor".equals(name)) {
                readPreprocessor((Element) node, md);
            }
        }
        node = node.getNextSibling();
    }
    return md;
}

From source file:org.nuxeo.runtime.jboss.deployer.structure.DeploymentStructureReader.java

protected void readPreprocessor(Element element, DeploymentStructure md) {
    Attr attr = element.getAttributeNode("enabled");
    String enabled = attr == null ? "true" : attr.getValue().trim();
    md.setRequirePreprocessing(Boolean.parseBoolean(enabled));
    attr = element.getAttributeNode("classpath");
    if (attr != null) {
        String[] ar = Utils.split(attr.getValue().trim(), ':', true);
        md.setPreprocessorClassPath(ar);
    }// ww  w .  j a  v  a 2s. c  o m
}

From source file:org.nuxeo.runtime.jboss.deployer.structure.DeploymentStructureReader.java

protected void readContext(Element element, DeploymentStructure md) {
    Attr attr = element.getAttributeNode("path");
    String path = attr == null ? "" : attr.getValue().trim();
    DeploymentStructure.Context ctx = new Context(path);
    attr = element.getAttributeNode("metaDataPath");
    if (attr != null) {
        String[] ar = Utils.split(attr.getValue().trim(), ':', true);
        ctx.setMetaDataPath(ar);// w  w w  .jav  a 2  s . c o m
    }
    attr = element.getAttributeNode("classpath");
    if (attr != null) {
        String[] ar = Utils.split(attr.getValue().trim(), ':', true);
        ctx.setClasspath(ar);
    }
    md.addContext(ctx);
}

From source file:org.nuxeo.runtime.jboss.deployer.structure.DeploymentStructureReader.java

@SuppressWarnings({ "rawtypes", "unchecked" })
public static void readProperties(VirtualFile file, Element element, DeploymentStructure md) throws Exception {
    Attr attr = element.getAttributeNode("src");
    if (attr != null) {
        VirtualFile vf = file.getChild(attr.getValue().trim());
        if (vf != null) {
            InputStream in = vf.openStream();
            try {
                Properties props = new Properties();
                props.load(in);/* w  w w . j  av  a  2  s.  c o m*/
                md.getProperties().putAll((Map) props);
            } finally {
                in.close();
            }
        } else {
            log.warn(
                    "Properties file referenced in nuxeo-structure.xml could not be found: " + attr.getValue());
        }
    }
    // load contents too if any
    Node child = element.getFirstChild();
    while (child != null) {
        if (child.getNodeType() == Node.ELEMENT_NODE) {
            if (child.getNodeName().equalsIgnoreCase("property")) {
                Element echild = (Element) child;
                attr = echild.getAttributeNode("name");
                if (attr == null) {
                    log.warn(
                            "Invalid property element format in nuxeo-structure.xml. Property name attribute is required");
                }
                md.setProperty(attr.getValue().trim(), echild.getTextContent().trim());
            }
        }
        child = child.getNextSibling();
    }
}

From source file:org.owasp.webscarab.plugin.saml.SamlModel.java

private boolean hasDestinationIndicationSaml2Response(Element responseElement) {
    if (null != responseElement.getAttributeNode("Destination")) {
        return true;
    }/*from   ww  w. j  ava2s .com*/
    NodeList assertionNodeList = responseElement.getElementsByTagNameNS("urn:oasis:names:tc:SAML:2.0:assertion",
            "Assertion");
    if (0 == assertionNodeList.getLength()) {
        return false;
    }
    Element assertionElement = (Element) assertionNodeList.item(0);
    NodeList audienceNodeList = assertionElement.getElementsByTagNameNS("urn:oasis:names:tc:SAML:2.0:assertion",
            "Audience");
    if (0 != audienceNodeList.getLength()) {
        return true;
    }
    NodeList subjectConfirmationDataNodeList = assertionElement
            .getElementsByTagNameNS("urn:oasis:names:tc:SAML:2.0:assertion", "SubjectConfirmationData");
    if (0 == subjectConfirmationDataNodeList.getLength()) {
        return false;
    }
    Element subjectConfirmationDataElement = (Element) subjectConfirmationDataNodeList.item(0);
    if (null != subjectConfirmationDataElement.getAttributeNode("Recipient")) {
        return true;
    }
    if (null != subjectConfirmationDataElement.getAttributeNode("Address")) {
        return true;
    }
    return false;
}

From source file:org.owasp.webscarab.plugin.saml.SamlModel.java

private boolean hasDestinationIndicationSaml1Response(Element responseElement) {
    if (null != responseElement.getAttributeNode("Recipient")) {
        return true;
    }/*from  w  w w. ja v a 2s .c  o m*/
    NodeList assertionNodeList = responseElement.getElementsByTagNameNS("urn:oasis:names:tc:SAML:1.0:assertion",
            "Assertion");
    if (0 == assertionNodeList.getLength()) {
        return false;
    }
    Element assertionElement = (Element) assertionNodeList.item(0);
    NodeList audienceNodeList = assertionElement.getElementsByTagNameNS("urn:oasis:names:tc:SAML:1.0:assertion",
            "Audience");
    if (0 != audienceNodeList.getLength()) {
        return true;
    }
    return false;
}