Changeset 7012 in josm for trunk/src/org/openstreetmap/josm/gui/mappaint/xml/XmlStyleSourceHandler.java
- Timestamp:
- 2014-04-27T15:35:47+02:00 (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/mappaint/xml/XmlStyleSourceHandler.java
r7005 r7012 14 14 import org.xml.sax.helpers.DefaultHandler; 15 15 16 public class XmlStyleSourceHandler extends DefaultHandler 17 { 16 public class XmlStyleSourceHandler extends DefaultHandler { 18 17 private boolean inDoc, inRule, inCondition, inLine, inLineMod, inIcon, inArea, inScaleMax, inScaleMin; 19 18 private boolean hadLine, hadLineMod, hadIcon, hadArea; … … 79 78 private void startElementLine(String qName, Attributes atts, LinePrototype line) { 80 79 for (int count=0; count<atts.getLength(); count++) { 81 if(atts.getQName(count).equals("width")) { 80 switch (atts.getQName(count)) { 81 case "width": 82 82 String val = atts.getValue(count); 83 83 if (! (val.startsWith("+") || val.startsWith("-") || val.endsWith("%"))) { 84 84 line.setWidth(Integer.parseInt(val)); 85 85 } 86 } else if (atts.getQName(count).equals("colour")) { 87 line.color=convertColor(atts.getValue(count)); 88 } else if (atts.getQName(count).equals("realwidth")) { 89 line.realWidth=Integer.parseInt(atts.getValue(count)); 90 } else if (atts.getQName(count).equals("dashed")) { 86 break; 87 case "colour": 88 line.color = convertColor(atts.getValue(count)); 89 break; 90 case "realwidth": 91 line.realWidth = Integer.parseInt(atts.getValue(count)); 92 break; 93 case "dashed": 91 94 Float[] dashed; 92 95 try { … … 105 108 } 106 109 line.setDashed(dashed == null ? null : Arrays.asList(dashed)); 107 } else if (atts.getQName(count).equals("dashedcolour")) { 108 line.dashedColor=convertColor(atts.getValue(count)); 109 } else if(atts.getQName(count).equals("priority")) { 110 break; 111 case "dashedcolour": 112 line.dashedColor = convertColor(atts.getValue(count)); 113 break; 114 case "priority": 110 115 line.priority = Integer.parseInt(atts.getValue(count)); 111 } else if (!(atts.getQName(count).equals("mode") && line instanceof LinemodPrototype)){ 116 break; 117 case "mode": 118 if (line instanceof LinemodPrototype) 119 break; 120 default: 112 121 error("The element \"" + qName + "\" has unknown attribute \"" + atts.getQName(count) + "\"!"); 113 122 } … … 118 127 startElementLine(qName, atts, line); 119 128 for (int count=0; count<atts.getLength(); count++) { 120 if (atts.getQName(count).equals("width")) { 129 switch (atts.getQName(count)) { 130 case "width": 121 131 String val = atts.getValue(count); 122 132 if (val.startsWith("+")) { … … 132 142 line.setWidth(Integer.parseInt(val)); 133 143 } 134 } else if(atts.getQName(count).equals("mode")) { 135 line.over = !atts.getValue(count).equals("under"); 136 } 137 } 138 } 139 140 @Override public void startElement(String uri,String name, String qName, Attributes atts) { 144 break; 145 case "mode": 146 line.over = !"under".equals(atts.getValue(count)); 147 break; 148 } 149 } 150 } 151 152 @Override 153 public void startElement(String uri,String name, String qName, Attributes atts) { 141 154 if (inDoc) { 142 if (qName.equals("rule")) { 143 inRule=true; 144 } else if (qName.equals("rules")) { 155 switch(qName) { 156 case "rule": 157 inRule = true; 158 break; 159 case "rules": 145 160 if (style.name == null) { 146 161 style.name = atts.getValue("name"); … … 152 167 style.icon = atts.getValue("icon"); 153 168 } 154 } else if (qName.equals("scale_max")) { 169 break; 170 case "scale_max": 155 171 inScaleMax = true; 156 } else if (qName.equals("scale_min")) { 172 break; 173 case "scale_min": 157 174 inScaleMin = true; 158 } else if (qName.equals("condition") && inRule) { 159 inCondition=true; 160 XmlCondition c = rule.cond; 161 if (c.key != null) { 162 if(rule.conditions == null) { 163 rule.conditions = new LinkedList<>(); 164 } 165 rule.conditions.add(new XmlCondition(rule.cond)); 166 c = new XmlCondition(); 167 rule.conditions.add(c); 168 } 169 for (int count=0; count<atts.getLength(); count++) { 170 if (atts.getQName(count).equals("k")) { 171 c.key = atts.getValue(count); 172 } else if (atts.getQName(count).equals("v")) { 173 c.value = atts.getValue(count); 174 } else if(atts.getQName(count).equals("b")) { 175 c.boolValue = atts.getValue(count); 176 } else { 177 error("The element \"" + qName + "\" has unknown attribute \"" + atts.getQName(count) + "\"!"); 178 } 179 } 180 if(c.key == null) { 181 error("The condition has no key!"); 182 } 183 } else if (qName.equals("line")) { 175 break; 176 case "condition": 177 if (inRule) { 178 inCondition = true; 179 XmlCondition c = rule.cond; 180 if (c.key != null) { 181 if(rule.conditions == null) { 182 rule.conditions = new LinkedList<>(); 183 } 184 rule.conditions.add(new XmlCondition(rule.cond)); 185 c = new XmlCondition(); 186 rule.conditions.add(c); 187 } 188 for (int count=0; count<atts.getLength(); count++) { 189 switch (atts.getQName(count)) { 190 case "k": 191 c.key = atts.getValue(count); 192 break; 193 case "v": 194 c.value = atts.getValue(count); 195 break; 196 case "b": 197 c.boolValue = atts.getValue(count); 198 break; 199 default: 200 error("The element \"" + qName + "\" has unknown attribute \"" + atts.getQName(count) + "\"!"); 201 } 202 } 203 if(c.key == null) { 204 error("The condition has no key!"); 205 } 206 } 207 break; 208 case "line": 184 209 hadLine = inLine = true; 185 210 startElementLine(qName, atts, rule.line); 186 } else if (qName.equals("linemod")) { 211 break; 212 case "linemod": 187 213 hadLineMod = inLineMod = true; 188 214 startElementLinemod(qName, atts, rule.linemod); 189 } else if (qName.equals("icon")) { 215 break; 216 case "icon": 190 217 inIcon = true; 191 218 for (int count=0; count<atts.getLength(); count++) { 192 if (atts.getQName(count).equals("src")) { 219 switch (atts.getQName(count)) { 220 case "src": 193 221 IconReference icon = new IconReference(atts.getValue(count), style); 194 222 hadIcon = (icon != null); 195 223 rule.icon.icon = icon; 196 } else if (atts.getQName(count).equals("annotate")) { 224 break; 225 case "annotate": 197 226 rule.icon.annotate = Boolean.parseBoolean (atts.getValue(count)); 198 } else if(atts.getQName(count).equals("priority")) { 227 break; 228 case "priority": 199 229 rule.icon.priority = Integer.parseInt(atts.getValue(count)); 200 } else { 230 break; 231 default: 201 232 error("The element \"" + qName + "\" has unknown attribute \"" + atts.getQName(count) + "\"!"); 202 233 } 203 234 } 204 } else if (qName.equals("area")) { 235 break; 236 case "area": 205 237 hadArea = inArea = true; 206 for (int count=0; count<atts.getLength(); count++) 207 {208 if (atts.getQName(count).equals("colour")) {238 for (int count=0; count<atts.getLength(); count++) { 239 switch (atts.getQName(count)) { 240 case "colour": 209 241 rule.area.color=convertColor(atts.getValue(count)); 210 } else if (atts.getQName(count).equals("closed")) { 242 break; 243 case "closed": 211 244 rule.area.closed=Boolean.parseBoolean(atts.getValue(count)); 212 } else if(atts.getQName(count).equals("priority")) { 245 break; 246 case "priority": 213 247 rule.area.priority = Integer.parseInt(atts.getValue(count)); 214 } else { 248 break; 249 default: 215 250 error("The element \"" + qName + "\" has unknown attribute \"" + atts.getQName(count) + "\"!"); 216 251 } 217 252 } 218 } else { 253 break; 254 default: 219 255 error("The element \"" + qName + "\" is unknown!"); 220 256 } … … 222 258 } 223 259 224 @Override public void endElement(String uri,String name, String qName)225 {226 if (inRule && qName.equals("rule")) {260 @Override 261 public void endElement(String uri,String name, String qName) { 262 if (inRule && "rule".equals(qName)) { 227 263 if (hadLine) { 228 264 style.add(rule.cond, rule.conditions, 229 265 new LinePrototype(rule.line, new Range(rule.scaleMin, rule.scaleMax))); 230 266 } 231 if (hadLineMod) 232 { 267 if (hadLineMod) { 233 268 style.add(rule.cond, rule.conditions, 234 269 new LinemodPrototype(rule.linemod, new Range(rule.scaleMin, rule.scaleMax))); 235 270 } 236 if (hadIcon) 237 { 271 if (hadIcon) { 238 272 style.add(rule.cond, rule.conditions, 239 273 new IconPrototype(rule.icon, new Range(rule.scaleMin, rule.scaleMax))); 240 274 } 241 if (hadArea) 242 { 275 if (hadArea) { 243 276 style.add(rule.cond, rule.conditions, 244 277 new AreaPrototype(rule.area, new Range(rule.scaleMin, rule.scaleMax))); … … 247 280 hadLine = hadLineMod = hadIcon = hadArea = false; 248 281 rule.init(); 249 } else if (inCondition && qName.equals("condition")) {282 } else if (inCondition && "condition".equals(qName)) { 250 283 inCondition = false; 251 } else if (inLine && qName.equals("line")) {284 } else if (inLine && "line".equals(qName)) { 252 285 inLine = false; 253 } else if (inLineMod && qName.equals("linemod")) {286 } else if (inLineMod && "linemod".equals(qName)) { 254 287 inLineMod = false; 255 } else if (inIcon && qName.equals("icon")) {288 } else if (inIcon && "icon".equals(qName)) { 256 289 inIcon = false; 257 } else if (inArea && qName.equals("area")) {290 } else if (inArea && "area".equals(qName)) { 258 291 inArea = false; 259 } else if ( qName.equals("scale_max")) {292 } else if ("scale_max".equals(qName)) { 260 293 inScaleMax = false; 261 } else if ( qName.equals("scale_min")) {294 } else if ("scale_min".equals(qName)) { 262 295 inScaleMin = false; 263 296 } 264 297 } 265 298 266 @Override public void characters(char[] ch, int start, int length) { 299 @Override 300 public void characters(char[] ch, int start, int length) { 267 301 if (inScaleMax) { 268 302 rule.scaleMax = Long.parseLong(new String(ch, start, length));
Note:
See TracChangeset
for help on using the changeset viewer.