diff src/nabble/view/web/template/NamespaceUtils.java @ 0:7ecd1a4ef557

add content
author Franklin Schmidt <fschmidt@gmail.com>
date Thu, 21 Mar 2019 19:15:52 -0600
parents
children
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/nabble/view/web/template/NamespaceUtils.java	Thu Mar 21 19:15:52 2019 -0600
@@ -0,0 +1,24 @@
+package nabble.view.web.template;
+
+import nabble.naml.compiler.Interpreter;
+import nabble.model.Site;
+
+
+public class NamespaceUtils {
+
+	public static int getInt(Interpreter interp, String attributeName, String errorMessage) {
+		return getInt(interp, attributeName, null, errorMessage);
+	}
+
+	public static int getInt(Interpreter interp, String attributeName, Integer defaultValue, String errorMessage) {
+		String value = interp.getArgString(attributeName);
+		if (value == null && defaultValue != null)
+			return defaultValue;
+		try {
+			return Integer.valueOf(value.trim());
+		} catch(NumberFormatException e) {
+			throw new RuntimeException(errorMessage,e);
+		}
+	}
+
+}