org.apache.velocity.exception.TemplateInitException Java Examples

The following examples show how to use org.apache.velocity.exception.TemplateInitException. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Include.java    From velocity-engine with Apache License 2.0 6 votes vote down vote up
/**
 *  simple init - init the tree and get the elementKey from
 *  the AST
 * @param rs
 * @param context
 * @param node
 * @throws TemplateInitException
 */
public void init(RuntimeServices rs, InternalContextAdapter context,
                 Node node)
    throws TemplateInitException
{
    super.init( rs, context, node );

    /*
     *  get the msg, and add the space so we don't have to
     *  do it each time
     */
    outputMsgStart = rsvc.getString(RuntimeConstants.ERRORMSG_START);
    outputMsgStart = outputMsgStart + " ";

    outputMsgEnd = rsvc.getString(RuntimeConstants.ERRORMSG_END );
    outputMsgEnd = " " + outputMsgEnd;
}
 
Example #2
Source File: SimpleNode.java    From velocity-engine with Apache License 2.0 6 votes vote down vote up
/**
 * @throws TemplateInitException
 * @see org.apache.velocity.runtime.parser.node.Node#init(org.apache.velocity.context.InternalContextAdapter, java.lang.Object)
 */
public Object init( InternalContextAdapter context, Object data) throws TemplateInitException
{
    /*
     * hold onto the RuntimeServices
     */

    rsvc = (RuntimeServices) data;
    log = rsvc.getLog("rendering");

    int i, k = jjtGetNumChildren();

    for (i = 0; i < k; i++)
    {
        jjtGetChild(i).init( context, data);
    }

    line = first.beginLine;
    column = first.beginColumn;

    return data;
}
 
Example #3
Source File: BlockMacro.java    From velocity-engine with Apache License 2.0 6 votes vote down vote up
/**
 * Initializes the directive.
 *
 * @param rs
 * @param macroName
 * @param context
 * @param node
 * @throws TemplateInitException
 */
public void init(RuntimeServices rs, String macroName, InternalContextAdapter context, Node node)
    throws TemplateInitException
{
    this.name = macroName;

    super.init(rs, context, node);

    // get name of the reference that refers to AST block passed to block macro call
    key = rsvc.getString(RuntimeConstants.VM_BODY_REFERENCE, "bodyContent");

    // use the macro max depth for bodyContent max depth as well
    maxDepth = rsvc.getInt(RuntimeConstants.VM_MAX_DEPTH);

    macro = new RuntimeMacro();
    macro.setLocation(getLine(), getColumn(), getTemplate());
    macro.init(rsvc, name, context, node);
}
 
Example #4
Source File: ASTText.java    From velocity-engine with Apache License 2.0 6 votes vote down vote up
/**
 * @see org.apache.velocity.runtime.parser.node.SimpleNode#init(org.apache.velocity.context.InternalContextAdapter, java.lang.Object)
 */
public Object init( InternalContextAdapter context, Object data)
throws TemplateInitException
{
    StringBuilder builder = new StringBuilder();
    Token t = getFirstToken();
    for (; t != getLastToken(); t = t.next)
    {
        builder.append(NodeUtils.tokenLiteral(parser, t));
    }
    builder.append(NodeUtils.tokenLiteral(parser, t));
    ctext = builder.toString();

    cleanupParserAndTokens();

    return data;
}
 
Example #5
Source File: ASTIdentifier.java    From velocity-engine with Apache License 2.0 6 votes vote down vote up
/**
 *  simple init - don't do anything that is context specific.
 *  just get what we need from the AST, which is static.
 * @param context
 * @param data
 * @return The data object.
 * @throws TemplateInitException
 */
public  Object init(InternalContextAdapter context, Object data)
    throws TemplateInitException
{
    super.init(context, data);

    identifier = rsvc.useStringInterning() ? getFirstToken().image.intern() : getFirstToken().image;

    uberInfo = new Info(getTemplateName(), getLine(), getColumn());

    strictRef = rsvc.getBoolean(RuntimeConstants.RUNTIME_REFERENCES_STRICT, false);

    saveTokenImages();
    cleanupParserAndTokens();

    return data;
}
 
