jstrachan 2003/04/04 07:58:54
Modified: jelly/src/java/org/apache/commons/jelly/tags/core
IncludeTag.java
Log:
Allowed a File to be specified to locate the script to be included.
Also tidied up the error handling to give a more descriptive reason for failure.
Also gave the source code a little spring clean.
Revision Changes Path
1.12 +40 -24
jakarta-commons/jelly/src/java/org/apache/commons/jelly/tags/core/IncludeTag.java
Index: IncludeTag.java
===================================================================
RCS file:
/home/cvs/jakarta-commons/jelly/src/java/org/apache/commons/jelly/tags/core/IncludeTag.java,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -r1.11 -r1.12
--- IncludeTag.java 24 Jan 2003 22:53:34 -0000 1.11
+++ IncludeTag.java 4 Apr 2003 15:58:54 -0000 1.12
@@ -62,6 +62,8 @@
package org.apache.commons.jelly.tags.core;
+import java.io.File;
+
import org.apache.commons.jelly.JellyException;
import org.apache.commons.jelly.JellyTagException;
import org.apache.commons.jelly.MissingAttributeException;
@@ -77,6 +79,7 @@
public class IncludeTag extends TagSupport {
private String uri;
+ private File file;
private boolean shouldExport;
private boolean shouldInherit;
@@ -87,13 +90,13 @@
}
public void setInherit(String inherit) {
- if ( "true".equals( inherit ) ) {
+ if ("true".equals(inherit)) {
this.shouldInherit = true;
}
}
public void setExport(String export) {
- if ( "true".equals( export ) ) {
+ if ("true".equals(export)) {
this.shouldExport = true;
}
}
@@ -106,40 +109,53 @@
return this.shouldExport;
}
- // Tag interface
-
- //-------------------------------------------------------------------------
+ /**
+ * @return
+ */
+ public File getFile() {
+ return file;
+ }
- public void doTag(XMLOutput output) throws MissingAttributeException,
JellyTagException {
+ /**
+ * Sets the file to be included which is either an absolute file or a file
+ * relative to the current directory
+ */
+ public void setFile(File file) {
+ this.file = file;
+ }
- if (uri == null) {
- throw new MissingAttributeException( "uri" );
+ // Tag interface
+ //-------------------------------------------------------------------------
+ public void doTag(XMLOutput output)
+ throws MissingAttributeException, JellyTagException {
+ if (uri == null && file == null) {
+ throw new MissingAttributeException("uri");
}
// we need to create a new JellyContext of the URI
-
// take off the script name from the URL
-
+ String text = null;
try {
- context.runScript(uri, output, isExport(), isInherit() );
- }
+ if (uri != null) {
+ text = uri;
+ context.runScript(uri, output, isExport(), isInherit());
+ }
+ else {
+ text = file.toString();
+ context.runScript(file, output, isExport(), isInherit());
+ }
+ }
catch (JellyException e) {
- throw new JellyTagException("could not include jelly script",e);
+ throw new JellyTagException("could not include jelly script: " + text +
". Reason: " + e, e);
}
}
// Properties
-
//-------------------------------------------------------------------------
-
/** Sets the URI (relative URI or absolute URL) for the script to evaluate. */
-
public void setUri(String uri) {
-
this.uri = uri;
-
}
-
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]