jon 00/11/22 13:50:27
Modified: src/java/org/apache/velocity/anakia AnakiaTask.java
Log:
fixed a logic bug in the last modified check
added a value to the context which is essentially the relative path. see the <img>
examples in the anakia examples for usage.
Revision Changes Path
1.5 +23 -3
jakarta-velocity/src/java/org/apache/velocity/anakia/AnakiaTask.java
Index: AnakiaTask.java
===================================================================
RCS file:
/home/cvs/jakarta-velocity/src/java/org/apache/velocity/anakia/AnakiaTask.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- AnakiaTask.java 2000/11/22 21:01:30 1.4
+++ AnakiaTask.java 2000/11/22 21:50:26 1.5
@@ -87,7 +87,7 @@
it for this project.
@author <a href="[EMAIL PROTECTED]">Jon S. Stevens</a>
- @version $Id: AnakiaTask.java,v 1.4 2000/11/22 21:01:30 jon Exp $
+ @version $Id: AnakiaTask.java,v 1.5 2000/11/22 21:50:26 jon Exp $
*/
public class AnakiaTask extends MatchingTask
{
@@ -175,7 +175,9 @@
{
if (lastmod.equalsIgnoreCase("false") || lastmod.equalsIgnoreCase("no")
|| lastmod.equalsIgnoreCase("off"))
+ {
this.lastModifiedCheck = false;
+ }
}
/**
@@ -257,7 +259,7 @@
outFile = new
File(destDir,xmlFile.substring(0,xmlFile.lastIndexOf('.'))+extension);
// only process files that have changed
- if (lastModifiedCheck && (inFile.lastModified() >
outFile.lastModified() ||
+ if (lastModifiedCheck == false || (inFile.lastModified() >
outFile.lastModified() ||
styleSheetLastModified > outFile.lastModified() ||
projectFileLastModified > outFile.lastModified()))
{
@@ -279,7 +281,8 @@
Context context = new Context();
context.put ("root", root.getRootElement());
context.put ("xmlout", new XMLOutputter());
-
+ context.put ("relativePath", getRelativePath(xmlFile));
+
// only put this into the context if it exists.
if (projectDocument != null)
context.put ("project", projectDocument.getRootElement());
@@ -325,6 +328,23 @@
}
}
}
+ }
+ /**
+ hacky method to figure out the relative path
+ that we are currently in. This is good for getting
+ the relative path for images and anchor's.
+ */
+ private String getRelativePath(String file)
+ {
+ StringTokenizer st = new StringTokenizer(file, "/\\");
+ // needs to be -1 cause ST returns 1 even if there are no matches. huh?
+ int slashCount = st.countTokens() - 1;
+ StringBuffer sb = new StringBuffer();
+ for (int i=0;i<slashCount ;i++ )
+ {
+ sb.append ("../");
+ }
+ return sb.toString();
}
/**
create directories as needed