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.getobjects.eoaccess.EOModelLoader.java

/**
 * Handle the "entity" tag./* w  ww . j  a v  a 2  s .  co  m*/
 * <p>
 * Attributes:
 * <pre>
 *   name          - String - name of entity
 *   table         - String
 *   schema        - String - none =&gt; inherit from model, "" =&gt; no schema
 *   class         - String - name of class for rows
 *   datasource    - String - name of datasource class
 *   tableNameLike - String - makes this a pattern entity for matches
 *   primarykey    - String - name of primary key attribute
 *   primarykeys   - String - comma separated names of pkey attributes
 *   readonly      - bool
 *   flags         - String - 'readonly' flag
 *   restrictingQualifier - String - an EOQualifier
 * </pre>
 *
 * Child elements:
 * <pre>
 *   "attribute" tags
 *   "to-one"    tags
 *   "to-many"   tags
 *   "fetch"     tags
 *   "operation" tags (not yet implemented)
 * </pre>
 */
protected EOEntity loadEntityFromElement(Element _node, Map<String, Object> _modelOpts) {
    if (_node == null)
        return null;
    if (!_node.getTagName().equals("entity")) {
        log.info("given node is not a <entity> tag");
        return null;
    }

    EOAttribute[] attrs = this.loadAttributesFromElement(_node);
    if (attrs == null)
        return null;

    EORelationship[] relships = this.loadRelationshipsFromElement(_node);

    /* determine attributes */

    String tableName = _node.getAttribute("table");
    String schemaName = _node.getAttribute("schema");
    String entityName = _node.getAttribute("name");
    String className = _node.getAttribute("class");
    String dsClassName = _node.getAttribute("datasource");
    String eQualifier = _node.getAttribute("restrictingQualifier");

    boolean tableNameIsPattern = false;
    if (tableName == null || tableName.length() == 0) {
        tableNameIsPattern = true;
        tableName = _node.getAttribute("tableNameLike");
        if (tableName == null || tableName.length() == 0) {
            if (entityName != null && entityName.length() > 0) {
                /* be tolerant, derive tablename from entity name ... */
                tableNameIsPattern = false;
                tableName = entityName;
            } else {
                this.addError("missing table name for entity");
                return null;
            }
        }
    }

    if (entityName == null || entityName.length() == 0) {
        if (!tableNameIsPattern)
            entityName = tableName;
    }

    if (className != null && className.length() == 0)
        className = null;
    if (dsClassName != null && dsClassName.length() == 0)
        dsClassName = null;

    if (schemaName == null)
        schemaName = (String) _modelOpts.get("defaultSchema");
    else if (schemaName.length() == 0) /* if you do NOT want to inherit */
        schemaName = null;

    String pkeys[] = null;
    String pkeyv = _node.getAttribute("primarykey");
    if (pkeyv != null && pkeyv.length() > 0) {
        pkeys = new String[] { pkeyv };
    } else {
        /* treat the value as a CSV list */
        pkeyv = _node.getAttribute("primarykeys");
        if (pkeyv != null && pkeyv.length() > 0)
            pkeys = pkeyv.split(",");
    }

    if (pkeys == null)
        log.warn("no primary key found for Entity named " + entityName);

    Boolean readonly = this.getBoolAttribute(_node, "readonly");
    String flagSet = _node.getAttribute("flags");
    if (flagSet != null && flagSet.length() > 0) {
        if (readonly == null)
            readonly = flagSet.contains("readonly");
    }

    // TODO: process restricting qualifier

    /* load fetch specifications and adaptor ops */

    Map<String, EOFetchSpecification> fspecs = this.loadFetchSpecificationsFromElement(entityName, _node);

    Map<String, EOAdaptorOperation[]> ops = this.loadAdaptorOperationsFromElement(entityName, _node);

    /* construct */

    EOEntity entity = new EOEntity(entityName, tableName, tableNameIsPattern, schemaName, className,
            dsClassName, attrs, pkeys, relships, fspecs, ops);
    if (readonly != null)
        entity.isReadOnly = readonly;

    if (eQualifier != null) {
        EOQualifier q = EOQualifier.qualifierWithQualifierFormat(eQualifier);
        entity.setRestrictingQualifier(q);
    }

    return entity;
}

