Anonymous avatar Anonymous committed 3358f1d

Make TextProvider configurable
Issue Number: XW-475
Submitted by: Oleg Gorobets

git-svn-id: http://svn.opensymphony.com/svn/xwork/branches/2.0@1357 e221344d-f017-0410-9bd5-d282ab1896d7

Comments (0)

Files changed (4)

src/java/com/opensymphony/xwork2/ActionSupport.java

  */
 public class ActionSupport implements Action, Validateable, ValidationAware, TextProvider, LocaleProvider, Serializable {
 
-    protected transient static final Log LOG = LogFactory.getLog(ActionSupport.class);
+    protected static Log LOG = LogFactory.getLog(ActionSupport.class);
 
-    private transient final TextProvider textProvider = new TextProviderSupport(getClass(), this);
+    private final transient TextProvider textProvider = TextProviderFactory.getInstance(getClass(), this);
     private final ValidationAwareSupport validationAware = new ValidationAwareSupport();
 
 

src/java/com/opensymphony/xwork2/TextProviderFactory.java

+/*
+ * Copyright (c) 2002-2007 by OpenSymphony
+ * All rights reserved.
+ */
+package com.opensymphony.xwork2;
+
+import java.util.ResourceBundle;
+
+/**
+ * <code>TextProviderFactory</code>
+ *
+ * @author Oleg Gorobets
+ */
+public class TextProviderFactory {
+
+    private static TextProvider instance = new TextProviderSupport();
+
+    /**
+     * @param instance Text provider
+     */
+    public static void setInstance(TextProvider instance) {
+        TextProviderFactory.instance = instance;
+    }
+
+    public static TextProvider getInstance() {
+        return instance;
+    }
+
+    public static TextProvider getInstance(Class clazz, LocaleProvider provider) {
+        if (instance instanceof TextProviderSupport) {
+            ((TextProviderSupport) instance).setClazz(clazz);
+            ((TextProviderSupport) instance).setLocaleProvider(provider);
+        }
+        return instance;
+    }
+
+    public static TextProvider getInstance(ResourceBundle bundle, LocaleProvider provider) {
+        if (instance instanceof TextProviderSupport) {
+            ((TextProviderSupport) instance).setBundle(bundle);
+            ((TextProviderSupport) instance).setLocaleProvider(provider);
+        }
+        return instance;
+    }
+}

src/java/com/opensymphony/xwork2/TextProviderSupport.java

 
 
     /**
+     * Default constructor
+     */
+    public TextProviderSupport() {
+    }
+
+    /**
      * Constructor.
      *
-     * @param clazz   a clazz to use for reading the resource bundle.
-     * @param provider  a locale provider.
+     * @param clazz    a clazz to use for reading the resource bundle.
+     * @param provider a locale provider.
      */
     public TextProviderSupport(Class clazz, LocaleProvider provider) {
         this.clazz = clazz;
     /**
      * Constructor.
      *
-     * @param bundle    the resource bundle.
-     * @param provider  a locale provider.
+     * @param bundle   the resource bundle.
+     * @param provider a locale provider.
      */
     public TextProviderSupport(ResourceBundle bundle, LocaleProvider provider) {
         this.bundle = bundle;
         this.localeProvider = provider;
     }
 
+    /**
+     * @param bundle the resource bundle.
+     */
+    public void setBundle(ResourceBundle bundle) {
+        this.bundle = bundle;
+    }
+
+    /**
+     * @param clazz a clazz to use for reading the resource bundle.
+     */
+    public void setClazz(Class clazz) {
+        this.clazz = clazz;
+    }
+
+
+    /**
+     * @param localeProvider a locale provider.
+     */
+    public void setLocaleProvider(LocaleProvider localeProvider) {
+        this.localeProvider = localeProvider;
+    }
 
     /**
      * Get a text from the resource bundles associated with this action.

src/java/com/opensymphony/xwork2/validator/DelegatingValidatorContext.java

      */
     public DelegatingValidatorContext(Class clazz) {
         localeProvider = new ActionContextLocaleProvider();
-        textProvider = new TextProviderSupport(clazz, localeProvider);
+        textProvider = TextProviderFactory.getInstance(clazz, localeProvider);
         validationAware = new LoggingValidationAware(clazz);
     }
 
         if (object instanceof TextProvider) {
             return (TextProvider) object;
         } else {
-            return new TextProviderSupport(object.getClass(), localeProvider);
+            return TextProviderFactory.getInstance(object.getClass(), localeProvider);
         }
     }
 
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.