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 10KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  1. /*
  2. * $Id$
  3. * ============================================================================
  4. * The Apache Software License, Version 1.1
  5. * ============================================================================
  6. *
  7. * Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
  8. *
  9. * Redistribution and use in source and binary forms, with or without modifica-
  10. * tion, are permitted provided that the following conditions are met:
  11. *
  12. * 1. Redistributions of source code must retain the above copyright notice,
  13. * this list of conditions and the following disclaimer.
  14. *
  15. * 2. Redistributions in binary form must reproduce the above copyright notice,
  16. * this list of conditions and the following disclaimer in the documentation
  17. * and/or other materials provided with the distribution.
  18. *
  19. * 3. The end-user documentation included with the redistribution, if any, must
  20. * include the following acknowledgment: "This product includes software
  21. * developed by the Apache Software Foundation (http://www.apache.org/)."
  22. * Alternately, this acknowledgment may appear in the software itself, if
  23. * and wherever such third-party acknowledgments normally appear.
  24. *
  25. * 4. The names "FOP" and "Apache Software Foundation" must not be used to
  26. * endorse or promote products derived from this software without prior
  27. * written permission. For written permission, please contact
  28. * apache@apache.org.
  29. *
  30. * 5. Products derived from this software may not be called "Apache", nor may
  31. * "Apache" appear in their name, without prior written permission of the
  32. * Apache Software Foundation.
  33. *
  34. * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
  35. * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
  36. * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  37. * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
  38. * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
  39. * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
  40. * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
  41. * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  42. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  43. * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  44. * ============================================================================
  45. *
  46. * This software consists of voluntary contributions made by many individuals
  47. * on behalf of the Apache Software Foundation and was originally created by
  48. * James Tauber <jtauber@jtauber.com>. For more information on the Apache
  49. * Software Foundation, please see <http://www.apache.org/>.
  50. */
  51. /*
  52. * This file is part of the RTF library of the FOP project, which was originally
  53. * created by Bertrand Delacretaz <bdelacretaz@codeconsult.ch> and by other
  54. * contributors to the jfor project (www.jfor.org), who agreed to donate jfor to
  55. * the FOP project.
  56. */
  57. package org.apache.fop.render.rtf.rtflib.rtfdoc;
  58. import java.util.Date;
  59. import java.util.Random;
  60. import java.io.Writer;
  61. import java.io.IOException;
  62. //import org.apache.fop.render.rtf.rtflib.jfor.main.JForVersionInfo;
  63. /**
  64. * RtfListTable: used to make the list table in the header section of the RtfFile.
  65. * This is the method that Word uses to make lists in RTF and the way most RTF readers,
  66. * esp. Adobe FrameMaker read lists from RTF.
  67. * @author Christopher Scott, scottc@westinghouse.com
  68. */
  69. public class RtfListTable extends RtfContainer {
  70. /** number of list in document */
  71. private Integer listNum;
  72. /** id of list */
  73. private Integer listId;
  74. private Integer listTemplateId;
  75. private RtfList parentList;
  76. //static data members
  77. /** constant for a list table */
  78. public static final String LIST_TABLE = "listtable";
  79. /** constant for a list */
  80. public static final String LIST = "list";
  81. /** constant for a list template id */
  82. public static final String LIST_TEMPLATE_ID = "listtemplateid";
  83. /** constant for a list level */
  84. public static final String LIST_LEVEL = "listlevel";
  85. /** constant for a list number type */
  86. public static final String LIST_NUMBER_TYPE = "levelnfc";
  87. /** constant for a list justification */
  88. public static final String LIST_JUSTIFICATION = "leveljc";
  89. /** constant for list following character */
  90. public static final String LIST_FOLLOWING_CHAR = "levelfollow";
  91. /** constant for list start at */
  92. public static final String LIST_START_AT = "levelstartat";
  93. /** constant for list space */
  94. public static final String LIST_SPACE = "levelspace";
  95. /** constant for list indentation */
  96. public static final String LIST_INDENT = "levelindent";
  97. /** constant for list text format */
  98. public static final String LIST_TEXT_FORM = "leveltext";
  99. /** constant for list number positioning */
  100. public static final String LIST_NUM_POSITION = "levelnumbers";
  101. /** constant for list name */
  102. public static final String LIST_NAME = "listname ;";
  103. /** constant for list ID */
  104. public static final String LIST_ID = "listid";
  105. /** constant for list font type */
  106. public static final String LIST_FONT_TYPE = "f";
  107. /** constant for list override table */
  108. public static final String LIST_OVR_TABLE = "listoverridetable";
  109. /** constant for list override */
  110. public static final String LIST_OVR = "listoverride";
  111. /** constant for list override count */
  112. public static final String LIST_OVR_COUNT = "listoverridecount";
  113. /** constant for list number */
  114. public static final String LIST_NUMBER = "ls";
  115. /** String array of list table attributes */
  116. public static final String [] LIST_TABLE_ATTR = {
  117. LIST_TABLE, LIST, LIST_TEMPLATE_ID,
  118. LIST_NUMBER_TYPE, LIST_JUSTIFICATION, LIST_FOLLOWING_CHAR,
  119. LIST_START_AT, LIST_SPACE, LIST_INDENT,
  120. LIST_TEXT_FORM, LIST_NUM_POSITION, LIST_ID,
  121. LIST_OVR_TABLE, LIST_OVR, LIST_OVR_COUNT,
  122. LIST_NUMBER, LIST_LEVEL
  123. };
  124. /**
  125. * RtfListTable Constructor: sets the number of the list, and allocates
  126. * for the RtfAttributes
  127. * @param parent RtfContainer holding this RtfListTable
  128. * @param w Writer
  129. * @param num number of the list in the document
  130. * @param attrs attributes of new RtfListTable
  131. * @throws IOException for I/O problems
  132. */
  133. public RtfListTable(RtfContainer parent, Writer w, Integer num, RtfAttributes attrs)
  134. throws IOException {
  135. super(parent, w, attrs);
  136. listNum = new Integer(num.intValue());
  137. //random number generator for ids
  138. Date runTime = new Date();
  139. Random listIdGenerator = new Random(runTime.getTime());
  140. listId = new Integer(listIdGenerator.nextInt());
  141. attrib.set(LIST_ID, listId.toString());
  142. listTemplateId = new Integer(listIdGenerator.nextInt());
  143. attrib.set(LIST_NUMBER_TYPE, 0);
  144. }
  145. /**
  146. * Set parentList
  147. * @param parent parentList to set
  148. */
  149. public void setParentList(RtfList parent) {
  150. parentList = parent;
  151. }
  152. /**
  153. * Accessor for listNum
  154. * @return listNum
  155. */
  156. public Integer getListNumber() {
  157. return listNum;
  158. }
  159. /** Set whether the list is a bulleted list not, and set attributes
  160. * accordingly */
  161. private void setListType() {
  162. if (parentList.isBulletedList()) {
  163. // bullet definition for bulleted lists
  164. // Chris Scott's version was "\\\'01\\u-3913 ?;"
  165. // 'b7 is what was used in jfor V0.5.2
  166. attrib.set(LIST_TEXT_FORM, "\\\'01\\'b7 ?;");
  167. attrib.set(LIST_NUM_POSITION);
  168. attrib.set(LIST_NUMBER_TYPE, 23);
  169. attrib.set(LIST_FONT_TYPE, 2);
  170. } else {
  171. attrib.set(LIST_TEXT_FORM, "\\\'03\\\'00. ;");
  172. attrib.set(LIST_NUM_POSITION, "\\\'01;");
  173. attrib.set(LIST_NUMBER_TYPE, 0);
  174. attrib.set(LIST_FONT_TYPE, 0);
  175. }
  176. }
  177. /**
  178. * Write the content
  179. * @throws IOException for I/O problems
  180. */
  181. public void writeRtfContent() throws IOException {
  182. setListType();
  183. writeGroupMark(true);
  184. writeStarControlWordNS(LIST_TABLE);
  185. writeGroupMark(true);
  186. writeControlWordNS(LIST);
  187. writeOneAttributeNS(LIST_TEMPLATE_ID, listTemplateId.toString());
  188. writeOneAttributeNS(LIST, attrib.getValue(LIST));
  189. writeGroupMark(true);
  190. writeControlWordNS(LIST_LEVEL);
  191. writeOneAttributeNS(LIST_NUMBER_TYPE, attrib.getValue(LIST_NUMBER_TYPE));
  192. writeOneAttributeNS(LIST_JUSTIFICATION, attrib.getValue(LIST_JUSTIFICATION));
  193. writeOneAttributeNS(LIST_FOLLOWING_CHAR, attrib.getValue(LIST_FOLLOWING_CHAR));
  194. writeOneAttributeNS(LIST_START_AT, attrib.getValue(LIST_START_AT));
  195. writeOneAttributeNS(LIST_SPACE, new Integer(0));
  196. writeOneAttributeNS(LIST_INDENT, attrib.getValue(LIST_INDENT));
  197. writeGroupMark(true);
  198. writeOneAttributeNS(LIST_TEXT_FORM, attrib.getValue(LIST_TEXT_FORM));
  199. writeGroupMark(false);
  200. writeGroupMark(true);
  201. writeOneAttributeNS(LIST_NUM_POSITION, attrib.getValue(LIST_NUM_POSITION));
  202. writeGroupMark(false);
  203. writeOneAttributeNS(LIST_FONT_TYPE, attrib.getValue(LIST_FONT_TYPE));
  204. writeGroupMark(false);
  205. writeGroupMark(true);
  206. writeControlWordNS(LIST_NAME);
  207. writeGroupMark(false);
  208. writeOneAttributeNS(LIST_ID, listId.toString());
  209. writeGroupMark(false);
  210. writeGroupMark(false);
  211. writeGroupMark(true);
  212. writeStarControlWordNS(LIST_OVR_TABLE);
  213. writeGroupMark(true);
  214. writeControlWordNS(LIST_OVR);
  215. writeOneAttributeNS(LIST_ID, listId.toString());
  216. writeOneAttributeNS(LIST_OVR_COUNT, new Integer(0));
  217. writeOneAttributeNS(LIST_NUMBER, listNum.toString());
  218. writeGroupMark(false);
  219. writeGroupMark(false);
  220. }
  221. /**
  222. * Since this has no text content we have to overwrite isEmpty to print
  223. * the table
  224. * @return false (always)
  225. */
  226. public boolean isEmpty() {
  227. return false;
  228. }
  229. }