01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * 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: RtfTemplate.java 426576 2006-07-28 15:44:37Z jeremias $ */
19:
20: /*
21: * This file is part of the RTF library of the FOP project, which was originally
22: * created by Bertrand Delacretaz <bdelacretaz@codeconsult.ch> and by other
23: * contributors to the jfor project (www.jfor.org), who agreed to donate jfor to
24: * the FOP project.
25: */
26:
27: package org.apache.fop.render.rtf.rtflib.rtfdoc;
28:
29: import java.io.IOException;
30:
31: /**
32: * Singelton of the RTF style template
33: * This class belongs to the <jfor:style-template> tag processing.
34: */
35:
36: public class RtfTemplate {
37:
38: /** Singelton instance */
39: private static RtfTemplate instance = null;
40:
41: private String templateFilePath = null;
42:
43: /**
44: * Constructor.
45: */
46: private RtfTemplate() {
47:
48: }
49:
50: /**
51: * Singelton.
52: *
53: * @return The instance of RtfTemplate
54: */
55: public static RtfTemplate getInstance() {
56: if (instance == null) {
57: instance = new RtfTemplate();
58: }
59:
60: return instance;
61: }
62:
63: /**
64: * Set the template file and adjust tha path separator
65: * @param templateFilePath The full path of the template
66: * @throws IOException for I/O problems
67: **/
68: public void setTemplateFilePath(String templateFilePath)
69: throws IOException {
70: // no validity checks here - leave this to the RTF client
71: if (templateFilePath == null) {
72: this .templateFilePath = null;
73: } else {
74: this .templateFilePath = templateFilePath.trim();
75: }
76: }
77:
78: /**
79: * Write the rtf template
80: * @param header Rtf header is the parent
81: * @throws IOException On write error
82: */
83: public void writeTemplate(RtfHeader header) throws IOException {
84: if (templateFilePath == null || templateFilePath.length() == 0) {
85: return;
86: }
87:
88: header.writeGroupMark(true);
89: header.writeControlWord("template");
90: header.writeRtfString(this .templateFilePath);
91: header.writeGroupMark(false);
92:
93: header.writeGroupMark(true);
94: header.writeControlWord("linkstyles");
95: header.writeGroupMark(false);
96: }
97: }
|