Example usage for org.w3c.dom Text getData

List of usage examples for org.w3c.dom Text getData

Introduction

In this page you can find the example usage for org.w3c.dom Text getData.

Prototype

public String getData() throws DOMException;

Source Link

Document

The character data of the node that implements this interface.

Usage

From source file:TreeDumper2.java

private void dumpTextNode(Text node, String indent) {
    System.out.println(indent + "TEXT length=" + node.getLength());
    System.out.println(indent + "  " + node.getData());
}

From source file:eionet.cr.util.xml.ConversionsParser.java

/**
 *
 * @param conversionElement/*  www. ja  va  2  s. com*/
 */
private void readConversion(Element conversionElement) {

    if (conversionElement != null) {

        boolean isRDFConversion = false;
        NodeList nl = conversionElement.getElementsByTagName("result_type");
        if (nl != null && nl.getLength() > 0) {
            Element element = (Element) nl.item(0);
            Text text = (Text) element.getFirstChild();
            if (text != null) {
                String resultType = text.getData();
                if (resultType != null && resultType.equals("RDF"))
                    isRDFConversion = true;
            }
        }

        if (isRDFConversion && (rdfConversionId == null || rdfConversionId.length() == 0)) {

            nl = conversionElement.getElementsByTagName("convert_id");
            if (nl != null && nl.getLength() > 0) {
                Element element = (Element) nl.item(0);
                Text text = (Text) element.getFirstChild();
                if (text != null) {
                    this.rdfConversionId = text.getData();
                }
            }

            nl = conversionElement.getElementsByTagName("xsl");
            if (nl != null && nl.getLength() > 0) {
                Element element = (Element) nl.item(0);
                Text text = (Text) element.getFirstChild();
                if (text != null) {
                    this.rdfConversionXslFileName = text.getData();
                }
            }
        }
    }
}

From source file:com.duroty.lucene.parser.HtmlParser.java

/**
 * DOCUMENT ME!/*w w w  . ja va2  s.co  m*/
 *
 * @return DOCUMENT ME!
 */
public String getTitle() {
    if (this.title != null) {
        return this.title;
    }

    if (element == null) {
        return null;
    }

    String title = null;

    NodeList nl = element.getElementsByTagName("title");

    if (nl.getLength() > 0) {
        Element titleElement = ((Element) nl.item(0));
        Text text = (Text) titleElement.getFirstChild();

        if (text != null) {
            title = text.getData();
        }
    }

    return title;
}

From source file:com.konakart.bl.modules.payment.globalcollect.GlobalCollectUtils.java

/**
 * @param gatewayResp/*ww  w .  j  a  v  a 2s  .c  om*/
 * @param arrayLocation
 * @return a Map of objects found in the XML string returned by the gateway
 * @throws Exception
 */
public Map<String, String> parseGlobalCollectResponseToMap(String gatewayResp, String arrayLocation)
        throws Exception {
    Map<String, String> xmlMap = new HashMap<String, String>();

    if (gatewayResp != null) {
        try {
            DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance();
            DocumentBuilder builder = builderFactory.newDocumentBuilder();
            ByteArrayInputStream bais = new ByteArrayInputStream(gatewayResp.getBytes());
            Document doc = builder.parse(bais);
            int arrayIndx = -1;

            // get the root node
            Node rootnode = doc.getDocumentElement();
            String rootName = rootnode.getNodeName();

            if (rootName != "XML") {
                throw new KKException("Unexpected root element in Initial Response: " + rootName);
            }

            // get all elements
            NodeList list = doc.getElementsByTagName("*");
            for (int i = 0; i < list.getLength(); i++) {
                Node node = list.item(i);
                String name = node.getNodeName();
                if (name != null) {
                    Node firstNode = node.getFirstChild();
                    if (firstNode == null) {
                        continue;
                    }
                    if (firstNode instanceof Text) {
                        Text dataNode = (Text) firstNode;
                        String path = getXmlPath(firstNode, arrayIndx, arrayLocation);
                        xmlMap.put(path, dataNode.getData());
                        continue;
                    } else {
                        if (arrayLocation != null && getXmlPath(firstNode).equals(arrayLocation)) {
                            arrayIndx++;
                        }
                    }
                }
            }

            if (log.isDebugEnabled()) {
                log.debug("Map: " + xmlMap);
            }
        } catch (Exception e) {
            // Problems parsing the XML
            if (log.isDebugEnabled()) {
                log.debug("Problems parsing Initial response: " + e.getMessage());
            }
            throw e;
        }
    }

    return xmlMap;
}

From source file:com.karlchu.mo.web.sitemesh.MyConfigLoader.java

