{
String uriPathType = null;
String uriPathElement = null;
try
{
DynamicURI uri = getRoot();
// Set Group/Role/User in path
switch (rootType)
{
case JetspeedLink.DEFAULT:
case JetspeedLink.CURRENT:
break;
case JetspeedLink.GROUP:
uriPathType = Profiler.PARAM_GROUP;
break;
case JetspeedLink.ROLE:
uriPathType = Profiler.PARAM_ROLE;
break;
case JetspeedLink.USER:
uriPathType = Profiler.PARAM_USER;
break;
}
if (rootType != JetspeedLink.CURRENT)
{
// Cleanup URI
uri.removePathInfo(Profiler.PARAM_GROUP);
uri.removePathInfo(Profiler.PARAM_ROLE);
uri.removePathInfo(Profiler.PARAM_USER);
if ((rootType != JetspeedLink.DEFAULT) && (rootValue != null) && (rootValue.trim().length() > 0))
{
uri.addPathInfo(uriPathType, rootValue);
}
}
// Set Page in path
if (pageName != null)
{
uri.removePathInfo(Profiler.PARAM_PAGE);
if (pageName.trim().length() > 0)
{
uri.addPathInfo(Profiler.PARAM_PAGE, pageName);
}
}
// Set Portlet/Pane in path
switch (elementType)
{
case JetspeedLink.CURRENT:
case JetspeedLink.DEFAULT:
break;
case JetspeedLink.PANE_ID:
uriPathElement = JetspeedResources.PATH_PANEID_KEY;
break;
case JetspeedLink.PANE_NAME:
uriPathElement = JetspeedResources.PATH_PANENAME_KEY;
break;
case JetspeedLink.PORTLET_ID:
uriPathElement = JetspeedResources.PATH_PORTLETID_KEY;
break;
case JetspeedLink.PORTLET_NAME:
uriPathElement = JetspeedResources.PATH_PORTLET_KEY;
break;
case JetspeedLink.PORTLET_ID_QUERY:
if (logger.isDebugEnabled())
{
logger.debug("BaseJetspeedLink: elementValue = " + elementValue);
}
uriPathElement = JetspeedResources.PATH_PORTLETID_KEY;
ProfileLocator baseLocator = Profiler.createLocator();
Profile baseProfile = null;
switch (rootType)
{
case JetspeedLink.DEFAULT:
break;
case JetspeedLink.CURRENT:
baseProfile = rundata.getProfile();
break;
case JetspeedLink.GROUP:
baseLocator.setGroupByName(rootValue);
break;
case JetspeedLink.ROLE:
baseLocator.setRoleByName(rootValue);
break;
case JetspeedLink.USER:
try
{
if (logger.isDebugEnabled())
{
logger.debug("BaseJetspeedLink: rootValue user = " + rootValue);
}
baseLocator.setUser(org.apache.jetspeed.services.JetspeedSecurity.getUser(rootValue));
}
catch (Exception se)
{
logger.error("Exception", se);
return null;
}
break;
}
if ((rootType != JetspeedLink.CURRENT) && (rootType != JetspeedLink.DEFAULT))
{
if (mediaType != null && mediaType.length() > 0)
{
baseLocator.setMediaType(mediaType);
}
if (language != null && language.length() > 0)
{
baseLocator.setLanguage(language);
}
if (country != null && country.length() > 0)
{
baseLocator.setCountry(country);
}
if (pageName != null && pageName.length() > 0)
{
baseLocator.setName(pageName);
}
baseProfile = Profiler.getProfile(baseLocator);
}
if (logger.isDebugEnabled())
{
logger.debug("BaseJetspeedLink: baseLocator = " + baseLocator.getPath());
}
if ((baseProfile != null) && (elementValue != null))
{
if (logger.isDebugEnabled())
{
logger.debug("BaseJetspeedLink: baseProfile = " + baseProfile.toString());
}
if (baseProfile.getDocument() != null)
{
if (logger.isDebugEnabled())
{
logger.debug("BaseJetspeedLink: baseProfile.getDocment() = " + baseProfile.getDocument());
}
Entry entry = baseProfile.getDocument().getEntry(elementValue);
if (entry != null)
{
if (logger.isDebugEnabled())
{
logger.debug("BaseJetspeedLink: entry id = " + entry.getId());
}
elementValue = entry.getId();
}
else
{
elementValue = null;
}
}
}
break;
}
if (elementType != JetspeedLink.CURRENT)
{
// Remove Group/Role/User in URI
uri.removePathInfo(JetspeedResources.PATH_PANEID_KEY);
uri.removePathInfo(JetspeedResources.PATH_PANENAME_KEY);
uri.removePathInfo(JetspeedResources.PATH_PORTLETID_KEY);
uri.removePathInfo(JetspeedResources.PATH_PORTLET_KEY);
if ((elementType != JetspeedLink.DEFAULT) && (elementValue != null) && (elementValue.length() > 0))
{
uri.addPathInfo(uriPathElement, elementValue);
}
}
// Set Template in path
if (templateName != null)
{
uri.removePathInfo(JetspeedResources.PATH_TEMPLATE_KEY);
if (templateName.length() > 0)
{
uri.addPathInfo(JetspeedResources.PATH_TEMPLATE_KEY, templateName);
}
}
// Set Action in path
if (actionName != null)
{
uri.removeQueryData(JetspeedResources.PATH_ACTION_KEY);
if (actionName.length() > 0)
{
uri.addQueryData(JetspeedResources.PATH_ACTION_KEY, actionName);
}
}
// Set MediaType in path
if (mediaType != null)
{
uri.removePathInfo(Profiler.PARAM_MEDIA_TYPE);
if (mediaType.length() > 0)
{
uri.addPathInfo(Profiler.PARAM_MEDIA_TYPE, mediaType);
}
}
// Set Language in path
if (language != null)
{
uri.removePathInfo(Profiler.PARAM_LANGUAGE);
if (language.length() > 0)
{
uri.addPathInfo(Profiler.PARAM_LANGUAGE, language);
}
}
// Set Country in path
if (country != null)
{
uri.removePathInfo(Profiler.PARAM_COUNTRY);
if (country.length() > 0)
{
uri.addPathInfo(Profiler.PARAM_COUNTRY, country);
}
}
return uri;
}