Statistics
| Revision:

root / tmp / org.txm.core / src / groovy / org / txm / importer / graal / GraalApplyXsl.groovy @ 187

History | View | Annotate | Download (3.5 kB)

1
// Copyright © 2010-2013 ENS de Lyon.
2
// Copyright © 2007-2010 ENS de Lyon, CNRS, INRP, University of
3
// Lyon 2, University of Franche-Comté, University of Nice
4
// Sophia Antipolis, University of Paris 3.
5
// 
6
// The TXM platform is free software: you can redistribute it
7
// and/or modify it under the terms of the GNU General Public
8
// License as published by the Free Software Foundation,
9
// either version 2 of the License, or (at your option) any
10
// later version.
11
// 
12
// The TXM platform is distributed in the hope that it will be
13
// useful, but WITHOUT ANY WARRANTY; without even the implied
14
// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15
// PURPOSE. See the GNU General Public License for more
16
// details.
17
// 
18
// You should have received a copy of the GNU General
19
// Public License along with the TXM platform. If not, see
20
// http://www.gnu.org/licenses.
21
// 
22
// 
23
// 
24
// $LastChangedDate: 2014-09-15 10:51:15 +0200 (Mon, 15 Sep 2014) $
25
// $LastChangedRevision: 2836 $
26
// $LastChangedBy: mdecorde $ 
27
//
28
package org.txm.importer.graal
29

    
30
import javax.xml.stream.*;
31
import java.net.URL;
32
import java.lang.Boolean
33
import javax.xml.transform.TransformerFactory
34
import javax.xml.transform.stream.StreamResult
35
import javax.xml.transform.stream.StreamSource
36
import java.util.Map
37

    
38
// TODO: Auto-generated Javadoc
39
/** The trans data. @author ayepdieu previous version of the script ApplyXsl */
40
public class GraalApplyXsl{
41
        private def transData;
42
        
43
        /** The factory. */
44
        private def factory;
45
        
46
        /** The source. */
47
        private def source;
48
        
49
        /** The transformer. */
50
        private def transformer;
51
        
52
        /**
53
         * Instantiates a new graal apply xsl.
54
         *
55
         * @param urlXsl the url xsl
56
         */
57
        public GraalApplyXsl(URL urlXsl){
58
                try 
59
                {
60
                        FileInputStream inputStream = new FileInputStream(new File(urlXsl.getFile()));
61
                        factory = new net.sf.saxon.TransformerFactoryImpl();
62
                        source = new StreamSource(inputStream)
63
                        source.setSystemId(urlXsl.getPath());
64
                        transformer = factory.newTransformer(source)
65
                } catch (XMLStreamException ex) {
66
                        System.out.println(ex);
67
                }catch (IOException ex) {
68
                        System.out.println("IOException while parsing ");
69
                }
70
        }
71
        
72
        /**
73
         * Sets the params.
74
         *
75
         * @param name the name
76
         * @param value the value
77
         */
78
        public void setParams(String name, int value) {
79
            transformer.setParameter(name, value);
80
        }
81
        
82
        /**
83
         * Sets the params.
84
         *
85
         * @param name the name
86
         * @param value the value
87
         */
88
        public void setParams(String name, String value) {
89
            transformer.setParameter(name, value);
90
        }
91
        
92
        /**
93
         * Apply xsl.
94
         *
95
         * @param urlXml the url xml
96
         * @param dirPathName the dir path name
97
         * @param fileName the file name
98
         * @return true, if successful
99
         */
100
        public boolean ApplyXsl(URL urlXml, String dirPathName, String fileName) {
101
                FileInputStream inputData = new FileInputStream(new File(urlXml.getFile()));
102
                def output = new File(dirPathName, fileName)
103

    
104
                transformer.transform( new StreamSource(inputData), new StreamResult(output) )
105
        }
106

    
107
        /**
108
         * The main method.
109
         *
110
         * @param args the arguments
111
         */
112
        public static void main(String[] args) 
113
        {
114
                String sortie = "Page-test"
115
                for (int index = 0; index < 1; index++) {
116
                        GraalApplyXsl DecTxt = new GraalApplyXsl(new URL("file:///home/ayepdieu/srcQuete/Sources/breakByMilestone.xsl"));
117
                        DecTxt.setParams("pbval1", index + 1);
118
                        DecTxt.setParams("pbval2", index + 2);
119
                        DecTxt.ApplyXsl(new URL("file:///home/ayepdieu/srcQuete/Sources/qgraal_cm_2009-07-d.xml"), "/home/ayepdieu/srcQuete/Decoupe", sortie + "_" + (index+ 1) + ".xml");
120
                }
121
        }
122
}