Source Code Cross Referenced for StandardPluginLocation.java in  » Development » Java-Plugin-Framework » org » java » plugin » standard » 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 » Development » Java Plugin Framework » org.java.plugin.standard 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*****************************************************************************
002:         * Java Plug-in Framework (JPF)
003:         * Copyright (C) 2004-2007 Dmitry Olshansky
004:         * 
005:         * This library is free software; you can redistribute it and/or
006:         * modify it under the terms of the GNU Lesser General Public
007:         * License as published by the Free Software Foundation; either
008:         * version 2.1 of the License, or (at your option) any later version.
009:         * 
010:         * This library is distributed in the hope that it will be useful,
011:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
012:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
013:         * Lesser General Public License for more details.
014:         * 
015:         * You should have received a copy of the GNU Lesser General Public
016:         * License along with this library; if not, write to the Free Software
017:         * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
018:         *****************************************************************************/package org.java.plugin.standard;
019:
020:        import java.io.File;
021:        import java.net.MalformedURLException;
022:        import java.net.URL;
023:        import java.util.Locale;
024:
025:        import org.java.plugin.PluginManager.PluginLocation;
026:        import org.java.plugin.util.IoUtil;
027:
028:        /**
029:         * A standard implementation of plug-in location interface. It may be used to
030:         * create plug-in locations from JAR or ZIP files of plug-in folders, or from
031:         * any URL pointers.
032:         * <p>
033:         * Inspired by Per Cederberg.
034:         * 
035:         * @version $Id$
036:         */
037:        public class StandardPluginLocation implements  PluginLocation {
038:            /**
039:             * Creates plug-in location from a given file and checks that all required
040:             * resources are available. Before creating location object, this method
041:             * probes given ZIP file of folder for presence of any of the following
042:             * files:
043:             * <ul>
044:             *   <li>/plugin.xml</li>
045:             *   <li>/plugin-fragment.xml</li>
046:             *   <li>/META-INF/plugin.xml</li>
047:             *   <li>/META-INF/plugin-fragment.xml</li>
048:             * </ul>
049:             * If any of those files present, a new plug-in location object created and
050:             * returned.
051:             * @param file plug-in JAR or ZIP file or plug-in folder
052:             * @return created new plug-in location or <code>null</code> if given file
053:             *         doesn't points to a valid plug-in file or folder
054:             * @throws MalformedURLException if the plug-in URL's couldn't be created
055:             */
056:            public static PluginLocation create(final File file)
057:                    throws MalformedURLException {
058:                if (file.isDirectory()) {
059:                    URL manifestUrl = getManifestUrl(file);
060:                    return (manifestUrl == null) ? null
061:                            : new StandardPluginLocation(IoUtil.file2url(file),
062:                                    manifestUrl);
063:                }
064:                String fileName = file.getName().toLowerCase(
065:                        Locale.getDefault());
066:                if (!fileName.endsWith(".jar") //$NON-NLS-1$
067:                        && !fileName.endsWith(".zip")) { //$NON-NLS-1$
068:                    return null;
069:                }
070:                URL manifestUrl = getManifestUrl(file);
071:                return (manifestUrl == null) ? null
072:                        : new StandardPluginLocation(
073:                                new URL("jar:" //$NON-NLS-1$
074:                                        + IoUtil.file2url(file)
075:                                                .toExternalForm() + "!/"), manifestUrl); //$NON-NLS-1$
076:            }
077:
078:            private static URL getManifestUrl(final File file)
079:                    throws MalformedURLException {
080:                if (file.isDirectory()) {
081:                    File result = new File(file, "plugin.xml"); //$NON-NLS-1$
082:                    if (result.isFile()) {
083:                        return IoUtil.file2url(result);
084:                    }
085:                    result = new File(file, "plugin-fragment.xml"); //$NON-NLS-1$
086:                    if (result.isFile()) {
087:                        return IoUtil.file2url(result);
088:                    }
089:                    result = new File(file, "META-INF" + File.separator //$NON-NLS-1$
090:                            + "plugin.xml"); //$NON-NLS-1$
091:                    if (result.isFile()) {
092:                        return IoUtil.file2url(result);
093:                    }
094:                    result = new File(file, "META-INF" + File.separator //$NON-NLS-1$
095:                            + "plugin-fragment.xml"); //$NON-NLS-1$
096:                    if (result.isFile()) {
097:                        return IoUtil.file2url(result);
098:                    }
099:                    return null;
100:                }
101:                if (!file.isFile()) {
102:                    return null;
103:                }
104:                URL url = new URL("jar:" //$NON-NLS-1$
105:                        + IoUtil.file2url(file).toExternalForm()
106:                        + "!/plugin.xml"); //$NON-NLS-1$
107:                if (IoUtil.isResourceExists(url)) {
108:                    return url;
109:                }
110:                url = new URL("jar:" //$NON-NLS-1$
111:                        + IoUtil.file2url(file).toExternalForm()
112:                        + "!/plugin-fragment.xml"); //$NON-NLS-1$
113:                if (IoUtil.isResourceExists(url)) {
114:                    return url;
115:                }
116:                url = new URL("jar:" //$NON-NLS-1$
117:                        + IoUtil.file2url(file).toExternalForm()
118:                        + "!/META-INF/plugin.xml"); //$NON-NLS-1$
119:                if (IoUtil.isResourceExists(url)) {
120:                    return url;
121:                }
122:                url = new URL("jar:" //$NON-NLS-1$
123:                        + IoUtil.file2url(file).toExternalForm()
124:                        + "!/META-INF/plugin-fragment.xml"); //$NON-NLS-1$
125:                if (IoUtil.isResourceExists(url)) {
126:                    return url;
127:                }
128:                return null;
129:            }
130:
131:            private final URL context;
132:            private final URL manifest;
133:
134:            /**
135:             * Creates a new plug-in location from a given context an manifest URL's.
136:             * @param aContext plug-in context URL
137:             * @param aManifest plug-in manifest URL
138:             */
139:            public StandardPluginLocation(final URL aContext,
140:                    final URL aManifest) {
141:                if (aContext == null) {
142:                    throw new NullPointerException("context"); //$NON-NLS-1$
143:                }
144:                if (aManifest == null) {
145:                    throw new NullPointerException("manifest"); //$NON-NLS-1$
146:                }
147:                context = aContext;
148:                manifest = aManifest;
149:            }
150:
151:            /**
152:             * Creates a new plug-in location from a jar or a zip file or a folder. This
153:             * plug-in manifest file path specified is relative to the root directory of
154:             * the jar or zip file or given folder.
155:             * @param file the plug-in zip file or plug-in folder
156:             * @param manifestPath the relative manifest path
157:             * @throws MalformedURLException if the plug-in URL's couldn't be created
158:             */
159:            public StandardPluginLocation(final File file,
160:                    final String manifestPath) throws MalformedURLException {
161:                if (file.isDirectory()) {
162:                    context = IoUtil.file2url(file);
163:                } else {
164:                    context = new URL("jar:" //$NON-NLS-1$
165:                            + IoUtil.file2url(file).toExternalForm() + "!/"); //$NON-NLS-1$
166:                }
167:                manifest = new URL(context, manifestPath.startsWith("/") //$NON-NLS-1$
168:                ? manifestPath.substring(1)
169:                        : manifestPath);
170:            }
171:
172:            /**
173:             * @see org.java.plugin.PluginManager.PluginLocation#getManifestLocation()
174:             */
175:            public URL getManifestLocation() {
176:                return manifest;
177:            }
178:
179:            /**
180:             * @see org.java.plugin.PluginManager.PluginLocation#getContextLocation()
181:             */
182:            public URL getContextLocation() {
183:                return context;
184:            }
185:
186:            /**
187:             * @see java.lang.Object#toString()
188:             */
189:            @Override
190:            public String toString() {
191:                return context.toString();
192:            }
193:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.