Author: juanpablo
Date: Fri Feb 8 20:36:06 2013
New Revision: 1444222
URL: http://svn.apache.org/r1444222
Log:
deprecated / moved [1/2]:
-> WikiContext#getBundle( String ) in favour of Preferences#getBundle(
WikiContext, String )
-> WikiContext#getLocale( WikiContext ) in favour of Preferences#getLocale(
WikiContext )
Modified:
incubator/jspwiki/trunk/src/org/apache/wiki/WikiContext.java
incubator/jspwiki/trunk/src/org/apache/wiki/preferences/Preferences.java
Modified: incubator/jspwiki/trunk/src/org/apache/wiki/WikiContext.java
URL:
http://svn.apache.org/viewvc/incubator/jspwiki/trunk/src/org/apache/wiki/WikiContext.java?rev=1444222&r1=1444221&r2=1444222&view=diff
==============================================================================
--- incubator/jspwiki/trunk/src/org/apache/wiki/WikiContext.java (original)
+++ incubator/jspwiki/trunk/src/org/apache/wiki/WikiContext.java Fri Feb 8
20:36:06 2013
@@ -22,7 +22,10 @@ import java.io.IOException;
import java.security.Permission;
import java.security.Principal;
import java.text.MessageFormat;
-import java.util.*;
+import java.util.HashMap;
+import java.util.Locale;
+import java.util.MissingResourceException;
+import java.util.ResourceBundle;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@@ -30,14 +33,16 @@ import javax.servlet.http.HttpSession;
import javax.servlet.jsp.PageContext;
import org.apache.log4j.Logger;
-
-import org.apache.wiki.auth.*;
+import org.apache.wiki.auth.AuthorizationManager;
+import org.apache.wiki.auth.NoSuchPrincipalException;
+import org.apache.wiki.auth.UserManager;
+import org.apache.wiki.auth.WikiPrincipal;
import org.apache.wiki.auth.permissions.AllPermission;
import org.apache.wiki.auth.user.UserDatabase;
import org.apache.wiki.i18n.InternationalizationManager;
+import org.apache.wiki.preferences.Preferences;
import org.apache.wiki.tags.WikiTagBase;
import org.apache.wiki.ui.*;
-import org.apache.wiki.preferences.Preferences;
/**
* <p>Provides state information throughout the processing of a page. A
@@ -829,19 +834,18 @@ public class WikiContext
if( !allowed && redirect )
{
Principal currentUser = m_session.getUserPrincipal();
- Object[] arguments = { getName() };
if( m_session.isAuthenticated() )
{
log.info("User "+currentUser.getName()+" has no access -
forbidden (permission=" + requiredPermission() + ")" );
String pageurl = m_page.getName();
- m_session.addMessage( MessageFormat.format(
rb.getString("security.error.noaccess.logged"), arguments) );
+ m_session.addMessage( MessageFormat.format(
rb.getString("security.error.noaccess.logged"), getName()) );
response.sendRedirect( m_engine.getURL(WikiContext.LOGIN,
pageurl, null, false ) );
}
else
{
log.info("User "+currentUser.getName()+" has no access -
redirecting (permission=" + requiredPermission() + ")");
String pageurl = m_page.getName();
- m_session.addMessage( MessageFormat.format(
rb.getString("security.error.noaccess"), arguments) );
+ m_session.addMessage( MessageFormat.format(
rb.getString("security.error.noaccess"), getName()) );
response.sendRedirect( m_engine.getURL(WikiContext.LOGIN,
pageurl, null, false ) );
}
}
@@ -960,7 +964,10 @@ public class WikiContext
* @param bundle The name of the bundle you are looking for.
* @return A resource bundle object
* @throws MissingResourceException If the bundle cannot be found
+ * @deprecated will be removed in 2.10 scope. Consider using
+ * {@link Preferences#getBundle(WikiContext,String)} instead.
*/
+ @Deprecated
// FIXME: This method should really cache the ResourceBundles or
something...
public ResourceBundle getBundle( String bundle ) throws
MissingResourceException
{
@@ -977,15 +984,13 @@ public class WikiContext
*
* @return A valid locale object
* @param context The WikiContext
+ * @deprecated will be removed in 2.10 scope. Consider using {@link
Preferences#getLocale(WikiContext)}
+ * instead
*/
+ @Deprecated
public static Locale getLocale( WikiContext context )
{
return Preferences.getLocale( context );
-/*
- HttpServletRequest request = context.getHttpRequest();
- return ( request != null )
- ? request.getLocale() : Locale.getDefault();
-*/
}
}
Modified:
incubator/jspwiki/trunk/src/org/apache/wiki/preferences/Preferences.java
URL:
http://svn.apache.org/viewvc/incubator/jspwiki/trunk/src/org/apache/wiki/preferences/Preferences.java?rev=1444222&r1=1444221&r2=1444222&view=diff
==============================================================================
--- incubator/jspwiki/trunk/src/org/apache/wiki/preferences/Preferences.java
(original)
+++ incubator/jspwiki/trunk/src/org/apache/wiki/preferences/Preferences.java
Fri Feb 8 20:36:06 2013
@@ -29,14 +29,13 @@ import javax.servlet.jsp.PageContext;
import org.apache.commons.lang.StringUtils;
import org.apache.log4j.Logger;
-import org.json.JSONObject;
-
import org.apache.wiki.InternalWikiException;
import org.apache.wiki.PropertyReader;
import org.apache.wiki.WikiContext;
import org.apache.wiki.i18n.InternationalizationManager;
import org.apache.wiki.util.HttpUtil;
import org.apache.wiki.util.TextUtil;
+import org.json.JSONObject;
/**
* Represents an object which is used to store user preferences.
@@ -202,16 +201,16 @@ public class Preferences
* @return a Locale object.
* @since 2.8
*/
- public static Locale getLocale(WikiContext context)
+ public static Locale getLocale( WikiContext context )
{
Locale loc = null;
- String langSetting = Preferences.getPreference( context, "Language" );
+ String langSetting = getPreference( context, "Language" );
//
// parse language and construct valid Locale object
//
- if( langSetting != null)
+ if( langSetting != null )
{
String language = "";
String country = "";
@@ -231,7 +230,7 @@ public class Preferences
}
// otherwise try to find out the browser's preferred language setting,
or use the JVM's default
- if( loc == null)
+ if( loc == null )
{
HttpServletRequest request = context.getHttpRequest();
loc = ( request != null ) ? request.getLocale() :
Locale.getDefault();
@@ -240,6 +239,24 @@ public class Preferences
//log.info( "using locale "+loc.toString() );
return loc;
}
+
+ /**
+ * Locates the i18n ResourceBundle given. This method interprets
+ * the request locale, and uses that to figure out which language the
+ * user wants.
+ * @see org.apache.wiki.i18n.InternationalizationManager
+ * @param context {@link WikiContext} holding the user's locale
+ * @param bundle The name of the bundle you are looking for.
+ * @return A localized string (or from the default language, if not found)
+ * @throws MissingResourceException If the bundle cannot be found
+ */
+ public static ResourceBundle getBundle( WikiContext context, String bundle
)
+ throws MissingResourceException
+ {
+ Locale loc = getLocale( context );
+ InternationalizationManager i18n =
context.getEngine().getInternationalizationManager();
+ return i18n.getBundle( bundle, loc );
+ }
/**
* Get SimpleTimeFormat according to user browser locale and preferred
time
@@ -254,8 +271,8 @@ public class Preferences
public static SimpleDateFormat getDateFormat( WikiContext context,
TimeFormat tf )
{
InternationalizationManager imgr =
context.getEngine().getInternationalizationManager();
- Locale clientLocale = Preferences.getLocale( context );
- String prefTimeZone = Preferences.getPreference( context, "TimeZone" );
+ Locale clientLocale = getLocale( context );
+ String prefTimeZone = getPreference( context, "TimeZone" );
String prefDateFormat;
log.debug("Checking for preferences...");
@@ -263,7 +280,7 @@ public class Preferences
switch( tf )
{
case DATETIME:
- prefDateFormat = Preferences.getPreference( context,
"DateFormat" );
+ prefDateFormat = getPreference( context, "DateFormat" );
log.debug("Preferences fmt = "+prefDateFormat);
if( prefDateFormat == null )
{