Example usage for org.w3c.dom NamedNodeMap getNamedItem

List of usage examples for org.w3c.dom NamedNodeMap getNamedItem

Introduction

In this page you can find the example usage for org.w3c.dom NamedNodeMap getNamedItem.

Prototype

public Node getNamedItem(String name);

Source Link

Document

Retrieves a node specified by name.

Usage

From source file:com.github.sevntu.checkstyle.internal.ChecksTest.java

private static void validateEclipseCsMetaXmlFileRule(String pkg, Class<?> module, Set<Node> children)
        throws Exception {
    final String moduleName = module.getSimpleName();
    final Set<String> properties = getFinalProperties(module);
    final Set<Field> fieldMessages = CheckUtil.getCheckMessages(module);
    final Set<String> messages = new TreeSet<>();

    for (Field fieldMessage : fieldMessages) {
        // below is required for package/private classes
        if (!fieldMessage.isAccessible()) {
            fieldMessage.setAccessible(true);
        }/* ww w.ja  va2  s . co m*/

        messages.add(fieldMessage.get(null).toString());
    }

    for (Node child : children) {
        final NamedNodeMap attributes = child.getAttributes();

        switch (child.getNodeName()) {
        case "alternative-name":
            final Node internalNameNode = attributes.getNamedItem("internal-name");

            Assert.assertNotNull(
                    pkg + " checkstyle-metadata.xml must contain an internal name for " + moduleName,
                    internalNameNode);

            final String internalName = internalNameNode.getTextContent();

            Assert.assertEquals(
                    pkg + " checkstyle-metadata.xml requires a valid internal-name for " + moduleName,
                    module.getName(), internalName);
            break;
        case "description":
            Assert.assertEquals(pkg + " checkstyle-metadata.xml requires a valid description for " + moduleName,
                    "%" + moduleName + ".desc", child.getTextContent());
            break;
        case "property-metadata":
            final String propertyName = attributes.getNamedItem("name").getTextContent();

            Assert.assertTrue(pkg + " checkstyle-metadata.xml has an unknown parameter for " + moduleName + ": "
                    + propertyName, properties.remove(propertyName));

            final Node firstChild = child.getFirstChild().getNextSibling();

            Assert.assertNotNull(pkg + " checkstyle-metadata.xml requires atleast one child for " + moduleName
                    + ", " + propertyName, firstChild);
            Assert.assertEquals(pkg + " checkstyle-metadata.xml should have a description for the "
                    + "first child of " + moduleName + ", " + propertyName, "description",
                    firstChild.getNodeName());
            Assert.assertEquals(pkg + " checkstyle-metadata.xml requires a valid description for " + moduleName
                    + ", " + propertyName, "%" + moduleName + "." + propertyName, firstChild.getTextContent());
            break;
        case "message-key":
            final String key = attributes.getNamedItem("key").getTextContent();

            Assert.assertTrue(
                    pkg + " checkstyle-metadata.xml has an unknown message for " + moduleName + ": " + key,
                    messages.remove(key));
            break;
        default:
            Assert.fail(pkg + " checkstyle-metadata.xml unknown node for " + moduleName + ": "
                    + child.getNodeName());
            break;
        }
    }

    for (String property : properties) {
        Assert.fail(pkg + " checkstyle-metadata.xml missing parameter for " + moduleName + ": " + property);
    }

    for (String message : messages) {
        Assert.fail(pkg + " checkstyle-metadata.xml missing message for " + moduleName + ": " + message);
    }
}

From source file:hoot.services.geo.BoundingBox.java

/**
 * Creates a bounding box from an OSM XML bounds node
 * //  w ww .j av a2 s. c om
 * @param xmlBounds OSM XML bounds node
 * @return a bounding box
 * @throws Exception 
 * @throws DOMException 
 * @throws NumberFormatException 
 */
