raphael 2002/11/03 06:41:48
Modified: src/java/org/apache/jetspeed/services/profiler
JetspeedProfilerService.java
Log:
Fix CastorPsmlManager to not use a media-type map keyed on mime-type.
Add a MediaTypeRegistry interface to provide needed search capability
Revision Changes Path
1.38 +75 -91
jakarta-jetspeed/src/java/org/apache/jetspeed/services/profiler/JetspeedProfilerService.java
Index: JetspeedProfilerService.java
===================================================================
RCS file:
/home/cvs/jakarta-jetspeed/src/java/org/apache/jetspeed/services/profiler/JetspeedProfilerService.java,v
retrieving revision 1.37
retrieving revision 1.38
diff -u -r1.37 -r1.38
--- JetspeedProfilerService.java 15 Oct 2002 17:35:32 -0000 1.37
+++ JetspeedProfilerService.java 3 Nov 2002 14:41:48 -0000 1.38
@@ -101,6 +101,7 @@
import org.apache.jetspeed.om.profile.Skin;
import org.apache.jetspeed.om.profile.psml.PsmlSkin;
import org.apache.jetspeed.om.profile.BasePSMLDocument;
+import org.apache.jetspeed.om.registry.MediaTypeRegistry;
import org.apache.jetspeed.om.registry.MediaTypeEntry;
import org.apache.jetspeed.om.profile.Entry;
@@ -132,15 +133,15 @@
* <dt>resource.ext</dt><dd>The default resource filename extension</dd>
* <dt>security</dt><dd>Use security flag</dd>
* <dt>fallback.language</dt><dd>Use language configuration flag</dd>
- * <dt>fallback.country</dt><dd>Use country configuration flag</dd>
- * <dt>fallback.to.root</dt><dd>Continue falling back past media type flag</dd>
+ * <dt>fallback.country</dt><dd>Use country configuration flag</dd>
+ * <dt>fallback.to.root</dt><dd>Continue falling back past media type flag</dd>
*
* </dl>
* </p>
*
* @author <a href="mailto:david@;bluesunrise.com">David Sean Taylor</a>
* @author <a href="mailto:sgala@;hisitech.com">Santiago Gala</a>
- * @author <a href="mailto:morciuch@;apache.org">Mark Orciuch</a>
+ * @author <a href="mailto:morciuch@;apache.org">Mark Orciuch</a>
* @version $Id$
*/
@@ -168,7 +169,7 @@
private final static boolean DEFAULT_CONFIG_SECURITY = false;
private final static boolean DEFAULT_CONFIG_ROLE_FALLBACK = true;
private final static String DEFAULT_CONFIG_NEWUSER_TEMPLATE = null;
- private final static String [] DEFAULT_CONFIG_NEWUSER_MEDIA =
+ private final static String [] DEFAULT_CONFIG_NEWUSER_MEDIA =
{ "html", "wml" };
private final static String DEFAULT_CONFIG_ROLE_MERGE_CONTROL = "TabControl";
private final static String DEFAULT_CONFIG_ROLE_MERGE_CONTROLLER =
"TabController";
@@ -198,12 +199,9 @@
String mediaTypes[] = null;
- // lookup a media type based on mime-type
- private Map mediaMap = null;
-
/**
* This methode creates a wml profile and a html profile
- * for a new user
+ * for a new user
* --------------------------------------------------------------------------
* last modified: 10/31/01
* Andreas Kempf, Siemens ICM S CP PE, Munich
@@ -224,11 +222,11 @@
map = ((JetspeedRunData)data).getCapability();
}
String mediaType = getMediaType(data, map);
-
+
// if template is null then use role-based psml
if (newUserTemplate == null)
return current;
-
+
if (mediaTypes != null)
{
Profile dummy;
@@ -238,32 +236,32 @@
if (mediaTypes[ix].equalsIgnoreCase(mediaType))
current = dummy;
}
- }
+ }
return current;
}
// --------------------------------------------------------------------------
/**
- * This is the early initialization method called by the
+ * This is the early initialization method called by the
* Turbine <code>Service</code> framework
* @param conf The <code>ServletConfig</code>
* @exception throws a <code>InitializationException</code> if the service
* fails to initialize
*/
- public synchronized void init(ServletConfig conf) throws
InitializationException {
+ public synchronized void init(ServletConfig conf) throws InitializationException
+ {
// already initialized
if (getInit()) return;
try
{
- initConfiguration();
- initMediaTypeMap();
+ initConfiguration();
}
catch (Exception e)
{
- Log.error("Failed to load Profiler Service: " + e);
+ Log.error("Profiler: Failed to load Service: " + e);
e.printStackTrace();
}
@@ -273,14 +271,18 @@
}
/**
- * This is the lateinitialization method called by the
+ * This is the lateinitialization method called by the
* Turbine <code>Service</code> framework
*
* @exception throws a <code>InitializationException</code> if the service
* fails to initialize
*/
- public void init() throws InitializationException {
- Log.info( "Late init for JetspeedProfilerService called" );
+ public void init() throws InitializationException
+ {
+ if (Log.getLogger().isInfoEnabled())
+ {
+ Log.info( "Profiler: Late init for JetspeedProfilerService
called" );
+ }
/*
while( !getInit() ) {
//Not yet...
@@ -295,10 +297,10 @@
}
/**
- * This is the shutdown method called by the
+ * This is the shutdown method called by the
* Turbine <code>Service</code> framework
*/
- public void shutdown()
+ public void shutdown()
{
}
@@ -315,7 +317,7 @@
{
JetspeedRunData rundata = (JetspeedRunData)data;
Profile profile = fallbackProfile(rundata, cm);
- if (null == profile && useRoleFallback)
+ if (null == profile && useRoleFallback)
{
Vector profiles = new Vector();
JetspeedUser user = rundata.getJetspeedUser();
@@ -359,15 +361,15 @@
* Merge role profiles to create default profile. Resulting psml will be a set
of
* tabs. If role's psml is a tab control, each tab is placed in the resulting
psml
* as is. Otherwise, a new tab is created and psml is placed there. In this
case,
- * tab name will be derived from role's name. For example, if role name is
"news",
- * the resulting profile name will be "News Home".
- *
+ * tab name will be derived from role's name. For example, if role name is
"news",
+ * the resulting profile name will be "News Home".
+ *
* @param data
* @param profiles Vector of profiles for all roles user is part of
* @return Merged profile
* @exception Exception
*/
- private Profile mergeRoleProfiles(RunData data, Vector profiles)
+ private Profile mergeRoleProfiles(RunData data, Vector profiles)
throws Exception
{
Profile result = null;
@@ -383,7 +385,7 @@
// Proceed with merging all profiles
else if (profiles.size() > 0)
{
- try
+ try
{
// Create an empty portlet container
Portlets portlets = new PsmlPortlets();
@@ -418,10 +420,10 @@
{
Portlets tab = tmpPortlets.getPortlets(i);
portlets.addPortlets(tab);
- }
- }
+ }
+ }
// Otherwise, add the contents of profile as a tab
- else
+ else
{
String title =
org.apache.turbine.util.StringUtils.firstLetterCaps(roleProfile.getRoleName());
tmpPortlets.setTitle(title + " Home");
@@ -430,7 +432,7 @@
if (Log.getLogger().isDebugEnabled())
{
- Log.debug("JetspeedProfilerService: Processing profile for
role " + roleProfile.getRoleName());
+ Log.debug("Profiler: Processing profile for role " +
roleProfile.getRoleName());
}
}
@@ -457,7 +459,7 @@
/**
* Regenerates jspeid for all portlets and entries
- *
+ *
* @param profile Profile to process
* @return Profile with portlet ids regenerated
*/
@@ -494,23 +496,23 @@
JetspeedRunData rundata = (JetspeedRunData)data;
Profile profile = new BaseProfile();
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)
- {
+ if (null != param)
+ {
// GROUP Resource
profile.setGroup( JetspeedSecurity.getGroup(param) );
}
else
{
param = rundata.getParameters().getString( Profiler.PARAM_ROLE );
- if (null != param)
- {
+ if (null != param)
+ {
// ROLE Resource
if (user.hasLoggedIn()) // disallow role access for anonymous
user
{ // this feature could be enhanced when
anon user is added to db
@@ -521,8 +523,8 @@
{
// accessing another user's resource
param = rundata.getParameters().getString( Profiler.PARAM_USER
);
- if (null != param)
- {
+ if (null != param)
+ {
if (param.equals(JetspeedSecurity.getAnonymousUserName()))
{
@@ -538,12 +540,12 @@
}
}
else
- {
+ {
profile.setAnonymous(user.getUserName().equals(JetspeedSecurity.getAnonymousUserName()));
profile.setUser( user );
}
}
- }
+ }
// get resource name
StringBuffer resource = new StringBuffer();
@@ -560,11 +562,11 @@
resource.append( resourceExt );
}
profile.setName( resource.toString() );
-
+
// LANGUAGE
if ((useFallbackLanguage || useFallbackCountry) && (rundata != null))
getLanguageSettings(profile, rundata);
-
+
PSMLDocument doc = fallback( profile );
if (null != doc)
{
@@ -590,7 +592,7 @@
throws ProfileException
{
CapabilityMap cm = null;
-
+
if (rundata instanceof JetspeedRunData)
{
cm = ((JetspeedRunData)rundata).getCapability();
@@ -599,7 +601,7 @@
{
cm = CapabilityMapFactory.getCapabilityMap( rundata );
}
-
+
return getProfile(rundata, cm);
}
@@ -696,30 +698,30 @@
{
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);
@@ -741,7 +743,7 @@
}
catch (CloneNotSupportedException e)
{
- Log.error("Could not clone profile locator object", e);
+ Log.error("Profiler: Could not clone profile locator object", e);
}
return null;
}
@@ -750,7 +752,7 @@
* 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.
@@ -759,7 +761,10 @@
*/
protected PSMLDocument fallback(ProfileLocator locator)
{
- Log.debug( "Profiler fallback called with: " + locator );
+ if (Log.getLogger().isDebugEnabled())
+ {
+ Log.debug( "Profiler: fallback called with: " + locator );
+ }
PSMLDocument doc = PsmlManager.getDocument( locator );
if (null != doc)
@@ -823,24 +828,6 @@
}
-
- /**
- * initialize the mime-type-to-media-type map
- *
- */
- private void initMediaTypeMap()
- {
- mediaMap = new HashMap();
-
- Enumeration entries = Registry.get(Registry.MEDIA_TYPE).getEntries();
- while (entries.hasMoreElements())
- {
- MediaTypeEntry mte = (MediaTypeEntry)entries.nextElement();
- if (null != mte)
- mediaMap.put( mte.getMimeType(), mte );
- }
- }
-
/**
* Lookup the media type from the CapabilitMap.
* First the RunData is checked for an explicit media-type request.
@@ -862,17 +849,14 @@
return paramMediaType;
}
- MimeType mimeType = cm.getPreferredType();
- if (null != mimeType)
+ MediaTypeRegistry mregistry =
(MediaTypeRegistry)Registry.get(Registry.MEDIA_TYPE);
+ Iterator i = mregistry.findForCapability(cm);
+
+ if (null != i)
{
- String key = mimeType.getContentType();
- String agent = cm.getAgent();
- if (agent.indexOf("wml") > -1) // FIXME:
- key = "text/vnd.wap.wml";
- MediaTypeEntry mte = (MediaTypeEntry) mediaMap.get(key);
- if (null != mte)
+ if (i.hasNext())
{
- return mte.getName();
+ return ((MediaTypeEntry)i.next()).getName();
}
}
return "";
@@ -892,7 +876,7 @@
.getResources(ProfilerService.SERVICE_NAME);
resourceDefault = serviceConf.getString( CONFIG_RESOURCE_DEFAULT,
DEFAULT_CONFIG_RESOURCE_DEFAULT );
-
+
resourceExt = serviceConf.getString( CONFIG_RESOURCE_EXT,
DEFAULT_CONFIG_RESOURCE_EXT );
if (-1 == resourceExt.indexOf(PATH_EXTENSION_DELIMITER))
resourceExt = PATH_EXTENSION_DELIMITER + resourceExt;
@@ -904,7 +888,7 @@
newUserTemplate = serviceConf.getString( CONFIG_NEWUSER_TEMPLATE,
DEFAULT_CONFIG_NEWUSER_TEMPLATE );
useFallbackToRoot = serviceConf.getBoolean( CONFIG_FALLBACK_TO_ROOT,
useFallbackToRoot );
-
+
useFallbackLanguage = serviceConf.getBoolean( CONFIG_FALLBACK_LANGUAGE,
useFallbackLanguage );
useRoleMerge = serviceConf.getBoolean( CONFIG_ROLE_MERGE, useRoleMerge );
@@ -1006,12 +990,12 @@
PSMLDocument doc = new BasePSMLDocument(null, portlets);
profile.setDocument(doc);
doc = PsmlManager.createDocument(profile);
- profile.setDocument(doc);
+ profile.setDocument(doc);
return profile;
}
/**
- * Create a new profile.
+ * Create a new profile.
* The profile parameter's document will be cloned.
*
* @param rundata The rundata object for the current request.
@@ -1025,7 +1009,7 @@
/**
* This methode creates a wml profile and a html profile
- * for a new user
+ * for a new user
*/
public Profile createProfile( RunData data, Profile profile, String
contentType, String from )
@@ -1036,7 +1020,7 @@
if ((from == null) || (from.length() < 2))
from = "turbine";
-
+
if ((null == profile.getDocument()) ||
(!profile.getMediaType().equalsIgnoreCase (contentType)))
{
@@ -1063,11 +1047,11 @@
throw new ProfileException(e.toString());
}
}
-
+
try
{
profile.setMediaType(contentType);
-
+
PSMLDocument doc = PsmlManager.createDocument(profile);
Profile newProfile = (Profile)profile.clone();
newProfile.setDocument(doc);
@@ -1105,7 +1089,7 @@
* @param locator The profile locator criteria.
*/
public void removeProfile( ProfileLocator locator )
- {
+ {
PsmlManager.removeDocument(locator);
}
--
To unsubscribe, e-mail: <mailto:jetspeed-dev-unsubscribe@;jakarta.apache.org>
For additional commands, e-mail: <mailto:jetspeed-dev-help@;jakarta.apache.org>