Example usage for org.w3c.dom Element getTextContent

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

Introduction

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

Prototype

public String getTextContent() throws DOMException;

Source Link

Document

This attribute returns the text content of this node and its descendants.

Usage

From source file:eu.elf.license.LicenseParser.java

/**
 * Creates LicenseConcludeResponseObject from the concludeLicense operation's response string
 * // ww w.  j  a  va 2 s .c o m
 * @param response
 * @return
 * @throws Exception
 */
public static LicenseConcludeResponseObject parseConcludeLicenseResponse(String response) throws Exception {
    LicenseConcludeResponseObject lcro = new LicenseConcludeResponseObject();

    try {
        Document xmlDoc = LicenseParser.createXMLDocumentFromString(response);
        NodeList LicenseReferenceNL = xmlDoc.getElementsByTagNameNS("http://www.52north.org/license/0.3.2",
                "LicenseReference");

        for (int i = 0; i < LicenseReferenceNL.getLength(); i++) {
            Element attributeStatementElement = (Element) LicenseReferenceNL.item(i);

            NodeList attributeElementList = attributeStatementElement
                    .getElementsByTagNameNS("urn:oasis:names:tc:SAML:2.0:assertion", "Attribute");

            for (int j = 0; j < attributeElementList.getLength(); j++) {
                Element attributeElement = (Element) attributeElementList.item(j);
                Element AttributeValueElement = (Element) attributeElement
                        .getElementsByTagName("AttributeValue").item(0);

                NamedNodeMap licenseReferenceElementAttributeMap = attributeElement.getAttributes();

                for (int k = 0; k < licenseReferenceElementAttributeMap.getLength(); k++) {
                    Attr attrs = (Attr) licenseReferenceElementAttributeMap.item(k);

                    if (attrs.getNodeName().equals("Name")) {
                        if (attrs.getNodeValue().equals("urn:opengeospatial:ows4:geodrm:NotOnOrAfter")) {
                            lcro.setValidTo(AttributeValueElement.getTextContent());
                        }
                        if (attrs.getNodeValue().equals("urn:opengeospatial:ows4:geodrm:ProductID")) {
                            lcro.setProductId(AttributeValueElement.getTextContent());
                        }
                        if (attrs.getNodeValue().equals("urn:opengeospatial:ows4:geodrm:LicenseID")) {
                            lcro.setLicenseId(AttributeValueElement.getTextContent());
                        }
                    }

                }

            }

        }

    } catch (Exception e) {
        throw e;
    }

    return lcro;
}

From source file:eu.elf.license.LicenseParser.java

/**
 * Parses a list of active licenses from GetLicenseReferences response string
 * //  w  ww  .ja va2  s  . c om
 * @param xml   - xml response
 * @return      - ArrayList of license identifiers that are active
 * @throws Exception
 */
public static ArrayList<String> parseActiveLicensesFromGetLicenseReferencesResponse(String xml)
        throws Exception {
    ArrayList<String> activeLicenses = new ArrayList<String>();

    try {
        Document xmlDoc = createXMLDocumentFromString(xml);

        NodeList licenseReferenceList = xmlDoc.getElementsByTagNameNS("http://www.52north.org/license/0.3.2",
                "LicenseReference");

        for (int i = 0; i < licenseReferenceList.getLength(); i++) {
            Element licenseReferenceElement = (Element) licenseReferenceList.item(i);

            NodeList attributeElementList = licenseReferenceElement
                    .getElementsByTagNameNS("urn:oasis:names:tc:SAML:2.0:assertion", "Attribute");

            for (int j = 0; j < attributeElementList.getLength(); j++) {
                Element attributeElement = (Element) attributeElementList.item(j);
                Element attributeValueElement = (Element) attributeElement
                        .getElementsByTagNameNS("urn:oasis:names:tc:SAML:2.0:assertion", "AttributeValue")
                        .item(0);

                NamedNodeMap attributeMap = attributeElement.getAttributes();

                for (int k = 0; k < attributeMap.getLength(); k++) {
                    Attr attrs = (Attr) attributeMap.item(k);
                    if (attrs.getNodeName().equals("Name")) {

                        if (attrs.getNodeValue().equals("urn:opengeospatial:ows4:geodrm:LicenseID")) {
                            activeLicenses.add(attributeValueElement.getTextContent());
                        }
                    }

                }

            }

        }

    } catch (Exception e) {
        throw e;
    }

    return activeLicenses;
}

