Example usage for org.w3c.dom Element getAttributes

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

Introduction

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

Prototype

public NamedNodeMap getAttributes();

Source Link

Document

A NamedNodeMap containing the attributes of this node (if it is an Element) or null otherwise.

Usage

From source file:com.hp.hpl.inkml.InkMLDOMParser.java

/**
 * Method to bind Canvas element// w  ww  . jav  a2s  .c o  m
 * 
 * @param element the Canvas element
 * @param definitions the definitions data object to resolve the reference attributes
 * @return Canvas data object
 * @throws InkMLException
 */
protected Canvas getCanvas(final Element element, final Definitions definitions) throws InkMLException {
    final Canvas canvas = new Canvas();
    // Extract and set Attribute values
    final NamedNodeMap attrMap = element.getAttributes();
    final int length = attrMap.getLength();
    for (int i = 0; i < length; i++) {
        final Node attr = attrMap.item(i);
        canvas.setAttribute(attr.getLocalName(), attr.getNodeValue());
    }

    final NodeList list = element.getElementsByTagName("traceFormat");
    if (list.getLength() != 0) {
        canvas.setTraceFormat(this.getTraceFormat((Element) list.item(0), definitions));
    }

    return canvas;
}

From source file:org.gvnix.dynamic.configuration.roo.addon.ConfigurationsImpl.java

/**
 * {@inheritDoc}/*from  w w  w  .jav  a  2  s.  c  om*/
 */
public DynComponent parseComponent(Element comp, String name) {

    // If property name specified, only it be considered
    List<Element> props;
    if (name == null) {

        props = XmlUtils.findElements("*", comp);
    } else {
        props = XmlUtils.findElements(
                PROPERTY_ELEMENT_NAME + "/" + KEY_ELEMENT_NAME + "[text()='" + name + "']/..", comp);
    }

    // Iterate all child property elements from the component element
    DynPropertyList dynProps = new DynPropertyList();
    for (Element prop : props) {

        dynProps.add(parseProperty(prop));
    }

    if (dynProps.size() == 0) {
        return null;
    }

    // Add new dynamic component
    NamedNodeMap attributes = comp.getAttributes();
    return new DynComponent(attributes.getNamedItem(ID_ATTRIBUTE_NAME).getNodeValue(),
            attributes.getNamedItem(NAME_ATTRIBUTE_NAME).getNodeValue(), dynProps);
}

From source file:com.microsoft.alm.plugin.external.commands.HistoryCommand.java

/**
 * Parses the output of the status command when formatted as xml.
 * SAMPLE//from  ww w .  j a  v  a  2 s. c  o  m
 * <?xml version="1.0" encoding="utf-8"?>
 * <history>
 * <changeset id="4" owner="john" committer="john" date="2016-06-07T11:18:18.790-0400">
 * <comment>add readme</comment>
 * <item change-type="add" server-item="$/tfs01/readme.txt"/>
 * </changeset>
 * <changeset id="3" owner="jeff" committer="jeff" date="2016-06-07T11:13:51.747-0400">
 * <comment>initial checkin</comment>
 * <item change-type="add" server-item="$/tfs01/com.microsoft.core"/>
 * <item change-type="add" server-item="$/tfs01/com.microsoft.core/.classpath"/>
 * </changeset>
 * </history>
 */
@Override
public List<ChangeSet> parseOutput(final String stdout, final String stderr) {
    super.throwIfError(stderr);
    final List<ChangeSet> changeSets = new ArrayList<ChangeSet>(100);
    final NodeList nodes = super.evaluateXPath(stdout, "/history/changeset");

    // Convert all the xpath nodes to changeset models
    if (nodes != null) {
        for (int i = 0; i < nodes.getLength(); i++) {
            final Element changeset = (Element) nodes.item(i);

            // Read comment element
            final NodeList commentNodes = changeset.getElementsByTagName("comment");
            final String comment;
            if (commentNodes.getLength() == 1) {
                comment = commentNodes.item(0).getTextContent();
            } else {
                comment = "";
            }

            // Gather pending changes
            final List<PendingChange> changes = new ArrayList<PendingChange>(100);
            final NodeList childNodes = changeset.getElementsByTagName("item");
            for (int j = 0; j < childNodes.getLength(); j++) {
                final Node child = childNodes.item(j);
                // Assume this is a change
                final NamedNodeMap attributes = child.getAttributes();
                changes.add(new PendingChange(attributes.getNamedItem("server-item").getNodeValue(),
                        attributes.getNamedItem("change-type").getNodeValue()));
            }

            final NamedNodeMap attributes = changeset.getAttributes();
            changeSets.add(new ChangeSet(attributes.getNamedItem("id").getNodeValue(),
                    attributes.getNamedItem("owner").getNodeValue(),
                    attributes.getNamedItem("committer").getNodeValue(),
                    attributes.getNamedItem("date").getNodeValue(), comment, changes));
        }
    }
    return changeSets;
}

