Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.example.struts2.DBTextProvider;
- import java.util.*;
- import com.opensymphony.xwork2.*;
- import com.opensymphony.xwork2.util.*;
- import com.example.text.util.RssUtil;
- /**
- * TextProvider implementation that calls static methods on an external helper.
- * This external helper RssUtil gets some resources from the database and uses a legacy API.
- */
- public class DBTextProvider
- implements TextProvider,
- LocaleProvider
- {
- //~ Instance fields --------------------------------------------------------
- private transient TextProvider textProvider;
- //~ Methods ----------------------------------------------------------------
- public Locale getLocale( )
- {
- ActionContext ctx = ActionContext.getContext( );
- if ( ctx != null )
- {
- return ctx.getLocale( );
- }
- else
- {
- return null;
- }
- }
- public boolean hasKey( String key )
- {
- // if ( RssUtil.lookupText( getLocale( ), key ) != null )
- // {
- // return true;
- // }
- return getTextProvider( ).hasKey( key );
- }
- public String getText( String aTextName )
- {
- // String rssText = RssUtil.convertText( aTextName );
- // if ( ( rssText != null ) && !rssText.equals( aTextName ) )
- // {
- // return rssText;
- // }
- return getTextProvider( ).getText( aTextName );
- }
- public String getText( String aTextName,
- String defaultValue )
- {
- // String rssText = RssUtil.convertText( aTextName );
- // if ( ( rssText != null ) && !rssText.equals( aTextName ) )
- // {
- // return rssText;
- // }
- return getTextProvider( ).getText( aTextName, defaultValue );
- }
- public String getText( String aTextName,
- String defaultValue,
- String obj )
- {
- // Object msgArgs[] = new Object[] { obj };
- // String rssText = RssUtil.convertText( aTextName, msgArgs );
- // if ( ( rssText != null ) && !rssText.equals( aTextName ) )
- // {
- // return rssText;
- // }
- return getTextProvider( ).getText( aTextName, defaultValue, obj );
- }
- public String getText( String aTextName,
- List<Object> args )
- {
- // String rssText = RssUtil.convertText( aTextName, args.toArray( ) );
- // if ( ( rssText != null ) && !rssText.equals( aTextName ) )
- // {
- // return rssText;
- // }
- return getTextProvider( ).getText( aTextName, args );
- }
- public String getText( String key,
- String args[] )
- {
- // String rssText = RssUtil.convertText( key, args );
- // if ( ( rssText != null ) && !rssText.equals( key ) )
- // {
- // return rssText;
- // }
- return getTextProvider( ).getText( key, args );
- }
- public String getText( String aTextName,
- String defaultValue,
- List<Object> args )
- {
- // String rssText = RssUtil.convertText( aTextName, args.toArray( ) );
- // if ( ( rssText != null ) && !rssText.equals( aTextName ) )
- // {
- // return rssText;
- // }
- return getTextProvider( ).getText( aTextName, defaultValue, args );
- }
- public String getText( String key,
- String defaultValue,
- String args[] )
- {
- // String rssText = RssUtil.convertText( key, args );
- // if ( ( rssText != null ) && !rssText.equals( key ) )
- // {
- // return rssText;
- // }
- return getTextProvider( ).getText( key, defaultValue, args );
- }
- public String getText( String key,
- String defaultValue,
- List<Object> args,
- ValueStack stack )
- {
- // String rssText = RssUtil.convertText( key, args.toArray( ) );
- // if ( ( rssText != null ) && !rssText.equals( key ) )
- // {
- // return rssText;
- // }
- return getTextProvider( ).getText( key, defaultValue, args, stack );
- }
- public String getText( String key,
- String defaultValue,
- String args[],
- ValueStack stack )
- {
- // String rssText = RssUtil.convertText( key, args );
- // if ( ( rssText != null ) && !rssText.equals( key ) )
- // {
- // return rssText;
- // }
- return getTextProvider( ).getText( key, defaultValue, args, stack );
- }
- public ResourceBundle getTexts( )
- {
- // should return RssUtil.resourceProperties as a Bundle?
- return getTextProvider( ).getTexts( );
- }
- public ResourceBundle getTexts( String aBundleName )
- {
- return getTextProvider( ).getTexts( aBundleName );
- }
- private TextProvider getTextProvider( )
- {
- if ( textProvider == null )
- {
- TextProviderFactory tpf = new TextProviderFactory( );
- textProvider = tpf.createInstance( getClass( ), this );
- }
- return textProvider;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment