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:org.openmrs.module.xforms.aop.XformsLocationAdvisor.java

/**
 * Refreshes a location in a given xforms select1 node.
 * /*from  w w  w. ja v a  2 s.  c o m*/
 * @param operation the refresh operation.
 * @param locationSelect1Element the location select1 node.
 * @param location the location.
 * @param oldName the location name before editing.
 * @param doc the xforms document.
 * @param xform the xform object.
 * @param xformsService the xforms service.
 * @throws Exception
 */
private void refreshLocationWithId(RefreshOperation operation, Element locationSelect1Element,
        Location location, String oldName, Document doc, Xform xform, XformsService xformsService)
        throws Exception {
    String sLocationId = location.getLocationId().toString();

    if (operation == RefreshOperation.DELETE || operation == RefreshOperation.EDIT) {

        //Get all xf:item nodes.
        NodeList elements = locationSelect1Element
                .getElementsByTagName(XformBuilder.PREFIX_XFORMS + ":" + "item");

        boolean locationFound = false;

        //Look for an item node having an id attribute equal to the locationId.
        for (int index = 0; index < elements.getLength(); index++) {
            Element itemElement = (Element) elements.item(index);
            if (!sLocationId.equals(itemElement.getAttribute(XformBuilder.ATTRIBUTE_ID)))
                continue; //Not the location we are looking for.

            //If the location has been deleted, then remove their item node from the xforms document.
            if (operation == RefreshOperation.DELETE) {
                locationSelect1Element.removeChild(itemElement);
            } else {
                //New name for the location after editing.
                String newName = XformBuilder.getLocationName(location);

                //If name has not changed, then just do nothing.
                if (newName.equals(oldName))
                    return;

                //If the location name has been edited, then change the xf:label node text.
                NodeList labels = itemElement.getElementsByTagName(XformBuilder.PREFIX_XFORMS + ":" + "label");

                //If the existing xforms label is not the same as the previous location's name, then
                //do not change it, possibly the location wants the xforms value not to match the location's name.
                Element labelElement = (Element) labels.item(0);
                if (!oldName.equals(labelElement.getTextContent()))
                    return;

                labelElement.setTextContent(newName);
            }

            locationFound = true;
            break;
        }

        //select1 node does not have the location to delete or edit.
        if (!locationFound) {
            if (operation == RefreshOperation.DELETE)
                return;

            addNewLocationNode(doc, locationSelect1Element, location);
        }

    } else {

        //Older versions of openmrs call AOP advisors more than once hence resulting into duplicates
        //if this check is not performed.
        if (locationExists(locationSelect1Element, sLocationId))
            return;

        //Add new location
        addNewLocationNode(doc, locationSelect1Element, location);
    }

    xform.setXformXml(XformsUtil.doc2String(doc));
    xformsService.saveXform(xform);
}

From source file:at.ac.tuwien.big.testsuite.impl.validator.WaiValidator.java

private boolean extractDescription(Element container, StringBuilder sb) {
    for (Element e : DomUtils.asList(container.getChildNodes())) {
        if ("span".equals(e.getTagName()) && e.getAttribute("class").contains("gd_msg")) {
            String text = e.getTextContent();
            Matcher matcher = CHECK_PATTERN.matcher(text);

            if (matcher.matches() && IGNORED_MESSAGES.contains(matcher.group(1))) {
                return false;
            }/* w  w  w  .  j  a v a 2s  . com*/

            sb.append(text.replaceAll("\\s*\\n\\s*", " ").trim());
        } else if ("div".equals(e.getTagName()) && e.getAttribute("class").contains("gd_question_section")) {
            sb.append('\n');
            sb.append(e.getTextContent().replaceAll("\\s*\\n\\s*", " ").trim());
        } else if ("table".equals(e.getTagName()) && e.getAttribute("class").contains("data")) {
            sb.append('\n');
            sb.append(DomUtils.textByXpath(e, ".//em").replaceAll("\\s*\\n\\s*", " ").trim());
            sb.append('\n');
            sb.append(DomUtils.textByXpath(e, ".//pre").replaceAll("\\s*\\n\\s*", " ").trim());
        }
    }

    return true;
}

From source file:com.obidea.semantika.app.ApplicationFactory.java

private void addDataSourceProperties(Element parent) {
    NodeList properties = parent.getChildNodes();
    for (int i = 0; i < properties.getLength(); i++) {
        Node childNode = properties.item(i);
        if (childNode instanceof Element) {
            Element node = (Element) properties.item(i);
            String name = node.getAttribute("name"); //$NON-NLS-1$
            String value = node.getTextContent();
            mProperties.setProperty(name, value);
        }/*  ww w.  j a v  a2 s  .c om*/
    }
}

From source file:imageencode.ImageEncode.java

