Changeset 159 in josm for src/org/openstreetmap/josm/plugins


Ignore:
Timestamp:
2006-10-13T13:02:57+02:00 (19 years ago)
Author:
imi
Message:
  • moved translations into plugins
  • added main menu control to main
  • added ImageProvider access to plugins
Location:
src/org/openstreetmap/josm/plugins
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • src/org/openstreetmap/josm/plugins/Plugin.java

    r154 r159  
    11package org.openstreetmap.josm.plugins;
    22
     3import java.io.File;
    34import java.io.FileNotFoundException;
    45import java.io.FileOutputStream;
     
    7172         */
    7273        public void copy(String from, String to) throws FileNotFoundException, IOException {
     74                File pluginDir = new File(getPluginDir());
     75                if (!pluginDir.exists())
     76                        pluginDir.mkdirs();
    7377        FileOutputStream out = new FileOutputStream(getPluginDir()+to);
    7478        InputStream in = getClass().getResourceAsStream(from);
  • src/org/openstreetmap/josm/plugins/PluginInformation.java

    r157 r159  
    66import java.net.URL;
    77import java.net.URLClassLoader;
     8import java.util.Map;
     9import java.util.TreeMap;
     10import java.util.jar.Attributes;
    811import java.util.jar.JarInputStream;
    912import java.util.jar.Manifest;
     
    2023        public final String className;
    2124        public final String description;
     25        public final boolean early;
     26        public final String author;
     27
     28        public final Map<String, String> attr = new TreeMap<String, String>();
    2229
    2330        public PluginInformation(File file) {
     
    2532                name = file.getName().substring(0, file.getName().length()-4);
    2633                try {
    27                 JarInputStream jar = new JarInputStream(new FileInputStream(file));
    28                 Manifest manifest = jar.getManifest();
    29                 className = manifest.getMainAttributes().getValue("Plugin-Class");
    30                 description = manifest.getMainAttributes().getValue("Plugin-Description");
    31                 jar.close();
    32         } catch (IOException e) {
    33                 throw new PluginException(null, name, e);
    34         }
    35     }
     34                        JarInputStream jar = new JarInputStream(new FileInputStream(file));
     35                        Manifest manifest = jar.getManifest();
     36                        Attributes attr = manifest.getMainAttributes();
     37                        className = attr.getValue("Plugin-Class");
     38                        description = attr.getValue("Plugin-Description");
     39                        early = Boolean.parseBoolean(attr.getValue("Plugin-Early"));
     40                        author = attr.getValue("Author");
     41                        for (Object o : attr.keySet())
     42                                this.attr.put(o.toString(), attr.getValue(o.toString()));
     43                        jar.close();
     44                } catch (IOException e) {
     45                        throw new PluginException(null, name, e);
     46                }
     47        }
    3648
    3749        /**
    3850         * Load and instantiate the plugin
    3951         */
    40         public PluginProxy load() {
     52        public PluginProxy load(Class<?> klass) {
     53                try {
     54                        return new PluginProxy(klass.newInstance(), this);
     55                } catch (Exception e) {
     56                        throw new PluginException(null, name, e);
     57                }
     58        }
     59
     60        /**
     61         * Load the class of the plugin
     62         */
     63        public Class<?> loadClass() {
    4164                try {
    4265                        ClassLoader loader = URLClassLoader.newInstance(
    4366                                        new URL[]{new URL(getURLString())},
    4467                                        getClass().getClassLoader());
    45                         Object plugin = Class.forName(className, true, loader).newInstance();
    46                         return new PluginProxy(plugin, this);
     68                        Class<?> realClass = Class.forName(className, true, loader);
     69                        return realClass;
    4770                } catch (Exception e) {
    4871                        throw new PluginException(null, name, e);
     
    5477                        return "file:/"+file.getAbsolutePath();
    5578                return "file://"+file.getAbsolutePath();
    56     }
     79        }
    5780}
Note: See TracChangeset for help on using the changeset viewer.