cmarchand / gaulois-pipe

A XSLT pipelining solution
Mozilla Public License 2.0
9 stars 4 forks source link

Error when calling external xslt file #38

Closed karrayhamdi closed 6 years ago

karrayhamdi commented 6 years ago

Hi,

i get an error whe i call an external xslt, with absolute path or uri. href is considered as path here

private File getFile() throws URISyntaxException {
 if(file==null) {
   if(href.startsWith("jar:")) {
     file = new File(new URI(href));
   } else if(href.startsWith("cp:")) {
     // nope
   } else {
     file = new File(href);
   }
 }
 return file;
}

and as uri here

private XsltTransformer getXsltTransformer(String href, HashMap<QName,ParameterValue> parameters)
    throws MalformedURLException, SaxonApiException, URISyntaxException, FileNotFoundException, IOException {
  String __href = (String)ParametersMerger.processParametersReplacement(href, parameters);
  LOGGER.debug("loading "+__href);
  XsltExecutable xsl = xslCache.get(__href);
  if(xsl==null) {
    LOGGER.trace(__href+" not in cache");
    try {
      Source xslSource = getUriResolver().resolve(href, getCurrentDirUri());
      if(xslSource==null) {
        throw new FileNotFoundException("Unable to resolve "+href);
      }

The best way, il think, is to consider href as an uri everywhere.

thanks :)

cmarchand commented 6 years ago

Could you provide your config file and the release of gaulois-pipe you use, to be able to create a test case ?

karrayhamdi commented 6 years ago

here is it :)

<config xmlns="http://efl.fr/chaine/saxon-pipe/config"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <pipe mutiThreadMaxSourceSize="40000000" nbThreads="8">

    <xslt href="$[xslt-file-uri]"/>

    <output id="html">
      <folder absolute="$[output-dir-uri]"/>
      <fileName name="$[input-basename].xml"/>
    </output>

  </pipe>
  <params>
    <param name="xslt-file-uri" value=""/>
    <param name="output-dir-uri" value=""/>
    <param name="input-dir-uri" value=""/>
  </params>
  <sources>
    <folder href="$[input-dir-uri]" pattern=".*\.xml" recurse="false"/>
  </sources>
</config>
cmarchand commented 6 years ago

And the value of xslt-file-uri you provide ?

karrayhamdi commented 6 years ago

i tried both "file:/d:/..../toto.xsl" and "d:/.../toto.xsl".

cmarchand commented 6 years ago

Here is a piece of code, to disply files as URI. dir_output log This image shows the File I want to log as URI

The code is :

public static void main(String[] args) {
    File local = new File(".");
    FileSystem fs = FileSystems.getDefault();
    Path d = null;
    for(Path path: fs.getRootDirectories()) {
        if(path.toString().toLowerCase().startsWith("d")) {
            d = path;
            break;
        }
    }
    if(d==null) {
        System.err.println("d: not found");
        return;
    }
    File fD = d.toFile();
    File devel = new File(fD, "devel");
    File output = new File(devel, "output.log");
    System.out.println("output.toString(): "+output.toString());
    System.out.println("output.getAbsolutePath: "+output.getAbsolutePath());
    System.out.println("output.toURI().toString(): "+output.toURI().toString());
}

Output of this code is :

output.toString(): D:\devel\output.log
output.getAbsolutePath: D:\devel\output.log
output.toURI().toString(): file:/D:/devel/output.log

I think, if you try file:/D:/.../toto.xsl, it should work correctly.

BUT : this is not a good practise. As properties may change from input file to input file, XSL won't be compiled when gaulois-pipe starts, but when required, and won't be cached, so will be compiled each time is need. You'd better use constant XSLT URIs.

Tell me if this solve your problem.

karrayhamdi commented 6 years ago

I already tried that but still not working for me. This is my project. This project allow you performing tnr on html. It need some xml files, 2 xslt and a working directory. To run it : main class : eu.els.sie.efl.html.tnr.Run

params : -xmlDirPath D:\08-ELS\15-CONVBIL\00-DATA\xml -workDirPath D:\08-ELS\15-CONVBIL\00-DATA\work -originalXsltFilePath D:\08-ELS\11-BOFIP\sie-efl-sgml2html\src\main\xslt\codescV2.xslt -revisedXsltFilePath D:\08-ELS\15-CONVBIL\01-DEV\sie-efl-sgml2html\src\main\xslt\codescV2.xslt

I get this exception (note that file:/ is in the middle of the path) :

Caused by: fr.efl.chaine.xslt.InvalidSyntaxException: D:\08-ELS\15-CONVBIL\01-DEV\html-tnr\file:\D:\08-ELS\11-BOFIP\sie-efl-sgml2html\src\main\xslt\codescV2.xslt does not exists or is not a regular file
    at fr.efl.chaine.xslt.config.Xslt.verify(Xslt.java:98) ~[gaulois-pipe-1.03.01.jar:?]
    at fr.efl.chaine.xslt.config.Pipe.verify(Pipe.java:77) ~[gaulois-pipe-1.03.01.jar:?]
    at fr.efl.chaine.xslt.config.Config.verify(Config.java:97) ~[gaulois-pipe-1.03.01.jar:?]
    at com.processing.step.GauloisPipeStep.run(GauloisPipeStep.java:128) ~[processing-0.0.2.jar:?]
    ... 5 more
cmarchand commented 6 years ago

Try running GP with these parameters :

-xmlDirPath file:/D:/08-ELS/15-CONVBIL/00-DATA/xml -workDirPath file:/D:/08-ELS/15-CONVBIL/00-DATA/work -originalXsltFilePath file:/D:/08-ELS/11-BOFIP/sie-efl-sgml2html/src/main/xslt/codescV2.xslt -revisedXsltFilePath file:/D:/08-ELS/15-CONVBIL/01-DEV/sie-efl-sgml2html/src/main/xslt/codescV2.xslt

cmarchand commented 6 years ago

Or, better, launch me a ZIP file, with a .bat, that I could reproduce exactly your problem.

karrayhamdi commented 6 years ago

:) i take file path as paratmeter and i pass new File(filePath).toUri.toString() to gaulois-pipe

karrayhamdi commented 6 years ago

tnr-0.0.2-SNAPSHOT-linux.tar.gz

script Run with 4 param as file path. Thanks :)

cmarchand commented 6 years ago

And I run this on WHAT ? I can not understand why you open an issue with windows-like file pathes problems, and give a sample program call xxx-linux-xxx with a bash script in...

cmarchand commented 6 years ago

Problem identified.

cmarchand commented 6 years ago

Release 1.03.04-RC4 published. You have to wait a little bit to be synchronized on maven central. Watch http://repo1.maven.org/maven2/top/marchand/xml/gaulois-pipe/

karrayhamdi commented 6 years ago

perfect :)