public List<Element> getDatatypeElements(List<XmlFile> metadataXmlList) { List<Element> list = new ArrayList<>(); for (XmlFile xmlFile : metadataXmlList) { Element datatypesEl = xmlFile.root.element("datatypes"); if (datatypesEl != null) { list.addAll(Dom4j.elements(datatypesEl, "datatype")); } } return list; }
private void addProperties(Element puElem, Map<String, String> properties) { Element propertiesEl = puElem.element("properties"); if (propertiesEl != null) { for (Element element : Dom4j.elements(propertiesEl, "property")) { properties.put(element.attributeValue("name"), element.attributeValue("value")); } } }
protected void loadConfig(Element rootElem) { for (Element serviceElem : Dom4j.elements(rootElem, "service")) { String serviceName = serviceElem.attributeValue("name"); for (Element methodElem : Dom4j.elements(serviceElem, "method")) { String methodName = methodElem.attributeValue("name"); addServiceMethod(serviceName, methodName); } } }
protected void initRootPackages(List<MetadataBuildSupport.XmlFile> metadataXmlList) { for (MetadataBuildSupport.XmlFile xmlFile : metadataXmlList) { for (Element element : Dom4j.elements(xmlFile.root, "metadata-model")) { String rootPackage = element.attributeValue("root-package"); if (!StringUtils.isBlank(rootPackage) && !rootPackages.contains(rootPackage)) { rootPackages.add(rootPackage); } } } }
private Element findPersistenceUnitElement(Element rootElem) { List<Element> puList = Dom4j.elements(rootElem, "persistence-unit"); if (puList.size() == 1) { return puList.get(0); } else { for (Element element : puList) { if ("cuba".equals(element.attributeValue("name"))) { return element; } } } return null; }
private void loadLicenses(Element rootElement) { Element licensesEl = rootElement.element("licenses"); if (licensesEl == null) return; for (Element element : Dom4j.elements(licensesEl)) { licenses.put(element.attributeValue("id"), element.getText()); } }
protected List<AutoImportFileDescriptor> convertXmlToFileDescriptors(List<XmlFile> xmlFiles) { List<AutoImportFileDescriptor> list = new ArrayList<>(); for (XmlFile xmlFile : xmlFiles) { List<Element> elements = Dom4j.elements(xmlFile.root, "auto-import-file"); for (Element element : elements) { String path = element.attributeValue("path"); String bean = element.attributeValue("bean"); String importClass = element.attributeValue("class"); list.add(new AutoImportFileDescriptor(path, bean, importClass)); } } return list; }
protected void processOneDirectionConfig(Element element, StandardEntityJsonTransformer transformer) { Set<String> removeAttributes = new HashSet<>(); for (Element removeAttributeElem : Dom4j.elements(element, "removeAttribute")) { String name = removeAttributeElem.attributeValue("name"); if (Strings.isNullOrEmpty(name)) { log.error("name for removeAttribute element is not specified"); continue; } removeAttributes.add(name); } transformer.setAttributesToRemove(removeAttributes); } }
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); } for (Element classEl : Dom4j.elements(element, "class")) { classNames.add(new EntityClassInfo(classEl.attributeValue("store"), classEl.getText().trim(), false)); } } } }
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 { classes.put(className, className); } } }
private void loadConfig(Element rootElement) { Element itemsEl = rootElement.element("items"); if (itemsEl == null) return; for (Element element : Dom4j.elements(itemsEl)) { CreditsItem item = new CreditsItem(element.attributeValue("name"), element.attributeValue("web"), element.attributeValue("license"), loadLicense(element), loadAcknowledgement(element), Boolean.parseBoolean(element.attributeValue("fork"))); if (items.contains(item)) { items.set(items.indexOf(item), item); } else { items.add(item); } } }
public List<MethodParameterInfo> getMethodParameters() { ArrayList<MethodParameterInfo> result = new ArrayList<>(); String xml = getMethodParamsXml(); if (!StringUtils.isBlank(xml)) { Document doc = Dom4j.readDocument(xml); List<Element> elements = Dom4j.elements(doc.getRootElement(), "param"); for (Element paramEl : elements) { String typeName = paramEl.attributeValue("type"); String name = paramEl.attributeValue("name"); Object value = paramEl.getText(); result.add(new MethodParameterInfo(typeName, name, value)); } } return result; }
protected void checkDuplicates(Element rootElem) { Set<String> checked = new HashSet<>(); for (Element viewElem : Dom4j.elements(rootElem, "view")) { String viewName = getViewName(viewElem); String key = getMetaClass(viewElem) + "/" + viewName; if (!Boolean.parseBoolean(viewElem.attributeValue("overwrite"))) { String extend = viewElem.attributeValue("extends"); if (extend != null) { List<String> ancestors = splitExtends(extend); if (!ancestors.contains(viewName) && checked.contains(key)) { log.warn("Duplicate view definition without 'overwrite' attribute and not extending parent view: " + key); } } } checked.add(key); } }
protected Object getXmlAnnotationAttributeValue(Element attributeEl) { String value = attributeEl.attributeValue("value"); String className = attributeEl.attributeValue("class"); String datatypeName = attributeEl.attributeValue("datatype"); List<Element> values = Dom4j.elements(attributeEl, "value"); if (StringUtils.isNotBlank(value)) { if (!values.isEmpty()) throw new IllegalStateException("Both 'value' attribute and 'value' element(s) are specified for attribute " + attributeEl.attributeValue("name")); return getXmlAnnotationAttributeValue(value, className, datatypeName); } if (!values.isEmpty()) { Object val0 = getXmlAnnotationAttributeValue(values.get(0).getTextTrim(), className, datatypeName); Object array = Array.newInstance(val0.getClass(), values.size()); Array.set(array, 0, val0); for (int i = 1; i < values.size(); i++) { Object val = getXmlAnnotationAttributeValue(values.get(i).getTextTrim(), className, datatypeName); Array.set(array, i, val); } return array; } return null; }
protected void loadDayNames(Calendar resultComponent, Element element) { Element dayNames = element.element("dayNames"); if (dayNames == null) { return; } Map<DayOfWeek, String> dayNamesMap = new HashMap<>(); for (Element dayName : Dom4j.elements(dayNames, "day")) { String dayKey = dayName.attributeValue("dayOfWeek"); DayOfWeek dayOfWeek = null; if (StringUtils.isNotEmpty(dayKey)) { dayOfWeek = DayOfWeek.valueOf(dayKey); } String dayValue = dayName.attributeValue("value"); if (StringUtils.isNotEmpty(dayValue)) { if (dayOfWeek != null) { dayValue = loadResourceString(dayValue); dayNamesMap.put(dayOfWeek, dayValue); } } } resultComponent.setDayNames(dayNamesMap); }
public void deployViews(String resourceUrl) { lock.readLock().lock(); try { checkInitialized(); } finally { lock.readLock().unlock(); } Element rootElem = DocumentHelper.createDocument().addElement("views"); lock.writeLock().lock(); try { addFile(rootElem, resourceUrl); for (Element viewElem : Dom4j.elements(rootElem, "view")) { deployView(rootElem, viewElem, new HashSet<>()); } } finally { lock.writeLock().unlock(); } }
private void compileSpecific(String xml, Node<BasicPermissionTarget> root) { Document doc = Dom4j.readDocument(xml); Element rootElem = doc.getRootElement(); for (Element element : Dom4j.elements(rootElem, "include")) { String fileName = element.attributeValue("file"); if (!StringUtils.isBlank(fileName)) { String incXml = resources.getResourceAsString(fileName); if (incXml == null) throw new RuntimeException("Config file not found: " + fileName); compileSpecific(incXml, root); } } Element specElem = rootElem.element("specific"); if (specElem == null) return; walkSpecific(specElem, root); }
@Override protected void loadActions(ActionsHolder actionsHolder, Element element) { Element actionsEl = element.element("actions"); if (actionsEl == null) return; for (Element actionEl : Dom4j.elements(actionsEl, "action")) { actionsHolder.addAction(loadDeclarativeAction(actionsHolder, actionEl)); String actionId = actionEl.attributeValue("id"); context.addPostInitTask(new ActionHolderAssignActionPostInitTask(actionsHolder, actionId, context.getFrame())); } }
protected void loadChartData(ChartModel chart, Element element) { Element dataElement = element.element("data"); if (dataElement != null) { ListDataProvider listDataProvider = new ListDataProvider(); for (Object item : dataElement.elements("item")) { Element itemElement = (Element) item; MapDataItem dataItem = new MapDataItem(); for (Element property : Dom4j.elements(itemElement, "property")) { loadDataItem(property, dataItem); } listDataProvider.addItem(dataItem); chart.setDataProvider(listDataProvider); } } }
protected void init() { StopWatch initTiming = new Slf4JStopWatch("ViewRepository.init." + getClass().getSimpleName()); storage.clear(); readFileNames.clear(); String configName = AppContext.getProperty("cuba.viewsConfig"); if (!StringUtils.isBlank(configName)) { Element rootElem = DocumentHelper.createDocument().addElement("views"); StringTokenizer tokenizer = new StringTokenizer(configName); for (String fileName : tokenizer.getTokenArray()) { addFile(rootElem, fileName); } checkDuplicates(rootElem); for (Element viewElem : Dom4j.elements(rootElem, "view")) { deployView(rootElem, viewElem, new HashSet<>()); } } initTiming.stop(); }