source: josm/trunk/src/org/openstreetmap/josm/plugins/PluginListParser.java@ 2946

Last change on this file since 2946 was 2817, checked in by Gubaer, 14 years ago

fixed #3063: Downloading a plugin yields 3 dialogs at the same time: Downloading plugin / You should restart JOSM / Plugin downloaded
fixed #3628: JOSM blocking itself updating broken plugin
fixed #4187: JOSM deleted random files from disk after start (data loss)
fixed #4199: new version - plugins update vs josm start [should be fixed. Be careful if you have two JOSM instances running. Auto-update of plugins in the second instance will fail because plugin files are locked by the first instance]
fixed #4034: JOSM should auto-download plugin list when it hasn't been downloaded before [JOSM now displays a hint]

fixed: splash screen showing again even if plugins are auto-updated
new: progress indication integrated in splash screen
new: cancelable, asynchronous download of plugins from preferences
new: cancelable, asynchronous download of plugin list from plugin download sites
new: asynchronous loading of plugin information, launch of preferences dialog accelerated
refactored: clean up, documentation of plugin management code (PluginHandler)

File size: 3.9 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.plugins;
3
4import static org.openstreetmap.josm.tools.I18n.tr;
5
6import java.io.BufferedReader;
7import java.io.ByteArrayInputStream;
8import java.io.IOException;
9import java.io.InputStream;
10import java.io.InputStreamReader;
11import java.io.UnsupportedEncodingException;
12import java.util.LinkedList;
13import java.util.List;
14
15/**
16 * A parser for the plugin list provided by a JOSM Plugin Download Site.
17 *
18 * See <a href="http://josm.openstreetmap.de/plugin">http://josm.openstreetmap.de/plugin</a>
19 * for a sample of the document. The format is a custom format, kind of mix of CSV and RFC822 style
20 * name/value-pairs.
21 *
22 */
23public class PluginListParser {
24
25 /**
26 * Creates the plugin information object
27 *
28 * @param name the plugin name
29 * @param url the plugin download url
30 * @param manifest the plugin manifest
31 * @return a plugin information object
32 * @throws PluginListParseException
33 */
34 protected PluginInformation createInfo(String name, String url, String manifest) throws PluginListParseException{
35 try {
36 return new PluginInformation(
37 new ByteArrayInputStream(manifest.getBytes("utf-8")),
38 name.substring(0, name.length() - 4),
39 url
40 );
41 } catch(UnsupportedEncodingException e) {
42 throw new PluginListParseException(tr("Failed to create plugin information from manifest for plugin ''{0}''", name), e);
43 } catch (PluginException e) {
44 throw new PluginListParseException(tr("Failed to create plugin information from manifest for plugin ''{0}''", name), e);
45 }
46 }
47
48 /**
49 * Parses a plugin information document and replies a list of plugin information objects.
50 *
51 * See <a href="http://josm.openstreetmap.de/plugin">http://josm.openstreetmap.de/plugin</a>
52 * for a sample of the document. The format is a custom format, kind of mix of CSV and RFC822 style
53 * name/value-pairs.
54 *
55 * @param in the input stream from which to parse
56 * @return the list of plugin information objects
57 * @throws PluginListParseException thrown if something goes wrong while parsing
58 */
59 public List<PluginInformation> parse(InputStream in) throws PluginListParseException{
60 List<PluginInformation> ret = new LinkedList<PluginInformation>();
61 BufferedReader r = null;
62 try {
63 r = new BufferedReader(new InputStreamReader(in, "utf-8"));
64 String name = null;
65 String url = null;
66 StringBuilder manifest = new StringBuilder();
67 for (String line = r.readLine(); line != null; line = r.readLine()) {
68 if (line.startsWith("\t")) {
69 line = line.substring(1);
70 if (line.length() > 70) {
71 manifest.append(line.substring(0, 70)).append("\n");
72 line = " " + line.substring(70);
73 }
74 manifest.append(line).append("\n");
75 continue;
76 }
77 if (name != null) {
78 PluginInformation info = createInfo(name, url, manifest.toString());
79 if (info != null) {
80 ret.add(info);
81 }
82 }
83 String x[] = line.split(";");
84 name = x[0];
85 url = x[1];
86 manifest = new StringBuilder();
87
88 }
89 if (name != null) {
90 PluginInformation info = createInfo(name, url, manifest.toString());
91 if (info != null) {
92 ret.add(info);
93 }
94 }
95 return ret;
96 } catch (IOException e) {
97 throw new PluginListParseException(e);
98 }
99 }
100}
Note: See TracBrowser for help on using the repository browser.