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:com.doculibre.constellio.services.SolrServicesImpl.java

License:Open Source License

@SuppressWarnings("unchecked")
@Override/*from   w w w  .  j av a 2s . co m*/
public void updateSchemaFieldTypes(RecordCollection collection) {
    String collectionName = SolrCoreContext.DEFAULT_COLLECTION_NAME;
    if (collection != null) {
        collectionName = collection.getName();
    }
    Document schemaDocument = readSchema(collectionName);
    Element typesElement = schemaDocument.getRootElement().element("types");
    List<Element> fieldTypeElements = typesElement.elements("fieldType");
    for (Iterator<Element> it = fieldTypeElements.iterator(); it.hasNext();) {
        it.next();
        it.remove();
    }
    FieldTypeServices fieldTypeServices = ConstellioSpringUtils.getFieldTypeServices();
    for (FieldType fieldType : fieldTypeServices.list()) {
        Element fieldTypeElement = DocumentHelper.createElement("fieldType");
        typesElement.add(fieldTypeElement);
        FieldTypeClass fieldTypeClass = fieldType.getFieldTypeClass();

        addNotNullAttribute(fieldTypeElement, "name", fieldType);
        addNotNullAttribute(fieldTypeElement, "class", fieldTypeClass.getClassName());
        addNotNullAttribute(fieldTypeElement, "indexed", fieldType);
        // Always true
        addNotNullAttribute(fieldTypeElement, "stored", true);
        addNotNullAttribute(fieldTypeElement, "multiValued", fieldType);
        addNotNullAttribute(fieldTypeElement, "omitNorms", fieldType);
        addNotNullAttribute(fieldTypeElement, "precisionStep", fieldType);
        addNotNullAttribute(fieldTypeElement, "positionIncrementGap", fieldType);
        addNotNullAttribute(fieldTypeElement, "sortMissingLast", fieldType);

        Analyzer analyzer = fieldType.getAnalyzer();
        Analyzer queryAnalyzer = fieldType.getQueryAnalyzer();

        if (analyzer != null) {
            Element analyzerElement = DocumentHelper.createElement("analyzer");
            fieldTypeElement.add(analyzerElement);
            if (queryAnalyzer != null) {
                analyzerElement.addAttribute("type", "index");
            }

            AnalyzerClass analyzerClass = analyzer.getAnalyzerClass();
            if (analyzerClass != null) {
                analyzerElement.addAttribute("class", analyzerClass.getClassName());
            }

            TokenizerClass tokenizerClass = analyzer.getTokenizerClass();
            if (tokenizerClass != null) {
                Element tokenizerElement = DocumentHelper.createElement("tokenizer");
                analyzerElement.add(tokenizerElement);
                tokenizerElement.addAttribute("class", tokenizerClass.getClassName());
            }

            Collection<AnalyzerFilter> filters = analyzer.getFilters();
            for (AnalyzerFilter filter : filters) {
                FilterClass filterClass = filter.getFilterClass();
                Element filterElement = DocumentHelper.createElement("filter");
                analyzerElement.add(filterElement);
                filterElement.addAttribute("class", filterClass.getClassName());
                addNotNullAttribute(filterElement, "catenateAll", filter);
                addNotNullAttribute(filterElement, "catenateWords", filter);
                addNotNullAttribute(filterElement, "delimiter", filter);
                addNotNullAttribute(filterElement, "enablePositionIncrements", filter);
                addNotNullAttribute(filterElement, "encoder", filter);
                addNotNullAttribute(filterElement, "expand", filter);
                addNotNullAttribute(filterElement, "generateNumberParts", filter);
                addNotNullAttribute(filterElement, "generateWordParts", filter);
                addNotNullAttribute(filterElement, "ignoreCase", filter);
                addNotNullAttribute(filterElement, "inject", filter);
                addNotNullAttribute(filterElement, "language", filter);
                addNotNullAttribute(filterElement, "pattern", filter);
                if (filter.getProtectedText() != null) {
                    filterElement.addAttribute("protected", filter.getProtectedText());
                }
                addNotNullAttribute(filterElement, "replace", filter);
                addNotNullAttribute(filterElement, "replacement", filter);
                addNotNullAttribute(filterElement, "splitOnCaseChange", filter);
                if (filter.getSynonymsText() != null) {
                    filterElement.addAttribute("synonyms", filter.getSynonymsText());
                }
                if (filter.getWordsText() != null) {
                    filterElement.addAttribute("words", filter.getWordsText());
                }
            }
        }

        if (queryAnalyzer != null) {
            Element analyzerElement = DocumentHelper.createElement("analyzer");
            fieldTypeElement.add(analyzerElement);
            analyzerElement.addAttribute("type", "query");

            AnalyzerClass analyzerClass = queryAnalyzer.getAnalyzerClass();
            if (analyzerClass != null) {
                analyzerElement.addAttribute("class", analyzerClass.getClassName());
            }

            TokenizerClass tokenizerClass = queryAnalyzer.getTokenizerClass();
            if (tokenizerClass != null) {
                Element tokenizerElement = DocumentHelper.createElement("tokenizer");
                analyzerElement.add(tokenizerElement);
                tokenizerElement.addAttribute("class", tokenizerClass.getClassName());
            }

            Collection<AnalyzerFilter> filters = queryAnalyzer.getFilters();
            for (AnalyzerFilter filter : filters) {
                FilterClass filterClass = filter.getFilterClass();
                Element filterElement = DocumentHelper.createElement("filter");
                analyzerElement.add(filterElement);
                filterElement.addAttribute("class", filterClass.getClassName());
                addNotNullAttribute(filterElement, "catenateAll", filter);
                addNotNullAttribute(filterElement, "catenateWords", filter);
                addNotNullAttribute(filterElement, "delimiter", filter);
                addNotNullAttribute(filterElement, "enablePositionIncrements", filter);
                addNotNullAttribute(filterElement, "encoder", filter);
                addNotNullAttribute(filterElement, "expand", filter);
                addNotNullAttribute(filterElement, "generateNumberParts", filter);
                addNotNullAttribute(filterElement, "generateWordParts", filter);
                addNotNullAttribute(filterElement, "ignoreCase", filter);
                addNotNullAttribute(filterElement, "inject", filter);
                addNotNullAttribute(filterElement, "language", filter);
                addNotNullAttribute(filterElement, "pattern", filter);
                if (filter.getProtectedText() != null) {
                    filterElement.addAttribute("protected", filter.getProtectedText());
                }
                addNotNullAttribute(filterElement, "replace", filter);
                addNotNullAttribute(filterElement, "replacement", filter);
                addNotNullAttribute(filterElement, "splitOnCaseChange", filter);
                if (filter.getSynonymsText() != null) {
                    filterElement.addAttribute("synonyms", filter.getSynonymsText());
                }
                if (filter.getWordsText() != null) {
                    filterElement.addAttribute("words", filter.getWordsText());
                }
            }
        }
    }
    writeSchema(collectionName, schemaDocument);
    if (collection != null) {
        // for _default_constellio, we do not need initialize
        initCore(collection);
    }
}

