Example usage for org.dom4j Element attributeValue

List of usage examples for org.dom4j Element attributeValue

Introduction

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

Prototype

String attributeValue(QName qName);

Source Link

Document

This returns the attribute value for the attribute with the given fully qualified name or null if there is no such attribute or the empty string if the attribute value is empty.

Usage

From source file:com.ah.ui.actions.config.USBModemAction.java

private USBModem readUSBModem(Element element) {
    USBModem usbModem = new USBModem();
    usbModem.setOwner(getDomain());//  ww  w. j  a  v  a  2s .  c  om

    usbModem.setModemName(element.attributeValue("id"));

    USBModem usbModemToFind = QueryUtil.findBoByAttribute(USBModem.class, "modemName", usbModem.getModemName(),
            this);
    if (usbModemToFind != null) {
        usbModem.setId(usbModemToFind.getId());
    }

    Element elementTmp = element.element("display");
    if (elementTmp != null) {
        usbModem.setDisplayName(elementTmp.attributeValue("name"));
        usbModem.setDisplayType(elementTmp.attributeValue("type"));
    }
    elementTmp = element.element("usb-info");
    if (elementTmp != null) {
        usbModem.setUsbVendorId(elementTmp.attributeValue("vendor-id"));
        usbModem.setUsbProductId(elementTmp.attributeValue("product-id"));
        usbModem.setUsbModule(elementTmp.attributeValue("module"));
    }
    elementTmp = element.element("hiveos-version");
    if (elementTmp != null) {
        usbModem.setHiveOSVersionMin(elementTmp.attributeValue("min"));
    }
    //elementTmp = element.element("signal-strength-check");
    //if (elementTmp != null) {
    //usbModem.setUsbSignalStrengthCheckList(readUSBStrengthChecks(elementTmp));
    //}
    elementTmp = element.element("connect");
    if (elementTmp != null) {
        usbModem.setConnectType(elementTmp.attributeValue("type"));
        Element elementTmp1 = elementTmp.element("serial-port");
        if (elementTmp1 != null) {
            usbModem.setSerialPort(elementTmp1.attributeValue("value"));
        }
        elementTmp1 = elementTmp.element("dialstring");
        if (elementTmp1 != null) {
            usbModem.setDailupNumber(elementTmp1.attributeValue("value"));
        }
        elementTmp1 = elementTmp.element("apn");
        if (elementTmp1 != null) {
            usbModem.setApn(elementTmp1.attributeValue("value"));
        }
        //elementTmp1 = elementTmp.element("usepeerdns");
        //usbModem.setUsePeerDns(false);
        //if (elementTmp1 != null) {
        //   usbModem.setUsePeerDns("true".equals(elementTmp1.attributeValue("value")));
        //}
        elementTmp1 = elementTmp.element("user-auth");
        if (elementTmp1 != null) {
            usbModem.setAuthType(elementTmp1.attributeValue("type"));
            if ("password".equals(usbModem.getAuthType())) {
                Element elementTmp2 = elementTmp1.element("username");
                if (elementTmp2 != null) {
                    usbModem.setUserId(elementTmp2.attributeValue("value"));
                }
                elementTmp2 = elementTmp1.element("password");
                if (elementTmp2 != null) {
                    usbModem.setPassword(elementTmp2.attributeValue("value"));
                }
            }
        }
    }

    return usbModem;
}

From source file:com.ah.ui.actions.config.USBModemAction.java

@SuppressWarnings("unused")
private List<USBSignalStrengthCheck> readUSBStrengthChecks(Element element) {
    List<USBSignalStrengthCheck> strengthCheckLst = new ArrayList<USBSignalStrengthCheck>();

    USBSignalStrengthCheck strengthCheck = new USBSignalStrengthCheck();

    strengthCheck.setType(element.attributeValue("type"));
    Element elementTmp = element.element("serial-port");
    if (elementTmp != null) {
        strengthCheck.setSerialPort(elementTmp.attributeValue("value"));
    }//  w  w w .j  a va  2  s. com
    elementTmp = element.element("check-cmd");
    if (elementTmp != null) {
        strengthCheck.setCheckCmd(elementTmp.attributeValue("value"));
    }

    strengthCheckLst.add(strengthCheck);

    return strengthCheckLst;
}

