portals-jetspeed-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From shins...@apache.org
Subject svn commit: r426855 - in /portals/jetspeed-2/trunk: components/portal/src/java/org/apache/jetspeed/desktop/impl/ jetspeed-api/src/java/org/apache/jetspeed/desktop/
Date Sun, 30 Jul 2006 00:15:56 GMT
Author: shinsuke
Date: Sat Jul 29 17:15:56 2006
New Revision: 426855

URL: http://svn.apache.org/viewvc?rev=426855&view=rev
Log:
l10n support. you can put properties file to desktop-theme/theme/resources and specify resource.file
in theme.properties.

Modified:
    portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/desktop/impl/JetspeedDesktopContextImpl.java
    portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/desktop/impl/JetspeedDesktopImpl.java
    portals/jetspeed-2/trunk/jetspeed-api/src/java/org/apache/jetspeed/desktop/JetspeedDesktop.java
    portals/jetspeed-2/trunk/jetspeed-api/src/java/org/apache/jetspeed/desktop/JetspeedDesktopContext.java

Modified: portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/desktop/impl/JetspeedDesktopContextImpl.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/desktop/impl/JetspeedDesktopContextImpl.java?rev=426855&r1=426854&r2=426855&view=diff
==============================================================================
--- portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/desktop/impl/JetspeedDesktopContextImpl.java
(original)
+++ portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/desktop/impl/JetspeedDesktopContextImpl.java
Sat Jul 29 17:15:56 2006
@@ -15,6 +15,14 @@
  */
 package org.apache.jetspeed.desktop.impl;
 
+import java.io.File;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.net.URLClassLoader;
+import java.util.Locale;
+import java.util.MissingResourceException;
+import java.util.ResourceBundle;
+
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 
@@ -37,13 +45,15 @@
     private BasePortalURL baseUrlAccess = null;
     private String themeRootPath = null;
     private String theme = null;
+    private String resourceName = null;
         
-    public JetspeedDesktopContextImpl(RequestContext context, BasePortalURL baseUrlAccess,
String theme, String themeRootPath )
+    public JetspeedDesktopContextImpl(RequestContext context, BasePortalURL baseUrlAccess,
String theme, String themeRootPath, String resourceName)
     {
         this.context = context;
         this.baseUrlAccess = baseUrlAccess;
         this.theme = theme;
         this.themeRootPath = themeRootPath;
+        this.resourceName = resourceName;
     }
     
     public String getPortalResourceUrl(String relativePath)
@@ -104,17 +114,58 @@
     
     public String getDesktopThemeResourceUrl(String relativePath)
     {
-        if ( relativePath.startsWith( "/" ) )
-            return getPortalResourceUrl(themeRootPath + relativePath);
+        return getPortalResourceUrl(getDesktopThemeResource(relativePath));
+    }
+
+    public String getDesktopThemeResource(String relativePath)
+    {
+        if (relativePath.startsWith("/"))
+        {
+            return themeRootPath + relativePath;
+        }
         else
-            return getPortalResourceUrl(themeRootPath + "/" + relativePath);
+        {
+            return themeRootPath + "/" + relativePath;
+        }
     }
+
     public String getDesktopThemeRootUrl()
     {
         return getPortalResourceUrl(themeRootPath);
     }
+    
     public String getDesktopTheme()
     {
         return theme;
+    }
+    
+    public ResourceBundle getResourceBundle(Locale locale)
+    {
+        String resourceDirName = context.getConfig().getServletContext()
+                .getRealPath(getDesktopThemeResource(RESOURCES_DIRECTORY_NAME));
+        File resourceDir = new File(resourceDirName);
+        if (resourceName == null)
+        {
+            throw new NullPointerException("The resource file is null.");
+        }
+        if (!resourceDir.isDirectory())
+        {
+            throw new MissingResourceException(
+                    "Can't find the resource directory: " + resourceDirName,
+                    resourceName + "_" + locale, "");
+        }
+        URL[] urls = new URL[1];
+        try
+        {
+            urls[0] = resourceDir.toURL();
+        }
+        catch (MalformedURLException e)
+        {
+            throw new MissingResourceException(
+                    "The resource directory cannot be parsed as a URL: "
+                            + resourceDirName, resourceName + "_" + locale, "");
+        }
+        return ResourceBundle.getBundle(resourceName, locale,
+                new URLClassLoader(urls));
     }
 }

