Example usage for org.w3c.dom Element getLocalName

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

Introduction

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

Prototype

public String getLocalName();

Source Link

Document

Returns the local part of the qualified name of this node.

Usage

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

/**
 * get the real namespace of the type//w  w  w  . ja  va2  s.  c om
 * 
 * @param annotations
 * @return null if this is a type inside wsdl, not from TL outside
 */
private String getSourceNamespaceAnnotations(EList<XSDAnnotation> annotations) {
    String orginalNamespace = null;
    if (annotations == null || annotations.size() == 0) {
        return orginalNamespace;
    }
    for (XSDAnnotation at : annotations) {
        EList<Element> list = at.getApplicationInformation();
        for (Element e : list) {
            String nodeName = e.getLocalName();
            // String content = e.getTextContent();
            // if (StringUtils.isEmpty(nodeName) == true) {
            // continue;
            // }
            if (APP_NODE_NAME.equalsIgnoreCase(nodeName) == false) {
                continue;
            }
            NodeList appChildren = e.getChildNodes();
            int len = appChildren.getLength();
            for (int i = 0; i < len; i++) {
                Node appChild = appChildren.item(i);
                if (TL_SOURCE_NODE_NAME.equalsIgnoreCase(appChild.getNodeName()) == false) {
                    continue;
                }
                NamedNodeMap tlSourceAttrs = appChild.getAttributes();
                Node tlNameNode = tlSourceAttrs.getNamedItem(TL_ARRT_NAME);
                Node typeNSNode = tlSourceAttrs.getNamedItem(TL_NS_ATTR_NAME);
                String tlName = tlNameNode.getNodeValue();
                String typeNS = typeNSNode.getNodeValue();
                if (typeNSNode == null || tlNameNode == null) {
                    return null;
                }
                if (SOALogger.DEBUG)
                    logger.debug(tlName + "\t" + typeNS);
                return typeNS;
            }
        }
    }
    return orginalNamespace;
}

From source file:org.eclipse.smila.datamodel.id.dom.IdParser.java

/**
 * Find the first child Id element and parse the Id it describes. If no Id element is found, null is returned.
 * /*from  w ww .ja v  a2  s. co  m*/
 * @param parentElement
 *          the element under which to search for Ids
 * @return the first Id found under the parentElement.
 */
public Id parseIdIn(final Element parentElement) {
    final NodeList children = parentElement.getChildNodes();
    if (children != null && children.getLength() > 0) {
        for (int i = 0; i < children.getLength(); i++) {
            final Node childNode = children.item(i);
            if (childNode instanceof Element) {
                final Element idElement = (Element) childNode;
                final String localName = idElement.getLocalName();
                // if (localName == null) {
                // localName = idElement.getTagName();
                // }
                if (TAG_ID.equals(localName)) {
                    return parseIdFrom(idElement);
                }
            }
        }
    }
    return null;
}

From source file:org.eclipse.smila.datamodel.id.dom.IdParser.java

/**
 * Find all child Id elements and parse the Id it describes. If no Id element is found, null is returned.
 * //from ww w .j  a va 2  s. com
 * @param parentElement
 *          the element under which to search for Ids
 * @return all Ids found under the parentElement.
 */
public List<Id> parseIdsIn(final Element parentElement) {
    final NodeList children = parentElement.getChildNodes();
    final List<Id> ids = new ArrayList<Id>();
    if (children != null && children.getLength() > 0) {
        for (int i = 0; i < children.getLength(); i++) {
            final Node childNode = children.item(i);
            if (childNode instanceof Element) {
                final Element idElement = (Element) childNode;
                if (TAG_ID.equals(idElement.getLocalName())) {
                    ids.add(parseIdFrom(idElement));
                }
            }
        }
    }
    return ids;
}

From source file:org.eclipse.smila.datamodel.id.dom.IdParser.java

/**
 * Expects a valid id:Id element and creates an Id object from it.
 * /*from w ww .j  a va 2  s  . com*/
 * @param idElement
 *          an id:Id element to parse.
 * @return the Id described by the given element
 */