From source file:org.finra.jtaf.core.parsing.CommandLibraryParser.java

private final InvocationTarget processInvocationTarget(Element elem, MessageCollector mc)
        throws ParsingException {
    InvocationTarget retval = null;/*www  .  j ava 2 s .co  m*/
    final String name = elem.getNodeName().toLowerCase();
    if (name.equals("command")) {
        retval = processCommand(elem, mc);
    } else if (name.equals("function")) {
        retval = processFunction(elem, mc);
    } else {
        throw new UnexpectedElementException(elem);
    }

    final Element usage = ParserHelper.getOptionalElement(elem, "usage");
    if (usage != null) {
        retval.setUsage(usage.getTextContent());
    }

    final Element requiredParameters = ParserHelper.getOptionalElement(elem, "requiredParameters");
    if (requiredParameters != null) {
        for (Element child : ParserHelper.getChildren(requiredParameters)) {
            AttributeHelper ah = new AttributeHelper(child);
            retval.addRequiredParameter(ah.getRequiredString("name"));
        }
    }

    final Element optionalParameters = ParserHelper.getOptionalElement(elem, "optionalParameters");
    if (optionalParameters != null) {
        for (Element child : ParserHelper.getChildren(optionalParameters)) {
            AttributeHelper ah = new AttributeHelper(child);
            retval.addOptionalParameter(ah.getRequiredString("name"));
        }
    }

    final Element produces = ParserHelper.getOptionalElement(elem, "produces");
    if (produces != null) {
        for (Element child : ParserHelper.getChildren(produces)) {
            AttributeHelper ah = new AttributeHelper(child);
            retval.addProduction(ah.getRequiredString("name"));
        }
    }

    return retval;
}

From source file:org.jboss.windup.config.spring.namespace.java.JavaHintBeanParser.java

@Override
protected AbstractBeanDefinition parseInternal(Element element, ParserContext parserContext) {
    BeanDefinitionBuilder beanBuilder = BeanDefinitionBuilder
            .rootBeanDefinition(JavaPatternHintProcessor.class);
    beanBuilder.addPropertyValue("regexPattern", element.getAttribute("regex"));

    if (element.hasAttribute("hint")) {
        beanBuilder.addPropertyValue("hint", element.getAttribute("hint"));
    } else {/*from  w ww .j a  v  a 2 s .  c  om*/
        String markdown = element.getTextContent();

        String lines[] = markdown.split("\\r?\\n");
        StringBuilder markdownRebuilder = new StringBuilder();

        for (String line : lines) {
            line = StringUtils.trim(line);
            if (line != null) {
                markdownRebuilder.append(line).append(SystemUtils.LINE_SEPARATOR);
            }
        }
        beanBuilder.addPropertyValue("hint", markdownRebuilder.toString());
    }

    if (element.hasAttribute("source-type")) {
        beanBuilder.addPropertyValue("sourceType", element.getAttribute("source-type"));
    }
    if (element.hasAttribute("effort")) {
        beanBuilder.addPropertyValue("effort", Integer.parseInt(element.getAttribute("effort")));
    }

    return beanBuilder.getBeanDefinition();
}

From source file:org.jboss.windup.config.spring.namespace.simple.RegexHintBeanParser.java

@Override
protected AbstractBeanDefinition parseInternal(Element element, ParserContext parserContext) {
    BeanDefinitionBuilder beanBuilder = BeanDefinitionBuilder
            .rootBeanDefinition(RegexPatternHintProcessor.class);
    beanBuilder.addPropertyValue("regexPattern", element.getAttribute("regex"));

    if (element.hasAttribute("hint")) {
        beanBuilder.addPropertyValue("hint", element.getAttribute("hint"));
    } else {//  w w  w.j a v a  2  s.c om
        String markdown = element.getTextContent();

        String lines[] = markdown.split("\\r?\\n");
        StringBuilder markdownRebuilder = new StringBuilder();

        for (int i = 0; i < lines.length; i++) {
            String line = lines[i];

            line = StringUtils.trim(line);
            if (line != null) {
                markdownRebuilder.append(line);
            }
            //test to see if it is last line...
            if (i < lines.length - 1) {
                markdownRebuilder.append(SystemUtils.LINE_SEPARATOR);
            }
        }
        beanBuilder.addPropertyValue("hint", markdownRebuilder.toString());
    }

    if (element.hasAttribute("effort")) {
        beanBuilder.addPropertyValue("effort", Integer.parseInt(element.getAttribute("effort")));
    }

    return beanBuilder.getBeanDefinition();
}

