Example usage for org.dom4j Element getText

List of usage examples for org.dom4j Element getText

Introduction

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

Prototype

String getText();

Source Link

Document

Returns the text value of this element without recursing through child elements.

Usage

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

License:Open Source License

@SuppressWarnings("unchecked")
@Override// www.java2  s.  c  om
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.utils.xml.SolrShemaXmlReader.java

License:Open Source License

public static String getUniqueKeyField(Document schemaDocument) throws DocumentException {
    String defaultUniqueKeyName = "id";
    String uniqueKeyFieldName = defaultUniqueKeyName;
    Element uniqueKeyElement = schemaDocument.getRootElement().element("uniqueKey");
    if (uniqueKeyElement != null) {
        uniqueKeyFieldName = uniqueKeyElement.getText();
    }/*from  ww  w .j a  va  2s .c  o  m*/

    return uniqueKeyFieldName;

}

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

License:Open Source License

public static String getDefaultSearchField(Document schemaDocument) throws DocumentException {
    String defaultSearchFieldName;
    Element defaultSearchFieldElement = schemaDocument.getRootElement().element("defaultSearchField");
    if (defaultSearchFieldElement != null) {
        defaultSearchFieldName = defaultSearchFieldElement.getText();
    } else {//from   ww w. j  av a  2 s. co m
        defaultSearchFieldName = null;
    }
    return defaultSearchFieldName;

}

From source file:com.doculibre.constellio.wicket.panels.admin.connector.AddEditConnectorPanel.java

License:Open Source License

@SuppressWarnings("unchecked")
@Override//ww  w . j av a2  s  .  c  o  m
protected void onSave(AjaxRequestTarget target) {
    AdminCollectionPanel collectionAdminPanel = (AdminCollectionPanel) findParent(AdminCollectionPanel.class);
    RecordCollection collection = collectionAdminPanel.getCollection();

    ConnectorInstanceServices connectorInstanceServices = ConstellioSpringUtils.getConnectorInstanceServices();
    ConnectorManagerServices connectorManagerServices = ConstellioSpringUtils.getConnectorManagerServices();
    ConnectorTypeServices connectorTypeServices = ConstellioSpringUtils.getConnectorTypeServices();

    ConnectorInstance connectorInstance = connectorInstanceModel.getObject();
    ConnectorType connectorType = connectorInstance.getConnectorType();

    // Ugly workaround... Avoid lazy loading exceptions since connectorType has been set in a
    // previous (ajax) request
    connectorType = connectorTypeServices.get(connectorType.getId());
    connectorInstance.setConnectorType(connectorType);

    RequestCycle requestCycle = RequestCycle.get();
    WebRequest webRequest = (WebRequest) requestCycle.getRequest();
    Map<String, String[]> params = webRequest.getHttpServletRequest().getParameterMap();

    ConnectorManager connectorManager = connectorManagerServices.getDefaultConnectorManager();

    EntityManager entityManager = ConstellioPersistenceContext.getCurrentEntityManager();
    if (!entityManager.getTransaction().isActive()) {
        entityManager.getTransaction().begin();
    }

    String connectorName = connectorInstance.getName();
    Element errorElement;
    Locale locale = getLocale();
    if (connectorInstance.getId() == null) {
        // Create
        connectorName = connectorManagerServices.generateConnectorName(connectorManager, collection.getName(),
                connectorType.getName());
        connectorInstance.setName(connectorName);
        errorElement = connectorManagerServices.createConnector(connectorManager, connectorName,
                connectorType.getName(), params, locale);
    } else {
        errorElement = connectorManagerServices.updateConnector(connectorManager, connectorName, params,
                locale);
    }

    if (errorElement == null) {
        boolean synchronizeIndex;
        if (collection.getConnectorInstances().isEmpty() || !collection.isSynchronizationRequired()) {
            synchronizeIndex = true;
        } else {
            synchronizeIndex = false;
        }
        collection.addConnectorInstance(connectorInstance);
        connectorInstanceServices.makePersistent(connectorInstance);

        if (!entityManager.getTransaction().isActive()) {
            entityManager.getTransaction().begin();
        }

        if (synchronizeIndex) {
            RecordCollectionServices collectionServices = ConstellioSpringUtils.getRecordCollectionServices();
            SolrServices solrServices = ConstellioSpringUtils.getSolrServices();
            solrServices.updateSchemaFields(collection);
            solrServices.initCore(collection);
            collectionServices.markSynchronized(collection);

            IndexingManager indexingManager = IndexingManager.get(collection);
            if (!indexingManager.isActive()) {
                indexingManager.startIndexing();
            }
        }

        // Schedule
        Schedule schedule = serializableSchedule.toSchedule();
        // Ensure
        schedule.setConnectorName(connectorName);
        connectorManagerServices.setSchedule(connectorManager, connectorName, schedule);

        entityManager.getTransaction().commit();
        if (!entityManager.getTransaction().isActive()) {
            entityManager.getTransaction().begin();
        }
    } else {
        Element formSnippetElement = errorElement.element(ServletUtil.XMLTAG_CONFIGURE_RESPONSE)
                .element(ServletUtil.XMLTAG_FORM_SNIPPET);
        if (formSnippetElement != null) {
            configFormSnippet.setInvalidFormSnippetElement(formSnippetElement);
            target.addComponent(configFormSnippet);
        }
        Element errorMessageElement = errorElement.element(ServletUtil.XMLTAG_CONFIGURE_RESPONSE)
                .element(ServletUtil.XMLTAG_MESSAGE);
        if (errorMessageElement != null) {
            String errorMessage = errorMessageElement.getText();
            getForm().error(errorMessage);
        } else {
            String statusId = errorElement.element(ServletUtil.XMLTAG_STATUSID).getTextTrim();
            getForm().error("Status Id : " + statusId);
        }
    }
}

