X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2Ftemplate%2FCssClassNameFilter.java;fp=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2Ftemplate%2FCssClassNameFilter.java;h=6ba5d6b59faf7ced809e128cef6b9e916b34837d;hb=1b1f5f1907fb307abd9f94cf3a1f9a2ee247c8d1;hp=0000000000000000000000000000000000000000;hpb=873af59aa0b0af826933e09e2843de30bdb044a8;p=Sone.git diff --git a/src/main/java/net/pterodactylus/sone/template/CssClassNameFilter.java b/src/main/java/net/pterodactylus/sone/template/CssClassNameFilter.java new file mode 100644 index 0000000..6ba5d6b --- /dev/null +++ b/src/main/java/net/pterodactylus/sone/template/CssClassNameFilter.java @@ -0,0 +1,42 @@ +/* + * Sone - CssClassNameFilter.java - Copyright © 2010 David Roden + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package net.pterodactylus.sone.template; + +import java.util.Map; + +import net.pterodactylus.util.template.DataProvider; +import net.pterodactylus.util.template.Filter; + +/** + * Converts the {@link String} {@link String#valueOf(Object) representation} of + * an object to a valid CSS class name by converting all characters that are not + * US-ASCII letters or numbers to an underscore. + * + * @author David ‘Bombe’ Roden + */ +public class CssClassNameFilter implements Filter { + + /** + * {@inheritDoc} + */ + @Override + public Object format(DataProvider dataProvider, Object data, Map parameters) { + return String.valueOf(data).replaceAll("[^a-zA-Z0-9-]", "_"); + } + +}