Source Code Cross Referenced for ConversionOptionsPropertiesReader.java in  » Code-Analyzer » Java2Html » de » java2html » properties » 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 » Code Analyzer » Java2Html » de.java2html.properties 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package de.java2html.properties;
002:
003:        import java.util.Properties;
004:        import java.util.StringTokenizer;
005:
006:        import de.java2html.javasource.JavaSourceType;
007:        import de.java2html.options.ConversionOptionsUtilities;
008:        import de.java2html.options.HorizontalAlignment;
009:        import de.java2html.options.IConversionOptionsConstants;
010:        import de.java2html.options.JavaSourceConversionOptions;
011:        import de.java2html.options.JavaSourceStyleEntry;
012:        import de.java2html.options.JavaSourceStyleTable;
013:        import de.java2html.util.RGB;
014:
015:        /**
016:         * @author Markus Gebhard
017:         */
018:        public class ConversionOptionsPropertiesReader {
019:
020:            public JavaSourceConversionOptions read(Properties properties)
021:                    throws IllegalPropertyValueException {
022:                JavaSourceConversionOptions conversionOptions = JavaSourceConversionOptions
023:                        .getRawDefault();
024:                adjustStyleTable(properties, conversionOptions);
025:                adjustShowFileName(properties, conversionOptions);
026:                adjustBorder(properties, conversionOptions);
027:                adjustLineNumbers(properties, conversionOptions);
028:                adjustShowJava2HtmlLink(properties, conversionOptions);
029:                adjustTabSize(properties, conversionOptions);
030:                adjustAlignment(properties, conversionOptions);
031:                adjustStyleEntries(properties, conversionOptions);
032:                return conversionOptions;
033:            }
034:
035:            private void adjustAlignment(Properties properties,
036:                    JavaSourceConversionOptions conversionOptions)
037:                    throws IllegalPropertyValueException {
038:                String alignmentValue = properties
039:                        .getProperty(IConversionOptionsConstants.HORIZONTAL_ALIGNMENT);
040:                if (alignmentValue != null) {
041:                    HorizontalAlignment alignment = HorizontalAlignment
042:                            .getByName(alignmentValue);
043:                    if (alignment == null) {
044:                        throw new IllegalPropertyValueException(
045:                                IConversionOptionsConstants.HORIZONTAL_ALIGNMENT,
046:                                alignmentValue, ConversionOptionsUtilities
047:                                        .getAvailableHorizontalAlignmentNames());
048:                    }
049:                    conversionOptions.setHorizontalAlignment(alignment);
050:                }
051:            }
052:
053:            private void adjustTabSize(Properties properties,
054:                    JavaSourceConversionOptions conversionOptions)
055:                    throws IllegalPropertyValueException {
056:                String tabSizeValue = properties
057:                        .getProperty(IConversionOptionsConstants.TAB_SIZE);
058:                if (tabSizeValue != null) {
059:                    try {
060:                        int tabSize = Integer.parseInt(tabSizeValue);
061:                        if (tabSize < 0) {
062:                            throw new NumberFormatException();
063:                        }
064:                        conversionOptions.setTabSize(tabSize);
065:                    } catch (NumberFormatException e) {
066:                        throw new IllegalPropertyValueException(
067:                                IConversionOptionsConstants.TAB_SIZE,
068:                                tabSizeValue);
069:                    }
070:                }
071:            }
072:
073:            private void adjustShowFileName(Properties properties,
074:                    JavaSourceConversionOptions conversionOptions)
075:                    throws IllegalPropertyValueException {
076:                String value = properties
077:                        .getProperty(IConversionOptionsConstants.SHOW_FILE_NAME);
078:                if (value != null) {
079:                    conversionOptions.setShowFileName(parseBooleanValue(
080:                            IConversionOptionsConstants.SHOW_FILE_NAME, value));
081:                }
082:            }
083:
084:            private void adjustShowJava2HtmlLink(Properties properties,
085:                    JavaSourceConversionOptions conversionOptions)
086:                    throws IllegalPropertyValueException {
087:                String value = properties
088:                        .getProperty(IConversionOptionsConstants.SHOW_JAVA2HTML_LINK);
089:                if (value != null) {
090:                    conversionOptions.setShowJava2HtmlLink(parseBooleanValue(
091:                            IConversionOptionsConstants.SHOW_JAVA2HTML_LINK,
092:                            value));
093:                }
094:            }
095:
096:            private void adjustLineNumbers(Properties properties,
097:                    JavaSourceConversionOptions conversionOptions)
098:                    throws IllegalPropertyValueException {
099:                String value = properties
100:                        .getProperty(IConversionOptionsConstants.SHOW_LINE_NUMBERS);
101:                if (value != null) {
102:                    conversionOptions.setShowLineNumbers(parseBooleanValue(
103:                            IConversionOptionsConstants.SHOW_LINE_NUMBERS,
104:                            value));
105:                }
106:            }
107:
108:            private void adjustBorder(Properties properties,
109:                    JavaSourceConversionOptions conversionOptions)
110:                    throws IllegalPropertyValueException {
111:                String value = properties
112:                        .getProperty(IConversionOptionsConstants.SHOW_TABLE_BORDER);
113:                if (value != null) {
114:                    conversionOptions.setShowTableBorder(parseBooleanValue(
115:                            IConversionOptionsConstants.SHOW_TABLE_BORDER,
116:                            value));
117:                }
118:            }
119:
120:            private void adjustStyleTable(Properties properties,
121:                    JavaSourceConversionOptions conversionOptions)
122:                    throws IllegalPropertyValueException {
123:                String defaultTableName = properties
124:                        .getProperty(IConversionOptionsConstants.DEFAULT_STYLE_NAME);
125:                if (defaultTableName != null) {
126:                    JavaSourceStyleTable table = JavaSourceStyleTable
127:                            .getPredefinedTable(defaultTableName);
128:                    if (table == null) {
129:                        throw new IllegalPropertyValueException(
130:                                IConversionOptionsConstants.DEFAULT_STYLE_NAME,
131:                                defaultTableName, ConversionOptionsUtilities
132:                                        .getPredefinedStyleTableNames());
133:                    }
134:                    conversionOptions.setStyleTable(table);
135:                }
136:            }
137:
138:            private boolean parseBooleanValue(String propertyName, String value)
139:                    throws IllegalPropertyValueException {
140:                if (value.equalsIgnoreCase("true")
141:                        || value.equalsIgnoreCase("yes")) {
142:                    return true;
143:                }
144:                if (value.equalsIgnoreCase("false")
145:                        || value.equalsIgnoreCase("no")) {
146:                    return false;
147:                }
148:                throw new IllegalPropertyValueException(propertyName, value,
149:                        new String[] { "true", "false" });
150:            }
151:
152:            private RGB parseColorValue(String propertyName, String colorValue)
153:                    throws IllegalPropertyValueException {
154:                StringTokenizer tokenizer = new StringTokenizer(colorValue, ","); //$NON-NLS-1$
155:                if (tokenizer.countTokens() != 3) {
156:                    throw new IllegalPropertyValueException(propertyName,
157:                            colorValue);
158:                }
159:                String redValue = tokenizer.nextToken();
160:                String greenValue = tokenizer.nextToken();
161:                String blueValue = tokenizer.nextToken();
162:                int red = 0, green = 0, blue = 0;
163:                try {
164:                    red = Integer.parseInt(redValue);
165:                    green = Integer.parseInt(greenValue);
166:                    blue = Integer.parseInt(blueValue);
167:                } catch (NumberFormatException e) {
168:                    throw new IllegalPropertyValueException(propertyName,
169:                            colorValue);
170:                }
171:                if (red > 255 || red < 0 || green > 255 || green < 0
172:                        || blue > 255 || blue < 0) {
173:                    throw new IllegalPropertyValueException(propertyName,
174:                            colorValue);
175:                }
176:                return new RGB(red, green, blue);
177:            }
178:
179:            private void adjustStyleEntries(Properties properties,
180:                    JavaSourceConversionOptions conversionOptions)
181:                    throws IllegalPropertyValueException {
182:                JavaSourceType[] sourceTypes = JavaSourceType.getAll();
183:                for (int i = 0; i < sourceTypes.length; i++) {
184:                    adjustStyleEntry(properties, conversionOptions,
185:                            sourceTypes[i]);
186:                }
187:            }
188:
189:            private void adjustStyleEntry(Properties properties,
190:                    JavaSourceConversionOptions conversionOptions,
191:                    JavaSourceType type) throws IllegalPropertyValueException {
192:                RGB color = getColor(properties, conversionOptions, type);
193:                boolean bold = getBold(properties, conversionOptions, type);
194:                boolean italic = getItalic(properties, conversionOptions, type);
195:                conversionOptions.getStyleTable().put(type,
196:                        new JavaSourceStyleEntry(color, bold, italic));
197:            }
198:
199:            private boolean getItalic(Properties properties,
200:                    JavaSourceConversionOptions conversionOptions,
201:                    JavaSourceType type) throws IllegalPropertyValueException {
202:
203:                String italicPropertyName = type.getName()
204:                        + IConversionOptionsConstants.POSTFIX_ITALIC;
205:                String italicValue = properties.getProperty(italicPropertyName);
206:                if (italicValue != null) {
207:                    return parseBooleanValue(italicPropertyName, italicValue);
208:                }
209:                return conversionOptions.getStyleTable().get(type).isItalic();
210:            }
211:
212:            private boolean getBold(Properties properties,
213:                    JavaSourceConversionOptions conversionOptions,
214:                    JavaSourceType type) throws IllegalPropertyValueException {
215:                String boldPropertyName = type.getName()
216:                        + IConversionOptionsConstants.POSTFIX_BOLD;
217:                String boldValue = properties.getProperty(boldPropertyName);
218:                if (boldValue != null) {
219:                    return parseBooleanValue(boldPropertyName, boldValue);
220:                }
221:                return conversionOptions.getStyleTable().get(type).isBold();
222:            }
223:
224:            private RGB getColor(Properties properties,
225:                    JavaSourceConversionOptions conversionOptions,
226:                    JavaSourceType type) throws IllegalPropertyValueException {
227:                String colorPropertyName = type.getName()
228:                        + IConversionOptionsConstants.POSTFIX_COLOR;
229:                String colorValue = properties.getProperty(colorPropertyName);
230:                if (colorValue != null) {
231:                    return parseColorValue(colorPropertyName, colorValue);
232:                }
233:                return conversionOptions.getStyleTable().get(type).getColor();
234:            }
235:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.