From source file:org.getobjects.eoaccess.EOModelLoader.java

/**
 * Example://w ww.  j a  va 2 s. c om
 * <pre>
 *   &lt;attribute column="id" autoincrement="true" null="false" /&gt;
 * </pre>
 * <p>
 * Attributes:
 * <pre>
 *   name           - property name of attribute (defaults to column)
 *   column         - column name of attribute
 *   columnNameLike - makes this a pattern attribute for matching columns
 *   autoincrement  - boolean -
 *   null           - boolean -
 *   type           - String  - SQL type, eg VARCHAR2
 *   readformat     - String
 *   writeformat    - String
 * </pre>
 */
protected EOAttribute loadAttributeFromElement(Element _node) {
    if (_node == null)
        return null;
    if (!_node.getTagName().equals("attribute")) {
        log.info("given node is not an <attribute> tag");
        return null;
    }

    /* extract attributes */

    String s;

    boolean isColumnPattern = false;

    s = _node.getAttribute("name");
    String name = UObject.isNotEmpty(s) ? s : null;
    s = _node.getAttribute("column");
    String column = UObject.isNotEmpty(s) ? s : null;

    if (column == null) {
        s = _node.getAttribute("columnNameLike");
        column = UObject.isNotEmpty(s) ? s : null;
        if (column == null) {
            if ((column = name) == null) {
                this.addError("missing column name for attribute: " + _node);
                return null;
            }
        } else
            isColumnPattern = true;
    } else if (name == null)
        name = column;

    s = _node.getAttribute("autoincrement");
    Boolean isAutoIncrement = UObject.isNotEmpty(s) ? UObject.boolValue(s) : null;
    s = _node.getAttribute("null");
    Boolean allowsNull = UObject.isNotEmpty(s) ? UObject.boolValue(s) : null;
    s = _node.getAttribute("notnull"); /* backwards compat */
    if (allowsNull != null && UObject.isNotEmpty(s)) {
        log.warn("both 'null' and 'notnull' attribute set for attribute '" + name + "', discarding 'notnull'");
    } else if (allowsNull == null && UObject.isNotEmpty(s)) {
        allowsNull = !UObject.boolValue(s);
    }

    s = _node.getAttribute("readformat");
    String readformat = UObject.isNotEmpty(s) ? s : null;
    s = _node.getAttribute("writeformat");
    String writeformat = UObject.isNotEmpty(s) ? s : null;

    // TODO: column type

    EOAttribute attr = new EOAttribute(name, column, isColumnPattern, _node.getAttribute("type"),
            isAutoIncrement, allowsNull, null, // TODO: width
            readformat, writeformat, null, // TODO: default
            null, /* comment     */
            null, /* collation   */
            null /* privileges */);
    return attr;
}

From source file:org.getobjects.eoaccess.EOModelLoader.java

/**
 * 'to-one' or 'to-many' tags/*from ww  w .ja v  a2s . com*/
 * <p>
 * Attributes:<pre>
 *   name              - name of relationship
 *   to or destination - name of target entity
 *   target            - name of target entity
 *   join              - Strings separated by comma</pre>
 *
 * Eg:<pre>
 *   &lt;to-one  name="toProject" to="Project" join="companyId,ownerId" /&gt;
 *   &lt;to-many name="toOwner"   to="Account" join="ownerId,companyId" /&gt;
 *   &lt;to-one  to="Project" join="companyId,ownerId" />
 * </pre>
 */
