Source Code Cross Referenced for RtfStyleSheetTable.java in  » Graphic-Library » fop » org » apache » fop » render » rtf » rtflib » rtfdoc » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Graphic Library » fop » org.apache.fop.render.rtf.rtflib.rtfdoc 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


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: RtfStyleSheetTable.java 426576 2006-07-28 15:44:37Z jeremias $ */
019:
020:        /*
021:         * This file is part of the RTF library of the FOP project, which was originally
022:         * created by Bertrand Delacretaz <bdelacretaz@codeconsult.ch> and by other
023:         * contributors to the jfor project (www.jfor.org), who agreed to donate jfor to
024:         * the FOP project.
025:         */
026:
027:        package org.apache.fop.render.rtf.rtflib.rtfdoc;
028:
029:        import java.util.Vector;
030:        import java.util.Hashtable;
031:        import java.io.IOException;
032:        import java.util.Iterator;
033:
034:        /**
035:         * Singelton of the RTF style sheet table.
036:         * This class belongs to the <jfor:stylesheet> tag processing.
037:         * @author <a href="mailto:a.putz@skynamics.com">Andreas Putz</a>
038:         */
039:        public class RtfStyleSheetTable {
040:            //////////////////////////////////////////////////
041:            // @@ Symbolic constants
042:            //////////////////////////////////////////////////
043:
044:            /** Start index number for the stylesheet reference table */
045:            private static int startIndex = 15;
046:
047:            /** OK status value for attribute handling */
048:            public static final int STATUS_OK = 0;
049:            /** Status value for attribute handling, if the stylesheet not found and
050:             *  the stylesheet set to the default stylesheet */
051:            public static final int STATUS_DEFAULT = 1;
052:
053:            /** Standard style name */
054:            private static final String STANDARD_STYLE = "Standard";
055:
056:            //////////////////////////////////////////////////
057:            // @@ Singleton
058:            //////////////////////////////////////////////////
059:
060:            /** Singelton instance */
061:            private static RtfStyleSheetTable instance = null;
062:
063:            //////////////////////////////////////////////////
064:            // @@ Members
065:            //////////////////////////////////////////////////
066:
067:            /** Table of styles */
068:            private Hashtable styles = null;
069:
070:            /** Used, style attributes to this vector */
071:            private Hashtable attrTable = null;
072:
073:            /** Used, style names to this vector */
074:            private Vector nameTable = null;
075:
076:            /** Default style */
077:            private String defaultStyleName = STANDARD_STYLE;
078:
079:            //////////////////////////////////////////////////
080:            // @@ Construction
081:            //////////////////////////////////////////////////
082:
083:            /**
084:             * Constructor.
085:             */
086:            private RtfStyleSheetTable() {
087:                styles = new Hashtable();
088:                attrTable = new Hashtable();
089:                nameTable = new Vector();
090:            }
091:
092:            /**
093:             * Singelton.
094:             *
095:             * @return The instance of RtfStyleSheetTable
096:             */
097:            public static RtfStyleSheetTable getInstance() {
098:                if (instance == null) {
099:                    instance = new RtfStyleSheetTable();
100:                }
101:
102:                return instance;
103:            }
104:
105:            //////////////////////////////////////////////////
106:            // @@ Member access
107:            //////////////////////////////////////////////////
108:
109:            /**
110:             * Sets the default style.
111:             * @param styleName Name of the default style, defined in the stylesheet
112:             */
113:            public void setDefaultStyle(String styleName) {
114:                this .defaultStyleName = styleName;
115:            }
116:
117:            /**
118:             * Gets the name of the default style.
119:             * @return Default style name.
120:             */
121:            public String getDefaultStyleName() {
122:                if (attrTable.get(defaultStyleName) != null) {
123:                    return defaultStyleName;
124:                }
125:
126:                if (attrTable.get(STANDARD_STYLE) != null) {
127:                    defaultStyleName = STANDARD_STYLE;
128:                    return defaultStyleName;
129:                }
130:
131:                return null;
132:            }
133:
134:            //////////////////////////////////////////////////
135:            // @@ Public methods
136:            //////////////////////////////////////////////////
137:
138:            /**
139:             * Adds a style to the table.
140:             * @param name Name of style to add
141:             * @param attrs Rtf attributes which defines the style
142:             */
143:            public void addStyle(String name, RtfAttributes attrs) {
144:                nameTable.addElement(name);
145:                if (attrs != null) {
146:                    attrTable.put(name, attrs);
147:                }
148:                styles
149:                        .put(name, new Integer(nameTable.size() - 1
150:                                + startIndex));
151:            }
152:
153:            /**
154:             * Adds the style attributes to the given attributes.
155:             * @param name Name of style, of which the attributes will copied to attr
156:             * @param attr Default rtf attributes
157:             * @return Status value
158:             */
159:            public int addStyleToAttributes(String name, RtfAttributes attr) {
160:                // Sets status to ok
161:                int status = STATUS_OK;
162:
163:                // Gets the style number from table
164:                Integer style = (Integer) styles.get(name);
165:
166:                if (style == null && !name.equals(defaultStyleName)) {
167:                    // If style not found, and style was not the default style, try the default style
168:                    name = defaultStyleName;
169:                    style = (Integer) styles.get(name);
170:                    // set status for default style setting
171:                    status = STATUS_DEFAULT;
172:                }
173:
174:                // Returns the status for invalid styles
175:                if (style == null) {
176:                    return status;
177:                }
178:
179:                // Adds the attributes to default attributes, if not available in default attributes
180:                attr.set("cs", style.intValue());
181:
182:                Object o = attrTable.get(name);
183:                if (o != null) {
184:                    RtfAttributes rtfAttr = (RtfAttributes) o;
185:
186:                    for (Iterator names = rtfAttr.nameIterator(); names
187:                            .hasNext();) {
188:                        String attrName = (String) names.next();
189:                        if (!attr.isSet(attrName)) {
190:                            Integer i = (Integer) rtfAttr.getValue(attrName);
191:                            if (i == null) {
192:                                attr.set(attrName);
193:                            } else {
194:                                attr.set(attrName, i.intValue());
195:                            }
196:                        }
197:                    }
198:                }
199:                return status;
200:            }
201:
202:            /**
203:             * Writes the rtf style sheet table.
204:             * @param header Rtf header is the parent
205:             * @throws IOException On write error
206:             */
207:            public void writeStyleSheet(RtfHeader header) throws IOException {
208:                if (styles == null || styles.size() == 0) {
209:                    return;
210:                }
211:                header.writeGroupMark(true);
212:                header.writeControlWord("stylesheet");
213:
214:                int number = nameTable.size();
215:                for (int i = 0; i < number; i++) {
216:                    String name = (String) nameTable.elementAt(i);
217:                    header.writeGroupMark(true);
218:                    header.writeControlWord("*\\"
219:                            + this .getRtfStyleReference(name));
220:
221:                    Object o = attrTable.get(name);
222:                    if (o != null) {
223:                        header.writeAttributes((RtfAttributes) o,
224:                                RtfText.ATTR_NAMES);
225:                        header.writeAttributes((RtfAttributes) o,
226:                                RtfText.ALIGNMENT);
227:                    }
228:
229:                    header.write(name + ";");
230:                    header.writeGroupMark(false);
231:                }
232:                header.writeGroupMark(false);
233:            }
234:
235:            /**
236:             * Gets the rtf style reference from the table.
237:             * @param name Name of Style
238:             * @return Rtf attribute of the style reference
239:             */
240:            private String getRtfStyleReference(String name) {
241:                return "cs" + styles.get(name).toString();
242:            }
243:        }
w___w___w__.__ja___v___a__2__s_.__c___o___m | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.