From source file:org.alfresco.web.config.forms.FormConfigRuntime.java

public boolean compareAttributeList(Element attributeElem, Map<String, String> attributeList) {
    if (compareObject(attributeElem, attributeList)) {
        return true;
    }//  ww  w .j av a2 s.c o m
    if (attributeElem != null) {
        if (attributeElem.getAttributes().getLength() != attributeList.size()) {
            return true;
        }
        for (String key : attributeList.keySet()) {
            if (!attributeElem.hasAttribute(key)
                    || !attributeElem.getAttribute(key).equals(attributeList.get(key))) {
                return true;
            }
        }
    }
    return false;
}

From source file:com.hp.hpl.inkml.InkMLDOMParser.java

/**
 * Method to bind InkSource element/*from  w  w  w.  j  a  va2s. co m*/
 * 
 * @param element the InkSource element
 * @param definitions the definitions data object to resolve the reference attributes
 * @return InkSource data object
 * @throws InkMLException
 */
protected InkSource getInkSource(final Element element, final Definitions definitions) throws InkMLException {
    final InkSource inkSrc = new InkSource();
    // Extract and set Attribute values
    final NamedNodeMap attrMap = element.getAttributes();
    final int length = attrMap.getLength();
    for (int i = 0; i < length; i++) {
        final Node attr = attrMap.item(i);
        inkSrc.setAttribute(attr.getLocalName(), attr.getNodeValue());
    }

    NodeList list = element.getElementsByTagName("traceFormat");
    if (list.getLength() != 0) {
        inkSrc.setTraceFormat(this.getTraceFormat((Element) list.item(0), definitions));
    }

    list = element.getElementsByTagName("sampleRate");
    if (list.getLength() != 0) {
        inkSrc.setSampleRate(this.getSampleRate((Element) list.item(0), inkSrc));
    }
    list = element.getElementsByTagName("latency");
    if (list.getLength() != 0) {
        inkSrc.setLatency(this.getLatency((Element) list.item(0), inkSrc));
    }
    list = element.getElementsByTagName("activeArea");
    if (list.getLength() != 0) {
        inkSrc.setActiveArea(this.getActiveArea((Element) list.item(0), inkSrc));
    }
    list = element.getElementsByTagName("srcProperty");
    for (int i = 0; i < list.getLength(); i++) {
        inkSrc.addSourceProperty(this.getSourceProperty((Element) list.item(i), inkSrc));
    }
    list = element.getElementsByTagName("channelProperties");
    if (list.getLength() != 0) {
        inkSrc.setChannelProperties(this.getChannelProperties((Element) list.item(0), inkSrc));
    }
    return inkSrc;
}

From source file:com.hp.hpl.inkml.InkMLDOMParser.java

/**
 * Method to bind Trace element//  w w w.  j  a v  a  2 s  . c  o  m
 * 
 * @param element the Trace element
 * @return Trace data object
 * @throws InkMLException
 */
protected Trace getTrace(final Element element) throws InkMLException {
    final Trace trace = new Trace();
    // set value of the object from the value of the DOM element
    // Extract and set Attribute values
    final NamedNodeMap attrMap = element.getAttributes();
    final int length = attrMap.getLength();
    for (int i = 0; i < length; i++) {
        final Node attr = attrMap.item(i);
        trace.setAttribute(attr.getLocalName(), attr.getNodeValue());
    }
    // get trace data
    String traceText = "";
    final NodeList nl = element.getChildNodes();
    for (int i = 0; i < nl.getLength(); i++) {
        if (nl.item(i).getNodeType() == Node.TEXT_NODE) {
            traceText += nl.item(i).getNodeValue();
        }
    }
    final Ink ink = this.inkMLProcessor.getInk();
    final Context currCtx = ink.getCurrentContext();
    final Definitions defs = ink.getDefinitions();
    trace.resolveAssociatedContext(currCtx, defs);
    trace.processTraceElement(traceText, currCtx, defs);

    return trace;
}