// TODO: support join subelements
protected EORelationship loadRelationshipFromElement(Element _node) {
    if (_node == null)
        return null;
    if (!_node.getTagName().startsWith("to")) {
        log.info("given node is not a <relationship> tag");
        return null;
    }

    /* extract attributes */

    String s;

    boolean isToMany = _node.getTagName().contains("many");

    s = _node.getAttribute("name");
    String name = UObject.isNotEmpty(s) ? s : null;

    s = _node.getAttribute("to");
    String destEntity = UObject.isNotEmpty(s) ? s : null;
    if (destEntity == null) {
        s = _node.getAttribute("destination");
        destEntity = UObject.isNotEmpty(s) ? s : null;
    }
    if (destEntity == null) {
        s = _node.getAttribute("target");
        destEntity = UObject.isNotEmpty(s) ? s : null;
    }

    /* default: is toTarget, eg to=Project => toProject */
    // TBD: such stuff belongs in the name-beautifier?
    if (name == null)
        name = "to" + destEntity;

    /* join attribute */

    s = _node.getAttribute("join");
    String[] parts = s != null ? s.split(",") : null;
    EOJoin[] joins = null;

    if (parts != null && parts.length == 1) {
        joins = new EOJoin[1];
        joins[0] = new EOJoin(parts[0], parts[0]);
    } else if (parts != null && parts.length > 1) {
        joins = new EOJoin[parts.length / 2];
        for (int i = 0; i < parts.length; i += 2)
            joins[i / 2] = new EOJoin(parts[i], parts[i + 1]);
    }
    // TODO: join subelements

    /* construct */

    EORelationship rel = new EORelationship(name, isToMany, null /* entity */, destEntity, joins);
    return rel;
}

From source file:org.getobjects.eoaccess.EOModelLoader.java

/**
 * "fetch" tag//  w w w  .  j  av a2s .c o m
 * <p>
 * Attributes:<pre>
 *   name       - String  - name of fetch specification
 *   rawrows    - boolean - do not map to objects, return raw Map's
 *   distinct   - boolean - make results distinct
 *   deep       - boolean - make a deep query (for hierarchical datasets)
 *   readonly   - boolean - do not store a snapshot to track modifications
 *   lock       - boolean - attempt some SQL lock
 *   requiresAllBindings  - boolean - all bindings must be filled
 *   attributes - CSV     - rawrows|distinct|deep|readonly|lock|allbinds
 *   limit      - int
 *   offset     - int
 *   prefetch   - CSV     - list of prefetch pathes
 * </pre>
 * Children:<pre>
 *   'attribute' tags - CSV (eg name,lastname,firstname)
 *   'prefetch'  tags - CSV (eg employments.company,projects)
 *   'qualifier' tags
 *   'ordering'  tags
 *   'sql'       tags (with pattern attribute)
 *     - EOCustomQueryExpressionHintKeyBindPattern (with pattern)
 *     - EOCustomQueryExpressionHintKey (w/o pattern)</pre>
 *
 * Example:<pre>
 *   &lt;fetch name="count" rawrows="true"&gt;
 *     &lt;sql&gt;SELECT COUNT(*) FROM table&lt;/sql&gt;
 *   &lt;/fetch&gt;
 *
 *   &lt;fetch name="abc" distinct="true" deep="false" lock="false"
 *          requiresAllBindings="true" limit="100" offset="0"
 *          entity="Contact"
 *          attributes="id,lastname,firstname"
 *     &gt;
 *     &lt;qualifier>lastname like $name&lt;/qualifier&gt;
 *     &lt;ordering key="balance" order="DESC" /&gt;
 *     &lt;ordering key="lastname" /&gt;
 *   &lt;/fetch&gt;
 * </pre>
 */
