dlr 01/05/07 18:27:21
Modified: src/java/org/apache/velocity/convert WebMacro.java
Log:
Single level directory structures (i.e. a directory with a template in
it) were causing String parsing exceptions. A combination of grabbing
the paths from the File object (used to test the user-specified file)
and better handling of the string parsing keeps us safe from such
exceptions.
Revision Changes Path
1.10 +15 -5
jakarta-velocity/src/java/org/apache/velocity/convert/WebMacro.java
Index: WebMacro.java
===================================================================
RCS file:
/home/cvs/jakarta-velocity/src/java/org/apache/velocity/convert/WebMacro.java,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- WebMacro.java 2001/05/08 00:24:52 1.9
+++ WebMacro.java 2001/05/08 01:27:21 1.10
@@ -70,7 +70,7 @@
* this class.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Jason van Zyl</a>
- * @version $Id: WebMacro.java,v 1.9 2001/05/08 00:24:52 dlr Exp $
+ * @version $Id: WebMacro.java,v 1.10 2001/05/08 01:27:21 dlr Exp $
*/
public class WebMacro
{
@@ -165,7 +165,7 @@
if (file.isDirectory())
{
- String basedir = args[0];
+ String basedir = file.getAbsolutePath();
String newBasedir = basedir + VM_EXT;
DirectoryScanner ds = new DirectoryScanner();
@@ -209,9 +209,8 @@
else
{
template = basedir + pathSeparator + file;
- templateDir = newBasedir + pathSeparator +
- file.substring(0, file.lastIndexOf(pathSeparator));
-
+ templateDir = newBasedir + extractPath(file);
+
outputDirectory = new File(templateDir);
if (! outputDirectory.exists())
@@ -235,6 +234,17 @@
}
return true;
+ }
+
+ /**
+ * Gets the path segment of the full path to a file (i.e. one
+ * which originally included the file name).
+ */
+ private final String extractPath(String file)
+ {
+ int lastSepPos = file.lastIndexOf(pathSeparator);
+ return (lastSepPos == -1 ? "" :
+ pathSeparator + file.substring(0, lastSepPos));
}
/**