From 0ffea4eece9090db61ff0042ac26a6cb2a356cab Mon Sep 17 00:00:00 2001
From: ?? ? <ulysseskao@ximple.com.tw>
Date: Tue, 06 May 2008 16:28:31 +0800
Subject: [PATCH] update for EOFM-73

---
 xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/jobs/OracleConvertDgn2ShpJob.java |  293 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 292 insertions(+), 1 deletions(-)

diff --git a/xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/jobs/OracleConvertDgn2ShpJob.java b/xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/jobs/OracleConvertDgn2ShpJob.java
index 7cf0442..82b14d9 100644
--- a/xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/jobs/OracleConvertDgn2ShpJob.java
+++ b/xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/jobs/OracleConvertDgn2ShpJob.java
@@ -1,14 +1,21 @@
 package com.ximple.eofms.jobs;
 
 import java.io.IOException;
+import java.io.File;
+import java.io.FilenameFilter;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
 import java.math.BigDecimal;
 import java.nio.ByteBuffer;
 import java.nio.ByteOrder;
+import java.nio.channels.FileChannel;
 import java.sql.ResultSet;
 import java.sql.SQLException;
 import java.sql.Statement;
 import java.sql.Types;
 import java.util.Date;
+import java.util.List;
+import java.util.Iterator;
 
 import org.apache.commons.collections.OrderedMap;
 import org.apache.commons.collections.OrderedMapIterator;
@@ -18,8 +25,11 @@
 import org.quartz.JobDetail;
 import org.quartz.JobExecutionContext;
 import org.quartz.JobExecutionException;
+import org.geotools.feature.IllegalAttributeException;
+import org.geotools.feature.SchemaException;
 
 import com.vividsolutions.jts.geom.GeometryFactory;
+import com.vividsolutions.jts.geom.Envelope;
 
 import oracle.jdbc.OracleConnection;
 import oracle.jdbc.OracleResultSet;
@@ -28,11 +38,21 @@
 
 import com.ximple.eofms.util.BinConverter;
 import com.ximple.eofms.util.ByteArrayCompressor;
+import com.ximple.eofms.util.TPCLIDConverter;
+import com.ximple.eofms.util.StringUtils;
 import com.ximple.io.dgn7.ComplexElement;
 import com.ximple.io.dgn7.Dgn7fileException;
 import com.ximple.io.dgn7.Element;
 import com.ximple.io.dgn7.ElementType;
 import com.ximple.io.dgn7.IElementHandler;
+import com.ximple.io.dgn7.Dgn7fileReader;
+import com.ximple.io.dgn7.Lock;
+import com.ximple.io.dgn7.ComplexChainElement;
+import com.ximple.io.dgn7.ComplexShapeElement;
+import com.ximple.io.dgn7.TextNodeElement;
+import com.ximple.io.dgn7.TextElement;
+import com.ximple.io.dgn7.UserAttributeData;
+import com.ximple.io.dgn7.FrammeAttributeData;
 import com.ximple.util.PrintfFormat;
 
 /**
@@ -104,6 +124,9 @@
                 //close all open filewriter instance
                 jobContext.closeFeatureWrite();
             }
+
+            convertIndexDesignFile(context);
+            convertOtherDesignFile(context);
         } catch (SQLException e)
         {
             logger.warn(e.getMessage(), e);
@@ -115,7 +138,11 @@
         }
     }
 
-    //Connectivity�ƻs�@�Ӫ����A�b�d�߹q�y��V�ɥΨӤ��OMS��Ʈw���q���s����(Connectivity)
+    /**
+     * Connectivity�ƻs�@�Ӫ����A�b�d�߹q�y��V�ɥΨӤ��OMS��Ʈw���q���s����(Connectivity)
+     * @param jobContext
+     * @throws SQLException
+     */
     private void copyConnectivity(OracleConvertJobContext jobContext) throws SQLException
     {
         OracleConnection connection = jobContext.getOracleConnection();
@@ -421,4 +448,268 @@
 
         return dgnElement;
     }
