1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111
|
/*
* NAT - An universal Translator
* Copyright (C) 2005 Bruno Mascret
* Contact: bmascret@free.fr
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package nat.convertisseur;
import gestionnaires.GestionnaireErreur;
import nat.Nat;
import nat.Transcription;
// *** writer2latex ***
/*import writer2latex.Writer2XHTML;
import writer2latex.office.MIMETypes;*/
//import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
//import java.util.Enumeration;
import writer2latex.api.*;
import writer2latex.office.MIMETypes;
/**
* Convertisseur de documents odt; utilise writer2xhtml pour convertir en xhtml puis {@link ConvertisseurXML}
* pour convertir au format interne
* @author bruno
*
*/
public class ConvertisseurOpenOffice extends ConvertisseurXML
{
/**
* Constructeur
* @param src l'adresse du fichier source
* @param tgt l'adresse du fichier cible
*/
public ConvertisseurOpenOffice(String src, String tgt){super(src, tgt);}
/**
* Redéfinition de {@link Convertisseur#convertir(GestionnaireErreur)}
* <p>Convertit d'abord le fichier odt en fichier xhtml avec <code>writer2xhtml</code> (création du fichier temporaire
* {@link Transcription#fTempXHTML}</p>.
* <p>Convertit ensuite le fichier {@link Transcription#fTempXHTML} au format interne.
*/
@Override
public boolean convertir(GestionnaireErreur gest)
{
tempsExecution = System.currentTimeMillis();
boolean retour;
gest.afficheMessage("** Conversion en XHTML avec Writer2XHTML...",Nat.LOG_VERBEUX);
//Create a XHTML converter
Converter converter = ConverterFactory.createConverter(MIMETypes.XHTML_MATHML);
//Create a configuration
Config config = converter.getConfig();
try
{
config.read(new FileInputStream("/usr/share/writer2latex/cleanxhtml.xml"));
config.setOption("inputencoding","utf-8");
config.setOption("use_named_entities", "true");
//Convert the document
//gest.afficheMessage(Transcription.fTempXHTML+" hdcd\n",Nat.LOG_SILENCIEUX);
String t=Transcription.fTempXHTML; //il ne faut que le nom de fichier sans le path pour la conversion et seulement le path pour result.write
ConverterResult result = converter.convert(new FileInputStream(source),t.substring(t.lastIndexOf("/")+1));
//gest.afficheMessage(t.substring(t.lastIndexOf("/"))+" hsdsdsdsd\n",Nat.LOG_SILENCIEUX);
//gest.afficheMessage(t.substring(0,t.lastIndexOf("/"))+" FFFFFFFFFFd\n",Nat.LOG_SILENCIEUX);
result.write(new File(t.substring(0,t.lastIndexOf("/"))));
/*Enumeration docEnum = result.getMasterDocument().;
while (docEnum.hasMoreElements())
{
OutputFile docOut = (OutputFile) docEnum.nextElement();
FileOutputStream fos = new FileOutputStream(docOut.getFileName());
docOut.write(fos);
fos.flush();
fos.close();
}*/
}
catch(Exception e)
{
gest.afficheMessage("Problème lors de la conversion avec Writer2XHTML "+e.getLocalizedMessage(),Nat.LOG_SILENCIEUX); e.printStackTrace();
e.printStackTrace();
}
/*Write the files
Enumeration docEnum = dataOut.getDocumentEnumeration();
while (docEnum.hasMoreElements())
{
OutputFile docOut = (OutputFile) docEnum.nextElement();
FileOutputStream fos = new FileOutputStream(docOut.getFileName());
docOut.write(fos);
fos.flush();
fos.close();
}*/
//conversion de xhtml vers interne
ConvertisseurXML convXML = new ConvertisseurXML(Transcription.fTempXHTML, cible);
retour = convXML.convertir(gest);
tempsExecution = System.currentTimeMillis() - tempsExecution;
return retour;
}
}
|