Author: cbrisson Date: Mon Oct 1 12:22:05 2018 New Revision: 1842484 URL: http://svn.apache.org/viewvc?rev=1842484&view=rev Log: [tools] javadoc fixes
Modified: velocity/tools/trunk/velocity-tools-generic/src/main/java/org/apache/velocity/tools/ClassUtils.java velocity/tools/trunk/velocity-tools-generic/src/main/java/org/apache/velocity/tools/ToolContext.java velocity/tools/trunk/velocity-tools-generic/src/main/java/org/apache/velocity/tools/ToolInfo.java velocity/tools/trunk/velocity-tools-generic/src/main/java/org/apache/velocity/tools/ToolManager.java velocity/tools/trunk/velocity-tools-generic/src/main/java/org/apache/velocity/tools/XmlUtils.java velocity/tools/trunk/velocity-tools-generic/src/main/java/org/apache/velocity/tools/generic/Alternator.java velocity/tools/trunk/velocity-tools-generic/src/main/java/org/apache/velocity/tools/generic/AlternatorTool.java velocity/tools/trunk/velocity-tools-generic/src/main/java/org/apache/velocity/tools/generic/ClassTool.java velocity/tools/trunk/velocity-tools-generic/src/main/java/org/apache/velocity/tools/generic/CollectionTool.java velocity/tools/trunk/velocity-tools-generic/src/main/java/org/apache/velocity/tools/generic/SafeConfig.java Modified: velocity/tools/trunk/velocity-tools-generic/src/main/java/org/apache/velocity/tools/ClassUtils.java URL: http://svn.apache.org/viewvc/velocity/tools/trunk/velocity-tools-generic/src/main/java/org/apache/velocity/tools/ClassUtils.java?rev=1842484&r1=1842483&r2=1842484&view=diff ============================================================================== --- velocity/tools/trunk/velocity-tools-generic/src/main/java/org/apache/velocity/tools/ClassUtils.java (original) +++ velocity/tools/trunk/velocity-tools-generic/src/main/java/org/apache/velocity/tools/ClassUtils.java Mon Oct 1 12:22:05 2018 @@ -394,6 +394,9 @@ public class ClassUtils * This method is almost entirely copied from Engine's UberspectImpl class. * @param obj the target obj * @return an iterator over the content of obj, or null if not found + * @throws NoSuchMethodException if no iterator() method + * @throws IllegalAccessException if iterator() method not callable + * @throws InvocationTargetException if iterator() method throwed */ public static Iterator getIterator(Object obj) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException Modified: velocity/tools/trunk/velocity-tools-generic/src/main/java/org/apache/velocity/tools/ToolContext.java URL: http://svn.apache.org/viewvc/velocity/tools/trunk/velocity-tools-generic/src/main/java/org/apache/velocity/tools/ToolContext.java?rev=1842484&r1=1842483&r2=1842484&view=diff ============================================================================== --- velocity/tools/trunk/velocity-tools-generic/src/main/java/org/apache/velocity/tools/ToolContext.java (original) +++ velocity/tools/trunk/velocity-tools-generic/src/main/java/org/apache/velocity/tools/ToolContext.java Mon Oct 1 12:22:05 2018 @@ -65,6 +65,7 @@ public class ToolContext implements Cont /** * Creates an instance that automatically has the specified * VelocityEngine and related tool properties set. + * @param engine VelocityEngine instance */ public ToolContext(VelocityEngine engine) { @@ -75,6 +76,7 @@ public class ToolContext implements Cont /** * Creates an instance starting with the specified tool properties. + * @param toolProps tools properties */ public ToolContext(Map<String,Object> toolProps) { @@ -91,6 +93,7 @@ public class ToolContext implements Cont * The default value is {@code true}. Set this to false if you want to * ensure that your tool references are never replaced within the course * of a template. + * @param overwrite flag value */ public void setUserCanOverwriteTools(boolean overwrite) { @@ -99,6 +102,7 @@ public class ToolContext implements Cont /** * Default is {@code true}. + * @return flag value * @see #setUserCanOverwriteTools */ public boolean getUserCanOverwriteTools() @@ -115,6 +119,7 @@ public class ToolContext implements Cont * Returns a {@link Map} of all tools available to this * context. NOTE: this is not a cheap operation as it will * request and initialize an instance of every available tool. + * @return aggregated toolbox of all available tools */ public Map<String,Object> getToolbox() { @@ -130,6 +135,7 @@ public class ToolContext implements Cont /** * Gets a map of keys to classes for all available tools. * This does not include any data nor any local context values. + * @return aggregated map of all available tools classes */ public Map<String,Class> getToolClassMap() { @@ -161,6 +167,7 @@ public class ToolContext implements Cont * engine has a MethodExceptionEventHandler configured, then * this will automatically set {@link #CATCH_EXCEPTIONS_KEY} * to false in the tool properties. + * @param engine VelocityEngine instance */ public void putVelocityEngine(VelocityEngine engine) { Modified: velocity/tools/trunk/velocity-tools-generic/src/main/java/org/apache/velocity/tools/ToolInfo.java URL: http://svn.apache.org/viewvc/velocity/tools/trunk/velocity-tools-generic/src/main/java/org/apache/velocity/tools/ToolInfo.java?rev=1842484&r1=1842483&r2=1842484&view=diff ============================================================================== --- velocity/tools/trunk/velocity-tools-generic/src/main/java/org/apache/velocity/tools/ToolInfo.java (original) +++ velocity/tools/trunk/velocity-tools-generic/src/main/java/org/apache/velocity/tools/ToolInfo.java Mon Oct 1 12:22:05 2018 @@ -50,6 +50,8 @@ public class ToolInfo implements java.io /** * Creates a new instance using the minimum required info * necessary for a tool. + * @param key tool key + * @param class tool class */ public ToolInfo(String key, Class clazz) { @@ -60,6 +62,10 @@ public class ToolInfo implements java.io /*********************** Mutators *************************/ + /** + * Set the tool key + * @param key tool key + */ public void setKey(String key) { this.key = key; @@ -120,6 +126,10 @@ public class ToolInfo implements java.io } } + /** + * Set whether or not to skip setters. + * @param cfgOnly flag value + */ public void setSkipSetters(boolean cfgOnly) { this.skipSetters = cfgOnly; @@ -129,6 +139,7 @@ public class ToolInfo implements java.io * Adds a map of properties from a parent scope to the properties * for this tool. Only new properties will be added; any that * are already set for this tool will be ignored. + * @param parentProps parent properties map */ public void addProperties(Map<String,Object> parentProps) { @@ -146,12 +157,19 @@ public class ToolInfo implements java.io /** * Puts a new property for this tool. + * @param name property name + * @param value property value + * @return previous property value */ public Object putProperty(String name, Object value) { return getProps().put(name, value); } + /** + * Get tools property (synchronized version) + * @return tools property + */ protected synchronized Map<String,Object> getProps() { if (properties == null) @@ -164,31 +182,55 @@ public class ToolInfo implements java.io /*********************** Accessors *************************/ + /** + * Get tool key + * @return tool key + */ public String getKey() { return key; } + /** + * Get tool class name + * @return tool class name + */ public String getClassname() { return clazz.getName(); } + /** + * Get tool class + * @return tool class + */ public Class getToolClass() { return clazz; } + /** + * Get tool properties + * @return tools properties + */ public Map<String,Object> getProperties() { return getProps(); } + /** + * Get whether this tool has a <code>configure()</code> method + * @return <code>true</code> if the tool has a <code>configure()</code> method, <code>false</code> otherwise + */ public boolean hasConfigure() { return (getConfigure() != null); } + /** + * Get whether setters are to be skipped + * @return whether to skip setters + */ public boolean isSkipSetters() { if (skipSetters == null) @@ -231,6 +273,8 @@ public class ToolInfo implements java.io * will be initialized using the given properties combined with * whatever "constant" properties have been put into this * ToolInfo. + * @param dynamicProperties map of dynamic properties + * @return newly created and configured object */ public Object create(Map<String,Object> dynamicProperties) { @@ -264,6 +308,8 @@ public class ToolInfo implements java.io * if the class lacks the {@link SkipSetters} annotation, then any * specific setters matching the configuration keys are called, then * the general configure(Map) method (if any) is called. + * @param tool newly created tool to be configured + * @param configuration properties */ protected void configure(Object tool, Map<String,Object> configuration) { @@ -294,6 +340,10 @@ public class ToolInfo implements java.io } } + /** + * Try to find a <code>configure()</code> method. + * @return <code>configure()</code> method if found, <code>null</code>otherwise. + */ protected Method getConfigure() { if (this.configure == null) @@ -330,6 +380,11 @@ public class ToolInfo implements java.io setResponse(ServletResponse) setServletContext(ServletContext) */ + /** + * Creates a new instance for this tool. + * @return newly created tool + * @throws IllegalStateException if creation failed + */ protected Object newInstance() { try @@ -353,7 +408,13 @@ public class ToolInfo implements java.io } } - + /** + * Invoke a single argument method on a tool + * @param method the method to invoke + * @param tool the tool on which to invoke the method + * @param param the method argument + * @throws IllegalStateException if invocation failed + */ protected void invoke(Method method, Object tool, Object param) { try @@ -375,7 +436,13 @@ public class ToolInfo implements java.io } } - + /** + * Set a property on a tool instance + * @param tool tool instance + * @param name property name + * @param value property value + * @throws Exception if setting the property throwed + */ protected void setProperty(Object tool, String name, Object value) throws Exception { if (PropertyUtils.isWriteable(tool, name)) @@ -387,6 +454,11 @@ public class ToolInfo implements java.io } //TODO? move to Utils? + /** + * Combine several property maps + * @param maps maps to combine + * @return combined map + */ protected Map<String,Object> combine(Map<String,Object>... maps) { Map<String,Object> combined = new HashMap<String,Object>(); Modified: velocity/tools/trunk/velocity-tools-generic/src/main/java/org/apache/velocity/tools/ToolManager.java URL: http://svn.apache.org/viewvc/velocity/tools/trunk/velocity-tools-generic/src/main/java/org/apache/velocity/tools/ToolManager.java?rev=1842484&r1=1842483&r2=1842484&view=diff ============================================================================== --- velocity/tools/trunk/velocity-tools-generic/src/main/java/org/apache/velocity/tools/ToolManager.java (original) +++ velocity/tools/trunk/velocity-tools-generic/src/main/java/org/apache/velocity/tools/ToolManager.java Mon Oct 1 12:22:05 2018 @@ -47,7 +47,7 @@ public class ToolManager private boolean userOverwrite = true; /** - * Constructs an instance already configured to use the + * Constructs an instance already configured to use the default tools and * any configuration specified via a "org.apache.velocity.tools" * system property. */ @@ -56,11 +56,27 @@ public class ToolManager this(true, true); } + /** + * Constructs an instance that may or not include default tools, + * and already configured with + * any configuration specified via a "org.apache.velocity.tools" + * system property. + * @param includeDefaults whether to include default tools + */ public ToolManager(boolean includeDefaults) { this(true, includeDefaults); } + /** + * Constructs an instance that may or not include default tools, + * and which may or not be already configured with + * any configuration specified via a "org.apache.velocity.tools" + * system property. + * @param autoConfig whether to use configuration file specified + * in the <code>org.apache.velocity.tools</code> system property + * @param includeDefaults whether to include default tools + */ public ToolManager(boolean autoConfig, boolean includeDefaults) { this.factory = new ToolboxFactory(); @@ -71,6 +87,11 @@ public class ToolManager } } + /** + * Autoconfiguration using the configuration file potentially found + * in the <code>org.apache.velocity.tools</code> system property. + * @param includeDefaults whether to include default tools + */ public void autoConfigure(boolean includeDefaults) { // look for any specified via system property @@ -81,6 +102,10 @@ public class ToolManager } } + /** + * Configure the tool manager with this toolbox factory config + * @param config toolbox factory config + */ public void configure(FactoryConfiguration config) { // clear the cached application toolbox @@ -88,6 +113,10 @@ public class ToolManager this.factory.configure(config); } + /** + * Configure the tool manager with the provided configuration file + * @param path path to configuration file + */ public void configure(String path) { FactoryConfiguration config = findConfig(path); @@ -101,6 +130,11 @@ public class ToolManager } } + /** + * Find a configuration file + * @param path path to a configuration file + * @return toolbox factory configuration + */ protected FactoryConfiguration findConfig(String path) { return ConfigurationUtils.find(path); @@ -108,6 +142,7 @@ public class ToolManager /** * Returns the underlying {@link ToolboxFactory} being used. + * @return underlying toolbox factory */ public ToolboxFactory getToolboxFactory() { @@ -118,6 +153,7 @@ public class ToolManager * Sets the underlying ToolboxFactory being used. * <b>If you use this, be sure that your ToolboxFactory * is already properly configured.</b> + * @param factory toolbox factory */ public void setToolboxFactory(ToolboxFactory factory) { @@ -136,6 +172,7 @@ public class ToolManager * Sets the underlying VelocityEngine being used. * <b>If you use this, be sure that your VelocityEngine * is already properly configured and initialized.</b> + * @param engine VelocityEngine instance */ public void setVelocityEngine(VelocityEngine engine) { @@ -146,21 +183,37 @@ public class ToolManager } } + /** + * Get the underlying VelocityEngine being used. + * @return VelocityEngine instance + */ public VelocityEngine getVelocityEngine() { return this.velocity; } + /** + * Set whether template user can overwrite tools keys + * @param overwrite flag value + */ public void setUserCanOverwriteTools(boolean overwrite) { this.userOverwrite = overwrite; } + /** + * Get whether template user can overwrite tools keys + * @return flag value + */ public boolean getUserCanOverwriteTools() { return this.userOverwrite; } + /** + * Get logger + * @return logger + */ public Logger getLog() { if (log == null) @@ -176,6 +229,9 @@ public class ToolManager return log; } + /** + * init logger + */ protected void initLog() { if (velocity == null) @@ -188,11 +244,21 @@ public class ToolManager } } + /** + * create new context with configured toolboxes tools + * @return newly created context + */ public ToolContext createContext() { return createContext(null); } + /** + * create new context with configured toolboxes tools, + * using the provided tools properties + * @param toolProps tools properties + * @return newly created context + */ public ToolContext createContext(Map<String,Object> toolProps) { ToolContext context = new ToolContext(toolProps); @@ -200,6 +266,10 @@ public class ToolManager return context; } + /** + * Prepare context + * @param context tool context + */ protected void prepareContext(ToolContext context) { context.setUserCanOverwriteTools(this.userOverwrite); @@ -210,6 +280,10 @@ public class ToolManager addToolboxes(context); } + /** + * Add toolboxes to contex + * @param context context + */ protected void addToolboxes(ToolContext context) { if (hasApplicationTools()) @@ -222,31 +296,59 @@ public class ToolManager } } + /** + * Check for the presence of tools in a given scope + * @param scope scope to check + * @return whether this scope contains tools + */ protected boolean hasTools(String scope) { return this.factory.hasTools(scope); } + /** + * Create a toolbox for the given scope + * @param scope scope + * @return newly created toolbox + */ protected Toolbox createToolbox(String scope) { return this.factory.createToolbox(scope); } + /** + * Check whether this tool manager has request scoped tools + * @return <code>true</code> if this tool manager has request scoped tools, + * <code>false</code> otherwise + */ protected boolean hasRequestTools() { return hasTools(Scope.REQUEST); } + /** + * Get the toolbox for request scoped tools + * @return toolbox of request scoped tools + */ protected Toolbox getRequestToolbox() { return createToolbox(Scope.REQUEST); } + /** + * Check whether this tool manager has application scoped tools + * @return <code>true</code> if this tool manager has application scoped tools, + * <code>false</code> otherwise + */ protected boolean hasApplicationTools() { return hasTools(Scope.APPLICATION); } + /** + * Get the toolbox for application scoped tools + * @return toolbox of application scoped tools + */ protected Toolbox getApplicationToolbox() { if (this.application == null && hasApplicationTools()) Modified: velocity/tools/trunk/velocity-tools-generic/src/main/java/org/apache/velocity/tools/XmlUtils.java URL: http://svn.apache.org/viewvc/velocity/tools/trunk/velocity-tools-generic/src/main/java/org/apache/velocity/tools/XmlUtils.java?rev=1842484&r1=1842483&r2=1842484&view=diff ============================================================================== --- velocity/tools/trunk/velocity-tools-generic/src/main/java/org/apache/velocity/tools/XmlUtils.java (original) +++ velocity/tools/trunk/velocity-tools-generic/src/main/java/org/apache/velocity/tools/XmlUtils.java Mon Oct 1 12:22:05 2018 @@ -68,7 +68,8 @@ public final class XmlUtils private static final Logger LOGGER = LoggerFactory.getLogger(XmlUtils.class); - /** Handles xml errors so that they're not logged to stderr. + /** + * Handles xml errors so that they're not logged to stderr. */ private static final ErrorHandler errorHandler = new ErrorHandler() { @@ -200,6 +201,10 @@ public final class XmlUtils } } + /** + * Get a document builder + * @return document builder + */ private static synchronized DocumentBuilder getDocumentBuilder() { DocumentBuilder builder = null; @@ -239,6 +244,10 @@ public final class XmlUtils return builder; } + /** + * Release the given document builder + * @param document builder + */ private static synchronized void releaseBuilder(DocumentBuilder builder) { builder.reset(); @@ -250,9 +259,9 @@ public final class XmlUtils /** * Extracts an attribute from a node. * - * @param node - * @param attr - * @param def + * @param node target node + * @param attr attribute name + * @param def default value * @return The value of the attribute, or def */ public static String getAttribute(Node node, String attr, String def) @@ -267,8 +276,8 @@ public final class XmlUtils } /** - * @param node - * @param attr + * @param node target node + * @param attr attribute name * @return The value of the given attribute, or null if not present. */ public static String getAttribute(Node node, String attr) @@ -279,9 +288,9 @@ public final class XmlUtils /** * Retrieves an attribute as a boolean. * - * @param node - * @param attr - * @param def + * @param node target node + * @param attr attribute name + * @param def default value * @return True if the attribute exists and is not equal to "false" * false if equal to "false", and def if not present. */ @@ -296,8 +305,8 @@ public final class XmlUtils } /** - * @param node - * @param attr + * @param node target node + * @param attr attribute name * @return True if the attribute exists and is not equal to "false" * false otherwise. */ @@ -307,6 +316,9 @@ public final class XmlUtils } /** + * @param target node + * @param attr attribute name + * @param def default value * @return An attribute coerced to an integer. */ public static int getIntAttribute(Node node, String attr, int def) @@ -327,6 +339,8 @@ public final class XmlUtils } /** + * @param node target node + * @param attr attribute name * @return An attribute coerced to an integer. */ public static int getIntAttribute(Node node, String attr) @@ -336,7 +350,7 @@ public final class XmlUtils /** * Attempts to parse the input xml into a single element. - * @param xml + * @param xml xml stream reader * @return The document object */ public static Element parse(Reader xml) @@ -362,7 +376,7 @@ public final class XmlUtils /** * Attempts to parse the input xml into a single element. - * @param xml + * @param xml xml string * @return The document object */ public static Element parse(String xml) @@ -388,7 +402,8 @@ public final class XmlUtils /** * <p>Builds the xpath expression for a node (tries to use id/name nodes when possible to get a unique path)</p> - * + * @param n target node + * @return node xpath */ // (borrow from http://stackoverflow.com/questions/5046174/get-xpath-from-the-org-w3c-dom-node ) public static String nodePath(Node n) @@ -497,8 +512,12 @@ public final class XmlUtils return buffer.toString(); } + /** + * XML Node to string + * @param node XML node + * @return XML node string representation + */ public static String nodeToString(Node node) - { StringWriter sw = new StringWriter(); try @@ -517,6 +536,11 @@ public final class XmlUtils return sw.toString(); } + /** + * Checkes whether the given mime type is an XML format + * @param mimeType + * @return <code>true</code> if this mime type is an XML format + */ public static boolean isXmlMimeType(String mimeType) { return mimeType != null && Modified: velocity/tools/trunk/velocity-tools-generic/src/main/java/org/apache/velocity/tools/generic/Alternator.java URL: http://svn.apache.org/viewvc/velocity/tools/trunk/velocity-tools-generic/src/main/java/org/apache/velocity/tools/generic/Alternator.java?rev=1842484&r1=1842483&r2=1842484&view=diff ============================================================================== --- velocity/tools/trunk/velocity-tools-generic/src/main/java/org/apache/velocity/tools/generic/Alternator.java (original) +++ velocity/tools/trunk/velocity-tools-generic/src/main/java/org/apache/velocity/tools/generic/Alternator.java Mon Oct 1 12:22:05 2018 @@ -58,6 +58,7 @@ public class Alternator /** * Creates a new Alternator for the specified list. Alternation * defaults to automatic. + * @param list the elements to alternate over */ public Alternator(Object... list) { @@ -96,6 +97,7 @@ public class Alternator /** * If set to true, the list index will shift automatically after a * call to toString(). + * @param auto flag value */ public void setAuto(boolean auto) { @@ -113,6 +115,7 @@ public class Alternator /** * Returns the current item without shifting the list index. + * @return current item */ public Object getCurrent() { @@ -121,6 +124,7 @@ public class Alternator /** * Returns the current item, then shifts the list index. + * @return current item */ public Object getNext() { @@ -134,6 +138,7 @@ public class Alternator * <code>null</code> if the current item is null. <b>If {@link * #auto} is true, this will shift after returning the current * item</b>. + * @return string representation of the current item */ public String toString() { @@ -148,5 +153,4 @@ public class Alternator } return o.toString(); } - } Modified: velocity/tools/trunk/velocity-tools-generic/src/main/java/org/apache/velocity/tools/generic/AlternatorTool.java URL: http://svn.apache.org/viewvc/velocity/tools/trunk/velocity-tools-generic/src/main/java/org/apache/velocity/tools/generic/AlternatorTool.java?rev=1842484&r1=1842483&r2=1842484&view=diff ============================================================================== --- velocity/tools/trunk/velocity-tools-generic/src/main/java/org/apache/velocity/tools/generic/AlternatorTool.java (original) +++ velocity/tools/trunk/velocity-tools-generic/src/main/java/org/apache/velocity/tools/generic/AlternatorTool.java Mon Oct 1 12:22:05 2018 @@ -73,6 +73,7 @@ public class AlternatorTool extends Safe /** * Looks for a default auto-alternate value in the given params, * if not, set the default to true. + * @param parser configuration values */ protected void configure(ValueParser parser) { @@ -82,6 +83,7 @@ public class AlternatorTool extends Safe /** * Returns true if the default for auto-alternating is true. + * @return flag value * @since VelocityTools 1.3 */ public boolean getAutoAlternateDefault() @@ -91,6 +93,7 @@ public class AlternatorTool extends Safe /** * Sets the default for auto-alternating. + * @param bool flag value * @since VelocityTools 1.3 */ protected void setAutoAlternateDefault(boolean bool) @@ -100,6 +103,8 @@ public class AlternatorTool extends Safe /** * Make an automatic {@link Alternator} from the specifed objects. + * @param list values to alternate over + * @return alternator */ public Alternator make(Object... list) { @@ -112,6 +117,7 @@ public class AlternatorTool extends Safe * * @param auto See {@link Alternator#setAuto(boolean auto)}. * @param list The list of elements to alternate. + * @return alternator */ public Alternator make(boolean auto, Object... list) { @@ -131,6 +137,7 @@ public class AlternatorTool extends Safe /** * Make an automatic {@link Alternator} from the specified objects. * + * @param list objects to alternate over * @return a new, automatic Alternator with the specified values or * <code>null</code> if there are none specified. * @since VelocityTools 1.3 @@ -143,6 +150,7 @@ public class AlternatorTool extends Safe /** * Make a manual {@link Alternator} from the specified objects. * + * @param list objects to alternate over * @return a new, manual Alternator with the values in the array or * <code>null</code> if the array is <code>null</code>. * @since VelocityTools 1.3 Modified: velocity/tools/trunk/velocity-tools-generic/src/main/java/org/apache/velocity/tools/generic/ClassTool.java URL: http://svn.apache.org/viewvc/velocity/tools/trunk/velocity-tools-generic/src/main/java/org/apache/velocity/tools/generic/ClassTool.java?rev=1842484&r1=1842483&r2=1842484&view=diff ============================================================================== --- velocity/tools/trunk/velocity-tools-generic/src/main/java/org/apache/velocity/tools/generic/ClassTool.java (original) +++ velocity/tools/trunk/velocity-tools-generic/src/main/java/org/apache/velocity/tools/generic/ClassTool.java Mon Oct 1 12:22:05 2018 @@ -91,6 +91,8 @@ public class ClassTool extends SafeConfi * Creates a new instance that inspects the specified type * and otherwise shares the configuration values of the specified "parent" * ClassTool instance. + * @param tool parent class tool + * @param type class to inspect */ protected ClassTool(ClassTool tool, Class type) { @@ -106,6 +108,10 @@ public class ClassTool extends SafeConfi setLockConfig(tool.isConfigLocked()); } + /** + * Configure this tool + * @param values configuration values + */ protected void configure(ValueParser values) { this.showDeprecated = @@ -118,6 +124,11 @@ public class ClassTool extends SafeConfi } } + /** + * Find a class given its name + * @param name class name + * @return found class or null + */ private Class toClass(String name) { try @@ -131,6 +142,10 @@ public class ClassTool extends SafeConfi } } + /** + * Set the class to inspect + * @param type the class to inspect + */ protected void setType(Class type) { if (type == null) @@ -140,6 +155,11 @@ public class ClassTool extends SafeConfi this.type = type; } + /** + * Check if an annotation deprecates its class + * @param element annotation + * @return deprecation status + */ protected static boolean isDeprecated(AnnotatedElement element) { return (element.getAnnotation(Deprecated.class) != null); @@ -147,6 +167,7 @@ public class ClassTool extends SafeConfi /** * Returns the current showDeprecated setting. + * @return flag value */ public boolean getShowDeprecated() { @@ -155,6 +176,7 @@ public class ClassTool extends SafeConfi /** * Returns the {@link Class} being inspected by this instance. + * @return inspected class */ public Class getType() { @@ -166,6 +188,8 @@ public class ClassTool extends SafeConfi * Class with the specified name. If the specified Class cannot * be found, then this will return {@code null}. All other * configuration settings will be copied to the new instance. + * @param name class name + * @return new class tool */ public ClassTool inspect(String name) { @@ -181,6 +205,8 @@ public class ClassTool extends SafeConfi * Class of the specified {@link Object}. If the specified object * is null, then this will return {@code null}. All other * configuration settings will be copied to the new instance. + * @param obj object instance to inspect + * @return new class tool */ public ClassTool inspect(Object obj) { @@ -197,6 +223,7 @@ public class ClassTool extends SafeConfi * If the current inspectee has no super class, * then this will return {@code null}. All other * configuration settings will be copied to the new instance. + * @return parent class tool */ public ClassTool getSuper() { @@ -216,6 +243,8 @@ public class ClassTool extends SafeConfi * If {@link #isSafeMode()} is {@code true} and the specified Class * is not declared {@code public}, then this will return * {@code null}. + * @param type class to inspect + * @return new class tool */ public ClassTool inspect(Class type) { @@ -235,6 +264,7 @@ public class ClassTool extends SafeConfi /** * Returns the name of the package to which the inspected Class belongs. + * @return package name */ public String getPackage() { @@ -244,6 +274,7 @@ public class ClassTool extends SafeConfi /** * Returns the simple name (i.e. full name with package name removed) of * the inspected Class. + * @return inspected class simple name */ public String getName() { @@ -252,6 +283,7 @@ public class ClassTool extends SafeConfi /** * Returns the fully-qualified name for the inspected Class. + * @return inspected class name */ public String getFullName() { @@ -263,6 +295,7 @@ public class ClassTool extends SafeConfi * inspected is successful; otherwise returns false. Unlike calling * newInstance() directly from a template, this will not throw an * Exception if it fails, as all Exceptions are caught. + * @return new instances supported or not */ public boolean supportsNewInstance() { @@ -279,6 +312,7 @@ public class ClassTool extends SafeConfi /** * Returns true if the inspected Class has been deprecated. + * @return deprecation status */ public boolean isDeprecated() { @@ -287,6 +321,7 @@ public class ClassTool extends SafeConfi /** * Returns true if the inspected Class is declared public. + * @return whether the inspected class is public */ public boolean isPublic() { @@ -295,6 +330,7 @@ public class ClassTool extends SafeConfi /** * Returns true if the inspected Class is declared protected. + * @return whether the inspected class is protected */ public boolean isProtected() { @@ -303,6 +339,7 @@ public class ClassTool extends SafeConfi /** * Returns true if the inspected Class is declared private. + * @return whether the inspected class is private */ public boolean isPrivate() { @@ -312,6 +349,7 @@ public class ClassTool extends SafeConfi /** * Returns true if the inspected Class is an inner class * that has been declared static or is a standard outer class.. + * @return whether the inspected class is static */ public boolean isStatic() { @@ -320,6 +358,7 @@ public class ClassTool extends SafeConfi /** * Returns true if the inspected Class is declared final. + * @return whether the inspected class is final */ public boolean isFinal() { @@ -328,6 +367,7 @@ public class ClassTool extends SafeConfi /** * Returns true if the inspected Class is an interface. + * @return whether the inspected class is an interface */ public boolean isInterface() { @@ -337,6 +377,7 @@ public class ClassTool extends SafeConfi /** * Returns true if the inspected Class is declared strictfp * (uses strict floating point math). + * @return whether the inspected class is strictfp */ public boolean isStrict() { @@ -345,6 +386,7 @@ public class ClassTool extends SafeConfi /** * Returns true if the inspected Class is declared abstract. + * @return whether the inspected class is abstract */ public boolean isAbstract() { @@ -357,6 +399,7 @@ public class ClassTool extends SafeConfi * in safe mode (which *is* the default), this will only return * the public methods. You must configure safe mode to be off * to receive a list of all methods. + * @return methods inspectors list */ public List<MethodSub> getMethods() { @@ -385,6 +428,7 @@ public class ClassTool extends SafeConfi * in safe mode (which *is* the default), this will only return * the public constructors. You must configure safe mode to be off * to receive a list of all constructors. + * @return constructors inspectors list */ public List<ConstructorSub> getConstructors() { @@ -413,6 +457,7 @@ public class ClassTool extends SafeConfi * in safe mode (which *is* the default), this will only return * the public fields. You must configure safe mode to be off * to receive a list of all fields. + * @return fields inspectors list */ public List<FieldSub> getFields() { @@ -439,6 +484,7 @@ public class ClassTool extends SafeConfi * Returns a {@link Set} of all {@link Class}es that are * part of the signatures (i.e. parameters or return types) * of the inspected Class's methods, constructors and fields. + * @return referenced classes set */ public Set<Class> getTypes() { @@ -491,12 +537,16 @@ public class ClassTool extends SafeConfi /** * Returns the {@link Annotation}s of the Class being inspected. + * @return annotation list */ public List<Annotation> getAnnotations() { return Arrays.asList(getType().getAnnotations()); } + /** + * @return string representation of inspected class + */ public String toString() { return getType().toString(); @@ -512,16 +562,26 @@ public class ClassTool extends SafeConfi { protected Field field; + /** + * FieldSub constructor + * @param field inspected field + */ public FieldSub(Field field) { this.field = field; } + /** + * @return inspected element + */ protected AnnotatedElement getElement() { return field; } + /** + * @return field name + */ public String getName() { return field.getName(); @@ -530,6 +590,7 @@ public class ClassTool extends SafeConfi /** * Simply returns the name of the field, since field names * cannot be overloaded. + * @return unique name */ public String getUniqueName() { @@ -539,12 +600,16 @@ public class ClassTool extends SafeConfi /** * Simply returns the name of the field. + * @return field name */ public String getJavadocRef() { return field.getName(); } + /** + * @return field class + */ public Class getType() { return field.getType(); @@ -554,6 +619,7 @@ public class ClassTool extends SafeConfi * Returns the value of the field if and only if * it is a static field that has no access restrictions * set by the security manager. + * @return value of static field */ public Object getStaticValue() { @@ -571,11 +637,17 @@ public class ClassTool extends SafeConfi return null; } + /** + * @return inspected field modifiers + */ protected int getModifiers() { return field.getModifiers(); } + /** + * @return inspected field inspector type, aka "field" + */ protected String getSubType() { return "field"; @@ -590,21 +662,34 @@ public class ClassTool extends SafeConfi { protected Constructor constructor; + /** + * Constructor inspector constructor + * @param constructor constructor to inspect + */ public ConstructorSub(Constructor constructor) { this.constructor = constructor; } + /** + * @return inspected element + */ protected AnnotatedElement getElement() { return constructor; } + /** + * @return inspected constructor name + */ public String getName() { return constructor.getDeclaringClass().getSimpleName(); } + /** + * @return inspected constructor parameters + */ public Class[] getParameters() { return constructor.getParameterTypes(); @@ -613,17 +698,24 @@ public class ClassTool extends SafeConfi /** * Returns true if the final parameter for the constructor was declared * as a vararg. + * @return whether the inspected constructor is vararg */ public boolean isVarArgs() { return constructor.isVarArgs(); } + /** + * @return inspected constructor modifiers + */ protected int getModifiers() { return constructor.getModifiers(); } + /** + * @return inspector type, aka "constructor" + */ protected String getSubType() { return "constructor"; @@ -638,16 +730,26 @@ public class ClassTool extends SafeConfi { protected Method method; + /** + * Method inspector constructor + * @param method methodto inspect + */ public MethodSub(Method method) { this.method = method; } + /** + * @return inspected element + */ protected AnnotatedElement getElement() { return method; } + /** + * @return method name + */ public String getName() { return method.getName(); @@ -658,6 +760,7 @@ public class ClassTool extends SafeConfi * (which does not exactly follow the javabean spec for such things) * then it will return the "bean property" equivalent of the method name. * (e.g. for getFoo(), isFoo() or setFoo(foo) it will return "foo") + * @return related property name, or null */ public String getPropertyName() { @@ -702,6 +805,7 @@ public class ClassTool extends SafeConfi /** * Returns true if the final parameter for the method was declared * as a vararg. + * @return vararg status */ public boolean isVarArgs() { @@ -710,27 +814,40 @@ public class ClassTool extends SafeConfi /** * Returns true if the return type of this method is void. + * @return <code>true</code> if the inspected method returns null */ public boolean isVoid() { return (getReturns() == Void.TYPE); } + /** + * @return inspected method return type + */ public Class getReturns() { return method.getReturnType(); } + /** + * @return inspected method parameters types + */ public Class[] getParameters() { return method.getParameterTypes(); } + /** + * @return inspected method modifiers + */ protected int getModifiers() { return method.getModifiers(); } + /** + * @return inspector type, aka "method" + */ protected String getSubType() { return "method"; @@ -746,6 +863,9 @@ public class ClassTool extends SafeConfi public abstract Class[] getParameters(); public abstract boolean isVarArgs(); + /** + * @return whether the inspected callable takes parameters + */ public boolean takesParameters() { return (getParameterCount() > 0); @@ -754,6 +874,7 @@ public class ClassTool extends SafeConfi /** * Returns the number of expected parameters. If this method or * constructor is declared with varargs, the vararg only counts as one. + * @return inspected callable parameters count */ public int getParameterCount() { @@ -766,6 +887,7 @@ public class ClassTool extends SafeConfi * and overloaded methods with a useful name that would still be a * valid method name. This is particularly useful for generating * JUnit test method names. + * @return inspected callable unique name */ public String getUniqueName() { @@ -808,6 +930,10 @@ public class ClassTool extends SafeConfi return uniqueName; } + /** + * Get (and cache) inspected callable signature + * @return inspected callable signature + */ public String getSignature() { if (signature == null) @@ -817,6 +943,9 @@ public class ClassTool extends SafeConfi return signature; } + /** + * @return inspected callable javadoc ref + */ public String getJavadocRef() { if (javadocRef == null) @@ -826,6 +955,11 @@ public class ClassTool extends SafeConfi return javadocRef; } + /** + * Internal method to get the inspected callable signature. + * @param fullNames whether to use full names + * @return inspected callable signature + */ protected String signature(boolean fullNames) { Class[] params = getParameters(); @@ -903,87 +1037,140 @@ public class ClassTool extends SafeConfi /** * Returns the {@link Annotation}s of the element being inspected. + * @return annotations list */ public List<Annotation> getAnnotations() { return Arrays.asList(getElement().getAnnotations()); } + /** + * Inspected object deprecation status + * @return deprecation status + */ public boolean isDeprecated() { return ClassTool.isDeprecated(getElement()); } + /** + * @return whether the inspected object is public + */ public boolean isPublic() { return Modifier.isPublic(getModifiers()); } + /** + * @return whether the inspected object is protected + */ public boolean isProtected() { return Modifier.isProtected(getModifiers()); } + /** + * @return whether the inspected object is private + */ public boolean isPrivate() { return Modifier.isPrivate(getModifiers()); } + /** + * @return whether the inspected object is static + */ public boolean isStatic() { return Modifier.isStatic(getModifiers()); } + /** + * @return whether the inspected object is final + */ public boolean isFinal() { return Modifier.isFinal(getModifiers()); } + /** + * @return whether the inspected object is an interface + */ public boolean isInterface() { return Modifier.isInterface(getModifiers()); } + /** + * @return whether the inspected object is native + */ public boolean isNative() { return Modifier.isNative(getModifiers()); } + /** + * @return whether the inspected object is strictfp + */ public boolean isStrict() { return Modifier.isStrict(getModifiers()); } + /** + * @return whether the inspected object is synchronized + */ public boolean isSynchronized() { return Modifier.isSynchronized(getModifiers()); } + /** + * @return whether the inspected object is transcient + */ public boolean isTransient() { return Modifier.isTransient(getModifiers()); } + /** + * @return whether the inspected object is volatile + */ public boolean isVolatile() { return Modifier.isVolatile(getModifiers()); } + /** + * @return whether the inspected object is abstract + */ public boolean isAbstract() { return Modifier.isAbstract(getModifiers()); } + /** + * Compare unique names of inspected and given objects + * @param that object to compare to + * @return comparison result + */ public int compareTo(T that) { return this.getUniqueName().compareTo(that.getUniqueName()); } + /** + * @return hash code + */ public int hashCode() { return this.getUniqueName().hashCode(); } + /** + * @param obj object to compare to + * @return whether it's the same object + */ public boolean equals(Object obj) { if (obj instanceof Sub) @@ -994,6 +1181,9 @@ public class ClassTool extends SafeConfi return false; } + /** + * @return string representation + */ public String toString() { return getSubType() + ' ' + getJavadocRef(); Modified: velocity/tools/trunk/velocity-tools-generic/src/main/java/org/apache/velocity/tools/generic/CollectionTool.java URL: http://svn.apache.org/viewvc/velocity/tools/trunk/velocity-tools-generic/src/main/java/org/apache/velocity/tools/generic/CollectionTool.java?rev=1842484&r1=1842483&r2=1842484&view=diff ============================================================================== --- velocity/tools/trunk/velocity-tools-generic/src/main/java/org/apache/velocity/tools/generic/CollectionTool.java (original) +++ velocity/tools/trunk/velocity-tools-generic/src/main/java/org/apache/velocity/tools/generic/CollectionTool.java Mon Oct 1 12:22:05 2018 @@ -132,6 +132,7 @@ public class CollectionTool extends Safe * Sets the delimiter used for separating values in a single String value. * The default string delimiter is a comma. * + * @param stringsDelimiter strings delimiter * @see #split(String) */ protected final void setStringsDelimiter(String stringsDelimiter) @@ -139,6 +140,10 @@ public class CollectionTool extends Safe this.stringsDelimiter = stringsDelimiter; } + /** + * Gets the configured strings delimiter + * @return strings delimiter + */ public final String getStringsDelimiter() { return this.stringsDelimiter; @@ -149,6 +154,7 @@ public class CollectionTool extends Safe * a delimited string value. * The default is true. * + * @param stringsTrim flag value * @see #split(String) */ protected final void setStringsTrim(boolean stringsTrim) @@ -156,6 +162,10 @@ public class CollectionTool extends Safe this.stringsTrim = stringsTrim; } + /** + * Gets whether to trim strings + * @return whether to trim strings + */ public final boolean getStringsTrim() { return this.stringsTrim; @@ -166,6 +176,7 @@ public class CollectionTool extends Safe * subclasses may share the same ValueParser and call configure * at any time, while preventing templates from doing so when * configure(Map) is locked. + * @param values configuration values */ @Override protected void configure(ValueParser values) @@ -329,21 +340,41 @@ public class CollectionTool extends Safe } } + /** + * Sort a collection + * @param collection collection to sort, left unchanged + * @return new sorted collection + */ public Collection sort(Collection collection) { return sort(collection, (List)null); } + /** + * Sort an array + * @param array array to sort, left unchanged + * @return new sorted collection + */ public Collection sort(Object[] array) { return sort(array, (List)null); } + /** + * Sort map values + * @param map map to sort + * @return new sorted collection of map values + */ public Collection sort(Map map) { return sort(map, (List)null); } + /** + * Sort a collection, array or map + * @param object collection, array or map to sort + * @return new sorted collection, or null of object type is not supported + */ public Collection sort(Object object) { if (object instanceof Collection) @@ -366,8 +397,9 @@ public class CollectionTool extends Safe /** * Sorts the collection on a single property. * - * @param object the collection to be sorted. + * @param object the collection to be sorted, left unchanged. * @param property the property to sort on. + * @return new collection, sorted. */ public Collection sort(Object object, String property) { @@ -390,6 +422,13 @@ public class CollectionTool extends Safe return null; } + /** + * Sorts the collection on several properties. + * + * @param object the collection to be sorted, left unchanged. + * @param property the property to sort on. + * @return new collection, sorted. + */ public Collection sort(Collection collection, List properties) { List list = new ArrayList<>(); @@ -407,16 +446,37 @@ public class CollectionTool extends Safe return internalSort(list, properties); } + /** + * Sorts map values on several properties. + * + * @param map the map to be sorted, left unchanged. + * @param properties the properties to sort on. + * @return new collection, sorted. + */ public Collection sort(Map map, List properties) { return sort(map.values(), properties); } + /** + * Sorts array on several properties. + * + * @param array array to be sorted, left unchanged. + * @param properties the properties to sort on. + * @return new collection, sorted. + */ public Collection sort(Object[] array, List properties) { return sort(Arrays.asList(array), properties); } + /** + * Internal sorting method. + * + * @param list values to sort. + * @param properties the properties to sort on. + * @return new collection, sorted. + */ protected Collection internalSort(List list, List properties) { try @@ -550,6 +610,9 @@ public class CollectionTool extends Safe * from the specified object. Subclasses that wish to perform more * advanced, efficient, or just different property retrieval methods * should override this method to do so. + * @param object target object + * @param property target property + * @return comparable */ protected static Comparable getComparable(Object object, String property) { Modified: velocity/tools/trunk/velocity-tools-generic/src/main/java/org/apache/velocity/tools/generic/SafeConfig.java URL: http://svn.apache.org/viewvc/velocity/tools/trunk/velocity-tools-generic/src/main/java/org/apache/velocity/tools/generic/SafeConfig.java?rev=1842484&r1=1842483&r2=1842484&view=diff ============================================================================== --- velocity/tools/trunk/velocity-tools-generic/src/main/java/org/apache/velocity/tools/generic/SafeConfig.java (original) +++ velocity/tools/trunk/velocity-tools-generic/src/main/java/org/apache/velocity/tools/generic/SafeConfig.java Mon Oct 1 12:22:05 2018 @@ -83,12 +83,17 @@ public class SafeConfig /** * Only allow subclass access to this. + * @param lock whether to lock config */ protected void setLockConfig(boolean lock) { this.configLocked = lock; } + /** + * Set or clear safe mode. + * @param safe whether to set safe mode + */ protected void setSafeMode(boolean safe) { this.safeMode = safe; @@ -97,6 +102,7 @@ public class SafeConfig /** * Returns {@code true} if the {@link #configure(Map)} method * has been locked. + * @return locked status */ public boolean isConfigLocked() { @@ -105,6 +111,7 @@ public class SafeConfig /** * Returns {@code true} if this tool is in "safe mode". + * @return safe mode status */ public boolean isSafeMode() { @@ -121,6 +128,7 @@ public class SafeConfig * The safe mode value should be a boolean under the key * {@link #SAFE_MODE_KEY} and the lock value should be a boolean * under the key {@link #LOCK_CONFIG_KEY}. + * @param params configuration values map */ public void configure(Map params) { @@ -147,6 +155,7 @@ public class SafeConfig * subclasses may share the same ValueParser and call configure * at any time, while preventing templates from doing so when * configure(Map) is locked. + * @param values configuration values */ protected void configure(ValueParser values) { @@ -185,6 +194,10 @@ public class SafeConfig } } + /** + * Get logger + * @return logger + */ protected Logger getLog() { if (log == null)