jetspeedprofilerservice.java
来自「jetspeed源代码」· Java 代码 · 共 1,107 行 · 第 1/3 页
JAVA
1,107 行
if (logger.isDebugEnabled())
{
logger.debug("Profiler: Processing profile for role " + roleProfile.getRoleName());
}
}
// Create a new profile for the user
ProfileLocator locator = createLocator();
locator.setUser((JetspeedUser) data.getUser());
locator.setMediaType(mediaType);
locator.setName(this.resourceDefault + this.resourceExt);
// Regenerate the portlet ids so they are unique
org.apache.jetspeed.util.PortletUtils.regenerateIds(portlets);
// Save the new profile to permament storage
result = this.createProfile(locator, portlets);
}
catch (Exception e)
{
logger.error("Exception", e);
}
}
return result;
}
/**
* get the Profile object using the Rundata state and capability map
* this is the mapping functionality of the profiler
*
* @param rundata the rundata object for the current request
* @param cm the <code>CapabilityMap</code> of the current requesting device
* @return a new Profile object
*/
protected Profile fallbackProfile(RunData data, CapabilityMap cm)
throws ProfileException
{
try
{
JetspeedRunData rundata = (JetspeedRunData)data;
Profile profile = createProfile();
JetspeedUser user = rundata.getJetspeedUser();
// get the media type from the capability map or rundata
profile.setMediaType(getMediaType(rundata, cm));
// Is it a group, role, or user resource?
// It can only be one
String param = rundata.getParameters().getString( Profiler.PARAM_GROUP );
if (null != param)
{
// GROUP Resource
profile.setGroup( JetspeedSecurity.getGroup(param) );
}
else
{
param = rundata.getParameters().getString( Profiler.PARAM_ROLE );
if (null != param)
{
// ROLE Resource
if (user.hasLoggedIn()) // disallow role access for anonymous user
{
profile.setRole( JetspeedSecurity.getRole(param) );
}
else
{
profile.setAnonymous(true);
profile.setUser( user );
}
}
else // it must be a user resource or anonymous resource
{
// accessing another user's resource
param = rundata.getParameters().getString( Profiler.PARAM_USER );
if (null != param)
{
if (param.equals(JetspeedSecurity.getAnonymousUserName()))
{
profile.setAnonymous(true);
}
if (user.getUserName().equals(param))
{
profile.setUser( user );
}
else
{
profile.setUser( JetspeedSecurity.getUser(param) );
}
}
else
{
profile.setAnonymous(user.getUserName().equals(JetspeedSecurity.getAnonymousUserName()));
profile.setUser( user );
}
}
}
// get resource name
StringBuffer resource = new StringBuffer();
param = rundata.getParameters().getString( Profiler.PARAM_PAGE );
if (null == param)
{
// the default resource
resource.append( resourceDefault );
resource.append( resourceExt );
}
else
{ // a specific resource
resource.append( param );
if ( -1 == param.indexOf( PATH_EXTENSION_DELIMITER ) )
resource.append( resourceExt );
}
profile.setName( resource.toString() );
// LANGUAGE
getLanguageSettings(profile, rundata);
PSMLDocument doc = fallback( profile );
if (null != doc)
{
profile.setDocument( doc );
return profile;
}
}
catch (Exception e)
{
logger.error( "Exception in fallbackProfile", e );
throw new ProfileException(e.toString());
}
return null;
}
/**
* get the Profile object using the Rundata state and capability map
* this is the mapping functionality of the profiler
*
* @param rundata the rundata object for the current request
* @return a new Profile object
*/
public Profile getProfile(RunData rundata)
throws ProfileException
{
CapabilityMap cm = null;
if (rundata instanceof JetspeedRunData)
{
cm = ((JetspeedRunData)rundata).getCapability();
}
else
{
cm = CapabilityMapFactory.getCapabilityMap( rundata );
}
return getProfile(rundata, cm);
}
/**
* get the Profile object using the Rundata state and specific mimetype
*
* @deprecated Do not use a profiler method based on MimeType
*
* @param rundata the rundata object for the current request
* @param mt the <code>MimeType</code> of the current requesting device
* @return a new Profile object
*/
public Profile getProfile(RunData data, MimeType mt)
throws ProfileException
{
CapabilityMap cm = CapabilityMapFactory.getCapabilityMap(mt.toString());
return getProfile(data, cm);
}
/**
* get the Profile object using a profile locator
*
* @param rundata The rundata object for the current request.
* @param locator The locator containing criteria describing the profile.
* @return a new Profile object
*/
public Profile getProfile(ProfileLocator locator)
throws ProfileException
{
PSMLDocument doc = fallback(locator);
Profile profile = createProfile(locator);
profile.setDocument(doc);
return profile;
}
/*
* Gets the language and country parameters from the request using the Turbine locale detector.
*
* @param profile The profile object which is modified with the new language settings.
* @param rundata The request specific state.
*/
protected void getLanguageSettings( Profile profile, RunData rundata )
{
String language = rundata.getParameters().getString(Profiler.PARAM_LANGUAGE);
if (language != null)
{
// dont use locale based fall back
profile.setLanguage(language);
if(! language.equals("-1"))
{
String country = rundata.getParameters().getString(Profiler.PARAM_COUNTRY);
if (country != null)
{
profile.setCountry(country);
}
}
}
else
{
Locale locale = (Locale)rundata.getUser().getTemp("locale");
if (locale == null)
{
// Get the locale store it in the user object
CustomLocalizationService locService = (CustomLocalizationService) ServiceUtil.getServiceByName(
LocalizationService.SERVICE_NAME);
locale = locService.getLocale(rundata);
if (locale == null)
{
locale = new Locale(
TurbineResources.getString("locale.default.language", "en"),
TurbineResources.getString("locale.default.country", "US"));
}
rundata.getUser().setTemp("locale", locale);
}
if (useFallbackLanguage)
{
profile.setLanguage( locale.getLanguage() );
}
if (useFallbackCountry)
{
profile.setCountry( locale.getCountry() );
}
}
}
/*
* A basic profiler fallback algorithm that starts from the most specific parameters,
* going to the least specific parameters. The PsmlManager implementation is passed
* a list of ProfileLocators ordered from most specific to least specific.
*
* @param locator The profile locator criteria used to locate a profile.
* @param rundata The request specific state.
* @return The found psml document, or null if not found.
*/
protected PSMLDocument fallbackList( ProfileLocator original, RunData rundata )
{
try
{
List locators = new LinkedList();
ProfileLocator locator = (ProfileLocator)original.clone();
locators.add( locator.clone() );
// remove country
if (null != original.getCountry())
{
locator.setCountry(null);
locators.add( locator.clone() );
}
// remove language
if (null != original.getLanguage())
{
locator.setLanguage(null);
locators.add( locator.clone() );
}
// fallback mediaType
if (null != original.getMediaType())
{
locator.setMediaType(null);
locators.add( locator.clone() );
}
if (null != original.getGroup())
{
locator.setGroup(null);
locators.add( locator.clone() );
}
else if (null != original.getRole())
{
locator.setRole(null);
locators.add( locator.clone() );
}
else if (null != original.getUser())
{
locator.setUser(null);
locators.add( locator.clone() );
}
PSMLDocument doc = PsmlManager.getDocument( locators );
return doc;
}
catch (CloneNotSupportedException e)
{
logger.error("Profiler: Could not clone profile locator object", e);
}
return null;
}
/*
* A basic profiler fallback algorithm that starts from the most specific parameters,
* going to the least specific parameters. The PsmlManager implementation is passed
* a list of ProfileLocators ordered from most specific to least specific.
*
* This is alternate fallback algorithm.
*
* @param locator The profile locator criteria used to locate a profile.
*
* @return PSMLDocument The located document or null.
*/
protected PSMLDocument fallback(ProfileLocator locator)
{
if (logger.isDebugEnabled())
{
logger.debug( "Profiler: fallback called with: " + locator );
}
PSMLDocument doc = PsmlManager.getDocument( locator );
if (null != doc)
return doc;
// remove country
if (null != locator.getCountry() && (! locator.getCountry().equals("-1")))
{
locator.setCountry(null);
doc = PsmlManager.getDocument( locator );
if (null != doc)
return doc;
}
// remove language
if (null != locator.getLanguage() && (! locator.getLanguage().equals("-1")))
{
locator.setLanguage(null);
doc = PsmlManager.getDocument( locator );
if (null != doc)
return doc;
}
// fallback mediaType
if (useFallbackToRoot)
{
if (null != locator.getMediaType())
{
locator.setMediaType(null);
doc = PsmlManager.getDocument( locator );
if (null != doc)
return doc;
}
}
if (!useRoleFallback)
{
if (null != locator.getGroup())
{
locator.setGroup(null);
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?