public Id parseIdFrom(final Element idElement) {
    final NodeList nodes = idElement.getChildNodes();
    String source = null;
    final Map<String, String> keyValues = new HashMap<String, String>();
    final List<Key> elementKeys = new ArrayList<Key>();
    final List<String> fragmentNames = new ArrayList<String>();

    for (int i = 0; i < nodes.getLength(); i++) {
        final Node node = nodes.item(i);
        if (node instanceof Element) {
            final Element element = (Element) node;
            final String elementName = element.getLocalName();
            if (TAG_SOURCE.equals(elementName)) {
                source = element.getTextContent();
            } else if (TAG_KEY.equals(elementName)) {
                parseKeyValue(keyValues, element);
            } else if (TAG_ELEMENT.equals(elementName)) {
                parseElement(elementKeys, element);
            } else if (TAG_FRAGMENT.equals(elementName)) {
                fragmentNames.add(element.getTextContent());
            }
        }
    }
    final Key sourceKey = _factory.createKey(keyValues);
    return _factory.createId(source, sourceKey, elementKeys, fragmentNames);
}

From source file:org.eclipse.smila.datamodel.id.dom.IdParser.java

/**
 * expects a valid id:Element, creates the described container element keys and adds them to the given key list.
 * /*from w w w  . j ava  2  s  .  c o  m*/
 * @param elementKeys
 *          list to add the container element keys to.
 * @param elementElement
 *          the id:Element element.
 */
private void parseElement(final List<Key> elementKeys, final Element elementElement) {
    final NodeList nodes = elementElement.getChildNodes();
    final Map<String, String> elementKeyValues = new HashMap<String, String>();
    for (int i = 0; i < nodes.getLength(); i++) {
        final Node node = nodes.item(i);
        if (node instanceof Element) {
            final Element subElement = (Element) node;
            final String elementName = subElement.getLocalName();
            if (TAG_KEY.equals(elementName)) {
                parseKeyValue(elementKeyValues, subElement);
            }
            if (TAG_ELEMENT.equals(elementName)) {
                final Key elementKey = _factory.createKey(elementKeyValues);
                elementKeys.add(elementKey);
                parseElement(elementKeys, subElement);
                return;
            }
        }
    }
}

From source file:org.eclipse.smila.datamodel.record.dom.RecordParser.java

/**
 * find the first child rec:Record element the specified parent element and create a Record from it.
 * /*ww w . j  a  v a  2  s  .co  m*/
 * @param parentElement
 *          parent element of rec:Record
 * @return the record described by the first rec:Record element under the parent.
 */
public Record parseRecordIn(final Element parentElement) {
    final NodeList children = parentElement.getChildNodes();
    if (children != null && children.getLength() > 0) {
        for (int i = 0; i < children.getLength(); i++) {
            final Node childNode = children.item(i);
            if (childNode instanceof Element) {
                final Element recordElement = (Element) childNode;
                if (TAG_RECORD.equals(recordElement.getLocalName())) {
                    return parseRecordFrom(recordElement);
                }
            }
        }
    }
    return null;
}

From source file:org.eclipse.smila.datamodel.record.dom.RecordParser.java

/**
 * Find all child rec:Record elements that are child of this specified element and parse the record it describes. If
 * no record element is found, null is returned.
 * /*from w ww .j  a  va2  s.c o m*/
 * @param parentElement
 *          the element under which to search for recordss
 * @return all records found under the parentElement.
 */
public List<Record> parseRecordsIn(final Element parentElement) {
    final NodeList children = parentElement.getChildNodes();
    final List<Record> records = new ArrayList<Record>();
    if (children != null && children.getLength() > 0) {
        for (int i = 0; i < children.getLength(); i++) {
            final Node childNode = children.item(i);
            if (childNode instanceof Element) {
                final Element recordElement = (Element) childNode;
                if (TAG_RECORD.equals(recordElement.getLocalName())) {
                    records.add(parseRecordFrom(recordElement));
                }
            }
        }
    }
    return records;
}

