Attention une mise à jour du service Gitlab va être effectuée le mardi 18 janvier (et non lundi 17 comme annoncé précédemment) entre 18h00 et 18h30. Cette mise à jour va générer une interruption du service dont nous ne maîtrisons pas complètement la durée mais qui ne devrait pas excéder quelques minutes.

Commit 8e479240 authored by Fabien Triolet's avatar Fabien Triolet
Browse files

Refactoring of TSerializer code. Implement a serializer should be easier.

parent ef664a45
/**
* $Id: PDFSerializer.java,v 1.12 2002-11-06 14:08:21 serge Exp $
* $Id: PDFSerializer.java,v 1.13 2002-11-07 14:31:11 triolet Exp $
*
* Transmorpher
*
......@@ -27,44 +27,38 @@ package fr.fluxmedia.tmcontrib.serializer;
// Imported fr.fluxmedia.transmorpher
import fr.fluxmedia.transmorpher.engine.TSerializer;
import fr.fluxmedia.transmorpher.utils.TMException;
import fr.fluxmedia.transmorpher.utils.TMRuntimeException;
import fr.fluxmedia.transmorpher.utils.Parameters;
import fr.fluxmedia.transmorpher.utils.StringParameters;
import fr.fluxmedia.transmorpher.utils.TMException;
import fr.fluxmedia.transmorpher.utils.TMRuntimeException;
// Imported java.io classes
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.util.Properties;
// Imported org.apache.fop
import org.apache.fop.apps.Driver;
import org.apache.fop.messaging.MessageHandler;
import org.apache.log.Hierarchy;
import org.apache.log.format.PatternFormatter;
import org.apache.log.Priority;
import org.apache.log.LogTarget;
import org.apache.log.Priority;
import org.apache.log.format.PatternFormatter;
import org.apache.log.output.io.StreamTarget;
// Imported SAX classes
import org.xml.sax.ContentHandler;
import org.xml.sax.SAXException;
/**
*
* This class allows transmorpher to produce pdf or ps.
* To use this serializer, transmorpher has to know it.
* To do this, just add the following declaration of defextern in the process file :
* To do this, just add the following declaration of defextern in the process file :
* <code><p>&lt defextern name="fop" class="fr.fluxmedia.transmorpher.tmcontrib.serializer.PDFSerializer/&gt</p></code>
* <p>A fop serializer can now be declared in the process file :
* <code><p>&lt serialize id="outputPDF" type="fop" in="out1" &gt</p>
* <p>&lt with-param name="file"&gt ../samples/fo-sample/output/${filename}.pdf &lt /with-param &gt</p>
*<p>&lt with-param name="format"&gt pdf &lt /with-param &gt</p>
*<p>&lt with-param name="format"&gt pdf &lt /with-param &gt</p>
*<p>&lt /serialize &gt</p></code></p>
*<p>Available formats are :
* <ul>
......@@ -85,35 +79,31 @@ import org.xml.sax.SAXException;
* <li>logkit-1.0.jar</li>
* </ul>
* </p>
*
*@author triolet
*/
public final class PDFSerializer extends TSerializer {
/** the serializer */
private Driver driver = null;
/** format of the file (default format is pdf)*/
private String format="pdf";
/**
* The object which creates pdf,ps with fo
*/
protected Driver driver = null;
/**
* Constructor for the PDFSerializer object
*
*@param pIn in ports
*@param pParam the parameters of this component
*@param pStaticAttributes Description of the Parameter
*@exception SAXException Any SAX exception, possibly wrapping another exception.
*@exception IOException Description of the Exception
*@param pStaticAttributes static attributes of this component
*/
public PDFSerializer(String[] pIn, Parameters pParam, StringParameters pStaticAttributes)
throws SAXException, IOException {
public PDFSerializer(String[] pIn, Parameters pParam, StringParameters pStaticAttributes) {
super(pIn, pParam, pStaticAttributes);
driver = new Driver();
MessageHandler.setScreenLogger(new org.apache.avalon.framework.logger.NullLogger());
driver.setLogger(new org.apache.avalon.framework.logger.NullLogger());
format = (String) pParam.getParameter("format");
driver.setRenderer(Driver.RENDER_PDF);
if ((format.toLowerCase()).equals("pdf")) {
driver.setRenderer(Driver.RENDER_PDF);
......@@ -129,36 +119,20 @@ public final class PDFSerializer extends TSerializer {
*@return The contentHandler value
*/
public ContentHandler getContentHandler() {
return driver.getContentHandler();
return (ContentHandler)driver.getContentHandler();
}
/**
* Sets the outputStream of this PDFSerializer object
*
*/
public void setOutputStream() throws TMRuntimeException, TMException, SAXException {
super.setOutputStream();
if ((fileName.lastIndexOf('$')==-1)&&(!printOut)){ // all parameters have been binded
try {
if (!format.equals("")) {
fileName = fileName.substring(0, fileName.lastIndexOf('.') + 1) + format;
}
FileOutputStream FOS = null;
FOS = new FileOutputStream(new File(fileName));
driver.setOutputStream(FOS);
generatePort();
} catch (Exception e) {
throw new TMRuntimeException(e, "[PDFSerializer] cannot serialize in " + fileName);
}//end try
}
else {
driver.setOutputStream(System.out);
}
}
/**Generates ports for this component */
public void generatePort() {
super.generatePort((ContentHandler) getContentHandler());
/**
* Sets the outputStream of this PDFSerializer object
*
*@exception TMRuntimeException Description of the Exception
*@exception TMException Description of the Exception
*@exception SAXException Description of the Exception
*/
public void setOutputStream() throws TMRuntimeException, TMException, SAXException {
super.setOutputStream();
driver.setOutputStream(getOutputStream());
}
}
/**
* $Id: RTFSerializer.java,v 1.6 2002-11-06 14:08:21 serge Exp $
* $Id: RTFSerializer.java,v 1.7 2002-11-07 14:31:11 triolet Exp $
*
* Transmorpher
*
......@@ -31,19 +31,19 @@ import fr.fluxmedia.transmorpher.utils.Parameters;
import fr.fluxmedia.transmorpher.utils.StringParameters;
import fr.fluxmedia.transmorpher.utils.TMException;
import fr.fluxmedia.transmorpher.utils.TMRuntimeException;
import java.io.BufferedOutputStream;
import java.io.BufferedWriter;
// Imported java.io classes
import java.io.File;
import java.io.FileOutputStream;
import java.io.BufferedOutputStream;
import java.io.FilterOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.Writer;
import java.io.BufferedWriter;
import java.io.FilterOutputStream;
import java.io.UnsupportedEncodingException;
import java.io.Writer;
import java.util.Properties;
// Imported jfor classes
......@@ -54,16 +54,17 @@ import org.jfor.jfor.converter.Converter;
import org.xml.sax.ContentHandler;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;
/**
* This class allows transmorpher to produce pdf or ps.
* To use this serializer, transmorpher has to know it.
* To do this, just add the following declaration of defextern in the process file :
* To do this, just add the following declaration of defextern in the process file :
* <code><p>&lt defextern name="rtf" class="fr.fluxmedia.transmorpher.tmcontrib.serializer.RTFSerializer/&gt</p></code>
* <p>A rtf serializer can now be declared in the process file :
* <code><p>&lt serialize id="outputRTF" type="rtf" in="out1" &gt</p>
* <p>&lt with-param name="file"&gt ../samples/fo-sample/output/${filename}.rtf &lt /with-param &gt</p>
*<p>&lt with-param name="format"&gt pdf &lt /with-param &gt</p>
*<p>&lt with-param name="format"&gt pdf &lt /with-param &gt</p>
*<p>&lt /serialize &gt</p></code></p>
*<p>Available format is :
* <ul>
......@@ -77,14 +78,15 @@ import org.xml.sax.SAXException;
*@author triolet
*/
public final class RTFSerializer extends TSerializer {
/** the writer*/
/**
* the writer
*/
private Writer rtfWriter = null;
/** a handler to convert fo to rtf*/
/**
* a handler to convert fo to rtf
*/
private Converter handler = null;
/** format of the file */
String format;
/**
* Constructor for the RTFSerializer object
*
......@@ -95,13 +97,9 @@ public final class RTFSerializer extends TSerializer {
*@exception IOException Description of the Exception
*/
public RTFSerializer(String[] pIn, Parameters pParam, StringParameters pStaticAttributes)
throws SAXException, IOException {
throws SAXException, IOException {
super(pIn, pParam, pStaticAttributes);
if (pParam.getParameter("format") != null) {
format = (String) pParam.getParameter("format");
} else {
format = "rtf";
}
format = "rtf";
}
/**
......@@ -110,60 +108,83 @@ public final class RTFSerializer extends TSerializer {
*@return The contentHandler value
*/
public ContentHandler getContentHandler() {
return handler;
return (ContentHandler)handler;
}
/**
* Sets the outputStream attribute of the RTFSerializer object
*/
public void setOutputStream() throws TMRuntimeException, TMException, SAXException {
super.setOutputStream();
if (fileName.lastIndexOf('$') == -1) { //all parameters have been bound
if (!format.equals("")) {
fileName = fileName.substring(0, fileName.lastIndexOf('.') + 1) + format;
}
try {
FileOutputStream FOS = null;
FOS = new FileOutputStream(new File(fileName));
rtfWriter = new BufferedWriter(new OutputStreamWriter(FOS));
handler = new Converter(rtfWriter, Converter.createConverterOption(new DebugOutputStream(System.err,debug)));
//generatePort();
} catch (Exception e) {
throw new TMRuntimeException(e, "[RTFSerializer] cannot serialize in " + fileName);
}//end try
/**
* Sets the outputStream attribute of the RTFSerializer object
*
*@exception TMRuntimeException Description of the Exception
*@exception TMException Description of the Exception
*@exception SAXException Description of the Exception
*/
public void setOutputStream() throws TMRuntimeException, TMException, SAXException {
super.setOutputStream();
try {
rtfWriter = new BufferedWriter(new OutputStreamWriter(getOutputStream()));
handler = new Converter(rtfWriter, Converter.createConverterOption(new DebugOutputStream(System.err, debug)));
} catch (Exception e) {
throw new TMRuntimeException(e, "[RTFSerializer] cannot serialize in " + fileName);
}
}
}
/**Generates ports for this component */
public void generatePort() {
super.generatePort((ContentHandler) handler);
}
/**
* An utility class to control the outputs of the jFor converter.
* Outputs are only visible when debug > 1
*/
class DebugOutputStream extends FilterOutputStream{
* An utility class to control the outputs of the jFor converter.
* Outputs are only visible when debug > 1
*
*@author triolet
*/
class DebugOutputStream extends FilterOutputStream {
// TO DO:debug has the same value as the command line argument debug
int debug;
public DebugOutputStream(OutputStream out,int d){
/**
*Constructor for the DebugOutputStream object
*
*@param out Description of the Parameter
*@param d Description of the Parameter
*/
public DebugOutputStream(OutputStream out, int d) {
super(out);
debug=d;
debug = d;
}
/**
* Description of the Method
*
*@param b Description of the Parameter
*@exception IOException Description of the Exception
*/
public void write(byte[] b) throws IOException {
if (debug>1)
if (debug > 1) {
super.write(b);
}
}
public void write(byte[] b, int off, int len)throws IOException{
if (debug>1)
super.write(b,off,len);
/**
* Description of the Method
*
*@param b Description of the Parameter
*@param off Description of the Parameter
*@param len Description of the Parameter
*@exception IOException Description of the Exception
*/
public void write(byte[] b, int off, int len) throws IOException {
if (debug > 1) {
super.write(b, off, len);
}
}
public void write(int b) throws IOException{
if (debug>1)
/**
* Description of the Method
*
*@param b Description of the Parameter
*@exception IOException Description of the Exception
*/
public void write(int b) throws IOException {
if (debug > 1) {
super.write(b);
}
}
}
}
......
/**
* $Id: writevcs.java,v 1.6 2002-11-06 14:08:21 serge Exp $
* $Id: writevcs.java,v 1.7 2002-11-07 14:31:11 triolet Exp $
*
* Transmorpher
*
......@@ -51,19 +51,19 @@ import javax.mail.internet.MimeUtility;
import org.xml.sax.Attributes;
import org.xml.sax.ContentHandler;
import org.xml.sax.helpers.DefaultHandler;
import org.xml.sax.Locator;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;
/**
* This class allows transmorpher to produce vcard of vcal files
* To use this serializer, transmorpher has to know it.
* To do this, just add the following declaration of defextern in the process file :
* To do this, just add the following declaration of defextern in the process file :
* <code><p>&lt defextern name="vcs" class="fr.fluxmedia.transmorpher.tmcontrib.serializer.writevcs/&gt</p></code>
* <p>A vcs serializer can now be declared in the process file :
* <code><p>&lt serialize id="outputVCS" type="vcs" in="out1" &gt</p>
* <p>&lt with-param name="file"&gt ../samples/output/${filename}.vcs &lt /with-param &gt</p>
*<p>&lt with-param name="type"&gt vcard &lt /with-param &gt</p>
*<p>&lt with-param name="type"&gt vcard &lt /with-param &gt</p>
*<p>&lt /serialize &gt</p></code></p>
*<p>Available types are :
* <ul>
......@@ -79,28 +79,29 @@ import org.xml.sax.SAXException;
*/
public final class writevcs extends TSerializer {
/** a handler to write vcard or vcal*/
vcsHandler vcs = null;
/**
* a handler to write vcard or vcal
*/
protected vcsHandler vcs = null;
/** True if the file is a vCard */
boolean card = true;
/**
* True if the file is a vCard
*/
protected boolean card = true;
/**
*Constructor for the writevcs object
*
*@param pIn Description of the Parameter
*@param pParam Description of the Parameter
*@param pStaticAttributes Description of the Parameter
*@exception SAXException Description of the Exception
*@exception IOException Description of the Exception
*@param pIn in ports
*@param pParam the parameters of this component
*@param pStaticAttributes static attributes of this component
*/
public writevcs(String[] pIn, Parameters pParam, StringParameters pStaticAttributes) throws SAXException, IOException {
public writevcs(String[] pIn, Parameters pParam, StringParameters pStaticAttributes) {
super(pIn, pParam, pStaticAttributes);
param = pParam;
if (pParam.getParameter("type") != null) {
String pCard = (String) pParam.getParameter("type");
String pCard = (String)pParam.getParameter("type");
if (pCard.equals("vcard")) {
card = true;
} else {
......@@ -110,29 +111,27 @@ public final class writevcs extends TSerializer {
vcs = new vcsHandler(card);
}
/**
* Sets the ouput of this serializer
*/
public void setOutputStream() throws TMRuntimeException, TMException, SAXException {
super.setOutputStream();
if (fileName.lastIndexOf('$') == -1) {
try {
FileOutputStream FOS = null;
FOS = new FileOutputStream(new File(fileName));
vcs.setOutputStream(FOS);
} catch (Exception e) {
throw new TMRuntimeException(e, "[VCSWriter] cannot serialize in " + fileName);
}//end try
/**
* Sets the ouput of this serializer
*
*@exception TMRuntimeException Description of the Exception
*@exception TMException Description of the Exception
*@exception SAXException Description of the Exception
*/
public void setOutputStream() throws TMRuntimeException, TMException, SAXException {
super.setOutputStream();
vcs.setOutputStream(getOutputStream());
}
}
/** Description of the Method */
public void generatePort() {
super.generatePort((ContentHandler) vcs);
}
}//end class
/**
* Gets the contentHandler attribute of the writevcs object
*
*@return The contentHandler value
*/
public ContentHandler getContentHandler() {
return (ContentHandler)vcs;
}
}
/**
* Description of the Class
......@@ -141,25 +140,39 @@ public final class writevcs extends TSerializer {
*/
final class vcsHandler extends DefaultHandler {
/** The OutputStream used by this serializer. */
/**
* The OutputStream used by this serializer.
*/
protected PrintStream output;
/** All the elements which require a Begin/End */
/**
* All the elements which require a Begin/End
*/
protected Vector vcsVector = new Vector();
/** All the elements which require a Begin/End */
/**
* All the elements which require a Begin/End
*/
protected Vector composedVector = new Vector();
/** True if we must */
/**
* True if we must
*/
private boolean composed = false;
/** The value of the composed value */
/**
* The value of the composed value
*/
private String composedValue = "";
/** True if we must */
/**
* True if we must
*/
private boolean encode = false;
/** The value of the encoding parameter */
/**
* The value of the encoding parameter
*/
private String encoding = "";
/**
......
/**
* $Id: TLoop.java,v 1.1 2002-11-06 14:08:21 serge Exp $
* $Id: TLoop.java,v 1.2 2002-11-07 14:31:11 triolet Exp $
*
* Transmorpher
*
......@@ -369,7 +369,7 @@ public final class TLoop extends TProcessComposite {
if (!(iterator.hasMoreElements())) {
stop = true;
} else {
if (!(iterator.getType().equals("fixpointIterator"))){
if (!(iterator.getType().equals("fixpoint"))){
if (iterator.getType().equals("file")){
fileName=(String)iterator.nextElement();
}
......@@ -408,9 +408,9 @@ public final class TLoop extends TProcessComposite {
// System.out.println("SERIALIZER :"+n);
if (iterator.getType().equals("file"))
((TSerializer)listOfSerializer.get(j)).setParameter(iterator.getName(),n.substring(fileName.lastIndexOf('/')+1));
else if (!(iterator.getType().equals("fixpoint")))
else if (!(iterator.getType().equals("fixpoint"))){
((TSerializer)listOfSerializer.get(j)).setParameter(iterator.getName(),number);
}
}
((TSerializer)listOfSerializer.get(j)).setOutputStream();
......
/**
* $Id: TProcessComposite.java,v 1.2 2002-11-07 08:13:26 triolet Exp $
* $Id: TProcessComposite.java,v 1.3 2002-11-07 14:31:11 triolet Exp $
*
* Transmorpher
*
......@@ -220,7 +220,7 @@ public abstract class TProcessComposite extends TProcess_Impl {
for (Enumeration e = listOfProcessBasic.elements() ; e.hasMoreElements() ;) {
Object o = e.nextElement();
if (!(o instanceof TLoop)){
TProcessBasic process = (TProcessBasic)e.nextElement();
TProcessBasic process = (TProcessBasic)o;
process.setThread(useThread);
if (!(process instanceof TReader))
process.execProcess();
......
/**
* $Id: TSerializer.java,v 1.1 2002-11-06 14:08:21 serge Exp $
* $Id: TSerializer.java,v 1.2 2002-11-07 14:31:11 triolet Exp $
*
* Transmorpher
*
......@@ -21,114 +21,231 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
/**
* This class offer a serializer mechanisme. A way to finish the transphormation process
* bye writing XML output file
*
* @author laurent tardif@inrialpes.fr
* @date 10 02 2001
* @since jdk 1.3 && SAX 2.0
*/
package fr.fluxmedia.transmorpher.engine ;
package fr.fluxmedia.transmorpher.engine;
import fr.fluxmedia.transmorpher.utils.Parameters;
import fr.fluxmedia.transmorpher.utils.StringParameters;
import fr.fluxmedia.transmorpher.utils.TMException;
import fr.fluxmedia.transmorpher.utils.TMRuntimeException;
import java.io.File;