Example usage for org.dom4j Element elements

List of usage examples for org.dom4j Element elements

Introduction

In this page you can find the example usage for org.dom4j Element elements.

Prototype

List<Element> elements(QName qName);

Source Link

Document

Returns the elements contained in this element with the given fully qualified name.

Usage

From source file:cn.itcreator.android.reader.util.XMLUtil.java

License:Open Source License

/**
 * the file parse to a list //from w w w .  j  a va  2  s.  c  o m
 * @return
 */
public List<BookMark> fileToList() {
    List<BookMark> list = new ArrayList<BookMark>();
    List<Element> el = null;
    Element elt = mDocument.getRootElement();
    if (null != elt)
        el = elt.elements("mark");
    if (el != null) {
        Iterator<Element> l = el.iterator();
        while (l.hasNext()) {
            Element Element = (Element) l.next();
            int offset = 0;
            try {
                offset = Integer.parseInt(Element.attributeValue("currentOffset"));
            } catch (Exception e) {
                offset = 0;
            }
            BookMark b = new BookMark(offset, Element.attributeValue("markName"), Constant.BOOK_ID_IN_DATABASE);
            list.add(b);
        }
    }
    System.gc();
    return list;
}

From source file:com.adspore.splat.xep0060.PubSubEngine.java

License:Open Source License