From source file:com.doculibre.constellio.services.SolrServicesImpl.java

License:Open Source License

@SuppressWarnings("unchecked")
@Override/* ww  w.  j  a  v a 2  s  . co  m*/
public synchronized void initConnectorTypeFields() {
    ConnectorTypeServices connectorTypeServices = ConstellioSpringUtils.getConnectorTypeServices();
    FieldTypeServices fieldTypeServices = ConstellioSpringUtils.getFieldTypeServices();
    AnalyzerClassServices analyzerClassServices = ConstellioSpringUtils.getAnalyzerClassServices();

    for (ConnectorType connectorType : connectorTypeServices.list()) {
        Collection<ConnectorTypeMetaMapping> connectorTypeMetaMappings = connectorType.getMetaMappings();
        if (connectorTypeMetaMappings.isEmpty()) {
            File connectorsDir = ConstellioSpringUtils.getGoogleConnectorsDir();
            File connectorTypeDir = new File(connectorsDir, connectorType.getName());
            File schemaFile = new File(connectorTypeDir, "schema.xml");

            // // we must ensure that collection with the name of
            // connectorType
            // // exists in solrcloud
            // Document schemaDocument =
            // readSchema(connectorType.getName());
            if (schemaFile.exists()) {
                Document schemaDocument = readSchema(schemaFile);
                if (schemaDocument != null) {
                    String defaultUniqueKeyName = "id";
                    String uniqueKeyFieldName = defaultUniqueKeyName;
                    Element uniqueKeyElement = schemaDocument.getRootElement().element("uniqueKey");
                    if (uniqueKeyElement != null) {
                        uniqueKeyFieldName = uniqueKeyElement.getText();
                    }

                    String defaultSearchFieldName;
                    Element defaultSearchFieldElement = schemaDocument.getRootElement()
                            .element("defaultSearchField");
                    if (defaultSearchFieldElement != null) {
                        defaultSearchFieldName = defaultSearchFieldElement.getText();
                    } else {
                        defaultSearchFieldName = null;
                    }

                    Element fieldsElement = schemaDocument.getRootElement().element("fields");
                    List<Element> fieldElements = fieldsElement.elements("field");
                    for (Iterator<Element> it = fieldElements.iterator(); it.hasNext();) {
                        Element fieldElement = it.next();

                        ConnectorTypeMetaMapping connectorTypeMetaMapping = new ConnectorTypeMetaMapping();
                        connectorType.addMetaMapping(connectorTypeMetaMapping);

                        String metaName = fieldElement.attributeValue("name");
                        connectorTypeMetaMapping.setMetaName(metaName);
                        if (metaName.equals(uniqueKeyFieldName)) {
                            connectorTypeMetaMapping.setUniqueKey(true);
                        }

                        if (defaultSearchFieldName != null && metaName.equals(defaultSearchFieldName)) {
                            connectorTypeMetaMapping.setDefaultSearchField(true);
                        }

                        String indexFieldName = IndexField.normalize(metaName);
                        connectorTypeMetaMapping.setIndexFieldName(indexFieldName);

                        setProperty(fieldElement, "indexed", connectorTypeMetaMapping);
                        // Defaults to true
                        // setProperty(fieldElement, "stored",
                        // connectorTypeMetaMapping);
                        setProperty(fieldElement, "multiValued", connectorTypeMetaMapping);

                        String analyzerClassName = fieldElement.attributeValue("analyzer");
                        if (analyzerClassName != null) {
                            AnalyzerClass analyzerClass = analyzerClassServices.get(analyzerClassName);
                            if (analyzerClass == null) {
                                analyzerClass = new AnalyzerClass();
                                analyzerClass.setClassName(analyzerClassName);
                                analyzerClassServices.makePersistent(analyzerClass, false);
                            }
                            Analyzer analyzer = new Analyzer();
                            analyzer.setAnalyzerClass(analyzerClass);
                            connectorTypeMetaMapping.setAnalyzer(analyzer);
                        }

                        String typeName = fieldElement.attributeValue("type");
                        FieldType fieldType = fieldTypeServices.get(typeName);
                        if (fieldType != null) {
                            connectorTypeMetaMapping.setFieldType(fieldType);
                            if (fieldType.getIndexed() != null) {
                                connectorTypeMetaMapping.setIndexed(fieldType.getIndexed());
                            }
                            if (fieldType.getMultiValued() != null) {
                                connectorTypeMetaMapping.setMultiValued(fieldType.getMultiValued());
                            }
                        }
                    }
                }
            }
        }
    }
}

