Bug #2208

XTZ Import, fail to apply xsl\4-edition\1-default-html.xsl

Added by Sebastien Jacquot over 2 years ago. Updated 7 months ago.

Status:New Start date:05/19/2017
Priority:Normal Due date:
Assignee:- % Done:

0%

Category:Import Spent time: -
Target version:TXM X.X

Description

XTZ import fails when applying xsl\4-edition\1-default-html.xsl (Windows) at the copying step, log:

-- Applying C:\Tools\Textometrie\___corpus\xml\_livrets_opera_final\livrets_opera_original\xsl\4-edition\1-default-html.xsl XSL to 75 files with parameters: {import-xml-path=file:/C:/Tools/Textometrie/___corpus/xml/_livrets_opera_final/livrets_opera_original/import.xml, number-words-per-page=500, output-directory=file:/C:/Users/s/TXM/corpora/LIVRETSOPERAORIGINAL/HTML/LIVRETSOPERAORIGINAL/default/, pagination-element=pb} on directory C:\Users\s\TXM\corpora\LIVRETSOPERAORIGINAL\txm\LIVRETSOPERAORIGINAL result written in C:\Users\s\TXM\corpora\LIVRETSOPERAORIGINAL\HTML\LIVRETSOPERAORIGINAL\default
 .copying inputfile in: C:\tmp\01_CADMUS.xml
java.io.FileNotFoundException: \tmp\01_CADMUS.xml (Le chemin d’accès spécifié est introuvable)
    at java.io.FileOutputStream.open(Native Method)
    at java.io.FileOutputStream.<init>(FileOutputStream.java:221)
    at java.io.FileOutputStream.<init>(FileOutputStream.java:171)
    at org.txm.utils.io.FileCopy.copy(FileCopy.java:81)
    at org.txm.utils.io.FileCopy.copy(FileCopy.java:56)
    at org.txm.importer.ApplyXsl2.process(ApplyXsl2.java:284)
    at org.txm.importer.ApplyXsl2.processImportSources(ApplyXsl2.java:408)
    at org.txm.importer.ApplyXsl2$processImportSources.call(Unknown Source)
    at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:45)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:108)
    at org.txm.importer.xtz.XTZPager.doPostEditionXSLStep(XTZPager.groovy:308)
    at org.txm.importer.xtz.XTZPager.process(XTZPager.groovy:54)
    at org.txm.importer.xtz.ImportModule$2.run(ImportModule.java:155)
Exception in thread "Thread-40" java.lang.NullPointerException
    at org.txm.utils.io.FileCopy.copy(FileCopy.java:91)
    at org.txm.utils.io.FileCopy.copy(FileCopy.java:56)
    at org.txm.importer.ApplyXsl2.process(ApplyXsl2.java:284)
    at org.txm.importer.ApplyXsl2.processImportSources(ApplyXsl2.java:408)
    at org.txm.importer.ApplyXsl2$processImportSources.call(Unknown Source)
    at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:45)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:108)
    at org.txm.importer.xtz.XTZPager.doPostEditionXSLStep(XTZPager.groovy:308)
    at org.txm.importer.xtz.XTZPager.process(XTZPager.groovy:54)
    at org.txm.importer.xtz.ImportModule$2.run(ImportModule.java:155)

Seems to be linked with C:\tmp\01_CADMUS.xml path and debug mode enabled (/org.txm.core/src/groovy/org/txm/importer/ApplyXsl2.java).

