List of usage examples for org.dom4j DocumentHelper makeElement
public static Element makeElement(Branch source, String path)
makeElement
a helper method which navigates from the given Document or Element node to some Element using the path expression, creating any necessary elements along the way.From source file:itensil.workflow.activities.rules.XPathConditionEval.java
License:Open Source License
/** * Will create or selet the elemen in the pathExpr, set to the XPath in valExpr * * @param activity/*w w w . jav a 2s . c o m*/ * @param pathExpr * @param valExpr * @throws EvalException */ public void setDataValueExpr(Activity activity, Document datDoc, Document valDoc, String pathExpr, String valExpr) throws EvalException { Element root = datDoc.getRootElement(); // Element created if it did not exist Element elem = DocumentHelper.makeElement(root, pathExpr); XPath xp = getXPath(valExpr, valDoc, activity); // set it elem.setText(xp.valueOf(root)); }
From source file:itensil.workflow.activities.rules.XPathConditionEval.java
License:Open Source License
public void setDataValues(Activity activity, Document datDoc, Map<String, String> values) { Element root = datDoc.getRootElement(); for (Entry<String, String> ent : values.entrySet()) { Element elem = DocumentHelper.makeElement(root, ent.getKey()); elem.setText(ent.getValue());/*from w ww. j ava 2 s . co m*/ } }
From source file:org.bigmouth.nvwa.utils.xml.Dom4jEncoder.java
License:Apache License
/** * ???XML<br>//from w w w . ja va 2 s .c o m * ?{@linkplain org.bigmouth.nvwa.utils.Argument}?? * * <pre> * e.g. * * List<Object> list = new ArrayList<Object>(); * * Object obj1 = new Object(); * obj1.setName("Allen"); * obj1.setOld(18); * obj1.setHomeAddr("Hangzhou"); * obj1.setCellphon_no("10086"); * * Object obj2 = new Object(); * obj2.setName("Lulu"); * obj2.setOld(16); * obj2.setHomeAddr("Hangzhou"); * obj2.setCellphon_no("10086-1"); * * list.add(obj1); * list.add(obj2); * * String xml = Dom4jEncoder.encode(list, "/class", "student"); * System.out.println(xml); * * ------------------------- * | XML Result: * ------------------------- * * <class> * <student> * <name>Allen</Name> * <old>18</old> * <home_addr>Hangzhou</home_addr> * <cellphone__no>10086</cellphone__no> * </student> * <student> * <name>Lulu</Name> * <old>16</old> * <home_addr>Hangzhou</home_addr> * <cellphone__no>10086-1</cellphone__no> * </student> * </class> * * </pre> * * @param <T> * @param objs ??? * @param xpath * @param itemNodeName ?? * @return * @see org.bigmouth.nvwa.utils.Argument */ public static <T> String encode(List<T> objs, String xpath, String itemNodeName) { if (CollectionUtils.isEmpty(objs)) return null; if (StringUtils.isBlank(xpath) || StringUtils.equals(xpath, "/")) { throw new IllegalArgumentException("xpath cannot be blank or '/'!"); } Document doc = DocumentHelper.createDocument(); Element root = null; if (StringUtils.split(xpath, "/").length > 2) { root = DocumentHelper.makeElement(doc, xpath); } else { xpath = StringUtils.removeStart(xpath, "/"); root = doc.addElement(xpath); } for (Object obj : objs) { addElement(itemNodeName, root, obj); } return doc.asXML(); }
From source file:org.pentaho.actionsequence.dom.actions.ActionDefinition.java
License:Open Source License
/** * Adds a new input parameter to this action definition. If the input already exists the type of the input is set to * the specified type.//from w w w . ja v a 2s. c om * * @param privateParamName * the name of the param as it is known by this action definition (the input element name). * @param inputType * the input type * @return the action input */ public ActionInput addInput(String privateParamName, String inputType) { ActionInput input = getInputParam(privateParamName); Element inputElement; if (input == null) { Element[] componentDefs = getComponentDefElements(privateParamName); for (int i = 0; i < componentDefs.length; i++) { componentDefs[i].detach(); } inputElement = DocumentHelper.makeElement(actionDefElement, ActionSequenceDocument.ACTION_INPUTS_NAME + "/" + privateParamName); //$NON-NLS-1$ inputElement.addAttribute(IAbstractIOElement.TYPE_NAME, inputType); input = new ActionInput(inputElement, actionParameterMgr); ActionSequenceDocument.fireIoAdded(input); } else { input.setType(inputType); } return input; }
From source file:org.pentaho.actionsequence.dom.actions.ActionDefinition.java
License:Open Source License
/** * Creates an input resource with the given name. The resource will reference the specified action sequence resource. * No operation is performed if the resource already exists. * /* w ww . j ava 2 s .c om*/ * @param privateResourceName * the name of the resource as it is known by this action definition (the element name). * @return the newly created or existing resource. */ public IActionResource addResource(String privateResourceName, String referencedActionSequenceResource) { IActionResource resource = getResource(privateResourceName); Element resourceElement; if (resource == null) { resourceElement = DocumentHelper.makeElement(actionDefElement, ActionSequenceDocument.ACTION_RESOURCES_NAME + "/" + privateResourceName); //$NON-NLS-1$ resourceElement.addAttribute(IAbstractIOElement.TYPE_NAME, ActionSequenceDocument.RESOURCE_TYPE); resource = new ActionResource(resourceElement, actionParameterMgr); if ((referencedActionSequenceResource != null) && (referencedActionSequenceResource.trim().length() > 0)) { resource.setMapping(referencedActionSequenceResource); } ActionSequenceDocument.fireResourceAdded(resource); } return resource; }
From source file:org.pentaho.actionsequence.dom.actions.ActionDefinition.java
License:Open Source License
public IActionOutput addOutput(String privateParamName, String outputType) { IActionOutput output = getOutput(privateParamName); Element outputElement;//from ww w. j ava 2 s. co m if (output == null) { outputElement = DocumentHelper.makeElement(actionDefElement, ActionSequenceDocument.ACTION_OUTPUTS_NAME + "/" + privateParamName); //$NON-NLS-1$ outputElement.addAttribute(IAbstractIOElement.TYPE_NAME, outputType); output = new ActionOutput(outputElement, actionParameterMgr); ActionSequenceDocument.fireIoAdded(output); } else { output.setType(outputType); } return output; }
From source file:org.pentaho.actionsequence.dom.actions.ActionDefinition.java
License:Open Source License
/** * Sets the value of the component definition elements at the specified XPath. * //from w w w . j a va2 s. c o m * @param compDefXpath * the XPath of the element relative to the component definition element. * @param values * the value to be assigned to the elements */ public void setComponentDefinition(String compDefXpath, String[] values) { boolean changed = false; Element[] componentDefs = getComponentDefElements(compDefXpath); for (int i = 0; i < componentDefs.length; i++) { componentDefs[i].detach(); } if (componentDefs.length > 0) { changed = true; } if (values.length > 0) { Element componentDef = DocumentHelper.makeElement(actionDefElement, ActionSequenceDocument.COMPONENT_DEF_NAME + "/" + compDefXpath); //$NON-NLS-1$ componentDef.setText(values[0]); Element parent = componentDef.getParent(); for (int i = 1; i < values.length; i++) { parent.addElement(componentDef.getName()).setText(values[i]); } changed = true; } if (changed) { ActionSequenceDocument.fireActionChanged(this); } }
From source file:org.pentaho.actionsequence.dom.actions.ActionDefinition.java
License:Open Source License
/** * Sets the attribute value of the component definition element at the specified XPath. * /*from www. ja v a2s.com*/ * @param compDefXpath * the XPath of the element relative to the component definition element. * @param attributeName * the attribute name * @param value * the value to be assigned to the attribute */ public void setComponentDefinitionAttribute(String compDefXpath, String attributeName, String value) { Element componentDef = getComponentDefElement(compDefXpath); if (componentDef == null) { if (value != null) { componentDef = DocumentHelper.makeElement(actionDefElement, ActionSequenceDocument.COMPONENT_DEF_NAME + "/" + compDefXpath); //$NON-NLS-1$ } } if (componentDef != null) { componentDef.addAttribute(attributeName, value); ActionSequenceDocument.fireActionChanged(this); } }
From source file:org.pentaho.actionsequence.dom.actions.ActionDefinition.java
License:Open Source License
/** * Sets the value of the component definition element at the specified XPath. * //from w ww . j a v a 2s . co m * @param compDefXpath * the XPath of the element relative to the component definition element. * @param value * the value to be assigned to the element * @param useCData * whether a CDATA node should be used to save the value */ public void setComponentDefinition(String compDefXpath, String value, boolean useCData) { if (value == null) { Element[] componentDefs = getComponentDefElements(compDefXpath); for (int i = 0; i < componentDefs.length; i++) { componentDefs[i].detach(); } if (componentDefs.length > 0) { ActionSequenceDocument.fireActionChanged(this); } } else { Element componentDef = getComponentDefElement(compDefXpath); if (componentDef == null) { componentDef = DocumentHelper.makeElement(actionDefElement, ActionSequenceDocument.COMPONENT_DEF_NAME + "/" + compDefXpath); //$NON-NLS-1$ } componentDef.clearContent(); if (useCData) { componentDef.addCDATA(value); } else { componentDef.setText(value); } ActionSequenceDocument.fireActionChanged(this); } }
From source file:org.pentaho.actionsequence.dom.actions.EmailAttachment.java
License:Open Source License
EmailAttachment(EmailAction emailAction, IActionInputVariable attachment) { attachmentElement = DocumentHelper .makeElement(emailAction.getElement(), ActionSequenceDocument.COMPONENT_DEF_NAME) .addElement(ELEMENT_NAME); //$NON-NLS-1$ actionInputProvider = emailAction.actionParameterMgr; setName(attachment.getVariableName()); setContentParam(attachment);/*from w w w . j ava 2 s. c o m*/ }