From source file:com.doculibre.constellio.services.SolrServicesImpl.java

License:Open Source License

@Override
@SuppressWarnings("unchecked")
public Boolean createMissingFieldTypes(Document schemaDocument) {
    Boolean newFielTypes = false;
    FieldTypeServices fieldTypeServices = ConstellioSpringUtils.getFieldTypeServices();
    ConnectorManagerServices connectorManagerServices = ConstellioSpringUtils.getConnectorManagerServices();
    FieldTypeClassServices fieldTypeClassServices = ConstellioSpringUtils.getFieldTypeClassServices();
    FilterClassServices filterClassServices = ConstellioSpringUtils.getFilterClassServices();
    TokenizerClassServices tokenizerClassServices = ConstellioSpringUtils.getTokenizerClassServices();
    AnalyzerClassServices analyzerClassServices = ConstellioSpringUtils.getAnalyzerClassServices();

    ConnectorManager connectorManager = connectorManagerServices.getDefaultConnectorManager();

    Element typesElement = schemaDocument.getRootElement().element("types");
    if (typesElement != null) {
        List<Element> fieldTypeElements = typesElement.elements("fieldType");
        for (Element fieldTypeElement : fieldTypeElements) {
            String name = fieldTypeElement.attributeValue("name");
            FieldType fieldType = fieldTypeServices.get(name);
            if (fieldType == null) {
                newFielTypes = true;/*from  w  ww.jav a 2  s. co m*/
                fieldType = new FieldType();
                fieldType.setName(name);

                String fieldTypeClassName = fieldTypeElement.attributeValue("class");
                FieldTypeClass fieldTypeClass = fieldTypeClassServices.get(fieldTypeClassName);
                if (fieldTypeClass == null) {
                    fieldTypeClass = new FieldTypeClass();
                    fieldTypeClass.setClassName(fieldTypeClassName);
                    fieldTypeClass.setConnectorManager(connectorManager);
                    fieldTypeClassServices.makePersistent(fieldTypeClass);
                }
                fieldType.setFieldTypeClass(fieldTypeClass);
                fieldType.setConnectorManager(connectorManager);

                setProperty(fieldTypeElement, "indexed", fieldType);
                // Always true
                // setProperty(fieldTypeElement, "stored", fieldType);
                setProperty(fieldTypeElement, "multiValued", fieldType);
                setProperty(fieldTypeElement, "omitNorms", fieldType);
                setProperty(fieldTypeElement, "precisionStep", fieldType);
                setProperty(fieldTypeElement, "positionIncrementGap", fieldType);
                setProperty(fieldTypeElement, "sortMissingLast", fieldType);

                List<Element> analyzerElements = fieldTypeElement.elements("analyzer");
                Element analyzerElement = null;
                Element queryAnalyzerElement = null;
                for (Element element : analyzerElements) {
                    String type = element.attributeValue("type");
                    if (type == null || type.equals("index")) {
                        analyzerElement = element;
                    } else if (type.equals("query")) {
                        queryAnalyzerElement = element;
                    }
                }

                if (analyzerElement != null) {
                    Analyzer analyzer = new Analyzer();
                    fieldType.setAnalyzer(analyzer);

                    String analyzerClassName = analyzerElement.attributeValue("class");
                    if (analyzerClassName != null) {
                        AnalyzerClass analyzerClass = analyzerClassServices.get(analyzerClassName);
                        if (analyzerClass == null) {
                            analyzerClass = new AnalyzerClass();
                            analyzerClass.setClassName(analyzerClassName);
                            analyzerClass.setConnectorManager(connectorManager);
                            analyzerClassServices.makePersistent(analyzerClass, false);
                        }
                        analyzer.setAnalyzerClass(analyzerClass);
                    }

                    Element tokenizerElement = analyzerElement.element("tokenizer");
                    if (tokenizerElement != null) {
                        String tokenizerClassName = tokenizerElement.attributeValue("class");
                        TokenizerClass tokenizerClass = tokenizerClassServices.get(tokenizerClassName);
                        if (tokenizerClass == null) {
                            tokenizerClass = new TokenizerClass();
                            tokenizerClass.setClassName(tokenizerClassName);
                            tokenizerClass.setConnectorManager(connectorManager);
                            tokenizerClassServices.makePersistent(tokenizerClass, false);
                        }
                        analyzer.setTokenizerClass(tokenizerClass);
                    }

                    for (Element filterElement : (List<Element>) analyzerElement.elements("filter")) {
                        AnalyzerFilter filter = new AnalyzerFilter();
                        filter.setAnalyzer(analyzer);
                        analyzer.getFilters().add(filter);

                        String filterClassName = filterElement.attributeValue("class");
                        FilterClass filterClass = filterClassServices.get(filterClassName);
                        if (filterClass == null) {
                            filterClass = new FilterClass();
                            filterClass.setClassName(filterClassName);
                            filterClass.setConnectorManager(connectorManager);
                            filterClassServices.makePersistent(filterClass);
                        }
                        filter.setFilterClass(filterClass);

                        setProperty(filterElement, "catenateAll", filter);
                        setProperty(filterElement, "catenateWords", filter);
                        setProperty(filterElement, "delimiter", filter);
                        setProperty(filterElement, "enablePositionIncrements", filter);
                        setProperty(filterElement, "encoder", filter);
                        setProperty(filterElement, "expand", filter);
                        setProperty(filterElement, "generateNumberParts", filter);
                        setProperty(filterElement, "generateWordParts", filter);
                        setProperty(filterElement, "ignoreCase", filter);
                        setProperty(filterElement, "inject", filter);
                        setProperty(filterElement, "language", filter);
                        setProperty(filterElement, "pattern", filter);
                        if (filterElement.attribute("protected") != null) {
                            filter.setProtectedText(filterElement.attributeValue("protected"));
                        }
                        setProperty(filterElement, "replace", filter);
                        setProperty(filterElement, "replacement", filter);
                        setProperty(filterElement, "splitOnCaseChange", filter);
                        if (filterElement.attribute("synonyms") != null) {
                            filter.setSynonymsText(filterElement.attributeValue("synonyms"));
                        }
                        if (filterElement.attribute("words") != null) {
                            filter.setWordsText(filterElement.attributeValue("words"));
                        }
                    }
                }

                if (queryAnalyzerElement != null) {
                    Analyzer queryAnalyzer = new Analyzer();
                    fieldType.setQueryAnalyzer(queryAnalyzer);

                    String analyzerClassName = queryAnalyzerElement.attributeValue("class");
                    if (analyzerClassName != null) {
                        AnalyzerClass analyzerClass = analyzerClassServices.get(analyzerClassName);
                        if (analyzerClass == null) {
                            analyzerClass = new AnalyzerClass();
                            analyzerClass.setClassName(analyzerClassName);
                            analyzerClass.setConnectorManager(connectorManager);
                            analyzerClassServices.makePersistent(analyzerClass, false);
                        }
                        queryAnalyzer.setAnalyzerClass(analyzerClass);
                    }

                    Element tokenizerElement = queryAnalyzerElement.element("tokenizer");
                    if (tokenizerElement != null) {
                        String tokenizerClassName = tokenizerElement.attributeValue("class");
                        TokenizerClass tokenizerClass = tokenizerClassServices.get(tokenizerClassName);
                        if (tokenizerClass == null) {
                            tokenizerClass = new TokenizerClass();
                            tokenizerClass.setClassName(tokenizerClassName);
                            tokenizerClass.setConnectorManager(connectorManager);
                            tokenizerClassServices.makePersistent(tokenizerClass, false);
                        }
                        queryAnalyzer.setTokenizerClass(tokenizerClass);
                    }

                    for (Element filterElement : (List<Element>) queryAnalyzerElement.elements("filter")) {
                        AnalyzerFilter filter = new AnalyzerFilter();
                        filter.setAnalyzer(queryAnalyzer);
                        queryAnalyzer.getFilters().add(filter);

                        String filterClassName = filterElement.attributeValue("class");
                        FilterClass filterClass = filterClassServices.get(filterClassName);
                        if (filterClass == null) {
                            filterClass = new FilterClass();
                            filterClass.setClassName(filterClassName);
                            filterClass.setConnectorManager(connectorManager);
                            filterClassServices.makePersistent(filterClass);
                        }
                        filter.setFilterClass(filterClass);

                        setProperty(filterElement, "catenateAll", filter);
                        setProperty(filterElement, "catenateWords", filter);
                        setProperty(filterElement, "delimiter", filter);
                        setProperty(filterElement, "enablePositionIncrements", filter);
                        setProperty(filterElement, "encoder", filter);
                        setProperty(filterElement, "expand", filter);
                        setProperty(filterElement, "generateNumberParts", filter);
                        setProperty(filterElement, "generateWordParts", filter);
                        setProperty(filterElement, "ignoreCase", filter);
                        setProperty(filterElement, "inject", filter);
                        setProperty(filterElement, "language", filter);
                        setProperty(filterElement, "pattern", filter);
                        if (filterElement.attribute("protected") != null) {
                            filter.setProtectedText(filterElement.attributeValue("protected"));
                        }
                        setProperty(filterElement, "replace", filter);
                        setProperty(filterElement, "replacement", filter);
                        setProperty(filterElement, "splitOnCaseChange", filter);
                        if (filterElement.attribute("synonyms") != null) {
                            filter.setSynonymsText(filterElement.attributeValue("synonyms"));
                        }
                        if (filterElement.attribute("words") != null) {
                            filter.setWordsText(filterElement.attributeValue("words"));
                        }
                    }
                }

                fieldTypeServices.makePersistent(fieldType);
            }
        }
    }
    return newFielTypes;
}