From source file:com.alibaba.citrus.springext.impl.SchemaImpl.java

License:Open Source License

/**
 * ?schema??//from ww  w .j  av a  2  s. c  om
 * <ol>
 * <li>targetNamespace</li>
 * <li>include name</li>
 * </ol>
 */
@Override
protected void doAnalyze() {
    Document doc = getDocument(); // ??null
    org.dom4j.Element root = doc.getRootElement();

    // return if not a schema file
    if (!W3C_XML_SCHEMA_NS_URI.equals(root.getNamespaceURI()) || !"schema".equals(root.getName())) {
        return;
    }

    // parse targetNamespace
    if (parsingTargetNamespace) {
        Attribute attr = root.attribute("targetNamespace");

        if (attr != null) {
            targetNamespace = trimToNull(attr.getStringValue());
        }
    }

    // parse include
    Namespace xsd = DocumentHelper.createNamespace("xsd", W3C_XML_SCHEMA_NS_URI);
    QName includeName = DocumentHelper.createQName("include", xsd);
    List<String> includeNames = createLinkedList();

    // for each <xsd:include>
    for (Iterator<?> i = root.elementIterator(includeName); i.hasNext();) {
        org.dom4j.Element includeElement = (org.dom4j.Element) i.next();
        String schemaLocation = trimToNull(includeElement.attributeValue("schemaLocation"));

        if (schemaLocation != null) {
            includeNames.add(schemaLocation);
        }
    }

    includes = includeNames.toArray(new String[includeNames.size()]);

    // parse xsd:element
    QName elementName = DocumentHelper.createQName("element", xsd);

    // for each <xsd:element>
    for (Iterator<?> i = root.elementIterator(elementName); i.hasNext();) {
        Element element = new ElementImpl((org.dom4j.Element) i.next());

        if (element.getName() != null) {
            this.elements.put(element.getName(), element);
        }
    }
}

From source file:com.alibaba.citrus.springext.support.SchemaUtil.java

License:Open Source License

