Author: jhm
Date: Tue Jul 18 01:28:25 2006
New Revision: 423009
URL: http://svn.apache.org/viewvc?rev=423009&view=rev
Log:
Bug 21042 "Setting XSL parameter to input filename when processed whole
directory."
* changed from File.getParent() to String.substring() to avoid changing between
/ and \
* "dir" defaults to '.' instead of empty string, so dir+'/'+name would not
result in an absolute path
Modified:
ant/core/trunk/docs/manual/CoreTasks/style.html
ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/XSLTProcess.java
ant/core/trunk/src/testcases/org/apache/tools/ant/taskdefs/StyleTest.java
Modified: ant/core/trunk/docs/manual/CoreTasks/style.html
URL:
http://svn.apache.org/viewvc/ant/core/trunk/docs/manual/CoreTasks/style.html?rev=423009&r1=423008&r2=423009&view=diff
==============================================================================
--- ant/core/trunk/docs/manual/CoreTasks/style.html (original)
+++ ant/core/trunk/docs/manual/CoreTasks/style.html Tue Jul 18 01:28:25 2006
@@ -191,8 +191,8 @@
</tr>
<tr>
<td valign="top">filenameparameter</td>
- <td valign="top">Specifies a xsl parameter for accessing the name
- of the current processed file. If not set, the file name is not
+ <td valign="top">Specifies a xsl parameter for accessing the name
+ of the current processed file. If not set, the file name is not
passed to the transformation.
<em>Since Ant 1.7</em>.</td>
<td valign="top" align="center">No</td>
@@ -200,8 +200,9 @@
<tr>
<td valign="top">filedirparameter</td>
<td valign="top">Specifies a xsl parameter for accessing the directory
- of the current processed file. If not set, the directory is not
- passed to the transformation.
+ of the current processed file. For files in the current directory a
+ value of '.' will be passed to the transformation.
+ If not set, the directory is not passed to the transformation.
<em>Since Ant 1.7</em>.</td>
<td valign="top" align="center">No</td>
</tr>
@@ -454,7 +455,7 @@
</xsl:template>
</xsl:stylesheet>
-</pre>
+</pre>
</blockquote>
<hr>
Modified: ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/XSLTProcess.java
URL:
http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/XSLTProcess.java?rev=423009&r1=423008&r2=423009&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/XSLTProcess.java
(original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/XSLTProcess.java Tue
Jul 18 01:28:25 2006
@@ -1037,13 +1037,23 @@
File inFile
) throws Exception {
String fileName = FileUtils.getRelativePath(baseDir, inFile);
- File file = new File(fileName);
-
+
+ String name;
+ String dir;
+ int lastDirSep = fileName.lastIndexOf("/");
+ if (lastDirSep > -1) {
+ name = fileName.substring(lastDirSep + 1);
+ dir = fileName.substring(0, lastDirSep);
+ } else {
+ name = fileName;
+ dir = "."; // so a dir+"/"+name would not result in an
absolute path
+ }
+
if (fileNameParameter != null) {
- liaison.addParam(fileNameParameter, inFile.getName());
+ liaison.addParam(fileNameParameter, name);
}
if (fileDirParameter != null) {
- liaison.addParam(fileDirParameter, (file.getParent()!=null) ?
file.getParent() : "" );
+ liaison.addParam(fileDirParameter, dir);
}
}
Modified:
ant/core/trunk/src/testcases/org/apache/tools/ant/taskdefs/StyleTest.java
URL:
http://svn.apache.org/viewvc/ant/core/trunk/src/testcases/org/apache/tools/ant/taskdefs/StyleTest.java?rev=423009&r1=423008&r2=423009&view=diff
==============================================================================
--- ant/core/trunk/src/testcases/org/apache/tools/ant/taskdefs/StyleTest.java
(original)
+++ ant/core/trunk/src/testcases/org/apache/tools/ant/taskdefs/StyleTest.java
Tue Jul 18 01:28:25 2006
@@ -168,7 +168,7 @@
public void testFilenameAndFiledirAsParam() throws Exception {
executeTarget("testFilenameAndFiledirAsParam");
assertFileContains("out/out/one.txt", "filename='one.xml'");
- assertFileContains("out/out/one.txt", "filedir =''");
+ assertFileContains("out/out/one.txt", "filedir ='.'");
assertFileContains("out/out/dir/four.txt", "filename='four.xml'");
assertFileContains("out/out/dir/four.txt", "filedir ='dir'");
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]