From source file:org.eclipse.smila.datamodel.record.dom.RecordParser.java

/**
 * parse an rec:Annotation element and create an Annotation object.
 * /*from w  w w.j a v  a  2s  .c  om*/
 * @param annotatable
 *          object to annotate.
 * @param annotationElement
 *          the element to parse
 */
public void parseAnnotation(final Annotatable annotatable, final Element annotationElement) {
    final String annotationName = annotationElement.getAttribute(ATTRIBUTE_NAME);
    final Annotation annotation = _recordFactory.createAnnotation();

    final NodeList children = annotationElement.getChildNodes();
    if (children != null && children.getLength() > 0) {
        for (int i = 0; i < children.getLength(); i++) {
            final Node childNode = children.item(i);
            if (childNode instanceof Element) {
                final Element childElement = (Element) childNode;
                if (TAG_VALUE.equals(childElement.getLocalName())) {
                    final String value = childElement.getTextContent();
                    final String name = childElement.getAttribute(ATTRIBUTE_NAME);
                    if (StringUtils.isBlank(name)) {
                        annotation.addAnonValue(value);
                    } else {
                        annotation.setNamedValue(name, value);
                    }
                } else if (TAG_ANNOTATION.equals(childElement.getLocalName())) {
                    parseAnnotation(annotation, childElement);
                }
            }
        }
    }
    annotatable.addAnnotation(annotationName, annotation);
}

From source file:org.eclipse.smila.datamodel.record.dom.RecordParser.java

/**
 * parse a metadata object from the given element.
 * //from w  w w  .  j ava  2 s  . co  m
 * @param element
 *          element to parse.
 * @return parsed metadata object, if appropriate objects could be found. else null.
 */
private MObject parseMetadataObject(final Element element) {
    // fixed to always create metadata object
    final MObject mObject = _recordFactory.createMetadataObject();
    final NodeList children = element.getChildNodes();
    if (children != null && children.getLength() > 0) {
        for (int i = 0; i < children.getLength(); i++) {
            final Node childNode = children.item(i);
            if (childNode instanceof Element) {
                final Element childElement = (Element) childNode;
                if (TAG_ATTRIBUTE.equals(childElement.getLocalName())) {
                    parseAttribute(mObject, childElement);
                } else if (TAG_ANNOTATION.equals(childElement.getLocalName())) {
                    parseAnnotation(mObject, childElement);
                }
            }
        }
    }
    return mObject;
}

From source file:org.eclipse.smila.datamodel.record.dom.RecordParser.java

/**
 * parse Attribute from given rec:Attribute element and attach to given metadata object.
 * // ww  w  .j  a  v  a2  s.  co  m
 * @param mObject
 *          metadata to add to
 * @param attributeElement
 *          rec:Attribute element to parse.
 */
private void parseAttribute(final MObject mObject, final Element attributeElement) {
    final String name = attributeElement.getAttribute(ATTRIBUTE_NAME);
    Attribute attribute = null;
    if (mObject.hasAttribute(name)) {
        attribute = mObject.getAttribute(name);
    } else {
        attribute = _recordFactory.createAttribute();
    }
    final NodeList children = attributeElement.getChildNodes();
    if (children != null && children.getLength() > 0) {
        for (int i = 0; i < children.getLength(); i++) {
            final Node childNode = children.item(i);
            if (childNode instanceof Element) {
                final Element childElement = (Element) childNode;
                if (TAG_LITERAL.equals(childElement.getLocalName())) {
                    parseLiterals(attribute, childElement);
                } else if (TAG_OBJECT.equals(childElement.getLocalName())) {
                    parseAttributeObject(attribute, attributeElement, childElement);
                } else if (TAG_ANNOTATION.equals(childElement.getLocalName())) {
                    parseAnnotation(attribute, childElement);
                }
            }
        }
    }
    mObject.setAttribute(name, attribute);
}