001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017:
018: /* $Id: RtfListTable.java 426576 2006-07-28 15:44:37Z jeremias $ */
019:
020: package org.apache.fop.render.rtf.rtflib.rtfdoc;
021:
022: /*
023: * This file is part of the RTF library of the FOP project, which was originally
024: * created by Bertrand Delacretaz <bdelacretaz@codeconsult.ch> and by other
025: * contributors to the jfor project (www.jfor.org), who agreed to donate jfor to
026: * the FOP project.
027: */
028:
029: import java.util.LinkedList;
030: import java.util.Iterator;
031: import java.io.Writer;
032: import java.io.IOException;
033:
034: //import org.apache.fop.render.rtf.rtflib.jfor.main.JForVersionInfo;
035:
036: /**
037: * RtfListTable: used to make the list table in the header section of the RtfFile.
038: * This is the method that Word uses to make lists in RTF and the way most RTF readers,
039: * esp. Adobe FrameMaker read lists from RTF.
040: * @author Christopher Scott, scottc@westinghouse.com
041: */
042: public class RtfListTable extends RtfContainer {
043: private LinkedList lists;
044: private LinkedList styles;
045:
046: //static data members
047: /** constant for a list table */
048: public static final String LIST_TABLE = "listtable";
049: /** constant for a list */
050: public static final String LIST = "list";
051: /** constant for a list template id */
052: public static final String LIST_TEMPLATE_ID = "listtemplateid";
053: /** constant for a list level */
054: public static final String LIST_LEVEL = "listlevel";
055: /** constant for a list number type */
056: public static final String LIST_NUMBER_TYPE = "levelnfc";
057: /** constant for a list justification */
058: public static final String LIST_JUSTIFICATION = "leveljc";
059: /** constant for list following character */
060: public static final String LIST_FOLLOWING_CHAR = "levelfollow";
061: /** constant for list start at */
062: public static final String LIST_START_AT = "levelstartat";
063: /** constant for list space */
064: public static final String LIST_SPACE = "levelspace";
065: /** constant for list indentation */
066: public static final String LIST_INDENT = "levelindent";
067: /** constant for list text format */
068: public static final String LIST_TEXT_FORM = "leveltext";
069: /** constant for list number positioning */
070: public static final String LIST_NUM_POSITION = "levelnumbers";
071: /** constant for list name */
072: public static final String LIST_NAME = "listname ;";
073: /** constant for list ID */
074: public static final String LIST_ID = "listid";
075: /** constant for list font type */
076: public static final String LIST_FONT_TYPE = "f";
077: /** constant for list override table */
078: public static final String LIST_OVR_TABLE = "listoverridetable";
079: /** constant for list override */
080: public static final String LIST_OVR = "listoverride";
081: /** constant for list override count */
082: public static final String LIST_OVR_COUNT = "listoverridecount";
083: /** constant for list number */
084: public static final String LIST_NUMBER = "ls";
085:
086: /** String array of list table attributes */
087: public static final String[] LIST_TABLE_ATTR = { LIST_TABLE, LIST,
088: LIST_TEMPLATE_ID, LIST_NUMBER_TYPE, LIST_JUSTIFICATION,
089: LIST_FOLLOWING_CHAR, LIST_START_AT, LIST_SPACE,
090: LIST_INDENT, LIST_TEXT_FORM, LIST_NUM_POSITION, LIST_ID,
091: LIST_OVR_TABLE, LIST_OVR, LIST_OVR_COUNT, LIST_NUMBER,
092: LIST_LEVEL };
093:
094: /**
095: * RtfListTable Constructor: sets the number of the list, and allocates
096: * for the RtfAttributes
097: * @param parent RtfContainer holding this RtfListTable
098: * @param w Writer
099: * @param num number of the list in the document
100: * @param attrs attributes of new RtfListTable
101: * @throws IOException for I/O problems
102: */
103: public RtfListTable(RtfContainer parent, Writer w, Integer num,
104: RtfAttributes attrs) throws IOException {
105: super (parent, w, attrs);
106:
107: styles = new LinkedList();
108: }
109:
110: /**
111: * Add List
112: * @param list RtfList to add
113: * @return number of lists in the table after adding
114: */
115: public int addList(RtfList list) {
116: if (lists == null) {
117: lists = new LinkedList();
118: }
119:
120: lists.add(list);
121:
122: return lists.size();
123: }
124:
125: /**
126: * Write the content
127: * @throws IOException for I/O problems
128: */
129: public void writeRtfContent() throws IOException {
130: newLine();
131: if (lists != null) {
132: //write '\listtable'
133: writeGroupMark(true);
134: writeStarControlWordNS(LIST_TABLE);
135: newLine();
136: for (Iterator it = lists.iterator(); it.hasNext();) {
137: final RtfList list = (RtfList) it.next();
138: writeListTableEntry(list);
139: newLine();
140: }
141: writeGroupMark(false);
142:
143: newLine();
144: //write '\listoveridetable'
145: writeGroupMark(true);
146: writeStarControlWordNS(LIST_OVR_TABLE);
147: int z = 1;
148: newLine();
149: for (Iterator it = styles.iterator(); it.hasNext();) {
150: final RtfListStyle style = (RtfListStyle) it.next();
151:
152: writeGroupMark(true);
153: writeStarControlWordNS(LIST_OVR);
154: writeGroupMark(true);
155:
156: writeOneAttributeNS(LIST_ID, style.getRtfList()
157: .getListId().toString());
158: writeOneAttributeNS(LIST_OVR_COUNT, new Integer(0));
159: writeOneAttributeNS(LIST_NUMBER, new Integer(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) throws IOException {
181: //write list-specific attributes
182: writeGroupMark(true);
183: writeControlWordNS(LIST);
184: writeOneAttributeNS(LIST_TEMPLATE_ID, list.getListTemplateId()
185: .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
193: .getValue(LIST_JUSTIFICATION));
194: writeOneAttributeNS(LIST_FOLLOWING_CHAR, attrib
195: .getValue(LIST_FOLLOWING_CHAR));
196: writeOneAttributeNS(LIST_SPACE, new Integer(0));
197: writeOneAttributeNS(LIST_INDENT, attrib.getValue(LIST_INDENT));
198:
199: RtfListItem item = (RtfListItem) list.getChildren().get(0);
200: if (item != null) {
201: item.getRtfListStyle().writeLevelGroup(this );
202: }
203:
204: writeGroupMark(false);
205:
206: writeGroupMark(true);
207: writeControlWordNS(LIST_NAME);
208: writeGroupMark(false);
209:
210: writeOneAttributeNS(LIST_ID, list.getListId().toString());
211:
212: writeGroupMark(false);
213: }
214:
215: /**
216: * Add list style
217: * @param ls ListStyle to set
218: * @return number of styles after adding
219: */
220: public int addRtfListStyle(RtfListStyle ls) {
221: styles.add(ls);
222: return styles.size();
223: }
224: }
|