Class Directives
Directives, instantiable from String.
 For example, to fetch directives from a string and apply to the DOM document:
 Document dom = DocumentBuilderFactory.newInstance()
   .newDocumentBuilder().newDocument();
 dom.appendChild(dom.createElement("root"));
 new Xembler(
   new Directives("XPATH 'root'; ADD 'employee';")
 ).apply(dom);
 Directives can be used as a builder of Xembly script:
 
 Document dom = DocumentBuilderFactory.newInstance()
   .newDocumentBuilder().newDocument();
 dom.appendChild(dom.createElement("root"));
 new Xembler(
   new Directives()
     .xpath("/root")
     .addIf("employees")
     .add("employee")
     .attr("id", 6564)
     .up()
     .xpath("employee[@id='100']")
     .strict(1)
     .remove()
 ).apply(dom);
 The class is mutable and thread-safe.
- Since:
- 0.1
- Suppressed Checkstyle violations:
- ClassFanOutComplexity (500 lines)
- 
Constructor SummaryConstructorsConstructorDescriptionPublic ctor.Directives(Iterable<Directive> dirs) Public ctor.Directives(String text) Public ctor.
- 
Method SummaryModifier and TypeMethodDescriptionAdd node to all current nodes.<K,V> Directives Add multiple nodes and set their text values.Add node if it's absent.Append all directives.Appends thenode.Set attribute.Set CDATA section.Add an XML comment.Create a collection of directives, which can create a copy of provided node.iterator()Add processing instruction.pop()Pop cursor to stack and replace current cursor with it.push()Push current cursor to stack.remove()Remove all current nodes and move cursor to their parents.Set text content.strict(int number) Check that there is exactly this number of current nodes.toString()up()Go one node/level up.Set attribute.Go to XPath.Set text content.Methods inherited from class java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface java.lang.IterableforEach, spliterator
- 
Constructor Details- 
Directivespublic Directives()Public ctor.
- 
DirectivesPublic ctor.- Parameters:
- text- Xembly script
 
- 
DirectivesPublic ctor.- Parameters:
- dirs- Directives
 
 
- 
- 
Method Details- 
toString
- 
iterator
- 
copyOfCreate a collection of directives, which can create a copy of provided node.For example, you already have a node in an XML document, which you'd like to add to another XML document: Document target = parse("<root/>"); Node node = parse("<user name='Jeffrey'/>"); new Xembler( new Directives() .xpath("/*") .add("jeff") .append(Directives.copyOf(node)) ).apply(target); assert print(target).equals( "<root><jeff name='Jeffrey'></root>" );- Parameters:
- node- Node to analyze
- Returns:
- Collection of directives
- Since:
- 0.13
- Suppressed Checkstyle violations:
- CyclomaticComplexity (50 lines)
 
- 
appendAppend all directives.- Parameters:
- dirs- Directives to append
- Returns:
- This object
- Since:
- 0.11
 
- 
appendAppends thenode.- Parameters:
- node- The node to append
- Returns:
- This object
- Since:
- 0.23
- See Also:
 
- 
addAdd node to all current nodes.- Parameters:
- name- Name of the node to add
- Returns:
- This object
- Since:
- 0.5
 
- 
addAdd multiple nodes and set their text values.Every pair in the provided map will be treated as a new node name and value. It's a convenient utility method that simplifies the process of adding a collection of nodes with pre-set values. For example: new Directives() .add("first", "hello, world!") .add( new ArrayMap<String, Object>() .with("alpha", 1) .with("beta", "2") .with("gamma", new Date()) ) .add("second");If a value provided contains illegal XML characters, a runtime exception will be thrown. To avoid this, it is recommended to use Xembler.escape(String).- Type Parameters:
- K- Type of key
- V- Type of value
- Parameters:
- nodes- Names and values of nodes to add
- Returns:
- This object
- Since:
- 0.8
 
- 
addIfAdd node if it's absent.- Parameters:
- name- Name of the node to add
- Returns:
- This object
- Since:
- 0.5
 
- 
removeRemove all current nodes and move cursor to their parents.- Returns:
- This object
- Since:
- 0.5
 
- 
attrSet attribute.If it's necessary to add an attribute with a namespace, append the namespace to the name of the attribute, separating them with a space. If a value provided contains illegal XML characters, a runtime exception will be thrown. To avoid this, it is recommended to use Xembler.escape(String).- Parameters:
- name- Name of the attribute
- value- Value to set
- Returns:
- This object
- Since:
- 0.5
 
- 
piAdd processing instruction.If a value provided contains illegal XML characters, a runtime exception will be thrown. To avoid this, it is recommended to use Xembler.escape(String).- Parameters:
- target- PI name
- data- Data to set
- Returns:
- This object
- Since:
- 0.9
- Suppressed Checkstyle violations:
- MethodName (3 lines)
 
- 
setSet text content.If a value provided contains illegal XML characters, a runtime exception will be thrown. To avoid this, it is recommended to use Xembler.escape(String).- Parameters:
- text- Text to set
- Returns:
- This object
- Since:
- 0.5
 
- 
xsetSet text content.- Parameters:
- text- Text to set
- Returns:
- This object
- Since:
- 0.7
 
- 
xattrSet attribute.- Parameters:
- attr- Attribute name
- text- Text to set
- Returns:
- This object
- Since:
- 0.28
 
- 
upGo one node/level up.- Returns:
- This object
- Since:
- 0.5
- Suppressed Checkstyle violations:
- MethodName (3 lines)
 
- 
xpathGo to XPath.- Parameters:
- path- Path to go to
- Returns:
- This object
- Since:
- 0.5
 
- 
strictCheck that there is exactly this number of current nodes.- Parameters:
- number- Number of expected nodes
- Returns:
- This object
- Since:
- 0.5
 
- 
pushPush current cursor to stack.- Returns:
- This object
- Since:
- 0.16
 
- 
popPop cursor to stack and replace current cursor with it.- Returns:
- This object
- Since:
- 0.16
 
- 
cdataSet CDATA section.If a value provided contains illegal XML characters, a runtime exception will be thrown. To avoid this, it is recommended to use Xembler.escape(String).- Parameters:
- text- Text to set
- Returns:
- This object
- Since:
- 0.17
 
- 
commentAdd an XML comment.If a value provided contains illegal XML characters, a runtime exception will be thrown. To avoid this, it is recommended to use Xembler.escape(String).- Parameters:
- text- Text to set
- Returns:
- This object
- Since:
- 0.23
 
 
-