/** * Evaluates an XPath expression on XML nodes in this model. * @param arguments the arguments to the method invocation. Expectes exactly * one argument - the XPath expression. * @return a new NodeListModel with nodes selected by applying the XPath * expression to this model's nodelist. * @see freemarker.template.TemplateMethodModel#exec(List) */ public Object exec(List arguments) throws TemplateModelException { if (arguments.size() != 1) { throw new TemplateModelException( "Expecting exactly one argument - an XPath expression"); } return deriveModel(navigator.applyXPath(nodes, (String) arguments.get(0), namespaces)); }
List applyXPath(List nodes, String xpathString, Object namespaces) throws TemplateModelException { XPathEx xpath = null; try { synchronized (xpathCache) { xpath = (XPathEx) xpathCache.get(xpathString); if (xpath == null) { xpath = createXPathEx(xpathString); xpathCache.put(xpathString, xpath); } } return xpath.selectNodes(nodes, (NamespaceContext) namespaces); } catch (Exception e) { throw new TemplateModelException("Could not evaulate XPath expression " + xpathString, e); } }
/** * Returns the string representation of the wrapped nodes. String objects in * the nodelist are rendered as-is (with no XML escaping applied). All other * nodes are rendered in the default XML serialization format ("plain XML"). * This makes the model quite suited for use as an XML-transformation tool. * @return the string representation of the wrapped nodes. String objects * in the nodelist are rendered as-is (with no XML escaping applied). All * other nodes are rendered in the default XML serialization format ("plain * XML"). * @see freemarker.template.TemplateScalarModel#getAsString() */ public String getAsString() throws TemplateModelException { StringWriter sw = new StringWriter(size() * 128); for (Iterator iter = nodes.iterator(); iter.hasNext(); ) { Object o = iter.next(); if (o instanceof String) { sw.write((String) o); } else { navigator.getAsString(o, sw); } } return sw.toString(); }
NodeOperator op = navigator.getOperator(key); String localName = null; String namespaceUri = ""; op = navigator.getAttributeOperator(); localName = localName.substring(1); } else { op = navigator.getChildrenOperator();
public void process(Object node, String localName, String namespaceUri, List result) { getDescendants(node, result); } }
public void process(Object node, String localName, String namespaceUri, List result) { Object document = getDocument(node); if (document != null) { result.add(document); } } }
public void process(Object node, String localName, String namespaceUri, List result) { getAttributes(node, localName, namespaceUri, result); } }
public void process(Object node, String localName, String namespaceUri, List result) { getChildren(node, localName, namespaceUri, result); } }
public void process(Object node, String localName, String namespaceUri, List result) { getContent(node, result); } }
NodeOperator op = navigator.getOperator(key); String localName = null; String namespaceUri = ""; op = navigator.getAttributeOperator(); localName = localName.substring(1); } else { op = navigator.getChildrenOperator();
public void process(Object node, String localName, String namespaceUri, List result) { result.add(node); getDescendants(node, result); } }
public void process(Object node, String localName, String namespaceUri, List result) { Object document = getDocument(node); if(document != null) { result.add(document); } } }
public void process(Object node, String localName, String namespaceUri, List result) { getAttributes(node, localName, namespaceUri, result); } }
public void process(Object node, String localName, String namespaceUri, List result) { getChildren(node, localName, namespaceUri, result); } }
public void process(Object node, String localName, String namespaceUri, List result) { getContent(node, result); } }
NodeOperator op = navigator.getOperator(key); String localName = null; String namespaceUri = ""; op = navigator.getAttributeOperator(); localName = localName.substring(1); op = navigator.getChildrenOperator();
public void process(Object node, String localName, String namespaceUri, List result) { getDescendants(node, result); } }
public void process(Object node, String localName, String namespaceUri, List result) { Object document = getDocument(node); if (document != null) { result.add(document); } } }
public void process(Object node, String localName, String namespaceUri, List result) { getAttributes(node, localName, namespaceUri, result); } }
public void process(Object node, String localName, String namespaceUri, List result) { getChildren(node, localName, namespaceUri, result); } }