From source file:com.doculibre.constellio.utils.xml.SolrShemaXmlReader.java

License:Open Source License

private static Map<String, Map<String, String>> readFields(Document schemaDocument, Boolean readDynamicFields,
        Boolean checkTypes) {/*from   w w w  . ja v  a 2  s  .c  om*/
    Map<String, Map<String, String>> returnList = new HashMap<String, Map<String, String>>();
    //AnalyzerClassServices analyzerClassServices = ConstellioSpringUtils.getAnalyzerClassServices();
    FieldTypeServices fieldTypeServices = ConstellioSpringUtils.getFieldTypeServices();
    if (schemaDocument != null) {

        Element fieldsElement = schemaDocument.getRootElement().element("fields");

        List<Element> fieldElements;
        if (readDynamicFields) {
            fieldElements = fieldsElement.elements("dynamicField");
        } else {
            fieldElements = fieldsElement.elements("field");
        }
        for (Iterator<Element> it = fieldElements.iterator(); it.hasNext();) {
            Element fieldElement = it.next();

            if (checkTypes) {
                /*String analyzerClassName = fieldElement.attributeValue("analyzer");
                if (analyzerClassName != null) {
                AnalyzerClass analyzerClass = analyzerClassServices.get(analyzerClassName);
                    if (analyzerClass == null) {
                       throw new RuntimeException("New Analyzers must be defined throught Constellio Interface");
                    }
                }*/
                String typeName = fieldElement.attributeValue("type");
                if (typeName == null) {
                    throw new RuntimeException("A Field must have a type");
                }
                FieldType fieldType = fieldTypeServices.get(typeName);
                if (fieldType == null) {
                    throw new RuntimeException(
                            "New Field type " + typeName + " must be defined throught Constellio Interface");
                }
            }
            String fieldName = fieldElement.attributeValue("name");
            if (fieldName == null) {
                throw new RuntimeException("A Field must have a name");
            }

            List<Attribute> attributes = fieldElement.attributes();
            Map<String, String> attributesToMap = new HashMap<String, String>();
            for (Attribute att : attributes) {
                if (!att.getQualifiedName().equals("name")) {
                    attributesToMap.put(att.getQualifiedName(), att.getValue());
                }
            }

            returnList.put(fieldName, attributesToMap);
        }
    }
    return returnList;
}

