Ignore:
Timestamp:
2011-09-17T10:59:32+02:00 (10 years ago)
Author:
jttt
Message:

Custom primitive name formatters via tagging presets

Location:
trunk/src/org/openstreetmap/josm/tools/template_engine
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/tools/template_engine/TemplateEngineDataProvider.java

    r4282 r4431  
    22package org.openstreetmap.josm.tools.template_engine;
    33
    4 import java.util.List;
     4import java.util.Collection;
    55
    66import org.openstreetmap.josm.actions.search.SearchCompiler.Match;
    77
    88public interface TemplateEngineDataProvider {
    9     List<String> getTemplateKeys();
    10     Object getTemplateValue(String name);
     9    Collection<String> getTemplateKeys();
     10    Object getTemplateValue(String name, boolean special);
    1111    boolean evaluateCondition(Match condition);
    1212}
  • trunk/src/org/openstreetmap/josm/tools/template_engine/Variable.java

    r4282 r4431  
    22package org.openstreetmap.josm.tools.template_engine;
    33
    4 import java.util.List;
     4import java.util.Collection;
    55
    66
    77public class Variable implements TemplateEntry {
    88
     9    private static final String SPECIAL_VARIABLE_PREFIX = "special:";
     10    private static final String SPECIAL_VALUE_EVERYTHING = "everything";
     11
     12
    913    private final String variableName;
     14    private final boolean special;
    1015
    1116    public Variable(String variableName) {
    12         this.variableName = variableName;
     17        if (variableName.toLowerCase().startsWith(SPECIAL_VARIABLE_PREFIX)) {
     18            this.variableName = variableName.substring(SPECIAL_VARIABLE_PREFIX.length());
     19            // special:special:key means that real key named special:key is needed, not special variable
     20            this.special = !this.variableName.toLowerCase().startsWith(SPECIAL_VARIABLE_PREFIX);
     21        } else {
     22            this.variableName = variableName;
     23            this.special = false;
     24        }
    1325    }
    1426
    1527    @Override
    1628    public void appendText(StringBuilder result, TemplateEngineDataProvider dataProvider) {
    17         if ("*".equals(variableName)) {
    18             List<String> keys = dataProvider.getTemplateKeys();
     29        if (special && SPECIAL_VALUE_EVERYTHING.equals(variableName)) {
     30            Collection<String> keys = dataProvider.getTemplateKeys();
    1931            boolean first = true;
    2032            for (String key: keys) {
     
    2436                    first = false;
    2537                }
    26                 result.append(key).append("=").append(dataProvider.getTemplateValue(key));
     38                result.append(key).append("=").append(dataProvider.getTemplateValue(key, false));
    2739            }
    2840        } else {
    29             Object value = dataProvider.getTemplateValue(variableName);
     41            Object value = dataProvider.getTemplateValue(variableName, special);
    3042            if (value != null) {
    3143                result.append(value);
     
    3648    @Override
    3749    public boolean isValid(TemplateEngineDataProvider dataProvider) {
    38         if ("*".equals(variableName))
     50        if (special && SPECIAL_VALUE_EVERYTHING.equals(variableName))
    3951            return true;
    4052        else
    41             return dataProvider.getTemplateValue(variableName) != null;
     53            return dataProvider.getTemplateValue(variableName, special) != null;
    4254    }
    4355
     
    4759    }
    4860
     61    public boolean isSpecial() {
     62        return special;
     63    }
     64
    4965}
Note: See TracChangeset for help on using the changeset viewer.