Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: DSpace/DSpace
...
head fork: aschweer/DSpace
Checking mergeability… Don't worry, you can still create the pull request.
  • 1 commit
  • 6 files changed
  • 0 commit comments
  • 1 contributor
Commits on Jul 11, 2012
@aschweer aschweer Unify display of a community's child communities/collections and glob…
…al community list.

Community pages show a list of all direct sub-communities and all subcollections. As part of this commit, the generation of this list
is separated out into its own transformer, CommunityChildren, rather than being squashed into the CommunityViewer. The list of
sub-communities and collections is very similar to that shown on the repository front page and on the community list page, both of
which are generated by CommunityBrowser. As part of this commit, the code that generates the list is separated out into a helper class
which is then used by both CommunityBrowser and CommunityChildren.

The advantage of this approach, apart from reducing code-duplication, is that modifications such as the collapsible community list
(https://wiki.duraspace.org/display/DSPACE/Add+expanding+and+collapsing+interface+to+community-list+hierarchy+%28Manakin%29) can then
be used on community pages as well.

Squashed commit of the following:

commit 4d26438ac776c297bd6401205767a01180845fd7
Author: Andrea Schweer <schweer@waikato.ac.nz>
Date:   Wed Jul 11 17:41:35 2012 +0100

    Make depth configurable and set to 1 to match legacy behaviour

commit aee7195aff0e6e2c33f52b32645d46778a2ae511
Author: Andrea Schweer <schweer@waikato.ac.nz>
Date:   Wed Jul 11 16:37:43 2012 +0100

    Add and use new class to render community children

commit 8c9ed16553cfe3b729806cc60c4672eddd905ff4
Author: Andrea Schweer <schweer@waikato.ac.nz>
Date:   Wed Jul 11 16:36:40 2012 +0100

    Stop CommunityViewer from adding child communities/collections

commit a20f73bab801dc9147cbbde5315da60c7a649e69
Author: Andrea Schweer <schweer@waikato.ac.nz>
Date:   Wed Jul 11 16:36:03 2012 +0100

    Refactor out tree creation code for re-use elsewhere
cacf6b8
View
320 ...e-xmlui/dspace-xmlui-api/src/main/java/org/dspace/app/xmlui/aspect/artifactbrowser/CommunityBrowser.java
@@ -10,9 +10,7 @@
import java.io.IOException;
import java.io.Serializable;
import java.sql.SQLException;
-import java.util.ArrayList;
import java.util.Map;
-import java.util.Stack;
import org.apache.avalon.framework.parameters.Parameters;
import org.apache.cocoon.ProcessingException;
@@ -22,6 +20,7 @@
import org.apache.excalibur.source.SourceValidity;
import org.apache.log4j.Logger;
import org.dspace.app.xmlui.cocoon.AbstractDSpaceTransformer;
+import org.dspace.app.xmlui.utils.CommunityTreeHelper;
import org.dspace.app.xmlui.utils.DSpaceValidity;
import org.dspace.app.xmlui.utils.UIException;
import org.dspace.app.xmlui.wing.Message;
@@ -30,16 +29,9 @@
import org.dspace.app.xmlui.wing.element.Division;
import org.dspace.app.xmlui.wing.element.ReferenceSet;
import org.dspace.app.xmlui.wing.element.List;
-import org.dspace.app.xmlui.wing.element.Reference;
import org.dspace.app.xmlui.wing.element.PageMeta;
import org.dspace.authorize.AuthorizeException;
-import org.dspace.browse.ItemCountException;
-import org.dspace.browse.ItemCounter;
-import org.dspace.content.Collection;
-import org.dspace.content.Community;
-import org.dspace.content.DSpaceObject;
import org.dspace.core.ConfigurationManager;
-import org.dspace.core.Constants;
import org.dspace.core.LogManager;
import org.xml.sax.SAXException;
@@ -77,18 +69,14 @@
/** Should collections be excluded from the list */
protected boolean excludeCollections = false;
- /** The default depth if one is not provided by the sitemap */
- private static final int DEFAULT_DEPTH = 999;
-
/** What depth is the maximum depth of the tree */
- protected int depth = DEFAULT_DEPTH;
+ protected int depth;
- /** Cached version the community / collection hierarchy */
- protected TreeNode root;
-
/** cached validity object */
private SourceValidity validity;
-
+
+ private CommunityTreeHelper helper;
+
/**
* Set the component up, pulling any configuration values from the sitemap
* parameters.
@@ -99,9 +87,11 @@ public void setup(SourceResolver resolver, Map objectModel, String src,
{
super.setup(resolver, objectModel, src, parameters);
- depth = parameters.getParameterAsInteger("depth", DEFAULT_DEPTH);
+ depth = parameters.getParameterAsInteger("depth", CommunityTreeHelper.DEFAULT_DEPTH);
excludeCollections = parameters.getParameterAsBoolean(
"exclude-collections", false);
+
+ helper = new CommunityTreeHelper(context, depth, excludeCollections);
}
/**
@@ -126,44 +116,8 @@ public SourceValidity getValidity()
{
try {
DSpaceValidity validity = new DSpaceValidity();
-
- TreeNode root = buildTree(Community.findAllTop(context));
-
- Stack<TreeNode> stack = new Stack<TreeNode>();
- stack.push(root);
-
- while (!stack.empty())
- {
- TreeNode node = stack.pop();
-
- validity.add(node.getDSO());
-
- // If we are configured to use collection strengths (i.e. item counts) then include that number in the validity.
- boolean useCache = ConfigurationManager.getBooleanProperty("webui.strengths.cache");
- if (useCache)
- {
- try
- { //try to determine Collection size (i.e. # of items)
-
- int size = new ItemCounter(context).getCount(node.getDSO());
- validity.add("size:"+size);
- }
- catch(ItemCountException e) { /* ignore */ }
- }
-
-
- for (TreeNode child : node.getChildren())
- {
- stack.push(child);
- }
- }
-
- // Check if we are configured to assume validity.
- String assumeCacheValidity = ConfigurationManager.getProperty("xmlui.community-list.cache");
- if (assumeCacheValidity != null)
- {
- validity.setAssumedValidityDelay(assumeCacheValidity);
- }
+
+ helper.addToValidity(validity, null);
this.validity = validity.complete();
}
@@ -201,274 +155,32 @@ public void addBody(Body body) throws SAXException, WingException,
division.setHead(T_head);
division.addPara(T_select);
- TreeNode root = buildTree(Community.findAllTop(context));
-
boolean full = ConfigurationManager.getBooleanProperty("xmlui.community-list.render.full", true);
if (full)
{
ReferenceSet referenceSet = division.addReferenceSet("community-browser",
ReferenceSet.TYPE_SUMMARY_LIST,null,"hierarchy");
-
- java.util.List<TreeNode> rootNodes = root.getChildrenOfType(Constants.COMMUNITY);
-
- for (TreeNode node : rootNodes)
- {
- buildReferenceSet(referenceSet,node);
- }
+
+ helper.makeReferenceSet(referenceSet, null);
}
else
{
List list = division.addList("comunity-browser");
+
+ helper.makeList(contextPath, list, null);
- java.util.List<TreeNode> rootNodes = root.getChildrenOfType(Constants.COMMUNITY);
-
- for (TreeNode node : rootNodes)
- {
- buildList(list,node);
- }
-
- }
- }
-
- /**
- * Recursively build an includeset of the community / collection hierarchy based upon
- * the given NodeTree.
- *
- * @param referenceSet The include set
- * @param node The current node of the hierarchy.
- */
- public void buildReferenceSet(ReferenceSet referenceSet, TreeNode node) throws WingException
- {
- DSpaceObject dso = node.getDSO();
-
- Reference objectInclude = referenceSet.addReference(dso);
-
- // Add all the sub-collections;
- java.util.List<TreeNode> collectionNodes = node.getChildrenOfType(Constants.COLLECTION);
- if (collectionNodes != null && collectionNodes.size() > 0)
- {
- ReferenceSet collectionSet = objectInclude.addReferenceSet(ReferenceSet.TYPE_SUMMARY_LIST);
-
- for (TreeNode collectionNode : collectionNodes)
- {
- collectionSet.addReference(collectionNode.getDSO());
- }
- }
-
- // Add all the sub-communities
- java.util.List<TreeNode> communityNodes = node.getChildrenOfType(Constants.COMMUNITY);
- if (communityNodes != null && communityNodes.size() > 0)
- {
- ReferenceSet communitySet = objectInclude.addReferenceSet(ReferenceSet.TYPE_SUMMARY_LIST);
-
- for (TreeNode communityNode : communityNodes)
- {
- buildReferenceSet(communitySet,communityNode);
- }
- }
- }
-
- /**
- * Recursively build a list of the community / collection hierarchy based upon
- * the given NodeTree.
- *
- * @param list The parent list
- * @param node The current node of the hierarchy.
- */
- public void buildList(List list, TreeNode node) throws WingException
- {
- DSpaceObject dso = node.getDSO();
-
- String name = null;
- if (dso instanceof Community)
- {
- name = ((Community) dso).getMetadata("name");
- }
- else if (dso instanceof Collection)
- {
- name = ((Collection) dso).getMetadata("name");
- }
-
- String url = contextPath + "/handle/"+dso.getHandle();
- list.addItem().addHighlight("bold").addXref(url, name);
-
- List subList = null;
-
- // Add all the sub-collections;
- java.util.List<TreeNode> collectionNodes = node.getChildrenOfType(Constants.COLLECTION);
- if (collectionNodes != null && collectionNodes.size() > 0)
- {
- subList = list.addList("sub-list-"+dso.getID());
-
- for (TreeNode collectionNode : collectionNodes)
- {
- String collectionName = ((Collection) collectionNode.getDSO()).getMetadata("name");
- String collectionUrl = contextPath + "/handle/"+collectionNode.getDSO().getHandle();
- subList.addItemXref(collectionUrl, collectionName);
- }
- }
-
-
- // Add all the sub-communities
- java.util.List<TreeNode> communityNodes = node.getChildrenOfType(Constants.COMMUNITY);
- if (communityNodes != null && communityNodes.size() > 0)
- {
- if (subList == null)
- {
- subList = list.addList("sub-list-" + dso.getID());
- }
-
- for (TreeNode communityNode : communityNodes)
- {
- buildList(subList,communityNode);
- }
}
}
-
+
/**
* recycle
*/
public void recycle()
{
- this.root = null;
+ helper.reset();
this.validity = null;
super.recycle();
}
- /**
- * construct a tree structure of communities and collections. The results
- * of this hierarchy are cached so calling it multiple times is acceptable.
- *
- * @param communities The root level communities
- * @return A root level node.
- */
- private TreeNode buildTree(Community[] communities) throws SQLException
- {
- if (root != null)
- {
- return root;
- }
-
- TreeNode newRoot = new TreeNode();
-
- // Setup for breath-first traversal
- Stack<TreeNode> stack = new Stack<TreeNode>();
-
- for (Community community : communities)
- {
- stack.push(newRoot.addChild(community));
- }
-
- while (!stack.empty())
- {
- TreeNode node = stack.pop();
-
- // Short circuit if we have reached our max depth.
- if (node.getLevel() >= this.depth)
- {
- continue;
- }
-
- // Only communities nodes are pushed on the stack.
- Community community = (Community) node.getDSO();
-
- for (Community subcommunity : community.getSubcommunities())
- {
- stack.push(node.addChild(subcommunity));
- }
-
- // Add any collections to the document.
- if (!excludeCollections)
- {
- for (Collection collection : community.getCollections())
- {
- node.addChild(collection);
- }
- }
- }
-
- this.root = newRoot;
- return root;
- }
-
- /**
- * Private class to represent the tree structure of communities & collections.
- */
- protected static class TreeNode
- {
- /** The object this node represents */
- private DSpaceObject dso;
-
- /** The level in the hierarchy that this node is at. */
- private int level;
-
- /** All children of this node */
- private java.util.List<TreeNode> children = new ArrayList<TreeNode>();
-
- /**
- * Construct a new root level node
- */
- public TreeNode()
- {
- // Root level node is add the zero level.
- this.level = 0;
- }
-
- /**
- * @return The DSpaceObject this node represents
- */
- public DSpaceObject getDSO()
- {
- return this.dso;
- }
-
- /**
- * Add a child DSpaceObject
- *
- * @param dso The child
- * @return A new TreeNode object attached to the tree structure.
- */
- public TreeNode addChild(DSpaceObject dso)
- {
- TreeNode child = new TreeNode();
- child.dso = dso;
- child.level = this.level + 1;
- children.add(child);
- return child;
- }
-
- /**
- * @return The current level in the hierarchy of this node.
- */
- public int getLevel()
- {
- return this.level;
- }
-
- /**
- * @return All children
- */
- public java.util.List<TreeNode> getChildren()
- {
- return children;
- }
-
- /**
- * @return All children of the given @type.
- */
- public java.util.List<TreeNode> getChildrenOfType(int type)
- {
- java.util.List<TreeNode> results = new ArrayList<TreeNode>();
- for (TreeNode node : children)
- {
- if (node.dso.getType() == type)
- {
- results.add(node);
- }
- }
- return results;
- }
- }
-
}
View
175 ...-xmlui/dspace-xmlui-api/src/main/java/org/dspace/app/xmlui/aspect/artifactbrowser/CommunityChildren.java
@@ -0,0 +1,175 @@
+/**
+ * The contents of this file are subject to the license and copyright
+ * detailed in the LICENSE and NOTICE files at the root of the source
+ * tree and available online at
+ *
+ * http://www.dspace.org/license/
+ */
+package org.dspace.app.xmlui.aspect.artifactbrowser;
+
+import org.apache.avalon.framework.parameters.Parameters;
+import org.apache.cocoon.ProcessingException;
+import org.apache.cocoon.caching.CacheableProcessingComponent;
+import org.apache.cocoon.environment.SourceResolver;
+import org.apache.cocoon.util.HashUtil;
+import org.apache.excalibur.source.SourceValidity;
+import org.dspace.app.xmlui.cocoon.AbstractDSpaceTransformer;
+import org.dspace.app.xmlui.utils.CommunityTreeHelper;
+import org.dspace.app.xmlui.utils.DSpaceValidity;
+import org.dspace.app.xmlui.utils.HandleUtil;
+import org.dspace.app.xmlui.utils.UIException;
+import org.dspace.app.xmlui.wing.Message;
+import org.dspace.app.xmlui.wing.WingException;
+import org.dspace.app.xmlui.wing.element.Body;
+import org.dspace.app.xmlui.wing.element.Division;
+import org.dspace.app.xmlui.wing.element.ReferenceSet;
+import org.dspace.authorize.AuthorizeException;
+import org.dspace.content.Collection;
+import org.dspace.content.Community;
+import org.dspace.content.DSpaceObject;
+import org.xml.sax.SAXException;
+
+import java.io.IOException;
+import java.io.Serializable;
+import java.sql.SQLException;
+import java.util.Map;
+
+/**
+ * Display the children (sub-communities and collections) of a community.
+ * @author Andrea Schweer
+ */
+public class CommunityChildren extends AbstractDSpaceTransformer implements CacheableProcessingComponent
+{
+
+ /** Cached validity object */
+ private DSpaceValidity validity;
+
+ private CommunityTreeHelper helper;
+ private static final Message T_head_community_children =
+ message("xmlui.ArtifactBrowser.CommunityChildren.head_community_children");
+ private int depth;
+
+ /**
+ * Set the component up, pulling any configuration values from the sitemap
+ * parameters.
+ */
+ public void setup(SourceResolver resolver, Map objectModel, String src,
+ Parameters parameters) throws ProcessingException, SAXException,
+ IOException
+ {
+ super.setup(resolver, objectModel, src, parameters);
+ depth = parameters.getParameterAsInteger("depth", CommunityTreeHelper.DEFAULT_DEPTH);
+
+ helper = new CommunityTreeHelper(context, depth, false);
+ }
+
+ @Override
+ public void addBody(Body body) throws SAXException, WingException, UIException, SQLException, IOException, AuthorizeException, ProcessingException {
+ DSpaceObject dso = HandleUtil.obtainHandle(objectModel);
+ if (!(dso instanceof Community))
+ {
+ return;
+ }
+
+ // Set up the major variables
+ Community community = (Community) dso;
+ Collection[] collections = community.getCollections();
+
+ if (community.getSubcommunities().length == 0 && collections.length == 0) {
+ // there are no children -- just stop
+ return;
+ }
+
+ // Build the community viewer division.
+ Division home = body.addDivision("community-home", "primary repository community");
+
+ Division parent = home.addDivision("community-children", "secondary children");
+
+ ReferenceSet referenceSet = parent.addReferenceSet("community-children-reference",
+ ReferenceSet.TYPE_SUMMARY_LIST,null,"hierarchy");
+
+ helper.makeReferenceSet(referenceSet, community);
+
+ if (collections != null && collections.length > 0)
+ {
+ // Sub collections
+ for (Collection collection : collections) {
+ referenceSet.addReference(collection);
+ }
+
+ }
+ referenceSet.setHead(T_head_community_children.parameterize(community.getName()));
+ }
+
+ /**
+ * Generate the unique caching key.
+ * This key must be unique inside the space of this component.
+ */
+ public Serializable getKey() {
+ try {
+ DSpaceObject dso = HandleUtil.obtainHandle(objectModel);
+
+ if (dso == null)
+ {
+ return "0"; // no item, something is wrong
+ }
+
+ return HashUtil.hash(dso.getHandle() + "-" + depth);
+ }
+ catch (SQLException sqle)
+ {
+ // Ignore all errors and just return that the component is not cachable.
+ return "0";
+ }
+ }
+
+
+ /**
+ * Generate the cache validity object.
+ *
+ * This validity object includes all sub-communites of the community being viewed
+ * (to the appropriate depth) and all sub-collections.
+ */
+ public SourceValidity getValidity()
+ {
+ if (this.validity == null)
+ {
+ try {
+ DSpaceObject dso = HandleUtil.obtainHandle(objectModel);
+
+ if (dso == null)
+ {
+ return null;
+ }
+
+ if (!(dso instanceof Community))
+ {
+ return null;
+
+ }
+
+ helper.addToValidity(validity, (Community) dso);
+
+ this.validity = validity.complete();
+ }
+ catch (Exception e)
+ {
+ // Ignore all errors and invalidate the cache.
+ }
+
+ }
+ return this.validity;
+ }
+
+
+ /**
+ * Recycle
+ */
+ public void recycle()
+ {
+ // Clear out our item's cache.
+ this.validity = null;
+ helper.reset();
+ super.recycle();
+ }
+}
View
76 ...ce-xmlui/dspace-xmlui-api/src/main/java/org/dspace/app/xmlui/aspect/artifactbrowser/CommunityViewer.java
@@ -70,14 +70,6 @@
private static final Message T_browse_dates =
message("xmlui.ArtifactBrowser.CommunityViewer.browse_dates");
-
-
- private static final Message T_head_sub_communities =
- message("xmlui.ArtifactBrowser.CommunityViewer.head_sub_communities");
-
- private static final Message T_head_sub_collections =
- message("xmlui.ArtifactBrowser.CommunityViewer.head_sub_collections");
-
/** Cached validity object */
private SourceValidity validity;
@@ -133,39 +125,6 @@ public SourceValidity getValidity()
DSpaceValidity validity = new DSpaceValidity();
validity.add(community);
-
- Community[] subCommunities = community.getSubcommunities();
- Collection[] collections = community.getCollections();
- // Sub communities
- for (Community subCommunity : subCommunities)
- {
- validity.add(subCommunity);
-
- // Include the item count in the validity, only if the value is cached.
- boolean useCache = ConfigurationManager.getBooleanProperty("webui.strengths.cache");
- if (useCache)
- {
- try {
- int size = new ItemCounter(context).getCount(subCommunity);
- validity.add("size:"+size);
- } catch(ItemCountException e) { /* ignore */ }
- }
- }
- // Sub collections
- for (Collection collection : collections)
- {
- validity.add(collection);
-
- // Include the item count in the validity, only if the value is cached.
- boolean useCache = ConfigurationManager.getBooleanProperty("webui.strengths.cache");
- if (useCache)
- {
- try {
- int size = new ItemCounter(context).getCount(collection);
- validity.add("size:"+size);
- } catch(ItemCountException e) { /* ignore */ }
- }
- }
this.validity = validity.complete();
}
@@ -246,8 +205,6 @@ public void addBody(Body body) throws SAXException, WingException,
// Set up the major variables
Community community = (Community) dso;
- Community[] subCommunities = community.getSubcommunities();
- Collection[] collections = community.getCollections();
// Build the community viewer division.
Division home = body.addDivision("community-home", "primary repository community");
@@ -305,38 +262,9 @@ public void addBody(Body body) throws SAXException, WingException,
ReferenceSet referenceSet = viewer.addReferenceSet("community-view",
ReferenceSet.TYPE_DETAIL_VIEW);
- Reference communityInclude = referenceSet.addReference(community);
-
- // If the community has any children communities also reference them.
- if (subCommunities != null && subCommunities.length > 0)
- {
- ReferenceSet communityReferenceSet = communityInclude
- .addReferenceSet(ReferenceSet.TYPE_SUMMARY_LIST,null,"hierarchy");
-
- communityReferenceSet.setHead(T_head_sub_communities);
-
- // Subcommunities
- for (Community subCommunity : subCommunities)
- {
- communityReferenceSet.addReference(subCommunity);
- }
- }
- if (collections != null && collections.length > 0)
- {
- ReferenceSet communityReferenceSet = communityInclude
- .addReferenceSet(ReferenceSet.TYPE_SUMMARY_LIST,null,"hierarchy");
-
- communityReferenceSet.setHead(T_head_sub_collections);
-
- // Subcollections
- for (Collection collection : collections)
- {
- communityReferenceSet.addReference(collection);
- }
-
- }
- } // main reference
+ referenceSet.addReference(community);
+ }// main reference
}
View
355 dspace-xmlui/dspace-xmlui-api/src/main/java/org/dspace/app/xmlui/utils/CommunityTreeHelper.java
@@ -0,0 +1,355 @@
+/**
+ * The contents of this file are subject to the license and copyright
+ * detailed in the LICENSE and NOTICE files at the root of the source
+ * tree and available online at
+ *
+ * http://www.dspace.org/license/
+ */
+package org.dspace.app.xmlui.utils;
+
+import org.dspace.app.xmlui.wing.WingException;
+import org.dspace.app.xmlui.wing.element.List;
+import org.dspace.app.xmlui.wing.element.Reference;
+import org.dspace.app.xmlui.wing.element.ReferenceSet;
+import org.dspace.browse.ItemCountException;
+import org.dspace.browse.ItemCounter;
+import org.dspace.content.Collection;
+import org.dspace.content.Community;
+import org.dspace.content.DSpaceObject;
+import org.dspace.core.ConfigurationManager;
+import org.dspace.core.Constants;
+import org.dspace.core.Context;
+
+import java.sql.SQLException;
+import java.util.ArrayList;
+import java.util.Stack;
+
+/**
+ * Helper class to hold methods common to creating community trees, as used in the community list and when showing a community's children.
+ * @author Andrea Schweer
+ */
+public class CommunityTreeHelper {
+
+ public static final int DEFAULT_DEPTH = 999;
+
+ /** Cached version the community / collection hierarchy */
+ private CommunityTreeHelper.TreeNode root;
+ private Context context;
+ private int depth;
+ private boolean excludeCollections;
+
+
+ public CommunityTreeHelper(Context context, int depth, boolean excludeCollections) {
+ this.context = context;
+ this.depth = depth;
+ this.excludeCollections = excludeCollections;
+ }
+
+ public CommunityTreeHelper(Context context, boolean excludeCollections) {
+ this(context, DEFAULT_DEPTH, excludeCollections);
+ }
+
+ private CommunityTreeHelper.TreeNode getRoot(Community parent) throws SQLException {
+ if (root == null) {
+ if (parent != null) {
+ root = buildTree(parent.getSubcommunities());
+ } else {
+ root = buildTree(Community.findAllTop(context));
+ }
+ }
+ return root;
+ }
+
+ /**
+ * Recursively build an includeset of the community / collection hierarchy based upon
+ * the given NodeTree.
+ *
+ * @param referenceSet The include set
+ * @param node The current node of the hierarchy.
+ */
+ public void buildReferenceSet(ReferenceSet referenceSet, TreeNode node) throws WingException
+ {
+ DSpaceObject dso = node.getDSO();
+
+ Reference objectInclude = referenceSet.addReference(dso);
+
+ // Add all the sub-collections;
+ java.util.List<TreeNode> collectionNodes = node.getChildrenOfType(Constants.COLLECTION);
+ if (collectionNodes != null && collectionNodes.size() > 0)
+ {
+ ReferenceSet collectionSet = objectInclude.addReferenceSet(ReferenceSet.TYPE_SUMMARY_LIST);
+
+ for (TreeNode collectionNode : collectionNodes)
+ {
+ collectionSet.addReference(collectionNode.getDSO());
+ }
+ }
+
+ // Add all the sub-communities
+ java.util.List<TreeNode> communityNodes = node.getChildrenOfType(Constants.COMMUNITY);
+ if (communityNodes != null && communityNodes.size() > 0)
+ {
+ ReferenceSet communitySet = objectInclude.addReferenceSet(ReferenceSet.TYPE_SUMMARY_LIST);
+
+ for (TreeNode communityNode : communityNodes)
+ {
+ buildReferenceSet(communitySet,communityNode);
+ }
+ }
+ }
+
+ /**
+ * Recursively build a list of the community / collection hierarchy based upon
+ * the given NodeTree.
+ *
+ * @param contextPath
+ * @param list The parent list
+ * @param node The current node of the hierarchy.
+ */
+ public void buildList(String contextPath, List list, TreeNode node) throws WingException
+ {
+ DSpaceObject dso = node.getDSO();
+
+ String name = null;
+ if (dso instanceof Community)
+ {
+ name = ((Community) dso).getMetadata("name");
+ }
+ else if (dso instanceof Collection)
+ {
+ name = ((Collection) dso).getMetadata("name");
+ }
+
+ String url = contextPath + "/handle/"+dso.getHandle();
+ list.addItem().addHighlight("bold").addXref(url, name);
+
+ List subList = null;
+
+ // Add all the sub-collections;
+ java.util.List<TreeNode> collectionNodes = node.getChildrenOfType(Constants.COLLECTION);
+ if (collectionNodes != null && collectionNodes.size() > 0)
+ {
+ subList = list.addList("sub-list-"+dso.getID());
+
+ for (TreeNode collectionNode : collectionNodes)
+ {
+ String collectionName = ((Collection) collectionNode.getDSO()).getMetadata("name");
+ String collectionUrl = contextPath + "/handle/"+collectionNode.getDSO().getHandle();
+ subList.addItemXref(collectionUrl, collectionName);
+ }
+ }
+
+
+ // Add all the sub-communities
+ java.util.List<TreeNode> communityNodes = node.getChildrenOfType(Constants.COMMUNITY);
+ if (communityNodes != null && communityNodes.size() > 0)
+ {
+ if (subList == null)
+ {
+ subList = list.addList("sub-list-" + dso.getID());
+ }
+
+ for (TreeNode communityNode : communityNodes)
+ {
+ buildList(contextPath, subList,communityNode);
+ }
+ }
+ }
+
+ public void addToValidity(DSpaceValidity validity, Community parent) throws SQLException {
+ TreeNode root = getRoot(parent);
+
+ Stack<TreeNode> stack = new Stack<TreeNode>();
+ stack.push(root);
+
+ while (!stack.empty())
+ {
+ TreeNode node = stack.pop();
+
+ validity.add(node.getDSO());
+
+ // If we are configured to use collection strengths (i.e. item counts) then include that number in the validity.
+ boolean useCache = ConfigurationManager.getBooleanProperty("webui.strengths.cache");
+ if (useCache)
+ {
+ try
+ { //try to determine Collection size (i.e. # of items)
+
+ int size = new ItemCounter(context).getCount(node.getDSO());
+ validity.add("size:"+size);
+ }
+ catch(ItemCountException e) { /* ignore */ }
+ }
+
+
+ for (TreeNode child : node.getChildren())
+ {
+ stack.push(child);
+ }
+ }
+
+ // Check if we are configured to assume validity.
+ String assumeCacheValidity = ConfigurationManager.getProperty("xmlui.community-list.cache");
+ if (assumeCacheValidity != null)
+ {
+ validity.setAssumedValidityDelay(assumeCacheValidity);
+ }
+ }
+
+ public void makeList(String contextPath, List list, Community parent) throws WingException, SQLException {
+ root = getRoot(parent);
+ java.util.List<TreeNode> rootNodes = root.getChildrenOfType(Constants.COMMUNITY);
+
+ for (TreeNode node : rootNodes)
+ {
+ buildList(contextPath, list, node);
+ }
+ }
+
+ public void makeReferenceSet(ReferenceSet referenceSet, Community parent) throws WingException, SQLException {
+ root = getRoot(parent);
+ java.util.List<TreeNode> rootNodes = root.getChildrenOfType(Constants.COMMUNITY);
+
+ for (TreeNode node : rootNodes)
+ {
+ buildReferenceSet(referenceSet, node);
+ }
+ }
+
+ /**
+ * construct a tree structure of communities and collections. The results
+ * of this hierarchy are cached so calling it multiple times is acceptable.
+ *
+ *
+ *
+ *
+ *
+ * @param communities The root level communities
+ * @return A root level node.
+ */
+ public TreeNode buildTree(Community[] communities) throws SQLException
+ {
+ TreeNode newRoot = new TreeNode();
+
+ // Setup for breath-first traversal
+ Stack<TreeNode> stack = new Stack<TreeNode>();
+
+ for (Community community : communities)
+ {
+ stack.push(newRoot.addChild(community));
+ }
+
+ while (!stack.empty())
+ {
+ TreeNode node = stack.pop();
+
+ // Short circuit if we have reached our max depth.
+ if (node.getLevel() >= depth)
+ {
+ continue;
+ }
+
+ // Only communities nodes are pushed on the stack.
+ Community community = (Community) node.getDSO();
+
+ for (Community subcommunity : community.getSubcommunities())
+ {
+ stack.push(node.addChild(subcommunity));
+ }
+
+ // Add any collections to the document.
+ if (!excludeCollections)
+ {
+ for (Collection collection : community.getCollections())
+ {
+ node.addChild(collection);
+ }
+ }
+ }
+
+ return newRoot;
+ }
+
+ public void reset() {
+ root = null;
+ }
+
+ /**
+ * Private class to represent the tree structure of communities & collections.
+ */
+ protected static class TreeNode
+ {
+ /** The object this node represents */
+ private DSpaceObject dso;
+
+ /** The level in the hierarchy that this node is at. */
+ private int level;
+
+ /** All children of this node */
+ private java.util.List<TreeNode> children = new ArrayList<TreeNode>();
+
+ /**
+ * Construct a new root level node
+ */
+ public TreeNode()
+ {
+ // Root level node is add the zero level.
+ this.level = 0;
+ }
+
+ /**
+ * @return The DSpaceObject this node represents
+ */
+ public DSpaceObject getDSO()
+ {
+ return this.dso;
+ }
+
+ /**
+ * Add a child DSpaceObject
+ *
+ * @param dso The child
+ * @return A new TreeNode object attached to the tree structure.
+ */
+ public TreeNode addChild(DSpaceObject dso)
+ {
+ TreeNode child = new TreeNode();
+ child.dso = dso;
+ child.level = this.level + 1;
+ children.add(child);
+ return child;
+ }
+
+ /**
+ * @return The current level in the hierarchy of this node.
+ */
+ public int getLevel()
+ {
+ return this.level;
+ }
+
+ /**
+ * @return All children
+ */
+ public java.util.List<TreeNode> getChildren()
+ {
+ return children;
+ }
+
+ /**
+ * @return All children of the given @type.
+ */
+ public java.util.List<TreeNode> getChildrenOfType(int type)
+ {
+ java.util.List<TreeNode> results = new ArrayList<TreeNode>();
+ for (TreeNode node : children)
+ {
+ if (node.dso.getType() == type)
+ {
+ results.add(node);
+ }
+ }
+ return results;
+ }
+ }
+}
View
4 dspace-xmlui/dspace-xmlui-api/src/main/resources/aspects/ViewArtifacts/sitemap.xmap
@@ -23,6 +23,7 @@ and searching the repository.
<map:transformers>
<map:transformer name="Navigation" src="org.dspace.app.xmlui.aspect.viewArtifacts.Navigation"/>
<map:transformer name="CommunityViewer" src="org.dspace.app.xmlui.aspect.artifactbrowser.CommunityViewer"/>
+ <map:transformer name="CommunityChildren" src="org.dspace.app.xmlui.aspect.artifactbrowser.CommunityChildren"/>
<map:transformer name="CollectionViewer" src="org.dspace.app.xmlui.aspect.artifactbrowser.CollectionViewer"/>
<map:transformer name="ItemViewer" src="org.dspace.app.xmlui.aspect.artifactbrowser.ItemViewer"/>
<map:transformer name="FeedbackForm" src="org.dspace.app.xmlui.aspect.artifactbrowser.FeedbackForm"/>
@@ -123,6 +124,9 @@ and searching the repository.
<map:parameter name="eventType" value="view"/>
</map:act>
<map:transform type="CommunityViewer"/>
+ <map:transform type="CommunityChildren">
+ <map:parameter name="depth" value="1"/>
+ </map:transform>
<map:serialize type="xml"/>
</map:match>
<map:match type="HandleTypeMatcher" pattern="collection">
View
4 dspace-xmlui/dspace-xmlui-webapp/src/main/webapp/i18n/messages.xml
@@ -199,6 +199,8 @@
<message key="xmlui.ArtifactBrowser.CommunityBrowser.head">Communities in DSpace</message>
<message key="xmlui.ArtifactBrowser.CommunityBrowser.select">Select a community to browse its collections.</message>
+ <message key="xmlui.ArtifactBrowser.CommunityChildren.head_community_children">Communities and collections in {0}</message>
+
<!-- org.dspace.app.xmlui.artifactbrowser.CommunityViewer.java -->
<message key="xmlui.ArtifactBrowser.CommunityViewer.search_scope">Search Scope</message>
<message key="xmlui.ArtifactBrowser.CommunityViewer.all_of_dspace">All of DSpace</message>
@@ -208,8 +210,6 @@
<message key="xmlui.ArtifactBrowser.CommunityViewer.browse_authors">Authors</message>
<message key="xmlui.ArtifactBrowser.CommunityViewer.browse_dates">Dates</message>
<message key="xmlui.ArtifactBrowser.CommunityViewer.advanced_search_link">Advanced Search</message>
- <message key="xmlui.ArtifactBrowser.CommunityViewer.head_sub_communities">Sub-communities within this community</message>
- <message key="xmlui.ArtifactBrowser.CommunityViewer.head_sub_collections">Collections in this community</message>
<message key="xmlui.ArtifactBrowser.CommunityViewer.head_recent_submissions">Recent Submissions</message>

No commit comments for this range

Something went wrong with that request. Please try again.