From source file:com.easyjf.generator.AllGenerator.java

License:Apache License

@SuppressWarnings("unchecked")
private Element findBean(Document document, String beanName) {
    Element beans = (Element) document.selectSingleNode("/beans");
    Element bean = null;//  w w w  .j a  v  a  2s  .co  m
    if (beans != null) {
        List e = beans.elements("bean");
        for (int i = 0; i < e.size(); i++) {
            Element n = (Element) e.get(i);
            if (beanName.equals(n.attributeValue("id")))
                bean = n;
        }
    }
    return bean;
}

From source file:com.easyjf.util.XmlElementUtil.java

License:Apache License

public static Element findElement(String name, Element el) {
    Element ret = null;/*from  ww w . ja va  2 s .c  om*/
    if (el != null) {
        List e = el.elements(name);
        for (int i = 0; i < e.size(); i++) {
            Element n = (Element) e.get(i);
            if (n.getName().equals(name)) {
                ret = n;
                break;
            }
        }
    }
    return ret;
}

From source file:com.easyjf.util.XmlElementUtil.java

License:Apache License

public static List findElements(String name, Element el) {
    List list = new ArrayList();
    if (el != null) {
        List e = el.elements(name);
        for (int i = 0; i < e.size(); i++) {
            Element n = (Element) e.get(i);
            if (n.getName().equals(name))
                list.add(n);/*  w  w  w  .  ja  v a  2 s .  com*/
        }
    }
    return list;
}

From source file:com.edo.dolphin.service.impl.DolphinServiceImpl.java

