Java XML Node Name getTagName(Node tag, boolean useJsfcTags)

Here you can find the source of getTagName(Node tag, boolean useJsfcTags)

Description

Returns the name for the tag

License

Open Source License

Parameter

Parameter Description
tag a parameter
useJsfcTags a parameter

Declaration

public static String getTagName(Node tag, boolean useJsfcTags) 

Method Source Code

//package com.java2s;
/******************************************************************************* 
 * Copyright (c) 2009 Red Hat, Inc. /*from   w  w w .j a  v a  2  s  .  c o  m*/
 * Distributed under license by Red Hat, Inc. All rights reserved. 
 * This program is made available under the terms of the 
 * Eclipse Public License v1.0 which accompanies this distribution, 
 * and is available at http://www.eclipse.org/legal/epl-v10.html 
 * 
 * Contributors: 
 * Red Hat, Inc. - initial API and implementation 
 ******************************************************************************/

import org.w3c.dom.Attr;
import org.w3c.dom.Element;
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;

public class Main {
    private static final String JSFC_ATTRIBUTE_NAME = "jsfc";

    /**
     * Returns the name for the tag
     * 
     * @param tag
     * @param useJsfcTags
     * @return
     */
    public static String getTagName(Node tag, boolean useJsfcTags) {
        String tagName = tag.getNodeName();
        if (useJsfcTags) {
            // Only HTML tags
            if (tagName.indexOf(':') > 0) {
                return tagName;
            }
            if (!(tag instanceof Element))
                return tagName;

            Element element = (Element) tag;

            NamedNodeMap attributes = element.getAttributes();
            Node jsfC = attributes.getNamedItem(JSFC_ATTRIBUTE_NAME);
            if (jsfC == null || (!(jsfC instanceof Attr))) {
                return tagName;
            }
            Attr jsfCAttribute = (Attr) jsfC;
            String jsfTagName = jsfCAttribute.getValue();
            if (jsfTagName == null || jsfTagName.indexOf(':') < 1) {
                return tagName;
            }
            tagName = jsfTagName;
        }
        return tagName;
    }
}

Related

  1. getSimpleName(final Node node)
  2. getSubNodes(Node node, String subNodeName)
  3. getSubNodeValue(Node node, String nodeName, String subNodeName)
  4. getTagName(Node labelNode)
  5. getTagName(Node node)
  6. getTagNameWithoutPrefix(Node node)
  7. getTifDimension(Node node, String nodeName)
  8. getUnqualifiedNodeName(org.w3c.dom.Node node)
  9. isMatchNodeName(Node node, String node_name)