+
+    /**
+     * �����ഫ���޹��ɪ��u�@
+     * @param context �u�@��������
+     */
+    private void convertIndexDesignFile(JobExecutionContext context) throws JobExecutionException
+    {
+        File indexDir = new File(getDataPath(), "index");
+        if (!indexDir.exists())
+        {
+            logger.info("index dir=" + indexDir + " not exist.");
+            return;
+        }
+
+        if (!indexDir.isDirectory())
+        {
+            logger.info("index dir=" + indexDir + " is not a directory.");
+        }
+
+        File[] dgnFiles = indexDir.listFiles(new FilenameFilter()
+        {
+            public boolean accept(File dir, String name)
+            {
+                return name.toLowerCase().endsWith(".dgn");
+            }
+        });
+
+        for (File dgnFile : dgnFiles)
+        {
+            IndexDgnConvertJobContext convertContext = new IndexDgnConvertJobContext(getDataPath());
+            try
+            {
+                convertContext.setExecutionContext(context);
+                String dgnPaths[] = StringUtils.splitToArray(dgnFile.toString(), File.pathSeparator);
+                convertContext.setFilename(dgnPaths[dgnPaths.length - 1]);
+
+                FileInputStream fs = new FileInputStream(dgnFile);
+                FileChannel fc = fs.getChannel();
+                Dgn7fileReader reader = new Dgn7fileReader(fc, new Lock());
+                convertContext.setReader(reader);
+
+                scanIndexDgnElement(convertContext);
+
+                convertContext.commitTransaction();
+            } catch (FileNotFoundException e)
+            {
+                convertContext.rollbackTransaction();
+                logger.warn(e.getMessage(), e);
+                throw new JobExecutionException(e.getMessage(), e);
+            } catch (Dgn7fileException e)
+            {
+                convertContext.rollbackTransaction();
+                logger.warn(e.getMessage(), e);
+                throw new JobExecutionException(e.getMessage(), e);
+            } catch (IOException e)
+            {
+                convertContext.rollbackTransaction();
+                logger.warn(e.getMessage(), e);
+                throw new JobExecutionException(e.getMessage(), e);
+            } catch (IllegalAttributeException e)
+            {
+                convertContext.rollbackTransaction();
+                logger.warn(e.getMessage(), e);
+                throw new JobExecutionException(e.getMessage(), e);
+            } catch (SchemaException e)
+            {
+                convertContext.rollbackTransaction();
+                logger.warn(e.getMessage(), e);
+                throw new JobExecutionException(e.getMessage(), e);
+            }
+        }
+    }
+
+    protected void scanIndexDgnElement(IndexDgnConvertJobContext convertContext)
+            throws Dgn7fileException, IOException, IllegalAttributeException, SchemaException
+    {
+        Dgn7fileReader reader = convertContext.getReader();
+        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()))
+                {
+                    lastComplex = null;
+
+                    processElement(element, convertContext);
+                } else if (element.isComponentElement())
+                {
+                    if (lastComplex != null)
+                    {
+                        ((ComplexElement) lastComplex).add(element);
+                    }
+                } else if (type.isComplexElement())
+                {
+                    if (lastComplex == null)
+                    {
+                        lastComplex = element;
+                    } else
+                    {
+                        processElement(element, convertContext);
+                        lastComplex = element;
+                    }
+                }
+            }
+            count++;
+        }
+
+        logger.debug("ElementRecord Count=" + count);
+    }
+
+    private void processElement(Element element, IndexDgnConvertJobContext convertContext) throws IllegalAttributeException, SchemaException
+    {
+        if (element instanceof TextElement)
+        {
+            convertContext.putFeatureCollection(element);
+        }
+    }
+
+
+    /**
+     * �����ഫ��L�]�p���ɪ��u�@
+     * @param context
+     */
+    private void convertOtherDesignFile(JobExecutionContext context)
+    {
+        File otherDir = new File(getDataPath(), "other");
+        if (!otherDir.exists())
+        {
+            logger.info("index dir=" + otherDir + " not exist.");
+            return;
+        }
+
+        if (!otherDir.isDirectory())
+        {
+            logger.info("index dir=" + otherDir + " is not a directory.");
+        }
+
+        File[] dgnFiles = otherDir.listFiles(new FilenameFilter()
+        {
+            public boolean accept(File dir, String name)
+            {
+                return name.toLowerCase().endsWith(".dgn");
+            }
+        });
+
+        for (File dgnFile : dgnFiles)
+        {
+            GeneralDgnConvertJobContext convertContext = new GeneralDgnConvertJobContext(getDataPath());
+            convertContext.setExecutionContext(context);
+        }
+    }
+
+    public void scanOtherDgnElement(GeneralDgnConvertJobContext convertContext) throws Dgn7fileException, IOException
+    {
+        Dgn7fileReader reader = convertContext.getReader();
+        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);
+    }
 }

--
Gitblit v0.0.0-SNAPSHOT