Source Code Cross Referenced for ExplicitPropertiesFileRenderer.java in  » Installer » AntInstaller » org » tp23 » antinstaller » 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 » Installer » AntInstaller » org.tp23.antinstaller 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /* 
002:         * Copyright 2005 Paul Hinds
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:        package org.tp23.antinstaller;
017:
018:        import java.io.BufferedWriter;
019:        import java.io.File;
020:        import java.io.FileWriter;
021:        import java.util.Date;
022:        import java.util.Iterator;
023:        import java.util.List;
024:
025:        import org.tp23.antinstaller.input.ConditionalField;
026:        import org.tp23.antinstaller.input.InputField;
027:        import org.tp23.antinstaller.input.OutputField;
028:        import org.tp23.antinstaller.input.SecretPropertyField;
029:        import org.tp23.antinstaller.page.Page;
030:
031:        /**
032:         * <p>Outputs the completed Pages as a Java Properties file. The file produced is compatible
033:         * with java.util.Properties. </p>
034:         * <p>Output is commented as it is printed to aid debugging</p>
035:         * @see http://java.sun.com/docs/books/jls/second_edition/html/lexical.doc.html#100850
036:         * @author Paul Hinds
037:         * @version $Id: ExplicitPropertiesFileRenderer.java,v 1.9 2007/01/09 22:41:41 teknopaul Exp $
038:         */
039:        public class ExplicitPropertiesFileRenderer implements 
040:                PropertiesFileRenderer {
041:
042:            private static String newLine = System
043:                    .getProperty("line.separator");
044:            private static final char[] hexidecimals = { '0', '1', '2', '3',
045:                    '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' };
046:
047:            public ExplicitPropertiesFileRenderer() {
048:            }
049:
050:            public void renderProperties(InstallerContext ctx, File baseDir) {
051:                Installer installer = ctx.getInstaller();
052:                Page[] completedPages = installer.getPages();
053:
054:                StringBuffer propertiesData = new StringBuffer();
055:                propertiesData
056:                        .append("### Ant Installer - properties auto generated on ");
057:                propertiesData.append(convert(new Date().toString(), true));
058:                propertiesData.append(newLine);
059:                propertiesData.append(newLine);
060:
061:                propertiesData.append(FILE_ROOT_PROPERTY);
062:                propertiesData.append(" = ");
063:                propertiesData.append(convert(baseDir.getAbsolutePath(), true));
064:                propertiesData.append(newLine);
065:
066:                propertiesData.append(INSTALLER_VERSION_PROPERTY);
067:                propertiesData.append(" = ");
068:                propertiesData.append(convert(ctx.getInstaller().getVersion(),
069:                        true));
070:                propertiesData.append(newLine);
071:
072:                propertiesData.append(newLine);
073:                String property = null;
074:                String value = null;
075:
076:                for (int i = 0; i < completedPages.length; i++) {
077:                    OutputField[] fields = completedPages[i].getOutputField();
078:
079:                    propertiesData.append(newLine);
080:                    propertiesData.append("## Properties from Page:"
081:                            + completedPages[i].getName());
082:                    propertiesData.append(newLine);
083:
084:                    retrievePropertiesData(fields, propertiesData);
085:
086:                    // print targets selected
087:                    List targets = completedPages[i].getTargets(ctx);
088:                    if (targets.size() > 0) {
089:                        Iterator iterator = targets.iterator();
090:                        StringBuffer targetProperty = new StringBuffer();
091:                        while (iterator.hasNext()) {
092:                            String target = (String) iterator.next();
093:                            targetProperty.append(target).append(",");
094:                        }
095:                        propertiesData.append("# Targets selected for page");
096:                        propertiesData.append(newLine);
097:                        property = convert(completedPages[i].getName()
098:                                + TARGETS_SUFFIX, true);
099:                        value = convert(targetProperty.toString(), true);
100:                        propertiesData.append(property + " = " + value);
101:                        propertiesData.append(newLine);
102:
103:                    }
104:                }
105:                try {
106:                    File antInstallProperties = new File(baseDir
107:                            .getAbsolutePath(), PROPERTIES_FILE_NAME);
108:                    FileWriter fos = new FileWriter(antInstallProperties);
109:                    BufferedWriter writer = new BufferedWriter(fos);
110:                    writer.write(propertiesData.toString());
111:                    writer.flush();
112:                    fos.close();
113:                } catch (Throwable ex) {
114:                    if (ctx.getInstaller().isVerbose()) {
115:                        ctx.log(ex);
116:                    }
117:                    //swallow Exceptions as in the contract for this method
118:                }
119:            }
120:
121:            private void retrievePropertiesData(OutputField[] fields,
122:                    StringBuffer propertiesData) {
123:                String property = null;
124:                String value = null;
125:
126:                for (int f = 0; f < fields.length; f++) {
127:                    if (fields[f] instanceof  SecretPropertyField) {
128:                        InputField field = (InputField) fields[f];
129:                        //String result = field.getInputResult();
130:                        propertiesData.append("# Property hidden "
131:                                + printClass(fields[f].getClass()));
132:                        propertiesData.append(newLine);
133:                        property = convert(field.getProperty(), true);
134:                        propertiesData.append("#" + property + "=XXXXXXXX");
135:                        propertiesData.append(newLine);
136:                    } else if (fields[f] instanceof  ConditionalField) {
137:                        ConditionalField confField = (ConditionalField) fields[f];
138:                        retrievePropertiesData(confField.getFields(),
139:                                propertiesData);
140:                    } else if (fields[f] instanceof  InputField) {
141:                        InputField field = (InputField) fields[f];
142:                        String result = field.getInputResult();
143:                        propertiesData.append("# "
144:                                + printClass(fields[f].getClass()));
145:                        propertiesData.append(newLine);
146:
147:                        property = convert(field.getProperty(), true);
148:                        value = convert(result, false);
149:                        propertiesData.append(property + " = " + value);
150:                        propertiesData.append(newLine);
151:                    }
152:                }
153:            }
154:
155:            private String printClass(Class clazz) {
156:                String name = clazz.getName();
157:                int lastDot = name.lastIndexOf('.');
158:                return name.substring(lastDot, name.length());
159:            }
160:
161:            private String convert(String input, boolean doSpaces) {
162:                if (input == null) {
163:                    // this happens when a page is skipped in text mode
164:                    return "";
165:                }
166:                int num = input.length();
167:                StringBuffer sb = new StringBuffer(num);
168:
169:                for (int i = 0; i < num; i++) {
170:                    char c = input.charAt(i);
171:                    switch (c) {
172:                    case ' ':
173:                        if (i == 0 || doSpaces) {
174:                            sb.append('\\');
175:                        }
176:                        sb.append(' ');
177:                        break;
178:                    case '\n':
179:                        sb.append("\\n");
180:                        break;
181:                    case '\r':
182:                        sb.append("\\r");
183:                        break;
184:                    case '\\':
185:                        sb.append("\\\\");
186:                        break;
187:                    case '\t':
188:                        sb.append("\\t");
189:                        break;
190:                    case '\f':
191:                        sb.append("\\f");
192:                        break;
193:                    case '=':
194:                        sb.append("\\=");
195:                        break;
196:                    case ':':
197:                        sb.append("\\:");
198:                        break;
199:                    case '#':
200:                        sb.append("\\#");
201:                        break;
202:                    case '!':
203:                        sb.append("\\!");
204:                        break;
205:
206:                    default:
207:                        if ((c < 0x0020) || (c > 0x007e)) {
208:                            sb.append("\\u").append(hex((c >> 12) & 0xF))
209:                                    .append(hex((c >> 8) & 0xF)).append(
210:                                            hex((c >> 4) & 0xF)).append(
211:                                            hex(c & 0xF));
212:                        } else {
213:                            sb.append(c);
214:                        }
215:                    }
216:                }
217:                return sb.toString();
218:            }
219:
220:            private char hex(int val) {
221:                return hexidecimals[(val & 0xF)];
222:            }
223:
224:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.