rdftemplate

Library for generating XML documents from RDF data using templates
git clone https://code.djc.id.au/git/rdftemplate/
commit 40152613d397638b595eb43cb41aac14ac088000
parent fdf70b2241c88c214fd1202f26222871f706c48b
Author: Dan Callaghan <djc@djc.id.au>
Date:   Thu, 12 Nov 2009 21:52:33 +1000

translate " to ' for joda date formats, for convenience in selector expressions

Diffstat:
Msrc/main/java/au/com/miskinhill/rdftemplate/selector/FormattedDateTimeAdaptation.java | 3++-
Msrc/test/java/au/com/miskinhill/rdftemplate/selector/SelectorEvaluationUnitTest.java | 7+++++++
2 files changed, 9 insertions(+), 1 deletion(-)
diff --git a/src/main/java/au/com/miskinhill/rdftemplate/selector/FormattedDateTimeAdaptation.java b/src/main/java/au/com/miskinhill/rdftemplate/selector/FormattedDateTimeAdaptation.java
@@ -12,9 +12,11 @@ import org.joda.time.format.DateTimeFormatter;
 public class FormattedDateTimeAdaptation implements Adaptation<String> {
     
     private final String pattern;
+    private final DateTimeFormatter formatter;
     
     public FormattedDateTimeAdaptation(String pattern) {
         this.pattern = pattern;
+        this.formatter = DateTimeFormat.forPattern(pattern.replace("\"", "'")); // for convenience in XML
     }
 
     public String getPattern() {
@@ -31,7 +33,6 @@ public class FormattedDateTimeAdaptation implements Adaptation<String> {
         if (!node.isLiteral()) {
             throw new SelectorEvaluationException("Attempted to apply #formatted-dt to non-literal node " + node);
         }
-        DateTimeFormatter formatter = DateTimeFormat.forPattern(pattern);
         Object lv = ((Literal) node).getValue();
         if (lv instanceof ReadableInstant) {
             ReadableInstant instant = (ReadableInstant) lv;
diff --git a/src/test/java/au/com/miskinhill/rdftemplate/selector/SelectorEvaluationUnitTest.java b/src/test/java/au/com/miskinhill/rdftemplate/selector/SelectorEvaluationUnitTest.java
@@ -182,4 +182,11 @@ public class SelectorEvaluationUnitTest {
         assertThat(result, equalTo("15 June 2009"));
     }
     
+    @Test
+    public void shouldEvaluateFormattedDTAdaptationWithDoubleQuotes() throws Exception {
+        String result = selectorFactory.get("!sioc:has_container/dc:created#formatted-dt('yyyy-MM-dd\"T\"HH:mm:ss')")
+                .withResultType(String.class).singleResult(forum);
+        assertThat(result, equalTo("2009-06-15T18:21:32"));
+    }
+    
 }