Example usage for org.w3c.dom Element getNodeName

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

Introduction

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

Prototype

public String getNodeName();

Source Link

Document

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

Usage

From source file:es.juntadeandalucia.panelGestion.negocio.utiles.PanelSettings.java

private static void readGeoserverConfiguration(Document xmlConfiguration, XPath xpath)
        throws XPathExpressionException {

    geoservers = new LinkedList<GeoserverVO>();

    Element doc = xmlConfiguration.getDocumentElement();
    NodeList geoserver_aux = doc.getElementsByTagName("geoserver");

    // iterate over the repositories
    for (int i = 0; i < geoserver_aux.getLength(); i++) {

        GeoserverVO geoserverAux = new GeoserverVO();

        Node geoserverNode = geoserver_aux.item(i);

        if (geoserverNode instanceof Element) {
            Element geoserverElem = (Element) geoserverNode;

            // get alias and url from the repository node
            NodeList geoserverChildren = geoserverElem.getChildNodes();
            for (int a = 0; a < geoserverChildren.getLength(); a++) {

                Node childrenAux = geoserverChildren.item(a);
                if (childrenAux instanceof Element) {
                    Element childrenAuxElement = (Element) childrenAux;
                    if (childrenAuxElement.getNodeName().equals("url")) {
                        geoserverAux.setGeoserverUrl(
                                Utils.removeLastSlash(childrenAuxElement.getAttributeNode("value").getValue()));
                    }/* ww  w  .  java  2  s .c o m*/
                    if (childrenAuxElement.getNodeName().equals("user")) {
                        geoserverAux.setGeoserverUser(childrenAuxElement.getAttributeNode("value").getValue());
                    }
                    if (childrenAuxElement.getNodeName().equals("password")) {
                        geoserverAux
                                .setGeoserverPassword(childrenAuxElement.getAttributeNode("value").getValue());
                    }
                    if (childrenAuxElement.getNodeName().equals("version")) {
                        NodeList childrenListVersionAux = childrenAuxElement.getChildNodes();
                        for (int b = 0; b < childrenListVersionAux.getLength(); b++) {
                            Node childrenVersionAux = childrenListVersionAux.item(b);
                            if (childrenVersionAux instanceof Element) {
                                Element childrenElementVersionAux = (Element) childrenVersionAux;
                                if (childrenElementVersionAux.getNodeName().equals("wms")) {
                                    geoserverAux.setGeoserverWMSVersion(
                                            childrenElementVersionAux.getAttributeNode("value").getValue());
                                }
                                if (childrenElementVersionAux.getNodeName().equals("wfs")) {
                                    geoserverAux.setGeoserverWFSVersion(
                                            childrenElementVersionAux.getAttributeNode("value").getValue());
                                }
                            }
                        }

                    }

                }

            }
            geoservers.add(geoserverAux);
        }

    }

}

From source file:de.codesourcery.utils.xml.XmlHelper.java

public static String getDirectChildValue(Element parent, String childTag, boolean isRequired)
        throws ParseException {

    NodeList list = parent.getChildNodes();

    Node matchingNode = null;/* w w w.  java 2s.c o  m*/
    for (int i = 0; i < list.getLength(); i++) {
        Node n = list.item(i);

        if (n.getNodeName().equals(childTag)) {
            if (matchingNode == null) {
                matchingNode = n;
            } else {
                throw new ParseException(
                        "Node " + parent.getNodeName() + " contains more than one child <" + childTag + "> ?!",
                        -1);
            }
        }
    }

    if (matchingNode == null) {
        if (isRequired) {
            throw new ParseException(
                    "Node " + parent.getNodeName() + " contains no child node <" + childTag + "> ?!", -1);
        }
        return null;
    }

    return getNodeValue(matchingNode, null, isRequired);
}

From source file:org.yamj.core.service.metadata.nfo.InfoReader.java

/**
 * Parse Actors from the XML NFO file.// w  w  w. ja  va2  s.c om
 *
 * @param nlElements
 * @param dto
 */
