@DefaultKey(value="depends") @ValidScope(value="request") public class UiDependencyTool extends SafeConfig
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 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.
|
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 |
---|---|
static String |
DEFAULT_SOURCE_FILE |
static String |
GROUPS_KEY_SPACE |
static String |
SOURCE_FILE_KEY |
static String |
TYPES_KEY_SPACE |
LOCK_CONFIG_KEY, log, LOGGER_NAME_KEY, SAFE_MODE_KEY, USE_CLASS_LOGGER_KEY
Constructor and Description |
---|
UiDependencyTool() |
Modifier and Type | Method and Description |
---|---|
protected void |
addDependencies(Map<String,List<String>> fbt)
Adds the specified files organized by type to this instance's
current dependencies.
|
protected void |
addFile(String type,
String file)
Adds a file to this instance's dependencies under the specified type.
|
protected void |
configure(ValueParser params)
Does the actual configuration.
|
UiDependencyTool |
context(String path)
Sets a custom {context} variable for the formats to use.
|
protected org.apache.commons.digester3.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. |
protected String |
format(String format,
String value)
Applies the format string to the given value.
|
Map<String,List<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.
|
List<String> |
getDependencies(String type)
Returns the
List of files for the specified file type, if any. |
String |
getFormat(String type)
Retrieves the configured format string for the specified file type.
|
protected UiDependencyTool.Group |
getGroup(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.
|
Map<String,List<String>> |
getGroupDependencies(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.
|
protected UiDependencyTool.Group |
makeGroup(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(String name)
Adds all the files required for the specified group, then returns
this instance.
|
UiDependencyTool |
on(String type,
String file)
Adds the specified file to this instance's list of dependencies
of the specified type, then returns this instance.
|
String |
print()
Formats and prints all the current dependencies of this tool,
using a new line in between the printed/formatted files.
|
String |
print(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.
|
String |
print(String type,
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.
|
String |
printAll(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(String file,
boolean required)
Reads group info out of the specified file and into this instance.
|
void |
setFormat(String type,
String format)
Sets the format string for the specified file type.
|
String |
toString()
Returns an empty String to avoid polluting the template output after a
successful call to
on(String) or on(String,String) . |
configure, getLog, initLogger, isConfigLocked, isSafeMode, setLockConfig, setSafeMode
public static final String GROUPS_KEY_SPACE
public static final String TYPES_KEY_SPACE
public static final String SOURCE_FILE_KEY
public static final String DEFAULT_SOURCE_FILE
protected void configure(ValueParser params)
SafeConfig
configure
in class SafeConfig
params
- configuration valuespublic UiDependencyTool on(String name)
name
- group namepublic UiDependencyTool on(String type, String file)
type
- file typefile
- dependency filepublic String print()
public String print(String typeOrDelim)
typeOrDelim
- type asked for, or delimiterprint(String,String)
,
printAll(String)
public String print(String type, String delim)
type
- file typedelim
- lines delimiterpublic String printAll(String delim)
delim
- delimiterpublic UiDependencyTool context(String path)
path
- context pathpublic String getFormat(String type)
type
- file typepublic void setFormat(String type, String format)
type
- file typeformat
- format stringpublic Map<String,List<String>> getDependencies()
public List<String> getDependencies(String type)
List
of files for the specified file type, if any.type
- file typepublic Map<String,List<String>> getGroupDependencies(String name)
name
- group namepublic String toString()
on(String)
or on(String,String)
.protected void read(String file, boolean required)
RuntimeException
s.file
- filerequired
- whether this file is requiredprotected org.apache.commons.digester3.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 String format(String format, String value)
format
- format stringvalue
- dependency fileprotected UiDependencyTool.Group getGroup(String name)
name
- file nameprotected UiDependencyTool.Group makeGroup(String name)
name
- group nameprotected void addDependencies(Map<String,List<String>> fbt)
fbt
- dependencies mapCopyright © 2002–2018 The Apache Software Foundation. All rights reserved.