001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017:
018: /* $Id: RtfHeader.java 426576 2006-07-28 15:44:37Z jeremias $ */
019:
020: package org.apache.fop.render.rtf.rtflib.rtfdoc;
021:
022: /*
023: * This file is part of the RTF library of the FOP project, which was originally
024: * created by Bertrand Delacretaz <bdelacretaz@codeconsult.ch> and by other
025: * contributors to the jfor project (www.jfor.org), who agreed to donate jfor to
026: * the FOP project.
027: */
028:
029: import java.util.Map;
030: import java.util.HashMap;
031: import java.util.Iterator;
032: import java.io.Writer;
033: import java.io.IOException;
034:
035: //import org.apache.fop.render.rtf.rtflib.jfor.main.JForVersionInfo;
036:
037: /** RTF file header, contains style, font and other document-level information.
038: * @author Bertrand Delacretaz bdelacretaz@codeconsult.ch
039: * @author Andreas Putz a.putz@skynamics.com
040: * @author Marc Wilhelm Kuester
041: */
042:
043: class RtfHeader extends RtfContainer {
044: private final String charset = "ansi";
045: private final Map userProperties = new HashMap();
046:
047: /** Create an RTF header */
048: RtfHeader(RtfFile f, Writer w) throws IOException {
049: super (f, w);
050: new RtfFontTable(this , w);
051: new RtfGenerator(this , w);
052: // m_userProperties.put("jforVersion",JForVersionInfo.getLongVersionInfo());
053: }
054:
055: /** Overridden to write our own data before our children's data */
056: protected void writeRtfContent() throws IOException {
057: writeControlWord(charset);
058: writeUserProperties();
059: RtfColorTable.getInstance().writeColors(this );
060: super .writeRtfContent();
061: RtfTemplate.getInstance().writeTemplate(this );
062: RtfStyleSheetTable.getInstance().writeStyleSheet(this );
063: writeFootnoteProperties();
064:
065: }
066:
067: /** write user properties if any */
068: private void writeUserProperties() throws IOException {
069: if (userProperties.size() > 0) {
070: writeGroupMark(true);
071: writeStarControlWord("userprops");
072: for (Iterator it = userProperties.entrySet().iterator(); it
073: .hasNext();) {
074: final Map.Entry entry = (Map.Entry) it.next();
075: writeGroupMark(true);
076: writeControlWord("propname");
077: RtfStringConverter.getInstance().writeRtfString(writer,
078: entry.getKey().toString());
079: writeGroupMark(false);
080: writeControlWord("proptype30");
081: writeGroupMark(true);
082: writeControlWord("staticval");
083: RtfStringConverter.getInstance().writeRtfString(writer,
084: entry.getValue().toString());
085: writeGroupMark(false);
086: }
087: writeGroupMark(false);
088: }
089: }
090:
091: /** write directly to our Writer
092: * TODO should check that this done at the right point, or even better, store
093: * what is written here to render it in writeRtfContent. <-- it is for the color table
094: */
095: void write(String toWrite) throws IOException {
096: writer.write(toWrite);
097: }
098:
099: /** write to our Writer using an RtfStringConverter */
100: void writeRtfString(String toWrite) throws IOException {
101: RtfStringConverter.getInstance()
102: .writeRtfString(writer, toWrite);
103: }
104:
105: /**
106: *write properties for footnote handling
107: */
108: private void writeFootnoteProperties() throws IOException {
109: newLine();
110: writeControlWord("fet0"); //footnotes, not endnotes
111: writeControlWord("ftnbj"); //place footnotes at the end of the
112: //page (should be the default, but
113: //Word 2000 thinks otherwise)
114: }
115: }
|