protected EOFetchSpecification loadFetchSpecificationFromElement(String _entityName, Element _node) {
    /*
     * TODO: would be cool to allow intermixing of raw SQL and qualifiers, like:
     *   <fetch name="count" rawrows="true">
     *     <sql>SELECT COUNT(T.*) FROM table T, rel X WHERE </sql>
     *     <qualifier>T.lastname = $lastname</qualifier>
     *     <sql> AND T.id = X.id</sql>
     *     <ordering>lastname</ordering>
     *   </fetch>
     */

    if (_node == null)
        return null;
    if (!_node.getTagName().equals("fetch")) {
        log.info("given node is not a <fetch> tag");
        return null;
    }

    Map<String, Object> hints = new HashMap<String, Object>(4);
    String s;

    /* flags */

    Boolean fetchesRawRows = this.getBoolAttribute(_node, "rawrows");
    Boolean distinct = this.getBoolAttribute(_node, "distinct");
    Boolean deep = this.getBoolAttribute(_node, "deep");
    Boolean readonly = this.getBoolAttribute(_node, "readonly");
    Boolean lock = this.getBoolAttribute(_node, "lock");
    Boolean requiresAllBindings = this.getBoolAttribute(_node, "requiresAllBindings");

    String flagSet = _node.getAttribute("flags");
    if (flagSet != null && flagSet.length() > 0) {
        if (fetchesRawRows == null)
            fetchesRawRows = flagSet.contains("raw");
        if (distinct == null)
            distinct = flagSet.contains("distinct");
        if (readonly == null)
            readonly = flagSet.contains("readonly");
        if (lock == null)
            lock = flagSet.contains("lock");
        if (requiresAllBindings == null)
            requiresAllBindings = flagSet.contains("allbinds");
    }

    if (distinct == null)
        distinct = Boolean.FALSE;
    if (deep == null)
        deep = Boolean.FALSE;

    /* more attributes */

    Integer limit = this.getIntAttribute(_node, "limit");
    Integer offset = this.getIntAttribute(_node, "offset");
    String entityName = _node.getAttribute("entity");
    if (entityName != null && entityName.length() == 0)
        entityName = null;
    if (entityName == null)
        entityName = _entityName;

    //    /* walk elements */
    //    TBD: walk objects in sequence, possibly creating merged SQL expressions
    //
    //    NodeList children = _node.getChildNodes();
    //    if (children != null && children.getLength() > 0) {
    //      List<String> collectAttrs = new ArrayList<String>(8);
    //
    //      for (int i = 0; i < children.getLength(); i++) {
    //        Node node = children.item(i);
    //        if (node == null || !(node instanceof Element)) continue;
    //
    //        Element element = (Element)node;
    //        String  tagName = element.getTagName();
    //
    //        if ("attributes".equals(tagName)) {
    //        }
    //      }
    //    }

    /* fetch attributes */

    String[] fetchAttributes = null;
    String[] prefetchPaths = null;

    s = _node.getAttribute("attributes");
    if (UObject.isNotEmpty(s)) {
        fetchAttributes = s.split(",");
    } else {
        s = this.joinTrimmedTextsOfElements(_node.getElementsByTagName("attributes"), ",");
        if (UObject.isNotEmpty(s))
            fetchAttributes = s.split(",");
    }

    s = _node.getAttribute("prefetch");
    if (UObject.isNotEmpty(s)) {
        prefetchPaths = s.split(",");
    } else {
        s = this.joinTrimmedTextsOfElements(_node.getElementsByTagName("prefetch"), ",");
        if (UObject.isNotEmpty(s))
            prefetchPaths = s.split(",");
    }

    /* qualifiers */

    s = this.joinTrimmedTextsOfElements(_node.getElementsByTagName("qualifier"), " AND ");
    EOQualifier qualifier = s != null ? EOQualifier.qualifierWithQualifierFormat(s) : null;
    if (s != null && qualifier == null) {
        log.error("could not parse qualifier in model:\n'" + s + "'");
        return null;
    }

    /* sort-orderings */

    EOSortOrdering[] orderings = null;
    NodeList orderingNodes = _node.getElementsByTagName("ordering");
    if (orderingNodes != null && orderingNodes.getLength() > 0) {
        orderings = new EOSortOrdering[orderingNodes.getLength()];
        for (int i = 0; i < orderingNodes.getLength(); i++) {
            orderings[i] = this.loadOrderingFromElement((Element) orderingNodes.item(i));
            if (orderings[i] == null) {
                log.error("could not parse an ordering in model: " + orderingNodes.item(i));
                return null;
            }
        }
    }

    /* custom SQL */

    NodeList sqlNodes = _node.getElementsByTagName("sql");
    s = this.joinTrimmedTextsOfElements(sqlNodes, "; ");
    if (UObject.isNotEmpty(s)) {
        Boolean pat = this.getBoolAttribute((Element) sqlNodes.item(0), "pattern");
        if (pat != null && pat)
            hints.put("EOCustomQueryExpressionHintKeyBindPattern", s);
        else
            hints.put("EOCustomQueryExpressionHintKey", s);
    }

    /* construct */

    if (hints.size() == 0)
        hints = null;

    EOFetchSpecification fs = new EOFetchSpecification(entityName, qualifier, orderings, distinct, deep, hints);

    if (fetchesRawRows != null)
        fs.setFetchesRawRows(fetchesRawRows);
    if (readonly != null)
        fs.setFetchesReadOnly(readonly);
    if (lock != null)
        fs.setLocksObjects(lock);
    if (limit != null)
        fs.setFetchLimit(limit);
    if (offset != null)
        fs.setFetchOffset(offset);
    if (fetchAttributes != null)
        fs.setFetchAttributeNames(fetchAttributes);
    if (prefetchPaths != null && prefetchPaths.length > 0)
        fs.setPrefetchingRelationshipKeyPaths(prefetchPaths);

    if (requiresAllBindings != null)
        fs.setRequiresAllQualifierBindingVariables(requiresAllBindings);

    return fs;
}

