paulsp 01/11/15 19:32:07
Modified: src/java/org/apache/jetspeed/services/template
JetspeedTemplateLocatorService.java
TemplateLocatorService.java
Log:
Added Email template
PR: 4537
Submitted by: Chris Kimpton
Revision Changes Path
1.2 +74 -2
jakarta-jetspeed/src/java/org/apache/jetspeed/services/template/JetspeedTemplateLocatorService.java
Index: JetspeedTemplateLocatorService.java
===================================================================
RCS file:
/home/cvs/jakarta-jetspeed/src/java/org/apache/jetspeed/services/template/JetspeedTemplateLocatorService.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- JetspeedTemplateLocatorService.java 2001/07/07 21:06:22 1.1
+++ JetspeedTemplateLocatorService.java 2001/11/16 03:32:07 1.2
@@ -107,7 +107,9 @@
*
* @author <a href="mailto:[EMAIL PROTECTED]">David Sean Taylor</a>
* @author <a href="mailto:[EMAIL PROTECTED]">Raphael Luta</a>
- * @version $Id: JetspeedTemplateLocatorService.java,v 1.1 2001/07/07 21:06:22
taylor Exp $
+ * @author <a href="mailto:[EMAIL PROTECTED]">Paul Spener</a>
+ * @author <a href="mailto:[EMAIL PROTECTED]">Chris Kimpton</a>
+ * @version $Id: JetspeedTemplateLocatorService.java,v 1.2 2001/11/16 03:32:07
paulsp Exp $
*/
public class JetspeedTemplateLocatorService extends TurbineBaseService
@@ -119,6 +121,7 @@
private final static String DIR_PORTLETS = "/portlets";
private final static String DIR_CONTROLS = "/controls";
private final static String DIR_CONTROLLERS = "/controllers";
+ private final static String DIR_EMAILS = "/emails";
private static final String PATH_SEPARATOR = "/";
// messages
@@ -345,6 +348,53 @@
}
/**
+ * Locate an email template using Jetspeed template location algorithm,
searching by
+ * mediatype and language criteria extracted from the request state in rundata.
+ *
+ * @param data The rundata for the request.
+ * @param template The name of the template.
+ *
+ * @return The path relative to the emails directory for the requested email
template,
+ * or null if not found.
+ */
+ public String locateEmailTemplate(RunData data, String template)
+ {
+ return locateEmailTemplate( data, template, LocaleDetector.getLocale(data));
+ }
+
+ /**
+ * Locate an email template using Jetspeed template location algorithm,
searching by
+ * mediatype and language.
+ *
+ * @param data The rundata for the request.
+ * @param template The name of the template.
+ * @param locale The name of the language.
+ *
+ * @return The path relative to the emails directory for the requested email
template,
+ * or null if not found.
+ */
+ public String locateEmailTemplate(RunData data, String template, Locale locale)
+ {
+ String path = localizeTemplateName(data, locale);
+ String located = locateTemplate(data, DIR_EMAILS, path, template);
+ if (null == located)
+ {
+ // Try to locate it directly on file system, perhaps it was recently
added
+ useNameCache = false;
+ located = locateTemplate(data, DIR_EMAILS, path, template);
+ if (null != located)
+ {
+ // add it to the map
+ templateMap.put( located, null );
+ }
+ useNameCache = true;
+ }
+ if (null != located)
+ return DIR_EMAILS + located;
+ return null;
+ }
+
+ /**
* General template location algorithm. Starts with the most specific resource,
* including mediatype + nls specification, and fallsback to least specific.
*
@@ -432,8 +482,30 @@
*/
private String localizeTemplateName(RunData data)
{
+ return localizeTemplateName(data, null);
+ }
+
+ /**
+ * Helper function for template locator to find a localized (NLS) resource.
+ * Considers both language and country resources.
+ *
+ * @param data The rundata for the request.
+ * @param locale The locale for the request.
+ *
+ * @return The possible path to a localized template.
+ */
+ private String localizeTemplateName(RunData data, Locale inLocale)
+ {
+ Locale tmplocale = null;
+ if (inLocale != null)
+ {
+ tmplocale = inLocale;
+ }
+ else
+ {
+ tmplocale = LocaleDetector.getLocale(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"),
1.2 +32 -3
jakarta-jetspeed/src/java/org/apache/jetspeed/services/template/TemplateLocatorService.java
Index: TemplateLocatorService.java
===================================================================
RCS file:
/home/cvs/jakarta-jetspeed/src/java/org/apache/jetspeed/services/template/TemplateLocatorService.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- TemplateLocatorService.java 2001/07/07 21:06:22 1.1
+++ TemplateLocatorService.java 2001/11/16 03:32:07 1.2
@@ -54,15 +54,18 @@
package org.apache.jetspeed.services.template;
-import org.apache.jetspeed.om.profile.*;
+import org.apache.jetspeed.om.profile.Profile;
import org.apache.jetspeed.services.Profiler;
import org.apache.jetspeed.capability.CapabilityMap;
+import org.apache.jetspeed.util.MimeType;
+
import org.apache.turbine.om.security.User;
import org.apache.turbine.services.Service;
import org.apache.turbine.util.RunData;
import org.apache.turbine.util.DynamicURI;
-import org.apache.jetspeed.util.MimeType;
+
import java.io.IOException;
+import java.util.Locale;
/**
* <p>This interface is a facade for all template location related operations.
@@ -76,7 +79,9 @@
* <p>Example: /screens/html/en/US/resource.vm</p>
*
* @author <a href="mailto:[EMAIL PROTECTED]">David Sean Taylor</a>
- * @version $Id: TemplateLocatorService.java,v 1.1 2001/07/07 21:06:22 taylor Exp $
+ * @author <a href="mailto:[EMAIL PROTECTED]">Paul Spencer</a>
+ * @author <a href="mailto:[EMAIL PROTECTED]">Chris Kimpton</a>
+ * @version $Id: TemplateLocatorService.java,v 1.2 2001/11/16 03:32:07 paulsp Exp $
*/
public interface TemplateLocatorService extends Service
@@ -144,5 +149,29 @@
* or null if not found.
*/
public String locateControllerTemplate(RunData data, String template);
+
+ /**
+ * Locate an email template using Jetspeed template location algorithm,
searching by
+ * language criteria extracted from the request state in rundata.
+ *
+ * @param data The rundata for the request.
+ * @param template The name of the template.
+ *
+ * @return The path relative to the emails directory for the requested email
template,
+ * or null if not found.
+ */
+ public String locateEmailTemplate(RunData data, String template);
+
+ /**
+ * Locate an email template using Jetspeed template location algorithm
+ *
+ * @param data The rundata for the request.
+ * @param template The name of the template.
+ * @param locale The locale of the template.
+ *
+ * @return The path relative to the emails directory for the requested email
template,
+ * or null if not found.
+ */
+ public String locateEmailTemplate(RunData data, String template, Locale locale);
}
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>