forked from geodmms/xdgnjobs

?? ?
2008-08-28 44114c9140a99d2c506000a345cfbca74b2ee085
update for EOFM-156
2 files modified
2 files added
517 ■■■■■ changed files
.gitattributes 2 ●●●●● patch | view | raw | blame | history
xdgnjobs/pom.xml 1 ●●●● patch | view | raw | blame | history
xdgnjobs/ximple-elmparser/pom.xml 300 ●●●●● patch | view | raw | blame | history
xdgnjobs/ximple-elmparser/src/main/java/com/ximple/eofms/XElementParser.java 214 ●●●●● patch | view | raw | blame | history
.gitattributes
@@ -41,6 +41,8 @@
xdgnjobs/ximple-dgnio/src/test/resources/com/ximple/io/dgn7/test-data/HV88491_0888888.dgn -text
xdgnjobs/ximple-dgnio/src/test/resources/com/ximple/io/dgn7/test-data/HV88494_0.dgn -text
xdgnjobs/ximple-dgnio/src/test/resources/com/ximple/io/dgn7/test-data/testHV.dgn -text
xdgnjobs/ximple-elmparser/pom.xml svneol=native#text/xml
xdgnjobs/ximple-elmparser/src/main/java/com/ximple/eofms/XElementParser.java svneol=native#text/plain
xdgnjobs/ximple-jobcarrier/pom.xml svneol=native#text/xml
xdgnjobs/ximple-jobcarrier/src/main/java/com/ximple/eofms/XQuartzJobCarrier.java svneol=native#text/plain
xdgnjobs/ximple-jobcarrier/src/main/java/com/ximple/eofms/XQuartzJobWizard.java svneol=native#text/plain
xdgnjobs/pom.xml
@@ -765,5 +765,6 @@
    <module>ximple-dgnio</module>
    <module>ximple-spatialjob</module>
    <module>ximple-jobcarrier</module>
    <module>ximple-elmparser</module>
  </modules>