From source file:org.getobjects.eoaccess.EOModelLoader.java

protected EOSortOrdering loadOrderingFromElement(Element _e) {
    /*/* w ww .  ja va 2s.c om*/
     * Eg:
     *   <ordering key="lastname" operation="DESC" />
     */
    if (_e == null)
        return null;
    if (!_e.getTagName().startsWith("order")) { // allow orderby, etc
        log.info("given node is not a <ordering> tag");
        return null;
    }

    /* determine key */

    String key = _e.getAttribute("key");
    if (key == null || key.length() == 0)
        key = _e.getTextContent();

    if (key == null || key.length() == 0) {
        log.error("could not parse an ordering in model: " + _e);
        return null;
    }

    /* determine selector */

    String ssel = _e.getAttribute("operation");
    if (ssel == null || ssel.length() == 0)
        ssel = _e.getAttribute("op");
    if (ssel == null || ssel.length() == 0)
        ssel = _e.getAttribute("order");
    Object sel;
    if (ssel == null || ssel.length() == 0)
        sel = EOSortOrdering.EOCompareAscending;
    else if ("ASC".equalsIgnoreCase(ssel))
        sel = EOSortOrdering.EOCompareAscending;
    else if ("DESC".equalsIgnoreCase(ssel))
        sel = EOSortOrdering.EOCompareDescending;
    else if ("CASE ASC".equalsIgnoreCase(ssel))
        sel = EOSortOrdering.EOCompareCaseInsensitiveAscending;
    else if ("CASE DESC".equalsIgnoreCase(ssel))
        sel = EOSortOrdering.EOCompareCaseInsensitiveDescending;
    else
        sel = ssel;

    return new EOSortOrdering(key, sel);
}

From source file:org.glom.app.libglom.Document.java

/**
 * @param node/*from  w w w. j  a  v a  2 s.c  om*/
 * @return
 */
