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:org.cruxframework.crux.core.declarativeui.ViewParser.java

/**
 * /*  w  ww .j  ava 2 s.  c o  m*/
 * @param node
 * @return
 */
private boolean isCruxModuleImportTag(Node node) {
    if (node instanceof Element) {
        Element elem = (Element) node;
        String tagName = elem.getTagName();
        String namespaceURI = elem.getNamespaceURI();
        String src = elem.getAttribute("src");
        return (namespaceURI == null || namespaceURI.equals(XHTML_NAMESPACE))
                && tagName.equalsIgnoreCase("script") && (src != null && src.endsWith(".nocache.js"));
    }
    return false;
}

From source file:org.deri.pipes.endpoints.SindiceProxy.java

public void searchSindice(String term) {
    int noResults = 0, totalResults;
    String searchUrl;/* w  w  w  .  j av a 2s  .c  o m*/
    searchUrl = createSindiceSearchString(term, 1);

    while (true) {

        try {
            String output = readHTTP(searchUrl);
            if (output == null)
                return;
            JSONObject result = new JSONObject(output);
            JSONArray resultList = result.getJSONArray("entries");
            totalResults = result.getInt("totalResults");

            for (int i = 0; i < resultList.length(); i++) {

                noResults++;
                String link = ((JSONObject) resultList.get(i)).getString("link");
                URL url;
                String domain = "";
                try {
                    url = new URL(link);
                    domain = url.getHost().toLowerCase();

                } catch (MalformedURLException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }

                if (!domains.contains(domain)) {
                    domains.add(domain);
                    System.out.println("domain" + domain);
                    if (hasSitemap(domain)) {
                        firstURI.put(domain, link);
                        try {

                            DOMParser parser = new DOMParser();

                            parser.parse("http://" + domain + "/sitemap.xml");
                            Document doc = parser.getDocument();
                            if (doc == null) {
                                System.out.println("doc null");
                                return;
                            }
                            Element rootElm = doc.getDocumentElement();
                            if (rootElm == null) {
                                System.out.println("root element null");
                                return;
                            }
                            Element datasetElm = XMLUtil.getFirstSubElementByName(rootElm, "sc:dataset");
                            if (datasetElm != null) {
                                System.out.println("first child tag " + datasetElm.getTagName());
                                String sparqlEndpoint = XMLUtil.getTextFromFirstSubEleByName(datasetElm,
                                        "sc:sparqlEndpointLocation");
                                if (sparqlEndpoint != null) {
                                    sparqlEndPoints.put(domain, sparqlEndpoint);
                                    descs.put(domain, "" + XMLUtil.getTextFromFirstSubEleByName(datasetElm,
                                            "sc:datasetLabel"));
                                }
                            }

                        } catch (SAXException se) {
                            se.printStackTrace();
                        } catch (IOException ioe) {
                            ioe.printStackTrace();
                        }
                    }
                }
                if ((noResults >= 1000) || (noResults >= totalResults))
                    return;
            }
            searchUrl = result.getString("next");

        } catch (JSONException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
}

From source file:org.dhatim.delivery.dom.DOMBuilder.java

private int getIndex(String elName) {
    for (int i = nodeStack.size() - 1; i >= 0; i--) {
        Node node = (Node) nodeStack.elementAt(i);
        if (node.getNodeType() == Node.ELEMENT_NODE) {
            Element element = (Element) node;
            if (element.getTagName().equals(elName)) {
                return i;
            }//from   ww w.jav  a2 s . c  o m
        }
    }

    return -1;
}

From source file:org.dhatim.xml.DomUtils.java

/**
 * Get the name from the supplied element.
 * <p/>//from  w  w  w . j  a v a  2 s .co m
 * Returns the {@link Node#getLocalName() localName} of the element
 * if set (namespaced element), otherwise the 
 * element's {@link Element#getTagName() tagName} is returned.
 * @param element The element.
 * @return The element name.
 */
public static String getName(Element element) {
    AssertArgument.isNotNull(element, "element");

    String name = element.getLocalName();

    if (name != null) {
        return name;
    } else {
        return element.getTagName();
    }
}

From source file:org.dhatim.xml.DomUtils.java

private static String getXPathToken(Element element) {
    AssertArgument.isNotNull(element, "element");

    String tagName = element.getTagName();
    int count = DomUtils.countElementsBefore(element, tagName);
    String xpathToken;/*  ww  w .j  av a 2 s .  com*/

    if (count > 0) {
        xpathToken = "/" + tagName + "[" + (count + 1) + "]";
    } else {
        xpathToken = "/" + tagName;
    }

    return xpathToken;
}

From source file:org.dita.dost.writer.ConrefPushParser.java

private void writeNode(final Node node) throws SAXException {
    switch (node.getNodeType()) {
    case Node.DOCUMENT_FRAGMENT_NODE: {
        final NodeList children = node.getChildNodes();
        for (int i = 0; i < children.getLength(); i++) {
            writeNode(children.item(i));
        }// w ww . jav a2  s.  com
        break;
    }
    case Node.ELEMENT_NODE:
        final Element e = (Element) node;
        final AttributesBuilder b = new AttributesBuilder();
        final NamedNodeMap atts = e.getAttributes();
        for (int i = 0; i < atts.getLength(); i++) {
            b.add((Attr) atts.item(i));
        }
        final String ns = e.getNamespaceURI() != null ? e.getNamespaceURI() : NULL_NS_URI;
        getContentHandler().startElement(ns, e.getTagName(), e.getNodeName(), b.build());
        final NodeList children = e.getChildNodes();
        for (int i = 0; i < children.getLength(); i++) {
            writeNode(children.item(i));
        }
        getContentHandler().endElement(ns, e.getTagName(), e.getNodeName());
        break;
    case Node.TEXT_NODE:
        final char[] data = node.getNodeValue().toCharArray();
        getContentHandler().characters(data, 0, data.length);
        break;
    case Node.PROCESSING_INSTRUCTION_NODE:
        getContentHandler().processingInstruction(node.getNodeName(), node.getNodeValue());
        break;
    default:
        throw new UnsupportedOperationException();
    }
}

From source file:org.dspace.installer_edm.InstallerEDMAskosi.java

/**
 * Modifica el archivo web.xml de Askosi para indicarle el directorio de datos de Askosi
 *
 * @param webXmlFile archivo web.xml de Askosi
 *//*ww  w  .ja  va 2s .co  m*/
private void changeWebXml(File webXmlFile, String webXmlFileName) {
    try {
        // se abre con DOM el archivo web.xml
        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
        factory.setNamespaceAware(true);
        DocumentBuilder builder = factory.newDocumentBuilder();
        Document doc = builder.parse(webXmlFile);
        XPath xpathInputForms = XPathFactory.newInstance().newXPath();

        // se busca el elemento SKOSdirectory
        NodeList results = (NodeList) xpathInputForms.evaluate("//*[contains(*,\"SKOSdirectory\")]", doc,
                XPathConstants.NODESET);
        if (results.getLength() > 0) {
            Element contextParam = (Element) results.item(0);

            // se busca el elemento context-param como hijo del anterior
            if (contextParam.getTagName().equals("context-param")) {

                // se busca el elemento param-value como hijo del anterior
                NodeList resultsParamValue = contextParam.getElementsByTagName("param-value");
                if (resultsParamValue.getLength() > 0) {

                    // se modifica con la ruta del directorio de datos de Askosi
                    Element valueParam = (Element) resultsParamValue.item(0);
                    Text text = doc.createTextNode(finalAskosiDataDestDirFile.getAbsolutePath());
                    valueParam.replaceChild(text, valueParam.getFirstChild());

                    // se guarda
                    TransformerFactory transformerFactory = TransformerFactory.newInstance();
                    Transformer transformer = transformerFactory.newTransformer();
                    transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "no");
                    transformer.setOutputProperty(OutputKeys.METHOD, "xml");
                    transformer.setOutputProperty(OutputKeys.INDENT, "yes");
                    //transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8");
                    transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2");
                    DocumentType docType = doc.getDoctype();
                    if (docType != null) {
                        if (docType.getPublicId() != null)
                            transformer.setOutputProperty(OutputKeys.DOCTYPE_PUBLIC, docType.getPublicId());
                        transformer.setOutputProperty(OutputKeys.DOCTYPE_SYSTEM, docType.getSystemId());
                    }
                    DOMSource source = new DOMSource(doc);
                    StreamResult result = (fileSeparator.equals("\\")) ? new StreamResult(webXmlFileName)
                            : new StreamResult(webXmlFile);
                    transformer.transform(source, result);
                }
            }
        } else
            installerEDMDisplay.showQuestion(currentStepGlobal, "changeWebXml.noSKOSdirectory",
                    new String[] { webXmlFile.getAbsolutePath() });
    } catch (ParserConfigurationException e) {
        showException(e);
    } catch (SAXException e) {
        showException(e);
    } catch (IOException e) {
        showException(e);
    } catch (XPathExpressionException e) {
        showException(e);
    } catch (TransformerConfigurationException e) {
        showException(e);
    } catch (TransformerException e) {
        showException(e);
    }

}

From source file:org.dspace.installer_edm.InstallerEDMConfEDMExport.java

/**
 * Abre el archivo EDMExport.war y se recorre la lista de archivos que lo componen.
 * En web.xml lo abre con jdom y pide la ruta de dspace.cfg para modificarlo
 * Para los jar con la api de dspace y de lucene muestra cul hay en el war y cul en dspace y pregunta si se cambia
 *//*w  ww.  j  av a2  s. c o  m*/
public void configure() {
    try {
        // comprobar validez del war
        if (checkEDMExporWar()) {
            // copiar al directorio de trabajo
            eDMExportWarWorkFile = new File(
                    myInstallerWorkDirPath + fileSeparator + eDMExportWarFile.getName());
            copyDspaceFile2Work(eDMExportWarFile, eDMExportWarWorkFile, "configure.edmexport");

            // abrir el war
            eDMExportWarJarFile = new JarFile(eDMExportWarWorkFile);
            // buscar web.xml
            ZipEntry edmExportWebZipentry = eDMExportWarJarFile.getEntry("WEB-INF/web.xml");
            if (edmExportWebZipentry == null)
                installerEDMDisplay.showQuestion(currentStepGlobal, "configure.notwebxml");
            else {
                // crear dom de web.xml
                InputStream is = eDMExportWarJarFile.getInputStream(edmExportWebZipentry);
                DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
                factory.setNamespaceAware(true);
                DocumentBuilder builder = factory.newDocumentBuilder();
                eDMExportDocument = builder.parse(is);
                // buscar dspace-config
                XPath xpathInputForms = XPathFactory.newInstance().newXPath();
                NodeList resultsDspaceConfig = (NodeList) xpathInputForms.evaluate(xpathDspaceConfigTemplate,
                        eDMExportDocument, XPathConstants.NODESET);
                if (resultsDspaceConfig.getLength() == 0) {
                    installerEDMDisplay.showQuestion(currentStepGlobal, "configure.nopath");
                } else {
                    // preguntar ruta de dspace.cfg y configurar los jar
                    Element contextParam = (Element) resultsDspaceConfig.item(0);
                    if (contextParam.getTagName().equals("context-param")) {
                        NodeList resultsParamValue = contextParam.getElementsByTagName("param-value");
                        if (resultsParamValue.getLength() > 0) {
                            Element valueParam = (Element) resultsParamValue.item(0);
                            String dspaceCfg = DspaceDir + "config" + fileSeparator + "dspace.cfg";
                            installerEDMDisplay.showQuestion(currentStepGlobal, "configure.dspacecfg",
                                    new String[] { dspaceCfg });
                            File dspaceCfgFile = new File(dspaceCfg);
                            String response = null;
                            do {
                                response = br.readLine();
                                if (response == null)
                                    continue;
                                response = response.trim();
                                if (response.isEmpty()) {
                                    break;
                                } else {
                                    dspaceCfgFile = new File(response);
                                    if (dspaceCfgFile.exists())
                                        break;
                                }
                            } while (true);
                            Text text = eDMExportDocument.createTextNode(dspaceCfgFile.getAbsolutePath());
                            valueParam.replaceChild(text, valueParam.getFirstChild());
                            // jar con la api de dspace
                            findDspaceApi();
                            // jars con lucene
                            findLuceneLib();
                            // escribir el nuevo war con las modificaciones
                            writeNewJar();
                            eDMExportWarJarFile = new JarFile(eDMExportWarWorkFile);
                            installerEDMDisplay.showLn();
                            installerEDMDisplay.showQuestion(currentStepGlobal, "configure.dspacecfg.ok",
                                    new String[] { eDMExportWarWorkFile.getAbsolutePath() });
                        }
                    }
                }
            }
        }
    } catch (IOException e) {
        showException(e);
        installerEDMDisplay.showQuestion(currentStepGlobal, "configure.dspacecfg.nok");
    } catch (ParserConfigurationException e) {
        showException(e);
        installerEDMDisplay.showQuestion(currentStepGlobal, "configure.dspacecfg.nok");
    } catch (SAXException e) {
        showException(e);
        installerEDMDisplay.showQuestion(currentStepGlobal, "configure.dspacecfg.nok");
    } catch (XPathExpressionException e) {
        showException(e);
        installerEDMDisplay.showQuestion(currentStepGlobal, "configure.dspacecfg.nok");
    } catch (TransformerException e) {
        showException(e);
        installerEDMDisplay.showQuestion(currentStepGlobal, "configure.dspacecfg.nok");
    }
}

From source file:org.ebayopensource.turmeric.eclipse.typelibrary.ui.wst.WTPCopyUtil.java

public static void fillAppInfo(Element appInfoElement, String libraryName, String libraryNamespace) {
    NodeList children = appInfoElement.getChildNodes();

    Element typeLibElement = null;
    for (int i = 0; i < children.getLength(); i++) {
        Node child = children.item(i);
        if (child instanceof Element) {
            Element childElement = (Element) child;
            if (SOATypeLibraryConstants.TAG_TYPE_LIB.equals(childElement.getTagName())) {
                typeLibElement = childElement;
                break;
            }/* w  w w.j  ava 2s. c om*/
        }

    }
    //no element exists already
    if (typeLibElement == null) {
        typeLibElement = appInfoElement.getOwnerDocument().createElement(SOATypeLibraryConstants.TAG_TYPE_LIB);
        appInfoElement.appendChild(typeLibElement);
    }
    typeLibElement.setAttribute(SOATypeLibraryConstants.ATTR_LIB, libraryName);
    typeLibElement.setAttribute(SOATypeLibraryConstants.ATTR_NMSPC, libraryNamespace);

}

From source file:org.etudes.ambrosia.impl.UiPropertyReference.java

/**
 * Construct from a dom element./*from  w ww. j a  v a 2s  . c o  m*/
 * 
 * @param service
 *        the UiService.
 * @param xml
 *        The dom element.
 */
protected UiPropertyReference(UiServiceImpl service, Element xml) {
    String ref = StringUtil.trimToNull(xml.getAttribute("ref"));
    if (ref != null) {
        setReference(ref);
    }

    String formatDelegate = StringUtil.trimToNull(xml.getAttribute("delegate"));
    String tool = StringUtil.trimToNull(xml.getAttribute("tool"));
    if ((formatDelegate != null) || (tool != null)) {
        FormatDelegate d = service.getFormatDelegate(formatDelegate, tool);
        if (d != null) {
            this.formatDelegate = d;
        } else {
            M_log.warn("missing delegate: " + formatDelegate + " tool: " + tool);
        }
    }

    String missingText = StringUtil.trimToNull(xml.getAttribute("missing"));
    if (missingText != null)
        setMissingText(missingText);

    Element settingsXml = XmlHelper.getChildElementNamed(xml, "missingValues");
    if (settingsXml != null) {
        List<String> missingValues = new ArrayList<String>();
        NodeList contained = settingsXml.getChildNodes();
        for (int i = 0; i < contained.getLength(); i++) {
            Node node = contained.item(i);
            if (node.getNodeType() == Node.ELEMENT_NODE) {
                Element valueXml = (Element) node;
                if ("missing".equals(valueXml.getTagName())) {
                    String value = StringUtil.trimToNull(valueXml.getAttribute("value"));
                    if (value != null)
                        missingValues.add(value);
                }
            }
        }

        if (!missingValues.isEmpty()) {
            this.missingValues = missingValues.toArray(new String[missingValues.size()]);
        }
    }

    // related references
    // use all the direct model references
    NodeList settings = xml.getChildNodes();
    for (int i = 0; i < settings.getLength(); i++) {
        Node node = settings.item(i);
        if (node.getNodeType() == Node.ELEMENT_NODE) {
            Element innerXml = (Element) node;
            PropertyReference pRef = service.parsePropertyReference(innerXml);
            if (pRef != null)
                addProperty(pRef);
        }
    }

    ref = StringUtil.trimToNull(xml.getAttribute("indexRef"));
    if (ref != null) {
        setIndexReference(ref);
    }
}