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:dpfmanager.shell.interfaces.gui.component.dessign.DessignController.java

public String readDescription(File file) {
    try {//from  w w w.  ja va  2 s  . c  o m
        DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
        DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
        Document doc = dBuilder.parse(file);
        NodeList nList = doc.getDocumentElement().getChildNodes();
        for (int i = 0; i < nList.getLength(); i++) {
            org.w3c.dom.Node node = nList.item(i);
            if (node.getNodeType() == org.w3c.dom.Node.ELEMENT_NODE) {
                Element elem = (Element) node;
                if (elem.getTagName().equals("description")) {
                    return elem.getTextContent();
                }
            }
        }
        return null;
    } catch (Exception e) {
        return null;
    }
}

From source file:com.cloud.agent.api.storage.OVFHelper.java

private OVFDiskController getController(Element controllerItem) {
    OVFDiskController dc = new OVFDiskController();
    NodeList child = controllerItem.getChildNodes();
    for (int l = 0; l < child.getLength(); l++) {
        if (child.item(l) instanceof Element) {
            Element el = (Element) child.item(l);
            if ("rasd:ElementName".equals(el.getNodeName())) {
                dc._name = el.getTextContent();
            }/*from  www. j av  a  2s.c  om*/
            if ("rasd:ResourceSubType".equals(el.getNodeName())) {
                dc._subType = el.getTextContent();
            }
        }
    }
    return dc;
}

From source file:edu.cornell.mannlib.vitro.webapp.web.templatemodels.customlistview.CustomListViewConfigFile.java

public String getSelectQuery(boolean collated, boolean editing) {
    Element cloned = (Element) selectQueryElement.cloneNode(true);

    if (!collated) {
        removeChildElements(cloned, TAG_COLLATED);
    }/*from  w  w w.j ava 2  s. c o m*/
    if (editing) {
        removeChildElements(cloned, TAG_CRITICAL);
    }

    return cloned.getTextContent();
}

From source file:honeypot.services.WepawetServiceImpl.java

/**
 * Parses the processing messages into the correct queues.
 * @param input The input stream containing the response from the Wepawet processing service.
 * @throws ParserConfigurationException If an error occurs parsing the XML response.
 * @throws SAXException If an error occurs processing the XML response.
 * @throws IOException If an I/O Error occurs.
 *///w  w  w .ja  va2s  .  c  o  m
private void handleProcessMsg(final InputStream input)
        throws ParserConfigurationException, SAXException, IOException {
    final DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
    final DocumentBuilder db = dbf.newDocumentBuilder();
    final Document doc = db.parse(input);
    doc.getDocumentElement().normalize();
    Element response = doc.getDocumentElement();
    String state = response.getAttribute("state");
    if ("ok".equals(state)) {
        // Success.
        final Element hash = (Element) doc.getElementsByTagName("hash").item(0);
        WepawetProcessing wepawetProcessing = new WepawetProcessing();
        wepawetProcessing.setHash(hash.getTextContent());
        wepawetProcessing.setStatus("queued");
        wepawetProcessing.setCreated(new Date());
        entityManager.persist(wepawetProcessing);
    } else {
        // Failure.
        final Element error = (Element) doc.getElementsByTagName("error").item(0);
        WepawetError wepawetError = new WepawetError();
        wepawetError.setCode(error.getAttribute("code"));
        wepawetError.setMessage(error.getAttribute("message"));
        wepawetError.setCreated(new Date());
        // Save the error to the database.
        entityManager.persist(wepawetError);
    }
}

From source file:com.cloud.agent.api.storage.OVFHelper.java

private Element getParentNode(final NodeList itemList, final Element childItem) {
    NodeList cn = childItem.getChildNodes();
    String parent_id = null;//from   w ww  .j  a  v  a 2s  . co  m
    for (int l = 0; l < cn.getLength(); l++) {
        if (cn.item(l) instanceof Element) {
            Element el = (Element) cn.item(l);
            if ("rasd:Parent".equals(el.getNodeName())) {
                parent_id = el.getTextContent();
            }
        }
    }
    if (parent_id != null) {
        for (int k = 0; k < itemList.getLength(); k++) {
            Element item = (Element) itemList.item(k);
            NodeList child = item.getChildNodes();
            for (int l = 0; l < child.getLength(); l++) {
                if (child.item(l) instanceof Element) {
                    Element el = (Element) child.item(l);
                    if ("rasd:InstanceID".equals(el.getNodeName())
                            && el.getTextContent().trim().equals(parent_id)) {
                        return item;
                    }
                }
            }
        }
    }
    return null;
}

From source file:com.cloud.agent.api.storage.OVFHelper.java

