From: <lpe...@sv...> - 2005-06-23 16:52:44
|
Author: lpercich Date: 2005-06-23 09:52:25 -0700 (Thu, 23 Jun 2005) New Revision: 14596 Modified: geotools/trunk/gt/plugin/mif/src/org/geotools/data/mif/MIFDataStore.ja= va geotools/trunk/gt/plugin/mif/src/org/geotools/data/mif/MIFDataStoreFac= tory.java geotools/trunk/gt/plugin/mif/test/org/geotools/data/mif/MIFDataStoreFa= ctoryTest.java geotools/trunk/gt/plugin/mif/test/org/geotools/data/mif/MIFDataStoreTe= st.java geotools/trunk/gt/plugin/mif/test/org/geotools/data/mif/MIFFileTest.ja= va geotools/trunk/gt/plugin/mif/test/org/geotools/data/mif/MIFFileTokeniz= erTest.java geotools/trunk/gt/plugin/mif/test/org/geotools/data/mif/MIFTestUtils.j= ava Log: MIF: fixed (?) problems with unix path names Modified: geotools/trunk/gt/plugin/mif/src/org/geotools/data/mif/MIFDataS= tore.java =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- geotools/trunk/gt/plugin/mif/src/org/geotools/data/mif/MIFDataStore.j= ava 2005-06-23 16:04:58 UTC (rev 14595) +++ geotools/trunk/gt/plugin/mif/src/org/geotools/data/mif/MIFDataStore.j= ava 2005-06-23 16:52:25 UTC (rev 14596) @@ -39,7 +39,7 @@ * </p> * * @author Luca S. Percich, AMA-MI - * @version $Id: MIFDataStore.java,v 1.9 2005/06/22 16:53:49 lpercich Ex= p $ + * @version $Id: MIFDataStore.java,v 1.10 2005/06/23 16:59:27 lpercich E= xp $ */ public class MIFDataStore extends AbstractDataStore { // MIF Header clause names @@ -157,8 +157,10 @@ } =20 try { - MIFFile mf =3D new MIFFile(this.filePath.getAbsolutePath() += "\\" - + featureType.getTypeName() + ".mif", featureType, p= arams); + File newFile =3D new File(filePath, featureType.getTypeName(= ) + + ".mif"); + MIFFile mf =3D new MIFFile(newFile.getAbsolutePath(), featur= eType, + params); MIFFileHolder mfh =3D new MIFFileHolder(mf); mifFileHolders.put(mf.getSchema().getTypeName(), mfh); } catch (Exception e) { Modified: geotools/trunk/gt/plugin/mif/src/org/geotools/data/mif/MIFDataS= toreFactory.java =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- geotools/trunk/gt/plugin/mif/src/org/geotools/data/mif/MIFDataStoreFa= ctory.java 2005-06-23 16:04:58 UTC (rev 14595) +++ geotools/trunk/gt/plugin/mif/src/org/geotools/data/mif/MIFDataStoreFa= ctory.java 2005-06-23 16:52:25 UTC (rev 14596) @@ -45,7 +45,7 @@ * </p> * * @author Luca S. Percich, AMA-MI - * @version $Id: MIFDataStoreFactory.java,v 1.8 2005/06/22 16:53:49 lper= cich Exp $ + * @version $Id: MIFDataStoreFactory.java,v 1.9 2005/06/23 16:59:27 lper= cich Exp $ * * @see MIFDataStore#MIFDataStore(String, HashMap); */ Modified: geotools/trunk/gt/plugin/mif/test/org/geotools/data/mif/MIFData= StoreFactoryTest.java =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- geotools/trunk/gt/plugin/mif/test/org/geotools/data/mif/MIFDataStoreF= actoryTest.java 2005-06-23 16:04:58 UTC (rev 14595) +++ geotools/trunk/gt/plugin/mif/test/org/geotools/data/mif/MIFDataStoreF= actoryTest.java 2005-06-23 16:52:25 UTC (rev 14596) @@ -72,7 +72,7 @@ =20 try { ds =3D DataStoreFinder.getDataStore(MIFTestUtils.getParams("= mif", - MIFTestUtils.getDataPath(), uri)); + MIFTestUtils.fileName(""), uri)); } catch (IOException e) { fail(e.getMessage()); } @@ -91,7 +91,7 @@ String strURI =3D "root-mifdatastore"; uri =3D new URI(strURI); ds =3D dsFactory.createDataStore(MIFTestUtils.getParams("mif= ", - MIFTestUtils.getDataPath(), uri)); + MIFTestUtils.fileName(""), uri)); =20 FeatureType ft =3D ds.getSchema("grafo"); assertEquals("Bad URI", new URI(strURI), ft.getNamespace()); @@ -115,55 +115,50 @@ * parameters */ public void testCanProcessPath() { - String dataPath =3D MIFTestUtils.getDataPath(); - // Opens the test-data directory assertEquals(true, - dsFactory.canProcess(MIFTestUtils.getParams("mif", dataPath,= uri))); + dsFactory.canProcess(MIFTestUtils.getParams("mif", MIFTestUt= ils.fileName(""), uri))); } =20 /** */ public void testCanProcessWrongDBType() { - String dataPath =3D MIFTestUtils.getDataPath(); =20 // fails because dbtype !=3D "mif" assertEquals(false, - dsFactory.canProcess(MIFTestUtils.getParams("miffooobar", da= taPath, + dsFactory.canProcess(MIFTestUtils.getParams("miffooobar", MI= FTestUtils.fileName(""), uri))); } =20 /** */ public void testCanProcessMIF() { - String dataPath =3D MIFTestUtils.getDataPath(); =20 // Opens a single mif file; works with or without extension, and= regardless the extension's case. assertEquals(true, dsFactory.canProcess(MIFTestUtils.getParams("mif", - dataPath + "grafo", uri))); + MIFTestUtils.fileName("grafo"), uri))); assertEquals(true, dsFactory.canProcess(MIFTestUtils.getParams("mif", - dataPath + "grafo.MIF", uri))); + MIFTestUtils.fileName("grafo.MIF"), uri))); assertEquals(true, dsFactory.canProcess(MIFTestUtils.getParams("mif", - dataPath + "grafo.mif", uri))); + MIFTestUtils.fileName("grafo.mif"), uri))); } =20 /** */ public void testCanProcessWrongPath() { - String dataPath =3D MIFTestUtils.getDataPath(); =20 // Fails because an extension other than ".mif" was specified assertEquals(false, dsFactory.canProcess(MIFTestUtils.getParams("mif", - dataPath + "grafo.zip", uri))); + MIFTestUtils.fileName("grafo.zip"), uri))); =20 // fails because the path is non-existent assertEquals(false, dsFactory.canProcess(MIFTestUtils.getParams("mif", - dataPath + "some/non/existent/path/", uri))); + MIFTestUtils.fileName("some_non_existent_file"), uri= ))); } =20 /** Modified: geotools/trunk/gt/plugin/mif/test/org/geotools/data/mif/MIFData= StoreTest.java =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- geotools/trunk/gt/plugin/mif/test/org/geotools/data/mif/MIFDataStoreT= est.java 2005-06-23 16:04:58 UTC (rev 14595) +++ geotools/trunk/gt/plugin/mif/test/org/geotools/data/mif/MIFDataStoreT= est.java 2005-06-23 16:52:25 UTC (rev 14596) @@ -31,6 +31,8 @@ import org.geotools.feature.FeatureType; import org.geotools.feature.FeatureTypeBuilder; import org.geotools.filter.Filter; + +import java.io.File; import java.io.FileNotFoundException; import java.io.IOException; import java.sql.Date; @@ -44,7 +46,6 @@ */ public class MIFDataStoreTest extends TestCase { private MIFDataStore ds; - private String dataPath =3D MIFTestUtils.getDataPath(); =20 /** * DOCUMENT ME! @@ -82,6 +83,8 @@ */ protected boolean initDS(String initPath) { try { + initPath =3D MIFTestUtils.fileName(initPath); + =20 HashMap params =3D MIFTestUtils.getParams("mif", initPath, n= ull); ds =3D new MIFDataStore(initPath, params); assertNotNull(ds); @@ -98,7 +101,7 @@ * See if all the MIF in data dir are recognized */ public void testOpenDir() { - initDS(dataPath); + initDS(""); =20 try { assertNotNull(ds.getSchema("grafo")); @@ -112,7 +115,8 @@ /** */ public void testCreateSchema() { - initDS(dataPath); + =20 + initDS(""); =20 try { FeatureTypeBuilder builder =3D FeatureTypeBuilder.newInstanc= e( @@ -148,7 +152,7 @@ /** */ public void testCreateSchemaBadGeometry() { - initDS(dataPath); + initDS(""); =20 try { FeatureTypeBuilder builder =3D FeatureTypeBuilder.newInstanc= e( @@ -171,7 +175,8 @@ /** */ public void testCreateSchemaTwoGeometry() { - initDS(dataPath); + =20 + initDS(""); =20 try { FeatureTypeBuilder builder =3D FeatureTypeBuilder.newInstanc= e( @@ -196,7 +201,7 @@ /** */ public void testFeatureReaderFilter() { - initDS(dataPath + "grafo"); // .mif + initDS("grafo"); // .mif =20 try { FeatureReader fr =3D getFeatureReader("grafo", "ID =3D 33755= "); @@ -220,7 +225,7 @@ * Tests createSchema & FeatureWriter */ public void testFeatureWriter() { - initDS(dataPath); + initDS(""); =20 String outmif =3D "grafo_new"; =20 @@ -299,7 +304,7 @@ try { String outmif =3D "grafo_append"; MIFTestUtils.copyMif("grafo", outmif); - initDS(dataPath); + initDS(outmif); =20 Feature f; Transaction transaction =3D new DefaultTransaction("mif"); @@ -358,7 +363,7 @@ fail(e.getMessage()); } =20 - initDS(dataPath); + initDS(outmif); =20 FeatureSource fs =3D null; FeatureType featureType =3D null; Modified: geotools/trunk/gt/plugin/mif/test/org/geotools/data/mif/MIFFile= Test.java =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- geotools/trunk/gt/plugin/mif/test/org/geotools/data/mif/MIFFileTest.j= ava 2005-06-23 16:04:58 UTC (rev 14595) +++ geotools/trunk/gt/plugin/mif/test/org/geotools/data/mif/MIFFileTest.j= ava 2005-06-23 16:52:25 UTC (rev 14596) @@ -31,7 +31,6 @@ * @author Luca S. Percich, AMA-MI */ public class MIFFileTest extends TestCase { - private String dataPath =3D MIFTestUtils.getDataPath(); private MIFFile mif =3D null; =20 /** @@ -66,7 +65,7 @@ */ public void testMIFFileOpen() { try { - mif =3D new MIFFile(MIFTestUtils.getDataPath() + "mixed", //= .mif + mif =3D new MIFFile(MIFTestUtils.fileName("mixed"), // .mif MIFTestUtils.getParams("mif", "", null)); assertEquals("450", mif.getHeaderClause(MIFDataStore.HCLAUSE_VERSION)); @@ -110,7 +109,7 @@ =20 try { // Input file - in =3D new MIFFile(dataPath + "grafo", null); // .mif + in =3D new MIFFile(MIFTestUtils.fileName("grafo"), null); //= .mif =20 FeatureType ft =3D in.getSchema(); =20 @@ -133,7 +132,7 @@ params.put(MIFDataStore.HCLAUSE_DELIMITER, ","); =20 // Output file - out =3D new MIFFile(dataPath + "grafo_out", ft, params); // = .mif + out =3D new MIFFile(MIFTestUtils.fileName("grafo_out"), ft, = params); // .mif } catch (Exception e) { fail("Can't create grafo_out: " + e.getMessage()); } @@ -198,7 +197,7 @@ try { MIFTestUtils.copyMif("mixed", "mixed_wri"); =20 - MIFFile in =3D new MIFFile(dataPath + "mixed_wri", // .mif + MIFFile in =3D new MIFFile(MIFTestUtils.fileName("mixed_wri"= ), // .mif MIFTestUtils.getParams("", "", null)); FeatureWriter fw =3D in.getFeatureWriter(); =20 Modified: geotools/trunk/gt/plugin/mif/test/org/geotools/data/mif/MIFFile= TokenizerTest.java =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- geotools/trunk/gt/plugin/mif/test/org/geotools/data/mif/MIFFileTokeni= zerTest.java 2005-06-23 16:04:58 UTC (rev 14595) +++ geotools/trunk/gt/plugin/mif/test/org/geotools/data/mif/MIFFileTokeni= zerTest.java 2005-06-23 16:52:25 UTC (rev 14596) @@ -50,8 +50,7 @@ super.setUp(); tok =3D new MIFFileTokenizer(new BufferedReader( new FileReader( - new File(MIFTestUtils.getDataPath() - + "MIFFileTokenizer.txt")))); + new File(MIFTestUtils.fileName("MIFFileTokenizer= .txt"))))); } =20 /* Modified: geotools/trunk/gt/plugin/mif/test/org/geotools/data/mif/MIFTest= Utils.java =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- geotools/trunk/gt/plugin/mif/test/org/geotools/data/mif/MIFTestUtils.= java 2005-06-23 16:04:58 UTC (rev 14595) +++ geotools/trunk/gt/plugin/mif/test/org/geotools/data/mif/MIFTestUtils.= java 2005-06-23 16:52:25 UTC (rev 14596) @@ -55,12 +55,11 @@ * * @return DOCUMENT ME! */ - public static String getDataPath() { + private static File getDataPath() { try { - return TestData.file(MIFTestUtils.class, null).getAbsolutePa= th() - + "/"; + return TestData.file(MIFTestUtils.class, null); } catch (IOException e) { - return ""; + return null; } } =20 @@ -74,12 +73,12 @@ */ public static void copyMif(String inMif, String outMif) throws FileNotFoundException { - File path =3D new File(getDataPath()); + File path =3D getDataPath(); =20 copyFileUsingChannels(MIFFile.getFileHandler(path, inMif, ".mif"= , true), - new File(getDataPath() + outMif + ".mif")); + new File(path, outMif + ".mif")); copyFileUsingChannels(MIFFile.getFileHandler(path, inMif, ".mid"= , true), - new File(getDataPath() + outMif + ".mid")); + new File(path, outMif + ".mid")); } =20 /** @@ -116,15 +115,13 @@ File f; =20 try { - f =3D MIFFile.getFileHandler(new File(getDataPath()), mifNam= e, - ".mif", false); + f =3D MIFFile.getFileHandler(getDataPath(), mifName, ".mif",= false); =20 if (f.exists()) { f.delete(); } =20 - f =3D MIFFile.getFileHandler(new File(getDataPath()), mifNam= e, - ".mid", false); + f =3D MIFFile.getFileHandler(getDataPath(), mifName, ".mid",= false); =20 if (f.exists()) { f.delete(); @@ -245,4 +242,21 @@ return Filter.ALL; } } + + /** + * DOCUMENT ME! + * + * @param fileName DOCUMENT ME! + * + * @return DOCUMENT ME! + */ + protected static String fileName(String fileName) { + if (fileName.equals("")) { + return getDataPath().getAbsolutePath(); + } + + File file =3D new File(getDataPath(), fileName); + + return file.getAbsolutePath(); + } } |