private static IQ getPublishedItems(PubSubService service, IQ iq, Element itemsElement) {
    String nodeID = itemsElement.attributeValue("node");
    String subID = itemsElement.attributeValue("subid");
    Node node;//from w ww .jav a  2  s.  co m
    if (nodeID == null) {
        // User must specify a leaf node ID so return a nodeid-required error
        Element pubsubError = DocumentHelper
                .createElement(QName.get("nodeid-required", "http://jabber.org/protocol/pubsub#errors"));
        return createErrorPacket(iq, PacketError.Condition.bad_request, pubsubError);
    } else {
        // Look for the specified node
        node = service.getNode(nodeID);
        if (node == null) {
            // Node does not exist. Return item-not-found error
            return createErrorPacket(iq, PacketError.Condition.item_not_found, null);
        }
    }
    if (node.isCollectionNode()) {
        // Node is a collection node. Return feature-not-implemented error
        Element pubsubError = DocumentHelper
                .createElement(QName.get("unsupported", "http://jabber.org/protocol/pubsub#errors"));
        pubsubError.addAttribute("feature", "retrieve-items");
        return createErrorPacket(iq, PacketError.Condition.feature_not_implemented, pubsubError);
    }
    // Check if sender and subscriber JIDs match or if a valid "trusted proxy" is being used
    JID subscriberJID = iq.getFrom();
    // TODO Assumed that the owner of the subscription is the bare JID of the subscription JID. Waiting StPeter answer for explicit field.
    JID owner = new JID(subscriberJID.getNode(), subscriberJID.getDomain(), null, true);
    // Check if the node's access model allows the subscription to proceed
    AccessModel accessModel = node.getAccessModel();
    if (!accessModel.canAccessItems(node, owner, subscriberJID)) {
        return createErrorPacket(iq, accessModel.getSubsriptionError(),
                accessModel.getSubsriptionErrorDetail());
    }
    // Check that the requester is not an outcast
    NodeAffiliate affiliate = node.getAffiliate(owner);
    if (affiliate != null && affiliate.getAffiliation() == NodeAffiliate.Affiliation.outcast) {
        return createErrorPacket(iq, PacketError.Condition.forbidden, null);
    }

    // Get the user's subscription
    NodeSubscription subscription = null;
    if (node.isMultipleSubscriptionsEnabled() && (node.getSubscriptions(owner).size() > 1)) {
        if (subID == null) {
            // No subid was specified and the node supports multiple subscriptions and the user
            // has multiple subscriptions
            Element pubsubError = DocumentHelper
                    .createElement(QName.get("subid-required", "http://jabber.org/protocol/pubsub#errors"));
            return createErrorPacket(iq, PacketError.Condition.bad_request, pubsubError);
        } else {
            // Check if the specified subID belongs to an existing node subscription
            subscription = node.getSubscription(subID);
            if (subscription == null) {
                Element pubsubError = DocumentHelper
                        .createElement(QName.get("invalid-subid", "http://jabber.org/protocol/pubsub#errors"));
                return createErrorPacket(iq, PacketError.Condition.not_acceptable, pubsubError);
            }
        }
    }

    if (subscription != null && !subscription.isActive()) {
        Element pubsubError = DocumentHelper
                .createElement(QName.get("not-subscribed", "http://jabber.org/protocol/pubsub#errors"));
        return createErrorPacket(iq, PacketError.Condition.not_authorized, pubsubError);
    }

    LeafNode leafNode = (LeafNode) node;
    // Get list of items to send to the user
    boolean forceToIncludePayload = false;
    List<PublishedItem> items;
    String max_items = itemsElement.attributeValue("max_items");
    int recentItems = 0;
    if (max_items != null) {
        try {
            // Parse the recent number of items requested
            recentItems = Integer.parseInt(max_items);
        } catch (NumberFormatException e) {
            // There was an error parsing the number so assume that all items were requested
            Log.warn("Assuming that all items were requested", e);
            max_items = null;
        }
    }
    if (max_items != null) {
        // Get the N most recent published items
        items = new ArrayList<PublishedItem>(leafNode.getPublishedItems(recentItems));
    } else {
        List requestedItems = itemsElement.elements("item");
        if (requestedItems.isEmpty()) {
            // Get all the active items that were published to the node
            items = new ArrayList<PublishedItem>(leafNode.getPublishedItems());
        } else {
            items = new ArrayList<PublishedItem>();
            // Indicate that payload should be included (if exists) no matter
            // the node configuration
            forceToIncludePayload = true;
            // Get the items as requested by the user
            for (Iterator it = requestedItems.iterator(); it.hasNext();) {
                Element element = (Element) it.next();
                String itemID = element.attributeValue("id");
                PublishedItem item = leafNode.getPublishedItem(itemID);
                if (item != null) {
                    items.add(item);
                }
            }
        }
    }

    if (subscription != null && subscription.getKeyword() != null) {
        // Filter items that do not match the subscription keyword
        for (Iterator<PublishedItem> it = items.iterator(); it.hasNext();) {
            PublishedItem item = it.next();
            if (!subscription.isKeywordMatched(item)) {
                // Remove item that does not match keyword
                it.remove();
            }
        }
    }

    // Send items to the user
    leafNode.sendPublishedItems(iq, items, forceToIncludePayload);

    //   FIXME:  Temporary return value
    return createSuccessPacket(iq);
}

From source file:com.adspore.splat.xep0060.PubSubEngine.java

License:Open Source License

/**
 * Returns the data form included in the configure element sent by the node owner or
 * <tt>null</tt> if none was included or access model was defined. If the
 * owner just wants to set the access model to use for the node and optionally set the
 * list of roster groups (i.e. contacts present in the node owner roster in the
 * specified groups are allowed to access the node) allowed to access the node then
 * instead of including a data form the owner can just specify the "access" attribute
 * of the configure element and optionally include a list of group elements. In this case,
 * the method will create a data form including the specified data. This is a nice way
 * to accept both ways to configure a node but always returning a data form.
 *
 * @param configureElement the configure element sent by the owner.
 * @return the data form included in the configure element sent by the node owner or
 *         <tt>null</tt> if none was included or access model was defined.
 *///from  w  ww .j  a va  2  s.  c o  m