@Override
public DolphinResult queryZrrKxHonest(Integer operatorID, String name, String idNumber, String mobile) {
    DolphinResult result = new DolphinResult();

    try {/*from   w w w . j a  v a 2 s  . c  om*/
        String data = DolphinAPIUtil.execute(name, idNumber, mobile);

        Document document = DocumentHelper.parseText(data);
        Element root = document.getRootElement();
        result.setName(root.attributeValue("name"));
        result.setIdNumber(root.attributeValue("zjhm"));
        result.setSearchNo(root.attributeValue("cxbh"));

        Element resultElement = root.element("RESULT");
        result.setResult(resultElement.getText());

        if (!result.getResult().equals("1005")) {
            return result;
        }

        @SuppressWarnings("unchecked")
        List<Element> resourceList = root.elements("RESOURCE");
        for (Element element : resourceList) {
            String resources = element.attributeValue("RESOURCES");
            Resource resource = null;
            switch (resources) {
            case "GRZX130000005":
                // ??:GRZX130000005
                resource = new SocialResource();

                SocialResource socialResource = (SocialResource) resource;

                // ??:SHBXDJM
                socialResource.setRegisterCode(element.elementText("SHBXDJM"));
                // ????:DWMC
                socialResource.setCompanyName(element.elementText("DWMC"));
                // ??:JNSHBXJZTHZ
                socialResource.setSocialPayStatus(element.elementText("JNSHBXJZTHZ"));
                // ???:LQYLJZTHZ
                socialResource.setSocialGetStatus(element.elementText("LQYLJZTHZ"));
                // :JDWRQ
                socialResource.setSocialStartTime(element.elementText("JDWRQ"));
                // :ZXGXSJ
                socialResource.setSocialUpdateTime(element.elementText("ZXGXSJ"));

                processStaffData(socialResource, idNumber, operatorID);
                processStaffExpData(socialResource, idNumber, operatorID);
                break;
            case "XY0700050207030001":
                // ?:XY0700050207030001
                resource = new HouseFundResource();
                HouseFundResource houseFundResource = (HouseFundResource) resource;

                // ??:A3
                houseFundResource.setAccountStatus(element.elementText("A3"));
                // ????:A4
                houseFundResource.setAccountCompanyName(element.elementText("A4"));
                // :A5
                houseFundResource.setAccountCreateTime(element.elementText("A5"));

                break;
            case "GRZX100000007":
            case "GRZX100000008":
                // ?:GRZX100000007
                // ?:GRZX100000008
                resource = new MarryResource();
                resource.setResourceCode(resources);
                MarryResource marryResource = (MarryResource) resource;

                // :DJJG
                marryResource.setRegisterOrg(element.elementText("DJJG"));
                // :DJRQ
                marryResource.setRegisterDate(element.elementText("DJRQ"));
                // ??:ZSBH
                marryResource.setRegisterNumber(element.elementText("ZSBH"));
                // ????:POXM
                marryResource.setMateName(element.elementText("POXM"));

                processRegisterData(marryResource, idNumber, operatorID);
                break;
            case "GRZX080000032":
                // ??:GRZX080000032
                resource = new IllegalResource();
                IllegalResource illegalResource = (IllegalResource) resource;
                // ??
                illegalResource.setHasSwindling(element.elementText("SFYZPLAJWFJL"));
                // ??
                illegalResource.setHasTheft(element.elementText("SFYDQLAJWFJL"));
                // ??
                illegalResource.setHasTrick(element.elementText("SFYZYZPLAJWFJL"));
                // ?????
                illegalResource.setHasCounterfeit(element.elementText("SFYWZBZMMGWZJLAJWFJL"));
                break;
            case "GRZX080000040":
                // ?:GRZX080000040
                resource = new VehicleResource();
                VehicleResource vehicleResource = (VehicleResource) resource;

                // ??:HPZL
                vehicleResource.setLicenseType(element.elementText("HPZL"));
                // ???:HPHM
                vehicleResource.setLicenseNumber(element.elementText("HPHM"));
                // ?:CCDJRQ
                vehicleResource.setRegisterTime(element.elementText("CCDJRQ"));
                // :YXQZ
                vehicleResource.setInspectionValidityDate(element.elementText("YXQZ"));
                // :DJRQ
                vehicleResource.setInspectionDate(element.elementText("DJRQ"));
                // :QZBFQZ
                vehicleResource.setRetirementDate(element.elementText("QZBFQZ"));
                // ?:BXZZRQ
                vehicleResource.setRepairDate(element.elementText("BXZZRQ"));
                // ?:XZQH
                vehicleResource.setRegisterArea(element.elementText("XZQH"));
                // ?:ZTHZ
                vehicleResource.setStatus(element.elementText("ZTHZ"));
                // ?:DYBJHZ
                vehicleResource.setIsMortgage(element.elementText("DYBJHZ"));

                processVehicleData(vehicleResource, idNumber, operatorID);
                break;
            case "GRZX080000039":
            case "GRZX080000038":
                // ?:GRZX080000039
                // ?:GRZX080000038
                resource = new DriverResource();

                DriverResource driverResource = (DriverResource) resource;
                // ??WFMS
                driverResource.setIllegalType(element.elementText("WFMS"));
                // ?:JDSBH
                driverResource.setIllegalNumber(element.elementText("JDSBH"));
                // ?:WFSJ
                driverResource.setIllegalTime(element.elementText("WFSJ"));
                // ??:WFDZ
                driverResource.setIllegalAddress(element.elementText("WFDZ"));
                // ?:CLSJ
                driverResource.setIllegalProcessTime(element.elementText("CLSJ"));
                break;
            }

            if (resource != null) {

                // RESOURCES:??
                resource.setResourceCode(resources);

                // RESOURCENAME:???
                resource.setResourceName(element.attributeValue("RESOURCENAME"));
                // XXSSDWDM:????
                resource.setUnitCode(element.attributeValue("XXSSDWDM"));
                // XXSSDW:???
                resource.setUnitName(element.attributeValue("XXSSDW"));
                // XXLB:?
                resource.setCategory(element.attributeValue("XXLB"));

                result.getResources().add(resource);
            }
        }

    } catch (Exception e) {
        logger.fatal(e);
    }

    return result;
}