public void decode(final String filePath, final Element node) throws IOException {
    final File imageFile = new File(filePath);
    final OutputStream os = new FileOutputStream(imageFile);
    String encodedImage = node.getTextContent();
    // String decoded = decode(encodedImage);
    // os.write(decoded);
    final Runtime runtime = Runtime.getRuntime();
    System.out.println("Free memory : " + runtime.freeMemory());
    String[] sei = encodedImage.split("\r\n");
    // System.out.println(encodedImage);
    System.out.println("Free memory : " + runtime.freeMemory());
    for (final String element : sei) {
        final byte[] byteImage = Base64.decodeBase64(element);
        try {// ww  w  .  j av  a 2  s .  c  o m
            os.write(byteImage);
        } catch (final FileNotFoundException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
    os.close();
    System.out.println("Free memory : " + runtime.freeMemory());
    encodedImage = null;
    sei = null;
    System.gc();
    System.out.println("Free memory : " + runtime.freeMemory());
}

From source file:com.evolveum.midpoint.util.DOMUtil.java

public static QName resolveQName(Element element) {
    return resolveQName(element, element.getTextContent());
}

From source file:com.evolveum.midpoint.util.DOMUtil.java

public static QName getQNameValue(Element element) {
    return resolveQName(element, element.getTextContent());
}

From source file:com.moviejukebox.reader.MovieNFOReader.java

/**
 * Parse Sets from the XML NFO file//  w  w  w .  j av a2 s  . c o  m
 *
 * @param nlElements
 * @param movie
 */
private static void parseSets(NodeList nlElements, Movie movie) {
    Node nElements;
    for (int looper = 0; looper < nlElements.getLength(); looper++) {
        nElements = nlElements.item(looper);
        if (nElements.getNodeType() == Node.ELEMENT_NODE) {
            Element eId = (Element) nElements;

            String setOrder = eId.getAttribute("order");
            if (StringUtils.isNumeric(setOrder)) {
                movie.addSet(eId.getTextContent(), Integer.parseInt(setOrder));
            } else {
                movie.addSet(eId.getTextContent());
            }
        }
    }
}

From source file:org.apache.cxf.fediz.service.idp.STSAuthenticationProvider.java

protected List<Claim> parseClaimsInAssertion(org.opensaml.saml2.core.Assertion assertion) {
    List<org.opensaml.saml2.core.AttributeStatement> attributeStatements = assertion.getAttributeStatements();
    if (attributeStatements == null || attributeStatements.isEmpty()) {
        LOG.debug("No attribute statements found");
        return Collections.emptyList();
    }/*  w  ww  . j a  v a 2 s .c om*/

    List<Claim> collection = new ArrayList<Claim>();
    Map<String, Claim> claimsMap = new HashMap<String, Claim>();

    for (org.opensaml.saml2.core.AttributeStatement statement : attributeStatements) {
        LOG.debug("parsing statement: {}", statement.getElementQName());
        List<org.opensaml.saml2.core.Attribute> attributes = statement.getAttributes();
        for (org.opensaml.saml2.core.Attribute attribute : attributes) {
            LOG.debug("parsing attribute: {}", attribute.getName());
            Claim c = new Claim();
            // Workaround for CXF-4484 
            // Value of Attribute Name not fully qualified
            // if NameFormat is http://schemas.xmlsoap.org/ws/2005/05/identity/claims
            // but ClaimType value must be fully qualified as Namespace attribute goes away
            URI attrName = URI.create(attribute.getName());
            if (ClaimTypes.URI_BASE.toString().equals(attribute.getNameFormat()) && !attrName.isAbsolute()) {
                c.setClaimType(URI.create(ClaimTypes.URI_BASE + "/" + attribute.getName()));
            } else {
                c.setClaimType(URI.create(attribute.getName()));
            }
            c.setIssuer(assertion.getIssuer().getNameQualifier());

            List<String> valueList = new ArrayList<String>();
            for (XMLObject attributeValue : attribute.getAttributeValues()) {
                Element attributeValueElement = attributeValue.getDOM();
                String value = attributeValueElement.getTextContent();
                LOG.debug(" [{}]", value);
                valueList.add(value);
            }
            mergeClaimToMap(claimsMap, c, valueList);
        }
    }
    collection.addAll(claimsMap.values());
    return collection;

}

From source file:com.amalto.core.history.accessor.UnaryFieldAccessor.java

@Override
public String get() {
    Element element = getElement();
    Node textChild = element.getFirstChild();
    if (textChild != null) {
        if (textChild instanceof Text) {
            return element.getTextContent();// get node value can not handle bracket well
        } else {//from w  ww  . ja  va 2 s.  c  om
            return textChild.getNodeValue();
        }
    } else {
        return StringUtils.EMPTY;
    }
}

From source file:com.cisco.dvbu.ps.common.adapters.config.SoapHttpConfig.java

private void parseCallback(Element eElement) throws AdapterException {
    XPath xpath = XPathFactory.newInstance().newXPath();
    try {//from ww w .  j a v a2  s  . com
        SoapHttpConnectorCallback cb = new SoapHttpConnectorCallback();
        cb.setOperation(eElement.getAttribute(AdapterConstants.CONNECTOR_SE_NAME));
        //         log.debug("Operation: " + cb.getOperation());
        cb.setEndpoint(eElement.getAttribute(AdapterConstants.CONNECTOR_SH_ENDPOINT));
        //         log.debug("Endpoint: " + cb.getEndpoint());
        cb.setName(cb.getEndpoint() + AdapterConstants.CONNECTOR_EP_SEPARATOR + cb.getOperation());
        Element e = (Element) xpath.evaluate(AdapterConstants.XPATH_CONN_CB_SOAPACTION, eElement,
                XPathConstants.NODE);
        cb.setAction(e.getTextContent());
        //         log.debug(e.getNodeName() + ": " + e.getTextContent());
        e = (Element) xpath.evaluate(AdapterConstants.XPATH_CONN_CB_RQ_BODY, eElement, XPathConstants.NODE);
        cb.setRequestBodyXsl(e.getTextContent().trim());
        //         log.debug(e.getNodeName() + ": " + e.getTextContent());
        e = (Element) xpath.evaluate(AdapterConstants.XPATH_CONN_CB_RS_BODY, eElement, XPathConstants.NODE);
        cb.setResponseBodyXsl(e.getTextContent().trim());
        //         log.debug(e.getNodeName() + ": " + e.getTextContent());
        connCallbacks.put(cb.getName(), cb);
    } catch (Exception e) {
        log.error("Configuration File Error! One or more mandatory configuration options are missing");
        throw new AdapterException(401,
                "Configuration File Error! One or more mandatory configuration options are missing.", e);
    }
}