@DefaultKey(value="depends") @ValidScope(value="request") public class UiDependencyTool extends java.lang.Object
Example of use:
Template --- <html> <head> $depends.on('profile').print(' ') </head> ... Output ------ <html> <head> <style rel="stylesheet" type="text/css" href="css/globals.css"/> <script type="text/javascript" src="js/jquery.js"></script> <script type="text/javascript" src="js/profile.js"></script> </head> ... Example tools.xml: <tools> <toolbox scope="request"> <tool class="org.apache.velocity.tools.view.beta.UiDependencyTool"/> </toolbox> </tools> Example ui.xml: <ui> <type name="style"><![CDATA[<link rel="stylesheet" type="text/css" href="/styles/{file}">]]></type> <group name="globals"> <file type="style">css/globals.css<file/> </group> <group name="jquery"> <file type="script">js/jquery.js<file/> </group> <group name="profile"> <needs>globals</needs> <needs>jquery</needs> <file type="script">js/profile.js<file/> </group> </ui>
Modifier and Type | Class and Description |
---|---|
protected static class |
UiDependencyTool.FileRule
NOTE: This class may change or disappear w/o warning; don't depend
on it unless you're willing to update your code whenever this changes.
|
protected static class |
UiDependencyTool.Group
NOTE: This class may change or disappear w/o warning; don't depend
on it unless you're willing to update your code whenever this changes.
|
protected static class |
UiDependencyTool.GroupRule
NOTE: This class may change or disappear w/o warning; don't depend
on it unless you're willing to update your code whenever this changes.
|
protected static class |
UiDependencyTool.NeedsRule
NOTE: This class may change or disappear w/o warning; don't depend
on it unless you're willing to update your code whenever this changes.
|
private static class |
UiDependencyTool.Type |
protected static class |
UiDependencyTool.TypeRule
NOTE: This class may change or disappear w/o warning; don't depend
on it unless you're willing to update your code whenever this changes.
|
Modifier and Type | Field and Description |
---|---|
private java.lang.String |
context |
static java.lang.String |
DEFAULT_SOURCE_FILE |
private static java.util.List<UiDependencyTool.Type> |
DEFAULT_TYPES |
private java.util.Map<java.lang.String,java.util.List<java.lang.String>> |
dependencies |
private java.util.Map<java.lang.String,UiDependencyTool.Group> |
groups |
static java.lang.String |
GROUPS_KEY_SPACE |
private Log |
LOG |
static java.lang.String |
SOURCE_FILE_KEY |
private java.util.List<UiDependencyTool.Type> |
types |
static java.lang.String |
TYPES_KEY_SPACE |
Constructor and Description |
---|
UiDependencyTool() |
Modifier and Type | Method and Description |
---|---|
protected void |
addDependencies(java.util.Map<java.lang.String,java.util.List<java.lang.String>> fbt)
Adds the specified files organized by type to this instance's
current dependencies.
|
protected void |
addFile(java.lang.String type,
java.lang.String file)
Adds a file to this instance's dependencies under the specified type.
|
void |
configure(java.util.Map params) |
UiDependencyTool |
context(java.lang.String path)
Sets a custom {context} variable for the formats to use.
|
protected Digester |
createDigester()
Creates the
Digester used by read(java.lang.String, boolean) to create
the group info for this instance out of the specified XML file. |
private void |
debug(java.lang.String msg,
java.lang.Object... args) |
protected java.lang.String |
format(java.lang.String format,
java.lang.String value)
Applies the format string to the given value.
|
java.util.Map<java.lang.String,java.util.List<java.lang.String>> |
getDependencies()
Returns the current dependencies of this instance, organized
as an ordered map of file types to lists of the required files
of that type.
|
java.util.List<java.lang.String> |
getDependencies(java.lang.String type)
Returns the
List of files for the specified file type, if any. |
java.lang.String |
getFormat(java.lang.String type)
Retrieves the configured format string for the specified file type.
|
protected UiDependencyTool.Group |
getGroup(java.lang.String name)
NOTE: This method may change or disappear w/o warning; don't depend
on it unless you're willing to update your code whenever this changes.
|
java.util.Map<java.lang.String,java.util.List<java.lang.String>> |
getGroupDependencies(java.lang.String name)
Returns the dependencies of the specified group, organized
as an ordered map of file types to lists of the required files
of that type.
|
private UiDependencyTool.Type |
getType(java.lang.String type)
For internal use only.
|
protected UiDependencyTool.Group |
makeGroup(java.lang.String name)
NOTE: This method may change or disappear w/o warning; don't depend
on it unless you're willing to update your code whenever this changes.
|
UiDependencyTool |
on(java.lang.String name)
Adds all the files required for the specified group, then returns
this instance.
|
UiDependencyTool |
on(java.lang.String type,
java.lang.String file)
Adds the specified file to this instance's list of dependencies
of the specified type, then returns this instance.
|
java.lang.String |
print()
Formats and prints all the current dependencies of this tool,
using a new line in between the printed/formatted files.
|
java.lang.String |
print(java.lang.String typeOrDelim)
If the parameter value is a known type, then this will
format and print all of this instance's current dependencies of the
specified type, using a new line in between the printed/formatted files.
|
java.lang.String |
print(java.lang.String type,
java.lang.String delim)
Formats and prints all of this instance's current dependencies of the
specified type, using the specified delimiter in between the
printed/formatted files.
|
java.lang.String |
printAll(java.lang.String delim)
Formats and prints all the current dependencies of this tool,
using the specified delimiter in between the printed/formatted files.
|
protected void |
read(java.lang.String file,
boolean required)
Reads group info out of the specified file and into this instance.
|
void |
setFormat(java.lang.String type,
java.lang.String format)
Sets the format string for the specified file type.
|
java.lang.String |
toString()
Returns an empty String to avoid polluting the template output after a
successful call to
on(String) or on(String,String) . |
private java.net.URL |
toURL(java.lang.String file) |
protected static void |
trace(Log log,
java.lang.String msg,
java.lang.Object... args) |
public static final java.lang.String GROUPS_KEY_SPACE
public static final java.lang.String TYPES_KEY_SPACE
public static final java.lang.String SOURCE_FILE_KEY
public static final java.lang.String DEFAULT_SOURCE_FILE
private static final java.util.List<UiDependencyTool.Type> DEFAULT_TYPES
private java.util.Map<java.lang.String,UiDependencyTool.Group> groups
private java.util.List<UiDependencyTool.Type> types
private java.util.Map<java.lang.String,java.util.List<java.lang.String>> dependencies
private Log LOG
private java.lang.String context
private void debug(java.lang.String msg, java.lang.Object... args)
protected static final void trace(Log log, java.lang.String msg, java.lang.Object... args)
public void configure(java.util.Map params)
public UiDependencyTool on(java.lang.String name)
public UiDependencyTool on(java.lang.String type, java.lang.String file)
public java.lang.String print()
public java.lang.String print(java.lang.String typeOrDelim)
print(String,String)
,
printAll(String)
public java.lang.String print(java.lang.String type, java.lang.String delim)
public java.lang.String printAll(java.lang.String delim)
public UiDependencyTool context(java.lang.String path)
public java.lang.String getFormat(java.lang.String type)
public void setFormat(java.lang.String type, java.lang.String format)
public java.util.Map<java.lang.String,java.util.List<java.lang.String>> getDependencies()
public java.util.List<java.lang.String> getDependencies(java.lang.String type)
List
of files for the specified file type, if any.public java.util.Map<java.lang.String,java.util.List<java.lang.String>> getGroupDependencies(java.lang.String name)
public java.lang.String toString()
on(String)
or on(String,String)
.toString
in class java.lang.Object
protected void read(java.lang.String file, boolean required)
RuntimeException
s.protected Digester createDigester()
Digester
used by read(java.lang.String, boolean)
to create
the group info for this instance out of the specified XML file.protected java.lang.String format(java.lang.String format, java.lang.String value)
protected UiDependencyTool.Group getGroup(java.lang.String name)
protected UiDependencyTool.Group makeGroup(java.lang.String name)
protected void addDependencies(java.util.Map<java.lang.String,java.util.List<java.lang.String>> fbt)
protected void addFile(java.lang.String type, java.lang.String file)
private UiDependencyTool.Type getType(java.lang.String type)
private java.net.URL toURL(java.lang.String file)
Copyright (c) 2003-2007 Apache Software Foundation