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

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