001    /*
002     * Copyright (c) 2009 The openGion Project.
003     *
004     * Licensed under the Apache License, Version 2.0 (the "License");
005     * you may not use this file except in compliance with the License.
006     * You may obtain a copy of the License at
007     *
008     *     http://www.apache.org/licenses/LICENSE-2.0
009     *
010     * Unless required by applicable law or agreed to in writing, software
011     * distributed under the License is distributed on an "AS IS" BASIS,
012     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
013     * either express or implied. See the License for the specific language
014     * governing permissions and limitations under the License.
015     */
016    package org.opengion.plugin.io;
017    
018    import java.io.BufferedReader;
019    import java.io.IOException;
020    import java.io.InputStream;
021    import java.util.ArrayList;
022    import java.util.List;
023    import java.util.zip.ZipEntry;
024    import java.util.zip.ZipFile;
025    
026    import javax.xml.parsers.DocumentBuilder;
027    import javax.xml.parsers.DocumentBuilderFactory;
028    import javax.xml.parsers.ParserConfigurationException;
029    
030    import org.opengion.fukurou.util.StringUtil;
031    import org.opengion.fukurou.util.Closer;                        // 5.5.2.6 (2012/05/25)
032    import org.opengion.hayabusa.common.HybsSystem;
033    import org.opengion.hayabusa.common.HybsSystemException;
034    import org.opengion.hayabusa.db.DBTableModelUtil;
035    import org.w3c.dom.Document;
036    import org.w3c.dom.Element;
037    import org.w3c.dom.NodeList;
038    import org.xml.sax.SAXException;
039    
040    /**
041     * XMLパã?サã«ã‚ˆã‚‹ã€OpenOffice.org Calcã®è¡¨è¨ˆç®—ドキュメントファイルを読ã¿å–る実è£?‚¯ãƒ©ã‚¹ã§ã™ã?
042     *
043     * â‘?‚«ãƒ©ãƒ?ãŒæŒ‡å®šã•れã¦ã?‚‹å ´å?
044     *  #NAMEã§å§‹ã¾ã‚‹è¡Œã‚’検索ã—ã?ãã?行ã?ãれãžã‚Œã®å€¤ã‚’カラãƒ?ã¨ã—ã¦å‡¦ç?—ã¾ã™ã?
045     *  #NAMEã§å§‹ã¾ã‚‹è¡Œã‚ˆã‚Šä»¥å‰ã?行ã«ã¤ã?¦ã¯ã€å?ã¦ç„¡è¦–ã•れã¾ã™ã?
046     *  ã¾ãŸã?#NAMEよりå‰ã?カラãƒ?Šã³ã€?NAMEã®è¡Œã?値ãŒNULL(カラãƒ?ãŒè¨­å®šã•れã¦ã?ªã?カラãƒ?‚‚
047     *  無視ã—ã¾ã™ã?
048     *  読ã¿é£›ã?ã•れãŸã‚«ãƒ©ãƒ??ã«å…¥åŠ›ã•れãŸå€¤ã¯å–り込ã¾ã‚Œã¾ã›ã‚“ã€?
049     *  ã¾ãŸã?#NAME行以é™ã?#ã§å§‹ã¾ã‚‹è¡Œã?ã€ã‚³ãƒ¡ãƒ³ãƒˆè¡Œã¨ã¿ãªã•れ処ç?•れã¾ã›ã‚“ã€?
050     *
051     * ②カラãƒ?ãŒæŒ‡å®šã•れã¦ã?‚‹å ´å?
052     *  æŒ?®šã•れãŸã‚«ãƒ©ãƒ?ã«åŸºã¥ãã?値をå–り込ã¿ã¾ã™ã?
053     *  カラãƒ?ã®é ?•ªã¨ã€ã‚·ãƒ¼ãƒˆã«è¨˜è¿°ã•れã¦ã?‚‹å€¤ã®é ?•ªã¯ä¸??ã—ã¦ã?‚‹å¿?¦ãŒã‚りã¾ã™ã?
054     *  æŒ?®šã•れãŸã‚«ãƒ©ãƒ?•°ã‚’è¶?ˆã‚‹å?ã®å€¤ã«ã¤ã?¦ã¯å…¨ã¦ç„¡è¦–ã•れã¾ã™ã?
055     *  #ã§å§‹ã¾ã‚‹è¡Œã?ã€ã‚³ãƒ¡ãƒ³ãƒˆè¡Œã¨ã¿ãªã•れ処ç?•れã¾ã›ã‚“ã€?
056     *
057     * ã¾ãŸã?ã?šã‚Œã?å ´åˆã‚‚å…¨ãデータãŒå­˜åœ¨ã—ã¦ã?ªã?¡Œã?読ã¿é£›ã?ã•れã¾ã™ã?
058     *
059     * @og.group ファイル入�
060     *
061     * @version 4.0
062     * @author Hiroki Nakamura
063     * @since JDK5.0,
064     */
065    public class TableReader_Calc extends TableReader_Default {
066            // * ã“ã?プログラãƒ??VERSIONæ–?­—å?を設定ã—ã¾ã™ã? {@value} */
067            private static final String VERSION = "5.5.7.2 (2012/10/09)";
068    
069            private String          sheetName               = null;
070            private String          sheetNos                = null;         // 5.5.7.2 (2012/10/09)
071            private String          filename                = null;
072            private int                     numberOfRows    = 0;
073            private int                     firstClmIdx             = 0;
074            private int[]           valueClmIdx             = null;
075    
076            /**
077             * DBTableModel ã‹ã‚‰ å?½¢å¼ã?ãƒ??タを作æ?ã—ã¦,BufferedReader より読ã¿å–りã¾ã™ã?
078             * コメンãƒ?空行を除ãã?æœ??ã®è¡Œã?ã€??ç›®åãŒå¿?¦ã§ã™ã?
079             * (ä½?—ã€ã‚«ãƒ©ãƒ?を指定ã™ã‚‹ã“ã¨ã§ã€??ç›®åã‚’çœç•¥ã™ã‚‹ã“ã¨ãŒã§ãã¾ã?
080             * ãれ以é™ã?ã€ã‚³ãƒ¡ãƒ³ãƒ?空行を除ãã?ãƒ??ã‚¿ã¨ã—ã¦èª­ã¿è¾¼ã‚“ã§ã?ã¾ã™ã?
081             * ã“ã?メソãƒ?ƒ‰ã¯ã€Calc 読ã¿è¾¼ã¿æ™‚ã«ä½¿ç”¨ã—ã¾ã™ã?
082             *
083             * @og.rev 4.3.5.0 (2009/02/01) toArray ã™ã‚‹ã¨ãã«ã€ã‚µã‚¤ã‚ºã®åˆæœŸå€¤æŒ?®šã‚’追åŠ?
084             * @og.rev 5.5.7.2 (2012/10/09) sheetNos 追åŠ?«ã‚ˆã‚‹è¤?•°ã‚·ãƒ¼ãƒˆã?マã?ジ読ã¿å–りサãƒã?ãƒ?
085             *
086             * @see #isExcel()
087             */
088            @Override
089            public void readDBTable() {
090    
091                    ZipFile zipFile = null;
092                    boolean errFlag = false;        // 5.0.0.1 (2009/08/15) finally ブロãƒ?‚¯ã® throw ã‚’é¿ã‘ã‚‹ã€?
093                    try {
094                            // OpenOffice.org odsファイルを開ã?
095                            zipFile = new ZipFile( filename );
096    
097                            ZipEntry entry = zipFile.getEntry( "content.xml" );
098                            if ( null == entry ) {
099                                    String errMsg = "ODSファイル中ã«ãƒ•ァイルcontent.xmlãŒå­˜åœ¨ã—ã¾ã›ã‚“ã€?;
100                                    throw new HybsSystemException( errMsg );
101                            }
102    
103                            // content.xmlをパースã—ã?行ã?列å˜ä½ã?オブジェクトã«åˆ?§£ã—ã¾ã™ã?
104                            DomOdsParser odsParser = new DomOdsParser();
105    //                      odsParser.doParse( zipFile.getInputStream( entry ), sheetName );
106                            odsParser.doParse( zipFile.getInputStream( entry ), sheetName , sheetNos );             // 5.5.7.2 (2012/10/09) sheetNos 対�
107                            List<RowInfo> rowInfoList = odsParser.getRowInfoList();
108    
109                            // 4.3.5.0 (2009/02/01) toArray ã™ã‚‹ã¨ãã«ã€ã‚µã‚¤ã‚ºã®åˆæœŸå€¤æŒ?®šã‚’追åŠ?
110    //                      makeDBTableModel( rowInfoList.toArray( new RowInfo[0] ) );
111                            makeDBTableModel( rowInfoList.toArray( new RowInfo[rowInfoList.size()] ) );
112                    }
113                    catch ( IOException ex ) {
114                            String errMsg = "ファイル読込ã¿ã‚¨ãƒ©ãƒ¼[" + filename + "]";
115                            throw new HybsSystemException( errMsg, ex );
116                    }
117                    finally {
118                            // 5.5.2.6 (2012/05/25) fukurou.util.Closer#zipClose( ZipFile ) を利用ã™ã‚‹ã‚ˆã†ã«ä¿®æ­£ã€?
119                            errFlag = ! Closer.zipClose( zipFile );         // OK ã®å ´åˆã?true ãªã®ã§ã€å転ã—ã¦ãŠãã€?
120    //                      if ( null != zipFile ) {
121    //                              try {
122    //                                      zipFile.close();
123    //                              }
124    //                              catch ( IOException ex ) {
125    //                                      errFlag = true;
126    //                              }
127    //                      }
128                    }
129    
130                    if( errFlag ) {
131                            String errMsg = "ODSファイルã®ã‚¯ãƒ­ãƒ¼ã‚ºä¸­ã«ã‚¨ãƒ©ãƒ¼ãŒç™ºç”Ÿã—ã¾ã—ãŸ[" + filename + "]";
132                            throw new HybsSystemException ( errMsg );
133                    }
134    
135    //              finally {
136    //                      if ( null != zipFile )
137    //                              try {
138    //                                      zipFile.close();
139    //                              }
140    //                              catch ( IOException ex ) {
141    //                                      String errMsg = "ODSファイルã®ã‚¯ãƒ­ãƒ¼ã‚ºä¸­ã«ã‚¨ãƒ©ãƒ¼ãŒç™ºç”Ÿã—ã¾ã—ãŸ[" + filename + "]";
142    //                                      throw new HybsSystemException ( errMsg, ex );
143    //                              }
144    //              }
145            }
146    
147            /**
148             * DBTableModel ã‹ã‚‰ å?½¢å¼ã?ãƒ??タを作æ?ã—ã¦,BufferedReader より読ã¿å–りã¾ã™ã?
149             * ã“ã?メソãƒ?ƒ‰ã¯ã€ã“ã®å®Ÿè£?‚¯ãƒ©ã‚¹ã§ã¯ä½¿ç”¨ã§ãã¾ã›ã‚“ã€?
150             *
151             * @param reader å?½¢å¼ã?ãƒ??ã‚¿(使用ã—ã¦ã?¾ã›ã‚“)
152             */
153            @Override
154            public void readDBTable( final BufferedReader reader ) {
155                    String errMsg = "ã“ã?クラスã§ã¯å®Ÿè£?•れã¦ã?¾ã›ã‚“ã€?;
156                    throw new UnsupportedOperationException( errMsg );
157            }
158    
159            /**
160             * DBTableModelã®ãƒ??ã‚¿ã¨ã—ã¦Calcファイルを読ã¿è¾¼ã‚?¨ãã?シートåを設定ã—ã¾ã™ã?
161             * ã“れã«ã‚ˆã‚Šã€è¤?•°ã®å½¢å¼ã?ç•°ãªã‚‹ãƒ‡ãƒ¼ã‚¿ã‚’é?次読ã¿è¾¼ã‚?“ã¨ã‚??シートをæŒ?®šã—ã¦
162             * 読ã¿å–ã‚‹ã“ã¨ãŒå¯èƒ½ã«ãªã‚Šã¾ã™ã?
163             * sheetNos 㨠sheetName ãŒåŒæ™‚ã«æŒ?®šã•れãŸå ´åˆã?ã€sheetNos ãŒå„ªå…ˆã•れã¾ã™ã?エラーã«ã¯ãªã‚‰ãªã??ã§ã”注æ„ãã?•ã??
164             * ã®ã§ã”注æ„ãã?•ã??
165             *
166             * @param sheetName シートå
167             */
168            @Override
169            public void setSheetName( final String sheetName ) {
170                    this.sheetName = sheetName;
171            }
172    
173            /**
174             * Calcファイルを読ã¿è¾¼ã‚?¨ãã?シート番å·ã‚’指定ã—ã¾ã?åˆæœŸå€¤:0)ã€?
175             *
176             * Calc読ã¿è¾¼ã¿æ™‚ã«è¤?•°ã‚·ãƒ¼ãƒˆã‚’マã?ジã—ã¦å–り込ã¿ã¾ã™ã?
177             * シート番å·ã¯ã€? ã‹ã‚‰å§‹ã¾ã‚‹æ•°å­—ã§è¡¨ã—ã¾ã™ã?
178             * ヘッãƒ??ã¯ã€æœ€åˆã?シートã?カラãƒ?½ç½®ã«åˆã‚ã›ã¾ã™ã??ˆã?ãƒ?ƒ€ãƒ¼ã‚¿ã‚¤ãƒˆãƒ«ã®è‡ªå‹•èªè­˜ã?ã‚りã¾ã›ã‚“。ï¼?
179             * よã£ã¦ã€æŒ‡å®šã™ã‚‹ã‚·ãƒ¼ãƒˆã?ã€ã™ã¹ã¦åŒä¸?ƒ¬ã‚¤ã‚¢ã‚¦ãƒˆã§ãªã?¨å–ã‚Šè¾¼ã¿æ™‚ã«ã‚«ãƒ©ãƒ??ãšã‚ŒãŒç™ºç”Ÿã—ã¾ã™ã?
180             * 
181             * シート番å·ã®æŒ?®šã?ã€ã‚«ãƒ³ãƒžåŒºåˆ?‚Šã§ã€è¤?•°æŒ?®šã§ãã¾ã™ã?ã¾ãŸã?N-M ã®æ§˜ã«ãƒã‚¤ãƒ•ンã§ç¹‹ã’ã‚‹ã“ã¨ã§ã€?
182             * N 番ã‹ã‚‰ã€M 番ã®ã‚·ãƒ¼ãƒˆç¯?›²ã‚’ä¸?‹¬æŒ?®šå¯èƒ½ã§ã™ã?ã¾ãŸã?"*" ã«ã‚ˆã‚‹ã€å?シート指定ãŒå¯èƒ½ã§ã™ã?
183             * ã“れらã?çµ?¿åˆã‚ã›ã‚‚å¯èƒ½ã§ã™ã???0,1,3,5-8,10-* ??
184             * ãŸã ã—ã?"*" ã«é–¢ã—ã¦ã¯ä¾‹å¤–çš„ã«ã€ä¸?–‡å­—ã ã‘ã§ã€ã™ã¹ã¦ã®ã‚·ãƒ¼ãƒˆã‚’表ã™ã‹ã€N-* ã‚’æœ€å¾Œã«æŒ?®šã™ã‚‹ã‹ã®
185             * ã©ã¡ã‚‰ã‹ã§ã™ã?途中ã«ã¯ã€?*" ã¯ã€ç¾ã‚Œã¾ã›ã‚“ã€?
186             * シート番å·ã¯ã€?‡è¤?1,1,2,2)ã€??転(3,2,1) ã§ã®æŒ?®šãŒå¯èƒ½ã§ã™ã?ã“れã¯ã€ãã®æŒ?®šé?ã§ã€èª­ã¿è¾¼ã¾ã‚Œã¾ã™ã?
187             * sheetNos 㨠sheetName ãŒåŒæ™‚ã«æŒ?®šã•れãŸå ´åˆã?ã€sheetNos ãŒå„ªå…ˆã•れã¾ã™ã?エラーã«ã¯ãªã‚‰ãªã??ã§ã”注æ„ãã?•ã??
188             * ã“ã?メソãƒ?ƒ‰ã¯ã€isExcel() == true ã®å ´åˆã?ã¿åˆ©ç”¨ã•れã¾ã™ã?
189             * 
190             * åˆæœŸå€¤ã¯ã€??ˆç¬¬ä¸?‚·ãƒ¼ãƒˆï¼?ã§ã™ã?
191             *
192             * ※ ã“ã?クラスã§ã¯å®Ÿè£?•れã¦ã?¾ã›ã‚“ã€?
193             *
194             * @og.rev 5.5.7.2 (2012/10/09) æ–°è¦è¿½åŠ?
195             *
196             * @param   sheetNos Calcファイルã®ã‚·ãƒ¼ãƒˆç•ªå·??ã‹ã‚‰å§‹ã¾ã‚‹ï¼?
197             * @see         #setSheetName( String ) 
198             */
199            @Override
200            public void setSheetNos( final String sheetNos ) {
201                    this.sheetNos = sheetNos;
202            }
203    
204            /**
205             * ã“ã?クラスãŒã?EXCEL対応機è?ã‚’æŒã£ã¦ã?‚‹ã‹ã©ã?‹ã‚’è¿”ã—ã¾ã™ã?
206             *
207             * EXCEL対応機è?ã¨ã¯ã€ã‚·ãƒ¼ãƒˆåã®ã‚»ãƒ?ƒˆã€èª­ã¿è¾¼ã¿å…?ƒ•ァイル㮠Fileオブジェクトå–å¾—ãªã©ã®ã€ç‰¹æ®Šæ©Ÿè?ã§ã™ã?
208             * 本æ¥ã¯ã€ã‚¤ãƒ³ã‚¿ãƒ¼ãƒ•ェースをå?ã‘ã‚‹ã¹ãã¨è€?ˆã¾ã™ãŒã€taglib クラス等ã? 関係ãŒã‚りã€å•ã?ˆã‚ã›ã«ã‚ˆã‚‹æ¡ä»¶åˆ?²ã§å¯¾å¿œã—ã¾ã™ã?
209             *
210             * @return      EXCEL対応機è?ã‚’æŒã£ã¦ã?‚‹ã‹ã©ã?‹(常ã«true)
211             */
212            @Override
213            public boolean isExcel() {
214                    return true;
215            }
216    
217            /**
218             * 読ã¿å–りå…?ƒ•ァイルåã‚’ã‚»ãƒ?ƒˆã—ã¾ã™ã?(DIR + Filename) ã“れã¯ã€OpenOffice.org
219             * Calc追åŠ?©Ÿè?ã¨ã—ã¦å®Ÿè£?•れã¦ã?¾ã™ã?
220             *
221             * @param filename 読ã¿å–りå…?ƒ•ァイルå?
222             */
223            @Override
224            public void setFilename( final String filename ) {
225                    this.filename = filename;
226                    if ( filename == null ) {
227                            String errMsg = "ファイルåãŒæŒ?®šã•れã¦ã?¾ã›ã‚“ã€?;
228                            throw new HybsSystemException( errMsg );
229                    }
230            }
231    
232            /**
233             * ODSファイルをパースã—ãŸçµæžœã‹ã‚‰DBTableModelを生æˆã—ã¾ã™ã?
234             *
235             * @og.rev 5.1.6.0 (2010/05/01) skipRowCountã®è¿½åŠ?
236             *
237             * @param rowInfoList 行オブジェクトã?é…å?
238             */
239            private void makeDBTableModel( final RowInfo[] rowInfoList ) {
240                    // カラãƒ?ãŒæŒ‡å®šã•れã¦ã?‚‹å ´åˆã?ã€å„ªå…ˆã™ã‚‹ã?
241                    if( columns != null && columns.length() > 0 ) {
242                            makeHeaderFromClms();
243                    }
244    
245    //              for( RowInfo rowInfo : rowInfoList ) {
246                    int skip = getSkipRowCount();                                           // 5.1.6.0 (2010/05/01)
247                    for( int row=skip; row<rowInfoList.length; row++ ) {
248                            RowInfo rowInfo = rowInfoList[row];                             // 5.1.6.0 (2010/05/01)
249                            if( valueClmIdx == null ) {
250                                    makeHeader( rowInfo );
251                            }
252                            else {
253                                    makeBody( rowInfo );
254                            }
255                    }
256    
257                    // æœ?¾Œã¾ã§ã€?NAME ãŒè¦‹ã¤ã‹ã‚‰ç„¡ã‹ã£ãŸå?å?
258                    if ( valueClmIdx == null ) {
259                            String errMsg = "æœ?¾Œã¾ã§ã€?NAME ãŒè¦‹ã¤ã‹ã‚Šã¾ã›ã‚“ã§ã—ãŸã€? + HybsSystem.CR + "ファイルãŒç©ºã‹ã?ã‚‚ã—ãã?æå‚·ã—ã¦ã?‚‹å¯èƒ½æ€§ãŒã‚りã¾ã™ã?" + HybsSystem.CR;
260                            throw new HybsSystemException( errMsg );
261                    }
262            }
263    
264            /**
265             * æŒ?®šã•れãŸã‚«ãƒ©ãƒ?¸?¦§ã‹ã‚‰ãƒ˜ãƒƒãƒ??æƒ??を生æˆã—ã¾ã™ã?
266             *
267             * @og.rev 5.1.6.0 (2010/05/01) useNumber ã®è¿½åŠ?
268             */
269            private void makeHeaderFromClms() {
270                    table = DBTableModelUtil.newDBTable();
271                    String[] names = StringUtil.csv2Array( columns );
272                    table.init( names.length );
273                    setTableDBColumn( names ) ;
274                    valueClmIdx = new int[names.length];
275                    int adrs = (isUseNumber()) ? 1:0 ;      // useNumber =true ã®å ´åˆã?ã€?¼‘ä»¶ç›®(No)ã¯èª­ã¿é£›ã?ã™ã?
276                    for( int i=0; i<names.length; i++ ) {
277    //                      valueClmIdx[i] = i;
278                            valueClmIdx[i] = adrs++;
279                    }
280            }
281    
282            /**
283             * ヘッãƒ??æƒ??を読ã¿å–りã€DBTableModelã®ã‚ªãƒ–ジェクトを新è¦ã«ä½œæ?ã—ã¾ã™ã?
284             * ※ ä»–ã?TableReaderã¨ç•°ãªã‚Šã?#NAME ãŒè¦‹ã¤ã‹ã‚‹ã¾ã§ã€èª­ã¿é£›ã?ã™ã?
285             *
286             * @og.rev 4.3.5.0 (2009/02/01) toArray ã™ã‚‹ã¨ãã«ã€ã‚µã‚¤ã‚ºã®åˆæœŸå€¤æŒ?®šã‚’追åŠ?
287             *
288             * @param rowInfo 行オブジェク�
289             */
290            private void makeHeader( final RowInfo rowInfo ) {
291    //              int rowRepeat = rowInfo.rowRepeat;
292                    CellInfo[] cellInfos = rowInfo.cellInfos;
293    
294                    int cellLen = cellInfos.length;
295                    int runPos = 0;
296                    ArrayList<String> nameList = null;
297                    ArrayList<Integer> posList = null;
298                    for ( int idx = 0; idx < cellLen; idx++ ) {
299                            // ãƒ??ブルã®ãƒ˜ãƒƒãƒ?#NAME)ãŒè¦‹ã¤ã‹ã‚‹å‰ã?行ã?列ã?å…¨ã¦ç„¡è¦–ã•れる
300                            CellInfo cellInfo = cellInfos[idx];
301                            String text = cellInfo.text.trim();
302    
303                            for ( int cellRep = 0; cellRep < cellInfo.colRepeat; cellRep++ ) {
304                                    // 空白ã®ãƒ˜ãƒƒãƒ??ç„¡è¦?ãã?列ã«ãƒ??ã‚¿ãŒå?ã£ã¦ã?¦ã‚‚読ã¾ãªã?
305                                    if ( text.length() != 0 ) {
306                                            if ( firstClmIdx == 0 && text.equalsIgnoreCase( "#NAME" ) ) {
307                                                    nameList = new ArrayList<String>();
308                                                    posList = new ArrayList<Integer>();
309                                                    table = DBTableModelUtil.newDBTable();
310                                                    firstClmIdx = idx;
311                                            }
312                                            else if ( nameList != null ) {
313                                                    nameList.add( text );
314                                                    posList.add( runPos );
315                                            }
316                                    }
317                                    runPos++;
318                            }
319                    }
320    
321    //              if ( posList != null && posList.size() > 0 ) {
322                    if ( posList != null && ! posList.isEmpty() ) {
323                            table = DBTableModelUtil.newDBTable();
324    //                      String[] names = nameList.toArray( new String[0] );
325    //                      table.init( names.length );
326                            // 4.3.5.0 (2009/02/01) サイズã®åˆæœŸå€¤æŒ?®?
327                            int size = nameList.size();
328                            String[] names = nameList.toArray( new String[size] );
329                            table.init( size );
330                            setTableDBColumn( names );
331    
332                            valueClmIdx = new int[posList.size()];
333                            for( int i = 0; i<posList.size(); i++ ) {
334                                    valueClmIdx[i] = posList.get( i ).intValue();
335                            }
336                    }
337            }
338    
339            /**
340             * 行ã?åˆ?セル)å˜ä½ã?æƒ??を読ã¿å–りã€DBTableModelã«å€¤ã‚’ã‚»ãƒ?ƒˆã—ã¾ã?
341             *
342             * @og.rev 5.2.1.0 (2010/10/01) setTableColumnValues メソãƒ?ƒ‰ã‚’経由ã—ã¦ã€ãƒ†ãƒ¼ãƒ–ルã«ãƒ??ã‚¿ã‚’ã‚»ãƒ?ƒˆã™ã‚‹ã€?
343             *
344             * @param rowInfo 行オブジェク�
345             */
346            private void makeBody( final RowInfo rowInfo ) {
347                    int rowRepeat = rowInfo.rowRepeat;
348                    CellInfo[] cellInfos = rowInfo.cellInfos;
349                    int cellLen = cellInfos.length;
350                    boolean isExistData = false;
351    
352                    List<String> colData = new ArrayList<String>();
353                    for ( int cellIdx = 0; cellIdx < cellLen; cellIdx++ ) {
354                            CellInfo cellInfo = cellInfos[cellIdx];
355                            for ( int cellRep = 0; cellRep < cellInfo.colRepeat; cellRep++ ) {
356                                    colData.add( cellInfo.text );
357                                    if( cellInfo.text.length() > 0 ) {
358                                            isExistData = true;
359                                    }
360                            }
361                    }
362    
363                    if( isExistData ) {
364                            // åˆã‚ã®åˆ?#NAMEãŒè¨˜è¿°ã•れã¦ã?Ÿåˆ?ã®å€¤ã?ã§å§‹ã¾ã£ã¦ã?‚‹å ´åˆã?ã€ã‚³ãƒ¡ãƒ³ãƒˆè¡Œã¨ã¿ãªã™ã?
365                            String firstVal = colData.get( firstClmIdx );
366                            if( firstVal.length() > 0 && firstVal.startsWith( "#" ) ) {
367                                    return;
368                            }
369                            else {
370                                    String[] vals = new String[valueClmIdx.length];
371                                    for( int col = 0; col < valueClmIdx.length; col++ ) {
372                                            vals[col] = colData.get( valueClmIdx[col] );
373                                    }
374    
375                                    // é‡è¤?¡Œã?繰り返ã—処ç?
376                                    for ( int rowIdx = 0; rowIdx < rowRepeat; rowIdx++ ) {
377                                            // ãƒ??ブルモãƒ?ƒ«ã«ãƒ??ã‚¿ã‚’ã‚»ãƒ?ƒˆ
378                                            if ( numberOfRows < getMaxRowCount() ) {
379                                                    setTableColumnValues( vals );           // 5.2.1.0 (2010/10/01)
380    //                                              table.addColumnValues( vals );
381                                                    numberOfRows++;
382                                            }
383                                            else {
384                                                    table.setOverflow( true );
385                                            }
386                                    }
387                            }
388                    }
389                    // å…¨ãデータãŒå­˜åœ¨ã—ãªã?¡Œã?読ã¿é£›ã?ã?
390                    else {
391                            return;
392                    }
393            }
394    
395            /**
396             * ODSファイルã«å«ã¾ã‚Œã‚‹content.xmlã‚’DOMパã?サーã§ãƒ‘ã?スã—ã?行ã?列å˜ä½ã«
397             * オブジェクトã«å¤‰æ›ã—ã¾ã™ã?
398             *
399             */
400            private static class DomOdsParser{
401    
402                    // OpenOffice.org Calc tag Names
403    //              private static final String OFFICE_DOCUMENT_CONTEBT_ELEM = "office:document-content";
404    //              private static final String OFFICE_SPREADSHEET_ELEM = "office:spreadsheet";
405                    private static final String TABLE_TABLE_ELEM = "table:table";
406    //              private static final String TABLE_TABLE_COLUMN_ELEM = "table:table-column";
407                    private static final String TABLE_TABLE_ROW_ELEM = "table:table-row";
408                    private static final String TABLE_TABLE_CELL_ELEM = "table:table-cell";
409                    private static final String TEXT_P_ELEM = "text:p";
410    
411                    // Sheet tag attributes
412                    private static final String TABLE_NAME_ATTR = "table:name";
413    //              private static final String OFFICE_VALUE_YPE_ATTR = "office:value-type";
414                    private static final String TABLE_NUMBER_ROWS_REPEATED_ATTR = "table:number-rows-repeated";
415                    private static final String TABLE_NUMBER_COLUMNS_REPEATED_ATTR = "table:number-columns-repeated";
416    //              private static final String TABLE_NUMBER_ROWS_SPANNED_ATTR = "table:number-rows-spanned";
417    //              private static final String TABLE_NUMBER_COLUMNS_SPANNED_ATTR = "table:number-columns-spanned";
418    
419    //              ArrayList<RowInfo> rowInfoList = new ArrayList<RowInfo>();
420                    List<RowInfo> rowInfoList = new ArrayList<RowInfo>();
421                    /**
422                     * Domパã?サã§XMLをパースã™ã‚‹
423                     *
424                     * @og.rev 5.5.7.2 (2012/10/09) sheetNos 追åŠ?«ã‚ˆã‚‹è¤?•°ã‚·ãƒ¼ãƒˆã?マã?ジ読ã¿å–りサãƒã?ãƒ?
425                     *
426                     * @param inputStream InputStream
427                     * @param sheetName String
428                     * @param sheetNos  String
429                     */
430    //              public void doParse( final InputStream inputStream, final String sheetName ) {
431                    public void doParse( final InputStream inputStream, final String sheetName, final String sheetNos ) {
432                            try {
433                                    // ドキュメントビル�?ファクトリを生�
434                                    DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
435                                    dbFactory.setNamespaceAware( true );
436    
437                                    // ドキュメントビル�?を生�
438                                    DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
439                                    // パã?スを実行ã—ã¦Documentオブジェクトをå–å¾?
440                                    Document doc = dBuilder.parse( inputStream );
441    //                              processBook( doc, sheetName );
442                                    processBook( doc, sheetName, sheetNos );                        // 5.5.7.2 (2012/10/09) sheetNos 追�
443                            }
444                            catch ( ParserConfigurationException ex ) {
445                                    throw new HybsSystemException( ex );
446                            }
447                            catch ( SAXException ex ) {
448                                    String errMsg = "ODSファイル中ã«å«ã¾ã‚Œã‚‹content.xmlãŒXMLå½¢å¼ã§ã¯ã‚りã¾ã›ã‚“ã€?;
449                                    throw new HybsSystemException( errMsg, ex );
450                            }
451                            catch ( IOException ex ) {
452                                    throw new HybsSystemException( ex );
453                            }
454                    }
455    
456                    /**
457                     * 行オブジェクトã?リストを返ã—ã¾ã™ã?
458                     *
459                     * @return List<RowInfo>
460                     */
461                    public List<RowInfo> getRowInfoList() {
462                            return rowInfoList;
463                    }
464    
465                    /**
466                     * ODSファイル全体ã?パã?スを行ã„ã€å?ç?¯¾è±¡ã¨ãªã‚‹ã‚·ãƒ¼ãƒˆã‚’検索ã—ã¾ã™ã?
467                     *
468                     * @og.rev 5.5.7.2 (2012/10/09) sheetNos 追åŠ?«ã‚ˆã‚‹è¤?•°ã‚·ãƒ¼ãƒˆã?マã?ジ読ã¿å–りサãƒã?ãƒ?
469                     *
470                     * @param doc Document
471                     * @param sheetName String
472                     * @param sheetNos  String
473                     */
474    //              private void processBook( final Document doc, final String sheetName ) {
475                    private void processBook( final Document doc, final String sheetName, final String sheetNos ) {
476                            // table:tableを探ã?
477                            NodeList nodetList = doc.getElementsByTagName( TABLE_TABLE_ELEM );
478                            int listLen = nodetList.getLength();
479    
480    //                      Element sheet = null;
481                            Element[] sheets = null ;                       // 5.5.7.2 (2012/10/09)
482    
483                            // 5.5.7.2 (2012/10/09) è¤?•°ã‚·ãƒ¼ãƒˆã?マã?ジ読ã¿å–りã€?sheetNos ã®æŒ?®šãŒå„ªå…ˆã•れるã€?
484                            if( sheetNos != null && sheetNos.length() > 0 ) {
485                                    String[] sheetList = StringUtil.csv2ArrayExt( sheetNos , listLen-1 );   // æœ?¤§ã‚·ãƒ¼ãƒˆç•ªå·ã¯ã€ã‚·ãƒ¼ãƒˆæ•°-1
486                                    sheets = new Element[sheetList.length];
487                                    for( int i=0; i<sheetList.length; i++ ) {
488                                            sheets[i] = (Element)nodetList.item( Integer.parseInt( sheetList[i] ) );
489                                    }
490                            }
491                            else if( sheetName != null && sheetName.length() > 0 ) {
492                                    Element sheet = null;
493                                    for ( int idx = 0; idx < listLen; idx++ ) {
494                                            Element st = (Element)nodetList.item( idx );
495                                            if ( sheetName.equals( st.getAttribute( TABLE_NAME_ATTR ) ) ) {
496                                                    sheet = st;
497                                                    break;
498                                            }
499                                    }
500                                    if( sheet == null ) {
501                                            String errMsg = "対応ã™ã‚‹ã‚·ãƒ¼ãƒˆãŒå­˜åœ¨ã—ã¾ã›ã‚“ã€?sheetName=[" + sheetName + "]" ;
502                                            throw new HybsSystemException( errMsg );
503                                    }
504                                    sheets = new Element[] { sheet };
505                            }
506                            else {
507                                    Element sheet = (Element)nodetList.item(0);
508                                    sheets = new Element[] { sheet };
509                            }
510    
511    //                      // シート探ã—:シートåãŒã‚れã?ã€ãã®ã¾ã¾ä½¿ç”¨ã€ãªã‘れã°ã€æœ€åˆã?シートを対象ã¨ã—ã¾ã™ã?
512    //                      for ( int idx = 0; idx < listLen; idx++ ) {
513    //                              Element st = (Element)nodetList.item( idx );
514    //                              if ( ( sheetName == null || sheetName.length() == 0 ) || sheetName.equals( st.getAttribute( TABLE_NAME_ATTR ) ) ) {
515    //                                      sheet = st;
516    //                                      break;
517    //                              }
518    //                      }
519                            // æŒ?®šã?シートãŒãªã‘れã°ã€ã‚¨ãƒ©ãƒ¼
520    //                      if ( sheet == null ) {
521                            if ( sheets == null ) {
522                                    String errMsg = "対応ã™ã‚‹ã‚·ãƒ¼ãƒˆãŒå­˜åœ¨ã—ã¾ã›ã‚“ã€?sheetNos=[" + sheetNos + "] or sheetName=[" + sheetName + "]";
523                                    throw new HybsSystemException( errMsg );
524                            }
525                            else {
526    //                              processSheet( sheet );
527                                    // 5.5.7.2 (2012/10/09) è¤?•°ã‚·ãƒ¼ãƒˆã?マã?ジ読ã¿å–りã€?
528                                    for( int i=0; i<sheets.length; i++ ) {
529                                            processSheet( sheets[i] );
530                                    }
531                            }
532                    }
533    
534                    /**
535                     * ODSファイルã®ã‚·ãƒ¼ãƒˆå˜ä½ã?パã?スを行ã„ã€è¡Œå˜ä½ã?オブジェクトを生æ?ã—ã¾ã™ã?
536                     *
537                     * @param sheet Element
538                     */
539                    private void processSheet( final Element sheet ) {
540                            NodeList rows = sheet.getElementsByTagName( TABLE_TABLE_ROW_ELEM );
541                            int listLen = rows.getLength();
542                            int rowRepeat;
543                            for ( int idx = 0; idx < listLen; idx++ ) {
544                                    Element row = (Element)rows.item( idx );
545                                    // 行ã?å†?®¹ãŒå?ãåŒã˜å?åˆã?table:number-rows-repeatedã‚¿ã‚°ã«ã‚ˆã‚Šçœç•¥ã•れるã?
546                                    String repeatStr = row.getAttribute( TABLE_NUMBER_ROWS_REPEATED_ATTR );
547                                    if ( repeatStr == null || repeatStr.length() == 0 ) {
548                                            rowRepeat = 1;
549                                    }
550                                    else {
551                                            rowRepeat = Integer.parseInt( repeatStr, 10 );
552                                    }
553    
554                                    processRow( row, rowRepeat );
555                            }
556                    }
557    
558                    /**
559                     * ODSファイルã®è¡Œå˜ä½ã?パã?スを行ã„ã€ã‚«ãƒ©ãƒ?˜ä½ã?オブジェクトを生æ?ã—ã¾ã™ã?
560                     *
561                     * @og.rev 4.3.5.0 (2009/02/01) toArray ã™ã‚‹ã¨ãã«ã€ã‚µã‚¤ã‚ºã®åˆæœŸå€¤æŒ?®šã‚’追åŠ?
562                     * @og.rev 5.1.8.0 (2010/07/01) セルå†?§æ›¸å¼è¨­å®šã•れã¦ã?‚‹å ´åˆã«ã€ãƒ†ã‚­ã‚¹ãƒˆãƒ‡ãƒ¼ã‚¿ãŒå–å¾—ã•れãªã?ƒã‚°ã‚’修正
563                     *
564                     * @param row Element
565                     * @param rowRepeat int
566                     */
567                    private void processRow( final Element row, final int rowRepeat ) {
568                            NodeList cells = row.getElementsByTagName( TABLE_TABLE_CELL_ELEM );
569                            int listLen = cells.getLength();
570                            int colRepeat;
571                            String cellText;
572                            ArrayList<CellInfo> cellInfoList = new ArrayList<CellInfo>();
573                            for ( int idx = 0; idx < listLen; idx++ ) {
574                                    Element cell = (Element)cells.item( idx );
575                                    // カラãƒ??å†?®¹ãŒå?ãåŒã˜å?åˆã?table:number-columns-repeatedã‚¿ã‚°ã«ã‚ˆã‚Šçœç•¥ã•れるã?
576                                    String repeatStr = cell.getAttribute( TABLE_NUMBER_COLUMNS_REPEATED_ATTR );
577                                    if ( repeatStr == null || repeatStr.length() == 0 ) {
578                                            colRepeat = 1;
579                                    }
580                                    else {
581                                            colRepeat = Integer.parseInt( repeatStr, 10 );
582                                    }
583    
584                                    // text:p
585                                    NodeList texts = cell.getElementsByTagName( TEXT_P_ELEM );
586                                    if ( texts.getLength() == 0 ) {
587                                            cellText = "";
588                                    }
589                                    else {
590                                            // 5.1.8.0 (2010/07/01) セルå†?§æ›¸å¼è¨­å®šã•れã¦ã?‚‹å ´åˆã«ã€ãƒ†ã‚­ã‚¹ãƒˆãƒ‡ãƒ¼ã‚¿ãŒå–å¾—ã•れãªã?ƒã‚°ã‚’修正
591    //                                      StringBuilder sb = new StringBuilder();
592    //                                      NodeList textElems = texts.item( 0 ).getChildNodes();
593    //                                      int textElemLen = textElems.getLength();
594    //                                      for ( int idxt = 0; idxt < textElemLen; idxt++ ) {
595    //                                              Node textElem = textElems.item( idxt );
596    //                                              if ( textElem.getNodeType() == Node.TEXT_NODE ) {
597    //                                                      sb.append( textElem.getNodeValue() );
598    //                                              }
599    //                                      }
600    //                                      cellText = sb.toString();
601                                            cellText = texts.item( 0 ).getTextContent();
602                                    }
603                                    cellInfoList.add( new CellInfo( colRepeat, cellText ) );
604                            }
605    
606    //                      if ( cellInfoList.size() > 0 ) {
607                            if ( ! cellInfoList.isEmpty() ) {
608    //                              rowInfoList.add( new RowInfo( rowRepeat, cellInfoList.toArray( new CellInfo[0] ) ) );
609                                    // 4.3.5.0 (2009/02/01) toArray ã™ã‚‹ã¨ãã«ã€ã‚µã‚¤ã‚ºã®åˆæœŸå€¤æŒ?®šã‚’追åŠ?
610                                    rowInfoList.add( new RowInfo( rowRepeat, cellInfoList.toArray( new CellInfo[cellInfoList.size()] ) ) );
611                            }
612                    }
613            }
614    
615            /**
616             * ODSファイルã®è¡Œæƒ…å ±ã‚’è¡¨ã™æ§‹é?ä½?
617             */
618            private static final class RowInfo {
619                    public final int rowRepeat;
620                    public final CellInfo[] cellInfos;
621    
622                    RowInfo( final int rep, final CellInfo[] cell ) {
623                            rowRepeat = rep;
624                            cellInfos = cell;
625                    }
626            }
627    
628            /**
629             * ODSファイルã®ã‚«ãƒ©ãƒ?ƒ…å ±ã‚’è¡¨ã™æ§‹é?ä½?
630             */
631            private static final class CellInfo {
632                    public final int colRepeat;
633                    public final String text;
634    
635                    CellInfo( final int rep, final String tx ) {
636                            colRepeat = rep;
637                            text = tx;
638                    }
639            }
640    }