hello,

I have posted twice this month a help message on the problem I am having. I 
guess I was unclear in my problem desc, because I got no answer. This is a 
technical problem related to the ded list, but maybe some user will have 
experienced the same.

I have a running turbine application, with a classical Screen -> Actions -> 
Templates flow.

I would like to make a portlet to plug that application into a jetspeed 
portal.

Therefore, I must modify the VelocityPortlet class that I find in the last 
Turbine CVS. (enclosed in that mail my source code)

I must modify this class, because otherwise my screens ( java classes ) are 
not getting called when the portlet is invoked. Only the .vm files are 
called in the current version.

The problem I have is that my first screen inherits from 
VelocitySecureScreen, and in the method isAuthorized, I have the following:

   boolean isAuthorized = false;

         AccessControlList acl = data.getACL();

         if (acl == null)
         {
             String previousTemplate = data.getScreenTemplate();

//                      System.out.println("screen template: " + 
previousTemplate);

             data.getSession().setAttribute(UI_KEY, previousTemplate);
             data.setScreenTemplate("Login.vm");
             return false;
         } else
         {
             return true;
         }

So, if the user is not logged in, I redirect the user toward a login 
screen. This causes an exception, and, moreover, I receive an exception 
because the Turbine engine doesn't find the default.vm layout template...

I think I have made some mistakes in the usage of the turbine framework, as 
default.vm jetspeed layout exists...

Could someone that understands how jetspeed work tell me what I can and 
what I cannot do with the Turbine API's, in the VelocityPortlet?

thanks a lot,

Stan.


Stanislas Pinte
Computer Consultant
/* ====================================================================
 * The Apache Software License, Version 1.1
 *
 * Copyright (c) 2000-2001 The Apache Software Foundation.  All rights
 * reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 *
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 *
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in
 *    the documentation and/or other materials provided with the
 *    distribution.
 *
 * 3. The end-user documentation included with the redistribution,
 *    if any, must include the following acknowledgment:
 *       "This product includes software developed by the
 *        Apache Software Foundation (http://www.apache.org/)."
 *    Alternately, this acknowledgment may appear in the software itself,
 *    if and wherever such third-party acknowledgments normally appear.
 *
 * 4. The names "Apache" and "Apache Software Foundation" and
 *     "Apache Jetspeed" must not be used to endorse or promote products
 *    derived from this software without prior written permission. For
 *    written permission, please contact [EMAIL PROTECTED]
 *
 * 5. Products derived from this software may not be called "Apache" or
 *    "Apache Jetspeed", nor may "Apache" appear in their name, without
 *    prior written permission of the Apache Software Foundation.
 *
 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 * ====================================================================
 *
 * This software consists of voluntary contributions made by many
 * individuals on behalf of the Apache Software Foundation.  For more
 * information on the Apache Software Foundation, please see
 * <http://www.apache.org/>.
 */

package org.apache.jetspeed.portal.portlets;

// Turbine stuff
import org.apache.turbine.util.RunData;
import org.apache.turbine.services.velocity.TurbineVelocity;
import org.apache.turbine.services.pull.TurbinePull;
import org.apache.turbine.modules.ActionLoader;
import org.apache.turbine.modules.ScreenLoader;

// Jetspeed stuff
import org.apache.jetspeed.portal.Portlet;
import org.apache.jetspeed.portal.portlets.AbstractPortlet;
import org.apache.jetspeed.portal.PortletException;
import org.apache.jetspeed.services.TemplateLocator;

import org.apache.turbine.modules.Screen;

// Ecs stuff
import org.apache.ecs.ConcreteElement;
import org.apache.ecs.StringElement;

// Velocity Stuff
import org.apache.velocity.context.Context;
import org.apache.turbine.util.Log;

/**
 * A Velocity based portlet implementation
 * 
 * @author <a href="mailto:[EMAIL PROTECTED]";>Roberto Carrasco</a>
 * @author <a href="mailto:[EMAIL PROTECTED]";>Rapha�l Luta</a>
 */
public class VelocityPortlet extends AbstractPortlet

{
    /**
    By default the data is non cacheable
    */
    public void init( ) throws PortletException
    {
        setCacheable( false );
    }

    public ConcreteElement getContent( RunData rundata )
    {

        //to remove...
        System.out.println("honey!!!!!!!!!!!!!!!!!!");

        // create a blank context and with all the global application
        // Pull Tools inside
        Context context = TurbineVelocity.getContext();
        context.put( "data", rundata );
        context.put( "portlet", this );
        context.put( "conf", this.getPortletConfig() );
        context.put( "skin", this.getPortletConfig().getPortletSkin() );
        
        String template = getPortletConfig().getInitParameter("template");
        
        if (template != null)
        {
            context.put("template",template); 
        }

        // Put the request and session based contexts
        TurbinePull.populateContext(context, rundata);
        
        String actionName = getPortletConfig().getInitParameter("action");
        
        //invoke the required action
        if (actionName != null)
        {
            // store the context so that the action can retrieve it
            Log.debug("VelocityPortlet found action "+actionName+" context "+context);
            rundata.getTemplateInfo().setTemplateContext( "VelocityPortletContext", 
context );

            // if there is an action with the same name in modules/actions/portlets 
exec it
            try
            {
                ActionLoader.getInstance().exec( rundata, actionName );
            }
            catch( Exception e)
            {
               Log.error( e.toString() );
            }
        }
 
        //either the action selected the template, or use the default template 
        // defined in the registry
        //If the context is not defined, I can try to invoke a turbine screen.

        //NOPE...in Turbine, I can have a vm template and a screen!
        //Anyway, the template entry cannot be null!!!!
        //I test that and log the error if found...

        if (context.get("template") == null)
            {
                Log.error( "invoking a Velocity template without having defined a 
\"template\" parameter!" );
            }
        
        
        //NOTE: it is possible that no screen got defined for that template
        //so we should be careful.
        
        //the screen name is the template name minus the ".vm"...
        String screenName = null;
        if (-1 != template.indexOf(".vm"))
            {
                screenName = template.substring(0, template.length()-3);
            } else
                {
                    screenName = template;
                }
        
        System.out.println("screen name: " + screenName);
        
        try
            {
                //I am not sure exec is the right method to call...I may not want
                //Turbine to take care of layout issues, as I want to let Jetspeed do 
that for me.

                ScreenLoader.getInstance().exec( rundata, screenName );
            }
        catch( Exception e)
            {
                e.printStackTrace();
                Log.error( e.toString() );
            }
        
                
        // generate the content
        String s = null;

        try
        {
            if (-1 == template.indexOf(".vm"))
                template = template + ".vm";

            System.out.println("template: " + template);

            String templatePath = TemplateLocator.locatePortletTemplate(rundata, 
template);

            System.out.println("template Path: " + templatePath);

            //The turbine velocity service expects an absolute file name,
            //and the TemplateLocator returns a relative one...
            s = TurbineVelocity.handleRequest(context, templatePath);
        }
        catch( Exception e)
        {
            s= e.toString();
        }
        
        TurbineVelocity.requestFinished(context);
        
        if (s == null) s = "";

        return new StringElement( s );
    }

}


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to