private OVFDiskController getControllerType(final NodeList itemList, final String diskId) {
    for (int k = 0; k < itemList.getLength(); k++) {
        Element item = (Element) itemList.item(k);
        NodeList cn = item.getChildNodes();
        for (int l = 0; l < cn.getLength(); l++) {
            if (cn.item(l) instanceof Element) {
                Element el = (Element) cn.item(l);
                if ("rasd:HostResource".equals(el.getNodeName())
                        && (el.getTextContent().contains("ovf:/file/" + diskId)
                                || el.getTextContent().contains("ovf:/disk/" + diskId))) {
                    Element oe = getParentNode(itemList, item);
                    Element voe = oe;
                    while (oe != null) {
                        voe = oe;//from w  w  w .  ja  va2 s . c o  m
                        oe = getParentNode(itemList, voe);
                    }
                    return getController(voe);
                }
            }
        }
    }
    return null;
}

From source file:com.cloud.test.stress.StressTestDirectAttach.java

public static Element queryAsyncJobResult(String host, InputStream inputStream) {
    Element returnBody = null;/*from w w w  . ja v  a 2  s  . co  m*/

    Map<String, String> values = getSingleValueFromXML(inputStream, new String[] { "jobid" });
    String jobId = values.get("jobid");

    if (jobId == null) {
        s_logger.error("Unable to get a jobId");
        return null;
    }

    //s_logger.info("Job id is " + jobId); 
    String resultUrl = host + "?command=queryAsyncJobResult&jobid=" + jobId;
    HttpClient client = new HttpClient();
    HttpMethod method = new GetMethod(resultUrl);
    while (true) {
        try {
            client.executeMethod(method);
            //s_logger.info("Method is executed successfully. Following url was sent " + resultUrl);
            InputStream is = method.getResponseBodyAsStream();
            DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
            DocumentBuilder builder = factory.newDocumentBuilder();
            Document doc = builder.parse(is);
            returnBody = doc.getDocumentElement();
            doc.getDocumentElement().normalize();
            Element jobStatusTag = (Element) returnBody.getElementsByTagName("jobstatus").item(0);
            String jobStatus = jobStatusTag.getTextContent();
            if (jobStatus.equals("0")) {
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                }
            } else {
                break;
            }

        } catch (Exception ex) {
            s_logger.error(ex);
        }
    }
    return returnBody;
}

From source file:cz.fi.muni.xkremser.editor.server.AuthenticationServlet.java

