Changeset 29241 in osm for applications
- Timestamp:
- 2013-02-10T09:31:02+01:00 (12 years ago)
- Location:
- applications/editors/josm/plugins/utilsplugin2
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/utilsplugin2/build.xml
r29234 r29241 31 31 32 32 <!-- enter the SVN commit message --> 33 <property name="commit.message" value="Utilsplugin2: improved pasting tags: paste from JOSM, support JSON format"/>33 <property name="commit.message" value="Utilsplugin2: validation for pasting tags"/> 34 34 <!-- enter the *lowest* JOSM version this plugin is currently compatible with --> 35 35 <property name="plugin.main.version" value="4980"/> -
applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/actions/PasteTagsExtendedAction.java
r29239 r29241 48 48 } 49 49 } else { // Paste tags from arbitrary text 50 Map<String, String> tags = TextTagParser. readTagsFromText(buf);50 Map<String, String> tags = TextTagParser.getTagsFromText(buf); 51 51 if (tags==null) return; 52 52 String v; -
applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/helper/TextTagParser.java
r29234 r29241 5 5 import java.util.regex.Matcher; 6 6 import java.util.regex.Pattern; 7 import javax.swing.JOptionPane; 8 import org.openstreetmap.josm.Main; 9 import org.openstreetmap.josm.gui.ExtendedDialog; 10 import org.openstreetmap.josm.io.XmlWriter; 11 12 import static org.openstreetmap.josm.tools.I18n.tr; 7 13 8 14 public class TextTagParser { … … 163 169 } 164 170 171 public static Map<String,String> getTagsFromText(String buf) { 172 Map<String,String> tags = readTagsFromText(buf); 173 return validateTags(tags) ? tags : null; 174 } 175 165 176 public static Map<String,String> readTagsFromText(String buf) { 166 177 Map<String,String> tags; … … 191 202 // a 1 "b" 2 c=3 d 4 e "5" 192 203 TextTagParser parser = new TextTagParser(buf); 193 System.out.println("free");194 204 tags = parser.getFreeParsedTags(); 195 205 return tags; 196 197 } 198 199 200 206 } 207 208 private static boolean validateTags(Map<String, String> tags) { 209 String value; 210 int r; 211 if (tags.size()>30) { 212 r=warning(tr("There was {0} tags found in the buffer, it is suspicious!",tags.size()), "", "toomanytags"); 213 if (r==2) return false; if (r==3) return true; 214 } 215 for (String key: tags.keySet()) { 216 value = tags.get(key); 217 if (key.length()>50) { 218 r = warning(tr("Key is too long:"), key+"="+value, "keytoolong"); 219 if (r==2) return false; if (r==3) return true; 220 } 221 if (!key.matches("[a-zA-Z:_]*")) { 222 r = warning(tr("Suspiciouns characters in tag:"), key, "keydoesnotmatch"); 223 if (r==2) return false; if (r==3) return true; 224 } 225 if (value.length()>255) { 226 r= warning(tr("Value too long (max 255 characters):"), value, "valuetoolong"); 227 if (r==2) return false; if (r==3) return true; 228 } 229 } 230 return true; 231 } 232 233 private static int warning(String text, String data, String code) { 234 ExtendedDialog ed = new ExtendedDialog( 235 Main.parent, 236 tr("Do you want to paste these tags?"), 237 new String[]{tr("Ok"), tr("Cancel"), tr("Ingore warnings")}); 238 ed.setButtonIcons(new String[]{"ok.png", "cancel.png", "pastetags.png"}); 239 ed.setContent("<html><b>"+text + "</b><br/><br/> <div width=\"300px\">"+XmlWriter.encode(data,true)+"</html>"); 240 ed.setDefaultButton(2); 241 ed.setCancelButton(2); 242 ed.setIcon(JOptionPane.WARNING_MESSAGE); 243 ed.toggleEnable(code); 244 ed.showDialog(); 245 Object o = ed.getValue(); 246 if (o instanceof Integer) 247 return ((Integer)o).intValue(); 248 else 249 return 2; 250 } 201 251 }
Note:
See TracChangeset
for help on using the changeset viewer.