public class Utils extends Object implements SystemEventListener
| Modifier and Type | Field and Description |
|---|---|
protected static Cache<String,XPathExpression> |
xpathCache |
protected static XPathFactory |
xpathFactory |
| Constructor and Description |
|---|
Utils() |
| Modifier and Type | Method and Description |
|---|---|
static Collection<Node> |
appendNodeList(NodeList list,
Node dest)
This method clones, imports and places all nodes in the list.
|
static void |
copyAllAttributes(Node source,
Node dest)
Copies all attributes from one node to the other.
|
static void |
copyAllAttributes(Node source,
Node dest,
List<String> except)
Same as above, but now you can supply a Vector with names which should NOT be copied.
|
static Node |
createAndAppendNode(Node parentnode,
String nodename,
String nodevalue)
This method creates a new node, places text and attaches it to the parent.
|
static Document |
emptyDocument()
This method returns an empty XMLDocument.
|
protected static String |
evaluateXPath(String xpath,
Node contextNode) |
protected static Object |
evaluateXPath(String xpath,
Node contextNode,
QName returnType) |
static String |
fillInParams(String text,
Map<String,?> params)
This method fills in params in a string.
|
static String |
getAttribute(Node node,
String name)
Gets an attribute of an node.
|
static String |
getAttribute(Node node,
String name,
String defaultvalue)
Gets an attribute of an node.
|
static DocumentBuilder |
getDocumentBuilder(boolean validate)
This method returns a new instance of a DocumentBuilder.
|
protected static XPathExpression |
getExpression(String xpath) |
static String |
getSerializedXML(Node node)
Serialize a node to a string, and return the result.
|
static String |
getText(Node node)
Returns the text value of the given node
|
static String |
getText(Node node,
String defaultvalue)
Returns the text value of the given node.
|
static String |
getText(Node node,
String defaultvalue,
Map<String,?> params)
Returns the text value of the given node.
|
int |
getWeight() |
static String |
getXML(Node node)
Serialize a node and returns the resulting String.
|
static String |
getXML(NodeList nodeList)
Serialize a nodelist and returns the resulting String (for debugging).
|
static boolean |
isEmptyNodeList(NodeList list)
Is nodelist empty
|
static boolean |
isNotEmptyNodeList(NodeList list)
Is nodelist not empty
|
static Document |
loadXMLFile(URL file)
This method can load a xml file and returns the resulting document.
|
static void |
main(String[] argv) |
static String |
multipleReplace(String text,
String searchfor,
String replacewith)
replaces single or multiple occurences of a string in a given source string.
|
void |
notify(SystemEvent se) |
static Document |
parseXML(String xml)
With this method you can parse a xml string and get the resulting Document.
|
static void |
printXML(Node node,
Writer writer)
Serialize a node to the given writer.
|
static NodeList |
selectNodeList(Node contextNode,
String xpath)
This method selects a multiple nodes using the given contextNode and xpath.
|
static Node |
selectSingleNode(Node contextNode,
String xpath)
This method selects a single node using the given contextNode and xpath.
|
static String |
selectSingleNodeText(Node node,
String xpath,
String defaultvalue)
Selects a single node using the given xpath and uses the given node a a starting context and returns the textnode found.
|
static String |
selectSingleNodeText(Node node,
String xpath,
String defaultvalue,
Cloud cloud)
Selects a single node using the given xpath and uses the given node a a starting context and returns the textnode found.
|
static void |
setAttribute(Node node,
String name,
String value)
Sets an attribute of a specific node.
|
protected static void |
setStylesheetParams(Transformer transformer,
Map<String,?> params,
Cloud cloud)
This method can set the stylesheetparams for a transformer.
|
static void |
storeText(Node node,
String text)
Same as above, but without the params.
|
static void |
storeText(Node node,
String text,
Map<String,?> params)
This method stores text in a node.
|
static String |
stringFormatted(Node node)
For debugging purposes.
|
static int |
tagNodeList(NodeList list,
String name,
String pre)
This method tags all nodes in the nodelist.
|
static int |
tagNodeList(NodeList list,
String name,
String pre,
int start)
Same as above, but now you can supply a startnumber.
|
static String |
transformAttribute(Node context,
String attributeTemplate)
transforms an attribute.
|
static String |
transformAttribute(Node context,
String attributeTemplate,
boolean plainTextIsPath)
same as above, but now you can supply if the given attributeTemplate is already a xpath or not.
|
static String |
transformAttribute(Node context,
String attributeTemplate,
boolean plainTextIsXpath,
Map<String,?> params)
Executes an attribute template.
|
static Node |
transformNode(Node node,
String xslFile,
URIResolver uri,
Writer out,
Map<String,?> params,
Cloud cloud) |
static Node |
transformNode(Node node,
URL xslFile,
URIResolver uri)
same as above, but now the result is returned in a new Node and some less params.
|
static Node |
transformNode(Node node,
URL xslFile,
URIResolver uri,
Map<String,?> params,
Cloud cloud)
same as above, but now you can supply a params hashtable.
|
static void |
transformNode(Node node,
URL xslFile,
URIResolver uri,
Result result,
Map<String,?> params,
Cloud cloud)
This method does a standard XSL(T) transform on a node as a base context node and sends it to the given Result result.
|
static void |
transformNode(Node node,
URL xslFile,
URIResolver uri,
Writer out)
same as above, but now the result is written to the writer.
|
static void |
transformNode(Node node,
URL xslFile,
URIResolver uri,
Writer out,
Map<String,?> params,
Cloud cloud)
same as above, but now the result is written to the writer and you can use params.
|
protected static final XPathFactory xpathFactory
protected static final Cache<String,XPathExpression> xpathCache
public void notify(SystemEvent se)
notify in interface SystemEventListenerpublic int getWeight()
getWeight in interface WeightEventListenerpublic static DocumentBuilder getDocumentBuilder(boolean validate)
public static Document emptyDocument()
public static Document loadXMLFile(URL file) throws WizardException
file - the file to be loaded.WizardException - if the document is invalidpublic static Document parseXML(String xml) throws WizardException
xml - The xml string to be parsed. Note that you should supply xml for a valid document (one root node, etc)WizardException - if something went wrongpublic static void printXML(Node node, Writer writer)
node - The node to serializewriter - The writer where the stream should be written to.public static String getSerializedXML(Node node)
node - The node to serializepublic static String getXML(Node node)
node - The node to serializepublic static String getXML(NodeList nodeList)
public static void setAttribute(Node node, String name, String value)
node - The node of which thepublic static String getAttribute(Node node, String name)
node - the node to get the attribute fromname - the attributename requestedpublic static String getAttribute(Node node, String name, String defaultvalue)
node - the node to get the attribute fromname - the attributename requesteddefaultvalue - the defaultvalue what should be returned if attribute was not found.public static String getText(Node node)
node - the node where you want the text from.public static String getText(Node node, String defaultvalue, Map<String,?> params)
node - the node where you want the text from.defaultvalue - of no text is found, this defaultvalue will be returnedparams - params to be used. eg.: $username will be replaced by the values in the hashtable, if a 'username' key is in the hashtable.public static String getText(Node node, String defaultvalue)
node - the node where you want the text from.defaultvalue - if no text is found, this defaultvalue will be returnedpublic static String selectSingleNodeText(Node node, String xpath, String defaultvalue)
node - the contextnode to start the xpath from.xpath - the xpath which should be fired.defaultvalue - this value will be returned when no node is found using the xpath.public static String selectSingleNodeText(Node node, String xpath, String defaultvalue, Cloud cloud)
node - the contextnode to start the xpath from.xpath - the xpath which should be fired.defaultvalue - this value will be returned when no node is found using the xpath.cloud - the cloud whose locale is to be used for selecting language-specific textspublic static void storeText(Node node, String text, Map<String,?> params)
node - the parentnode on which a textnode should be created or overwritten.text - The text what should be placed in the textnode.params - optional params which should be used in a replace action.public static void storeText(Node node, String text)
public static Collection<Node> appendNodeList(NodeList list, Node dest)
public static Node createAndAppendNode(Node parentnode, String nodename, String nodevalue)
parentnode - Place where new node should be appendednodename - the name of the new nodenodevalue - the new nodevaluepublic static int tagNodeList(NodeList list, String name, String pre)
list - the nodelistname - the name of the tagspre - the prefix what should be used in the tag-valuespublic static int tagNodeList(NodeList list, String name, String pre, int start)
public static void copyAllAttributes(Node source, Node dest)
source - One nodedest - The other nodepublic static void copyAllAttributes(Node source, Node dest, List<String> except)
protected static void setStylesheetParams(Transformer transformer, Map<String,?> params, Cloud cloud)
transformer - The transformer.params - The params to be placed. Standard name/value pairs.public static void transformNode(Node node, URL xslFile, URIResolver uri, Result result, Map<String,?> params, Cloud cloud) throws TransformerException
node - the base context node to run the xsl(t) against.xslFile - the xsl fileresult - The place where to put the result of the transformationparams - Optional params.TransformerExceptionpublic static String stringFormatted(Node node)
public static Node transformNode(Node node, URL xslFile, URIResolver uri) throws TransformerException
node - the base context node.xslFile - the xslFile.TransformerExceptionpublic static Node transformNode(Node node, URL xslFile, URIResolver uri, Map<String,?> params, Cloud cloud) throws TransformerException
TransformerExceptionpublic static void transformNode(Node node, URL xslFile, URIResolver uri, Writer out) throws TransformerException
TransformerExceptionpublic static void transformNode(Node node, URL xslFile, URIResolver uri, Writer out, Map<String,?> params, Cloud cloud) throws TransformerException
TransformerExceptionpublic static Node transformNode(Node node, String xslFile, URIResolver uri, Writer out, Map<String,?> params, Cloud cloud) throws TransformerException
TransformerExceptionpublic static String transformAttribute(Node context, String attributeTemplate)
context - the contextnodeattributeTemplate - the template to evaluate.public static String transformAttribute(Node context, String attributeTemplate, boolean plainTextIsPath)
public static String transformAttribute(Node context, String attributeTemplate, boolean plainTextIsXpath, Map<String,?> params)
context - the Node on which any xpaths are fired.attributeTemplate - the String containting an attribute template.plainTextIsXpath - true means that if the template doesn't contain
any curly braces, the template is assumed to be a valid xpath (instead
of plain data). Else the template is assumed to be a valid attribute template.protected static XPathExpression getExpression(String xpath)
protected static Object evaluateXPath(String xpath, Node contextNode, QName returnType)
protected static String evaluateXPath(String xpath, Node contextNode)
public static Node selectSingleNode(Node contextNode, String xpath)
contextNode - xpath - public static NodeList selectNodeList(Node contextNode, String xpath)
contextNode - xpath - public static String fillInParams(String text, Map<String,?> params)
text - the source text to be usedparams - the table with params (name/value pairs)public static String multipleReplace(String text, String searchfor, String replacewith)
text - the source text (the haystack)searchfor - the needle. the this we're looking forreplacewith - the string which should be placed.public static boolean isEmptyNodeList(NodeList list)
list - NodeListtrue when emptypublic static boolean isNotEmptyNodeList(NodeList list)
list - NodeListtrue when not emptypublic static void main(String[] argv)
MMBase 1.9-SNAPSHOT - ${javadoctimestamp}