Example usage for org.w3c.dom Element getTagName

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

Introduction

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

Prototype

public String getTagName();

Source Link

Document

The name of the element.

Usage

From source file:com.googlecode.jgenhtml.JGenXmlTest.java

/**
 * Test of main method, of class JGenHtml.
 *//*from  ww  w  .jav  a  2  s. co m*/
public void testMain() {
    System.out.println("main");
    Document doc = getXmlPage("xml/index.xml");
    Element root = doc.getDocumentElement();
    assertEquals(root.getTagName(), "coverage");
    String[] lines = JGenHtmlTestUtils.TOP_IDX_STATS_EXPECTED[JGenHtmlTestUtils.LINES];
    Map<String, String> expected = getExpectedCoverage(lines[JGenHtmlTestUtils.TOTAL],
            lines[JGenHtmlTestUtils.HIT], traceFileName, "index");
    checkAttributes(expected, root);
}

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

private static boolean getNodes(NodeList nodeList, ArrayList<Node> nodes, String[] tags,
        boolean checkChildren) {
    ArrayList<String> list = new ArrayList<String>(Arrays.asList(tags));
    // Check the immediate node level
    for (int i = 0; i < nodeList.getLength(); i++) {
        Node n = nodeList.item(i);
        if (n != null) {
            if (n.getNodeType() == Node.ELEMENT_NODE) {
                Element element = ((Element) n);
                String tag = element.getTagName();
                if (list.contains(tag)) {
                    nodes.add(n);/*  w  ww  . jav a2s .c  o  m*/
                }
            }
        }
    }
    if (nodes.size() > 0) {
        return true;
    }
    // Check the children nodes
    if (checkChildren) {
        for (int i = 0; i < nodeList.getLength(); i++) {
            Node n = nodeList.item(i);
            getNodes(n.getChildNodes(), nodes, tags, checkChildren);
        }
    }
    return nodes.size() > 0;
}

From source file:nl.b3p.kaartenbalie.service.requesthandler.WMSRequestHandler.java

/**
 * Method which copies information from one XML document to another
 * document. It adds information to an document and with this method it's
 * possible to create one document from several other documents as used to
 * create an GetFeatureInfo document.//w  ww .ja v a2  s .c  om
 *
 * @param source Document object
 * @param destination Document object
 */
private static void copyElements(Document source, Document destination) {
    Element root_source = source.getDocumentElement();
    NodeList nodelist_source = root_source.getChildNodes();
    int size_source = nodelist_source.getLength();

    for (int i = 0; i < size_source; i++) {
        Node node_source = nodelist_source.item(i);
        if (node_source instanceof Element) {
            Element element_source = (Element) node_source;
            String tagName = element_source.getTagName();
            if (!tagName.equalsIgnoreCase("ServiceException")) {
                Node importedNode = destination.importNode(element_source, true);
                Element root_destination = destination.getDocumentElement();
                root_destination.appendChild(importedNode);
            }
        }
    }
}

From source file:com.pari.nm.modules.jobs.PcbImportJob.java

