Ticket #8902: entities.diff

File entities.diff, 3.3 KB (added by shinigami, 12 years ago)

map of entities

  • src/org/openstreetmap/josm/data/validation/tests/TagChecker.java

     
    144144    /** List of sources for spellcheck data */
    145145    protected JList sourcesList;
    146146
    147     protected static final Entities entities = new Entities();
    148 
    149147    /**
    150148     * Constructor
    151149     */
     
    411409                        tr(s, key), MessageFormat.format(s, key), INVALID_SPACE, p) );
    412410                withErrors.put(p, "SPACE");
    413411            }
    414             if (checkValues && value != null && !value.equals(entities.unescape(value)) && !withErrors.contains(p, "HTML")) {
     412            if (checkValues && value != null && !value.equals(Entities.unescape(value)) && !withErrors.contains(p, "HTML")) {
    415413                errors.add( new TestError(this, Severity.OTHER, tr("Property values contain HTML entity"),
    416414                        tr(s, key), MessageFormat.format(s, key), INVALID_HTML, p) );
    417415                withErrors.put(p, "HTML");
     
    721719                } else if (key.startsWith(" ") || key.endsWith(" ")) {
    722720                    commands.add(new ChangePropertyKeyCommand(Collections.singleton(p), key, key.trim()));
    723721                } else {
    724                     String evalue = entities.unescape(value);
     722                    String evalue = Entities.unescape(value);
    725723                    if (!evalue.equals(value)) {
    726724                        commands.add(new ChangePropertyCommand(Collections.singleton(p), key, evalue));
    727725                    } else {
  • src/org/openstreetmap/josm/data/validation/util/Entities.java

     
    334334        {"euro", "8364"}, // -- euro sign, U+20AC NEW -->
    335335    };
    336336
    337     private static Map<String, String> mapNameToValue = null;
     337    private static final Map<String, Integer> MAP_NAME_TO_VALUE = new HashMap<String, Integer>();
    338338
    339     public String unescape(String str) {
     339    static {
     340        for (String[] pair : ARRAY) {
     341            MAP_NAME_TO_VALUE.put(pair[0], Integer.parseInt(pair[1]));
     342        }
     343    }
     344
     345    public static String unescape(String str) {
    340346        int firstAmp = str.indexOf('&');
    341347        if (firstAmp < 0)
    342348            return str;
     
    384390                            }
    385391                        }
    386392                    } else { // escaped value content is an entity name
    387                         if(mapNameToValue == null)
    388                         {
    389                             mapNameToValue = new HashMap<String, String>();
    390                             for (String[] pair : ARRAY)
    391                                 mapNameToValue.put(pair[0], pair[1]);
    392                         }
    393                         String value = mapNameToValue.get(entityContent);
    394                         entityValue = (value == null ? -1 : Integer.parseInt(value));
     393                        final Integer value = MAP_NAME_TO_VALUE.get(entityContent);
     394                        if (value != null) entityValue = value;
    395395                    }
    396396                }
    397397