[pal-cvs 3368] [1102] supported login theme.

Back to archive index

svnno****@sourc***** svnno****@sourc*****
2008年 8月 22日 (金) 18:18:44 JST


Revision: 1102
          http://svn.sourceforge.jp/cgi-bin/viewcvs.cgi?root=pal&view=rev&rev=1102
Author:   shinsuke
Date:     2008-08-22 18:18:44 +0900 (Fri, 22 Aug 2008)

Log Message:
-----------
supported login theme.

Modified Paths:
--------------
    pal-portal/branches/pal-portal-1.x/portal/jetspeed-2/components/portal/src/java/org/apache/jetspeed/login/LoginProxyServlet.java
    pal-portal/branches/pal-portal-1.x/portal/jetspeed-2/components/portal/src/java/org/apache/jetspeed/login/LoginRedirectorServlet.java
    pal-portal/branches/pal-portal-1.x/portal/jetspeed-2/components/portal/src/java/org/apache/jetspeed/login/impl/LoginJSPViewValve.java
    pal-portal/branches/pal-portal-1.x/portal/jetspeed-2/jetspeed-api/src/java/org/apache/jetspeed/login/LoginConstants.java


-------------- next part --------------
Modified: pal-portal/branches/pal-portal-1.x/portal/jetspeed-2/components/portal/src/java/org/apache/jetspeed/login/LoginProxyServlet.java
===================================================================
--- pal-portal/branches/pal-portal-1.x/portal/jetspeed-2/components/portal/src/java/org/apache/jetspeed/login/LoginProxyServlet.java	2008-08-22 06:46:15 UTC (rev 1101)
+++ pal-portal/branches/pal-portal-1.x/portal/jetspeed-2/components/portal/src/java/org/apache/jetspeed/login/LoginProxyServlet.java	2008-08-22 09:18:44 UTC (rev 1102)
@@ -27,6 +27,7 @@
 import javax.servlet.http.HttpServletResponse;
 import javax.servlet.http.HttpSession;
 
+import org.apache.commons.lang.StringUtils;
 import org.apache.jetspeed.Jetspeed;
 import org.apache.jetspeed.PortalReservedParameters;
 import org.apache.jetspeed.administration.PortalAuthenticationConfiguration;
@@ -89,6 +90,24 @@
             // session.getAttribute(LoginConstants.PASSWORD);
         }
 
+        // theme
+        parameter = request.getParameter(LoginConstants.THEME);
+        if (parameter != null)
+        {
+            if (parameter.length() > 30)
+            {
+                parameter = parameter.substring(0, 30);
+            }
+            if (StringUtils.isAlphanumeric(parameter))
+            {
+                session.setAttribute(LoginConstants.THEME, parameter);
+            }
+        }
+        else
+        {
+            session.removeAttribute(LoginConstants.THEME);
+        }
+
         // Globaly override all psml themes
         if (request
                 .getParameter(PortalReservedParameters.PAGE_THEME_OVERRIDE_ATTRIBUTE) != null)

Modified: pal-portal/branches/pal-portal-1.x/portal/jetspeed-2/components/portal/src/java/org/apache/jetspeed/login/LoginRedirectorServlet.java
===================================================================
--- pal-portal/branches/pal-portal-1.x/portal/jetspeed-2/components/portal/src/java/org/apache/jetspeed/login/LoginRedirectorServlet.java	2008-08-22 06:46:15 UTC (rev 1101)
+++ pal-portal/branches/pal-portal-1.x/portal/jetspeed-2/components/portal/src/java/org/apache/jetspeed/login/LoginRedirectorServlet.java	2008-08-22 09:18:44 UTC (rev 1102)
@@ -56,6 +56,7 @@
         session.removeAttribute(LoginConstants.RETRYCOUNT);
         session
                 .removeAttribute(PortalReservedParameters.PREFERED_LOCALE_ATTRIBUTE);