private static void parseActors(NodeList nlElements, InfoDTO dto) {
    // check if we have a node
    if (nlElements == null || nlElements.getLength() == 0) {
        return;
    }

    for (int actorLoop = 0; actorLoop < nlElements.getLength(); actorLoop++) {
        // Get all the name/role/thumb nodes
        Node nActors = nlElements.item(actorLoop);
        NodeList nlCast = nActors.getChildNodes();
        Node nElement;

        String aName = null;
        String aRole = null;
        String aThumb = null;
        Boolean firstActor = Boolean.TRUE;

        if (nlCast.getLength() > 1) {
            for (int looper = 0; looper < nlCast.getLength(); looper++) {
                nElement = nlCast.item(looper);
                if (nElement.getNodeType() == Node.ELEMENT_NODE) {
                    Element eCast = (Element) nElement;
                    if (eCast.getNodeName().equalsIgnoreCase("name")) {
                        if (firstActor) {
                            firstActor = Boolean.FALSE;
                        } else {
                            dto.addActor(aName, aRole, aThumb);
                        }
                        aName = eCast.getTextContent();
                        aRole = null;
                        aThumb = null;
                    } else if (eCast.getNodeName().equalsIgnoreCase("role")
                            && StringUtils.isNotBlank(eCast.getTextContent())) {
                        aRole = eCast.getTextContent();
                    } else if (eCast.getNodeName().equalsIgnoreCase("thumb")
                            && StringUtils.isNotBlank(eCast.getTextContent())) {
                        // thumb will be skipped if there's nothing in there
                        aThumb = eCast.getTextContent();
                    }
                    // There's a case where there might be a different node here that isn't name, role or thumb, but that will be ignored
                }
            }
        } else {
            // This looks like a Mede8er node in the "<actor>Actor Name</actor>" format, so just get the text element
            aName = nActors.getTextContent();
        }

        // after all add the last scraped actor
        dto.addActor(aName, aRole, aThumb);
    }
}

From source file:microsoft.exchange.webservices.data.core.EwsServiceXmlWriter.java

/**
 * @param element DOM element//from  w ww .j  a  v  a2 s.co  m
 * @param writer XML stream writer
 * @throws XMLStreamException the XML stream exception
 */
public static void addElement(Element element, XMLStreamWriter writer) throws XMLStreamException {
    String nameSpace = element.getNamespaceURI();
    String prefix = element.getPrefix();
    String localName = element.getLocalName();
    if (prefix == null) {
        prefix = "";
    }
    if (localName == null) {
        localName = element.getNodeName();

        if (localName == null) {
            throw new IllegalStateException("Element's local name cannot be null!");
        }
    }

    String decUri = writer.getNamespaceContext().getNamespaceURI(prefix);
    boolean declareNamespace = decUri == null || !decUri.equals(nameSpace);

    if (nameSpace == null || nameSpace.length() == 0) {
        writer.writeStartElement(localName);
    } else {
        writer.writeStartElement(prefix, localName, nameSpace);
    }

    NamedNodeMap attrs = element.getAttributes();
    for (int i = 0; i < attrs.getLength(); i++) {
        Node attr = attrs.item(i);

        String name = attr.getNodeName();
        String attrPrefix = "";
        int prefixIndex = name.indexOf(':');
        if (prefixIndex != -1) {
            attrPrefix = name.substring(0, prefixIndex);
            name = name.substring(prefixIndex + 1);
        }

        if ("xmlns".equals(attrPrefix)) {
            writer.writeNamespace(name, attr.getNodeValue());
            if (name.equals(prefix) && attr.getNodeValue().equals(nameSpace)) {
                declareNamespace = false;
            }
        } else {
            if ("xmlns".equals(name) && "".equals(attrPrefix)) {
                writer.writeNamespace("", attr.getNodeValue());
                if (attr.getNodeValue().equals(nameSpace)) {
                    declareNamespace = false;
                }
            } else {
                writer.writeAttribute(attrPrefix, attr.getNamespaceURI(), name, attr.getNodeValue());
            }
        }
    }

    if (declareNamespace) {
        if (nameSpace == null) {
            writer.writeNamespace(prefix, "");
        } else {
            writer.writeNamespace(prefix, nameSpace);
        }
    }

    NodeList nodes = element.getChildNodes();
    for (int i = 0; i < nodes.getLength(); i++) {
        Node n = nodes.item(i);
        writeNode(n, writer);
    }

    writer.writeEndElement();

}

From source file:de.codesourcery.eve.apiclient.utils.XMLParseHelper.java

