mikeh 01/11/13 11:45:09
Modified: src/java/org/apache/turbine Turbine.java
TurbineConstants.java
src/java/org/apache/turbine/modules ModuleLoader.java
src/java/org/apache/turbine/pipeline ClassicPipeline.java
Renderer.java
Added: src/java/org/apache/turbine Resolver.java
src/java/org/apache/turbine/pipeline DefaultResolver.java
ModuleRunner.java PipeLineUtil.java
Removed: src/java/org/apache/turbine/pipeline Resolver.java
Log:
Updated the source to use a pluggable Resolver. Made a ModuleRunner,
and made the Renderer only render.
I will be mailing shortly a complete explaination.
Revision Changes Path
1.12 +24 -2 jakarta-turbine-3/src/java/org/apache/turbine/Turbine.java
Index: Turbine.java
===================================================================
RCS file: /home/cvs/jakarta-turbine-3/src/java/org/apache/turbine/Turbine.java,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -r1.11 -r1.12
--- Turbine.java 2001/10/24 20:54:57 1.11
+++ Turbine.java 2001/11/13 19:45:08 1.12
@@ -111,7 +111,7 @@
* @author <a href="mailto:[EMAIL PROTECTED]">Rafal Krzewski</a>
* @author <a href="mailto:[EMAIL PROTECTED]">Jason van Zyl</a>
* @author <a href="mailto:[EMAIL PROTECTED]">Daniel Rall</a>
- * @version $Id: Turbine.java,v 1.11 2001/10/24 20:54:57 jon Exp $
+ * @version $Id: Turbine.java,v 1.12 2001/11/13 19:45:08 mikeh Exp $
*/
public class Turbine
extends HttpServlet
@@ -503,6 +503,8 @@
*/
private static ModuleLoader moduleLoader;
+ private static Resolver resolver;
+
private static Pipeline pipeline;
private static RunDataService runDataService;
@@ -616,6 +618,17 @@
moduleLoader.setConfiguration(configuration);
moduleLoader.init();
+ //
+ // set up the resolver, should be done before the pipeline
+ //
+ String resolverClass;
+ resolverClass = configuration.getString(RESOLVER,
+ "org.apache.turbine.pipeline.DefaultResolver");
+
+ Log.debug("[Turbine] Using Resolver: " + resolverClass);
+ resolver = (Resolver) Class.forName(resolverClass).newInstance();
+ resolver.init();
+
// Set some system properties
ExtendedProperties systemProperties = configuration.subset(SYSTEM);
@@ -641,7 +654,7 @@
.newInstance();
pipeline.init();
-
+
// Setup the RunData service for the application
runDataService = (RunDataService) TurbineServices.getInstance()
.getService(RunDataService.SERVICE_NAME);
@@ -678,6 +691,15 @@
public static ModuleLoader getModuleLoader()
{
return moduleLoader;
+ }
+
+ /**
+ * Get the Resolver for this Turbine webapp.
+ * @return Resolver
+ */
+ public static Resolver getResolver()
+ {
+ return resolver;
}
/**
1.6 +6 -0
jakarta-turbine-3/src/java/org/apache/turbine/TurbineConstants.java
Index: TurbineConstants.java
===================================================================
RCS file:
/home/cvs/jakarta-turbine-3/src/java/org/apache/turbine/TurbineConstants.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- TurbineConstants.java 2001/09/21 03:21:00 1.5
+++ TurbineConstants.java 2001/11/13 19:45:08 1.6
@@ -120,6 +120,12 @@
public static final String MODULE_PACKAGES = "module.packages";
/**
+ * what resolver Turbine will use
+ */
+ public static final String RESOLVER = "resolver.default";
+
+
+ /**
* JDBC database driver.
*/
public static final String DB_DRIVER = "database.default.driver";
1.1 jakarta-turbine-3/src/java/org/apache/turbine/Resolver.java
Index: Resolver.java
===================================================================
package org.apache.turbine;
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 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 Turbine" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact [EMAIL PROTECTED]
*
* 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.turbine.modules.Module;
/**
* This interface is used to to allow users to plug in
* their own resolver. The default algorithm is in DefaultResolver.java.
* @author <a href="mailto:[EMAIL PROTECTED]">Mike Haberman</a>
* @version $Id: Resolver.java,v 1.1 2001/11/13 19:45:08 mikeh Exp $
*/
public interface Resolver
{
public void init()
throws Exception;
public String getTemplate(String moduleType, String targetTemplate)
throws Exception;
public Module getModule(String type, String name)
throws Exception;
}
1.4 +79 -4
jakarta-turbine-3/src/java/org/apache/turbine/modules/ModuleLoader.java
Index: ModuleLoader.java
===================================================================
RCS file:
/home/cvs/jakarta-turbine-3/src/java/org/apache/turbine/modules/ModuleLoader.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- ModuleLoader.java 2001/10/06 03:04:22 1.3
+++ ModuleLoader.java 2001/11/13 19:45:09 1.4
@@ -55,23 +55,26 @@
*/
import java.util.Iterator;
+import java.util.ArrayList;
import java.util.List;
import java.util.Vector;
import java.util.Map;
import org.apache.turbine.RunData;
import org.apache.turbine.Turbine;
import org.apache.turbine.TurbineException;
-import org.apache.turbine.pipeline.Resolver;
+import org.apache.turbine.Resolver;
import org.apache.commons.collections.FastArrayList;
import org.apache.commons.collections.FastHashMap;
import org.apache.commons.collections.ExtendedProperties;
import org.apache.turbine.Log;
+import org.apache.turbine.pipeline.PipeLineUtil;
+
/**
* Load modules for use in the view pipeline.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Jason van Zyl</a>
- * @version $Id: ModuleLoader.java,v 1.3 2001/10/06 03:04:22 jvanzyl Exp $
+ * @version $Id: ModuleLoader.java,v 1.4 2001/11/13 19:45:09 mikeh Exp $
*/
public class ModuleLoader
{
@@ -228,8 +231,8 @@
else
{
StringBuffer sb = new StringBuffer();
- Resolver.parseTemplatePath(name, sb);
- j = Resolver.getPossibleModules(sb.toString());
+ PipeLineUtil.parseTemplatePath(name, sb);
+ j = getPossibleModules(sb.toString());
k = getAllPossibleModules(i,j,type);
}
@@ -338,4 +341,76 @@
{
scriptingEnabled = state;
}
+
+ protected Iterator getPossibleModules(String template)
+ throws Exception
+ {
+ List packages = new ArrayList();
+
+ // Parse the template name and change it into a package.
+ StringBuffer pckage = new StringBuffer();
+ int i = PipeLineUtil.parseTemplatePath(template,pckage);
+
+ if (pckage.charAt(0) == '/')
+ {
+ pckage.deleteCharAt(0);
+ i--;
+ }
+
+ if (i >= 0)
+ {
+ for (int j = 0; j <= i; j++)
+ {
+ if (pckage.charAt(j) == '/')
+ {
+ pckage.setCharAt(j,'.');
+ }
+ }
+ }
+
+ // Remove a possible file extension.
+ for (int j = i + 1; j < pckage.length(); j++)
+ {
+ if (pckage.charAt(j) == '.')
+ {
+ pckage.delete(j,pckage.length());
+ break;
+ }
+ }
+
+ // Try first an exact match for a module having the same
+ // name as the input template, traverse then upper level
+ // packages to find a default module named Default.
+ int j = 9999;
+ String module;
+ while (j-- > 0)
+ {
+ module = pckage.toString();
+
+ packages.add(module);
+
+ pckage.setLength(i + 1);
+ if (i > 0)
+ {
+ // We have still packages to traverse.
+ for (i = pckage.length() - 2; i >= 0; i--)
+ {
+ if (pckage.charAt(i) == '.')
+ {
+ break;
+ }
+ }
+ }
+ else if (j > 0)
+ {
+ // Only the main level left.
+ j = 1;
+ }
+ pckage.append("Default");
+ }
+
+ // Not found, return the default module name.
+ return packages.iterator();
+ }
+
}
1.6 +37 -8
jakarta-turbine-3/src/java/org/apache/turbine/pipeline/ClassicPipeline.java
Index: ClassicPipeline.java
===================================================================
RCS file:
/home/cvs/jakarta-turbine-3/src/java/org/apache/turbine/pipeline/ClassicPipeline.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- ClassicPipeline.java 2001/10/25 06:08:52 1.5
+++ ClassicPipeline.java 2001/11/13 19:45:09 1.6
@@ -59,6 +59,7 @@
import org.apache.turbine.TurbineConstants; // for convenience right now
import org.apache.turbine.Pipeline;
import org.apache.turbine.RunData;
+import org.apache.turbine.Resolver;
import org.apache.turbine.TemplateContext;
import org.apache.turbine.modules.Module;
import org.apache.turbine.modules.ModuleLoader;
@@ -75,15 +76,17 @@
* The ClassicPipeline uses the 'template' as a
* starting point for output.
*
+ * @author <a href="mailto:[EMAIL PROTECTED]">Mike Haberman</a>
* @author <a href="mailto:[EMAIL PROTECTED]">Jason van Zyl</a>
* @author <a href="mailto:[EMAIL PROTECTED]">Jon S. Stevens</a>
- * @version $Id: ClassicPipeline.java,v 1.5 2001/10/25 06:08:52 dlr Exp $
+ * @version $Id: ClassicPipeline.java,v 1.6 2001/11/13 19:45:09 mikeh Exp $
*/
public class ClassicPipeline
implements Pipeline,TurbineConstants
{
SessionValidator sessionValidator = null;
AccessController accessController = null;
+ String targetModuleType;
/**
* Here we can setup objects that are thread safe and
@@ -95,16 +98,21 @@
{
// Get the instance of the Session Validator.
sessionValidator = (SessionValidator)
- Turbine.getModuleLoader().getModule(ACTIONS,
+ Turbine.getResolver().getModule(ACTIONS,
Turbine.getConfiguration().getString(
ACTION_SESSION_VALIDATOR));
// Get the instance of the AccessController.
accessController = (AccessController)
- Turbine.getModuleLoader().getModule(ACTIONS,
+ Turbine.getResolver().getModule(ACTIONS,
Turbine.getConfiguration().getString(
ACTION_ACCESS_CONTROLLER));
+ // get the module type
+ targetModuleType =
+ Turbine.getConfiguration().getString(
+ "pipeline.default.targetModuleType");
+
}
public void process(RunData data)
@@ -163,8 +171,10 @@
}
}
- Turbine.getModuleLoader()
- .getModule(ACTIONS, data.getAction()).execute(data);
+ Module action;
+ action = Turbine.getResolver().getModule(ACTIONS,
+ data.getAction());
+ action.execute(data);
data.setAction(null);
}
@@ -200,7 +210,7 @@
// can re-define the template definition.
if (data.hasAction())
{
- Turbine.getModuleLoader().getModule(
+ Turbine.getResolver().getModule(
Turbine.ACTIONS, data.getAction()).execute(data);
}
}
@@ -210,10 +220,13 @@
{
}
+ ModuleRunner runner = new ModuleRunner();
+
//!! Get rid of hard coding.
public void execute(RunData data)
throws Exception
{
+ /*
// The whole pipeline starts with the target template
// specified by the 'template' paramter.
StringBuffer sb = new StringBuffer();
@@ -237,7 +250,11 @@
"pipeline.default.targetModuleType");
Turbine.getModuleLoader().getModule(targetModuleType, target).execute(data);
+ */
+ // run the module chain
+ runner.run(targetModuleType, data);
+
// The execution of the module that corresponds to the requested
// template may result in the target template being changed.
// This happens for example when a user isn't logged in. The
@@ -245,7 +262,7 @@
// module might result in the target template being changed
// to '/Login.vm'. We want to reset the target template value
// here in case it has changed.
- target = data.getTarget();
+ String target = data.getTarget();
// With this target template we start by rendering
// the appropriate layout template and everything
@@ -253,7 +270,6 @@
// Need to execute the module that matches the template
// if it exists.
- String layoutTemplate = Resolver.getTemplate("layouts", target);
data.getResponse().setLocale(data.getLocale());
data.getResponse().setContentType(data.getContentType());
@@ -266,7 +282,9 @@
TemplateContext context = Module.getTemplateContext(data);
context.put("renderer", r);
context.put("template", target);
+ context.put("runner", runner);
+ /* to be removed This is now fixed!!!
//!! We should be able to use the renderer here, but we have
// the normalize the way it's used. right now the renderer
// is being used in templates and you specify the module type
@@ -276,7 +294,18 @@
// like /layouts/layouts/Default.vm which obviously doesn't
// work.
//data.getOut().print(r.render("layouts", data, layoutTemplate));
+
data.getOut().print(Module.handleRequest(context, layoutTemplate));
+ */
+
+ // now we can use the renderer here
+ // use the renderer to start the whole shabang
+ String layoutTemplate;
+ layoutTemplate = Turbine.getResolver().getTemplate("layouts", target);
+ String out = r.render(data, layoutTemplate);
+ data.getOut().print(out);
+
+ /* Note that the target is not yet rendered */
}
public void finished(RunData data)
1.4 +54 -9
jakarta-turbine-3/src/java/org/apache/turbine/pipeline/Renderer.java
Index: Renderer.java
===================================================================
RCS file:
/home/cvs/jakarta-turbine-3/src/java/org/apache/turbine/pipeline/Renderer.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- Renderer.java 2001/10/16 09:09:56 1.3
+++ Renderer.java 2001/11/13 19:45:09 1.4
@@ -55,41 +55,86 @@
*/
import org.apache.turbine.Turbine;
+import org.apache.turbine.Resolver;
import org.apache.turbine.RunData;
import org.apache.turbine.modules.Module;
import org.apache.turbine.TurbineException;
import org.apache.turbine.Log;
+import org.apache.turbine.TemplateContext;
/**
* This class is used in the context to render templates.
*
+ * @author <a href="mailto:[EMAIL PROTECTED]">Mike Haberman</a>
* @author <a href="mailto:[EMAIL PROTECTED]">Jason van Zyl</a>
* @author <a href="mailto:[EMAIL PROTECTED]">Jon S. Stevens</a>
- * @version $Id: Renderer.java,v 1.3 2001/10/16 09:09:56 jon Exp $
+ * @version $Id: Renderer.java,v 1.4 2001/11/13 19:45:09 mikeh Exp $
*/
public class Renderer
{
+ public String render(TemplateContext context, String target)
+ throws TurbineException,Exception
+ {
+ try
+ {
+ Log.debug("[ClassicPipeline] render target => " + target);
+ return Module.handleRequest(context, target);
+ }
+ catch (Exception e) {
+ Log.error(e);
+ return Module.handleRequest(context, "Error.vm");
+ }
+ }
+
public String render(String moduleType, RunData data, String template)
throws TurbineException,Exception
{
- Turbine.getModuleLoader().getModule(moduleType, template).execute(data);
+ //
+ // use the resolver to find the template
+ //
+ String target = Turbine.getResolver().getTemplate(moduleType, template);
+ return render(data, target);
+ /*
+ Turbine.getModuleLoader().getModule(moduleType, template).execute(data);
return Module.handleRequest(Module.getTemplateContext(data),
getFullPath(moduleType, template));
+ */
}
+ public String render(RunData data, String target)
+ throws TurbineException,Exception
+ {
+ TemplateContext context = Module.getTemplateContext(data);
+ return render(context, target);
+ }
+
+
+ public String render(String moduleType,
+ TemplateContext context,
+ String template)
+ throws TurbineException,Exception
+ {
+ String target = Turbine.getResolver().getTemplate(moduleType, template);
+ return render(context, target);
+ }
+
/**
* Attemps to locate the template and if it can't find it, then
* it will attempt to render the defaultTemplate
*/
- public String render(String moduleType, RunData data, String template,
- String defaultTemplate)
+ public String render(String moduleType,
+ RunData data,
+ String template,
+ String defaultTemplate)
throws TurbineException,Exception
{
+ String target = Turbine.getResolver().getTemplate(moduleType, template);
+
String output = null;
- if (Module.templateExists(getFullPath(moduleType, template)))
+ if (Module.templateExists(target))
{
- output = render(moduleType, data, template);
+ output = render(data, target);
}
else
{
@@ -98,12 +143,12 @@
return output;
}
- /**
- * Concatinates the moduleType with the template
- */
+ /*
+ NO longer needed, use the resolver for this
public String getFullPath(String moduleType, String template)
{
//!! I shouldn't need that slash in there.
return moduleType + '/' + template;
}
+ */
}
1.1
jakarta-turbine-3/src/java/org/apache/turbine/pipeline/DefaultResolver.java
Index: DefaultResolver.java
===================================================================
package org.apache.turbine.pipeline;
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 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 Turbine" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact [EMAIL PROTECTED]
*
* 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/>.
*/
// Renderers and context builders
// We need to match up the target template with sibling
// templates and context builders for each of these templates.
import java.util.ArrayList;
import java.util.List;
import java.util.Iterator;
import org.apache.turbine.Turbine;
import org.apache.turbine.Resolver;
import org.apache.turbine.modules.Module;
// Given a target template
// 1. find all possible classes that could be used
// as context builders
// 2. find all possible sibling templates that could
// be used with the target template
// We are using the classic turbine method of using
// a screen template.
// Say we have a base template of:
//
// /base/science/chemistry/Titanium.vm
//
// 1. We want to find the context builder to this
// target template if there is one, there won't
// be if we're using pull.
//
// 2. Find the layout/nav templates to use and find
// their context builders.
/**
* Resolver that finds the appropriate context populator
* and sibling templates for a given target template.
*
* This is the 2.1 algorithm used to find a context populator
* (or module in 2.1 parlance), sibling templates and their
* context populators.
*
* This algorithm or strategy should be pluggable. For example
* using a different resolver would allow search for templates
* to occur in a localized manner possibly even for content
* type. Right now there is some code in Jetspeed called the
* profiler that David Taylor is working on and it would probably
* be good to turn that into a resolver so that the functionality
* is available in Turbine. There is also the Resources code in
* the commons which we can also leverage and that code can now
* deal with localization issues it appears. Would be good to
* take a look at all this code and pull the best out so that
* it can be placed in Turbine proper. The first task is to
* get a simple resolver working for the 'classic' pipeline.
* More flexibility in terms of configuration with XML can
* come in a while.
*/
/*
NOTE: Currently the ModuleLoader handles a lot of the responisbile
for finding, caching, and serving up modules. That functionaly
should be placed in the pluggable resolver. I'll leave it for now so
to make the changes more gradually.
*/
/**
* This class is used to find templates and modules
*
* @author <a href="mailto:[EMAIL PROTECTED]">Jason van Zyl</a>
* @author <a href="mailto:[EMAIL PROTECTED]">Mike Haberman</a>
* @version $Id: DefaultResolver.java,v 1.1 2001/11/13 19:45:09 mikeh Exp $
*/
public class DefaultResolver
implements Resolver
{
String defaultTemplate;
public void init()
throws Exception
{
defaultTemplate =
Turbine.getConfiguration().getString("template.default") + "." +
Turbine.getConfiguration().getString("template.default.extension");
if (defaultTemplate.indexOf('/') == -1)
{
defaultTemplate = "/" + defaultTemplate;
}
}
/**
* Used for resolving top level rendering process.
*/
public String getTemplate(String moduleType, String targetTemplate)
throws Exception
{
StringBuffer sb = new StringBuffer();
int i = PipeLineUtil.parseTemplatePath(targetTemplate, sb);
Iterator j = getPossibleTemplates(sb.toString());
while (j.hasNext())
{
String template = moduleType + "/" + (String) j.next();
if (Module.templateExists(template))
{
return template;
}
}
// We should have a default template type for
// each corresponding module and a default extension.
return moduleType + defaultTemplate;
}
/**
* Get the parsed module name for the specified template.
*
* @param template The template name.
* @param key The module type key.
* @return The parsed module name.
* @exception Exception, a generaic exception.
*/
protected Iterator getPossibleTemplates(String template)
throws Exception
{
List packages = new ArrayList();
// Parse the template name and change it into a package.
StringBuffer pckage = new StringBuffer();
int i = PipeLineUtil.parseTemplatePath(template,pckage);
if (pckage.charAt(0) == '/')
{
pckage.deleteCharAt(0);
i--;
}
String extension = ".vm";
// Try first an exact match for a module having the same
// name as the input template, traverse then upper level
// packages to find a default module named Default.
int j = 9999;
String module;
while (j-- > 0)
{
module = pckage.toString();
packages.add(module);
pckage.setLength(i + 1);
if (i > 0)
{
// We have still packages to traverse.
for (i = pckage.length() - 2; i >= 0; i--)
{
if (pckage.charAt(i) == '/')
{
break;
}
}
}
else if (j > 0)
{
// Only the main level left.
j = 1;
}
pckage.append("Default").append(extension);
}
// Not found, return the default module name.
return packages.iterator();
}
/**
* Get an instance of a module
*
* @param String name
* @param String type
* @return Module
*/
public Module getModule(String type, String name)
throws Exception
{
// just use the module loader's default algorithm
// for this pass
// eventually that functionality should be put
// in the resolver.
return Turbine.getModuleLoader().getModule(type,name);
}
}
1.1
jakarta-turbine-3/src/java/org/apache/turbine/pipeline/ModuleRunner.java
Index: ModuleRunner.java
===================================================================
package org.apache.turbine.pipeline;
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 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 Turbine" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact [EMAIL PROTECTED]
*
* 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.turbine.Turbine;
import org.apache.turbine.RunData;
import org.apache.turbine.modules.Module;
import org.apache.turbine.TurbineException;
import org.apache.turbine.Log;
import org.apache.turbine.TemplateContext;
/**
* This class is used execute the module chain.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Mike Haberman</a>
* @version $Id: ModuleRunner.java,v 1.1 2001/11/13 19:45:09 mikeh Exp $
*/
public class ModuleRunner
{
public void run(String moduleType, RunData data)
throws TurbineException,Exception
{
String target;
String oldTarget = "";
Module module;
target = getTarget(data);
while(! oldTarget.equals(target))
{
Log.debug("[ClassicPipeline] module to run => " +
moduleType + ":" + target);
module = Turbine.getResolver().getModule(moduleType, target);
module.execute(data);
// target may have changed
oldTarget = target;
target = getTarget(data);
}
/*
// set the run data's target to the normalized target path
// i.e. ',' are changed to '/'
NOT A good idea. Template Services expect the ','
data.setTarget(target);
*/
}
private String getTarget(RunData data)
throws Exception
{
String target = data.getTarget();
if (target == null)
{
target = data.getParameters().getString("template");
data.setTarget(target);
}
// normalize the target
target = data.getTarget();
StringBuffer sb = new StringBuffer();
PipeLineUtil.parseTemplatePath(target,sb);
return sb.toString();
}
}
1.1
jakarta-turbine-3/src/java/org/apache/turbine/pipeline/PipeLineUtil.java
Index: PipeLineUtil.java
===================================================================
package org.apache.turbine.pipeline;
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 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 Turbine" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact [EMAIL PROTECTED]
*
* 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/>.
*/
/*
perhaps this code should go someplace else.
The following classes use it:
+ DefaultResolver
+ ModuleRunner
+ modules/ModuleLoader
*/
/**
*
* @author <a href="mailto:[EMAIL PROTECTED]">Mike Haberman</a>
* @version $Id: PipeLineUtil.java,v 1.1 2001/11/13 19:45:09 mikeh Exp $
*/
public class PipeLineUtil
{
private PipeLineUtil()
{
}
/**
* Parse the template name collected from URL parameters or
* template context to a path name. Double slashes are changed
* into single ones and commas used as path delemiters in
* URL parameters are changed into slashes. Empty names or
* names without a file part are not accepted.
*
* @param template The template name.
* @param buffer A buffer for the result.
* @return The index of the separator between the path and the name.
* @exception Exception Malformed template name.
*/
/*
TODO: it would be nice to cache this info
*/
public static int parseTemplatePath(String template,StringBuffer buffer)
throws Exception
{
char c;
int j = 0;
int ind = -1;
buffer.setLength(0);
buffer.append(template);
int len = buffer.length();
while (j < len)
{
c = buffer.charAt(j);
if (c == ',')
{
c = '/';
buffer.setCharAt(j,c);
}
if (c == '/')
{
ind = j;
if (j < (len - 1))
{
c = buffer.charAt(j + 1);
if ((c == '/') ||
(c == ','))
{
buffer.deleteCharAt(j);
len--;
continue;
}
}
}
j++;
}
if ((len == 0) ||
(ind >= (len - 1)))
{
throw new Exception(
"Syntax error in template name '" + template + '\'');
}
return ind;
}
}
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>