@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';") ).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.
Constructor and Description |
---|
Directives()
Public ctor.
|
Directives(Collection<Directive> dirs)
Public ctor.
|
Directives(String text)
Public ctor.
|
Modifier and Type | Method and Description |
---|---|
<K,V> Directives |
add(Map<K,V> nodes)
Add multiple nodes and set their text values.
|
Directives |
add(String name)
Add node to all current nodes.
|
Directives |
addIf(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 |
pi(String target,
String data)
Add processing instruction.
|
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.
|
Directives |
xset(String text)
Set text content.
|
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 <K,V> Directives add(@NotNull(message="map can\'t be NULL") Map<K,V> nodes)
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");
K
- Type of keyV
- Type of valuenodes
- Names and values of nodes to addpublic Directives addIf(@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 pi(@NotNull(message="target can\'t be NULL") String target, @NotNull(message="data can\'t be NULL") String data)
target
- PI namedata
- Data to setpublic Directives set(@NotNull(message="content can\'t be NULL") String text)
text
- Text to setpublic Directives xset(@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.