From source file:com.dtolabs.client.services.RundeckAPICentralDispatcher.java

License:Apache License

@Override
public List<String> listProjectNames() throws CentralDispatcherException {
    final HashMap<String, String> params = new HashMap<String, String>();
    final WebserviceResponse response;
    try {//from   ww  w . j  a  v a2 s .co m
        response = serverService.makeRundeckRequest(RUNDECK_API_PROJECTS, params, null, "GET", "text/xml",
                null);
    } catch (MalformedURLException e) {
        throw new CentralDispatcherServerRequestException("Failed to make request", e);
    }
    validateResponse(response);

    final Document resultDoc = response.getResultDoc();

    ArrayList<String> result = new ArrayList<>();
    if (null != resultDoc.selectNodes("/projects/project/name")) {
        for (Object o : resultDoc.selectNodes("/projects/project/name")) {
            Element elem = (Element) o;
            result.add(elem.getText());
        }
    }
    return result;
}

From source file:com.dtolabs.shared.resources.ResourceXMLParser.java

License:Apache License

/**
 * Parse the DOM attributes as properties for the particular entity node type
 *
 * @param ent  Entity object/*from   w ww . j a  va  2s  .  c o  m*/
 * @param node entity DOM node
 *
 * @throws ResourceXMLParserException if the DOM node is an unexpected tag name
 */
private void parseEntSubAttributes(final Entity ent, final Node node) throws ResourceXMLParserException {
    final Element node1 = (Element) node;
    //load all sub elements called "attribute" as properties
    for (final Object attribute : node1.selectNodes(ATTRIBUTE_TAG)) {
        Element attr = (Element) attribute;
        if (null == attr.selectSingleNode("@" + ATTRIBUTE_NAME_ATTR)) {
            throw new ResourceXMLParserException(ATTRIBUTE_TAG + " element has no '" + ATTRIBUTE_NAME_ATTR
                    + "' attribute: " + reportNodeErrorLocation(attr));
        }
        String attrname = attr.selectSingleNode("@" + ATTRIBUTE_NAME_ATTR).getStringValue();

        String attrvalue;
        //look for "value" attribute
        if (null != attr.selectSingleNode("@" + ATTRIBUTE_VALUE_ATTR)) {
            attrvalue = attr.selectSingleNode("@" + ATTRIBUTE_VALUE_ATTR).getStringValue();
        } else if (null != attr.getText()) {
            //look for text content
            attrvalue = attr.getText();
        } else {
            throw new ResourceXMLParserException(ATTRIBUTE_TAG + " element has no '" + ATTRIBUTE_VALUE_ATTR
                    + "' attribute or text content: " + reportNodeErrorLocation(attr));
        }

        ent.properties.setProperty(attrname, attrvalue);
    }
}

From source file:com.easyjf.web.ajax.AjaxConfigManager.java

License:Apache License

public void parseConfig(Document doc) {
    if (doc == null)
        return;/*from   w  ww.  j av  a2s .  c  o  m*/
    Element root = XmlElementUtil.findElement("ajax", doc.getRootElement());
    Element maxDepth = XmlElementUtil.findElement("json-max-depth", root);
    if (maxDepth != null) {
        try {
            Integer depth = new Integer(maxDepth.getText());
            AjaxUtil.JSON_OBJECT_MAX_DEPTH = depth;//JSON?
        } catch (NumberFormatException e) {
        }
    }
    Element serviceRoot = XmlElementUtil.findElement("services", root);
    if (serviceRoot != null) {
        parseServices(serviceRoot);
    }

    List converts = XmlElementUtil.findElements("convert", root);
    if (converts != null) {
        parseConvert(converts);
    }
    Element signatures = XmlElementUtil.findElement("signatures", root);
    if (signatures != null) {
        parseSignatures(signatures);
    }
}