private static DataForm getSentConfigurationForm(Element configureElement) {
    DataForm completedForm = null;
    FormField formField;
    Element formElement = configureElement.element(QName.get("x", "jabber:x:data"));
    if (formElement != null) {
        completedForm = new DataForm(formElement);
    }
    String accessModel = configureElement.attributeValue("access");
    if (accessModel != null) {
        if (completedForm == null) {
            // Create a form (i.e. simulate that the user sent a form with roster groups)
            completedForm = new DataForm(DataForm.Type.submit);
            // Add the hidden field indicating that this is a node config form
            formField = completedForm.addField();
            formField.setVariable("FORM_TYPE");
            formField.setType(FormField.Type.hidden);
            formField.addValue("http://jabber.org/protocol/pubsub#node_config");
        }
        if (completedForm.getField("pubsub#access_model") == null) {
            // Add the field that will specify the access model of the node
            formField = completedForm.addField();
            formField.setVariable("pubsub#access_model");
            formField.addValue(accessModel);
        } else {
            Log.debug("PubSubEngine: Owner sent access model in data form and as attribute: "
                    + configureElement.asXML());
        }
        // Check if a list of groups was specified
        List groups = configureElement.elements("group");
        if (!groups.isEmpty()) {
            // Add the field that will contain the specified groups
            formField = completedForm.addField();
            formField.setVariable("pubsub#roster_groups_allowed");
            // Add each group as a value of the groups field
            for (Iterator it = groups.iterator(); it.hasNext();) {
                formField.addValue(((Element) it.next()).getTextTrim());
            }
        }
    }
    return completedForm;
}

From source file:com.ah.be.performance.db.TablePartitionProcessor.java

private void init() {
    try {/*from  www.  j  a v  a  2  s  .  c  o  m*/
        File f = new File(TABLE_PARTITION_CONF_FILE);
        SAXReader reader = new SAXReader();
        Document doc = reader.read(f);
        Element root = doc.getRootElement();
        Element cata = null;

        int catalog = 1;
        for (Iterator<?> i = root.elementIterator(); i.hasNext();) {
            //for catalog
            cata = (Element) i.next();
            String enable = cata.elementText("enable");
            if (enable != null && enable.equalsIgnoreCase("false"))
                continue;
            int default_maxtime = Integer.parseInt(cata.elementTextTrim("default_maxtime"));
            int default_interval = Integer.parseInt(cata.elementTextTrim("default_interval"));
            int table_partition_number = Integer.parseInt(cata.elementTextTrim("table_partition_number"));
            int default_max_record = Integer.parseInt(cata.elementTextTrim("default_max_record"));
            int default_max_record_per_partition = Integer
                    .parseInt(cata.elementTextTrim("default_max_record_per_partition"));
            int maxtime_policy = Integer.parseInt(cata.elementTextTrim("maxtime_policy"));
            int interval_policy = Integer.parseInt(cata.elementTextTrim("interval_policy"));
            int max_record_policy = Integer.parseInt(cata.elementTextTrim("max_record_policy"));

            addTableCatalogInfo(catalog, default_maxtime, default_interval, table_partition_number,
                    default_max_record, default_max_record_per_partition, maxtime_policy, interval_policy,
                    max_record_policy);

            List<?> tableElements = cata.elements("table");
            //for table in catalog
            for (int j = 0; j < tableElements.size(); j++) {
                Element table = (Element) tableElements.get(j);
                String tableName = table.attributeValue("name");
                String schemaName = table.elementTextTrim("schemaname");
                String timeField = table.elementTextTrim("timefield");
                addTableInfo(schemaName, tableName, timeField, catalog);
            }

            catalog++;
        }
    } catch (Exception e) {
        BeLogTools.error(HmLogConst.M_PERFORMANCE_TABLEPARTITION, "Fail to init table partition configure file",
                e);
    }
}

From source file:com.aliyun.odps.ogg.handler.datahub.ConfigureReader.java

License:Apache License

public static Configure reader(String configueFileName) throws DocumentException {
    logger.info("Begin read configure[" + configueFileName + "]");

    Configure configure = new Configure();
    SAXReader reader = new SAXReader();
    File file = new File(configueFileName);

    Document document = reader.read(file);
    Element root = document.getRootElement();

    String elementText = root.elementTextTrim("batchSize");
    if (StringUtils.isNotBlank(elementText)) {
        configure.setBatchSize(Integer.parseInt(elementText));
    }/*w w w  .  j ava 2 s  . c  o  m*/

    elementText = root.elementTextTrim("dirtyDataContinue");
    if (StringUtils.isNotBlank(elementText)) {
        configure.setDirtyDataContinue(Boolean.parseBoolean(elementText));
    }

    elementText = root.elementTextTrim("dirtyDataFile");
    if (StringUtils.isNotBlank(elementText)) {
        configure.setDirtyDataFile(elementText);
    }

    elementText = root.elementTextTrim("dirtyDataFileMaxSize");
    if (StringUtils.isNotBlank(elementText)) {
        configure.setDirtyDataFileMaxSize(Integer.parseInt(elementText));
    }

    elementText = root.elementTextTrim("retryTimes");
    if (StringUtils.isNotBlank(elementText)) {
        configure.setRetryTimes(Integer.parseInt(elementText));
    }

    elementText = root.elementTextTrim("retryInterval");
    if (StringUtils.isNotBlank(elementText)) {
        configure.setRetryInterval(Integer.parseInt(elementText));
    }

    elementText = root.elementTextTrim("disableCheckPointFile");
    if (StringUtils.isNotBlank(elementText)) {
        configure.setDisableCheckPointFile(Boolean.parseBoolean(elementText));
    }

    elementText = root.elementTextTrim("checkPointFileName");
    if (StringUtils.isNotBlank(elementText)) {
        configure.setCheckPointFileName(elementText);
    }

    Element element = root.element("defaultOracleConfigure");
    if (element == null) {
        throw new RuntimeException("defaultOracleConfigure is null");
    }

    elementText = element.elementTextTrim("sid");
    if (StringUtils.isBlank(elementText)) {
        throw new RuntimeException("defaultOracleConfigure.sid is null");
    }
    configure.setSid(elementText);

    String defaultOracleSchema = element.elementTextTrim("schema");

    SimpleDateFormat defaultSimpleDateFormat;
    elementText = element.elementTextTrim("dateFormat");
    if (StringUtils.isNotBlank(elementText)) {
        defaultSimpleDateFormat = new SimpleDateFormat(elementText);
    } else {
        defaultSimpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    }

    element = root.element("defalutDatahubConfigure");
    if (element == null) {
        throw new RuntimeException("defalutDatahubConfigure is null");
    }

    String endPoint = element.elementText("endPoint");
    if (StringUtils.isBlank(endPoint)) {
        throw new RuntimeException("defalutDatahubConfigure.endPoint is null");

    }

    String defaultDatahubProject = element.elementText("project");
    String defaultDatahubAccessID = element.elementText("accessId");
    String defaultDatahubAccessKey = element.elementText("accessKey");

    Field defaultCTypeField = null;
    String defaultCTypeColumn = element.elementText("ctypeColumn");
    if (StringUtils.isNotBlank(defaultCTypeColumn)) {
        defaultCTypeField = new Field(defaultCTypeColumn, FieldType.STRING);
    }
    Field defaultCTimeField = null;
    String defaultCTimeColumn = element.elementText("ctimeColumn");
    if (StringUtils.isNotBlank(defaultCTimeColumn)) {
        defaultCTimeField = new Field(defaultCTimeColumn, FieldType.STRING);
    }
    Field defaultCidField = null;
    String defaultCidColumn = element.elementText("cidColumn");
    if (StringUtils.isNotBlank(defaultCidColumn)) {
        defaultCidField = new Field(defaultCidColumn, FieldType.STRING);
    }

    String defaultConstColumnMapStr = element.elementText("constColumnMap");
    Map<String, String> defalutConstColumnMappings = Maps.newHashMap();
    Map<String, Field> defaultConstColumnFieldMappings = Maps.newHashMap();
    parseConstColumnMap(defaultConstColumnMapStr, defalutConstColumnMappings, defaultConstColumnFieldMappings);

    element = root.element("mappings");
    if (element == null) {
        throw new RuntimeException("mappings is null");
    }

    List<Element> mappingElements = element.elements("mapping");
    if (mappingElements == null || mappingElements.size() == 0) {
        throw new RuntimeException("mappings.mapping is null");
    }

    //init table mapping
    for (Element e : mappingElements) {
        String oracleSchema = e.elementTextTrim("oracleSchema");
        if (StringUtils.isNotBlank(oracleSchema)) {
            //nothing
        } else if (StringUtils.isNotBlank(defaultOracleSchema)) {
            oracleSchema = defaultOracleSchema;
        } else {
            throw new RuntimeException(
                    "both mappings.mapping.oracleSchema and defaultOracleConfigure.schema is null");
        }

        String oracleTable = e.elementTextTrim("oracleTable");
        if (StringUtils.isBlank(oracleTable)) {
            throw new RuntimeException("mappings.mapping.oracleTable is null");
        }

        String datahubProject = e.elementTextTrim("datahubProject");
        if (StringUtils.isNotBlank(datahubProject)) {
            //nothing
        } else if (StringUtils.isNotBlank(defaultOracleSchema)) {
            datahubProject = defaultDatahubProject;
        } else {
            throw new RuntimeException(
                    "both mappings.mapping.datahubProject and defalutDatahubConfigure.project is null");
        }

        String datahubAccessId = e.elementTextTrim("datahubAccessId");
        if (StringUtils.isNotBlank(datahubAccessId)) {
            //nothing
        } else if (StringUtils.isNotBlank(defaultDatahubAccessID)) {
            datahubAccessId = defaultDatahubAccessID;
        } else {
            throw new RuntimeException(
                    "both mappings.mapping.datahubAccessId and defalutDatahubConfigure.accessId is null");
        }

        String datahubAccessKey = e.elementTextTrim("datahubAccessKey");
        if (StringUtils.isNotBlank(datahubAccessKey)) {
            //nothing
        } else if (StringUtils.isNotBlank(defaultDatahubAccessKey)) {
            datahubAccessKey = defaultDatahubAccessKey;
        } else {
            throw new RuntimeException(
                    "both mappings.mapping.datahubAccessKey and defalutDatahubConfigure.accessKey is null");
        }

        String topicName = e.elementTextTrim("datahubTopic");
        if (topicName == null) {
            throw new RuntimeException("mappings.mapping.datahubTopic is null");
        }

        String ctypeColumn = e.elementText("ctypeColumn");
        String ctimeColumn = e.elementText("ctimeColumn");
        String cidColumn = e.elementText("cidColumn");

        DatahubConfiguration datahubConfiguration = new DatahubConfiguration(
                new AliyunAccount(datahubAccessId, datahubAccessKey), endPoint);
        Project project = Project.Builder.build(datahubProject, datahubConfiguration);
        Topic topic = project.getTopic(topicName);
        if (topic == null) {
            throw new RuntimeException("Can not find datahub topic[" + topicName + "]");
        } else {
            logger.info(
                    "topic name: " + topicName + ", topic schema: " + topic.getRecordSchema().toJsonString());
        }

        TableMapping tableMapping = new TableMapping();
        tableMapping.setTopic(topic);
        tableMapping.setOracleSchema(oracleSchema.toLowerCase());
        tableMapping.setOracleTableName(oracleTable.toLowerCase());
        tableMapping.setOracleFullTableName(
                tableMapping.getOracleSchema() + "." + tableMapping.getOracleTableName());
        tableMapping
                .setCtypeField(StringUtils.isNotBlank(ctypeColumn) ? new Field(ctypeColumn, FieldType.STRING)
                        : defaultCTypeField);
        tableMapping
                .setCtimeField(StringUtils.isNotBlank(ctimeColumn) ? new Field(ctimeColumn, FieldType.STRING)
                        : defaultCTimeField);
        tableMapping.setCidField(
                StringUtils.isNotBlank(cidColumn) ? new Field(cidColumn, FieldType.STRING) : defaultCidField);

        String constColumnMapStr = e.elementText("constColumnMap");
        Map<String, String> constColumnMappings = Maps.newHashMap();
        Map<String, Field> constColumnFieldMappings = Maps.newHashMap();
        parseConstColumnMap(constColumnMapStr, constColumnMappings, constColumnFieldMappings);

        tableMapping.setConstColumnMappings(
                constColumnMappings.isEmpty() ? defalutConstColumnMappings : constColumnMappings);
        tableMapping.setConstFieldMappings(constColumnFieldMappings.isEmpty() ? defaultConstColumnFieldMappings
                : constColumnFieldMappings);

        Map<String, ColumnMapping> columnMappings = Maps.newHashMap();
        tableMapping.setColumnMappings(columnMappings);

        elementText = e.elementTextTrim("shardId");
        if (StringUtils.isNotBlank(elementText)) {
            tableMapping.setShardId(elementText);
        }

        configure.addTableMapping(tableMapping);

        RecordSchema recordSchema = topic.getRecordSchema();

        Element columnMappingElement = e.element("columnMapping");
        List<Element> columns = columnMappingElement.elements("column");
        for (Element columnElement : columns) {
            String oracleColumnName = columnElement.attributeValue("src");
            if (StringUtils.isBlank(oracleColumnName)) {
                throw new RuntimeException("Topic[" + topicName + "] src attribute is null");
            }

            oracleColumnName = oracleColumnName.toLowerCase();
            ColumnMapping columnMapping = new ColumnMapping();
            columnMappings.put(oracleColumnName, columnMapping);
            columnMapping.setOracleColumnName(oracleColumnName);

            String datahubFieldName = columnElement.attributeValue("dest");
            if (datahubFieldName == null) {
                throw new RuntimeException("Topic[" + topicName + "] dest attribute is null");
            }

            Field field = recordSchema.getField(datahubFieldName.toLowerCase());
            if (field == null) {
                throw new RuntimeException(
                        "Topic[" + topicName + "] Field[" + datahubFieldName + "] is not exist");
            }

            columnMapping.setField(field);

            String datahubOldFieldName = columnElement.attributeValue("destOld");
            if (StringUtils.isNotBlank(datahubOldFieldName)) {
                Field oldField = recordSchema.getField(datahubOldFieldName);

                if (field == null) {
                    throw new RuntimeException(
                            "Topic[" + topicName + "] Field[" + datahubOldFieldName + "] is not exist");
                }
                columnMapping.setOldFiled(oldField);
            }

            String isShardColumn = columnElement.attributeValue("isShardColumn");
            if (StringUtils.isNotBlank(isShardColumn) && Boolean.TRUE.equals(Boolean.valueOf(isShardColumn))) {
                tableMapping.setIsShardHash(true);
                columnMapping.setIsShardColumn(true);
            } else {
                columnMapping.setIsShardColumn(false);
            }

            String isKeyColumn = columnElement.attributeValue("isKeyColumn");
            if (StringUtils.isNotBlank(isKeyColumn) && Boolean.TRUE.equals(Boolean.valueOf(isKeyColumn))) {
                columnMapping.setIsKeyColumn(true);
            } else {
                columnMapping.setIsKeyColumn(false);
            }

            String dateFormat = columnElement.attributeValue("dateFormat");

            if (StringUtils.isNotBlank(dateFormat)) {
                columnMapping.setSimpleDateFormat(new SimpleDateFormat(dateFormat));
            } else {
                columnMapping.setSimpleDateFormat(defaultSimpleDateFormat);
            }

            String isDateFormat = columnElement.attributeValue("isDateFormat");

            if (StringUtils.isNotBlank(isDateFormat) && Boolean.FALSE.equals(Boolean.valueOf(isDateFormat))) {
                columnMapping.setIsDateFormat(false);
            } else {
                columnMapping.setIsDateFormat(true);
            }
        }
    }

    logger.info("Read configure success: " + JsonHelper.beanToJson(configure));
    return configure;
}

