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 */
016package org.opengion.plugin.io;
017
018import org.odftoolkit.odfdom.OdfFileDom;
019import org.odftoolkit.odfdom.doc.table.OdfTableCell;
020import org.odftoolkit.odfdom.dom.element.office.OfficeAnnotationElement;
021import org.odftoolkit.odfdom.dom.element.text.TextPElement;
022import org.opengion.hayabusa.db.DBColumn;
023
024/**
025 * Calcファイルの書き出しクラスです。
026 *
027 * このクラスでは、通常の出力クラスと異なり、以下のように出力されます。
028 *  ①データ部分には、X(文字側)または9(数値型)をリソース定義の桁数分出力
029 *  ②各セルのコメント情報として{@ANO.カラム名_行番号}を出力
030 *
031 * この出力結果は、通常、Calc帳票システムの雛形を作成するための、元情報として
032 * 利用することを想定しています。
033 *
034 * @og.group ファイル出力
035 *
036 * @version  5.0
037 * @author       Hiroki Nakamura
038 * @since    JDK6.0,
039 */
040public class TableWriter_CalcDefAno extends TableWriter_CalcDef {
041        //* このプログラムのVERSION文字列を設定します。   {@value} */
042        private static final String VERSION = "4.0.0.0 (2005/08/31)" ;
043
044        /**
045         * テキストコンテンツ用のセルを生成する
046         *
047         * @param       contentDom      OdfFileDomオブジェクト
048         * @param       content         コンテンツ
049         * @param       col                     DBColumnオブジェクト
050         * @param       isCellTypeNumber        [true:数字型/false:文字型]
051         * @param       isNumberList            [true:数字リスト=999/false:通常]
052         *
053         * @return      テキストコンテンツ用のセル
054         */
055        @Override
056        protected OdfTableCell createTextCell( final OdfFileDom contentDom, final String content, final DBColumn col, final Boolean isCellTypeNumber, final Boolean isNumberList ) {
057                String val = null;
058                if( isNumberList ) { val = "999"; }
059                else {
060                        StringBuilder buf = new StringBuilder();
061                        int sizeX = col.getSizeX();
062                        int sizeY = col.getSizeY();
063                        String fillStr = isCellTypeNumber ? "9" : "X";
064                        for( int i=0; i<sizeX; i++ ) {
065                                buf.append( fillStr );
066                        }
067                        if( sizeY > 0 ) {
068                                buf.append( "." );
069                                for( int i=0; i<sizeY; i++ ) {
070                                        buf.append( fillStr );
071                                }
072                        }
073                        val = buf.toString();
074                }
075
076                OdfTableCell cell = super.createTextCell( contentDom, val, isCellTypeNumber, isNumberList );
077                OfficeAnnotationElement anotation = cell.newOfficeAnnotationElement();
078                TextPElement text = anotation.newTextPElement();
079                text.setTextContent( "{@ANO." + content + "}" );
080
081                return cell;
082        }
083}