public static Document readDocument(String xmlString) { return readDocument(new StringReader(xmlString)); }
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; }
public static String writeDocument(Document doc, boolean prettyPrint) { StringWriter writer = new StringWriter(); writeDocument(doc, prettyPrint, writer); return writer.toString(); }
public static void walkAttributesRecursive(Element element, ElementAttributeVisitor visitor) { walkAttributes(element, visitor); for (Element childElement : element.elements()) { walkAttributesRecursive(childElement, visitor); } }
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; }
Document doc = Dom4j.readDocument(currSetting.getValue()); newSetting.setValue(Dom4j.writeDocument(doc, true)); } catch (Exception e) { newSetting.setValue(currSetting.getValue());
for (Element element : new ArrayList<>(Dom4j.elements(puElem, "class"))) { puElem.remove(element); try { os = new FileOutputStream(outFileName); Dom4j.writeDocument(doc, true, os); } catch (IOException e) { throw new RuntimeException(e);
Element layoutElement = document.getRootElement().element("layout"); if (layoutElement != null) { Dom4j.walkAttributesRecursive(layoutElement, (element, attribute) -> { String attributeValue = attribute.getValue(); if (StringUtils.isNotEmpty(attributeValue)
private static SAXReader getSaxReader() { String useThreadLocalCache = System.getProperty("cuba.saxParserThreadLocalCache"); if (useThreadLocalCache == null || Boolean.parseBoolean(useThreadLocalCache)) { try { return new SAXReader(getParser().getXMLReader()); } catch (SAXException e) { throw new RuntimeException("Unable to create SAX reader", e); } } else { return new SAXReader(); } }
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 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; }
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 File writeDocument(Document doc) { File file = new File(dir, "orm.xml"); log.info("Creating file " + file); OutputStream os = null; try { os = new FileOutputStream(file); Dom4j.writeDocument(doc, true, os); } catch (IOException e) { throw new RuntimeException(e); } finally { IOUtils.closeQuietly(os); } return file; }
@Override public Entity parseEntity(String content) { Document document = Dom4j.readDocument(content); Element instanceEl = document.getRootElement(); return parseEntity(instanceEl, null, null); }
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); } } }
@Override public void commit() { if (modified && root != null) { String xml = Dom4j.writeDocument(root.getDocument(), true); getSettingsClient().setSetting(name, xml); modified = false; } }
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); } }
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")); } } }
Dom4j.writeDocument(result.getDocument(), true, writer); log.trace("Resulting template:\n" + writer.toString());
/** * 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(); } }