private List<LayoutGroup> loadLayoutNode(final Element node, final String tableName, final String layoutName) {
    if (node == null) {
        return null;
    }

    final List<LayoutGroup> result = new ArrayList<>();
    int groupIndex = 0;
    final List<Node> listNodes = getChildrenByTagName(node, NODE_DATA_LAYOUT_GROUPS);
    for (final Node nodeGroups : listNodes) {
        if (!(nodeGroups instanceof Element)) {
            continue;
        }

        final Element elementGroups = (Element) nodeGroups;

        final NodeList list = elementGroups.getChildNodes();
        final int num = list.getLength();
        for (int i = 0; i < num; i++) {
            final Node nodeLayoutGroup = list.item(i);
            if (nodeLayoutGroup == null) {
                continue;
            }

            if (!(nodeLayoutGroup instanceof Element)) {
                continue;
            }

            final Path path = new Path();
            path.tableName = tableName;
            path.layoutName = layoutName;
            path.indices[0 /* depth */] = groupIndex;
            ++groupIndex;

            final Element element = (Element) nodeLayoutGroup;
            final String tagName = element.getTagName();
            switch (tagName) {
            case NODE_DATA_LAYOUT_GROUP: {
                final LayoutGroup group = new LayoutGroup();
                loadDataLayoutGroup(element, group, tableName, path);
                result.add(group);
                break;
            }
            case NODE_DATA_LAYOUT_NOTEBOOK: {
                final LayoutItemNotebook group = new LayoutItemNotebook();
                loadDataLayoutGroup(element, group, tableName, path);
                result.add(group);
                break;
            }
            case NODE_DATA_LAYOUT_PORTAL:
                final LayoutItemPortal portal = new LayoutItemPortal();
                loadDataLayoutPortal(element, portal, tableName, path);
                result.add(portal);
                break;
            }
        }
    }

    return result;
}

From source file:org.glom.app.libglom.Document.java

/**
 * @param nodeGroup//from  w  w w .  java2 s.c o m
 * @param group
 */
private void loadDataLayoutGroup(final Element nodeGroup, final LayoutGroup group, final String tableName,
        final Path path) {
    loadTitle(nodeGroup, group);

    // Read the column count:
    int columnCount = (int) getAttributeAsDecimal(nodeGroup, ATTRIBUTE_LAYOUT_GROUP_COLUMNS_COUNT);
    if (columnCount < 1) {
        columnCount = 1; // 0 is a useless default.
    }
    group.setColumnCount(columnCount);

    final int depth = path.indices.length;

    // Get the child items:
    final NodeList listNodes = nodeGroup.getChildNodes();
    final int num = listNodes.getLength();
    int pathIndex = 0;
    for (int i = 0; i < num; i++) {

        final Node node = listNodes.item(i);
        if (!(node instanceof Element)) {
            continue;
        }

        final Element element = (Element) node;
        final String tagName = element.getTagName();

        //Do not increment pathIndex for an item
        //that we will not use:
        if (tagName.equals(NODE_TRANSLATIONS_SET)) {
            continue;
        }

        // Create a path of indices for the child:
        final Path pathChild = new Path();
        pathChild.tableName = path.tableName;
        pathChild.layoutName = path.layoutName;
        pathChild.indices = new int[path.indices.length + 1];
        System.arraycopy(path.indices, 0, pathChild.indices, 0, path.indices.length);
        pathChild.indices[depth] = pathIndex;
        pathIndex++;

        switch (tagName) {
        case NODE_DATA_LAYOUT_GROUP: {
            final LayoutGroup childGroup = new LayoutGroup();
            loadDataLayoutGroup(element, childGroup, tableName, pathChild);
            group.addItem(childGroup);
            break;
        }
        case NODE_DATA_LAYOUT_NOTEBOOK: {
            final LayoutItemNotebook childGroup = new LayoutItemNotebook();
            loadDataLayoutGroup(element, childGroup, tableName, pathChild);
            group.addItem(childGroup);
            break;
        }
        case NODE_DATA_LAYOUT_PORTAL: {
            final LayoutItemPortal childGroup = new LayoutItemPortal();
            loadDataLayoutPortal(element, childGroup, tableName, pathChild);
            group.addItem(childGroup);
            break;
        }
        case NODE_DATA_LAYOUT_ITEM: {
            final LayoutItemField item = new LayoutItemField();
            loadDataLayoutItemField(element, item, tableName);
            group.addItem(item);
            break;
        }
        case NODE_DATA_LAYOUT_TEXTOBJECT: {
            final LayoutItemText item = new LayoutItemText();
            loadDataLayoutItemText(element, item);
            group.addItem(item);
            break;
        }
        case NODE_DATA_LAYOUT_IMAGEOBJECT: {
            final LayoutItemImage item = new LayoutItemImage();
            loadDataLayoutItemImage(element, item, pathChild);
            group.addItem(item);
            break;
        }
        case NODE_DATA_LAYOUT_ITEM_GROUPBY: {
            final LayoutItemGroupBy item = new LayoutItemGroupBy();
            loadDataLayoutItemGroupBy(element, item, tableName, pathChild);
            group.addItem(item);
            break;
        }
        }
    }
}

