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:de.erdesignerng.model.serializer.xml50.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);
        deserializeCommentElement(theDomainElement, theDomain);

        theDomain.setConcreteType(/*from ww  w  . j ava  2  s . co m*/
                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:hydrograph.engine.bhse.xmlparser.preprocessor.ParseExternalSchemaTest.java

@Test
public void itShouldGetTheExternalFields() throws ParseException {

    String[] args = new String[] { "-xmlpath", "testData/XMLFiles/DelimitedInputAndOutput.xml", "-param",
            "PATH=testData/Input/delimitedInputFile", "-param", "PATH2=testData/XMLFiles/schema2.xml", "-param",
            "input=input'1", "-param", "out&put=output" };
    try {/* w ww.j a va 2  s .  co m*/
        ParameterSubstitutor parameterSubstitutor = new ParameterSubstitutor(new UserParameters(args));

        String xmlContents = XmlParsingUtils.getXMLStringFromPath(args[1]);

        ParseExternalSchema parseExternalSchema = new ParseExternalSchema(
                parameterSubstitutor.substitute(xmlContents), parameterSubstitutor);

        Document xmlDom = parseExternalSchema.getXmlDom();

        NodeList nodes = xmlDom.getElementsByTagName("schema");

        Assert.assertEquals(3, nodes.item(0).getChildNodes().getLength());
    } catch (IOException e) {
        LOG.error("", e);
    }
}

From source file:com.nebhale.gpxconverter.StandardParser.java

@Override
public String parseName(Document document) {
    NodeList nodes = document.getElementsByTagName("name");
    return nodes.item(nodes.getLength() - 1).getTextContent();
}

From source file:com.dell.asm.asmcore.asmmanager.util.discovery.DeviceTypeCheckUtil.java

private static DiscoverDeviceType checkCompllent(String ipAddress, InfrastructureDevice device) {
    String compllentHtml = String.format("https://%s/SystemExplorer.asp", ipAddress);
    DiscoverDeviceType retVal = DiscoverDeviceType.UNKNOWN;
    CredentialEntity cred = getCredentialDAO().findById(device.getStorageCredentialId());
    try {// w  w  w  . j a v a2s  . co m
        String compellentResponse = getHTML(compllentHtml);
        if (compellentResponse != null && compellentResponse.toUpperCase().contains("COMPELLENT")) {
            // Ok, we know this device is compellent, but we don't know if it's the master or a slave.
            // Make a compellent api call to get the IP of the master, then compare it to this IP.
            // if they don't match, this is a slave and we want to skip it.

            //                -bash-4.1# java -jar /etc/puppetlabs/puppet/modules/compellent/lib/puppet/files/CompCU-6.3.jar -host 172.17.10.41 -user Admin -password P@ssw0rd -c "system show" -xml xmlfilename
            //                <compellent>
            //                <system>
            //                <SerialNumber>24260</SerialNumber>
            //                <Name>SC8000-10-50</Name>
            //                <ManagementIP>172.17.10.40</ManagementIP>
            //                <Version>6.3.2.16</Version>
            //                <OperationMode>Normal</OperationMode>
            //                <PortsBalanced>No</PortsBalanced>
            //                <MailServer></MailServer>
            //                <BackupMailServer></BackupMailServer>
            //                </system>
            //                </compellent>

            // call compellent command line
            File devicesDir = new File(TEMP_PATH);
            File tempFile = File.createTempFile(ipAddress, ".tmp.conf", devicesDir);
            ExecuteSystemCommands cmdRunner = ExecuteSystemCommands.getInstance();

            String[] volumeCommand = { "java", "-jar",
                    "/etc/puppetlabs/puppet/modules/compellent/lib/puppet/files/CompCU.jar", "-host", ipAddress,
                    "-user", cred.getUsername(), "-password", cred.getPasswordData().getString(), "-c",
                    "system show -xml " + tempFile.getAbsolutePath() };

            //LOGGER.debug("Calling Compellent : " + volumeCommand);
            CommandResponse cmdresponse = cmdRunner.runCommandWithConsoleOutput(volumeCommand);
            LOGGER.debug("Return code: " + cmdresponse.getReturnCode() + " Return message: "
                    + cmdresponse.getReturnMessage());
            device.setDiscoveryResponse(cmdresponse.getReturnMessage());
            if (cmdresponse.getReturnCode().equalsIgnoreCase("0")) {
                // read the generated XML file, look for managementIP
                DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
                DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
                Document doc = dBuilder.parse(tempFile);

                NodeList nList = doc.getElementsByTagName("ManagementIP");
                String reportedManagerIP = null;
                for (int temp = 0; temp < nList.getLength(); temp++) {

                    Node nNode = nList.item(temp);
                    reportedManagerIP = nNode.getTextContent();
                }

                // compare the management ip we found with the one we're discovering
                if (reportedManagerIP != null && reportedManagerIP.equals(ipAddress)) {
                    retVal = DiscoverDeviceType.COMPELLENT;
                } else {
                    LOGGER.info("Skipping compellent IP " + ipAddress + " because it is not the management IP, "
                            + reportedManagerIP);
                }
            }

            try {
                tempFile.delete();
            } catch (Exception e) {
                LOGGER.warn("could not delete temp file " + tempFile.getAbsolutePath() + ", ignoring.");
            }
        } else {
            LOGGER.debug("Check for Compellent didn't detect a known pattern in HTML response: "
                    + compellentResponse);
            device.setDiscoveryResponse(compellentResponse);
        }
    } catch (Exception ioe) {
        LOGGER.debug("In DeviceTypeCheck.checkCompllent, could not connect to " + ipAddress + " because of "
                + ioe.getMessage() + ".  Ignoring.");
    }

    return retVal;
}

From source file:hydrograph.engine.bhse.xmlparser.preprocessor.ParseExternalElementsTest.java

@Test
public void itShouldGetTheExternalFields() throws ParseException {

    String[] args = new String[] { "-xmlpath", "testData/XMLFiles/DelimitedInputAndOutput.xml", "-param",
            "PATH=testData/Input/delimitedInputFile", "-param", "PATH2=testData/XMLFiles/schema2.xml", "-param",
            "input=input'1", "-param", "out&put=output" };
    try {/*  w w  w .  java2s  . c o  m*/
        ParameterSubstitutor parameterSubstitutor = new ParameterSubstitutor(new UserParameters(args));

        String xmlContents = XmlParsingUtils.getXMLStringFromPath(args[1]);

        ParseExternalElements parseExternalElements = new ParseExternalElements(
                parameterSubstitutor.substitute(xmlContents), parameterSubstitutor);

        Document xmlDom = parseExternalElements.getXmlDom();

        NodeList nodes = xmlDom.getElementsByTagName("schema");

        Assert.assertEquals(3, nodes.item(0).getChildNodes().getLength());
    } catch (IOException e) {
        LOG.error("", e);
    }
}

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

/**
 * Parse PropertyGroups.xml definitions//from   w w w .  ja  v  a2  s.  c o m
 * 
 * @return A Map with all the forms and its form elements.
 */
public static synchronized Map<PropertyGroup, List<FormElement>> parsePropertyGroupsForms(String pgForm)
        throws IOException, ParseException {
    log.debug("parsePropertyGroupsForms({})", pgForm);

    if (pGroups == null) {
        pGroups = new HashMap<PropertyGroup, List<FormElement>>();
        FileInputStream fis = null;

        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);
            fis = new FileInputStream(pgForm);

            if (fis != null) {
                Document doc = db.parse(fis);
                doc.getDocumentElement().normalize();
                NodeList nlForm = doc.getElementsByTagName("property-group");

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

                    if (nForm.getNodeType() == Node.ELEMENT_NODE) {
                        PropertyGroup pg = new PropertyGroup();

                        Node item = nForm.getAttributes().getNamedItem("label");
                        if (item != null)
                            pg.setLabel(item.getNodeValue());
                        item = nForm.getAttributes().getNamedItem("name");
                        if (item != null)
                            pg.setName(item.getNodeValue());
                        item = nForm.getAttributes().getNamedItem("visible");
                        if (item != null)
                            pg.setVisible(Boolean.valueOf(item.getNodeValue()));
                        item = nForm.getAttributes().getNamedItem("readonly");
                        if (item != null)
                            pg.setReadonly(Boolean.valueOf(item.getNodeValue()));

                        NodeList nlField = nForm.getChildNodes();
                        List<FormElement> fe = parseField(nlField);
                        pGroups.put(pg, fe);
                    }
                }
            }
        } catch (ParserConfigurationException e) {
            throw new ParseException(e.getMessage());
        } catch (SAXException e) {
            throw new ParseException(e.getMessage());
        } catch (IOException e) {
            throw e;
        } finally {
            IOUtils.closeQuietly(fis);
        }
    }

    log.debug("parsePropertyGroupsForms: {}", pGroups);
    return clonedPropertyGroups();
}

