You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jetspeed-dev@portals.apache.org by ta...@apache.org on 2001/06/04 09:14:38 UTC
cvs commit: jakarta-jetspeed/src/java/org/apache/jetspeed/services/template JetspeedTemplateService.java
taylor 01/06/04 00:14:38
Modified: src/java/org/apache/jetspeed/services Profiler.java
src/java/org/apache/jetspeed/services/profiler
JetspeedProfilerService.java ProfilerService.java
src/java/org/apache/jetspeed/services/template
JetspeedTemplateService.java
Added: src/java/org/apache/jetspeed/services JetspeedSecurity.java
Log:
- start of portlet security service
- implemented template locator service. It is implemented with 4 new methods in the Profiler. We are looking into factoring it out to a common locator service, potentially in jakarta commons.
Revision Changes Path
1.4 +34 -1 jakarta-jetspeed/src/java/org/apache/jetspeed/services/Profiler.java
Index: Profiler.java
===================================================================
RCS file: /home/cvs/jakarta-jetspeed/src/java/org/apache/jetspeed/services/Profiler.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- Profiler.java 2001/05/08 19:17:42 1.3
+++ Profiler.java 2001/06/04 07:14:37 1.4
@@ -71,7 +71,7 @@
* @see org.apache.jetspeed.services.profiler.Profiler
* @see org.apache.jetspeed.services.profiler.ProfilerService
* @author <a href="mailto:david@bluesunrise.com">David Sean Taylor</a>
- * @version $Id: Profiler.java,v 1.3 2001/05/08 19:17:42 taylor Exp $
+ * @version $Id: Profiler.java,v 1.4 2001/06/04 07:14:37 taylor Exp $
*/
public class Profiler
{
@@ -213,5 +213,38 @@
{
return getService().getResourceNameCaching();
}
+
+ /**
+ * @see ProfilerService#locateTemplate
+ */
+ public static String locateTemplate(RunData data, String path, String template)
+ {
+ return getService().locateTemplate(data, path, template);
+ }
+
+ /**
+ * @see ProfilerService#locateScreenTemplate
+ */
+ public static String locateScreenTemplate(RunData data, String template)
+ {
+ return getService().locateScreenTemplate(data, template);
+ }
+
+ /**
+ * @see ProfilerService#locateLayoutTemplate
+ */
+ public static String locateLayoutTemplate(RunData data, String template)
+ {
+ return getService().locateLayoutTemplate(data, template);
+ }
+
+ /**
+ * @see ProfilerService#locatePortletTemplate
+ */
+ public static String locatePortletTemplate(RunData data, String template)
+ {
+ return getService().locatePortletTemplate(data, template);
+ }
+
}
1.1 jakarta-jetspeed/src/java/org/apache/jetspeed/services/JetspeedSecurity.java
Index: JetspeedSecurity.java
===================================================================
/* ====================================================================
* 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 apache@apache.org.
*
* 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.services;
import org.apache.turbine.services.security.TurbineSecurity;
import org.apache.jetspeed.services.security.*;
import org.apache.turbine.util.RunData;
import org.apache.jetspeed.portal.Portlet;
/**
* <P>This is a commodity static accessor class around the
* <code>JetspeedSecurityService</code></P>
*
* @see org.apache.jetspeed.services.security.JetspeedSecurityService
* @author <a href="mailto:david@bluesunrise.com">David Sean Taylor</a>
* @version $Id: JetspeedSecurity.java,v 1.1 2001/06/04 07:14:36 taylor Exp $
*/
abstract public class JetspeedSecurity extends TurbineSecurity
{
/**
* @see JetspeedSecurityService#checkPermission
*/
public static boolean checkPermission(RunData runData, String permission, Portlet portlet)
{
return ((JetspeedSecurityService)getService()).checkPermission(runData, permission, portlet);
}
/**
* @see JetspeedSecurityService#checkPermission
*/
public static boolean checkPermission(String user, String action, Portlet portlet)
{
return ((JetspeedSecurityService)getService()).checkPermission(user, action, portlet);
}
}
1.3 +271 -6 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.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- JetspeedProfilerService.java 2001/05/08 19:18:14 1.2
+++ JetspeedProfilerService.java 2001/06/04 07:14:37 1.3
@@ -101,12 +101,14 @@
* <dt>resource.ext</dt><dd>The default resource filename extension</dd>
* <dt>security</dt><dd>Use security flag</dd>
* <dt>language</dt><dd>Use language configuration flag</dd>
+ *
+ * <dt>templatRoot</dt><dd>The webapp rel. path to the root template directory</dd>
* </dl>
* </p>
*
* @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.2 2001/05/08 19:18:14 taylor Exp $
+ * @version $Id: JetspeedProfilerService.java,v 1.3 2001/06/04 07:14:37 taylor Exp $
*/
public class JetspeedProfilerService extends TurbineBaseService
@@ -121,6 +123,7 @@
public final static String TEMP_USER = "temp_user";
// configuration keys
private final static String CONFIG_ROOT = ".root";
+ private final static String CONFIG_TEMPLATE_ROOT = ".templateRoot";
private final static String CONFIG_RESOURCE_DEFAULT = ".resource.default";
private final static String CONFIG_RESOURCE_EXT = ".resource.ext";
private final static String CONFIG_SECURITY = ".security";
@@ -145,17 +148,22 @@
// configuration parameters
String root; // the root psml resource directory
+ String templateRoot;
String resourceDefault; // the default name for a resource
String resourceExt; // the default extension for a resource
boolean useSecurity = false; // use security features
boolean useLanguage = true; // use extended language mapping features
boolean useNameCache = true; // use the cache to check existence of resources
+ // template configuration parameters
+
+
// lookup a media type based on mime-type
private Map mediaMap = null;
// fallback map of resources
private Map resourceMap = null;
+ private Map templateMap = null;
/**
* This is the early initialization method called by the
@@ -606,7 +614,7 @@
StringBuffer fullPath = new StringBuffer( root );
fullPath.append(path);
- if (!path.endsWith(PATH_SEPARATOR))
+ if (path.length() > 0 && !path.endsWith(PATH_SEPARATOR))
fullPath.append(PATH_SEPARATOR);
// search for language specific resources at each level
@@ -788,6 +796,16 @@
+ ProfilerService.SERVICE_NAME
+ CONFIG_NAMECACHE,
true);
+
+ templateRoot = JetspeedResources.getString(TurbineServices.SERVICE_PREFIX
+ + ProfilerService.SERVICE_NAME
+ + CONFIG_TEMPLATE_ROOT);
+ if (templateRoot == null)
+ throw new InitializationException(
+ MSG_MISSING_PARAMETER + CONFIG_TEMPLATE_ROOT);
+ if (!templateRoot.endsWith(PATH_SEPARATOR))
+ templateRoot = templateRoot + PATH_SEPARATOR;
+
}
/**
@@ -804,8 +822,14 @@
// traverse starting from the root directory and add resources
String realRootPath = TurbineServlet.getRealPath( root );
- traverseResources( realRootPath, "" );
+ if (null != realRootPath)
+ traverseResources( realRootPath, "", resourceMap );
+ templateMap = new HashMap();
+ // traverse starting from the root template directory and add resources
+ realRootPath = TurbineServlet.getRealPath( templateRoot );
+ if (null != realRootPath)
+ traverseResources( realRootPath, "", templateMap );
}
/**
@@ -814,13 +838,13 @@
* @parameter path the file path with file name of the resource
* @parameter name just the name of the resource
*/
- private void traverseResources(String path, String name)
+ private void traverseResources(String path, String name, Map map)
{
File file = new File(path);
if(file.isFile()) {
// add it to the map
- resourceMap.put( path, null );
+ map.put( path, null );
} else if(file.isDirectory()) {
@@ -831,7 +855,7 @@
// Process all files recursivly
for(int ix = 0; list != null && ix < list.length; ix++)
- traverseResources(path + list[ix], list[ix]);
+ traverseResources(path + list[ix], list[ix], map);
}
}
@@ -882,6 +906,247 @@
uri.addPathInfo(PARAM_PAGE, page);
return uri;
+ }
+
+ /**
+ * Locate a screen template using the Profiler's fallback algorithm
+ *
+ * @param data the rundata for the request.
+ * @param template the name of the template
+ *
+ * @return the exact path to the screen template, or null if not found
+ */
+ public String locateScreenTemplate(RunData data, String template)
+ {
+ String path = localizeTemplateName(data);
+ if (!template.startsWith("/"))
+ path = path + "/" ;
+
+ 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;
+ }
+
+ /**
+ * Locate a layout template using the Profiler's fallback algorithm
+ *
+ * @param data the rundata for the request.
+ * @param template the name of the template
+ *
+ * @return the exact path to the layout template, or null if not found
+ */
+ public String locateLayoutTemplate(RunData data, String template)
+ {
+ String path = localizeTemplateName(data);
+ if (!template.startsWith("/"))
+ path = path + "/" ;
+
+ 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;
+ }
+
+ /**
+ * Locate a portlet template using the Profiler's fallback algorithm
+ *
+ * @param data the rundata for the request.
+ * @param template the name of the template
+ *
+ * @return the exact path to the portlet template, or null if not found
+ */
+ 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);
+ }
+
+ /**
+ * Locate a template using the Profiler's fallback algorithm
+ *
+ * @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)
+ {
+ String finalPath;
+ int len = template.length();
+ if (template.startsWith("/") && len > 1)
+ template = template.substring(1, len);
+
+ while( (finalPath = templateFallback(path, template)) == "") {
+ int pt = path.lastIndexOf(PATH_SEPARATOR);
+ if (-1 == pt)
+ {
+ 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
+ }
+ int length = path.length();
+ if (pt == length - 1 && length > 1)
+ {
+ //pt = pt - 1;
+ path = path.substring(0, pt);
+ pt = path.lastIndexOf(PATH_SEPARATOR);
+ }
+ 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;
+ }
+
+ /**
+ * helper function for template locator to find a localized (NLS) resource
+ *
+ * @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
+ */
+ private String localizeTemplateName(RunData data)
+ {
+ // Get the locale store it in the user object
+ Locale tmplocale = LocaleDetector.getLocale(data);
+ if (tmplocale == null) {
+ tmplocale = new Locale(
+ TurbineResources.getString("locale.default.language", "en"),
+ TurbineResources.getString("locale.default.country", "US"));
+ }
+
+ data.getUser().setTemp("locale", tmplocale);
+
+ StringBuffer templatePath = new StringBuffer();
+
+ // set the content type (including charset)
+ CapabilityMap cm = CapabilityMapFactory.getCapabilityMap( data );
+ String type = MimeType.getCode( cm.getPreferredType() );
+ 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();
+ String country = locale.getCountry();
+ if ((language != null) && (language.length() > 0))
+ templatePath.append("/").append(language);
+ if ((country != null) && (country.length() > 0))
+ templatePath.append("/").append(country);
+
+ return templatePath.toString();
+ }
+
+ /*
+ * string manipulation function to remove a prefixed substring from a string
+ *
+ * @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;
+ }
+
+ /**
+ * 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
+ *
+ * @parameter key the resource name.
+ */
+ public boolean templateExists(String templateKey)
+ {
+ if (useNameCache == true)
+ {
+ return templateMap.containsKey(templateKey);
+ }
+ return (new File(templateKey).exists());
}
}
1.3 +13 -1 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.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- ProfilerService.java 2001/05/08 19:18:16 1.2
+++ ProfilerService.java 2001/06/04 07:14:37 1.3
@@ -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.2 2001/05/08 19:18:16 taylor Exp $
+ * @version $Id: ProfilerService.java,v 1.3 2001/06/04 07:14:37 taylor Exp $
*/
public interface ProfilerService extends Service
@@ -200,5 +200,17 @@
* @return the resource caching status: true in on, false is off
*/
public boolean getResourceNameCaching();
+
+ /**
+ * Locate a template using the Profiler's fallback algorithm
+ *
+ * @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 locateScreenTemplate(RunData data, String template);
+ public String locateLayoutTemplate(RunData data, String template);
+ public String locatePortletTemplate(RunData data, String template);
}
1.5 +2 -1 jakarta-jetspeed/src/java/org/apache/jetspeed/services/template/JetspeedTemplateService.java
Index: JetspeedTemplateService.java
===================================================================
RCS file: /home/cvs/jakarta-jetspeed/src/java/org/apache/jetspeed/services/template/JetspeedTemplateService.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- JetspeedTemplateService.java 2001/04/03 12:13:45 1.4
+++ JetspeedTemplateService.java 2001/06/04 07:14:38 1.5
@@ -91,7 +91,8 @@
*/
public class JetspeedTemplateService
extends TurbineBaseService
- implements TemplateService
+ // implements TemplateService
+ // removed dst: 2001/06/03, TDK 2.2 integration
{
/** The hashtable used to cache Screen names. */
private Hashtable screenCache = null;
---------------------------------------------------------------------
To unsubscribe, e-mail: jetspeed-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: jetspeed-dev-help@jakarta.apache.org