Commit 48741163 authored by Jérôme Euzenat's avatar Jérôme Euzenat
Browse files

Implementing partially TMException

parent 02fa2fac
/**
* $Id: tidy.java,v 1.5 2002-10-28 09:24:22 triolet Exp $
* $Id: tidy.java,v 1.6 2002-11-04 08:56:59 jerome Exp $
*
* Transmorpher
*
......@@ -21,14 +21,20 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
package fr.fluxmedia.tmcontrib.generator;
// Imported Transmorpher classes
import fr.fluxmedia.transmorpher.TProcessFactory.*;
import fr.fluxmedia.transmorpher.Files.ReadWrite;
import fr.fluxmedia.transmorpher.TProcessFactory.TReader;
import fr.fluxmedia.transmorpher.TProcessFactory.TProcessFactory;
import fr.fluxmedia.transmorpher.Utils.Parameters;
import fr.fluxmedia.transmorpher.Utils.StringParameters;
import fr.fluxmedia.transmorpher.Utils.SystemResources;
import fr.fluxmedia.transmorpher.Utils.TMRuntimeException;
// Imported Java classes
import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;
......@@ -39,16 +45,25 @@ import java.net.URL;
import java.net.URLConnection;
import java.util.Hashtable;
import javax.xml.parsers.SAXParserFactory;
// Imported JAXP classes
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerConfigurationException;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.sax.SAXResult;
// Imported DOM classes
import org.w3c.dom.Node;
// Imported Tidy class
import org.w3c.tidy.Tidy;
// Imported SAX classes
import org.xml.sax.Attributes;
import org.xml.sax.ContentHandler;
import org.xml.sax.InputSource;
......@@ -66,75 +81,74 @@ import org.xml.sax.helpers.XMLReaderFactory;
*/
public final class tidy extends TReader {
/**
*Constructor for the tidy object
*
*@param pOut 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
*/
public tidy(String[] pOut, Parameters pParam, StringParameters pStaticAttributes) throws SAXException, IOException {
super(pOut, pParam, pStaticAttributes);
try {
SAXParserFactory parserFactory = SAXParserFactory.newInstance();
parserFactory.setFeature(NAMESPACES_FEATURE_ID, DEFAULT_NAMESPACES);
parserFactory.setFeature(NAMESPACES_PREFIXES_FEATURE_ID, DEFAULT_NAMESPACES_PREFIXES);
parserFactory.setFeature(VALIDATION_FEATURE_ID, DEFAULT_VALIDATION);
parserFactory.setFeature(SCHEMA_VALIDATION_FEATURE_ID, DEFAULT_SCHEMA_VALIDATION);
iReader = (parserFactory.newSAXParser()).getXMLReader();
//System.out.println(iReader);
} catch (Exception e) {
System.out.println("[tidy]Exception :" + e);
System.out.println("[tidy] " + SystemResources.getProperty("XML_READER"));
}//end try
}
/**
*Constructor for the tidy object
*
*@param pOut 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
*/
public tidy(String[] pOut, Parameters pParam, StringParameters pStaticAttributes) throws SAXException, IOException {
super(pOut, pParam, pStaticAttributes);
try {
SAXParserFactory parserFactory = SAXParserFactory.newInstance();
parserFactory.setFeature(NAMESPACES_FEATURE_ID, DEFAULT_NAMESPACES);
parserFactory.setFeature(NAMESPACES_PREFIXES_FEATURE_ID, DEFAULT_NAMESPACES_PREFIXES);
parserFactory.setFeature(VALIDATION_FEATURE_ID, DEFAULT_VALIDATION);
parserFactory.setFeature(SCHEMA_VALIDATION_FEATURE_ID, DEFAULT_SCHEMA_VALIDATION);
iReader = (parserFactory.newSAXParser()).getXMLReader();
//System.out.println(iReader);
} catch (Exception e) {
System.out.println("[tidy]Exception :" + e);
System.out.println("[tidy] " + SystemResources.getProperty("XML_READER"));
}//end try
}
/**
* Description of the Method
*
*@exception IOException Description of the Exception
*@exception SAXException Description of the Exception
*/
public void read() throws IOException, SAXException {
Tidy cleaner = new Tidy();
cleaner.setErrout(new PrintWriter(System.err));
InputStream inStream;
if (iFilename != null) {
if (iFilename.startsWith("http://")) {
URL url = new URL(iFilename);
URLConnection urlConnect = url.openConnection();
inStream = urlConnect.getInputStream();
} else {
File file = new File(iFilename);
inStream = new FileInputStream(file);
}
Node document = cleaner.parseDOM(inStream, null);
Transformer transformer = null;
try {
transformer = TProcessFactory.getSAXTFactory().newTransformer();
}
catch (Exception e) {}
DOMSource source = new DOMSource(document);
source.setSystemId(iFilename);
ContentHandler handler = iReader.getContentHandler();
SAXResult result = new SAXResult(handler);
try {
transformer.transform(source, result);
}
catch (TransformerException e) {}
} else {
iReader.parse(standardInput);
}//end if
}
/**
* Description of the Method
*
*@exception IOException I/O error in either
*@exception SAXException Parsing error
*@exception TMRuntimeException Tidy processing error
*/
public void read() throws IOException, SAXException, TMRuntimeException {
Tidy cleaner = new Tidy();
cleaner.setErrout(new PrintWriter(System.err));
InputStream inStream;
if ( iFilename != null) {
if (iFilename.startsWith("http://")) {
URL url = new URL(iFilename);
URLConnection urlConnect = url.openConnection();
inStream = urlConnect.getInputStream();
} else {
File file = new File(iFilename);
inStream = new FileInputStream(file);
}
Node document = cleaner.parseDOM(inStream, null);
Transformer transformer = null;
try {
transformer =TProcessFactory.getSAXTFactory().newTransformer();
} catch (TransformerConfigurationException e) {
throw new TMRuntimeException( e, "Cannot create SAX transformer" );
}
DOMSource source = new DOMSource(document);
source.setSystemId(iFilename);
ContentHandler handler = iReader.getContentHandler();
SAXResult result = new SAXResult(handler);
try { transformer.transform(source, result); }
catch (TransformerException e) {
throw new TMRuntimeException( e, "Cannot process Tidy on "+iFilename );
}
} else {
// JE: it seems that here nothing is done!
iReader.parse(standardInput);
}//end if
}
}
/*
/**
* $Id: PDFSerializer.java,v 1.10 2002-11-04 08:56:59 jerome Exp $
*
* Transmorpher
*
* Copyright (C) 2001-2002 Fluxmedia and INRIA Rhne-Alpes.
......@@ -21,18 +23,25 @@
*/
package fr.fluxmedia.tmcontrib.serializer;
// Imported fr.fluxmedia.transmorpher
import fr.fluxmedia.transmorpher.Files.ReadWrite;
import fr.fluxmedia.transmorpher.TProcessFactory.*;
import fr.fluxmedia.transmorpher.TProcessFactory.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;
// 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;
......@@ -40,7 +49,9 @@ import org.apache.log.format.PatternFormatter;
import org.apache.log.Priority;
import org.apache.log.LogTarget;
import org.apache.log.output.io.StreamTarget;
// Imported SAX classes
import org.xml.sax.ContentHandler;
import org.xml.sax.SAXException;
......@@ -121,33 +132,27 @@ public final class PDFSerializer extends TSerializer {
return driver.getContentHandler();
}
/**
* Sets the outputStream of this PDFSerializer object
*
*/
public void setOutputStream() {
super.setOutputStream();
if (fileName.lastIndexOf('$')==-1){ // 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 (IOException IOE) {
System.err.println("[PDFSerializer]error : " + IOE);
System.err.println("[PDFSerializer]error : f=" + fileName);
IOE.printStackTrace();
} //end try
catch (Exception e) {
System.err.println("[PDFSerializer]erreur : " + e);
e.printStackTrace();
}//end try
/**
* Sets the outputStream of this PDFSerializer object
*
*/
public void setOutputStream() throws TMRuntimeException, TMException, SAXException {
super.setOutputStream();
if (fileName.lastIndexOf('$')==-1){ // 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
}
}
/**Generates ports for this component */
public void generatePort() {
super.generatePort((ContentHandler) getContentHandler());
......
/*
/**
* $Id: RTFSerializer.java,v 1.5 2002-11-04 08:56:59 jerome Exp $
*
* Transmorpher
*
* Copyright (C) 2001-2002 Fluxmedia and INRIA Rhne-Alpes.
......@@ -21,13 +23,17 @@
*/
package fr.fluxmedia.tmcontrib.serializer;
// Imported fr.fluxmedia.transmorpher
import fr.fluxmedia.transmorpher.Files.ReadWrite;
import fr.fluxmedia.transmorpher.TProcessFactory.*;
import fr.fluxmedia.transmorpher.TProcessFactory.TSerializer;
import fr.fluxmedia.transmorpher.Utils.Parameters;
import fr.fluxmedia.transmorpher.Utils.StringParameters;
import java.io.BufferedWriter;
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.BufferedOutputStream;
......@@ -35,12 +41,17 @@ 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.util.Properties;
// Imported jfor classes
import org.jfor.jfor.converter.Converter;
// Imported SAX classes
import org.xml.sax.ContentHandler;
import org.xml.sax.SAXException;
......@@ -102,32 +113,26 @@ public final class RTFSerializer extends TSerializer {
return handler;
}
/**
* Sets the outputStream attribute of the RTFSerializer object
*/
public void setOutputStream() {
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 (IOException IOE) {
System.err.println("[RTFSerializer]error : " + IOE);
System.err.println("[RTFSerializer]error : f=" + fileName);
IOE.printStackTrace();
} //end try
catch (Exception e) {
System.err.println("[RTFSerializer]error : " + e);
e.printStackTrace();
}//end try
}
/**
* 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
}
}
/**Generates ports for this component */
public void generatePort() {
......
/*
/**
* $Id: writevcs.java,v 1.5 2002-11-04 08:56:59 jerome Exp $
*
* Transmorpher
*
* Copyright (C) 2001-2002 Fluxmedia and INRIA Rhne-Alpes.
......@@ -21,11 +23,17 @@
*/
package fr.fluxmedia.tmcontrib.serializer;
// Imported Transmorpher Classes
import fr.fluxmedia.transmorpher.TProcessFactory.TSerializer;
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 Classes
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileOutputStream;
......@@ -33,10 +41,14 @@ import java.io.IOException;
import java.io.OutputStream;
import java.io.PrintStream;
import java.util.Vector;
//Imported javax.mail Classes
import javax.mail.MessagingException;
import javax.mail.internet.MimeUtility;
// Imported SAX Classes
import org.xml.sax.Attributes;
import org.xml.sax.ContentHandler;
import org.xml.sax.helpers.DefaultHandler;
......@@ -44,16 +56,16 @@ import org.xml.sax.Locator;
import org.xml.sax.SAXException;
/**
* This class allows transmorpher to produce pdf or ps.
* 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 :
* <code><p>&lt defextern name="vcs" class="fr.fluxmedia.transmorpher.tmcontrib.serializer.writevcs/&gt</p></code>
* <p>A rtf serializer can now be declared in the process file :
* <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 /serialize &gt</p></code></p>
*<p>Available type is :
*<p>Available types are :
* <ul>
* <li>vcal</li>
* <li>vcard</li></ul></p>
......@@ -98,31 +110,26 @@ public final class writevcs extends TSerializer {
vcs = new vcsHandler(card);
}
/**
* Sets the ouput of this serializer
*/
public void setOutputStream() {
super.setOutputStream();
if (fileName.lastIndexOf('$') == -1) {
try {
FileOutputStream FOS = null;
FOS = new FileOutputStream(new File(fileName));
vcs.setOutputStream(FOS);
} catch (IOException IOE) {
System.err.println("[writevcs]error : " + IOE);
System.err.println("[writevcs]error : f=" + fileName);
IOE.printStackTrace();
} catch (Exception e) {
System.err.println("[writevcs]error : " + e);
e.printStackTrace();
}
}
}
/** Description of the Method */
public void generatePort() {
super.generatePort((ContentHandler) vcs);
/**
* 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
}
}
/** Description of the Method */
public void generatePort() {
super.generatePort((ContentHandler) vcs);
}
}//end class
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment