Example usage for org.w3c.dom Document getElementsByTagName

List of usage examples for org.w3c.dom Document getElementsByTagName

Introduction

In this page you can find the example usage for org.w3c.dom Document getElementsByTagName.

Prototype

public NodeList getElementsByTagName(String tagname);

Source Link

Document

Returns a NodeList of all the Elements in document order with a given tag name and are contained in the document.

Usage

From source file:io.personium.test.utils.DavResourceUtils.java

/**
 * PROPFIND???OData?????????. <br />
 * p:odata?????? OData ??????.//from w w w .ja va2  s . co  m
 * @param res PROPFIND?
 */
public static void assertIsODataCol(TResponse res) {
    Document propfind = res.bodyAsXml();
    NodeList list;
    list = propfind.getElementsByTagName("p:odata");
    assertThat(list.getLength()).isGreaterThanOrEqualTo(1);
}

From source file:io.personium.test.utils.DavResourceUtils.java

/**
 * PROPFIND???Service?????????. <br />
 * p:path?????? Service ??????.//from  w  w  w  . jav  a 2 s .com
 * @param res PROPFIND?
 */
public static void assertIsServiceCol(TResponse res) {
    Document propfind = res.bodyAsXml();
    NodeList list;
    list = propfind.getElementsByTagName("p:path");
    assertThat(list.getLength()).isGreaterThanOrEqualTo(1);
}

From source file:com.fujitsu.dc.test.utils.DavResourceUtils.java

/**
 * XML????????????????.//w  ww. ja  va2 s  . c  o  m
 * @param res PROPFIND?
 * @param tagName ?????
 * @param expectedNode ?
 */
public static void assertEqualsNodeInResXml(TResponse res, String tagName, Node expectedNode) {
    Document propfind = res.bodyAsXml();
    NodeList list;
    list = propfind.getElementsByTagName(tagName);
    for (int i = 0; i < list.getLength(); i++) {
        Node item = list.item(i);
        if (item.isEqualNode(expectedNode)) {
            return;
        }
    }
    // ???????????
    fail();
}

From source file:com.fujitsu.dc.test.utils.DavResourceUtils.java

private static boolean containsUrl(final String expectedUrl, TResponse res) {
    Document propfind = res.bodyAsXml();
    NodeList list;// ww  w  . j  a  v  a2 s.  com
    list = propfind.getElementsByTagName("href");
    int index = 0;
    boolean isMatch = false;
    for (index = 0; index < list.getLength(); index++) {
        org.w3c.dom.Node node = list.item(index);
        NodeList children = node.getChildNodes();
        assertEquals(1, children.getLength());
        Text item = (Text) children.item(0);
        if (expectedUrl.equals(item.getNodeValue())) {
            isMatch = true;
        }
    }
    return isMatch;
}

From source file:canreg.client.dataentry.Convert.java

public static boolean convertDictionary(
        canreg.client.gui.management.CanReg4MigrationInternalFrame.MigrationTask task, String filepath,
        String dictionaryfile, String regcode) {
    Connection conn = null;//w ww  .  java2 s. co  m
    Statement stmt = null;
    ResultSet rs = null;
    boolean success = false;

    String xml = Globals.CANREG_SERVER_SYSTEM_CONFIG_FOLDER + Globals.FILE_SEPARATOR + regcode + ".xml";
    String dic = filepath + Globals.FILE_SEPARATOR + regcode + ".txt";

    File xmlfile = new File(xml);
    File dicfile = new File(dic);

    try {
        String query = "SELECT * FROM \"" + dictionaryfile + "\"";
        conn = DriverManager.getConnection("jdbc:paradox:///" + filepath.replaceAll("\\\\", "/"));
        stmt = conn.createStatement();
        rs = stmt.executeQuery(query);

        txt_fw = new FileWriter(dicfile);
        txt_bw = new BufferedWriter(txt_fw);

        if (xmlfile.exists()) {
            DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
            // Use the factory to create a builder
            DocumentBuilder builder = factory.newDocumentBuilder();
            Document doc = builder.parse(xmlfile);
            doc.getDocumentElement().normalize();
            // Get a list of all elements in the document
            debugOut("Migrating dictionary " + dictionaryfile);
            NodeList nlist = doc.getElementsByTagName("ns3:dictionary");
            for (int i = 0; i < nlist.getLength(); i++) {
                Node nNode = nlist.item(i);
                if (nNode.getNodeType() == Node.ELEMENT_NODE) {
                    Element eElement = (Element) nNode;
                    int dicId = Integer.parseInt(
                            eElement.getElementsByTagName("ns3:dictionary_id").item(0).getTextContent());
                    String dicName = eElement.getElementsByTagName("ns3:name").item(0).getTextContent();
                    String dicType = eElement.getElementsByTagName("ns3:type").item(0).getTextContent();
                    String dic_head = "#" + dicId + " ----" + dicName + "\n";
                    txt_bw.write(dic_head);
                    // Processing dictionary child nodes.
                    processChildNodes(task, dicId, dicType, filepath, dictionaryfile);
                } //if node ends
            } //for ends
        } //file if ends
        else {
            debugOut("Files not found");
        }
        txt_bw.close();
        success = true;
    } catch (SQLException ex) {
        Logger.getLogger(Convert.class.getName()).log(Level.SEVERE, null, ex);
    } catch (IOException ex) {
        Logger.getLogger(Convert.class.getName()).log(Level.SEVERE, null, ex);
    } catch (NumberFormatException ex) {
        Logger.getLogger(Convert.class.getName()).log(Level.SEVERE, null, ex);
    } catch (ParserConfigurationException ex) {
        Logger.getLogger(Convert.class.getName()).log(Level.SEVERE, null, ex);
    } catch (DOMException ex) {
        Logger.getLogger(Convert.class.getName()).log(Level.SEVERE, null, ex);
    } catch (SAXException ex) {
        Logger.getLogger(Convert.class.getName()).log(Level.SEVERE, null, ex);
    }
    return success;
}