private void populatePathMapper(State newState, NodeList patternNodes, String role, String name,
        String decorId) {/*  w w w  .j  a  v a2s.co  m*/
    for (int j = 0; j < patternNodes.getLength(); j++) {
        Element p = (Element) patternNodes.item(j);
        Text patternText = (Text) p.getFirstChild();
        if (patternText != null) {
            String pattern = patternText.getData().trim();
            if (pattern != null) {
                if (newState.pathMapperMap.get(decorId) == null) {
                    newState.pathMapperMap.put(decorId, new PathMapper());
                }
                if (role != null) {
                    // concatenate name and role to allow more
                    // than one decorator per role
                    newState.pathMapperMap.get(decorId).put(name + role, pattern);
                } else {
                    newState.pathMapperMap.get(decorId).put(name, pattern);
                }
            }
        }
    }
}

From source file:edu.lternet.pasta.client.ReservationsManager.java

/**
 * Return the number of subscriptions for a given user.
 * //from  w w w.  j  a  va  2  s.  c  o m
 * @return  the number of subscriptions for this user.
 */
public int numberOfReservations() throws Exception {
    int numberOfReservations = 0;

    if (this.uid != null && !this.uid.equals("public")) {
        String xmlString = listActiveReservations();

        DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();

        try {
            DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
            InputStream inputStream = IOUtils.toInputStream(xmlString, "UTF-8");
            Document document = documentBuilder.parse(inputStream);
            Element documentElement = document.getDocumentElement();
            NodeList reservations = documentElement.getElementsByTagName("reservation");
            int nReservations = reservations.getLength();

            for (int i = 0; i < nReservations; i++) {
                Node reservationNode = reservations.item(i);
                NodeList reservationChildren = reservationNode.getChildNodes();
                String principal = "";
                for (int j = 0; j < reservationChildren.getLength(); j++) {
                    Node childNode = reservationChildren.item(j);
                    if (childNode instanceof Element) {
                        Element reservationElement = (Element) childNode;

                        if (reservationElement.getTagName().equals("principal")) {
                            Text text = (Text) reservationElement.getFirstChild();
                            if (text != null) {
                                principal = text.getData().trim();
                                if (principal.startsWith(this.uid)) {
                                    numberOfReservations++;
                                }
                            }
                        }
                    }
                }
            }
        } catch (Exception e) {
            logger.error("Exception:\n" + e.getMessage());
            e.printStackTrace();
            throw new PastaEventException(e.getMessage());
        }
    }

    return numberOfReservations;
}

From source file:com.interface21.beans.factory.xml.XmlBeanFactory.java

/**
 * Make the horrible DOM API slightly more bearable:
 * get the text value we know this element contains
 *//*from   ww w  .jav a  2  s  .c  o m*/
private String getTextValue(Element e) {
    NodeList nl = e.getChildNodes();
    if (nl.item(0) == null) {
        // treat empty value as empty String
        return "";
    }
    if (nl.getLength() != 1 || !(nl.item(0) instanceof Text)) {
        throw new FatalBeanException("Unexpected element or type mismatch: " + "expected single node of "
                + nl.item(0).getClass() + " to be of type Text: " + "found " + e, null);
    }
    Text t = (Text) nl.item(0);
    // This will be a String
    return t.getData();
}

From source file:com.konakart.actions.gateways.AuthorizeNetBaseAction.java

/**
 * Common code to send a message and receive a response
 * //from w w w. java2 s  . c o  m
 * @param kkAppEng
 * @param msg
 * @param methodName
 * @param retAttr
 * @param custId
 * @param profileId
 * @return Returns the value of the attribute called retAttr
 * @throws Exception
 */
protected String sendMsgToGateway(KKAppEng kkAppEng, StringBuffer msg, String methodName, String retAttr,
        int custId, String profileId) throws Exception {
    // Get a response from the gateway
    String gatewayResp = getGatewayResponse(msg, methodName);

    // Now process the XML response
    String ret = null;

    if (gatewayResp != null) {
        try {
            DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance();
            DocumentBuilder builder = builderFactory.newDocumentBuilder();
            ByteArrayInputStream bais = new ByteArrayInputStream(gatewayResp.getBytes());
            Document doc = builder.parse(bais);

            boolean val = validateGatewayResponse(kkAppEng, msg, methodName, custId, profileId, doc);
            if (val) {
                NodeList list = doc.getElementsByTagName(retAttr);
                if (list != null && list.getLength() == 1) {
                    Node node = list.item(0);
                    Text datanode = (Text) node.getFirstChild();
                    ret = datanode.getData();
                }
                if (log.isDebugEnabled()) {
                    log.debug("AuthorizeNet " + methodName + " response data:" + "\n    " + retAttr
                            + "                              = " + ret);
                }
            }
            return ret;

        } catch (Exception e) {
            // Problems parsing the XML
            if (log.isDebugEnabled()) {
                log.debug("Problems parsing AuthorizeNet " + methodName + " response: " + e.getMessage());
            }
            throw e;
        }
    }

    return retAttr;

}

