KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > lowagie > text > rtf > RtfAddableElement


1 /*
2  * $Id: RtfAddableElement.java 2776 2007-05-23 20:01:40Z hallm $
3  * $Name$
4  *
5  * Copyright 2001, 2002, 2003, 2004 by Mark Hall
6  *
7  * The contents of this file are subject to the Mozilla Public License Version 1.1
8  * (the "License"); you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at http://www.mozilla.org/MPL/
10  *
11  * Software distributed under the License is distributed on an "AS IS" basis,
12  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
13  * for the specific language governing rights and limitations under the License.
14  *
15  * The Original Code is 'iText, a free JAVA-PDF library'.
16  *
17  * The Initial Developer of the Original Code is Bruno Lowagie. Portions created by
18  * the Initial Developer are Copyright (C) 1999, 2000, 2001, 2002 by Bruno Lowagie.
19  * All Rights Reserved.
20  * Co-Developer of the code is Paulo Soares. Portions created by the Co-Developer
21  * are Copyright (C) 2000, 2001, 2002 by Paulo Soares. All Rights Reserved.
22  * Co-Developer of the code is Mark Hall. Portions created by the Co-Developer are
23  * Copyright (C) 2006 by Mark Hall. All Rights Reserved
24  *
25  * Contributor(s): all the names of the contributors are added in the source code
26  * where applicable.
27  *
28  * Alternatively, the contents of this file may be used under the terms of the
29  * LGPL license (the ?GNU LIBRARY GENERAL PUBLIC LICENSE?), in which case the
30  * provisions of LGPL are applicable instead of those above. If you wish to
31  * allow use of your version of this file only under the terms of the LGPL
32  * License and not to allow others to use your version of this file under
33  * the MPL, indicate your decision by deleting the provisions above and
34  * replace them with the notice and other provisions required by the LGPL.
35  * If you do not delete the provisions above, a recipient may use your version
36  * of this file under either the MPL or the GNU LIBRARY GENERAL PUBLIC LICENSE.
37  *
38  * This library is free software; you can redistribute it and/or modify it
39  * under the terms of the MPL as stated above or under the terms of the GNU
40  * Library General Public License as published by the Free Software Foundation;
41  * either version 2 of the License, or any later version.
42  *
43  * This library is distributed in the hope that it will be useful, but WITHOUT
44  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
45  * FOR A PARTICULAR PURPOSE. See the GNU Library general Public License for more
46  * details.
47  *
48  * If you didn't download this code from the following link, you should check if
49  * you aren't using an obsolete version:
50  * http://www.lowagie.com/iText/
51  */

52
53 package com.lowagie.text.rtf;
54
55 import java.io.IOException JavaDoc;
56 import java.io.OutputStream JavaDoc;
57
58 import com.lowagie.text.Chunk;
59 import com.lowagie.text.Font;
60 import com.lowagie.text.rtf.document.RtfDocument;
61
62 /**
63  * The RtfAddableElement is the superclass for all rtf specific elements
64  * that need to be added to an iText document. It is an extension of Chunk
65  * and it also implements RtfBasicElement. It is an abstract class thus it
66  * cannot be instantiated itself and has to be subclassed to be used.
67  *
68  * @version $Id: RtfAddableElement.java 2776 2007-05-23 20:01:40Z hallm $
69  * @author Mark Hall (mhall@edu.uni-klu.ac.at)
70  * @author Thomas Bickel (tmb99@inode.at)
71  */

72 public abstract class RtfAddableElement extends Chunk implements RtfBasicElement {
73
74     /**
75      * The RtfDocument this RtfAddableElement belongs to.
76      */

77     protected RtfDocument doc = null;
78     /**
79      * Whether this RtfAddableElement is contained in a table.
80      */

81     protected boolean inTable = false;
82     /**
83      * Whether this RtfAddableElement is contained in a header.
84      */

85     protected boolean inHeader = false;
86     
87     /**
88      * Constructs a new RtfAddableElement. The Chunk content is
89      * set to an empty string and the font to the default Font().
90      */

91     public RtfAddableElement() {
92         super("", new Font());
93     }
94
95     /**
96      * Subclasses have to implement this method.
97      *
98      * @deprecated replaced by {@link #writeContent(OutputStream)}
99      */

100     public abstract byte[] write();
101
102     /**
103      * Writes the element content to the given output stream.
104      * This method replaces the {@link #write()} method which is now deprecated.
105      */

106     public void writeContent(OutputStream JavaDoc out) throws IOException JavaDoc
107     {
108         byte[] content = write();
109         out.write(content);
110     }
111     
112     /**
113      * Sets the RtfDocument this RtfAddableElement belongs to
114      */

115     public void setRtfDocument(RtfDocument doc) {
116         this.doc = doc;
117     }
118
119     /**
120      * Sets whether this RtfAddableElement is contained in a table.
121      */

122     public void setInTable(boolean inTable) {
123         this.inTable = inTable;
124     }
125
126     /**
127      * Sets whether this RtfAddableElement is contained in a header/footer.
128      */

129     public void setInHeader(boolean inHeader) {
130         this.inHeader = inHeader;
131     }
132
133     /**
134      * Transforms an integer into its String representation and then returns the bytes
135      * of that string.
136      *
137      * @param i The integer to convert
138      * @return A byte array representing the integer
139      */

140     public byte[] intToByteArray(int i) {
141         return Integer.toString(i).getBytes();
142     }
143     
144     /**
145      * RtfAddableElement subclasses are never assumed to be empty.
146      */

147     public boolean isEmpty() {
148         return false;
149     }
150 }
151
Popular Tags