com.sapportals.portal.appintegrator.template_processor
Interface ITemplateProcessor


public interface ITemplateProcessor

The ITemplateProcessor Interface ITemplateProcessor defines methods to parse a template and to process its tag expressions. The Template Processing step substitutes the tag expressions by values stored in contexts where the context names must match the tag expressions.

Definitions:

  • A template is a string containing plain text sections as well as tags.
    Example: "This is a template with a simple <tag>."
  • A tag is a variable expression followed by an optional modifier sequence within angle brackets.
    Example: "surround tags always with <angle.brackets>"
  • A variable expression (or tag expression) is a non-empty set of varibales separated by dots.
    Example: "<tag.expression.with.multiple.variables>"
  • A variable is an identifier that is matched with entries in the context. If a varible name equals a context entry name, the tag is replaced by the value of the context entry.
  • A modifier sequence contains one or more modifiers separeted by blanks within square brackets. Modifiers are applied to the substitute of a processed tag expression in the order they appear.
    Example: This is a template with a <modified.tag[URL_ENC UPRCASE]>
  • A context is a data structure that stores name-value pairs like java.util.Hashtable. Contexts can be nested in opposite to hashtables.
  • A substitute of a tag expression is the result of a processed tag expression.
    Example: "<User.Name>" is the tag expression and
    Blair Pascal is the substitute.
  • Nested contexts are accessed by tag expressions, where the single varibales in the tag expression describe the "path" in the context tree. If a variable doesn't matche to a context, the tag is replaced with the empty string.

    Processed tag expressions can be automatically URLEncoded by placing a percent sign just before the ending angle bracket.

    Note: This approach is deprecated and the URL_ENC modifier should be used instead.
    Example: "<this.will.be.Urlencoded[URL_ENC]>"

    The slash is the escape character in templates. Angle brackets prefixed by the slash aren't treated as tags and substituted by themself (stripping the slash of course): < has to be escaped by /< and > has to be escaped by />

    Template grammar:

    template::= ( plain | tag )*
    tag::= "<" tagexpr ">" | "<" tagexpr ( modif_seq | encode )">"
    tagexpr::= simpletagexr ( "." simpletagexr )*
    simpletagexpr::= alpha alphanum*
    alpha::= "A" | ... | "Z" | "a" | ... | "z" | "_"
    alphanum::= alpha | "0" | ... | "9"
    reserved::= "<" | ">"
    unreserved::= ... all characters except the reserved ones
    plain::= unreserved*
    modif_seq::= ( alphanum+ " " )+
    encode::= "%" DEPRECATED

    Example:
    <Protocol>://<HostAddress>:<Port>/some/path?user=<User.Name[UPR_CASE]>&url=<HomeServer.url[URL_ENC UPR_CASE]>

    Copyright (c) SAP Portals Europe GmbH 2001

    Version:
    $Revision: #1 $

    Field Summary
    static java.lang.String MODIFIER_BASE64
              Modifier for UTF8 + BASE64: BASE64
    static java.lang.String MODIFIER_ESID
              Modifier for standard External Session ID: ESID
    static java.lang.String MODIFIER_HASH
              Modifier for Java-Hash function
    static java.lang.String MODIFIER_HTML_ESCAPE
              Modifier for HTML escaping: HTML_ESCAPE
    static java.lang.String MODIFIER_IF_FALSE
              Modifier for selective processing - negative (replace whole expression by empty string): IF_FALSE
    static java.lang.String MODIFIER_IF_TRUE
              Modifier for selective processing - positive (do nothing): IF_TRUE
    static java.lang.String MODIFIER_LOWERCASE
              Modifier for lowercase convertion: LOWERCASE
    static java.lang.String MODIFIER_MD5
              Modifier for UTF8 + MD5 hash: MD5
    static java.lang.String MODIFIER_MD5_BASE64
              Modifier for combination of UTF8 + MD5 + BASE64: MD5_BASE64
    static java.lang.String MODIFIER_PORTAL_URL
              Modifier for Portal URL: PORTAL_URL
    static java.lang.String MODIFIER_PROCESS_RECURSIVE
              Modifier for recursive template processing: PROCESS_RECURSIVE
    static java.lang.String MODIFIER_SAP_BOOL
              converts boolean values to SAP notation. true/1 -> 'X', false/0 -> '': SAP_BOOL
    static java.lang.String MODIFIER_SAP_ITS_NAMESPACE
              Modifier for SAP-ITS Namespace: SAP_ITS_NAMESPACE
    static java.lang.String MODIFIER_TRIM
              Modifier for string trimming: TRIM
    static java.lang.String MODIFIER_UPPERCASE
              Modifier for uppercase convertion: UPPERCASE
    static java.lang.String MODIFIER_URL_DECODE
              Modifier for url decoding: URL_DECODE
    static java.lang.String MODIFIER_URL_ENCODE
              Modifier for url encoding: URL_ENCODE
    static java.lang.String MODIFIER_URL64
              Modifier for UTF8 + URL64 - special SAP version of BASE64 that uses '-' instead of '/': URL64
    static java.lang.String MODIFIER_WAS_ESID
              Modifier for WAS related External Session ID: WAS_ESID
     
    Method Summary
     java.lang.String process(java.lang.String template, IAccessor root, com.sapportals.portal.prt.component.IPortalComponentRequest request, boolean errorMode)
              main parsing method which takes a root context and a template to process
     java.lang.String process(java.lang.String template, IAccessor root, java.util.Locale loc)
              Processes the given template using the given root context and the given locale.
     java.lang.String process(java.lang.String template, IAccessor root, java.util.Locale locale, boolean errorMode)
              main process method which takes a root context and a template to process
     

    Field Detail

    MODIFIER_URL_ENCODE

    public static final java.lang.String MODIFIER_URL_ENCODE
    Modifier for url encoding: URL_ENCODE

    MODIFIER_URL_DECODE

    public static final java.lang.String MODIFIER_URL_DECODE
    Modifier for url decoding: URL_DECODE

    MODIFIER_UPPERCASE

    public static final java.lang.String MODIFIER_UPPERCASE
    Modifier for uppercase convertion: UPPERCASE

    MODIFIER_LOWERCASE

    public static final java.lang.String MODIFIER_LOWERCASE
    Modifier for lowercase convertion: LOWERCASE

    MODIFIER_TRIM

    public static final java.lang.String MODIFIER_TRIM
    Modifier for string trimming: TRIM

    MODIFIER_HTML_ESCAPE

    public static final java.lang.String MODIFIER_HTML_ESCAPE
    Modifier for HTML escaping: HTML_ESCAPE

    MODIFIER_SAP_ITS_NAMESPACE

    public static final java.lang.String MODIFIER_SAP_ITS_NAMESPACE
    Modifier for SAP-ITS Namespace: SAP_ITS_NAMESPACE

    MODIFIER_SAP_BOOL

    public static final java.lang.String MODIFIER_SAP_BOOL
    converts boolean values to SAP notation. true/1 -> 'X', false/0 -> '': SAP_BOOL

    MODIFIER_MD5

    public static final java.lang.String MODIFIER_MD5
    Modifier for UTF8 + MD5 hash: MD5

    MODIFIER_BASE64

    public static final java.lang.String MODIFIER_BASE64
    Modifier for UTF8 + BASE64: BASE64

    MODIFIER_URL64

    public static final java.lang.String MODIFIER_URL64
    Modifier for UTF8 + URL64 - special SAP version of BASE64 that uses '-' instead of '/': URL64

    MODIFIER_MD5_BASE64

    public static final java.lang.String MODIFIER_MD5_BASE64
    Modifier for combination of UTF8 + MD5 + BASE64: MD5_BASE64

    MODIFIER_PROCESS_RECURSIVE

    public static final java.lang.String MODIFIER_PROCESS_RECURSIVE
    Modifier for recursive template processing: PROCESS_RECURSIVE

    MODIFIER_ESID

    public static final java.lang.String MODIFIER_ESID
    Modifier for standard External Session ID: ESID

    MODIFIER_WAS_ESID

    public static final java.lang.String MODIFIER_WAS_ESID
    Modifier for WAS related External Session ID: WAS_ESID

    MODIFIER_PORTAL_URL

    public static final java.lang.String MODIFIER_PORTAL_URL
    Modifier for Portal URL: PORTAL_URL

    MODIFIER_IF_TRUE

    public static final java.lang.String MODIFIER_IF_TRUE
    Modifier for selective processing - positive (do nothing): IF_TRUE

    MODIFIER_IF_FALSE

    public static final java.lang.String MODIFIER_IF_FALSE
    Modifier for selective processing - negative (replace whole expression by empty string): IF_FALSE

    MODIFIER_HASH

    public static final java.lang.String MODIFIER_HASH
    Modifier for Java-Hash function
    Method Detail

    process

    public java.lang.String process(java.lang.String template,
                                    IAccessor root,
                                    java.util.Locale loc)
                             throws TemplateParserException
    Processes the given template using the given root context and the given locale. The tag expressions inside the template are replaced by the corresponding entries of the context. Contexts can contain terminal values (which may have a locale) or nested contexts. Error mode is on.
    Parameters:
    template - the template that is to be processed
    root - the root context
    loc - the locale to be used when context terminals are locale depended
    Returns:
    the processed template
    Throws:
    TemplateParserException, - if parsing fails (due to invalid template for example)
    See Also:
    IAccessor, ITemplateProcessor

    process

    public java.lang.String process(java.lang.String template,
                                    IAccessor root,
                                    java.util.Locale locale,
                                    boolean errorMode)
                             throws java.lang.NullPointerException,
                                    TemplateParserException
    main process method which takes a root context and a template to process
    Parameters:
    template - the template that is to be processed
    root - the root context
    locale - the locale for language depended properties
    errorMode - if true, invalid tag expressions result in an exception, if false, invalid tag expressions are replaced by the empty word.
    Returns:
    the processed template
    Throws:
    NullPointerException, - if either template or root is null
    TemplateParserException -  

    process

    public java.lang.String process(java.lang.String template,
                                    IAccessor root,
                                    com.sapportals.portal.prt.component.IPortalComponentRequest request,
                                    boolean errorMode)
                             throws java.lang.NullPointerException,
                                    TemplateParserException
    main parsing method which takes a root context and a template to process
    Parameters:
    template - the template that is to be processed
    root - the root context
    request - Portal Component Request
    errorMode - if true, invalid tag expressions result in an exception, if false, invalid tag expressions are replaced by the empty word.
    Returns:
    the processed template
    Throws:
    NullPointerException, - if either template or root is null
    TemplateParserException -