From source file:org.glom.web.server.libglom.Document.java

/**
 * @param node/*from  w w w . j av  a 2 s  .c o  m*/
 * @return
 */
private List<LayoutGroup> loadLayoutNode(final Element node, final String tableName, final String layoutName) {
    if (node == null) {
        return null;
    }

    final List<LayoutGroup> result = new ArrayList<LayoutGroup>();
    int groupIndex = 0;
    final List<Node> listNodes = getChildrenByTagName(node, NODE_DATA_LAYOUT_GROUPS);
    for (final Node nodeGroups : listNodes) {
        if (!(nodeGroups instanceof Element)) {
            continue;
        }

        final Element elementGroups = (Element) nodeGroups;

        final NodeList list = elementGroups.getChildNodes();
        final int num = list.getLength();
        for (int i = 0; i < num; i++) {
            final Node nodeLayoutGroup = list.item(i);
            if (nodeLayoutGroup == null) {
                continue;
            }

            if (!(nodeLayoutGroup instanceof Element)) {
                continue;
            }

            final Path path = new Path();
            path.tableName = tableName;
            path.layoutName = layoutName;
            path.indices[0 /* depth */] = groupIndex;
            ++groupIndex;

            final Element element = (Element) nodeLayoutGroup;
            final String tagName = element.getTagName();
            if (tagName.equals(NODE_DATA_LAYOUT_GROUP)) {
                final LayoutGroup group = new LayoutGroup();
                loadDataLayoutGroup(element, group, tableName, path);
                result.add(group);
            } else if (tagName.equals(NODE_DATA_LAYOUT_NOTEBOOK)) {
                final LayoutItemNotebook group = new LayoutItemNotebook();
                loadDataLayoutGroup(element, group, tableName, path);
                result.add(group);
            } else if (tagName.equals(NODE_DATA_LAYOUT_PORTAL)) {
                final LayoutItemPortal portal = new LayoutItemPortal();
                loadDataLayoutPortal(element, portal, tableName, path);
                result.add(portal);
            }
        }
    }

    return result;
}

From source file:org.glom.web.server.libglom.Document.java

/**
 * @param element/*  www . j av a2  s.  c  om*/
 * @param group
 */
