You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@turbine.apache.org by he...@apache.org on 2003/07/22 12:58:51 UTC
cvs commit: jakarta-turbine-2/src/java/org/apache/turbine/services/template/mapper BaseMapper.java BaseTemplateMapper.java ClassMapper.java DirectMapper.java LayoutTemplateMapper.java Mapper.java ScreenDefaultTemplateMapper.java ScreenTemplateMapper.java TemplateBaseLayoutMapper.java TemplateBaseMapper.java TemplateClassMapper.java TemplateDirectMapper.java TemplateLayoutMapper.java TemplateMapper.java TemplateScreenDefaultMapper.java TemplateScreenMapper.java
henning 2003/07/22 03:58:50
Modified: src/java/org/apache/turbine/services/template
TurbineTemplateService.java
Added: src/java/org/apache/turbine/services/template/mapper
BaseMapper.java BaseTemplateMapper.java
ClassMapper.java DirectMapper.java
LayoutTemplateMapper.java Mapper.java
ScreenDefaultTemplateMapper.java
ScreenTemplateMapper.java
Removed: src/java/org/apache/turbine/services/template/mapper
TemplateBaseLayoutMapper.java
TemplateBaseMapper.java TemplateClassMapper.java
TemplateDirectMapper.java TemplateLayoutMapper.java
TemplateMapper.java
TemplateScreenDefaultMapper.java
TemplateScreenMapper.java
Log:
Big Mapper Class renaming:
TemplateBaseLayoutMapper -> BaseTemplateMapper
TemplateBaseMapper -> BaseMapper
TemplateClassMapper -> ClassMapper
TemplateDirectMapper -> DirectMapper
TemplateLayoutMapper -> LayoutTemplateMapper
TemplateMapper -> Mapper
TemplateScreenDefaultMapper -> ScreenDefaultTemplateMapper
TemplateScreenMapper -> ScreenTemplateMapper
Revision Changes Path
1.17 +38 -38 jakarta-turbine-2/src/java/org/apache/turbine/services/template/TurbineTemplateService.java
Index: TurbineTemplateService.java
===================================================================
RCS file: /home/cvs/jakarta-turbine-2/src/java/org/apache/turbine/services/template/TurbineTemplateService.java,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -r1.16 -r1.17
--- TurbineTemplateService.java 22 Jul 2003 10:33:27 -0000 1.16
+++ TurbineTemplateService.java 22 Jul 2003 10:58:49 -0000 1.17
@@ -78,13 +78,13 @@
import org.apache.turbine.services.TurbineBaseService;
import org.apache.turbine.services.factory.TurbineFactory;
import org.apache.turbine.services.servlet.TurbineServlet;
-import org.apache.turbine.services.template.mapper.TemplateBaseLayoutMapper;
-import org.apache.turbine.services.template.mapper.TemplateBaseMapper;
-import org.apache.turbine.services.template.mapper.TemplateClassMapper;
-import org.apache.turbine.services.template.mapper.TemplateDirectMapper;
-import org.apache.turbine.services.template.mapper.TemplateLayoutMapper;
-import org.apache.turbine.services.template.mapper.TemplateMapper;
-import org.apache.turbine.services.template.mapper.TemplateScreenMapper;
+import org.apache.turbine.services.template.mapper.BaseMapper;
+import org.apache.turbine.services.template.mapper.BaseTemplateMapper;
+import org.apache.turbine.services.template.mapper.ClassMapper;
+import org.apache.turbine.services.template.mapper.DirectMapper;
+import org.apache.turbine.services.template.mapper.LayoutTemplateMapper;
+import org.apache.turbine.services.template.mapper.Mapper;
+import org.apache.turbine.services.template.mapper.ScreenTemplateMapper;
import org.apache.turbine.util.RunData;
import org.apache.turbine.util.TurbineException;
import org.apache.turbine.util.uri.URIConstants;
@@ -262,7 +262,7 @@
public static final int TEMPLATE_TYPES = 7;
/** Here we register the mapper objects for our various object types */
- private TemplateMapper [] mapperRegistry = null;
+ private Mapper [] mapperRegistry = null;
/**
* The default file extension used as a registry key when a
@@ -329,7 +329,7 @@
templateEngineRegistry = Collections.synchronizedMap(new HashMap());
- initTemplateMapper(config);
+ initMapper(config);
setInit(true);
}
@@ -458,7 +458,7 @@
*/
public String getDefaultPageName(String template)
{
- return ((TemplateMapper) mapperRegistry[PAGE_KEY]).getDefaultName(template);
+ return ((Mapper) mapperRegistry[PAGE_KEY]).getDefaultName(template);
}
/**
@@ -471,7 +471,7 @@
*/
public String getDefaultScreenName(String template)
{
- return ((TemplateMapper) mapperRegistry[SCREEN_KEY]).getDefaultName(template);
+ return ((Mapper) mapperRegistry[SCREEN_KEY]).getDefaultName(template);
}
/**
@@ -484,7 +484,7 @@
*/
public String getDefaultLayoutName(String template)
{
- return ((TemplateMapper) mapperRegistry[LAYOUT_KEY]).getDefaultName(template);
+ return ((Mapper) mapperRegistry[LAYOUT_KEY]).getDefaultName(template);
}
/**
@@ -497,7 +497,7 @@
*/
public String getDefaultNavigationName(String template)
{
- return ((TemplateMapper) mapperRegistry[NAVIGATION_KEY]).getDefaultName(template);
+ return ((Mapper) mapperRegistry[NAVIGATION_KEY]).getDefaultName(template);
}
/**
@@ -510,7 +510,7 @@
*/
public String getDefaultLayoutTemplateName(String template)
{
- return ((TemplateMapper) mapperRegistry[LAYOUT_TEMPLATE_KEY]).getDefaultName(template);
+ return ((Mapper) mapperRegistry[LAYOUT_TEMPLATE_KEY]).getDefaultName(template);
}
/**
@@ -552,7 +552,7 @@
public String getScreenName(String template)
throws Exception
{
- return ((TemplateMapper) mapperRegistry[SCREEN_KEY]).getMappedName(template);
+ return ((Mapper) mapperRegistry[SCREEN_KEY]).getMappedName(template);
}
/**
@@ -566,7 +566,7 @@
public String getLayoutName(String template)
throws Exception
{
- return ((TemplateMapper) mapperRegistry[LAYOUT_KEY]).getMappedName(template);
+ return ((Mapper) mapperRegistry[LAYOUT_KEY]).getMappedName(template);
}
/**
@@ -580,7 +580,7 @@
public String getNavigationName(String template)
throws Exception
{
- return ((TemplateMapper) mapperRegistry[NAVIGATION_KEY]).getMappedName(template);
+ return ((Mapper) mapperRegistry[NAVIGATION_KEY]).getMappedName(template);
}
/**
@@ -595,7 +595,7 @@
public String getScreenTemplateName(String template)
throws Exception
{
- return ((TemplateMapper) mapperRegistry[SCREEN_TEMPLATE_KEY]).getMappedName(template);
+ return ((Mapper) mapperRegistry[SCREEN_TEMPLATE_KEY]).getMappedName(template);
}
/**
@@ -609,7 +609,7 @@
public String getLayoutTemplateName(String template)
throws Exception
{
- return ((TemplateMapper) mapperRegistry[LAYOUT_TEMPLATE_KEY]).getMappedName(template);
+ return ((Mapper) mapperRegistry[LAYOUT_TEMPLATE_KEY]).getMappedName(template);
}
/**
@@ -624,7 +624,7 @@
public String getNavigationTemplateName(String template)
throws Exception
{
- return ((TemplateMapper) mapperRegistry[NAVIGATION_TEMPLATE_KEY]).getMappedName(template);
+ return ((Mapper) mapperRegistry[NAVIGATION_TEMPLATE_KEY]).getMappedName(template);
}
/**
@@ -703,9 +703,9 @@
* object type which is managed by the TemplateService.
*
* @param templateKey One of the _KEY constants for the Template object types.
- * @param mapper An object which implements the TemplateMapper interface.
+ * @param mapper An object which implements the Mapper interface.
*/
- private void registerMapper(int templateKey, TemplateMapper mapper)
+ private void registerMapper(int templateKey, Mapper mapper)
{
mapper.init();
mapperRegistry[templateKey] = mapper;
@@ -718,14 +718,14 @@
* @param conf The current configuration object.
* @throws InitializationException A problem occured trying to set up the mappers.
*/
- private void initTemplateMapper(Configuration conf)
+ private void initMapper(Configuration conf)
throws InitializationException
{
// Create a registry with the number of Template Types managed by this service.
// We could use a List object here and extend the number of managed objects
// dynamically. However, by using an Object Array, we get much more performance
// out of the Template Service.
- mapperRegistry = new TemplateMapper [TEMPLATE_TYPES];
+ mapperRegistry = new Mapper [TEMPLATE_TYPES];
String [] mapperNames = new String [] {
PAGE_NAME,SCREEN_NAME, LAYOUT_NAME,
@@ -733,13 +733,13 @@
};
String [] mapperClasses = new String [] {
- TemplateDirectMapper.class.getName(),
- TemplateClassMapper.class.getName(),
- TemplateClassMapper.class.getName(),
- TemplateClassMapper.class.getName(),
- TemplateLayoutMapper.class.getName(),
- TemplateScreenMapper.class.getName(),
- TemplateScreenMapper.class.getName()
+ DirectMapper.class.getName(),
+ ClassMapper.class.getName(),
+ ClassMapper.class.getName(),
+ ClassMapper.class.getName(),
+ LayoutTemplateMapper.class.getName(),
+ ScreenTemplateMapper.class.getName(),
+ ScreenTemplateMapper.class.getName()
};
int [] mapperCacheSize = new int [] {
@@ -801,11 +801,11 @@
log.info("Using " + mapperClass + " to map " + mapperNames[i] + " elements");
- TemplateMapper tm = null;
+ Mapper tm = null;
try
{
- tm = (TemplateMapper) TurbineFactory.getInstance(mapperClass);
+ tm = (Mapper) TurbineFactory.getInstance(mapperClass);
}
catch (TurbineException te)
{
@@ -817,14 +817,14 @@
tm.setDefaultProperty(mapperDefaultProperty[i]);
tm.setSeparator(mapperSeparator[i]);
- if ((mapperLoader[i] != null) && (tm instanceof TemplateClassMapper))
+ if ((mapperLoader[i] != null) && (tm instanceof ClassMapper))
{
- ((TemplateClassMapper) tm).setLoader(mapperLoader[i]);
+ ((ClassMapper) tm).setLoader(mapperLoader[i]);
}
- if ((mapperPrefix[i] != null) && (tm instanceof TemplateBaseLayoutMapper))
+ if ((mapperPrefix[i] != null) && (tm instanceof BaseTemplateMapper))
{
- ((TemplateBaseLayoutMapper) tm).setPrefix(mapperPrefix[i]);
+ ((BaseTemplateMapper) tm).setPrefix(mapperPrefix[i]);
}
registerMapper(i, tm);
1.1 jakarta-turbine-2/src/java/org/apache/turbine/services/template/mapper/BaseMapper.java
Index: BaseMapper.java
===================================================================
package org.apache.turbine.services.template.mapper;
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2001-2003 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 Turbine" 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",
* "Apache Turbine", 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/>.
*/
import java.util.HashMap;
import java.util.Map;
import org.apache.commons.lang.StringUtils;
import org.apache.turbine.services.template.TurbineTemplate;
import org.apache.turbine.services.template.TemplateEngineService;
/**
* A base class for the various mappers which contains common
* code.
*
* @author <a href="mailto:hps@intermeta.de">Henning P. Schmiedehausen</a>
* @version $Id: BaseMapper.java,v 1.1 2003/07/22 10:58:49 henning Exp $
*/
public abstract class BaseMapper
{
/** True if this mapper should cache template -> name mappings */
private boolean useCache = false;
/** Default cache size. Just a number out of thin air. Will be set at init time */
private int cacheSize = 5;
/** The internal template -> name mapping cache */
private Map templateCache = null;
/** The name of the default property to pull from the Template Engine Service if the default is requested */
protected String defaultProperty;
/** The separator used to concatenate the result parts for this mapper. */
protected char separator;
// Note: You might _not_ use TurbineTemplate.<xxx> in the C'tor and the init method.
// The service isn't configured yet and if you do, the Broker will try to reinit the
// Service which leads to an endless loop and a deadlock.
/**
* Default C'tor. If you use this C'tor, you must use
* the bean setter to set the various properties needed for
* this mapper before first usage.
*/
public BaseMapper()
{
}
/**
* Get the CacheSize value.
* @return the CacheSize value.
*/
public int getCacheSize()
{
return cacheSize;
}
/**
* Set the CacheSize value.
* @param cacheSize The new CacheSize value.
*/
public void setCacheSize(int cacheSize)
{
this.cacheSize = cacheSize;
}
/**
* Get the UseCache value.
* @return the UseCache value.
*/
public boolean isUseCache()
{
return useCache;
}
/**
* Set the UseCache value.
* @param newUseCache The new UseCache value.
*/
public void setUseCache(boolean useCache)
{
this.useCache = useCache;
}
/**
* Get the DefaultProperty value.
* @return the DefaultProperty value.
*/
public String getDefaultProperty()
{
return defaultProperty;
}
/**
* Set the DefaultProperty value.
* @param defaultProperty The new DefaultProperty value.
*/
public void setDefaultProperty(String defaultProperty)
{
this.defaultProperty = defaultProperty;
}
/**
* Get the Separator value.
* @return the Separator value.
*/
public char getSeparator()
{
return separator;
}
/**
* Set the Separator value.
* @param separator The new Separator value.
*/
public void setSeparator(char separator)
{
this.separator = separator;
}
/**
* Initializes the Mapper. Must be called before the mapper might be used.
*/
public void init()
{
if (useCache)
{
templateCache = new HashMap(cacheSize);
}
}
/**
* Returns the default name for the passed Template.
* If the passed template has no extension,
* the default extension is assumed.
* If the template is empty, the default template is
* returned.
*
* @param template The template name.
*
* @return the mapped default name for the template.
*/
public String getDefaultName(String template)
{
// We might get a Name without an extension passed. If yes, then we use
// the Default extension
TemplateEngineService tes
= TurbineTemplate.getTemplateEngineService(template);
if (StringUtils.isEmpty(template) || (tes == null))
{
return TurbineTemplate.getDefaultTemplate();
}
String defaultName = (String) tes.getTemplateEngineServiceConfiguration()
.get(defaultProperty);
return StringUtils.isEmpty(defaultName)
? TurbineTemplate.getDefaultTemplate()
: defaultName;
}
/**
* Return the first match name for the given template name.
*
* @param template The template name.
*
* @return The first matching class or template name.
*/
public String getMappedName(String template)
{
if (StringUtils.isEmpty(template))
{
return null;
}
if (useCache && templateCache.containsKey(template))
{
return (String) templateCache.get(template);
}
String res = doMapping(template);
// Never cache "null" return values and empty Strings.
if (useCache && StringUtils.isNotEmpty(res))
{
templateCache.put(template, res);
}
return res;
}
/**
* The actual mapping implementation class. It
* is guaranteed that never an empty or null
* template name is passed to it. This might
* return null.
*
* @param template The template name.
* @return The mapped class or template name.
*/
public abstract String doMapping(String template);
}
1.1 jakarta-turbine-2/src/java/org/apache/turbine/services/template/mapper/BaseTemplateMapper.java
Index: BaseTemplateMapper.java
===================================================================
package org.apache.turbine.services.template.mapper;
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2001-2003 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 Turbine" 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",
* "Apache Turbine", 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/>.
*/
import org.apache.commons.lang.StringUtils;
import org.apache.turbine.services.template.TemplateService;
import org.apache.turbine.services.template.TurbineTemplate;
/**
* This is a mapper like the BaseMapper but it returns its
* results with the extension of the template names passed or (if no
* extension is passed), the default extension.
*
* @author <a href="mailto:hps@intermeta.de">Henning P. Schmiedehausen</a>
* @version $Id: BaseTemplateMapper.java,v 1.1 2003/07/22 10:58:49 henning Exp $
*/
public abstract class BaseTemplateMapper
extends BaseMapper
{
/** A prefix which is used to separate the various template types (screen, layouts, navigation) */
protected String prefix = "";
/**
* Default C'tor. If you use this C'tor, you must use
* the bean setter to set the various properties needed for
* this mapper before first usage.
*/
public BaseTemplateMapper()
{
super();
}
/**
* Get the Prefix value.
* @return the Prefix value.
*/
public String getPrefix()
{
return prefix;
}
/**
* Set the Prefix value.
* @param prefix The new Prefix value.
*/
public void setPrefix(String prefix)
{
this.prefix = prefix;
}
/**
* Returns the default name for the passed Template.
* If the template has no extension, the default extension
* is added.
* If the template is empty, the default template is
* returned.
*
* @param template The template name.
*
* @return the mapped default name for the template.
*/
public String getDefaultName(String template)
{
String res = super.getDefaultName(template);
// Does the Template Name component have an extension?
String [] components
= StringUtils.split(res, String.valueOf(separator));
if (components[components.length -1 ].indexOf(TemplateService.EXTENSION_SEPARATOR) < 0)
{
StringBuffer resBuf = new StringBuffer();
resBuf.append(res);
String [] templateComponents = StringUtils.split(template, String.valueOf(TemplateService.TEMPLATE_PARTS_SEPARATOR));
// Only the extension of the Template name component is interesting...
int dotIndex = templateComponents[templateComponents.length -1].lastIndexOf(TemplateService.EXTENSION_SEPARATOR);
if (dotIndex < 0)
{
if (StringUtils.isNotEmpty(TurbineTemplate.getDefaultExtension()))
{
resBuf.append(TemplateService.EXTENSION_SEPARATOR);
resBuf.append(TurbineTemplate.getDefaultExtension());
}
}
else
{
resBuf.append(templateComponents[templateComponents.length -1].substring(dotIndex));
}
res = resBuf.toString();
}
return res;
}
}
1.1 jakarta-turbine-2/src/java/org/apache/turbine/services/template/mapper/ClassMapper.java
Index: ClassMapper.java
===================================================================
package org.apache.turbine.services.template.mapper;
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2001-2003 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 Turbine" 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",
* "Apache Turbine", 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/>.
*/
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import org.apache.commons.lang.StringUtils;
import org.apache.turbine.modules.Loader;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.turbine.services.template.TemplateService;
/**
* This mapper tries to map Template names to class names. If no direct match
* is found, it tries matches "upwards" in the package hierarchy until either
* a match is found or the root is hit. Then it returns the name of the
* default class from the TemplateEngineService.
*
* 1. about.directions.Driving <- direct matching the template to the class name
* 2. about.directions.Default <- matching the package, class name is Default
* 3. about.Default <- stepping up in the package hierarchy, looking for Default
* 4. Default <- Class called "Default" without package
* 5. VelocityScreen <- The class configured by the Service (VelocityService) to
*
* Please note, that no actual packages are searched. This is the scope of the
* TemplateEngine Loader which is passed at construction time.
*
* @author <a href="mailto:hps@intermeta.de">Henning P. Schmiedehausen</a>
* @version $Id: ClassMapper.java,v 1.1 2003/07/22 10:58:49 henning Exp $
*/
public class ClassMapper
extends BaseMapper
implements Mapper
{
/** The loader for actually trying out the package names */
private Loader loader = null;
/** Logging */
private static Log log = LogFactory.getLog(ClassMapper.class);
/**
* Default C'tor. If you use this C'tor, you must use
* the bean setter to set the various properties needed for
* this mapper before first usage.
*/
public ClassMapper()
{
}
/**
* Get the Loader value.
* @return the Loader value.
*/
public Loader getLoader()
{
return loader;
}
/**
* Set the Loader value.
* @param loader The new Loader value.
*/
public void setLoader(Loader loader)
{
this.loader = loader;
log.debug("Loader is " + this.loader);
}
/**
* Strip off a possible extension, replace all "," with "."
* Look through the given package path until a match is found.
*
* @param template The template name.
* @return A class name for the given template.
*/
public String doMapping(String template)
{
log.debug("doMapping(" + template + ")");
// Copy our elements into an array
List components
= new ArrayList(Arrays.asList(StringUtils.split(
template,
String.valueOf(TemplateService.TEMPLATE_PARTS_SEPARATOR))));
int componentSize = components.size() - 1 ;
// This method never gets an empty string passed.
// So this is never < 0
String className = (String) components.get(componentSize);
components.remove(componentSize--);
log.debug("className is " + className);
// Strip off a possible Extension
int dotIndex = className.lastIndexOf(TemplateService.EXTENSION_SEPARATOR);
className = (dotIndex < 0) ? className : className.substring(0, dotIndex);
// This is an optimization. If the name we're looking for is
// already the default name for the template, don't do a "first run"
// which looks for an exact match.
boolean firstRun = !className.equals(TemplateService.DEFAULT_NAME);
for(;;)
{
String pkg = StringUtils.join(components.iterator(), String.valueOf(separator));
StringBuffer testName = new StringBuffer();
log.debug("classPackage is now: " + pkg);
if (!components.isEmpty())
{
testName.append(pkg);
testName.append(separator);
}
testName.append((firstRun)
? className
: TemplateService.DEFAULT_NAME);
log.debug("Looking for " + testName);
try
{
loader.getAssembler(testName.toString());
log.debug("Found it, returning " + testName);
return testName.toString();
}
catch (Exception e)
{
// Not found. Go on.
}
if (firstRun)
{
firstRun = false;
}
else
{
if (components.isEmpty())
{
break; // for(;;)
}
components.remove(componentSize--);
}
}
log.debug("Returning default");
return getDefaultName(template);
}
}
1.1 jakarta-turbine-2/src/java/org/apache/turbine/services/template/mapper/DirectMapper.java
Index: DirectMapper.java
===================================================================
package org.apache.turbine.services.template.mapper;
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2001-2003 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 Turbine" 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",
* "Apache Turbine", 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/>.
*/
import org.apache.commons.lang.StringUtils;
import org.apache.turbine.services.template.TemplateService;
/**
* The most primitive mapper. It is used for the page objects in the
* Template service. It never caches and simply returns what is given to it.
*
* @author <a href="mailto:hps@intermeta.de">Henning P. Schmiedehausen</a>
* @version $Id: DirectMapper.java,v 1.1 2003/07/22 10:58:49 henning Exp $
*/
public class DirectMapper
extends BaseMapper
implements Mapper
{
/**
* Default C'tor. If you use this C'tor, you must use
* the bean setter to set the various properties needed for
* this mapper before first usage.
*/
public DirectMapper()
{
}
/**
* Strip off a possible extension, replace all "," with "."
*
* about,directions,Driving.vm --> about.directions.Driving
*
* @param template The template name.
* @return A class name for the given template.
*/
public String doMapping(String template)
{
String [] components
= StringUtils.split(template, String.valueOf(TemplateService.TEMPLATE_PARTS_SEPARATOR));
String className = components[components.length - 1];
// Strip off a possible Extension
int dotIndex = className.lastIndexOf(TemplateService.EXTENSION_SEPARATOR);
className = (dotIndex < 0) ? className : className.substring(0, dotIndex);
components[components.length -1] = className;
// Class names are always separated by "."
return StringUtils.join(components, String.valueOf(separator));
}
}
1.1 jakarta-turbine-2/src/java/org/apache/turbine/services/template/mapper/LayoutTemplateMapper.java
Index: LayoutTemplateMapper.java
===================================================================
package org.apache.turbine.services.template.mapper;
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2001-2003 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 Turbine" 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",
* "Apache Turbine", 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/>.
*/
import java.util.List;
import java.util.ArrayList;
import java.util.Arrays;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.turbine.services.template.TemplateEngineService;
import org.apache.turbine.services.template.TemplateService;
import org.apache.turbine.services.template.TurbineTemplate;
/**
* This mapper is responsible for the lookup of templates for the Layout
* It tries to look in various packages for a match:
*
* 1. about,directions,Driving.vm <- exact match
* 2. about,directions,Default.vm <- package match, Default name
* 3. about,Default.vm <- stepping up in the hierarchy
* 4. Default.vm <- The name configured as default.layout.template
* in the corresponding Templating Engine
*
* @author <a href="mailto:hps@intermeta.de">Henning P. Schmiedehausen</a>
* @version $Id: LayoutTemplateMapper.java,v 1.1 2003/07/22 10:58:49 henning Exp $
*/
public class LayoutTemplateMapper
extends BaseTemplateMapper
implements Mapper
{
/** Logging */
private static Log log = LogFactory.getLog(LayoutTemplateMapper.class);
/**
* Default C'tor. If you use this C'tor, you must use
* the bean setter to set the various properties needed for
* this mapper before first usage.
*/
public LayoutTemplateMapper()
{
}
/**
* Look for a given Template, then try the
* defaults until we hit the root.
*
* @param template The template name.
* @return The parsed module name.
*/
public String doMapping(String template)
{
log.debug("doMapping(" + template + ")");
// Copy our elements into an array
List components
= new ArrayList(Arrays.asList(StringUtils.split(
template,
String.valueOf(TemplateService.TEMPLATE_PARTS_SEPARATOR))));
int componentSize = components.size() - 1 ;
// This method never gets an empty string passed.
// So this is never < 0
String templateName = (String) components.get(componentSize);
components.remove(componentSize--);
log.debug("templateName is " + templateName);
// Last element decides, which template Service to use...
TemplateEngineService tes = TurbineTemplate.getTemplateEngineService(templateName);
if (tes == null)
{
return null;
}
String defaultName =
TurbineTemplate.getDefaultLayoutTemplateName(templateName); // We're, after all, a Layout Template Mapper...
// This is an optimization. If the name we're looking for is
// already the default name for the template, don't do a "first run"
// which looks for an exact match.
boolean firstRun = !templateName.equals(defaultName);
for(;;)
{
String templatePackage = StringUtils.join(components.iterator(), String.valueOf(separator));
log.debug("templatePackage is now: " + templatePackage);
StringBuffer testName = new StringBuffer();
if (!components.isEmpty())
{
testName.append(templatePackage);
testName.append(separator);
}
testName.append((firstRun)
? templateName
: defaultName);
// But the Templating service must look for the name with prefix
StringBuffer templatePath = new StringBuffer();
if (StringUtils.isNotEmpty(prefix))
{
templatePath.append(prefix);
templatePath.append(separator);
}
templatePath.append(testName);
log.debug("Looking for " + templatePath);
if (tes.templateExists(templatePath.toString()))
{
log.debug("Found it, returning " + testName);
return testName.toString();
}
if (firstRun)
{
firstRun = false;
}
else
{
// We're no longer on the first Run (so we
// already tested the "Default" template)
// and the package is empty (we've hit the
// root. So we now break the endless loop.
if (components.isEmpty())
{
break; // for(;;)
}
// We still have components. Remove the
// last one and go through the loop again.
components.remove(componentSize--);
}
}
log.debug("Returning default");
return getDefaultName(template);
}
}
1.1 jakarta-turbine-2/src/java/org/apache/turbine/services/template/mapper/Mapper.java
Index: Mapper.java
===================================================================
package org.apache.turbine.services.template.mapper;
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2001-2003 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 Turbine" 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",
* "Apache Turbine", 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/>.
*/
/**
* To separate out the various map and search policies for class
* names and template names, we use classes that implement this
* interface.
*
* @author <a href="mailto:hps@intermeta.de">Henning P. Schmiedehausen</a>
* @version $Id: Mapper.java,v 1.1 2003/07/22 10:58:49 henning Exp $
*/
public interface Mapper
{
/**
* Mapper initialization.
*/
void init();
/**
* Get the CacheSize value.
* @return the CacheSize value.
*/
int getCacheSize();
/**
* Set the CacheSize value.
* @param cacheSize The new CacheSize value.
*/
void setCacheSize(int cacheSize);
/**
* Get the UseCache value.
* @return the UseCache value.
*/
boolean isUseCache();
/**
* Set the UseCache value.
* @param newUseCache The new UseCache value.
*/
void setUseCache(boolean useCache);
/**
* Get the DefaultProperty value.
* @return the DefaultProperty value.
*/
String getDefaultProperty();
/**
* Set the DefaultProperty value.
* @param defaultProperty The new DefaultProperty value.
*/
void setDefaultProperty(String defaultProperty);
/**
* Get the Separator value.
* @return the Separator value.
*/
char getSeparator();
/**
* Set the Separator value.
* @param separator The new Separator value.
*/
void setSeparator(char separator);
/**
* Returns the default name for the supplied template
* name. Must never return null.
*
* @param template The template name.
*
* @return The default name for this template.
*/
String getDefaultName(String template);
/**
* Return the first match name for the given template name.
* This method might return null if no possible match can
* be found.
*
* @param template The template name.
*
* @return The first matching class or template name.
*/
String getMappedName(String template);
}
1.1 jakarta-turbine-2/src/java/org/apache/turbine/services/template/mapper/ScreenDefaultTemplateMapper.java
Index: ScreenDefaultTemplateMapper.java
===================================================================
package org.apache.turbine.services.template.mapper;
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2001-2003 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 Turbine" 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",
* "Apache Turbine", 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/>.
*/
import java.util.List;
import java.util.ArrayList;
import java.util.Arrays;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.turbine.services.template.TemplateEngineService;
import org.apache.turbine.services.template.TemplateService;
import org.apache.turbine.services.template.TurbineTemplate;
/**
* This is a pretty simple mapper which returns template pathes for
* a supplied template name. If the path does not exist, it looks for
* a templated called "Default" in the same package.
* This path can be used by the TemplateEngine to access
* a certain resource to actually render the template.
*
* @author <a href="mailto:hps@intermeta.de">Henning P. Schmiedehausen</a>
* @version $Id: ScreenDefaultTemplateMapper.java,v 1.1 2003/07/22 10:58:49 henning Exp $
*/
public class ScreenDefaultTemplateMapper
extends BaseTemplateMapper
implements Mapper
{
/** Logging */
private static Log log = LogFactory.getLog(ScreenDefaultTemplateMapper.class);
/**
* Default C'tor. If you use this C'tor, you must use
* the bean setter to set the various properties needed for
* this mapper before first usage.
*/
public ScreenDefaultTemplateMapper()
{
}
/**
* Look for a given Template, then try the
* default.
*
* @param template The template name.
* @return The parsed module name.
*/
public String doMapping(String template)
{
log.debug("doMapping(" + template + ")");
// Copy our elements into an array
List components
= new ArrayList(Arrays.asList(StringUtils.split(
template,
String.valueOf(TemplateService.TEMPLATE_PARTS_SEPARATOR))));
int componentSize = components.size() - 1 ;
// This method never gets an empty string passed.
// So this is never < 0
String templateName = (String) components.get(componentSize);
components.remove(componentSize--);
log.debug("templateName is " + templateName);
// Last element decides, which template Service to use...
TemplateEngineService tes = TurbineTemplate.getTemplateEngineService(templateName);
if (tes == null)
{
return null;
}
String defaultName = "Default.vm";
// This is an optimization. If the name we're looking for is
// already the default name for the template, don't do a "first run"
// which looks for an exact match.
boolean firstRun = !templateName.equals(defaultName);
for(;;)
{
String templatePackage = StringUtils.join(components.iterator(), String.valueOf(separator));
log.debug("templatePackage is now: " + templatePackage);
StringBuffer testName = new StringBuffer();
if (!components.isEmpty())
{
testName.append(templatePackage);
testName.append(separator);
}
testName.append((firstRun)
? templateName
: defaultName);
// But the Templating service must look for the name with prefix
StringBuffer templatePath = new StringBuffer();
if (StringUtils.isNotEmpty(prefix))
{
templatePath.append(prefix);
templatePath.append(separator);
}
templatePath.append(testName);
log.debug("Looking for " + templatePath);
if (tes.templateExists(templatePath.toString()))
{
log.debug("Found it, returning " + testName);
return testName.toString();
}
if (firstRun)
{
firstRun = false;
}
else
{
// We run this loop only two times. The
// first time with the 'real' name and the
// second time with "Default". The second time
// we will end up here and break the for(;;) loop.
break;
}
}
log.debug("Returning default");
return getDefaultName(template);
}
}
1.1 jakarta-turbine-2/src/java/org/apache/turbine/services/template/mapper/ScreenTemplateMapper.java
Index: ScreenTemplateMapper.java
===================================================================
package org.apache.turbine.services.template.mapper;
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2001-2003 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 Turbine" 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",
* "Apache Turbine", 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/>.
*/
import org.apache.commons.lang.StringUtils;
import org.apache.turbine.services.template.TemplateEngineService;
import org.apache.turbine.services.template.TemplateService;
import org.apache.turbine.services.template.TurbineTemplate;
/**
* This is a pretty simple mapper which returns template pathes for
* a supplied template name. This path can be used by the TemplateEngine
* to access a certain resource to actually render the template.
*
* @author <a href="mailto:hps@intermeta.de">Henning P. Schmiedehausen</a>
* @version $Id: ScreenTemplateMapper.java,v 1.1 2003/07/22 10:58:49 henning Exp $
*/
public class ScreenTemplateMapper
extends BaseTemplateMapper
implements Mapper
{
/**
* Default C'tor. If you use this C'tor, you must use
* the bean setter to set the various properties needed for
* this mapper before first usage.
*/
public ScreenTemplateMapper()
{
}
/**
* Check, whether the provided name exists. Returns null
* if the screen does not exist.
*
* @param template The template name.
* @return The matching screen name.
*/
public String doMapping(String template)
{
String [] components = StringUtils.split(template, String.valueOf(TemplateService.TEMPLATE_PARTS_SEPARATOR));
// Last element decides, which template Service to use...
TemplateEngineService tes =
TurbineTemplate.getTemplateEngineService(components[components.length - 1]);
String templatePackage = StringUtils.join(components, String.valueOf(separator));
// But the Templating service must look for the name with prefix
StringBuffer testPath = new StringBuffer();
if (StringUtils.isNotEmpty(prefix))
{
testPath.append(prefix);
testPath.append(separator);
}
testPath.append(templatePackage);
return (tes != null && tes.templateExists(testPath.toString()))
? templatePackage
: null;
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: turbine-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: turbine-dev-help@jakarta.apache.org