public static String getChildValue(Element node, String childName) {

    final NodeList l = node.getChildNodes();
    Element result = null;/*from  w  w  w  .j a v  a  2s .c  o m*/
    for (int i = 0; i < l.getLength(); i++) {
        final Node n = l.item(i);
        if (n instanceof Element && n.getNodeName().equals(childName)) {
            if (result != null) {
                throw new UnparseableResponseException("Found more than one child element " + " named '"
                        + childName + "' " + "below node '" + node.getNodeName() + "' , expected exactly one");
            }
            result = (Element) n;
        }
    }
    if (result == null) {
        throw new UnparseableResponseException("Expected child element " + " '" + childName + "' "
                + " not found below node '" + node.getNodeName());
    }

    final String value = result.getTextContent();
    if (StringUtils.isBlank(value)) {
        throw new UnparseableResponseException("Child element " + " '" + childName + "' " + " below node '"
                + node.getNodeName() + " has no/blank value ?");
    }
    return value;
}

From source file:com.microsoft.tfs.core.clients.versioncontrol.workspacecache.WorkspaceInfo.java

/**
 * Creates an instance from the XML representation used in the cache file.
 *
 * @param serverINfo//from w w  w  .  j a  v a  2 s.  com
 *        the workspace's host server
 * @param workspaceInfoNode
 *        the {@value #XML_WORKSPACE_INFO} node to load from
 * @return an instance of a {@link WorkspaceInfo} created from the XML
 */
public static WorkspaceInfo loadFromXML(final InternalServerInfo serverInfo, final Element workspaceInfoNode) {
    final WorkspaceInfo workspaceInfo = new WorkspaceInfo();
    workspaceInfo.serverInfo = serverInfo;

    final NamedNodeMap attributes = workspaceInfoNode.getAttributes();
    Check.notNull(attributes, "attributes"); //$NON-NLS-1$

    workspaceInfo.name = getStringValue(attributes.getNamedItem(XML_NAME));
    workspaceInfo.ownerName = getStringValue(attributes.getNamedItem(XML_OWNER_NAME));
    workspaceInfo.ownerDisplayName = getStringValue(attributes.getNamedItem(XML_OWNER_DISPLAY_NAME));

    // The "ownerDisplayName" attribute was absent for some users.
    // Expecting it to always exist was causing a NullPointerException.
    // Now, use the "ownerName" if the "ownerDisplayName" is missing.
    if (StringUtil.isNullOrEmpty(workspaceInfo.ownerDisplayName)) {
        workspaceInfo.ownerDisplayName = workspaceInfo.getOwnerName();
    }

    workspaceInfo.computer = getStringValue(attributes.getNamedItem(XML_COMPUTER));
    workspaceInfo.comment = getStringValue(attributes.getNamedItem(XML_COMMENT));
    workspaceInfo.securityToken = getStringValue(attributes.getNamedItem(XML_SECURITY_TOKEN), null);
    workspaceInfo.isLocalWorkspace = getBooleanValue(attributes.getNamedItem(XML_IS_LOCAL_WORKSPACE));
    workspaceInfo.lastSavedCheckinTimeStamp = getTimeStampValue(
            attributes.getNamedItem(XML_LAST_SAVED_CHECKIN_TIME_STAMP));
    workspaceInfo.options = getWorkspaceOptionsValue(attributes.getNamedItem(OPTIONS_NAME));

    for (final Element child : DOMUtils.getChildElements(workspaceInfoNode)) {
        final String name = child.getNodeName();

        if (name.equals(XML_MAPPED_PATHS)) {
            final Element[] mappedPathElements = DOMUtils.getChildElements(child, XML_MAPPED_PATH);
            workspaceInfo.mappedPaths = new String[mappedPathElements.length];

            for (int i = 0; i < mappedPathElements.length; i++) {
                workspaceInfo.mappedPaths[i] = getStringValue(
                        mappedPathElements[i].getAttributes().getNamedItem(XML_PATH));
            }
        } else if (name.equals(XML_WORKING_FOLDERS)) {
            // Backwards compatibility with PDC build of Dev11 (and
            // earlier).
            final Element[] mapElements = DOMUtils.getChildElements(child, XML_MAP);
            workspaceInfo.mappedPaths = new String[mapElements.length];

            for (int i = 0; i < mapElements.length; i++) {
                workspaceInfo.mappedPaths[i] = getStringValue(
                        mapElements[i].getAttributes().getNamedItem(XML_LOCAL_PATH));
            }

            workspaceInfo.state = LocalWorkspaceState.MODIFIED;
        } else if (name.equals(XML_LAST_SAVED_CHECKIN)) {
            Check.isTrue(DOMUtils.getChildElements(child, SavedCheckin.XML_SAVED_CHECKIN).length == 1,
                    MessageFormat.format("Wrong number of LastSavedCheckin children: {0}", //$NON-NLS-1$
                            DOMUtils.getChildElements(child, SavedCheckin.XML_SAVED_CHECKIN).length));
            workspaceInfo.lastSavedCheckin = SavedCheckin
                    .loadFromXML(DOMUtils.getFirstChildElement(child, SavedCheckin.XML_SAVED_CHECKIN));
        } else if (name.equals(XML_OWNER_ALIASES)) {
            final Element[] aliasNodes = DOMUtils.getChildElements(child, XML_OWNER_ALIAS);
            final List<String> aliases = new ArrayList<String>(aliasNodes.length);

            for (int i = 0; i < aliasNodes.length; i++) {
                final String alias = getStringValue(
                        aliasNodes[i].getAttributes().getNamedItem(XML_OWNER_ALIAS));

                if (!StringUtil.isNullOrEmpty(alias)) {
                    aliases.add(alias);
                } else {
                    log.error(MessageFormat.format("Owner alias loaded from cache was null or empty: {0}", //$NON-NLS-1$
                            workspaceInfo));
                }
            }

            workspaceInfo.ownerAliases = aliases.toArray(new String[aliases.size()]);
        } else {
            log.warn(MessageFormat.format("Unknown workspace child node: {0}", name)); //$NON-NLS-1$
        }
    }

    if (workspaceInfo.ownerAliases == null) {
        workspaceInfo.ownerAliases = new String[0];
    }

    // Since we've just loaded the workspace, make sure it is marked as
    // clean.
    workspaceInfo.markClean();

    return workspaceInfo;
}

