From 1e7af72a7636b51a765f0a4d7c615c32c249249a Mon Sep 17 00:00:00 2001 From: Richard Jones Date: Wed, 30 Jan 2008 16:53:34 +0000 Subject: [PATCH] re-enable xml-ui with rudimentary identifier support. This involves having fitted a new resolving mechanism to work with the xmlui way of obtaining DSpaceObjects, and decoupling the handle specific dependencies. This has appeared to be successful with regard to communities and collections, but it is not currently possible to submit items through the UI. git-svn-id: http://scm.dspace.org/svn/repo/trunk@2587 9c30dcfa-912a-0410-8fc2-9e0234be79fd --- .../aspect/administrative/Navigation.java | 14 ++-- .../aspect/administrative/WithdrawnItems.java | 9 ++- .../artifactbrowser/AbstractSearch.java | 47 ++++++----- .../artifactbrowser/CollectionViewer.java | 23 +++--- .../artifactbrowser/CommunityViewer.java | 9 ++- .../artifactbrowser/ConfigurableBrowse.java | 28 +++---- .../aspect/artifactbrowser/ItemViewer.java | 9 ++- .../aspect/artifactbrowser/Navigation.java | 8 +- .../artifactbrowser/RestrictedItem.java | 5 +- .../aspect/artifactbrowser/SimpleSearch.java | 11 +-- .../general/HandleAuthorizedMatcher.java | 12 +-- .../xmlui/aspect/general/HandleMatcher.java | 12 +-- .../aspect/general/HandleTypeMatcher.java | 12 +-- .../aspect/submission/CollectionViewer.java | 8 +- .../xmlui/aspect/submission/Navigation.java | 2 +- .../dspace/app/xmlui/cocoon/ThemeMatcher.java | 17 ++-- .../dspace/app/xmlui/utils/HandleUtil.java | 24 ++---- .../org/dspace/app/xmlui/utils/URIUtil.java | 53 +++++++++++++ .../aspects/ArtifactBrowser/sitemap.xmap | 79 ++++++++++++++++++- pom.xml | 2 +- 20 files changed, 253 insertions(+), 131 deletions(-) create mode 100644 dspace-xmlui/dspace-xmlui-api/src/main/java/org/dspace/app/xmlui/utils/URIUtil.java diff --git a/dspace-xmlui/dspace-xmlui-api/src/main/java/org/dspace/app/xmlui/aspect/administrative/Navigation.java b/dspace-xmlui/dspace-xmlui-api/src/main/java/org/dspace/app/xmlui/aspect/administrative/Navigation.java index 18a8d92922..ca3f406fce 100644 --- a/dspace-xmlui/dspace-xmlui-api/src/main/java/org/dspace/app/xmlui/aspect/administrative/Navigation.java +++ b/dspace-xmlui/dspace-xmlui-api/src/main/java/org/dspace/app/xmlui/aspect/administrative/Navigation.java @@ -39,10 +39,6 @@ */ package org.dspace.app.xmlui.aspect.administrative; -import java.io.IOException; -import java.io.Serializable; -import java.sql.SQLException; - import org.apache.cocoon.caching.CacheableProcessingComponent; import org.apache.cocoon.environment.ObjectModelHelper; import org.apache.cocoon.environment.Request; @@ -51,8 +47,8 @@ import org.apache.excalibur.source.SourceValidity; import org.apache.excalibur.source.impl.validity.NOPValidity; import org.dspace.app.xmlui.cocoon.AbstractDSpaceTransformer; 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.utils.URIUtil; import org.dspace.app.xmlui.wing.Message; import org.dspace.app.xmlui.wing.WingException; import org.dspace.app.xmlui.wing.element.List; @@ -67,6 +63,10 @@ import org.dspace.core.Constants; import org.dspace.eperson.Group; import org.xml.sax.SAXException; +import java.io.IOException; +import java.io.Serializable; +import java.sql.SQLException; + /** * * Create the navigation options for everything in the administrative aspects. This includes @@ -187,7 +187,7 @@ public class Navigation extends AbstractDSpaceTransformer implements CacheablePr List admin = options.addList("administrative"); // Context Administrative options - DSpaceObject dso = HandleUtil.obtainHandle(objectModel); + DSpaceObject dso = URIUtil.resolve(objectModel); if (dso instanceof Item) { @@ -270,7 +270,7 @@ public class Navigation extends AbstractDSpaceTransformer implements CacheablePr // How many options were added. int options = 0; - DSpaceObject dso = HandleUtil.obtainHandle(objectModel); + DSpaceObject dso = URIUtil.resolve(objectModel); if (dso instanceof Item) { diff --git a/dspace-xmlui/dspace-xmlui-api/src/main/java/org/dspace/app/xmlui/aspect/administrative/WithdrawnItems.java b/dspace-xmlui/dspace-xmlui-api/src/main/java/org/dspace/app/xmlui/aspect/administrative/WithdrawnItems.java index 1a099a545a..8e7faddd1f 100644 --- a/dspace-xmlui/dspace-xmlui-api/src/main/java/org/dspace/app/xmlui/aspect/administrative/WithdrawnItems.java +++ b/dspace-xmlui/dspace-xmlui-api/src/main/java/org/dspace/app/xmlui/aspect/administrative/WithdrawnItems.java @@ -51,6 +51,7 @@ import org.dspace.app.xmlui.utils.DSpaceValidity; import org.dspace.app.xmlui.utils.HandleUtil; import org.dspace.app.xmlui.utils.RequestUtils; import org.dspace.app.xmlui.utils.UIException; +import org.dspace.app.xmlui.utils.URIUtil; import org.dspace.app.xmlui.wing.Message; import org.dspace.app.xmlui.wing.WingException; import org.dspace.app.xmlui.wing.element.Body; @@ -170,7 +171,7 @@ public class WithdrawnItems extends AbstractDSpaceTransformer implements if (key != null) { - DSpaceObject dso = HandleUtil.obtainHandle(objectModel); + DSpaceObject dso = URIUtil.resolve(objectModel); if (dso != null) key += "-" + IdentifierFactory.getCanonicalForm(dso); @@ -192,7 +193,7 @@ public class WithdrawnItems extends AbstractDSpaceTransformer implements try { DSpaceValidity validity = new DSpaceValidity(); - DSpaceObject dso = HandleUtil.obtainHandle(objectModel); + DSpaceObject dso = URIUtil.resolve(objectModel); if (dso != null) validity.add(dso); @@ -240,7 +241,7 @@ public class WithdrawnItems extends AbstractDSpaceTransformer implements pageMeta.addMetadata("title").addContent(getTitleMessage(info)); - DSpaceObject dso = HandleUtil.obtainHandle(objectModel); + DSpaceObject dso = URIUtil.resolve(objectModel); pageMeta.addTrailLink(contextPath + "/", T_dspace_home); if (dso != null) @@ -598,7 +599,7 @@ public class WithdrawnItems extends AbstractDSpaceTransformer implements params.scope = new BrowserScope(context); // Are we in a community or collection? - DSpaceObject dso = HandleUtil.obtainHandle(objectModel); + DSpaceObject dso = URIUtil.resolve(objectModel); if (dso instanceof Community) params.scope.setCommunity((Community) dso); if (dso instanceof Collection) diff --git a/dspace-xmlui/dspace-xmlui-api/src/main/java/org/dspace/app/xmlui/aspect/artifactbrowser/AbstractSearch.java b/dspace-xmlui/dspace-xmlui-api/src/main/java/org/dspace/app/xmlui/aspect/artifactbrowser/AbstractSearch.java index a57ca56123..9658181fdb 100644 --- a/dspace-xmlui/dspace-xmlui-api/src/main/java/org/dspace/app/xmlui/aspect/artifactbrowser/AbstractSearch.java +++ b/dspace-xmlui/dspace-xmlui-api/src/main/java/org/dspace/app/xmlui/aspect/artifactbrowser/AbstractSearch.java @@ -39,12 +39,6 @@ */ package org.dspace.app.xmlui.aspect.artifactbrowser; -import java.io.IOException; -import java.io.Serializable; -import java.sql.SQLException; -import java.util.HashMap; -import java.util.Map; - import org.apache.cocoon.environment.ObjectModelHelper; import org.apache.cocoon.environment.Request; import org.apache.cocoon.util.HashUtil; @@ -54,33 +48,40 @@ import org.dspace.app.xmlui.utils.ContextUtil; 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.utils.URIUtil; 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.Cell; import org.dspace.app.xmlui.wing.element.Division; -import org.dspace.app.xmlui.wing.element.ReferenceSet; import org.dspace.app.xmlui.wing.element.Para; +import org.dspace.app.xmlui.wing.element.ReferenceSet; +import org.dspace.app.xmlui.wing.element.Row; import org.dspace.app.xmlui.wing.element.Select; import org.dspace.app.xmlui.wing.element.Table; -import org.dspace.app.xmlui.wing.element.Row; -import org.dspace.app.xmlui.wing.element.Cell; import org.dspace.authorize.AuthorizeException; import org.dspace.content.Collection; import org.dspace.content.Community; import org.dspace.content.DSpaceObject; import org.dspace.content.Item; -import org.dspace.uri.ResolvableIdentifier; -import org.dspace.uri.IdentifierFactory; -import org.dspace.uri.dao.ExternalIdentifierDAO; -import org.dspace.uri.dao.ExternalIdentifierDAOFactory; import org.dspace.core.Context; import org.dspace.search.DSQuery; import org.dspace.search.QueryArgs; import org.dspace.search.QueryResults; -import org.dspace.sort.SortOption; import org.dspace.sort.SortException; +import org.dspace.sort.SortOption; +import org.dspace.uri.IdentifierFactory; +import org.dspace.uri.ResolvableIdentifier; +import org.dspace.uri.dao.ExternalIdentifierDAO; +import org.dspace.uri.dao.ExternalIdentifierDAOFactory; import org.xml.sax.SAXException; +import java.io.IOException; +import java.io.Serializable; +import java.sql.SQLException; +import java.util.HashMap; +import java.util.Map; + /** * This is an abstract search page. It is a collection of search methods that * are common between diffrent search implementation. An implementer must @@ -498,22 +499,20 @@ public abstract class AbstractSearch extends AbstractDSpaceTransformer ExternalIdentifierDAOFactory.getInstance(context); // Are we in a community or collection? + /* DSpaceObject dso; - if (scopeString == null - || "".equals(scopeString) - || "/".equals(scopeString)) + if (scopeString == null || "".equals(scopeString) || "/".equals(scopeString)) + { // get the search scope from the url handle - dso = HandleUtil.obtainHandle(objectModel); + dso = URIUtil.resolve(objectModel); + } else { // Get the search scope from the location parameter -// dso = HandleManager.resolveToObject(context, scopeString); ResolvableIdentifier ri = IdentifierFactory.resolve(context, scopeString); dso = ri.getObject(context); - /* - ExternalIdentifier identifier = dao.retrieve(scopeString); - dso = identifier.getObjectIdentifier().getObject(context);*/ - } + }*/ + DSpaceObject dso = URIUtil.resolve(objectModel); return dso; } @@ -583,7 +582,7 @@ public abstract class AbstractSearch extends AbstractDSpaceTransformer */ protected boolean variableScope() throws SQLException { - if (HandleUtil.obtainHandle(objectModel) == null) + if (URIUtil.resolve(objectModel) == null) return true; else return false; diff --git a/dspace-xmlui/dspace-xmlui-api/src/main/java/org/dspace/app/xmlui/aspect/artifactbrowser/CollectionViewer.java b/dspace-xmlui/dspace-xmlui-api/src/main/java/org/dspace/app/xmlui/aspect/artifactbrowser/CollectionViewer.java index 7ecb062f84..3325328de5 100644 --- a/dspace-xmlui/dspace-xmlui-api/src/main/java/org/dspace/app/xmlui/aspect/artifactbrowser/CollectionViewer.java +++ b/dspace-xmlui/dspace-xmlui-api/src/main/java/org/dspace/app/xmlui/aspect/artifactbrowser/CollectionViewer.java @@ -39,10 +39,6 @@ */ package org.dspace.app.xmlui.aspect.artifactbrowser; -import java.io.IOException; -import java.io.Serializable; -import java.sql.SQLException; - import org.apache.cocoon.caching.CacheableProcessingComponent; import org.apache.cocoon.util.HashUtil; import org.apache.excalibur.source.SourceValidity; @@ -52,28 +48,33 @@ import org.dspace.app.xmlui.cocoon.DSpaceFeedGenerator; 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.utils.URIUtil; 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.app.xmlui.wing.element.List; import org.dspace.app.xmlui.wing.element.PageMeta; import org.dspace.app.xmlui.wing.element.Para; +import org.dspace.app.xmlui.wing.element.ReferenceSet; import org.dspace.authorize.AuthorizeException; import org.dspace.browse.BrowseEngine; import org.dspace.browse.BrowseException; import org.dspace.browse.BrowseIndex; import org.dspace.browse.BrowserScope; -import org.dspace.sort.SortOption; -import org.dspace.sort.SortException; import org.dspace.content.Collection; import org.dspace.content.DSpaceObject; import org.dspace.content.Item; import org.dspace.core.ConfigurationManager; +import org.dspace.sort.SortException; +import org.dspace.sort.SortOption; import org.dspace.uri.IdentifierFactory; import org.xml.sax.SAXException; +import java.io.IOException; +import java.io.Serializable; +import java.sql.SQLException; + /** * Display a single collection. This includes a full text search, browse by * list, community display and a list of recent submissions. @@ -126,7 +127,7 @@ public class CollectionViewer extends AbstractDSpaceTransformer implements Cache { try { - DSpaceObject dso = HandleUtil.obtainHandle(objectModel); + DSpaceObject dso = URIUtil.resolve(objectModel); if (dso == null) return "0"; @@ -154,7 +155,7 @@ public class CollectionViewer extends AbstractDSpaceTransformer implements Cache { try { - DSpaceObject dso = HandleUtil.obtainHandle(objectModel); + DSpaceObject dso = URIUtil.resolve(objectModel); if (dso == null) return null; @@ -193,7 +194,7 @@ public class CollectionViewer extends AbstractDSpaceTransformer implements Cache WingException, UIException, SQLException, IOException, AuthorizeException { - DSpaceObject dso = HandleUtil.obtainHandle(objectModel); + DSpaceObject dso = URIUtil.resolve(objectModel); if (!(dso instanceof Collection)) return; @@ -231,7 +232,7 @@ public class CollectionViewer extends AbstractDSpaceTransformer implements Cache public void addBody(Body body) throws SAXException, WingException, UIException, SQLException, IOException, AuthorizeException { - DSpaceObject dso = HandleUtil.obtainHandle(objectModel); + DSpaceObject dso = URIUtil.resolve(objectModel); if (!(dso instanceof Collection)) return; diff --git a/dspace-xmlui/dspace-xmlui-api/src/main/java/org/dspace/app/xmlui/aspect/artifactbrowser/CommunityViewer.java b/dspace-xmlui/dspace-xmlui-api/src/main/java/org/dspace/app/xmlui/aspect/artifactbrowser/CommunityViewer.java index 86c7d66421..dd5eb52b49 100644 --- a/dspace-xmlui/dspace-xmlui-api/src/main/java/org/dspace/app/xmlui/aspect/artifactbrowser/CommunityViewer.java +++ b/dspace-xmlui/dspace-xmlui-api/src/main/java/org/dspace/app/xmlui/aspect/artifactbrowser/CommunityViewer.java @@ -48,6 +48,7 @@ import org.dspace.app.xmlui.cocoon.DSpaceFeedGenerator; 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.utils.URIUtil; import org.dspace.app.xmlui.wing.Message; import org.dspace.app.xmlui.wing.WingException; import org.dspace.app.xmlui.wing.element.Body; @@ -133,7 +134,7 @@ public class CommunityViewer extends AbstractDSpaceTransformer implements Cachea */ public Serializable getKey() { try { - DSpaceObject dso = HandleUtil.obtainHandle(objectModel); + DSpaceObject dso = URIUtil.resolve(objectModel); if (dso == null) return "0"; // no item, something is wrong @@ -159,7 +160,7 @@ public class CommunityViewer extends AbstractDSpaceTransformer implements Cachea if (this.validity == null) { try { - DSpaceObject dso = HandleUtil.obtainHandle(objectModel); + DSpaceObject dso = URIUtil.resolve(objectModel); if (dso == null) return null; @@ -209,7 +210,7 @@ public class CommunityViewer extends AbstractDSpaceTransformer implements Cachea WingException, UIException, SQLException, IOException, AuthorizeException { - DSpaceObject dso = HandleUtil.obtainHandle(objectModel); + DSpaceObject dso = URIUtil.resolve(objectModel); if (!(dso instanceof Community)) return; @@ -249,7 +250,7 @@ public class CommunityViewer extends AbstractDSpaceTransformer implements Cachea UIException, SQLException, IOException, AuthorizeException { - DSpaceObject dso = HandleUtil.obtainHandle(objectModel); + DSpaceObject dso = URIUtil.resolve(objectModel); if (!(dso instanceof Community)) return; diff --git a/dspace-xmlui/dspace-xmlui-api/src/main/java/org/dspace/app/xmlui/aspect/artifactbrowser/ConfigurableBrowse.java b/dspace-xmlui/dspace-xmlui-api/src/main/java/org/dspace/app/xmlui/aspect/artifactbrowser/ConfigurableBrowse.java index 52bf25f0f9..c524218569 100644 --- a/dspace-xmlui/dspace-xmlui-api/src/main/java/org/dspace/app/xmlui/aspect/artifactbrowser/ConfigurableBrowse.java +++ b/dspace-xmlui/dspace-xmlui-api/src/main/java/org/dspace/app/xmlui/aspect/artifactbrowser/ConfigurableBrowse.java @@ -40,16 +40,6 @@ package org.dspace.app.xmlui.aspect.artifactbrowser; -import java.io.IOException; -import java.io.Serializable; -import java.io.UnsupportedEncodingException; -import java.net.URLEncoder; -import java.sql.SQLException; -import java.util.HashMap; -import java.util.Locale; -import java.util.Map; -import java.util.Set; - import org.apache.cocoon.caching.CacheableProcessingComponent; import org.apache.cocoon.environment.ObjectModelHelper; import org.apache.cocoon.environment.Request; @@ -61,6 +51,7 @@ import org.dspace.app.xmlui.utils.DSpaceValidity; import org.dspace.app.xmlui.utils.HandleUtil; import org.dspace.app.xmlui.utils.RequestUtils; import org.dspace.app.xmlui.utils.UIException; +import org.dspace.app.xmlui.utils.URIUtil; import org.dspace.app.xmlui.wing.Message; import org.dspace.app.xmlui.wing.WingException; import org.dspace.app.xmlui.wing.element.Body; @@ -85,13 +76,20 @@ import org.dspace.content.DCDate; import org.dspace.content.DSpaceObject; import org.dspace.content.Item; import org.dspace.core.ConfigurationManager; -import org.dspace.core.Constants; import org.dspace.core.Context; import org.dspace.sort.SortException; import org.dspace.sort.SortOption; import org.dspace.uri.IdentifierFactory; import org.xml.sax.SAXException; +import java.io.IOException; +import java.io.Serializable; +import java.sql.SQLException; +import java.util.HashMap; +import java.util.Locale; +import java.util.Map; +import java.util.Set; + /** * Implements all the browse functionality (browse by title, subject, authors, * etc.) The types of browse available are configurable by the implementor. See @@ -173,7 +171,7 @@ public class ConfigurableBrowse extends AbstractDSpaceTransformer implements if (key != null) { - DSpaceObject dso = HandleUtil.obtainHandle(objectModel); + DSpaceObject dso = URIUtil.resolve(objectModel); if (dso != null) key += "-" + IdentifierFactory.getCanonicalForm(dso); @@ -195,7 +193,7 @@ public class ConfigurableBrowse extends AbstractDSpaceTransformer implements try { DSpaceValidity validity = new DSpaceValidity(); - DSpaceObject dso = HandleUtil.obtainHandle(objectModel); + DSpaceObject dso = URIUtil.resolve(objectModel); if (dso != null) validity.add(dso); @@ -243,7 +241,7 @@ public class ConfigurableBrowse extends AbstractDSpaceTransformer implements pageMeta.addMetadata("title").addContent(getTitleMessage(info)); - DSpaceObject dso = HandleUtil.obtainHandle(objectModel); + DSpaceObject dso = URIUtil.resolve(objectModel); pageMeta.addTrailLink(contextPath + "/", T_dspace_home); if (dso != null) @@ -596,7 +594,7 @@ public class ConfigurableBrowse extends AbstractDSpaceTransformer implements params.scope = new BrowserScope(context); // Are we in a community or collection? - DSpaceObject dso = HandleUtil.obtainHandle(objectModel); + DSpaceObject dso = URIUtil.resolve(objectModel); if (dso instanceof Community) params.scope.setCommunity((Community) dso); if (dso instanceof Collection) diff --git a/dspace-xmlui/dspace-xmlui-api/src/main/java/org/dspace/app/xmlui/aspect/artifactbrowser/ItemViewer.java b/dspace-xmlui/dspace-xmlui-api/src/main/java/org/dspace/app/xmlui/aspect/artifactbrowser/ItemViewer.java index 281e61cfba..ae174ee2a5 100644 --- a/dspace-xmlui/dspace-xmlui-api/src/main/java/org/dspace/app/xmlui/aspect/artifactbrowser/ItemViewer.java +++ b/dspace-xmlui/dspace-xmlui-api/src/main/java/org/dspace/app/xmlui/aspect/artifactbrowser/ItemViewer.java @@ -48,6 +48,7 @@ import org.dspace.app.xmlui.cocoon.AbstractDSpaceTransformer; 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.utils.URIUtil; import org.dspace.app.xmlui.wing.Message; import org.dspace.app.xmlui.wing.WingException; import org.dspace.app.xmlui.wing.element.Body; @@ -100,7 +101,7 @@ public class ItemViewer extends AbstractDSpaceTransformer implements CacheablePr */ public Serializable getKey() { try { - DSpaceObject dso = HandleUtil.obtainHandle(objectModel); + DSpaceObject dso = URIUtil.resolve(objectModel); if (dso == null) return "0"; // no item, something is wrong. @@ -125,7 +126,7 @@ public class ItemViewer extends AbstractDSpaceTransformer implements CacheablePr if (this.validity == null) { try { - DSpaceObject dso = HandleUtil.obtainHandle(objectModel); + DSpaceObject dso = URIUtil.resolve(objectModel); DSpaceValidity validity = new DSpaceValidity(); validity.add(dso); @@ -148,7 +149,7 @@ public class ItemViewer extends AbstractDSpaceTransformer implements CacheablePr AuthorizeException { - DSpaceObject dso = HandleUtil.obtainHandle(objectModel); + DSpaceObject dso = URIUtil.resolve(objectModel); if (!(dso instanceof Item)) return; Item item = (Item) dso; @@ -173,7 +174,7 @@ public class ItemViewer extends AbstractDSpaceTransformer implements CacheablePr UIException, SQLException, IOException, AuthorizeException { - DSpaceObject dso = HandleUtil.obtainHandle(objectModel); + DSpaceObject dso = URIUtil.resolve(objectModel); if (!(dso instanceof Item)) return; Item item = (Item) dso; diff --git a/dspace-xmlui/dspace-xmlui-api/src/main/java/org/dspace/app/xmlui/aspect/artifactbrowser/Navigation.java b/dspace-xmlui/dspace-xmlui-api/src/main/java/org/dspace/app/xmlui/aspect/artifactbrowser/Navigation.java index 8f8f1be8be..9b31f98ff6 100644 --- a/dspace-xmlui/dspace-xmlui-api/src/main/java/org/dspace/app/xmlui/aspect/artifactbrowser/Navigation.java +++ b/dspace-xmlui/dspace-xmlui-api/src/main/java/org/dspace/app/xmlui/aspect/artifactbrowser/Navigation.java @@ -46,8 +46,8 @@ import org.apache.cocoon.util.HashUtil; import org.apache.excalibur.source.SourceValidity; import org.apache.excalibur.source.impl.validity.NOPValidity; import org.dspace.app.xmlui.cocoon.AbstractDSpaceTransformer; -import org.dspace.app.xmlui.utils.HandleUtil; import org.dspace.app.xmlui.utils.UIException; +import org.dspace.app.xmlui.utils.URIUtil; import org.dspace.app.xmlui.wing.Message; import org.dspace.app.xmlui.wing.WingException; import org.dspace.app.xmlui.wing.element.List; @@ -114,7 +114,7 @@ public class Navigation extends AbstractDSpaceTransformer implements CacheablePr Request request = ObjectModelHelper.getRequest(objectModel); String key = request.getScheme() + request.getServerName() + request.getServerPort() + request.getSitemapURI() + request.getQueryString(); - DSpaceObject dso = HandleUtil.obtainHandle(objectModel); + DSpaceObject dso = URIUtil.resolve(objectModel); if (dso != null) key += "-" + IdentifierFactory.getCanonicalForm(dso); @@ -173,7 +173,7 @@ public class Navigation extends AbstractDSpaceTransformer implements CacheablePr // Add the configured browse lists for 'top level' browsing addBrowseOptions(browseGlobal, contextPath + "/browse"); - DSpaceObject dso = HandleUtil.obtainHandle(objectModel); + DSpaceObject dso = URIUtil.resolve(objectModel); if (dso != null) { if (dso instanceof Item) @@ -225,7 +225,7 @@ public class Navigation extends AbstractDSpaceTransformer implements CacheablePr pageMeta.addMetadata("page","contactURL").addContent(contextPath + "/contact"); pageMeta.addMetadata("page","feedbackURL").addContent(contextPath + "/feedback"); - DSpaceObject dso = HandleUtil.obtainHandle(objectModel); + DSpaceObject dso = URIUtil.resolve(objectModel); if (dso != null) { if (dso instanceof Item) diff --git a/dspace-xmlui/dspace-xmlui-api/src/main/java/org/dspace/app/xmlui/aspect/artifactbrowser/RestrictedItem.java b/dspace-xmlui/dspace-xmlui-api/src/main/java/org/dspace/app/xmlui/aspect/artifactbrowser/RestrictedItem.java index e638287adf..0d348e75e3 100644 --- a/dspace-xmlui/dspace-xmlui-api/src/main/java/org/dspace/app/xmlui/aspect/artifactbrowser/RestrictedItem.java +++ b/dspace-xmlui/dspace-xmlui-api/src/main/java/org/dspace/app/xmlui/aspect/artifactbrowser/RestrictedItem.java @@ -44,6 +44,7 @@ import org.apache.cocoon.environment.Request; import org.dspace.app.xmlui.cocoon.AbstractDSpaceTransformer; import org.dspace.app.xmlui.utils.HandleUtil; import org.dspace.app.xmlui.utils.UIException; +import org.dspace.app.xmlui.utils.URIUtil; import org.dspace.app.xmlui.wing.Message; import org.dspace.app.xmlui.wing.WingException; import org.dspace.app.xmlui.wing.element.Body; @@ -87,7 +88,7 @@ public class RestrictedItem extends AbstractDSpaceTransformer //implements Cache WingException, UIException, SQLException, IOException, AuthorizeException { - DSpaceObject dso = HandleUtil.obtainHandle(objectModel); + DSpaceObject dso = URIUtil.resolve(objectModel); pageMeta.addMetadata("title").addContent(T_title); @@ -103,7 +104,7 @@ public class RestrictedItem extends AbstractDSpaceTransformer //implements Cache UIException, SQLException, IOException, AuthorizeException { Request request = ObjectModelHelper.getRequest(objectModel); - DSpaceObject dso = HandleUtil.obtainHandle(objectModel); + DSpaceObject dso = URIUtil.resolve(objectModel); String type = null; String identifier = null; diff --git a/dspace-xmlui/dspace-xmlui-api/src/main/java/org/dspace/app/xmlui/aspect/artifactbrowser/SimpleSearch.java b/dspace-xmlui/dspace-xmlui-api/src/main/java/org/dspace/app/xmlui/aspect/artifactbrowser/SimpleSearch.java index d8be9756a6..c123a549e1 100644 --- a/dspace-xmlui/dspace-xmlui-api/src/main/java/org/dspace/app/xmlui/aspect/artifactbrowser/SimpleSearch.java +++ b/dspace-xmlui/dspace-xmlui-api/src/main/java/org/dspace/app/xmlui/aspect/artifactbrowser/SimpleSearch.java @@ -39,15 +39,12 @@ */ package org.dspace.app.xmlui.aspect.artifactbrowser; -import java.io.IOException; -import java.sql.SQLException; -import java.util.Map; - import org.apache.cocoon.caching.CacheableProcessingComponent; import org.apache.cocoon.environment.ObjectModelHelper; import org.apache.cocoon.environment.Request; import org.dspace.app.xmlui.utils.HandleUtil; import org.dspace.app.xmlui.utils.UIException; +import org.dspace.app.xmlui.utils.URIUtil; import org.dspace.app.xmlui.wing.Message; import org.dspace.app.xmlui.wing.WingException; import org.dspace.app.xmlui.wing.element.Body; @@ -62,6 +59,10 @@ import org.dspace.content.Community; import org.dspace.content.DSpaceObject; import org.xml.sax.SAXException; +import java.io.IOException; +import java.sql.SQLException; +import java.util.Map; + /** * Preform a simple search of the repository. The user provides a simple one * field query (the url parameter is named query) and the results are processed. @@ -100,7 +101,7 @@ public class SimpleSearch extends AbstractSearch implements CacheableProcessingC pageMeta.addMetadata("title").addContent(T_title); pageMeta.addTrailLink(contextPath + "/", T_dspace_home); - DSpaceObject dso = HandleUtil.obtainHandle(objectModel); + DSpaceObject dso = URIUtil.resolve(objectModel); if ((dso instanceof Collection) || (dso instanceof Community)) { HandleUtil.buildHandleTrail(dso,pageMeta,contextPath); diff --git a/dspace-xmlui/dspace-xmlui-api/src/main/java/org/dspace/app/xmlui/aspect/general/HandleAuthorizedMatcher.java b/dspace-xmlui/dspace-xmlui-api/src/main/java/org/dspace/app/xmlui/aspect/general/HandleAuthorizedMatcher.java index 20a3f940c6..feafd2565b 100644 --- a/dspace-xmlui/dspace-xmlui-api/src/main/java/org/dspace/app/xmlui/aspect/general/HandleAuthorizedMatcher.java +++ b/dspace-xmlui/dspace-xmlui-api/src/main/java/org/dspace/app/xmlui/aspect/general/HandleAuthorizedMatcher.java @@ -40,21 +40,21 @@ package org.dspace.app.xmlui.aspect.general; -import java.sql.SQLException; -import java.util.HashMap; -import java.util.Map; - import org.apache.avalon.framework.logger.AbstractLogEnabled; import org.apache.avalon.framework.parameters.Parameters; import org.apache.cocoon.matching.Matcher; import org.apache.cocoon.sitemap.PatternException; import org.dspace.app.xmlui.utils.ContextUtil; -import org.dspace.app.xmlui.utils.HandleUtil; +import org.dspace.app.xmlui.utils.URIUtil; import org.dspace.authorize.AuthorizeManager; import org.dspace.content.DSpaceObject; import org.dspace.core.Constants; import org.dspace.core.Context; +import java.sql.SQLException; +import java.util.HashMap; +import java.util.Map; + /** * Test the current URL to see if the user has access to the described * resources. The privelege tested against uses the pattern attribute, the @@ -108,7 +108,7 @@ public class HandleAuthorizedMatcher extends AbstractLogEnabled implements Match try { Context context = ContextUtil.obtainContext(objectModel); - DSpaceObject dso = HandleUtil.obtainHandle(objectModel); + DSpaceObject dso = URIUtil.resolve(objectModel); if (dso == null) return null; diff --git a/dspace-xmlui/dspace-xmlui-api/src/main/java/org/dspace/app/xmlui/aspect/general/HandleMatcher.java b/dspace-xmlui/dspace-xmlui-api/src/main/java/org/dspace/app/xmlui/aspect/general/HandleMatcher.java index 6cd4e1ad06..4d6a9f5478 100644 --- a/dspace-xmlui/dspace-xmlui-api/src/main/java/org/dspace/app/xmlui/aspect/general/HandleMatcher.java +++ b/dspace-xmlui/dspace-xmlui-api/src/main/java/org/dspace/app/xmlui/aspect/general/HandleMatcher.java @@ -40,21 +40,21 @@ package org.dspace.app.xmlui.aspect.general; -import java.sql.SQLException; -import java.util.HashMap; -import java.util.Map; - import org.apache.avalon.framework.logger.AbstractLogEnabled; import org.apache.avalon.framework.parameters.Parameters; import org.apache.cocoon.matching.Matcher; import org.apache.cocoon.sitemap.PatternException; -import org.dspace.app.xmlui.utils.HandleUtil; +import org.dspace.app.xmlui.utils.URIUtil; import org.dspace.content.Collection; import org.dspace.content.Community; import org.dspace.content.DSpaceObject; import org.dspace.content.Item; import org.dspace.core.Constants; +import java.sql.SQLException; +import java.util.HashMap; +import java.util.Map; + /** * Test the current URL to see if it or any of it's parants match against the * given handle. @@ -81,7 +81,7 @@ public class HandleMatcher extends AbstractLogEnabled implements Matcher { try { - DSpaceObject dso = HandleUtil.obtainHandle(objectModel); + DSpaceObject dso = URIUtil.resolve(objectModel); if (dso == null) return null; diff --git a/dspace-xmlui/dspace-xmlui-api/src/main/java/org/dspace/app/xmlui/aspect/general/HandleTypeMatcher.java b/dspace-xmlui/dspace-xmlui-api/src/main/java/org/dspace/app/xmlui/aspect/general/HandleTypeMatcher.java index b278891022..25ccbfad07 100644 --- a/dspace-xmlui/dspace-xmlui-api/src/main/java/org/dspace/app/xmlui/aspect/general/HandleTypeMatcher.java +++ b/dspace-xmlui/dspace-xmlui-api/src/main/java/org/dspace/app/xmlui/aspect/general/HandleTypeMatcher.java @@ -40,18 +40,18 @@ package org.dspace.app.xmlui.aspect.general; -import java.sql.SQLException; -import java.util.HashMap; -import java.util.Map; - import org.apache.avalon.framework.logger.AbstractLogEnabled; import org.apache.avalon.framework.parameters.Parameters; import org.apache.cocoon.matching.Matcher; import org.apache.cocoon.sitemap.PatternException; -import org.dspace.app.xmlui.utils.HandleUtil; +import org.dspace.app.xmlui.utils.URIUtil; import org.dspace.content.DSpaceObject; import org.dspace.core.Constants; +import java.sql.SQLException; +import java.util.HashMap; +import java.util.Map; + /** * Test the current URL to see if it contains a reference to a DSpaceObject, if * it dose then the object type is compared against the given pattern. The @@ -106,7 +106,7 @@ public class HandleTypeMatcher extends AbstractLogEnabled implements Matcher try { // HandleUtil handles caching if needed. - dso = HandleUtil.obtainHandle(objectModel); + dso = URIUtil.resolve(objectModel); } catch (SQLException sqle) { diff --git a/dspace-xmlui/dspace-xmlui-api/src/main/java/org/dspace/app/xmlui/aspect/submission/CollectionViewer.java b/dspace-xmlui/dspace-xmlui-api/src/main/java/org/dspace/app/xmlui/aspect/submission/CollectionViewer.java index 96029e8ff8..d615048954 100644 --- a/dspace-xmlui/dspace-xmlui-api/src/main/java/org/dspace/app/xmlui/aspect/submission/CollectionViewer.java +++ b/dspace-xmlui/dspace-xmlui-api/src/main/java/org/dspace/app/xmlui/aspect/submission/CollectionViewer.java @@ -44,8 +44,8 @@ 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.DSpaceValidity; -import org.dspace.app.xmlui.utils.HandleUtil; import org.dspace.app.xmlui.utils.UIException; +import org.dspace.app.xmlui.utils.URIUtil; import org.dspace.app.xmlui.wing.Message; import org.dspace.app.xmlui.wing.WingException; import org.dspace.app.xmlui.wing.element.Body; @@ -85,7 +85,7 @@ public class CollectionViewer extends AbstractDSpaceTransformer implements Cache { try { - DSpaceObject dso = HandleUtil.obtainHandle(objectModel); + DSpaceObject dso = URIUtil.resolve(objectModel); if (dso == null) return "0"; @@ -113,7 +113,7 @@ public class CollectionViewer extends AbstractDSpaceTransformer implements Cache { try { - DSpaceObject dso = HandleUtil.obtainHandle(objectModel); + DSpaceObject dso = URIUtil.resolve(objectModel); if (dso == null) return null; @@ -155,7 +155,7 @@ public class CollectionViewer extends AbstractDSpaceTransformer implements Cache public void addBody(Body body) throws SAXException, WingException, UIException, SQLException, IOException, AuthorizeException { - DSpaceObject dso = HandleUtil.obtainHandle(objectModel); + DSpaceObject dso = URIUtil.resolve(objectModel); if (!(dso instanceof Collection)) return; diff --git a/dspace-xmlui/dspace-xmlui-api/src/main/java/org/dspace/app/xmlui/aspect/submission/Navigation.java b/dspace-xmlui/dspace-xmlui-api/src/main/java/org/dspace/app/xmlui/aspect/submission/Navigation.java index 91c4f1e1af..c3f3702f49 100644 --- a/dspace-xmlui/dspace-xmlui-api/src/main/java/org/dspace/app/xmlui/aspect/submission/Navigation.java +++ b/dspace-xmlui/dspace-xmlui-api/src/main/java/org/dspace/app/xmlui/aspect/submission/Navigation.java @@ -97,7 +97,7 @@ public class Navigation extends AbstractDSpaceTransformer implements CacheablePr options.addList("administrative"); // This dosn't flow very well, lets remove it and see if anyone misses it. -// DSpaceObject dso = HandleUtil.obtainHandle(objectModel); +// DSpaceObject dso = URIUtil.resolve(objectModel); // if (dso != null && dso instanceof Collection) // { // Collection collection = (Collection) dso; diff --git a/dspace-xmlui/dspace-xmlui-api/src/main/java/org/dspace/app/xmlui/cocoon/ThemeMatcher.java b/dspace-xmlui/dspace-xmlui-api/src/main/java/org/dspace/app/xmlui/cocoon/ThemeMatcher.java index f3083aa9ec..da503b204d 100644 --- a/dspace-xmlui/dspace-xmlui-api/src/main/java/org/dspace/app/xmlui/cocoon/ThemeMatcher.java +++ b/dspace-xmlui/dspace-xmlui-api/src/main/java/org/dspace/app/xmlui/cocoon/ThemeMatcher.java @@ -40,23 +40,24 @@ package org.dspace.app.xmlui.cocoon; -import java.sql.SQLException; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.regex.Pattern; - import org.apache.avalon.framework.logger.AbstractLogEnabled; import org.apache.avalon.framework.parameters.Parameters; import org.apache.cocoon.environment.ObjectModelHelper; import org.apache.cocoon.environment.Request; import org.apache.cocoon.matching.Matcher; import org.apache.cocoon.sitemap.PatternException; -import org.dspace.app.xmlui.configuration.XMLUIConfiguration; import org.dspace.app.xmlui.configuration.Theme; +import org.dspace.app.xmlui.configuration.XMLUIConfiguration; import org.dspace.app.xmlui.utils.HandleUtil; +import org.dspace.app.xmlui.utils.URIUtil; import org.dspace.content.DSpaceObject; +import java.sql.SQLException; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.regex.Pattern; + /** * This class determines the correct Aspect to use. This is determined by the * url string, if it is prepended with a number followed by a slash (such as 1/ @@ -94,7 +95,7 @@ public class ThemeMatcher extends AbstractLogEnabled implements Matcher { try { Request request = ObjectModelHelper.getRequest(objectModel); String uri = request.getSitemapURI(); - DSpaceObject dso = HandleUtil.obtainHandle(objectModel); + DSpaceObject dso = URIUtil.resolve(objectModel); List rules = XMLUIConfiguration.getThemeRules(); getLogger().debug("Checking if URL=" + uri + " matches any theme rules."); diff --git a/dspace-xmlui/dspace-xmlui-api/src/main/java/org/dspace/app/xmlui/utils/HandleUtil.java b/dspace-xmlui/dspace-xmlui-api/src/main/java/org/dspace/app/xmlui/utils/HandleUtil.java index b4d9fa273e..fbbc89fefd 100644 --- a/dspace-xmlui/dspace-xmlui-api/src/main/java/org/dspace/app/xmlui/utils/HandleUtil.java +++ b/dspace-xmlui/dspace-xmlui-api/src/main/java/org/dspace/app/xmlui/utils/HandleUtil.java @@ -60,6 +60,9 @@ import org.dspace.core.Context; /** * Simple utility class for extracting handles. + * + * NOTE: this class is effectively deprecated, and exists to provide legacy support for + * handle resolution * * @author Scott Phillips */ @@ -96,26 +99,11 @@ public class HandleUtil String handle = uri.substring(HANDLE_PREFIX.length()); - int firstSlash = handle.indexOf('/'); - if (firstSlash < 0) - // If there is no first slash then no match - return null; - - int secondSlash = handle.indexOf('/', firstSlash + 1); - if (secondSlash < 0) - // A trailing slash is not nesssary if there is nothing after - // the handle. - secondSlash = handle.length(); - - handle = handle.substring(0, secondSlash); + // now fudge the legacy version of the handle + handle = "hdl:" + handle; Context context = ContextUtil.obtainContext(objectModel); -// dso = HandleManager.resolveToObject(context, handle); - /* - ExternalIdentifierDAO dao = - ExternalIdentifierDAOFactory.getInstance(context); - ExternalIdentifier identifier = dao.retrieve(handle); - dso = identifier.getObjectIdentifier().getObject(context);*/ + ResolvableIdentifier ri = IdentifierFactory.resolve(context, handle); dso = ri.getObject(context); diff --git a/dspace-xmlui/dspace-xmlui-api/src/main/java/org/dspace/app/xmlui/utils/URIUtil.java b/dspace-xmlui/dspace-xmlui-api/src/main/java/org/dspace/app/xmlui/utils/URIUtil.java new file mode 100644 index 0000000000..3ecd323451 --- /dev/null +++ b/dspace-xmlui/dspace-xmlui-api/src/main/java/org/dspace/app/xmlui/utils/URIUtil.java @@ -0,0 +1,53 @@ +package org.dspace.app.xmlui.utils; + +import org.dspace.content.DSpaceObject; +import org.dspace.core.Context; +import org.dspace.uri.ResolvableIdentifier; +import org.dspace.uri.IdentifierFactory; +import org.apache.cocoon.environment.Request; +import org.apache.cocoon.environment.ObjectModelHelper; + +import java.util.Map; +import java.sql.SQLException; + +public class URIUtil +{ + /** The URL prefix of all object uris */ + protected static final String URI_PREFIX = "resource/"; + + protected static final String DSPACE_OBJECT = "dspace.object"; + + /** + * Obtain the current DSpace handle for the specified request. + * + * @param objectModel + * The cocoon model. + * @return A DSpace handle, or null if none found. + */ + public static DSpaceObject resolve(Map objectModel) + throws SQLException + { + Request request = ObjectModelHelper.getRequest(objectModel); + DSpaceObject dso = (DSpaceObject) request.getAttribute(DSPACE_OBJECT); + + if (dso == null) + { + String uri = request.getSitemapURI(); + Context context = ContextUtil.obtainContext(objectModel); + ResolvableIdentifier ri = IdentifierFactory.resolve(context, uri); + if (ri == null) + { + // FIXME: this is not right, but there's not much choice just now + + // maybe we have a legacy url problem + dso = HandleUtil.obtainHandle(objectModel); + return dso; + } + dso = ri.getObject(context); + + request.setAttribute(DSPACE_OBJECT, dso); + } + + return dso; + } +} diff --git a/dspace-xmlui/dspace-xmlui-api/src/main/resources/aspects/ArtifactBrowser/sitemap.xmap b/dspace-xmlui/dspace-xmlui-api/src/main/resources/aspects/ArtifactBrowser/sitemap.xmap index 390c31cc12..cba380669b 100644 --- a/dspace-xmlui/dspace-xmlui-api/src/main/resources/aspects/ArtifactBrowser/sitemap.xmap +++ b/dspace-xmlui/dspace-xmlui-api/src/main/resources/aspects/ArtifactBrowser/sitemap.xmap @@ -153,7 +153,84 @@ and searching the repository. - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/pom.xml b/pom.xml index 716a3a4e7b..0526f2aaee 100644 --- a/pom.xml +++ b/pom.xml @@ -46,7 +46,7 @@ language-packs dspace-api dspace-jspui - + dspace-xmlui dspace-lni dspace-oai