</project>
xdgnjobs/ximple-elmparser/pom.xml
New file
@@ -0,0 +1,300 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <parent>
    <groupId>com.ximple.eofms</groupId>
    <artifactId>ximple-dgnjobs</artifactId>
    <version>0.9.0</version>
  </parent>
  <groupId>com.ximple.eofms</groupId>
  <artifactId>ximple-elmparser</artifactId>
  <version>0.9.0</version>
  <packaging>jar</packaging>
  <name>ximple-elmparser</name>
  <url>http://maven.apache.org</url>
  <properties>
    <xdgnio.version>0.9.0</xdgnio.version>
  </properties>
  <scm>
    <connection>
      scm:svn:http://www.ximple.com.tw/svn/xeofms/xspatialjob/truck/
    </connection>
    <url>http://www.ximple.com.tw/svn/xeofms/xspatialjob/truck/</url>
  </scm>
  <description>
    Ximple Element Parser
  </description>
  <organization>
    <name>Ximple</name>
    <url>http://www.ximple.com.tw</url>
  </organization>
  <inceptionYear>2008</inceptionYear>
  <developers>
    <developer>
      <name>Kuo-Feng Kao</name>
      <id>ulysseskao</id>
      <email>ulysseskao@ximple.com.tw</email>
      <organization>Ximple</organization>
      <roles>
        <role>Java Developer</role>
      </roles>
    </developer>
  </developers>
  <contributors>
  </contributors>
  <!-- =========================================================== -->
  <!--     Dependencies to be inherited by all modules.            -->
  <!-- =========================================================== -->
  <dependencies>
    <dependency>
      <artifactId>quartz</artifactId>
      <groupId>opensymphony</groupId>
    </dependency>
    <dependency>
      <groupId>javax.transaction</groupId>
      <artifactId>jta</artifactId>
      <version>1.0.1B</version>
    </dependency>
    <dependency>
      <groupId>org.geotools</groupId>
      <artifactId>gt2-shapefile</artifactId>
    </dependency>
    <dependency>
      <groupId>org.geotools</groupId>
      <artifactId>gt2-sample-data</artifactId>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.geotools</groupId>
      <artifactId>gt2-data</artifactId>
    </dependency>
    <dependency>
      <groupId>org.geotools</groupId>
      <artifactId>gt2-jdbc</artifactId>
    </dependency>
    <dependency>
      <groupId>org.geotools</groupId>
      <artifactId>gt2-postgis</artifactId>
    </dependency>
    <dependency>
      <groupId>org.geotools</groupId>
      <artifactId>gt2-oracle-spatial</artifactId>
    </dependency>
    <dependency>
      <groupId>org.geotools</groupId>
      <artifactId>gt2-mysql</artifactId>
    </dependency>
    <!-- because main and sample-data depend on referencing we need a tie breaker -->
    <dependency>
      <groupId>org.geotools</groupId>
      <artifactId>gt2-referencing</artifactId>
    </dependency>
    <!-- We need this to make the referencing module useful -->
    <dependency>
      <artifactId>gt2-epsg-hsql</artifactId>
      <groupId>org.geotools</groupId>
      <scope>test</scope>
    </dependency>
    <dependency>
      <artifactId>jdom</artifactId>
      <groupId>jdom</groupId>
    </dependency>
    <dependency>
      <groupId>org.apache.velocity</groupId>
      <artifactId>velocity</artifactId>
    </dependency>
    <dependency>
      <groupId>commons-cli</groupId>
      <artifactId>commons-cli</artifactId>
    </dependency>
    <!-- ORACLE -->
    <dependency>
      <groupId>com.oracle</groupId>
      <artifactId>ojdbc5</artifactId>
    </dependency>
    <dependency>
      <groupId>com.oracle</groupId>
      <artifactId>ojdbc5</artifactId>
    </dependency>
    <dependency>
      <groupId>com.oracle</groupId>
      <artifactId>sdoapi</artifactId>
    </dependency>
    <dependency>
      <groupId>com.oracle</groupId>
      <artifactId>sdotype</artifactId>
    </dependency>
    <dependency>
      <groupId>com.oracle</groupId>
      <artifactId>sdoutl</artifactId>
    </dependency>
    <dependency>
      <groupId>postgresql</groupId>
      <artifactId>postgresql</artifactId>
    </dependency>
    <dependency>
      <groupId>org.postgis</groupId>
      <artifactId>postgis-driver</artifactId>
    </dependency>
    <dependency>
      <groupId>mysql</groupId>
      <artifactId>mysql-connector-java</artifactId>
    </dependency>
    <!-- AWL -->
    <dependency>
      <groupId>org.awl</groupId>
      <artifactId>awl</artifactId>
    </dependency>
    <!-- Ximple Library -->
    <dependency>
      <artifactId>ximple-dgnio</artifactId>
      <groupId>com.ximple.eofms</groupId>
      <version>${xdgnio.version}</version>
    </dependency>
    <dependency>
      <artifactId>ximple-spatialjob</artifactId>
      <groupId>com.ximple.eofms</groupId>
      <version>${xdgnio.version}</version>
    </dependency>
  </dependencies>
  <build>
    <plugins>
      <!-- ======================================================= -->
      <!--     JAR packaging.                                      -->
      <!-- ======================================================= -->
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-jar-plugin</artifactId>
        <configuration>
          <archive>
            <manifest>
              <mainClass>com.ximple.eofms.XQuartzJobCarrier</mainClass>
              <addClasspath>true</addClasspath>
            </manifest>
          </archive>
        </configuration>
      </plugin>
      <!-- ======================================================= -->
      <!--     exec jar.                                           -->
      <!-- ======================================================= -->
      <plugin>
        <!--
           Use maven from the command line:
             mvn exec:java -Dexec.mainClass="com.ximple.eofms.XQuartzJobCarrier"
        -->
        <artifactId>exec-maven-plugin</artifactId>
        <groupId>org.codehaus.mojo</groupId>
        <!--
        <executions>
          <execution>
            <phase>package</phase>
            <goals>
              <goal>run</goal>
            </goals>
          </execution>
        </executions>
        -->
        <configuration>
          <mainClass>com.ximple.eofms.XQuartzJobCarrier</mainClass>
          <!--
          <commandlineArgs>-wizard</commandlineArgs>
          -->
        </configuration>
        <!--
        <dependencies>
          <dependency>
             <groupId>com.ximple.eofms</groupId>
             <artifactId>ximple-jobcarrier</artifactId>
             <version>0.0.1</version>
             <type>jar</type>
           </dependency>
        </dependencies>
        -->
      </plugin>
      <plugin>
        <groupId>com.ximple.eofms.maven</groupId>
        <artifactId>ximple-jar-collector</artifactId>
        <version>${project.version}</version>
        <executions>
          <execution>
            <goals>
              <goal>collect</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>native2ascii-maven-plugin</artifactId>
        <version>1.0-alpha-1</version>
        <configuration>
          <dest>target/classes/com/ximple/eofms</dest>
          <src>src/main/resources/com/ximple/eofms</src>
        </configuration>
        <executions>
          <execution>
            <id>native2ascii-utf8</id>
            <goals>
              <goal>native2ascii</goal>
            </goals>
            <configuration>
              <encoding>UTF8</encoding>
              <includes>XQuartzJobWizard_zh*.properties</includes>
            </configuration>
          </execution>
        </executions>
      </plugin>
    </plugins>
    <resources>
      <resource>
        <directory>src/main/resources/com/ximple/eofms</directory>
        <excludes>
          <exclude>XQuartzJobWizard_zh*.properties</exclude>
        </excludes>
        <filtering>true</filtering>
      </resource>
      <resource>
        <directory>src/main/resources</directory>
        <includes>
          <include>log4j.properties</include>
          <include>quartz.properties</include>
          <include>quartz_jobs.xml</include>
        </includes>
        <!--
        <excludes>
          <exclude>XQuartzJobWizard*.properties</exclude>
          <exclude>quartz_jobs.xml</exclude>
          <exclude>quartz_jobs_shapefiles.xml</exclude>
        </excludes>
        -->
        <filtering>false</filtering>
      </resource>
    </resources>
  </build>
