List of usage examples for org.dom4j Element elements
List<Element> elements(QName qName);
From source file:com.haulmont.cuba.gui.xml.layout.loaders.WindowLoader.java
License:Apache License
protected void loadTimers(ComponentsFactory factory, Window component, Element element) { Element timersElement = element.element("timers"); if (timersElement != null) { final List timers = timersElement.elements("timer"); for (final Object o : timers) { loadTimer(factory, component, (Element) o); }/* www . j a v a 2 s . c om*/ } }
From source file:com.haulmont.cuba.restapi.XMLConverter2.java
License:Apache License
@Override public CommitRequest parseCommitRequest(String content) { try {/*from w w w.j av a 2s . co m*/ CommitRequest commitRequest = new CommitRequest(); Document document = Dom4j.readDocument(content); Element rootElement = document.getRootElement(); //commit instances Element commitInstancesEl = rootElement.element("commitInstances"); if (commitInstancesEl != null) { //first find and register ids of all entities to be commited Set<String> commitIds = new HashSet<>(); for (Object instance : commitInstancesEl.elements("instance")) { Element instanceEl = (Element) instance; String id = instanceEl.attributeValue("id"); if (id.startsWith("NEW-")) id = id.substring(id.indexOf('-') + 1); commitIds.add(id); } commitRequest.setCommitIds(commitIds); List commitInstanceElements = commitInstancesEl.elements("instance"); List<Entity> commitInstances = new ArrayList<>(); for (Object el : commitInstanceElements) { Element commitInstanceEl = (Element) el; String id = commitInstanceEl.attributeValue("id"); InstanceRef ref = commitRequest.parseInstanceRefAndRegister(id); Entity instance = ref.getInstance(); parseEntity(commitInstanceEl, instance, commitRequest); commitInstances.add(instance); } commitRequest.setCommitInstances(commitInstances); } //remove instances Element removeInstancesEl = rootElement.element("removeInstances"); if (removeInstancesEl != null) { List removeInstanceElements = removeInstancesEl.elements("instance"); List<Entity> removeInstances = new ArrayList<>(); for (Object el : removeInstanceElements) { Element removeInstance = (Element) el; String id = removeInstance.attributeValue("id"); InstanceRef ref = commitRequest.parseInstanceRefAndRegister(id); Entity instance = ref.getInstance(); removeInstances.add(instance); } commitRequest.setRemoveInstances(removeInstances); } //soft deletion Element softDeletionEl = rootElement.element("softDeletion"); if (softDeletionEl != null) { commitRequest.setSoftDeletion(Boolean.parseBoolean(softDeletionEl.getText())); } return commitRequest; } catch (Exception e) { throw new RuntimeException(e); } }
From source file:com.haulmont.cuba.restapi.XMLConverter2.java
License:Apache License
protected Element findParamByName(Element paramsEl, String paramName) { List params = paramsEl.elements("param"); for (Object param : params) { String curName = ((Element) param).attributeValue("name"); if (paramName.equals(curName)) return (Element) param; }/*from w w w . j a v a 2 s . c o m*/ return null; }
From source file:com.haulmont.cuba.restapi.XMLConverter2.java
License:Apache License
@Override public QueryRequest parseQueryRequest(String content) throws IllegalArgumentException, ClassNotFoundException, ParseException { Document document = Dom4j.readDocument(content); Element rootElement = document.getRootElement(); QueryRequest queryRequest = new QueryRequest(); Element entityElem = rootElement.element("entity"); String entity = entityElem.getTextTrim(); queryRequest.setEntity(entity);/*ww w . jav a 2s . c o m*/ Element queryElem = rootElement.element("query"); String query = queryElem.getTextTrim(); queryRequest.setQuery(query); if (rootElement.element("view") != null) { Element viewElem = rootElement.element("view"); String view = viewElem.getTextTrim(); queryRequest.setViewName(view); } if (rootElement.element("max") != null) { Element maxElem = rootElement.element("max"); String maxString = maxElem.getTextTrim(); int max = Integer.parseInt(maxString); queryRequest.setMax(max); } if (rootElement.element("first") != null) { Element firstElem = rootElement.element("first"); String firstString = firstElem.getTextTrim(); int first = Integer.parseInt(firstString); queryRequest.setFirst(first); } if (rootElement.element("dynamicAttributes") != null) { Element dynamicAttributesElem = rootElement.element("dynamicAttributes"); String dynamicAttributesString = dynamicAttributesElem.getTextTrim(); Boolean dynamicAttributes = Boolean.valueOf(dynamicAttributesString); queryRequest.setDynamicAttributes(dynamicAttributes); } if (rootElement.element("params") != null) { Element paramsElem = rootElement.element("params"); List paramList = paramsElem.elements("param"); for (Object obj : paramList) { if (obj instanceof Element) { Element paramElem = (Element) obj; Element nameElem = paramElem.element("name"); String paramName = nameElem.getStringValue(); Element valueElem = paramElem.element("value"); String paramValue = valueElem.getStringValue(); Object value = null; if (paramElem.element("type") != null) { Element typeElem = paramElem.element("type"); String typeString = typeElem.getStringValue(); Class type = ClassUtils.forName(typeString, null); value = ParseUtils.toObject(type, paramValue, this); } else { value = ParseUtils.tryParse(paramValue); } queryRequest.getParams().put(paramName, value != null ? value : paramValue); } } } return queryRequest; }
From source file:com.haulmont.cuba.web.gui.components.WebGroupTable.java
License:Apache License
@Override public void applyColumnSettings(Element element) { super.applyColumnSettings(element); final Element groupPropertiesElement = element.element("groupProperties"); if (groupPropertiesElement != null) { final List elements = groupPropertiesElement.elements("property"); final List<MetaPropertyPath> properties = new ArrayList<>(elements.size()); for (final Object o : elements) { final MetaPropertyPath property = datasource.getMetaClass() .getPropertyPath(((Element) o).attributeValue("id")); properties.add(property);// www .j av a 2s .c o m } groupBy(properties.toArray()); } }
From source file:com.haulmont.cuba.web.sys.WebExternalUIComponentsSource.java
License:Apache License
@SuppressWarnings("unchecked") protected void _registerComponent(InputStream is) throws ClassNotFoundException { ClassLoader classLoader = App.class.getClassLoader(); Element rootElement = Dom4j.readDocument(is).getRootElement(); List<Element> components = rootElement.elements("component"); for (Element component : components) { String name = trimToEmpty(component.elementText("name")); String componentClassName = trimToEmpty(component.elementText("class")); String componentLoaderClassName = trimToEmpty(component.elementText("componentLoader")); String tag = trimToEmpty(component.elementText("tag")); if (StringUtils.isEmpty(tag)) { tag = name;/* w w w . ja v a 2s . co m*/ } if (StringUtils.isEmpty(name) && StringUtils.isEmpty(tag)) { log.warn("You have to provide name or tag for custom component"); // skip this <component> element continue; } if (StringUtils.isEmpty(componentLoaderClassName) && StringUtils.isEmpty(componentClassName)) { log.warn("You have to provide at least <class> or <componentLoader> for custom component {} / <{}>", name, tag); // skip this <component> element continue; } if (StringUtils.isNotEmpty(name) && StringUtils.isNotEmpty(componentClassName)) { Class<?> componentClass = classLoader.loadClass(componentClassName); if (Component.class.isAssignableFrom(componentClass)) { log.trace("Register component {} class {}", name, componentClass.getCanonicalName()); webComponentsFactory.register(name, (Class<? extends Component>) componentClass); } else { log.warn("Component {} is not a subclass of com.haulmont.cuba.gui.components.Component", componentClassName); } } if (StringUtils.isNotEmpty(tag) && StringUtils.isNotEmpty(componentLoaderClassName)) { Class<?> componentLoaderClass = classLoader.loadClass(componentLoaderClassName); if (ComponentLoader.class.isAssignableFrom(componentLoaderClass)) { log.trace("Register tag {} loader {}", tag, componentLoaderClass.getCanonicalName()); LayoutLoaderConfig.registerLoader(tag, (Class<? extends ComponentLoader>) componentLoaderClass); } else { log.warn( "Component loader {} is not a subclass of com.haulmont.cuba.gui.xml.layout.ComponentLoader", componentLoaderClassName); } } } _loadWindowLoaders(rootElement); }
From source file:com.haulmont.yarg.structure.xml.impl.DefaultXmlReader.java
License:Apache License
protected Map<String, ReportTemplate> parseTemplates(Element rootElement) throws IOException { Element templatesElement = rootElement.element("templates"); List<Element> templates = templatesElement.elements("template"); Map<String, ReportTemplate> templateMap = new HashMap<String, ReportTemplate>(); for (Element template : templates) { String code = template.attribute("code").getText(); String documentName = template.attribute("documentName").getText(); String documentPath = template.attribute("documentPath").getText(); String outputType = template.attribute("outputType").getText(); String outputNamePattern = template.attribute("outputNamePattern").getText(); ReportTemplate reportTemplate = new ReportTemplateBuilder().code(code).documentName(documentName) .documentPath(documentPath).documentContent(getDocumentContent(documentPath)) .outputType(ReportOutputType.getOutputTypeById(outputType)).outputNamePattern(outputNamePattern) .build();//from w ww .ja va2s . c o m templateMap.put(reportTemplate.getCode(), reportTemplate); } return templateMap; }
From source file:com.haulmont.yarg.structure.xml.impl.DefaultXmlReader.java
License:Apache License
protected List<ReportParameter> parseInputParameters(Element rootElement) throws FileNotFoundException, ClassNotFoundException { List<ReportParameter> reportParameters = new ArrayList<ReportParameter>(); Element inputParametersElement = rootElement.element("parameters"); if (inputParametersElement != null) { List<Element> parameters = inputParametersElement.elements("parameter"); for (Element parameter : parameters) { String name = parameter.attribute("name").getText(); String alias = parameter.attribute("alias").getText(); Boolean required = Boolean.valueOf(parameter.attribute("required").getText()); Class type = Class.forName(parameter.attribute("class").getText()); Attribute defaultValueAttr = parameter.attribute("defaultValue"); String defaultValue = null; if (defaultValueAttr != null) { defaultValue = defaultValueAttr.getText(); }//from ww w . j av a 2s .co m ReportParameterImpl reportParameter = new ReportParameterImpl(name, alias, required, type, defaultValue); reportParameters.add(reportParameter); } } return reportParameters; }
From source file:com.haulmont.yarg.structure.xml.impl.DefaultXmlReader.java
License:Apache License
protected List<ReportFieldFormat> parseValueFormats(Element rootElement) throws FileNotFoundException, ClassNotFoundException { List<ReportFieldFormat> reportParameters = new ArrayList<ReportFieldFormat>(); Element formatsElement = rootElement.element("formats"); if (formatsElement != null) { List<Element> parameters = formatsElement.elements("format"); for (Element parameter : parameters) { String name = parameter.attribute("name").getText(); String format = parameter.attribute("format").getText(); reportParameters.add(new ReportFieldFormatImpl(name, format)); }//from ww w . ja v a2 s . c o m } return reportParameters; }
From source file:com.haulmont.yarg.structure.xml.impl.DefaultXmlReader.java
License:Apache License
protected void parseChildBandDefinitions(Element bandDefinitionElement, BandBuilder parentBandDefinitionBuilder) throws FileNotFoundException, ClassNotFoundException { Element childrenBandsElement = bandDefinitionElement.element("bands"); if (childrenBandsElement != null) { List<Element> childrenBands = childrenBandsElement.elements("band"); for (Element childBandElement : childrenBands) { String childBandName = childBandElement.attribute("name").getText(); BandOrientation orientation = BandOrientation .fromId(childBandElement.attribute("orientation").getText()); BandBuilder childBandDefinitionBuilder = new BandBuilder().name(childBandName) .orientation(orientation); parseQueries(childBandElement, childBandDefinitionBuilder); parseChildBandDefinitions(childBandElement, childBandDefinitionBuilder); ReportBand childBandDefinition = childBandDefinitionBuilder.build(); parentBandDefinitionBuilder.child(childBandDefinition); }//from www . java 2 s . c o m } }