public static BoundingBox fromXml(final Node xml) throws NumberFormatException, DOMException, Exception {
    NamedNodeMap nodeAttributes = xml.getAttributes();
    return new BoundingBox(Double.parseDouble(nodeAttributes.getNamedItem("minLon").getNodeValue()),
            Double.parseDouble(nodeAttributes.getNamedItem("minLat").getNodeValue()),
            Double.parseDouble(nodeAttributes.getNamedItem("maxLon").getNodeValue()),
            Double.parseDouble(nodeAttributes.getNamedItem("maxLat").getNodeValue()));
}

From source file:com.idynin.ftbutils.ModPack.java

/**
 * Lightly modified from FTB net.ftb.workers.ModpackLoader
 * //from   ww w .java  2 s  .c o m
 * @param modPackFilter
 */
public static void populateModpacks(String server, String modpackMetaPath, ModPackFilter modPackFilter) {
    InputStream modPackStream = null;
    if (modPackStream == null) {
        try {
            modPackStream = new URL("http://" + server + modpackMetaPath).openStream();
        } catch (IOException e) {
            System.err.println("Completely unable to download the modpack file - check your connection");
            e.printStackTrace();
        }
    }
    if (modPackStream != null) {
        Document doc;
        try {
            doc = getXML(modPackStream);
        } catch (Exception e) {
            System.err.println("Exception reading modpack file");
            e.printStackTrace();
            return;
        }
        if (doc == null) {
            System.err.println("Error: could not load modpack data!");
            return;
        }
        NodeList modPacks = doc.getElementsByTagName("modpack");
        ModPack mp;
        for (int i = 0; i < modPacks.getLength(); i++) {
            Node modPackNode = modPacks.item(i);
            NamedNodeMap modPackAttr = modPackNode.getAttributes();
            try {
                mp = new ModPack(modPackAttr.getNamedItem("name").getTextContent(),
                        modPackAttr.getNamedItem("author").getTextContent(),
                        modPackAttr.getNamedItem("version").getTextContent(),
                        modPackAttr.getNamedItem("logo").getTextContent(),
                        modPackAttr.getNamedItem("url").getTextContent(),
                        modPackAttr.getNamedItem("image").getTextContent(),
                        modPackAttr.getNamedItem("dir").getTextContent(),
                        modPackAttr.getNamedItem("mcVersion").getTextContent(),
                        modPackAttr.getNamedItem("serverPack").getTextContent(),
                        modPackAttr.getNamedItem("description").getTextContent(),
                        modPackAttr.getNamedItem("mods") != null
                                ? modPackAttr.getNamedItem("mods").getTextContent()
                                : "",
                        modPackAttr.getNamedItem("oldVersions") != null
                                ? modPackAttr.getNamedItem("oldVersions").getTextContent()
                                : "",
                        modPackAttr.getNamedItem("animation") != null
                                ? modPackAttr.getNamedItem("animation").getTextContent()
                                : "",
                        modPackAttr.getNamedItem("maxPermSize") != null
                                ? modPackAttr.getNamedItem("maxPermSize").getTextContent()
                                : "",
                        (ModPack.getPackArray().isEmpty() ? 0 : ModPack.getPackArray().size()), false,
                        "modpacks.xml",
                        modPackAttr.getNamedItem("bundledMap") != null
                                ? modPackAttr.getNamedItem("bundledMap").getTextContent()
                                : "",
                        modPackAttr.getNamedItem("customTP") != null ? true : false);
                if (modPackFilter == null || modPackFilter.accept(mp)) {
                    ModPack.addPack(mp);
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        IOUtils.closeQuietly(modPackStream);
    }
}

From source file:com.jaspersoft.jasperserver.ws.xml.Unmarshaller.java

public static ResourceDescriptor readResourceDescriptor(Element rpNode) {

    ResourceDescriptor rd = new ResourceDescriptor();
    NamedNodeMap nodeAttributes;

    if (rpNode instanceof Element) {
        nodeAttributes = rpNode.getAttributes();
    } else {/*from   www.  j ava  2  s .c om*/
        // the current implementation currently rely on rpNode being an Element
        throw new IllegalStateException("repNode is not an Element");
    }

    if (nodeAttributes.getNamedItem("name") != null)
        rd.setName(nodeAttributes.getNamedItem("name").getNodeValue());
    if (nodeAttributes.getNamedItem("wsType") != null)
        rd.setWsType(nodeAttributes.getNamedItem("wsType").getNodeValue());
    if (nodeAttributes.getNamedItem(ResourceDescriptor.REFERENCE_TYPE) != null)
        rd.setReferenceType(nodeAttributes.getNamedItem(ResourceDescriptor.REFERENCE_TYPE).getNodeValue());
    if (nodeAttributes.getNamedItem("uriString") != null)
        rd.setUriString(nodeAttributes.getNamedItem("uriString").getNodeValue());
    if (nodeAttributes.getNamedItem("isNew") != null)
        rd.setIsNew(nodeAttributes.getNamedItem("isNew").getNodeValue().equals("true"));

    NodeList childsOfChild = rpNode.getChildNodes();
    for (int c_count = 0; c_count < childsOfChild.getLength(); c_count++) {
        Node child_child = (Node) childsOfChild.item(c_count);

        if (child_child.getNodeType() == Node.ELEMENT_NODE && child_child.getNodeName().equals("label")) {
            rd.setLabel(readPCDATA(child_child));
        } else if (child_child.getNodeType() == Node.ELEMENT_NODE
                && child_child.getNodeName().equals("description")) {
            rd.setDescription(readPCDATA(child_child));
        } else if (child_child.getNodeType() == Node.ELEMENT_NODE
                && child_child.getNodeName().equals("creationDate")) {
            Date creationDate = readCreationDate(child_child);
            if (creationDate != null) {
                rd.setCreationDate(creationDate);
            }
        } else if (child_child.getNodeType() == Node.ELEMENT_NODE
                && child_child.getNodeName().equals("resourceProperty")) {
            rd.setResourceProperty(readResourceProperty(child_child));
        } else if (child_child.getNodeType() == Node.ELEMENT_NODE
                && child_child.getNodeName().equals("resourceDescriptor")) {
            rd.getChildren().add(readResourceDescriptor((Element) child_child));
        } else if (child_child.getNodeType() == Node.ELEMENT_NODE
                && child_child.getNodeName().equals("parameter")) {
            rd.getParameters().add(readResourceParameter(child_child));
        }
    }

    return rd;
}

From source file:jp.sf.fess.solr.plugin.suggest.util.SolrConfigUtil.java

public static SuggestUpdateConfig getUpdateHandlerConfig(final SolrConfig config) {
    final SuggestUpdateConfig suggestUpdateConfig = new SuggestUpdateConfig();

    final Node solrServerNode = config.getNode("updateHandler/suggest/solrServer", false);
    if (solrServerNode != null) {
        try {// www .j  a  v a2s. co m
            final Node classNode = solrServerNode.getAttributes().getNamedItem("class");
            String className;
            if (classNode != null) {
                className = classNode.getTextContent();
            } else {
                className = "org.codelibs.solr.lib.server.SolrLibHttpSolrServer";
            }
            @SuppressWarnings("unchecked")
            final Class<? extends SolrServer> clazz = (Class<? extends SolrServer>) Class.forName(className);
            final String arg = config.getVal("updateHandler/suggest/solrServer/arg", false);
            SolrServer solrServer;
            if (StringUtils.isNotBlank(arg)) {
                final Constructor<? extends SolrServer> constructor = clazz.getConstructor(String.class);
                solrServer = constructor.newInstance(arg);
            } else {
                solrServer = clazz.newInstance();
            }

            final String username = config.getVal("updateHandler/suggest/solrServer/credentials/username",
                    false);
            final String password = config.getVal("updateHandler/suggest/solrServer/credentials/password",
                    false);
            if (StringUtils.isNotBlank(username) && StringUtils.isNotBlank(password)
                    && solrServer instanceof SolrLibHttpSolrServer) {
                final SolrLibHttpSolrServer solrLibHttpSolrServer = (SolrLibHttpSolrServer) solrServer;
                final URL u = new URL(arg);
                final AuthScope authScope = new AuthScope(u.getHost(), u.getPort());
                final Credentials credentials = new UsernamePasswordCredentials(username, password);
                solrLibHttpSolrServer.setCredentials(authScope, credentials);
                solrLibHttpSolrServer.addRequestInterceptor(new PreemptiveAuthInterceptor());
            }

            final NodeList childNodes = solrServerNode.getChildNodes();
            for (int i = 0; i < childNodes.getLength(); i++) {
                final Node node = childNodes.item(i);
                if (node.getNodeType() == Node.ELEMENT_NODE) {
                    final String name = node.getNodeName();
                    if (!"arg".equals(name) && !"credentials".equals(name)) {
                        final String value = node.getTextContent();
                        final Node typeNode = node.getAttributes().getNamedItem("type");
                        final Method method = clazz.getMethod(
                                "set" + name.substring(0, 1).toUpperCase() + name.substring(1),
                                getMethodArgClass(typeNode));
                        method.invoke(solrServer, getMethodArgValue(typeNode, value));
                    }
                }
            }
            if (solrServer instanceof SolrLibHttpSolrServer) {
                ((SolrLibHttpSolrServer) solrServer).init();
            }
            suggestUpdateConfig.setSolrServer(solrServer);
        } catch (final Exception e) {
            throw new FessSuggestException("Failed to load SolrServer.", e);
        }
    }

    final String labelFields = config.getVal("updateHandler/suggest/labelFields", false);
    if (StringUtils.isNotBlank(labelFields)) {
        suggestUpdateConfig.setLabelFields(labelFields.trim().split(","));
    }
    final String roleFields = config.getVal("updateHandler/suggest/roleFields", false);
    if (StringUtils.isNotBlank(roleFields)) {
        suggestUpdateConfig.setRoleFields(roleFields.trim().split(","));
    }

    final String expiresField = config.getVal("updateHandler/suggest/expiresField", false);
    if (StringUtils.isNotBlank(expiresField)) {
        suggestUpdateConfig.setExpiresField(expiresField);
    }
    final String segmentField = config.getVal("updateHandler/suggest/segmentField", false);
    if (StringUtils.isNotBlank(segmentField)) {
        suggestUpdateConfig.setSegmentField(segmentField);
    }
    final String updateInterval = config.getVal("updateHandler/suggest/updateInterval", false);
    if (StringUtils.isNotBlank(updateInterval) && StringUtils.isNumeric(updateInterval)) {
        suggestUpdateConfig.setUpdateInterval(Long.parseLong(updateInterval));
    }

    //set suggestFieldInfo
    final NodeList nodeList = config.getNodeList("updateHandler/suggest/suggestFieldInfo", true);
    for (int i = 0; i < nodeList.getLength(); i++) {
        try {
            final SuggestUpdateConfig.FieldConfig fieldConfig = new SuggestUpdateConfig.FieldConfig();
            final Node fieldInfoNode = nodeList.item(i);
            final NamedNodeMap fieldInfoAttributes = fieldInfoNode.getAttributes();
            final Node fieldNameNode = fieldInfoAttributes.getNamedItem("fieldName");
            final String fieldName = fieldNameNode.getNodeValue();
            if (StringUtils.isBlank(fieldName)) {
                continue;
            }
            fieldConfig.setTargetFields(fieldName.trim().split(","));
            if (logger.isInfoEnabled()) {
                for (final String s : fieldConfig.getTargetFields()) {
                    logger.info("fieldName : " + s);
                }
            }

            final NodeList fieldInfoChilds = fieldInfoNode.getChildNodes();
            for (int j = 0; j < fieldInfoChilds.getLength(); j++) {
                final Node fieldInfoChildNode = fieldInfoChilds.item(j);
                final String fieldInfoChildNodeName = fieldInfoChildNode.getNodeName();

                if ("tokenizerFactory".equals(fieldInfoChildNodeName)) {
                    //field tokenier settings
                    final SuggestUpdateConfig.TokenizerConfig tokenizerConfig = new SuggestUpdateConfig.TokenizerConfig();

                    final NamedNodeMap tokenizerFactoryAttributes = fieldInfoChildNode.getAttributes();
                    final Node tokenizerClassNameNode = tokenizerFactoryAttributes.getNamedItem("class");
                    final String tokenizerClassName = tokenizerClassNameNode.getNodeValue();
                    tokenizerConfig.setClassName(tokenizerClassName);
                    if (logger.isInfoEnabled()) {
                        logger.info("tokenizerFactory : " + tokenizerClassName);
                    }

                    final Map<String, String> args = new HashMap<String, String>();
                    for (int k = 0; k < tokenizerFactoryAttributes.getLength(); k++) {
                        final Node attribute = tokenizerFactoryAttributes.item(k);
                        final String key = attribute.getNodeName();
                        final String value = attribute.getNodeValue();
                        if (!"class".equals(key)) {
                            args.put(key, value);
                        }
                    }
                    if (!args.containsKey(USER_DICT_PATH)) {
                        final String userDictPath = System.getProperty(SuggestConstants.USER_DICT_PATH, "");
                        if (StringUtils.isNotBlank(userDictPath)) {
                            args.put(USER_DICT_PATH, userDictPath);
                        }
                        final String userDictEncoding = System.getProperty(SuggestConstants.USER_DICT_ENCODING,
                                "");
                        if (StringUtils.isNotBlank(userDictEncoding)) {
                            args.put(USER_DICT_ENCODING, userDictEncoding);
                        }
                    }
                    tokenizerConfig.setArgs(args);

                    fieldConfig.setTokenizerConfig(tokenizerConfig);
                } else if ("suggestReadingConverter".equals(fieldInfoChildNodeName)) {
                    //field reading converter settings
                    final NodeList converterNodeList = fieldInfoChildNode.getChildNodes();
                    for (int k = 0; k < converterNodeList.getLength(); k++) {
                        final SuggestUpdateConfig.ConverterConfig converterConfig = new SuggestUpdateConfig.ConverterConfig();

                        final Node converterNode = converterNodeList.item(k);
                        if (!"converter".equals(converterNode.getNodeName())) {
                            continue;
                        }

                        final NamedNodeMap converterAttributes = converterNode.getAttributes();
                        final Node classNameNode = converterAttributes.getNamedItem("class");
                        final String className = classNameNode.getNodeValue();
                        converterConfig.setClassName(className);
                        if (logger.isInfoEnabled()) {
                            logger.info("converter : " + className);
                        }

                        final Map<String, String> properties = new HashMap<String, String>();
                        for (int l = 0; l < converterAttributes.getLength(); l++) {
                            final Node attribute = converterAttributes.item(l);
                            final String key = attribute.getNodeName();
                            final String value = attribute.getNodeValue();
                            if (!"class".equals(key)) {
                                properties.put(key, value);
                            }
                        }
                        converterConfig.setProperties(properties);
                        if (logger.isInfoEnabled()) {
                            logger.info("converter properties = " + properties);
                        }
                        fieldConfig.addConverterConfig(converterConfig);
                    }
                } else if ("suggestNormalizer".equals(fieldInfoChildNodeName)) {
                    //field normalizer settings
                    final NodeList normalizerNodeList = fieldInfoChildNode.getChildNodes();
                    for (int k = 0; k < normalizerNodeList.getLength(); k++) {
                        final SuggestUpdateConfig.NormalizerConfig normalizerConfig = new SuggestUpdateConfig.NormalizerConfig();

                        final Node normalizerNode = normalizerNodeList.item(k);
                        if (!"normalizer".equals(normalizerNode.getNodeName())) {
                            continue;
                        }

                        final NamedNodeMap normalizerAttributes = normalizerNode.getAttributes();
                        final Node classNameNode = normalizerAttributes.getNamedItem("class");
                        final String className = classNameNode.getNodeValue();
                        normalizerConfig.setClassName(className);
                        if (logger.isInfoEnabled()) {
                            logger.info("normalizer : " + className);
                        }

                        final Map<String, String> properties = new HashMap<String, String>();
                        for (int l = 0; l < normalizerAttributes.getLength(); l++) {
                            final Node attribute = normalizerAttributes.item(l);
                            final String key = attribute.getNodeName();
                            final String value = attribute.getNodeValue();
                            if (!"class".equals(key)) {
                                properties.put(key, value);
                            }
                        }
                        normalizerConfig.setProperties(properties);
                        if (logger.isInfoEnabled()) {
                            logger.info("normalize properties = " + properties);
                        }
                        fieldConfig.addNormalizerConfig(normalizerConfig);
                    }
                }
            }

            suggestUpdateConfig.addFieldConfig(fieldConfig);
        } catch (final Exception e) {
            throw new FessSuggestException("Failed to load Suggest Field Info.", e);
        }
    }

    return suggestUpdateConfig;
}

From source file:it.unibo.alchemist.language.EnvironmentBuilder.java

private static Time buildTime(final Node son, final Map<String, Object> env, final RandomGenerator random)
        throws InstantiationException, IllegalAccessException, InvocationTargetException,
        ClassNotFoundException {/*from ww  w.j a va  2  s.co  m*/
    final NamedNodeMap attributes = son.getAttributes();
    String type = attributes.getNamedItem(TYPE).getNodeValue();
    type = type.contains(".") ? type : "it.unibo.alchemist.model.implementations.times." + type;
    return (Time) coreOperations(env, son, type, random);
}

From source file:it.unibo.alchemist.language.EnvironmentBuilder.java

@SuppressWarnings("unchecked")
private static <E> E coreOperations(final Map<String, Object> environment, final Node root, final String type,
        final RandomGenerator random) throws InstantiationException, IllegalAccessException,
        InvocationTargetException, ClassNotFoundException {
    final NamedNodeMap atts = root.getAttributes();
    final Node nameNode = atts.getNamedItem(NAME);
    final String name = nameNode == null ? "" : nameNode.getNodeValue();
    if (!name.equals("") && atts.getLength() == 1 && environment.containsKey(name)) {
        return (E) environment.get(name);
    }/*from   w  w  w . j ava  2  s  .  c o m*/
    final Class<?> objClass = (Class<?>) Class.forName(type);
    final List<Constructor<E>> consList = unsafeExtractConstructors(objClass);
    final ArrayList<String> params = new ArrayList<String>();
    int index = 0;
    for (Node param = atts.getNamedItem("p0"); param != null; param = atts.getNamedItem("p" + (++index))) {
        params.add(param.getNodeValue());
    }
    params.trimToSize();
    final E res = tryToBuild(consList, params, environment, random);
    environment.put(name, res);
    return res;
}

From source file:com.jkoolcloud.tnt4j.streams.parsers.ActivityXmlParser.java

/**
 * Resolves DOM node contained textual data and formats it using provided locator.
 *
 * @param locator//from   w w w.  ja va2  s.c  o m
 *            locator instance to alter using XML attributes contained data type, format and units used to format
 *            resolved value
 * @param node
 *            DOM node to collect textual data
 * @return resolved textual value formatted based on the locator's formatting properties
 * @throws ParseException
 *             if exception occurs applying locator format properties to specified value
 */
protected static Object getTextContent(ActivityFieldLocator locator, Node node) throws ParseException {
    String strValue = node.getTextContent();
    Node attrsNode = node;

    if (node instanceof Attr) {
        Attr attr = (Attr) node;

        attrsNode = attr.getOwnerElement();
    }

    // Get list of attributes and their values for
    // current element
    NamedNodeMap attrsMap = attrsNode == null ? null : attrsNode.getAttributes();

    Node attr;
    String attrVal;
    ActivityFieldLocator locCopy = locator.clone();
    if (attrsMap != null && attrsMap.getLength() > 0) {
        attr = attrsMap.getNamedItem(DATA_TYPE_ATTR);
        attrVal = attr == null ? null : attr.getTextContent();
        if (StringUtils.isNotEmpty(attrVal)) {
            locCopy.setDataType(ActivityFieldDataType.valueOf(attrVal));
        }

        attr = attrsMap.getNamedItem(FORMAT_ATTR);
        attrVal = attr == null ? null : attr.getTextContent();
        if (StringUtils.isNotEmpty(attrVal)) {
            attr = attrsMap.getNamedItem(LOCALE_ATTR);
            String attrLVal = attr == null ? null : attr.getTextContent();

            locCopy.setFormat(attrVal, StringUtils.isEmpty(attrLVal) ? locator.getLocale() : attrLVal);
        }

        attr = attrsMap.getNamedItem(UNITS_ATTR);
        attrVal = attr == null ? null : attr.getTextContent();
        if (StringUtils.isNotEmpty(attrVal)) {
            locCopy.setUnits(attrVal);
        }
    }

    return locCopy.formatValue(strValue.trim());
}

From source file:com.photon.phresco.framework.commons.QualityUtil.java

public static void changeTestName(String performancePath, String testName) throws Exception {
    File buildPathXml = null;//from   w  w  w.  java2  s.co m
    S_LOGGER.debug("Entering Method QualityUtil.testSuite() performance path and TestName " + performancePath
            + " " + testName);
    buildPathXml = new File(performancePath + buildFileName);
    Document document = com.photon.phresco.framework.impl.util.FrameworkUtil.getDocument(buildPathXml);
    String fileNameNode = "project/target[@name='init']/property[@name='jmeter.result.file']";
    NodeList nodelist = org.apache.xpath.XPathAPI.selectNodeList(document, fileNameNode);
    if (nodelist != null && nodelist.getLength() > 0) {
        Node stringProp = nodelist.item(0);
        NamedNodeMap attributes = stringProp.getAttributes();
        Node valueAttr = attributes.getNamedItem("value");
        String valueAttrTxt = valueAttr.getTextContent();
        S_LOGGER.debug("Load test xml name "
                + valueAttrTxt.substring(0, valueAttrTxt.indexOf("/") + 1).concat(testName + ".xml"));
        valueAttr.setTextContent(
                valueAttrTxt.substring(0, valueAttrTxt.indexOf("/") + 1).concat(testName + ".xml"));
    }
    saveDocument(buildPathXml, document);
}

From source file:com.photon.phresco.framework.commons.QualityUtil.java

public static List<String> getDeviceNames(Document document) throws Exception {
    NodeList nodeList = org.apache.xpath.XPathAPI.selectNodeList(document, "/*/*");
    List<String> deviceList = new ArrayList<String>();
    for (int i = 0; i < nodeList.getLength(); i++) {
        Node node = nodeList.item(i);
        NamedNodeMap nameNodeMap = node.getAttributes();
        String deviceId = "";
        String deviceName = "";
        Node idAttr = nameNodeMap.getNamedItem(FrameworkConstants.ATTR_ID);
        deviceId = idAttr.getNodeValue();
        Node nameAttr = nameNodeMap.getNamedItem(FrameworkConstants.ATTR_NAME);
        deviceName = nameAttr.getNodeValue();
        deviceList.add(deviceId + "#SEP#" + deviceName);
    }//  ww  w  .  j a va2  s .  c om
    return deviceList;
}