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

Implemented TMException

parent 48741163
/*
* $Id: TestingDispatcher.java,v 1.2 2002-10-17 15:34:58 triolet Exp $
* $Id: TestingDispatcher.java,v 1.3 2002-11-04 08:58:06 jerome Exp $
*
* Transmorpher
*
......@@ -24,12 +24,16 @@
package fr.fluxmedia.transmorpher.stdlib;
// Imported transmorpher classes
import fr.fluxmedia.transmorpher.Files.ReadWrite;
import fr.fluxmedia.transmorpher.TProcessFactory.*;
import fr.fluxmedia.transmorpher.TProcessFactory.TDispatcher;
import fr.fluxmedia.transmorpher.Utils.Parameters;
// Imported java classes
import java.util.Hashtable;
// Imported SAX classes
import org.xml.sax.Attributes;
import org.xml.sax.ContentHandler;
import org.xml.sax.Locator;
......
/**
* $Id: broadcast.java,v 1.4 2002-10-16 08:11:11 triolet Exp $
* $Id: broadcast.java,v 1.5 2002-11-04 08:58:06 jerome Exp $
*
* Transmorpher
*
......@@ -34,9 +34,11 @@
package fr.fluxmedia.transmorpher.stdlib ;
// Imported transmorpher classes
import fr.fluxmedia.transmorpher.TProcessFactory.*;
import fr.fluxmedia.transmorpher.Files.ReadWrite;
import fr.fluxmedia.transmorpher.TProcessFactory.TProcessFactory;
import fr.fluxmedia.transmorpher.TProcessFactory.TDispatcher;
import fr.fluxmedia.transmorpher.Utils.Parameters;
// Imported SAX classes
import org.xml.sax.ContentHandler;
......
/*
* $Id: readfile.java,v 1.10 2002-10-28 09:26:04 triolet Exp $
* $Id: readfile.java,v 1.11 2002-11-04 08:58:06 jerome Exp $
*
* Transmorpher
*
......@@ -23,13 +23,18 @@
*/
package fr.fluxmedia.transmorpher.stdlib;
// Imported Transmorpher classes
import fr.fluxmedia.transmorpher.Files.ReadWrite;
import fr.fluxmedia.transmorpher.TProcessFactory.*;
import fr.fluxmedia.transmorpher.TProcessFactory.TProcessFactory;
import fr.fluxmedia.transmorpher.TProcessFactory.TReader;
import fr.fluxmedia.transmorpher.Utils.Parameters;
import fr.fluxmedia.transmorpher.Utils.TMException;
import fr.fluxmedia.transmorpher.Utils.StringParameters;
import fr.fluxmedia.transmorpher.Utils.SystemResources;
// Imported Java classes
import java.io.*;
import java.io.File;
import java.io.IOException;
......@@ -37,7 +42,9 @@ import java.io.InputStream;
import java.lang.Runnable;
import java.net.*;
import java.util.Hashtable;
// Imported SAX and JAXP classes
import javax.xml.parsers.SAXParserFactory;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
......@@ -57,65 +64,66 @@ import org.xml.sax.XMLReader;
public final class readfile extends TReader {
/**
*Constructor for the readfile 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 readfile(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();
} catch (Exception e) {
System.out.println("[readfile]Exception :" + e);
System.out.println("[readfile] " + SystemResources.getProperty("XML_READER"));
}//end try
}
/**
* Description of the Method
*
*@exception IOException if an IO operations failed
*@exception SAXException can wrap others exceptions
*/
public void read() throws IOException, SAXException {
try {
InputSource inSource;
if (iFilename != null) {
if (iFilename.startsWith("http://")) {
URL url = new URL(iFilename);
URLConnection urlConnect = url.openConnection();
InputStream inStream = urlConnect.getInputStream();
inSource = new InputSource(inStream);
inSource.setSystemId(iFilename);
iReader.parse(inSource);
} else {
File file = new File(iFilename);
inSource = new InputSource(new FileInputStream(file));
inSource.setSystemId(file.toURL().toString());
iReader.parse(inSource);
}
} else {
iReader.parse(standardInput);
}
} catch (IOException e) {
System.err.println("File : " + iFilename + " can't be found.");
iReader.getContentHandler().startDocument();
iReader.getContentHandler().endDocument();
/**
*Constructor for the readfile 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 readfile(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();
} catch (Exception e) {
System.out.println("[readfile]Exception :" + e);
System.out.println("[readfile] " + SystemResources.getProperty("XML_READER"));
}//end try
}
/**
* Description of the Method
*
*@exception IOException if an IO operations failed
*@exception SAXException can wrap others exceptions
*/
public void read() throws IOException, SAXException {
InputSource inSource;
try {
if (iFilename != null) {
if (iFilename.startsWith("http://")) {
URL url = new URL(iFilename);
URLConnection urlConnect = url.openConnection();
InputStream inStream = urlConnect.getInputStream();
inSource = new InputSource(inStream);
inSource.setSystemId(iFilename);
iReader.parse(inSource);
} else {
File file = new File(iFilename);
inSource = new InputSource(new FileInputStream(file));
inSource.setSystemId(file.toURL().toString());
iReader.parse(inSource);
}
} else {
iReader.parse(standardInput);
}
} catch (IOException e) {
// JE: There is a problem here either we report the error,
// either we send the empty document! And if we report it,
// this must be by raising an exception
System.err.println("File : " + iFilename + " can't be found.");
// Send the empty document on error!?
iReader.getContentHandler().startDocument();
iReader.getContentHandler().endDocument();
}
}
}
/**
* $Id: stdout.java,v 1.3 2002-10-28 09:26:04 triolet Exp $
* $Id: stdout.java,v 1.4 2002-11-04 08:58:06 jerome Exp $
*
* Transmorpher
*
......@@ -32,8 +32,7 @@
package fr.fluxmedia.transmorpher.stdlib ;
import fr.fluxmedia.transmorpher.TProcessFactory.*;
import fr.fluxmedia.transmorpher.Files.ReadWrite;
import fr.fluxmedia.transmorpher.TProcessFactory.TSerializer;
import fr.fluxmedia.transmorpher.Utils.Parameters;
import fr.fluxmedia.transmorpher.Utils.StringParameters;
......@@ -42,13 +41,6 @@ import fr.fluxmedia.transmorpher.Utils.StringParameters;
import org.xml.sax.SAXException;
import org.xml.sax.ContentHandler;
// Imported Serializer classes
// JE: why this depends on Xalan?
/* import org.apache.xalan.serialize.Serializer;
import org.apache.xalan.serialize.SerializerFactory;
import org.apache.xalan.templates.OutputProperties; */
// Imported java.io classes
import java.io.FileOutputStream;
import java.io.OutputStream;
......@@ -92,31 +84,20 @@ public final class stdout extends TSerializer {
//generatePort();
}
protected SAXTransformerFactory getTransformerFactory(){
if(tfactory == null){
tfactory = (SAXTransformerFactory) TransformerFactory.newInstance();
}
return tfactory;
protected SAXTransformerFactory getTransformerFactory(){
if (tfactory == null) {
tfactory = (SAXTransformerFactory)TransformerFactory.newInstance();
}
return tfactory;
}
public void setOutputStream() {
try {
handler.getTransformer().setOutputProperties(Op);
handler.setResult(new StreamResult(System.out));
}
catch (Exception e){
System.out.println("[writefile]erreur : " + e);
e.printStackTrace();
}
}
public void generatePort(){
super.generatePort((ContentHandler)handler);
handler.getTransformer().setOutputProperties(Op);
handler.setResult(new StreamResult(System.out));
}
/* try {
super.generatePort((ContentHandler)serializer.asContentHandler());
} catch(IOException IOE) {
System.out.println("[stdout]erreur : " + IOE);
IOE.printStackTrace();
} //end try */
public void generatePort(){
super.generatePort((ContentHandler)handler);
}
} //end class
/**
* $Id: writefile.java,v 1.8 2002-10-16 07:32:17 jerome Exp $
* $Id: writefile.java,v 1.9 2002-11-04 08:58:06 jerome Exp $
*
* Transmorpher
*
......@@ -24,11 +24,14 @@
package fr.fluxmedia.transmorpher.stdlib;
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 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;
......@@ -36,17 +39,19 @@ import java.io.OutputStream;
import java.io.BufferedOutputStream;
import java.io.StringWriter;
import java.util.Properties;
// Imported SAX classes
import org.xml.sax.SAXException;
import org.xml.sax.ContentHandler;
// Imported JAXP classes
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.sax.SAXTransformerFactory;
import javax.xml.transform.sax.TransformerHandler;
import javax.xml.transform.stream.StreamResult;
/**
* This class offer a serializer mechanisme. A way to finish the transphormation process
* by writing XML output file
......@@ -57,83 +62,75 @@ import javax.xml.transform.stream.StreamResult;
*/
public final class writefile extends TSerializer {
TransformerHandler handler;
static final int DEFAULT_BUFFER_SIZE = 8192;
int outputBufferSize = DEFAULT_BUFFER_SIZE;
SAXTransformerFactory tfactory = null;
/**
*Constructor for the writefile object
*
*@param pIn in ports of this object
*@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 writefile(String[] pIn, Parameters pParam, StringParameters pStaticAttributes)
throws SAXException, IOException {
super(pIn, pParam, pStaticAttributes);
//param = pParam;
try{
handler = getTransformerFactory().newTransformerHandler();
}
catch (Exception e){
e.printStackTrace();
}
TransformerHandler handler;
static final int DEFAULT_BUFFER_SIZE = 8192;
int outputBufferSize = DEFAULT_BUFFER_SIZE;
SAXTransformerFactory tfactory = null;
/**
*Constructor for the writefile object
*
*@param pIn in ports of this object
*@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 writefile(String[] pIn, Parameters pParam, StringParameters pStaticAttributes)
throws TMRuntimeException {
super(pIn, pParam, pStaticAttributes);
//param = pParam;
try{
handler = getTransformerFactory().newTransformerHandler();
}
protected SAXTransformerFactory getTransformerFactory(){
if(tfactory == null){
tfactory = (SAXTransformerFactory) TransformerFactory.newInstance();
}
return tfactory;
catch (Exception e){
throw new TMRuntimeException( e, "Cannot write");
}
/**
* Sets the ouput file of this serializer
* path is needed when this serializer is used inside a loop.
*
*@param name The file name to write in
*/
public void setOutputStream() {
super.setOutputStream();
if (fileName.lastIndexOf('$')==-1){
try {
FileOutputStream FOS = null;
FOS = new FileOutputStream(new File(fileName));
BufferedOutputStream streamBuffer=null;
streamBuffer = new BufferedOutputStream(FOS,outputBufferSize);
handler.getTransformer().setOutputProperties(Op);
handler.setResult(new StreamResult(streamBuffer));
} catch (IOException IOE) {
System.out.println("[writefile]erreur : " + IOE);
System.out.println("[writefile]erreur : f=" + fileName);
IOE.printStackTrace();
}//end try
catch (Exception e){
System.out.println("[writefile]erreur : " + e);
e.printStackTrace();
}
}
}
protected SAXTransformerFactory getTransformerFactory(){
if(tfactory == null){
tfactory = (SAXTransformerFactory) TransformerFactory.newInstance();
}
public void reset(){
try{
handler=null;
handler = getTransformerFactory().newTransformerHandler();
}
catch (Exception e){
e.printStackTrace();
}
return tfactory;
}
/**
* Sets the ouput file of this serializer
* path is needed when this serializer is used inside a loop.
*
*@param name The file name to write in
*/
public void setOutputStream() throws TMRuntimeException, TMException, SAXException {
super.setOutputStream();
if (fileName.lastIndexOf('$')==-1){
try {
FileOutputStream FOS = null;
FOS = new FileOutputStream(new File(fileName));
BufferedOutputStream streamBuffer=null;
streamBuffer = new BufferedOutputStream(FOS,outputBufferSize);
handler.getTransformer().setOutputProperties(Op);
handler.setResult(new StreamResult(streamBuffer));
} catch (Exception e) {
throw new TMRuntimeException( e, "Output stream error");
}
}
/** Generates ports for this component */
public void generatePort() {
super.generatePort((ContentHandler) handler);
}
public void reset() throws TMRuntimeException {
try {
handler = getTransformerFactory().newTransformerHandler();
} catch (Exception e) {
throw new TMRuntimeException( e, "Reset writefile error");
}
}
/** Generates ports for this component */
public void generatePort() {
super.generatePort((ContentHandler) handler);
}
}
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