/** ?URI? */
public static Transformer getAddPrefixTransformer(final SchemaSet schemas, String prefix) {
    if (prefix != null) {
        if (!prefix.endsWith("/")) {
            prefix += "/";
        }//ww  w .  java  2 s  .  co m
    }

    final String normalizedPrefix = prefix;

    return new Transformer() {
        public void transform(Document document, String systemId) {
            if (normalizedPrefix != null) {
                Element root = document.getRootElement();

                // <xsd:schema>
                if (W3C_XML_SCHEMA_NS_URI.equals(root.getNamespaceURI()) && "schema".equals(root.getName())) {
                    Namespace xsd = DocumentHelper.createNamespace("xsd", W3C_XML_SCHEMA_NS_URI);
                    QName includeName = DocumentHelper.createQName("include", xsd);
                    QName importName = DocumentHelper.createQName("import", xsd);

                    // for each <xsd:include>
                    for (Iterator<?> i = root.elementIterator(includeName); i.hasNext();) {
                        Element includeElement = (Element) i.next();
                        String schemaLocation = trimToNull(includeElement.attributeValue("schemaLocation"));

                        if (schemaLocation != null) {
                            schemaLocation = getNewSchemaLocation(schemaLocation, null, systemId);

                            if (schemaLocation != null) {
                                includeElement.addAttribute("schemaLocation", schemaLocation);
                            }
                        }
                    }

                    // for each <xsd:import>
                    for (Iterator<?> i = root.elementIterator(importName); i.hasNext();) {
                        Element importElement = (Element) i.next();
                        String schemaLocation = importElement.attributeValue("schemaLocation");
                        String namespace = trimToNull(importElement.attributeValue("namespace"));

                        if (schemaLocation != null || namespace != null) {
                            schemaLocation = getNewSchemaLocation(schemaLocation, namespace, systemId);

                            if (schemaLocation != null) {
                                importElement.addAttribute("schemaLocation", schemaLocation);
                            }
                        }
                    }
                }
            }
        }

        private String getNewSchemaLocation(String schemaLocation, String namespace, String systemId) {
            // ?schemaLocation
            if (schemaLocation != null) {
                Schema schema = schemas.findSchema(schemaLocation);

                if (schema != null) {
                    return normalizedPrefix + schema.getName();
                } else {
                    return schemaLocation; // location??
                }
            }

            // ??namespace
            if (namespace != null) {
                Set<Schema> nsSchemas = schemas.getNamespaceMappings().get(namespace);

                if (nsSchemas != null && !nsSchemas.isEmpty()) {
                    // ?nsschema?schema
                    String versionedExtension = getVersionedExtension(systemId);

                    if (versionedExtension != null) {
                        for (Schema schema : nsSchemas) {
                            if (schema.getName().endsWith(versionedExtension)) {
                                return normalizedPrefix + schema.getName();
                            }
                        }
                    }

                    // schema?beans.xsd?beans-2.5.xsd?beans-2.0.xsd
                    return normalizedPrefix + nsSchemas.iterator().next().getName();
                }
            }

            return null;
        }

        /** spring-aop-2.5.xsd?-2.5.xsd */
        private String getVersionedExtension(String systemId) {
            if (systemId != null) {
                int dashIndex = systemId.lastIndexOf("-");
                int slashIndex = systemId.lastIndexOf("/");

                if (dashIndex > slashIndex) {
                    return systemId.substring(dashIndex);
                }
            }

            return null;
        }
    };
}

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));
    }/*from w ww.jav  a2 s.c om*/

    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.alkacon.opencms.feeder.CmsFeedXmlContentHandler.java

License:Open Source License

/**
 * Initializes the feed rule mappings for this content handler.<p>
 * //  w  w  w .j  a v a  2  s. co  m
 * @param root the "feedrules" element from the appinfo node of the XML content definition
 * @param contentDefinition the content definition the mappings belong to
 * 
 * @throws CmsXmlException if something goes wrong
 */
protected void initFeedRules(Element root, CmsXmlContentDefinition contentDefinition) throws CmsXmlException {

    Iterator i = root.elementIterator(APPINFO_FEEDRULE);
    while (i.hasNext()) {
        // iterate all "mapping" elements in the "mappings" node
        Element element = (Element) i.next();
        // this is a mapping node
        String xmlField = element.attributeValue(APPINFO_ATTR_ELEMENT);
        String maptoName = element.attributeValue(APPINFO_ATTR_MAPTO);
        String maxLength = element.attributeValue(ATTR_MAXLENGTH);
        String defaultValue = element.attributeValue(ATTR_DEFAULT);
        if ((xmlField != null) && (maptoName != null)) {
            // add the element mapping 
            addFeedRule(contentDefinition, xmlField, maptoName, maxLength, defaultValue);
        }
    }
}

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

License:Open Source License