+        session.removeAttribute(LoginConstants.THEME);
 
         AuditActivity audit = (AuditActivity) Jetspeed.getComponentManager()
                 .getComponent("org.apache.jetspeed.audit.AuditActivity");

Modified: pal-portal/branches/pal-portal-1.x/portal/jetspeed-2/components/portal/src/java/org/apache/jetspeed/login/impl/LoginJSPViewValve.java
===================================================================
--- pal-portal/branches/pal-portal-1.x/portal/jetspeed-2/components/portal/src/java/org/apache/jetspeed/login/impl/LoginJSPViewValve.java	2008-08-22 06:46:15 UTC (rev 1101)
+++ pal-portal/branches/pal-portal-1.x/portal/jetspeed-2/components/portal/src/java/org/apache/jetspeed/login/impl/LoginJSPViewValve.java	2008-08-22 09:18:44 UTC (rev 1102)
@@ -16,13 +16,20 @@
  */
 package org.apache.jetspeed.login.impl;
 
+import java.io.File;
 import java.io.IOException;
+import java.util.Locale;
+import java.util.Map;
 
 import javax.servlet.RequestDispatcher;
+import javax.servlet.ServletContext;
 import javax.servlet.ServletException;
 
+import org.apache.commons.collections.map.LRUMap;
+import org.apache.commons.lang.StringUtils;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
+import org.apache.jetspeed.login.LoginConstants;
 import org.apache.jetspeed.pipeline.PipelineException;
 import org.apache.jetspeed.pipeline.valve.AbstractValve;
 import org.apache.jetspeed.pipeline.valve.LoginViewValve;
