Package org.apache.velocity.context

Examples of org.apache.velocity.context.Context


     * @param data Turbine information.
     * @exception Exception, a generic exception.
     */
    protected void doBuildBeforeAction(RunData data) throws Exception
    {
        Context context = TurbineVelocity.getContext(data);
        data.getTemplateInfo()
            .setTemplateContext(VelocityService.CONTEXT, context);
    }
View Full Code Here


     * Allows the VelocityService to peform post-request actions.
     * (releases the (non-global) tools in the context for reuse later)
     */
    protected void doPostBuild(RunData data) throws Exception
    {
        Context context = TurbineVelocity.getContext(data);
        TurbineVelocity.requestFinished(context);
    }
View Full Code Here

    public Context initControlContext()
    {
        /*
         * Create a new Velocity context.
         */
        Context context = new VelocityContext();
        context.put("targetDatabase", targetDatabase);
        context.put("targetPlatform", targetPlatform);
        context.put("databaseName", databaseName);
        context.put("databaseUser", databaseUser);
        context.put("databasePassword", databasePassword);
        context.put("databaseHost", databaseHost);
        return context;
    }
View Full Code Here

    public Context initControlContext()
    {
        /*
         * Create a new Velocity context.
         */
        Context context = new VelocityContext();

        /*
         * Transform the XML database schema into an
         * object that represents our model.
         */
        XmlToAppData xmlParser = new XmlToAppData();
        app = xmlParser.parseFile(xmlFile);

        Database db = app.getDatabase(databaseName);
        if (db == null)
        {
            db = app.getDatabases()[0];
        }
        try
        {
            XmlToData dataXmlParser = new XmlToData(db, dataDTD);
            List data = dataXmlParser.parseFile(dataXmlFile);
            context.put("data", data);
        }
        catch (Exception e)
        {
            System.err.println("Exception parsing data XML:");
            e.printStackTrace();
        }
        /*
         * Place our model in the context.
         */
        context.put("appData", app);

        /*
         * Place the target database in the context.
         */
        context.put("targetDatabase", targetDatabase);

        return context;
    }
View Full Code Here

     * @exception Exception, a generic exception.
     */
    public ConcreteElement buildTemplate( RunData data )
        throws Exception
    {
        Context context = TurbineVelocity.getContext( data );

        String templateName = data.getTemplateInfo().getNavigationTemplate();

        StringElement output = new StringElement();
        output.setFilterState(false);
View Full Code Here

    public Context initControlContext()
    {
        /*
         * Create a new Velocity context.
         */
        Context context = new VelocityContext();

        /*
         * Transform the XML database schema into an
         * object that represents our model.
         */
        XmlToAppData xmlParser = new XmlToAppData();
        app = xmlParser.parseFile(xmlFile);

        /*
         * Place our model in the context.
         */
        Database dbm = app.getDatabase(databaseName);
        if (dbm == null)
        {
            dbm = app.getDatabases()[0];
        }
        context.put("databaseModel", dbm);

        context.put("dataset", "all");

        System.err.println("Your DB settings are:");
        System.err.println("driver : " + databaseDriver);
        System.err.println("URL : " + databaseUrl);
        System.err.println("user : " + databaseUser);
        System.err.println("password : " + databasePassword);

        try
        {
            Class.forName(databaseDriver);
            System.err.println("DB driver sucessfuly instantiated");

            // Attemtp to connect to a database.

            Connection conn = DriverManager.getConnection(
                    databaseUrl, databaseUser, databasePassword);

            System.err.println("DB connection established");
            context.put("tableTool", new TableTool(conn));
        }
        catch (SQLException se)
        {
            System.err.println("SQLException while connecting to DB:");
            se.printStackTrace();
View Full Code Here

     */
    public ConcreteElement buildTemplate( RunData data ) throws Exception
    {
        StringElement output = null;
        String screenData = null;
        Context context = TurbineVelocity.getContext(data);

        // This will already be properly set and will not be null
        // because of TemplateSessionValidator.
        String templateName = TurbineTemplate.getScreenTemplateName(
            data.getTemplateInfo().getScreenTemplate() );

        // Template service adds the leading slash, but make it sure.
        if ((templateName.length() > 0) &&
            (templateName.charAt(0) != '/'))
        {
            templateName = '/' + templateName;
        }

        try
        {
            // if a layout has been defined return the results, otherwise
            // send the results directly to the output stream.
            if (getLayout(data) == null)
            {
                TurbineVelocity.handleRequest(context,
                    "screens" + templateName,
                    data.getResponse().getOutputStream());
            }
            else
            {
                screenData = TurbineVelocity
                    .handleRequest(context,"screens" + templateName);
            }
        }
        catch (Exception e)
        {
            // If there is an error, build a $processingException and
            // attempt to call the error.vm template in the screens
            // directory.
            context.put ( "processingException", e.toString() );
            context.put ( "stackTrace", StringUtils.stackTrace(e) );
            templateName = TurbineResources.getString(
                "template.error", "/error.vm");
            if ((templateName.length() > 0) &&
                (templateName.charAt(0) != '/'))
            {
View Full Code Here

    {
        /*
         * Attempt to get it from the data first.  If it doesn't
         * exist, create it and then stuff it into the data.
         */
        Context context = (Context)
            data.getTemplateInfo().getTemplateContext(VelocityService.CONTEXT);
       
        if (context == null)
        {
            context = getContext();
            context.put ( "data", data );

            if (pullModelActive)
            {
                /*
                 * Populate the toolbox with request scope, session scope
View Full Code Here

     * @exception MessagingException.
     */
    public void send()
        throws MessagingException
    {
        Context context = getContext(data);
        context.put("mail",this);

        String htmlbody = "";
        String textbody = "";

        // Process the templates.
View Full Code Here

     */
    private static final Context getContext(RunData data)
    {
        // Attempt to get it from the RunData first.  If it doesn't
        // exist, create it and then stuff it into the RunData.
        Context vc = (Context)data.getTemplateInfo()
            .getTemplateContext(VelocityService.CONTEXT);
        if (vc == null)
        {
            vc = TurbineVelocity.getContext(data);
            data.getTemplateInfo()
View Full Code Here

TOP

Related Classes of org.apache.velocity.context.Context

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.