@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    HttpSession session = req.getSession(true);
    String url = (String) session.getAttribute(HttpCookies.TARGET_URL);
    String root = (URLS.LOCALHOST() ? "http://" : "https://") + req.getServerName() + (URLS.LOCALHOST()
            ? (req.getServerPort() == 80 || req.getServerPort() == 443 ? "" : (":" + req.getServerPort()))
            : "") + URLS.ROOT() + (URLS.LOCALHOST() ? "?gwt.codesvr=127.0.0.1:9997" : "");
    String authHeader = req.getHeader("Authorization");
    if (authHeader != null) {
        String decodedHeader = decode(req, authHeader);
        String pass = configuration.getHttpBasicPass();
        if (pass == null || "".equals(pass.trim()) || pass.length() < 4) {
            requrireAuthentication(resp);
        }/*from  w w w .  j  a va 2  s  .  c  o  m*/
        if (decodedHeader.equals(ALLOWED_PREFIX + pass)) {
            session.setAttribute(HttpCookies.TARGET_URL, null);
            session.setAttribute(HttpCookies.SESSION_ID_KEY,
                    "https://www.google.com/profiles/109255519115168093543");
            session.setAttribute(HttpCookies.NAME_KEY, "admin");
            session.setAttribute(HttpCookies.ADMIN, HttpCookies.ADMIN_YES);
            ACCESS_LOGGER.info("LOG IN: [" + FORMATTER.format(new Date()) + "] User "
                    + decodedHeader.substring(0, decodedHeader.indexOf(":")) + " with openID BASIC_AUTH and IP "
                    + req.getRemoteAddr());
            URLS.redirect(resp, url == null ? root : url);
            return;
        } else {
            requrireAuthentication(resp);
            return;
        }
    }
    session.setAttribute(HttpCookies.TARGET_URL, null);
    String token = req.getParameter("token");

    String appID = configuration.getOpenIDApiKey();
    String openIdurl = configuration.getOpenIDApiURL();
    RPX rpx = new RPX(appID, openIdurl);
    Element e = null;
    try {
        e = rpx.authInfo(token);
    } catch (ConnectionException connEx) {
        requrireAuthentication(resp);
        return;
    }
    String idXPath = "//identifier";
    String nameXPath = "//displayName";
    XPathFactory xpfactory = XPathFactory.newInstance();
    XPath xpath = xpfactory.newXPath();
    String identifier = null;
    String name = null;
    try {
        XPathExpression expr1 = xpath.compile(idXPath);
        XPathExpression expr2 = xpath.compile(nameXPath);
        NodeList nodes1 = (NodeList) expr1.evaluate(e.getOwnerDocument(), XPathConstants.NODESET);
        NodeList nodes2 = (NodeList) expr2.evaluate(e.getOwnerDocument(), XPathConstants.NODESET);
        Element el = null;
        if (nodes1.getLength() != 0) {
            el = (Element) nodes1.item(0);
        }
        if (el != null) {
            identifier = el.getTextContent();
        }
        if (nodes2.getLength() != 0) {
            el = (Element) nodes2.item(0);
        }
        if (el != null) {
            name = el.getTextContent();
        }
    } catch (XPathExpressionException e1) {
        e1.printStackTrace();
    }
    if (identifier != null && !"".equals(identifier)) {
        ACCESS_LOGGER.info("LOG IN: [" + FORMATTER.format(new Date()) + "] User " + name + " with openID "
                + identifier + " and IP " + req.getRemoteAddr());
        int userStatus = UserDAO.UNKNOWN;
        try {
            userStatus = userDAO.isSupported(identifier);
        } catch (DatabaseException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        }
        switch (userStatus) {
        case UserDAO.UNKNOWN:
            // TODO handle DB error (inform user)
            break;
        case UserDAO.USER:
            // HttpCookies.setCookie(req, resp, HttpCookies.SESSION_ID_KEY,
            // identifier);
            session.setAttribute(HttpCookies.SESSION_ID_KEY, identifier);
            session.setAttribute(HttpCookies.NAME_KEY, name);
            URLS.redirect(resp, url == null ? root : url);
            break;
        case UserDAO.ADMIN:
            // HttpCookies.setCookie(req, resp, HttpCookies.SESSION_ID_KEY,
            // identifier);
            // HttpCookies.setCookie(req, resp, HttpCookies.ADMIN,
            // HttpCookies.ADMIN_YES);
            session.setAttribute(HttpCookies.SESSION_ID_KEY, identifier);
            session.setAttribute(HttpCookies.NAME_KEY, name);
            session.setAttribute(HttpCookies.ADMIN, HttpCookies.ADMIN_YES);
            URLS.redirect(resp, url == null ? root : url);
            break;
        case UserDAO.NOT_PRESENT:
        default:
            session.setAttribute(HttpCookies.UNKNOWN_ID_KEY, identifier);
            session.setAttribute(HttpCookies.NAME_KEY, name);
            URLS.redirect(resp, root + URLS.INFO_PAGE);
            break;
        }
    } else {
        URLS.redirect(resp, root + (URLS.LOCALHOST() ? URLS.LOGIN_LOCAL_PAGE : URLS.LOGIN_PAGE));
    }

    // System.out.println("ID:" + identifier);

    // if user is supported redirect to homepage else show him a page that he
    // has to be added to system first by admin

}

From source file:fr.acxio.tools.agia.alfresco.configuration.NodeDefinitionParser.java

protected List<BeanDefinition> parseAssociations(Element sElement) {
    List<Element> childRefElements = DomUtils.getChildElementsByTagName(sElement, NODEDEF_ASSOC_REF);
    List<Element> childQueryElements = DomUtils.getChildElementsByTagName(sElement, NODEDEF_ASSOC_QUERY);

    ManagedList<BeanDefinition> children = new ManagedList<BeanDefinition>(
            childRefElements.size() + childQueryElements.size());

    for (Element element : childRefElements) {
        BeanDefinitionBuilder aRefAssocBuilder = BeanDefinitionBuilder
                .genericBeanDefinition(RefAssociationDefinitionFactoryBean.class);
        aRefAssocBuilder.addPropertyValue("type", element.getAttribute(PROPDEF_TYPE));
        aRefAssocBuilder.addPropertyValue("reference", element.getTextContent());
        children.add(aRefAssocBuilder.getBeanDefinition());
    }// w w  w. j a  v a 2s  .  co m

    for (Element element : childQueryElements) {
        BeanDefinitionBuilder aQueryAssocBuilder = BeanDefinitionBuilder
                .genericBeanDefinition(QueryAssociationDefinitionFactoryBean.class);
        aQueryAssocBuilder.addPropertyValue("type", element.getAttribute(PROPDEF_TYPE));
        aQueryAssocBuilder.addPropertyValue("queryLanguage", element.getAttribute(PROPDEF_QUERY_LANGUAGE));
        aQueryAssocBuilder.addPropertyValue("query", element.getTextContent());
        children.add(aQueryAssocBuilder.getBeanDefinition());
    }

    return children;
}