/** access the name of the class of the context node - useful for finding nodes by class * e.g. //*[functions:type() = 'org.astrogrid.Blob'] * */ public static String type(ExpressionContext ctxt) { Pointer ptr = ctxt.getContextNodePointer(); if (ptr == null) { return "null"; } Object candidate = ctxt.getContextNodePointer().getValue(); if (candidate == null) { return "null"; } return candidate.getClass().getName(); }
/** * Get the current node. * * @param context * the xpath context * @return the current node, null if no current node */ public static Object current(ExpressionContext context) { Pointer pointer = context.getContextNodePointer(); if (pointer == null) { return null; } return pointer.getValue(); }
/** * Get the current node. * * @param context * the xpath context * @return the current node, null if no current node */ public static Object current(ExpressionContext context) { Pointer pointer = context.getContextNodePointer(); if (pointer == null) { return null; } return pointer.getValue(); }
/** * Check if a value matches a java class. * * @param context * the xpath context * @param className * the class name * @param exact * false to consider inheritance, true to only do exact class * match. * @return true if matches, false if not match */ public static boolean matchClass(ExpressionContext context, String className, boolean exact) { Pointer pointer = context.getContextNodePointer(); if (pointer == null) { return false; } Object value = pointer.getValue(); if (value == null) { return false; } if (exact) { return ReflectUtils.loadClassStrict(className, null).equals(value.getClass()); } else { return ReflectUtils.loadClassStrict(className, null).isInstance(value); } }
/** * Check if a value matches a java class. * * @param context * the xpath context * @param className * the class name * @param exact * false to consider inheritance, true to only do exact class * match. * @return true if matches, false if not match */ public static boolean matchClass(ExpressionContext context, String className, boolean exact) { Pointer pointer = context.getContextNodePointer(); if (pointer == null) { return false; } Object value = pointer.getValue(); if (value == null) { return false; } if (exact) { return ReflectUtils.loadClassStrict(className, null).equals(value.getClass()); } else { return ReflectUtils.loadClassStrict(className, null).isInstance(value); } }
/** returns true if context node is equal to variable target. * i.e. $target.equals(.) * @param ctxt * @return */ public static boolean matchTarget(ExpressionContext ctxt) { Object candidate = ctxt.getContextNodePointer().getValue(); Object target = ctxt.getJXPathContext().getVariables().getVariable("target"); return target.equals(candidate); }
/** * Get the id of the current node * * @param obj * @return */ public static String findId(ExpressionContext context) { Pointer pointer = context.getContextNodePointer(); if (pointer == null) { return null; } Object obj = pointer.getValue(); return Context.getCurrentContext().findConstId(obj, true, true); } }
/** * Get the id of the current node * * @param obj * @return */ public static String findId(ExpressionContext context) { Pointer pointer = context.getContextNodePointer(); if (pointer == null) { return null; } Object obj = pointer.getValue(); return Context.getCurrentContext().findConstId(obj, true, true); } }
/** * Check if a value is in a collection. * * @param context * the xpath context * @param collection * comma delimited string or collection * @return true if the comma delimited string is in */ public static boolean in(ExpressionContext context, Object collection) { if (collection == null) { return false; } Pointer pointer = context.getContextNodePointer(); if (pointer == null) { return false; } Object value = pointer.getValue(); if (value == null) { return false; } if (collection instanceof Collection) { return UtilFunctions.in(value, (Collection) collection); } else { return UtilFunctions.in(value, UtilFunctions.breakString(collection.toString(), null)); } }
/** * Check if a value is in a collection. * * @param context * the xpath context * @param collection * comma delimited string or collection * @return true if the comma delimited string is in */ public static boolean in(ExpressionContext context, Object collection) { if (collection == null) { return false; } Pointer pointer = context.getContextNodePointer(); if (pointer == null) { return false; } Object value = pointer.getValue(); if (value == null) { return false; } if (collection instanceof Collection) { return UtilFunctions.in(value, (Collection) collection); } else { return UtilFunctions.in(value, UtilFunctions.breakString(collection.toString(), null)); } }