portals-jetspeed-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rwat...@apache.org
Subject svn commit: r209305 [2/10] - in /portals/jetspeed-2/branches/MENUS_BRANCH: components/locator/src/java/org/apache/jetspeed/profiler/impl/ components/page-manager/ components/page-manager/src/java/META-INF/ components/page-manager/src/java/org/apache/je...
Date Tue, 05 Jul 2005 18:58:14 GMT
Modified: portals/jetspeed-2/branches/MENUS_BRANCH/components/page-manager/src/java/org/apache/jetspeed/om/page/psml/PageImpl.java
URL: http://svn.apache.org/viewcvs/portals/jetspeed-2/branches/MENUS_BRANCH/components/page-manager/src/java/org/apache/jetspeed/om/page/psml/PageImpl.java?rev=209305&r1=209304&r2=209305&view=diff
==============================================================================
--- portals/jetspeed-2/branches/MENUS_BRANCH/components/page-manager/src/java/org/apache/jetspeed/om/page/psml/PageImpl.java (original)
+++ portals/jetspeed-2/branches/MENUS_BRANCH/components/page-manager/src/java/org/apache/jetspeed/om/page/psml/PageImpl.java Tue Jul  5 11:58:05 2005
@@ -17,8 +17,10 @@
 package org.apache.jetspeed.om.page.psml;
 
 import java.util.Iterator;
+import java.util.List;
 import java.util.Stack;
 
+import org.apache.jetspeed.om.folder.impl.MenuDefinitionImpl;
 import org.apache.jetspeed.om.page.Fragment;
 import org.apache.jetspeed.om.page.Page;
 import org.apache.jetspeed.page.document.AbstractNode;
@@ -34,6 +36,11 @@
 
     private int hashCode;
 
+    /**
+     * menuDefinitions - menu definitions for page
+     */
+    private List menuDefinitions;
+    
     public PageImpl()
     {
         // empty constructor
@@ -185,21 +192,73 @@
     {       
         return DOCUMENT_TYPE;
     }
+
     /**
-     * <p>
-     * getUrl
-     * </p>
-     * Same as invoking <code>AbstractBaseElement.getId()</code> unless url explicitly set.
+     * getMenuDefinitions - get list of menu definitions
      *
-     * @see org.apache.jetspeed.om.page.Document#getUrl()
-     * @return
+     * @return definition list
+     */
+    public List getMenuDefinitions()
+    {
+        return menuDefinitions;
+    }
+
+    /**
+     * setMenuDefinitions - set list of menu definitions
+     *
+     * @param definitions definition list
      */
-    public String getUrl()
+    public void setMenuDefinitions(List definitions)
     {
-        if (isUrlSet())
-            return super.getUrl();
-        return getId();
+        menuDefinitions = definitions;
     }
 
+    /**
+     * unmarshalled - notification that this instance has been
+     *                loaded from the persistent store
+     */
+    public void unmarshalled()
+    {
+        // notify super class implementation
+        super.unmarshalled();
+
+        // propagate unmarshalled notification
+        // to all menu definitions
+        if (menuDefinitions != null)
+        {
+            Iterator menuIter = menuDefinitions.iterator();
+            while (menuIter.hasNext())
+            {
+                ((MenuDefinitionImpl)menuIter.next()).unmarshalled();
+            }
+        }
+
+        // default title of pages to name
+        if (getTitle() == null)
+        {
+            setTitle(getTitleName());
+        }
+    }
+
+    /**
+     * marshalling - notification that this instance is to
+     *               be saved to the persistent store
+     */
+    public void marshalling()
+    {
+        // propagate marshalling notification
+        // to all menu definitions
+        if (menuDefinitions != null)
+        {
+            Iterator menuIter = menuDefinitions.iterator();
+            while (menuIter.hasNext())
+            {
+                ((MenuDefinitionImpl)menuIter.next()).marshalling();
+            }
+        }
+
+        // notify super class implementation
+        super.marshalling();
+    }
 }
 

Modified: portals/jetspeed-2/branches/MENUS_BRANCH/components/page-manager/src/java/org/apache/jetspeed/om/page/psml/PageMetadataImpl.java
URL: http://svn.apache.org/viewcvs/portals/jetspeed-2/branches/MENUS_BRANCH/components/page-manager/src/java/org/apache/jetspeed/om/page/psml/PageMetadataImpl.java?rev=209305&r1=209304&r2=209305&view=diff
==============================================================================
--- portals/jetspeed-2/branches/MENUS_BRANCH/components/page-manager/src/java/org/apache/jetspeed/om/page/psml/PageMetadataImpl.java (original)
+++ portals/jetspeed-2/branches/MENUS_BRANCH/components/page-manager/src/java/org/apache/jetspeed/om/page/psml/PageMetadataImpl.java Tue Jul  5 11:58:05 2005
@@ -15,8 +15,15 @@
  */
 package org.apache.jetspeed.om.page.psml;
 
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Locale;
+import java.util.Map;
+
 import org.apache.jetspeed.om.common.LocalizedField;
 import org.apache.jetspeed.om.impl.GenericMetadataImpl;
+import org.apache.jetspeed.util.ArgUtil;
 
 /**
  * @author <a href="mailto:jford@apache.org">Jeremy Ford</a>
@@ -24,6 +31,10 @@
  */
 public class PageMetadataImpl extends GenericMetadataImpl
 {
+    /**
+     * localizedText - cached text metadata
+     */
+    private Map localizedText;
 
     /* (non-Javadoc)
      * @see org.apache.jetspeed.om.common.GenericMetadata#createLocalizedField()
@@ -33,4 +44,56 @@
         return new PageLocalizedFieldImpl();
     }
 
+    /**
+     * getText - get localized text from metadata
+     * 
+     * @param name text name
+     * @param locale preferred locale
+     * @return localized text or null if not available
+     */
+    public String getText(String name, Locale locale)
+    {
+        // validate parameters
+        ArgUtil.assertNotNull(String.class, name, this, "getText(String, Locale)");
+        ArgUtil.assertNotNull(Locale.class, locale, this, "getText(String, Locale)");
+
+        // populate cache for named text by locale
+        Map namedLocalizedText = (Map)((localizedText != null) ? localizedText.get(name) : null);
+        if ((namedLocalizedText == null) && (getFields() != null))
+        {
+            Collection fields = getFields(name);
+            if (fields != null)
+            {
+                if (localizedText == null)
+                {
+                    localizedText = new HashMap(getFields().size());
+                }
+                namedLocalizedText = new HashMap(getFields().size());
+                localizedText.put(name, namedLocalizedText);
+                Iterator fieldsItr = fields.iterator();
+                while (fieldsItr.hasNext())
+                {
+                    LocalizedField field = (LocalizedField)fieldsItr.next();
+                    namedLocalizedText.put(field.getLocale(), field);
+                }
+            }
+        }
+
+        // retrieve cached named text by locale if found
+        if (namedLocalizedText != null)
+        {
+            // test locale
+            if (namedLocalizedText.containsKey(locale) )
+            {
+                return ((LocalizedField)namedLocalizedText.get(locale)).getValue().trim();
+            }
+            // test language only locale
+            Locale languageOnly = new Locale(locale.getLanguage());
+            if (namedLocalizedText.containsKey(languageOnly))
+            {
+                return ((LocalizedField)namedLocalizedText.get(languageOnly)).getValue().trim();
+            }
+        }
+        return null;
+    }
 }

