X-Git-Url: https://git.pterodactylus.net/?p=Sone.git;a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2Ftemplate%2FUnknownDateFilter.java;fp=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2Ftemplate%2FUnknownDateFilter.java;h=4fc95f71069afa8dc5c36793e09417a6e0a3fc95;hp=0000000000000000000000000000000000000000;hb=5d18f62236a3771c4efa05d96c2851b95366a7dd;hpb=0001614e7188967fabe8597d4c5663952ab19197
diff --git a/src/main/java/net/pterodactylus/sone/template/UnknownDateFilter.java b/src/main/java/net/pterodactylus/sone/template/UnknownDateFilter.java
new file mode 100644
index 0000000..4fc95f7
--- /dev/null
+++ b/src/main/java/net/pterodactylus/sone/template/UnknownDateFilter.java
@@ -0,0 +1,66 @@
+/*
+ * Sone - UnknownDateFilter.java - Copyright © 2011 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;
+import freenet.l10n.BaseL10n;
+
+/**
+ * {@link Filter} implementation that replaces a {@link Long} with a value of
+ * {@code 0} by a {@link String} from an {@link BaseL10n l10n handler}.
+ *
+ * @author David âBombeâ Roden
+ */
+public class UnknownDateFilter implements Filter {
+
+ /** The l10n handler. */
+ private BaseL10n l10nHandler;
+
+ /** The key for the text to show. */
+ private final String unknownKey;
+
+ /**
+ * Creates a new unknown date filter.
+ *
+ * @param l10nHandler
+ * The l10n handler
+ * @param unknownKey
+ * The key of the text to show
+ */
+ public UnknownDateFilter(BaseL10n l10nHandler, String unknownKey) {
+ this.l10nHandler = l10nHandler;
+ this.unknownKey = unknownKey;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public Object format(DataProvider dataProvider, Object data, Map parameters) {
+ if (data instanceof Long) {
+ if ((Long) data == 0) {
+ return l10nHandler.getString(unknownKey);
+ }
+ }
+ return data;
+ }
+
+}