Example #6
Source File: ASTTextblock.java    From velocity-engine with Apache License 2.0 6 votes vote down vote up
/**
 * @see org.apache.velocity.runtime.parser.node.SimpleNode#init(org.apache.velocity.context.InternalContextAdapter, java.lang.Object)
 */
public Object init( InternalContextAdapter context, Object data)
throws TemplateInitException
{
    Token t = getFirstToken();

    String text = t.image;

    // t.image is in format: #[[ <string> ]]#
    // we must strip away the hash tags
    text = text.substring(START.length(), text.length() - END.length());

    ctext = text.toCharArray();

    cleanupParserAndTokens();

    return data;
}
 
Example #7
Source File: ASTMethod.java    From velocity-engine with Apache License 2.0 6 votes vote down vote up
/**
 *  simple init - init our subtree and get what we can from
 *  the AST
 * @param context
 * @param data
 * @return The init result
 * @throws TemplateInitException
 */
public Object init(  InternalContextAdapter context, Object data)
    throws TemplateInitException
{
    super.init(  context, data );

    /*
     * make an uberinfo - saves new's later on
     */

    uberInfo = new Info(getTemplateName(),
            getLine(),getColumn());
    /*
     *  this is about all we can do
     */

    methodName = getFirstToken().image;
    paramCount = jjtGetNumChildren() - 1;

    strictRef = rsvc.getBoolean(RuntimeConstants.RUNTIME_REFERENCES_STRICT, false);
    logOnInvalid = rsvc.getBoolean(RuntimeConstants.RUNTIME_LOG_METHOD_CALL_LOG_INVALID, true);

    cleanupParserAndTokens();

    return data;
}
 
Example #8
Source File: Template.java    From velocity-engine with Apache License 2.0 5 votes vote down vote up
/**
 *  initializes the document.  init() is not longer
 *  dependant upon context, but we need to let the
 *  init() carry the template name down through for VM
 *  namespace features
 * @throws TemplateInitException When a problem occurs during the document initialization.
 */
public void initDocument()
throws TemplateInitException
{
    /*
     *  send an empty InternalContextAdapter down into the AST to initialize it
     */

    InternalContextAdapterImpl ica = new InternalContextAdapterImpl(  new VelocityContext() );

    try
    {
        /*
         *  put the current template name on the stack
         */

        ica.pushCurrentTemplateName( name );
        ica.setCurrentResource( this );

        /*
         *  init the AST
         */

        ((SimpleNode)data).init( ica, rsvc);

        provideScope = rsvc.isScopeControlEnabled(scopeName);
    }
    finally
    {
        /*
         *  in case something blows up...
         *  pull it off for completeness
         */

        ica.popCurrentTemplateName();
        ica.setCurrentResource( null );
    }

}
 
Example #9
Source File: ASTFalse.java    From velocity-engine with Apache License 2.0 5 votes vote down vote up
/**
 * @throws TemplateInitException
 * @see org.apache.velocity.runtime.parser.node.Node#init(org.apache.velocity.context.InternalContextAdapter, java.lang.Object)
 */
public Object init( InternalContextAdapter context, Object data) throws TemplateInitException
{
	Object obj = super.init(context, data);
	cleanupParserAndTokens(); // drop reference to Parser and all JavaCC Tokens
	return obj;
}
 
Example #10
Source File: ASTIntegerRange.java    From velocity-engine with Apache License 2.0 5 votes vote down vote up
/**
 * @throws TemplateInitException
 * @see org.apache.velocity.runtime.parser.node.Node#init(org.apache.velocity.context.InternalContextAdapter, java.lang.Object)
 */
public Object init( InternalContextAdapter context, Object data) throws TemplateInitException
{
	Object obj = super.init(context, data);
	cleanupParserAndTokens(); // drop reference to Parser and all JavaCC Tokens
	return obj;
}
 
Example #11
Source File: ASTObjectArray.java    From velocity-engine with Apache License 2.0 5 votes vote down vote up
/**
 * @throws TemplateInitException
 * @see org.apache.velocity.runtime.parser.node.Node#init(org.apache.velocity.context.InternalContextAdapter, java.lang.Object)
 */