public static void populateDiscoveredList(Element docRoot, int customerId, int instanceId) throws Exception {
    if (!docRoot.getTagName().equals("DiscoveredDeviceList")) {
        throw new Exception("Invalid format. Expecting: DiscoveredDeviceList, found " + docRoot.getTagName());
    }/*from  w  ww  . j a va 2s . c  o m*/
    NodeList devList = docRoot.getElementsByTagName("DiscoveredDevice");
    int numCh = devList.getLength();
    for (int i = 0; i < numCh; i++) {
        Element specRoot = (Element) devList.item(i);
        String tagName = specRoot.getTagName();
        if (!tagName.equals("DiscoveredDevice")) {
            throw new Exception("Invalid format. Expecting: DiscoveredDevice, found " + tagName);
        }
        DiscoveredDevice dev = new DiscoveredDevice();
        dev.setCustomer_id(customerId);
        dev.setInstanceId(instanceId);
        NodeList aList = specRoot.getElementsByTagName("IpAddress");
        if (aList.getLength() > 0) {
            Node n = aList.item(0);
            Node nn = n.getFirstChild();
            dev.setIpAddress(nn.getNodeValue().trim());
        }
        aList = specRoot.getElementsByTagName("HostName");
        if (aList.getLength() > 0) {
            Node n = aList.item(0);
            Node nn = n.getFirstChild();
            dev.setNodeName(nn.getNodeValue().trim());
        }
        aList = specRoot.getElementsByTagName("MACAddress");
        if (aList.getLength() > 0) {
            Node n = aList.item(0);
            Node nn = n.getFirstChild();
            dev.setMacAddress(nn.getNodeValue().trim());
        }
        aList = specRoot.getElementsByTagName("Description");
        if (aList.getLength() > 0) {
            Node n = aList.item(0);
            Node nn = n.getFirstChild();
            dev.setDescription(nn.getNodeValue().trim());
        }
        aList = specRoot.getElementsByTagName("DeviceFamily");
        if (aList.getLength() > 0) {
            Node n = aList.item(0);
            Node nn = n.getFirstChild();
            dev.setDevice_family(nn.getNodeValue().trim());
        }
        aList = specRoot.getElementsByTagName("ProductFamily");
        if (aList.getLength() > 0) {
            Node n = aList.item(0);
            Node nn = n.getFirstChild();
            dev.setProduct_family(nn.getNodeValue().trim());
        }
        aList = specRoot.getElementsByTagName("ProductModel");
        if (aList.getLength() > 0) {
            Node n = aList.item(0);
            Node nn = n.getFirstChild();
            dev.setProduct_model(nn.getNodeValue().trim());
        }
        aList = specRoot.getElementsByTagName("OSName");
        if (aList.getLength() > 0) {
            Node n = aList.item(0);
            Node nn = n.getFirstChild();
            dev.setOsName(nn.getNodeValue().trim());
        }
        aList = specRoot.getElementsByTagName("OSVersion");
        if (aList.getLength() > 0) {
            Node n = aList.item(0);
            Node nn = n.getFirstChild();
            dev.setOsVersion(nn.getNodeValue().trim());
        }
        aList = specRoot.getElementsByTagName("VendorName");
        if (aList.getLength() > 0) {
            Node n = aList.item(0);
            Node nn = n.getFirstChild();
            dev.setVendor_name(nn.getNodeValue().trim());
        }
        aList = specRoot.getElementsByTagName("IsManaged");
        if (aList.getLength() > 0) {
            Node n = aList.item(0);
            Node nn = n.getFirstChild();
            dev.setManaged(nn.getNodeValue().trim().equalsIgnoreCase("yes"));
        }
        aList = specRoot.getElementsByTagName("DiscoveryMethod");
        if (aList.getLength() > 0) {
            Node n = aList.item(0);
            Node nn = n.getFirstChild();
            dev.setDiscovery_method(nn.getNodeValue().trim());
        }
        aList = specRoot.getElementsByTagName("DiscoveryCredential");
        if (aList.getLength() > 0) {
            Node n = aList.item(0);
            Node nn = n.getFirstChild();
            dev.setDiscovery_credential(nn.getNodeValue().trim());
        }
        aList = specRoot.getElementsByTagName("DiscoveryTime");
        if (aList.getLength() > 0) {
            Node n = aList.item(0);
            Node nn = n.getFirstChild();
            dev.setDiscovery_time(nn.getNodeValue().trim());
        }
        aList = specRoot.getElementsByTagName("DiscoveredFrom");
        if (aList.getLength() > 0) {
            Node n = aList.item(0);
            Node nn = n.getFirstChild();
            dev.setDiscovered_from(nn.getNodeValue().trim());
        }
        InventoryDBHelper.insertDiscoveredDevice(dev);
    }
}

From source file:nl.b3p.kaartenbalie.service.requesthandler.WMSRequestHandler.java

private static void prefixElements(Document source, Document destination, String spAbbr) {
    Element root_source = source.getDocumentElement();
    NodeList nodelist_source = root_source.getChildNodes();
    int size_source = nodelist_source.getLength();

    for (int i = 0; i < size_source; i++) {
        Node node_source = nodelist_source.item(i);

        if (node_source instanceof Element) {
            Element element_source = (Element) node_source;
            String tagName = element_source.getTagName();

            if (!tagName.equalsIgnoreCase("ServiceException")) {
                Node importedNode = destination.importNode(element_source, true);
                Node newNode = destination.renameNode(importedNode, importedNode.getNamespaceURI(),
                        OGCCommunication.attachSp(spAbbr, tagName));

                Element root_destination = destination.getDocumentElement();
                root_destination.appendChild(newNode);
            }/*  ww  w.  ja va2 s.c  o  m*/
        }
    }
}