@@ -40,22 +47,35 @@
 public class LoginJSPViewValve extends AbstractValve implements LoginViewValve
 {
 
+    private static final String LOGIN_JSP_FILENAME = "login.jsp";
+
     private static final Log log = LogFactory.getLog(LoginJSPViewValve.class);
 
-    private static final String DEFAULT_TEMPLATE_PATH = "/WEB-INF/templates/login";
+    private static final String DEFAULT_TEMPLATE_ROOT_PATH = "/WEB-INF/templates/login";
 
-    private String templatePath;
+    protected String templateRootPath;
 
+    protected String loginFilename;
+
+    protected Map loginTemplateMap;
+
     public LoginJSPViewValve()
     {
-        templatePath = DEFAULT_TEMPLATE_PATH;
+        this(DEFAULT_TEMPLATE_ROOT_PATH);
     }
 
     public LoginJSPViewValve(String templatePath)
     {
-        this.templatePath = templatePath;
+        this(templatePath, LOGIN_JSP_FILENAME);
     }
 
+    public LoginJSPViewValve(String templatePath, String loginFile)
+    {
+        this.templateRootPath = templatePath;
+        this.loginFilename = "/" + loginFile;
+        loginTemplateMap = new LRUMap();
+    }
+
     /*
      * (non-Javadoc)
      * 
@@ -65,13 +85,12 @@
     public void invoke(RequestContext request, ValveContext context)
             throws PipelineException
     {
-        String loginTemplateFile = templatePath + "/" + request.getMediaType()
-                + "/login.jsp";
+        String loginTemplatePath = getLoginTemplatePath(request);
 
         try
         {
             RequestDispatcher rd = request.getRequest().getRequestDispatcher(
-                    loginTemplateFile);
+                    loginTemplatePath);
             rd.include(request.getRequest(), request.getResponse());
         }
         catch (ServletException e)
@@ -96,6 +115,104 @@
         context.invokeNext(request);
     }
 
+    protected String getLoginTemplatePath(RequestContext request)
+    {
+        StringBuffer path = new StringBuffer();
+        String theme = (String) request
+                .getSessionAttribute(LoginConstants.THEME);
+        if (theme != null)
+        {
+            path.append("/");
+            path.append(theme);
+        }
+        if (request.getMediaType() != null)
+        {
+            path.append("/");
+            path.append(request.getMediaType());
+        }
+        Locale locale = request.getLocale();
+        if (locale != null && !StringUtils.isEmpty(locale.getLanguage()))
+        {
+            path.append("/");
+            path.append(locale.getLanguage());
+            if (!StringUtils.isEmpty(locale.getCountry()))
+            {
+                path.append("/");
+                path.append(locale.getCountry());
+            }
+        }
+        String clientPath = path.toString(); // /theme/mediatype/language/country
+        String templatePath = (String) loginTemplateMap.get(clientPath);
+        if (templatePath != null) { return templatePath; }
+
+        ServletContext servletContext = request.getConfig().getServletContext();
+
+        templatePath = templateRootPath + path.toString() + loginFilename;
+        if (new File(servletContext.getRealPath(templatePath)).isFile())
+        {
+            // TEMPLATE_PATH/theme/mediatype/language/country
+            loginTemplateMap.put(clientPath, templatePath);
+            return templatePath;
+        }
+
+        // fallback
+        String p = path.toString();
+        int pos = p.lastIndexOf("/");
+        while (pos > 0)
+        {
+            p = p.substring(0, pos);
+            templatePath = templateRootPath + p + loginFilename;
+            if (new File(servletContext.getRealPath(templatePath)).isFile())
+            {
+                loginTemplateMap.put(clientPath, templatePath);
+                return templatePath;
+            }
+            pos = p.lastIndexOf("/");
+        }
+
+        // fallback without theme
+        path = new StringBuffer();
+        if (request.getMediaType() != null)
+        {
+            path.append("/");
+            path.append(request.getMediaType());
+        }
+        if (locale != null && locale.getLanguage() != null)
+        {
+            path.append("/");
+            path.append(locale.getLanguage());
+            if (locale.getCountry() != null)
+            {
+                path.append("/");
+                path.append(locale.getCountry());
+            }
+        }
+        templatePath = templateRootPath + path.toString() + loginFilename;
+        if (new File(servletContext.getRealPath(templatePath)).isFile())
+        {
+            // TEMPLATE_PATH/mediatype/language/country
+            loginTemplateMap.put(clientPath, templatePath);
+            return templatePath;
+        }
+        p = path.toString();
+        pos = p.lastIndexOf("/");
+        while (pos > 0)
+        {
+            p = p.substring(0, pos);
+            templatePath = templateRootPath + p + loginFilename;
+            if (new File(servletContext.getRealPath(templatePath)).isFile())
+            {
+                loginTemplateMap.put(clientPath, templatePath);
+                return templatePath;
+            }
+            pos = p.lastIndexOf("/");
+        }
+
+        loginTemplateMap.put(clientPath, templatePath + loginFilename);
+        return templatePath + loginFilename;
+
+    }
+
     public String toString()
     {
         return "LoginViewValve";

Modified: pal-portal/branches/pal-portal-1.x/portal/jetspeed-2/jetspeed-api/src/java/org/apache/jetspeed/login/LoginConstants.java
===================================================================
--- pal-portal/branches/pal-portal-1.x/portal/jetspeed-2/jetspeed-api/src/java/org/apache/jetspeed/login/LoginConstants.java	2008-08-22 06:46:15 UTC (rev 1101)
+++ pal-portal/branches/pal-portal-1.x/portal/jetspeed-2/jetspeed-api/src/java/org/apache/jetspeed/login/LoginConstants.java	2008-08-22 09:18:44 UTC (rev 1102)
@@ -37,6 +37,8 @@
 
     public final static String LOGIN_CHECK = "org.apache.jetspeed.login.check";
 
+    public final static String THEME = "org.apache.jetspeed.login.theme";
+
     // DONE Findbugs
     // public final static Integer ERROR_UNKNOWN_USER = new Integer(1);
     public final static Integer ERROR_UNKNOWN_USER = Integer.valueOf(1);


pal-cvs メーリングリストの案内
Back to archive index