Author: rwatler Date: Sat Mar 20 18:37:14 2010 New Revision: 925651 URL: http://svn.apache.org/viewvc?rev=925651&view=rev Log: Add user and base folder path access methods to PortalAdministration component API
Modified: portals/jetspeed-2/portal/branches/JETSPEED-2.1.4/components/portal/src/java/org/apache/jetspeed/administration/PortalAdministrationImpl.java portals/jetspeed-2/portal/branches/JETSPEED-2.1.4/jetspeed-api/src/java/org/apache/jetspeed/administration/PortalAdministration.java Modified: portals/jetspeed-2/portal/branches/JETSPEED-2.1.4/components/portal/src/java/org/apache/jetspeed/administration/PortalAdministrationImpl.java URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/branches/JETSPEED-2.1.4/components/portal/src/java/org/apache/jetspeed/administration/PortalAdministrationImpl.java?rev=925651&r1=925650&r2=925651&view=diff ============================================================================== --- portals/jetspeed-2/portal/branches/JETSPEED-2.1.4/components/portal/src/java/org/apache/jetspeed/administration/PortalAdministrationImpl.java (original) +++ portals/jetspeed-2/portal/branches/JETSPEED-2.1.4/components/portal/src/java/org/apache/jetspeed/administration/PortalAdministrationImpl.java Sat Mar 20 18:37:14 2010 @@ -292,31 +292,7 @@ public class PortalAdministrationImpl im String userFolderPath = null; if ((subsite == null) && (serverName != null)) { - // setup profiler and portal site to determine template - // folders paths generate mock request for new user to profile - RequestContext request = new MockRequestContext("/"); - request.setSubject(user.getSubject()); - request.setLocale((locale != null) ? locale : Locale.getDefault()); - MockHttpServletRequest servletRequest = new MockHttpServletRequest(); - servletRequest.setServerName(serverName); - request.setRequest(servletRequest); - - // get profile locators map for new user request - Principal principal = SecurityHelper.getBestPrincipal(user.getSubject(), UserPrincipal.class); - Map locators = profiler.getProfileLocators(request, principal); - if (locators.size() == 0) - { - locators = profiler.getDefaultProfileLocators(request); - } - if (locators.size() == 0) - { - locators.put(ProfileLocator.PAGE_LOCATOR, profiler.getProfile(request, ProfileLocator.PAGE_LOCATOR)); - } - - // get user folder path from profiler site component - // using the profile locators for new user request - PortalSiteSessionContext sessionContext = portalSite.newSessionContext(); - PortalSiteRequestContext requestContext = sessionContext.newRequestContext(locators, userName); + PortalSiteRequestContext requestContext = getMockPortalSiteRequestContext(userName, user, locale, serverName); userFolderPath = requestContext.getUserFolderPath(); } else if (subsite != null) @@ -563,9 +539,86 @@ public class PortalAdministrationImpl im forgottenPasswordData.remove(guid); } } + + /* (non-Javadoc) + * @see org.apache.jetspeed.administration.PortalAdministration#getUserFolderPath(java.lang.String, java.util.Locale, java.lang.String) + */ + public String getUserFolderPath(String userName, Locale locale, String serverName) + { + try + { + User user = userManager.getUser(userName); + PortalSiteRequestContext requestContext = getMockPortalSiteRequestContext(userName, user, locale, serverName); + return requestContext.getUserFolderPath(); + } + catch (Exception e) + { + log.error("Unexpected exception getting user folder path for "+userName+": "+e, e); + return null; + } + } + + /* (non-Javadoc) + * @see org.apache.jetspeed.administration.PortalAdministration#getBaseFolderPath(java.lang.String, java.util.Locale, java.lang.String) + */ + public String getBaseFolderPath(String userName, Locale locale, String serverName) + { + try + { + User user = userManager.getUser(userName); + PortalSiteRequestContext requestContext = getMockPortalSiteRequestContext(userName, user, locale, serverName); + return requestContext.getBaseFolderPath(); + } + catch (Exception e) + { + log.error("Unexpected exception getting base folder path for "+userName+": "+e, e); + return null; + } + } - - - - + /** + * Returns temporary mock portal site request context for + * specified user for use in constructing user or base PSML + * folder paths or accessing other profiled site data. + * + * @param userName portal user name + * @param user portal user + * @param locale optional locale, (defaults to system locale, for language + * profiling rules) + * @param serverName server name, (required for subsite profiling rules) + * @return portal site request context + * @throws Exception + */ + private PortalSiteRequestContext getMockPortalSiteRequestContext(String userName, User user, Locale locale, String serverName) throws Exception + { + // setup profiler and portal site to determine template + // folders paths generate mock request for new user to profile + RequestContext request = new MockRequestContext("/"); + request.setSubject(user.getSubject()); + request.setLocale((locale != null) ? locale : Locale.getDefault()); + MockHttpServletRequest servletRequest = new MockHttpServletRequest(); + if (serverName != null) + { + servletRequest.setServerName(serverName); + } + request.setRequest(servletRequest); + + // get profile locators map for new user request, (taken from + // ProfilerValveImpl) + Principal principal = SecurityHelper.getBestPrincipal(user.getSubject(), UserPrincipal.class); + Map locators = profiler.getProfileLocators(request, principal); + if (locators.size() == 0) + { + locators = profiler.getDefaultProfileLocators(request); + } + if (locators.size() == 0) + { + locators.put(ProfileLocator.PAGE_LOCATOR, profiler.getProfile(request, ProfileLocator.PAGE_LOCATOR)); + } + + // get new portal site request context from portal site + // component using the profile locators for new user request + PortalSiteSessionContext sessionContext = portalSite.newSessionContext(); + return sessionContext.newRequestContext(locators, userName); + } } Modified: portals/jetspeed-2/portal/branches/JETSPEED-2.1.4/jetspeed-api/src/java/org/apache/jetspeed/administration/PortalAdministration.java URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/branches/JETSPEED-2.1.4/jetspeed-api/src/java/org/apache/jetspeed/administration/PortalAdministration.java?rev=925651&r1=925650&r2=925651&view=diff ============================================================================== --- portals/jetspeed-2/portal/branches/JETSPEED-2.1.4/jetspeed-api/src/java/org/apache/jetspeed/administration/PortalAdministration.java (original) +++ portals/jetspeed-2/portal/branches/JETSPEED-2.1.4/jetspeed-api/src/java/org/apache/jetspeed/administration/PortalAdministration.java Sat Mar 20 18:37:14 2010 @@ -181,5 +181,28 @@ public interface PortalAdministration */ public void removeNewLoginInfo(String guid); + /** + * Returns PSML user folder path for specified user by + * running full profiler and portal site rules. + * + * @param userName existing portal user name + * @param locale optional locale, (defaults to system locale, for language + * profiling rules) + * @param serverName server name, (required for subsite profiling rules) + * @return PSML user folder path + */ + public String getUserFolderPath(String userName, Locale locale, String serverName); + + /** + * Returns PSML base folder path for specified user by + * running full profiler and portal site rules. + * + * @param userName existing portal user name + * @param locale optional locale, (defaults to system locale, for language + * profiling rules) + * @param serverName server name, (required for subsite profiling rules) + * @return PSML base folder path + */ + public String getBaseFolderPath(String userName, Locale locale, String serverName); } --------------------------------------------------------------------- To unsubscribe, e-mail: jetspeed-dev-unsubscr...@portals.apache.org For additional commands, e-mail: jetspeed-dev-h...@portals.apache.org