List of usage examples for org.dom4j Element getText
String getText();
From source file:com.haulmont.cuba.core.global.filter.FilterParser.java
License:Apache License
protected Condition createCondition(Element conditionElement) { Condition condition;/*ww w .ja v a 2 s . c o m*/ String conditionName; if (conditionElement.attributeValue("locCaption") == null) { conditionName = conditionElement.attributeValue("name"); } else { conditionName = conditionElement.attributeValue("locCaption"); } if ("c".equals(conditionElement.getName())) { condition = new Clause(conditionName, conditionElement.getText(), getJoinValue(conditionElement), conditionElement.attributeValue("operatorType"), conditionElement.attributeValue("type")); // support unary conditions without parameters in text (e.g. "is null") for (Element paramElem : Dom4j.elements(conditionElement, "param")) { Set<ParameterInfo> params = ParametersHelper.parseQuery(":" + paramElem.attributeValue("name")); Attribute javaClass = paramElem.attribute("javaClass"); if (javaClass != null) { for (ParameterInfo param : params) { try { param.setJavaClass(Class.forName(javaClass.getValue())); param.setConditionName(conditionName); param.setValue(paramElem.getText()); } catch (ClassNotFoundException e) { //do not fail } if (condition.getParameters().contains(param)) { for (ParameterInfo parameterInfo : condition.getParameters()) { if (parameterInfo.equals(param)) { parameterInfo.setJavaClass(param.getJavaClass()); parameterInfo.setConditionName(param.getConditionName()); parameterInfo.setValue(param.getValue()); } } } } } condition.getParameters().addAll(params); } } else { condition = new LogicalCondition(conditionName, LogicalOp.fromString(conditionElement.getName())); } return condition; }
From source file:com.haulmont.cuba.core.global.filter.FilterParser.java
License:Apache License
protected String getJoinValue(Element conditionElement) { Element joinElement = conditionElement.element("join"); String join;//from ww w . ja v a2 s . c o m if (joinElement != null) { join = joinElement.getText(); } else { //for backward compatibility join = conditionElement.attributeValue("join"); } return join; }
From source file:com.haulmont.cuba.core.sys.MetadataBuildSupport.java
License:Apache License
protected void loadFromMetadataConfig(Map<String, List<EntityClassInfo>> packages, List<XmlFile> metadataXmlList) { for (XmlFile xmlFile : metadataXmlList) { for (Element element : Dom4j.elements(xmlFile.root, "metadata-model")) { String rootPackage = element.attributeValue("root-package"); if (StringUtils.isBlank(rootPackage)) throw new IllegalStateException("metadata-model/@root-package is empty in " + xmlFile.name); List<EntityClassInfo> classNames = packages.get(rootPackage); if (classNames == null) { classNames = new ArrayList<>(); packages.put(rootPackage, classNames); }//w ww. ja v a 2 s . com for (Element classEl : Dom4j.elements(element, "class")) { classNames.add( new EntityClassInfo(classEl.attributeValue("store"), classEl.getText().trim(), false)); } } } }
From source file:com.haulmont.cuba.core.sys.MetadataBuildSupport.java
License:Apache License
protected void loadFromPersistenceConfig(Map<String, List<EntityClassInfo>> packages, String db) { String persistenceConfig = getPersistenceConfig(db); if (persistenceConfig == null) return;// w w w. java2 s . c om StrTokenizer persistenceFilesTokenizer = new StrTokenizer(persistenceConfig); for (String fileName : persistenceFilesTokenizer.getTokenArray()) { Element root = readXml(fileName); Element puEl = root.element("persistence-unit"); if (puEl == null) throw new IllegalStateException("File " + fileName + " has no persistence-unit element"); for (Element classEl : Dom4j.elements(puEl, "class")) { String className = classEl.getText().trim(); boolean included = false; for (String rootPackage : packages.keySet()) { if (className.startsWith(rootPackage + ".")) { List<EntityClassInfo> classNames = packages.get(rootPackage); if (classNames == null) { classNames = new ArrayList<>(); packages.put(rootPackage, classNames); } classNames.add(new EntityClassInfo(db, className, true)); included = true; break; } } if (!included) throw new IllegalStateException("Can not find a model for class " + className + ". The class's package must be inside of some model's root package."); } } }
From source file:com.haulmont.cuba.core.sys.persistence.PersistenceConfigProcessor.java
License:Apache License
private void addClasses(Element puElem, Map<String, String> classes) { for (Element element : Dom4j.elements(puElem, "class")) { String className = element.getText(); Class<Object> cls = ReflectionHelper.getClass(className); Entity annotation = cls.getAnnotation(Entity.class); if (annotation != null) { classes.put(annotation.name(), className); } else {//from www . j a v a 2s.c o m classes.put(className, className); } } }
From source file:com.haulmont.cuba.gui.app.core.credits.CreditsLoader.java
License:Apache License
private void loadLicenses(Element rootElement) { Element licensesEl = rootElement.element("licenses"); if (licensesEl == null) return;//from www.j a v a 2 s.co m for (Element element : Dom4j.elements(licensesEl)) { licenses.put(element.attributeValue("id"), element.getText()); } }
From source file:com.haulmont.cuba.gui.app.core.credits.CreditsLoader.java
License:Apache License
private String loadLicense(Element element) { String licenseRef = element.attributeValue("license"); if (licenseRef != null) { String license = licenses.get(licenseRef); if (license == null) throw new IllegalStateException("License text for " + licenseRef + " not found"); return license; } else {/*from w w w .j a v a2 s . c o m*/ Element licenseEl = element.element("license"); if (licenseEl == null) throw new IllegalStateException("Neither license attribute, nor license element is not set for " + element.attributeValue("name")); return licenseEl.getText(); } }
From source file:com.haulmont.cuba.gui.app.core.credits.CreditsLoader.java
License:Apache License
private String loadAcknowledgement(Element element) { Element acknowledgmentEl = element.element("acknowledgment"); return acknowledgmentEl == null ? null : acknowledgmentEl.getText(); }
From source file:com.haulmont.cuba.gui.components.filter.condition.AbstractCondition.java
License:Apache License
protected AbstractCondition(Element element, String messagesPack, String filterComponentName, Datasource datasource) {/*from w w w .j a va2 s .co m*/ this.messagesPack = messagesPack; this.filterComponentName = filterComponentName; name = element.attributeValue("name"); text = StringEscapeUtils.unescapeXml(element.getText()); if (text == null) text = ""; caption = element.attributeValue("caption"); MessageTools messageTools = AppBeans.get(MessageTools.class); locCaption = messageTools.loadString(messagesPack, caption); unary = Boolean.valueOf(element.attributeValue("unary")); inExpr = Boolean.valueOf(element.attributeValue("inExpr")); hidden = Boolean.valueOf(element.attributeValue("hidden")); required = Boolean.valueOf(element.attributeValue("required")); useUserTimeZone = Boolean.valueOf(element.attributeValue("useUserTimeZone")); entityParamWhere = element.attributeValue("paramWhere"); entityParamView = element.attributeValue("paramView"); width = Strings.isNullOrEmpty(element.attributeValue("width")) ? 1 : Integer.parseInt(element.attributeValue("width")); this.datasource = datasource; resolveParam(element); }
From source file:com.haulmont.cuba.gui.components.filter.condition.AbstractCondition.java
License:Apache License
protected void resolveParam(Element element) { Scripting scripting = AppBeans.get(Scripting.NAME); String aclass = element.attributeValue("class"); if (!isBlank(aclass)) { javaClass = scripting.loadClass(aclass); }//from ww w . j a va 2s . c o m String operatorName = element.attributeValue("operatorType", null); if (operatorName != null) { operator = Op.valueOf(operatorName); } List<Element> paramElements = Dom4j.elements(element, "param"); if (!paramElements.isEmpty()) { Element paramElem = paramElements.iterator().next(); if (BooleanUtils.toBoolean(paramElem.attributeValue("hidden", "false"), "true", "false")) { paramElem = paramElements.iterator().next(); } paramName = paramElem.attributeValue("name"); if (!isBlank(paramElem.attributeValue("javaClass"))) { paramClass = scripting.loadClass(paramElem.attributeValue("javaClass")); } ConditionParamBuilder paramBuilder = AppBeans.get(ConditionParamBuilder.class); if (Strings.isNullOrEmpty(paramName)) { paramName = paramBuilder.createParamName(this); } param = paramBuilder.createParam(this); param.setDateInterval( BooleanUtils.toBoolean(paramElem.attributeValue("isDateInterval", "false"), "true", "false")); param.parseValue(paramElem.getText()); param.setDefaultValue(param.getValue()); } if ("EMPTY".equals(operatorName)) { //for backward compatibility with old filters that still use EMPTY operator operatorName = "NOT_EMPTY"; if (BooleanUtils.isTrue((Boolean) param.getValue())) param.setValue(false); param.setDefaultValue(false); operator = Op.valueOf(operatorName); } }