From source file:com.twinsoft.convertigo.engine.util.XMLUtils.java

public static void handleElement(Element elt, JSONObject obj, boolean ignoreStepIds, boolean useType)
        throws JSONException {
    String key = elt.getTagName();
    JSONObject value = new JSONObject();
    NodeList nl = elt.getChildNodes();

    for (int i = 0; i < nl.getLength(); i++) {
        Node node = nl.item(i);/*from w  w  w  .j a va2  s .  co m*/

        if (node instanceof Element) {
            Element child = (Element) node;
            Object childValue = useType ? getValue(child, ignoreStepIds, useType) : null;

            if (childValue != null) {
                value.accumulate(child.getTagName(), childValue);
            } else {
                handleElement(child, value, ignoreStepIds, useType);
            }
        }
    }

    JSONObject attr = new JSONObject();
    NamedNodeMap nnm = elt.getAttributes();

    for (int i = 0; i < nnm.getLength(); i++) {
        Node node = nnm.item(i);
        if (ignoreStepIds && (node.getNodeName() != "step_id")) {
            attr.accumulate(node.getNodeName(), node.getNodeValue());
        }
    }

    if (value.length() == 0) {
        String content = elt.getTextContent();
        if (attr.length() == 0) {
            obj.accumulate(key, content);
        } else {
            value.accumulate("text", content);
        }
    }

    if (attr.length() != 0) {
        value.accumulate("attr", attr);
    }

    if (value.length() != 0) {
        obj.accumulate(key, value);
    }
}

From source file:com.hp.hpl.inkml.InkMLDOMParser.java

/**
 * Method to bind Context element/*  w  ww. j a v a 2  s.  c  om*/
 * 
 * @param element the Context element
 * @param definitions the definitions data object to resolve the reference attributes
 * @return Context data object
 * @throws InkMLException
 */
protected Context getContext(final Element element, final Definitions definitions) throws InkMLException {
    final Context context = new Context();
    // set value of the object from the value of the DOM element
    // Extract and set Attribute values
    final NamedNodeMap attrMap = element.getAttributes();
    final int length = attrMap.getLength();
    for (int i = 0; i < length; i++) {
        final Node attr = attrMap.item(i);
        context.setAttribute(attr.getLocalName(), attr.getNodeValue());
    }
    final NodeList list = element.getChildNodes();
    for (int i = 0; i < list.getLength(); i++) {
        final Node node = list.item(i);
        if (!(node instanceof Element)) {
            continue;
        }
        final Element child = (Element) node;
        this.addToContextChildrenList(child, context, definitions);
    }
    return context;
}

From source file:com.amalto.core.storage.hibernate.MappingGenerator.java

