You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

RtfListTable.java 7.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  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. /* $Id$ */
  18. package org.apache.fop.render.rtf.rtflib.rtfdoc;
  19. /*
  20. * This file is part of the RTF library of the FOP project, which was originally
  21. * created by Bertrand Delacretaz <bdelacretaz@codeconsult.ch> and by other
  22. * contributors to the jfor project (www.jfor.org), who agreed to donate jfor to
  23. * the FOP project.
  24. */
  25. import java.io.IOException;
  26. import java.io.Writer;
  27. import java.util.Iterator;
  28. import java.util.LinkedList;
  29. /**
  30. * <p>RtfListTable: used to make the list table in the header section of the RtfFile.
  31. * This is the method that Word uses to make lists in RTF and the way most RTF readers,
  32. * esp. Adobe FrameMaker read lists from RTF.</p>
  33. *
  34. * <p>This work was authored by Christopher Scott (scottc@westinghouse.com).</p>
  35. */
  36. public class RtfListTable extends RtfContainer {
  37. private LinkedList lists;
  38. private LinkedList styles;
  39. //static data members
  40. /** constant for a list table */
  41. public static final String LIST_TABLE = "listtable";
  42. /** constant for a list */
  43. public static final String LIST = "list";
  44. /** constant for a list template id */
  45. public static final String LIST_TEMPLATE_ID = "listtemplateid";
  46. /** constant for a list level */
  47. public static final String LIST_LEVEL = "listlevel";
  48. /** constant for a list number type */
  49. public static final String LIST_NUMBER_TYPE = "levelnfc";
  50. /** constant for a list justification */
  51. public static final String LIST_JUSTIFICATION = "leveljc";
  52. /** constant for list following character */
  53. public static final String LIST_FOLLOWING_CHAR = "levelfollow";
  54. /** constant for list start at */
  55. public static final String LIST_START_AT = "levelstartat";
  56. /** constant for list space */
  57. public static final String LIST_SPACE = "levelspace";
  58. /** constant for list indentation */
  59. public static final String LIST_INDENT = "levelindent";
  60. /** constant for list text format */
  61. public static final String LIST_TEXT_FORM = "leveltext";
  62. /** constant for list number positioning */
  63. public static final String LIST_NUM_POSITION = "levelnumbers";
  64. /** constant for list name */
  65. public static final String LIST_NAME = "listname ;";
  66. /** constant for list ID */
  67. public static final String LIST_ID = "listid";
  68. /** constant for list font type */
  69. public static final String LIST_FONT_TYPE = "f";
  70. /** constant for list override table */
  71. public static final String LIST_OVR_TABLE = "listoverridetable";
  72. /** constant for list override */
  73. public static final String LIST_OVR = "listoverride";
  74. /** constant for list override count */
  75. public static final String LIST_OVR_COUNT = "listoverridecount";
  76. /** constant for list number */
  77. public static final String LIST_NUMBER = "ls";
  78. /** String array of list table attributes */
  79. public static final String [] LIST_TABLE_ATTR = {
  80. LIST_TABLE, LIST, LIST_TEMPLATE_ID,
  81. LIST_NUMBER_TYPE, LIST_JUSTIFICATION, LIST_FOLLOWING_CHAR,
  82. LIST_START_AT, LIST_SPACE, LIST_INDENT,
  83. LIST_TEXT_FORM, LIST_NUM_POSITION, LIST_ID,
  84. LIST_OVR_TABLE, LIST_OVR, LIST_OVR_COUNT,
  85. LIST_NUMBER, LIST_LEVEL
  86. };
  87. /**
  88. * RtfListTable Constructor: sets the number of the list, and allocates
  89. * for the RtfAttributes
  90. * @param parent RtfContainer holding this RtfListTable
  91. * @param w Writer
  92. * @param num number of the list in the document
  93. * @param attrs attributes of new RtfListTable
  94. * @throws IOException for I/O problems
  95. */
  96. public RtfListTable(RtfContainer parent, Writer w, Integer num, RtfAttributes attrs)
  97. throws IOException {
  98. super(parent, w, attrs);
  99. styles = new LinkedList();
  100. }
  101. /**
  102. * Add List
  103. * @param list RtfList to add
  104. * @return number of lists in the table after adding
  105. */
  106. public int addList(RtfList list) {
  107. if (lists == null) {
  108. lists = new LinkedList();
  109. }
  110. lists.add(list);
  111. return lists.size();
  112. }
  113. /**
  114. * Write the content
  115. * @throws IOException for I/O problems
  116. */
  117. public void writeRtfContent() throws IOException {
  118. newLine();
  119. if (lists != null) {
  120. //write '\listtable'
  121. writeGroupMark(true);
  122. writeStarControlWordNS(LIST_TABLE);
  123. newLine();
  124. for (Iterator it = lists.iterator(); it.hasNext();) {
  125. final RtfList list = (RtfList)it.next();
  126. writeListTableEntry(list);
  127. newLine();
  128. }
  129. writeGroupMark(false);
  130. newLine();
  131. //write '\listoveridetable'
  132. writeGroupMark(true);
  133. writeStarControlWordNS(LIST_OVR_TABLE);
  134. int z = 1;
  135. newLine();
  136. for (Iterator it = styles.iterator(); it.hasNext();) {
  137. final RtfListStyle style = (RtfListStyle)it.next();
  138. writeGroupMark(true);
  139. writeStarControlWordNS(LIST_OVR);
  140. writeGroupMark(true);
  141. writeOneAttributeNS(LIST_ID, style.getRtfList().getListId().toString());
  142. writeOneAttributeNS(LIST_OVR_COUNT, 0);
  143. writeOneAttributeNS(LIST_NUMBER, z++);
  144. writeGroupMark(false);
  145. writeGroupMark(false);
  146. newLine();
  147. }
  148. writeGroupMark(false);
  149. newLine();
  150. }
  151. }
  152. /**
  153. * Since this has no text content we have to overwrite isEmpty to print
  154. * the table
  155. * @return false (always)
  156. */
  157. public boolean isEmpty() {
  158. return false;
  159. }
  160. private void writeListTableEntry(RtfList list)
  161. throws IOException {
  162. //write list-specific attributes
  163. writeGroupMark(true);
  164. writeControlWordNS(LIST);
  165. writeOneAttributeNS(LIST_TEMPLATE_ID, list.getListTemplateId().toString());
  166. writeOneAttributeNS(LIST, attrib.getValue(LIST));
  167. // write level-specific attributes
  168. writeGroupMark(true);
  169. writeControlWordNS(LIST_LEVEL);
  170. writeOneAttributeNS(LIST_JUSTIFICATION, attrib.getValue(LIST_JUSTIFICATION));
  171. writeOneAttributeNS(LIST_FOLLOWING_CHAR, attrib.getValue(LIST_FOLLOWING_CHAR));
  172. writeOneAttributeNS(LIST_SPACE, 0);
  173. writeOneAttributeNS(LIST_INDENT, attrib.getValue(LIST_INDENT));
  174. RtfListItem item = (RtfListItem)list.getChildren().get(0);
  175. if (item != null) {
  176. item.getRtfListStyle().writeLevelGroup(this);
  177. }
  178. writeGroupMark(false);
  179. writeGroupMark(true);
  180. writeControlWordNS(LIST_NAME);
  181. writeGroupMark(false);
  182. writeOneAttributeNS(LIST_ID, list.getListId().toString());
  183. writeGroupMark(false);
  184. }
  185. /**
  186. * Add list style
  187. * @param ls ListStyle to set
  188. * @return number of styles after adding
  189. */
  190. public int addRtfListStyle(RtfListStyle ls) {
  191. styles.add(ls);
  192. return styles.size();
  193. }
  194. }