Modified: portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/desktop/impl/JetspeedDesktopImpl.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/desktop/impl/JetspeedDesktopImpl.java?rev=426855&r1=426854&r2=426855&view=diff
==============================================================================
--- portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/desktop/impl/JetspeedDesktopImpl.java
(original)
+++ portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/desktop/impl/JetspeedDesktopImpl.java
Sat Jul 29 17:15:56 2006
@@ -41,6 +41,12 @@
  */
 public class JetspeedDesktopImpl implements JetspeedDesktop, ServletContextAware
 {
+    private static final String TEMPLATE_EXTENSION_ATTR = "template.extension";
+
+    private static final String ID_ATTR = "id";
+    
+    private static final String RESOURCE_FILE_ATTR =  "resource.file";
+
     private static final Log log = LogFactory.getLog( JetspeedDesktopImpl.class );
 
     /** the webapp relative root of all themes */
@@ -86,7 +92,9 @@
         try
         {
             RequestDispatcher dispatcher = request.getRequest().getRequestDispatcher(path);
               
-            JetspeedDesktopContext desktopContext = new JetspeedDesktopContextImpl(request,
this.baseUrlAccess, theme, getThemeRootPath( theme ) );
+            JetspeedDesktopContext desktopContext = new JetspeedDesktopContextImpl(
+                    request, this.baseUrlAccess, theme,
+                    getThemeRootPath(theme), getResourceName(theme));
             request.getRequest().setAttribute(JetspeedDesktopContext.DESKTOP_ATTRIBUTE, desktopContext);
             dispatcher.include(request.getRequest(), request.getResponse());
         }
@@ -121,6 +129,16 @@
         return this.themesRoot + "/" +  theme + "/" + JetspeedDesktop.CONFIG_FILE_NAME;
     }
     
+    protected String getResourceName(String theme)
+    {
+        Properties themeConfiguration = (Properties)themesProperties.get(theme);
+        if (themeConfiguration == null)
+        {
+            themeConfiguration = getConfiguration(theme);
+        }
+        return themeConfiguration.getProperty(RESOURCE_FILE_ATTR);
+    }
+    
     protected String getThemePath(String theme)
     {
         Properties themeConfiguration = (Properties)themesProperties.get(theme);
@@ -128,10 +146,10 @@
         {
             themeConfiguration = getConfiguration(theme);
         }
-        String id = themeConfiguration.getProperty("id");
+        String id = themeConfiguration.getProperty(ID_ATTR);
         if (id == null)
             id = theme;
-        String ext = themeConfiguration.getProperty("template.extension");
+        String ext = themeConfiguration.getProperty(TEMPLATE_EXTENSION_ATTR);
         if (ext == null)
             ext = this.defaultExtension;
         return getThemeRootPath(theme) + "/" + id + ext;
@@ -167,14 +185,14 @@
                 log.warn("Could not locate the theme.properties configuration file for theme
\""
                         + theme +
                      "\".  This theme may not exist.");
-                props.setProperty("id", theme);
+                props.setProperty(ID_ATTR, theme);
                 props.setProperty("extension", this.defaultExtension);
             }                
         }
         catch (Exception e)
         {
             log.warn("Failed to load theme configuration.", e);
-            props.setProperty("id", theme);
+            props.setProperty(ID_ATTR, theme);
         }
         finally
         {

Modified: portals/jetspeed-2/trunk/jetspeed-api/src/java/org/apache/jetspeed/desktop/JetspeedDesktop.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/trunk/jetspeed-api/src/java/org/apache/jetspeed/desktop/JetspeedDesktop.java?rev=426855&r1=426854&r2=426855&view=diff
==============================================================================
--- portals/jetspeed-2/trunk/jetspeed-api/src/java/org/apache/jetspeed/desktop/JetspeedDesktop.java
(original)
+++ portals/jetspeed-2/trunk/jetspeed-api/src/java/org/apache/jetspeed/desktop/JetspeedDesktop.java
Sat Jul 29 17:15:56 2006
@@ -15,9 +15,6 @@
  */
 package org.apache.jetspeed.desktop;
 
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-
 import org.apache.jetspeed.request.RequestContext;
 
 /**
@@ -29,7 +26,7 @@
 public interface JetspeedDesktop 
 {
     String CONFIG_FILE_NAME = "theme.properties";
-    
+
     /**
      * Render a desktop theme.
      * 

Modified: portals/jetspeed-2/trunk/jetspeed-api/src/java/org/apache/jetspeed/desktop/JetspeedDesktopContext.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/trunk/jetspeed-api/src/java/org/apache/jetspeed/desktop/JetspeedDesktopContext.java?rev=426855&r1=426854&r2=426855&view=diff
==============================================================================
--- portals/jetspeed-2/trunk/jetspeed-api/src/java/org/apache/jetspeed/desktop/JetspeedDesktopContext.java
(original)
+++ portals/jetspeed-2/trunk/jetspeed-api/src/java/org/apache/jetspeed/desktop/JetspeedDesktopContext.java
Sat Jul 29 17:15:56 2006
@@ -15,6 +15,9 @@
  */
 package org.apache.jetspeed.desktop;
 
+import java.util.Locale;
+import java.util.ResourceBundle;
+
 /**
  * Jetspeed Desktop 
  *
@@ -25,6 +28,8 @@
 {
     String DESKTOP_ATTRIBUTE = "jetspeedDesktop";
     
+    String RESOURCES_DIRECTORY_NAME = "resources";
+    
     /**
      * Get an absolute portal from a relative URL.
      * This request adds in the servlet path such as "/desktop"
@@ -64,4 +69,5 @@
      */
     String getDesktopThemeResourceUrl(String relativePath);
     
+    public ResourceBundle getResourceBundle(Locale locale);
 }



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


Mime
View raw message