Changeset 4796 in josm


Ignore:
Timestamp:
Jan 15, 2012 9:28:46 PM (17 months ago)
Author:
simon04
Message:

fix #6425 - remotecontrol: make download objects available (e.g., /load_object?objects=n1,w2,r3[&new_layer=false&relation_members=true])

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

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/actions/DownloadPrimitiveAction.java

    r4675 r4796  
    200200    } 
    201201 
    202     void processItems(boolean newLayer, final List<PrimitiveId> ids, boolean downloadReferrers, boolean full) { 
     202    /** 
     203     * @param newLayer if the data should be downloaded into a new layer 
     204     * @param ids 
     205     * @param downloadReferrers if the referrers of the object should be downloaded as well, i.e., parent relations, and for nodes, additionally, parent ways 
     206     * @param full if the members of a relation should be downloaded as well 
     207     */ 
     208    public static void processItems(boolean newLayer, final List<PrimitiveId> ids, boolean downloadReferrers, boolean full) { 
    203209        OsmDataLayer layer = getEditLayer(); 
    204210        if ((layer == null) || newLayer) { 
     
    274280    } 
    275281 
    276     private ExtendedDialog reportProblemDialog(Set<PrimitiveId> errs, 
     282    private static ExtendedDialog reportProblemDialog(Set<PrimitiveId> errs, 
    277283            String TITLE, String TEXT, String LIST_LABEL, int msgType) { 
    278284        JPanel p = new JPanel(new GridBagLayout()); 
  • trunk/src/org/openstreetmap/josm/data/osm/SimplePrimitiveId.java

    r3115 r4796  
    33 
    44import java.io.Serializable; 
     5import java.util.regex.Matcher; 
     6import java.util.regex.Pattern; 
    57 
    68public class SimplePrimitiveId implements PrimitiveId, Serializable { 
     
    5759        return type + " " + id; 
    5860    } 
     61 
     62    /** 
     63     * Parses a {@code OsmPrimitiveType} from the string {@code s}. 
     64     * @param s the string to be parsed, e.g., {@code n1}, {@code node1}, 
     65     * {@code w1}, {@code way1}, {@code r1}, {@code rel1}, {@code relation1}. 
     66     * @return the parsed {@code OsmPrimitiveType} 
     67     * @throws IllegalArgumentException if the string does not match the pattern 
     68     */ 
     69    public static SimplePrimitiveId fromString(String s) { 
     70        final Pattern p = Pattern.compile("((n(ode)?|w(ay)?|r(el(ation)?)?)/?)(\\d+)"); 
     71        final Matcher m = p.matcher(s); 
     72        if (m.matches()) { 
     73            return new SimplePrimitiveId(Long.parseLong(m.group(m.groupCount())), 
     74                    s.charAt(0) == 'n' ? OsmPrimitiveType.NODE 
     75                    : s.charAt(0) == 'w' ? OsmPrimitiveType.WAY 
     76                    : OsmPrimitiveType.RELATION); 
     77        } else { 
     78            throw new IllegalArgumentException("The string " + s + " does not match the pattern " + p); 
     79        } 
     80    } 
    5981} 
  • trunk/src/org/openstreetmap/josm/gui/widgets/OsmIdTextField.java

    r4081 r4796  
    9292         
    9393        public boolean readOsmIds() { 
    94             String value  = getComponent().getText(); 
     94            String value = getComponent().getText(); 
    9595            char c; 
    96             if (value == null || value.trim().length() == 0) return false; 
    97             try { 
    98                 ids.clear(); 
    99                 StringTokenizer st = new StringTokenizer(value,",.+/ \t\n"); 
    100                 String s; 
    101                 while (st.hasMoreTokens()) { 
    102                     s = st.nextToken(); 
    103                     // convert tokens to int skipping v-words (version v2 etc) 
    104                     c = s.charAt(0); 
    105                     if (c=='v') { 
    106                         continue; 
    107                     } 
    108                     else if (c=='n') { 
    109                         ids.add(new SimplePrimitiveId(Long.parseLong(s.substring(1)), OsmPrimitiveType.NODE)); 
    110                     } else if (c=='w') { 
    111                         ids.add(new SimplePrimitiveId(Long.parseLong(s.substring(1)), OsmPrimitiveType.WAY)); 
    112                     } else if (c=='r') {  
    113                         ids.add(new SimplePrimitiveId(Long.parseLong(s.substring(1)), OsmPrimitiveType.RELATION)); 
    114                     } else if (type==OsmPrimitiveType.NODE) { 
    115                         ids.add(new SimplePrimitiveId(Long.parseLong(s), OsmPrimitiveType.NODE)); 
    116                     } else if (type==OsmPrimitiveType.WAY) { 
    117                         ids.add(new SimplePrimitiveId(Long.parseLong(s), OsmPrimitiveType.WAY)); 
    118                     } else if (type==OsmPrimitiveType.RELATION) { 
    119                         ids.add(new SimplePrimitiveId(Long.parseLong(s), OsmPrimitiveType.RELATION)); 
     96            if (value == null || value.trim().length() == 0) { 
     97                return false; 
     98            } 
     99            ids.clear(); 
     100            StringTokenizer st = new StringTokenizer(value, ",.+/ \t\n"); 
     101            String s; 
     102            while (st.hasMoreTokens()) { 
     103                s = st.nextToken(); 
     104                // convert tokens to int skipping v-words (version v2 etc) 
     105                c = s.charAt(0); 
     106                if (c == 'v') { 
     107                    continue; 
     108                } else { 
     109                    try { 
     110                        ids.add(SimplePrimitiveId.fromString(s)); 
     111                    } catch (IllegalArgumentException ex) { 
     112                        if (type == OsmPrimitiveType.NODE) { 
     113                            ids.add(new SimplePrimitiveId(Long.parseLong(s), OsmPrimitiveType.NODE)); 
     114                        } else if (type == OsmPrimitiveType.WAY) { 
     115                            ids.add(new SimplePrimitiveId(Long.parseLong(s), OsmPrimitiveType.WAY)); 
     116                        } else if (type == OsmPrimitiveType.RELATION) { 
     117                            ids.add(new SimplePrimitiveId(Long.parseLong(s), OsmPrimitiveType.RELATION)); 
     118                        } else { 
     119                            return false; 
     120                        } 
    120121                    } 
    121122                } 
    122                 return true; 
    123             } catch(NumberFormatException e) { 
    124                 return false; 
    125123            } 
     124            return true; 
    126125        } 
    127126    } 
  • trunk/src/org/openstreetmap/josm/io/remotecontrol/RequestProcessor.java

    r3715 r4796  
    1919import org.openstreetmap.josm.io.remotecontrol.handler.ImportHandler; 
    2020import org.openstreetmap.josm.io.remotecontrol.handler.LoadAndZoomHandler; 
     21import org.openstreetmap.josm.io.remotecontrol.handler.LoadObject; 
    2122import org.openstreetmap.josm.io.remotecontrol.handler.RequestHandler; 
    2223import org.openstreetmap.josm.io.remotecontrol.handler.RequestHandler.RequestHandlerBadRequestException; 
     
    117118        addRequestHandlerClass(ImportHandler.command, ImportHandler.class, true); 
    118119        addRequestHandlerClass(VersionHandler.command, VersionHandler.class, true); 
     120        addRequestHandlerClass(LoadObject.command, LoadObject.class, true); 
    119121    } 
    120122 
Note: See TracChangeset for help on using the changeset viewer.