Ignore:
Timestamp:
2017-04-23T22:55:45+02:00 (7 years ago)
Author:
stoecker
Message:

add support for type=building relation and support variable role names using regexp (level_0, level_1, ...)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/tagging/presets/items/Roles.java

    r10001 r11989  
    2929        /** Role name used in a relation */
    3030        public String key; // NOSONAR
     31        /** Is the role name a regular expression */
     32        public boolean regexp; // NOSONAR
    3133        /** The text to display */
    3234        public String text; // NOSONAR
     
    3739        /** An expression (cf. search dialog) for objects of this role */
    3840        public SearchCompiler.Match memberExpression; // NOSONAR
    39 
     41        /** Is this role required at least once in the relation? */
    4042        public boolean required; // NOSONAR
     43        /** How often must the element appear */
    4144        private long count;
    4245
     
    5053            } else if (!"optional".equals(str))
    5154                throw new SAXException(tr("Unknown requisite: {0}", str));
     55        }
     56
     57        public void setRegexp(String str) throws SAXException {
     58            if ("true".equals(str)) {
     59                regexp = true;
     60            } else if (!"false".equals(str))
     61                throw new SAXException(tr("Unknown regexp value: {0}", str));
    5262        }
    5363
     
    8393            else
    8494                return c != 0 ? c : 1;
     95        }
     96
     97        /**
     98         * Check if the given role matches this class (required to check regexp role types)
     99         * @param role role to check
     100         * @return <code>true</code> if role matches
     101         * @since 11989
     102         */
     103        public boolean isRole(String role) {
     104            if (regexp && role != null) { // pass null through, it will anyway fail
     105               
     106                return role.matches(this.key);
     107            }
     108            return this.key.equals(role);
    85109        }
    86110
Note: See TracChangeset for help on using the changeset viewer.