public static Document readDocument(String xmlString) { return readDocument(new StringReader(xmlString)); }
protected String getProcessName(String xml) { Document document = Dom4j.readDocument(xml); Element process = document.getRootElement().element("process"); if (process == null) { throw new IllegalArgumentException("Process xml doesn't contain 'process' element"); } String name = process.attributeValue("name"); if (Strings.isNullOrEmpty(name)) { throw new IllegalArgumentException("Process name is not defined"); } return name; }
@Override public Entity parseEntity(String content) { Document document = Dom4j.readDocument(content); Element instanceEl = document.getRootElement(); return parseEntity(instanceEl, null, null); }
protected Element readXml(String path) { try (InputStream stream = resources.getResourceAsStream(path)) { if (stream == null) { throw new IllegalStateException("Resource not found: " + path); } Document document = Dom4j.readDocument(stream); return document.getRootElement(); } catch (IOException e) { throw new IllegalStateException("Unable to read resource: " + path); } }
/** * Creates a conditions tree from XML string. */ public Condition fromXml(String xml) { Element element = Dom4j.readDocument(xml).getRootElement(); return fromXml(element); }
public static Document readDocument(File file) { FileInputStream inputStream = null; try { inputStream = new FileInputStream(file); return Dom4j.readDocument(inputStream); } catch (FileNotFoundException e) { throw new RuntimeException("Unable to read XML from file", e); } finally { IOUtils.closeQuietly(inputStream); } }
/** * copy/paste from {@link com.haulmont.cuba.core.sys.MetadataBuildSupport#readXml(String)} */ protected Element readXml(String path) throws IOException { try (InputStream stream = resources.getResourceAsStream(path)) { if (stream == null) { throw new FileNotFoundException("File not found by path: " + path); } Document document = Dom4j.readDocument(stream); return document.getRootElement(); } }
@Override public ConditionsTree getConditions(Filter filter, String xml) { ConditionsTree conditions = new ConditionsTree(); if (!StringUtils.isBlank(xml)) { Element root = Dom4j.readDocument(xml).getRootElement(); Element andElem = root.element("and"); if (andElem == null) throw new IllegalStateException("Root element doesn't contain 'and': " + xml); recursiveFromXml(andElem, null, filter, xml, conditions); } return conditions; }
@Override public Collection<? extends Entity> parseEntitiesCollection(String content, Class<? extends Collection> collectionClass) { try { Collection collection = newCollectionInstance(collectionClass); Document document = Dom4j.readDocument(content); List instances = document.getRootElement().elements("instance"); for (Object instance : instances) { Entity entity = parseEntity((Element) instance, null, null); collection.add(entity); } return collection; } catch (Exception e) { throw new RuntimeException(e); } }
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; }
public Document parseDescriptor(String template) { checkNotNullArgument(template, "template is null"); Document document = Dom4j.readDocument(template); replaceAssignParameters(document); return document; }
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); }
protected void parseConfigFile(String fileName) { String fileContent = resources.getResourceAsString(fileName); if (!Strings.isNullOrEmpty(fileContent)) { Document document = Dom4j.readDocument(fileContent); List<Element> permissionElements = document.getRootElement().elements("permission"); for (Element element : permissionElements) { String target = element.attributeValue("target"); Integer value = Integer.valueOf(element.attributeValue("value")); Integer type = Integer.valueOf(element.attributeValue("type")); Permission permission = metadata.create(Permission.class); permission.setTarget(target); permission.setType(PermissionType.fromId(type)); permission.setValue(value); permissionValues.put(target, permission); } } else { log.error("File {} not found", fileName); } }
protected void checkLoaded() { if (root == null) { // use cache String xml = getSettingsClient().getSetting(name); if (StringUtils.isBlank(xml)) { root = DocumentHelper.createDocument().addElement("settings"); } else { root = Dom4j.readDocument(xml).getRootElement(); } } }
protected void init() { String configName = AppContext.getProperty(CUBA_REST_QUERIES_CONFIG_PROP_NAME); StringTokenizer tokenizer = new StringTokenizer(configName); for (String location : tokenizer.getTokenArray()) { Resource resource = resources.getResource(location); if (resource.exists()) { InputStream stream = null; try { stream = resource.getInputStream(); loadConfig(Dom4j.readDocument(stream).getRootElement()); } catch (IOException e) { throw new RuntimeException(e); } finally { IOUtils.closeQuietly(stream); } } else { log.warn("Resource {} not found, ignore it", location); } } }
protected void loadScreensXml() { String configName = AppContext.getProperty(WINDOW_CONFIG_XML_PROP); StringTokenizer tokenizer = new StringTokenizer(configName); for (String location : tokenizer.getTokenArray()) { Resource resource = resources.getResource(location); if (resource.exists()) { try (InputStream stream = resource.getInputStream()) { loadConfig(Dom4j.readDocument(stream).getRootElement()); } catch (IOException e) { throw new RuntimeException("Unable to read window config from " + location, e); } } else { log.warn("Resource {} not found, ignore it", location); } } }
protected void applyDatasourceFilter() { checkState(); String currentFilterXml = filterParser.getXml(conditions, Param.ValueProperty.VALUE); if (!Strings.isNullOrEmpty(currentFilterXml)) { Element element = Dom4j.readDocument(currentFilterXml).getRootElement(); QueryFilter queryFilter = new QueryFilter(element); if (dsQueryFilter != null) { queryFilter = QueryFilter.merge(dsQueryFilter, queryFilter); } adapter.setQueryFilter(queryFilter); } else { adapter.setQueryFilter(dsQueryFilter); } }
@Override public Element getSettings(Presentation p) { p = getPresentation(p.getId()); if (p != null) { Document doc; if (!StringUtils.isEmpty(p.getXml())) { doc = Dom4j.readDocument(p.getXml()); } else { doc = DocumentHelper.createDocument(); doc.setRootElement(doc.addElement("presentation")); } return doc.getRootElement(); } else { return null; } }
protected void collectQueryAndParametersFromFilter() { FilterParser filterParser = AppBeans.get(FilterParser.class); filterEntity.setXml(filterParser.getXml(filterEditor.getConditions(), Param.ValueProperty.DEFAULT_VALUE)); if (filterEntity.getXml() != null) { Element element = Dom4j.readDocument(filterEntity.getXml()).getRootElement(); QueryFilter queryFilter = new QueryFilter(element); conditionsTree = filterEditor.getConditionsTree(); filter = filterEditor.getFilter(); wizard.query = collectQuery(queryFilter); wizard.queryParameters = collectQueryParameters(queryFilter); } else { wizard.showNotification(wizard.getMessage("defaultQueryHasBeenSet"), Frame.NotificationType.HUMANIZED); wizard.query = filter.getDatasource().getQuery(); wizard.queryParameters = Collections.emptyList(); } wizard.setQueryButton.setCaption(wizard.getMessage("changeQuery")); }
public Filter createFakeFilter() { if (filter != null) { return filter; } Filter fakeFilter = AppBeans.get(ComponentsFactory.NAME, ComponentsFactory.class).createComponent(Filter.class); ((HasXmlDescriptor) fakeFilter).setXmlDescriptor(Dom4j.readDocument("<filter/>").getRootElement()); CollectionDatasourceImpl fakeDatasource = new CollectionDatasourceImpl(); LegacyFrame legacyFrame = (LegacyFrame) this.frameOwner; DsContextImpl fakeDsContext = new DsContextImpl(legacyFrame.getDsContext().getDataSupplier()); FrameContextImpl fakeFrameContext = new FrameContextImpl((Frame) legacyFrame); fakeDsContext.setFrameContext(fakeFrameContext); fakeDatasource.setDsContext(fakeDsContext); //Attention: this query should match the logic in com.haulmont.reports.wizard.ReportingWizardBean.createJpqlDataSet() fakeDatasource.setQuery("select queryEntity from " + metaClass.getName() + " queryEntity"); fakeDatasource.setMetaClass(metaClass); fakeFilter.setDatasource(fakeDatasource); fakeFilter.setFrame(UiControllerUtils.getFrame(frameOwner)); return fakeFilter; }