From source file:com.ikon.util.FormUtils.java

/**
 * Parse params.xml definitions// w ww. j a  v  a  2  s. c  o  m
 * 
 * @return A List parameter elements.
 */
public static List<FormElement> parseReportParameters(InputStream is) throws ParseException {
    log.debug("parseReportParameters({})", is);
    List<FormElement> params = new ArrayList<FormElement>();

    try {
        DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
        dbf.setNamespaceAware(true);
        dbf.setValidating(true);
        ErrorHandler handler = new ErrorHandler();
        // EntityResolver resolver = new LocalResolver(Config.DTD_BASE);
        DocumentBuilder db = dbf.newDocumentBuilder();
        db.setErrorHandler(handler);
        db.setEntityResolver(resolver);

        if (is != null) {
            Document doc = db.parse(is);
            doc.getDocumentElement().normalize();
            NodeList nlForm = doc.getElementsByTagName("report-parameters");

            for (int i = 0; i < nlForm.getLength(); i++) {
                Node nForm = nlForm.item(i);

                if (nForm.getNodeType() == Node.ELEMENT_NODE) {
                    NodeList nlField = nForm.getChildNodes();
                    params = parseField(nlField);
                }
            }
        }
    } catch (ParserConfigurationException e) {
        throw new ParseException(e.getMessage(), e);
    } catch (SAXException e) {
        throw new ParseException(e.getMessage(), e);
    } catch (IOException e) {
        throw new ParseException(e.getMessage(), e);
    }

    log.debug("parseReportParameters: {}", params);
    return params;
}

From source file:com.ikon.util.FormUtils.java

/**
 * Parse form.xml definitions/*from w  ww  .  ja v  a  2s.c o m*/
 * 
 * @return A Map with all the forms and its form elements.
 */
public static Map<String, List<FormElement>> parseWorkflowForms(InputStream is) throws ParseException {
    log.debug("parseWorkflowForms({})", is);
    Map<String, List<FormElement>> forms = new HashMap<String, List<FormElement>>();

    try {
        DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
        dbf.setNamespaceAware(true);
        dbf.setValidating(true);
        ErrorHandler handler = new ErrorHandler();
        // EntityResolver resolver = new LocalResolver(Config.DTD_BASE);
        DocumentBuilder db = dbf.newDocumentBuilder();
        db.setErrorHandler(handler);
        db.setEntityResolver(resolver);

        if (is != null) {
            Document doc = db.parse(is);
            doc.getDocumentElement().normalize();
            NodeList nlForm = doc.getElementsByTagName("workflow-form");

            for (int i = 0; i < nlForm.getLength(); i++) {
                Node nForm = nlForm.item(i);

                if (nForm.getNodeType() == Node.ELEMENT_NODE) {
                    String taskName = nForm.getAttributes().getNamedItem("task").getNodeValue();
                    NodeList nlField = nForm.getChildNodes();
                    List<FormElement> fe = parseField(nlField);
                    forms.put(taskName, fe);
                }
            }
        }
    } catch (ParserConfigurationException e) {
        throw new ParseException(e.getMessage(), e);
    } catch (SAXException e) {
        throw new ParseException(e.getMessage(), e);
    } catch (IOException e) {
        throw new ParseException(e.getMessage(), e);
    }

    log.debug("parseWorkflowForms: {}", forms);
    return forms;
}