From source file:com.serotonin.m2m2.util.license.InstanceLicense.java

public InstanceLicense(Document doc) throws LicenseParseException {
    Element licenseElement = doc.getDocumentElement();
    if (licenseElement == null || !StringUtils.equals("license", licenseElement.getTagName()))
        throw new LicenseParseException("Root element must be 'license'");

    Element coreElement = XmlUtilsTS.getChildElement(licenseElement, "core");
    if (coreElement == null)
        throw new LicenseParseException("Missing core element");

    guid = XmlUtilsTS.getChildElementText(coreElement, "guid");

    distributor = XmlUtilsTS.getChildElementText(coreElement, "distributor");
    version = XmlUtilsTS.getChildElementTextAsInt(coreElement, "version", -1);
    licenseType = XmlUtilsTS.getChildElementText(coreElement, "licenseType");

    Element featuresElement = XmlUtilsTS.getChildElement(coreElement, "features");
    List<LicenseFeature> featureList = new ArrayList<LicenseFeature>();
    if (featuresElement != null) {
        for (Element feature : XmlUtilsTS.getChildElements(featuresElement))
            featureList.add(new LicenseFeature(feature));
    }/* ww w  .j  a v a2 s .c o m*/
    features = Collections.unmodifiableList(featureList);

    Element modulesElement = XmlUtilsTS.getChildElement(licenseElement, "modules");
    List<ModuleLicense> moduleList = new ArrayList<ModuleLicense>();
    if (modulesElement != null) {
        for (Element module : XmlUtilsTS.getChildElements(modulesElement))
            moduleList.add(new ModuleLicense(module));
    }
    modules = Collections.unmodifiableList(moduleList);
}

From source file:com.krawler.esp.utils.mime.MimeTypesReader.java

/** Read Element named mime-types. */
private MimeType[] readMimeTypes(Element element) {
    ArrayList types = new ArrayList();
    NodeList nodes = element.getChildNodes();
    for (int i = 0; i < nodes.getLength(); i++) {
        Node node = nodes.item(i);
        if (node.getNodeType() == Node.ELEMENT_NODE) {
            Element nodeElement = (Element) node;
            if (nodeElement.getTagName().equals("mime-type")) {
                MimeType type = readMimeType(nodeElement);
                if (type != null) {
                    types.add(type);/*from  w ww .  ja v  a 2 s. c om*/
                }
            }
        }
    }
    return (MimeType[]) types.toArray(new MimeType[types.size()]);
}

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

public static CustomForm processForm(Node formNode) {
    // Each table in the form node is a "Group"
    Element formElement = (Element) formNode;
    // Populate the form object
    CustomForm form = new CustomForm();
    form.setName(formElement.getAttribute("name"));
    // Parse the tables which represent a group of fields
    NodeList tableNodes = formNode.getChildNodes();
    for (int tableI = 0; tableI < tableNodes.getLength(); tableI++) {
        // For each table, parse the rows
        Node tableNode = tableNodes.item(tableI);
        // There will be 1 group per table
        CustomFormGroup group = null;//from w  w  w .j  a  va  2  s  .  co  m
        // Split the rows into groups and fields...
        NodeList rowNodes = tableNode.getChildNodes();
        for (int rowI = 0; rowI < rowNodes.getLength(); rowI++) {
            // For each row, parse the groups and fields
            Node rowNode = rowNodes.item(rowI);
            NodeList cellNodes = rowNode.getChildNodes();
            // Any number of fields should be found...
            CustomFormField field = null;
            for (int cellI = 0; cellI < cellNodes.getLength(); cellI++) {
                Node cellNode = cellNodes.item(cellI);
                Element cellElement = (Element) cellNode;
                String tag = cellElement.getTagName();
                // Check to see if there is a group row, represented by th
                if ("th".equals(tag)) {
                    group = new CustomFormGroup();
                    group.setName(cellNode.getTextContent());
                }
                // Construct a field object from each row's tds
                if ("td".equals(tag)) {
                    if (field == null) {
                        field = new CustomFormField();
                        field.setLabel(cellNode.getTextContent());
                    } else {
                        // TODO: parse the td
                        /*
                        field.setName();
                        field.setType();
                        field.setRequired();
                        field.setParameters();
                        field.setAdditionalText();
                        */
                    }
                }
            }
            if (field != null) {
                if (group == null) {
                    group = new CustomFormGroup();
                }
                group.add(field);
            }
        }
        if (group != null) {
            form.add(group);
        }
    }
    return form;
}

