So I have been working on a practical solution that allows me to source
my localization texts from a database table.  I am using Spring 3.0.2
and Hibernate 3.5.1 along with Struts 2.1.8.1 for the implementation.  I
have my base action being wired with my TextService via Spring and then
I have overwritten each of the getText() methods to make calls to
getMyTextProvider().getText(...) methods as shown below.

 

// MyBaseAction.java

//

abstract public class MyBaseAction 

  extends ActionSupport

  implements Preparable, SessionAware, ServletContextAware,
ServletRequestAware {

 

  protected TextService                                 textService;

 

  public void setTextService(TextService textService) {

    this.textService = textService;

  }

 

  public MyTextProvider getMyTextProvider() {

    return new MyTextProvider(textService, this);

  }

 

  // Overwrote all getText methods to use 

  // return(getMyTextProvider().getText(......) methods

}

 

The text provider itself simply extends TextProviderSupport and when the
object is being created, I am actually referencing a special
ResourceBundle class called MyDatabaseBundle and passing that to the
TextProvider framework as shown here.

 

// MyTextProvider.java

//

public class MyTextProvider extends TextProviderSupport {

  public MyTextProvider(TextService textService, LocaleProvider
localeProvider) {

    super(new MyDatabaseBundle(textService), localeProvider);

  }

}

 

The MyDatabaseBundle resource bundle object will read the database table
and store the values.

 

// MyDatabaseBundle.java

//

public class MyDatabaseBundle extends ResourceBundle {

  // overwritten implement here

}

 

>From what I have gathered, this looks pretty straight forward but is it
the right and practical way?  What about multiple languages?  Will that
resource bundle object handle it appropriately?  What will I need to do
to support that?  If there is a better approach, please inform me.   It
is probably worth noting that in my struts.xml file I have the following
configurations:

 

<constant name="seek.xworkTextProvider" value="myTextProvider"/>

<bean name="myTextProvider"
class="com.struts2.localization.MyTextProvider" scope="default"
type="com.opensymphony.xwork2.TextProvider"/>

 

Thanks

Chris

 

Reply via email to