/**
 * ??//from   w  ww  .  j av  a 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.LocalTreeObjectRepository.java

License:Open Source License

public void correctDisplayNameForCategory(TreeObject category) {
    if (category.getType() != TreeObject.CATEGORY_FOLDER) {
        return;//from   w w w. j av a 2s. co  m
    }
    if (category.getServerRoot() == null) {
        return;
    }
    String xpath = getXPathForTreeObject(category);
    Document doc = credentials.get(UnifyUrl(category.getServerRoot().getWsKey().toString())).doc;
    List<Element> elems = doc.selectNodes(xpath);
    if (elems.size() > 0) {
        Element elem = elems.get(0);
        String value = elem.attributeValue(REALNAME);
        if (value != null) {
            category.setDisplayName(value);
        }
    }
}

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

License:Open Source License

private void checkUpAllCategoryForModel(TreeParent model) {
    if (model.getServerRoot() == null) {
        return;//from w w  w  . jav a  2 s  .  c om
    }
    String xpath = "//" + model.getServerRoot().getUser().getUsername() + "/" //$NON-NLS-1$//$NON-NLS-2$
            + filterOutBlank(model.getDisplayName()) + "//child::*[text() = '" + TreeObject.CATEGORY_FOLDER + "' and @Url='" //$NON-NLS-1$//$NON-NLS-2$
            + getURLFromTreeObject(model) + "']";//$NON-NLS-1$
    Document doc = credentials.get(UnifyUrl(model.getServerRoot().getWsKey().toString())).doc;
    String xpathForModel = getXPathForTreeObject(model);
    List<Element> elems = doc.selectNodes(xpathForModel);
    Element modelElem = elems.get(0);
    elems = doc.selectNodes(xpath);
    for (Element elem : elems) {
        Element spec = elem;
        ArrayList<Element> hierarchicalList = new ArrayList<Element>();
        while (spec != modelElem) {
            hierarchicalList.add(spec);
            spec = spec.getParent();
        }
        Collections.reverse(hierarchicalList);
        TreeParent modelCpy = model;
        while (!hierarchicalList.isEmpty()) {
            spec = hierarchicalList.remove(0);
            String elemName = spec.getName();
            if (spec.attributeValue(REALNAME) != null) {
                elemName = spec.attributeValue(REALNAME);
            }
            TreeObject to = findObject(modelCpy, Integer.parseInt(spec.getText().trim()), elemName);
            if (to == null) {
                TreeParent catalog = new TreeParent(elemName, modelCpy.getServerRoot(),
                        TreeObject.CATEGORY_FOLDER, null, null);
                boolean cpyInternalCheck = internalCheck;
                internalCheck = true;
                modelCpy.addChild(catalog);
                internalCheck = cpyInternalCheck;
                modelCpy = catalog;
            } else {
                modelCpy = (TreeParent) to;
            }
        }
    }
}

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

License:Open Source License

private void createCategoryForOrgDoc(String categoryToCreate, Element srcElem, Element tgtElem,
        TreeParent serverRoot) {//from   w w  w. j a  v  a 2  s  . co  m
    String[] xpathSnippetsToCreate = categoryToCreate.split("/");//$NON-NLS-1$
    int categoryBeginPos = 3;
    if (xpathSnippetsToCreate[3].equals("EventManagement")) {//$NON-NLS-1$
        categoryBeginPos = 4;
    }

    int pos = categoryToCreate.indexOf("/" + xpathSnippetsToCreate[categoryBeginPos]);//$NON-NLS-1$
    String categoryXpath = categoryToCreate.substring(0,
            pos + xpathSnippetsToCreate[categoryBeginPos].length() + 1);
    Element subParentElem = pingElement(categoryXpath, tgtElem);
    for (int i = categoryBeginPos + 1; i < xpathSnippetsToCreate.length; i++) {
        String categoryXpathSnippet = "child::" + xpathSnippetsToCreate[i] + "[text()='" //$NON-NLS-1$//$NON-NLS-2$
                + TreeObject.CATEGORY_FOLDER + "']";//$NON-NLS-1$
        Element newCategory = pingElement(categoryXpathSnippet, subParentElem);
        if (newCategory == null) {
            Element existedCategory = pingElement(categoryXpath + "/" + categoryXpathSnippet, srcElem);//$NON-NLS-1$
            newCategory = subParentElem.addElement(xpathSnippetsToCreate[i]);
            newCategory.setText(TreeObject.CATEGORY_FOLDER + "");//$NON-NLS-1$
            newCategory.addAttribute(URL, getURLFromTreeObject(serverRoot));
            newCategory.addAttribute(REALNAME, existedCategory.attributeValue(REALNAME));
        }
        categoryXpath += "/" + xpathSnippetsToCreate[i];//$NON-NLS-1$
        subParentElem = newCategory;
    }

    transferElementsWithCategoryPath(categoryToCreate, srcElem, tgtElem);
}