KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > fop > render > rtf > rtflib > rtfdoc > RtfListTable


1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */

17
18 /* $Id: RtfListTable.java 426576 2006-07-28 15:44:37Z jeremias $ */
19
20 package org.apache.fop.render.rtf.rtflib.rtfdoc;
21
22 /*
23  * This file is part of the RTF library of the FOP project, which was originally
24  * created by Bertrand Delacretaz <bdelacretaz@codeconsult.ch> and by other
25  * contributors to the jfor project (www.jfor.org), who agreed to donate jfor to
26  * the FOP project.
27  */

28
29 import java.util.LinkedList JavaDoc;
30 import java.util.Iterator JavaDoc;
31 import java.io.Writer JavaDoc;
32 import java.io.IOException JavaDoc;
33 //import org.apache.fop.render.rtf.rtflib.jfor.main.JForVersionInfo;
34

35 /**
36  * RtfListTable: used to make the list table in the header section of the RtfFile.
37  * This is the method that Word uses to make lists in RTF and the way most RTF readers,
38  * esp. Adobe FrameMaker read lists from RTF.
39  * @author Christopher Scott, scottc@westinghouse.com
40  */

41 public class RtfListTable extends RtfContainer {
42     private LinkedList JavaDoc lists;
43     private LinkedList JavaDoc styles;
44
45 //static data members
46
/** constant for a list table */
47     public static final String JavaDoc LIST_TABLE = "listtable";
48     /** constant for a list */
49     public static final String JavaDoc LIST = "list";
50     /** constant for a list template id */
51     public static final String JavaDoc LIST_TEMPLATE_ID = "listtemplateid";
52     /** constant for a list level */
53     public static final String JavaDoc LIST_LEVEL = "listlevel";
54     /** constant for a list number type */
55     public static final String JavaDoc LIST_NUMBER_TYPE = "levelnfc";
56     /** constant for a list justification */
57     public static final String JavaDoc LIST_JUSTIFICATION = "leveljc";
58     /** constant for list following character */
59     public static final String JavaDoc LIST_FOLLOWING_CHAR = "levelfollow";
60     /** constant for list start at */
61     public static final String JavaDoc LIST_START_AT = "levelstartat";
62     /** constant for list space */
63     public static final String JavaDoc LIST_SPACE = "levelspace";
64     /** constant for list indentation */
65     public static final String JavaDoc LIST_INDENT = "levelindent";
66     /** constant for list text format */
67     public static final String JavaDoc LIST_TEXT_FORM = "leveltext";
68     /** constant for list number positioning */
69     public static final String JavaDoc LIST_NUM_POSITION = "levelnumbers";
70     /** constant for list name */
71     public static final String JavaDoc LIST_NAME = "listname ;";
72     /** constant for list ID */
73     public static final String JavaDoc LIST_ID = "listid";
74     /** constant for list font type */
75     public static final String JavaDoc LIST_FONT_TYPE = "f";
76     /** constant for list override table */
77     public static final String JavaDoc LIST_OVR_TABLE = "listoverridetable";
78     /** constant for list override */
79     public static final String JavaDoc LIST_OVR = "listoverride";
80     /** constant for list override count */
81     public static final String JavaDoc LIST_OVR_COUNT = "listoverridecount";
82     /** constant for list number */
83     public static final String JavaDoc LIST_NUMBER = "ls";
84
85     /** String array of list table attributes */
86     public static final String JavaDoc [] LIST_TABLE_ATTR = {
87         LIST_TABLE, LIST, LIST_TEMPLATE_ID,
88         LIST_NUMBER_TYPE, LIST_JUSTIFICATION, LIST_FOLLOWING_CHAR,
89         LIST_START_AT, LIST_SPACE, LIST_INDENT,
90         LIST_TEXT_FORM, LIST_NUM_POSITION, LIST_ID,
91         LIST_OVR_TABLE, LIST_OVR, LIST_OVR_COUNT,
92         LIST_NUMBER, LIST_LEVEL
93     };
94
95     /**
96      * RtfListTable Constructor: sets the number of the list, and allocates
97      * for the RtfAttributes
98      * @param parent RtfContainer holding this RtfListTable
99      * @param w Writer
100      * @param num number of the list in the document
101      * @param attrs attributes of new RtfListTable
102      * @throws IOException for I/O problems
103      */

104     public RtfListTable(RtfContainer parent, Writer JavaDoc w, Integer JavaDoc num, RtfAttributes attrs)
105     throws IOException JavaDoc {
106         super(parent, w, attrs);
107
108         styles = new LinkedList JavaDoc();
109     }
110
111     /**
112      * Add List
113      * @param list RtfList to add
114      * @return number of lists in the table after adding
115      */

116     public int addList(RtfList list) {
117         if (lists == null) {
118             lists = new LinkedList JavaDoc();
119         }
120
121         lists.add(list);
122         
123         return lists.size();
124     }
125
126     /**
127      * Write the content
128      * @throws IOException for I/O problems
129      */

130     public void writeRtfContent() throws IOException JavaDoc {
131         newLine();
132         if (lists != null) {
133             //write '\listtable'
134
writeGroupMark(true);
135             writeStarControlWordNS(LIST_TABLE);
136             newLine();
137             for (Iterator JavaDoc it = lists.iterator(); it.hasNext();) {
138                 final RtfList list = (RtfList)it.next();
139                 writeListTableEntry(list);
140                 newLine();
141             }
142             writeGroupMark(false);
143                
144             newLine();
145             //write '\listoveridetable'
146
writeGroupMark(true);
147             writeStarControlWordNS(LIST_OVR_TABLE);
148             int z = 1;
149             newLine();
150             for (Iterator JavaDoc it = styles.iterator(); it.hasNext();) {
151                 final RtfListStyle style = (RtfListStyle)it.next();
152                         
153                 writeGroupMark(true);
154                 writeStarControlWordNS(LIST_OVR);
155                 writeGroupMark(true);
156         
157                 writeOneAttributeNS(LIST_ID, style.getRtfList().getListId().toString());
158                 writeOneAttributeNS(LIST_OVR_COUNT, new Integer JavaDoc(0));
159                 writeOneAttributeNS(LIST_NUMBER, new Integer JavaDoc(z++));
160
161                 writeGroupMark(false);
162                 writeGroupMark(false);
163                 newLine();
164             }
165             
166             writeGroupMark(false);
167             newLine();
168         }
169     }
170
171     /**
172      * Since this has no text content we have to overwrite isEmpty to print
173      * the table
174      * @return false (always)
175      */

176     public boolean isEmpty() {
177         return false;
178     }
179     
180     private void writeListTableEntry(RtfList list)
181     throws IOException JavaDoc {
182         //write list-specific attributes
183
writeGroupMark(true);
184         writeControlWordNS(LIST);
185         writeOneAttributeNS(LIST_TEMPLATE_ID, list.getListTemplateId().toString());
186         writeOneAttributeNS(LIST, attrib.getValue(LIST));
187         
188         // write level-specific attributes
189
writeGroupMark(true);
190         writeControlWordNS(LIST_LEVEL);
191         
192         writeOneAttributeNS(LIST_JUSTIFICATION, attrib.getValue(LIST_JUSTIFICATION));
193         writeOneAttributeNS(LIST_FOLLOWING_CHAR, attrib.getValue(LIST_FOLLOWING_CHAR));
194         writeOneAttributeNS(LIST_SPACE, new Integer JavaDoc(0));
195         writeOneAttributeNS(LIST_INDENT, attrib.getValue(LIST_INDENT));
196         
197         RtfListItem item = (RtfListItem)list.getChildren().get(0);
198         if (item != null) {
199             item.getRtfListStyle().writeLevelGroup(this);
200         }
201         
202         writeGroupMark(false);
203         
204         writeGroupMark(true);
205         writeControlWordNS(LIST_NAME);
206         writeGroupMark(false);
207         
208         writeOneAttributeNS(LIST_ID, list.getListId().toString());
209                 
210         writeGroupMark(false);
211     }
212
213     /**
214      * Add list style
215      * @param ls ListStyle to set
216      * @return number of styles after adding
217      */

218     public int addRtfListStyle(RtfListStyle ls) {
219         styles.add(ls);
220         return styles.size();
221     }
222 }
Popular Tags