KickJava   Java API By Example, From Geeks To Geeks.

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


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: RtfBookmark.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 /**
33  * RTF Bookmark.
34  * Create an RTF bookmark as a child of given container with default attributes.
35  * This class belongs to the "id" attribute processing.
36  * @author <a HREF="mailto:a.putz@skynamics.com">Andreas Putz</a>
37  */

38 public class RtfBookmark extends RtfElement {
39     //////////////////////////////////////////////////
40
// @@ Members
41
//////////////////////////////////////////////////
42

43     /** Name of the bokkmark */
44     private String JavaDoc bookmark = null;
45     /** Word 2000 supports a length of 40 characters only */
46     public static final int MAX_BOOKMARK_LENGTH = 40;
47     /** Word 2000 converts '.' in bookmarks to "_", thats why we control this replacement. */
48     public static final char REPLACE_CHARACTER = '_';
49
50
51     //////////////////////////////////////////////////
52
// @@ Construction
53
//////////////////////////////////////////////////
54

55     /**
56      * Constructor.
57      *
58      * @param parent a <code>RtfBookmarkContainer</code> value
59      * @param writer a <code>Writer</code> value
60      * @param bookmark Name of the bookmark
61      */

62     RtfBookmark (RtfContainer parent, Writer JavaDoc w, String JavaDoc bookmark) throws IOException JavaDoc {
63         super (parent, w);
64
65         int now = bookmark.length ();
66
67         this.bookmark = bookmark.substring (0,
68                 now < MAX_BOOKMARK_LENGTH ? now : MAX_BOOKMARK_LENGTH);
69         this.bookmark = this.bookmark.replace ('.', REPLACE_CHARACTER);
70         this.bookmark = this.bookmark.replace (' ', REPLACE_CHARACTER);
71     }
72
73
74     //////////////////////////////////////////////////
75
// @@ RtfElement implementation
76
//////////////////////////////////////////////////
77

78     /**
79      * Is called before writing the Rtf content.
80      *
81      * @throws IOException On Error
82      */

83     public void writeRtfPrefix () throws IOException JavaDoc {
84         startBookmark ();
85     }
86
87     /**
88      * Writes the RTF content to m_writer.
89      *
90      * @exception IOException On error
91      */

92     public void writeRtfContent () throws IOException JavaDoc {
93 // this.getRtfFile ().getLog ().logInfo ("Write bookmark '" + bookmark + "'.");
94
// No content to write
95
}
96
97     /**
98      * Is called after writing the Rtf content.
99      *
100      * @throws IOException On Error
101      */

102     public void writeRtfSuffix () throws IOException JavaDoc {
103         endBookmark ();
104     }
105
106
107     //////////////////////////////////////////////////
108
// @@ Private methods
109
//////////////////////////////////////////////////
110

111     /**
112      * Writes RTF content to begin the bookmark.
113      *
114      * @throws IOException On error
115      */

116     private void startBookmark () throws IOException JavaDoc {
117
118         // {\*\bkmkstart test}
119
writeRtfBookmark ("bkmkstart");
120     }
121
122     /**
123      * Writes RTF content to close the bookmark.
124      *
125      * @throws IOException On error
126      */

127     private void endBookmark () throws IOException JavaDoc {
128
129         // {\*\bkmkend test}
130
writeRtfBookmark ("bkmkend");
131     }
132
133     /**
134      * Writes the rtf bookmark.
135      *
136      * @param tag Begin or close tag
137      *
138      * @throws IOException On error
139      */

140     private void writeRtfBookmark (String JavaDoc tag) throws IOException JavaDoc {
141         if (bookmark == null) {
142             return;
143
144         }
145
146         this.writeGroupMark (true);
147
148         //changed. Now using writeStarControlWord
149
this.writeStarControlWord (tag);
150
151         writer.write (bookmark);
152         this.writeGroupMark (false);
153     }
154
155         /**
156          * @return true if this element would generate no "useful" RTF content
157          */

158         public boolean isEmpty() {
159             return bookmark == null || bookmark.trim().length() == 0;
160         }
161 }
162
Popular Tags