Source Code Cross Referenced for ShortcutPanelAutomationHelper.java in  » Installer » IzPack » com » izforge » izpack » panels » 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 » IzPack » com.izforge.izpack.panels 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * $Id: copyright-notice-template 1421 2006-03-12 16:32:32Z jponge $
003:         * IzPack - Copyright 2001-2008 Julien Ponge, All Rights Reserved.
004:         *
005:         * http://izpack.org/
006:         * http://izpack.codehaus.org/
007:         *
008:         * Copyright 2006 Marc Eppelmann (marc.eppelmann@gmx.de)
009:         *
010:         * Licensed under the Apache License, Version 2.0 (the "License");
011:         * you may not use this file except in compliance with the License.
012:         * You may obtain a copy of the License at
013:         *
014:         *     http://www.apache.org/licenses/LICENSE-2.0
015:         *
016:         * Unless required by applicable law or agreed to in writing, software
017:         * distributed under the License is distributed on an "AS IS" BASIS,
018:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
019:         * See the License for the specific language governing permissions and
020:         * limitations under the License.
021:         */
022:        package com.izforge.izpack.panels;
023:
024:        import com.izforge.izpack.ExecutableFile;
025:        import com.izforge.izpack.installer.AutomatedInstallData;
026:        import com.izforge.izpack.installer.PanelAutomation;
027:        import com.izforge.izpack.installer.UninstallData;
028:        import com.izforge.izpack.util.Debug;
029:        import com.izforge.izpack.util.FileExecutor;
030:        import com.izforge.izpack.util.OsConstraint;
031:        import com.izforge.izpack.util.OsVersion;
032:        import com.izforge.izpack.util.TargetFactory;
033:        import com.izforge.izpack.util.os.Shortcut;
034:
035:        import net.n3.nanoxml.XMLElement;
036:
037:        import java.io.File;
038:
039:        import java.util.ArrayList;
040:        import java.util.Enumeration;
041:        import java.util.Vector;
042:
043:        /**
044:         * The ShortcutPanelAutomationHelper is responsible to create Shortcuts during the automated
045:         * installation. Most code comes copied from the ShortcutPanel
046:         * 
047:         * @author Marc Eppelmann (marc.eppelmann@gmx.de)
048:         * @version $Revision: 1540 $
049:         */
050:        public class ShortcutPanelAutomationHelper implements  PanelAutomation {
051:
052:            // ~ Methods ****************************************************************************
053:
054:            /**
055:             * dummy method
056:             * 
057:             * @param idata DOCUMENT ME!
058:             * @param panelRoot DOCUMENT ME!
059:             */
060:            public void makeXMLData(AutomatedInstallData idata,
061:                    XMLElement panelRoot) {
062:                Debug.log(this .getClass().getName()
063:                        + "::entering makeXMLData()");
064:
065:                // ShortcutPanel.getInstance().makeXMLData( idata, panelRoot );
066:            }
067:
068:            /**
069:             * Implementation of the Shortcut Specific Automation Code
070:             * 
071:             * @param installData DOCUMENT ME!
072:             * @param panelRoot DOCUMENT ME!
073:             * 
074:             * @return DOCUMENT ME!
075:             */
076:            public boolean runAutomated(AutomatedInstallData installData,
077:                    XMLElement panelRoot) {
078:                Shortcut shortcut;
079:
080:                /**
081:                 * A list of ShortcutData> objects. Each object is the complete specification for one
082:                 * shortcut that must be created.
083:                 */
084:                Vector<ShortcutData> shortcuts = new Vector<ShortcutData>();
085:
086:                Vector<ExecutableFile> execFiles = new Vector<ExecutableFile>();
087:
088:                /**
089:                 * Holds a list of all the shortcut files that have been created. Note: this variable
090:                 * contains valid data only after createShortcuts() has been called. This list is created so
091:                 * that the files can be added to the uninstaller.
092:                 */
093:                Vector<String> files = new Vector<String>();
094:
095:                Debug
096:                        .log(this .getClass().getName()
097:                                + " Entered runAutomated()");
098:
099:                try {
100:                    shortcut = (Shortcut) (TargetFactory.getInstance()
101:                            .makeObject("com.izforge.izpack.util.os.Shortcut"));
102:                    shortcut.initialize(Shortcut.APPLICATIONS, "-");
103:                } catch (Throwable exception) {
104:                    Debug.log("Could not create shortcut instance");
105:                    exception.printStackTrace();
106:
107:                    return true;
108:                }
109:
110:                // ----------------------------------------------------
111:                // if shortcuts are not supported, then we can not
112:                // create shortcuts, even if there was any install
113:                // data. Just return.
114:                // ----------------------------------------------------
115:                if (!shortcut.supported()) {
116:                    Debug.log("shortcuts not supported here");
117:
118:                    return true;
119:                }
120:
121:                if (!OsConstraint.oneMatchesCurrentSystem(panelRoot)) {
122:                    Debug.log("Shortcuts Not oneMatchesCurrentSystem");
123:
124:                    return true;
125:                }
126:
127:                shortcuts = new Vector<ShortcutData>();
128:
129:                Vector<XMLElement> shortcutElements;
130:                ShortcutData data;
131:                XMLElement dataElement;
132:
133:                // ----------------------------------------------------
134:                // set the name of the program group
135:                // ----------------------------------------------------
136:                dataElement = panelRoot
137:                        .getFirstChildNamed(ShortcutPanel.AUTO_KEY_PROGRAM_GROUP);
138:
139:                String groupName = dataElement
140:                        .getAttribute(ShortcutPanel.AUTO_ATTRIBUTE_NAME);
141:
142:                if (groupName == null) {
143:                    groupName = "";
144:                }
145:
146:                // ----------------------------------------------------
147:                // add the details for each of the shortcuts
148:                // ----------------------------------------------------
149:                shortcutElements = panelRoot
150:                        .getChildrenNamed(ShortcutPanel.AUTO_KEY_SHORTCUT);
151:
152:                for (int i = 0; i < shortcutElements.size(); i++) {
153:                    Debug.log(this .getClass().getName()
154:                            + "runAutomated:shortcutElements " + i);
155:                    data = new ShortcutData();
156:                    dataElement = shortcutElements.elementAt(i);
157:
158:                    data.name = dataElement
159:                            .getAttribute(ShortcutPanel.AUTO_ATTRIBUTE_NAME);
160:                    data.addToGroup = Boolean.valueOf(dataElement
161:                            .getAttribute(ShortcutPanel.AUTO_ATTRIBUTE_GROUP));
162:
163:                    if (OsVersion.IS_WINDOWS) {
164:                        data.type = Integer
165:                                .valueOf(dataElement
166:                                        .getAttribute(ShortcutPanel.AUTO_ATTRIBUTE_TYPE));
167:                    } else {
168:                        Debug
169:                                .log("WARN: On Linux data.type is NOT an int. Ignored.");
170:                    }
171:
172:                    data.commandLine = dataElement
173:                            .getAttribute(ShortcutPanel.AUTO_ATTRIBUTE_COMMAND);
174:                    data.description = dataElement
175:                            .getAttribute(ShortcutPanel.AUTO_ATTRIBUTE_DESCRIPTION);
176:                    data.iconFile = dataElement
177:                            .getAttribute(ShortcutPanel.AUTO_ATTRIBUTE_ICON);
178:                    data.iconIndex = Integer
179:                            .valueOf(dataElement
180:                                    .getAttribute(ShortcutPanel.AUTO_ATTRIBUTE_ICON_INDEX));
181:                    data.initialState = Integer
182:                            .valueOf(dataElement
183:                                    .getAttribute(ShortcutPanel.AUTO_ATTRIBUTE_INITIAL_STATE));
184:                    data.target = dataElement
185:                            .getAttribute(ShortcutPanel.AUTO_ATTRIBUTE_TARGET);
186:                    data.workingDirectory = dataElement
187:                            .getAttribute(ShortcutPanel.AUTO_ATTRIBUTE_WORKING_DIR);
188:
189:                    // Linux
190:                    data.deskTopEntryLinux_Encoding = dataElement.getAttribute(
191:                            ShortcutPanel.SPEC_ATTRIBUTE_ENCODING, "");
192:                    data.deskTopEntryLinux_MimeType = dataElement.getAttribute(
193:                            ShortcutPanel.SPEC_ATTRIBUTE_MIMETYPE, "");
194:                    data.deskTopEntryLinux_Terminal = dataElement.getAttribute(
195:                            ShortcutPanel.SPEC_ATTRIBUTE_TERMINAL, "");
196:                    data.deskTopEntryLinux_TerminalOptions = dataElement
197:                            .getAttribute(
198:                                    ShortcutPanel.SPEC_ATTRIBUTE_TERMINAL_OPTIONS,
199:                                    "");
200:                    data.deskTopEntryLinux_Type = dataElement.getAttribute(
201:                            ShortcutPanel.SPEC_ATTRIBUTE_TYPE, "");
202:
203:                    data.deskTopEntryLinux_URL = dataElement.getAttribute(
204:                            ShortcutPanel.SPEC_ATTRIBUTE_URL, "");
205:
206:                    data.deskTopEntryLinux_X_KDE_SubstituteUID = dataElement
207:                            .getAttribute(
208:                                    ShortcutPanel.SPEC_ATTRIBUTE_KDE_SUBST_UID,
209:                                    "false");
210:
211:                    data.deskTopEntryLinux_X_KDE_UserName = dataElement
212:                            .getAttribute(
213:                                    ShortcutPanel.SPEC_ATTRIBUTE_KDE_USERNAME,
214:                                    "root");
215:
216:                    data.Categories = dataElement.getAttribute(
217:                            ShortcutPanel.SPEC_CATEGORIES,
218:                            "Application;Development");
219:
220:                    data.TryExec = dataElement.getAttribute(
221:                            ShortcutPanel.SPEC_TRYEXEC, "");
222:
223:                    data.createForAll = Boolean
224:                            .valueOf(dataElement.getAttribute(
225:                                    ShortcutPanel.CREATE_FOR_ALL, "false"));
226:                    data.userType = Integer.valueOf(dataElement.getAttribute(
227:                            ShortcutPanel.USER_TYPE, Integer
228:                                    .toString(Shortcut.CURRENT_USER)));
229:                    // END LINUX
230:                    shortcuts.add(data);
231:                }
232:
233:                System.out.print("[ Creating shortcuts ");
234:
235:                // ShortcutData data;
236:                for (int i = 0; i < shortcuts.size(); i++) {
237:                    data = shortcuts.elementAt(i);
238:
239:                    try {
240:                        if (data.subgroup != null) {
241:                            groupName = groupName + data.subgroup;
242:                        }
243:                        shortcut.setUserType(data.userType);
244:                        shortcut.setLinkName(data.name);
245:
246:                        if (OsVersion.IS_WINDOWS) {
247:                            shortcut.setLinkType(data.type);
248:                        }
249:
250:                        shortcut.setArguments(data.commandLine);
251:                        shortcut.setDescription(data.description);
252:                        shortcut.setIconLocation(data.iconFile, data.iconIndex);
253:
254:                        shortcut.setShowCommand(data.initialState);
255:                        shortcut.setTargetPath(data.target);
256:                        shortcut.setWorkingDirectory(data.workingDirectory);
257:                        shortcut.setEncoding(data.deskTopEntryLinux_Encoding);
258:                        shortcut.setMimetype(data.deskTopEntryLinux_MimeType);
259:
260:                        shortcut.setTerminal(data.deskTopEntryLinux_Terminal);
261:                        shortcut
262:                                .setTerminalOptions(data.deskTopEntryLinux_TerminalOptions);
263:
264:                        if (!OsVersion.IS_WINDOWS) {
265:                            shortcut.setType(data.deskTopEntryLinux_Type);
266:                        }
267:
268:                        shortcut
269:                                .setKdeSubstUID(data.deskTopEntryLinux_X_KDE_SubstituteUID);
270:                        shortcut.setURL(data.deskTopEntryLinux_URL);
271:                        shortcut.setCreateForAll(data.createForAll);
272:
273:                        if (data.addToGroup) {
274:                            shortcut.setProgramGroup(groupName);
275:                        } else {
276:                            shortcut.setProgramGroup("");
277:                        }
278:
279:                        try {
280:                            // save the shortcut
281:                            System.out.print(".");
282:                            System.out.flush();
283:
284:                            shortcut.save();
285:
286:                            // add the file and directory name to the file list
287:                            String fileName = shortcut.getFileName();
288:                            files.add(0, fileName);
289:
290:                            File file = new File(fileName);
291:                            File base = new File(shortcut.getBasePath());
292:                            Vector<File> intermediates = new Vector<File>();
293:
294:                            // String directoryName = shortcut.getDirectoryCreated ();
295:                            execFiles.add(new ExecutableFile(fileName,
296:                                    ExecutableFile.UNINSTALL,
297:                                    ExecutableFile.IGNORE,
298:                                    new ArrayList<OsConstraint>(), false));
299:
300:                            files.add(fileName);
301:
302:                            while ((file = file.getParentFile()) != null) {
303:                                if (file.equals(base)) {
304:                                    break;
305:                                }
306:
307:                                intermediates.add(file);
308:                            }
309:
310:                            if (file != null) {
311:                                Enumeration<File> filesEnum = intermediates
312:                                        .elements();
313:
314:                                while (filesEnum.hasMoreElements()) {
315:                                    files.add(0, filesEnum.nextElement()
316:                                            .toString());
317:                                }
318:                            }
319:                        } catch (Exception exception) {
320:                        }
321:                    } catch (Throwable exception) {
322:                    }
323:                }
324:
325:                // }
326:                //
327:                try {
328:                    if (execFiles != null) {
329:                        FileExecutor executor = new FileExecutor(execFiles);
330:
331:                        // 
332:                        // TODO: Hi Guys,
333:                        // TODO The following commented-out line sometimes produces an uncatchable
334:                        // nullpointer Exception!
335:                        // TODO evaluate for what reason the files should exec.
336:                        // TODO if there is a serious explanation, why to do that,
337:                        // TODO the code must be more robust
338:                        // evaluate executor.executeFiles( ExecutableFile.NEVER, null );
339:                    }
340:                } catch (NullPointerException nep) {
341:                    nep.printStackTrace();
342:                } catch (RuntimeException cannot) {
343:                    cannot.printStackTrace();
344:                }
345:
346:                System.out.println(" done. ]");
347:                System.out.print("[ Add shortcuts to uninstaller ");
348:
349:                UninstallData uninstallData = UninstallData.getInstance();
350:
351:                for (int i = 0; i < files.size(); i++) {
352:                    uninstallData.addFile(files.elementAt(i), true);
353:                    System.out.print(".");
354:                    System.out.flush();
355:                }
356:
357:                System.out.println(" done. ]");
358:
359:                return true;
360:            }
361:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.