You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jetspeed-dev@portals.apache.org by ta...@apache.org on 2002/03/29 00:13:15 UTC
cvs commit: jakarta-jetspeed/src/java/org/apache/jetspeed/services/registry TestRegistryCategories.java CastorRegistryService.java TestMarshallRegistry.java
taylor 02/03/28 15:13:15
Modified: src/java/org/apache/jetspeed/om/registry PortletEntry.java
src/java/org/apache/jetspeed/om/registry/base
BasePortletEntry.java BasePortletRegistry.java
BaseRegistry.java
src/java/org/apache/jetspeed/services/registry
CastorRegistryService.java
TestMarshallRegistry.java
Added: src/java/org/apache/jetspeed/om/registry Category.java
PortletRegistry.java
src/java/org/apache/jetspeed/om/registry/base
BaseCategory.java CategoryIterator.java
PortletIterator.java
src/java/org/apache/jetspeed/services/registry
TestRegistryCategories.java
Log:
Added categories to portlet registry elements
Revision Changes Path
1.3 +62 -1 jakarta-jetspeed/src/java/org/apache/jetspeed/om/registry/PortletEntry.java
Index: PortletEntry.java
===================================================================
RCS file: /home/cvs/jakarta-jetspeed/src/java/org/apache/jetspeed/om/registry/PortletEntry.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- PortletEntry.java 26 Mar 2002 09:06:53 -0000 1.2
+++ PortletEntry.java 28 Mar 2002 23:13:14 -0000 1.3
@@ -54,6 +54,8 @@
package org.apache.jetspeed.om.registry;
+import java.util.Iterator;
+
/**
* This entry describes all the properties that should be present in
* a RegistryEntry describing a Portlet.
@@ -69,7 +71,7 @@
* </dl></p>
*
* @author <a href="mailto:raphael@apache.org">Rapha�l Luta</a>
- * @version $Id: PortletEntry.java,v 1.2 2002/03/26 09:06:53 taylor Exp $
+ * @version $Id: PortletEntry.java,v 1.3 2002/03/28 23:13:14 taylor Exp $
*/
public interface PortletEntry extends PortletInfoEntry
{
@@ -78,6 +80,10 @@
public static final String TYPE_INSTANCE = "instance";
public static final String TYPE_ABSTRACT = "abstract";
+ public final static String DEFAULT_GROUP = "Jetspeed";
+ public final static String DEFAULT_CATEGORY_REF = "General";
+ public final static String DEFAULT_CATEGORY_ABSTRACT = "Abstract";
+
/** @return the URL associated with this portlet or null */
public String getURL();
@@ -159,6 +165,61 @@
* @param type the new type for the PortletEntry
*/
public void setType( String type );
+
+
+ /**
+ * Returns a list of the categories
+ *
+ * @return an iterator on the categories
+ */
+ public Iterator listCategories();
+
+ /**
+ * Test if a given category exists for this entry
+ *
+ * @param name the category name
+ * @return true is the category exists in the default group
+ */
+ public boolean hasCategory(String name);
+
+ /**
+ * Test if a given category exists for this entry, in the specified group of categories.
+ *
+ * @param name the category name
+ * @param group the category group
+ * @return true is the category exists in the specified group
+ */
+ public boolean hasCategory(String name, String group);
+
+ /**
+ * Add a new category to this portlet entry in the default group.
+ *
+ * @param name the category name
+ */
+ public void addCategory(String name);
+
+ /**
+ * Add a new category to this portlet entry.
+ *
+ * @param name the category name
+ * @param group the category group name
+ */
+ public void addCategory(String name, String group);
+
+ /**
+ * Remove a category from this portlet entry in the default group.
+ *
+ * @param name the category name
+ */
+ public void removeCategory(String name);
+
+ /**
+ * Remove a category from this portlet entry in the specified group.
+ *
+ * @param name the media type name to remove.
+ * @param group the category group name
+ */
+ public void removeCategory(String name, String group);
}
1.1 jakarta-jetspeed/src/java/org/apache/jetspeed/om/registry/Category.java
Index: Category.java
===================================================================
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2000-2001 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Apache" and "Apache Software Foundation" and
* "Apache Jetspeed" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache" or
* "Apache Jetspeed", nor may "Apache" appear in their name, without
* prior written permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.jetspeed.om.registry;
/**
* Interface describing a Category in the registry
*
* @author <a href="mailto:taylor@apache.org">David Sean Taylor</a>
* @version $Id: Category.java,v 1.1 2002/03/28 23:13:14 taylor Exp $
*/
public interface Category
{
/** @return the string category name */
public String getName();
/** Sets the string category name
*
* @param value the new category name
*/
public void setName(String name);
/** @return the string group */
public String getGroup();
/** Sets the string category name
*
* @param value the new category group name
*/
public void setGroup(String group);
}
1.6 +76 -175 jakarta-jetspeed/src/java/org/apache/jetspeed/om/registry/PortletRegistry.java
1.3 +115 -1 jakarta-jetspeed/src/java/org/apache/jetspeed/om/registry/base/BasePortletEntry.java
Index: BasePortletEntry.java
===================================================================
RCS file: /home/cvs/jakarta-jetspeed/src/java/org/apache/jetspeed/om/registry/base/BasePortletEntry.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- BasePortletEntry.java 26 Mar 2002 09:06:53 -0000 1.2
+++ BasePortletEntry.java 28 Mar 2002 23:13:15 -0000 1.3
@@ -68,7 +68,7 @@
* suitable for serialization with Castor
*
* @author <a href="mailto:raphael@apache.org">Rapha�l Luta</a>
- * @version $Id: BasePortletEntry.java,v 1.2 2002/03/26 09:06:53 taylor Exp $
+ * @version $Id: BasePortletEntry.java,v 1.3 2002/03/28 23:13:15 taylor Exp $
*/
public class BasePortletEntry extends BasePortletInfoEntry
implements PortletEntry
@@ -77,6 +77,8 @@
private String parent;
private ContentURL url = new BaseContentURL();
+
+ protected Vector categories = new Vector();
private boolean application;
@@ -371,6 +373,118 @@
{
this.url = url;
}
+
+ /*
+ * Categories
+ */
+ public Vector getCategories()
+ {
+ return this.categories;
+ }
+
+ public void setCategories(Vector v)
+ {
+ this.categories = v;
+ }
+
+ /**
+ * Returns a list of the supported media type names
+ *
+ * @return an iterator on the supported media type names
+ */
+ public Iterator listCategories()
+ {
+ return new PortletIterator(this, "getCategories");
+ }
+
+ /**
+ * Test if a given category exists for this entry
+ *
+ * @param name the category name
+ * @return true is the category exists in the default group
+ */
+ public boolean hasCategory(String name)
+ {
+ return hasCategory(name, PortletEntry.DEFAULT_GROUP);
+ }
+
+ /**
+ * Test if a given category exists for this entry, in the specified group of categories.
+ *
+ * @param name the category name
+ * @param group the category group
+ * @return true is the category exists in the specified group
+ */
+ public boolean hasCategory(String name, String group)
+ {
+ Iterator it = listCategories();
+ while (it.hasNext())
+ {
+ Category cat = (Category)it.next();
+ if (cat.getName().equals(name) && cat.getGroup().equals(group))
+ return true;
+ }
+ return false;
+ }
+
+
+ /**
+ * Add a new category to this portlet entry in the default group.
+ *
+ * @param name the category name
+ */
+ public void addCategory(String name)
+ {
+ addCategory(name, PortletEntry.DEFAULT_GROUP);
+ }
+
+ /**
+ * Add a new category to this portlet entry.
+ *
+ * @param name the category name
+ * @param group the category group name
+ */
+ public void addCategory(String name, String group)
+ {
+ if (!hasCategory(name, group))
+ {
+ Category cat = new BaseCategory();
+ cat.setName(name);
+ cat.setGroup(group);
+ categories.add(cat);
+ }
+ }
+
+ /**
+ * Remove a category from this portlet entry in the default group.
+ *
+ * @param name the category name
+ */
+ public void removeCategory(String name)
+ {
+ removeCategory(name, PortletEntry.DEFAULT_GROUP);
+ }
+
+ /**
+ * Remove a category from this portlet entry in the specified group.
+ *
+ * @param name the media type name to remove.
+ * @param group the category group name
+ */
+ public void removeCategory(String name, String group)
+ {
+ for (int ix = 0; ix < categories.size(); ix++)
+ {
+ Category cat = (Category)categories.elementAt(ix);
+ if (cat.getName().equals(name) && cat.getGroup().equals(group))
+ {
+ categories.remove(ix);
+ return;
+ }
+ }
+ }
+
+
}
1.3 +169 -118 jakarta-jetspeed/src/java/org/apache/jetspeed/om/registry/base/BasePortletRegistry.java
Index: BasePortletRegistry.java
===================================================================
RCS file: /home/cvs/jakarta-jetspeed/src/java/org/apache/jetspeed/om/registry/base/BasePortletRegistry.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- BasePortletRegistry.java 4 Dec 2001 18:15:54 -0000 1.2
+++ BasePortletRegistry.java 28 Mar 2002 23:13:15 -0000 1.3
@@ -55,145 +55,196 @@
package org.apache.jetspeed.om.registry.base;
import org.apache.jetspeed.om.registry.*;
-import org.apache.turbine.util.Log;
-import java.util.Hashtable;
+
+import java.util.Map;
+import java.util.SortedMap;
+import java.util.TreeMap;
+import java.util.HashMap;
+import java.util.Iterator;
import java.util.Enumeration;
+import java.util.Vector;
/**
-Represents all items within Jetspeed that hold configuration information.
-
-@author <a href="mailto:burton@apache.org">Kevin A. Burton</a>
-@version $Id: BasePortletRegistry.java,v 1.2 2001/12/04 18:15:54 sgala Exp $
-*/
-public class BasePortletRegistry extends BaseRegistry {
-
- /**
- Handles mapping URLs to a EntryGroup which holds all Entries that depend
- on the URL
- */
- private Hashtable urlmap = new Hashtable();
+ * Provides base functionality within a Portlet Registry.
+ *
+ * @author <a href="mailto:taylor@apache.org">David Sean Taylor</a>
+ * @version $Id: BasePortletRegistry.java,v 1.3 2002/03/28 23:13:15 taylor Exp $
+ */
+public class BasePortletRegistry extends BaseRegistry implements PortletRegistry
+{
+
+ private Map catMap = new TreeMap();
+
+ /**
+ @see Registry#setEntry
+ */
+ public void setEntry( RegistryEntry entry ) throws InvalidEntryException
+ {
+ super.setEntry(entry);
+ setPortletEntry((PortletEntry)entry);
+ }
/**
- add and entry but also add it to the local entrygroup
-
- @see BaseRegistry#addEntry
- */
- public final void addEntry( PortletEntry entry ) throws RegistryException {
-
- synchronized( this ) {
-
- if ( entry.getURL() != null ) {
- this.getEntryGroup( entry.getURL() ).addEntry( entry );
+ @see Registry#addEntry
+ */
+ public void addEntry( RegistryEntry entry ) throws InvalidEntryException
+ {
+ super.addEntry(entry);
+ setPortletEntry((PortletEntry)entry);
+ }
+
+ protected void setPortletEntry(PortletEntry entry) throws InvalidEntryException
+ {
+ synchronized (catMap)
+ {
+ int count = 0;
+ Iterator it = ((PortletEntry)entry).listCategories();
+ while (it.hasNext())
+ {
+ Category category = (Category)it.next();
+ String key = getCategoryKey(category);
+ HashMap bucket = (HashMap)this.catMap.get(key);
+ if (null == bucket)
+ {
+ bucket = new HashMap();
+ bucket.put(entry.getName(), entry);
+ this.catMap.put(key, bucket);
+ }
+ else
+ {
+ bucket.put(entry.getName(), entry);
+ }
+ count++;
}
-
- super.addEntry( entry );
+ /*
+ TODO: this feature could be optional
+ */
+ if (0 == count)
+ {
+ StringBuffer key = new StringBuffer(128);
+ key.append(PortletEntry.DEFAULT_GROUP);
+ key.append(".");
+ if (entry.getType().equals(PortletEntry.TYPE_ABSTRACT))
+ key.append(PortletEntry.DEFAULT_CATEGORY_ABSTRACT);
+ else
+ key.append(PortletEntry.DEFAULT_CATEGORY_REF);
+
+ HashMap bucket = (HashMap)this.catMap.get(key.toString());
+ if (null == bucket)
+ {
+ bucket = new HashMap();
+ bucket.put(entry.getName(), entry);
+ this.catMap.put(key.toString(), bucket);
+ }
+ else
+ {
+ bucket.put(entry.getName(), entry);
+ }
+ }
}
-
}
- /**
- remove and entry but also remove it to the local entrygroup
-
- @see #removeEntry( PortletEntry )
- */
- public final void removeEntry( String name ) {
- try {
+ public String getCategoryKey(Category category)
+ {
+ if (category == null)
+ return PortletEntry.DEFAULT_GROUP;
+
+ String categoryName = category.getName();
+ if (categoryName == null || categoryName.equals(""))
+ return category.getGroup();
+ return category.getGroup() + "." + categoryName;
+ }
+
+
+ /*
+ * Find portlets in this registry, looking up by category in the default category group.
+ *
+ * @param category The category and optional subcategories.
+ * @return Iterator The result as an iterator.
+ */
+ public Iterator findPortletsByCategory(String category)
+ {
+ String key;
+ if (category == null || category.equals(""))
+ key = PortletEntry.DEFAULT_GROUP;
+ else
+ key = PortletEntry.DEFAULT_GROUP + "." + category;
+ CategoryIterator iterator = new CategoryIterator((SortedMap)catMap, key);
+ return iterator;
+ }
+
+ /*
+ * Find portlets in this registry, looking up by category and category group.
+ *
+ * @param group The group to search for categories in.
+ * @param category The category and optional subcategories.
+ * @return Iterator The result as an iterator.
+ */
+ public Iterator findPortletsByGroupCategory(String group, String category)
+ {
+ if (group == null || group.equals(""))
+ group = PortletEntry.DEFAULT_GROUP;
+
+ String key = group + "." + category;
+
+ CategoryIterator iterator = new CategoryIterator((SortedMap)catMap, key);
+ return iterator;
+ }
+
+ /*
+ * List all portlets in this registry, sorted by category
+ *
+ * @return Iterator The result as an iterator.
+ */
+ public Iterator listByCategory()
+ {
+ CategoryIterator iterator = new CategoryIterator((SortedMap)catMap, null);
+ return iterator;
+ }
+
+ /**
+ @see Registry#removeEntry
+ */
+ public void removeEntry( String name )
+ {
+ if (name == null)
+ return;
- this.removeEntry( (PortletEntry)getEntry( name ) );
-
- } catch ( RegistryException e ) {
- Log.error( e );
+ RegistryEntry entry = (RegistryEntry)this.entries.get( name ) ;
+ if (entry == null)
return;
- }
+ removeEntry(entry);
}
/**
- remove and entry but also remove it to the local entrygroup
-
- @see BaseRegistry#removeEntry( RegistryEntry )
+ @see Registry#removeEntry
*/
- public final void removeEntry( PortletEntry entry ) {
-
- synchronized( this ) {
-
- if ( entry != null && entry.getURL() != null ) {
-
- this.getEntryGroup( entry.getURL() ).removeEntry( entry.getName() );
+ public void removeEntry( RegistryEntry entry )
+ {
+ synchronized(catMap)
+ {
+ int count = 0;
+ Iterator it = ((PortletEntry)entry).listCategories();
+ while (it.hasNext())
+ {
+ Category category = (Category)it.next();
+ HashMap map = (HashMap)catMap.get(getCategoryKey(category));
+ if (map != null)
+ {
+ map.remove(entry.getName());
+ if (0 == map.size())
+ {
+ catMap.remove(getCategoryKey(category));
+ }
+ }
}
-
- super.removeEntry( entry );
- }
-
- }
-
- /**
- Get all entries from the PortletRegistry that are based on the following URL
- */
- public final Enumeration getEntries( String url ) {
- return this.getEntryGroup( url ).getEntries();
- }
-
- /**
- Look into the urlmap and get the EntryGroup that holds this URL or create
- one if it doesn't exist.
- */
- private EntryGroup getEntryGroup( String url ) {
-
- EntryGroup eg = (EntryGroup)this.urlmap.get( url );
-
- if ( eg == null ) {
-
- eg = new EntryGroup();
- this.urlmap.put( url, eg );
-
}
-
- return eg;
- }
-
-}
-
-/**
-Allows the developer to group multiple Entries together.
-*/
-class EntryGroup {
-
- private Hashtable table = new Hashtable();
-
- /**
- Add an Entry to this EntryGroup
- */
- public void addEntry( PortletEntry entry ) {
- this.table.put( entry.getName(), entry );
- }
-
- /**
- Get an Entry from this EntryGroup or null if it does not exist
- */
- public PortletEntry getEntry( String name ) {
- return (PortletEntry)this.table.get( name );
- }
-
- /**
- Remove an Entry from this EntryGroup if it exists.
- */
- public void removeEntry( String name ) {
- this.table.remove( name );
- }
-
- /**
- Get the Entries that are stored in this EntryGroup
- */
- public Enumeration getEntries() {
- return this.table.elements();
+ super.removeEntry(entry);
}
-}
-
-
-
+}
\ No newline at end of file
1.3 +2 -2 jakarta-jetspeed/src/java/org/apache/jetspeed/om/registry/base/BaseRegistry.java
Index: BaseRegistry.java
===================================================================
RCS file: /home/cvs/jakarta-jetspeed/src/java/org/apache/jetspeed/om/registry/base/BaseRegistry.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- BaseRegistry.java 4 Dec 2001 18:15:54 -0000 1.2
+++ BaseRegistry.java 28 Mar 2002 23:13:15 -0000 1.3
@@ -66,12 +66,12 @@
*
* @author <a href="mailto:burton@apache.org">Kevin A. Burton</a>
* @author <a href="mailto:raphael@apache.org">Rapha�l Luta</a>
- * @version $Id: BaseRegistry.java,v 1.2 2001/12/04 18:15:54 sgala Exp $
+ * @version $Id: BaseRegistry.java,v 1.3 2002/03/28 23:13:15 taylor Exp $
*/
public class BaseRegistry implements Registry
{
- private Map entries = new TreeMap();
+ protected Map entries = new TreeMap();
/** @see Registry#getEntryCount */
public int getEntryCount()
1.1 jakarta-jetspeed/src/java/org/apache/jetspeed/om/registry/base/BaseCategory.java
Index: BaseCategory.java
===================================================================
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2000-2001 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Apache" and "Apache Software Foundation" and
* "Apache Jetspeed" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache" or
* "Apache Jetspeed", nor may "Apache" appear in their name, without
* prior written permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.jetspeed.om.registry.base;
import java.util.Vector;
import java.util.Iterator;
import org.apache.jetspeed.om.registry.Category;
/**
* Bean like implementation of the Category interface suitable for
* Castor serialization.
*
* @see org.apache.jetspeed.om.registry.Security
* @author <a href="mailto:taylor@apache.org">David Sean Taylor</a>
* @version $Id: BaseCategory.java,v 1.1 2002/03/28 23:13:15 taylor Exp $
*/
public class BaseCategory implements Category
{
private String name;
private String group = "Jetspeed";
/** @return the string Name */
public String getName()
{
return name;
}
/** Sets the string Name
*
* @param value the new Name value
*/
public void setName(String name)
{
this.name = name;
}
/** @return the string Group */
public String getGroup()
{
return group;
}
/** Sets the string Group
*
* @param value the new Group value
*/
public void setGroup(String group)
{
this.group = group;
}
}
1.1 jakarta-jetspeed/src/java/org/apache/jetspeed/om/registry/base/CategoryIterator.java
Index: CategoryIterator.java
===================================================================
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2000-2001 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Apache" and "Apache Software Foundation" and
* "Apache Jetspeed" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache" or
* "Apache Jetspeed", nor may "Apache" appear in their name, without
* prior written permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.jetspeed.om.registry.base;
import java.util.Iterator;
import java.util.Vector;
import java.util.Map;
import java.util.TreeMap;
import java.util.SortedMap;
import java.util.HashMap;
import java.util.NoSuchElementException;
import java.lang.UnsupportedOperationException;
import java.lang.IllegalStateException;
import org.apache.jetspeed.om.registry.*;
import org.apache.jetspeed.services.Registry;
/**
* CategoryIterator - iterators over category treemap/hashmap allowing dups
*
*
* @author <a href="mailto:taylor@apache.org">David Sean Taylor</a>
* @version $Id: CategoryIterator.java,v 1.1 2002/03/28 23:13:15 taylor Exp $
*/
public class CategoryIterator implements Iterator
{
protected SortedMap map = null;
protected String key;
protected Iterator mapIterator = null;
protected Iterator bucketIterator = null;
protected boolean iteratingMaps = true;
protected HashMap bucket = null;
protected PortletEntry portlet = null;
protected boolean findall = false;
protected String category = "";
protected String group = "";
public String getCategory()
{
return category;
}
public String getGroup()
{
return group;
}
public CategoryIterator(SortedMap map, String key)
{
this.map = map;
this.key = key;
findall = (this.key == null || this.key.equals(""));
if (findall)
this.map = map;
else
this.map = map.tailMap(key);
this.mapIterator = this.map.entrySet().iterator();
this.bucketIterator = null;
this.bucket = null;
}
private CategoryIterator()
{}
public boolean hasNext()
{
if (iteratingMaps)
{
if (mapIterator.hasNext() == false)
return false;
return filter();
}
if (bucketIterator.hasNext())
return getPortletEntry();
// reached end of bucket, try next map
if (mapIterator.hasNext())
{
return filter();
}
return false; //reached end of maps
}
protected boolean filter()
{
java.util.Map.Entry entry = (java.util.Map.Entry)mapIterator.next();
String entryKey = (String)entry.getKey();
int pos = entryKey.indexOf('.');
this.category = "";
if (-1 == pos)
{
this.group = entryKey;
}
else
{
this.group = entryKey.substring(0, pos);
int length = entryKey.length();
if (length > pos + 1)
this.category = entryKey.substring(pos + 1, length);
}
if (!findall && !entryKey.startsWith(this.key))
return false; // end of criteria
bucket = (HashMap)entry.getValue();
bucketIterator = bucket.entrySet().iterator();
iteratingMaps = false;
if (bucketIterator.hasNext() == false)
return false;
return getPortletEntry();
}
protected boolean getPortletEntry()
{
java.util.Map.Entry entry = (java.util.Map.Entry)bucketIterator.next();
if (null == entry)
return false;
this.portlet = (PortletEntry)entry.getValue();
return true;
}
public void remove() throws IllegalStateException, UnsupportedOperationException
{
throw new UnsupportedOperationException("The remove() method is not supported");
}
public Object next() throws NoSuchElementException
{
return portlet;
}
}
1.1 jakarta-jetspeed/src/java/org/apache/jetspeed/om/registry/base/PortletIterator.java
Index: PortletIterator.java
===================================================================
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2000-2001 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Apache" and "Apache Software Foundation" and
* "Apache Jetspeed" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache" or
* "Apache Jetspeed", nor may "Apache" appear in their name, without
* prior written permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.jetspeed.om.registry.base;
import java.util.Iterator;
import java.util.Vector;
import java.util.Map;
import java.util.Hashtable;
import java.util.HashMap;
import java.util.NoSuchElementException;
import java.lang.UnsupportedOperationException;
import java.lang.IllegalStateException;
import org.apache.jetspeed.om.registry.*;
import org.apache.jetspeed.services.Registry;
/**
* PortletIterator - seamless iterator over nested vectors of portlet collections
*
*
* @author <a href="mailto:taylor@apache.org">David Sean Taylor</a>
* @version $Id: PortletIterator.java,v 1.1 2002/03/28 23:13:15 taylor Exp $
*/
public class PortletIterator implements Iterator
{
protected BasePortletEntry entry;
protected String method;
protected Vector vector ;
protected int index = 0;
public PortletIterator(BasePortletEntry entry, String method)
{
this.entry = entry;
this.method = method;
this.vector = getVector();
}
public boolean hasNext()
{
int size = vector.size();
if (size == 0)
return false;
if (index >= size)
{
entry = getParentEntry(entry);
if (entry == null)
return false;
vector = getVector();
if (vector == null)
{
return false;
}
index = 0;
if (vector.size() == 0)
return false;
}
return true;
}
public void remove() throws IllegalStateException, UnsupportedOperationException
{
throw new UnsupportedOperationException("The remove() method is not supported");
}
protected BasePortletEntry getParentEntry(BasePortletEntry entry)
{
String parentName = entry.getParent();
if (parentName == null || parentName.equals(""))
return null;
BasePortletEntry parent = null;
parent = (BasePortletEntry)Registry.getEntry( Registry.PORTLET, entry.getParent() );
return parent;
}
public Object next() throws NoSuchElementException
{
Object o = vector.elementAt(index);
index++;
return o;
}
protected Vector getVector()
{
try
{
this.vector = (Vector)this.entry.getClass().getMethod(this.method, null).invoke(this.entry, null);
}
catch (Exception e)
{
this.vector = null;
}
return this.vector;
}
}
1.14 +5 -2 jakarta-jetspeed/src/java/org/apache/jetspeed/services/registry/CastorRegistryService.java
Index: CastorRegistryService.java
===================================================================
RCS file: /home/cvs/jakarta-jetspeed/src/java/org/apache/jetspeed/services/registry/CastorRegistryService.java,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -r1.13 -r1.14
--- CastorRegistryService.java 19 Mar 2002 16:18:14 -0000 1.13
+++ CastorRegistryService.java 28 Mar 2002 23:13:15 -0000 1.14
@@ -102,7 +102,7 @@
* </p>
*
* @author <a href="mailto:raphael@apache.org">Rapha�l Luta</a>
- * @version $Id: CastorRegistryService.java,v 1.13 2002/03/19 16:18:14 kimptoc Exp $
+ * @version $Id: CastorRegistryService.java,v 1.14 2002/03/28 23:13:15 taylor Exp $
*/
public class CastorRegistryService
extends TurbineBaseService
@@ -380,7 +380,10 @@
if (registry==null)
{
- registry = new BaseRegistry();
+ if (name.equals(org.apache.jetspeed.services.Registry.PORTLET))
+ registry = new BasePortletRegistry();
+ else
+ registry = new BaseRegistry();
registries.put(name,registry);
}
1.2 +23 -1 jakarta-jetspeed/src/java/org/apache/jetspeed/services/registry/TestMarshallRegistry.java
Index: TestMarshallRegistry.java
===================================================================
RCS file: /home/cvs/jakarta-jetspeed/src/java/org/apache/jetspeed/services/registry/TestMarshallRegistry.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- TestMarshallRegistry.java 26 Mar 2002 09:03:19 -0000 1.1
+++ TestMarshallRegistry.java 28 Mar 2002 23:13:15 -0000 1.2
@@ -34,7 +34,7 @@
* TestMarshallRegistry
*
* @author <a href="taylor@apache.org">David Sean Taylor</a>
- * @version $Id: TestMarshallRegistry.java,v 1.1 2002/03/26 09:03:19 taylor Exp $
+ * @version $Id: TestMarshallRegistry.java,v 1.2 2002/03/28 23:13:15 taylor Exp $
*/
public class TestMarshallRegistry extends TestCase {
@@ -242,6 +242,28 @@
assertNotNull(cp);
assertTrue(cp.isCachedOnName() == true);
assertTrue(cp.isCachedOnValue() == true);
+
+ // categories
+ PortletEntry feeder = (PortletEntry)portlets.elementAt(3);
+ assertNotNull(feeder);
+ assertTrue(feeder.getName().equals("Feeder"));
+ assertTrue(feeder.getType().equals("ref"));
+ Iterator fi = feeder.listCategories();
+ Category cat = (Category)fi.next();
+ assertTrue(cat.getName().equals("news.world.politics"));
+ assertTrue(cat.getGroup().equals("news"));
+ assertTrue(feeder.hasCategory("news.world.politics", "news"));
+ feeder.addCategory("news.us.economy");
+ assertTrue(feeder.hasCategory("news.us.economy"));
+ feeder.removeCategory("news.us.economy");
+ assertTrue(!feeder.hasCategory("news.us.economy"));
+ /*
+ Iterator fi = feeder.listCategories();
+ Category cat = (Category)fi.next();
+ System.out.println("cat = " + cat.getName());
+ System.out.println("cat.group = " + cat.getGroup());
+ }
+ */
}
catch (Exception e)
{
1.1 jakarta-jetspeed/src/java/org/apache/jetspeed/services/registry/TestRegistryCategories.java
Index: TestRegistryCategories.java
===================================================================
package org.apache.jetspeed.services.registry;
import java.io.File;
import java.io.FileReader;
import java.util.Vector;
import java.util.Iterator;
import java.util.HashMap;
import java.util.Map;
import java.util.TreeMap;
import java.util.SortedMap;
// Junit imports
import junit.framework.Test;
import junit.framework.TestSuite;
import junit.framework.TestCase;
import org.apache.jetspeed.om.registry.*;
import org.apache.turbine.services.TurbineServices;
import org.apache.jetspeed.services.idgenerator.*;
import org.apache.stratum.configuration.Configuration;
import org.apache.stratum.configuration.PropertiesConfiguration;
import org.apache.turbine.util.TurbineConfig;
import org.apache.turbine.util.StringUtils;
import org.apache.jetspeed.services.Registry;
import org.apache.jetspeed.om.registry.base.CategoryIterator;
/**
* TestRegistryCategories
*
* @author <a href="taylor@apache.org">David Sean Taylor</a>
* @version $Id: TestRegistryCategories.java,v 1.1 2002/03/28 23:13:15 taylor Exp $
*/
public class TestRegistryCategories extends TestCase {
/**
* Defines the testcase name for JUnit.
*
* @param name the testcase's name.
*/
public TestRegistryCategories( String name ) {
super( name );
}
/**
* Start the tests.
*
* @param args the arguments. Not used
*/
public static void main(String args[]) {
junit.awtui.TestRunner.main( new String[] { TestRegistryCategories.class.getName() } );
}
public void setup() {
System.out.println("Setup: Testing categories of Registry");
}
/**
* Creates the test suite.
*
* @return a test suite (<code>TestSuite</code>) that includes all methods
* starting with "test"
*/
public static Test suite() {
// All methods starting with "test" will be executed in the test suite.
return new TestSuite( TestRegistryCategories.class );
}
/**
* Tests categories
* @throws Exception
*/
public void testCategories() throws Exception
{
try
{
PortletRegistry registry = (PortletRegistry)Registry.get(Registry.PORTLET);
PortletEntry pe = (PortletEntry)registry.getEntry("RSS");
assertNotNull(pe);
Iterator iterator = registry.findPortletsByCategory("news");
int count = 0;
init();
PortletEntry rss;
while (iterator.hasNext())
{
rss = (PortletEntry)iterator.next();
print(iterator, rss);
count++;
}
System.out.println("[news] count = " + count);
System.out.println("------------------");
assertTrue(count == 1);
registry.removeEntry(pe);
iterator = registry.findPortletsByCategory("news");
assertTrue(iterator.hasNext() == false);
registry.addEntry(pe);
iterator = registry.findPortletsByCategory("news");
assertTrue(iterator.hasNext());
rss = (PortletEntry)iterator.next();
Iterator cats = rss.listCategories();
assertNotNull(cats);
assertTrue(cats.hasNext());
Category cat = (Category)cats.next();
assertTrue(cat.getName().startsWith("news"));
iterator = registry.listByCategory();
count = 0;
init();
while (iterator.hasNext())
{
PortletEntry entry = (PortletEntry)iterator.next();
// print(iterator, entry);
count++;
}
System.out.println("[Everything] count = " + count);
System.out.println("------------------");
iterator = registry.findPortletsByCategory("General");
count = 0;
init();
while (iterator.hasNext())
{
PortletEntry entry = (PortletEntry)iterator.next();
//print(iterator, entry);
count++;
}
System.out.println("[General] count = " + count);
System.out.println("------------------");
iterator = registry.findPortletsByGroupCategory("base", "news.xml.rss");
count = 0;
init();
while (iterator.hasNext())
{
PortletEntry entry = (PortletEntry)iterator.next();
//print(iterator, entry);
count++;
}
System.out.println("[base][xml.rss] count = " + count);
System.out.println("------------------");
iterator = registry.findPortletsByCategory("");
count = 0;
init();
while (iterator.hasNext())
{
PortletEntry entry = (PortletEntry)iterator.next();
//print(iterator, entry);
count++;
}
System.out.println("[] count = " + count);
System.out.println("------------------");
iterator = registry.findPortletsByGroupCategory("", "");
count = 0;
init();
while (iterator.hasNext())
{
PortletEntry entry = (PortletEntry)iterator.next();
//print(iterator, entry);
count++;
}
System.out.println("[][] count = " + count);
System.out.println("------------------");
iterator = registry.findPortletsByGroupCategory("Jetspeed", "");
count = 0;
init();
while (iterator.hasNext())
{
PortletEntry entry = (PortletEntry)iterator.next();
//print(iterator, entry);
count++;
}
System.out.println("[Jetspeed][] count = " + count);
System.out.println("------------------");
iterator = registry.findPortletsByCategory("news");
count = 0;
init();
while (iterator.hasNext())
{
PortletEntry entry = (PortletEntry)iterator.next();
//print(iterator, entry);
count++;
}
System.out.println("[news] count = " + count);
System.out.println("------------------");
// SortedMap sm = tree.tailMap("sports");
// Iterator it = sm.keySet().iterator();
}
catch (Exception e)
{
String errmsg = "Error in category test: " + e.toString();
// e.printStackTrace();
assertNotNull(errmsg, null);
}
}
private String lastGroup = "";
private String lastCategory = "";
private void init()
{
lastGroup = "";
lastCategory = "";
}
private void print(Iterator iterator, PortletEntry entry)
{
String group = ((CategoryIterator)iterator).getGroup();
String category = ((CategoryIterator)iterator).getCategory();
if (!lastGroup.equals(group))
{
System.out.println("Group: [" + group + "]");
lastGroup = group;
}
if (!lastCategory.equals(category))
{
System.out.println("....Cat: [" + category + "]");
lastCategory = category;
}
System.out.println("........" + entry.getName());
}
/**
* Tests IdentityElement unmarshaling entryset base stuff
* @throws Exception
*/
/*
Configuration object to run Turbine outside a servlet container
( uses turbine.properties )
*/
private static TurbineConfig config = null;
/*
Sets up TurbineConfig using the system property:
<pre>turbine.properties</pre>
*/
static
{
try
{
config = new TurbineConfig( "../webapp", "/WEB-INF/conf/TurbineResources.properties");
config.init();
}
catch (Exception e)
{
fail(StringUtils.stackTrace(e));
}
}
}
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>