public Object init( InternalContextAdapter context, Object data) throws TemplateInitException
{
	Object obj = super.init(context, data);
	cleanupParserAndTokens(); // drop reference to Parser and all JavaCC Tokens
	return obj;
}
 
Example #12
Source File: ASTModNode.java    From velocity-engine with Apache License 2.0 5 votes vote down vote up
/**
 * @throws TemplateInitException
 * @see org.apache.velocity.runtime.parser.node.Node#init(org.apache.velocity.context.InternalContextAdapter, java.lang.Object)
 */
public Object init( InternalContextAdapter context, Object data) throws TemplateInitException
{
	Object obj = super.init(context, data);
	cleanupParserAndTokens(); // drop reference to Parser and all JavaCC Tokens
	return obj;
}
 
Example #13
Source File: ASTNegateNode.java    From velocity-engine with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
public Object init(InternalContextAdapter context, Object data) throws TemplateInitException
{
    super.init(context, data);
    /* save a literal image now (needed in case of error) */
    strictMode = rsvc.getBoolean(RuntimeConstants.STRICT_MATH, false);
    cleanupParserAndTokens();
    return data;
}
 
Example #14
Source File: ASTNotNode.java    From velocity-engine with Apache License 2.0 5 votes vote down vote up
/**
 * @throws TemplateInitException
 * @see org.apache.velocity.runtime.parser.node.Node#init(org.apache.velocity.context.InternalContextAdapter, java.lang.Object)
 */
public Object init( InternalContextAdapter context, Object data) throws TemplateInitException
{
	Object obj = super.init(context, data);
	cleanupParserAndTokens(); // drop reference to Parser and all JavaCC Tokens
	return obj;
}
 
Example #15
Source File: ASTMathNode.java    From velocity-engine with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
public Object init(InternalContextAdapter context, Object data) throws TemplateInitException
{
    super.init(context, data);
    strictMode = rsvc.getBoolean(RuntimeConstants.STRICT_MATH, false);
    cleanupParserAndTokens();
    return data;
}
 
Example #16
Source File: ASTTrue.java    From velocity-engine with Apache License 2.0 5 votes vote down vote up
/**
 * @throws TemplateInitException
 * @see org.apache.velocity.runtime.parser.node.Node#init(org.apache.velocity.context.InternalContextAdapter, java.lang.Object)
 */
public Object init( InternalContextAdapter context, Object data) throws TemplateInitException
{
	Object obj = super.init(context, data);
	cleanupParserAndTokens(); // drop reference to Parser and all JavaCC Tokens
	return obj;
}
 
Example #17
Source File: ASTIndex.java    From velocity-engine with Apache License 2.0 5 votes vote down vote up
/**
 * @param context
 * @param data
 * @return data
 * @throws TemplateInitException
 */
public Object init(InternalContextAdapter context, Object data)
    throws TemplateInitException
{
    super.init(context, data);
    strictRef = rsvc.getBoolean(RuntimeConstants.RUNTIME_REFERENCES_STRICT, false);
    cleanupParserAndTokens();
    return data;
}
 
Example #18
Source File: ASTFloatingPointLiteral.java    From velocity-engine with Apache License 2.0 5 votes vote down vote up
/**
 *  Initialization method - doesn't do much but do the object
 *  creation.  We only need to do it once.
 * @param context
 * @param data
 * @return The data object.
 * @throws TemplateInitException
 */
public Object init( InternalContextAdapter context, Object data)
    throws TemplateInitException
{
    /*
     *  init the tree correctly
     */

    super.init( context, data );

    /**
     * Determine the size of the item and make it a Double or BigDecimal as appropriate.
     */
     String str = getFirstToken().image;
     try
     {
         value = new Double( str );

     } catch ( NumberFormatException E1 )
     {

        // if there's still an Exception it will propqgate out
        value = new BigDecimal( str );

    }
    cleanupParserAndTokens();

    return data;
}
 
