Changeset 906 in josm


Ignore:
Timestamp:
Sep 2, 2008 6:22:40 PM (5 years ago)
Author:
stoecker
Message:

added generic mirroring Input stream, replace validator specific one soon

Location:
trunk/src/org/openstreetmap/josm
Files:
1 added
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/preferences/PluginPreference.java

    r873 r906  
    171171                // refresh description 
    172172                PluginDownloader.downloadDescription(); 
     173                refreshPluginPanel(gui); 
    173174 
    174175                Set<PluginDescription> toUpdate = new HashSet<PluginDescription>(); 
  • trunk/src/org/openstreetmap/josm/gui/tagging/TaggingPreset.java

    r895 r906  
    99import java.awt.event.ActionEvent; 
    1010import java.io.BufferedReader; 
    11 import java.io.FileInputStream; 
     11import java.io.InputStreamReader; 
    1212import java.io.IOException; 
    13 import java.io.InputStream; 
    14 import java.io.InputStreamReader; 
    1513import java.io.UnsupportedEncodingException; 
    16 import java.net.URL; 
    1714import java.util.Collection; 
    1815import java.util.HashMap; 
     
    2219import java.util.List; 
    2320import java.util.Set; 
    24 import java.util.StringTokenizer; 
    2521 
    2622import javax.swing.AbstractAction; 
     
    4036import org.openstreetmap.josm.data.osm.OsmPrimitive; 
    4137import org.openstreetmap.josm.data.osm.OsmUtils; 
     38import org.openstreetmap.josm.io.MirroredInputStream; 
    4239import org.openstreetmap.josm.gui.QuadStateCheckBox; 
    4340import org.openstreetmap.josm.gui.tagging.TaggingPresetMenu; 
     
    326323         */ 
    327324        public Collection<Class<?>> types; 
    328         private List<Item> data = new LinkedList<Item>(); 
     325        public List<Item> data = new LinkedList<Item>(); 
    329326        private static HashMap<String,String> lastValue = new HashMap<String,String>(); 
    330327 
     
    386383        } 
    387384 
    388         public static List<TaggingPreset> readAll(InputStream inStream) throws SAXException { 
    389                 BufferedReader in = null; 
    390                 try { 
    391                         in = new BufferedReader(new InputStreamReader(inStream, "UTF-8")); 
    392                 } catch (UnsupportedEncodingException e) { 
    393                         e.printStackTrace(); 
    394                         in = new BufferedReader(new InputStreamReader(inStream)); 
    395                 } 
     385        private static List<TaggingPreset> readAll(BufferedReader in) throws SAXException { 
    396386                XmlObjectParser parser = new XmlObjectParser(); 
    397387                parser.mapOnStart("item", TaggingPreset.class); 
     
    441431                String allTaggingPresets = Main.pref.get("taggingpreset.sources"); 
    442432                 
    443                 if (Main.pref.getBoolean("taggingpreset.enable-defaults", true)) { 
    444                         InputStream in = Main.class.getResourceAsStream("/presets/presets.xml"); 
     433                if (Main.pref.getBoolean("taggingpreset.enable-defaults", true)) 
     434                { 
     435                        allTaggingPresets = "resource://presets/presets.xml" 
     436                        + (allTaggingPresets != null ? ";"+allTaggingPresets : ""); 
     437                } 
     438                 
     439                for(String source : allTaggingPresets.split(";")) 
     440                { 
    445441                        try { 
    446                                 allPresets.addAll(TaggingPreset.readAll(in)); 
    447                         } catch (SAXException x) { 
    448                                 JOptionPane.showMessageDialog(Main.parent, tr("Error parsing presets.xml: ")+x.getMessage()); 
    449                         } 
    450                 } 
    451                  
    452                 StringTokenizer st = new StringTokenizer(allTaggingPresets, ";"); 
    453                 while (st.hasMoreTokens()) { 
    454                         InputStream in = null; 
    455                         String source = st.nextToken(); 
    456                         try { 
    457                                 if (source.startsWith("http") || source.startsWith("ftp") || source.startsWith("file")) 
    458                                         in = new URL(source).openStream(); 
    459                                 else if (source.startsWith("resource://"))  
    460                                         in = Main.class.getResourceAsStream(source.substring("resource:/".length())); 
    461                                 else 
    462                                         in = new FileInputStream(source); 
    463                                 allPresets.addAll(TaggingPreset.readAll(in)); 
    464                                 in.close(); 
     442                                MirroredInputStream s = new MirroredInputStream(source); 
     443                                InputStreamReader r; 
     444                                try 
     445                                { 
     446                                        r = new InputStreamReader(s, "UTF-8"); 
     447                                } 
     448                                catch (UnsupportedEncodingException e) 
     449                                { 
     450                                        r = new InputStreamReader(s); 
     451                                } 
     452                                allPresets.addAll(TaggingPreset.readAll(new BufferedReader(r))); 
    465453                        } catch (IOException e) { 
    466454                                e.printStackTrace(); 
Note: See TracChangeset for help on using the changeset viewer.