001: /*
002: * DSpaceObjectManager.java
003: *
004: * Version: $Revision: 1.1 $
005: *
006: * Date: $Date: 2006/03/20 22:39:04 $
007: *
008: * Copyright (c) 2002, Hewlett-Packard Company and Massachusetts
009: * Institute of Technology. All rights reserved.
010: *
011: * Redistribution and use in source and binary forms, with or without
012: * modification, are permitted provided that the following conditions are
013: * met:
014: *
015: * - Redistributions of source code must retain the above copyright
016: * notice, this list of conditions and the following disclaimer.
017: *
018: * - Redistributions in binary form must reproduce the above copyright
019: * notice, this list of conditions and the following disclaimer in the
020: * documentation and/or other materials provided with the distribution.
021: *
022: * - Neither the name of the Hewlett-Packard Company nor the name of the
023: * Massachusetts Institute of Technology nor the names of their
024: * contributors may be used to endorse or promote products derived from
025: * this software without specific prior written permission.
026: *
027: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
028: * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
029: * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
030: * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
031: * HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
032: * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
033: * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
034: * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
035: * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
036: * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
037: * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
038: * DAMAGE.
039: */
040:
041: package org.dspace.app.xmlui.objectmanager;
042:
043: import java.util.ArrayList;
044: import java.util.HashMap;
045: import java.util.List;
046:
047: import org.dspace.app.xmlui.wing.ObjectManager;
048: import org.dspace.app.xmlui.wing.WingException;
049: import org.dspace.browse.BrowseItem;
050: import org.dspace.content.Collection;
051: import org.dspace.content.Community;
052: import org.dspace.content.DSpaceObject;
053: import org.dspace.content.Item;
054: import org.dspace.core.ConfigurationManager;
055:
056: /**
057: * The Wing ObjectManager implemented specificaly for DSpace. This manager
058: * is able identify all DSpace items, communities, and collections.
059: *
060: * @author Scott Phillips
061: */
062:
063: public class DSpaceObjectManager implements ObjectManager {
064:
065: /** List of all managed DSpaceObjects */
066: private List<DSpaceObject> dsos = new ArrayList<DSpaceObject>();
067:
068: /**
069: * Manage the given object, if this manager is unable to manage the object then false must be returned.
070: *
071: * @param object
072: * The object to be managed.
073: * @return The object identifiers
074: */
075: public boolean manageObject(Object object) throws WingException {
076: // First check that the object is of a type we can manage.
077: if (object instanceof BrowseItem) {
078: dsos.add((BrowseItem) object);
079: return true;
080: } else if (object instanceof Item) {
081: dsos.add((Item) object);
082: return true;
083: } else if (object instanceof Collection) {
084: dsos.add((Collection) object);
085: return true;
086: } else if (object instanceof Community) {
087: dsos.add((Community) object);
088: return true;
089: }
090:
091: // We are unable to manage this object.
092: return false;
093: }
094:
095: /**
096: * Return the metadata URL of the supplied object, assuming
097: * it's a DSpace item, community or collection.
098: *
099: */
100: public String getObjectURL(Object object) throws WingException {
101: if (object instanceof DSpaceObject) {
102: DSpaceObject dso = (DSpaceObject) object;
103: String handle = dso.getHandle();
104:
105: // If the object has a handle then refrence it by it's handle.
106: if (handle != null) {
107: return "/metadata/handle/" + handle + "/mets.xml";
108: } else {
109: // No handle then refrence it by an internal ID.
110: if (dso instanceof Item || dso instanceof BrowseItem) {
111: return "/metadata/internal/item/" + dso.getID()
112: + "/mets.xml";
113: } else if (object instanceof Collection) {
114: return "/metadata/internal/collection/"
115: + dso.getID() + "/mets.xml";
116: } else if (object instanceof Community) {
117: return "/metadata/internal/community/"
118: + dso.getID() + "/mets.xml";
119: }
120: }
121: }
122:
123: return null;
124: }
125:
126: /**
127: * Return a pretty specific string giving a hint to the theme as to what
128: * type of DSpace object is being refrenced.
129: */
130: public String getObjectType(Object object) throws WingException {
131: if (object instanceof Item || object instanceof BrowseItem) {
132: return "DSpace Item";
133: } else if (object instanceof Collection) {
134: return "DSpace Collection";
135: } else if (object instanceof Community) {
136: return "DSpace Community";
137: }
138:
139: return null;
140: }
141:
142: /**
143: * Return a globably unique identifier for the repository. For dspace, we use the handle prefix.
144: */
145: public String getRepositoryIdentifier(Object object)
146: throws WingException {
147: return ConfigurationManager.getProperty("handle.prefix");
148: }
149:
150: /**
151: * Return the metadata URL for this repository.
152: */
153: public String getRepositoryURL(Object object) throws WingException {
154: String handlePrefix = ConfigurationManager
155: .getProperty("handel.prefix");
156: return "/metadata/internal/repository/" + handlePrefix
157: + "/mets.xml";
158: }
159:
160: /**
161: * For the DSpace implementation we just return a hash of one entry which contains
162: * a reference to this repository's metadata.
163: */
164: public HashMap<String, String> getAllManagedRepositories()
165: throws WingException {
166: String handlePrefix = ConfigurationManager
167: .getProperty("handle.prefix");
168:
169: HashMap<String, String> allRepositories = new HashMap<String, String>();
170: allRepositories.put(handlePrefix,
171: "/metadata/internal/repository/" + handlePrefix
172: + "/mets.xml");
173:
174: return allRepositories;
175: }
176: }
|