From source file:org.apache.servicemix.jms.JmsConsumerEndpointTest.java

public void testConsumerDefaultInOut() throws Exception {
    JmsComponent component = new JmsComponent();
    JmsConsumerEndpoint endpoint = new JmsConsumerEndpoint();
    endpoint.setService(new QName("jms"));
    endpoint.setEndpoint("endpoint");
    endpoint.setTargetService(new QName("echo"));
    endpoint.setListenerType("default");
    endpoint.setConnectionFactory(connectionFactory);
    endpoint.setDestinationName("destination");
    endpoint.setReplyDestinationName("replyDestination");
    endpoint.setMarshaler(new DefaultConsumerMarshaler(JbiConstants.IN_OUT));
    component.setEndpoints(new JmsConsumerEndpoint[] { endpoint });
    container.activateComponent(component, "servicemix-jms");

    jmsTemplate.convertAndSend("destination", "<hello>world</hello>");
    TextMessage msg = (TextMessage) jmsTemplate.receive("replyDestination");
    Element e = sourceTransformer.toDOMElement(new StringSource(msg.getText()));
    assertEquals("hello", e.getTagName());
    assertEquals("world", e.getTextContent());
    Thread.sleep(500);// w w  w.  j  a v a2s. co m
}

From source file:org.apache.servicemix.jms.JmsConsumerEndpointTest.java

public void testConsumerDefaultInOutJmsTx() throws Exception {
    JmsComponent component = new JmsComponent();
    JmsConsumerEndpoint endpoint = new JmsConsumerEndpoint();
    endpoint.setService(new QName("jms"));
    endpoint.setEndpoint("endpoint");
    endpoint.setTargetService(new QName("echo"));
    endpoint.setListenerType("default");
    endpoint.setConnectionFactory(connectionFactory);
    endpoint.setDestinationName("destination");
    endpoint.setReplyDestinationName("replyDestination");
    endpoint.setTransacted("jms");
    endpoint.setMarshaler(new DefaultConsumerMarshaler(JbiConstants.IN_OUT));
    component.setEndpoints(new JmsConsumerEndpoint[] { endpoint });
    container.activateComponent(component, "servicemix-jms");

    jmsTemplate.convertAndSend("destination", "<hello>world</hello>");
    TextMessage msg = (TextMessage) jmsTemplate.receive("replyDestination");
    Element e = sourceTransformer.toDOMElement(new StringSource(msg.getText()));
    assertEquals("hello", e.getTagName());
    assertEquals("world", e.getTextContent());
    Thread.sleep(500);//from w  w  w  .j  a v  a  2s. com
}

From source file:com.concursive.connect.web.modules.wiki.utils.HTMLToWikiUtils.java

