Commit f3f01b69 authored by Fabien Triolet's avatar Fabien Triolet
Browse files

code reorganization

parent 02cde962
/*
* $Id: ReadCSV.java,v 1.1 2002-10-18 11:58:34 triolet Exp $
* $Id: ReadCSV.java,v 1.2 2002-10-28 09:24:22 triolet Exp $
*
* Transmorpher
*
......@@ -39,19 +39,16 @@ import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import org.xml.sax.XMLReader;
/**
* Description of the Class
* Read a CSV (comma separated value) file which coordinates (local path or URL) are given in the
* file parameter of the generate call, parse it, process it through CSVXMLReader
* and generate a SAX event flow to the next handler
*
*
*@author triolet
*/
public class ReadCSV extends TReader {
/**
* name of the file to parse
*/
String iFilename = null;
/**
*Constructor for the readCSV object
*
......@@ -67,21 +64,6 @@ public class ReadCSV extends TReader {
iReader = new CSVXMLReader(((String)pParam.getParameter("separator")));
}
/**
* Starts to parse the document
*
*@exception IOException if an I/O operation failed
*@exception SAXException an exception that an wrap others exceptions
*/
public void execProcess() throws IOException, SAXException {
iFilename = (String)getParameter("file");
if (isThread) {
myThread.start();
} else {
read();
}//end if
}//end proc
/**
* Creates an input source for the parser with the name of the file and starts
* the parsing
......@@ -90,62 +72,29 @@ public class ReadCSV extends TReader {
*@exception SAXException an exception that an wrap others exceptions
*/
public void read() throws IOException, SAXException {
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);
} else {
File file = new File(iFilename);
inSource = new InputSource(new FileInputStream(file));
inSource.setSystemId(file.toURL().toExternalForm());
}
iReader.parse(inSource);
} else {
//reader.parse(standardInput);
}//end if
}
/**
* Begins the parsing of a file.
* This method is called inside a repeat . At each loop, a new file is parsed.
*
*@param file name of the file to parse
*@exception IOException if an I/O operation failed
*@exception SAXException an exception that an wrap others exceptions
*/
public void execProcess(String file) throws IOException, SAXException {
iFilename = file;
try {
InputSource inSource;
if (iFilename != null) {
read();
//iReader.parse(iFilename);
if (iFilename.startsWith("http://")) {
URL url = new URL(iFilename);
URLConnection urlConnect = url.openConnection();
InputStream inStream = urlConnect.getInputStream();
inSource = new InputSource(inStream);
inSource.setSystemId(iFilename);
} else {
File file = new File(iFilename);
inSource = new InputSource(new FileInputStream(file));
inSource.setSystemId(file.toURL().toExternalForm());
}
iReader.parse(inSource);
} else {
//reader.parse(standardInput);
iReader.parse(standardInput);
}//end if
} catch (SAXException e) {
System.out.println("[readvcs] " + e + " " + file);
e.printStackTrace();
} catch (IOException e) {
System.err.println("File : " + iFilename + " can't be found.");
iReader.getContentHandler().startDocument();
iReader.getContentHandler().endDocument();
}
}
/**
* Starts the parsing of a file using Thread
*/
public final void run() {
if (!isRunning) {
try {
read();
//myThread.interrupt();
} catch (Exception e) {
System.err.println("Fin du parse 2 !erreur dans le thread");
e.printStackTrace();
}//end try
isRunning = true;
}//end if
}//end run
}
......@@ -21,7 +21,6 @@
* 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
......@@ -49,11 +48,9 @@ import org.xml.sax.XMLReader;
*/
public class readvcs extends TReader {
//vcsReader reader = null;
/** name of the file to parse*/
String iFilename = null;
/** Is the file a vCard ? */
/**
* Is the file a vCard ?
*/
boolean card = true;
......@@ -63,13 +60,13 @@ public class readvcs extends TReader {
*@param pOut out port of this generator
*@param pParam parameters of this generator
*@param pStaticAttributes Description of the Parameter
*@exception SAXException Description of the Exception
*@exception IOException Description of the Exception
*@exception SAXException can wrap others exceptions
*@exception IOException if an IO operations failed
*/
public readvcs(String[] pOut, Parameters pParam, StringParameters pStaticAttributes) throws SAXException, IOException {
super(pOut, pParam, pStaticAttributes);
if (pParam.getParameter("type")!=null){
String pCard = (String) pParam.getParameter("type");
if (pParam.getParameter("type") != null) {
String pCard = (String)pParam.getParameter("type");
if (pCard.equals("vcard")) {
card = true;
} else {
......@@ -79,90 +76,38 @@ public class readvcs extends TReader {
iReader = new vcsReader(card);
}
/**
* Starts to parse the document
*
*@exception IOException Description of the Exception
*@exception SAXException Description of the Exception
*/
public void execProcess() throws IOException, SAXException {
iFilename = (String) getParameter("file");
if (isThread) {
myThread.start();
} else {
read();
}//end if
}//end proc
/**
* Creates an input source for the parser with the name of the file and starts
* the parsing
*
*@exception IOException Description of the Exception
*@exception SAXException Description of the Exception
*@exception IOException if an IO operations failed
*@exception SAXException can wrap others exceptions
*/
public void read() throws IOException, SAXException {
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().toExternalForm());
iReader.parse(inSource);
}
} else {
//reader.parse(standardInput);
}//end if
}
/**
* Begins the parsing of a file.
* This method is called inside a repeat . At each loop, a new file is parsed.
*
*@param file name of the file to parse
*@exception IOException Description of the Exception
*@exception SAXException Description of the Exception
*/
public void execProcess(String file) throws IOException, SAXException {
iFilename = file;
try {
InputSource inSource;
if (iFilename != null) {
read();
//iReader.parse(iFilename);
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().toExternalForm());
iReader.parse(inSource);
}
} else {
//reader.parse(standardInput);
}//end if
} catch (SAXException e) {
System.out.println("[readvcs] " + e + " " + file);
e.printStackTrace();
}
}
/* public void generatePort(){
*iListOut[0] = new XML_Port(nameOut[0],this,(XMLReader)iReader,0,XML_Port.OUT);
*} */
/**
* Starts the parsing of a file using Thread
*/
public final void run() {
if (!isRunning) {
try {
read();
//myThread.interrupt();
} catch (Exception e) {
System.err.println("Fin du parse 2 !erreur dans le thread");
e.printStackTrace();
}//end try
isRunning = true;
iReader.parse(standardInput);
}
} catch (IOException e) {
System.err.println("File : " + iFilename + " can't be found.");
iReader.getContentHandler().startDocument();
iReader.getContentHandler().endDocument();
}//end if
}//end run
}
}
/**
* $Id: tidy.java,v 1.4 2002-09-24 05:59:37 triolet Exp $
* $Id: tidy.java,v 1.5 2002-10-28 09:24:22 triolet Exp $
*
* Transmorpher
*
......@@ -67,10 +67,6 @@ import org.xml.sax.helpers.XMLReaderFactory;
public final class tidy extends TReader {
/** The file to read */
String iFilename = null;
/** the standard input to parse by default*/
InputSource standardInput = null;
/**
*Constructor for the tidy object
......@@ -101,21 +97,6 @@ public final class tidy extends TReader {
}
/**
* Exec the process
*
*@exception IOException Description of the Exception
*@exception SAXException Description of the Exception
*/
public void execProcess() throws IOException, SAXException {
iFilename = (String) getParameter("file");
if (isThread) {
myThread.start();
} else {
read();
}//end if
}//end proc
/**
* Description of the Method
......@@ -126,7 +107,6 @@ public final class tidy extends TReader {
public void read() throws IOException, SAXException {
Tidy cleaner = new Tidy();
cleaner.setErrout(new PrintWriter(System.err));
InputSource inSource;
InputStream inStream;
if (iFilename != null) {
if (iFilename.startsWith("http://")) {
......@@ -136,7 +116,6 @@ public final class tidy extends TReader {
} else {
File file = new File(iFilename);
inStream = new FileInputStream(file);
//inSource.setSystemId(file.toURL().toString());
}
Node document = cleaner.parseDOM(inStream, null);
Transformer transformer = null;
......@@ -157,28 +136,5 @@ public final class tidy extends TReader {
}//end if
}
/**
* Description of the Method
*
*@param fileName Description of the Parameter
*@exception IOException Description of the Exception
*@exception SAXException Description of the Exception
*/
public void execProcess(String fileName) throws IOException, SAXException { }
/** Main processing method for the tidy object */
public final void run() {
if (!isRunning) {
try {
read();
isRunning = true;
//myThread.interrupt();
} catch (Exception e) {
System.err.println("Fin du parse 2 !erreur dans le thread" + e);
e.printStackTrace();
isRunning = true;
}//end try
}//fin if
}//end run
}
/**
* $Id: directoryIterator.java,v 1.1 2002-08-27 08:51:46 jerome Exp $
* $Id: directoryIterator.java,v 1.2 2002-10-28 09:26:04 triolet Exp $
*
* Transmorpher
*
......@@ -55,6 +55,10 @@ public final class directoryIterator implements TIterator {
name = n;
}
public String getName(){
return name;
}
/** Static initialization is currently not used */
public void staticInit(Parameters p) {
}
......
......@@ -171,7 +171,6 @@ public final class fileIterator implements TIterator {
*@return The next file name.
*/
public final Object nextElement() {
//System.out.println(files.get(index));
return files.get(index++);
}
}//end class
......
......@@ -52,6 +52,10 @@ public final class fixpointIterator implements TIterator {
init(p);
}
public String getName(){
return name;
}
/**
* Static initialization is currently not used
*
......
/**
* $Id: readfile.java,v 1.9 2002-10-16 08:11:11 triolet Exp $
/*
* $Id: readfile.java,v 1.10 2002-10-28 09:26:04 triolet Exp $
*
* Transmorpher
*
......@@ -21,153 +21,101 @@
* 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 provide a basic process which is
* able to read an XML file
*
* @author Laurent.Tardif@inrialpes.fr
* @since jdk 1.3 && SAX 2.0
*/
package fr.fluxmedia.transmorpher.stdlib ;
// Imported SAX classes
package fr.fluxmedia.transmorpher.stdlib;
// Imported Transmorpher classes
import fr.fluxmedia.transmorpher.Files.ReadWrite;
import fr.fluxmedia.transmorpher.TProcessFactory.*;
import org.xml.sax.SAXException;
import org.xml.sax.XMLReader;
import org.xml.sax.InputSource;
import fr.fluxmedia.transmorpher.Utils.Parameters;
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;
import java.io.InputStream;
import java.io.File;
import java.io.*;
import java.lang.Runnable;
import java.net.*;
import java.util.Hashtable;
import java.lang.Runnable ;
// Imported Transmorpher classes
import fr.fluxmedia.transmorpher.Utils.Parameters ;
import fr.fluxmedia.transmorpher.Utils.StringParameters;
import fr.fluxmedia.transmorpher.Utils.SystemResources;
import fr.fluxmedia.transmorpher.Files.ReadWrite;
// Imported SAX and JAXP classes
import javax.xml.parsers.SAXParserFactory;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import org.xml.sax.XMLReader;
/**
* read a file which coordinates (local path or URL) is give in the
*
* This class provide a basic process which is
* able to read an XML file
* reads a file which coordinates (local path or URL) is give in the
* file parameter of the generate call, parse it and generate a SAX event
* flow to the next handler
*
*@author Laurent.Tardif@inrialpes.fr
*@since jdk 1.3 && SAX 2.0
*/
public final class readfile extends TReader {
/** The file name whish describe the file to read */
String iFilename = null;
InputSource standardInput = null;
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();
//System.out.println(iReader);
} catch(Exception e) {
System.out.println("[readfile]Exception :"+e);
System.out.println("[readfile] "+SystemResources.getProperty("XML_READER"));
} //end try
//if (isThread) myThread = new Thread(this);
}
/** Exec the process :parse a file or an URL content*/
public void execProcess() throws IOException,SAXException {
iFilename = (String)getParameter("file");
if (isThread) {
myThread.start();
} else {
read();
}
} //end proc
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
}
/**
* Begins the parse of a file. This method is called inside a repeat . At each loop, file is changed.
* @Param file The file to parse.
* Description of the Method
*
*@exception IOException if an IO operations failed
*@exception SAXException can wrap others exceptions
*/
public void execProcess(String file) throws IOException,SAXException {
iFilename = file;
try{
if(iFilename != null) {
iReader.parse(iFilename);
} else {
iReader.parse(standardInput);
} //end if
}
catch(SAXException e){
System.out.println("[readfile] "+ e+" "+file);
e.printStackTrace();
public void read() throws IOException, SAXException {
try {