Example #19
Source File: Parse.java    From velocity-engine with Apache License 2.0 5 votes vote down vote up
/**
 * Init's the #parse directive.
 * @param rs
 * @param context
 * @param node
 * @throws TemplateInitException
 */
public void init(RuntimeServices rs, InternalContextAdapter context, Node node)
    throws TemplateInitException
{
    super.init(rs, context, node);

    this.maxDepth = rsvc.getInt(RuntimeConstants.PARSE_DIRECTIVE_MAXDEPTH, 10);

    strictRef = rsvc.getBoolean(RuntimeConstants.RUNTIME_REFERENCES_STRICT, false);
}
 
Example #20
Source File: Directive.java    From velocity-engine with Apache License 2.0 5 votes vote down vote up
/**
 * How this directive is to be initialized.
 * @param rs
 * @param context
 * @param node
 * @throws TemplateInitException
 */
public void init( RuntimeServices rs, InternalContextAdapter context,
                  Node node)
    throws TemplateInitException
{
    rsvc = rs;
    log = rsvc.getLog("directive." + getName());

    provideScope = rsvc.isScopeControlEnabled(getScopeName());
}
 
Example #21
Source File: Block.java    From velocity-engine with Apache License 2.0 5 votes vote down vote up
/**
 *  simple init - get the key
 *  @param rs
 *  @param context
 *  @param node
 */
public void init(RuntimeServices rs, InternalContextAdapter context, Node node)
    throws TemplateInitException
{
    super.init(rs, context, node);

    log = rsvc.getLog();

    /**
     * No checking is done. We just grab the last child node and assume
     * that it's the block!
     */
    block = node.jjtGetChild(node.jjtGetNumChildren() - 1);
}
 
Example #22
Source File: Define.java    From velocity-engine with Apache License 2.0 5 votes vote down vote up
/**
 *  simple init - get the key
 */
public void init(RuntimeServices rs, InternalContextAdapter context, Node node)
    throws TemplateInitException
{
    super.init(rs, context, node);

    // the first child is the block name (key), the second child is the block AST body
    if ( node.jjtGetNumChildren() != 2 )
    {
        throw new VelocityException("parameter missing: block name at "
             + StringUtils.formatFileString(this),
            null,
            rsvc.getLogContext().getStackTrace());
    }

    /*
     * first token is the name of the block. We don't even check the format,
     * just assume it looks like this: $block_name. Should we check if it has
     * a '$' or not?
     */
    key = node.jjtGetChild(0).getFirstTokenImage().substring(1);

    /*
     * default max depth of two is used because intentional recursion is
     * unlikely and discouraged, so make unintentional ones end fast
     */
    maxDepth = rsvc.getInt(RuntimeConstants.DEFINE_DIRECTIVE_MAXDEPTH, 2);
}
 
Example #23
Source File: For.java    From velocity-engine with Apache License 2.0 5 votes vote down vote up
public void init(RuntimeServices rs, InternalContextAdapter context, Node node)
    throws TemplateInitException
{
  super.init(rs, context, node);
  // If we have more then 3 argument then the user has specified an
  // index value, i.e.; #foreach($a in $b index $c)
  if (node.jjtGetNumChildren() > 4)
  {
      // The index variable name is at position 4
      counterName = ((ASTReference) node.jjtGetChild(4)).getRootString();
      // The count value always starts at 0 when using an index.
      counterInitialValue = 0;
  }
}
 
Example #24
Source File: Macro.java    From velocity-engine with Apache License 2.0 5 votes vote down vote up
/**
 * @see org.apache.velocity.runtime.directive.Directive#init(org.apache.velocity.runtime.RuntimeServices, org.apache.velocity.context.InternalContextAdapter, org.apache.velocity.runtime.parser.node.Node)
 */
public void init(RuntimeServices rs, InternalContextAdapter context,
                 Node node)
   throws TemplateInitException
{
    super.init(rs, context, node);


    // Add this macro to the VelocimacroManager now that it has been initialized.
    List<MacroArg> macroArgs = getArgArray(node, rsvc);
    int numArgs = node.jjtGetNumChildren();
    rsvc.addVelocimacro(macroArgs.get(0).name, node.jjtGetChild(numArgs - 1),
        macroArgs, node.getTemplate());
}
 