From source file:com.founder.fix.fixflow.core.impl.ProcessEngineConfigurationImpl.java

License:Apache License

private void initRulesConfig() {
    // this.rulesConfigs=new ArrayList<RulesConfig>();
    ruleMap.clear();/*from w  w w.  j a v  a2s .co m*/

    RulesResourceConfig rulesResourceConfig = getFixFlowConfig().getRulesResourceConfig();
    List<RulesResource> rulesResources = rulesResourceConfig.getRulesResource();

    for (RulesResource rulesResource : rulesResources) {
        String classPath = rulesResource.getSrc();
        Document document = null;
        try {
            InputStream in = ReflectUtil.getResourceAsStream(classPath);
            document = XmlUtil.read(in);
        } catch (DocumentException e) {
            log.error("??:" + classPath + "", e);
            throw new FixFlowClassLoadingException(ExceptionCode.CLASSLOAD_EXCEPTION_DCUMENT, classPath, e);
        }

        for (Object ele : document.getRootElement().elements("dataBaseTable")) {
            Element element = (Element) ele;

            DataBaseTable dataBaseTable = SqlmappingconfigFactory.eINSTANCE.createDataBaseTable();
            dataBaseTable.setTableId(element.attributeValue("tableId"));
            dataBaseTable.setTableName(element.attributeValue("tableName"));
            dataBaseTable.setTableValue(element.attributeValue("tableValue"));
            dataBaseTable.setArchiveTable(element.attributeValue("archiveTable"));
            //dataBaseTable.setMappingType(element.attributeValue("mappingType"));

            for (Object eleNew : element.elements("column")) {
                Element columnElement = (Element) eleNew;
                Column column = SqlmappingconfigFactory.eINSTANCE.createColumn();
                column.setColumn(columnElement.attributeValue("column"));
                column.setName(columnElement.attributeValue("name"));
                column.setJdbcType(columnElement.attributeValue("jdbcType"));
                //column.setProperty(columnElement.attributeValue("property"));
                //column.setSimpleKey(columnElement.attributeValue("property"));

                dataBaseTable.getColumn().add(column);
                columnMap.put(dataBaseTable.getTableId() + "_" + column.getColumn(), column);
            }

            dataBaseTables.put(dataBaseTable.getTableId(), dataBaseTable);

        }

        for (Object ele : document.getRootElement().elements("resultMap")) {
            Element element = (Element) ele;

            ResultMap resultMap = SqlmappingconfigFactory.eINSTANCE.createResultMap();
            resultMap.setId(element.attributeValue("id"));
            resultMap.setName(element.attributeValue("name"));
            resultMap.setType(element.attributeValue("type"));

            for (Object eleNew : element.elements("result")) {
                Element resultMappingElement = (Element) eleNew;
                Result result = SqlmappingconfigFactory.eINSTANCE.createResult();
                result.setColumn(resultMappingElement.attributeValue("column"));
                result.setName(resultMappingElement.attributeValue("name"));
                result.setJdbcType(resultMappingElement.attributeValue("jdbcType"));
                result.setProperty(resultMappingElement.attributeValue("property"));
                //result.setSimpleKey(columnMappingElement.attributeValue("property"));

                resultMap.getResult().add(result);
                //columnMappingMap.put(dataBaseTable.getTableId()+"_"+columnMapping.getColumn(), columnMapping);
            }

            resultMaps.put(resultMap.getId(), resultMap);

        }

        for (Object ele : document.getRootElement().elements("insert")) {
            Element element = (Element) ele;

            Insert insertObj = SqlmappingconfigFactory.eINSTANCE.createInsert();
            insertObj.setId(element.attributeValue("id"));
            insertObj.setParameterType(element.attributeValue("parameterType"));
            insertObj.setRemark(element.attributeValue("remark"));
            insertObj.setSqlValue(element.getText());

            String classPathString = element.attributeValue("classPath");

            if (StringUtil.isNotEmpty(classPathString)) {
                Class<?> classObj = ReflectUtil.loadClass(classPathString);
                if (classObj != null) {
                    insertObj.setClassPath(classPathString);
                    ruleClassMap.put(element.attributeValue("id"), classObj);
                }
            }

            ruleMap.put(insertObj.getId(), insertObj);

        }

        for (Object ele : document.getRootElement().elements("delete")) {
            Element element = (Element) ele;

            Delete deleteObj = SqlmappingconfigFactory.eINSTANCE.createDelete();
            deleteObj.setId(element.attributeValue("id"));
            deleteObj.setParameterType(element.attributeValue("parameterType"));
            deleteObj.setRemark(element.attributeValue("remark"));
            deleteObj.setSqlValue(element.getText());

            String classPathString = element.attributeValue("classPath");

            if (StringUtil.isNotEmpty(classPathString)) {
                Class<?> classObj = ReflectUtil.loadClass(classPathString);
                if (classObj != null) {
                    deleteObj.setClassPath(classPathString);
                    ruleClassMap.put(element.attributeValue("id"), classObj);
                }
            }

            ruleMap.put(deleteObj.getId(), deleteObj);

        }

        for (Object ele : document.getRootElement().elements("update")) {
            Element element = (Element) ele;
            Update updateObj = SqlmappingconfigFactory.eINSTANCE.createUpdate();
            updateObj.setId(element.attributeValue("id"));
            updateObj.setParameterType(element.attributeValue("parameterType"));
            updateObj.setRemark(element.attributeValue("remark"));
            updateObj.setSqlValue(element.getText());
            String classPathString = element.attributeValue("classPath");

            if (StringUtil.isNotEmpty(classPathString)) {
                Class<?> classObj = ReflectUtil.loadClass(classPathString);
                if (classObj != null) {
                    updateObj.setClassPath(classPathString);
                    ruleClassMap.put(element.attributeValue("id"), classObj);
                }
            }
            ruleMap.put(updateObj.getId(), updateObj);
        }

        for (Object ele : document.getRootElement().elements("select")) {
            Element element = (Element) ele;
            Select selectObj = SqlmappingconfigFactory.eINSTANCE.createSelect();
            selectObj.setId(element.attributeValue("id"));
            selectObj.setParameterType(element.attributeValue("parameterType"));
            selectObj.setRemark(element.attributeValue("remark"));
            selectObj.setSqlValue(element.getText());
            selectObj.setResultMap(element.attributeValue("resultMap"));
            String classPathString = element.attributeValue("classPath");
            if (StringUtil.isNotEmpty(classPathString)) {
                Class<?> classObj = ReflectUtil.loadClass(classPathString);
                if (classObj != null) {
                    selectObj.setClassPath(classPathString);
                    ruleClassMap.put(element.attributeValue("id"), classObj);
                }
            }
            ruleMap.put(selectObj.getId(), selectObj);
        }

        for (Object ele : document.getRootElement().elements("businessRules")) {
            Element element = (Element) ele;
            BusinessRules businessRules = SqlmappingconfigFactory.eINSTANCE.createBusinessRules();
            businessRules.setId(element.attributeValue("id"));
            businessRules.setParameterType(element.attributeValue("parameterType"));
            businessRules.setRemark(element.attributeValue("remark"));
            businessRules.setSqlValue(element.getText());
            businessRules.setResultType(element.attributeValue("resultType"));
            String classPathString = element.attributeValue("classPath");
            if (StringUtil.isNotEmpty(classPathString)) {
                Class<?> classObj = ReflectUtil.loadClass(classPathString);
                if (classObj != null) {
                    businessRules.setClassPath(classPathString);
                    ruleClassMap.put(element.attributeValue("id"), classObj);
                }
            }
            ruleMap.put(businessRules.getId(), businessRules);
        }
    }
}

