portals-jetspeed-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From raph...@apache.org
Subject cvs commit: jakarta-jetspeed/src/java/org/apache/jetspeed/util URILookup.java
Date Wed, 06 Jun 2001 22:29:11 GMT
raphael     01/06/06 15:29:11

  Modified:    src/java/org/apache/jetspeed/modules/actions JLoginUser.java
                        JetspeedSessionValidator.java
               src/java/org/apache/jetspeed/modules/pages
                        JetspeedTemplatePage.java
               src/java/org/apache/jetspeed/portal BasePortletConfig.java
                        BasePortletSet.java
               src/java/org/apache/jetspeed/portal/controllers
                        CardPortletController.java
                        GridPortletController.java
               src/java/org/apache/jetspeed/services/profiler
                        JetspeedProfilerService.java ProfilerService.java
               src/java/org/apache/jetspeed/util URILookup.java
  Log:
  [fix] allow the portal to use either JSP or Velocity templates
  
  Revision  Changes    Path
  1.12      +2 -1      jakarta-jetspeed/src/java/org/apache/jetspeed/modules/actions/JLoginUser.java
  
  Index: JLoginUser.java
  ===================================================================
  RCS file: /home/cvs/jakarta-jetspeed/src/java/org/apache/jetspeed/modules/actions/JLoginUser.java,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- JLoginUser.java	2001/05/07 15:39:27	1.11
  +++ JLoginUser.java	2001/06/06 22:28:53	1.12
  @@ -65,6 +65,7 @@
   import org.apache.turbine.util.RunData;
   import org.apache.turbine.services.localization.Localization;
   import org.apache.turbine.services.resources.TurbineResources;
  +import org.apache.turbine.services.template.TurbineTemplate;
   import org.apache.turbine.services.db.TurbineDB;
   import org.apache.turbine.util.db.Criteria;
   import org.apache.turbine.util.db.pool.DBConnection;
  @@ -114,7 +115,7 @@
               String button1 = data.getParameters().getString ( "submit1", null );
               if ( button1 != null && button1.equalsIgnoreCase("Cancel") )
               {
  -                data.setScreen (TurbineResources.getString( "screen.homepage" ));
  +                data.setScreenTemplate(TurbineTemplate.getDefaultScreen());
                   return;
               }
               
  
  
  
  1.7       +20 -47    jakarta-jetspeed/src/java/org/apache/jetspeed/modules/actions/JetspeedSessionValidator.java
  
  Index: JetspeedSessionValidator.java
  ===================================================================
  RCS file: /home/cvs/jakarta-jetspeed/src/java/org/apache/jetspeed/modules/actions/JetspeedSessionValidator.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- JetspeedSessionValidator.java	2001/06/04 17:44:24	1.6
  +++ JetspeedSessionValidator.java	2001/06/06 22:28:53	1.7
  @@ -60,7 +60,7 @@
   import org.apache.turbine.util.RunData;
   import org.apache.turbine.util.Log;
   import org.apache.turbine.services.security.TurbineSecurity;
  -import org.apache.turbine.modules.actions.sessionvalidator.SessionValidator;
  +import org.apache.turbine.modules.actions.sessionvalidator.TemplateSessionValidator;
   import org.apache.turbine.services.resources.TurbineResources;
   import org.apache.jetspeed.services.rundata.JetspeedRunData;
   import org.apache.jetspeed.services.Profiler;
  @@ -76,9 +76,9 @@
   @see org.apache.turbine.actions.SessionValidator
   @author <a href="mailto:ingo@raleigh.ibm.com">Ingo Schuster</a>
   @author <a href="mailto:raphael@apache.org">RaphaŽl Luta</a>
  -@version $Id: JetspeedSessionValidator.java,v 1.6 2001/06/04 17:44:24 raphael Exp $
  +@version $Id: JetspeedSessionValidator.java,v 1.7 2001/06/06 22:28:53 raphael Exp $
   */
  -public class JetspeedSessionValidator extends SessionValidator
  +public class JetspeedSessionValidator extends TemplateSessionValidator
   {
   
       /**
  @@ -89,49 +89,12 @@
        */
       public void doPerform( RunData data ) throws Exception
       {
  -        data.populate();
  -        
  -        // The user may have not logged in, so create a "guest" user.
  -        if ( data.getUser() == null )
  -        {
  -            data.setUser(TurbineSecurity.getAnonymousUser());
  -            data.save();
  -        }
  -
  -        // Get the locale store it in the user object
  -        Locale locale = LocaleDetector.getLocale(data);
  -        if (locale == null) {
  -            locale = new Locale(
  -                     TurbineResources.getString("locale.default.language", "en"),
  -                     TurbineResources.getString("locale.default.country", "US"));
  -        }
  -        
  -        data.getUser().setTemp("locale", locale);
  -        
  -        // make sure we have some way to return a response
  -        if ( !data.hasScreen() &&
  -            data.getTemplateInfo().getScreenTemplate() == null )
  -        {
  -            String template = TurbineResources.getString("template.homepage");
  -            if (template != null)
  -            {
  -                data.getTemplateInfo().setScreenTemplate(template);
  -            }
  -            else
  -            {
  -                data.setScreen( TurbineResources
  -                    .getString("screen.homepage") );
  -            }
  -        }
  -        
  -        // we do not want to allow both a screen and template parameter.
  -        // The template parameter is dominant.
  -        if ( data.getTemplateInfo().getScreenTemplate() != null )
  -        {
  -            data.setScreen(null);
  -        }
  -        
  -        // define Jetspeed specific properties
  +        //first, invoke our superclass action to make sure 
  +        //we follow Turbine evolutions
  +         super.doPerform(data);         
  +         
  +        // now, define Jetspeed specific properties, using the customized
  +        // RunData properties
           JetspeedRunData jdata = null;
           
           try
  @@ -144,8 +107,18 @@
                          +"please verify the RunData factory settings");
               return;
           }
  +        
  +        // Get the locale store it in the user object
  +        Locale locale = LocaleDetector.getLocale(data);
  +        if (locale == null) {
  +            locale = new Locale(
  +                     TurbineResources.getString("locale.default.language", "en"),
  +                     TurbineResources.getString("locale.default.country", "US"));
  +        }
  +        
  +        data.getUser().setTemp("locale", locale);
           
  -        // now set any jetspeed specific properties;
  +        // get the profile and store it in the RunData
           Profile newProfile = Profiler.getProfile(jdata);
           Profile currentProfile = jdata.getProfile();
           
  
  
  
  1.13      +27 -33    jakarta-jetspeed/src/java/org/apache/jetspeed/modules/pages/JetspeedTemplatePage.java
  
  Index: JetspeedTemplatePage.java
  ===================================================================
  RCS file: /home/cvs/jakarta-jetspeed/src/java/org/apache/jetspeed/modules/pages/JetspeedTemplatePage.java,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- JetspeedTemplatePage.java	2001/06/04 17:21:07	1.12
  +++ JetspeedTemplatePage.java	2001/06/06 22:28:56	1.13
  @@ -125,7 +125,7 @@
    *
    * @author <a href="mailto:john.mcnally@clearink.com">John D. McNally</a>
    * @author <a href="mailto:mbryson@mont.mindspring.com">Dave Bryson</a>
  - * @version $Id: JetspeedTemplatePage.java,v 1.12 2001/06/04 17:21:07 raphael Exp $
  + * @version $Id: JetspeedTemplatePage.java,v 1.13 2001/06/06 22:28:56 raphael Exp $
    */
   public class JetspeedTemplatePage extends DefaultPage
   {
  @@ -144,46 +144,40 @@
           // is hardcoded into the Screen in this instance.  In this case this
           // action is skipped.
   
  -        // if only a screen but no template is specified, then we need to display
  -        // a legacy ecs screen --> screenTemplate = ECS
  -        if ( data.getTemplateInfo().getScreenTemplate() == null )
  +        if (!data.hasScreen())
           {
  -            String screen = TurbineTemplate.getDefaultScreen();
  +            
  +            // if only a screen but no template is specified, then we need to display
  +            // a legacy ecs screen --> screenTemplate = ECS
  +            if ( data.getTemplateInfo().getScreenTemplate() == null )
  +            {
  +                String screen = TurbineTemplate.getDefaultScreen();
  +                data.setScreenTemplate(screen);
  +            }
  +
               String ext = TurbineTemplate.getDefaultExtension();
               
  -            if (!screen.endsWith(ext))
  +            String template = data.getTemplateInfo().getScreenTemplate();
  +
  +            if (template.lastIndexOf('.')<0)
               {
  -                screen=screen+ext;
  +                template=template+"."+ext;
               }
  -            data.setScreenTemplate(screen);
  -        }
   
  -        String template = data.getTemplateInfo().getScreenTemplate();
  -        Log.debug("JetspeedTemplatePage: requested template = " + template);
  +            Log.debug("JetspeedTemplatePage: requested template = " + template);
   
  -        // get real path now - this is a fix to get us thru 1.3a2
  -        // when the TurbineTemplateService can locate resources by NLS and mediatype,
  -        // then it can be removed
  -
  -        String locatedScreen = Profiler.locateScreenTemplate(data, template);
  -        data.setScreenTemplate( locatedScreen );
  -        Log.debug("JetspeedTemplatePage: calculated template = " + locatedScreen);
  -
  -        // -----------------------------------------------------------
  -        // Get screen and layout template (first screen then layout!!) 
  -        // and the correct Screen from the template service
  -        // -----------------------------------------------------------
  -
  -        //String screenTemplate = TurbineTemplate.getScreenTemplateName(located);
  -        //Log.note("JetspeedTemplatePage: screenTemplate is finally " + screenTemplate);
  -        //data.setScreenTemplate( screenTemplate );
  -
  -        String layout = Profiler.locateLayoutTemplate(data, template);
  -        data.setLayoutTemplate(layout);
  -        Log.debug("JetspeedTemplatePage: layoutTemplate is finally " + layout);
  +            // get real path now - this is a fix to get us thru 1.3a2
  +            // when the TurbineTemplateService can locate resources by NLS and mediatype,
  +            // then it can be removed
  +
  +            String locatedScreen = Profiler.locateScreenTemplate(data, template);
  +            data.setScreenTemplate( locatedScreen );
  +            Log.debug("JetspeedTemplatePage: calculated template = " + locatedScreen);
  +
  +            String layout = Profiler.locateLayoutTemplate(data, template);
  +            data.setLayoutTemplate(layout);
  +            Log.debug("JetspeedTemplatePage: layoutTemplate is finally " + layout);
   
  -        if ( !data.hasScreen() )
  -        {
               String screen = TurbineTemplate.getScreenName(template);
               if (screen == null)
               {
  
  
  
  1.5       +2 -2      jakarta-jetspeed/src/java/org/apache/jetspeed/portal/BasePortletConfig.java
  
  Index: BasePortletConfig.java
  ===================================================================
  RCS file: /home/cvs/jakarta-jetspeed/src/java/org/apache/jetspeed/portal/BasePortletConfig.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- BasePortletConfig.java	2001/06/04 17:36:33	1.4
  +++ BasePortletConfig.java	2001/06/06 22:28:58	1.5
  @@ -71,7 +71,7 @@
    * about the running environment of a given Portlet.
    *
    * @author <a href="mailto:burton@apache.org">Kevin A. Burton</a>
  - * @version $Id: BasePortletConfig.java,v 1.4 2001/06/04 17:36:33 raphael Exp $
  + * @version $Id: BasePortletConfig.java,v 1.5 2001/06/06 22:28:58 raphael Exp $
    */
   public class BasePortletConfig extends BaseConfig implements PortletConfig
   {
  @@ -280,7 +280,7 @@
           {
               if (getSkin()==null)
               {
  -                setSkin(new Hashtable());
  +                setPortletSkin(getPortletSkin());
               }
               
               if (value==null)
  
  
  
  1.7       +1 -2      jakarta-jetspeed/src/java/org/apache/jetspeed/portal/BasePortletSet.java
  
  Index: BasePortletSet.java
  ===================================================================
  RCS file: /home/cvs/jakarta-jetspeed/src/java/org/apache/jetspeed/portal/BasePortletSet.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- BasePortletSet.java	2001/06/04 17:36:34	1.6
  +++ BasePortletSet.java	2001/06/06 22:28:58	1.7
  @@ -81,7 +81,7 @@
    *
    * @author <a href="mailto:raphael@apache.org">RaphaŽl Luta</a>
    * @author <a href="mailto:burton@apache.org">Kevin A. Burton</a>
  - * @version $Id: BasePortletSet.java,v 1.6 2001/06/04 17:36:34 raphael Exp $
  + * @version $Id: BasePortletSet.java,v 1.7 2001/06/06 22:28:58 raphael Exp $
    */
   public class BasePortletSet implements PortletSet, Portlet, PortletState
   {
  @@ -282,7 +282,6 @@
   
           //process the normal rendering flow
               
  -        CapabilityMap map = CapabilityMapFactory.getCapabilityMap( rundata );
           PortletController controller = getController();
               
           if ( controller == null )
  
  
  
  1.17      +11 -8     jakarta-jetspeed/src/java/org/apache/jetspeed/portal/controllers/CardPortletController.java
  
  Index: CardPortletController.java
  ===================================================================
  RCS file: /home/cvs/jakarta-jetspeed/src/java/org/apache/jetspeed/portal/controllers/CardPortletController.java,v
  retrieving revision 1.16
  retrieving revision 1.17
  diff -u -r1.16 -r1.17
  --- CardPortletController.java	2001/06/04 17:37:10	1.16
  +++ CardPortletController.java	2001/06/06 22:29:01	1.17
  @@ -81,7 +81,7 @@
   or with an invalid value, use the first portlet (position 0)</li>
   </p>
   @author <a href="mailto:raphael@apache.org">RaphaŽl Luta</a>
  -@version $Id: CardPortletController.java,v 1.16 2001/06/04 17:37:10 raphael Exp $
  +@version $Id: CardPortletController.java,v 1.17 2001/06/06 22:29:01 raphael Exp $
   */
   public class CardPortletController extends AbstractPortletController
   {
  @@ -149,15 +149,18 @@
           }
   
           // then in the explicit position field
  -        Enumeration en = myPortlets.getPortlets();
  -        while ( en.hasMoreElements() && ( ! found ) )
  +        if (!found)
           {
  -            Portlet p = (Portlet)en.nextElement();
  -            if ( p.getPortletConfig().getPosition() == paneNum )
  +            Enumeration en = myPortlets.getPortlets();
  +            while ( en.hasMoreElements() && ( ! found ) )
               {
  -                base.addElement( p.getContent( rundata ) );
  -                pane = String.valueOf( paneNum );
  -                found=true;
  +                Portlet p = (Portlet)en.nextElement();
  +                if ( p.getPortletConfig().getPosition() == paneNum )
  +                {
  +                    base.addElement( p.getContent( rundata ) );
  +                    pane = String.valueOf( paneNum );
  +                    found=true;
  +                }
               }
           }
   
  
  
  
  1.13      +17 -8     jakarta-jetspeed/src/java/org/apache/jetspeed/portal/controllers/GridPortletController.java
  
  Index: GridPortletController.java
  ===================================================================
  RCS file: /home/cvs/jakarta-jetspeed/src/java/org/apache/jetspeed/portal/controllers/GridPortletController.java,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- GridPortletController.java	2001/06/04 17:37:10	1.12
  +++ GridPortletController.java	2001/06/06 22:29:02	1.13
  @@ -98,7 +98,7 @@
   first cell of the table</p>
   
   @author <a href="mailto:raphael@apache.org">RaphaŽl Luta</a>
  -@version $Id: GridPortletController.java,v 1.12 2001/06/04 17:37:10 raphael Exp $
  +@version $Id: GridPortletController.java,v 1.13 2001/06/06 22:29:02 raphael Exp $
   */
   public class GridPortletController extends AbstractPortletController {
   
  @@ -131,16 +131,15 @@
   
              
           PortletConfig portletConf = portlet.getPortletConfig();
  +        Integer colObj = portletConf.getConstraints().getColumn();
  +        Integer rowObj = portletConf.getConstraints().getRow();
   
  -        int col = portletConf.getConstraints().getColumn().intValue();
  -
  +        int col = (colObj!=null)?colObj.intValue():0;
  +        int row = (rowObj!=null)?rowObj.intValue():0;
           
           if ( col + 1 > this.getColumn() ) {
               this.setColumn( col + 1 );
           }
  -           
  -        int row = portletConf.getConstraints().getRow().intValue();
  -
           
           if ( row + 1 > this.getRow() ) {
               this.setRow( row + 1 );
  @@ -156,6 +155,8 @@
   
           ElementContainer base = new ElementContainer();
   
  +        try 
  +        {
           PortletSet portlets = getPortlets();
           PortletConfig pc = portlets.getPortletConfig();
   
  @@ -202,8 +203,10 @@
               Portlet p = (Portlet)en.nextElement();
               PortletConfig pConf = p.getPortletConfig();
   
  -            int colnum = pConf.getConstraints().getColumn().intValue();
  -            int rownum = pConf.getConstraints().getRow().intValue();
  +            Integer colObj = pConf.getConstraints().getColumn();
  +            Integer rowObj = pConf.getConstraints().getRow();
  +            int colnum = (colObj!=null)?colObj.intValue():0;
  +            int rownum = (rowObj!=null)?rowObj.intValue():0;
   
               elements[rownum % rows][colnum % cols]
                   .addElement( p.getContent( rundata ) );
  @@ -227,6 +230,12 @@
               t.addElement(row);
           }
   
  +        }
  +        catch (Exception e)
  +        {
  +            org.apache.turbine.util.Log.error(e);
  +        }
  +        
           return base;
   
       }
  
  
  
  1.5       +116 -138  jakarta-jetspeed/src/java/org/apache/jetspeed/services/profiler/JetspeedProfilerService.java
  
  Index: JetspeedProfilerService.java
  ===================================================================
  RCS file: /home/cvs/jakarta-jetspeed/src/java/org/apache/jetspeed/services/profiler/JetspeedProfilerService.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- JetspeedProfilerService.java	2001/06/04 17:30:41	1.4
  +++ JetspeedProfilerService.java	2001/06/06 22:29:07	1.5
  @@ -60,6 +60,7 @@
   import org.apache.jetspeed.capability.CapabilityMap;
   import org.apache.jetspeed.capability.CapabilityMapFactory;
   import org.apache.jetspeed.services.resources.JetspeedResources;
  +import org.apache.jetspeed.services.rundata.JetspeedRunData;
   import org.apache.jetspeed.util.MimeType;
   import org.apache.jetspeed.services.Registry;
   import org.apache.jetspeed.om.newregistry.RegistryException;
  @@ -75,6 +76,7 @@
   import org.apache.turbine.services.servlet.TurbineServlet;
   import org.apache.turbine.services.localization.LocaleDetector;
   import org.apache.turbine.services.resources.TurbineResources;
  +import org.apache.turbine.services.template.TurbineTemplate;
   
   //java stuff
   import java.util.Map;
  @@ -108,7 +110,7 @@
    *
    * @author <a href="mailto:david@bluesunrise.com">David Sean Taylor</a>
    * @author <a href="mailto:sgala@hisitech.com">Santiago Gala</a>
  - * @version $Id: JetspeedProfilerService.java,v 1.4 2001/06/04 17:30:41 raphael Exp $
  + * @version $Id: JetspeedProfilerService.java,v 1.5 2001/06/06 22:29:07 raphael Exp $
    */
   
   public class JetspeedProfilerService  extends TurbineBaseService
  @@ -280,7 +282,6 @@
           throws ProfileException
       {
           Profile profile = getResourceURL(rundata, cm, true);
  -        this.setSessionProfile(rundata, profile);
           return profile;
       }
   
  @@ -294,10 +295,18 @@
       public Profile getProfile(RunData rundata)
           throws ProfileException
       {
  -        CapabilityMap cm = CapabilityMapFactory.getCapabilityMap( rundata );
  -        Profile profile = getResourceURL(rundata, cm, true);
  -        this.setSessionProfile(rundata, profile);
  -        return profile;
  +        CapabilityMap cm = null;
  +        
  +        if (rundata instanceof JetspeedRunData)
  +        {
  +            cm = ((JetspeedRunData)rundata).getCapability();
  +        }
  +        else
  +        {
  +            cm = CapabilityMapFactory.getCapabilityMap( rundata );
  +        }
  +        
  +        return getProfile(rundata, cm);
       }
   
       /**
  @@ -311,9 +320,7 @@
           throws ProfileException
       {
           CapabilityMap cm = CapabilityMapFactory.getCapabilityMap(mt.toString());
  -        Profile profile = getResourceURL(data, cm, false);
  -        //this.setSessionProfile(data, profile);
  -        return profile;
  +        return getResourceURL(data, cm, false);
       }
   
        /**
  @@ -475,9 +482,9 @@
               if (finalPath.length() == 0)
               {
                   finalPath = root + original;
  -                URL url = TurbineServlet.getResource( finalPath );
  -                if (url != null)
  -                    profile.setURL(url.toString());
  +                String realPath = TurbineServlet.getRealPath( finalPath );
  +                if (realPath != null)
  +                    profile.setURL(realPath);
                   else
                       profile.setURL(finalPath);
                   return profile;
  @@ -485,11 +492,11 @@
           }
           // TODO: ACL security
   
  -         URL url = TurbineServlet.getResource( finalPath );
  -         if (url != null)
  -             profile.setURL(url.toString());
  -         else
  -             profile.setURL(finalPath);
  +        String realPath = TurbineServlet.getRealPath( finalPath );
  +        if (realPath != null)
  +            profile.setURL(realPath);
  +        else
  +            profile.setURL(finalPath);
   
           return profile;
       }
  @@ -919,13 +926,15 @@
       public String locateScreenTemplate(RunData data, String template)
       {
           String path = localizeTemplateName(data);
  -        if (!template.startsWith("/"))
  -            path = path + "/" ;
  +
  +        String located = locateTemplate(data, "/screens", path, template);
  +        if (null == located) 
  +        {
  +            // FIXME: need to get default.layout.template from TR.p
  +            template = "/default."+getTemplateExtension(template);
  +            located = locateTemplate(data, "/screens", path, template);
  +        }
   
  -        path = "/screens" + path;
  -        String located = locateTemplate(data, path, template);
  -        if (null == located)  // FIXME: need to get default.layout.template from TR.p
  -            located = locateTemplate(data, path, "/default.vm");
           return located;
       }
   
  @@ -940,13 +949,15 @@
       public String locateLayoutTemplate(RunData data, String template)
       {
           String path = localizeTemplateName(data);
  -        if (!template.startsWith("/"))
  -            path = path + "/" ;
  +
  +        String located = locateTemplate(data, "/layouts", path, template);
  +        if (null == located) 
  +        {
  +            // FIXME: need to get default.layout.template from TR.p
  +            template = "/default."+getTemplateExtension(template);
  +            located = locateTemplate(data, "/layouts", path, template);
  +        }
   
  -        path = "/layouts" + path;
  -        String located = locateTemplate(data, path, template);
  -        if (null == located)  // FIXME: need to get default.layout.template from TR.p
  -            located = locateTemplate(data, path, "/default.vm");
           return located;
       }
   
  @@ -961,67 +972,83 @@
       public String locatePortletTemplate(RunData data, String template)
       {
           String path = localizeTemplateName(data);
  -        if (!template.startsWith("/"))
  -            path = path + "/" ;
   
  -        path = "/portlets" + path.toString();
  -        return locateTemplate(data, path, template);
  +        path = locateTemplate(data, "/portlets", path, template);
  +        
  +        return "/portlets"+path;
       }
   
       /**
        * Locate a template using the Profiler's fallback algorithm
        *
  +     * @param resourceType the path specific to the resource type sought (eg /screens)
        * @param path the fullest path to the template based on simple NLS/mediatype directory
        * @param template the name of the template
        *
        * @return the exact path to the template, or null if not found
        */
  -    public String locateTemplate(RunData data, String path, String template)
  +    public String locateTemplate(RunData data, String resourceType, String path, String
template)
       {
           String finalPath;
  -        int len = template.length();
  -        if (template.startsWith("/") && len > 1)
  -            template = template.substring(1, len);
   
  -        while( (finalPath = templateFallback(path, template)) == "") {
  +        // make sure resourceType doesn't end with "/" but starts with "/"
  +        if (resourceType.endsWith("/"))
  +        {
  +            resourceType = resourceType.substring(0, resourceType.length()-1);
  +        }
  +        if (!resourceType.startsWith("/"))
  +        {
  +            resourceType = "/"+resourceType;
  +        }
  +        // make sure path doesn't end with "/" but starts with "/"
  +        if (path.endsWith("/"))
  +        {
  +            path = path.substring(0, path.length()-1);
  +        }
  +        if (!path.startsWith("/"))
  +        {
  +            path = "/"+path;
  +        }
  +        // make sure template starts with "/"
  +        if (!template.startsWith("/"))
  +        {
  +            template = "/"+template;
  +        }
  +        
  +        StringBuffer fullPath = new StringBuffer( templateRoot );
  +
  +        fullPath.append("/").append(getTemplateExtension(template));
  +        fullPath.append(resourceType);
  +        
  +        String basePath = fullPath.toString();
  +        String realPath = null;
  +        String workingPath = null;
  +
  +        do
  +        {
  +            workingPath = path+template;
  +            realPath = TurbineServlet.getRealPath( basePath + workingPath );
  +
  +            // the current template exists, return the corresponding path
  +            if (templateExists(realPath))
  +            {
  +                Log.debug("template exists: "+realPath+" returning "+workingPath);
  +                return workingPath;
  +            }
  +            // else strip path of one of its components and loop
               int pt = path.lastIndexOf(PATH_SEPARATOR);
  -            if (-1 == pt)
  +            if ( pt > -1 )
               {
  -                path = "";  // look in psml root
  -                finalPath = templateFallback(path, template);
  -                if (finalPath == "")
  -                {
  -                    //String errorMessage = "Failed to find resource for " + original;
  -                    // throw new ProfileException(errorMessage);
  -                    return null;
  -                }
  -                break; // found default resource in root
  +                path = path.substring(0,pt);
               }
  -            int length = path.length();
  -            if (pt == length - 1 && length > 1)
  +            else
               {
  -                //pt = pt - 1;
  -                path = path.substring(0, pt);
  -                pt = path.lastIndexOf(PATH_SEPARATOR);
  +                path = null;
               }
  -            path = path.substring(0, pt);
  -        }
  -        if ("" == finalPath)
  -            finalPath = null;
  -        else
  -        {
  -            // now remove the webapp full path info
  -            finalPath = stripPrefix(templateRoot, finalPath);
  -            if (!finalPath.startsWith("/"))
  -               finalPath = "/" + finalPath;
  -            if (finalPath.startsWith("/screens" ))
  -                finalPath = stripPrefix("/screens", finalPath);
  -            else if (finalPath.startsWith("/layouts" ))
  -                finalPath = stripPrefix("/layouts", finalPath);
  -//            else if (finalPath.startsWith("/portlets" ))
  -//                finalPath = stripPrefix("/portlets", finalPath);
           }
  -        return finalPath;
  +        while (path != null);
  +        
  +        return null;
       }
   
       /**
  @@ -1052,7 +1079,7 @@
           data.setContentType( cm.getPreferredType().toString() );  
           if ((type != null) && (type.length() > 0)) 
               templatePath.append("/").append(type);
  -	    
  +        
           // Grab the Locale from the temporary storage in the User object
           Locale locale = (Locale)data.getUser().getTemp("locale");
           String language = locale.getLanguage();
  @@ -1065,76 +1092,27 @@
           return  templatePath.toString();
       }
   
  -    /*
  -     * string manipulation function to remove a prefixed substring from a string
  +    /** 
  +     * Returns the extension for the specified template
        *
  -     * @param head the prepended string.
  -     * @param finalPath the full string.
  -     * @return the finalPath minus the head.
  -     */
  -    private String stripPrefix( String head, String finalPath)
  -    {
  -        int start = head.length();
  -        int end = finalPath.length();
  -        if (end > start)
  -            finalPath = finalPath.substring(start, end);
  -        return finalPath;
  +     * @param template the template name to scan for an extension
  +     * @return the template extension if it exists or the default 
  +     * template extension
  +     */
  +    private String getTemplateExtension(String template)
  +    {
  +        String ext = TurbineTemplate.getDefaultExtension();
  +        
  +        int idx = template.lastIndexOf(".");
  +        
  +        if (idx > 0)
  +        {
  +            ext = template.substring(idx+1);
  +        }
  +        
  +        return ext;
       }
  -
  -    /**
  -     * apply fallback algorithm to finding resources from most specific
  -     * to least specific starting at media type specific, fallback to a specific
  -     *
  -     * @parameter path full path to resource
  -     * @parameeter resource the template resource name.
  -     * @return a String the modified path to the resource based on fallback
  -     */
  -    protected String templateFallback(String path, String resource)
  -    {
  -        StringBuffer fullPath = new StringBuffer( templateRoot );
  -
  -        int len = path.length();
  -        if (path.startsWith("/") && len > 1)
  -            path = path.substring(1, len);
  -        fullPath.append(path);
  -        if (path.length() > 0 && !path.endsWith(PATH_SEPARATOR))
  -            fullPath.append(PATH_SEPARATOR);
  -
  -//        int count = 0;
  -
  -        String basePath = fullPath.toString();
  -        String realPath, workingPath;
  -
  -//        for ( ; count > 0 ; count--)
  - //       {
  -           workingPath = basePath + resource;
  -           realPath = TurbineServlet.getRealPath( workingPath );
  -           if (templateExists(realPath))
  -               return workingPath;
  -            int pt = basePath.lastIndexOf(PATH_SEPARATOR);
  -            int length = basePath.length();
  -            if (-1 != pt)
  -            {
  -                if (pt == length - 1 && length > 1)
  -                {
  -                    //pt = pt - 1;
  -                    basePath = basePath.substring(0, pt);
  -                    pt = basePath.lastIndexOf(PATH_SEPARATOR);
  -                }
  -                basePath = basePath.substring(0, pt);
  -                basePath = basePath + PATH_SEPARATOR;
  -            }
  -   //     }
  -
  -        fullPath.append(resource);
  -        realPath = TurbineServlet.getRealPath( fullPath.toString() );
       
  -        if (templateExists(realPath))
  -            return fullPath.toString();  // found as is
  -
  -        return "";
  -    }
  -
       /**
        * checks for the existence of a template resource given a key
        *
  
  
  
  1.4       +3 -2      jakarta-jetspeed/src/java/org/apache/jetspeed/services/profiler/ProfilerService.java
  
  Index: ProfilerService.java
  ===================================================================
  RCS file: /home/cvs/jakarta-jetspeed/src/java/org/apache/jetspeed/services/profiler/ProfilerService.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- ProfilerService.java	2001/06/04 07:14:37	1.3
  +++ ProfilerService.java	2001/06/06 22:29:08	1.4
  @@ -68,7 +68,7 @@
    * 
    * @see org.apache.jetspeed.om.profile.Profile
    * @author <a href="mailto:david@bluesunrise.com">David Sean Taylor</a>
  - * @version $Id: ProfilerService.java,v 1.3 2001/06/04 07:14:37 taylor Exp $
  + * @version $Id: ProfilerService.java,v 1.4 2001/06/06 22:29:08 raphael Exp $
    */
   
   public interface ProfilerService extends Service
  @@ -204,11 +204,12 @@
       /**
        * Locate a template using the Profiler's fallback algorithm
        *
  +     * @param resourceType the path specific to the resource type sought (eg /screens)
        * @param path the fullest path to the template based on simple NLS/mediatype directory
        * @param template the name of the template
        * @return the exact path to the found template
        */
  -    public String locateTemplate(RunData data, String path, String template);
  +    public String locateTemplate(RunData data, String resourceType, String path, String
template);
       public String locateScreenTemplate(RunData data, String template);
       public String locateLayoutTemplate(RunData data, String template);
       public String locatePortletTemplate(RunData data, String template);
  
  
  
  1.15      +2 -3      jakarta-jetspeed/src/java/org/apache/jetspeed/util/URILookup.java
  
  Index: URILookup.java
  ===================================================================
  RCS file: /home/cvs/jakarta-jetspeed/src/java/org/apache/jetspeed/util/URILookup.java,v
  retrieving revision 1.14
  retrieving revision 1.15
  diff -u -r1.14 -r1.15
  --- URILookup.java	2001/05/08 06:27:25	1.14
  +++ URILookup.java	2001/06/06 22:29:10	1.15
  @@ -119,7 +119,7 @@
    * 
    * @author <A HREF="shesmer@raleigh.ibm.com">Stephan Hesmer</A>
    * @author <A HREF="sgala@apache.org">Santiago Gala</A>
  - * @version $Id: URILookup.java,v 1.14 2001/05/08 06:27:25 taylor Exp $
  + * @version $Id: URILookup.java,v 1.15 2001/06/06 22:29:10 raphael Exp $
    */
   
   public class URILookup {
  @@ -366,8 +366,7 @@
                   if (aPortletName==null) throw new JetspeedException( "A portlet is required
to return an URI." );
                   DynamicURI uri = new DynamicURI( rundata );
                   uri.setAction( ACTION_MARKPAGE );
  -                uri.addPathInfo( "portlet", 
  -                                 URIEncoder.encode( aPortletName ) );
  +                uri.addPathInfo( "portlet", aPortletName );
                   newURI = uri.toString();
               }
               else if (aSubType==SUBTYPE_LOGOUT) {
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: jetspeed-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: jetspeed-dev-help@jakarta.apache.org


Mime
View raw message