From source file:com.intel.podm.redfish.resources.MetadataResourceProvider.java

private void updateUris(Document xmlDocument) {
    NodeList list = xmlDocument.getElementsByTagName("edmx:Reference");
    for (int i = 0; i < list.getLength(); i++) {
        Node item = list.item(i);
        Node uri = item.getAttributes().getNamedItem("Uri");
        uri.setTextContent("/redfish/v1/metadata/" + uri.getTextContent());
    }/*from w  w w.  j a va  2s. c  o m*/
}

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

/**
 * Parse params.xml definitions//w  ww. jav  a  2s.com
 * 
 * @return A List parameter elements.
 */
public static List<FormElement> parseReportParameters(InputStream is) throws ParseException {
    log.debug("parseReportParameters({})", is);
    long begin = System.currentTimeMillis();
    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.trace("parseReportParameters.Time: {}", System.currentTimeMillis() - begin);
    log.debug("parseReportParameters: {}", params);
    return params;
}

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

/**
 * Parse form.xml definitions/*from   w w  w  . j a va 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);
    long begin = System.currentTimeMillis();
    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.trace("parseWorkflowForms.Time: {}", System.currentTimeMillis() - begin);
    log.debug("parseWorkflowForms: {}", forms);
    return forms;
}

From source file:com.nebhale.gpxconverter.StandardParser.java

@Override
public List<Point> parsePoints(Document document) {
    NodeList nodes;/*  w  w w  . j  a  va  2s  . com*/

    nodes = document.getElementsByTagName("rtept");
    if (nodes.getLength() > 0) {
        return gpxRoute(nodes);
    }

    nodes = document.getElementsByTagName("trkpt");
    if (nodes.getLength() > 0) {
        return gpxTrack(nodes);
    }

    nodes = document.getElementsByTagName("Position");
    if (nodes.getLength() > 0) {
        return tcxTrack(nodes);
    }

    throw new RuntimeException("Unable to parse point input");
}