KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > fop > render > rtf > rtflib > rtfdoc > RtfAfterBeforeBase


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
18 /* $Id: RtfAfterBeforeBase.java 426576 2006-07-28 15:44:37Z jeremias $ */
19
20 package org.apache.fop.render.rtf.rtflib.rtfdoc;
21
22 /*
23  * This file is part of the RTF library of the FOP project, which was originally
24  * created by Bertrand Delacretaz <bdelacretaz@codeconsult.ch> and by other
25  * contributors to the jfor project (www.jfor.org), who agreed to donate jfor to
26  * the FOP project.
27  */

28
29 import java.io.Writer JavaDoc;
30 import java.io.IOException JavaDoc;
31
32 /** Common code for RtfAfter and RtfBefore
33 * @author Andreas Lambert <andreas.lambert@cronidesoft.com>
34 * @author Christopher Scott, scottc@westinghouse.com
35 * @author Christoph Zahm <zahm@jnet.ch> (support for tables in headers/footers)
36 */

37
38 abstract class RtfAfterBeforeBase
39 extends RtfContainer
40 implements IRtfParagraphContainer, IRtfExternalGraphicContainer, IRtfTableContainer,
41         IRtfTextrunContainer {
42     protected RtfAttributes attrib;
43     private RtfParagraph para;
44     private RtfExternalGraphic externalGraphic;
45     private RtfTable table;
46
47     RtfAfterBeforeBase(RtfSection parent, Writer JavaDoc w, RtfAttributes attrs) throws IOException JavaDoc {
48         super((RtfContainer)parent, w, attrs);
49         attrib = attrs;
50     }
51
52     public RtfParagraph newParagraph() throws IOException JavaDoc {
53         closeAll();
54         para = new RtfParagraph(this, writer);
55         return para;
56     }
57
58     public RtfParagraph newParagraph(RtfAttributes attrs) throws IOException JavaDoc {
59         closeAll();
60         para = new RtfParagraph(this, writer, attrs);
61         return para;
62     }
63
64     public RtfExternalGraphic newImage() throws IOException JavaDoc {
65         closeAll();
66         externalGraphic = new RtfExternalGraphic(this, writer);
67         return externalGraphic;
68     }
69
70     private void closeCurrentParagraph() throws IOException JavaDoc {
71         if (para != null) {
72             para.close();
73         }
74     }
75
76     private void closeCurrentExternalGraphic() throws IOException JavaDoc {
77         if (externalGraphic != null) {
78             externalGraphic.close();
79         }
80     }
81
82     private void closeCurrentTable() throws IOException JavaDoc {
83         if (table != null) {
84             table.close();
85         }
86     }
87
88     protected void writeRtfPrefix() throws IOException JavaDoc {
89         writeGroupMark(true);
90         writeMyAttributes();
91     }
92
93     /** must be implemented to write the header or footer attributes */
94     protected abstract void writeMyAttributes() throws IOException JavaDoc;
95
96     protected void writeRtfSuffix() throws IOException JavaDoc {
97         writeGroupMark(false);
98     }
99
100     public RtfAttributes getAttributes() {
101         return attrib;
102     }
103
104     public void closeAll() throws IOException JavaDoc {
105         closeCurrentParagraph();
106         closeCurrentExternalGraphic();
107         closeCurrentTable();
108     }
109
110     /** close current table if any and start a new one
111      * @param tc added by Boris Poudérous on july 2002 in order to process
112      * number-columns-spanned attribute
113      */

114     public RtfTable newTable(RtfAttributes attrs, ITableColumnsInfo tc) throws IOException JavaDoc {
115         closeAll();
116         table = new RtfTable(this, writer, attrs, tc);
117         return table;
118     }
119
120     /** close current table if any and start a new one */
121     public RtfTable newTable(ITableColumnsInfo tc) throws IOException JavaDoc {
122         closeAll();
123         table = new RtfTable(this, writer, tc);
124         return table;
125     }
126     
127     public RtfTextrun getTextrun()
128     throws IOException JavaDoc {
129         return RtfTextrun.getTextrun(this, writer, null);
130     }
131 }
132
Popular Tags