@Loggable(value=1) public final class Directives extends AbstractCollection<Directive>
Directive
s, 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';") ).exec(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") .addIfAbsent("employees") .add("employee") .attr("id", 6564) .up() .xpath("employee[@id='100']") .strict(1) .remove() ).exec(dom);
The class is mutable and thread-safe.
Constructor and Description |
---|
Directives()
Public ctor.
|
Directives(Collection<Directive> dirs)
Public ctor.
|
Directives(String text)
Public ctor.
|
Modifier and Type | Method and Description |
---|---|
Directives |
add(String name)
Add node to all current nodes.
|
Directives |
addIfAbsent(String name)
Add node if it's absent.
|
Directives |
append(Collection<Directive> list)
Add more directives to the end of the list.
|
Directives |
attr(String name,
String value)
Set attribute.
|
Iterator<Directive> |
iterator() |
Directives |
remove()
Remove all current nodes and move cursor to their parents.
|
Directives |
set(String text)
Set text content.
|
int |
size() |
Directives |
strict(int number)
Check that there is exactly this number of current nodes.
|
String |
toString() |
Directives |
up()
Go one node/level up.
|
Directives |
xpath(String path)
Go to XPath.
|
add, addAll, clear, contains, containsAll, isEmpty, remove, removeAll, retainAll, toArray, toArray
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
equals, hashCode
public Directives()
public Directives(@NotNull(message="xembly script can\'t be NULL") String text) throws XemblySyntaxException
text
- Xembly scriptXemblySyntaxException
- If syntax is brokenpublic Directives(@NotNull(message="directives can\'t be NULL") Collection<Directive> dirs)
dirs
- Directivespublic String toString()
toString
in class AbstractCollection<Directive>
public Iterator<Directive> iterator()
iterator
in interface Iterable<Directive>
iterator
in interface Collection<Directive>
iterator
in class AbstractCollection<Directive>
public int size()
size
in interface Collection<Directive>
size
in class AbstractCollection<Directive>
public Directives append(Collection<Directive> list)
list
- List of thempublic Directives add(@NotNull(message="name can\'t be NULL") String name)
name
- Name of the node to addpublic Directives addIfAbsent(@NotNull(message="name can\'t be NULL") String name)
name
- Name of the node to addpublic Directives remove()
public Directives attr(@NotNull(message="attr name can\'t be NULL") String name, @NotNull(message="value can\'t be NULL") String value)
name
- Name of the attributevalue
- Value to setpublic Directives set(@NotNull(message="content can\'t be NULL") String text)
text
- Text to setpublic Directives up()
public Directives xpath(@NotNull(message="xpath can\'t be NULL") String path)
path
- Path to go topublic Directives strict(@NotNull(message="number can\'t be NULL") int number)
number
- Number of expected nodesCopyright © 2013 Xembly. All rights reserved.