Modified: portals/jetspeed-2/branches/MENUS_BRANCH/components/page-manager/src/java/org/apache/jetspeed/page/document/AbstractNode.java
URL: http://svn.apache.org/viewcvs/portals/jetspeed-2/branches/MENUS_BRANCH/components/page-manager/src/java/org/apache/jetspeed/page/document/AbstractNode.java?rev=209305&r1=209304&r2=209305&view=diff
==============================================================================
--- portals/jetspeed-2/branches/MENUS_BRANCH/components/page-manager/src/java/org/apache/jetspeed/page/document/AbstractNode.java (original)
+++ portals/jetspeed-2/branches/MENUS_BRANCH/components/page-manager/src/java/org/apache/jetspeed/page/document/AbstractNode.java Tue Jul  5 11:58:05 2005
@@ -15,13 +15,9 @@
  */
 package org.apache.jetspeed.page.document;
 
-import java.util.ArrayList;
 import java.util.Collection;
-import java.util.HashMap;
-import java.util.Iterator;
 import java.util.List;
 import java.util.Locale;
-import java.util.Map;
 
 import org.apache.jetspeed.om.common.GenericMetadata;
 import org.apache.jetspeed.om.common.LocalizedField;
@@ -31,7 +27,6 @@
 import org.apache.jetspeed.om.page.psml.PageMetadataImpl;
 import org.apache.jetspeed.om.page.psml.SecurityConstraintsImpl;
 import org.apache.jetspeed.page.document.Node;