public static void processLink(StringBuffer sb, Element element, String appendToCRLF, String contextPath,
        int projectId) {
    // take the href and rip out the document section
    // output the text associated with the link
    String href = element.getAttribute("href").trim();

    // See if the href has content, it won't if it is an image link
    String value = element.getTextContent();

    // Create the markup
    //"<a class=\"wikiLink\" title=\"UI Configurability\" href=\"/team/ProjectManagement.do?command=ProjectCenter&amp;section=Wiki&amp;pid=177&amp;subject=UI+Configurability\">UI Configurability</a></p>\n" +
    sb.append("[[");
    if (isExternalLink(href, contextPath)) {
        // [[http://www.concursive.com Concursive]]
        sb.append(href);//from  ww  w .j  av  a2 s  .c  o  m
        if (StringUtils.hasText(value) && !href.equals(value)) {
            // The link has a name
            sb.append(" ").append(StringUtils.fromHtmlValue(value.trim()));
        }
    } else {
        URLControllerBean url = new URLControllerBean(href, contextPath);
        if ("wiki".equals(url.getDomainObject())
                && (url.getProjectId() == projectId || url.getProjectId() == -1)) {
            String subject = url.getObjectValue();
            // The incoming link will have a + for a space
            subject = StringUtils.replace(subject, "+", " ");
            // The incoming link will be url encoded
            subject = StringUtils.jsUnEscape(subject);
            sb.append(subject);
            // Base the display on the content of the 'a' tag
            if (StringUtils.hasText(value) && !subject.equals(StringUtils.fromHtmlValue(value))) {
                sb.append("|").append(StringUtils.fromHtmlValue(value));
            }
        } else if (!url.hasDomainObject()) {
            // "[[|9999999:project|project unique id|project title]]"
            sb.append("|");
            sb.append(url.getProjectId());
            sb.append(":profile");
            sb.append("|");
            sb.append(url.getProjectTitle());
            if (StringUtils.hasText(value)) {
                sb.append("|");
                sb.append(StringUtils.fromHtmlValue(value));
            }
        } else {
            // "[[|9999999:issue|200|Some issue]]"
            sb.append("|");
            sb.append(url.getProjectId());
            sb.append(":").append(url.getDomainObject());
            sb.append("|");
            String subject = url.getObjectValue();
            // The incoming link will have a + for a space
            subject = StringUtils.replace(subject, "+", " ");
            // The incoming link will be url encoded
            subject = StringUtils.jsUnEscape(subject);
            sb.append(subject);
            if (StringUtils.hasText(value)) {
                sb.append("|");
                sb.append(StringUtils.fromHtmlValue(value));
            }
        }
    }
    sb.append("]]");
}

From source file:org.apache.streams.gnip.powertrack.ActivityXMLActivitySerializer.java

private String setContentIfEmpty(String xml) throws Exception {
    DocumentBuilder docBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
    InputSource is = new InputSource(new StringReader(xml));
    Document doc = docBuilder.parse(is);
    doc.getDocumentElement().normalize();
    Element base = (Element) doc.getElementsByTagName("entry").item(0);
    NodeList nodeList = base.getChildNodes();
    //        for(int i=0; i < nodeList.getLength(); ++i) {
    //            System.out.println(nodeList.item(i).getNodeName());
    //        }/*from  w w  w.j  a  va2 s . c o m*/
    Element obj = (Element) base.getElementsByTagName("activity:object").item(0);
    Element content = (Element) obj.getElementsByTagName("content").item(0);
    //        System.out.println("Number of child nodes : "+content.getChildNodes().getLength());
    //        System.out.println("Text content before : "+content.getTextContent());
    if (content.getTextContent() == null || content.getTextContent().equals("")) {
        content.setTextContent(" ");
    }
    //        System.out.println("Number of child nodes after : "+content.getChildNodes().getLength());
    //        System.out.println("Text content after : "+content.getTextContent());
    TransformerFactory tf = TransformerFactory.newInstance();
    Transformer transformer = tf.newTransformer();
    transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
    StringWriter writer = new StringWriter();
    transformer.transform(new DOMSource(doc), new StreamResult(writer));
    String output = writer.getBuffer().toString().replaceAll("\n|\r", "");
    //        System.out.println(output);
    //        System.out.println(output);
    //        System.out.println(content);
    return output;
}

From source file:net.dontdrinkandroot.lastfm.api.ws.AbstractLastfmWebServices.java

/**
 * Check if the Response contains an error element and throw an Exception with the corresponding
 * error code and message./*www  .  jav  a2  s . c  om*/
 * 
 * @param document
 *            The Response Document to check.
 */
private void checkForError(final Document document) throws LastfmWebServicesException {

    final NodeList errors = document.getDocumentElement().getElementsByTagName("error");
    if (errors != null && errors.getLength() > 0) {
        final Element error = (Element) errors.item(0);
        throw new LastfmWebServicesException(Integer.parseInt(error.getAttribute("code")),
                StringUtils.trim(error.getTextContent()));
    }
}