Example #25
Source File: ASTElseStatement.java    From velocity-engine with Apache License 2.0 5 votes vote down vote up
/**
 * @throws TemplateInitException
 * @see org.apache.velocity.runtime.parser.node.Node#init(org.apache.velocity.context.InternalContextAdapter, java.lang.Object)
 */
public Object init( InternalContextAdapter context, Object data) throws TemplateInitException
{
	Object obj = super.init(context, data);
	cleanupParserAndTokens(); // drop reference to Parser and all JavaCC Tokens
	return obj;
}
 
Example #26
Source File: JavaScriptCompressorDirective.java    From htmlcompressor with Apache License 2.0 5 votes vote down vote up
@Override
public void init(RuntimeServices rs, InternalContextAdapter context, Node node) throws TemplateInitException {
	super.init(rs, context, node);
	log = rs.getLog();
	
	//set compressor properties
	enabled = rs.getBoolean("userdirective.compressJs.enabled", true);
	jsCompressor = rs.getString("userdirective.compressHtml.jsCompressor", HtmlCompressor.JS_COMPRESSOR_YUI);
	yuiJsNoMunge = rs.getBoolean("userdirective.compressJs.yuiJsNoMunge", false);
	yuiJsPreserveAllSemiColons = rs.getBoolean("userdirective.compressJs.yuiJsPreserveAllSemiColons", false);
	yuiJsLineBreak = rs.getInt("userdirective.compressJs.yuiJsLineBreak", -1);
	closureOptLevel = rs.getString("userdirective.compressHtml.closureOptLevel", ClosureJavaScriptCompressor.COMPILATION_LEVEL_SIMPLE);
}
 
Example #27
Source File: CssCompressorDirective.java    From htmlcompressor with Apache License 2.0 5 votes vote down vote up
@Override
public void init(RuntimeServices rs, InternalContextAdapter context, Node node) throws TemplateInitException {
	super.init(rs, context, node);
	log = rs.getLog();
	
	//set compressor properties
	enabled = rs.getBoolean("userdirective.compressCss.enabled", true);
	yuiCssLineBreak = rs.getInt("userdirective.compressCss.yuiCssLineBreak", -1);
}
 
Example #28
Source File: XmlCompressorDirective.java    From htmlcompressor with Apache License 2.0 5 votes vote down vote up
@Override
public void init(RuntimeServices rs, InternalContextAdapter context, Node node) throws TemplateInitException {
	super.init(rs, context, node);
	log = rs.getLog();
	
	//set compressor properties
	xmlCompressor.setEnabled(rs.getBoolean("userdirective.compressXml.enabled", true));
	xmlCompressor.setRemoveComments(rs.getBoolean("userdirective.compressXml.removeComments", true));
	xmlCompressor.setRemoveIntertagSpaces(rs.getBoolean("userdirective.compressXml.removeIntertagSpaces", true));
}
 
Example #29
Source File: ASTLogicalOperator.java    From velocity-engine with Apache License 2.0 5 votes vote down vote up
/**
 * @throws TemplateInitException
 * @see org.apache.velocity.runtime.parser.node.Node#init(org.apache.velocity.context.InternalContextAdapter, java.lang.Object)
 */
public Object init( InternalContextAdapter context, Object data) throws TemplateInitException
{
    Object obj = super.init(context, data);
    cleanupParserAndTokens(); // drop reference to Parser and all JavaCC Tokens
    return obj;
}
 
Example #30
Source File: ASTAssignment.java    From velocity-engine with Apache License 2.0 5 votes vote down vote up
/**
 * @throws TemplateInitException
 * @see org.apache.velocity.runtime.parser.node.Node#init(org.apache.velocity.context.InternalContextAdapter, java.lang.Object)
 */
public Object init( InternalContextAdapter context, Object data) throws TemplateInitException
{
	Object obj = super.init(context, data);
	cleanupParserAndTokens(); // drop reference to Parser and all JavaCC Tokens
	return obj;
}