Changeset 15760 in josm for trunk/src


Ignore:
Timestamp:
2020-01-25T21:11:58+01:00 (5 years ago)
Author:
simon04
Message:

fix #15628 - Strip HTML code from GPX descriptions

Location:
trunk/src/org/openstreetmap/josm
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/data/gpx/GpxData.java

    r15502 r15760  
    7979    private final ArrayList<GpxRoute> privateRoutes = new ArrayList<>();
    8080    /**
    81      * Addidionaly waypoints for this file.
     81     * Additional waypoints for this file.
    8282     */
    8383    private final ArrayList<WayPoint> privateWaypoints = new ArrayList<>();
  • trunk/src/org/openstreetmap/josm/data/gpx/WayPoint.java

    r15007 r15760  
    1515import org.openstreetmap.josm.data.projection.Projecting;
    1616import org.openstreetmap.josm.tools.Logging;
     17import org.openstreetmap.josm.tools.Utils;
    1718import org.openstreetmap.josm.tools.date.DateUtils;
    1819import org.openstreetmap.josm.tools.template_engine.TemplateEngineDataProvider;
     
    265266    @Override
    266267    public Object getTemplateValue(String name, boolean special) {
    267         if (!special)
     268        if (special) {
     269            return null;
     270        } else if ("desc".equals(name)) {
     271            final Object value = get(name);
     272            return value instanceof String ? Utils.stripHtml(((String) value)) : value;
     273        } else {
    268274            return get(name);
    269         else
    270             return null;
     275        }
    271276    }
    272277
  • trunk/src/org/openstreetmap/josm/tools/Utils.java

    r15740 r15760  
    19901990        }
    19911991    }
     1992
     1993    /**
     1994     * Strips all HTML characters and return the result.
     1995     *
     1996     * @param rawString The raw HTML string
     1997     * @return the plain text from the HTML string
     1998     * @since 15760
     1999     */
     2000    public static String stripHtml(String rawString) {
     2001        // remove HTML tags
     2002        rawString = rawString.replaceAll("<.*?>", " ");
     2003        // consolidate multiple spaces between a word to a single space
     2004        rawString = rawString.replaceAll("\\b\\s{2,}\\b", " ");
     2005        // remove extra whitespaces
     2006        return rawString.trim();
     2007    }
    19922008}
Note: See TracChangeset for help on using the changeset viewer.