henning 2003/03/18 02:26:38
Modified: src/java/org/apache/turbine/util/template
TemplateNavigation.java
Log:
Cleaned up the toString() handling with respect to the
template being unset. If you simply call $navigation
in your template before using "$navigation.setTemplate()" you
would get a strange NPE in your logs without any real hint
where the problem is.
Now your application will report
"Navigation Template is null (Might be unset)"
on screen to show where the bug is.
Revision Changes Path
1.7 +31 -11
jakarta-turbine-2/src/java/org/apache/turbine/util/template/TemplateNavigation.java
Index: TemplateNavigation.java
===================================================================
RCS file:
/home/cvs/jakarta-turbine-2/src/java/org/apache/turbine/util/template/TemplateNavigation.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- TemplateNavigation.java 9 Mar 2003 02:54:14 -0000 1.6
+++ TemplateNavigation.java 18 Mar 2003 10:26:38 -0000 1.7
@@ -57,6 +57,8 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.apache.commons.lang.StringUtils;
+
import org.apache.ecs.ConcreteElement;
import org.apache.turbine.modules.NavigationLoader;
@@ -91,7 +93,7 @@
private RunData data;
/* The name of the navigation template. */
- private String template;
+ private String template = null;
/**
* Constructor
@@ -112,6 +114,7 @@
*/
public TemplateNavigation setTemplate(String template)
{
+ log.debug("setTemplate(" + template + ")");
this.template = template;
return this;
}
@@ -123,25 +126,42 @@
*/
public String toString()
{
- log.debug("toString: " + this.template);
- data.getTemplateInfo().setNavigationTemplate(this.template);
String module = null;
String returnValue = null;
+
try
{
- module = TurbineTemplate.getNavigationName(template);
+ if (template == null)
+ {
+ returnValue = "Navigation Template is null (Might be unset)";
+ throw new Exception(returnValue);
+ }
- ConcreteElement results = NavigationLoader.getInstance()
- .eval(data, module);
+ data.getTemplateInfo().setNavigationTemplate(template);
+ module = TurbineTemplate.getNavigationName(template);
+
+ if (module == null)
+ {
+ returnValue = "Template Service returned null for Navigation
Template " + template;
+ throw new Exception(returnValue);
+ }
+
+ ConcreteElement results =
+ NavigationLoader.getInstance().eval(data, module);
returnValue = results.toString();
}
catch (Exception e)
{
- String message = ("Error processing navigation template:"
- + this.template + " using module: " + module);
- log.error(message, e);
- returnValue = message;
+ if (returnValue == null)
+ {
+ returnValue = "Error processing navigation template: "
+ + template + ", using module: " + module;
+ }
+ log.error(returnValue, e);
}
+
+ log.debug("Returning " + returnValue);
+
return returnValue;
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]