Browse Source

Fix file protocol prefix so that there is no more

and no less than 3 '/' on whatever platform it is running.
PR: 6259
Reported by: sl@ragbildung.de (Sascha Luedecke)


git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@271216 13f79535-47bb-0310-9956-ffa450edef68
master
Stephane Bailliez 23 years ago
parent
commit
1df82da13f
4 changed files with 25 additions and 5 deletions
  1. +1
    -1
      src/main/org/apache/tools/ant/taskdefs/XSLTLiaison.java
  2. +1
    -1
      src/main/org/apache/tools/ant/taskdefs/XSLTProcess.java
  3. +9
    -3
      src/main/org/apache/tools/ant/taskdefs/optional/TraXLiaison.java
  4. +14
    -0
      src/testcases/org/apache/tools/ant/taskdefs/optional/TraXLiaisonTest.java

+ 1
- 1
src/main/org/apache/tools/ant/taskdefs/XSLTLiaison.java View File

@@ -76,7 +76,7 @@ public interface XSLTLiaison {
* case since most parsers for now incorrectly makes no difference
* between it.. and users also have problem with that :)
*/
String FILE_PROTOCOL_PREFIX = "file:///";
String FILE_PROTOCOL_PREFIX = "file://";

/**
* set the stylesheet to use for the transformation.


+ 1
- 1
src/main/org/apache/tools/ant/taskdefs/XSLTProcess.java View File

@@ -217,7 +217,7 @@ public class XSLTProcess extends MatchingTask implements XSLTLogger {
/**
* Set the destination directory into which the XSL result
* files should be copied to
* @param dirName the name of the destination directory
* @param dir the name of the destination directory
**/
public void setDestdir(File dir) {
destDir = dir;


+ 9
- 3
src/main/org/apache/tools/ant/taskdefs/optional/TraXLiaison.java View File

@@ -162,9 +162,15 @@ public class TraXLiaison implements XSLTLiaison, ErrorListener, XSLTLoggerAware
// because it grabs the base uri via lastIndexOf('/') without
// making sure it is really a /'ed path
protected String getSystemId(File file){
String path = file.getAbsolutePath();
path = path.replace('\\','/');
return FILE_PROTOCOL_PREFIX + path;
String path = file.getAbsolutePath();
path = path.replace('\\','/');

// on Windows, use 'file:///'
if (File.separatorChar == '\\') {
return FILE_PROTOCOL_PREFIX + "/" + path;
}
// Unix, use 'file://'
return FILE_PROTOCOL_PREFIX + path;
}

public void addParam(String name, String value){


+ 14
- 0
src/testcases/org/apache/tools/ant/taskdefs/optional/TraXLiaisonTest.java View File

@@ -1,6 +1,7 @@
package org.apache.tools.ant.taskdefs.optional;

import org.apache.tools.ant.taskdefs.XSLTLiaison;
import org.apache.tools.ant.taskdefs.condition.Os;
import org.apache.tools.ant.BuildException;

import java.io.File;
@@ -110,4 +111,17 @@ public class TraXLiaisonTest extends AbstractXSLTLiaisonTest {
}
}
}

public void testSystemId(){
File file = null;
if ( File.separatorChar == '\\' ){
file = new File("d:\\jdk");
} else {
file = new File("/user/local/bin");
}
String systemid = ((TraXLiaison)liaison).getSystemId(file);
assert("SystemIDs should start by file:///", systemid.startsWith("file:///"));
assert("SystemIDs should not start with file:////", !systemid.startsWith("file:////"));
}

}

Loading…
Cancel
Save