private Element newManyToOneElement(ReferenceFieldMetadata referencedField, boolean enforceDataBaseIntegrity) {
    Element propertyElement = document.createElement("many-to-one"); //$NON-NLS-1$
    Attr propertyName = document.createAttribute("name"); //$NON-NLS-1$
    propertyName.setValue(referencedField.getName());
    Attr className = document.createAttribute("class"); //$NON-NLS-1$
    className.setValue(ClassCreator.getClassName(referencedField.getReferencedType().getName()));
    // fetch="join" lazy="false"
    Attr lazy = document.createAttribute("lazy"); //$NON-NLS-1$
    lazy.setValue("proxy"); //$NON-NLS-1$
    propertyElement.getAttributes().setNamedItem(lazy);
    Attr joinAttribute = document.createAttribute("fetch"); //$NON-NLS-1$
    joinAttribute.setValue("join"); //$NON-NLS-1$
    propertyElement.getAttributes().setNamedItem(joinAttribute);
    // foreign-key="..."
    String fkConstraintName = resolver.getFkConstraintName(referencedField);
    if (!fkConstraintName.isEmpty()) {
        Attr foreignKeyConstraintName = document.createAttribute("foreign-key"); //$NON-NLS-1$
        foreignKeyConstraintName.setValue(fkConstraintName);
        propertyElement.getAttributes().setNamedItem(foreignKeyConstraintName);
        Attr indexName = document.createAttribute("index"); //$NON-NLS-1$
        indexName.setValue("FK_" + fkConstraintName); //$NON-NLS-1$
        propertyElement.getAttributes().setNamedItem(indexName);
    }/*w  w w .  j  a  va 2s . com*/
    // Not null
    if (referencedField.isMandatory() && generateConstrains) {
        Attr notNull = document.createAttribute("not-null"); //$NON-NLS-1$
        notNull.setValue("true"); //$NON-NLS-1$
        propertyElement.getAttributes().setNamedItem(notNull);
    } else {
        Attr notNull = document.createAttribute("not-null"); //$NON-NLS-1$
        notNull.setValue("false"); //$NON-NLS-1$
        propertyElement.getAttributes().setNamedItem(notNull);
    }
    // If data model authorizes fk integrity override, don't enforce database FK integrity.
    if (enforceDataBaseIntegrity) {
        // Ensure default settings for Hibernate are set (in case they change).
        Attr notFound = document.createAttribute("not-found"); //$NON-NLS-1$
        notFound.setValue("exception"); //$NON-NLS-1$
        propertyElement.getAttributes().setNamedItem(notFound);
    } else {
        // Disables all warning/errors from Hibernate.
        Attr integrity = document.createAttribute("unique"); //$NON-NLS-1$
        integrity.setValue("false"); //$NON-NLS-1$
        propertyElement.getAttributes().setNamedItem(integrity);

        Attr foreignKey = document.createAttribute("foreign-key"); //$NON-NLS-1$*
        // Disables foreign key generation for DDL.
        foreignKey.setValue("none"); //$NON-NLS-1$
        propertyElement.getAttributes().setNamedItem(foreignKey);

        Attr notFound = document.createAttribute("not-found"); //$NON-NLS-1$
        notFound.setValue("ignore"); //$NON-NLS-1$
        propertyElement.getAttributes().setNamedItem(notFound);
    }
    propertyElement.getAttributes().setNamedItem(propertyName);
    propertyElement.getAttributes().setNamedItem(className);
    // Cascade delete
    if (Boolean.parseBoolean(referencedField.<String>getData(SQL_DELETE_CASCADE))) {
        Attr cascade = document.createAttribute("cascade"); //$NON-NLS-1$
        cascade.setValue("lock, save-update, delete"); //$NON-NLS-1$
        propertyElement.getAttributes().setNamedItem(cascade);
    }
    isDoingColumns = true;
    isColumnMandatory = referencedField.isMandatory() && generateConstrains;
    this.parentElement = propertyElement;
    compositeKeyPrefix = referencedField.getName();
    {
        referencedField.getReferencedField().accept(this);
    }
    isDoingColumns = false;
    return propertyElement;
}

From source file:com.nridge.ds.solr.SolrSchemaXML.java

private DataField loadField(Element anElement) {
    Attr nodeAttr;/*from w  w  w  .j  a v a2s . c  o  m*/
    DataField dataField;
    Field.Type fieldType;
    String nodeName, nodeValue;
    Logger appLogger = mAppMgr.getLogger(this, "loadField");

    appLogger.trace(mAppMgr.LOGMSG_TRACE_ENTER);

    String attrValue = anElement.getAttribute("name");
    if (StringUtils.isNotEmpty(attrValue)) {
        String fieldName = attrValue;
        attrValue = anElement.getAttribute("type");
        if (StringUtils.isNotEmpty(attrValue))
            fieldType = mapSolrFieldType(attrValue);
        else
            fieldType = Field.Type.Text;
        dataField = new DataField(fieldType, fieldName);
        dataField.setTitle(Field.nameToTitle(fieldName));

        NamedNodeMap namedNodeMap = anElement.getAttributes();
        int attrCount = namedNodeMap.getLength();
        for (int attrOffset = 0; attrOffset < attrCount; attrOffset++) {
            nodeAttr = (Attr) namedNodeMap.item(attrOffset);
            nodeName = nodeAttr.getNodeName();
            nodeValue = nodeAttr.getNodeValue();

            if (StringUtils.isNotEmpty(nodeValue)) {
                if ((!StringUtils.equalsIgnoreCase(nodeName, "name"))
                        && (!StringUtils.equalsIgnoreCase(nodeName, "type")))
                    assignSolrFieldFeature(dataField, nodeName, nodeValue);
            }
        }
    } else
        dataField = null;

    appLogger.trace(mAppMgr.LOGMSG_TRACE_DEPART);

    return dataField;
}