From source file:edu.lternet.pasta.client.ReservationsManager.java

/**
 * Builds an options list for the number of reservations the end user is
 * requesting with a single button click.
 * //from   w  ww  .j a va2 s .  co m
 * @return the options HTML to be inserted into the <select> element
 * @throws PastaEventException
 */
public String reservationsDeleteOptionsHTML() throws Exception {
    String html;
    StringBuilder sb = new StringBuilder("");

    if (this.uid != null && !this.uid.equals("public")) {
        String xmlString = listActiveReservations();

        DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();

        try {
            DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
            InputStream inputStream = IOUtils.toInputStream(xmlString, "UTF-8");
            Document document = documentBuilder.parse(inputStream);
            Element documentElement = document.getDocumentElement();
            NodeList reservations = documentElement.getElementsByTagName("reservation");
            int nReservations = reservations.getLength();

            for (int i = 0; i < nReservations; i++) {
                Node reservationNode = reservations.item(i);
                NodeList reservationChildren = reservationNode.getChildNodes();
                String docid = "";
                String principal = "";
                boolean include = false;
                for (int j = 0; j < reservationChildren.getLength(); j++) {
                    Node childNode = reservationChildren.item(j);
                    if (childNode instanceof Element) {
                        Element reservationElement = (Element) childNode;
                        if (reservationElement.getTagName().equals("principal")) {
                            Text text = (Text) reservationElement.getFirstChild();
                            if (text != null) {
                                principal = text.getData().trim();
                                if (principal.startsWith(this.uid)) {
                                    include = true;
                                }
                            }
                        } else if (reservationElement.getTagName().equals("docid")) {
                            Text text = (Text) reservationElement.getFirstChild();
                            if (text != null) {
                                docid = text.getData().trim();
                            }
                        }
                    }
                }
                if (include) {
                    sb.append(String.format("  <option value=\"%s\">%s</option>\n", docid, docid));
                }
            }
        } catch (Exception e) {
            logger.error("Exception:\n" + e.getMessage());
            e.printStackTrace();
            throw new PastaEventException(e.getMessage());
        }
    }

    html = sb.toString();
    return html;
}

From source file:com.konakart.actions.gateways.AuthorizeNetBaseAction.java

/**
 * Common code to validate the gateway response.
 * //from w  ww .j a  v a2s  .  c o m
 * @param kkAppEng
 * @param msg
 * @param methodName
 * @param custId
 * @param profileId
 * @param doc
 * @return Returns true if there were no gateway errors
 */
protected boolean validateGatewayResponse(KKAppEng kkAppEng, StringBuffer msg, String methodName, int custId,
        String profileId, Document doc) {

    String resultCode = null;
    String code = null;
    String text = null;

    // get all elements
    int count = 0;
    NodeList list = doc.getElementsByTagName("*");
    for (int i = 0; i < list.getLength(); i++) {
        if (count == 3) {
            break;
        }
        Node node = list.item(i);
        String name = node.getNodeName();
        if (name != null) {
            if (name.equals("resultCode")) {
                Text datanode = (Text) node.getFirstChild();
                resultCode = datanode.getData();
                count++;
            } else if (name.equals("code")) {
                Text datanode = (Text) node.getFirstChild();
                code = datanode.getData();
                count++;
            } else if (name.equals("text")) {
                Text datanode = (Text) node.getFirstChild();
                text = datanode.getData();
                count++;
            }
        }
    }

    if (log.isDebugEnabled()) {
        log.debug("AuthorizeNet " + methodName + " response data:"
                + "\n    resultCode                                   = " + resultCode
                + "\n    code                                         = " + code
                + "\n    text                                         = " + text);
    }

    if (resultCode != null && resultCode.equalsIgnoreCase("Error")) {
        String errorMsg = kkAppEng.getMsg("after.login.body.gateway.problem", new String[] { "" });
        addActionError(errorMsg);
        log.warn("AuthorizeNet " + methodName + " response data" + " for customer id : " + custId
                + ((profileId != null) ? (" profile id : " + profileId) : "")
                + "\n    resultCode                                   = " + resultCode
                + "\n    code                                         = " + code
                + "\n    text                                         = " + text);
        return false;
    }
    return true;
}