private void loadDataLayoutGroup(final Element nodeGroup, final LayoutGroup group, final String tableName,
        final Path path) {
    loadTitle(nodeGroup, group);

    // Read the column count:
    int columnCount = (int) getAttributeAsDecimal(nodeGroup, ATTRIBUTE_LAYOUT_GROUP_COLUMNS_COUNT);
    if (columnCount < 1) {
        columnCount = 1; // 0 is a useless default.
    }
    group.setColumnCount(columnCount);

    final int depth = path.indices.length;

    // Get the child items:
    final NodeList listNodes = nodeGroup.getChildNodes();
    final int num = listNodes.getLength();
    int pathIndex = 0;
    for (int i = 0; i < num; i++) {

        final Node node = listNodes.item(i);
        if (!(node instanceof Element)) {
            continue;
        }

        final Element element = (Element) node;
        final String tagName = element.getTagName();

        //Do not increment pathIndex for an item
        //that we will not use:
        if (tagName.equals(NODE_TRANSLATIONS_SET)) {
            continue;
        }

        // Create a path of indices for the child:
        final Path pathChild = new Path();
        pathChild.tableName = path.tableName;
        pathChild.layoutName = path.layoutName;
        pathChild.indices = new int[path.indices.length + 1];
        System.arraycopy(path.indices, 0, pathChild.indices, 0, path.indices.length);
        pathChild.indices[depth] = pathIndex;
        pathIndex++;

        if (tagName.equals(NODE_DATA_LAYOUT_GROUP)) {
            final LayoutGroup childGroup = new LayoutGroup();
            loadDataLayoutGroup(element, childGroup, tableName, pathChild);
            group.addItem(childGroup);
        } else if (tagName.equals(NODE_DATA_LAYOUT_NOTEBOOK)) {
            final LayoutItemNotebook childGroup = new LayoutItemNotebook();
            loadDataLayoutGroup(element, childGroup, tableName, pathChild);
            group.addItem(childGroup);
        } else if (tagName.equals(NODE_DATA_LAYOUT_PORTAL)) {
            final LayoutItemPortal childGroup = new LayoutItemPortal();
            loadDataLayoutPortal(element, childGroup, tableName, pathChild);
            group.addItem(childGroup);
        } else if (tagName.equals(NODE_DATA_LAYOUT_ITEM)) {
            final LayoutItemField item = new LayoutItemField();
            loadDataLayoutItemField(element, item, tableName);
            group.addItem(item);
        } else if (tagName.equals(NODE_DATA_LAYOUT_TEXTOBJECT)) {
            final LayoutItemText item = new LayoutItemText();
            loadDataLayoutItemText(element, item);
            group.addItem(item);
        } else if (tagName.equals(NODE_DATA_LAYOUT_IMAGEOBJECT)) {
            final LayoutItemImage item = new LayoutItemImage();
            loadDataLayoutItemImage(element, item, pathChild);
            group.addItem(item);
        } else if (tagName.equals(NODE_DATA_LAYOUT_ITEM_GROUPBY)) {
            final LayoutItemGroupBy item = new LayoutItemGroupBy();
            loadDataLayoutItemGroupBy(element, item, tableName, pathChild);
            group.addItem(item);
        }
    }
}

From source file:org.gvnix.flex.ui.MxmlRoundTripUtils.java

/**
 * Create a base 64 encoded SHA1 hash key for a given XML element. The key
 * is based on the element name, the attribute names and their values. Child
 * elements are ignored. Attributes named 'z' are not concluded since they
 * contain the hash key itself.//from  w w  w .  j  a  va 2  s  . c o  m
 * 
 * @param element The element to create the base 64 encoded hash key for
 * @return the unique key
 */
public static String calculateUniqueKeyFor(Element element) {
    StringBuilder sb = new StringBuilder();
    sb.append(element.getTagName());
    NamedNodeMap attributes = element.getAttributes();
    SortedMap<String, String> attrKVStore = Collections.synchronizedSortedMap(new TreeMap<String, String>());
    for (int i = 0; i < attributes.getLength(); i++) {
        Node attr = attributes.item(i);
        if (!"z".equals(attr.getNodeName()) && !attr.getNodeName().startsWith("_")) {
            attrKVStore.put(attr.getNodeName(), attr.getNodeValue());
        }
    }
    for (Entry<String, String> entry : attrKVStore.entrySet()) {
        sb.append(entry.getKey()).append(entry.getValue());
    }
    return base64(sha1(sb.toString().getBytes()));
}