From source file:com.allinfinance.common.grid.GridConfigUtil.java

License:Open Source License

/**
 * ??//from www  . j ava  2  s.co m
 * @param context
 * @throws Exception
 */
@SuppressWarnings("unchecked")
public static void initGirdConfig(ServletContext context) throws Exception {
    SAXReader reader = new SAXReader();

    Document document = null;
    document = reader.read(context.getResourceAsStream(Constants.GRID_CONFIG_CONTEXTPATH));

    Element root = document.getRootElement();

    List<Element> gridInfoList = root.elements(GridConfigConstants.NODE_GRID);

    for (Element gridNode : gridInfoList) {
        String gridId = gridNode.attributeValue(GridConfigConstants.GRID_ID);
        String gridConfigType = gridNode.attributeValue(GridConfigConstants.GRID_TYPE);

        //?
        GridModel gridModel = new GridModel();
        gridModel.setId(gridId);
        gridModel.setType(gridConfigType);
        gridModel.setColumns(gridNode.elementText(GridConfigConstants.COLUMNS).trim());

        if (GridConfigConstants.TYPE_SQL.equals(gridConfigType)) {

            SqlMode sqlMode = new SqlMode();
            //SQL?
            Element sqlModeNode = gridNode.element(GridConfigConstants.TYPE_SQLMODE);
            //?
            Element wheresNode = sqlModeNode.element(GridConfigConstants.WHERES);

            List<Element> whereList = wheresNode.elements(GridConfigConstants.WHERE);

            sqlMode.setSql(sqlModeNode.elementText(GridConfigConstants.SQL).trim());
            sqlMode.setDao(sqlModeNode.elementText(GridConfigConstants.QUERY_DAO).trim());

            //?
            if (whereList != null && whereList.size() > 0) {
                WheresModel wheresModel = new WheresModel();
                List<WhereModel> whereModelList = new ArrayList<WhereModel>();
                for (Element whereNode : whereList) {
                    WhereModel whereModel = new WhereModel();
                    whereModel.setType(whereNode.attributeValue(GridConfigConstants.WHERE_TYPE));
                    whereModel.setOperator(whereNode.attributeValue(GridConfigConstants.WHERE_OPERATOR));
                    whereModel.setLogic(whereNode.attributeValue(GridConfigConstants.WHERE_LOGIC));
                    whereModel.setDataBaseColumn(
                            whereNode.elementText(GridConfigConstants.WHERE_DATABASE_COLUMN).trim());
                    whereModel.setQueryColumn(
                            whereNode.elementText(GridConfigConstants.WHERE_QUERY_COLUMN).trim());
                    whereModelList.add(whereModel);
                }
                wheresModel.setWhereModelList(whereModelList);
                sqlMode.setWheresModel(wheresModel);
            }

            // ???
            if (sqlModeNode.element(GridConfigConstants.ORDERS) != null) {
                OrdersModel ordersModel = new OrdersModel();
                Element orderModels = sqlModeNode.element(GridConfigConstants.ORDERS);
                ordersModel.setSort(orderModels.attributeValue("sort"));
                List<Element> orderList = orderModels.elements(GridConfigConstants.ORDER);
                for (Element element : orderList) {
                    ordersModel.getOrders().add(element.getText());
                }
                sqlMode.setOrdersModel(ordersModel);
            }

            gridModel.setSqlMode(sqlMode);
        } else if (GridConfigConstants.TYPE_SYNC.equals(gridConfigType)) {

            SyncMode syncMode = new SyncMode();

            Element syncModeNode = gridNode.element(GridConfigConstants.TYPE_SYNCMODE);

            Element methodNode = syncModeNode.element(GridConfigConstants.SYNC_METHOD);

            syncMode.setMethod(methodNode.attributeValue(GridConfigConstants.SYNC_METHOD_VALUE));

            gridModel.setSyncMode(syncMode);
        } else {
            throw new Exception("???[ id:" + gridId + " ]");
        }

        gridConfigMap.put(gridId, gridModel);
    }
}

