List of usage examples for org.dom4j DocumentHelper createDocument
public static Document createDocument()
From source file:com.haulmont.cuba.gui.components.filter.FilterParserImpl.java
License:Apache License
/** * Converts filter conditions tree to filter xml * @param conditions conditions tree//from w w w . j a v a 2s . co m * @param valueProperty Describes what parameter value will be serialized to xml: current value or default one * @return filter xml */ @Override @Nullable public String getXml(ConditionsTree conditions, Param.ValueProperty valueProperty) { String xml = null; if (conditions != null && !conditions.getRootNodes().isEmpty()) { Document document = DocumentHelper.createDocument(); Element root = document.addElement("filter"); Element element = root.addElement("and"); for (Node<AbstractCondition> node : conditions.getRootNodes()) { recursiveToXml(node, element, valueProperty); } xml = Dom4j.writeDocument(document, true); } log.trace("toXML: " + xml); return xml; }
From source file:com.haulmont.cuba.gui.components.filter.UserSetHelper.java
License:Apache License
public static String generateSetFilter(Set ids, String entityClass, String componentId, String entityAlias) { Document document = DocumentHelper.createDocument(); Element root = DocumentHelper.createElement("filter"); Element or = root.addElement("and"); Element condition = or.addElement("c"); condition.addAttribute("name", "set"); condition.addAttribute("inExpr", "true"); condition.addAttribute("hidden", "true"); condition.addAttribute("locCaption", "Set filter"); condition.addAttribute("entityAlias", entityAlias); condition.addAttribute("class", entityClass); condition.addAttribute("type", ConditionType.CUSTOM.name()); String listOfId = createIdsString(ids); String randomName = RandomStringUtils.randomAlphabetic(10); condition.addText(entityAlias + ".id in :component$" + componentId + "." + randomName); Element param = condition.addElement("param"); param.addAttribute("name", "component$" + componentId + "." + randomName); param.addText(listOfId);/*from w w w. ja v a 2s .c o m*/ document.add(root); return Dom4j.writeDocument(document, true); }
From source file:com.haulmont.cuba.gui.dynamicattributes.FilteringLookupAction.java
License:Apache License
protected Element createConditionXmlElement() { Element conditionElement = DocumentHelper.createDocument().addElement("c"); conditionElement.addAttribute("name", RandomStringUtils.randomAlphabetic(10)); conditionElement.addAttribute("width", "1"); conditionElement.addAttribute("type", "CUSTOM"); conditionElement.addAttribute("locCaption", messages.getMainMessage("dynamicAttributes.filter.conditionName")); return conditionElement; }
From source file:com.haulmont.cuba.gui.presentations.PresentationsImpl.java
License:Apache License
@Override public Element getSettings(Presentation p) { p = getPresentation(p.getId());//from w w w. j a v a 2 s .c om 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; } }
From source file:com.haulmont.cuba.gui.relatedentities.RelatedEntitiesBean.java
License:Apache License
protected Element getConditionXmlElement(String conditionName, MetaClass metaClass) { Element conditionElement = DocumentHelper.createDocument().addElement("c"); conditionElement.addAttribute("name", conditionName); conditionElement.addAttribute("width", "1"); conditionElement.addAttribute("type", "CUSTOM"); String conditionCaption = String.format("%s ids", metaClass.getName().split("\\$")[1]); // condition will be hidden so we don't have to load localized condition caption conditionElement.addAttribute("locCaption", conditionCaption); return conditionElement; }
From source file:com.haulmont.cuba.gui.settings.SettingsImpl.java
License:Apache License
protected void checkLoaded() { if (root == null) { // use cache String xml = getSettingsClient().getSetting(name); if (StringUtils.isBlank(xml)) { root = DocumentHelper.createDocument().addElement("settings"); } else {// w ww .jav a2 s . co m root = Dom4j.readDocument(xml).getRootElement(); } } }
From source file:com.haulmont.cuba.restapi.XMLConverter2.java
License:Apache License
protected Document _process(Entity entity, View view) throws Exception { Document document = DocumentHelper.createDocument(); Element rootEl = document.addElement("instances"); encodeEntity(entity, new HashSet<Entity>(), view, rootEl); return document; }
From source file:com.haulmont.cuba.restapi.XMLConverter2.java
License:Apache License
protected Document _process(List<Entity> entities, MetaClass metaClass, View view) throws Exception { Document document = DocumentHelper.createDocument(); Element rootEl = document.addElement("instances"); for (Entity entity : entities) { encodeEntity(entity, new HashSet<Entity>(), view, rootEl); }/*from w w w . j a va 2s .co m*/ return document; }
From source file:com.haulmont.cuba.restapi.XMLConverter2.java
License:Apache License
@Override public String process(Set<Entity> entities) throws Exception { Document document = DocumentHelper.createDocument(); Element rootEl = document.addElement("instances"); for (Entity entity : entities) { encodeEntity(entity, new HashSet<Entity>(), null, rootEl); }// ww w .j av a 2 s . co m return documentToString(document); }
From source file:com.haulmont.cuba.restapi.XMLConverter2.java
License:Apache License
@Override @Nonnull/* w ww .j a v a2 s . c om*/ public String processServiceMethodResult(Object result, Class resultType) throws Exception { Document document = DocumentHelper.createDocument(); Element resultEl = document.addElement("result"); if (result instanceof Entity) { Entity entity = (Entity) result; Document convertedEntity = _process(entity, null); resultEl.add(convertedEntity.getRootElement()); } else if (result instanceof Collection) { if (!checkCollectionItemTypes((Collection) result, Entity.class)) throw new IllegalArgumentException( "Items that are not instances of Entity class found in service method result"); ArrayList list = new ArrayList((Collection) result); MetaClass metaClass = null; if (!list.isEmpty()) metaClass = ((Entity) list.get(0)).getMetaClass(); Document processed = _process(list, metaClass, null); resultEl.add(processed.getRootElement()); } else { if (result != null && resultType != Void.TYPE) { Datatype datatype = getDatatype(resultType); resultEl.setText(datatype != null ? datatype.format(result) : result.toString()); } else { encodeNull(resultEl); } } return documentToString(document); }