diff options
author | David A. Madore <david+git@madore.org> | 2014-10-09 17:27:58 +0200 |
---|---|---|
committer | David A. Madore <david+git@madore.org> | 2014-10-09 17:27:58 +0200 |
commit | 8ed1ac19770dca2b5c37c529fe4420068e107f77 (patch) | |
tree | 09d3e8397c4751b197c5e44260838f4480099806 /org | |
parent | 240a3c4d99aba9aca244033425569ce56f7dc0c8 (diff) | |
download | damlengine-8ed1ac19770dca2b5c37c529fe4420068e107f77.tar.gz damlengine-8ed1ac19770dca2b5c37c529fe4420068e107f77.tar.bz2 damlengine-8ed1ac19770dca2b5c37c529fe4420068e107f77.zip |
Allow substitution of literal or numeric month in weblog month selection.
Diffstat (limited to 'org')
-rw-r--r-- | org/madore/damlengine/TodoElement.java | 4 | ||||
-rw-r--r-- | org/madore/damlengine/TodoWeblogMonthsCalendar.java | 22 | ||||
-rw-r--r-- | org/madore/damlengine/TodoWeblogSelectionElement.java | 23 |
3 files changed, 39 insertions, 10 deletions
diff --git a/org/madore/damlengine/TodoElement.java b/org/madore/damlengine/TodoElement.java index 83275ad..acccac0 100644 --- a/org/madore/damlengine/TodoElement.java +++ b/org/madore/damlengine/TodoElement.java @@ -64,8 +64,8 @@ public abstract class TodoElement extends TodoItem { damlFactories.put("weblog-select", new TodoWeblogSelectElement.Factory()); damlFactories.put("weblog-index-select", new TodoWeblogIndexSelectElement.Factory()); damlFactories.put("weblog-selection-recent-count", new TodoWeblogSelectionElement.Factory(TodoWeblogSelectionElement.Type.RECENT_COUNT)); - damlFactories.put("weblog-selection-month-year", new TodoWeblogSelectionElement.Factory(TodoWeblogSelectionElement.Type.MONTH_YEAR)); - damlFactories.put("weblog-selection-month-month", new TodoWeblogSelectionElement.Factory(TodoWeblogSelectionElement.Type.MONTH_MONTH)); + damlFactories.put("weblog-selection-month-numeric", new TodoWeblogSelectionElement.Factory(TodoWeblogSelectionElement.Type.MONTH_NUMERIC)); + damlFactories.put("weblog-selection-month-literal", new TodoWeblogSelectionElement.Factory(TodoWeblogSelectionElement.Type.MONTH_LITERAL)); damlFactories.put("weblog-selection-cat-code", new TodoWeblogSelectionElement.Factory(TodoWeblogSelectionElement.Type.CATEGORY_CODE)); damlFactories.put("weblog-selection-cat-name", new TodoWeblogSelectionElement.Factory(TodoWeblogSelectionElement.Type.CATEGORY_NAME)); damlFactories.put("weblog-selection-single-number", new TodoWeblogSelectionElement.Factory(TodoWeblogSelectionElement.Type.SINGLE_NUMBER)); diff --git a/org/madore/damlengine/TodoWeblogMonthsCalendar.java b/org/madore/damlengine/TodoWeblogMonthsCalendar.java index 044f05f..481f05a 100644 --- a/org/madore/damlengine/TodoWeblogMonthsCalendar.java +++ b/org/madore/damlengine/TodoWeblogMonthsCalendar.java @@ -23,6 +23,28 @@ public final class TodoWeblogMonthsCalendar extends TodoDefaultElement { "Sep", "Oct", "Nov", "Dec", }; + public static final String[] monthNamesEn = { + null, + "January", "February", "March", "April", + "May", "June", "July", "August", + "September", "October", "November", "December", + }; + + public static final String[] monthNamesFr = { + null, + "janvier", "f\u00e9vrier", "mars", "avril", + "mai", "juin", "juillet", "ao\u00fbt", + "septembre", "octobre", "novembre", "d\u00e9cembre", + }; + + public static final Map<String,String[]> monthNames; + + static { + monthNames = new HashMap<String,String[]>(); + monthNames.put("en", monthNamesEn); + monthNames.put("fr", monthNamesFr); + } + public static class Factory extends TodoElement.Factory { @Override public TodoWeblogMonthsCalendar newItem(Element node, diff --git a/org/madore/damlengine/TodoWeblogSelectionElement.java b/org/madore/damlengine/TodoWeblogSelectionElement.java index c9088eb..637bc85 100644 --- a/org/madore/damlengine/TodoWeblogSelectionElement.java +++ b/org/madore/damlengine/TodoWeblogSelectionElement.java @@ -12,8 +12,8 @@ public final class TodoWeblogSelectionElement extends TodoDefaultElement { public enum Type { RECENT_COUNT, - MONTH_YEAR, - MONTH_MONTH, + MONTH_NUMERIC, + MONTH_LITERAL, CATEGORY_NAME, CATEGORY_CODE, SINGLE_NUMBER, @@ -114,19 +114,26 @@ public final class TodoWeblogSelectionElement extends TodoDefaultElement { newNode = ctx.doc.createTextNode(str); node.getParentNode().replaceChild(newNode, node); break; - case MONTH_YEAR: + case MONTH_NUMERIC: if ( ! ( ctx.wsc instanceof Context.WeblogMonthSelectionContext ) ) - throw new IllegalStateException("weblog-selection-month-year element encountered while not in weblog month selection state"); - str = ((Context.WeblogMonthSelectionContext)(ctx.wsc)).year; + throw new IllegalStateException("weblog-selection-month-numeric element encountered while not in weblog month selection state"); + str = ((Context.WeblogMonthSelectionContext)(ctx.wsc)).year + "-" + + ((Context.WeblogMonthSelectionContext)(ctx.wsc)).month; newNode = ctx.doc.createTextNode(str); node.getParentNode().replaceChild(newNode, node); break; - case MONTH_MONTH: + case MONTH_LITERAL: if ( ! ( ctx.wsc instanceof Context.WeblogMonthSelectionContext ) ) - throw new IllegalStateException("weblog-selection-month-month element encountered while not in weblog month selection state"); - str = ((Context.WeblogMonthSelectionContext)(ctx.wsc)).month; + throw new IllegalStateException("weblog-selection-month-literal element encountered while not in weblog month selection state"); + int mnum = Integer.parseInt(((Context.WeblogMonthSelectionContext)(ctx.wsc)).month); + String lang = LangHelper.getLangRec(node); + String[] mnames = TodoWeblogMonthsCalendar.monthNames.get(lang); + if ( mnames == null ) + mnames = TodoWeblogMonthsCalendar.monthNamesEn; + str = mnames[mnum] + " " + ((Context.WeblogMonthSelectionContext)(ctx.wsc)).year; newNode = ctx.doc.createTextNode(str); node.getParentNode().replaceChild(newNode, node); + LangHelper.setLangRec(node, lang); break; case CATEGORY_CODE: if ( ! ( ctx.wsc instanceof Context.WeblogCategorySelectionContext ) ) |