|
From: <mla...@us...> - 2003-02-14 03:22:32
|
Update of /cvsroot/dbunit/dbunit/src/java/org/dbunit/dataset/xml
In directory sc8-pr-cvs1:/tmp/cvs-serv11211/dbunit/src/java/org/dbunit/dataset/xml
Modified Files:
FlatDtdDataSet.java FlatXmlDataSet.java XmlDataSet.java
Log Message:
1. Allows disabling DTD dataset for FlatXmlDataSet having a DOCTYPE.
2. Provided Reader and Writers for the xml dataset methods, to make possible the use of Unicode and international characters in the datasets. Existing InputStream methods are now deprecated.
Index: FlatDtdDataSet.java
===================================================================
RCS file: /cvsroot/dbunit/dbunit/src/java/org/dbunit/dataset/xml/FlatDtdDataSet.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -d -r1.4 -r1.5
*** FlatDtdDataSet.java 13 Feb 2003 04:32:42 -0000 1.4
--- FlatDtdDataSet.java 14 Feb 2003 03:21:59 -0000 1.5
***************
*** 30,36 ****
private final Map _tableMap = new HashMap();
public FlatDtdDataSet(InputStream in) throws IOException
{
! DTDParser dtdParser = new DTDParser(new InputStreamReader(in));
DTD dtd = dtdParser.parse(true);
--- 30,44 ----
private final Map _tableMap = new HashMap();
+ /**
+ * @deprecated Use Reader overload instead
+ */
public FlatDtdDataSet(InputStream in) throws IOException
{
! this(new InputStreamReader(in));
! }
!
! public FlatDtdDataSet(Reader in) throws IOException
! {
! DTDParser dtdParser = new DTDParser(in);
DTD dtd = dtdParser.parse(true);
***************
*** 59,68 ****
/**
! * Write the specified dataset to the specified output as DTD.
*/
public static void write(IDataSet dataSet, OutputStream out)
throws IOException, DataSetException
{
! PrintStream printOut = new PrintStream(out);
String[] tableNames = dataSet.getTableNames();
--- 67,85 ----
/**
! * Write the specified dataset to the specified output stream as DTD.
*/
public static void write(IDataSet dataSet, OutputStream out)
throws IOException, DataSetException
{
! write(dataSet, new OutputStreamWriter(out));
! }
!
! /**
! * Write the specified dataset to the specified writer as DTD.
! */
! public static void write(IDataSet dataSet, Writer out)
! throws IOException, DataSetException
! {
! PrintWriter printOut = new PrintWriter(out);
String[] tableNames = dataSet.getTableNames();
Index: FlatXmlDataSet.java
===================================================================
RCS file: /cvsroot/dbunit/dbunit/src/java/org/dbunit/dataset/xml/FlatXmlDataSet.java,v
retrieving revision 1.17
retrieving revision 1.18
diff -C2 -d -r1.17 -r1.18
*** FlatXmlDataSet.java 3 Aug 2002 02:26:40 -0000 1.17
--- FlatXmlDataSet.java 14 Feb 2003 03:21:59 -0000 1.18
***************
*** 49,64 ****
* Relative DOCTYPE uri are resolved from the xml file path.
*
! * @param file the xml file
*/
public FlatXmlDataSet(File xmlFile) throws IOException, DataSetException
{
try
{
! Document document = new Document(new FileInputStream(xmlFile));
- // Create metadata from dtd if defined
IDataSet metaDataSet = null;
String dtdUri = getDocTypeUri(document);
! if (dtdUri != null)
{
File dtdFile = new File(dtdUri);
--- 49,78 ----
* Relative DOCTYPE uri are resolved from the xml file path.
*
! * @param xmlFile the xml file
*/
public FlatXmlDataSet(File xmlFile) throws IOException, DataSetException
{
+ this(xmlFile, true);
+ }
+
+ /**
+ * Creates an FlatXmlDataSet object with the specifed xml file.
+ * Relative DOCTYPE uri are resolved from the xml file path.
+ *
+ * @param xmlFile the xml file
+ * @param dtdMetadata if <code>false</code> do not use DTD as metadata
+ */
+ public FlatXmlDataSet(File xmlFile, boolean dtdMetadata)
+ throws IOException, DataSetException
+ {
try
{
! Document document = new Document(new BufferedReader(new FileReader(xmlFile)));
IDataSet metaDataSet = null;
+
+ // Create metadata from dtd if defined
String dtdUri = getDocTypeUri(document);
! if (dtdMetadata && dtdUri != null)
{
File dtdFile = new File(dtdUri);
***************
*** 67,71 ****
dtdFile = new File(xmlFile.getParent(), dtdUri);
}
! metaDataSet = new FlatDtdDataSet(new FileInputStream(dtdFile));
}
--- 81,85 ----
dtdFile = new File(xmlFile.getParent(), dtdUri);
}
! metaDataSet = new FlatDtdDataSet(new FileReader(dtdFile));
}
***************
*** 79,106 ****
/**
! * Creates an FlatXmlDataSet object with the specifed xml input stream.
* Relative DOCTYPE uri are resolved from the current working dicrectory.
*
! * @param stream the xml input stream
*/
! public FlatXmlDataSet(InputStream stream) throws IOException, DataSetException
{
try
{
! Document document = new Document(stream);
// Create metadata from dtd if defined
IDataSet metaDataSet = null;
String dtdUri = getDocTypeUri(document);
! if (dtdUri != null)
{
try
{
URL dtdUrl = new URL(dtdUri);
! metaDataSet = new FlatDtdDataSet(dtdUrl.openStream());
}
catch (MalformedURLException e)
{
! metaDataSet = new FlatDtdDataSet(new FileInputStream(dtdUri));
}
}
--- 93,134 ----
/**
! * Creates an FlatXmlDataSet object with the specifed xml reader.
* Relative DOCTYPE uri are resolved from the current working dicrectory.
*
! * @param xmlReader the xml reader
*/
! public FlatXmlDataSet(Reader xmlReader) throws IOException, DataSetException
! {
! this(xmlReader, true);
! }
!
! /**
! * Creates an FlatXmlDataSet object with the specifed xml reader.
! * Relative DOCTYPE uri are resolved from the current working dicrectory.
! *
! * @param xmlReader the xml reader
! * @param dtdMetadata if <code>false</code> do not use DTD as metadata
! */
! public FlatXmlDataSet(Reader xmlReader, boolean dtdMetadata)
! throws IOException, DataSetException
{
try
{
! Document document = new Document(new BufferedReader(xmlReader));
// Create metadata from dtd if defined
IDataSet metaDataSet = null;
String dtdUri = getDocTypeUri(document);
! if (dtdMetadata && dtdUri != null)
{
try
{
URL dtdUrl = new URL(dtdUri);
! metaDataSet = new FlatDtdDataSet(new InputStreamReader(
! dtdUrl.openStream()));
}
catch (MalformedURLException e)
{
! metaDataSet = new FlatDtdDataSet(new FileReader(dtdUri));
}
}
***************
*** 115,118 ****
--- 143,204 ----
/**
+ * Creates an FlatXmlDataSet object with the specifed xml and dtd readers.
+ *
+ * @param xmlReader the xml reader
+ * @param dtdReader the dtd reader
+ */
+ public FlatXmlDataSet(Reader xmlReader, Reader dtdReader)
+ throws IOException, DataSetException
+ {
+ this(xmlReader, new FlatDtdDataSet(dtdReader));
+ }
+
+ /**
+ * Creates an FlatXmlDataSet object with the specifed xml reader.
+ *
+ * @param xmlReader the xml reader
+ * @param metaDataSet the dataset used as metadata source.
+ */
+ public FlatXmlDataSet(Reader xmlReader, IDataSet metaDataSet)
+ throws IOException, DataSetException
+ {
+ try
+ {
+ _tables = getTables(new Document(new BufferedReader(xmlReader)), metaDataSet);
+ }
+ catch (ParseException e)
+ {
+ throw new DataSetException(e);
+ }
+ }
+
+ /**
+ * Creates an FlatXmlDataSet object with the specifed xml input stream.
+ * Relative DOCTYPE uri are resolved from the current working dicrectory.
+ *
+ * @param xmlStream the xml input stream
+ * @deprecated Use Reader overload instead
+ */
+ public FlatXmlDataSet(InputStream xmlStream) throws IOException, DataSetException
+ {
+ this(xmlStream, true);
+ }
+
+ /**
+ * Creates an FlatXmlDataSet object with the specifed xml input stream.
+ * Relative DOCTYPE uri are resolved from the current working dicrectory.
+ *
+ * @param xmlStream the xml input stream
+ * @param dtdMetadata if <code>false</code> do not use DTD as metadata
+ * @deprecated Use Reader overload instead
+ *
+ */
+ public FlatXmlDataSet(InputStream xmlStream, boolean dtdMetadata)
+ throws IOException, DataSetException
+ {
+ this(new InputStreamReader(xmlStream), dtdMetadata);
+ }
+
+ /**
* Creates an FlatXmlDataSet object with the specifed xml and dtd input
* stream.
***************
*** 120,123 ****
--- 206,210 ----
* @param xmlStream the xml input stream
* @param dtdStream the dtd input stream
+ * @deprecated Use Reader overload instead
*/
public FlatXmlDataSet(InputStream xmlStream, InputStream dtdStream)
***************
*** 132,135 ****
--- 219,223 ----
* @param xmlStream the xml input stream
* @param metaDataSet the dataset used as metadata source.
+ * @deprecated Use Reader overload instead
*/
public FlatXmlDataSet(InputStream xmlStream, IDataSet metaDataSet)
***************
*** 147,153 ****
/**
! * Write the specified dataset to the specified output as xml.
*/
public static void write(IDataSet dataSet, OutputStream out)
throws IOException, DataSetException
{
--- 235,253 ----
/**
! * Write the specified dataset to the specified output stream as xml.
*/
public static void write(IDataSet dataSet, OutputStream out)
+ throws IOException, DataSetException
+ {
+ Document document = buildDocument(dataSet);
+
+ // write xml document
+ document.write(out);
+ }
+
+ /**
+ * Write the specified dataset to the specified writer as xml.
+ */
+ public static void write(IDataSet dataSet, Writer out)
throws IOException, DataSetException
{
Index: XmlDataSet.java
===================================================================
RCS file: /cvsroot/dbunit/dbunit/src/java/org/dbunit/dataset/xml/XmlDataSet.java,v
retrieving revision 1.12
retrieving revision 1.13
diff -C2 -d -r1.12 -r1.13
*** XmlDataSet.java 3 Aug 2002 02:26:40 -0000 1.12
--- XmlDataSet.java 14 Feb 2003 03:21:59 -0000 1.13
***************
*** 45,49 ****
--- 45,67 ----
/**
+ * Creates an XmlDataSet with the specified xml reader.
+ */
+ public XmlDataSet(Reader in) throws DataSetException
+ {
+ try
+ {
+ Document document = new Document(new BufferedReader(in));
+ _tables = getTables(document);
+ }
+ catch (ParseException e)
+ {
+ throw new DataSetException(e);
+ }
+ }
+
+ /**
* Creates an XmlDataSet with the specified xml input stream.
+ *
+ * @deprecated Use Reader overload instead
*/
public XmlDataSet(InputStream in) throws DataSetException
***************
*** 52,66 ****
{
Document document = new Document(in);
! Elements tableElems = document.getElement("dataset").getElements("table");
!
! List tableList = new ArrayList();
! while (tableElems.hasMoreElements())
! {
! Element tableElem = (Element)tableElems.nextElement();
! ITable table = new XmlTable(tableElem);
! tableList.add(table);
! }
!
! _tables = (ITable[])tableList.toArray(new ITable[0]);
}
catch (ParseException e)
--- 70,85 ----
{
Document document = new Document(in);
! _tables = getTables(document);
! // Elements tableElems = document.getElement("dataset").getElements("table");
! //
! // List tableList = new ArrayList();
! // while (tableElems.hasMoreElements())
! // {
! // Element tableElem = (Element)tableElems.nextElement();
! // ITable table = new XmlTable(tableElem);
! // tableList.add(table);
! // }
! //
! // _tables = (ITable[])tableList.toArray(new ITable[0]);
}
catch (ParseException e)
***************
*** 86,92 ****
/**
! * Write the specified dataset to the specified output as xml.
*/
public static void write(IDataSet dataSet, OutputStream out)
throws IOException, DataSetException
{
--- 105,123 ----
/**
! * Write the specified dataset to the specified output stream as xml.
*/
public static void write(IDataSet dataSet, OutputStream out)
+ throws IOException, DataSetException
+ {
+ Document document = buildDocument(dataSet);
+
+ // write xml document
+ document.write(out);
+ }
+
+ /**
+ * Write the specified dataset to the specified writer as xml.
+ */
+ public static void write(IDataSet dataSet, Writer out)
throws IOException, DataSetException
{
|