--- /dev/null
+/*
+ * 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 <http://www.gnu.org/licenses/>.
+ */
+
+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 <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
+ */
+public class CssClassNameFilter implements Filter {
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public Object format(DataProvider dataProvider, Object data, Map<String, String> parameters) {
+ return String.valueOf(data).replaceAll("[^a-zA-Z0-9-]", "_");
+ }
+
+}
import net.pterodactylus.sone.freenet.wot.Identity;
import net.pterodactylus.sone.main.SonePlugin;
import net.pterodactylus.sone.template.CollectionAccessor;
+import net.pterodactylus.sone.template.CssClassNameFilter;
import net.pterodactylus.sone.template.GetPagePlugin;
import net.pterodactylus.sone.template.IdentityAccessor;
import net.pterodactylus.sone.template.PostAccessor;
templateFactory.addFilter("xml", new XmlFilter());
templateFactory.addFilter("change", new RequestChangeFilter());
templateFactory.addFilter("match", new MatchFilter());
+ templateFactory.addFilter("css", new CssClassNameFilter());
templateFactory.addPlugin("getpage", new GetPagePlugin());
templateFactory.addPlugin("paginate", new PaginationPlugin());
templateFactory.setTemplateProvider(new ClassPathTemplateProvider(templateFactory));
}
/**
+ * Filters the given Sone ID, replacing all “~” characters by an underscore.
+ *
+ * @param soneId
+ * The Sone ID to filter
+ * @returns The filtered Sone ID
+ */
+function filterSoneId(soneId) {
+ return soneId.replace(/[^a-zA-Z0-9-]/g, "_");
+}
+
+/**
* Updates the status of the given Sone.
*
* @param soneId
* The date and time of the last update (formatted for display)
*/
function updateSoneStatus(soneId, name, status, modified, lastUpdated) {
- $("#sone .sone." + soneId).
+ $("#sone .sone." + filterSoneId(soneId)).
toggleClass("unknown", status == "unknown").
toggleClass("idle", status == "idle").
toggleClass("inserting", status == "inserting").
toggleClass("downloading", status == "downloading").
toggleClass("modified", modified);
- $("#sone .sone." + soneId + " .last-update span.time").text(lastUpdated);
- $("#sone .sone." + soneId + " .profile-link a").text(name);
+ $("#sone .sone." + filterSoneId(soneId) + " .last-update span.time").text(lastUpdated);
+ $("#sone .sone." + filterSoneId(soneId) + " .profile-link a").text(name);
}
var watchedSones = {};
-<div class="sone <% sone.status|html><%if sone.modified> modified<%/if> <% sone.id|html><%if sone.local> local<%/if>">
+<div class="sone <% sone.status|html><%if sone.modified> modified<%/if> <% sone.id|css|html><%if sone.local> local<%/if>">
<div class="id"><% sone.id|html></div>
<div class="unknown-marker" title="<%= View.Sone.Status.Unknown|l10n|html>">?</div>
<div class="modified-marker" title="<%= View.Sone.Status.Modified|l10n|html>">!</div>