From source file:com.easyjf.web.ajax.AjaxConfigManager.java

License:Apache License

public void parseSignatures(Element serviceRoot) {
    String[] value = StringUtils.tokenizeToStringArray(serviceRoot.getText().trim(), ";");
    if (value != null) {
        for (int i = 0; i < value.length; i++) {
            String line = value[i].trim();
            int b = line.indexOf("(");
            String name = line.substring(0, b);
            String v = line.substring(b + 1, line.lastIndexOf(")"));
            String[] pas = StringUtils.tokenizeToStringArray(v, ",");
            if (pas != null) {
                Class[] clzs = new Class[pas.length];
                for (int j = 0; j < pas.length; j++) {
                    try {
                        clzs[j] = Class.forName(pas[j].trim());
                    } catch (java.lang.ClassNotFoundException e) {
                        logger.error("load ajax signatures config errors:" + e.getMessage());
                        continue;
                    }//from w w  w.  ja  va 2s .  c  o  m
                }
                this.signatures.put(name, clzs);
            }
        }
    }
}

From source file:com.easyjf.web.config.XMLConfigFactory.java

License:Apache License

public Map initOther() {
    if (doc == null)
        return null;
    Map result = new HashMap();
    Element root = findElement("framework-setting", getRootElement());
    if (root == null) {
        root = findElement("frame-setting", getRootElement());
    }/*w  ww  .j a  v  a  2s . c o  m*/
    if (root != null) {
        // 
        Element node = findElement("template-base", root);
        if (node != null)
            result.put("TemplateBasePath", node.getText());
        // ???
        node = findElement("init-app", root);
        List appList = findElements("app-class", node);
        List applist = new ArrayList();
        for (int i = 0; i < appList.size(); i++) {
            Element e = (Element) appList.get(i);
            Map app = new HashMap();
            app.put("init-method", e.attributeValue("init-method"));
            app.put("destroy-method", e.attributeValue("destroy-method"));
            app.put("class", e.getText());
            applist.add(app);
        }
        result.put("initApp", applist);

        // ?
        node = findElement("interceptors", root);
        List interceptors = findElements("app-class", node);
        List appinterceptorslist = new ArrayList();
        if (interceptors != null) {
            for (int i = 0; i < interceptors.size(); i++) {
                Element e = (Element) interceptors.get(i);
                Map app = new HashMap();
                app.put("name", e.attributeValue("name"));
                app.put("method", e.attributeValue("method"));
                app.put("class", e.getText());
                appinterceptorslist.add(app);
            }
        }
        result.put("interceptors", appinterceptorslist);

        // ???
        node = findElement("error-handler", root);
        List errorHandlers = findElements("app-class", node);
        if (errorHandlers != null) {
            for (int i = 0; i < errorHandlers.size(); i++) {
                Element e = (Element) errorHandlers.get(i);
                Map app = new HashMap();
                app.put("exception", e.attributeValue("exception"));
                app.put("path", e.attributeValue("path"));
                app.put("class", e.getText());
                errorHandlers.set(i, app);
            }
        }
        result.put("errorHandlers", errorHandlers);
        // ????   
        List list = findElements("property", root);
        if (list != null) {
            for (int i = 0; i < list.size(); i++) {
                Element el = (Element) list.get(i);
                result.put(el.attributeValue("name"), el.getText());
            }
        }
    }
    List importResources = new java.util.ArrayList();
    List list = findElements("import", getRootElement());
    if (list != null) {
        for (int i = 0; i < list.size(); i++) {
            Element el = (Element) list.get(i);
            String resource = el.attributeValue("resource");
            if (resource != null && !"".equals(resource)) {
                //?/WEB-INFclasspath
                if (resource.toLowerCase().indexOf("web-inf") < 0 && resource.indexOf("classpath") != 0)
                    resource = "/WEB-INF/" + resource;
                importResources.add(resource);
            }
        }
    }
    result.put("importResources", importResources);
    // EasyJWebBean??bean beanDefinitions
    result.put("beanDefinitions", BeanConfigReader.parseBeansFromDocument(doc));
    return result;
}

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.  co  m
        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;
}