From source file:org.devefx.httpmapper.spring.config.ListenersBeanDefinitionParser.java

public BeanDefinition parse(Element element, ParserContext parserContext) {
    CompositeComponentDefinition compDefinition = new CompositeComponentDefinition(element.getTagName(),
            parserContext.extractSource(element));
    parserContext.pushContainingComponent(compDefinition);

    RuntimeBeanReference pathMatcherRef = null;
    if (element.hasAttribute("path-matcher")) {
        pathMatcherRef = new RuntimeBeanReference(element.getAttribute("path-matcher"));
    }/*  w w  w  . ja  v  a2s .  c om*/

    List<Element> listeners = DomUtils.getChildElementsByTagName(element, "bean", "ref", "listener");
    for (Element listener : listeners) {
        RootBeanDefinition mappedListenerDef = new RootBeanDefinition(MappedListener.class);
        mappedListenerDef.setSource(parserContext.extractSource(listener));
        mappedListenerDef.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);

        ManagedList<String> includePatterns = null;
        ManagedList<String> excludePatterns = null;
        Object listenerBean;
        if ("listener".equals(listener.getLocalName())) {
            includePatterns = getIncludePatterns(listener, "mapping");
            excludePatterns = getIncludePatterns(listener, "exclude-mapping");
            Element beanElem = DomUtils.getChildElementsByTagName(listener, "bean", "ref").get(0);
            listenerBean = parserContext.getDelegate().parsePropertySubElement(beanElem, null);
        } else {
            listenerBean = parserContext.getDelegate().parsePropertySubElement(listener, null);
        }
        mappedListenerDef.getConstructorArgumentValues().addIndexedArgumentValue(0, includePatterns);
        mappedListenerDef.getConstructorArgumentValues().addIndexedArgumentValue(1, excludePatterns);
        mappedListenerDef.getConstructorArgumentValues().addIndexedArgumentValue(2, listenerBean);

        if (pathMatcherRef != null) {
            mappedListenerDef.getPropertyValues().add("pathMatcher", pathMatcherRef);
        }

        String beanName = parserContext.getReaderContext().registerWithGeneratedName(mappedListenerDef);
        parserContext.registerComponent(new BeanComponentDefinition(mappedListenerDef, beanName));
    }

    parserContext.popAndRegisterContainingComponent();
    return null;
}

From source file:com.norconex.importer.parser.impl.xfdl.XFDLParser.java

private void parseXML(Document doc, Writer out, ImporterMetadata metadata) throws IOException {

    // Grab the title
    NodeList xmlTitles = doc.getElementsByTagName("title");
    if (xmlTitles != null && xmlTitles.getLength() > 0) {
        Node titleItem = xmlTitles.item(0);
        if (titleItem instanceof Element) {
            metadata.addString("title", ((Element) titleItem).getTextContent());
        }//from   w  w w  . j a  va2 s. com
    }

    boolean isEmpty = true;
    NodeList xmlFields = doc.getElementsByTagName("field");
    for (int i = 0; i < xmlFields.getLength(); i++) {
        if (xmlFields.item(i) instanceof Element) {
            NodeList children = xmlFields.item(i).getChildNodes();
            for (int j = 0; j < children.getLength(); j++) {
                Node childItem = children.item(j);
                if (childItem instanceof Element) {
                    Element tag = ((Element) childItem);
                    String tagName = tag.getTagName();
                    if ("value".equalsIgnoreCase(tagName)) {
                        isEmpty = writeValue(out, tag.getTextContent(), isEmpty);
                    }
                }
            }
        }
    }
}