Copied: portals/jetspeed-2/portal/trunk/components/jetspeed-portal-site/src/main/java/org/apache/jetspeed/portalsite/view/SearchPathsSiteView.java (from r919260, portals/jetspeed-2/portal/trunk/components/jetspeed-portal-site/src/main/java/org/apache/jetspeed/portalsite/view/SiteView.java) URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/trunk/components/jetspeed-portal-site/src/main/java/org/apache/jetspeed/portalsite/view/SearchPathsSiteView.java?p2=portals/jetspeed-2/portal/trunk/components/jetspeed-portal-site/src/main/java/org/apache/jetspeed/portalsite/view/SearchPathsSiteView.java&p1=portals/jetspeed-2/portal/trunk/components/jetspeed-portal-site/src/main/java/org/apache/jetspeed/portalsite/view/SiteView.java&r1=919260&r2=920191&rev=920191&view=diff ============================================================================== --- portals/jetspeed-2/portal/trunk/components/jetspeed-portal-site/src/main/java/org/apache/jetspeed/portalsite/view/SiteView.java (original) +++ portals/jetspeed-2/portal/trunk/components/jetspeed-portal-site/src/main/java/org/apache/jetspeed/portalsite/view/SearchPathsSiteView.java Mon Mar 8 03:54:17 2010 @@ -17,11 +17,9 @@ package org.apache.jetspeed.portalsite.view; import java.util.ArrayList; -import java.util.HashSet; import java.util.Iterator; import java.util.List; import java.util.Map; -import java.util.Set; import org.apache.jetspeed.om.folder.Folder; import org.apache.jetspeed.om.folder.FolderNotFoundException; @@ -40,78 +38,20 @@ import org.apache.jetspeed.page.document.Node; import org.apache.jetspeed.page.document.NodeException; import org.apache.jetspeed.page.document.NodeNotFoundException; -import org.apache.jetspeed.page.document.NodeSet; import org.apache.jetspeed.page.document.proxy.NodeProxy; -import org.apache.jetspeed.portalsite.menu.StandardBackMenuDefinition; -import org.apache.jetspeed.portalsite.menu.StandardBreadcrumbsMenuDefinition; -import org.apache.jetspeed.portalsite.menu.StandardNavigationsMenuDefinition; -import org.apache.jetspeed.portalsite.menu.StandardPagesMenuDefinition; import org.apache.jetspeed.profiler.ProfileLocator; import org.apache.jetspeed.profiler.ProfileLocatorProperty; /** - * This class defines the logical view of site content. + * This class defines a logical view of site content using + * search paths generated by the profiler. * * @author <a href="mailto:[email protected]">Randy Watler</a> * @version $Id$ */ -public class SiteView +public class SearchPathsSiteView extends AbstractSiteView { /** - * CURRENT_PAGE_PATH - expression used to match the current page - */ - public final static String CURRENT_PAGE_PATH = "~"; - - /** - * ALT_CURRENT_PAGE_PATH - alternate expression used to match the current page - */ - public final static String ALT_CURRENT_PAGE_PATH = "@"; - public final static char ALT_CURRENT_PAGE_PATH_CHAR = '@'; - public final static String ALT_CURRENT_PAGE_PATH_0 = "@0"; - - /** - * STANDARD_*_MENU_NAME - standard menu names - */ - public final static String STANDARD_BACK_MENU_NAME = "back"; - public final static String STANDARD_BREADCRUMBS_MENU_NAME = "breadcrumbs"; - public final static String STANDARD_PAGES_MENU_NAME = "pages"; - public final static String STANDARD_NAVIGATIONS_MENU_NAME = "navigations"; - - /** - * CUSTOM_*_MENU_NAME - custom menu names - */ - public final static String CUSTOM_PAGE_NAVIGATIONS_MENU_NAME = "page-navigations"; - - /** - * STANDARD_MENU_NAMES - set of supported standard menu names - */ - private final static Set STANDARD_MENU_NAMES = new HashSet(3); - static - { - STANDARD_MENU_NAMES.add(STANDARD_BACK_MENU_NAME); - STANDARD_MENU_NAMES.add(STANDARD_BREADCRUMBS_MENU_NAME); - STANDARD_MENU_NAMES.add(STANDARD_PAGES_MENU_NAME); - STANDARD_MENU_NAMES.add(STANDARD_NAVIGATIONS_MENU_NAME); - } - - /** - * STANDARD_MENU_DEFINITION_LOCATORS - list of standard menu definition locators - */ - private final static List STANDARD_MENU_DEFINITION_LOCATORS = new ArrayList(4); - static - { - STANDARD_MENU_DEFINITION_LOCATORS.add(new SiteViewMenuDefinitionLocator(new StandardBackMenuDefinition())); - STANDARD_MENU_DEFINITION_LOCATORS.add(new SiteViewMenuDefinitionLocator(new StandardBreadcrumbsMenuDefinition())); - STANDARD_MENU_DEFINITION_LOCATORS.add(new SiteViewMenuDefinitionLocator(new StandardPagesMenuDefinition())); - STANDARD_MENU_DEFINITION_LOCATORS.add(new SiteViewMenuDefinitionLocator(new StandardNavigationsMenuDefinition())); - } - - /** - * pageManager - PageManager component - */ - private PageManager pageManager; - - /** * searchPaths - validated list of ordered search path objects * where paths have no trailing folder separator */ @@ -128,21 +68,16 @@ private boolean forceReservedVisible; /** - * rootFolderProxy - root folder proxy instance - */ - private Folder rootFolderProxy; - - /** - * SiteView - validating constructor + * SearchPathsSiteView - validating constructor * * @param pageManager PageManager component instance * @param searchPaths list of search paths in string or search path * object form * @param forceReservedVisible force visibility of hidden/reserved folders */ - public SiteView(PageManager pageManager, List searchPaths, boolean forceReservedVisible) + public SearchPathsSiteView(PageManager pageManager, List searchPaths, boolean forceReservedVisible) { - this.pageManager = pageManager; + super(pageManager); if ((searchPaths != null) && !searchPaths.isEmpty()) { // validate search path format and existence @@ -165,7 +100,7 @@ { try { - if (this.pageManager.getFolder(searchPath.toString()) != null) + if (pageManager.getFolder(searchPath.toString()) != null) { this.searchPaths.add(searchPath); @@ -217,13 +152,13 @@ } /** - * SiteView - validating constructor + * SearchPathsSiteView - validating constructor * * @param pageManager PageManager component instance * @param searchPaths array of search paths * @param forceReservedVisible force visibility of hidden/reserved folders */ - public SiteView(PageManager pageManager, String [] searchPaths, boolean forceReservedVisible) + public SearchPathsSiteView(PageManager pageManager, String [] searchPaths, boolean forceReservedVisible) { this(pageManager, makeSearchPathList(searchPaths), forceReservedVisible); } @@ -249,13 +184,13 @@ } /** - * SiteView - validating constructor + * SearchPathsSiteView - validating constructor * * @param pageManager PageManager component instance * @param searchPaths string of comma separated search paths * @param forceReservedVisible force visibility of hidden/reserved folders */ - public SiteView(PageManager pageManager, String searchPaths, boolean forceReservedVisible) + public SearchPathsSiteView(PageManager pageManager, String searchPaths, boolean forceReservedVisible) { this(pageManager, makeSearchPathList(searchPaths), forceReservedVisible); } @@ -272,13 +207,13 @@ } /** - * SiteView - validating constructor + * SearchPathsSiteView - validating constructor * * @param pageManager PageManager component instance * @param locator profile locator search specification * @param forceReservedVisible force visibility of hidden/reserved folders */ - public SiteView(PageManager pageManager, ProfileLocator locator, boolean forceReservedVisible) + public SearchPathsSiteView(PageManager pageManager, ProfileLocator locator, boolean forceReservedVisible) { this(pageManager, makeSearchPathList(locator), forceReservedVisible); } @@ -300,13 +235,13 @@ } /** - * SiteView - validating constructor + * SearchPathsSiteView - validating constructor * * @param pageManager PageManager component instance * @param locators map of named profile locator search specifications * @param forceReservedVisible force visibility of hidden/reserved folders */ - public SiteView(PageManager pageManager, Map locators, boolean forceReservedVisible) + public SearchPathsSiteView(PageManager pageManager, Map locators, boolean forceReservedVisible) { this(pageManager, makeSearchPathList(locators), forceReservedVisible); } @@ -591,26 +526,16 @@ } /** - * SiteView - basic constructor + * SearchPathsSiteView - basic constructor * * @param pageManager PageManager component instance */ - public SiteView(PageManager pageManager) + public SearchPathsSiteView(PageManager pageManager) { this(pageManager, (List)null, false); } /** - * getPageManager - return PageManager component instance - * - * @return PageManager instance - */ - public PageManager getPageManager() - { - return pageManager; - } - - /** * getSearchPaths - return ordered search paths list that * defines this view * @@ -632,653 +557,61 @@ } /** - * getRootFolderProxy - create and return root folder proxy instance + * createRootFolderView - create and return root folder view instance * - * @return root folder proxy + * @return root folder view * @throws FolderNotFoundException if not found * @throws SecurityException if view access not granted */ - public Folder getRootFolderProxy() throws FolderNotFoundException + protected Folder createRootFolderView() throws FolderNotFoundException { - // latently construct and return root folder proxy - if (rootFolderProxy == null) - { - try - { - // the folder and profile locator name of the root - // folder proxy in the view is the locator name of the - // first search path since search paths are valid - SiteViewSearchPath searchPath = (SiteViewSearchPath)searchPaths.get(0); - String path = searchPath.toString(); - String locatorName = searchPath.getLocatorName(); - - // get concrete root folder from page manager - // and construct proxy - Folder rootFolder = pageManager.getFolder(path); - rootFolderProxy = FolderProxy.newInstance(this, locatorName, null, rootFolder, forceReservedVisible); - } - catch (NodeException ne) - { - FolderNotFoundException fnfe = new FolderNotFoundException("Root folder not found"); - fnfe.initCause(ne); - throw fnfe; - } - catch (NodeNotFoundException nnfe) - { - FolderNotFoundException fnfe = new FolderNotFoundException("Root folder not found"); - fnfe.initCause(nnfe); - throw fnfe; - } - } - return rootFolderProxy; - } - - /** - * getNodeProxy - get single folder, page, or link proxy - * at relative or absolute path - * - * @param path single node path - * @param currentNode current folder or page for relative paths or null - * @param onlyViewable node required to be viewable - * @param onlyVisible node required to be visible, (or current) - * @return folder, page, or link node proxy - * @throws NodeNotFoundException if not found - * @throws SecurityException if view access not granted - */ - public Node getNodeProxy(String path, Node currentNode, boolean onlyViewable, boolean onlyVisible) throws NodeNotFoundException - { - // determine current folder and page - String currentPath = path; - Folder currentFolder = null; - Page currentPage = null; - if (currentNode instanceof Page) - { - currentPage = (Page)currentNode; - currentFolder = (Folder)currentPage.getParent(); - } - else if (currentNode instanceof Folder) - { - currentFolder = (Folder)currentNode; - } - - // match current page path - if (currentPath.equals(CURRENT_PAGE_PATH) || currentPath.equals(ALT_CURRENT_PAGE_PATH)) - { - // return current page if specified, (assume viewable) - return currentPage; - } - - // match current node path - if (currentPath.equals(ALT_CURRENT_PAGE_PATH_0)) - { - // return current node, (assume viewable) - List proxies = new ArrayList(1); - proxies.add(currentNode); - return currentNode; - } - - // convert absolute path to a root relative search - // and default current folder - if (currentPath.startsWith(Folder.PATH_SEPARATOR)) - { - currentPath = currentPath.substring(1); - currentFolder = null; - } - if (currentFolder == null) - { - currentFolder = getRootFolderProxy(); - } - - // search for path based on current folder - while ((currentPath.length() > 0) && !currentPath.equals(Folder.PATH_SEPARATOR)) - { - // parse relative sub-folder from path - int separatorIndex = currentPath.indexOf(Folder.PATH_SEPARATOR); - if (separatorIndex != -1) - { - // isolate sub-folder and continue search - // using remaining paths - String subfolder = currentPath.substring(0, separatorIndex); - currentPath = currentPath.substring(separatorIndex+1); - if (subfolder.equals("..")) - { - // adjust current folder if parent exists - if (currentFolder.getParent() != null) - { - currentFolder = (Folder)currentFolder.getParent(); - } - else - { - throw new NodeNotFoundException("Specified path " + path + " not found."); - } - } - else if (!subfolder.equals(".")) - { - // access sub-folder or return null if nonexistent - // or access forbidden - try - { - currentFolder = currentFolder.getFolder(subfolder); - } - catch (NodeException ne) - { - NodeNotFoundException nnfe = new NodeNotFoundException("Specified path " + path + " not found."); - nnfe.initCause(ne); - throw nnfe; - } - catch (NodeNotFoundException nnfe) - { - // check security access to folder not found in site view - FolderProxy.getFolderProxy(currentFolder).checkAccessToFolderNotFound(subfolder); - // folder not found in site view - NodeNotFoundException nnfeWrapper = new NodeNotFoundException("Specified path " + path + " not found."); - nnfeWrapper.initCause(nnfe); - throw nnfeWrapper; - } - } - } - else - { - // access remaining path as page, folder, or link node - // proxy; return null if not found or not viewable/visible - // and visibility is required - try - { - NodeSet children = currentFolder.getAll(); - if (children != null) - { - Node node = children.get(currentPath); - if (((node instanceof Folder) | (node instanceof Page) | (node instanceof Link)) && - (!onlyVisible || !node.isHidden() || (node == currentPage)) && - (!onlyViewable || isProxyViewable(node, onlyVisible))) - { - return node; - } - } - } - catch (NodeException ne) - { - NodeNotFoundException nnfe = new NodeNotFoundException("Specified path " + path + " not found."); - nnfe.initCause(ne); - throw nnfe; - } - // check security access to folder node not found in site view - FolderProxy.getFolderProxy(currentFolder).checkAccessToNodeNotFound(currentPath); - // folder node not found in site view - throw new NodeNotFoundException("Specified path " + path + " not found or viewable/visible."); - } - } - - // path maps to current folder; return if viewable/visible - // or visibility not required - if ((!onlyVisible || !currentFolder.isHidden()) && - (!onlyViewable || isProxyViewable(currentFolder, onlyVisible))) - { - return currentFolder; - } - throw new NodeNotFoundException("Specified path " + path + " not found or viewable/visible."); - } - - /** - * getNodeProxies - get folder, page, or link proxies at - * relative or absolute path using simple path - * wildcards and character classes - * - * @param regexpPath regular expression node path - * @param currentNode current folder or page for relative paths or null - * @param onlyViewable nodes required to be viewable flag - * @param onlyVisible node required to be visible, (or current) - * @return list of folder, page, or link node proxies - */ - public List getNodeProxies(String regexpPath, Node currentNode, boolean onlyViewable, boolean onlyVisible) - { - // determine current folder and page - String currentRegexpPath = regexpPath; - Folder currentFolder = null; - Page currentPage = null; - if (currentNode instanceof Page) - { - currentPage = (Page)currentNode; - currentFolder = (Folder)currentPage.getParent(); - } - else if (currentNode instanceof Folder) - { - currentFolder = (Folder)currentNode; - } - - // match current page path - if (currentRegexpPath.equals(CURRENT_PAGE_PATH) || currentRegexpPath.equals(ALT_CURRENT_PAGE_PATH)) - { - if (currentPage != null) - { - // return current page, (assume viewable) - List proxies = new ArrayList(1); - proxies.add(currentPage); - return proxies; - } - else - { - // current page not specified - return null; - } - } - - // convert pattern with indexed current node path expressions - if (currentNode != null) - { - // match current node path - if (currentRegexpPath.equals(ALT_CURRENT_PAGE_PATH_0)) - { - // return current node, (assume viewable) - List proxies = new ArrayList(1); - proxies.add(currentNode); - return proxies; - } - - // match current node path expression - int currentNodePathIndex = currentRegexpPath.indexOf(ALT_CURRENT_PAGE_PATH_CHAR); - String [] currentNodePathElements = null; - while (currentNodePathIndex != -1) - { - if (currentNodePathIndex+1 < currentRegexpPath.length()) - { - String currentNodePathElement = null; - char currentNodePathElementIndexChar = currentRegexpPath.charAt(currentNodePathIndex+1); - if ((currentNodePathElementIndexChar >= '0') && (currentNodePathElementIndexChar <= '9')) - { - // valid current node path pattern - int currentNodePathElementIndex = (int)(currentNodePathElementIndexChar-'0'); - if (currentNodePathElementIndex > 0) - { - // use indexed current node path element - if (currentNodePathElements == null) - { - // note: leading '/' in path makes index one based - currentNodePathElements = currentNode.getPath().split(Folder.PATH_SEPARATOR); - } - if (currentNodePathElementIndex < currentNodePathElements.length) - { - currentNodePathElement = currentNodePathElements[currentNodePathElementIndex]; - } - } - else - { - // use full current node path trimmed of separators - currentNodePathElement = currentNode.getPath(); - if (currentNodePathElement.endsWith(Folder.PATH_SEPARATOR)) - { - currentNodePathElement = currentNodePathElement.substring(0, currentNodePathElement.length()-1); - } - if (currentNodePathElement.startsWith(Folder.PATH_SEPARATOR)) - { - currentNodePathElement = currentNodePathElement.substring(1); - } - } - } - else if (currentNodePathElementIndexChar == '$') - { - // use last current node path element - if (currentNodePathElements == null) - { - // note: leading '/' in path makes index one based - currentNodePathElements = currentNode.getPath().split(Folder.PATH_SEPARATOR); - } - currentNodePathElement = currentNodePathElements[currentNodePathElements.length-1]; - } - // replace current node path expression - if (currentNodePathElement != null) - { - currentRegexpPath = currentRegexpPath.substring(0, currentNodePathIndex)+currentNodePathElement+currentRegexpPath.substring(currentNodePathIndex+2); - currentNodePathIndex += currentNodePathElement.length()-1; - } - } - currentNodePathIndex = currentRegexpPath.indexOf(ALT_CURRENT_PAGE_PATH_CHAR, currentNodePathIndex+1); - } - } - - // convert absolute path to a root relative search - // and default current folder - if (currentRegexpPath.startsWith(Folder.PATH_SEPARATOR)) - { - currentRegexpPath = currentRegexpPath.substring(1); - currentFolder = null; - } - if (currentFolder == null) + try { - try - { - currentFolder = getRootFolderProxy(); - } - catch (FolderNotFoundException fnfe) - { - return null; - } - catch (SecurityException se) - { - return null; - } - } + // the folder and profile locator name of the root + // folder proxy in the view is the locator name of the + // first search path since search paths are valid + SiteViewSearchPath searchPath = (SiteViewSearchPath)searchPaths.get(0); + String path = searchPath.toString(); + String locatorName = searchPath.getLocatorName(); - // search for path based on current folder - while ((currentRegexpPath.length() > 0) && !currentRegexpPath.equals(Folder.PATH_SEPARATOR)) - { - // parse relative sub-folder from path - int separatorIndex = currentRegexpPath.indexOf(Folder.PATH_SEPARATOR); - if (separatorIndex != -1) - { - // isolate sub-folder and continue search - // using remaining paths - String subfolder = currentRegexpPath.substring(0, separatorIndex); - currentRegexpPath = currentRegexpPath.substring(separatorIndex+1); - if (subfolder.equals("..")) - { - // adjust current folder if parent exists - if (currentFolder.getParent() != null) - { - currentFolder = (Folder)currentFolder.getParent(); - } - else - { - return null; - } - } - else if (!subfolder.equals(".")) - { - try - { - // check for regular expression pattern - String subfolderPattern = pathRegexpPattern(subfolder); - if (subfolderPattern != null) - { - // follow all matching sub-folders - NodeSet subfolders = currentFolder.getFolders(); - if (subfolders != null) - { - subfolders = subfolders.inclusiveSubset(subfolderPattern); - if (subfolders != null) - { - // recursively process sub-folders if more than - // one match, access single sub-folder, or return - // null if nonexistent - if (subfolders.size() > 1) - { - // recursively process matching sub-folders - List proxies = null; - Iterator subfoldersIter = subfolders.iterator(); - while (subfoldersIter.hasNext()) - { - currentFolder = (Folder)subfoldersIter.next(); - List subfolderProxies = getNodeProxies(currentRegexpPath, currentFolder, onlyViewable, onlyVisible); - if ((subfolderProxies != null) && !subfolderProxies.isEmpty()) - { - if (proxies == null) - { - proxies = new ArrayList(); - } - proxies.addAll(subfolderProxies); - } - } - return proxies; - } - else if (subfolders.size() == 1) - { - // access single sub-folder - currentFolder = (Folder)subfolders.iterator().next(); - } - else - { - // no matching sub-folders - return null; - } - } - else - { - // no matching sub-folders - return null; - } - } - else - { - // no sub-folders - return null; - } - } - else - { - // access single sub-folder or return null if - // nonexistent by throwing exception - currentFolder = currentFolder.getFolder(subfolder); - } - } - catch (NodeException ne) - { - // could not access sub-folders - return null; - } - catch (NodeNotFoundException nnfe) - { - // could not access sub-folders - return null; - } - catch (SecurityException se) - { - // could not access sub-folders - return null; - } - } - } - else - { - try - { - // get all children of current folder - NodeSet children = currentFolder.getAll(); - if (children != null) - { - // check for regular expression pattern - String pathPattern = pathRegexpPattern(currentRegexpPath); - if (pathPattern != null) - { - // copy children matching remaining path pattern as - // page, folder, or link proxies if viewable/visible or - // visibility not required - children = children.inclusiveSubset(pathPattern); - if ((children != null) && !children.isEmpty()) - { - List proxies = null; - Iterator childrenIter = children.iterator(); - while (childrenIter.hasNext()) - { - Node child = (Node)childrenIter.next(); - if (((child instanceof Folder) | (child instanceof Page) | (child instanceof Link)) && - (!onlyVisible || !child.isHidden() || (child == currentPage)) && - (!onlyViewable || isProxyViewable(child, onlyVisible))) - { - if (proxies == null) - { - proxies = new ArrayList(children.size()); - } - proxies.add(child); - } - } - return proxies; - } - } - else - { - // access remaining path as page, folder, or link - // node proxy; return null if not found or not - // viewable and visibility is required - Node child = children.get(currentRegexpPath); - if (((child instanceof Folder) | (child instanceof Page) | (child instanceof Link)) && - (!onlyVisible || !child.isHidden() || (child == currentPage)) && - (!onlyViewable || isProxyViewable(child, onlyVisible))) - { - List proxies = new ArrayList(1); - proxies.add(currentFolder); - return proxies; - } - } - } - - } - catch (NodeException ne) - { - } - catch (SecurityException se) - { - } - - // no children match or available - return null; - } + // get concrete root folder from page manager + // and construct proxy + Folder rootFolder = getPageManager().getFolder(path); + return FolderProxy.newInstance(this, locatorName, null, rootFolder, forceReservedVisible); } - - // path maps to current folder; return if viewable/visible - // or visibility not required - if ((!onlyVisible || !currentFolder.isHidden()) && - (!onlyViewable || isProxyViewable(currentFolder, onlyVisible))) + catch (NodeException ne) { - List proxies = new ArrayList(1); - proxies.add(currentFolder); - return proxies; + FolderNotFoundException fnfe = new FolderNotFoundException("Root folder not found"); + fnfe.initCause(ne); + throw fnfe; } - return null; - } - - /** - * pathRegexpPattern - tests for and converts simple path wildcard - * and character class regular expressions to - * perl5/standard java pattern syntax - * - * @param regexp - candidate path regular expression - * @return - converted pattern or null if no regular expression - */ - private static String pathRegexpPattern(String regexp) - { - // convert expression to pattern - StringBuffer pattern = null; - for (int i = 0, limit = regexp.length(); (i < limit); i++) + catch (NodeNotFoundException nnfe) { - char regexpChar = regexp.charAt(i); - switch (regexpChar) - { - case '*': - case '.': - case '?': - case '[': - if (pattern == null) - { - pattern = new StringBuffer(regexp.length()*2); - pattern.append(regexp.substring(0, i)); - } - switch (regexpChar) - { - case '*': - pattern.append(".*"); - break; - case '.': - pattern.append("\\."); - break; - case '?': - pattern.append('.'); - break; - case '[': - pattern.append('['); - break; - } - break; - default: - if (pattern != null) - { - pattern.append(regexpChar); - } - break; - } - } - - // return converted pattern or null if not a regular expression - if (pattern != null) - return pattern.toString(); - return null; + FolderNotFoundException fnfe = new FolderNotFoundException("Root folder not found"); + fnfe.initCause(nnfe); + throw fnfe; + } } /** - * isProxyViewable - tests for node proxy visibility in view + * checkAccessToFolderNotFound - checks security access to child folder + * nodes not found in site view when accessed + * directly * - * @param nodeProxy test node proxy - * @param onlyVisible nodes required to be visible - * @return - viewable flag + * @param folder parent view folder + * @param folderName name of child folder in view to check + * @throws SecurityException if view access to folder not granted */ - private static boolean isProxyViewable(Node nodeProxy, boolean onlyVisible) + protected void checkAccessToNodeNotFound(Folder folder, String folderName) { - // pages and links are always considered viewable - if ((nodeProxy instanceof Page) || (nodeProxy instanceof Link)) - { - return true; - } - // folders must be tested for viewable and visible - // child nodes - if (nodeProxy instanceof Folder) - { - try - { - NodeSet children = ((Folder) nodeProxy).getAll(); - if (children != null) - { - Iterator childrenIter = children.iterator(); - while (childrenIter.hasNext()) - { - Node child = (Node)childrenIter.next(); - if ((!onlyVisible || !child.isHidden()) && isProxyViewable(child, onlyVisible)) - { - return true; - } - } - } - } - catch (NodeException ne) - { - } - catch (SecurityException se) - { - } - return false; - } - // templates, fragments, and dynamic page are not visible - return false; - } - - /** - * getStandardMenuNames - get set of available standard menu names - * - * @return menu names set - */ - public Set getStandardMenuNames() - { - // return constant standard menu names - return STANDARD_MENU_NAMES; - } - - /** - * getStandardMenuDefinitionLocators - get list of available standard - * menu definition locators - * - * @return menu definition locators list - */ - public List getStandardMenuDefinitionLocators() - { - // return constant standard menu definition locators - return STANDARD_MENU_DEFINITION_LOCATORS; + // check security access to folder node not found in site view + FolderProxy.getFolderProxy(folder).checkAccessToNodeNotFound(folderName); } /** - * getMenuDefinitionLocators - get list of view node proxy menu - * definition locators; implemented here - * to hide view proxy manipulation from - * more general portal site implementation + * getMenuDefinitionLocators - get list of view node menu definition locators * - * @param node node proxy + * @param node node view * @return definition locator list */ public List getMenuDefinitionLocators(Node node) @@ -1294,14 +627,10 @@ } /** - * getMenuDefinitionLocator - get named view node proxy menu - * definition locator; implemented here - * to hide view proxy manipulation from - * more general portal site implementation + * getMenuDefinitionLocators - get list of view node menu definition locators * - * @param node node proxy - * @param name menu definition name - * @return menu definition locator + * @param node node view + * @return definition locator list */ public SiteViewMenuDefinitionLocator getMenuDefinitionLocator(Node node, String name) { @@ -1316,16 +645,14 @@ } /** - * getProfileLocatorName - get view node proxy profile locator name; - * implemented here to hide view proxy manipulation - * from more general portal site implementation + * getProfileLocatorName - get profile locator name from view node * - * @param node node proxy - * @return profile locator name + * @param node node view + * @return profile locator name or null */ public String getProfileLocatorName(Node node) { - SiteViewProxy siteViewProxy = SiteViewProxy.getSiteViewProxy(node); + SearchPathsSiteViewProxy siteViewProxy = SearchPathsSiteViewProxy.getSiteViewProxy(node); if (siteViewProxy != null) { return siteViewProxy.getLocatorName(); @@ -1334,11 +661,9 @@ } /** - * getManagedPage - get concrete page instance from page proxy; - * implemented here to hide view proxy manipulation - * from more general portal site implementation + * getManagedPage - get concrete page instance from page view * - * @param page page proxy + * @param page page view * @return managed page */ public Page getManagedPage(Page page) @@ -1350,11 +675,9 @@ } /** - * getManagedLink - get concrete link instance from link proxy; - * implemented here to hide view proxy manipulation - * from more general portal site implementation + * getManagedLink - get concrete link instance from link view * - * @param link link proxy + * @param link link view * @return managed link */ public Link getManagedLink(Link link) @@ -1366,11 +689,9 @@ } /** - * getManagedFolder - get concrete folder instance from folder proxy; - * implemented here to hide view proxy manipulation - * from more general portal site implementation + * getManagedFolder - get concrete folder instance from folder view * - * @param folder folder proxy + * @param folder folder view * @return managed folder */ public Folder getManagedFolder(Folder folder) @@ -1383,11 +704,9 @@ /** * getManagedPageTemplate - get concrete page template instance from - * page template proxy; implemented here to - * hide view proxy manipulation from more - * general portal site implementation + * page template view * - * @param pageTemplate page template proxy + * @param pageTemplate page template view * @return managed page template */ public PageTemplate getManagedPageTemplate(PageTemplate pageTemplate) @@ -1400,11 +719,9 @@ /** * getManagedDynamicPage - get concrete dynamic page instance from - * dynamic page proxy; implemented here to - * hide view proxy manipulation from more - * general portal site implementation + * dynamic page view * - * @param dynamicPage dynamic page proxy + * @param dynamicPage dynamic page view * @return managed dynamic page */ public DynamicPage getManagedDynamicPage(DynamicPage dynamicPage) @@ -1418,11 +735,9 @@ /** * getManagedFragmentDefinition - get concrete fragment definition * instance from fragment definition - * proxy; implemented here to hide - * view proxy manipulation from more - * general portal site implementation + * view * - * @param fragmentDefinition fragment definition proxy + * @param fragmentDefinition fragment definition view * @return managed dynamic page */ public FragmentDefinition getManagedFragmentDefinition(FragmentDefinition fragmentDefinition)
Copied: portals/jetspeed-2/portal/trunk/components/jetspeed-portal-site/src/main/java/org/apache/jetspeed/portalsite/view/SearchPathsSiteViewProxy.java (from r918638, portals/jetspeed-2/portal/trunk/components/jetspeed-portal-site/src/main/java/org/apache/jetspeed/portalsite/view/SiteViewProxy.java) URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/trunk/components/jetspeed-portal-site/src/main/java/org/apache/jetspeed/portalsite/view/SearchPathsSiteViewProxy.java?p2=portals/jetspeed-2/portal/trunk/components/jetspeed-portal-site/src/main/java/org/apache/jetspeed/portalsite/view/SearchPathsSiteViewProxy.java&p1=portals/jetspeed-2/portal/trunk/components/jetspeed-portal-site/src/main/java/org/apache/jetspeed/portalsite/view/SiteViewProxy.java&r1=918638&r2=920191&rev=920191&view=diff ============================================================================== --- portals/jetspeed-2/portal/trunk/components/jetspeed-portal-site/src/main/java/org/apache/jetspeed/portalsite/view/SiteViewProxy.java (original) +++ portals/jetspeed-2/portal/trunk/components/jetspeed-portal-site/src/main/java/org/apache/jetspeed/portalsite/view/SearchPathsSiteViewProxy.java Mon Mar 8 03:54:17 2010 @@ -26,12 +26,12 @@ * @author <a href="mailto:[email protected]">Randy Watler</a> * @version $Id$ */ -public abstract class SiteViewProxy +public abstract class SearchPathsSiteViewProxy { /** * view - site view this proxy is part of */ - private SiteView view; + private SearchPathsSiteView view; /** * locatorName - name of profile locator name associated @@ -48,7 +48,7 @@ * the derived delegate of this proxy in * the site view */ - protected SiteViewProxy(SiteView view, String locatorName) + protected SearchPathsSiteViewProxy(SearchPathsSiteView view, String locatorName) { this.view = view; this.locatorName = locatorName; @@ -59,7 +59,7 @@ * * @return site view */ - public SiteView getView() + public SearchPathsSiteView getView() { return view; } @@ -105,14 +105,14 @@ * @param proxy proxy instance * @return site view invocation handler instance */ - public static SiteViewProxy getSiteViewProxy(Object proxy) + public static SearchPathsSiteViewProxy getSiteViewProxy(Object proxy) { if ((proxy != null) && Proxy.isProxyClass(proxy.getClass())) { Object proxyHandler = Proxy.getInvocationHandler(proxy); - if (proxyHandler instanceof SiteViewProxy) + if (proxyHandler instanceof SearchPathsSiteViewProxy) { - return (SiteViewProxy)proxyHandler; + return (SearchPathsSiteViewProxy)proxyHandler; } } return null; Added: portals/jetspeed-2/portal/trunk/components/jetspeed-portal-site/src/main/java/org/apache/jetspeed/portalsite/view/SiteViewUtils.java URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/trunk/components/jetspeed-portal-site/src/main/java/org/apache/jetspeed/portalsite/view/SiteViewUtils.java?rev=920191&view=auto ============================================================================== --- portals/jetspeed-2/portal/trunk/components/jetspeed-portal-site/src/main/java/org/apache/jetspeed/portalsite/view/SiteViewUtils.java (added) +++ portals/jetspeed-2/portal/trunk/components/jetspeed-portal-site/src/main/java/org/apache/jetspeed/portalsite/view/SiteViewUtils.java Mon Mar 8 03:54:17 2010 @@ -0,0 +1,157 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.jetspeed.portalsite.view; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.Iterator; +import java.util.List; + +import org.apache.jetspeed.om.folder.MenuDefinition; +import org.apache.jetspeed.page.document.Node; + +/** + * Utilities for constructing and accessing site views. + * + * @author <a href="mailto:[email protected]">Randy Watler</a> + * @version $Id$ + */ +public class SiteViewUtils +{ + /** + * mergeMenuDefinitionLocators - utility to merge menu definition locator lists + * to be used by derived implementations to aggregate + * menu definition locators + * + * @param locators list of menu definition locators to merge + * @param node node view + * @param override override menu definition + * @param menuDefinitionLocators merged menu definition locators + * @return merged menu definition locators + */ + public static List mergeMenuDefinitionLocators(List definitions, Node node, boolean override, List menuDefinitionLocators) + { + // merge definitions into aggregated menu definition + // locators if defined + if (definitions != null) + { + Iterator definitionsIter = definitions.iterator(); + while (definitionsIter.hasNext()) + { + // aggregate menu definition by valid name + MenuDefinition definition = (MenuDefinition)definitionsIter.next(); + String definitionName = definition.getName(); + if (definitionName != null) + { + // add unique menu definition to end of + // ordered menu definition locators list + if (!menuDefinitionLocatorsContains(menuDefinitionLocators, definitionName)) + { + if (menuDefinitionLocators == null) + { + menuDefinitionLocators = Collections.synchronizedList(new ArrayList(definitions.size() * 2)); + } + menuDefinitionLocators.add(new SiteViewMenuDefinitionLocator(definition, node, override)); + } + else if (override) + { + throw new RuntimeException("Override menu definitions must be merged/added before others!"); + } + } + } + } + return menuDefinitionLocators; + } + + /** + * mergeMenuDefinitionLocators - utility to merge menu definition locator lists + * to be used by derived implementations to aggregate + * menu definition locators + * + * @param locators list of menu definition locators to merge + * @param menuDefinitionLocators merged menu definition locators + * @return merged menu definition locators + */ + public static List mergeMenuDefinitionLocators(List locators, List menuDefinitionLocators) + { + // merge locators into aggregated menu definition + // locators if defined + if (locators != null) + { + Iterator locatorsIter = locators.iterator(); + while (locatorsIter.hasNext()) + { + // aggregate menu definition by valid name + SiteViewMenuDefinitionLocator locator = (SiteViewMenuDefinitionLocator)locatorsIter.next(); + String definitionName = locator.getName(); + + // add unique menu definition to end of + // ordered menu definition locators list + if (!menuDefinitionLocatorsContains(menuDefinitionLocators, definitionName)) + { + if (menuDefinitionLocators == null) + { + menuDefinitionLocators = Collections.synchronizedList(new ArrayList(locators.size() * 2)); + } + menuDefinitionLocators.add(locator); + } + } + } + return menuDefinitionLocators; + } + + /** + * menuDefinitionLocatorsContains - contains test for menu definition locators by name + * + * @param menuDefinitionLocators merged menu definition locators + * @param name menu definition name + * @return contains name result + */ + public static boolean menuDefinitionLocatorsContains(List menuDefinitionLocators, String name) + { + // test for matching name in menu definition locators + return (findMenuDefinitionLocator(menuDefinitionLocators, name) != null); + } + + /** + * findMenuDefinitionLocator - find menu definition locator by name + * + * @param menuDefinitionLocators merged menu definition locators + * @param name menu definition name + * @return menu definition locator + */ + public static SiteViewMenuDefinitionLocator findMenuDefinitionLocator(List menuDefinitionLocators, String name) + { + // find matching menu definition locator by name + if ((menuDefinitionLocators != null) && (name != null)) + { + synchronized (menuDefinitionLocators) + { + Iterator locatorsIter = menuDefinitionLocators.iterator(); + while (locatorsIter.hasNext()) + { + SiteViewMenuDefinitionLocator locator = (SiteViewMenuDefinitionLocator)locatorsIter.next(); + if (name.equals(locator.getName())) + { + return locator; + } + } + } + } + return null; + } +} --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
