public class TemplateParseUtil extends Object
| Modifier and Type | Class and Description |
|---|---|
static class |
TemplateParseUtil.PreProcessedTemplate
Contains the data for templates,
each template must have a template key and the template itself
|
static class |
TemplateParseUtil.ProcessedTemplate
Contains the processed template with the values from the processed input string
that was determined to be related to this template
|
static class |
TemplateParseUtil.Template
Represents a parseable template (which is basically a key and the template string),
the array which defines the set of template keys is
PARSE_TEMPLATE_KEYSRules for parse templates: 1) "{","}", and SEPARATOR are special characters and must be used as indicated only
2) Must begin with a SEPARATOR, must not end with a SEPARATOR
3) must begin with "/{prefix}" (use the SEPARATOR and PREFIX constants)
3) each {var} can only be used once in a template
4) {var} can never touch each other (i.e /{var1}{var2}/{id} is invalid)
5) each {var} can only have the chars from VALID_VAR_CHARS
6) parse templates can only have the chars from VALID_TEMPLATE_CHARS
7) Empty braces ({}) cannot appear in the template |
| Modifier and Type | Field and Description |
|---|---|
static String |
BRACES |
static Set<String> |
commonExtensions
Contains a set of all the common extensions
|
static List<TemplateParseUtil.PreProcessedTemplate> |
defaultPreprocessedTemplates
Stores the preloaded processed default templates
|
static List<TemplateParseUtil.Template> |
defaultTemplates
Stores the preloaded default templates
|
static String |
DIRECT_PREFIX |
static String |
DIRECT_PREFIX_SLASH |
static String |
DOT_EXTENSION
The extension with a period in front marker (Example value: ".xml")
|
static String |
EXTENSION
The entity extension (format) marker (Example value: "xml")
|
static String |
ID
The entity ID marker (Example value: "123")
|
static String[] |
PARSE_TEMPLATE_KEYS
Defines the order that parse templates will be processed in and
the set of parse template types (keys) which must be defined,
the first one to match will be used when parsing in a path
|
static char |
PERIOD |
static String |
PREFIX
The entity prefix marker (Example value: "myprefix")
|
static String |
PREFIX_VARIABLE |
static String |
QUERY_STRING
The value in the query string (without a leading ?)
|
static String |
QUESTION_QUERY_STRING
The value in the query string (with a leading ?)
|
static char |
SEPARATOR |
static String |
TEMPLATE_DELETE
Defines the parse template for the "delete" operation,
access the data to remove a record,
typically /{prefix}/{id}/delete
|
static String |
TEMPLATE_EDIT
Defines the parse template for the "edit" operation,
access the data to modify a record,
typically /{prefix}/{id}/edit
|
static String |
TEMPLATE_LIST
Defines the parse template for the "list" operation,
return a list of all records,
typically /{prefix}
|
static String |
TEMPLATE_NEW
Defines the parse template for the "new" operation,
return a form for creating a new record,
typically /{prefix}/new
|
static String |
TEMPLATE_PREFIX |
static String |
TEMPLATE_SHOW
Defines the parse template for the "show" operation,
access a record OR POST operations related to a record,
typically /{prefix}/{id}
|
static String |
VALID_INPUT_CHARS
Defines the valid chars for a parser input (e.g. entity reference)
|
static String |
VALID_TEMPLATE_CHARS
Defines the valid chars for a template
|
static String |
VALID_TEMPLATE_CHARS_OUTGOING
Defines the valid template chars for an outgoing template (allows ?)
|
static String |
VALID_VAR_CHARS
Defines the valid chars for a replacement variable
|
| Constructor and Description |
|---|
TemplateParseUtil() |
| Modifier and Type | Method and Description |
|---|---|
static String[] |
findExtension(String input)
Find the extension from a string and return the string without the extension and the extension,
an extension is a period (".") followed by any number of non-periods,
the original input is returned as the 0th item in the array
returned array contains 3 strings: 0 = the original input string 1 = the string without the extension or the original if it has none 2 = the extension OR null if there is no extension |
static String |
getDefaultTemplate(String templateKey)
Get a default template for a specific template key
|
static String |
mergeTemplate(String template,
Map<String,String> segments)
Takes a template and replaces the segment keys with the segment values,
keys should not have {} around them yet as these will be added around each key
in the segments map
|
static TemplateParseUtil.ProcessedTemplate |
parseTemplate(String input,
List<TemplateParseUtil.PreProcessedTemplate> preprocessed)
Parse a string and attempt to match it to a template and then
return the match information along with all the parsed out keys and values
|
static TemplateParseUtil.PreProcessedTemplate |
preprocessTemplate(TemplateParseUtil.Template t)
process a template into a preprocessed template which can be cached
|
static List<TemplateParseUtil.PreProcessedTemplate> |
preprocessTemplates(List<TemplateParseUtil.Template> templates)
Process the templates before attempting to match them,
this is here so we can reduce the load of reprocessing the same templates over and over
|
static String |
validateOutgoingTemplate(String template)
Validates an outgoing template to make sure it is valid
|
static void |
validateTemplate(String template)
Validate a template, if invalid then an exception is thrown
|
static void |
validateTemplateKey(String templateKey)
Check if a templateKey is valid, if not then throws
IllegalArgumentException |
public static final char SEPARATOR
public static final char PERIOD
public static final String BRACES
public static final String PREFIX
public static final String ID
public static final String EXTENSION
public static final String DOT_EXTENSION
public static final String QUERY_STRING
public static final String QUESTION_QUERY_STRING
public static final String PREFIX_VARIABLE
public static final String TEMPLATE_PREFIX
public static final String DIRECT_PREFIX
public static final String DIRECT_PREFIX_SLASH
public static final String VALID_VAR_CHARS
public static final String VALID_INPUT_CHARS
public static final String VALID_TEMPLATE_CHARS
public static final String VALID_TEMPLATE_CHARS_OUTGOING
public static final String TEMPLATE_LIST
public static final String TEMPLATE_SHOW
public static final String TEMPLATE_NEW
public static final String TEMPLATE_EDIT
public static final String TEMPLATE_DELETE
public static final String[] PARSE_TEMPLATE_KEYS
public static final List<TemplateParseUtil.Template> defaultTemplates
public static final List<TemplateParseUtil.PreProcessedTemplate> defaultPreprocessedTemplates
public static void validateTemplateKey(String templateKey)
IllegalArgumentExceptiontemplateKey - a key from the set of template keys PARSE_TEMPLATE_KEYSpublic static String getDefaultTemplate(String templateKey)
templateKey - a key from the set of template keys PARSE_TEMPLATE_KEYSIllegalArgumentException - if the template key is invalidpublic static void validateTemplate(String template)
template - a parse templatepublic static String validateOutgoingTemplate(String template)
template - an outgoing template,
if starts with / then it will be used as is and redirected to,
otherwise it will have the direct URL prefixed and will be forwardedpublic static String mergeTemplate(String template, Map<String,String> segments)
template - a parse template with {variables} in itsegments - a map of all possible segment keys and values,
unused keys will be ignoredIllegalArgumentException - if all template variables cannot be replaced or template is empty/nullpublic static String[] findExtension(String input)
input - any stringpublic static TemplateParseUtil.ProcessedTemplate parseTemplate(String input, List<TemplateParseUtil.PreProcessedTemplate> preprocessed)
input - a string which we want to attempt to match to one of the templatespreprocessed - the analyzed templates to attempt to match in the order they should attempt the match,
can be a single template or multiples, use preprocessTemplates(List) to create this
(recommend caching the preprocessed templates to avoid reprocessing them over and over)public static List<TemplateParseUtil.PreProcessedTemplate> preprocessTemplates(List<TemplateParseUtil.Template> templates)
templates - the templates to attempt to preprocess, can be a single template or multiplespublic static TemplateParseUtil.PreProcessedTemplate preprocessTemplate(TemplateParseUtil.Template t)
t - the templateCopyright © 2003–2021 Sakai Project. All rights reserved.