Statistics
| Revision:

root / tmp / org.txm.core / src / groovy / org / txm / importer / bfm / BuildBiblioFromHeaders.groovy @ 187

History | View | Annotate | Download (3.6 kB)

1
package org.txm.importer.bfm;
2

    
3
import java.io.File;
4
import java.io.FileInputStream;
5
import java.io.InputStreamReader;
6
import java.nio.charset.Charset;
7
import org.txm.utils.*;
8
import org.txm.importer.*;
9

    
10
import javax.xml.stream.*;
11
import java.net.URL;
12
        
13

    
14
String xslfile = "G:\\Feuilles de style\\teiHeader2ficheBiblio.xsl";
15
ApplyXsl a = new ApplyXsl(xslfile);
16

    
17
File srcdirectory = new File("C:\\Documents and Settings\\alavrent\\TXM-SRC\\corptef")
18
File outdirectory = new File("C:\\Documents and Settings\\alavrent\\TXM-SRC\\corptef-biblio")
19
outdirectory.mkdir();
20
assert(srcdirectory.exists())
21
assert(outdirectory.exists())
22
assert(srcdirectory.isDirectory())
23
assert(srcdirectory.canRead())
24
assert(srcdirectory.canExecute())
25

    
26
List<File> files = srcdirectory.listFiles();
27

    
28
files = files.findAll{item-> item.getName().endsWith(".xml")}
29

    
30
long bigstart = System.currentTimeMillis()
31
for(File infile : files)
32
{
33
        String outfile = outdirectory.getAbsolutePath()+"/"+infile.getName().substring(0,infile.getName().length()-4)+"-biblio.html";
34
        if(infile.canRead())
35
        {
36
                long start = System.currentTimeMillis()
37
                println "Process : "+infile.getName()
38
                // String[] params = ["pbval1",1,"pbval2",2];
39
                a.process(infile.getAbsolutePath(), outfile); // no parameters
40
                // a.process( infile.getAbsolutePath(),outfile,params);
41
                println "Done : "+(System.currentTimeMillis()-start)+"ms"
42
        }
43
}
44
println "Total time : "+(System.currentTimeMillis()-bigstart)+"ms"
45
/*
46
class BuildBiblioFromHeaders {
47
        
48
        public static boolean process(File dir, File xslfile, File outputfile) {
49
                if(!(xslfile.exists() && xslfile.canRead()))
50
                {
51
                        println "xslfile does not exist"
52
                        return false;
53
                }
54
                
55
                if(!outputfile.getParentFile().exists())
56
                {
57
                        println "outputfile's parent does not exist"
58
                        return false;
59
                }
60
                
61
                
62
                
63
                XMLOutputFactory factory = XMLOutputFactory.newInstance();
64
                FileOutputStream output = new FileOutputStream(outputfile)
65
                XMLStreamWriter writer = factory.createXMLStreamWriter(output, "UTF-8");
66
                
67
                
68
                writer.writeStartDocument("UTF-8","1.0");
69
                writer.writeStartElement("html");
70
                //header
71
                writer.writeStartElement("head");
72
                //writer.write("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\"/>");
73
                writer.writeStartElement("meta");
74
                writer.writeAttribute("http-equiv","Content-Type");
75
                writer.writeAttribute("content","text/html");
76
                writer.writeAttribute("charset","UTF-8");
77
                writer.writeEndElement();//meta
78
                writer.writeStartElement("title");
79
                writer.writeCharacters("Fiches biblio BFM")
80
                writer.writeEndElement();//title
81
                writer.writeEndElement();//head
82
                
83
                writer.writeStartElement("body");
84
                
85
                String rootDir = dir.getAbsolutePath()+"/";
86
                
87
                List<File> files = new File(rootDir,"").listFiles();//scan directory split
88
                
89
                for(File f : files) {
90
                        
91
//                        ApplyXsl a = new ApplyXsl(xslfile.getAbsolutePath());
92
//                        String[] args = ["outputDir",xxx];
93
//                        a.process(f.getAbsolutePath(), "./HTML",args);
94
                        
95
                        
96

97
                }
98
                
99
                
100
                writer.writeEndElement();//body
101
                writer.close();
102
                return true;
103
        }
104
        
105
        
106
        
107
        public static void main(String[] args)
108
        {
109
        
110
                String rootDir;
111
                String htmloutdir;
112
                File dir = new File(rootDir);
113
                
114
                rootDir = "C:\\Documents and Settings\\alavrent\\TXM-SRC\\corptef";
115
                File xslfile = new File("G:\\Feuilles de style\\teiHeader2ficheBiblio.xsl")
116
                File outputfile = new File("C:\\Documents and Settings\\alavrent\\Mes documents\\bfm - local\\Bases bibliographiques (copie)\\Fiches_biblio_TXM_test.html")
117

118
                
119
                if(!BuildBiblioFromHeaders.process(xslfile, outputfile, false))
120
                        println("Error.")
121
                else
122
                        println "Success";
123
        }
124
}
125
*/