From source file:com.glaf.activiti.extension.xml.ExtensionReader.java

License:Apache License

public List<ExtensionEntity> readTasks(java.io.InputStream inputStream) {
    List<ExtensionEntity> extensions = new java.util.ArrayList<ExtensionEntity>();
    SAXReader xmlReader = new SAXReader();
    try {//w  w w .ja va 2 s .  c o  m
        Document doc = xmlReader.read(inputStream);
        Element root = doc.getRootElement();
        String x_type = root.attributeValue("type");
        List<?> rows = root.elements("taskmgr");
        Iterator<?> iterator = rows.iterator();
        while (iterator.hasNext()) {
            Element element = (Element) iterator.next();
            ExtensionEntity extension = new ExtensionEntity();
            extension.setProcessName(element.attributeValue("processName"));
            extension.setTaskName(element.attributeValue("taskName"));
            extension.setType(x_type);
            if (element.elementTextTrim("taskMgmtType") != null) {
                ExtensionFieldEntity extensionField = new ExtensionFieldEntity();
                extensionField.setName("taskMgmtType");
                extensionField.setValue(element.elementTextTrim("taskMgmtType"));
                extension.addField(extensionField);
            }
            Element propertiesE = element.element("properties");
            if (propertiesE != null) {
                List<?> properties = propertiesE.elements("property");
                Iterator<?> iter = properties.iterator();
                while (iter.hasNext()) {
                    Element elem = (Element) iter.next();
                    String propertyName = elem.attributeValue("key");
                    String propertyValue = null;
                    if (elem.attribute("value") != null) {
                        propertyValue = elem.attributeValue("value");
                    } else {
                        propertyValue = elem.getTextTrim();
                    }
                    if (StringUtils.isNotEmpty(propertyName) && StringUtils.isNotEmpty(propertyValue)) {
                        ExtensionFieldEntity extensionField = new ExtensionFieldEntity();
                        extensionField.setName(propertyName.trim());
                        extensionField.setValue(propertyValue.trim());
                        extension.addField(extensionField);
                    }
                }
            }
            if (element.elementText("handlers") != null) {
                ExtensionFieldEntity extensionField = new ExtensionFieldEntity();
                extensionField.setName("handlers");
                extensionField.setValue(element.elementTextTrim("handlers"));
                extension.addField(extensionField);
            }
            extensions.add(extension);
        }

    } catch (Exception ex) {
        throw new RuntimeException(ex);
    }
    return extensions;
}