From 0c81ed405b41865f7c9fb2250cafd1323c959e68 Mon Sep 17 00:00:00 2001 From: ?? ? <ulysseskao@ximple.com.tw> Date: Thu, 13 Mar 2008 15:12:22 +0800 Subject: [PATCH] EOFM-14 --- /dev/null | 23 -- ximple-dgnio/src/test/java/com/ximple/io/dgn7/OracleTarget.java | 162 ++++++++++++++ ximple-dgnio/src/test/resources/com/ximple/io/dgn7/test-data/HV88491_0888888.dgn | 0 ximple-dgnio/src/test/java/com/ximple/io/dgn7/Dgn7fileReaderTest.java | 119 ++++++++++ .gitattributes | 10 ximple-dgnio/src/test/resources/com/ximple/io/dgn7/test-data/HV88491-1.dgn | 0 ximple-dgnio/src/test/resources/com/ximple/io/dgn7/test-data/testHV.dgn | 0 ximple-dgnio/src/test/resources/com/ximple/io/dgn7/test-data/Demo.dgn | 0 ximple-dgnio/src/test/java/com/ximple/io/dgn7/Dgn7OracleReaderTest.java | 125 +++++++++++ ximple-dgnio/src/test/java/com/ximple/io/dgn7/Dgn7TextElementReaderTest.java | 180 ++++++++++++++++ ximple-dgnio/src/test/resources/com/ximple/io/dgn7/test-data/HV88494_0.dgn | 0 11 files changed, 595 insertions(+), 24 deletions(-) diff --git a/.gitattributes b/.gitattributes index 9d6a37a..6ef086c 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,5 +1,4 @@ * text=auto !eol -ximple-dgnio/.project svneol=native#text/xml ximple-dgnio/pom.xml svneol=native#text/xml ximple-dgnio/src/main/java/com/ximple/io/dgn7/ArcElement.java svneol=native#text/plain ximple-dgnio/src/main/java/com/ximple/io/dgn7/ComplexChainElement.java svneol=native#text/plain @@ -26,6 +25,15 @@ ximple-dgnio/src/main/java/com/ximple/io/dgn7/UserAttributeData.java svneol=native#text/plain ximple-dgnio/src/main/java/com/ximple/io/dgn7/Utility.java svneol=native#text/plain ximple-dgnio/src/main/java/com/ximple/util/PrintfFormat.java svneol=native#text/plain +ximple-dgnio/src/test/java/com/ximple/io/dgn7/Dgn7OracleReaderTest.java svneol=native#text/plain +ximple-dgnio/src/test/java/com/ximple/io/dgn7/Dgn7TextElementReaderTest.java svneol=native#text/plain +ximple-dgnio/src/test/java/com/ximple/io/dgn7/Dgn7fileReaderTest.java svneol=native#text/plain +ximple-dgnio/src/test/java/com/ximple/io/dgn7/OracleTarget.java svneol=native#text/plain +ximple-dgnio/src/test/resources/com/ximple/io/dgn7/test-data/Demo.dgn -text +ximple-dgnio/src/test/resources/com/ximple/io/dgn7/test-data/HV88491-1.dgn -text +ximple-dgnio/src/test/resources/com/ximple/io/dgn7/test-data/HV88491_0888888.dgn -text +ximple-dgnio/src/test/resources/com/ximple/io/dgn7/test-data/HV88494_0.dgn -text +ximple-dgnio/src/test/resources/com/ximple/io/dgn7/test-data/testHV.dgn -text ximple-jobcarrier/pom.xml svneol=native#text/xml ximple-jobcarrier/src/main/java/com/ximple/eofms/App.java svneol=native#text/plain ximple-jobcarrier/src/test/java/com/ximple/eofms/AppTest.java svneol=native#text/plain diff --git a/ximple-dgnio/.project b/ximple-dgnio/.project deleted file mode 100644 index 4198653..0000000 --- a/ximple-dgnio/.project +++ /dev/null @@ -1,23 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<projectDescription> - <name>ximple-dgnio</name> - <comment></comment> - <projects> - </projects> - <buildSpec> - <buildCommand> - <name>org.maven.ide.eclipse.maven2Builder</name> - <arguments> - </arguments> - </buildCommand> - <buildCommand> - <name>org.eclipse.jdt.core.javabuilder</name> - <arguments> - </arguments> - </buildCommand> - </buildSpec> - <natures> - <nature>org.eclipse.jdt.core.javanature</nature> - <nature>org.maven.ide.eclipse.maven2Nature</nature> - </natures> -</projectDescription> diff --git a/ximple-dgnio/src/test/java/com/ximple/io/dgn7/Dgn7OracleReaderTest.java b/ximple-dgnio/src/test/java/com/ximple/io/dgn7/Dgn7OracleReaderTest.java new file mode 100644 index 0000000..0ab0b93 --- /dev/null +++ b/ximple-dgnio/src/test/java/com/ximple/io/dgn7/Dgn7OracleReaderTest.java @@ -0,0 +1,125 @@ +package com.ximple.io.dgn7; + +import java.io.IOException; +import java.sql.SQLException; +import java.util.List; + +import org.testng.annotations.BeforeTest; +import org.testng.annotations.Test; + +import com.vividsolutions.jts.geom.Coordinate; +import com.ximple.util.PrintfFormat; +import oracle.jdbc.OracleConnection; + +/** + * Dgn7OracleReaderTest + * User: Ulysses + * Date: 2007/10/24 + * Time: �W�� 10:49:54 + */ +public class Dgn7OracleReaderTest +{ + @BeforeTest + public void setUp() + { + + } + + @Test + public void testOracleReader() throws SQLException, IOException + { + OracleConnection connection = OracleTarget.getInstance().getOracleConnection(); + // String fetchSrcStmtFmt = "SELECT IGDSELM FROM \"%s\".\"%s\" ORDER BY ROWID"; + String fetchSrcStmtFmt = "SELECT IGDSELM FROM \"%s\".\"%s\" WHERE TAG_SFSC=106 ORDER BY ROWID"; + PrintfFormat spf = new PrintfFormat(fetchSrcStmtFmt); + String srcschema = "SPATIALDB"; + String srctable = "IGSET_1"; + String fetchSrcStmt = spf.sprintf(new Object[]{srcschema, srctable}); + + Dgn7OracleReader reader = new Dgn7OracleReader(fetchSrcStmt, "IGDSELM", connection); + int count = 0; + while (reader.hasNext()) + { + Element element = reader.next(); + + if (element instanceof ComplexChainElement) + { + ComplexChainElement complexChain = (ComplexChainElement) element; + FrammeAttributeData frammeLinkage = null; + + List<UserAttributeData> attrs = complexChain.getUserAttributeData(); + for (int k = 0; k < attrs.size(); k++) + { + UserAttributeData userAttr = attrs.get(k); + if (userAttr instanceof FrammeAttributeData) + { + frammeLinkage = (FrammeAttributeData) userAttr; + break; + } + } + + System.out.print("complexChain:"); + if (frammeLinkage != null) + System.out.print(":FSC-" + frammeLinkage.getFsc() + + ":UFID-" + frammeLinkage.getUfid() + + ":COMP-" + frammeLinkage.getComponentID()); + else + System.out.print("Linkage is null"); + + for (int i = 0; i < complexChain.size(); i++) + { + Element elm = (Element) complexChain.get(i); + if (elm instanceof LineStringElement) + { + LineStringElement lineStringElement = (LineStringElement) elm; + int size = lineStringElement.getVerticeSize(); + System.out.print("size=" + size + ":"); + Coordinate[] coords = lineStringElement.getVertices(); + for (int j = 0; j < coords.length; j++) + System.out.print("[" + j + "]" + coords[j].toString()); + } + } + + System.out.println(); + } else if (element instanceof TextNodeElement) + { + TextNodeElement textNode = (TextNodeElement) element; + + FrammeAttributeData frammeLinkage = null; + + List<UserAttributeData> attrs = textNode.getUserAttributeData(); + for (int k = 0; k < attrs.size(); k++) + { + UserAttributeData userAttr = attrs.get(k); + if (userAttr instanceof FrammeAttributeData) + { + frammeLinkage = (FrammeAttributeData) userAttr; + break; + } + } + + Coordinate coord = textNode.getOrigin(); + System.out.print("TextNode:origin=" + coord.toString()); + if (frammeLinkage != null) + System.out.print(":FSC-" + frammeLinkage.getFsc() + + ":UFID-" + frammeLinkage.getUfid() + + ":COMP-" + frammeLinkage.getComponentID()); + else + System.out.print("Linkage is null"); + for (int i = 0; i < textNode.size(); i++) + { + Element elm = (Element) textNode.get(i); + if (elm instanceof TextElement) + { + TextElement textElm = (TextElement) elm; + System.out.print("---"); + String text = textElm.getText(); + System.out.print("'" + text + "'"); + } + } + System.out.println(); + } + } + } + +} diff --git a/ximple-dgnio/src/test/java/com/ximple/io/dgn7/Dgn7TextElementReaderTest.java b/ximple-dgnio/src/test/java/com/ximple/io/dgn7/Dgn7TextElementReaderTest.java new file mode 100644 index 0000000..cc1ed35 --- /dev/null +++ b/ximple-dgnio/src/test/java/com/ximple/io/dgn7/Dgn7TextElementReaderTest.java @@ -0,0 +1,180 @@ +package com.ximple.io.dgn7; + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.nio.channels.FileChannel; +import java.util.Iterator; +import java.util.List; + +import org.apache.log4j.Logger; +import org.testng.annotations.BeforeTest; +import org.testng.annotations.Test; +import org.geotools.TestData; + +/** + * Dgn7TextElementReaderTest + * User: Ulysses + * Date: 2008/1/10 + * Time: �W�� 12:19:14 + */ +public class Dgn7TextElementReaderTest +{ + private final static Logger logger = Logger.getLogger(Dgn7fileReaderTest.class); + + private final static String testFilePathCreated = "demo.dgn"; + private final static String testFilePathExist = "HV88491-1.dgn"; + private final static String testFilePathPostComplete = "HV88494_0.dgn"; + + private FileInputStream _fs; + + @BeforeTest + public void setUp() throws FileNotFoundException + { + } + + @Test + public void testRead() throws Dgn7fileException, IOException + { + File dataFile = TestData.file(this, testFilePathCreated); + if (dataFile.exists()) + { + System.out.println("Output--" + testFilePathCreated); + _fs = new FileInputStream(dataFile); + FileChannel fc = _fs.getChannel(); + dumpElements(fc); + fc.close(); + _fs.close(); + } + + dataFile = TestData.file(this, testFilePathExist); + if (dataFile.exists()) + { + System.out.println("Output--" + testFilePathExist); + _fs = new FileInputStream(dataFile); + FileChannel fc = _fs.getChannel(); + dumpElements(fc); + fc.close(); + _fs.close(); + } + + dataFile = TestData.file(this, testFilePathPostComplete); + if (dataFile.exists()) + { + System.out.println("Output--" + testFilePathPostComplete); + _fs = new FileInputStream(dataFile); + FileChannel fc = _fs.getChannel(); + dumpElements(fc); + fc.close(); + _fs.close(); + } + } + + public void dumpElements(FileChannel fc) throws Dgn7fileException, IOException + { + Dgn7fileReader reader = new Dgn7fileReader(fc, new Lock()); + int count = 0; + Element lastComplex = null; + while (reader.hasNext()) + { + Dgn7fileReader.Record record = reader.nextElement(); + if (record.element() != null) + { + Element element = (Element) record.element(); + ElementType type = element.getElementType(); + + if ((!type.isComplexElement()) && (!element.isComponentElement())) + { + if (lastComplex != null) + { + // @todo add process in here + lastComplex = null; + } + + // @todo add process in here + } else if (element.isComponentElement()) + { + if (lastComplex != null) + { + ((ComplexElement) lastComplex).add(element); + } + } else if (type.isComplexElement()) + { + if (lastComplex == null) + { + lastComplex = element; + } else + { + // @todo add process in here + lastComplex = element; + } + } + + if (element.getElementType().isComplexElement()) + { + if (element instanceof ComplexChainElement) + { + ComplexChainElement complexChain = (ComplexChainElement) element; + int size = complexChain.size(); + for (Object aComplexChain : complexChain) + { + Element subElement = (Element) aComplexChain; + subElement.getType(); + } + } + + if (element instanceof ComplexShapeElement) + { + ComplexShapeElement complexShape = (ComplexShapeElement) element; + } + + if (element instanceof TextNodeElement) + { + TextNodeElement textNode = (TextNodeElement) element; + int size = textNode.size(); + for (int i = 0; i < size; i++) + { + Element subElement = (Element) textNode.get(i); + subElement.getElementType(); + } + } + + } else + { + boolean hasLinkage = false; + if (element instanceof TextElement) + { + TextElement textElm = (TextElement) element; + List<UserAttributeData> usrData = textElm.getUserAttributeData(); + Iterator<UserAttributeData> it = usrData.iterator(); + while (it.hasNext()) + { + UserAttributeData attr = it.next(); + if (attr instanceof FrammeAttributeData) + { + hasLinkage = true; + System.out.println("------------------------------------------"); + System.out.println("FSC=" + ((FrammeAttributeData) attr).getFsc() + ":" + + ((FrammeAttributeData) attr).getUfid()); + } + } + + if (hasLinkage) + { + System.out.println("Text.Font=" + textElm.getFontIndex()); + System.out.println("Text.Just=" + textElm.getJustification()); + System.out.println("usrData.len=" + usrData.size()); + System.out.println("text=" + textElm.getText()); + System.out.println("Origin=" + textElm.getOrigin()); + System.out.println("UserOrigin=" + textElm.getUserOrigin()); + } + } + } + } + count++; + } + + logger.info("ElementRecord Count=" + count); + } +} diff --git a/ximple-dgnio/src/test/java/com/ximple/io/dgn7/Dgn7fileReaderTest.java b/ximple-dgnio/src/test/java/com/ximple/io/dgn7/Dgn7fileReaderTest.java new file mode 100644 index 0000000..314427c --- /dev/null +++ b/ximple-dgnio/src/test/java/com/ximple/io/dgn7/Dgn7fileReaderTest.java @@ -0,0 +1,119 @@ +package com.ximple.io.dgn7; + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.nio.channels.FileChannel; + +import org.apache.log4j.Logger; +import org.testng.annotations.BeforeTest; +import org.testng.annotations.Test; +import org.geotools.TestData; + +/** + * Dgn7fileReaderTest + * User: Ulysses + * Date: 2007/10/24 + * Time: �W�� 01:43:41 + * To change this template use File | Settings | File Templates. + */ +public class Dgn7fileReaderTest +{ + private final static Logger logger = Logger.getLogger(Dgn7fileReaderTest.class); + + // private final static String testFilePath = "test-data\\testHV.dgn"; + private final static String testFilePath = "testHV.dgn"; + private FileInputStream _fs; + + @BeforeTest + public void setUp() throws IOException + { + File dataFile = TestData.file(this, testFilePath); + if (!dataFile.exists()) + { + return; + } + + _fs = new FileInputStream(dataFile); + } + + @Test + public void testRead() throws Dgn7fileException, IOException + { + if (_fs == null) return; + FileChannel fc = _fs.getChannel(); + Dgn7fileReader reader = new Dgn7fileReader(fc, new Lock()); + int count = 0; + Element lastComplex = null; + while (reader.hasNext()) + { + Dgn7fileReader.Record record = reader.nextElement(); + if (record.element() != null) + { + Element element = (Element) record.element(); + ElementType type = element.getElementType(); + + if ((!type.isComplexElement()) && (!element.isComponentElement())) + { + if (lastComplex != null) + { + // @todo add process in here + lastComplex = null; + } + + // @todo add process in here + } else if (element.isComponentElement()) + { + if (lastComplex != null) + { + ((ComplexElement) lastComplex).add(element); + } + } else if (type.isComplexElement()) + { + if (lastComplex == null) + { + lastComplex = element; + } else + { + // @todo add process in here + lastComplex = element; + } + } + + if (element.getElementType().isComplexElement()) + { + if (element instanceof ComplexChainElement) + { + ComplexChainElement complexChain = (ComplexChainElement) element; + int size = complexChain.size(); + for (Object aComplexChain : complexChain) + { + Element subElement = (Element) aComplexChain; + subElement.getType(); + } + } + + if (element instanceof ComplexShapeElement) + { + ComplexShapeElement complexShape = (ComplexShapeElement) element; + } + + if (element instanceof TextNodeElement) + { + TextNodeElement textNode = (TextNodeElement) element; + int size = textNode.size(); + for (int i = 0; i < size; i++) + { + Element subElement = (Element) textNode.get(i); + subElement.getElementType(); + } + } + } + } + count++; + } + + logger.info("ElementRecord Count=" + count); + } +} diff --git a/ximple-dgnio/src/test/java/com/ximple/io/dgn7/OracleTarget.java b/ximple-dgnio/src/test/java/com/ximple/io/dgn7/OracleTarget.java new file mode 100644 index 0000000..8e72795 --- /dev/null +++ b/ximple-dgnio/src/test/java/com/ximple/io/dgn7/OracleTarget.java @@ -0,0 +1,162 @@ +package com.ximple.io.dgn7; + +//~--- JDK imports ------------------------------------------------------------ + +import java.sql.DriverManager; +import java.sql.SQLException; +import java.util.Properties; + +import org.apache.log4j.Logger; + +import com.vividsolutions.jts.util.Assert; +import oracle.jdbc.OracleConnection; + +/** + * OracleTarget + * User: Ulysses + * Date: 2007/6/15 + * Time: ?U?? 03:12:43 + * To change this template use File | Settings | File Templates. + */ +public class OracleTarget +{ + private static final Logger logger = Logger.getLogger(OracleTarget.class); + private static OracleTarget _instance = null; + private static final String ORACLE_URL = "jdbc:oracle:thin:@"; + private static final String _propUsrKey = "user"; + private static final String _propPassKey = "password"; + private static String _oracleHost = "192.168.11.119"; + private static String _oracleInstance = "ORCL"; + private static String _oraclePort = "1521"; + + static + { + try + { + DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver()); + } catch (SQLException e) + { + Assert.shouldNeverReachHere(e.getMessage()); + } + } + + private OracleConnection oracleConnection = null; + private Properties properties; + + private OracleTarget() + { + properties = new Properties(); + properties.put(_propUsrKey, "SPATIALDB"); + properties.put(_propPassKey, "SPATIALDB000"); + } + + public static String getOracleHost() + { + return _oracleHost; + } + + public static void setOracleHost(String oracleHost) + { + OracleTarget._oracleHost = oracleHost; + } + + public static String getOracleInstance() + { + return _oracleInstance; + } + + public static void setOracleInstance(String oracleInstance) + { + OracleTarget._oracleInstance = oracleInstance; + } + + public static String getOraclePort() + { + return _oraclePort; + } + + public static void setOraclePort(String oraclePort) + { + OracleTarget._oraclePort = oraclePort; + } + + public static String getCurrentURL() + { + StringBuilder builder = new StringBuilder(); + + builder.append(ORACLE_URL); + builder.append(_oracleHost); + builder.append(":"); + builder.append(_oraclePort); + builder.append(":"); + builder.append(_oracleInstance); + + return builder.toString(); + } + + public String getLoginPass() + { + return (String) properties.get(_propPassKey); + } + + public void setLoginPass(String loginPass) + { + properties.put(_propPassKey, loginPass); + } + + public String getLoginUsr() + { + return (String) properties.get(_propUsrKey); + } + + public void setLoginUsr(String loginUsr) + { + properties.put(_propUsrKey, loginUsr); + } + + public static OracleTarget getInstance() + { + if (_instance == null) + { + _instance = new OracleTarget(); + } + + return _instance; + } + + public OracleConnection getOracleConnection() + { + try + { + if (oracleConnection == null) + { + oracleConnection = (OracleConnection) DriverManager.getConnection(getCurrentURL(), properties); + } + + return oracleConnection; + } catch (SQLException e) + { + logger.warn(e.getMessage(), e); + } + + oracleConnection = null; + + return null; + } + + public void closeConnection() + { + try + { + if (oracleConnection != null) + { + oracleConnection.close(); + oracleConnection = null; + } + } catch (SQLException e) + { + logger.warn(e.getMessage(), e); + } + } +} + diff --git a/ximple-dgnio/src/test/resources/com/ximple/io/dgn7/test-data/Demo.dgn b/ximple-dgnio/src/test/resources/com/ximple/io/dgn7/test-data/Demo.dgn new file mode 100644 index 0000000..d749f68 --- /dev/null +++ b/ximple-dgnio/src/test/resources/com/ximple/io/dgn7/test-data/Demo.dgn Binary files differ diff --git a/ximple-dgnio/src/test/resources/com/ximple/io/dgn7/test-data/HV88491-1.dgn b/ximple-dgnio/src/test/resources/com/ximple/io/dgn7/test-data/HV88491-1.dgn new file mode 100644 index 0000000..acbb8a2 --- /dev/null +++ b/ximple-dgnio/src/test/resources/com/ximple/io/dgn7/test-data/HV88491-1.dgn Binary files differ diff --git a/ximple-dgnio/src/test/resources/com/ximple/io/dgn7/test-data/HV88491_0888888.dgn b/ximple-dgnio/src/test/resources/com/ximple/io/dgn7/test-data/HV88491_0888888.dgn new file mode 100644 index 0000000..f29f86f --- /dev/null +++ b/ximple-dgnio/src/test/resources/com/ximple/io/dgn7/test-data/HV88491_0888888.dgn Binary files differ diff --git a/ximple-dgnio/src/test/resources/com/ximple/io/dgn7/test-data/HV88494_0.dgn b/ximple-dgnio/src/test/resources/com/ximple/io/dgn7/test-data/HV88494_0.dgn new file mode 100644 index 0000000..4899d19 --- /dev/null +++ b/ximple-dgnio/src/test/resources/com/ximple/io/dgn7/test-data/HV88494_0.dgn Binary files differ diff --git a/ximple-dgnio/src/test/resources/com/ximple/io/dgn7/test-data/testHV.dgn b/ximple-dgnio/src/test/resources/com/ximple/io/dgn7/test-data/testHV.dgn new file mode 100644 index 0000000..05fb839 --- /dev/null +++ b/ximple-dgnio/src/test/resources/com/ximple/io/dgn7/test-data/testHV.dgn Binary files differ -- Gitblit v0.0.0-SNAPSHOT