</project>
xdgnjobs/ximple-elmparser/src/main/java/com/ximple/eofms/XElementParser.java
New file
@@ -0,0 +1,214 @@
package com.ximple.eofms;
import java.util.HashMap;
import java.util.ArrayList;
import java.util.List;
import java.io.File;
import java.io.FilenameFilter;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.FileNotFoundException;
import java.io.UnsupportedEncodingException;
import java.nio.channels.FileChannel;
import java.net.URL;
import java.net.MalformedURLException;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.commons.digester.Digester;
import org.apache.commons.digester.xmlrules.DigesterLoader;
import org.apache.commons.collections.map.MultiValueMap;
import org.xml.sax.SAXException;
import org.geotools.feature.Feature;
import com.vividsolutions.jts.geom.GeometryFactory;
import com.ximple.io.dgn7.Dgn7fileReader;
import com.ximple.io.dgn7.Lock;
import com.ximple.io.dgn7.Dgn7fileException;
import com.ximple.io.dgn7.Element;
import com.ximple.io.dgn7.ElementType;
import com.ximple.io.dgn7.ComplexElement;
import com.ximple.io.dgn7.FrammeAttributeData;
import com.ximple.eofms.filter.ElementDispatcher;
import com.ximple.eofms.filter.AbstractFLinkageDispatchableFilter;
import com.ximple.eofms.jobs.context.postgis.FeatureDgnConvertPostGISJobContext;
public class XElementParser implements Runnable
{
    static Log logger = LogFactory.getLog(XElementParser.class);
    static final GeometryFactory geometryFactory = new GeometryFactory();
    private HashMap<String, String> dataConfig;
    private ElementDispatcher elementDispatcher;
    private MultiValueMap featuresContext = new MultiValueMap();
    public static void main(String[] args)
    {
        XElementParser parser = new XElementParser();
        parser.run();
    }
    public XElementParser()
    {
        initializeDataConfig();
    }
    private void initializeDataConfig()
    {
        dataConfig = new HashMap<String, String>();
        dataConfig.put("DATAPATH", "G:\\Temp\\JobData\\nstpc\\elmout");
        elementDispatcher = createElementDispatcher();
    }
    private ElementDispatcher createElementDispatcher()
    {
        try
        {
            URL rulesURL = ElementDispatcher.class.getResource("ElementDispatcherRules.xml");
            assert rulesURL != null;
            Digester digester = DigesterLoader.createDigester(rulesURL);
            URL filterURL;
            filterURL = FeatureDgnConvertPostGISJobContext.class.getResource("/conf/DefaultConvertShpFilter.xml");
            assert filterURL != null;
            return (ElementDispatcher) digester.parse(filterURL);
        } catch (UnsupportedEncodingException e)
        {
            logger.info(e.getMessage(), e);
            throw new RuntimeException(e.getMessage(), e);
        } catch (MalformedURLException e)
        {
            logger.info(e.getMessage(), e);
            throw new RuntimeException(e.getMessage(), e);
        } catch (IOException e)
        {
            logger.info(e.getMessage(), e);
            throw new RuntimeException(e.getMessage(), e);
        } catch (SAXException e)
        {
            logger.info(e.getMessage(), e);
            throw new RuntimeException(e.getMessage(), e);
        }
    }
    public void run()
    {
        File dataDir = new File(dataConfig.get("DATAPATH"));
        if ((!dataDir.exists()) || (!dataDir.isDirectory()))
        {
            return;
        }
        File[] dataFiles = dataDir.listFiles(new FilenameFilter() {
            public boolean accept(File dir, String name)
            {
                return name.toLowerCase().endsWith(".dgn");
            }
        });
        for (File dataFile : dataFiles)
        {
            try
            {
                FileInputStream fs = new FileInputStream(dataFile);
                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)
                            {
                                processFeatureElement(lastComplex);
                                lastComplex = null;
                            }
                            processFeatureElement(element);
                        } else if (element.isComponentElement())
                        {
                            if (lastComplex != null)
                            {
                                ((ComplexElement) lastComplex).add(element);
                            }
                        } else if (type.isComplexElement())
                        {
                            if (lastComplex != null)
                            {
                                processFeatureElement(lastComplex);
                            }
                            lastComplex = element;
                        }
                    }
                    count++;
                }
                if (lastComplex != null)
                {
                    processFeatureElement(lastComplex);
                }
                logger.debug("ElementRecord Count=" + count);
            } catch (Dgn7fileException e)
            {
                logger.warn(e.getMessage(), e);
            } catch (FileNotFoundException e)
            {
                logger.warn(e.getMessage(), e);
            } catch (IOException e)
            {
                logger.warn(e.getMessage(), e);
            }
        }
        postProcessFeatureContext();
    }
    private void processFeatureElement(Element element)
    {
        if (element == null)
        {
            logger.warn("Unknown Element:" + null);
            return;
        }
        // §PÂ_¬O§_²Å©M±ø¥ó
        Feature feature = elementDispatcher.execute(element);
        if (feature == null)
        {
            FrammeAttributeData linkage =
                    AbstractFLinkageDispatchableFilter.getFeatureLinkage(element);
            logger.warn("Unknown Element:" + element.getElementType().toString() +
                    ":type=" + element.getType() + ":lv=" + element.getLevelIndex() + ":id=" +
                    (linkage == null ? "NULL" : (linkage.getFsc() + "|" + linkage.getComponentID())));
            if (element instanceof ComplexElement)
            {
                ComplexElement complex = (ComplexElement) element;
                logger.warn("----Complex Element size=" + complex.size());
            }
            return;
        }
        featuresContext.put(feature.getFeatureType(), feature);
    }
    private void postProcessFeatureContext()
    {
        if (featuresContext.size() == 0) return;
        for (Object key : featuresContext.keySet())
        {
            List elements = (List) featuresContext.get(key);
        }
    }
}