You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@turbine.apache.org by Dave Polito <da...@planetcad.com> on 2001/04/10 21:58:09 UTC
[Patch] TurbineJspService.java
Fixed a problem in the handleRequest method, where getRequestDispatcher was
being called with paths[0] + filename. The paths[] was populated with
absolute path names, but servlet > 2.1 seems to need a relative pathname.
So I changed String[] paths to String[] templatePaths. The array
templatePaths is still needed for templateExists. I also added an array for
relativeTemplatePaths, and a method that will return the
relativeTemplateName if it exists. This will allow multiple template.paths
to be used for jsp.
I will send a patch to the docs shortly.
Index: TurbineJspService.java
===================================================================
RCS file:
/home/cvspublic/jakarta-turbine/src/java/org/apache/turbine/services/jsp/Tur
bineJspService.java,v
retrieving revision 1.13
diff -u -r1.13 TurbineJspService.java
--- TurbineJspService.java 2001/04/02 05:49:36 1.13
+++ TurbineJspService.java 2001/04/10 19:41:09
@@ -88,8 +88,11 @@
public class TurbineJspService extends BaseTemplateEngineService
implements JspService
{
- /** The base path prepended to filenames given in arguments */
- private String[] paths;
+ /** The base path[s] prepended to filenames given in arguments */
+ private String[] templatePaths;
+
+ /** The relative path[s] prepended to filenames */
+ private String[] relativeTemplatePaths;
/** The buffer size for the output stream. */
private int bufferSize;
@@ -165,9 +168,18 @@
public void handleRequest(RunData data, String filename, boolean
isForward)
throws TurbineException
{
+ /** template name with relative path */
+ String relativeTemplateName = getRelativeTemplateName(filename);
+
+ if (relativeTemplateName == null)
+ {
+ throw new TurbineException(
+ "Template " + filename + " not found in template paths");
+ }
+
// get the RequestDispatcher for the JSP
RequestDispatcher dispatcher = data.getServletContext()
- .getRequestDispatcher(paths[0] + filename);
+ .getRequestDispatcher(relativeTemplateName);
try
{
@@ -215,19 +227,25 @@
* Use the turbine template service to translate
* the template paths.
*/
- paths = TurbineTemplate.translateTemplatePaths(
- config.getStringArray("templates"));
+ templatePaths = TurbineTemplate.translateTemplatePaths(
+ config.getStringArray("templates"));
- /* not working properly - removing until I can investigate (jdm)
- if (path.startsWith("/"))
- {
- path = path.substring(1);
- }
- if (path.length() > 0 && !path.endsWith("/"))
+ /*
+ * Set relative paths from config.
+ * Needed for javax.servlet.RequestDispatcher
+ */
+ relativeTemplatePaths = config.getStringArray("templates");
+
+ /*
+ * Make sure that the relative paths begin with /
+ */
+ for (int i = 0; i < relativeTemplatePaths.length; i++)
{
- path += "/";
+ if (!relativeTemplatePaths[i].startsWith("/"))
+ {
+ relativeTemplatePaths[i] = "/" + relativeTemplatePaths[i];
+ }
}
- */
bufferSize = config.getInt("buffer.size", 8192);
@@ -247,7 +265,36 @@
* @return boolean
*/
public boolean templateExists(String template)
+ {
+ return TurbineTemplate.templateExists(template, templatePaths);
+ }
+ /**
+ * Searchs for a template in the default.template path[s] and
+ * returns the template name with a relative path which is
+ * required by <a
href="http://java.sun.com/products/servlet/2.3/javadoc/javax/servlet/Servlet
Context.html#getRequestDispatcher(java.lang.String)">
+ * javax.servlet.RequestDispatcher</a>
+ *
+ * @param String template
+ * @return String
+ */
+
+ public String getRelativeTemplateName(String template)
{
- return TurbineTemplate.templateExists(template, paths);
- }
+ /* A dummy String[] object used to pass a String to
+ TurbineTemplate.templateExists
+ */
+ String[] testTemplatePath = new String[1];
+
+ /** Find which template path the template is in */
+ for (int i = 0; i < relativeTemplatePaths.length; i++)
+ {
+ testTemplatePath[0] =
TurbineServlet.getRealPath(relativeTemplatePaths[i]);
+ if (TurbineTemplate.templateExists(template, testTemplatePath))
+ {
+ return relativeTemplatePaths[i] + template;
+ }
+ }
+
+ return null;
+ }
}
---------------------------------------------------------------------
To unsubscribe, e-mail: turbine-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: turbine-dev-help@jakarta.apache.org
Re: [Patch] TurbineJspService.java
Posted by Jason van Zyl <jv...@apache.org>.
Daniel Rall wrote:
>
> Looks like nobody got to this...can someone who knows more about JSP
> service either reject this patch or merge it in?
I asked for a simple JSP example a while ago. I won't merge any patches
that I can't test. If someone sends me a small JSP example that I can
use for testing then I will try to merge the patch and test it with
the TDK.
>
> Dave Polito <da...@planetcad.com> writes:
>
> > Fixed a problem in the handleRequest method, where getRequestDispatcher was
> > being called with paths[0] + filename. The paths[] was populated with
> > absolute path names, but servlet > 2.1 seems to need a relative pathname.
> > So I changed String[] paths to String[] templatePaths. The array
> > templatePaths is still needed for templateExists. I also added an array for
> > relativeTemplatePaths, and a method that will return the
> > relativeTemplateName if it exists. This will allow multiple template.paths
> > to be used for jsp.
> >
> > I will send a patch to the docs shortly.
> >
> >
> > Index: TurbineJspService.java
> > ===================================================================
> > RCS file:
> > /home/cvspublic/jakarta-turbine/src/java/org/apache/turbine/services/jsp/Tur
> > bineJspService.java,v
> > retrieving revision 1.13
> > diff -u -r1.13 TurbineJspService.java
> > --- TurbineJspService.java 2001/04/02 05:49:36 1.13
> > +++ TurbineJspService.java 2001/04/10 19:41:09
> > @@ -88,8 +88,11 @@
> > public class TurbineJspService extends BaseTemplateEngineService
> > implements JspService
> > {
> > - /** The base path prepended to filenames given in arguments */
> > - private String[] paths;
> > + /** The base path[s] prepended to filenames given in arguments */
> > + private String[] templatePaths;
> > +
> > + /** The relative path[s] prepended to filenames */
> > + private String[] relativeTemplatePaths;
> >
> > /** The buffer size for the output stream. */
> > private int bufferSize;
> > @@ -165,9 +168,18 @@
> > public void handleRequest(RunData data, String filename, boolean
> > isForward)
> > throws TurbineException
> > {
> > + /** template name with relative path */
> > + String relativeTemplateName = getRelativeTemplateName(filename);
> > +
> > + if (relativeTemplateName == null)
> > + {
> > + throw new TurbineException(
> > + "Template " + filename + " not found in template paths");
> > + }
> > +
> > // get the RequestDispatcher for the JSP
> > RequestDispatcher dispatcher = data.getServletContext()
> > - .getRequestDispatcher(paths[0] + filename);
> > + .getRequestDispatcher(relativeTemplateName);
> >
> > try
> > {
> > @@ -215,19 +227,25 @@
> > * Use the turbine template service to translate
> > * the template paths.
> > */
> > - paths = TurbineTemplate.translateTemplatePaths(
> > - config.getStringArray("templates"));
> > + templatePaths = TurbineTemplate.translateTemplatePaths(
> > + config.getStringArray("templates"));
> >
> > - /* not working properly - removing until I can investigate (jdm)
> > - if (path.startsWith("/"))
> > - {
> > - path = path.substring(1);
> > - }
> > - if (path.length() > 0 && !path.endsWith("/"))
> > + /*
> > + * Set relative paths from config.
> > + * Needed for javax.servlet.RequestDispatcher
> > + */
> > + relativeTemplatePaths = config.getStringArray("templates");
> > +
> > + /*
> > + * Make sure that the relative paths begin with /
> > + */
> > + for (int i = 0; i < relativeTemplatePaths.length; i++)
> > {
> > - path += "/";
> > + if (!relativeTemplatePaths[i].startsWith("/"))
> > + {
> > + relativeTemplatePaths[i] = "/" + relativeTemplatePaths[i];
> > + }
> > }
> > - */
> >
> > bufferSize = config.getInt("buffer.size", 8192);
> >
> > @@ -247,7 +265,36 @@
> > * @return boolean
> > */
> > public boolean templateExists(String template)
> > + {
> > + return TurbineTemplate.templateExists(template, templatePaths);
> > + }
> > + /**
> > + * Searchs for a template in the default.template path[s] and
> > + * returns the template name with a relative path which is
> > + * required by <a
> > href="http://java.sun.com/products/servlet/2.3/javadoc/javax/servlet/Servlet
> > Context.html#getRequestDispatcher(java.lang.String)">
> > + * javax.servlet.RequestDispatcher</a>
> > + *
> > + * @param String template
> > + * @return String
> > + */
> > +
> > + public String getRelativeTemplateName(String template)
> > {
> > - return TurbineTemplate.templateExists(template, paths);
> > - }
> > + /* A dummy String[] object used to pass a String to
> > + TurbineTemplate.templateExists
> > + */
> > + String[] testTemplatePath = new String[1];
> > +
> > + /** Find which template path the template is in */
> > + for (int i = 0; i < relativeTemplatePaths.length; i++)
> > + {
> > + testTemplatePath[0] =
> > TurbineServlet.getRealPath(relativeTemplatePaths[i]);
> > + if (TurbineTemplate.templateExists(template, testTemplatePath))
> > + {
> > + return relativeTemplatePaths[i] + template;
> > + }
> > + }
> > +
> > + return null;
> > + }
> > }
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: turbine-dev-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail: turbine-dev-help@jakarta.apache.org
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: turbine-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: turbine-dev-help@jakarta.apache.org
--
jvz.
Jason van Zyl
jvanzyl@apache.org
http://jakarta.apache.org/velocity
http://jakarta.apache.org/turbine
http://tambora.zenplex.org
---------------------------------------------------------------------
To unsubscribe, e-mail: turbine-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: turbine-dev-help@jakarta.apache.org
Re: [Patch] TurbineJspService.java
Posted by Daniel Rall <dl...@collab.net>.
Looks like nobody got to this...can someone who knows more about JSP
service either reject this patch or merge it in?
Dave Polito <da...@planetcad.com> writes:
> Fixed a problem in the handleRequest method, where getRequestDispatcher was
> being called with paths[0] + filename. The paths[] was populated with
> absolute path names, but servlet > 2.1 seems to need a relative pathname.
> So I changed String[] paths to String[] templatePaths. The array
> templatePaths is still needed for templateExists. I also added an array for
> relativeTemplatePaths, and a method that will return the
> relativeTemplateName if it exists. This will allow multiple template.paths
> to be used for jsp.
>
> I will send a patch to the docs shortly.
>
>
> Index: TurbineJspService.java
> ===================================================================
> RCS file:
> /home/cvspublic/jakarta-turbine/src/java/org/apache/turbine/services/jsp/Tur
> bineJspService.java,v
> retrieving revision 1.13
> diff -u -r1.13 TurbineJspService.java
> --- TurbineJspService.java 2001/04/02 05:49:36 1.13
> +++ TurbineJspService.java 2001/04/10 19:41:09
> @@ -88,8 +88,11 @@
> public class TurbineJspService extends BaseTemplateEngineService
> implements JspService
> {
> - /** The base path prepended to filenames given in arguments */
> - private String[] paths;
> + /** The base path[s] prepended to filenames given in arguments */
> + private String[] templatePaths;
> +
> + /** The relative path[s] prepended to filenames */
> + private String[] relativeTemplatePaths;
>
> /** The buffer size for the output stream. */
> private int bufferSize;
> @@ -165,9 +168,18 @@
> public void handleRequest(RunData data, String filename, boolean
> isForward)
> throws TurbineException
> {
> + /** template name with relative path */
> + String relativeTemplateName = getRelativeTemplateName(filename);
> +
> + if (relativeTemplateName == null)
> + {
> + throw new TurbineException(
> + "Template " + filename + " not found in template paths");
> + }
> +
> // get the RequestDispatcher for the JSP
> RequestDispatcher dispatcher = data.getServletContext()
> - .getRequestDispatcher(paths[0] + filename);
> + .getRequestDispatcher(relativeTemplateName);
>
> try
> {
> @@ -215,19 +227,25 @@
> * Use the turbine template service to translate
> * the template paths.
> */
> - paths = TurbineTemplate.translateTemplatePaths(
> - config.getStringArray("templates"));
> + templatePaths = TurbineTemplate.translateTemplatePaths(
> + config.getStringArray("templates"));
>
> - /* not working properly - removing until I can investigate (jdm)
> - if (path.startsWith("/"))
> - {
> - path = path.substring(1);
> - }
> - if (path.length() > 0 && !path.endsWith("/"))
> + /*
> + * Set relative paths from config.
> + * Needed for javax.servlet.RequestDispatcher
> + */
> + relativeTemplatePaths = config.getStringArray("templates");
> +
> + /*
> + * Make sure that the relative paths begin with /
> + */
> + for (int i = 0; i < relativeTemplatePaths.length; i++)
> {
> - path += "/";
> + if (!relativeTemplatePaths[i].startsWith("/"))
> + {
> + relativeTemplatePaths[i] = "/" + relativeTemplatePaths[i];
> + }
> }
> - */
>
> bufferSize = config.getInt("buffer.size", 8192);
>
> @@ -247,7 +265,36 @@
> * @return boolean
> */
> public boolean templateExists(String template)
> + {
> + return TurbineTemplate.templateExists(template, templatePaths);
> + }
> + /**
> + * Searchs for a template in the default.template path[s] and
> + * returns the template name with a relative path which is
> + * required by <a
> href="http://java.sun.com/products/servlet/2.3/javadoc/javax/servlet/Servlet
> Context.html#getRequestDispatcher(java.lang.String)">
> + * javax.servlet.RequestDispatcher</a>
> + *
> + * @param String template
> + * @return String
> + */
> +
> + public String getRelativeTemplateName(String template)
> {
> - return TurbineTemplate.templateExists(template, paths);
> - }
> + /* A dummy String[] object used to pass a String to
> + TurbineTemplate.templateExists
> + */
> + String[] testTemplatePath = new String[1];
> +
> + /** Find which template path the template is in */
> + for (int i = 0; i < relativeTemplatePaths.length; i++)
> + {
> + testTemplatePath[0] =
> TurbineServlet.getRealPath(relativeTemplatePaths[i]);
> + if (TurbineTemplate.templateExists(template, testTemplatePath))
> + {
> + return relativeTemplatePaths[i] + template;
> + }
> + }
> +
> + return null;
> + }
> }
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: turbine-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: turbine-dev-help@jakarta.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: turbine-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: turbine-dev-help@jakarta.apache.org