From source file:fm.last.lastfmlive.service.MapNodeMapper.java

public Map<String, String> mapNode(Node arg0, int arg1) throws DOMException {
    Map<String, String> result = new HashMap<String, String>();
    for (String xpath : xpaths) {
        List<Node> nodes = xpathTemplate.evaluateAsNodeList(xpath, new DOMSource(arg0));
        if (nodes.size() != 0) {
            Element e = (Element) nodes.get(0);
            result.put(e.getNodeName(), e.getTextContent());
        }//from  ww w  . j  a v  a2  s  .c  o  m
    }
    return result;
}

From source file:com.fota.Link.sdpApi.java

public static String getNcnInfo(String CTN) throws JDOMException {
    String resultStr = "";
    String logData = "";
    try {//from   w w  w .j  a  v  a  2  s .c o m
        String endPointUrl = PropUtil.getPropValue("sdp.oif516.url");

        String strRequest = "<soapenv:Envelope xmlns:soapenv='http://schemas.xmlsoap.org/soap/envelope/' "
                + "xmlns:oas='http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd'"
                + " xmlns:sdp='http://kt.com/sdp'>" + "     <soapenv:Header>" + "         <oas:Security>"
                + "             <oas:UsernameToken>" + "                 <oas:Username>"
                + PropUtil.getPropValue("sdp.id") + "</oas:Username>" + "                 <oas:Password>"
                + PropUtil.getPropValue("sdp.pw") + "</oas:Password>" + "             </oas:UsernameToken>"
                + "         </oas:Security>" + "     </soapenv:Header>"

                + "     <soapenv:Body>" + "         <sdp:getBasicUserInfoAndMarketInfoRequest>"
                + "         <!--You may enterthe following 6 items in any order-->"
                + "             <sdp:CALL_CTN>" + CTN + "</sdp:CALL_CTN>"
                + "         </sdp:getBasicUserInfoAndMarketInfoRequest>\n" + "     </soapenv:Body>\n"
                + "</soapenv:Envelope>";

        logData = "\r\n---------- Get Ncn Req Info start ----------\r\n";
        logData += " get Ncn Req Info - endPointUrl : " + endPointUrl;
        logData += "\r\n get Ncn Req Info - Content-type : text/xml;charset=utf-8";
        logData += "\r\n get Ncn Req Info - RequestMethod : POST";
        logData += "\r\n get Ncn Req Info - xml : " + strRequest;
        logData += "\r\n---------- Get Ncn Req Info end ----------";

        logger.info(logData);

        // connection
        URL url = new URL(endPointUrl);
        HttpURLConnection connection = (HttpURLConnection) url.openConnection();
        connection.setRequestProperty("Content-type", "text/xml;charset=utf-8");
        connection.setRequestMethod("POST");
        connection.setDoOutput(true);
        connection.setDoInput(true);
        connection.connect();

        // output
        OutputStream os = connection.getOutputStream();
        // os.write(strRequest.getBytes(), 0, strRequest.length());
        os.write(strRequest.getBytes("utf-8"));
        os.flush();
        os.close();

        // input
        InputStream is = connection.getInputStream();
        BufferedReader br = new BufferedReader(new InputStreamReader(is, "utf-8"));
        String line = "";
        String resValue = "";
        String parseStr = "";
        while ((line = br.readLine()) != null) {
            System.out.println(line);
            parseStr = line;

        }

        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
        DocumentBuilder builder = factory.newDocumentBuilder();
        InputSource temp = new InputSource();
        temp.setCharacterStream(new StringReader(parseStr));
        Document doc = builder.parse(temp); //xml?

        NodeList list = doc.getElementsByTagName("*");

        int i = 0;
        Element element;
        String contents;

        String contractNum = "";
        String customerId = "";
        while (list.item(i) != null) {
            element = (Element) list.item(i);
            if (element.hasChildNodes()) {
                contents = element.getFirstChild().getNodeValue();
                System.out.println(element.getNodeName() + " / " + element.getFirstChild().getNodeName());

                if (element.getNodeName().equals("sdp:NS_CONTRACT_NUM")) {
                    //                  resultStr = element.getFirstChild().getNodeValue();
                    contractNum = element.getFirstChild().getNodeValue();
                }
                if (element.getNodeName().equals("sdp:NS_CUSTOMER_ID")) {
                    customerId = element.getFirstChild().getNodeValue();
                }

                //               System.out.println(" >>>>> " + contents);
            }
            i++;
        }

        //         System.out.println("contractNum : " + contractNum + " / cusomerId : " + customerId);

        resultStr = getNcnFromContractnumAndCustomerId(contractNum, customerId);
        //         System.out.println("ncn : " + resultStr);

        //resultStr = resValue;         
        //         resultStr = java.net.URLDecoder.decode(resultStr, "euc-kr");
        connection.disconnect();

    } catch (Exception e) {
        e.printStackTrace();
    }

    return resultStr;
}

