Source Code Cross Referenced for AbstractFontReader.java in  » Graphic-Library » fop » org » apache » fop » fonts » apps » 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.fonts.apps 
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$ */
019:
020:        package org.apache.fop.fonts.apps;
021:
022:        import java.io.File;
023:        import java.io.IOException;
024:        import java.io.OutputStream;
025:        import java.util.List;
026:        import java.util.Map;
027:
028:        import javax.xml.transform.Transformer;
029:        import javax.xml.transform.TransformerException;
030:        import javax.xml.transform.TransformerFactory;
031:
032:        import org.apache.commons.logging.Log;
033:        import org.apache.commons.logging.LogFactory;
034:        import org.apache.fop.util.CommandLineLogger;
035:
036:        /**
037:         * Abstract base class for the PFM and TTF Reader command-line applications.
038:         */
039:        public abstract class AbstractFontReader {
040:
041:            /** Logger instance */
042:            protected static Log log;
043:
044:            /**
045:             * Main constructor.
046:             */
047:            protected AbstractFontReader() {
048:                // Create logger if necessary here to allow embedding of TTFReader in
049:                // other applications. There is a possible but harmless synchronization
050:                // issue.
051:                if (log == null) {
052:                    log = LogFactory.getLog(AbstractFontReader.class);
053:                }
054:            }
055:
056:            /**
057:             * Parse commandline arguments. put options in the HashMap and return
058:             * arguments in the String array
059:             * the arguments: -fn Perpetua,Bold -cn PerpetuaBold per.ttf Perpetua.xml
060:             * returns a String[] with the per.ttf and Perpetua.xml. The hash
061:             * will have the (key, value) pairs: (-fn, Perpetua) and (-cn, PerpetuaBold)
062:             * @param options Map that will receive options
063:             * @param args the command-line arguments
064:             * @return the arguments
065:             */
066:            protected static String[] parseArguments(Map options, String[] args) {
067:                List arguments = new java.util.ArrayList();
068:                for (int i = 0; i < args.length; i++) {
069:                    if (args[i].startsWith("-")) {
070:                        if ("-d".equals(args[i]) || "-q".equals(args[i])) {
071:                            options.put(args[i], "");
072:                        } else if ((i + 1) < args.length
073:                                && !args[i + 1].startsWith("-")) {
074:                            options.put(args[i], args[i + 1]);
075:                            i++;
076:                        } else {
077:                            options.put(args[i], "");
078:                        }
079:                    } else {
080:                        arguments.add(args[i]);
081:                    }
082:                }
083:                return (String[]) arguments.toArray(new String[0]);
084:            }
085:
086:            /**
087:             * Sets the logging level.
088:             * @param level the logging level ("debug", "info", "error" etc., see Jakarta Commons Logging) 
089:             */
090:            protected static void setLogLevel(String level) {
091:                // Set the evel for future loggers.
092:                LogFactory.getFactory().setAttribute("level", level);
093:                if (log instanceof  CommandLineLogger) {
094:                    // Set the level for the logger creates already.
095:                    ((CommandLineLogger) log).setLogLevel(level);
096:                }
097:            }
098:
099:            /**
100:             * Determines the log level based of the options from the command-line.
101:             * @param options the command-line options
102:             */
103:            protected static void determineLogLevel(Map options) {
104:                //Determine log level
105:                if (options.get("-d") != null) {
106:                    setLogLevel("debug");
107:                } else if (options.get("-q") != null) {
108:                    setLogLevel("error");
109:                } else {
110:                    setLogLevel("info");
111:                }
112:            }
113:
114:            /**
115:             * Writes the generated DOM Document to a file.
116:             *
117:             * @param   doc The DOM Document to save.
118:             * @param   target The target filename for the XML file.
119:             * @throws TransformerException if an error occurs during serialization
120:             */
121:            public void writeFontXML(org.w3c.dom.Document doc, String target)
122:                    throws TransformerException {
123:                writeFontXML(doc, new File(target));
124:            }
125:
126:            /**
127:             * Writes the generated DOM Document to a file.
128:             *
129:             * @param   doc The DOM Document to save.
130:             * @param   target The target file for the XML file.
131:             * @throws TransformerException if an error occurs during serialization
132:             */
133:            public void writeFontXML(org.w3c.dom.Document doc, File target)
134:                    throws TransformerException {
135:                log.info("Writing xml font file " + target + "...");
136:
137:                try {
138:                    OutputStream out = new java.io.FileOutputStream(target);
139:                    out = new java.io.BufferedOutputStream(out);
140:                    try {
141:                        TransformerFactory factory = TransformerFactory
142:                                .newInstance();
143:                        Transformer transformer = factory.newTransformer();
144:                        transformer
145:                                .transform(
146:                                        new javax.xml.transform.dom.DOMSource(
147:                                                doc),
148:                                        new javax.xml.transform.stream.StreamResult(
149:                                                out));
150:                    } finally {
151:                        out.close();
152:                    }
153:                } catch (IOException ioe) {
154:                    throw new TransformerException(
155:                            "Error writing the output file", ioe);
156:                }
157:            }
158:
159:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.