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:com.fota.Link.sdpApi.java

public String GetBasicUserInfoAndMarketInfo2(String CTN) throws JDOMException {
    String resultStr = null;/*www . j  av a2s .c om*/
    try {
        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>";

        // 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 = null;
        String resValue = null;
        String parseStr = null;
        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;

        while (list.item(i) != null) {
            element = (Element) list.item(i);
            //            System.out.println("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
            //            System.out.println(element.getNodeName());
            if (element.hasChildNodes()) {
                contents = element.getFirstChild().getNodeValue();
                //            System.out.println("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%55");
                //            System.out.println(element.getNodeName());
                //            System.out.println(element.getFirstChild().getNodeName());
                if (element.getNodeName().equals("sdp:CUSTOMER_LINK_NAME")) {
                    resultStr = element.getFirstChild().getNodeValue();
                }
                System.out.println(contents);
            }
            i++;
        }
        //resultStr = resValue;         
        resultStr = java.net.URLDecoder.decode(resultStr, "euc-kr");
        connection.disconnect();

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

    return resultStr;
}

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

public String GetBasicUserInfoAndMarketInfo(String CTN) throws JDOMException {
    String resultStr = null;//from  w  w w.j  a  va 2  s  . co  m
    StringBuffer logSb = new StringBuffer();
    try {
        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>";

        logSb.append("\r\n---------- GetBasicUserInfoAndMarketInfo(" + CTN + ") ----------");
        logSb.append("\r\nendPointUrl : " + endPointUrl);
        logSb.append("\r\nrequest msg : \r\n==============================\r\n" + strRequest
                + "\r\n===============================\r\n");

        logger.info(logSb.toString());
        logSb.setLength(0);

        // 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 = null;
        String resValue = null;
        String parseStr = null;
        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;

        while (list.item(i) != null) {
            element = (Element) list.item(i);
            //            System.out.println("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
            //            System.out.println(element.getNodeName());
            if (element.hasChildNodes()) {
                contents = element.getFirstChild().getNodeValue();
                //            System.out.println("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%55");
                //            System.out.println(element.getNodeName());
                //            System.out.println(element.getFirstChild().getNodeName());
                if (element.getNodeName().equals("sdp:PREPAID")) {
                    resultStr = contents;
                }
                System.out.println(contents);
            }
            i++;
        }
        //resultStr = resValue;         

        connection.disconnect();

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

    return resultStr;
}

From source file:jef.tools.XMLUtils.java

/**
 * /*from   w ww  .  j av a2 s  .  c  o  m*/
 * 
 * <pre>
 * &lt;object&gt;
 * &lt;id&gt;100&lt;/id&gt;
 * &lt;name&gt;Jhon smith&lt;/name&gt;
 * &lt;phone&gt;130100000&lt;/phone&gt;
 * &lt;object&gt;
 * </pre>
 * 
 * XML??
 * 
 * <pre>
 * &lt;object id="100" name="Jhon smith" pone="130100000"&gt;
 * &lt;/object&gt;
 * </pre>
 * 
 * ?
 * 
 * @param e
 *            ??
 * @param keys
 *            ??
 */
public static void moveChildElementAsAttribute(Element e, String... keys) {
    NodeList nds = e.getChildNodes();
    for (Node node : toArray(nds)) {
        if (node.getNodeType() == Node.TEXT_NODE) {
            e.removeChild(node); // 
        }
        if (node.getNodeType() != Node.ELEMENT_NODE)
            continue;
        Element sub = (Element) node;
        String key = sub.getNodeName();
        if (keys.length == 0 || ArrayUtils.contains(keys, key)) {
            String value = nodeText(sub);
            e.setAttribute(key, value);
            e.removeChild(sub);
        }

    }
}

From source file:jef.tools.XMLUtils.java

/**
 * ?//from   ww  w.  j  a  va 2  s  .c o m
 * 
 * <pre>
 * &lt;object&gt;
 * &lt;id&gt;100&lt;/id&gt;
 * &lt;name&gt;Jhon smith&lt;/name&gt;
 * &lt;phone&gt;130100000&lt;/phone&gt;
 * &lt;object&gt;
 * </pre>
 * 
 * ?
 * {@code getAttributesInChildElements(objectNode, "name", "phone")}?
 * {name="Jhon smith"phone="130100000"}Map
 * ?????Map
 * 
 * @param parent
 *            
 * @param keys
 *            ?
 * @return ????Map
 */
public static Map<String, String> getAttributesInChildElements(Element parent, String... keys) {
    NodeList nds = parent.getChildNodes();
    Map<String, String> attribs = new HashMap<String, String>();
    for (int i = 0; i < nds.getLength(); i++) {
        Node node = nds.item(i);
        if (node.getNodeType() != Node.ELEMENT_NODE)
            continue;
        Element sub = (Element) node;
        String key = sub.getNodeName();
        if (keys.length == 0 || ArrayUtils.contains(keys, key)) {
            String value = nodeText(sub);
            if (attribs.containsKey(key)) {
                attribs.put(key, attribs.get(key) + "," + value);
            } else {
                attribs.put(key, value);
            }
        }
    }
    return attribs;
}

From source file:jef.tools.XMLUtils.java

/**
 * ?//from   w  ww  . ja v  a2s .co m
 * 
 * @param e
 *            
 * @param subElementAsAttr
 *            trueElement?<br>
 *            
 * 
 *            <pre>
 * &lt;Foo size="103" name="Karen"&gt;
 *   &lt;dob&gt;2012-4-12&lt;/dobh&gt;
 *   &lt;dod&gt;2052-4-12&lt;/dodh&gt;
 * &lt;/Foo&gt;
 * </pre>
 * 
 *            subElementAsAttr=falsedob,dod?true?
 * @return
 */
public static Map<String, String> getAttributesMap(Element e, boolean subElementAsAttr) {
    Map<String, String> attribs = new HashMap<String, String>();
    if (e == null)
        return attribs;
    NamedNodeMap nmp = e.getAttributes();
    for (int i = 0; i < nmp.getLength(); i++) {
        Attr child = (Attr) nmp.item(i);
        attribs.put(StringEscapeUtils.unescapeHtml(child.getName()),
                StringEscapeUtils.unescapeHtml(child.getValue()));
    }
    if (subElementAsAttr) {
        NodeList nds = e.getChildNodes();
        for (int i = 0; i < nds.getLength(); i++) {
            Node node = nds.item(i);
            if (node.getNodeType() != Node.ELEMENT_NODE)
                continue;
            Element sub = (Element) node;
            String key = sub.getNodeName();
            String value = nodeText(sub);
            if (attribs.containsKey(key)) {
                attribs.put(key, attribs.get(key) + "," + value);
            } else {
                attribs.put(key, value);
            }
        }
    }
    return attribs;
}

From source file:jef.tools.XMLUtils.java

/**
 * ??Tag Name?/*from   www .  jav a 2  s  .  com*/
 * 
 * @param parent
 *            
 * @param elementName
 *            ???
 * @return ??
 */
public static Element first(Node node, String tagName) {
    if (node == null)
        return null;
    NodeList nds = node.getChildNodes();
    for (int i = 0; i < nds.getLength(); i++) {
        Node child = nds.item(i);
        if (child.getNodeType() == Node.ELEMENT_NODE) {
            Element e = (Element) child;
            if (tagName == null || tagName.equals(e.getNodeName())) {
                return e;
            }
            // } else if (child.getNodeType() == Node.CDATA_SECTION_NODE) {
            // } else if (child.getNodeType() == Node.COMMENT_NODE) {
            // } else if (child.getNodeType() ==
            // Node.DOCUMENT_FRAGMENT_NODE) {
            // } else if (child.getNodeType() == Node.DOCUMENT_NODE) {
            // } else if (child.getNodeType() == Node.DOCUMENT_TYPE_NODE) {
            // } else if (child.getNodeType() == Node.ATTRIBUTE_NODE) {
            // } else if (child.getNodeType() == Node.TEXT_NODE) {
        }
    }
    return null;
}

From source file:jef.tools.XMLUtils.java

/**
 * Element(??)/*from w w w.  jav a 2  s . c  o  m*/
 * 
 * @param node
 *            
 * @param tagName
 *            ????nullElement
 * @return ??
 */
public static List<Element> childElements(Node node, String... tagName) {
    if (node == null)
        throw new NullPointerException("the input node can not be null!");
    List<Element> list = new ArrayList<Element>();
    NodeList nds = node.getChildNodes();
    if (tagName.length == 0 || tagName[0] == null) {// ?API
        tagName = null;
    }
    for (int i = 0; i < nds.getLength(); i++) {
        Node child = nds.item(i);
        if (child.getNodeType() == Node.ELEMENT_NODE) {
            Element e = (Element) child;
            if (tagName == null || ArrayUtils.contains(tagName, e.getNodeName())) {
                list.add(e);
            }
        } else if (child.getNodeType() == Node.CDATA_SECTION_NODE) {
        } else if (child.getNodeType() == Node.COMMENT_NODE) {
        } else if (child.getNodeType() == Node.DOCUMENT_FRAGMENT_NODE) {

        } else if (child.getNodeType() == Node.DOCUMENT_NODE) {

        } else if (child.getNodeType() == Node.DOCUMENT_TYPE_NODE) {
        } else if (child.getNodeType() == Node.ATTRIBUTE_NODE) {
        } else if (child.getNodeType() == Node.TEXT_NODE) {
        }
    }
    return list;
}

From source file:jef.tools.XMLUtils.java

private static Element[] findElementsByNameAndAttribute(Node root, String tagName, String attribName,
        String keyword, boolean findFirst) {
    List<Element> result = new ArrayList<Element>();
    List<Element> es;
    if (root instanceof Document) {
        es = toElementList(((Document) root).getElementsByTagName(tagName));
    } else if (root instanceof Element) {
        es = toElementList(((Element) root).getElementsByTagName(tagName));
    } else if (root instanceof DocumentFragment) {
        Element eRoot = (Element) first(root, Node.ELEMENT_NODE);
        es = toElementList(eRoot.getElementsByTagName(tagName));
        if (eRoot.getNodeName().equals(tagName))
            es.add(eRoot);/*w  ww.ja v  a 2  s .  c o  m*/
    } else {
        throw new UnsupportedOperationException(root + " is a unknow Node type to find");
    }
    for (Element e : es) {
        String s = attrib(e, attribName);
        if (s != null && s.equals(keyword)) {
            result.add(e);
            if (findFirst)
                break;
        }
    }
    return result.toArray(new Element[result.size()]);
}

From source file:com.opensymphony.xwork3.config.providers.XmlConfigurationProvider.java

/**
 * Build a map of ResultConfig objects from below a given XML element.
 *///from www  . ja  v  a  2 s.  co  m
protected List<ExceptionMappingConfig> buildExceptionMappings(Element element,
        PackageConfig.Builder packageContext) {
    NodeList exceptionMappingEls = element.getElementsByTagName("exception-mapping");

    List<ExceptionMappingConfig> exceptionMappings = new ArrayList<ExceptionMappingConfig>();

    for (int i = 0; i < exceptionMappingEls.getLength(); i++) {
        Element ehElement = (Element) exceptionMappingEls.item(i);

        if (ehElement.getParentNode().equals(element)
                || ehElement.getParentNode().getNodeName().equals(element.getNodeName())) {
            String emName = ehElement.getAttribute("name");
            String exceptionClassName = ehElement.getAttribute("exception");
            String exceptionResult = ehElement.getAttribute("result");

            Map<String, String> params = XmlHelper.getParams(ehElement);

            if (StringUtils.isEmpty(emName)) {
                emName = exceptionResult;
            }

            ExceptionMappingConfig ehConfig = new ExceptionMappingConfig.Builder(emName, exceptionClassName,
                    exceptionResult).addParams(params)
                            //                        .location(DomHelper.getLocationObject(ehElement))
                            .build();
            exceptionMappings.add(ehConfig);
        }
    }

    return exceptionMappings;
}