You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@velocity.apache.org by nb...@apache.org on 2007/08/09 02:02:59 UTC
svn commit: r564050 - in
/velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools:
config/InvalidScopeException.java generic/SortTool.java
view/VelocityViewServlet.java view/jsp/VelocityViewTag.java
Author: nbubna
Date: Wed Aug 8 17:02:58 2007
New Revision: 564050
URL: http://svn.apache.org/viewvc?view=rev&rev=564050
Log:
resolve misc serialization issues (FindBugs)
Modified:
velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/config/InvalidScopeException.java
velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/generic/SortTool.java
velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/view/VelocityViewServlet.java
velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/view/jsp/VelocityViewTag.java
Modified: velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/config/InvalidScopeException.java
URL: http://svn.apache.org/viewvc/velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/config/InvalidScopeException.java?view=diff&rev=564050&r1=564049&r2=564050
==============================================================================
--- velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/config/InvalidScopeException.java (original)
+++ velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/config/InvalidScopeException.java Wed Aug 8 17:02:58 2007
@@ -27,7 +27,8 @@
*/
public class InvalidScopeException extends ConfigurationException
{
- private ToolConfiguration tool;
+ // this isn't crucial to keep around if the exception is serialized
+ private transient ToolConfiguration tool;
public InvalidScopeException(ToolboxConfiguration toolbox,
ToolConfiguration tool)
Modified: velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/generic/SortTool.java
URL: http://svn.apache.org/viewvc/velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/generic/SortTool.java?view=diff&rev=564050&r1=564049&r2=564050
==============================================================================
--- velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/generic/SortTool.java (original)
+++ velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/generic/SortTool.java Wed Aug 8 17:02:58 2007
@@ -198,7 +198,8 @@
/**
* Does all of the comparisons
*/
- public static class PropertiesComparator implements Comparator
+ public static class PropertiesComparator
+ implements Comparator, java.io.Serializable
{
private static final int TYPE_ASCENDING = 1;
private static final int TYPE_DESCENDING = -1;
Modified: velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/view/VelocityViewServlet.java
URL: http://svn.apache.org/viewvc/velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/view/VelocityViewServlet.java?view=diff&rev=564050&r1=564049&r2=564050
==============================================================================
--- velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/view/VelocityViewServlet.java (original)
+++ velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/view/VelocityViewServlet.java Wed Aug 8 17:02:58 2007
@@ -92,7 +92,7 @@
"org.apache.velocity.tools.shared.config";
private static final long serialVersionUID = -3329444102562079189L;
- private VelocityView view;
+ private transient VelocityView view;
/**
* <p>Initializes servlet and VelocityView used to process requests.
@@ -104,19 +104,8 @@
{
super.init(config);
- // check for an init-param telling this servlet NOT
- // to share its VelocityView with others. by default, we
- // play nice and share the VelocityView with the other kids.
- String shared = findInitParameter(config, SHARED_CONFIG_PARAM);
- if (shared == null || shared.equals("false"))
- {
- setVelocityView(ServletUtils.getVelocityView(config));
- }
- else
- {
- // just create our own non-shared VelocityView
- setVelocityView(new VelocityView(config));
- }
+ // init the VelocityView (if it hasn't been already)
+ getVelocityView();
}
@@ -138,28 +127,37 @@
return param;
}
- protected void setVelocityView(VelocityView view)
+ protected VelocityView getVelocityView()
{
- if (view == null)
+ if (this.view == null)
{
- throw new NullPointerException("VelocityView cannot be null");
+ // check for an init-param telling this servlet NOT
+ // to share its VelocityView with others. by default, we
+ // play nice and share the VelocityView with the other kids.
+ ServletConfig config = getServletConfig();
+ String shared = findInitParameter(config, SHARED_CONFIG_PARAM);
+ if (shared == null || shared.equals("false"))
+ {
+ this.view = ServletUtils.getVelocityView(config);
+ assert (view != null);
+ }
+ else
+ {
+ // just create our own non-shared VelocityView
+ this.view = new VelocityView(config);
+ }
}
- this.view = view;
- }
-
- protected VelocityView getVelocityView()
- {
return this.view;
}
protected String getVelocityProperty(String name, String alternate)
{
- return this.view.getProperty(name, alternate);
+ return getVelocityView().getProperty(name, alternate);
}
protected Log getLog()
{
- return this.view.getLog();
+ return getVelocityView().getLog();
}
/**
@@ -220,7 +218,7 @@
protected Context createContext(HttpServletRequest request,
HttpServletResponse response)
{
- return view.getContext(request, response);
+ return getVelocityView().getContext(request, response);
}
protected void fillContext(Context context, HttpServletRequest request)
@@ -235,7 +233,7 @@
*
* <p>The default implementation is :
* <code>
- * response.setContentType(view.getDefaultContentType());
+ * response.setContentType(getVelocityView().getDefaultContentType());
* </code>
* where defaultContentType is set to the value of the default.contentType
* property, or "text/html" if that was not set for the {@link VelocityView}.
@@ -247,25 +245,25 @@
protected void setContentType(HttpServletRequest request,
HttpServletResponse response)
{
- response.setContentType(view.getDefaultContentType());
+ response.setContentType(getVelocityView().getDefaultContentType());
}
protected Template getTemplate(HttpServletRequest request,
HttpServletResponse response)
{
- return view.getTemplate(request, response);
+ return getVelocityView().getTemplate(request, response);
}
protected Template getTemplate(String name)
{
- return view.getTemplate(name);
+ return getVelocityView().getTemplate(name);
}
protected void mergeTemplate(Template template, Context context,
HttpServletResponse response)
throws IOException
{
- view.merge(template, context, response.getWriter());
+ getVelocityView().merge(template, context, response.getWriter());
}
@@ -326,7 +324,7 @@
// let's log the new exception then give up and
// throw a runtime exception that wraps the first one
String msg = "Exception while printing error screen";
- view.getLog().error(msg, e2);
+ getLog().error(msg, e2);
throw new RuntimeException(msg, e);
}
}
Modified: velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/view/jsp/VelocityViewTag.java
URL: http://svn.apache.org/viewvc/velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/view/jsp/VelocityViewTag.java?view=diff&rev=564050&r1=564049&r2=564050
==============================================================================
--- velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/view/jsp/VelocityViewTag.java (original)
+++ velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/view/jsp/VelocityViewTag.java Wed Aug 8 17:02:58 2007
@@ -47,8 +47,8 @@
private static int count = 0;
private static final long serialVersionUID = -3329444102562079189L;
- protected VelocityView view;
- protected ViewToolContext context;
+ protected transient VelocityView view;
+ protected transient ViewToolContext context;
protected String var;
protected String scope;
protected String template;