Source Code Cross Referenced for AbstractFOPTranscoder.java in  » Graphic-Library » fop » org » apache » fop » svg » 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.svg 
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: AbstractFOPTranscoder.java 426576 2006-07-28 15:44:37Z jeremias $ */
019:
020:        package org.apache.fop.svg;
021:
022:        import org.xml.sax.EntityResolver;
023:
024:        import org.apache.commons.logging.impl.SimpleLog;
025:        import org.apache.commons.logging.Log;
026:        import org.apache.batik.bridge.UserAgent;
027:        import org.apache.batik.dom.svg.SVGDOMImplementation;
028:        import org.apache.batik.dom.util.DocumentFactory;
029:        import org.apache.batik.transcoder.ErrorHandler;
030:        import org.apache.batik.transcoder.TranscoderException;
031:        import org.apache.batik.transcoder.TranscodingHints;
032:        import org.apache.batik.transcoder.SVGAbstractTranscoder;
033:        import org.apache.batik.transcoder.image.ImageTranscoder;
034:        import org.apache.batik.transcoder.keys.BooleanKey;
035:        import org.apache.batik.util.SVGConstants;
036:        import org.w3c.dom.DOMImplementation;
037:
038:        /**
039:         * This is the common base class of all of FOP's transcoders.
040:         */
041:        public abstract class AbstractFOPTranscoder extends
042:                SVGAbstractTranscoder {
043:
044:            /**
045:             * The key to specify whether to stroke text instead of using text 
046:             * operations.
047:             */
048:            public static final TranscodingHints.Key KEY_STROKE_TEXT = new BooleanKey();
049:
050:            /** The value to turn on text stroking. */
051:            public static final Boolean VALUE_FORMAT_ON = Boolean.TRUE;
052:
053:            /** The value to turn off text stroking. */
054:            public static final Boolean VALUE_FORMAT_OFF = Boolean.FALSE;
055:
056:            /**
057:             * The user agent dedicated to this Transcoder.
058:             */
059:            protected UserAgent userAgent = createUserAgent();
060:
061:            private Log logger;
062:            private EntityResolver resolver;
063:
064:            /**
065:             * Constructs a new FOP-style transcoder.
066:             */
067:            public AbstractFOPTranscoder() {
068:                hints.put(KEY_DOCUMENT_ELEMENT_NAMESPACE_URI,
069:                        SVGConstants.SVG_NAMESPACE_URI);
070:                hints.put(KEY_DOCUMENT_ELEMENT, SVGConstants.SVG_SVG_TAG);
071:                hints.put(KEY_DOM_IMPLEMENTATION, SVGDOMImplementation
072:                        .getDOMImplementation());
073:            }
074:
075:            /**
076:             * Creates and returns the default user agent for this transcoder. Override
077:             * this method if you need non-default behaviour.
078:             * @return UserAgent the newly created user agent
079:             */
080:            protected UserAgent createUserAgent() {
081:                return new FOPTranscoderUserAgent();
082:            }
083:
084:            public void setLogger(Log logger) {
085:                this .logger = logger;
086:            }
087:
088:            /**
089:             * Sets the EntityResolver that should be used when building SVG documents.
090:             * @param resolver the resolver
091:             */
092:            public void setEntityResolver(EntityResolver resolver) {
093:                this .resolver = resolver;
094:            }
095:
096:            /**
097:             * Returns the logger associated with this transcoder. It returns a 
098:             * SimpleLog if no logger has been explicitly set.
099:             * @return Logger the logger for the transcoder.
100:             */
101:            protected final Log getLogger() {
102:                if (this .logger == null) {
103:                    this .logger = new SimpleLog("FOP/Transcoder");
104:                    ((SimpleLog) logger).setLevel(SimpleLog.LOG_LEVEL_INFO);
105:                }
106:                return this .logger;
107:            }
108:
109:            /**
110:             * Creates a <tt>DocumentFactory</tt> that is used to create an SVG DOM
111:             * tree. The specified DOM Implementation is ignored and the Batik
112:             * SVG DOM Implementation is automatically used.
113:             *
114:             * @param domImpl the DOM Implementation (not used)
115:             * @param parserClassname the XML parser classname
116:             * @return the document factory
117:             */
118:            protected DocumentFactory createDocumentFactory(
119:                    DOMImplementation domImpl, String parserClassname) {
120:                final FOPSAXSVGDocumentFactory factory = new FOPSAXSVGDocumentFactory(
121:                        parserClassname);
122:                if (this .resolver != null) {
123:                    factory.setAdditionalEntityResolver(this .resolver);
124:                }
125:                return factory;
126:            }
127:
128:            // --------------------------------------------------------------------
129:            // FOP's default error handler (for transcoders)
130:            // --------------------------------------------------------------------
131:
132:            /**
133:             * This is the default transcoder error handler for FOP. It logs error
134:             * to an Commons Logger instead of to System.out. The remaining behaviour 
135:             * is the same as Batik's DefaultErrorHandler.
136:             */
137:            protected class FOPErrorHandler implements  ErrorHandler {
138:
139:                /**
140:                 * @see org.apache.batik.transcoder.ErrorHandler#error(TranscoderException)
141:                 */
142:                public void error(TranscoderException te)
143:                        throws TranscoderException {
144:                    getLogger().error(te.getMessage());
145:                }
146:
147:                /**
148:                 * @see org.apache.batik.transcoder.ErrorHandler#fatalError(TranscoderException)
149:                 */
150:                public void fatalError(TranscoderException te)
151:                        throws TranscoderException {
152:                    throw te;
153:                }
154:
155:                /**
156:                 * @see org.apache.batik.transcoder.ErrorHandler#warning(TranscoderException)
157:                 */
158:                public void warning(TranscoderException te)
159:                        throws TranscoderException {
160:                    getLogger().warn(te.getMessage());
161:                }
162:
163:            }
164:
165:            // --------------------------------------------------------------------
166:            // UserAgent implementation
167:            // --------------------------------------------------------------------
168:
169:            /**
170:             * A user agent implementation for FOP's Transcoders.
171:             */
172:            protected class FOPTranscoderUserAgent extends
173:                    SVGAbstractTranscoderUserAgent {
174:
175:                /**
176:                 * Displays the specified error message using the <tt>ErrorHandler</tt>.
177:                 * @param message the message to display
178:                 */
179:                public void displayError(String message) {
180:                    try {
181:                        getErrorHandler().error(
182:                                new TranscoderException(message));
183:                    } catch (TranscoderException ex) {
184:                        throw new RuntimeException();
185:                    }
186:                }
187:
188:                /**
189:                 * Displays the specified error using the <tt>ErrorHandler</tt>.
190:                 * @param e the exception to display
191:                 */
192:                public void displayError(Exception e) {
193:                    try {
194:                        getErrorHandler().error(new TranscoderException(e));
195:                    } catch (TranscoderException ex) {
196:                        throw new RuntimeException();
197:                    }
198:                }
199:
200:                /**
201:                 * Displays the specified message using the <tt>ErrorHandler</tt>.
202:                 * @param message the message to display
203:                 */
204:                public void displayMessage(String message) {
205:                    getLogger().info(message);
206:                }
207:
208:                /**
209:                 * Returns the pixel to millimeter conversion factor specified in the
210:                 * <tt>TranscodingHints</tt> or 0.3528 if any.
211:                 * @return the pixel unit to millimeter factor
212:                 */
213:                public float getPixelUnitToMillimeter() {
214:                    Object key = ImageTranscoder.KEY_PIXEL_UNIT_TO_MILLIMETER;
215:                    if (getTranscodingHints().containsKey(key)) {
216:                        return ((Float) getTranscodingHints().get(key))
217:                                .floatValue();
218:                    } else {
219:                        // return 0.3528f; // 72 dpi
220:                        return 25.4f / 96; //96dpi = 0.2645833333333333333f;
221:                    }
222:                }
223:
224:                /**
225:                 * Get the media for this transcoder. Which is always print.
226:                 * @return PDF media is "print"
227:                 */
228:                public String getMedia() {
229:                    return "print";
230:                }
231:
232:            }
233:
234:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.