Source Code Cross Referenced for Hyphenator.java in  » PDF » pdf-itext » com » lowagie » text » pdf » hyphenation » 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 » PDF » pdf itext » com.lowagie.text.pdf.hyphenation 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright 1999-2004 The Apache Software Foundation.
003:         * 
004:         * Licensed under the Apache License, Version 2.0 (the "License");
005:         * you may not use this file except in compliance with the License.
006:         * You may obtain a copy of the License at
007:         * 
008:         *      http://www.apache.org/licenses/LICENSE-2.0
009:         * 
010:         * Unless required by applicable law or agreed to in writing, software
011:         * distributed under the License is distributed on an "AS IS" BASIS,
012:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013:         * See the License for the specific language governing permissions and
014:         * limitations under the License.
015:         */
016:
017:        package com.lowagie.text.pdf.hyphenation;
018:
019:        import java.io.File;
020:        import java.io.FileInputStream;
021:        import java.io.InputStream;
022:        import java.util.Hashtable;
023:
024:        import com.lowagie.text.pdf.BaseFont;
025:
026:        /**
027:         * This class is the main entry point to the hyphenation package.
028:         * You can use only the static methods or create an instance.
029:         *
030:         * @author Carlos Villegas <cav@uniscope.co.jp>
031:         */
032:        public class Hyphenator {
033:
034:            /** TODO: Don't use statics */
035:            private static Hashtable hyphenTrees = new Hashtable();
036:
037:            private HyphenationTree hyphenTree = null;
038:            private int remainCharCount = 2;
039:            private int pushCharCount = 2;
040:            private static final String defaultHyphLocation = "com/lowagie/text/pdf/hyphenation/hyph/";
041:
042:            /** Holds value of property hyphenDir. */
043:            private static String hyphenDir = "";
044:
045:            /**
046:             * @param lang
047:             * @param country
048:             * @param leftMin
049:             * @param rightMin
050:             */
051:            public Hyphenator(String lang, String country, int leftMin,
052:                    int rightMin) {
053:                hyphenTree = getHyphenationTree(lang, country);
054:                remainCharCount = leftMin;
055:                pushCharCount = rightMin;
056:            }
057:
058:            /**
059:             * @param lang
060:             * @param country
061:             * @return the hyphenation tree
062:             */
063:            public static HyphenationTree getHyphenationTree(String lang,
064:                    String country) {
065:                String key = lang;
066:                // check whether the country code has been used
067:                if (country != null && !country.equals("none")) {
068:                    key += "_" + country;
069:                }
070:                // first try to find it in the cache
071:                if (hyphenTrees.containsKey(key)) {
072:                    return (HyphenationTree) hyphenTrees.get(key);
073:                }
074:                if (hyphenTrees.containsKey(lang)) {
075:                    return (HyphenationTree) hyphenTrees.get(lang);
076:                }
077:
078:                HyphenationTree hTree = getResourceHyphenationTree(key);
079:                if (hTree == null)
080:                    hTree = getFileHyphenationTree(key);
081:                // put it into the pattern cache
082:                if (hTree != null) {
083:                    hyphenTrees.put(key, hTree);
084:                }
085:                return hTree;
086:            }
087:
088:            /**
089:             * @param key
090:             * @return a hyphenation tree
091:             */
092:            public static HyphenationTree getResourceHyphenationTree(String key) {
093:                try {
094:                    InputStream stream = BaseFont
095:                            .getResourceStream(defaultHyphLocation + key
096:                                    + ".xml");
097:                    if (stream == null && key.length() > 2)
098:                        stream = BaseFont.getResourceStream(defaultHyphLocation
099:                                + key.substring(0, 2) + ".xml");
100:                    if (stream == null)
101:                        return null;
102:                    HyphenationTree hTree = new HyphenationTree();
103:                    hTree.loadSimplePatterns(stream);
104:                    return hTree;
105:                } catch (Exception e) {
106:                    return null;
107:                }
108:            }
109:
110:            /**
111:             * @param key
112:             * @return a hyphenation tree
113:             */
114:            public static HyphenationTree getFileHyphenationTree(String key) {
115:                try {
116:                    if (hyphenDir == null)
117:                        return null;
118:                    InputStream stream = null;
119:                    File hyphenFile = new File(hyphenDir, key + ".xml");
120:                    if (hyphenFile.canRead())
121:                        stream = new FileInputStream(hyphenFile);
122:                    if (stream == null && key.length() > 2) {
123:                        hyphenFile = new File(hyphenDir, key.substring(0, 2)
124:                                + ".xml");
125:                        if (hyphenFile.canRead())
126:                            stream = new FileInputStream(hyphenFile);
127:                    }
128:                    if (stream == null)
129:                        return null;
130:                    HyphenationTree hTree = new HyphenationTree();
131:                    hTree.loadSimplePatterns(stream);
132:                    return hTree;
133:                } catch (Exception e) {
134:                    return null;
135:                }
136:            }
137:
138:            /**
139:             * @param lang
140:             * @param country
141:             * @param word
142:             * @param leftMin
143:             * @param rightMin
144:             * @return a hyphenation object
145:             */
146:            public static Hyphenation hyphenate(String lang, String country,
147:                    String word, int leftMin, int rightMin) {
148:                HyphenationTree hTree = getHyphenationTree(lang, country);
149:                if (hTree == null) {
150:                    //log.error("Error building hyphenation tree for language "
151:                    //                       + lang);
152:                    return null;
153:                }
154:                return hTree.hyphenate(word, leftMin, rightMin);
155:            }
156:
157:            /**
158:             * @param lang
159:             * @param country
160:             * @param word
161:             * @param offset
162:             * @param len
163:             * @param leftMin
164:             * @param rightMin
165:             * @return a hyphenation object
166:             */
167:            public static Hyphenation hyphenate(String lang, String country,
168:                    char[] word, int offset, int len, int leftMin, int rightMin) {
169:                HyphenationTree hTree = getHyphenationTree(lang, country);
170:                if (hTree == null) {
171:                    //log.error("Error building hyphenation tree for language "
172:                    //                       + lang);
173:                    return null;
174:                }
175:                return hTree.hyphenate(word, offset, len, leftMin, rightMin);
176:            }
177:
178:            /**
179:             * @param min
180:             */
181:            public void setMinRemainCharCount(int min) {
182:                remainCharCount = min;
183:            }
184:
185:            /**
186:             * @param min
187:             */
188:            public void setMinPushCharCount(int min) {
189:                pushCharCount = min;
190:            }
191:
192:            /**
193:             * @param lang
194:             * @param country
195:             */
196:            public void setLanguage(String lang, String country) {
197:                hyphenTree = getHyphenationTree(lang, country);
198:            }
199:
200:            /**
201:             * @param word
202:             * @param offset
203:             * @param len
204:             * @return a hyphenation object
205:             */
206:            public Hyphenation hyphenate(char[] word, int offset, int len) {
207:                if (hyphenTree == null) {
208:                    return null;
209:                }
210:                return hyphenTree.hyphenate(word, offset, len, remainCharCount,
211:                        pushCharCount);
212:            }
213:
214:            /**
215:             * @param word
216:             * @return a hyphenation object
217:             */
218:            public Hyphenation hyphenate(String word) {
219:                if (hyphenTree == null) {
220:                    return null;
221:                }
222:                return hyphenTree.hyphenate(word, remainCharCount,
223:                        pushCharCount);
224:            }
225:
226:            /** Getter for property hyphenDir.
227:             * @return Value of property hyphenDir.
228:             */
229:            public static String getHyphenDir() {
230:                return hyphenDir;
231:            }
232:
233:            /** Setter for property hyphenDir.
234:             * @param _hyphenDir New value of property hyphenDir.
235:             */
236:            public static void setHyphenDir(String _hyphenDir) {
237:                hyphenDir = _hyphenDir;
238:            }
239:
240:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.