/** <p>Constructor for the CopyEmitter.</p> * * @param namePool The name pool to use for constructing elements and attributes. */ public CopyEmitter(Controller controller, NamePool namePool) { rtf = new FragmentValue(controller); rtfEmitter = rtf.getEmitter(); this.namePool = namePool; }
public static NodeInfo getNodeInfo(Object contextNode) { return ((SingletonNodeSet)contextNode).getFirst(); }
public boolean test(Node context, String test) throws TransformerException { NodeInfo cNode = (NodeInfo) context; Expression exp = Expression.make(test, new StandaloneContext()); Context ctx = new Context(); ctx.setContextNode(cNode); ctx.setPosition(1); ctx.setLast(1); return exp.evaluateAsBoolean(ctx); }
try { if(arg instanceof FragmentValue) { ((FragmentValue)arg).copy(controller.getOutputter()); } else if(arg instanceof TextFragmentValue) { ((TextFragmentValue)arg).copy(controller.getOutputter()); } else if(arg instanceof NodeSetValue) { NodeEnumeration enm = ((NodeSetValue)arg).enumerate(context, true); while(enm.hasMoreElements()) { NodeInfo node = enm.nextElement(); controller.getOutputter().writeContent(((Value)arg).asString()); } else { return arg;
public List<Node> select(Node context, String xpath) throws TransformerException { List<Node> result; result = new ArrayList<Node>(); NodeInfo cNode = (NodeInfo) context; Expression exp = Expression.make(xpath, new StandaloneContext()); Context ctx = new Context(); ctx.setContextNode(cNode); ctx.setPosition(1); ctx.setLast(1); NodeSetValue nodeSet = exp.evaluateAsNodeSet(ctx); NodeEnumeration enm = nodeSet.enumerate(); while (enm.hasMoreElements()) { result.add((Node)enm.nextElement()); } return result; }
/** * <p>Find the string value of a stylesheet variable or parameter</p> * * <p>Returns the string value of <code>varName</code> in the current * <code>context</code>. Returns the empty string if the variable is * not defined.</p> * * @param context The current stylesheet context * @param varName The name of the variable (without the dollar sign) * * @return The string value of the variable */ protected static String getVariable(Context context, String varName) throws TransformerException { Value variable = null; String varString = null; try { variable = Extensions.evaluate(context, "$" + varName); varString = variable.asString(); return varString; } catch (IllegalArgumentException e) { System.out.println("Undefined variable: " + varName); return ""; } }
public static String getLocation(Context context) { StringBuilder sb = new StringBuilder(); NodeInfo currentNode = context.getCurrentNodeInfo(); if(currentNode != null) { sb.append(currentNode.getSystemId() + ":" + currentNode.getParent().getParent().getLineNumber()); } StaticContext staticContext = context.getStaticContext(); sb.append(" "+staticContext.getSystemId()+ ":"+staticContext.getLineNumber()); return sb.toString(); }
public Value getIncludeParam(Context parentContext, String name) throws Exception { try { if(!includeContextStack.isEmpty()) { IncludeContext includeContext = includeContextStack.peek(); Value value = includeContext.getIncludePartParam(name); if(value != null) { return value; } } throw new XPathException("Include parameter '" + name + "' not found."); } catch (Exception x) { ExtensionFunctionUtils.setExtensionFunctionError(x); throw x; } }
public String getStylesheetSystemId() { StringValue value = ((StringValue)context.getController().getParameter("__stylesheet")); if(value != null) { return value.asString(); } return null; }
value = evaluate(context, select); } else { value = new SingletonNodeSet((NodeInfo)elem); value = evaluate(context, select); } else { value = new SingletonNodeSet((NodeInfo)elem);
String href = hrefExpr.evaluateAsString(context); String encoding = encodingExpr.evaluateAsString(context);
/** * <p>Find the string value of a stylesheet variable or parameter</p> * * <p>Returns the string value of <code>varName</code> in the current * <code>context</code>. Returns the empty string if the variable is * not defined.</p> * * @param context The current stylesheet context * @param varName The name of the variable (without the dollar sign) * * @return The string value of the variable */ protected static String getVariable(Context context, String varName) { Value variable = null; String varString = null; try { variable = Extensions.evaluate(context, "$" + varName); varString = variable.asString(); return varString; } catch (TransformerException te) { System.out.println("Undefined variable: " + varName); return ""; } catch (IllegalArgumentException iae) { System.out.println("Undefined variable: " + varName); return ""; } }
public static String getLocation(Context context) { StringBuilder sb = new StringBuilder(); StaticContext staticContext = context.getStaticContext(); if(staticContext != null) { String systemId = staticContext.getSystemId(); if(systemId != null && systemId.length() > 0) { sb.append(systemId).append(":").append(staticContext.getLineNumber()); } } NodeInfo current = context.getCurrentNodeInfo(); if(current != null) { String systemId = current.getSystemId(); if(systemId != null && systemId.length() > 0) { if(sb.length() > 0) { sb.append("|"); } sb.append(systemId).append(":").append(current.getLineNumber()); } } return sb.toString(); }
namePool, foStylesheet); rtf.replay(ulEmitter); tryAgain = ulEmitter.tryAgain(); rtf = (FragmentValue) ulEmitter.getResultTreeFragment();
public static String formatDate(String dateTime, String datePattern, String timeZone, String dateLocale) throws XPathException { try { SimpleDateFormat format; if(dateLocale != null && !dateLocale.isEmpty()) { Locale locale = LocaleUtils.getLocale(dateLocale); format = new SimpleDateFormat(datePattern, locale); } else { format = new SimpleDateFormat(datePattern); } if(timeZone != null && !timeZone.isEmpty()) { format.setTimeZone(TimeZone.getTimeZone(timeZone)); } return format.format(new Date(Long.parseLong(dateTime))); } catch (Exception err) { ExtensionFunctionUtils.setExtensionFunctionError(err); throw new XPathException(err); } }
/** * <p>Find the string value of a stylesheet variable or parameter</p> * * <p>Returns the string value of <code>varName</code> in the current * <code>context</code>. Returns the empty string if the variable is * not defined.</p> * * @param context The current stylesheet context * @param varName The name of the variable (without the dollar sign) * * @return The string value of the variable */ protected static String getVariable(Context context, String varName) { Value variable = null; String varString = null; try { variable = Extensions.evaluate(context, "$" + varName); varString = variable.asString(); return varString; } catch (TransformerException te) { System.out.println("Undefined variable: " + varName); return ""; } catch (IllegalArgumentException iae) { System.out.println("Undefined variable: " + varName); return ""; } }
public static NodeEnumeration tokenize(Context context, String str, String pattern) throws XPathException { try { Builder builder = context.getController().makeBuilder(); NamePool pool = context.getController().getNamePool(); builder.setNamePool(pool); builder.startDocument(); int name = pool.allocate("", "", "token"); AttributeCollection emptyAtts = new AttributeCollection(pool); String[] tokens = str.split(pattern); for(String token: tokens) { builder.startElement(name, emptyAtts, new int[0], 0); builder.characters(token.toCharArray(), 0, token.length()); builder.endElement(name); } builder.endDocument(); DocumentInfo doc = builder.getCurrentDocument(); return doc.getEnumeration(Axis.CHILD, AnyNodeTest.getInstance()); } catch (Exception err) { ExtensionFunctionUtils.setExtensionFunctionError(err); throw new XPathException(err); } }
fCallout); cEmitter.setupCallouts(areaspecNodeList); rtf.replay(cEmitter); return cEmitter.getResultTreeFragment(); } catch (TransformerException e) {