KickJava   Java API By Example, From Geeks To Geeks.

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


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: RtfHeader.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.util.Map JavaDoc;
30 import java.util.HashMap JavaDoc;
31 import java.util.Iterator JavaDoc;
32 import java.io.Writer JavaDoc;
33 import java.io.IOException JavaDoc;
34 //import org.apache.fop.render.rtf.rtflib.jfor.main.JForVersionInfo;
35

36 /** RTF file header, contains style, font and other document-level information.
37  * @author Bertrand Delacretaz bdelacretaz@codeconsult.ch
38  * @author Andreas Putz a.putz@skynamics.com
39  * @author Marc Wilhelm Kuester
40  */

41
42 class RtfHeader extends RtfContainer {
43     private final String JavaDoc charset = "ansi";
44     private final Map JavaDoc userProperties = new HashMap JavaDoc();
45
46     /** Create an RTF header */
47     RtfHeader(RtfFile f, Writer JavaDoc w) throws IOException JavaDoc {
48         super(f, w);
49         new RtfFontTable(this, w);
50         new RtfGenerator(this, w);
51 // m_userProperties.put("jforVersion",JForVersionInfo.getLongVersionInfo());
52
}
53
54     /** Overridden to write our own data before our children's data */
55     protected void writeRtfContent() throws IOException JavaDoc {
56         writeControlWord(charset);
57         writeUserProperties();
58         RtfColorTable.getInstance().writeColors(this);
59         super.writeRtfContent();
60         RtfTemplate.getInstance().writeTemplate(this);
61         RtfStyleSheetTable.getInstance().writeStyleSheet(this);
62         writeFootnoteProperties();
63         
64     }
65
66     /** write user properties if any */
67     private void writeUserProperties() throws IOException JavaDoc {
68         if (userProperties.size() > 0) {
69             writeGroupMark(true);
70             writeStarControlWord("userprops");
71             for (Iterator JavaDoc it = userProperties.entrySet().iterator(); it.hasNext();) {
72                 final Map.Entry JavaDoc entry = (Map.Entry JavaDoc)it.next();
73                 writeGroupMark(true);
74                 writeControlWord("propname");
75                 RtfStringConverter.getInstance().writeRtfString(writer,
76                         entry.getKey().toString());
77                 writeGroupMark(false);
78                 writeControlWord("proptype30");
79                 writeGroupMark(true);
80                 writeControlWord("staticval");
81                 RtfStringConverter.getInstance().writeRtfString(writer,
82                         entry.getValue().toString());
83                 writeGroupMark(false);
84             }
85             writeGroupMark(false);
86         }
87     }
88
89     /** write directly to our Writer
90      * TODO should check that this done at the right point, or even better, store
91      * what is written here to render it in writeRtfContent. <-- it is for the color table
92      */

93     void write(String JavaDoc toWrite) throws IOException JavaDoc {
94         writer.write(toWrite);
95     }
96
97     /** write to our Writer using an RtfStringConverter */
98     void writeRtfString(String JavaDoc toWrite) throws IOException JavaDoc {
99         RtfStringConverter.getInstance().writeRtfString(writer, toWrite);
100     }
101
102     /**
103      *write properties for footnote handling
104      */

105     private void writeFootnoteProperties() throws IOException JavaDoc {
106         newLine();
107         writeControlWord("fet0"); //footnotes, not endnotes
108
writeControlWord("ftnbj"); //place footnotes at the end of the
109
//page (should be the default, but
110
//Word 2000 thinks otherwise)
111
}
112 }
113
Popular Tags