1 /*
2 * $Id: RtfTableOfContents.java 3373 2008-05-12 16:21:24Z xlv $
3 *
4 * Copyright 2004 by Mark Hall
5 * Uses code Copyright 2002
6 * Steffen.Stundzig (Steffen.Stundzig@smb-tec.com)
7 *
8 * The contents of this file are subject to the Mozilla Public License Version 1.1
9 * (the "License"); you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at http://www.mozilla.org/MPL/
11 *
12 * Software distributed under the License is distributed on an "AS IS" basis,
13 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
14 * for the specific language governing rights and limitations under the License.
15 *
16 * The Original Code is 'iText, a free JAVA-PDF library'.
17 *
18 * The Initial Developer of the Original Code is Bruno Lowagie. Portions created by
19 * the Initial Developer are Copyright (C) 1999, 2000, 2001, 2002 by Bruno Lowagie.
20 * All Rights Reserved.
21 * Co-Developer of the code is Paulo Soares. Portions created by the Co-Developer
22 * are Copyright (C) 2000, 2001, 2002 by Paulo Soares. All Rights Reserved.
23 *
24 * Contributor(s): all the names of the contributors are added in the source code
25 * where applicable.
26 *
27 * Alternatively, the contents of this file may be used under the terms of the
28 * LGPL license (the ?GNU LIBRARY GENERAL PUBLIC LICENSE?), in which case the
29 * provisions of LGPL are applicable instead of those above. If you wish to
30 * allow use of your version of this file only under the terms of the LGPL
31 * License and not to allow others to use your version of this file under
32 * the MPL, indicate your decision by deleting the provisions above and
33 * replace them with the notice and other provisions required by the LGPL.
34 * If you do not delete the provisions above, a recipient may use your version
35 * of this file under either the MPL or the GNU LIBRARY GENERAL PUBLIC LICENSE.
36 *
37 * This library is free software; you can redistribute it and/or modify it
38 * under the terms of the MPL as stated above or under the terms of the GNU
39 * Library General Public License as published by the Free Software Foundation;
40 * either version 2 of the License, or any later version.
41 *
42 * This library is distributed in the hope that it will be useful, but WITHOUT
43 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
44 * FOR A PARTICULAR PURPOSE. See the GNU Library general Public License for more
45 * details.
46 *
47 * If you didn't download this code from the following link, you should check if
48 * you aren't using an obsolete version:
49 * http://www.lowagie.com/iText/
50 */
51
52 package com.lowagie.text.rtf.field;
53
54 import java.io.IOException;
55 import java.io.OutputStream;
56
57 import com.lowagie.text.Font;
58
59
60
61 /**
62 * The RtfTableOfContents together with multiple RtfTOCEntry objects generates a table
63 * of contents. The table of contents will display no entries in the viewing program
64 * and the user will have to update it first. A text to inform the user of this is
65 * displayed instead.
66 *
67 * @version $Id: RtfTableOfContents.java 3373 2008-05-12 16:21:24Z xlv $
68 * @author Mark Hall (Mark.Hall@mail.room3b.eu)
69 * @author Steffen.Stundzig (Steffen.Stundzig@smb-tec.com)
70 * @author Thomas Bickel (tmb99@inode.at)
71 */
72 public class RtfTableOfContents extends RtfField {
73
74 /**
75 * field inst content
76 */
77 private final static String FIELD_INST = "TOC \\\\f \\\\h \\\\u \\\\o \"1-5\" ";
78 /**
79 * The default text to display
80 */
81 private String defaultText = "Table of Contents - Click to update";
82
83 /**
84 * Constructs a RtfTableOfContents. The default text is the text that is displayed
85 * before the user updates the table of contents
86 *
87 * @param defaultText The default text to display
88 */
89 public RtfTableOfContents(String defaultText) {
90 super(null, new Font());
91 this.defaultText = defaultText;
92 }
93
94 /**
95 * Writes the field instruction content
96 *
97 * @param result The <code>OutputStream</code> to write to.
98 * @throws IOException on i/o errors.
99 */
100 protected void writeFieldInstContent(final OutputStream result) throws IOException
101 {
102 result.write(FIELD_INST.getBytes());
103 }
104
105 /**
106 * Writes the field result content
107 *
108 * @param out The <code>OutputStream</code> to write to.
109 * @throws IOException on i/o errors.
110 */
111 protected void writeFieldResultContent(final OutputStream out) throws IOException
112 {
113 document.filterSpecialChar(out, defaultText, true, true);
114 }
115 }