package nl.eveoh.thymeleaf.joda.dialect;

import nl.eveoh.thymeleaf.joda.expression.Joda;
import nl.eveoh.thymeleaf.joda.expression.JodaImpl;
import org.thymeleaf.context.IContext;
import org.thymeleaf.context.IProcessingContext;
import org.thymeleaf.context.IWebContext;
import org.thymeleaf.dialect.AbstractDialect;
import org.thymeleaf.dialect.IExpressionEnhancingDialect;

import javax.servlet.http.HttpServletRequest;

import java.util.HashMap;
import java.util.Map;

/**
 * Thymeleaf dialect used to format Joda {@link org.joda.time.DateTime}, {@link org.joda.time.LocalDate}, and
 * {@link org.joda.time.LocalTime} objects in Thymeleaf pages.
 *
 * @author Marco Krikke
 */
public class JodaDialect extends AbstractDialect implements IExpressionEnhancingDialect {

    public static final String DEFAULT_PREFIX = "joda";

    public static final String JODA_EXPRESSION_OBJECT_NAME = "joda";

    public JodaDialect() {
        super();
    }

    public String getPrefix() {
        return DEFAULT_PREFIX;
    }

    @Override
    public Map<String, Object> getAdditionalExpressionObjects(IProcessingContext processingContext) {
        final IContext context = processingContext.getContext();
        final IWebContext webContext = (context instanceof IWebContext ? (IWebContext) context : null);

        final Map<String, Object> objects = new HashMap<String, Object>(1, 1.0f);

		/*
         * Create the #joda expression object
		 */
        if (webContext != null) {
            final HttpServletRequest request = webContext.getHttpServletRequest();

            if (request != null) {
                final Joda joda = new JodaImpl(request.getLocale());

                objects.put(JODA_EXPRESSION_OBJECT_NAME, joda);
            }

        }

        return objects;
    }
}

@@ -85,99 +85,12 @@
 Joda
-;%0Aimport nl.eveoh.thymeleaf.joda.expression.JodaImpl;%0Aimport org.thymeleaf.context.IContext
+Impl
 ;%0Aim
@@ -140,50 +140,8 @@
 xt;%0A
-import org.thymeleaf.context.IWebContext;%0A
 impo
@@ -245,55 +245,8 @@
 t;%0A%0A
-import javax.servlet.http.HttpServletRequest;%0A%0A
 impo
@@ -267,16 +267,41 @@
 ashMap;%0A
+import java.util.Locale;%0A
 import j
@@ -990,30 +990,21 @@
     
-final IContext context
+Locale locale
  = p
@@ -1036,111 +1036,19 @@
 xt()
-;%0A        final IWebContext webContext = (context instanceof IWebContext ? (IWebContext) context : null
+.getLocale(
 );%0A%0A
@@ -1055,22 +1055,16 @@
         
-final 
 Map%3CStri
@@ -1075,17 +1075,27 @@
 Object%3E 
-o
+expressionO
 bjects =
@@ -1127,316 +1127,30 @@
 ct%3E(
-1, 1.0f);%0A%0A%09%09/*%0A         * Create the #joda expression object%0A%09%09 */%0A        if (webContext != null) %7B%0A            final HttpServletRequest request = webContext.getHttpServletRequest();%0A%0A            if (request != null) %7B%0A                final Joda joda = new JodaImpl(request.getLocale());%0A%0A                o
+);%0A        expressionO
 bjec
@@ -1189,39 +1189,30 @@
 ME, 
-joda);%0A            %7D%0A%0A        %7D
+new JodaImpl(locale));
 %0A%0A  
@@ -1224,17 +1224,27 @@
  return 
-o
+expressionO
 bjects;%0A

Make sure the expression object also works in non-Web contexts.