From source file:com.shopzilla.spring.util.config.ShopzillaNamespaceUtils.java

/**
 * Provides a user friendly description of an element based on its node name and, if available, its "id" attribute value. This is useful for creating error messages from within bean definition parsers.
 *//*from   ww  w.  j  a v  a2 s .  c  o  m*/
public String createElementDescription(Element element) {
    String elementId = "'" + element.getNodeName() + "'";
    String id = element.getAttribute("id");

    if (StringUtils.hasText(id)) {
        elementId += (" with id='" + id + "'");
    }

    return elementId;
}

From source file:fr.aliasource.webmail.server.proxy.client.http.SettingsMethod.java

public Map<String, String> getSettings() {
    Map<String, String> params = new HashMap<String, String>();
    params.put("token", token);

    Document doc = execute(params);
    Map<String, String> settings = new HashMap<String, String>();
    if (doc != null) {
        if (logger.isDebugEnabled()) {
            DOMUtils.logDom(doc);// w  w  w  . ja v a 2 s. c om
        }
        Element root = doc.getDocumentElement();
        NodeList cats = root.getChildNodes();
        for (int i = cats.getLength() - 1; i >= 0; i--) {
            Element cat = (Element) cats.item(i);
            String catName = cat.getNodeName();
            NodeList vals = cat.getChildNodes();
            for (int j = vals.getLength() - 1; j >= 0; j--) {
                Element val = (Element) vals.item(j);
                StringBuilder key = new StringBuilder(50);
                key.append(catName);
                key.append('/');
                key.append(val.getNodeName());
                String k = key.toString();
                settings.put(k, val.getAttribute("value"));
                GWT.log("added setting " + k + " (" + val.getAttribute("value") + ")", null);
            }
        }
    }

    settings.putAll(links);

    return settings;
}