-import org.apache.jetspeed.util.ArgUtil;
 
 
 /**
@@ -48,9 +43,7 @@
  */
 public abstract class AbstractNode extends AbstractBaseElement implements Node
 {
-    private Collection metadataFields = null;
-    private Map localizedTitles;
-    private Map localizedShortTitles;
+    private PageMetadataImpl metadata;
     private Node parent;
     private String path;
     private String url;
@@ -61,41 +54,64 @@
     {
     }
 
+    /**
+     * getMetadata - get/construct metadata
+     *
+     * @return metadata
+     */
     public GenericMetadata getMetadata()
     {
-        if (metadataFields == null)
-        {
-            metadataFields = new ArrayList();
-        }
-
-        GenericMetadata metadata = new PageMetadataImpl();
-        metadata.setFields(metadataFields);
-        return metadata;
+        return getPageMetadata();
     }
 
-    public void setMetadata( GenericMetadata metadata )
+    /**
+     * setMetadata - set metadata fields
+     *
+     * @param metadata metadata
+     */
+    public void setMetadata(GenericMetadata metadata)
     {
-        this.metadataFields = metadata.getFields();
+        getPageMetadata().setFields(metadata.getFields());
     }
 
     /**
-     * This should only be used during castor marshalling
-     * 
-     * @see org.apache.jetspeed.om.page.Page#getMetadataFields()
+     * getMetadataFields - get metadata fields collection for
+     *                     marshalling/unmarshalling
+     *
+     * @return metadata fields collection
      */
     public Collection getMetadataFields()
     {
-        return metadataFields;
+        // return metadata fields collection that
+        // may in fact be side effected on unmarshall
+        return getPageMetadata().getFields();
     }
 
     /**
-     * This should only be used during castor unmarshalling
-     * 
-     * @see org.apache.jetspeed.om.page.Page#setMetadataFields(java.util.Collection)
+     * setMetadataFields - set metadata fields collection
+     *
+     * @param metadataFields metadata fields collection
      */
-    public void setMetadataFields( Collection metadataFields )
+    public void setMetadataFields(Collection metadataFields)
     {
-        this.metadataFields = metadataFields;
+        // set metadata fields collection that
+        // may in fact be side effected after
+        // invocation on unmarshall
+        getPageMetadata().setFields(metadataFields);
+    }
+
+    /**
+     * getPageMetadata - get/construct page metadata instance
+     *
+     * @return metadata instance
+     */
+    private PageMetadataImpl getPageMetadata()
+    {
+        if (metadata == null)
+        {
+            metadata = new PageMetadataImpl();
+        }
+        return metadata;
     }
 
     /**
@@ -107,39 +123,15 @@
      * @param locale
      * @return
      */
-    public String getTitle( Locale locale )
+    public String getTitle(Locale locale)
     {
-        ArgUtil.assertNotNull(Locale.class, locale, this, "getTile(Locale)");
-        if (localizedTitles == null && metadataFields != null)
+        // get title from metadata or use default title
+        String title = getPageMetadata().getText("title", locale);
+        if (title == null)
         {
-            this.localizedTitles = new HashMap(metadataFields.size());
-            Iterator fieldsItr = metadataFields.iterator();
-            while (fieldsItr.hasNext())
-            {
-                LocalizedField field = (LocalizedField) fieldsItr.next();
-                if (field.getName().equals("title"))
-                {
-                    localizedTitles.put(field.getLocale(), field);
-                }
-            }
-        }
-        
-        Locale languageOnly = new Locale(locale.getLanguage());
-        if (localizedTitles != null
-            && (localizedTitles.containsKey(locale) 
-                || localizedTitles.containsKey(languageOnly)))
-        {
-            if(localizedTitles.containsKey(locale) )
-            {
-                return ((LocalizedField) localizedTitles.get(locale)).getValue().trim();
-            }
-            else if(localizedTitles.containsKey(languageOnly))
-            {
-                return ((LocalizedField) localizedTitles.get(languageOnly)).getValue().trim();
-            }
+            title = getTitle();
         }
-
-        return getTitle();
+        return title;
     }
 
     /**
@@ -153,44 +145,22 @@
      */
     public String getShortTitle( Locale locale )
     {
-        ArgUtil.assertNotNull(Locale.class, locale, this, "getShortTitle(Locale)");
-        if (localizedShortTitles == null && metadataFields != null)
+        // get short title from metadata or use title from metadata,
+        // default short title, or default title
+        String shortTitle = getPageMetadata().getText("short-title", locale);
+        if (shortTitle == null)
         {
-            this.localizedShortTitles = new HashMap(metadataFields.size());
-            Iterator fieldsItr = metadataFields.iterator();
-            while (fieldsItr.hasNext())
+            shortTitle = getPageMetadata().getText("title", locale);
+            if (shortTitle == null)
             {
-                LocalizedField field = (LocalizedField) fieldsItr.next();
-                if (field.getName().equals("short-title"))
+                shortTitle = getShortTitle();
+                if (shortTitle == null)
                 {
-                    localizedShortTitles.put(field.getLocale(), field);
+                    shortTitle = getTitle();
                 }
             }
         }
-
-        Locale languageOnly = new Locale(locale.getLanguage());
-        if (localizedShortTitles != null
-            && (localizedShortTitles.containsKey(locale) 
-                || localizedShortTitles.containsKey(languageOnly)))
-        {
-            if(localizedShortTitles.containsKey(locale) )
-            {
-                return ((LocalizedField) localizedShortTitles.get(locale)).getValue().trim();
-            }
-            else if(localizedShortTitles.containsKey(languageOnly))
-            {
-                return ((LocalizedField) localizedShortTitles.get(languageOnly)).getValue().trim();
-            }
-        }
-
-        // default to localized title, default short title, or default
-        // title if not specified
-        String title = getTitle(locale);
-        if (title == getTitle())
-        {
-            title = getShortTitle();
-        }
-        return title;
+        return shortTitle;
     }
 
     /**
@@ -223,7 +193,9 @@
      */
     public Node getParent()
     {
-        // by default disable access checks to facilitate navigation
+        // by default disable access checks since it is assumed
+        // that by accessing this node, access to parent must
+        // also be granted
         return getParent(false);
     }
 
@@ -250,25 +222,56 @@
      */
     public String getName()
     {
-        String path = getPath();
-        String parentName = "";
-        if(getParent(false) != null)
+        // simply strip path to determine name
+        String name = getPath();
+        if ((name != null) && !name.equals(PATH_SEPARATOR))
         {
-            parentName = getParent(false).getPath();
-            if (! parentName.endsWith(PATH_SEPARATOR))
+            if (name.endsWith(PATH_SEPARATOR))
             {
-                parentName += PATH_SEPARATOR;
+                name = name.substring(0, name.length()-1);
             }
+            name = name.substring(name.lastIndexOf(PATH_SEPARATOR)+1);
         }
-        
-        if (path.startsWith(parentName))
-        {
-            return path.substring(parentName.length());
-        }
-        else
+        return name;
+    }
+
+    /**
+     * getTitleName - get name for use as default titles
+     *
+     * @return title name
+     */
+    public String getTitleName()
+    {
+        String titleName = getName();
+        if (titleName != null)
         {
-            return path;
+            // transform file system name to title
+            if (titleName.endsWith(getType()))
+            {
+                titleName = titleName.substring(0, titleName.length()-getType().length());
+            }
+            else if (titleName.equals(PATH_SEPARATOR))
+            {
+                titleName = "top";
+            }
+            titleName = titleName.replace('_', ' ');
+            titleName = titleName.replace('-', ' ');
+            int wordIndex = -1;
+            do
+            {
+                if (!Character.isTitleCase(titleName.charAt(wordIndex+1)))
+                {
+                    StringBuffer makeTitle = new StringBuffer();
+                    makeTitle.append(titleName.substring(0, wordIndex+1));
+                    makeTitle.append(Character.toTitleCase(titleName.charAt(wordIndex+1)));
+                    makeTitle.append(titleName.substring(wordIndex+2));
+                    titleName = makeTitle.toString();
+                }
+                wordIndex = titleName.indexOf(' ', wordIndex+1);
+            }
+            while (wordIndex != -1);
         }
+        return titleName;
     }
 
     /**
@@ -280,12 +283,17 @@
     }
     
     /**
+     * <p>
+     * setPath
+     * </p>
+     *
      * @param path The path to set.
      */
     public void setPath( String path )
     {
         this.path = path;
     }
+
     /**
      * <p>
      * getUrl
@@ -297,24 +305,25 @@
      */
     public String getUrl()
     {
-        if (isUrlSet())
+        if (url != null)
+        {
             return url;
+        }
         return getPath();
     }
+
     /**
+     * <p>
+     * setUrl
+     * </p>
+     *
      * @param url The url to set.
      */
-    public void setUrl(String url)
+    public void setUrl( String url )
     {
         this.url = url;
     }
-    /**
-     * @return Flag indicating whether url is set.
-     */
-    public boolean isUrlSet()
-    {
-        return (url != null);
-    }
+
     /**
      * <p>
      * isHidden
@@ -365,7 +374,6 @@
      */
     public void checkConstraints(List actions, List userPrincipals, List rolePrincipals, List groupPrincipals, boolean checkNodeOnly, boolean checkParentsOnly) throws SecurityException
     {
-String debug=""; Iterator i = actions.iterator(); while(i.hasNext())debug+=(String)i.next()+" ";
         // check constraints in node hierarchy
         if (checkNodeOnly)
         {
@@ -453,5 +461,24 @@
     public String getPhysicalPermissionPath()
     {
         return path;
+    }
+
+    /**
+     * unmarshalled - notification that this instance has been
+     *                loaded from the persistent store
+     */
+    public void unmarshalled()
+    {
+        // notify super class implementation
+        super.unmarshalled();
+
+        // force metadata update after unmarshalled since
+        // metadata collection can be side effected by
+        // unmarshalling colection accessors
+        Collection metadataFields = getMetadataFields();
+        if (metadataFields != null)
+        {
+            setMetadataFields(metadataFields);
+        }
     }
 }

Modified: portals/jetspeed-2/branches/MENUS_BRANCH/components/page-manager/src/java/org/apache/jetspeed/page/document/CastorFileSystemDocumentHandler.java
URL: http://svn.apache.org/viewcvs/portals/jetspeed-2/branches/MENUS_BRANCH/components/page-manager/src/java/org/apache/jetspeed/page/document/CastorFileSystemDocumentHandler.java?rev=209305&r1=209304&r2=209305&view=diff
==============================================================================
--- portals/jetspeed-2/branches/MENUS_BRANCH/components/page-manager/src/java/org/apache/jetspeed/page/document/CastorFileSystemDocumentHandler.java (original)
+++ portals/jetspeed-2/branches/MENUS_BRANCH/components/page-manager/src/java/org/apache/jetspeed/page/document/CastorFileSystemDocumentHandler.java Tue Jul  5 11:58:05 2005
@@ -17,13 +17,14 @@
 
 import java.io.File;
 import java.io.FileNotFoundException;
+import java.io.FileReader;
 import java.io.FileWriter;
 import java.io.IOException;
 import java.io.InputStream;
 
-import javax.xml.parsers.DocumentBuilder;
-import javax.xml.parsers.DocumentBuilderFactory;
 import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.parsers.SAXParser;
+import javax.xml.parsers.SAXParserFactory;
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
@@ -39,12 +40,18 @@
 import org.apache.xml.serialize.XMLSerializer;
 import org.exolab.castor.mapping.Mapping;
 import org.exolab.castor.mapping.MappingException;
+import org.exolab.castor.xml.EventProducer;
 import org.exolab.castor.xml.MarshalException;
 import org.exolab.castor.xml.Marshaller;
 import org.exolab.castor.xml.Unmarshaller;
 import org.exolab.castor.xml.ValidationException;
+import org.xml.sax.AttributeList;
+import org.xml.sax.DocumentHandler;
 import org.xml.sax.InputSource;
+import org.xml.sax.Locator;
 import org.xml.sax.SAXException;
+import org.xml.sax.XMLReader;
+import org.xml.sax.helpers.XMLReaderAdapter;
 
 /**
  * <p>
@@ -58,7 +65,7 @@
  * @version $Id$
  *  
  */
-public class CastorFileSystemDocumentHandler implements DocumentHandler, FileCacheEventListener
+public class CastorFileSystemDocumentHandler implements org.apache.jetspeed.page.document.DocumentHandler, FileCacheEventListener
 {
 
     private final static Log log = LogFactory.getLog(CastorFileSystemDocumentHandler.class);
@@ -159,6 +166,7 @@
         documentImpl.setHandlerFactory(handlerFactory);
         documentImpl.setPermissionsEnabled(handlerFactory.getPermissionsEnabled());
         documentImpl.setConstraintsEnabled(handlerFactory.getConstraintsEnabled());
+        documentImpl.marshalling();
         
         // marshal page to disk
         String fileName = path;        
@@ -171,9 +179,77 @@
 
         try
         {
+            // marshal: use SAX I handler to filter document XML for
+            // page and folder menu definition menu elements ordered
+            // polymorphic collection to strip artifical <menu-element>
+            // tags enabling Castor XML binding; see META-INF/page-mapping.xml
             writer = new FileWriter(f);
             Serializer serializer = new XMLSerializer(writer, this.format);
-            Marshaller marshaller = new Marshaller(serializer.asDocumentHandler());
+            final DocumentHandler handler = serializer.asDocumentHandler();
+            Marshaller marshaller = new Marshaller(new DocumentHandler()
+                {
+                    private int menuDepth = 0;
+
+                    public void characters(char[] ch, int start, int length) throws SAXException
+                    {
+                        handler.characters(ch, start, length);
+                    }
+
+                    public void endDocument() throws SAXException
+                    {
+                        handler.endDocument();
+                    }
+                    
+                    public void endElement(String name) throws SAXException
+                    {
+                        // track menu depth
+                        if (name.equals("menu"))
+                        {
+                            menuDepth--;
+                        }
+
+                        // filter menu-element noded within menu definition
+                        if ((menuDepth == 0) || !name.equals("menu-element"))
+                        {
+                            handler.endElement(name);
+                        }
+                    }
+                    
+                    public void ignorableWhitespace(char[] ch, int start, int length) throws SAXException
+                    {
+                        handler.ignorableWhitespace(ch, start, length);
+                    }
+                    
+                    public void processingInstruction(String target, String data) throws SAXException
+                    {
+                        handler.processingInstruction(target, data);
+                    }
+                    
+                    public void setDocumentLocator(Locator locator)
+                    {
+                        handler.setDocumentLocator(locator);
+                    }
+                    
+                    public void startDocument() throws SAXException
+                    {
+                        handler.startDocument();
+                    }
+                    
+                    public void startElement(String name, AttributeList atts) throws SAXException
+                    {
+                        // filter menu-element noded within menu definition
+                        if ((menuDepth == 0) || !name.equals("menu-element"))
+                        {
+                            handler.startElement(name, atts);
+                        }
+
+                        // track menu depth
+                        if (name.equals("menu"))
+                        {
+                            menuDepth++;
+                        }
+                    }
+                });
             marshaller.setMapping(this.mapping);
             marshaller.marshal(document);
         }
@@ -265,19 +341,123 @@
 
         try
         {
-            DocumentBuilderFactory dbfactory = DocumentBuilderFactory.newInstance();
-            DocumentBuilder builder = dbfactory.newDocumentBuilder();
-
-            org.w3c.dom.Document d = builder.parse(f);
-
+            // unmarshal: use SAX I parser to read document XML, filtering
+            // for page and folder menu definition menu elements ordered
+            // polymorphic collection to insert artifical <menu-element>
+            // tags enabling Castor XML binding; see META-INF/page-mapping.xml
+            SAXParserFactory factory = SAXParserFactory.newInstance();
+            SAXParser parser = factory.newSAXParser();
+            XMLReader reader = parser.getXMLReader();
+            final XMLReaderAdapter readerAdapter = new XMLReaderAdapter(reader);
+            final InputSource readerInput = new InputSource(new FileReader(f));
             Unmarshaller unmarshaller = new Unmarshaller(this.mapping);
-            document = (Document) unmarshaller.unmarshal((org.w3c.dom.Node) d);
+            document = (Document) unmarshaller.unmarshal(new EventProducer()
+                {
+                    public void setDocumentHandler(final DocumentHandler handler)
+                    {
+                        readerAdapter.setDocumentHandler(new DocumentHandler()
+                            {
+                                private int menuDepth = 0;
+
+                                public void characters(char[] ch, int start, int length) throws SAXException
+                                {
+                                    handler.characters(ch, start, length);
+                                }
+
+                                public void endDocument() throws SAXException
+                                {
+                                    handler.endDocument();
+                                }
+
+                                public void endElement(String name) throws SAXException
+                                {
+                                    // always include all elements
+                                    handler.endElement(name);
+
+                                    // track menu depth and insert menu-element nodes
+                                    // to encapsulate menu elements to support collection
+                                    // polymorphism in Castor
+                                    if (name.equals("menu"))
+                                    {
+                                        menuDepth--;
+                                        if (menuDepth > 0)
+                                        {
+                                            handler.endElement("menu-element");
+                                        }
+                                    }
+                                    else if ((menuDepth > 0) &&
+                                             (name.equals("options") || name.equals("separator") ||
+                                              name.equals("include") || name.equals("exclude")))
+                                    {
+                                        handler.endElement("menu-element");
+                                    }
+                                }
+
+                                public void ignorableWhitespace(char[] ch, int start, int length) throws SAXException
+                                {
+                                    handler.ignorableWhitespace(ch, start, length);
+                                }
+
+                                public void processingInstruction(String target, String data) throws SAXException
+                                {
+                                    handler.processingInstruction(target, data);
+                                }
+
+                                public void setDocumentLocator(Locator locator)
+                                {
+                                    handler.setDocumentLocator(locator);
+                                }
+
+                                public void startDocument() throws SAXException
+                                {
+                                    handler.startDocument();
+                                }
+
+                                public void startElement(String name, AttributeList atts) throws SAXException
+                                {
+                                    // track menu depth and insert menu-element nodes
+                                    // to encapsulate menu elements to support collection
+                                    // polymorphism in Castor
+                                    if (name.equals("menu"))
+                                    {
+                                        if (menuDepth > 0)
+                                        {
+                                            handler.startElement("menu-element", null);
+                                        }
+                                        menuDepth++;
+                                    }
+                                    else if ((menuDepth > 0) &&
+                                             (name.equals("options") || name.equals("separator") ||
+                                              name.equals("include") || name.equals("exclude")))
+                                    {
+                                        handler.startElement("menu-element", null);
+                                    }
+
+                                    // always include all elements
+                                    handler.startElement(name, atts);
+                                }
+                            });
+                    }
+                    public void start() throws SAXException
+                    {
+                        try
+                        {
+                            readerAdapter.parse(readerInput);
+                        }
+                        catch (IOException ioe)
+                        {
+                            throw new SAXException(ioe);
+                        }
+                    }
+                });
+
             document.setId(path);
             document.setPath(path);
             AbstractBaseElement documentImpl = (AbstractBaseElement)document;
             documentImpl.setHandlerFactory(handlerFactory);
             documentImpl.setPermissionsEnabled(handlerFactory.getPermissionsEnabled());
             documentImpl.setConstraintsEnabled(handlerFactory.getConstraintsEnabled());
+            documentImpl.unmarshalled();
         }
         catch (IOException e)
         {

Modified: portals/jetspeed-2/branches/MENUS_BRANCH/components/page-manager/src/java/org/apache/jetspeed/page/document/FileSystemFolderHandler.java
URL: http://svn.apache.org/viewcvs/portals/jetspeed-2/branches/MENUS_BRANCH/components/page-manager/src/java/org/apache/jetspeed/page/document/FileSystemFolderHandler.java?rev=209305&r1=209304&r2=209305&view=diff
==============================================================================
--- portals/jetspeed-2/branches/MENUS_BRANCH/components/page-manager/src/java/org/apache/jetspeed/page/document/FileSystemFolderHandler.java (original)
+++ portals/jetspeed-2/branches/MENUS_BRANCH/components/page-manager/src/java/org/apache/jetspeed/page/document/FileSystemFolderHandler.java Tue Jul  5 11:58:05 2005
@@ -145,7 +145,6 @@
      */
     public Folder getFolder( String path, boolean fromCache ) throws NodeException, FolderNotFoundException, InvalidFolderException
     {
-        FolderMetaData metadata = null;
         Folder folder = null;
         File folderFile = new File(documentRootDir, path);
         if(!folderFile.exists())
@@ -158,47 +157,57 @@
             throw new InvalidFolderException(folderFile.getAbsolutePath()+" is not a valid directory.");
         }
         
+        // cleanup trailing separators
+        if (!path.equals(Folder.PATH_SEPARATOR) && path.endsWith(Folder.PATH_SEPARATOR))
+        {
+            path = path.substring(0, path.length()-1);
+        }
 
+        // check cache
         if (fromCache)
         {
             folder = (Folder) fileCache.getDocument(path);
         }
 
+        // get new folder
         if (folder == null)
         {
             try
             {
-                if (path.endsWith(Folder.PATH_SEPARATOR))
-                {
-                    Object obj = metadataDocHandler.getDocument(path + FolderMetaData.DOCUMENT_TYPE);
-                    metadata = (FolderMetaData) obj;
-                }
-                else
-                {
-                    Object obj =(FolderMetaData) metadataDocHandler.getDocument(path + Folder.PATH_SEPARATOR
-                            + FolderMetaData.DOCUMENT_TYPE);
-                    metadata = (FolderMetaData) obj;
-                }
+                // look for metadata
+                FolderMetaData metadata = (FolderMetaData) metadataDocHandler.getDocument(path + Folder.PATH_SEPARATOR + FolderMetaData.DOCUMENT_TYPE);
                 folder = new FolderImpl(path, metadata, handlerFactory, this);
             }
             catch (DocumentNotFoundException e)
             {
+                // no metadata
                 folder = new FolderImpl(path, handlerFactory, this);
             }
 
-            if (!path.equals(Folder.PATH_SEPARATOR) && path.indexOf(Folder.PATH_SEPARATOR_CHAR) > -1)
+            // recursively set parent
+            if (!path.equals(Folder.PATH_SEPARATOR))
             {
-                folder.setParent(getFolder(path.substring(0, path.lastIndexOf(Folder.PATH_SEPARATOR_CHAR))));
+                String parentPath = path;
+                int parentSeparatorIndex = parentPath.lastIndexOf(Folder.PATH_SEPARATOR_CHAR);
+                if (parentSeparatorIndex > 0)
+                {
+                    parentPath = parentPath.substring(0, parentSeparatorIndex);
+                }
+                else
+                {
+                    parentPath = Folder.PATH_SEPARATOR;
+                }
+                folder.setParent(getFolder(parentPath));
             }
-            else if (!path.equals(Folder.PATH_SEPARATOR) && path.indexOf(Folder.PATH_SEPARATOR_CHAR) < 0)
+
+            // folder unmarshalled
+            ((FolderImpl) folder).unmarshalled();
+
+            // add to cache
+            if (fromCache)
             {
-                folder.setParent(getFolder(Folder.PATH_SEPARATOR));
+                addToCache(path, folder);
             }
-        }
-
-        if (fromCache)
-        {
-            addToCache(path, folder);
         }
 
         return folder;

Modified: portals/jetspeed-2/branches/MENUS_BRANCH/components/page-manager/src/java/org/apache/jetspeed/page/impl/AbstractPageManager.java
URL: http://svn.apache.org/viewcvs/portals/jetspeed-2/branches/MENUS_BRANCH/components/page-manager/src/java/org/apache/jetspeed/page/impl/AbstractPageManager.java?rev=209305&r1=209304&r2=209305&view=diff
==============================================================================
--- portals/jetspeed-2/branches/MENUS_BRANCH/components/page-manager/src/java/org/apache/jetspeed/page/impl/AbstractPageManager.java (original)
+++ portals/jetspeed-2/branches/MENUS_BRANCH/components/page-manager/src/java/org/apache/jetspeed/page/impl/AbstractPageManager.java Tue Jul  5 11:58:05 2005
@@ -15,33 +15,29 @@
  */
 package org.apache.jetspeed.page.impl;
 
-import java.util.ArrayList;
-import java.util.Iterator;
 import java.util.List;
-import java.util.Map;
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.jetspeed.idgenerator.IdGenerator;
 import org.apache.jetspeed.om.common.SecuredResource;
-import org.apache.jetspeed.om.folder.DocumentSet;
-import org.apache.jetspeed.om.folder.Folder;
-import org.apache.jetspeed.om.folder.impl.FolderImpl;
+import org.apache.jetspeed.om.folder.MenuDefinition;
+import org.apache.jetspeed.om.folder.MenuExcludeDefinition;
+import org.apache.jetspeed.om.folder.MenuIncludeDefinition;
+import org.apache.jetspeed.om.folder.MenuOptionsDefinition;
+import org.apache.jetspeed.om.folder.MenuSeparatorDefinition;
+import org.apache.jetspeed.om.folder.impl.MenuDefinitionImpl;
+import org.apache.jetspeed.om.folder.impl.MenuExcludeDefinitionImpl;
+import org.apache.jetspeed.om.folder.impl.MenuIncludeDefinitionImpl;
+import org.apache.jetspeed.om.folder.impl.MenuOptionsDefinitionImpl;
+import org.apache.jetspeed.om.folder.impl.MenuSeparatorDefinitionImpl;
 import org.apache.jetspeed.om.page.Fragment;
-import org.apache.jetspeed.om.page.Link;
 import org.apache.jetspeed.om.page.Page;
 import org.apache.jetspeed.om.page.Property;
 import org.apache.jetspeed.om.page.psml.FragmentImpl;
 import org.apache.jetspeed.om.page.psml.PageImpl;
 import org.apache.jetspeed.om.page.psml.PropertyImpl;
 import org.apache.jetspeed.page.PageManager;
-import org.apache.jetspeed.page.document.AbstractNode;
-import org.apache.jetspeed.page.document.Node;
-import org.apache.jetspeed.page.document.NodeException;
-import org.apache.jetspeed.page.document.NodeSet;
-import org.apache.jetspeed.page.document.NodeSetImpl;
-import org.apache.jetspeed.profiler.ProfileLocator;
-import org.apache.jetspeed.profiler.ProfiledPageContext;
 
 /**
  * AbstractPageManagerService
@@ -57,6 +53,12 @@
     protected Class fragmentClass = FragmentImpl.class;
     protected Class pageClass = PageImpl.class;
     protected Class propertyClass = PropertyImpl.class;
+    protected Class menuDefinitionClass = MenuDefinitionImpl.class;
+    protected Class menuExcludeDefinitionClass = MenuExcludeDefinitionImpl.class;
+    protected Class menuIncludeDefinitionClass = MenuIncludeDefinitionImpl.class;
+    protected Class menuOptionsDefinitionClass = MenuOptionsDefinitionImpl.class;
+    protected Class menuSeparatorDefinitionClass = MenuSeparatorDefinitionImpl.class;
+
     protected IdGenerator generator = null;
 
     private boolean permissionsEnabled;
@@ -183,387 +185,118 @@
         return property;        
     }
 
-    public Object createObject(Class classe)
+    /**
+     * newMenuDefinition - creates a new empty menu definition
+     *
+     * @return a newly created MenuDefinition object
+     */
+    public MenuDefinition newMenuDefinition()
     {
-        Object object = null;
         try
         {
-            object = classe.newInstance();
+            return (MenuDefinition)createObject(this.menuDefinitionClass);
         }
-        catch (Exception e)
+        catch (ClassCastException e)
         {
-            log.error("Factory failed to create object: " + classe.getName(), e);            
+            String message = "Failed to create menu definition object for " + this.menuDefinitionClass;
+            log.error(message, e);
         }
-        
-        return object;        
+        return null;
     }
-    
-    protected class CacheablePageContext
-    {
-        public Page page;
-        public Folder folder;
-        public NodeSet siblingPages;
-        public Folder parentFolder;
-        public NodeSet siblingFolders;
-        public NodeSet rootLinks;
-        public NodeSet documentSets;
-        public Map documentSetNames;
-        public Map documentSetNodeSets;
-        public List profiledFolders;
-        public NodeSet nestedDocumentSets;
-
-        public CacheablePageContext(Page page, Folder folder, NodeSet siblingPages, Folder parentFolder, NodeSet siblingFolders, NodeSet rootLinks, NodeSet documentSets, Map documentSetNames, Map documentSetNodeSets, List profiledFolders)
-        {
-            this.page = page;
-            this.folder = folder;
-            this.siblingPages = siblingPages;
-            this.parentFolder = parentFolder;
-            this.siblingFolders = siblingFolders;
-            this.profiledFolders = profiledFolders;
-            this.rootLinks = rootLinks;
-            this.documentSets = documentSets;
-            this.documentSetNames = documentSetNames;
-            this.documentSetNodeSets = documentSetNodeSets;
-
-            // compute nested document sets nodes set: these
-            // do not appear in the document set but are mapped
-            // in docuemnt set names/node sets
-            if ((this.documentSetNames != null) && (this.documentSets != null) && (this.documentSetNames.size() > this.documentSets.size()))
-            {
-                Iterator mappedIter = this.documentSetNames.entrySet().iterator();
-                while (mappedIter.hasNext())
-                {
-                    Map.Entry mappedEntry = (Map.Entry)mappedIter.next();
-                    DocumentSet documentSet = (DocumentSet)mappedEntry.getKey();
-                    if (!this.documentSets.contains(documentSet))
-                    {
-                        if (this.nestedDocumentSets == null)
-                        {
-                            this.nestedDocumentSets = new NodeSetImpl(null);
-                        }
-                        this.nestedDocumentSets.add(documentSet);
-                    }
-                }
-            }
 
-            // debug profiled page context elements
-            if (log.isDebugEnabled())
-            {
-                log.debug("CacheablePageContext(), folder = " + this.folder + ", url = " + this.folder.getUrl());
-                log.debug("CacheablePageContext(), page = " + this.page + ", url = " + this.page.getUrl());
-                if ((this.siblingPages != null) && !this.siblingPages.isEmpty())
-                {
-                    Iterator debugIter = this.siblingPages.iterator();
-                    while (debugIter.hasNext())
-                    {
-                        Page debug = (Page) debugIter.next();
-                        log.debug("CacheablePageContext(), siblingPage = " + debug + ", url = " + debug.getUrl());
-                    }
-                }
-                else
-                    log.debug("CacheablePageContext(), siblingPages = null/empty");
-                log.debug("CacheablePageContext(), parentFolder = " + this.parentFolder + ", url = " + ((this.parentFolder != null) ? this.parentFolder.getUrl() : "null"));
-                if ((this.siblingFolders != null) && !this.siblingFolders.isEmpty())
-                {
-                    Iterator debugIter = this.siblingFolders.iterator();
-                    while (debugIter.hasNext())
-                    {
-                        Folder debug = (Folder) debugIter.next();
-                        log.debug("CacheablePageContext(), siblingFolder = " + debug + ", url = " + debug.getUrl());
-                    }
-                }
-                else
-                    log.debug("CacheablePageContext(), siblingFolders = null/empty");
-                if ((this.rootLinks != null) && !this.rootLinks.isEmpty())
-                {
-                    Iterator debugIter = this.rootLinks.iterator();
-                    while (debugIter.hasNext())
-                    {
-                        Link debug = (Link) debugIter.next();
-                        log.debug("CacheablePageContext(), rootLink = " + debug + ", url = " + debug.getUrl());
-                    }
-                }
-                else
-                    log.debug("CacheablePageContext(), rootLinks = null/empty");
-                if ((this.documentSets != null) && !this.documentSets.isEmpty() &&
-                    (this.documentSetNames != null) && !this.documentSetNames.isEmpty() &&
-                    (this.documentSetNodeSets != null) && !this.documentSetNodeSets.isEmpty())
-                {
-                    Iterator debugIter = this.documentSets.iterator();
-                    while (debugIter.hasNext())
-                    {
-                        log.debug("CacheablePageContext(), " + debugDocumentSetMessage((DocumentSet)debugIter.next()));
-                    }
-                    if ((this.nestedDocumentSets != null) && !this.nestedDocumentSets.isEmpty())
-                    {
-                        debugIter = this.nestedDocumentSets.iterator();
-                        while (debugIter.hasNext())
-                        {
-                            log.debug("CacheablePageContext(), nested " + debugDocumentSetMessage((DocumentSet)debugIter.next()));
-                        }
-                    }
-                }
-                else
-                    log.debug("CacheablePageContext(), documentSets/documentSetNames/documentSetNodeSets = null/empty");
-                if ((this.profiledFolders != null) && !this.profiledFolders.isEmpty())
-                {
-                    Iterator debugIter = this.profiledFolders.iterator();
-                    while (debugIter.hasNext())
-                    {
-                        Folder debug = (Folder) debugIter.next();
-                        log.debug("CacheablePageContext(), profiledFolder = " + debug + ", url = " + debug.getUrl());
-                    }
-                }
-                else
-                    log.debug("CacheablePageContext(), profiledFolders = null/empty");
-            }
+    /**
+     * newMenuExcludeDefinition - creates a new empty menu exclude definition
+     *
+     * @return a newly created MenuExcludeDefinition object
+     */
+    public MenuExcludeDefinition newMenuExcludeDefinition()
+    {
+        try
+        {
+            return (MenuExcludeDefinition)createObject(this.menuExcludeDefinitionClass);
         }
-
-        private String debugDocumentSetMessage(DocumentSet debug)
+        catch (ClassCastException e)
         {
-            String debugName = (String) this.documentSetNames.get(debug);
-            NodeSet debugNodes = (NodeSet) this.documentSetNodeSets.get(debug);
-            String debugMessage = "document set " + debug + ", name = " + debugName + ", nodes = {";
-            Iterator nodesIter = debugNodes.iterator();
-            if (nodesIter.hasNext())
-            {
-                debugMessage += ((Node) nodesIter.next()).getUrl();
-            }
-            while (nodesIter.hasNext())
-            {
-                debugMessage += ", " + ((Node) nodesIter.next()).getUrl();
-            }
-            debugMessage += "}, url = " + debug.getUrl();
-            return debugMessage;
+            String message = "Failed to create menu exclude definition object for " + this.menuExcludeDefinitionClass;
+            log.error(message, e);
         }
+        return null;
     }
 
-    protected void populateProfiledPageContext(CacheablePageContext cachedPageContext, ProfiledPageContext pageContext)
+    /**
+     * newMenuIncludeDefinition - creates a new empty menu include definition
+     *
+     * @return a newly created MenuIncludeDefinition object
+     */
+    public MenuIncludeDefinition newMenuIncludeDefinition()
     {
-        // populate supplied page context object while checking
-        // page and folder visibility using access permissions
-        // and/or constraints; by definition, page visibility implies
-        // folder and parent folder visibility
-        pageContext.setPage((Page)checkVisibility((AbstractNode)cachedPageContext.page, cachedPageContext.profiledFolders));
-        pageContext.setFolder(cachedPageContext.folder);
-        pageContext.setSiblingPages(checkVisibility(cachedPageContext.siblingPages, cachedPageContext.profiledFolders));
-        pageContext.setParentFolder(cachedPageContext.parentFolder);
-        pageContext.setSiblingFolders(checkVisibility(cachedPageContext.siblingFolders, cachedPageContext.profiledFolders));
-        pageContext.setRootLinks(checkVisibility(cachedPageContext.rootLinks, cachedPageContext.profiledFolders));
-        if (cachedPageContext.documentSets != null)
+        try
         {
-            Iterator documentSetIter = checkVisibility(cachedPageContext.documentSets, cachedPageContext.profiledFolders).iterator();
-            while (documentSetIter.hasNext())
-            {
-                // populate root document set
-                DocumentSet documentSet = (DocumentSet)documentSetIter.next();
-                String documentSetName = (String)cachedPageContext.documentSetNames.get(documentSet);
-                NodeSet documentSetNodes = checkVisibility((NodeSet)cachedPageContext.documentSetNodeSets.get(documentSet), cachedPageContext.profiledFolders);
-                pageContext.setDocumentSet(documentSetName, documentSet, documentSetNodes);
-            }
-            if (cachedPageContext.nestedDocumentSets != null)
-            {
-                Iterator nestedDocumentSetIter = checkVisibility(cachedPageContext.nestedDocumentSets, cachedPageContext.profiledFolders).iterator();
-                while (nestedDocumentSetIter.hasNext())
-                {
-                    // populate nested document set
-                    DocumentSet documentSet = (DocumentSet)nestedDocumentSetIter.next();
-                    String documentSetName = (String)cachedPageContext.documentSetNames.get(documentSet);
-                    NodeSet documentSetNodes = checkVisibility((NodeSet)cachedPageContext.documentSetNodeSets.get(documentSet), cachedPageContext.profiledFolders);
-                    pageContext.setNestedDocumentSet(documentSetName, documentSet, documentSetNodes);
-                }
-            }
+            return (MenuIncludeDefinition)createObject(this.menuIncludeDefinitionClass);
         }
-    }
-
-    protected AbstractNode checkVisibility(AbstractNode node, List profiledFolders) throws SecurityException
-    {
-        // check access constraints/permissions of node
-        // to determine visibility, (hidden status already
-        // tested by profiler); throws SecurityExceptiond
-        // if view access not granted
-        if (node != null)
+        catch (ClassCastException e)
         {
-            if (node instanceof Folder)
-            {
-                // visibility of folder determined by visibility
-                // of pages in folder; accessible pages in subfolders
-                // are not checked since navigating into a folder
-                // with no visible pages is not permitted; finally,
-                // all equivalent profiled folders must be checked
-                // if available
-                boolean securityException = false;
-                try
-                {
-                    Iterator pagesIter = ((FolderImpl) node).getPages(false).iterator();
-                    while (pagesIter.hasNext())
-                    {
-                        try
-                        {
-                            AbstractNode page = (AbstractNode)pagesIter.next();
-                            if (!page.isHidden())
-                            {
-                                checkVisibility(page, profiledFolders);
-                                return node;
-                            }
-                        }
-                        catch (SecurityException se)
-                        {
-                            securityException = true;
-                        }
-                    }
-                }
-                catch (NodeException ne)
-                {
-                }
-                if (profiledFolders != null)
-                {
-                    String folderUrl = node.getUrl();
-                    Iterator foldersIter = profiledFolders.iterator();
-                    while (foldersIter.hasNext())
-                    {
-                        FolderImpl profiledFolder = (FolderImpl)foldersIter.next();
-                        if ((profiledFolder != node) && folderUrl.equals(profiledFolder.getUrl()))
-                        {
-                            try
-                            {
-                                Iterator pagesIter = profiledFolder.getPages(false).iterator();
-                                while (pagesIter.hasNext())
-                                {
-                                    try
-                                    {
-                                        AbstractNode page = (AbstractNode)pagesIter.next();
-                                        if (!page.isHidden())
-                                        {
-                                            checkVisibility(page, profiledFolders);
-                                            return node;
-                                        }
-                                    }
-                                    catch (SecurityException se)
-                                    {
-                                        securityException = true;
-                                    }
-                                }
-                            }
-                            catch (NodeException ne)
-                            {
-                            }
-                        }
-                    }
-                }
-
-                // no visible pages found in folder or equivalent
-                // folder: throw security or runtime exception
-                if (securityException)
-                {
-                    throw new SecurityException("AbstractPageManager.checkVisibility(): Access for " + SecuredResource.VIEW_ACTION + " not permitted to any folder page.");
-                }
-                throw new RuntimeException("AbstractPageManager.checkVisibility(): Empty folders not visible.");
-            }
-            else
-            {
-                // simple access test for document
-                node.checkAccess(SecuredResource.VIEW_ACTION);
-            }
+            String message = "Failed to create menu include definition object for " + this.menuIncludeDefinitionClass;
+            log.error(message, e);
         }
-        return node;
+        return null;
     }
 
-    protected NodeSet checkVisibility(NodeSet nodes, List profiledFolders)
+    /**
+     * newMenuOptionsDefinition - creates a new empty menu options definition
+     *
+     * @return a newly created MenuOptionsDefinition object
+     */
+    public MenuOptionsDefinition newMenuOptionsDefinition()
     {
-        // check access constraints/permissions of nodes
-        // to determine visibility; filter nodes accordingly
-        if ((nodes != null) && !nodes.isEmpty())
+        try
         {
-            NodeSetImpl filteredNodes = null;
-            Iterator checkAccessIter = nodes.iterator();
-            while (checkAccessIter.hasNext())
-            {
-                AbstractNode node = (AbstractNode)checkAccessIter.next();
-                try
-                {
-                    // check visibility
-                    checkVisibility(node, profiledFolders);
-
-                    // add to filteredNodes nodes if copying
-                    if (filteredNodes != null)
-                    {
-                        // permitted, add to filteredNodes nodes
-                        filteredNodes.add(node);
-                    }
-                }
-                catch (RuntimeException rte)
-                {
-                    // create filteredNodes nodes if not already copying
-                    if (filteredNodes == null)
-                    {
-                        // not permitted, copy previously permitted nodes
-                        // to new filteredNodes node set with same comparator
-                        filteredNodes = new NodeSetImpl(null, ((NodeSetImpl)nodes).getComparator());
-                        Iterator copyIter = nodes.iterator();
-                        while (copyIter.hasNext())
-                        {
-                            AbstractNode copyNode = (AbstractNode)copyIter.next();
-                            if (copyNode != node)
-                            {
-                                filteredNodes.add(copyNode);
-                            }
-                            else
-                            {
-                                break;
-                            }
-                        }
-                    }
-                }
-            }
-
-            // return filteredNodes nodes if generated
-            if (filteredNodes != null)
-            {
-                return filteredNodes;
-            }
+            return (MenuOptionsDefinition)createObject(this.menuOptionsDefinitionClass);
         }
-        return nodes;
-    }
-
-    protected ProfileLocator selectPageProfileLocator(Map profileLocators)
-    {
-        // select page profile locator from session/principal profile locators
-        return (ProfileLocator) profileLocators.get(ProfileLocator.PAGE_LOCATOR);
+        catch (ClassCastException e)
+        {
+            String message = "Failed to create menu options definition object for " + this.menuOptionsDefinitionClass;
+            log.error(message, e);
+        }
+        return null;
     }
 
-    protected List selectAlternatePageProfileLocators(Map profileLocators)
+    /**
+     * newMenuSeparatorDefinition - creates a new empty menu separator definition
+     *
+     * @return a newly created MenuSeparatorDefinition object
+     */
+    public MenuSeparatorDefinition newMenuSeparatorDefinition()
     {
-        // select alternate page profile locators from session/principal profile locators
-        List locators = new ArrayList(4);
-        Iterator locatorsIter = profileLocators.entrySet().iterator();
-        while (locatorsIter.hasNext())
+        try
         {
-            Map.Entry locatorEntry = (Map.Entry) locatorsIter.next();
-            if (! ((String) locatorEntry.getKey()).equals(ProfileLocator.PAGE_LOCATOR))
-            {
-                locators.add(locatorEntry.getValue());
-            }
+            return (MenuSeparatorDefinition)createObject(this.menuSeparatorDefinitionClass);
+        }
+        catch (ClassCastException e)
+        {
+            String message = "Failed to create menu separator definition object for " + this.menuSeparatorDefinitionClass;
+            log.error(message, e);
         }
-        return locators;
+        return null;
     }
 
-    protected ProfileLocator selectNavigationProfileLocator(String profileLocatorName, Map profileLocators)
+    /**
+     * createObject - creates a new page manager implementation object
+     *
+     * @param classe implementation class
+     * @return a newly created implementation object
+     */
+    public Object createObject(Class classe)
     {
-        // select navigation profile locator from session/principal profile locators
-        ProfileLocator locator = null;
-        if (profileLocatorName != null)
+        Object object = null;
+        try
         {
-            locator = (ProfileLocator) profileLocators.get(profileLocatorName);
+            object = classe.newInstance();
         }
-        else
+        catch (Exception e)
         {
-            locator = (ProfileLocator) profileLocators.get(ProfileLocator.DOCSET_LOCATOR);
-            if (locator == null)
-            {
-                locator = (ProfileLocator) profileLocators.get(ProfileLocator.PAGE_LOCATOR);
-            }
+            log.error("Factory failed to create object: " + classe.getName(), e);            
         }
-        return locator;
-    }
+        return object;        
+    }    
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: jetspeed-dev-unsubscribe@portals.apache.org
For additional commands, e-mail: jetspeed-dev-help@portals.apache.org


Mime
View raw message