public Object exec(List arguments) throws TemplateModelException { if (arguments.size() != 1) { throw new TemplateModelException("Expecting exactly one string argument here"); } if (!(node instanceof Element)) { throw new TemplateModelException("Expecting element here."); } Element elem = (Element) node; return new NodeListTM(elem.getElementsByTagName((String) arguments.get(0))); } }
/** * Retrieves the i-th object from the collection, wrapped as a TemplateModel. * @throws TemplateModelException if the index is out of bounds, or the * underlying collection is not a List. */ public TemplateModel get(int index) throws TemplateModelException { // Don't forget to keep getSupportsIndexedAccess in sync with this! if (object instanceof List) { try { return wrap(((List) object).get(index)); } catch (IndexOutOfBoundsException e) { return null; // throw new TemplateModelException("Index out of bounds: " + index); } } else { throw new TemplateModelException("Underlying collection is not a list, it's " + object.getClass().getName()); } }
throws TemplateModelException { if (arguments.size() < 1) throw new TemplateModelException("No message key was specified"); int args = arguments.size() - 1; Object[] params = new Object[args]; for (int i = 0; i < args; ++i) throw new TemplateModelException("No such key: " + key); } catch (Exception e) { throw new TemplateModelException(e.getMessage());
public TemplateModel exec(List args) throws TemplateModelException { if (args.size() != 1) { throw new TemplateModelException("Expecting exactly one arguments"); } String query = (String) args.get(0); // Now, we try to behave as if this is an XPath expression XPathSupport xps = getXPathSupport(); if (xps == null) { throw new TemplateModelException("No XPath support available"); } return xps.executeQuery(node, query); }
Object array = Array.newInstance(componentType, list.size()); recursionStops.put(list, array); try { Array.set(array, i, listItem); } catch (IllegalArgumentException e) { throw new TemplateModelException( "Failed to convert " + ClassUtil.getShortClassNameOfObject(list) + " object to " + ClassUtil.getShortClassNameOfObject(array)
/** * Retrieves the i-th element of the node list. */ public TemplateModel get(int i) throws TemplateModelException { try { return new NodeListModel(nodes.get(i), namespaces); } catch (IndexOutOfBoundsException e) { throw new TemplateModelException("Index out of bounds: " + e.getMessage()); } }
public Object exec(List arguments) throws TemplateModelException { if (arguments.size() != 2) throw new TemplateModelException("_registerNamespace(prefix, uri) requires two arguments"); registerNamespace((String) arguments.get(0), (String) arguments.get(1)); return TemplateScalarModel.EMPTY_STRING; } }
if (context != null) { if (isNodeList(context)) { int cnt = ((List) context).size(); if (cnt != 0) { throw new TemplateModelException( "Cannot perform an XPath query against a node set of " + cnt + " nodes. Expecting a single node."/* " + ERRMSG_RECOMMEND_JAXEN*/); } else { throw new TemplateModelException(ERRMSG_EMPTY_NODE_SET); throw new TemplateModelException( "Cannot perform an XPath query against a " + context.getClass().getName() + ". Expecting a single org.w3c.dom.Node."); throw new TemplateModelException(ERRMSG_EMPTY_NODE_SET); return new SimpleNumber(Double.valueOf(((XNumber) xresult).num())); throw new TemplateModelException("Cannot deal with type: " + xresult.getClass().getName()); } catch (TransformerException te) { throw new TemplateModelException(te);
@Override public Object exec(@SuppressWarnings("rawtypes") List arguments) throws TemplateModelException { @SuppressWarnings({ "unchecked", "PMD.AvoidDuplicateLiterals" }) List<TemplateModel> args = (List<TemplateModel>) arguments; if (!(args.get(0) instanceof SimpleScalar)) { throw new TemplateModelException("Not a string."); } return portal.prefix().resolve( ((SimpleScalar) args.get(0)).getAsString()).getRawPath(); } });
public Object exec(List arguments) throws TemplateModelException { if (arguments.size() != 2) { throw new TemplateModelException("_registerNamespace(prefix, uri) requires two arguments"); } registerNamespace((String) arguments.get(0), (String) arguments.get(1)); return TemplateScalarModel.EMPTY_STRING; }
if (context != null) { if (isNodeList(context)) { int cnt = ((List) context).size(); if (cnt != 0) { throw new TemplateModelException( "Cannot perform an XPath query against a node set of " + cnt + " nodes. Expecting a single node." + ERRMSG_RECOMMEND_JAXEN); } else { throw new TemplateModelException(ERRMSG_EMPTY_NODE_SET); throw new TemplateModelException( "Cannot perform an XPath query against a " + context.getClass().getName() + ". Expecting a single org.w3c.dom.Node."); throw new TemplateModelException(ERRMSG_EMPTY_NODE_SET); return new SimpleNumber(Double.valueOf(((XNumber) xresult).num())); throw new TemplateModelException("Cannot deal with type: " + xresult.getClass().getName()); } catch (TransformerException te) { throw new TemplateModelException(te);
/** * Retrieves the i-th element of the node list. */ public TemplateModel get(int i) throws TemplateModelException { try { return new NodeListModel(nodes.get(i), namespaces); } catch (IndexOutOfBoundsException e) { throw new TemplateModelException("Index out of bounds: " + e.getMessage()); } }
StringBuilder aOutputBuffer = new StringBuilder(); if ( arguments.size() < 1 ) { throw new TemplateModelException( "Need an argument to execute" ); aExecute = (String) (arguments.get(0)); throw new TemplateModelException( ioe.getMessage() );
return ""; java.io.StringWriter sw = new java.io.StringWriter(nodes.size() * 128); try { for (Iterator i = nodes.iterator(); i.hasNext(); ) { OUTPUT.output((EntityRef) node, sw); else throw new TemplateModelException(node.getClass().getName() + " is not a core JDOM class"); throw new TemplateModelException(e.getMessage());
/** * Retrieves the i-th element of the node list. */ public TemplateModel get(int i) throws TemplateModelException { try { return new NodeListModel(nodes.get(i), namespaces); } catch (IndexOutOfBoundsException e) { throw new TemplateModelException("Index out of bounds: " + e.getMessage()); } }
public Object exec(List args) throws TemplateModelException { if (args.isEmpty()) { throw new TemplateModelException("This method must have at least one argument, the name of the class to instantiate."); } String classname = args.get(0).toString(); Class cl = null; try { cl = ClassUtil.forName(classname); } catch (Exception e) { throw new TemplateModelException(e.getMessage()); } BeansWrapper bw = BeansWrapper.getDefaultInstance(); Object obj = bw.newInstance(cl, args.subList(1, args.size())); return bw.wrap(obj); } }
protected void checkArgsCount(String methodName, List arguments, int... count) throws TemplateModelException { if ((arguments == null || arguments.size() == 0) && Arrays.binarySearch(count, 0) == -1) throw new TemplateModelException(String.format("Arguments not specified for method: %s", methodName)); if (arguments != null && Arrays.binarySearch(count, arguments.size()) == -1) { throw new TemplateModelException(String.format("Incorrect arguments count: %s. Expected count: %s", arguments.size(), Arrays.toString(count))); } }
/** * Retrieves the i-th element of the node list. */ public TemplateModel get(int i) throws TemplateModelException { try { return new NodeListModel(nodes.get(i), namespaces); } catch (IndexOutOfBoundsException e) { throw new TemplateModelException("Index out of bounds: " + e.getMessage()); } }
/** * 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)); }
getFullName() + " does not support parameters."); } try { return getValue(); } catch (IOException exc) { throw new TemplateModelException( getFullName() + " failed", exc); } } private String getFullName() { return "pp.get" + getName().substring(0, 1).toUpperCase() + getName().substring(1) + "()"; }