From source file:co.pugo.convert.Configuration.java

/**
 * helper method to get element content/*from  w  w w .  j  ava2 s  .  co m*/
 * @param document xml document
 * @param tag xml tag
 * @return element content
 */
private String getConfigElementTextContent(Document document, String tag) {
    return document.getElementsByTagName(tag).item(0).getTextContent();
}

From source file:de.erdesignerng.model.serializer.xml30.XMLDomainSerializer.java

@Override
public void deserialize(Model aModel, Document aDocument) {
    NodeList theElements = aDocument.getElementsByTagName(DOMAIN);
    for (int i = 0; i < theElements.getLength(); i++) {
        Element theDomainElement = (Element) theElements.item(i);

        Domain theDomain = new Domain();
        deserializeProperties(theDomainElement, theDomain);
        theDomain.setConcreteType(/*from  ww w.  j av a2s. com*/
                aModel.getDomainDataTypes().findByName(theDomainElement.getAttribute(DATATYPE)));

        // Bug Fixing 2876916 [ERDesignerNG] Reverse-Eng. PgSQL VARCHAR max-length wrong
        theDomain.setSize(safeInteger(theDomainElement.getAttribute(SIZE)));
        theDomain.setFraction(safeInteger(theDomainElement.getAttribute(FRACTION)));
        theDomain.setScale(safeInteger(theDomainElement.getAttribute(SCALE)));

        String theNullable = theDomainElement.getAttribute(NULLABLE);
        if (!StringUtils.isEmpty(theNullable)) {
            theDomain.setNullable(Boolean.parseBoolean(theNullable));
        }

        aModel.getDomains().add(theDomain);
    }
}

From source file:com.hpe.application.automation.tools.srf.run.RunFromSrfBuilder.java

public static JSONObject getSrfConnectionData(AbstractBuild<?, ?> build, PrintStream logger) {
    try {//  ww  w.j  a  v a  2 s  .c om
        CookieHandler.setDefault(new CookieManager(null, CookiePolicy.ACCEPT_ALL));
        // Create all-trusting host name verifier
        HostnameVerifier allHostsValid = new HostnameVerifier() {
            public boolean verify(String hostname, SSLSession session) {
                return true;
            }
        };
        HttpsURLConnection.setDefaultHostnameVerifier(allHostsValid);
        String path = build.getProject().getParent().getRootDir().toString();
        path = path.concat("/com.hpe.application.automation.tools.settings.SrfServerSettingsBuilder.xml");
        File file = new File(path);
        DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
        DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
        Document document = documentBuilder.parse(file);
        // This also shows how you can consult the global configuration of the builder
        JSONObject connectionData = new JSONObject();

        String app = document.getElementsByTagName("srfAppName").item(0).getTextContent();
        String tenant = app.substring(1, app.indexOf('_'));
        String secret = document.getElementsByTagName("srfSecretName").item(0).getTextContent();
        String server = document.getElementsByTagName("srfServerName").item(0).getTextContent();
        boolean https = true;
        if (!server.startsWith("https://")) {
            if (!server.startsWith("http://")) {
                String tmp = server;
                server = "https://";
                server = server.concat(tmp);
            } else
                https = false;
        }
        URL urlTmp = new URL(server);
        if (urlTmp.getPort() == -1) {
            if (https)
                server = server.concat(":443");
            else
                server = server.concat(":80");
        }
        String srfProxy = "";
        String srfTunnel = "";
        try {
            srfProxy = document.getElementsByTagName("srfProxyName").item(0).getTextContent().trim();
            srfTunnel = document.getElementsByTagName("srfTunnelPath").item(0).getTextContent();
        } catch (Exception e) {
            throw e;
        }
        connectionData.put("app", app);
        connectionData.put("tunnel", srfTunnel);
        connectionData.put("secret", secret);
        connectionData.put("server", server);
        connectionData.put("https", (https) ? "True" : "False");
        connectionData.put("proxy", srfProxy);
        connectionData.put("tenant", tenant);
        return connectionData;
    } catch (ParserConfigurationException e) {
        logger.print(e.getMessage());
        logger.print("\n\r");
    } catch (SAXException | IOException e) {
        logger.print(e.getMessage());
    }
    return null;
}