public boolean process(File xmlinfile, File xmloutfile) throws TransformerException, IOException {

        // bufferize result in a String
        StringWriter strWriter = new StringWriter();
        StreamResult out = new StreamResult(strWriter);

        if (debug) {
            File inputfile_copy = new File("/tmp", xmlinfile.getName());
            System.out.println("copying inputfile in: "+inputfile_copy.getAbsolutePath());
            inputfile_copy.delete();
            FileCopy.copy(xmlinfile, inputfile_copy);
        }

        transformer.transform(new StreamSource(xmlinfile), out);

        // then write the result in the result file
        if (xmloutfile != null) {
            BufferedWriter w = new BufferedWriter(new FileWriter(xmloutfile));
            w.write(strWriter.toString());
            w.close();

            if (debug) {
                File inputfile_copy = new File("/tmp", xmlinfile.getName());
                String s = Diff.diffFile(inputfile_copy, xmloutfile);
                if (s.length() > 0) { // for ultra debug ?
                    System.out.println("Result "+xmlinfile.getName()+" VS "+ xmloutfile.getName()+" diff="+s);
                } else {
                    System.out.println("Warning: no diff between "+inputfile_copy+" and "+ xmloutfile);
                }
            }
        }

        cleanMemory();
        return true;
    }

Also the tmp files seem to not be deleted.

Solution 1 (store the files in tmp user directory)

  • use System.getProperty("java.io.tmpdir") to retrieve the platform tmp directory
  • use inputfile.deleteOnExit() to destroy the tmp file when JVM exits

Solution 2 (store the files in current corpora directory)

  • use the current corpus absolute path + "tmp/"
  • use inputfile.deleteOnExit() to destroy the tmp file when JVM exits

Solution 3 (remove the debug code when XTZ module will be validated)

Misspelling

  • replace ".copying inputfile in:" with ".copying inputfile to:"

History

#1 Updated by Sebastien Jacquot over 2 years ago

  • Description updated (diff)

#2 Updated by Sebastien Jacquot over 2 years ago

  • Description updated (diff)

#3 Updated by Sebastien Jacquot over 2 years ago

Code proposal that creates the tmp directory in the corpora dir in TXM_USER with deleteOnExit():

        /**
     * Process files without xslt args.
     *
     * @param xmlinfile the xmlinfile
     * @param xmloutfile the xmloutfile
     * @return true, if successful
     * @throws TransformerException 
     * @throws IOException 
     */
    public boolean process(File xmlinfile, File xmloutfile) throws TransformerException, IOException {

        // bufferize result in a String
        StringWriter strWriter = new StringWriter();
        StreamResult out = new StreamResult(strWriter);

        File tmp_dir = null;
        File inputfile_copy = null;

        if (debug) {
            //FIXME: old version
            //File inputfile_copy = new File("/tmp", xmlinfile.getName());
            //FIXME: new version
            tmp_dir = new File(xmlinfile.getParentFile().getAbsolutePath() + "/tmp");
            tmp_dir.mkdirs();
            tmp_dir.deleteOnExit();

            inputfile_copy = new File(tmp_dir, xmlinfile.getName());

            System.out.println("copying inputfile to: "+inputfile_copy.getAbsolutePath());
            //FIXME: old version
            //inputfile_copy.delete();
            //FIXME: new version
            inputfile_copy.deleteOnExit();
            FileCopy.copy(xmlinfile, inputfile_copy);

        }

        transformer.transform(new StreamSource(xmlinfile), out);

        // then write the result in the result file
        if (xmloutfile != null) {
            BufferedWriter w = new BufferedWriter(new FileWriter(xmloutfile));
            w.write(strWriter.toString());
            w.close();

            if (debug && inputfile_copy != null) {
                //FIXME: old version
                //File inputfile_copy = new File("/tmp", xmlinfile.getName());

                String s = Diff.diffFile(inputfile_copy, xmloutfile);
                if (s.length() > 0) { // for ultra debug ?
                    System.out.println("Result "+xmlinfile.getName()+" VS "+ xmloutfile.getName()+" diff="+s);
                } else {
                    System.out.println("Warning: no diff between "+inputfile_copy+" and "+ xmloutfile);
                }
            }
        }

        cleanMemory();
        return true;
    }

#4 Updated by Sebastien Jacquot over 2 years ago

For information: the debug mode is activated if TXM log level > WARNING.

#5 Updated by Sebastien Jacquot over 1 year ago

  • Target version changed from TXM 0.8.0a (split/restructuration) to TXM 0.8.0

#6 Updated by Matthieu Decorde 7 months ago

  • Target version changed from TXM 0.8.0 to TXM X.X

Also available in: Atom PDF