From source file:com.amalto.workbench.utils.MDMServerHelper.java

License:Open Source License

private static Element getServerElement(Element rootElement, String matchingName) {
    List<?> properties = rootElement.elements(MDMServerHelper.PROPERTIES);
    for (Iterator<?> iterator = properties.iterator(); iterator.hasNext();) {
        Element serverElement = (Element) iterator.next();
        Element nameElement = serverElement.element(MDMServerHelper.NAME);
        if (nameElement != null) {
            String name = nameElement.getText();
            if (matchingName.equals(name)) {
                return serverElement;
            }//from  w w w. ja v  a  2 s .  c  o m
        }
    }
    return null;
}

From source file:com.apicloud.commons.model.Config.java

License:Open Source License

public static Config loadXml(InputStream input) {
    Config config = new Config();
    if (input == null) {
        return null;
    }/*from  w  ww  . ja v  a  2  s  .com*/
    Document document = null;
    try {
        document = XMLUtil.loadXmlFile(input);
        if (input != null) {
            input.close();
        }
    } catch (DocumentException e) {
        e.printStackTrace();
        return null;
    } catch (IOException e) {
        e.printStackTrace();
        return null;
    }
    Element rootElement = document.getRootElement();
    String id = rootElement.attributeValue("id");
    String version = rootElement.attributeValue("version");
    config.setId(id);
    config.setVersion(version);
    parseGenral(rootElement, config);

    List<Element> preferenceElementList = rootElement.elements("preference");
    List<Preference> preferences = parsePreference(preferenceElementList);
    config.getPreferences().addAll(preferences);

    List<Element> accessElementList = rootElement.elements("access");
    List<Access> accesses = parseAccess(accessElementList);
    config.getAccesses().addAll(accesses);

    List<Element> permissionElementList = rootElement.elements("permission");
    List<Permission> permissions = parsePermission(permissionElementList);
    config.getPermissions().addAll(permissions);

    List<Element> featureElementList = rootElement.elements("feature");
    List<Feature> features = parseFeature(featureElementList);
    config.getFeatures().addAll(features);

    return config;
}

From source file:com.apicloud.commons.model.Config.java

License:Open Source License

private static List<Feature> parseFeature(List<Element> featureElementList) {
    List<Feature> features = new ArrayList<Feature>();
    for (Element pref : featureElementList) {
        Feature feature = new Feature();
        String name = pref.attributeValue("name");
        feature.setName(name);// w  w w  .  j  a  v  a  2  s  . c o  m
        features.add(feature);
        List<Element> paramElementList = pref.elements("param");
        parseParam(paramElementList, feature);
    }
    return features;
}

From source file:com.apicloud.commons.model.Feature.java

License:Open Source License

public static List<Feature> loadXml(File file) {
    if (!file.exists()) {
        return new ArrayList<Feature>();
    }//  ww w  .j a v a  2 s .  c  o m
    Document document = null;
    try {
        document = XMLUtil.loadXmlFile(file);
    } catch (DocumentException e) {
        e.printStackTrace();
        return null;
    }
    Element rootElement = document.getRootElement();
    List<Element> featureElementList = rootElement.elements("feature");
    return parseFeature(featureElementList);
}