(Scott Phillips) Adding Manakin, version 1.1, to DSpace. This new cocoon-based interface utilizes XML and XSLT to provide interface themability for specific community and collections while also providing interface level modularity thruogh the use of Manakin aspects.

git-svn-id: http://scm.dspace.org/svn/repo/trunk@2045 9c30dcfa-912a-0410-8fc2-9e0234be79fd
This commit is contained in:
Scott Phillips
2007-07-07 00:02:39 +00:00
parent b4399e950a
commit fde5c09d41
273 changed files with 72310 additions and 3 deletions

View File

@@ -0,0 +1,66 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.dspace</groupId>
<artifactId>dspace-xmlui-api</artifactId>
<packaging>jar</packaging>
<name>DSpace XMLUI (Manakin) :: API and Core Aspects</name>
<version>1.5-SNAPSHOT</version>
<url>http://www.dspace.org</url>
<description>DSpace/Manakin XML UI Based APIs and components using the Cocoon and Wing frameworks.</description>
<parent>
<groupId>org.dspace</groupId>
<artifactId>dspace-xmlui</artifactId>
<version>1.5-SNAPSHOT</version>
<relativePath>../</relativePath>
</parent>
<!-- FIXME: Override this from dspace-pom -->
<properties>
<config>../../dspace/config/dspace.cfg</config>
</properties>
<scm>
<connection>
scm:svn:https://dspace.svn.sourceforge.net/svnroot/dspace/trunk/dspace-xmlui/api
</connection>
<developerConnection>
scm:svn:https://dspace.svn.sourceforge.net/svnroot/dspace/trunk/dspace-xmlui/api
</developerConnection>
<url>
http://dspace.svn.sourceforge.net/viewvc/dspace/trunk/dspace-xmlui/api/
</url>
</scm>
<distributionManagement>
<site>
<id>website</id>
<url>
http://projects.dspace.org/dspace-xmlui/
</url>
</site>
</distributionManagement>
<dependencies>
<!-- DSpace API -->
<dependency>
<groupId>org.dspace</groupId>
<artifactId>dspace-api</artifactId>
<version>1.5-SNAPSHOT</version>
</dependency>
<!-- Wing framework -->
<dependency>
<groupId>org.dspace</groupId>
<artifactId>dspace-xmlui-wing</artifactId>
<version>1.5-SNAPSHOT</version>
</dependency>
</dependencies>
</project>

View File

@@ -0,0 +1,457 @@
/*
* ControlPanel.java
*
* Version: $Revision: 1.3 $
*
* Date: $Date: 2006/07/13 23:20:54 $
*
* Copyright (c) 2002, Hewlett-Packard Company and Massachusetts
* Institute of Technology. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* - 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.
*
* - Neither the name of the Hewlett-Packard Company nor the name of the
* Massachusetts Institute of Technology nor the names of their
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS 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 COPYRIGHT
* HOLDERS OR 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.
*/
package org.dspace.app.xmlui.aspect.administrative;
import java.io.IOException;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import org.apache.avalon.framework.service.ServiceException;
import org.apache.avalon.framework.service.ServiceManager;
import org.apache.avalon.framework.service.Serviceable;
import org.apache.cocoon.components.flow.ContinuationsManager;
import org.apache.cocoon.components.flow.WebContinuation;
import org.apache.cocoon.components.flow.WebContinuationDataBean;
import org.apache.cocoon.environment.ObjectModelHelper;
import org.apache.cocoon.environment.Request;
import org.dspace.app.xmlui.cocoon.AbstractDSpaceTransformer;
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.Item;
import org.dspace.app.xmlui.wing.element.List;
import org.dspace.app.xmlui.wing.element.PageMeta;
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.TextArea;
import org.dspace.authorize.AuthorizeException;
import org.dspace.authorize.AuthorizeManager;
import org.dspace.core.ConfigurationManager;
import org.xml.sax.SAXException;
/**
* This page displays important (and some not-so important) systems
* type information about your running dspace.
*
* @author Jay Paz
* @author Scott Phillips
*/
public class ControlPanel extends AbstractDSpaceTransformer implements Serviceable{
/** Language Strings */
private static final Message T_DSPACE_HOME =
message("xmlui.general.dspace_home");
private static final Message T_title = message("xmlui.administrative.ControlPanel.title");
private static final Message T_trail = message("xmlui.administrative.ControlPanel.trail");
private static final Message T_head = message("xmlui.administrative.ControlPanel.head");
private static final Message T_option_java = message("xmlui.administrative.ControlPanel.option_java");
private static final Message T_option_dspace = message("xmlui.administrative.ControlPanel.option_dspace");
private static final Message T_option_knots = message("xmlui.administrative.ControlPanel.option_knots");
private static final Message T_option_alerts = message("xmlui.administrative.ControlPanel.option_alerts");
private static final Message T_JAVA_HEAD = message("xmlui.administrative.ControlPanel.java_head");
private static final Message T_JAVA_VERSION = message("xmlui.administrative.ControlPanel.java_version");
private static final Message T_JAVA_VENDOR = message("xmlui.administrative.ControlPanel.java_vendor");
private static final Message T_OS_NAME = message("xmlui.administrative.ControlPanel.os_name");
private static final Message T_OS_ARCH = message("xmlui.administrative.ControlPanel.os_arch");
private static final Message T_OS_VERSION = message("xmlui.administrative.ControlPanel.os_version");
private static final Message T_RUNTIME_HEAD = message("xmlui.administrative.ControlPanel.runtime_head");
private static final Message T_RUNTIME_PROCESSORS = message("xmlui.administrative.ControlPanel.runtime_processors");
private static final Message T_RUNTIME_MAX = message("xmlui.administrative.ControlPanel.runtime_max");
private static final Message T_RUNTIME_TOTAL = message("xmlui.administrative.ControlPanel.runtime_total");
private static final Message T_RUNTIME_USED = message("xmlui.administrative.ControlPanel.runtime_used");
private static final Message T_RUNTIME_FREE = message("xmlui.administrative.ControlPanel.runtime_free");
private static final Message T_DSPACE_HEAD = message("xmlui.administrative.ControlPanel.dspace_head");
private static final Message T_DSPACE_DIR = message("xmlui.administrative.ControlPanel.dspace_dir");
private static final Message T_DSPACE_URL = message("xmlui.administrative.ControlPanel.dspace_url");
private static final Message T_DSPACE_HOST_NAME = message("xmlui.administrative.ControlPanel.dspace_hostname");
private static final Message T_DSPACE_NAME = message("xmlui.administrative.ControlPanel.dspace_name");
private static final Message T_DB_NAME = message("xmlui.administrative.ControlPanel.db_name");
private static final Message T_DB_URL = message("xmlui.administrative.ControlPanel.db_url");
private static final Message T_DB_DRIVER = message("xmlui.administrative.ControlPanel.db_driver");
private static final Message T_DB_MAX_CONN = message("xmlui.administrative.ControlPanel.db_maxconnections");
private static final Message T_DB_MAX_WAIT = message("xmlui.administrative.ControlPanel.db_maxwait");
private static final Message T_DB_MAX_IDLE = message("xmlui.administrative.ControlPanel.db_maxidle");
private static final Message T_MAIL_SERVER = message("xmlui.administrative.ControlPanel.mail_server");
private static final Message T_MAIL_FROM_ADDRESS = message("xmlui.administrative.ControlPanel.mail_from_address");
private static final Message T_FEEDBACK_RECIPIENT = message("xmlui.administrative.ControlPanel.mail_feedback_recipient");
private static final Message T_MAIL_ADMIN = message("xmlui.administrative.ControlPanel.mail_admin");
private static final Message T_knots_head = message("xmlui.administrative.ControlPanel.knots_head");
private static final Message T_knots_column1 = message("xmlui.administrative.ControlPanel.knots_column1");
private static final Message T_knots_column2 = message("xmlui.administrative.ControlPanel.knots_column2");
private static final Message T_knots_column3 = message("xmlui.administrative.ControlPanel.knots_column3");
private static final Message T_knots_hours = message("xmlui.administrative.ControlPanel.knots_hours");
private static final Message T_knots_minutes = message("xmlui.administrative.ControlPanel.knots_minutes");
private static final Message T_knots_expired = message("xmlui.administrative.ControlPanel.knots_expired");
private static final Message T_knots_active = message("xmlui.administrative.ControlPanel.knots_active");
private static final Message T_knots_none = message("xmlui.administrative.ControlPanel.knots_none");
private static final Message T_alerts_head = message("xmlui.administrative.ControlPanel.alerts_head");
private static final Message T_alerts_warning = message("xmlui.administrative.ControlPanel.alerts_warning");
private static final Message T_alerts_message_label = message("xmlui.administrative.ControlPanel.alerts_message_label");
private static final Message T_alerts_message_default = message("xmlui.administrative.ControlPanel.alerts_message_default");
private static final Message T_alerts_countdown_label = message("xmlui.administrative.ControlPanel.alerts_countdown_label");
private static final Message T_alerts_countdown_none = message("xmlui.administrative.ControlPanel.alerts_countdown_none");
private static final Message T_alerts_countdown_5 = message("xmlui.administrative.ControlPanel.alerts_countdown_5");
private static final Message T_alerts_countdown_15 = message("xmlui.administrative.ControlPanel.alerts_countdown_15");
private static final Message T_alerts_countdown_30 = message("xmlui.administrative.ControlPanel.alerts_countdown_30");
private static final Message T_alerts_countdown_60 = message("xmlui.administrative.ControlPanel.alerts_countdown_60");
private static final Message T_alerts_countdown_keep = message("xmlui.administrative.ControlPanel.alerts_countdown_keep");
private static final Message T_alerts_submit_activate = message("xmlui.administrative.ControlPanel.alerts_submit_activate");
private static final Message T_alerts_submit_deactivate = message("xmlui.administrative.ControlPanel.alerts_submit_deactivate");
private static final Message T_select_panel = message("xmlui.administrative.ControlPanel.select_panel");
/**
* The service manager allows us to access the continuation's
* manager, it is obtained from the servicable API
*/
private ServiceManager serviceManager;
/**
* The four states that this page can be in.
*/
private enum OPTIONS {java, dspace,knots,alerts};
/**
* From the servicable api, give us a service manager.
*/
public void service(ServiceManager serviceManager) throws ServiceException
{
this.serviceManager = serviceManager;
}
public void addPageMeta(PageMeta pageMeta) throws SAXException,
WingException, UIException, SQLException, IOException,
AuthorizeException {
pageMeta.addMetadata("title").addContent(T_title);
pageMeta.addTrailLink(contextPath + "/", T_DSPACE_HOME);
pageMeta.addTrailLink(contextPath + "/admin/panel", T_trail);
}
public void addBody(Body body) throws SAXException, WingException,
UIException, SQLException, IOException, AuthorizeException {
if (!AuthorizeManager.isAdmin(context))
throw new AuthorizeException("You are not authorized to view this page.");
Request request = ObjectModelHelper.getRequest(objectModel);
OPTIONS option = null;
if (request.getParameter("java") != null)
option = OPTIONS.java;
if (request.getParameter("dspace") != null)
option = OPTIONS.dspace;
if (request.getParameter("knots") != null)
option = OPTIONS.knots;
if (request.getParameter("alerts") != null)
option = OPTIONS.alerts;
Division div = body.addInteractiveDivision("control-panel", contextPath+"/admin/panel", Division.METHOD_POST, "primary administrative");
div.setHead(T_head);
// LIST: options
List options = div.addList("options",List.TYPE_SIMPLE,"horizontal");
// our options, selected or not....
if (option == OPTIONS.java)
options.addItem().addHighlight("bold").addXref("?java",T_option_java);
else
options.addItemXref("?java",T_option_java);
if (option == OPTIONS.dspace)
options.addItem().addHighlight("bold").addXref("?dspace",T_option_dspace);
else
options.addItemXref("?dspace",T_option_dspace);
if (option == OPTIONS.knots)
options.addItem().addHighlight("bold").addXref("?knots",T_option_knots);
else
options.addItemXref("?knots",T_option_knots);
if (option == OPTIONS.alerts)
options.addItem().addHighlight("bold").addXref("?alerts",T_option_alerts);
else
options.addItemXref("?alerts",T_option_alerts);
// The main content:
if (option == OPTIONS.java)
addJavaInformation(div);
else if (option == OPTIONS.dspace)
addDSpaceConfiguration(div);
else if (option == OPTIONS.knots)
addWebContinuations(div);
else if (option == OPTIONS.alerts)
addAlerts(div);
else{
div.addPara(T_select_panel);
}
}
/**
* Add specific java information including JRE, OS, and runtime memory statistics.
*/
private void addJavaInformation(Division div) throws WingException
{
// Get memory statistics
int processors = Runtime.getRuntime().availableProcessors();
long maxMemory = Runtime.getRuntime().maxMemory();
long totalMemory = Runtime.getRuntime().totalMemory();
long freeMemory = Runtime.getRuntime().freeMemory();
long usedMemory = totalMemory-freeMemory;
// Convert bytes into MiB
maxMemory = maxMemory / 1024 / 1024;
totalMemory = totalMemory / 1024 / 1024;
usedMemory = usedMemory / 1024 / 1024;
freeMemory = freeMemory / 1024 / 1024;
// LIST: Java
List list = div.addList("javaOs");
list.setHead(T_JAVA_HEAD);
list.addLabel(T_JAVA_VERSION);
list.addItem(System.getProperty("java.version"));
list.addLabel(T_JAVA_VENDOR);
list.addItem(System.getProperty("java.vendor"));
list.addLabel(T_OS_NAME);
list.addItem(System.getProperty("os.name"));
list.addLabel(T_OS_ARCH);
list.addItem(System.getProperty("os.arch"));
list.addLabel(T_OS_VERSION);
list.addItem(System.getProperty("os.version"));
// LIST: memory
List runtime = div.addList("runtime");
runtime.setHead(T_RUNTIME_HEAD);
runtime.addLabel(T_RUNTIME_PROCESSORS);
runtime.addItem(String.valueOf(processors));
runtime.addLabel(T_RUNTIME_MAX);
runtime.addItem(String.valueOf(maxMemory) + " MiB");
runtime.addLabel(T_RUNTIME_TOTAL);
runtime.addItem(String.valueOf(totalMemory) + " MiB");
runtime.addLabel(T_RUNTIME_USED);
runtime.addItem(String.valueOf(usedMemory) + " MiB");
runtime.addLabel(T_RUNTIME_FREE);
runtime.addItem(String.valueOf(freeMemory) + " MiB");
}
/**
* List important DSpace configuration parameters.
*/
private void addDSpaceConfiguration(Division div) throws WingException
{
// LIST: DSpace
List dspace = div.addList("dspace");
dspace.setHead(T_DSPACE_HEAD);
dspace.addLabel(T_DSPACE_DIR);
dspace.addItem(ConfigurationManager.getProperty("dspace.dir"));
dspace.addLabel(T_DSPACE_URL);
dspace.addItem(ConfigurationManager.getProperty("dspace.url"));
dspace.addLabel(T_DSPACE_HOST_NAME);
dspace.addItem(ConfigurationManager.getProperty("dspace.hostname"));
dspace.addLabel(T_DSPACE_NAME);
dspace.addItem(ConfigurationManager.getProperty("dspace.name"));
dspace.addLabel(T_DB_NAME);
dspace.addItem(ConfigurationManager.getProperty("db.name"));
dspace.addLabel(T_DB_URL);
dspace.addItem(ConfigurationManager.getProperty("db.url"));
dspace.addLabel(T_DB_DRIVER);
dspace.addItem(ConfigurationManager.getProperty("db.driver"));
dspace.addLabel(T_DB_MAX_CONN);
dspace.addItem(ConfigurationManager.getProperty("db.maxconnections"));
dspace.addLabel(T_DB_MAX_WAIT);
dspace.addItem(ConfigurationManager.getProperty("db.maxwait"));
dspace.addLabel(T_DB_MAX_IDLE);
dspace.addItem(ConfigurationManager.getProperty("db.maxidle"));
dspace.addLabel(T_MAIL_SERVER);
dspace.addItem(ConfigurationManager.getProperty("mail.server"));
dspace.addLabel(T_MAIL_FROM_ADDRESS);
dspace.addItem(ConfigurationManager.getProperty("mail.from.address"));
dspace.addLabel(T_FEEDBACK_RECIPIENT);
dspace.addItem(ConfigurationManager.getProperty("feedback.recipient"));
dspace.addLabel(T_MAIL_ADMIN);
dspace.addItem(ConfigurationManager.getProperty("mail.admin"));
}
/**
* Add a list of all active web continuations.
*/
private void addWebContinuations(Division div) throws WingException
{
// Get all the web continuations and sort them.
ArrayList<WebContinuation> knots = new ArrayList<WebContinuation>();
try {
// Get a list of all continuations
ContinuationsManager continuationManager = (ContinuationsManager) serviceManager.lookup(ContinuationsManager.ROLE);
@SuppressWarnings("unchecked") // the cast is correct
java.util.List<WebContinuationDataBean> knotBeans = continuationManager.getWebContinuationsDataBeanList();
for (WebContinuationDataBean flow : knotBeans)
{
WebContinuation knot = continuationManager.lookupWebContinuation(flow.getId(), flow.getInterpreterId());
if (knot != null)
knots.add(knot);
}
// Sort them based upon access time
Collections.sort(knots, new WebContinuationByAccessTimeComparator<WebContinuation>());
// Reverse it so that the shortest times are at the top.
Collections.reverse(knots);
}
catch (ServiceException se)
{
throw new UIException("Unable to query continuation states.",se);
}
// LIST: Flows
Table activeFlows = div.addTable("knots",1,1);
activeFlows.setHead(T_knots_head);
Row row = activeFlows.addRow(Row.ROLE_HEADER);
row.addCellContent(T_knots_column1);
row.addCellContent(T_knots_column2);
row.addCellContent(T_knots_column3);
for (WebContinuation knot : knots)
{
String interpreter = knot.getInterpreterId();
if (interpreter != null && interpreter.length() > 45)
interpreter = "..." + interpreter.substring(interpreter.length()-43);
Message lastAccessMessage = null;
long lastAccess = System.currentTimeMillis() - knot.getLastAccessTime();
if (lastAccess > 2*60*60*1000)
lastAccessMessage = T_knots_hours.parameterize((lastAccess / (60*60*1000)));
else
lastAccessMessage = T_knots_minutes.parameterize((lastAccess / (60*1000)));
row = activeFlows.addRow();
row.addCellContent(interpreter);
row.addCellContent(lastAccessMessage);
row.addCellContent(knot.hasExpired() ? T_knots_expired : T_knots_active);
}
if (knots.size() == 0)
{
activeFlows.addRow().addCell(1, 3).addContent(T_knots_none);
}
}
/**
* Comparator to sort webcontinuations by their access times.
*/
public static class WebContinuationByAccessTimeComparator<WC extends WebContinuation> implements Comparator<WC>
{
public int compare(WC a, WC b) {
if (a.getLastAccessTime() > b.getLastAccessTime())
return 1; // A > B
else if (a.getLastAccessTime() > b.getLastAccessTime())
return -1; // B < A
return 0; // A == B
}
}
/**
* Add a section that allows administrators to activate or deactivate system-wide alerts.
*/
private void addAlerts(Division div) throws WingException
{
// Remember we're in teh alerts section
div.addHidden("alerts").setValue("true");
List form = div.addList("system-wide-alerts",List.TYPE_FORM);
form.setHead(T_alerts_head);
form.addItem(T_alerts_warning);
TextArea message = form.addItem().addTextArea("message");
message.setLabel(T_alerts_message_label);
message.setSize(5, 45);
if (SystemwideAlerts.getMessage() == null)
message.setValue(T_alerts_message_default);
else
message.setValue(SystemwideAlerts.getMessage());
Select countdown = form.addItem().addSelect("countdown");
countdown.setLabel(T_alerts_countdown_label);
countdown.addOption(0,T_alerts_countdown_none);
countdown.addOption(5,T_alerts_countdown_5);
countdown.addOption(15,T_alerts_countdown_15);
countdown.addOption(30,T_alerts_countdown_30);
countdown.addOption(60,T_alerts_countdown_60);
// Is there a current count down active?
if (SystemwideAlerts.isAlertActive() && SystemwideAlerts.getCountDownToo() - System.currentTimeMillis() > 0)
countdown.addOption(true,-1,T_alerts_countdown_keep);
else
countdown.setOptionSelected(0);
Item actions = form.addItem();
actions.addButton("submit_activate").setValue(T_alerts_submit_activate);
actions.addButton("submit_deactivate").setValue(T_alerts_submit_deactivate);
}
}

View File

@@ -0,0 +1,120 @@
/*
* ControlPanelAction.java
*
* Version: $Revision: 1.1 $
*
* Date: $Date: 2006/05/01 22:33:39 $
*
* Copyright (c) 2002, Hewlett-Packard Company and Massachusetts
* Institute of Technology. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* - 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.
*
* - Neither the name of the Hewlett-Packard Company nor the name of the
* Massachusetts Institute of Technology nor the names of their
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS 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 COPYRIGHT
* HOLDERS OR 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.
*/
package org.dspace.app.xmlui.aspect.administrative;
import java.util.HashMap;
import java.util.Map;
import org.apache.avalon.framework.parameters.Parameters;
import org.apache.cocoon.acting.AbstractAction;
import org.apache.cocoon.environment.ObjectModelHelper;
import org.apache.cocoon.environment.Redirector;
import org.apache.cocoon.environment.Request;
import org.apache.cocoon.environment.SourceResolver;
/**
* Update the alert system based upon the form submitted from the control panel.
*
* @author Scott Phillips
*/
public class ControlPanelAction extends AbstractAction
{
/**
* Either activate or deactivate the alert system.
*/
public Map act(Redirector redirector, SourceResolver resolver, Map objectModel,
String source, Parameters parameters) throws Exception
{
Request request = ObjectModelHelper.getRequest(objectModel);
// In any case update the system-wide alert system
String message = request.getParameter("message");
String countdownString = request.getParameter("countdown");
int countdown = -1;
if (countdownString != null)
{
try {
countdown = Integer.valueOf(countdownString);
}
catch (NumberFormatException nfe)
{
// just ignore it.
}
}
// Update the message
if (message != null)
SystemwideAlerts.setMessage(message);
if (countdown >= 0)
{
// Convert from minutes to milliseconds;
countdown = countdown * 60 * 1000;
// Figure out when the count down is.
long countDownTo = System.currentTimeMillis() + countdown;
// set it.
SystemwideAlerts.setCountDownToo(countDownTo);
}
if (request.getParameter("submit_activate") != null)
{
SystemwideAlerts.activateAlert();
// Ensure the alert is active for this request, return
// a success so the sitemap can add the alert in.
return new HashMap();
}
else if (request.getParameter("submit_deactivate") != null)
{
SystemwideAlerts.deactivateAlert();
}
return null;
}
}

View File

@@ -0,0 +1,325 @@
/*
* FlowAuthorizationUtils.java
*
* Version: $Revision: 1.3 $
*
* Date: $Date: 2006/07/13 23:20:54 $
*
* Copyright (c) 2002, Hewlett-Packard Company and Massachusetts
* Institute of Technology. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* - 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.
*
* - Neither the name of the Hewlett-Packard Company nor the name of the
* Massachusetts Institute of Technology nor the names of their
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS 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 COPYRIGHT
* HOLDERS OR 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.
*/
package org.dspace.app.xmlui.aspect.administrative;
import java.sql.SQLException;
import java.util.List;
import org.dspace.app.xmlui.wing.Message;
import org.dspace.authorize.AuthorizeException;
import org.dspace.authorize.AuthorizeManager;
import org.dspace.authorize.PolicySet;
import org.dspace.authorize.ResourcePolicy;
import org.dspace.content.Bitstream;
import org.dspace.content.Bundle;
import org.dspace.content.Collection;
import org.dspace.content.Community;
import org.dspace.content.DSpaceObject;
import org.dspace.content.Item;
import org.dspace.core.Context;
import org.dspace.eperson.Group;
import org.dspace.handle.HandleManager;
import org.dspace.core.Constants;
/**
*
* FIXME: add documentation
*
* @author Alexey maslov
*/
public class FlowAuthorizationUtils {
/** Language Strings */
//example language string
// private static final Message T_add_eperson_success_notice =
// new Message("default","xmlui.administrative.FlowUtils.add-eperson-success-notice");
/**
* Resolve an identifier submitted into the item lookup box. If it contains a slash, it's assumed to be a
* handle and is resolved by that mechanism into an item, collection or community. Otherwise, it's assumed
* to be an item and looked up by ID.
*
* @param context The current DSpace context.
* @param identifier The identifier that is to be resolved.
* @return A process result's object.
*/
public static FlowResult resolveItemIdentifier(Context context, String identifier) throws SQLException
{
FlowResult result = new FlowResult();
result.setContinue(false);
//Check whether it's a handle or internal id (by check ing if it has a slash in the string)
if (identifier.contains("/")) {
DSpaceObject dso = HandleManager.resolveToObject(context, identifier);
if (dso != null && dso.getType() == Constants.ITEM) {
result.setParameter("itemID", dso.getID());
result.setParameter("type", Constants.ITEM);
result.setContinue(true);
return result;
}
else if (dso != null && dso.getType() == Constants.COLLECTION) {
result.setParameter("collectionID", dso.getID());
result.setParameter("type", Constants.COLLECTION);
result.setContinue(true);
return result;
}
else if (dso != null && dso.getType() == Constants.COMMUNITY) {
result.setParameter("communityID", dso.getID());
result.setParameter("type", Constants.COMMUNITY);
result.setContinue(true);
return result;
}
}
// Otherwise, it's assumed to be a DSpace Item
else {
Item item = null;
try {
item = Item.find(context, Integer.valueOf(identifier));
} catch (NumberFormatException e) {
// ignoring the exception in case of a malformed input string
}
if (item != null) {
result.setParameter("itemID", item.getID());
result.setParameter("type", Constants.ITEM);
result.setContinue(true);
return result;
}
}
result.addError("identifier");
return result;
}
/**
* Process the editing of an existing or a newly created policy.
*
* @param context The current DSpace context.
* @param objectType The type of the policy's parent object (ITEM, COLLECTION, COMMUNITY)
* @param objectID The ID of the policy's parent object
* @param policyID The ID of the policy being edited (-1 if a new policy is being created)
* @param groupID The ID of the group to be associated with this policy
* @param actionID The ID of the action (dependent on the objectType) to be associated with this policy
* @return A process result's object.
*/
public static FlowResult processEditPolicy(Context context, int objectType, int objectID, int policyID, int groupID, int actionID) throws SQLException, AuthorizeException
{
FlowResult result = new FlowResult();
boolean added = false;
ResourcePolicy policy = ResourcePolicy.find(context, policyID);
/* First and foremost, if no group or action was selected, throw an error back to the user */
if (actionID == -1) {
result.setContinue(false);
result.addError("action_id");
return result;
}
if (groupID == -1) {
result.setContinue(false);
result.addError("group_id");
return result;
}
/* If the policy doesn't exist, cretae a new one and set its parent resource */
DSpaceObject policyParent = null;
if (policy == null)
{
policy = ResourcePolicy.create(context);
switch (objectType) {
case Constants.COMMUNITY: policyParent = Community.find(context, objectID); break;
case Constants.COLLECTION: policyParent = Collection.find(context, objectID); break;
case Constants.ITEM: policyParent = Item.find(context, objectID); break;
case Constants.BUNDLE: policyParent = Bundle.find(context, objectID); break;
case Constants.BITSTREAM: policyParent = Bitstream.find(context, objectID); break;
}
policy.setResource(policyParent);
added = true;
}
Group group = Group.find(context, groupID);
// modify the policy
policy.setAction(actionID);
policy.setGroup(group);
// propagate the changes to the logo, which is treated on the same level as the parent object
Bitstream logo = null;
DSpaceObject logoContainer = null;
if (objectType == Constants.COLLECTION)
{
logoContainer = Collection.find(context, objectID);
logo = ((Collection)logoContainer).getLogo();
}
else if (objectType == Constants.COMMUNITY)
{
logoContainer = Community.find(context, objectID);
logo = ((Community)logoContainer).getLogo();
}
if (logo != null)
{
List policySet = AuthorizeManager.getPolicies(context, logoContainer);
AuthorizeManager.removeAllPolicies(context, logo);
AuthorizeManager.addPolicies(context, policySet, logo);
}
// Perform the update action
policy.update();
context.commit();
result.setContinue(true);
result.setOutcome(true);
if (added) result.setMessage(new Message("default","A new policy was created successfully"));
else result.setMessage(new Message("default","The policy was edited successfully"));
result.setParameter("policyID", policy.getID());
return result;
}
/**
* Delete the policies specified by the policyIDs parameter. This assumes that the
* deletion has been confirmed.
*
* @param context The current DSpace context
* @param policyIDs The unique ids of the policies being deleted.
* @return A process result's object.
*/
public static FlowResult processDeletePolicies(Context context, String[] policyIDs) throws NumberFormatException, SQLException
{
FlowResult result = new FlowResult();
for (String id : policyIDs)
{
ResourcePolicy policyDeleted = ResourcePolicy.find(context, Integer.valueOf(id));
policyDeleted.delete();
}
result.setContinue(true);
result.setOutcome(true);
result.setMessage(new Message("default","The policies were deleted successfully"));
return result;
}
/**
* Process addition of a several authorizations at once, as entered in the wildcard/advanced authorizations tool
*
* @param context The current DSpace context.
* @param groupIDs The IDs of the groups to be associated with the newly created policies
* @param actionID The ID of the action to be associated with the policies
* @param resourceID Whether the policies will apply to Items or Bitstreams
* @param collectionIDs The IDs of the collections that the policies will be applied to
* @return A process result's object.
*/
public static FlowResult processAdvancedPolicyAdd(Context context, String[] groupIDs, int actionID,
int resourceID, String [] collectionIDs) throws NumberFormatException, SQLException, AuthorizeException
{
FlowResult result = new FlowResult();
for (String groupID : groupIDs)
{
for (String collectionID : collectionIDs)
{
PolicySet.setPolicies(context, Constants.COLLECTION, Integer.valueOf(collectionID),
resourceID, actionID, Integer.valueOf(groupID), false, false);
// if it's a bitstream, do it to the bundle too
if (resourceID == Constants.BITSTREAM)
{
PolicySet.setPolicies(context, Constants.COLLECTION, Integer.valueOf(collectionID),
Constants.BUNDLE, actionID, Integer.valueOf(groupID), false, false);
}
}
}
result.setContinue(true);
result.setOutcome(true);
result.setMessage(new Message("default","The policies were added successfully!"));
return result;
}
/**
* Process the deletion of all authorizations across a set of collections, regardless of associated
* actions or groups. This functionality should probably not be used, ever, unless the goal to
* completely reset a collection for one reason or another.
*
* @param context The current DSpace context.
* @param resourceID Whether the policies will apply to Items or Bitstreams
* @param collectionIDs The IDs of the collections that the policy wipe will be applied to
* @return A process result's object.
*/
public static FlowResult processAdvancedPolicyDelete(Context context, int resourceID, String [] collectionIDs)
throws NumberFormatException, SQLException, AuthorizeException
{
FlowResult result = new FlowResult();
for (String collectionID : collectionIDs)
{
PolicySet.setPolicies(context, Constants.COLLECTION, Integer.valueOf(collectionID),
resourceID, 0, 0, false, true);
// if it's a bitstream, do it to the bundle too
if (resourceID == Constants.BITSTREAM)
{
PolicySet.setPolicies(context, Constants.COLLECTION, Integer.valueOf(collectionID),
Constants.BUNDLE, 0, 0, false, true);
}
}
result.setContinue(true);
result.setOutcome(true);
result.setMessage(new Message("default","The policies for the selected collections were cleared."));
return result;
}
}

View File

@@ -0,0 +1,837 @@
/*
* FlowContainerUtils.java
*
* Version: $Revision: 1.3 $
*
* Date: $Date: 2006/07/13 23:20:54 $
*
* Copyright (c) 2002, Hewlett-Packard Company and Massachusetts
* Institute of Technology. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* - 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.
*
* - Neither the name of the Hewlett-Packard Company nor the name of the
* Massachusetts Institute of Technology nor the names of their
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS 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 COPYRIGHT
* HOLDERS OR 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.
*/package org.dspace.app.xmlui.aspect.administrative;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.sql.SQLException;
import java.util.List;
import org.apache.cocoon.environment.Request;
import org.apache.cocoon.servlet.multipart.Part;
import org.dspace.app.xmlui.utils.UIException;
import org.dspace.app.xmlui.wing.Message;
import org.dspace.authorize.AuthorizeException;
import org.dspace.authorize.AuthorizeManager;
import org.dspace.authorize.ResourcePolicy;
import org.dspace.content.Collection;
import org.dspace.content.Community;
import org.dspace.content.Item;
import org.dspace.core.Constants;
import org.dspace.core.Context;
import org.dspace.eperson.Group;
import org.jdom.JDOMException;
import org.jdom.input.SAXBuilder;
/**
* Utility methods to processes actions on Communities and Collections.
*
* @author scott phillips
*/
public class FlowContainerUtils
{
/** Possible Collection roles */
public static final String ROLE_ADMIN = "ADMIN";
public static final String ROLE_WF_STEP1 = "WF_STEP1";
public static final String ROLE_WF_STEP2 = "WF_STEP2";
public static final String ROLE_WF_STEP3 = "WF_STEP3";
public static final String ROLE_SUBMIT = "SUBMIT";
public static final String ROLE_DEFAULT_READ = "DEFAULT_READ";
// Collection related functions
/**
* Process the collection metadata edit form.
*
* @param context The current DSpace context.
* @param collectionID The collection id.
* @param deleteLogo Determines if the logo should be deleted along with the metadata editing action.
* @param request the Cocoon request object
* @return A process result's object.
*/
public static FlowResult processEditCollection(Context context, int collectionID, boolean deleteLogo, Request request) throws SQLException, IOException, AuthorizeException
{
FlowResult result = new FlowResult();
Collection collection = Collection.find(context, collectionID);
// Get the metadata
String name = request.getParameter("name");
String shortDescription = request.getParameter("short_description");
String introductoryText = request.getParameter("introductory_text");
String copyrightText = request.getParameter("copyright_text");
String sideBarText = request.getParameter("side_bar_text");
String license = request.getParameter("license");
String provenanceDescription = request.getParameter("provenance_description");
// If they don't have a name then make it untitled.
if (name == null || name.length() == 0)
name = "Untitled";
// If empty, make it null.
if (shortDescription != null && shortDescription.length() == 0)
shortDescription = null;
if (introductoryText != null && introductoryText.length() == 0)
introductoryText = null;
if (copyrightText != null && copyrightText.length() == 0)
copyrightText = null;
if (sideBarText != null && sideBarText.length() == 0)
sideBarText = null;
if (license != null && license.length() == 0)
license = null;
if (provenanceDescription != null && provenanceDescription.length() == 0)
provenanceDescription = null;
// Save the metadata
collection.setMetadata("name", name);
collection.setMetadata("short_description", shortDescription);
collection.setMetadata("introductory_text", introductoryText);
collection.setMetadata("copyright_text", copyrightText);
collection.setMetadata("side_bar_text", sideBarText);
collection.setMetadata("license", license);
collection.setMetadata("provenance_description", provenanceDescription);
// Change or delete the logo
if (deleteLogo)
{
// Remove the logo
collection.setLogo(null);
}
else
{
// Update the logo
Object object = request.get("logo");
Part filePart = null;
if (object instanceof Part)
filePart = (Part) object;
if (filePart != null && filePart.getSize() > 0)
{
InputStream is = filePart.getInputStream();
collection.setLogo(is);
}
}
// Save everything
collection.update();
context.commit();
// No notice...
result.setContinue(true);
return result;
}
/**
* Look up the id of the template item for a given collection.
*
* @param context The current DSpace context.
* @param collectionID The collection id.
* @return The id of the template item.
* @throws IOException
*/
public static int getTemplateItemID(Context context, int collectionID) throws SQLException, AuthorizeException, IOException
{
Collection collection = Collection.find(context, collectionID);
Item template = collection.getTemplateItem();
if (template == null)
{
collection.createTemplateItem();
template = collection.getTemplateItem();
collection.update();
template.update();
context.commit();
}
return template.getID();
}
/**
* Look up the id of a group authorized for one of the given roles. If no group is currently
* authorized to preform this role then a new group will be created and assigned the role.
*
* @param context The current DSpace context.
* @param collectionID The collection id.
* @param roleName ADMIN, WF_STEP1, WF_STEP2, WF_STEP3, SUBMIT, DEFAULT_READ.
* @return The id of the group associated with that particular role, or -1 if the role was not found.
*/
public static int getCollectionRole(Context context, int collectionID, String roleName) throws SQLException, AuthorizeException, IOException
{
Collection collection = Collection.find(context, collectionID);
// Determine the group based upon wich role we are looking for.
Group role = null;
if (ROLE_ADMIN.equals(roleName))
{
role = collection.getAdministrators();
if (role == null)
role = collection.createAdministrators();
}
else if (ROLE_SUBMIT.equals(roleName))
{
role = collection.getSubmitters();
if (role == null)
role = collection.createSubmitters();
}
else if (ROLE_WF_STEP1.equals(roleName))
{
role = collection.getWorkflowGroup(1);
if (role == null)
role = collection.createWorkflowGroup(1);
}
else if (ROLE_WF_STEP2.equals(roleName))
{
role = collection.getWorkflowGroup(2);
if (role == null)
role = collection.createWorkflowGroup(2);
}
else if (ROLE_WF_STEP3.equals(roleName))
{
role = collection.getWorkflowGroup(3);
if (role == null)
role = collection.createWorkflowGroup(3);
}
// In case we needed to create a group, save our changes
collection.update();
context.commit();
// If the role name was valid then role should be non null,
if (role != null)
return role.getID();
return -1;
}
/**
* Delete one of collection's roles
*
* @param context The current DSpace context.
* @param collectionID The collection id.
* @param roleName ADMIN, WF_STEP1, WF_STEP2, WF_STEP3, SUBMIT, DEFAULT_READ.
* @param groupID The id of the group associated with this role.
* @return A process result's object.
*/
public static FlowResult processDeleteCollectionRole(Context context, int collectionID, String roleName, int groupID) throws SQLException, UIException, IOException, AuthorizeException
{
FlowResult result = new FlowResult();
Collection collection = Collection.find(context,collectionID);
Group role = Group.find(context, groupID);
// First, Unregister the role
if (ROLE_ADMIN.equals(roleName))
{
// FIXME: This should unregister this role from the collection
// object however there is no method available to do this. Once
// Manakin is integrated into dspace this situatiotion should be
// resolved.
throw new UIException("This operation can not be preformed untill the DSpace API is modified to enable the removal of collection administrators.");
}
else if (ROLE_SUBMIT.equals(roleName))
{
// FIXME: This should unregister this role from the collection
// object however there is no method available to do this. Once
// Manakin is integrated into dspace this situatiotion should be
// resolved.
throw new UIException("This operation can not be preformed untill the DSpace API is modified to enable the removal of collection submitters.");
}
else if (ROLE_WF_STEP1.equals(roleName))
{
collection.setWorkflowGroup(1, null);
}
else if (ROLE_WF_STEP2.equals(roleName))
{
collection.setWorkflowGroup(2, null);
}
else if (ROLE_WF_STEP3.equals(roleName))
{
collection.setWorkflowGroup(3, null);
}
// Second, remove all outhorizations for this role by searching for all policies that this
// group has on the collection and remove them otherwise the delete will fail because
// there are dependencies.
@SuppressWarnings("unchecked") // the cast is correct
List<ResourcePolicy> policies = AuthorizeManager.getPolicies(context,collection);
for (ResourcePolicy policy : policies)
{
if (policy.getGroupID() == groupID)
policy.delete();
}
// Finaly, Delete the role's actual group.
collection.update();
role.delete();
context.commit();
result.setContinue(true);
result.setOutcome(true);
result.setMessage(new Message("default","The role was successfully deleted."));
return result;
}
/**
* Look up the id of a group authorized for one of the given roles. If no group is currently
* authorized to preform this role then a new group will be created and assigned the role.
*
* @param context The current DSpace context.
* @param collectionID The collection id.
* @param roleName ADMIN, WF_STEP1, WF_STEP2, WF_STEP3, SUBMIT, DEFAULT_READ.
* @return The id of the group associated with that particular role.
*/
public static int getCollectionDefaultRead(Context context, int collectionID) throws SQLException, AuthorizeException
{
Collection collection = Collection.find(context,collectionID);
Group[] itemGroups = AuthorizeManager.getAuthorizedGroups(context, collection, Constants.DEFAULT_ITEM_READ);
Group[] bitstreamGroups = AuthorizeManager.getAuthorizedGroups(context, collection, Constants.DEFAULT_BITSTREAM_READ);
if (itemGroups.length != 1 && bitstreamGroups.length != 1)
// If there are more than one groups assigned either of these privleges then this role based method will not work.
// The user will need to go to the authorization section to manualy straight this out.
return -1;
Group itemGroup = itemGroups[0];
Group bitstreamGroup = bitstreamGroups[0];
if (itemGroup.getID() != bitstreamGroup.getID())
// If the same group is not assigned both of these priveleges then this role based method will not work. The user
// will need to go to the authorization section to manualy straighten this out.
return -1;
return itemGroup.getID();
}
/**
* Change default privleges from the anonymous group to a new group that will be created and
* approrpate privleges assigned. The id of this new group will be returned.
*
* @param context The current DSpace context.
* @param collectionID The collection id.
* @return The group ID of the new group.
*/
public static int createCollectionDefaultReadGroup(Context context, int collectionID) throws SQLException, AuthorizeException, UIException
{
int roleID = getCollectionDefaultRead(context, collectionID);
if (roleID != 0)
throw new UIException("Unable to create a new default read group because either the group allready exists or multiple groups are assigned the default privleges.");
Collection collection = Collection.find(context,collectionID);
Group role = Group.create(context);
role.setName("COLLECTION_"+collection.getID() +"_DEFAULT_READ");
// Remove existing privleges from the anynomous group.
AuthorizeManager.removePoliciesActionFilter(context, collection, Constants.DEFAULT_ITEM_READ);
AuthorizeManager.removePoliciesActionFilter(context, collection, Constants.DEFAULT_BITSTREAM_READ);
// Grant our new role the default privleges.
AuthorizeManager.addPolicy(context, collection, Constants.DEFAULT_ITEM_READ, role);
AuthorizeManager.addPolicy(context, collection, Constants.DEFAULT_BITSTREAM_READ, role);
// Committ the changes
role.update();
context.commit();
return role.getID();
}
/**
* Change the default read priveleges to the anonymous group.
*
* If getCollectionDefaultRead() returns -1 or the anonymous group then nothing
* is done.
*
* @param context The current DSpace context.
* @param collectionID The collection id.
* @return A process result's object.
*/
public static FlowResult changeCollectionDefaultReadToAnonymous(Context context, int collectionID) throws SQLException, AuthorizeException, UIException
{
FlowResult result = new FlowResult();
int roleID = getCollectionDefaultRead(context, collectionID);
if (roleID < 1)
{
throw new UIException("Unable to delete the default read role because the role is either allready assigned to the anonymous group or multiple groups are assigned the default priveleges.");
}
Collection collection = Collection.find(context,collectionID);
Group role = Group.find(context, roleID);
Group anonymous = Group.find(context,0);
// Delete the old role, this will remove the default privleges.
role.delete();
// Set anonymous as the default read group.
AuthorizeManager.addPolicy(context, collection, Constants.DEFAULT_ITEM_READ, anonymous);
AuthorizeManager.addPolicy(context, collection, Constants.DEFAULT_BITSTREAM_READ, anonymous);
// Commit the changes
context.commit();
result.setContinue(true);
result.setOutcome(true);
result.setMessage(new Message("default","All new items submitted to this collection will default to anonymous read."));
return result;
}
/**
* Delete collection itself
*
* @param context The current DSpace context.
* @param collectionID The collection id.
* @return A process result's object.
*/
public static FlowResult processDeleteCollection(Context context, int collectionID) throws SQLException, AuthorizeException, IOException
{
FlowResult result = new FlowResult();
Collection collection = Collection.find(context, collectionID);
Community[] parents = collection.getCommunities();
for (Community parent: parents)
{
parent.removeCollection(collection);
parent.update();
}
context.commit();
result.setContinue(true);
result.setOutcome(true);
result.setMessage(new Message("default","The collection was successfully deleted."));
return result;
}
/**
* Create a new collection
*
* @param context The current DSpace context.
* @param communityID The id of the parent community.
* @return A process result's object.
*/
public static FlowResult processCreateCollection(Context context, int communityID, Request request) throws SQLException, AuthorizeException, IOException
{
FlowResult result = new FlowResult();
Community parent = Community.find(context, communityID);
Collection newCollection = parent.createCollection();
// Get the metadata
String name = request.getParameter("name");
String shortDescription = request.getParameter("short_description");
String introductoryText = request.getParameter("introductory_text");
String copyrightText = request.getParameter("copyright_text");
String sideBarText = request.getParameter("side_bar_text");
String license = request.getParameter("license");
String provenanceDescription = request.getParameter("provenance_description");
// If they don't have a name then make it untitled.
if (name == null || name.length() == 0)
name = "Untitled";
// If empty, make it null.
if (shortDescription != null && shortDescription.length() == 0)
shortDescription = null;
if (introductoryText != null && introductoryText.length() == 0)
introductoryText = null;
if (copyrightText != null && copyrightText.length() == 0)
copyrightText = null;
if (sideBarText != null && sideBarText.length() == 0)
sideBarText = null;
if (license != null && license.length() == 0)
license = null;
if (provenanceDescription != null && provenanceDescription.length() == 0)
provenanceDescription = null;
// Save the metadata
newCollection.setMetadata("name", name);
newCollection.setMetadata("short_description", shortDescription);
newCollection.setMetadata("introductory_text", introductoryText);
newCollection.setMetadata("copyright_text", copyrightText);
newCollection.setMetadata("side_bar_text", sideBarText);
newCollection.setMetadata("license", license);
newCollection.setMetadata("provenance_description", provenanceDescription);
// Set the logo
Object object = request.get("logo");
Part filePart = null;
if (object instanceof Part)
filePart = (Part) object;
if (filePart != null && filePart.getSize() > 0)
{
InputStream is = filePart.getInputStream();
newCollection.setLogo(is);
}
// Save everything
newCollection.update();
context.commit();
// success
result.setContinue(true);
result.setOutcome(true);
result.setMessage(new Message("default","The collection was successfully created."));
result.setParameter("collectionID", newCollection.getID());
return result;
}
// Community related functions
/**
* Create a new community
*
* @param context The current DSpace context.
* @param communityID The id of the parent community (-1 for a top-level community).
* @return A process result's object.
*/
public static FlowResult processCreateCommunity(Context context, int communityID, Request request) throws AuthorizeException, IOException, SQLException
{
FlowResult result = new FlowResult();
Community parent = Community.find(context, communityID);
Community newCommunity;
if (parent != null)
newCommunity = parent.createSubcommunity();
else
newCommunity = Community.create(null, context);
String name = request.getParameter("name");
String shortDescription = request.getParameter("short_description");
String introductoryText = request.getParameter("introductory_text");
String copyrightText = request.getParameter("copyright_text");
String sideBarText = request.getParameter("side_bar_text");
// If they don't have a name then make it untitled.
if (name == null || name.length() == 0)
name = "Untitled";
// If empty, make it null.
if (shortDescription != null && shortDescription.length() == 0)
shortDescription = null;
if (introductoryText != null && introductoryText.length() == 0)
introductoryText = null;
if (copyrightText != null && copyrightText.length() == 0)
copyrightText = null;
if (sideBarText != null && sideBarText.length() == 0)
sideBarText = null;
newCommunity.setMetadata("name", name);
newCommunity.setMetadata("short_description", shortDescription);
newCommunity.setMetadata("introductory_text", introductoryText);
newCommunity.setMetadata("copyright_text", copyrightText);
newCommunity.setMetadata("side_bar_text", sideBarText);
// Upload the logo
Object object = request.get("logo");
Part filePart = null;
if (object instanceof Part)
filePart = (Part) object;
if (filePart != null && filePart.getSize() > 0)
{
InputStream is = filePart.getInputStream();
newCommunity.setLogo(is);
}
// Save everything
newCommunity.update();
context.commit();
// success
result.setContinue(true);
result.setOutcome(true);
result.setMessage(new Message("default","The community was successfully created."));
result.setParameter("communityID", newCommunity.getID());
return result;
}
/**
* Process the community metadata edit form.
*
* @param context The current DSpace context.
* @param communityID The community id.
* @param deleteLogo Determines if the logo should be deleted along with the metadata editing action.
* @param request the Cocoon request object
* @return A process result's object.
*/
public static FlowResult processEditCommunity(Context context, int communityID, boolean deleteLogo, Request request) throws AuthorizeException, IOException, SQLException
{
FlowResult result = new FlowResult();
Community community = Community.find(context, communityID);
String name = request.getParameter("name");
String shortDescription = request.getParameter("short_description");
String introductoryText = request.getParameter("introductory_text");
String copyrightText = request.getParameter("copyright_text");
String sideBarText = request.getParameter("side_bar_text");
// If they don't have a name then make it untitled.
if (name == null || name.length() == 0)
name = "Untitled";
// If empty, make it null.
if (shortDescription != null && shortDescription.length() == 0)
shortDescription = null;
if (introductoryText != null && introductoryText.length() == 0)
introductoryText = null;
if (copyrightText != null && copyrightText.length() == 0)
copyrightText = null;
if (sideBarText != null && sideBarText.length() == 0)
sideBarText = null;
// Save the data
community.setMetadata("name", name);
community.setMetadata("short_description", shortDescription);
community.setMetadata("introductory_text", introductoryText);
community.setMetadata("copyright_text", copyrightText);
community.setMetadata("side_bar_text", sideBarText);
if (deleteLogo)
{
// Remove the logo
community.setLogo(null);
}
else
{
// Update the logo
Object object = request.get("logo");
Part filePart = null;
if (object instanceof Part)
filePart = (Part) object;
if (filePart != null && filePart.getSize() > 0)
{
InputStream is = filePart.getInputStream();
community.setLogo(is);
}
}
// Save everything
community.update();
context.commit();
// No notice...
result.setContinue(true);
return result;
}
/**
* Delete community itself
*
* @param context The current DSpace context.
* @param communityID The community id.
* @return A process result's object.
*/
public static FlowResult processDeleteCommunity(Context context, int communityID) throws SQLException, AuthorizeException, IOException
{
FlowResult result = new FlowResult();
Community community = Community.find(context, communityID);
community.delete();
context.commit();
result.setContinue(true);
result.setOutcome(true);
result.setMessage(new Message("default","The community was successfully deleted."));
return result;
}
/**
* Check whether this metadata value is a proper XML fragment. If the value is not
* then an error message will be returned that might (sometimes not) tell the user how
* to correct the problem.
*
* @param value The metadat's value
* @return An error string of the problem or null if there is no problem with the metadata's value.
*/
public static String checkXMLFragment(String value)
{
// escape the ampersand correctly;
value = escapeXMLEntities(value);
// Try and parse the XML into a mini-dom
String xml = "<fragment>"+value+"</fragment>";
ByteArrayInputStream inputStream = new ByteArrayInputStream(xml.getBytes());
SAXBuilder builder = new SAXBuilder();
try
{
// This will generate an error if not valid XML.
builder.build(inputStream);
}
catch (JDOMException jdome)
{
// It's not XML
return jdome.getMessage();
}
catch (IOException ioe)
{
// This shouldn't ever occure because we are parsing
// an in-memory string, but in case it does we'll just return
// it as a normal error.
return ioe.getMessage();
}
return null;
}
/**
* Sanatize any XML that was inputed by the user, this will clean up
* any unescaped characters so that they can be stored as proper XML.
* These are errors that in general we want to take care of on behalf
* of the user.
*
* @param value The unsantized value
* @return A sanatized value
*/
public static String escapeXMLEntities(String value)
{
if (value == null)
return null;
// Escape any XML entities
int amp = -1;
while ((amp = value.indexOf('&', amp+1)) > -1)
{
// Is it an xml entity named by number?
if (substringCompare(value,amp+1,'#'))
continue;
// &amp;
if (substringCompare(value,amp+1,'a','m','p',';'))
continue;
// &apos;
if (substringCompare(value,amp+1,'a','p','o','s',';'))
continue;
// &quot;
if (substringCompare(value,amp+1,'q','u','o','t',';'))
continue;
// &lt;
if (substringCompare(value,amp+1,'l','t',';'))
continue;
// &gt;
if (substringCompare(value,amp+1,'g','t',';'))
continue;
// Replace the ampersand with an XML entity.
value = value.substring(0,amp) + "&amp;" + value.substring(amp+1);
}
return value;
}
/**
* Check if the given character sequence is located in the given
* string at the specified index. If it is then return true, otherwise false.
*
* @param string The string to test against
* @param index The location within the string
* @param characters The character sequence to look for.
* @return true if the character sequence was found, otherwise false.
*/
private static boolean substringCompare(String string, int index, char ... characters)
{
// Is the string long enough?
if (string.length() <= index + characters.length)
return false;
// Do all the characters match?
for (char character : characters)
{
if (string.charAt(index) != character)
return false;
index++;
}
return false;
}
}

View File

@@ -0,0 +1,275 @@
/*
* FlowEPersonUtils.java
*
* Version: $Revision: 1.3 $
*
* Date: $Date: 2006/07/13 23:20:54 $
*
* Copyright (c) 2002, Hewlett-Packard Company and Massachusetts
* Institute of Technology. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* - 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.
*
* - Neither the name of the Hewlett-Packard Company nor the name of the
* Massachusetts Institute of Technology nor the names of their
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS 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 COPYRIGHT
* HOLDERS OR 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.
*/
package org.dspace.app.xmlui.aspect.administrative;
import java.io.IOException;
import java.sql.SQLException;
import java.util.Map;
import javax.mail.MessagingException;
import org.apache.cocoon.environment.Request;
import org.dspace.app.xmlui.utils.AuthenticationUtil;
import org.dspace.app.xmlui.wing.Message;
import org.dspace.authorize.AuthorizeException;
import org.dspace.core.Context;
import org.dspace.eperson.AccountManager;
import org.dspace.eperson.EPerson;
import org.dspace.eperson.EPersonDeletionException;
/**
* Utility methods to processes actions on EPeople. These methods are used
* exclusivly from the administrative flow scripts.
*
* @author scott phillips
*/
public class FlowEPersonUtils {
/** Language Strings */
private static final Message T_add_eperson_success_notice =
new Message("default","xmlui.administrative.FlowEPersonUtils.add_eperson_success_notice");
private static final Message T_edit_eperson_success_notice =
new Message("default","xmlui.administrative.FlowEPersonUtils.edit_eperson_success_notice");
private static final Message T_reset_password_success_notice =
new Message("default","xmlui.administrative.FlowEPersonUtils.reset_password_success_notice");
private static final Message t_delete_eperson_success_notice =
new Message("default","xmlui.administrative.FlowEPersonUtils.delete_eperson_success_notice");
/**
* Add a new eperson. This method will check that the email address,
* first name, and last name are non empty. Also a check is preformed
* to see if the requested email address is allready in use by another
* user.
*
* @param context The current DSpace context
* @param request The HTTP request parameters
* @param objectModel Cocoon's object model
* @return A process result's object.
*/
public static FlowResult processAddEPerson(Context context, Request request, Map objectModel) throws SQLException, AuthorizeException
{
FlowResult result = new FlowResult();
result.setContinue(false); // default to no continue
// Get all our request parameters
String email = request.getParameter("email_address");
String first = request.getParameter("first_name");
String last = request.getParameter("last_name");
String phone = request.getParameter("phone");
boolean login = (request.getParameter("can_log_in") != null) ? true : false;
boolean certificate = (request.getParameter("certificate") != null) ? true : false;
// If we have errors, the form needs to be resubmitted to fix those problems
if (email.length() == 0)
result.addError("email_address");
if (first.length() == 0)
result.addError("first_name");
if (last.length() == 0)
result.addError("last_name");
// Check if the email address is all ready being used.
EPerson potentialDupicate = EPerson.findByEmail(context,email);
if (potentialDupicate != null)
{
// special error that the front end knows about.
result.addError("eperson_email_key");
}
// No errors, so we try to create the EPerson from the data provided
if (result.getErrors() == null)
{
EPerson newPerson = AuthenticationUtil.createNewEperson(objectModel,email);
newPerson.setFirstName(first);
newPerson.setLastName(last);
newPerson.setMetadata("phone", phone);
newPerson.setCanLogIn(login);
newPerson.setRequireCertificate(certificate);
newPerson.setSelfRegistered(false);
newPerson.update();
context.commit();
// success
result.setContinue(true);
result.setOutcome(true);
result.setMessage(T_add_eperson_success_notice);
result.setParameter("epersonID", newPerson.getID());
}
return result;
}
/**
* Edit an eperson's metadata, the email address, first name, and last name are all
* required. The user's email address can be updated but it must remain unique, if
* the email address allready exists then the an error is produced.
*
* @param context The current DSpace context
* @param request The HTTP request parameters
* @param objectModel Cocoon's object model
* @param epersonID The unique id of the eperson being edited.
* @return A process result's object.
*/
public static FlowResult processEditEPerson(Context context, Request request, Map ObjectModel, int epersonID) throws SQLException, AuthorizeException
{
FlowResult result = new FlowResult();
result.setContinue(false); // default to failure
// Get all our request parameters
String email = request.getParameter("email_address");
String first = request.getParameter("first_name");
String last = request.getParameter("last_name");
String phone = request.getParameter("phone");
boolean login = (request.getParameter("can_log_in") != null) ? true : false;
boolean certificate = (request.getParameter("certificate") != null) ? true : false;
// If we have errors, the form needs to be resubmitted to fix those problems
if (email.length() == 0)
result.addError("email_address");
if (first.length() == 0)
result.addError("first_name");
if (last.length() == 0)
result.addError("last_name");
// No errors, so we edit the EPerson with the data provided
if (result.getErrors() == null)
{
// Grab the person in question
EPerson personModified = EPerson.find(context, epersonID);
// Make sure the email address we are changing to is unique
if (personModified.getEmail() != email)
{
EPerson potentialDupicate = EPerson.findByEmail(context,email);
if (potentialDupicate == null)
{
personModified.setEmail(email);
}
else if (potentialDupicate != personModified)
{
// set a special field in error so that the transformer can display a pretty error.
result.addError("eperson_email_key");
return result;
}
}
if (personModified.getFirstName() != first) {
personModified.setFirstName(first);
}
if (personModified.getLastName() != last) {
personModified.setLastName(last);
}
if (personModified.getMetadata("phone") != phone) {
personModified.setMetadata("phone", phone);
}
personModified.setCanLogIn(login);
personModified.setRequireCertificate(certificate);
personModified.update();
context.commit();
result.setContinue(true);
result.setOutcome(true);
// FIXME: rename this message
result.setMessage(T_edit_eperson_success_notice);
}
// Everything was fine
return result;
}
/**
* Send the user a forgot password email message. The message will
* contain a token that the user can use to login and pick a new password.
*
* @param context The current DSpace context
* @param epersonID The unique id of the eperson being edited.
* @return A process result's object.
*/
public static FlowResult processResetPassword(Context context, int epersonID) throws IOException, MessagingException, SQLException, AuthorizeException
{
EPerson eperson = EPerson.find(context, epersonID);
// Note, this may throw an error is the email is bad.
AccountManager.sendForgotPasswordInfo(context,eperson.getEmail());
FlowResult result = new FlowResult();
result.setContinue(true);
result.setOutcome(true);
result.setMessage(T_reset_password_success_notice);
return result;
}
/**
* Delete the epeople specified by the epeopleIDs parameter. This assumes that the
* detetion has been confirmed.
*
* @param context The current DSpace context
* @param epeopleIDs The unique id of the eperson being edited.
* @return A process result's object.
*/
public static FlowResult processDeleteEPeople(Context context, String[] epeopleIDs) throws NumberFormatException, SQLException, AuthorizeException, EPersonDeletionException
{
FlowResult result = new FlowResult();
for (String id : epeopleIDs)
{
EPerson personDeleted = EPerson.find(context, Integer.valueOf(id));
personDeleted.delete();
}
result.setOutcome(true);
result.setMessage(t_delete_eperson_success_notice);
return result;
}
}

View File

@@ -0,0 +1,398 @@
/*
* FlowGroupUtils.java
*
* Version: $Revision: 1.3 $
*
* Date: $Date: 2006/07/13 23:20:54 $
*
* Copyright (c) 2002, Hewlett-Packard Company and Massachusetts
* Institute of Technology. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* - 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.
*
* - Neither the name of the Hewlett-Packard Company nor the name of the
* Massachusetts Institute of Technology nor the names of their
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS 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 COPYRIGHT
* HOLDERS OR 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.
*/package org.dspace.app.xmlui.aspect.administrative;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import org.dspace.app.xmlui.wing.Message;
import org.dspace.authorize.AuthorizeException;
import org.dspace.core.Context;
import org.dspace.eperson.EPerson;
import org.dspace.eperson.Group;
/**
* Utility methods to processes actions on Groups. These methods are used
* exclusivly from the administrative flow scripts.
*
* @author scott phillips
*/
public class FlowGroupUtils {
/** Language Strings */
private static final Message T_edit_group_success_notice =
new Message("default","xmlui.administrative.FlowGroupUtils.edit_group_success_notice");
private static final Message T_delete_group_success_notice =
new Message("default","xmlui.administrative.FlowGroupUtils.delete_group_success_notice");
/**
* Return the current name for the given group ID.
* @param context The current DSpace context.
* @param groupID The group id.
* @return The group's name.
*/
public static String getName(Context context, int groupID) throws SQLException
{
if (groupID < 0)
return "New Group";
Group group = Group.find(context,groupID);
if (group == null)
return "New Group";
return group.getName();
}
/**
* Return the list of current epeople ID's that are a member of this group.
*
* @param context The current DSpace context
* @param groupID The group's id.
* @return An array of ids.
*/
public static String[] getEPeopleMembers(Context context, int groupID) throws SQLException
{
// New group, just return an empty list
if (groupID < 0)
return new String[0];
Group group = Group.find(context,groupID);
if (group == null)
return new String[0];
EPerson[] epeople = group.getMembers();
String[] epeopleIDs = new String[epeople.length];
for (int i=0; i < epeople.length; i++)
epeopleIDs[i] = String.valueOf(epeople[i].getID());
return epeopleIDs;
}
/**
* Return the list of current group id's that are a member of this group.
*
* @param context The current DSpace context
* @param groupID The group's id.
* @return An array of ids.
*/
public static String[] getGroupMembers(Context context, int groupID) throws SQLException
{
if (groupID < 0)
return new String[0];
Group group = Group.find(context,groupID);
if (group == null)
return new String[0];
Group[] groups = group.getMemberGroups();
String[] groupIDs = new String[groups.length];
for (int i=0; i < groups.length; i++)
groupIDs[i] = String.valueOf(groups[i].getID());
return groupIDs;
}
/**
* Add the given id to the list and return a new list.
*
* @param list The current array
* @param id The new element
* @return A new combined array.
*/
public static String[] addMember(String[] list, String id)
{
// FIXME: this is terribly ineffecient.
List<String> newList = new ArrayList<String>(Arrays.asList(list));
newList.add(id);
return newList.toArray(new String[newList.size()]);
}
/**
* Remove all instances of the given id from the member list.
*
* @param list The current array
* @param id The id to remove
* @return A new combined array.
*/
public static String[] removeMember(String[] list, String id)
{
// FIXME: this is terribly ineffecient.
List<String> newList = new ArrayList<String>(Arrays.asList(list));
newList.remove(id);
return newList.toArray(new String[newList.size()]);
}
/**
* Save the group. If the name has been changed then it will be updated, if any
* members have been added or removed then they are updated.
*
* If the groupID is -1 then a new group is created.
*
* @param context The current dspace context
* @param groupID The group id, or -1 for a new group.
* @param newName The group's new name.
* @param newEPeopleIDsArray All epeople members
* @param newGroupIDsArray All group members.
* @return A result
*/
public static FlowResult processSaveGroup(Context context, int groupID, String newName, String[] newEPeopleIDsArray, String[] newGroupIDsArray) throws SQLException, AuthorizeException
{
FlowResult result = new FlowResult();
// If the new name is empty we can return in error right away.
if (newName == null || newName.length() == 0)
{
// Group's can not have blank names.
result.setContinue(false);
result.addError("group_name");
result.setOutcome(false);
result.setMessage(new Message("default","The group name may not be blank."));
return result;
}
Group group = null;
if (groupID == -1)
{
// Create a new group, check if the newName is allready in use.
Group potentialDuplicate = Group.findByName(context,newName);
if (potentialDuplicate == null)
{
// All good, create the new group.
group = Group.create(context);
group.setName(newName);
}
else
{
// The name is allready in use, return in error.
result.setContinue(false);
result.addError("group_name");
result.addError("group_name_duplicate");
result.setOutcome(false);
result.setMessage(new Message("default","The group name is allready in use"));
return result;
}
}
else
{
group = Group.find(context,groupID);
// First, check if the name is being updated.
String name = group.getName();
if (name == null || !name.equals(newName))
{
// The group name is to be updated, check if the newName is allready in use.
Group potentialDuplicate = Group.findByName(context,newName);
if (potentialDuplicate == null)
{
// All good, update the name
group.setName(newName);
}
else
{
// The name is allready in use, return in error.
result.setContinue(false);
result.addError("group_name");
result.addError("group_name_duplicate");
result.setOutcome(false);
result.setMessage(new Message("default","The group name is allready in use"));
return result;
}
}
}
// Second, Prepare to check members by turning arrays into lists
List<Integer> newEPeopleIDs = new ArrayList<Integer>();
for (String epeopleID : newEPeopleIDsArray)
newEPeopleIDs.add(Integer.valueOf(epeopleID));
List<Integer> newGroupIDs = new ArrayList<Integer>();
for (String _groupID : newGroupIDsArray)
newGroupIDs.add(Integer.valueOf(_groupID));
// Third, check if there are any members to remove
// i.e. scan the list on the group against the ids.
for (EPerson epersonMember : group.getMembers())
{
if (!newEPeopleIDs.contains(epersonMember.getID()))
{
// The current eperson is not contained in the new list.
group.removeMember(epersonMember);
}
else
{
// If they are still in the list then remove them
// from the list of people to add.
newEPeopleIDs.remove((Object)epersonMember.getID());
}
}
for (Group groupMember : group.getMemberGroups())
{
if (!newGroupIDs.contains(groupMember.getID()))
{
// The current group is not contained in the new list.
group.removeMember(groupMember);
}
else
{
// If they are still in the list then remove them
// from the list of groups to add.
newGroupIDs.remove((Object)group.getID());
}
}
// Third, check if there are any members to add
// i.e. scan the list of ids against the group.
for (Integer epersonID : newEPeopleIDs)
{
EPerson eperson = EPerson.find(context, epersonID);
group.addMember(eperson);
}
for (Integer _groupID : newGroupIDs)
{
Group _group = Group.find(context, _groupID);
group.addMember(_group);
}
// Last, create the result flow
group.update();
context.commit();
// Let's record our group id incase we created a new one.
result.setParameter("groupID", group.getID());
result.setContinue(true);
result.setOutcome(true);
result.setMessage(T_edit_group_success_notice);
return result;
}
/**
* Remove the specified groups. It is assumed that the user has allready confirm this selection.
*
* @param context The current DSpace context
* @param groupIDs A list of groups to be removed.
* @return A results object.
*/
public static FlowResult processDeleteGroups(Context context, String[] groupIDs) throws SQLException
{
FlowResult result = new FlowResult();
result.setContinue(true);
for (String id : groupIDs)
{
Group groupDeleted = Group.find(context, Integer.valueOf(id));
groupDeleted.delete();
}
result.setOutcome(true);
result.setMessage(T_delete_group_success_notice);
return result;
}
/**
* The collection prefix, all groups which are specific to
* a collection start with this.
*/
private static final String COLLECTION_PREFIX = "COLLECTION_";
/**
* These are the possible collection suffixes, all groups which are
* specific to a collection will end with one of these. The collection
* id should be inbetween the prefix and the suffix.
*/
private static final String[] COLLECTION_SUFFIXES = {"_SUBMIT","_ADMIN","_WFSTEP_1","_WORKFLOW_STEP_1","_WFSTEP_2","_WORKFLOW_STEP_2","_WFSTEP_3","_WORKFLOW_STEP_3","_DEFAULT_ITEM_READ"};
/**
* Extracts the collection id that may be immbedded in the given group name.
*
* @param groupName - the name of a group (ie group.getName())
* @return the integer collection id or -1 if the group is not that of a collection
*/
public static int getCollectionId(String groupName)
{
if (groupName != null && groupName.startsWith(COLLECTION_PREFIX))
{
for (String suffix : COLLECTION_SUFFIXES)
{
if (groupName.endsWith(suffix))
{
String idString = groupName.substring(COLLECTION_PREFIX.length());
idString = idString.substring(0, idString.length() - suffix.length());
int collectionID = -1;
try {
collectionID = Integer.valueOf(idString);
return collectionID;
// All good, we were able to ah
}
catch (NumberFormatException nfe)
{
// Somethnig went wrong, just ignore the exception and
// continue searching for a collection id
} // try & catch
} // if it ends with a proper suffix.
} // for each possible suffix
} // if it starts with COLLECTION_
return -1;
}
}

View File

@@ -0,0 +1,603 @@
/*
* FlowItemUtils.java
*
* Version: $Revision: 1.3 $
*
* Date: $Date: 2006/07/13 23:20:54 $
*
* Copyright (c) 2002, Hewlett-Packard Company and Massachusetts
* Institute of Technology. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* - 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.
*
* - Neither the name of the Hewlett-Packard Company nor the name of the
* Massachusetts Institute of Technology nor the names of their
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS 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 COPYRIGHT
* HOLDERS OR 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.
*/package org.dspace.app.xmlui.aspect.administrative;
import java.io.IOException;
import java.io.InputStream;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Enumeration;
import org.apache.cocoon.environment.Request;
import org.apache.cocoon.servlet.multipart.Part;
import org.dspace.app.xmlui.utils.UIException;
import org.dspace.app.xmlui.wing.Message;
import org.dspace.authorize.AuthorizeException;
import org.dspace.content.Bitstream;
import org.dspace.content.BitstreamFormat;
import org.dspace.content.Bundle;
import org.dspace.content.Collection;
import org.dspace.content.DSpaceObject;
import org.dspace.content.FormatIdentifier;
import org.dspace.content.Item;
import org.dspace.content.MetadataField;
import org.dspace.content.MetadataSchema;
import org.dspace.core.Constants;
import org.dspace.core.Context;
import org.dspace.handle.HandleManager;
/**
* Utility methods to processes actions on Groups. These methods are used
* exclusivly from the administrative flow scripts.
*
* @author Jay Paz
* @author Scott Phillips
*/
public class FlowItemUtils
{
/** Language Strings */
private static final Message T_metadata_updated = new Message("default","The Item's metadata was successfully updated.");
private static final Message T_metadata_added = new Message("default","New metadata was added.");
private static final Message T_item_withdrawn = new Message("default","The item has been withdrawn.");
private static final Message T_item_reinstated = new Message("default","The item has been reinstated.");
private static final Message T_bitstream_added = new Message("default","The new bitstream was successfully uploaded.");
private static final Message T_bitstream_failed = new Message("default","Error while uploading file.");
private static final Message T_bitstream_updated = new Message("default","The bitstream has been updated.");
private static final Message T_bitstream_delete = new Message("default","The selected bitstreams have been deleted.");
/**
* Resolve the given identifier to an item. The identifier may be either an
* internal ID or a handle. If an item is found then the result the internal
* ID of the item will be placed in the result "itemID" parameter.
*
* If the identifier was unable to be resolved to an item then the "identifier"
* field is placed in error.
*
* @param context The current DSpace context.
* @param identifier An Internal ID or a handle
* @return A flow result
*/
public static FlowResult resolveItemIdentifier(Context context, String identifier) throws SQLException
{
FlowResult result = new FlowResult();
result.setContinue(false);
// Check whether it's a handle or internal id (by check ing if it has a slash inthe string)
if (identifier.contains("/"))
{
DSpaceObject dso = HandleManager.resolveToObject(context, identifier);
if (dso != null && dso.getType() == Constants.ITEM)
{
result.setParameter("itemID", dso.getID());
result.setParameter("type", Constants.ITEM);
result.setContinue(true);
return result;
}
}
else
{
Item item = null;
try {
item = Item.find(context, Integer.valueOf(identifier));
} catch (NumberFormatException e) {
// ignoring the exception
}
if (item != null)
{
result.setParameter("itemID", item.getID());
result.setParameter("type", Constants.ITEM);
result.setContinue(true);
return result;
}
}
result.addError("identifier");
return result;
}
/**
* Process the request parameters to update the item's metadata and remove any selected bitstreams.
*
* Each metadata entry will have three fields "name_X", "value_X", and "language_X" where X is an
* integer that relates all three of the fields together. The name parameter stores the metadata name
* that is used by the entry (i.e schema_element_qualifier). The value and language paramaters are user
* inputed fields. If the optional parameter "remove_X" is given then the metadata value is removed.
*
* To support AJAX operations on this page an aditional parameter is considered, the "scope". The scope
* is the set of metadata entries that are being updated during this request. It the metadata name,
* schema_element_qualifier, only fields that have this name are considered! If all fields are to be
* considered then scope should be set to "*".
*
* When creating an AJAX query include all the name_X, value_X, language_X, and remove_X for the fields
* in the set, and then set the scope parameter to be the metadata field.
*
* @param context The current DSpace context
* @param itemID internal item id
* @param request the Cocoon request
* @return A flow result
*/
public static FlowResult processEditItem(Context context, int itemID, Request request) throws SQLException, AuthorizeException, UIException, IOException
{
FlowResult result = new FlowResult();
result.setContinue(false);
Item item = Item.find(context, itemID);
// STEP 1:
// Clear all metadata within the scope
// Only metadata values within this scope will be considered. This
// is so ajax request can operate on only a subset of the values.
String scope = request.getParameter("scope");
if ("*".equals(scope))
{
item.clearMetadata(Item.ANY, Item.ANY, Item.ANY, Item.ANY);
}
else
{
String[] parts = parseName(scope);
item.clearMetadata(parts[0],parts[1],parts[2],Item.ANY);
}
// STEP 2:
// First determine all the metadata fields that are within
// the scope parameter
ArrayList<Integer> indexes = new ArrayList<Integer>();
Enumeration parameters = request.getParameterNames();
while(parameters.hasMoreElements())
{
// Only consider the name_ fields
String parameterName = (String) parameters.nextElement();
if (parameterName.startsWith("name_"))
{
// Check if the name is within the scope
String parameterValue = request.getParameter(parameterName);
if ("*".equals(scope) || scope.equals(parameterValue))
{
// Extract the index from the name.
String indexString = parameterName.substring("name_".length());
Integer index = Integer.valueOf(indexString);
indexes.add(index);
}
}
}
// STEP 3:
// Iterate over all the indexes within the scope and add them back in.
for (Integer index : indexes)
{
String name = request.getParameter("name_"+index);
String value = request.getParameter("value_"+index);
String lang = request.getParameter("language_"+index);
String remove = request.getParameter("remove_"+index);
// the user selected the remove checkbox.
if (remove != null)
continue;
// get the field's name broken up
String[] parts = parseName(name);
// Add the metadata back in.
item.addMetadata(parts[0], parts[1], parts[2], lang, value);
}
item.update();
context.commit();
result.setContinue(true);
result.setOutcome(true);
result.setMessage(T_metadata_updated);
return result;
}
/**
* Process the request paramaters to add a new metadata entry for the item.
*
* @param context The current DSpace context
* @param itemID internal item id
* @param request the Cocoon request
* @return A flow result
*/
public static FlowResult processAddMetadata(Context context, int itemID, Request request) throws SQLException, AuthorizeException, UIException, IOException
{
FlowResult result = new FlowResult();
result.setContinue(false);
Item item = Item.find(context, itemID);
String fieldID = request.getParameter("field");
String value = request.getParameter("value");
String language = request.getParameter("language");
MetadataField field = MetadataField.find(context,Integer.valueOf(fieldID));
MetadataSchema schema = MetadataSchema.find(context,field.getSchemaID());
item.addMetadata(schema.getName(), field.getElement(), field.getQualifier(), language, value);
item.update();
context.commit();
result.setContinue(true);
result.setOutcome(true);
result.setMessage(T_metadata_added);
return result;
}
/**
* Withdraw the specified item, this method assumes that the action has been confirmed.
*
* @param context The DSpace context
* @param itemID The id of the to-be-withdrawn item.
* @return A result object
*/
public static FlowResult processWithdrawItem(Context context, int itemID) throws SQLException, AuthorizeException, IOException
{
FlowResult result = new FlowResult();
result.setContinue(false);
Item item = Item.find(context, itemID);
item.withdraw();
context.commit();
result.setContinue(true);
result.setOutcome(true);
result.setMessage(T_item_withdrawn);
return result;
}
/**
* Reinstate the specified item, this method assumes that the action has been confirmed.
*
* @param context The DSpace context
* @param itemID The id of the to-be-reinstated item.
* @return A result object
*/
public static FlowResult processReinstateItem(Context context, int itemID) throws SQLException, AuthorizeException, IOException
{
FlowResult result = new FlowResult();
result.setContinue(false);
Item item = Item.find(context, itemID);
item.reinstate();
context.commit();
result.setContinue(true);
result.setOutcome(true);
result.setMessage(T_item_reinstated);
return result;
}
/**
* Permanently delete the specified item, this method assumes that
* the action has been confirmed.
*
* @param context The DSpace context
* @param itemID The id of the to-be-deleted item.
* @return A result object
*/
public static FlowResult processDeleteItem(Context context, int itemID) throws SQLException, AuthorizeException, IOException
{
FlowResult result = new FlowResult();
result.setContinue(false);
Item item = Item.find(context, itemID);
Collection[] collections = item.getCollections();
// Remove item from all the collections it's in
for (Collection collection : collections)
{
collection.removeItem(item);
}
// Note: when removing an item from the last collection it will
// be removed from the system. So there is no need to also call
// an item.delete() method.
context.commit();
result.setContinue(true);
return result;
}
/**
* Add a new bitstream to the item. The bundle, bitstream (aka file), and description
* will be used to create a new bitstream. If the format needs to be adjusted then they
* will need to access the edit bitstream form after it has been uploaded.
*
* @param context The DSpace content
* @param itemID The item to add a new bitstream too
* @param request The request.
* @return A flow result
*/
public static FlowResult processAddBitstream(Context context, int itemID, Request request) throws SQLException, AuthorizeException, IOException
{
FlowResult result = new FlowResult();
result.setContinue(false);
// Upload a new file
Item item = Item.find(context, itemID);
Object object = request.get("file");
Part filePart = null;
if (object instanceof Part)
filePart = (Part) object;
if (filePart != null && filePart.getSize() > 0)
{
InputStream is = filePart.getInputStream();
String bundleName = request.getParameter("bundle");
Bitstream bitstream;
Bundle[] bundles = item.getBundles(bundleName);
if (bundles.length < 1)
{
// set bundle's name to ORIGINAL
bitstream = item.createSingleBitstream(is, bundleName);
}
else
{
// we have a bundle already, just add bitstream
bitstream = bundles[0].createBitstream(is);
}
// Strip all but the last filename. It would be nice
// to know which OS the file came from.
String name = filePart.getUploadName();
while (name.indexOf('/') > -1)
{
name = name.substring(name.indexOf('/') + 1);
}
while (name.indexOf('\\') > -1)
{
name = name.substring(name.indexOf('\\') + 1);
}
bitstream.setName(name);
bitstream.setSource(filePart.getUploadName());
bitstream.setDescription(request.getParameter("description"));
// Identify the format
BitstreamFormat format = FormatIdentifier.guessFormat(context, bitstream);
bitstream.setFormat(format);
// Update to DB
bitstream.update();
item.update();
result.setContinue(true);
result.setOutcome(true);
result.setMessage(T_bitstream_added);
}
else
{
result.setContinue(false);
result.setOutcome(false);
result.setMessage(T_bitstream_failed);
}
return result;
}
/**
* Update a bitstream's metadata.
*
* @param context The DSpace content
* @param itemID The item to which the bitstream belongs
* @param bitstreamID The bitstream being updated.
* @param description The new description of the bitstream
* @param formatID The new format ID of the bitstream
* @param userFormat Any user supplied formats.
* @return A flow result object.
*/
public static FlowResult processEditBitstream(Context context, int itemID, int bitstreamID, String primary, String description, int formatID, String userFormat) throws SQLException, AuthorizeException
{
FlowResult result = new FlowResult();
result.setContinue(false);
Bitstream bitstream = Bitstream.find(context, bitstreamID);
BitstreamFormat currentFormat = bitstream.getFormat();
//Step 1:
// Update the bitstream's description
if (description != null && description.length() > 0)
{
bitstream.setDescription(description);
}
//Step 2:
// Check if the primary bitstream status has changed
Bundle[] bundles = bitstream.getBundles();
if (bundles != null && bundles.length > 0)
{
if (bitstreamID == bundles[0].getPrimaryBitstreamID())
{
// currently the bitstream is primary
if ("no".equals(primary))
{
// However the user has removed this bitstream as a primary bitstream.
bundles[0].unsetPrimaryBitstreamID();
bundles[0].update();
}
}
else
{
// currently the bitstream is non-primary
if ("yes".equals(primary))
{
// However the user has set this bitstream as primary.
bundles[0].setPrimaryBitstreamID(bitstreamID);
bundles[0].update();
}
}
}
//Step 2:
// Update the bitstream's format
if (formatID > 0)
{
if (currentFormat == null || currentFormat.getID() != formatID)
{
BitstreamFormat newFormat = BitstreamFormat.find(context, formatID);
if (newFormat != null)
{
bitstream.setFormat(newFormat);
}
}
}
else
{
if (userFormat != null && userFormat.length() > 0)
{
bitstream.setUserFormatDescription(userFormat);
}
}
//Step 3:
// Save our changes
bitstream.update();
context.commit();
result.setContinue(true);
result.setOutcome(true);
result.setMessage(T_bitstream_updated);
return result;
}
/**
* Delete the given bitstreams from the bundle and item. If there are no more bitstreams
* left in a bundle then also remove it.
*
* @param context Current dspace content
* @param itemID The item id from which to remove bitstreams
* @param bitstreamIDs A bundle slash bitstream id pair of bitstreams to be removed.
* @return A flow result
*/
public static FlowResult processDeleteBitstreams(Context context, int itemID, String[] bitstreamIDs) throws SQLException, AuthorizeException, IOException, UIException
{
FlowResult result = new FlowResult();
result.setContinue(false);
Item item = Item.find(context, itemID);
for (String id : bitstreamIDs)
{
String[] parts = id.split("/");
if (parts.length != 2)
throw new UIException("Unable to parse id into bundle and bitstream id: "+id);
int bundleID = Integer.valueOf(parts[0]);
int bitstreamID = Integer.valueOf(parts[1]);
Bundle bundle = Bundle.find(context, bundleID);
Bitstream bitstream = Bitstream.find(context,bitstreamID);
bundle.removeBitstream(bitstream);
if (bundle.getBitstreams().length == 0)
{
item.removeBundle(bundle);
}
}
item.update();
result.setContinue(true);
result.setOutcome(true);
result.setMessage(T_bitstream_delete);
return result;
}
/**
* Parse the given name into three parts, divided by an _. Each part should represent the
* schema, element, and qualifier. You are guaranteed that if no qualifier was supplied the
* third entry is null.
*
* @param name The name to be parsed.
* @return An array of name parts.
*/
private static String[] parseName(String name) throws UIException
{
String[] parts = new String[3];
String[] split = name.split("_");
if (split.length == 2) {
parts[0] = split[0];
parts[1] = split[1];
parts[2] = null;
} else if (split.length == 3) {
parts[0] = split[0];
parts[1] = split[1];
parts[2] = split[2];
} else {
throw new UIException("Unable to parse metedata field name: "+name);
}
return parts;
}
}

View File

@@ -0,0 +1,144 @@
/*
* FlowMapperUtils.java
*
* Version: $Revision: 1.3 $
*
* Date: $Date: 2006/07/13 23:20:54 $
*
* Copyright (c) 2002, Hewlett-Packard Company and Massachusetts
* Institute of Technology. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* - 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.
*
* - Neither the name of the Hewlett-Packard Company nor the name of the
* Massachusetts Institute of Technology nor the names of their
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS 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 COPYRIGHT
* HOLDERS OR 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.
*/package org.dspace.app.xmlui.aspect.administrative;
import java.io.IOException;
import java.sql.SQLException;
import org.dspace.app.xmlui.utils.UIException;
import org.dspace.app.xmlui.wing.Message;
import org.dspace.authorize.AuthorizeException;
import org.dspace.authorize.AuthorizeManager;
import org.dspace.browse.Browse;
import org.dspace.content.Collection;
import org.dspace.content.Item;
import org.dspace.core.Constants;
import org.dspace.core.Context;
/**
*
* @author Scott Phillips
*/
public class FlowMapperUtils
{
/** Language Strings */
private static final Message T_map_items = new Message("default","xmlui.administrative.FlowMapperUtils.map_items");
private static final Message T_unmaped_items = new Message("default","xmlui.administrative.FlowMapperUtils.unmaped_items");
/**
* Map the given items into this collection
*
* @param context The current DSpace content
* @param collectionID The collection to map items into.
* @param itemIDs The items to map.
* @return Flow result
*/
public static FlowResult processMapItems(Context context, int collectionID, String[] itemIDs) throws SQLException, AuthorizeException, UIException, IOException
{
FlowResult result = new FlowResult();
result.setContinue(false);
Collection toCollection = Collection.find(context,collectionID);
for (String itemID : itemIDs)
{
Item item = Item.find(context, Integer.valueOf(itemID));
if (AuthorizeManager.authorizeActionBoolean(context, item, Constants.READ))
{
// make sure item doesn't belong to this collection
if (!item.isOwningCollection(toCollection))
{
toCollection.addItem(item);
Browse.itemChanged(context,item);
}
}
}
context.commit();
result.setContinue(true);
result.setOutcome(true);
result.setMessage(T_map_items);
return result;
}
/**
* Unmap the given items from this collection
*
* @param context The DSpace context
* @param collectionID The collection to unmap these items from.
* @param itemIDs The items to be unmapped.
* @return A flow result
*/
public static FlowResult processUnmapItems(Context context, int collectionID, String[] itemIDs) throws SQLException, AuthorizeException, UIException, IOException
{
FlowResult result = new FlowResult();
result.setContinue(false);
Collection toCollection = Collection.find(context,collectionID);
for (String itemID : itemIDs)
{
Item item = Item.find(context, Integer.valueOf(itemID));
if (AuthorizeManager.authorizeActionBoolean(context, item, Constants.READ))
{
// make sure item doesn't belong to this collection
if (!item.isOwningCollection(toCollection))
{
toCollection.removeItem(item);
Browse.itemChanged(context,item);
}
}
}
context.commit();
result.setContinue(true);
result.setOutcome(true);
result.setMessage(T_unmaped_items);
return result;
}
}

View File

@@ -0,0 +1,491 @@
/*
* FlowRegistryUtils.java
*
* Version: $Revision: 1.3 $
*
* Date: $Date: 2006/07/13 23:20:54 $
*
* Copyright (c) 2002, Hewlett-Packard Company and Massachusetts
* Institute of Technology. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* - 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.
*
* - Neither the name of the Hewlett-Packard Company nor the name of the
* Massachusetts Institute of Technology nor the names of their
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS 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 COPYRIGHT
* HOLDERS OR 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.
*/package org.dspace.app.xmlui.aspect.administrative;
import java.io.IOException;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import org.apache.cocoon.environment.Request;
import org.dspace.app.xmlui.utils.RequestUtils;
import org.dspace.app.xmlui.wing.Message;
import org.dspace.authorize.AuthorizeException;
import org.dspace.content.BitstreamFormat;
import org.dspace.content.MetadataField;
import org.dspace.content.MetadataSchema;
import org.dspace.content.NonUniqueMetadataException;
import org.dspace.core.Context;
/**
* Utility methods to process actions on either the metadata registry
* or format registry.
* @author scott phillips
*/
public class FlowRegistryUtils
{
/** Language Strings */
private static final Message T_add_metadata_schema_success_notice =
new Message("default","xmlui.administrative.FlowRegistryUtils.add_metadata_schema_success_notice");
private static final Message T_delete_metadata_schema_success_notice =
new Message("default","xmlui.administrative.FlowRegistryUtils.delete_metadata_schema_success_notice");
private static final Message T_add_metadata_field_success_notice =
new Message("default","xmlui.administrative.FlowRegistryUtils.add_metadata_field_success_notice");
private static final Message T_edit_metadata_field_success_notice =
new Message("default","xmlui.administrative.FlowRegistryUtils.edit_metadata_field_success_notice");
private static final Message T_move_metadata_field_sucess_notice =
new Message("default","xmlui.administrative.FlowRegistryUtils.move_metadata_field_success_notice");
private static final Message T_delete_metadata_field_success_notice =
new Message("default","xmlui.administrative.FlowRegistryUtils.delete_metadata_field_success_notice");
private static final Message T_edit_bitstream_format_success_notice =
new Message("default","xmlui.administrative.FlowRegistryUtils.edit_bitstream_format_success_notice");
private static final Message T_delete_bitstream_format_success_notice =
new Message("default","xmlui.administrative.FlowRegistryUtils.delete_bitstream_format_success_notice");
/**
* Add a new metadata schema. The ID of the new schema will be added
* as the "schemaID" parameter on the results object.
*
* @param context The DSpace context
* @param namespace The new schema's namespace
* @param name The new schema's name.
* @return A flow result
*/
public static FlowResult processAddMetadataSchema(Context context, String namespace, String name) throws SQLException, AuthorizeException, NonUniqueMetadataException
{
FlowResult result = new FlowResult();
result.setContinue(false);
if (namespace == null ||
namespace.length() <= 0)
result.addError("namespace");
if (name == null ||
name.length() <= 0 ||
name.indexOf('.') != -1 ||
name.indexOf('_') != -1 ||
name.indexOf(' ') != -1)
// The name must not be empty nor contain dot, underscore or spaces.
result.addError("name");
if (result.getErrors() == null)
{
MetadataSchema schema = new MetadataSchema();
schema.setNamespace(namespace);
schema.setName(name);
schema.create(context);
context.commit();
result.setContinue(true);
result.setOutcome(true);
result.setMessage(T_add_metadata_schema_success_notice);
result.setParameter("schemaID", schema.getSchemaID());
}
return result;
}
/**
* Delete the given schemas.
*
* @param context The DSpace context
* @param schemaIDs A list of schema IDs to be deleted.
* @return A flow result
*/
public static FlowResult processDeleteMetadataSchemas(Context context, String[] schemaIDs) throws SQLException, AuthorizeException, NonUniqueMetadataException
{
FlowResult result = new FlowResult();
int count = 0;
for (String id : schemaIDs)
{
MetadataSchema schema = MetadataSchema.find(context, Integer.valueOf(id));
// First remove and fields in the schema
MetadataField[] fields = MetadataField.findAllInSchema(context, schema.getSchemaID());
for (MetadataField field : fields)
field.delete(context);
// Once all the fields are gone, then delete the schema.
schema.delete(context);
count++;
}
if (count > 0)
{
context.commit();
result.setContinue(true);
result.setOutcome(true);
result.setMessage(T_delete_metadata_schema_success_notice);
}
return result;
}
/**
* Add a new metadata field. The newly created field's ID will be added as
* the "fieldID" parameter on the results object.
*
* @param context The DSpace context
* @param schemaID The id of the schema where this new field should be added.
* @param element The field's element.
* @param qualifier The field's qualifier.
* @param note A scope not about the field.
* @return A results object
*/
public static FlowResult processAddMetadataField(Context context, int schemaID, String element, String qualifier, String note) throws IOException, AuthorizeException, SQLException
{
FlowResult result = new FlowResult();
result.setContinue(false);
// Check if the field name is good.
result.setErrors(checkMetadataFieldName(element, qualifier));
// Make sure qualifier is null if blank.
if ("".equals(qualifier))
qualifier = null;
if (result.getErrors() == null)
{
try
{
MetadataField field = new MetadataField();
field.setSchemaID(schemaID);
field.setElement(element);
field.setQualifier(qualifier);
field.setScopeNote(note);
field.create(context);
context.commit();
result.setContinue(true);
result.setOutcome(true);
result.setMessage(T_add_metadata_field_success_notice);
result.setParameter("fieldID", field.getFieldID());
}
catch (NonUniqueMetadataException nume)
{
result.addError("duplicate_field");
}
}
return result;
}
/**
* Edit a metadata field.
*
* @param context The DSpace context.
* @param schemaID The ID of the schema for this field.
* @param fieldID The id of this field.
* @param element A new element value
* @param qualifier A new qualifier value
* @param note A new note value.
* @return A results object.
*/
public static FlowResult processEditMetadataField(Context context, int schemaID, int fieldID, String element, String qualifier, String note) throws IOException, AuthorizeException, SQLException
{
FlowResult result = new FlowResult();
result.setContinue(false);
// Check if the field name is good.
result.setErrors(checkMetadataFieldName(element, qualifier));
// Make sure qualifier is null if blank.
if ("".equals(qualifier))
qualifier = null;
// Check to make sure the field is unique, sometimes the NonUniqueMetadataException is not thrown.
MetadataField possibleDuplicate = MetadataField.findByElement(context, schemaID, element, qualifier);
if (possibleDuplicate != null && possibleDuplicate.getFieldID() != fieldID)
result.addError("duplicate_field");
if (result.getErrors() == null)
{
try
{
// Update the metadata for a DC type
MetadataField field = MetadataField.find(context, fieldID);
field.setElement(element);
field.setQualifier(qualifier);
field.setScopeNote(note);
field.update(context);
context.commit();
result.setContinue(true);
result.setOutcome(true);
result.setMessage(T_edit_metadata_field_success_notice);
}
catch (NonUniqueMetadataException nume)
{
// This shouldn't ever occure.
result.addError("duplicate_field");
}
}
return result;
}
/**
* Simple method to check the a metadata field's name: element and qualifier.
*
* @param element The field's element.
* @param qualifier The field's qualifier
* @return A list of errors found, null if none are found.
*/
private static List<String> checkMetadataFieldName(String element, String qualifier)
{
List<String> errors = new ArrayList<String>();
// Is the element empty?
if (element == null || element.length() <= 0)
{
element = ""; // so that the rest of the checks don't fail.
errors.add("element_empty");
}
// Is there a bad character in the element?
if (element.indexOf('.') != -1 ||
element.indexOf('_') != -1 ||
element.indexOf(' ') != -1)
errors.add("element_badchar");
// Is the element too long?
if (element.length() > 64)
errors.add("element_tolong");
// The qualifier can be empty.
if (qualifier != null && qualifier.length() > 0)
{
if (qualifier.length() > 64)
errors.add("qualifier_tolong");
if (qualifier.indexOf('.') != -1 ||
qualifier.indexOf('_') != -1 ||
qualifier.indexOf(' ') != -1)
errors.add("qualifier_badchar");
}
// If there were no errors then just return null.
if (errors.size() == 0)
return null;
return errors;
}
/**
* Move the specified metadata fields to the target schema.
*
* @param context The DSpace context
* @param schemaID The target schema ID
* @param fieldIDs The fields to be moved.
* @return A results object.
*/
public static FlowResult processMoveMetadataField(Context context, int schemaID, String[] fieldIDs) throws NumberFormatException, SQLException, AuthorizeException, NonUniqueMetadataException, IOException
{
FlowResult result = new FlowResult();
int count = 0;
for (String id : fieldIDs)
{
MetadataField field = MetadataField.find(context, Integer.valueOf(id));
field.setSchemaID(schemaID);
field.update(context);
count++;
}
if (count > 0)
{
context.commit();
result.setContinue(true);
result.setOutcome(true);
result.setMessage(T_move_metadata_field_sucess_notice);
}
return result;
}
/**
* Delete the specified metadata fields.
*
* @param context The DSpace context
* @param fieldIDs The fields to be deleted.
* @return A results object
*/
public static FlowResult processDeleteMetadataField(Context context, String[] fieldIDs) throws NumberFormatException, SQLException, AuthorizeException
{
FlowResult result = new FlowResult();
int count = 0;
for (String id : fieldIDs)
{
MetadataField field = MetadataField.find(context, Integer.valueOf(id));
field.delete(context);
count++;
}
if (count > 0)
{
context.commit();
result.setContinue(true);
result.setOutcome(true);
result.setMessage(T_delete_metadata_field_success_notice);
}
return result;
}
/**
* Edit a bitstream format. If the formatID is -1 then a new format is created.
* The formatID of the new format is added as a parameter to the results object.
*
* FIXME: the reason we accept a request object is so that we can use the
* RequestUtils.getFieldvalues() to get the multivalue field values.
*
* @param context The dspace context
* @param formatID The id of the format being updated.
* @param request The request object, for all the field entries.
* @return A results object
*/
public static FlowResult processEditBitstreamFormat(Context context, int formatID, Request request) throws SQLException, AuthorizeException
{
FlowResult result = new FlowResult();
result.setContinue(false);
// Get the values
String mimeType = request.getParameter("mimetype");
String shortDescription = request.getParameter("short_description");
String description = request.getParameter("description");
String supportLevel = request.getParameter("support_level");
String internal = request.getParameter("internal");
List<String> extensionsList = RequestUtils.getFieldValues(request, "extensions");
String[] extensions = extensionsList.toArray(new String[extensionsList.size()]);
// The format must at least have a name.
if (formatID != 1 && (shortDescription == null || shortDescription.length() == 0))
{
result.addError("short_description");
return result;
}
// Remove leading periods from file extensions.
for (int i = 0; i < extensions.length; i++)
if (extensions[i].startsWith("."))
extensions[i] = extensions[i].substring(1);
// Get or create the format
BitstreamFormat format;
if (formatID >= 0)
format = BitstreamFormat.find(context, formatID);
else
format = BitstreamFormat.create(context);
// Update values
format.setMIMEType(mimeType);
if (formatID != 1) // don't change the unknow format.
format.setShortDescription(shortDescription);
format.setDescription(description);
format.setSupportLevel(Integer.valueOf(supportLevel));
if (internal == null)
format.setInternal(false);
else
format.setInternal(true);
format.setExtensions(extensions);
// Commit the change
format.update();
context.commit();
// Return status
result.setContinue(true);
result.setOutcome(true);
result.setMessage(T_edit_bitstream_format_success_notice);
result.setParameter("formatID",format.getID());
return result;
}
/**
* Delete the specified bitstream formats.
*
* @param context The DSpace context
* @param formatIDs The formats-to-be-deleted.
* @return A results object.
*/
public static FlowResult processDeleteBitstreamFormats(Context context, String[] formatIDs) throws NumberFormatException, SQLException, AuthorizeException
{
FlowResult result = new FlowResult();
int count = 0;
for (String id : formatIDs)
{
BitstreamFormat format = BitstreamFormat.find(context,Integer.valueOf(id));
format.delete();
count++;
}
if (count > 0)
{
context.commit();
result.setContinue(true);
result.setOutcome(true);
result.setMessage(T_delete_bitstream_format_success_notice);
}
return result;
}
}

View File

@@ -0,0 +1,306 @@
/*
* FlowResult.java
*
* Version: $Revision: 1.3 $
*
* Date: $Date: 2006/07/13 23:20:54 $
*
* Copyright (c) 2002, Hewlett-Packard Company and Massachusetts
* Institute of Technology. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* - 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.
*
* - Neither the name of the Hewlett-Packard Company nor the name of the
* Massachusetts Institute of Technology nor the names of their
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS 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 COPYRIGHT
* HOLDERS OR 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.
*/
package org.dspace.app.xmlui.aspect.administrative;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.dspace.app.xmlui.wing.Message;
/**
* This class represents the results that may be generated during a flow script
* in this administrative section. Typicaly, some method preforms an operation
* and returns an object of type FlowResult, then the flow script can inspect
* the results object to determine what the next course of action is.
*
* Basicaly, this results object stores all the errors and contiunation states
* that need to be represented. There are four types of information stored:
*
* 1) Continuation, this is a simple boolean variable that indicates wheather
* the required operation is complete and the user may continue on to the next step.
*
* 2) Notice information, this is a simple encoding of a notice message to be displayed
* to the user on their next step. There are four parts: outcome, header, message, and
* characters. See each field for more description on each part. Note: either a message
* or characters are required.
*
* 3) Errors, this is a list of errors that were encountered during processing.
* Typical, it just consists of a list of errored fields. However occasionaly there
* may be other specialized errors listed.
*
* 4) Parameters, this is a map of attached parameters that may be relevnt to the
* result. This should be used for things such as generated id's when objects are newly
* created.
*
* @author Scott Phillips
*/
public class FlowResult {
/**
* Determine wheather the operation has been completed enough that the user
* may successufully continue on to the next step.
*/
private boolean continuep;
/**
* Notice parameters:
*
* Outcome: The outcome of the notice, may be either success, failure, or netural.
*
* Header: The notice's label, an i18n dictionary key.
*
* message: The main body of the notice, an i18n dictionary key.
*
* characters: Supplementaiol information for the notice, plain text. This is
* typicaly used for exepctions.
*
*/
private enum Outcome{ SUCCESS, FAILURE, NETURAL};
private Outcome outcome = Outcome.NETURAL;
private Message header;
private Message message;
private String characters;
/**
* A list of errors encountered while processing this operation.
*/
private List<String> errors;
/**
* Any parameters that may be attached to this result.
*/
private Map<String,Object> parameters;
/**
* Set the continuation parameter determining if the
* user should progress to the next step in the flow.
*/
public void setContinue(boolean continuep)
{
this.continuep = continuep;
}
/**
* Determine if the user should progress to the
* next step in the flow.
*
* @return the continuation parameter
*/
public boolean getContinue()
{
return this.continuep;
}
/**
* Set the notice outcome to either success or failure. Note,
* the default outcome is netural, once an outcome is set the
* netural outcome can never be atained again.
*
* @param success True for success, false for failure.
*/
public void setOutcome(boolean success)
{
if (success)
outcome = Outcome.SUCCESS;
else
outcome = Outcome.FAILURE;
}
/**
* Get the notice outcome in string form, either success
* or failure. If the outcome is netural then null is returned.
*/
public String getOutcome()
{
if (outcome == Outcome.SUCCESS)
{
return "success";
}
else if (outcome == Outcome.FAILURE)
{
return "failure";
}
return null;
}
/**
* Set the notice header.
*
* This must be an i18n dictionary key
*/
public void setHeader(Message header)
{
this.header = header;
}
/**
* Return the notice header
*/
public String getHeader()
{
if (this.header != null)
return this.header.getKey();
return null;
}
/**
* Set the notice message
*
* This must be an i18n dictionary key
*/
public void setMessage(Message message)
{
this.message = message;
}
/**
* return the notice message
*/
public String getMessage()
{
if (this.message != null)
return this.message.getKey();
return null;
}
/**
* Set the notice characters
*/
public void setCharacters(String characters)
{
this.characters = characters;
}
/**
* Return the notice characters
*/
public String getCharacters()
{
return this.characters;
}
/**
* Set the results errors, note this will remove any previous errors.
*
* @param errors New error list.
*/
public void setErrors(List<String> errors)
{
this.errors = errors;
}
/**
* Add a new single error to the error list.
*
* @param newError New error.
*/
public void addError(String newError)
{
if (this.errors == null)
this.errors = new ArrayList<String>();
this.errors.add(newError);
}
/**
* Return the current list of errors.
*/
public List<String> getErrors()
{
return this.errors;
}
/**
* Return the list of errors in string form, i.e. a comma seperated list
* of errors. If there are no errors then null is returned.
*/
public String getErrorString()
{
if (errors == null || errors.size() == 0)
return null;
String errorString = null;
for (String error : errors)
{
if (errorString == null)
errorString = error;
else
errorString += ","+error;
}
return errorString;
}
/**
* Attatch a new parameter to this result object with the specified
* name & value.
*
* @param name The parameter's name
* @param value The parameter's value.
*/
public void setParameter(String name, Object value)
{
if (this.parameters == null)
this.parameters = new HashMap<String,Object>();
this.parameters.put(name, value);
}
/**
* Find the attached parameter with the given name. If no parameter is
* found for the specified name then null is returned.
*
* @param name The parameter's name.
* @return The parameter's value.
*/
public Object getParameter(String name)
{
if (this.parameters == null)
return null;
return this.parameters.get(name);
}
}

View File

@@ -0,0 +1,337 @@
/*
* Navigation.java
*
* Version: $Revision: 1.3 $
*
* Date: $Date: 2006/07/13 23:20:54 $
*
* Copyright (c) 2002, Hewlett-Packard Company and Massachusetts
* Institute of Technology. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* - 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.
*
* - Neither the name of the Hewlett-Packard Company nor the name of the
* Massachusetts Institute of Technology nor the names of their
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS 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 COPYRIGHT
* HOLDERS OR 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.
*/
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;
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.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.List;
import org.dspace.app.xmlui.wing.element.Options;
import org.dspace.authorize.AuthorizeException;
import org.dspace.authorize.AuthorizeManager;
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 org.dspace.eperson.Group;
import org.xml.sax.SAXException;
/**
*
* Create the navigation options for everything in the administrative aspects. This includes
* Epeople, group, item, access control, and registry management.
*
* @author Scott Phillips
* @author Afonso Araujo Neto (internationalization)
* @author Alexey Maslov
*/
public class Navigation extends AbstractDSpaceTransformer implements CacheableProcessingComponent
{
private static final Message T_context_head = message("xmlui.administrative.Navigation.context_head");
private static final Message T_context_edit_item = message("xmlui.administrative.Navigation.context_edit_item");
private static final Message T_context_edit_collection = message("xmlui.administrative.Navigation.context_edit_collection");
private static final Message T_context_item_mapper = message("xmlui.administrative.Navigation.context_item_mapper");
private static final Message T_context_edit_community = message("xmlui.administrative.Navigation.context_edit_community");
private static final Message T_context_create_collection = message("xmlui.administrative.Navigation.context_create_collection");
private static final Message T_context_create_subcommunity = message("xmlui.administrative.Navigation.context_create_subcommunity");
private static final Message T_context_create_community = message("xmlui.administrative.Navigation.context_create_community");
private static final Message T_administrative_head = message("xmlui.administrative.Navigation.administrative_head");
private static final Message T_administrative_access_control = message("xmlui.administrative.Navigation.administrative_access_control");
private static final Message T_administrative_people = message("xmlui.administrative.Navigation.administrative_people");
private static final Message T_administrative_groups = message("xmlui.administrative.Navigation.administrative_groups");
private static final Message T_administrative_authorizations = message("xmlui.administrative.Navigation.administrative_authorizations");
private static final Message T_administrative_registries = message("xmlui.administrative.Navigation.administrative_registries");
private static final Message T_administrative_metadata = message("xmlui.administrative.Navigation.administrative_metadata");
private static final Message T_administrative_format = message("xmlui.administrative.Navigation.administrative_format");
private static final Message T_administrative_items = message("xmlui.administrative.Navigation.administrative_items");
private static final Message T_administrative_control_panel = message("xmlui.administrative.Navigation.administrative_control_panel");
/** Cached validity object */
private SourceValidity validity;
/**
* Generate the unique cache key.
*
* @return The generated key hashes the src
*/
public Serializable getKey()
{
Request request = ObjectModelHelper.getRequest(objectModel);
// Special case, don't cache anything if the user is logging
// in. The problem occures because of timming, this cache key
// is generated before we know whether the operation has
// succeded or failed. So we don't know whether to cache this
// under the user's specific cache or under the anonymous user.
if (request.getParameter("login_email") != null ||
request.getParameter("login_password") != null ||
request.getParameter("login_realm") != null )
{
return "0";
}
String key;
if (context.getCurrentUser() != null)
key = context.getCurrentUser().getEmail();
else
key = "anonymous";
return HashUtil.hash(key);
}
/**
* Generate the validity object.
*
* @return The generated validity object or <code>null</code> if the
* component is currently not cacheable.
*/
public SourceValidity getValidity()
{
if (this.validity == null)
{
// Only use the DSpaceValidity object is someone is logged in.
if (context.getCurrentUser() != null)
{
try {
DSpaceValidity validity = new DSpaceValidity();
validity.add(eperson);
Group[] groups = Group.allMemberGroups(context, eperson);
for (Group group : groups)
{
validity.add(group);
}
this.validity = validity.complete();
}
catch (SQLException sqle)
{
// Just ignore it and return invalid.
}
}
else
{
this.validity = NOPValidity.SHARED_INSTANCE;
}
}
return this.validity;
}
public void addOptions(Options options) throws SAXException, WingException,
UIException, SQLException, IOException, AuthorizeException
{
/* Create skeleton menu structure to ensure consistent order between aspects,
* even if they are never used
*/
options.addList("browse");
options.addList("account");
List context = options.addList("context");
List admin = options.addList("administrative");
// Context Administrative options
DSpaceObject dso = HandleUtil.obtainHandle(objectModel);
if (dso instanceof Item)
{
Item item = (Item) dso;
if (item.canEdit())
{
context.setHead(T_context_head);
context.addItem().addXref(contextPath+"/admin/item?itemID="+item.getID(), T_context_edit_item);
}
}
else if (dso instanceof Collection)
{
Collection collection = (Collection) dso;
// can they admin this collection?
if (AuthorizeManager.authorizeActionBoolean(this.context, collection, Constants.COLLECTION_ADMIN))
{
context.setHead(T_context_head);
context.addItemXref(contextPath+"/admin/collection?collectionID=" + collection.getID(), T_context_edit_collection);
context.addItemXref(contextPath+"/admin/mapper?collectionID="+collection.getID(), T_context_item_mapper);
}
}
else if (dso instanceof Community)
{
Community community = (Community) dso;
// can they admin this collection?
if (community.canEditBoolean())
{
context.setHead(T_context_head);
context.addItemXref(contextPath+"/admin/community?communityID=" + community.getID(), T_context_edit_community);
}
// can they add to this community?
if (AuthorizeManager.authorizeActionBoolean(this.context, community,Constants.ADD))
{
context.setHead(T_context_head);
context.addItemXref(contextPath+"/admin/collection?createNew&communityID=" + community.getID(), T_context_create_collection);
context.addItemXref(contextPath+"/admin/community?createNew&communityID=" + community.getID(), T_context_create_subcommunity);
}
}
if ("community-list".equals(this.sitemapURI))
{
if (AuthorizeManager.isAdmin(this.context))
{
context.setHead(T_context_head);
context.addItemXref(contextPath+"/admin/community?createNew", T_context_create_community);
}
}
// System Administrator options!
if (AuthorizeManager.isAdmin(this.context))
{
admin.setHead(T_administrative_head);
List epeople = admin.addList("epeople");
List registries = admin.addList("registries");
epeople.setHead(T_administrative_access_control);
epeople.addItemXref(contextPath+"/admin/epeople", T_administrative_people);
epeople.addItemXref(contextPath+"/admin/groups", T_administrative_groups);
epeople.addItemXref(contextPath+"/admin/authorize", T_administrative_authorizations);
registries.setHead(T_administrative_registries);
registries.addItemXref(contextPath+"/admin/metadata-registry",T_administrative_metadata);
registries.addItemXref(contextPath+"/admin/format-registry",T_administrative_format);
admin.addItemXref(contextPath+"/admin/item", T_administrative_items);
admin.addItemXref(contextPath+"/admin/panel", T_administrative_control_panel);
}
}
public int addContextualOptions(List context) throws SQLException, WingException
{
// How many options were added.
int options = 0;
DSpaceObject dso = HandleUtil.obtainHandle(objectModel);
if (dso instanceof Item)
{
Item item = (Item) dso;
if (item.canEdit())
{
context.addItem().addXref(contextPath+"/admin/item?itemID="+item.getID(), T_context_edit_item);
options++;
}
}
else if (dso instanceof Collection)
{
Collection collection = (Collection) dso;
// can they admin this collection?
if (AuthorizeManager.authorizeActionBoolean(this.context, collection, Constants.COLLECTION_ADMIN))
{
context.addItemXref(contextPath+"/admin/collection?collectionID=" + collection.getID(), T_context_edit_collection);
context.addItemXref(contextPath+"/admin/mapper?collectionID="+collection.getID(), T_context_item_mapper);
options++;
}
}
else if (dso instanceof Community)
{
Community community = (Community) dso;
// can they admin this collection?
if (community.canEditBoolean())
{
context.addItemXref(contextPath+"/admin/community?communityID=" + community.getID(), T_context_edit_community);
options++;
}
// can they add to this community?
if (AuthorizeManager.authorizeActionBoolean(this.context, community,Constants.ADD))
{
context.addItemXref(contextPath+"/admin/collection?createNew&communityID=" + community.getID(), T_context_create_collection);
context.addItemXref(contextPath+"/admin/community?createNew&communityID=" + community.getID(), T_context_create_subcommunity);
options++;
}
}
if ("community-list".equals(this.sitemapURI))
{
if (AuthorizeManager.isAdmin(this.context))
{
context.addItemXref(contextPath+"/admin/community?createNew", T_context_create_community);
options++;
}
}
return options;
}
/**
* recycle
*/
public void recycle()
{
this.validity = null;
super.recycle();
}
}

View File

@@ -0,0 +1,109 @@
/*
* NotAuthorized.java
*
* Version: $Revision: 1.0 $
*
* Date: $Date: 2006/07/13 23:20:54 $
*
* Copyright (c) 2002, Hewlett-Packard Company and Massachusetts
* Institute of Technology. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* - 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.
*
* - Neither the name of the Hewlett-Packard Company nor the name of the
* Massachusetts Institute of Technology nor the names of their
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS 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 COPYRIGHT
* HOLDERS OR 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.
*/
package org.dspace.app.xmlui.aspect.administrative;
import java.sql.SQLException;
import org.dspace.app.xmlui.cocoon.AbstractDSpaceTransformer;
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.PageMeta;
import org.dspace.app.xmlui.wing.element.Para;
/**
* Display a generic error message saying the user can
* not preform the requested action.
*
* @author Scott phillips
*/
public class NotAuthorized extends AbstractDSpaceTransformer
{
private static final Message T_title =
message("xmlui.administrative.NotAuthorized.title");
private static final Message T_dspace_home =
message("xmlui.general.dspace_home");
private static final Message T_trail =
message("xmlui.administrative.NotAuthorized.trail");
private static final Message T_head =
message("xmlui.administrative.NotAuthorized.head");
private static final Message T_para1a =
message("xmlui.administrative.NotAuthorized.para1a");
private static final Message T_para1b =
message("xmlui.administrative.NotAuthorized.para1b");
private static final Message T_para1c =
message("xmlui.administrative.NotAuthorized.para1c");
private static final Message T_para2 =
message("xmlui.administrative.NotAuthorized.para2");
public void addPageMeta(PageMeta pageMeta) throws WingException
{
pageMeta.addMetadata("title").addContent(T_title);
pageMeta.addTrailLink(contextPath + "/", T_dspace_home);
pageMeta.addTrail().addContent(T_trail);
}
public void addBody(Body body) throws WingException, SQLException
{
String loginURL = contextPath+"/login";
String feedbackURL = contextPath+"/feedback";
Division main = body.addDivision("not-authorized","primary administrative");
main.setHead(T_head);
Para para1 = main.addPara();
para1.addContent(T_para1a);
para1.addXref(feedbackURL,T_para1b);
para1.addContent(T_para1c);
main.addPara().addXref(loginURL,T_para2);
}
}

View File

@@ -0,0 +1,183 @@
/*
* SystemwideAlerts.java
*
* Version: $Revision: 1.3 $
*
* Date: $Date: 2006/07/13 23:20:54 $
*
* Copyright (c) 2002, Hewlett-Packard Company and Massachusetts
* Institute of Technology. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* - 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.
*
* - Neither the name of the Hewlett-Packard Company nor the name of the
* Massachusetts Institute of Technology nor the names of their
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS 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 COPYRIGHT
* HOLDERS OR 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.
*/
package org.dspace.app.xmlui.aspect.administrative;
import java.io.Serializable;
import org.apache.cocoon.caching.CacheableProcessingComponent;
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.wing.Message;
import org.dspace.app.xmlui.wing.WingException;
import org.dspace.app.xmlui.wing.element.Metadata;
import org.dspace.app.xmlui.wing.element.PageMeta;
/**
* This class maintains any system-wide alerts. If any alerts are activated then
* they are added to the page's metadata for display by the theme.
*
* This class also creates an interface for the alert system to be maintained.
*
* @author Scott Phillips
*/
public class SystemwideAlerts extends AbstractDSpaceTransformer implements CacheableProcessingComponent
{
/** Language Strings */
private static final Message T_COUNTDOWN = message("xmlui.administrative.SystemwideAlerts.countdown");
// Is an alert activated?
private static boolean active;
// The alert's message
private static String message;
// If a count down time is present, what time are we counting down too?
private static long countDownToo;
/**
* Generate the unique caching key.
*/
public Serializable getKey()
{
if (active)
// Don't cache any alert messages
return null;
else
return "1";
}
/**
* Generate the cache validity object.
*/
public SourceValidity getValidity()
{
if (active)
return null;
else
return NOPValidity.SHARED_INSTANCE;
}
/**
* If an alert is activated then add a count down message.
*/
public void addPageMeta(PageMeta pageMeta) throws WingException
{
if (active)
{
Metadata alert = pageMeta.addMetadata("alert","message");
long time = countDownToo - System.currentTimeMillis();
if (time > 0)
{
// from milliseconds to minutes
time = time / (60*1000);
alert.addContent(T_COUNTDOWN.parameterize(time));
}
alert.addContent(message);
}
}
/**
* Check whether an alert is active.
*/
public static boolean isAlertActive()
{
return SystemwideAlerts.active;
}
/**
* Activate the current alert.
*/
public static void activateAlert()
{
SystemwideAlerts.active = true;
}
/**
* Deactivate the current alert.
*/
public static void deactivateAlert()
{
SystemwideAlerts.active = false;
}
/**
* Set the current alert's message.
* @param message The new message
*/
public static void setMessage(String message)
{
SystemwideAlerts.message = message;
}
/**
* @return the current alert's message
*/
public static String getMessage()
{
return SystemwideAlerts.message;
}
/**
* Get the time, in millieseconds, when the countdown timer is scheduled to end.
*/
public static long getCountDownToo()
{
return SystemwideAlerts.countDownToo;
}
/**
* Set the time, in millieseconds, to which the countdown timer should end.
*
* Note, that once the countdown has expried, the alert is
* still active. However the countdown will disappear.
*/
public static void setCountDownToo(long countDownTo)
{
SystemwideAlerts.countDownToo = countDownTo;
}
}

View File

@@ -0,0 +1,161 @@
/*
* AuthorizationMain.java
*
* Version: $Revision: 1.0 $
*
* Date: $Date: 2006/07/13 23:20:54 $
*
* Copyright (c) 2002, Hewlett-Packard Company and Massachusetts
* Institute of Technology. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* - 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.
*
* - Neither the name of the Hewlett-Packard Company nor the name of the
* Massachusetts Institute of Technology nor the names of their
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS 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 COPYRIGHT
* HOLDERS OR 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.
*/
package org.dspace.app.xmlui.aspect.administrative.authorization;
import java.sql.SQLException;
import org.dspace.app.xmlui.cocoon.AbstractDSpaceTransformer;
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.List;
import org.dspace.app.xmlui.wing.element.PageMeta;
import org.dspace.app.xmlui.wing.element.Para;
import org.dspace.app.xmlui.wing.element.Select;
import org.dspace.content.Collection;
import org.dspace.core.Constants;
import org.dspace.eperson.Group;
/**
* @author Alexey Maslov
*/
public class AdvacedAuthorizationsForm extends AbstractDSpaceTransformer
{
private static final Message T_title =
message("xmlui.administrative.authorization.AdvacedAuthorizationsForm.title");
private static final Message T_trail =
message("xmlui.administrative.authorization.AdvacedAuthorizationsForm.trail");
private static final Message T_authorize_trail =
message("xmlui.administrative.authorization.general.authorize_trail");
private static final Message T_main_head =
message("xmlui.administrative.authorization.AdvacedAuthorizationsForm.main_head");
private static final Message T_main_para =
message("xmlui.administrative.authorization.AdvacedAuthorizationsForm.main_para");
private static final Message T_actions_groupSentence =
message("xmlui.administrative.authorization.AdvacedAuthorizationsForm.actions_groupSentence");
private static final Message T_actions_actionSentence =
message("xmlui.administrative.authorization.AdvacedAuthorizationsForm.actions_actionSentence");
private static final Message T_actions_resourceSentence =
message("xmlui.administrative.authorization.AdvacedAuthorizationsForm.actions_resourceSentence");
private static final Message T_actions_collectionSentence =
message("xmlui.administrative.authorization.AdvacedAuthorizationsForm.actions_collectionSentence");
private static final Message T_actions_policyGroup =
message("xmlui.administrative.authorization.AdvacedAuthorizationsForm.actions_policyGroup");
private static final Message T_actions_policyAction =
message("xmlui.administrative.authorization.AdvacedAuthorizationsForm.actions_policyAction");
private static final Message T_actions_policyResource =
message("xmlui.administrative.authorization.AdvacedAuthorizationsForm.actions_policyResource");
private static final Message T_actions_policyCollections =
message("xmlui.administrative.authorization.AdvacedAuthorizationsForm.actions_policyCollections");
private static final Message T_submit_add =
message("xmlui.administrative.authorization.AdvacedAuthorizationsForm.submit_add");
private static final Message T_submit_remove_all =
message("xmlui.administrative.authorization.AdvacedAuthorizationsForm.submit_remove_all");
private static final Message T_submit_return =
message("xmlui.general.return");
private static final Message T_dspace_home =
message("xmlui.general.dspace_home");
public void addPageMeta(PageMeta pageMeta) throws WingException
{
pageMeta.addMetadata("title").addContent(T_title);
pageMeta.addTrailLink(contextPath + "/", T_dspace_home);
pageMeta.addTrailLink(contextPath + "/admin/authorize", T_authorize_trail);
pageMeta.addTrail().addContent(T_trail);
}
public void addBody(Body body) throws WingException, SQLException
{
Division main = body.addInteractiveDivision("advanced-authorization",contextPath+"/admin/authorize",Division.METHOD_POST,"primary administrative authorization");
main.setHead(T_main_head);
main.addPara(T_main_para);
List actionsList = main.addList("actions","form");
// For all of the selected groups...
actionsList.addItem().addContent(T_actions_groupSentence);
actionsList.addLabel(T_actions_policyGroup);
Select groupSelect = actionsList.addItem().addSelect("group_id");
groupSelect.setMultiple(true);
groupSelect.setSize(15);
for (Group group : Group.findAll(context, Group.NAME))
groupSelect.addOption(false, group.getID(), group.getName());
// Grant the ability to perform the following action...
actionsList.addItem().addContent(T_actions_actionSentence);
actionsList.addLabel(T_actions_policyAction);
Select actionSelect = actionsList.addItem().addSelect("action_id");
for( int i = 0; i < Constants.actionText.length; i++ )
actionSelect.addOption(i, Constants.actionText[i]);
// For all following object types...
actionsList.addItem().addContent(T_actions_resourceSentence);
actionsList.addLabel(T_actions_policyResource);
Select resourceSelect = actionsList.addItem().addSelect("resource_id");
resourceSelect.addOption(true, Constants.ITEM, "item");
resourceSelect.addOption(false, Constants.BITSTREAM, "bitstream");
// Across the following collections...
actionsList.addItem().addContent(T_actions_collectionSentence);
actionsList.addLabel(T_actions_policyCollections);
Select collectionsSelect = actionsList.addItem().addSelect("collection_id");
collectionsSelect.setMultiple(true);
collectionsSelect.setSize(15);
for (Collection collection : Collection.findAll(context))
collectionsSelect.addOption(false, collection.getID(), collection.getMetadata("name"));
Para buttons = main.addPara();
buttons.addButton("submit_add").setValue(T_submit_add);
buttons.addButton("submit_remove_all").setValue(T_submit_remove_all);
buttons.addButton("submit_return").setValue(T_submit_return);
main.addHidden("administrative-continue").setValue(knot.getId());
}
}

View File

@@ -0,0 +1,185 @@
/*
* AuthorizationMain.java
*
* Version: $Revision: 1.0 $
*
* Date: $Date: 2006/07/13 23:20:54 $
*
* Copyright (c) 2002, Hewlett-Packard Company and Massachusetts
* Institute of Technology. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* - 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.
*
* - Neither the name of the Hewlett-Packard Company nor the name of the
* Massachusetts Institute of Technology nor the names of their
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS 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 COPYRIGHT
* HOLDERS OR 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.
*/
package org.dspace.app.xmlui.aspect.administrative.authorization;
import java.sql.SQLException;
import java.util.ArrayList;
import org.dspace.app.xmlui.cocoon.AbstractDSpaceTransformer;
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.Item;
import org.dspace.app.xmlui.wing.element.List;
import org.dspace.app.xmlui.wing.element.PageMeta;
import org.dspace.app.xmlui.wing.element.Text;
import org.dspace.content.Collection;
import org.dspace.content.Community;
/**
* @author Alexey Maslov
*/
public class AuthorizationMain extends AbstractDSpaceTransformer
{
private static final Message T_title =
message("xmlui.administrative.authorization.AuthorizationMain.title");
private static final Message T_authorize_trail =
message("xmlui.administrative.authorization.general.authorize_trail");
private static final Message T_main_head =
message("xmlui.administrative.authorization.AuthorizationMain.main_head");
private static final Message T_actions_head =
message("xmlui.administrative.authorization.AuthorizationMain.actions_head");
private static final Message T_actions_item_lookup =
message("xmlui.administrative.authorization.AuthorizationMain.actions_item_lookup");
private static final Message T_bad_name =
message("xmlui.administrative.authorization.AuthorizationMain.bad_name");
private static final Message T_search_help =
message("xmlui.administrative.authorization.AuthorizationMain.search_help");
private static final Message T_submit_find =
message("xmlui.administrative.authorization.AuthorizationMain.submit_find");
private static final Message T_actions_advanced =
message("xmlui.administrative.authorization.AuthorizationMain.actions_advanced");
private static final Message T_actions_advanced_link =
message("xmlui.administrative.authorization.AuthorizationMain.actions_advanced_link");
private static final Message T_containerList_head =
message("xmlui.administrative.authorization.AuthorizationMain.containerList_head");
private static final Message T_containerList_para =
message("xmlui.administrative.authorization.AuthorizationMain.containerList_para");
private static final Message T_dspace_home =
message("xmlui.general.dspace_home");
public void addPageMeta(PageMeta pageMeta) throws WingException
{
pageMeta.addMetadata("title").addContent(T_title);
pageMeta.addTrailLink(contextPath + "/", T_dspace_home);
pageMeta.addTrailLink(contextPath + "/admin/authorize", T_authorize_trail);
}
public void addBody(Body body) throws WingException, SQLException
{
/* Get and setup our parameters */
String query = parameters.getParameter("query",null);
String baseURL = contextPath+"/admin/epeople?administrative-continue="+knot.getId();
String errorString = parameters.getParameter("errors",null);
ArrayList<String> errors = new ArrayList<String>();
if (errorString != null)
{
for (String error : errorString.split(","))
errors.add(error);
}
Division main = body.addInteractiveDivision("authorization-main",contextPath+"/admin/authorize",Division.METHOD_POST,"primary administrative authorization");
main.setHead(T_main_head);
//main.addPara(T_main_para);
// DIVISION: authorization-actions
Division actions = main.addDivision("authorization-actions");
actions.setHead(T_actions_head);
List actionsList = actions.addList("actions");
actionsList.addLabel(T_actions_item_lookup);
Item actionItem = actionsList.addItem();
Text queryField = actionItem.addText("identifier");
if (query != null)
queryField.setValue(query);
if (errors.contains("identifier"))
queryField.addError(T_bad_name);
queryField.setHelp(T_search_help);
actionItem.addButton("submit_edit").setValue(T_submit_find);
actionsList.addLabel(T_actions_advanced);
actionsList.addItemXref(baseURL+"&submit_wildcard", T_actions_advanced_link);
// DIVISION: authorization-containerList
Division containers = main.addDivision("authorization-containerList");
containers.setHead(T_containerList_head);
containers.addPara(T_containerList_para);
List containerList = containers.addList("containerList");
this.containerListBuilder(baseURL,containerList,null);
main.addHidden("administrative-continue").setValue(knot.getId());
}
/* A recursive helper method to build the community/collection hierarchy list */
private void containerListBuilder (String baseURL, List parentList, Community currentCommunity)
throws SQLException, WingException
{
if (currentCommunity == null) {
for (Community topLevel : Community.findAllTop(context)) {
containerListBuilder(baseURL,parentList,topLevel);
}
}
else {
parentList.addItem().addHighlight("bold").addXref(baseURL+"&submit_edit&community_id="+currentCommunity.getID(), currentCommunity.getMetadata("name"));
List containerSubList = null;
for (Collection subCols : currentCommunity.getCollections())
{
if (containerSubList == null)
containerSubList = parentList.addList("subList" + currentCommunity.getID());
containerSubList.addItemXref(baseURL+"&submit_edit&collection_id="+subCols.getID(), subCols.getMetadata("name"));
}
for (Community subComs : currentCommunity.getSubcommunities())
{
if (containerSubList == null)
containerSubList = parentList.addList("subList" + currentCommunity.getID());
containerListBuilder(baseURL,containerSubList,subComs);
}
}
}
}

View File

@@ -0,0 +1,137 @@
/*
* AuthorizationMain.java
*
* Version: $Revision: 1.0 $
*
* Date: $Date: 2006/07/13 23:20:54 $
*
* Copyright (c) 2002, Hewlett-Packard Company and Massachusetts
* Institute of Technology. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* - 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.
*
* - Neither the name of the Hewlett-Packard Company nor the name of the
* Massachusetts Institute of Technology nor the names of their
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS 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 COPYRIGHT
* HOLDERS OR 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.
*/
package org.dspace.app.xmlui.aspect.administrative.authorization;
import java.sql.SQLException;
import java.util.ArrayList;
import org.dspace.app.xmlui.cocoon.AbstractDSpaceTransformer;
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.PageMeta;
import org.dspace.app.xmlui.wing.element.Para;
import org.dspace.app.xmlui.wing.element.Row;
import org.dspace.app.xmlui.wing.element.Table;
import org.dspace.authorize.ResourcePolicy;
/**
* @author Alexey Maslov
*/
public class DeletePoliciesConfirm extends AbstractDSpaceTransformer
{
/** Language Strings */
private static final Message T_dspace_home =
message("xmlui.general.dspace_home");
private static final Message T_title =
message("xmlui.administrative.authorization.DeletePoliciesConfirm.title");
private static final Message T_trail =
message("xmlui.administrative.authorization.DeletePoliciesConfirm.trail");
private static final Message T_authorize_trail =
message("xmlui.administrative.authorization.general.authorize_trail");
private static final Message T_policyList_trail =
message("xmlui.administrative.authorization.general.policyList_trail");
private static final Message T_confirm_head =
message("xmlui.administrative.authorization.DeletePoliciesConfirm.confirm_head");
private static final Message T_confirm_para =
message("xmlui.administrative.authorization.DeletePoliciesConfirm.confirm_para");
private static final Message T_head_id =
message("xmlui.administrative.authorization.DeletePoliciesConfirm.head_id");
private static final Message T_head_action =
message("xmlui.administrative.authorization.DeletePoliciesConfirm.head_action");
private static final Message T_head_group =
message("xmlui.administrative.authorization.DeletePoliciesConfirm.head_group");
private static final Message T_submit_confirm =
message("xmlui.general.delete");
private static final Message T_submit_cancel =
message("xmlui.general.cancel");
public void addPageMeta(PageMeta pageMeta) throws WingException
{
pageMeta.addMetadata("title").addContent(T_title);
pageMeta.addTrailLink(contextPath + "/", T_dspace_home);
pageMeta.addTrailLink(contextPath + "/admin/authorize", T_authorize_trail);
pageMeta.addTrail().addContent(T_policyList_trail);
pageMeta.addTrail().addContent(T_trail);
}
public void addBody(Body body) throws WingException, SQLException
{
// Get all our parameters
String idsString = parameters.getParameter("policyIDs", null);
ArrayList<ResourcePolicy> policies = new ArrayList<ResourcePolicy>();
for (String id : idsString.split(","))
{
ResourcePolicy policy = ResourcePolicy.find(context,Integer.valueOf(id));
policies.add(policy);
}
// DIVISION: policies-confirm-delete
Division deleted = body.addInteractiveDivision("policies-confirm-delete",contextPath+"/admin/authorize",Division.METHOD_POST,"primary administrative authorization");
deleted.setHead(T_confirm_head);
deleted.addPara(T_confirm_para);
Table table = deleted.addTable("policies-confirm-delete",policies.size() + 1, 4);
Row header = table.addRow(Row.ROLE_HEADER);
header.addCell().addContent(T_head_id);
header.addCell().addContent(T_head_action);
header.addCell().addContent(T_head_group);
for (ResourcePolicy policy : policies)
{
Row row = table.addRow();
row.addCell().addContent(policy.getID());
row.addCell().addContent(policy.getActionText());
if (policy.getGroup() != null) row.addCell().addContent(policy.getGroup().getName());
else row.addCell().addContent("...");
}
Para buttons = deleted.addPara();
buttons.addButton("submit_confirm").setValue(T_submit_confirm);
buttons.addButton("submit_cancel").setValue(T_submit_cancel);
deleted.addHidden("administrative-continue").setValue(knot.getId());
}
}

View File

@@ -0,0 +1,183 @@
/*
* AuthorizationMain.java
*
* Version: $Revision: 1.0 $
*
* Date: $Date: 2006/07/13 23:20:54 $
*
* Copyright (c) 2002, Hewlett-Packard Company and Massachusetts
* Institute of Technology. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* - 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.
*
* - Neither the name of the Hewlett-Packard Company nor the name of the
* Massachusetts Institute of Technology nor the names of their
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS 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 COPYRIGHT
* HOLDERS OR 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.
*/
package org.dspace.app.xmlui.aspect.administrative.authorization;
import java.sql.SQLException;
import java.util.ArrayList;
import org.dspace.app.xmlui.cocoon.AbstractDSpaceTransformer;
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.CheckBox;
import org.dspace.app.xmlui.wing.element.Division;
import org.dspace.app.xmlui.wing.element.Highlight;
import org.dspace.app.xmlui.wing.element.PageMeta;
import org.dspace.app.xmlui.wing.element.Para;
import org.dspace.app.xmlui.wing.element.Row;
import org.dspace.app.xmlui.wing.element.Table;
import org.dspace.authorize.AuthorizeManager;
import org.dspace.authorize.ResourcePolicy;
import org.dspace.content.Collection;
import org.dspace.content.Community;
import org.dspace.core.Constants;
import org.dspace.eperson.Group;
/**
* @author Alexey Maslov
*/
public class EditContainerPolicies extends AbstractDSpaceTransformer
{
private static final Message T_title =
message("xmlui.administrative.authorization.EditContainerPolicies.title");
private static final Message T_policyList_trail =
message("xmlui.administrative.authorization.general.policyList_trail");
private static final Message T_authorize_trail =
message("xmlui.administrative.authorization.general.authorize_trail");
private static final Message T_main_head_collection =
message("xmlui.administrative.authorization.EditContainerPolicies.main_head_collection");
private static final Message T_main_head_community =
message("xmlui.administrative.authorization.EditContainerPolicies.main_head_community");
private static final Message T_add_link =
message("xmlui.administrative.authorization.EditContainerPolicies.main_add_link");
private static final Message T_head_id =
message("xmlui.administrative.authorization.EditContainerPolicies.head_id");
private static final Message T_head_action =
message("xmlui.administrative.authorization.EditContainerPolicies.head_action");
private static final Message T_head_group =
message("xmlui.administrative.authorization.EditContainerPolicies.head_group");
private static final Message T_group_edit =
message("xmlui.administrative.authorization.EditContainerPolicies.group_edit");
private static final Message T_submit_delete =
message("xmlui.administrative.authorization.EditContainerPolicies.submit_delete");
private static final Message T_submit_return =
message("xmlui.general.return");
private static final Message T_dspace_home =
message("xmlui.general.dspace_home");
public void addPageMeta(PageMeta pageMeta) throws WingException
{
pageMeta.addMetadata("title").addContent(T_title);
pageMeta.addTrailLink(contextPath + "/", T_dspace_home);
pageMeta.addTrailLink(contextPath + "/admin/authorize", T_authorize_trail);
pageMeta.addTrail().addContent(T_policyList_trail);
}
public void addBody(Body body) throws WingException, SQLException
{
/* Get and setup our parameters */
int containerType = parameters.getParameterAsInteger("containerType",-1);
int containerID = parameters.getParameterAsInteger("containerID",-1);
int highlightID = parameters.getParameterAsInteger("highlightID",-1);
String baseURL = contextPath+"/admin/epeople?administrative-continue="+knot.getId();
ArrayList<ResourcePolicy> policies = new ArrayList<ResourcePolicy>();
// DIVISION: edit-container-policies
Division main = body.addInteractiveDivision("edit-container-policies",contextPath+"/admin/authorize",Division.METHOD_POST,"primary administrative authorization");
if (containerType == Constants.COLLECTION)
{
Collection col = Collection.find(context, containerID);
main.setHead(T_main_head_collection.parameterize(col.getMetadata("name"),col.getHandle(),col.getID()));
policies = (ArrayList<ResourcePolicy>)AuthorizeManager.getPolicies(context, col);
}
else
{
Community com = Community.find(context, containerID);
main.setHead(T_main_head_community.parameterize(com.getMetadata("name"),com.getHandle(),com.getID()));
policies = (ArrayList<ResourcePolicy>)AuthorizeManager.getPolicies(context, com);
}
/* Adding a new policy link */
main.addPara().addXref(baseURL + "&submit_add", T_add_link);
Table table = main.addTable("container-policy-list",policies.size() + 1, 4);
Row header = table.addRow(Row.ROLE_HEADER);
header.addCell();
header.addCell().addContent(T_head_id);
header.addCell().addContent(T_head_action);
header.addCell().addContent(T_head_group);
for (ResourcePolicy policy : policies)
{
Row row;
if (policy.getID() == highlightID)
row = table.addRow(null, null, "highlight");
else
row = table.addRow();
CheckBox select = row.addCell().addCheckBox("select_policy");
select.setLabel(String.valueOf(policy.getID()));
select.addOption(String.valueOf(policy.getID()));
// Accounting for the funky case of an empty policy
Group policyGroup = policy.getGroup();
row.addCell().addXref(baseURL + "&submit_edit&policy_id=" + policy.getID(), String.valueOf(policy.getID()));
row.addCell().addXref(baseURL + "&submit_edit&policy_id=" + policy.getID(), policy.getActionText());
if (policyGroup != null) {
Cell groupCell = row.addCell();
groupCell.addContent(policyGroup.getName());
Highlight groupHigh = groupCell.addHighlight("fade");
groupHigh.addContent(" [");
groupHigh.addXref(baseURL + "&submit_edit_group&group_id=" + policyGroup.getID(), T_group_edit);
groupHigh.addContent("]");
}
else {
row.addCell().addContent("...");
}
}
Para buttons = main.addPara();
buttons.addButton("submit_delete").setValue(T_submit_delete);
buttons.addButton("submit_return").setValue(T_submit_return);
main.addHidden("administrative-continue").setValue(knot.getId());
}
}

View File

@@ -0,0 +1,252 @@
/*
* AuthorizationMain.java
*
* Version: $Revision: 1.0 $
*
* Date: $Date: 2006/07/13 23:20:54 $
*
* Copyright (c) 2002, Hewlett-Packard Company and Massachusetts
* Institute of Technology. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* - 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.
*
* - Neither the name of the Hewlett-Packard Company nor the name of the
* Massachusetts Institute of Technology nor the names of their
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS 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 COPYRIGHT
* HOLDERS OR 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.
*/
package org.dspace.app.xmlui.aspect.administrative.authorization;
import java.sql.SQLException;
import java.util.ArrayList;
import org.dspace.app.xmlui.cocoon.AbstractDSpaceTransformer;
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.CheckBox;
import org.dspace.app.xmlui.wing.element.Division;
import org.dspace.app.xmlui.wing.element.Highlight;
import org.dspace.app.xmlui.wing.element.PageMeta;
import org.dspace.app.xmlui.wing.element.Para;
import org.dspace.app.xmlui.wing.element.Row;
import org.dspace.app.xmlui.wing.element.Table;
import org.dspace.authorize.AuthorizeManager;
import org.dspace.authorize.ResourcePolicy;
import org.dspace.content.Bitstream;
import org.dspace.content.Bundle;
import org.dspace.content.Item;
import org.dspace.core.Constants;
import org.dspace.eperson.Group;
/**
* @author Alexey Maslov
*/
public class EditItemPolicies extends AbstractDSpaceTransformer
{
private static final Message T_title =
message("xmlui.administrative.authorization.EditItemPolicies.title");
private static final Message T_policyList_trail =
message("xmlui.administrative.authorization.general.policyList_trail");
private static final Message T_authorize_trail =
message("xmlui.administrative.authorization.general.authorize_trail");
private static final Message T_main_head =
message("xmlui.administrative.authorization.EditItemPolicies.main_head");
private static final Message T_main_para1 =
message("xmlui.administrative.authorization.EditItemPolicies.main_para1");
private static final Message T_main_para2 =
message("xmlui.administrative.authorization.EditItemPolicies.main_para2");
private static final Message T_subhead_item =
message("xmlui.administrative.authorization.EditItemPolicies.subhead_item");
private static final Message T_subhead_bundle =
message("xmlui.administrative.authorization.EditItemPolicies.subhead_bundle");
private static final Message T_subhead_bitstream =
message("xmlui.administrative.authorization.EditItemPolicies.subhead_bitstream");
private static final Message T_add_itemPolicy_link =
message("xmlui.administrative.authorization.EditItemPolicies.add_itemPolicy_link");
private static final Message T_add_bundlePolicy_link =
message("xmlui.administrative.authorization.EditItemPolicies.add_bundlePolicy_link");
private static final Message T_add_bitstreamPolicy_link =
message("xmlui.administrative.authorization.EditItemPolicies.add_bitstreamPolicy_link");
private static final Message T_head_id =
message("xmlui.administrative.authorization.EditContainerPolicies.head_id");
private static final Message T_head_action =
message("xmlui.administrative.authorization.EditContainerPolicies.head_action");
private static final Message T_head_group =
message("xmlui.administrative.authorization.EditContainerPolicies.head_group");
private static final Message T_group_edit =
message("xmlui.administrative.authorization.EditContainerPolicies.group_edit");
private static final Message T_submit_delete =
message("xmlui.administrative.authorization.EditContainerPolicies.submit_delete");
private static final Message T_submit_return =
message("xmlui.general.return");
private static final Message T_no_policies =
message("xmlui.administrative.authorization.EditContainerPolicies.no_policies");
private static final Message T_dspace_home =
message("xmlui.general.dspace_home");
public void addPageMeta(PageMeta pageMeta) throws WingException
{
pageMeta.addMetadata("title").addContent(T_title);
pageMeta.addTrailLink(contextPath + "/", T_dspace_home);
pageMeta.addTrailLink(contextPath + "/admin/authorize", T_authorize_trail);
pageMeta.addTrail().addContent(T_policyList_trail);
}
public void addBody(Body body) throws WingException, SQLException
{
/* Get and setup our parameters */
int itemID = parameters.getParameterAsInteger("itemID",-1);
int highlightID = parameters.getParameterAsInteger("highlightID",-1);
String baseURL = contextPath+"/admin/epeople?administrative-continue="+knot.getId();
/* First, set up our various data structures */
Item item = Item.find(context, itemID);
Bundle[] bundles = item.getBundles();
Bitstream[] bitstreams;
ArrayList<ResourcePolicy> itemPolicies = (ArrayList<ResourcePolicy>)AuthorizeManager.getPolicies(context, item);
ArrayList<ResourcePolicy> bundlePolicies = new ArrayList<ResourcePolicy>();
ArrayList<ResourcePolicy> bitstreamPolicies = new ArrayList<ResourcePolicy>();
// DIVISION: main
Division main = body.addInteractiveDivision("edit-item-policies",contextPath+"/admin/authorize",Division.METHOD_POST,"primary administrative authorization");
main.setHead(T_main_head.parameterize(item.getHandle(),item.getID()));
main.addPara().addHighlight("italic").addContent(T_main_para1);
main.addPara().addHighlight("italic").addContent(T_main_para2);
Table table = main.addTable("policies-confirm-delete",itemPolicies.size() + 3, 5);
Row header = table.addRow(Row.ROLE_HEADER);
header.addCell();
header.addCell().addContent(T_head_id);
header.addCell().addContent(T_head_action);
header.addCell().addContent(T_head_group);
header.addCell();
// First, the item's policies are listed
Row subheader = table.addRow(null,Row.ROLE_HEADER,"subheader");
subheader.addCell(1, 4).addHighlight("bold").addContent(T_subhead_item);
subheader.addCell().addHighlight("bold").addXref(baseURL + "&submit_add_item", T_add_itemPolicy_link);
this.rowBuilder(baseURL, table, itemPolicies, item.getID(), Constants.ITEM, highlightID);
// Next, one by one, we get the bundles
for (Bundle bundle : bundles) {
subheader = table.addRow(null,Row.ROLE_HEADER,"subheader");
subheader.addCell(null, null, 1, 4, "indent").addHighlight("bold").addContent(T_subhead_bundle.parameterize(bundle.getName(),bundle.getID()));
subheader.addCell().addHighlight("bold").addXref(baseURL + "&submit_add_bundle_" + bundle.getID(), T_add_bundlePolicy_link);
bundlePolicies = (ArrayList<ResourcePolicy>)AuthorizeManager.getPolicies(context, bundle);
this.rowBuilder(baseURL, table, bundlePolicies, bundle.getID(), Constants.BUNDLE, highlightID);
// And eventually to the bundle's bitstreams
bitstreams = bundle.getBitstreams();
for (Bitstream bitstream : bitstreams) {
subheader = table.addRow(null,Row.ROLE_HEADER,"subheader");
subheader.addCell(null, null, 1, 4, "doubleIndent").addContent(T_subhead_bitstream.parameterize(bitstream.getName(),bitstream.getID()));
subheader.addCell().addXref(baseURL + "&submit_add_bitstream_" + bitstream.getID(), T_add_bitstreamPolicy_link);
bitstreamPolicies = (ArrayList<ResourcePolicy>)AuthorizeManager.getPolicies(context, bitstream);
this.rowBuilder(baseURL, table, bitstreamPolicies, bitstream.getID(), Constants.BITSTREAM, highlightID);
}
}
Para buttons = main.addPara();
buttons.addButton("submit_delete").setValue(T_submit_delete);
buttons.addButton("submit_return").setValue(T_submit_return);
main.addHidden("administrative-continue").setValue(knot.getId());
}
private void rowBuilder(String baseURL, Table table, ArrayList<ResourcePolicy> policies, int objectID, int objectType, int highlightID) throws WingException, SQLException
{
// If the list of policies is empty, say so
if (policies == null || policies.size() == 0) {
table.addRow().addCell(1, 4).addHighlight("italic").addContent(T_no_policies);
}
// Otherwise, iterate over the given policies, creating a new table row for each one
else {
for (ResourcePolicy policy : policies)
{
Row row;
if (policy.getID() == highlightID)
row = table.addRow(null, null, "highlight");
else
row = table.addRow();
Cell cell;
if (objectType == Constants.BUNDLE)
cell = row.addCell(null, null, "indent");
else if (objectType == Constants.BITSTREAM)
cell = row.addCell(null, null, "doubleIndent");
else
cell = row.addCell();
CheckBox select = cell.addCheckBox("select_policy");
select.setLabel(String.valueOf(policy.getID()));
select.addOption(String.valueOf(policy.getID()));
// Accounting for the funky case of an empty policy
Group policyGroup = policy.getGroup();
row.addCell().addXref(baseURL + "&submit_edit&policy_id=" + policy.getID() +
"&object_id=" + objectID + "&object_type=" + objectType, String.valueOf(policy.getID()));
row.addCell().addXref(baseURL + "&submit_edit&policy_id=" + policy.getID() +
"&object_id=" + objectID + "&object_type=" + objectType, policy.getActionText());
if (policyGroup != null) {
Cell groupCell = row.addCell(1,2);
groupCell.addContent(policyGroup.getName());
Highlight groupHigh = groupCell.addHighlight("fade");
groupHigh.addContent(" [");
groupHigh.addXref(baseURL + "&submit_edit_group&group_id=" + policyGroup.getID(), T_group_edit);
groupHigh.addContent("]");
}
else {
row.addCell(1,2).addContent("...");
}
}
}
}
}

View File

@@ -0,0 +1,353 @@
/*
* AuthorizationMain.java
*
* Version: $Revision: 1.0 $
*
* Date: $Date: 2006/07/13 23:20:54 $
*
* Copyright (c) 2002, Hewlett-Packard Company and Massachusetts
* Institute of Technology. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* - 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.
*
* - Neither the name of the Hewlett-Packard Company nor the name of the
* Massachusetts Institute of Technology nor the names of their
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS 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 COPYRIGHT
* HOLDERS OR 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.
*/
package org.dspace.app.xmlui.aspect.administrative.authorization;
import java.sql.SQLException;
import java.util.ArrayList;
import org.dspace.app.xmlui.cocoon.AbstractDSpaceTransformer;
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.Item;
import org.dspace.app.xmlui.wing.element.List;
import org.dspace.app.xmlui.wing.element.PageMeta;
import org.dspace.app.xmlui.wing.element.Radio;
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.Text;
import org.dspace.authorize.AuthorizeManager;
import org.dspace.authorize.ResourcePolicy;
import org.dspace.content.Bitstream;
import org.dspace.content.Bundle;
import org.dspace.content.Collection;
import org.dspace.content.Community;
import org.dspace.content.DSpaceObject;
import org.dspace.core.Constants;
import org.dspace.eperson.Group;
/**
* @author Alexey Maslov
*/
public class EditPolicyForm extends AbstractDSpaceTransformer
{
private static final Message T_title =
message("xmlui.administrative.authorization.EditPolicyForm.title");
private static final Message T_trail =
message("xmlui.administrative.authorization.EditPolicyForm.trail");
private static final Message T_authorize_trail =
message("xmlui.administrative.authorization.general.authorize_trail");
private static final Message T_policyList_trail =
message("xmlui.administrative.authorization.general.policyList_trail");
private static final Message T_main_head_new =
message("xmlui.administrative.authorization.EditPolicyForm.main_head_new");
private static final Message T_main_head_edit =
message("xmlui.administrative.authorization.EditPolicyForm.main_head_edit");
private static final Message T_error_no_group =
message("xmlui.administrative.authorization.EditPolicyForm.error_no_group");
private static final Message T_error_no_action =
message("xmlui.administrative.authorization.EditPolicyForm.error_no_action");
private static final Message T_no_results =
message("xmlui.administrative.group.EditGroupForm.no_results");
private static final Message T_groups_column1 =
message("xmlui.administrative.authorization.EditPolicyForm.groups_column1");
private static final Message T_groups_column2 =
message("xmlui.administrative.authorization.EditPolicyForm.groups_column2");
private static final Message T_groups_column3 =
message("xmlui.administrative.authorization.EditPolicyForm.groups_column3");
private static final Message T_groups_column4 =
message("xmlui.administrative.authorization.EditPolicyForm.groups_column4");
private static final Message T_submit_save =
message("xmlui.general.save");
private static final Message T_submit_cancel =
message("xmlui.general.cancel");
private static final Message T_set_group =
message("xmlui.administrative.authorization.EditPolicyForm.set_group");
private static final Message T_current_group =
message("xmlui.administrative.authorization.EditPolicyForm.current_group");
private static final Message T_groups_head =
message("xmlui.administrative.authorization.EditPolicyForm.groups_head");
private static final Message T_policy_currentGroup =
message("xmlui.administrative.authorization.EditPolicyForm.policy_currentGroup");
private static final Message T_label_search =
message("xmlui.administrative.authorization.EditPolicyForm.label_search");
private static final Message T_submit_search_groups =
message("xmlui.administrative.authorization.EditPolicyForm.submit_search_groups");
private static final Message T_label_action =
message("xmlui.administrative.authorization.EditPolicyForm.label_action");
private static final Message T_dspace_home =
message("xmlui.general.dspace_home");
// How many search results are displayed at once
private static final int RESULTS_PER_PAGE = 10;
public void addPageMeta(PageMeta pageMeta) throws WingException
{
pageMeta.addMetadata("title").addContent(T_title);
pageMeta.addTrailLink(contextPath + "/", T_dspace_home);
pageMeta.addTrailLink(contextPath + "/admin/authorize", T_authorize_trail);
pageMeta.addTrail().addContent(T_policyList_trail);
pageMeta.addTrail().addContent(T_trail);
}
public void addBody(Body body) throws WingException, SQLException
{
/* Get and setup our parameters. We should always have an objectType and objectID, since every policy
* has to have a parent resource. policyID may, however, be -1 for new, not-yet-created policies and
* the groupID is only set if the group is being changed. */
int objectType = parameters.getParameterAsInteger("objectType",-1);
int objectID = parameters.getParameterAsInteger("objectID",-1);
int policyID = parameters.getParameterAsInteger("policyID",-1);
int groupID = parameters.getParameterAsInteger("groupID",-1);
int actionID = parameters.getParameterAsInteger("actionID",-1);
int page = parameters.getParameterAsInteger("page",0);
String query = parameters.getParameter("query","-1");
// The current policy, if it exists (i.e. we are not creating a new one)
ResourcePolicy policy = ResourcePolicy.find(context, policyID);
// The currently set group; it's value depends on wether previously clicked the "Set" button to change
// the associated group, came here to edit an existing group, or create a new one.
Group currentGroup;
if (groupID != -1) {
currentGroup = Group.find(context, groupID);
}
else if (policy != null) {
currentGroup = policy.getGroup();
}
else currentGroup = null;
// Same for the current action; it can either blank (-1), manually set, or inherited from the current policy
if (policy != null && actionID == -1)
actionID = policy.getAction();
String errorString = parameters.getParameter("errors",null);
ArrayList<String> errors = new ArrayList<String>();
if (errorString != null)
{
for (String error : errorString.split(","))
errors.add(error);
}
/* Set up our current Dspace object */
DSpaceObject dso;
switch (objectType) {
case Constants.COMMUNITY: dso = Community.find(context, objectID); break;
case Constants.COLLECTION: dso = Collection.find(context, objectID); break;
case Constants.ITEM: dso = org.dspace.content.Item.find(context, objectID); break;
case Constants.BUNDLE: dso = Bundle.find(context, objectID); break;
case Constants.BITSTREAM: dso = Bitstream.find(context, objectID); break;
default: dso = null;
}
// DIVISION: edit-container-policies
Division main = body.addInteractiveDivision("edit-policy",contextPath+"/admin/authorize",Division.METHOD_POST,"primary administrative authorization");
if (policyID >= 0) {
objectID = policy.getResourceID();
objectType = policy.getResourceType();
main.setHead(T_main_head_edit.parameterize(policyID,Constants.typeText[objectType],objectID));
}
else
main.setHead(T_main_head_new.parameterize(Constants.typeText[objectType],objectID));
int resourceRelevance = 1 << objectType;
// DIVISION: authorization-actions
Division actions = main.addDivision("edit-policy-actions");
List actionsList = actions.addList("actions","form");
// actions radio buttons
actionsList.addLabel(T_label_action);
Item actionSelectItem = actionsList.addItem();
Radio actionSelect = actionSelectItem.addRadio("action_id");
actionSelect.setLabel(T_label_action);
//Select actionSelect = actionSelectItem.addSelect("action_id");
//actionsBox.addContent(T_label_action);
//Select actionSelect = actionsBox.addSelect("action_id");
for( int i = 0; i < Constants.actionText.length; i++ )
{
// only display if action i is relevant
// to resource type resourceRelevance
if( (Constants.actionTypeRelevance[i] & resourceRelevance) > 0)
{
if (actionID == i)
actionSelect.addOption(true, i, Constants.actionText[i]);
else
actionSelect.addOption(i, Constants.actionText[i]);
}
}
if (errors.contains("action_id"))
actionSelect.addError(T_error_no_action);
// currently set group
actionsList.addLabel(T_policy_currentGroup);
Select groupSelect = actionsList.addItem().addSelect("group_id");
groupSelect.setSize(5);
for (Group group : Group.findAll(context, Group.NAME))
{
if (group == currentGroup)
groupSelect.addOption(true, group.getID(), group.getName());
else
groupSelect.addOption(group.getID(), group.getName());
}
if (errors.contains("group_id"))
groupSelect.addError(T_error_no_group);
// the search function
actionsList.addLabel(T_label_search);
Item searchItem = actionsList.addItem();
Text searchText = searchItem.addText("query");
if (!query.equals(new String("-1")))
searchText.setValue(query);
searchItem.addButton("submit_search_groups").setValue(T_submit_search_groups);
actionsList.addLabel();
Item buttons = actionsList.addItem();
buttons.addButton("submit_save").setValue(T_submit_save);
buttons.addButton("submit_cancel").setValue(T_submit_cancel);
// Display the search results table
if (!query.equals(new String("-1"))) {
Division groupsList = main.addDivision("edit-policy-groupsList");
groupsList.setHead(T_groups_head);
this.addGroupSearch(groupsList, currentGroup, dso, query, page);
}
main.addHidden("administrative-continue").setValue(knot.getId());
}
/**
* Search for groups to add to this group.
*/
private void addGroupSearch(Division div, Group sourceGroup, DSpaceObject dso, String query, int page) throws WingException, SQLException
{
Group[] groups = Group.search(context, query, page*RESULTS_PER_PAGE, (page+1)*RESULTS_PER_PAGE);
int totalResults = Group.searchResultCount(context, query);
ArrayList<ResourcePolicy> otherPolicies = (ArrayList<ResourcePolicy>)AuthorizeManager.getPolicies(context, dso);
if (totalResults > RESULTS_PER_PAGE) {
int firstIndex = page*RESULTS_PER_PAGE+1;
int lastIndex = page*RESULTS_PER_PAGE + groups.length;
String baseURL = contextPath+"/admin/authorize?administrative-continue="+knot.getId();
String nextURL = null, prevURL = null;
if (page < ((totalResults - 1) / RESULTS_PER_PAGE))
nextURL = baseURL+"&page="+(page+1);
if (page > 0)
prevURL = baseURL+"&page="+(page-1);
div.setSimplePagination(totalResults,firstIndex,lastIndex,prevURL, nextURL);
}
Table table = div.addTable("policy-edit-search-group",groups.length + 1, 1);
Row header = table.addRow(Row.ROLE_HEADER);
// Add the header row
header = table.addRow(Row.ROLE_HEADER);
header.addCell().addContent(T_groups_column1);
header.addCell().addContent(T_groups_column2);
header.addCell().addContent(T_groups_column3);
header.addCell().addContent(T_groups_column4);
// The rows of search results
for (Group group : groups)
{
String groupID = String.valueOf(group.getID());
String name = group.getName();
url = contextPath+"/admin/groups?administrative-continue="+knot.getId()+"&submit_edit_group&group_id="+groupID;
Row row = table.addRow();
row.addCell().addContent(groupID);
row.addCell().addXref(url,name);
// Iterate other other polices of our parent resource to see if any match the currently selected group
String otherAuthorizations = new String();
int groupsMatched = 0;
for (ResourcePolicy otherPolicy : otherPolicies) {
if (otherPolicy.getGroup() == group) {
otherAuthorizations += otherPolicy.getActionText() + ", ";
groupsMatched++;
}
}
if (groupsMatched > 0) {
row.addCell().addContent(otherAuthorizations.substring(0,otherAuthorizations.lastIndexOf(", ")));
}
else
row.addCell().addContent("-");
if (group != sourceGroup)
row.addCell().addButton("submit_group_id_"+groupID).setValue(T_set_group);
else
row.addCell().addContent(T_current_group);
}
if (groups.length <= 0) {
table.addRow().addCell(1, 4).addContent(T_no_results);
}
}
}

View File

@@ -0,0 +1,320 @@
/*
* AssignCollectionRoles.java
*
* Version: $Revision: 1.0 $
*
* Date: $Date: 2006/07/13 23:20:54 $
*
* Copyright (c) 2002, Hewlett-Packard Company and Massachusetts
* Institute of Technology. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* - 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.
*
* - Neither the name of the Hewlett-Packard Company nor the name of the
* Massachusetts Institute of Technology nor the names of their
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS 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 COPYRIGHT
* HOLDERS OR 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.
*/
package org.dspace.app.xmlui.aspect.administrative.collection;
import java.sql.SQLException;
import org.dspace.app.xmlui.aspect.administrative.FlowContainerUtils;
import org.dspace.app.xmlui.cocoon.AbstractDSpaceTransformer;
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.Button;
import org.dspace.app.xmlui.wing.element.Cell;
import org.dspace.app.xmlui.wing.element.Division;
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.Row;
import org.dspace.app.xmlui.wing.element.Table;
import org.dspace.authorize.AuthorizeException;
import org.dspace.authorize.AuthorizeManager;
import org.dspace.content.Collection;
import org.dspace.eperson.Group;
/**
* Presents the user (most likely a global administrator) with the form to edit
* the collection's special authorization groups (or roles). Those include submission
* group, workflows, collection admin, and default read.
* @author Alexey Maslov
*/
public class AssignCollectionRoles extends AbstractDSpaceTransformer
{
/** Language Strings */
private static final Message T_dspace_home = message("xmlui.general.dspace_home");
private static final Message T_collection_trail = message("xmlui.administrative.collection.general.collection_trail");
private static final Message T_options_metadata = message("xmlui.administrative.collection.general.options_metadata");
private static final Message T_options_roles = message("xmlui.administrative.collection.general.options_roles");
private static final Message T_submit_return = message("xmlui.general.return");
private static final Message T_title = message("xmlui.administrative.collection.AssignCollectionRoles.title");
private static final Message T_trail = message("xmlui.administrative.collection.AssignCollectionRoles.trail");
private static final Message T_main_head = message("xmlui.administrative.collection.AssignCollectionRoles.main_head");
private static final Message T_no_role = message("xmlui.administrative.collection.AssignCollectionRoles.no_role");
private static final Message T_create = message("xmlui.administrative.collection.AssignCollectionRoles.create");
private static final Message T_delete = message("xmlui.administrative.collection.AssignCollectionRoles.delete");
private static final Message T_restrict = message("xmlui.administrative.collection.AssignCollectionRoles.restrict");
private static final Message T_help_admins = message("xmlui.administrative.collection.AssignCollectionRoles.help_admins");
private static final Message T_help_wf_step1 = message("xmlui.administrative.collection.AssignCollectionRoles.help_wf_step1");
private static final Message T_help_wf_step2 = message("xmlui.administrative.collection.AssignCollectionRoles.help_wf_step2");
private static final Message T_help_wf_step3 = message("xmlui.administrative.collection.AssignCollectionRoles.help_wf_step3");
private static final Message T_help_submitters = message("xmlui.administrative.collection.AssignCollectionRoles.help_submitters");
private static final Message T_help_default_read = message("xmlui.administrative.collection.AssignCollectionRoles.help_default_read");
private static final Message T_default_read_custom = message("xmlui.administrative.collection.AssignCollectionRoles.default_read_custom");
private static final Message T_default_read_anonymous = message("xmlui.administrative.collection.AssignCollectionRoles.default_read_anonymous");
private static final Message T_edit_authorization = message("xmlui.administrative.collection.AssignCollectionRoles.edit_authorization");
private static final Message T_role_name = message("xmlui.administrative.collection.AssignCollectionRoles.role_name");
private static final Message T_role_group = message("xmlui.administrative.collection.AssignCollectionRoles.role_group");
private static final Message T_role_buttons = message("xmlui.administrative.collection.AssignCollectionRoles.role_buttons");
private static final Message T_label_admins = message("xmlui.administrative.collection.AssignCollectionRoles.label_admins");
private static final Message T_label_wf_step1 = message("xmlui.administrative.collection.AssignCollectionRoles.label_wf_step1");
private static final Message T_label_wf_step2 = message("xmlui.administrative.collection.AssignCollectionRoles.label_wf_step2");
private static final Message T_label_wf_step3 = message("xmlui.administrative.collection.AssignCollectionRoles.label_wf_step3");
private static final Message T_label_submitters = message("xmlui.administrative.collection.AssignCollectionRoles.label_submitters");
private static final Message T_label_default_read = message("xmlui.administrative.collection.AssignCollectionRoles.label_default_read");
private static final Message T_sysadmins_only = message("xmlui.administrative.collection.AssignCollectionRoles.sysadmins_only");
public void addPageMeta(PageMeta pageMeta) throws WingException
{
pageMeta.addMetadata("title").addContent(T_title);
pageMeta.addTrailLink(contextPath + "/", T_dspace_home);
pageMeta.addTrail().addContent(T_collection_trail);
pageMeta.addTrail().addContent(T_trail);
}
public void addBody(Body body) throws WingException, SQLException, AuthorizeException
{
int collectionID = parameters.getParameterAsInteger("collectionID", -1);
Collection thisCollection = Collection.find(context, collectionID);
String baseURL = contextPath + "/admin/collection?administrative-continue=" + knot.getId();
Group admins = thisCollection.getAdministrators();
Group wfStep1 = thisCollection.getWorkflowGroup(1);
Group wfStep2 = thisCollection.getWorkflowGroup(2);
Group wfStep3 = thisCollection.getWorkflowGroup(3);
Group submitters = thisCollection.getSubmitters();
Group defaultRead = null;
int defaultReadID = FlowContainerUtils.getCollectionDefaultRead(context, collectionID);
if (defaultReadID >= 0)
defaultRead = Group.find(context, defaultReadID);
// DIVISION: main
Division main = body.addInteractiveDivision("collection-assign-roles",contextPath+"/admin/collection",Division.METHOD_POST,"primary administrative collection");
main.setHead(T_main_head.parameterize(thisCollection.getMetadata("name")));
List options = main.addList("options", List.TYPE_SIMPLE, "horizontal");
options.addItem().addXref(baseURL+"&submit_metadata",T_options_metadata);
options.addItem().addHighlight("bold").addXref(baseURL+"&submit_roles",T_options_roles);
// The table of admin roles
Table rolesTable = main.addTable("roles-table", 6, 5);
Row tableRow;
// The header row
Row tableHeader = rolesTable.addRow(Row.ROLE_HEADER);
tableHeader.addCell().addContent(T_role_name);
tableHeader.addCell().addContent(T_role_group);
tableHeader.addCell().addContent(T_role_buttons);
rolesTable.addRow();
/*
* The collection admins
*/
// data row
tableRow = rolesTable.addRow(Row.ROLE_DATA);
tableRow.addCell(Cell.ROLE_HEADER).addContent(T_label_admins);
if (admins != null)
{
tableRow.addCell().addXref(baseURL + "&submit_edit_admin", admins.getName());
tableRow.addCell();
}
else
{
tableRow.addCell().addContent(T_no_role);
addAdministratorOnlyButton(tableRow.addCell(),"submit_create_admin",T_create);
}
// help and directions row
tableRow = rolesTable.addRow(Row.ROLE_DATA);
tableRow.addCell();
tableRow.addCell(1,2).addHighlight("fade offset").addContent(T_help_admins);
/*
* Workflow steps 1-3
*/
// data row
tableRow = rolesTable.addRow(Row.ROLE_DATA);
tableRow.addCell(Cell.ROLE_HEADER).addContent(T_label_wf_step1);
if (wfStep1 != null)
{
tableRow.addCell().addXref(baseURL + "&submit_edit_wf_step1", wfStep1.getName());
addAdministratorOnlyButton(tableRow.addCell(),"submit_delete_wf_step1",T_delete);
}
else
{
tableRow.addCell().addContent(T_no_role);
addAdministratorOnlyButton(tableRow.addCell(),"submit_create_wf_step1",T_create);
}
// help and directions row
tableRow = rolesTable.addRow(Row.ROLE_DATA);
tableRow.addCell();
tableRow.addCell(1,2).addHighlight("fade offset").addContent(T_help_wf_step1);
// data row
tableRow = rolesTable.addRow(Row.ROLE_DATA);
tableRow.addCell(Cell.ROLE_HEADER).addContent(T_label_wf_step2);
if (wfStep2 != null)
{
tableRow.addCell().addXref(baseURL + "&submit_edit_wf_step2", wfStep2.getName());
addAdministratorOnlyButton(tableRow.addCell(),"submit_delete_wf_step2",T_delete);
}
else
{
tableRow.addCell().addContent(T_no_role);
addAdministratorOnlyButton(tableRow.addCell(),"submit_create_wf_step2",T_create);
}
// help and directions row
tableRow = rolesTable.addRow(Row.ROLE_DATA);
tableRow.addCell();
tableRow.addCell(1,2).addHighlight("fade offset").addContent(T_help_wf_step2);
// data row
tableRow = rolesTable.addRow(Row.ROLE_DATA);
tableRow.addCell(Cell.ROLE_HEADER).addContent(T_label_wf_step3);
if (wfStep3 != null)
{
tableRow.addCell().addXref(baseURL + "&submit_edit_wf_step3", wfStep3.getName());
addAdministratorOnlyButton(tableRow.addCell(),"submit_delete_wf_step3",T_delete);
}
else
{
tableRow.addCell().addContent(T_no_role);
addAdministratorOnlyButton(tableRow.addCell(),"submit_create_wf_step3",T_create);
}
// help and directions row
tableRow = rolesTable.addRow(Row.ROLE_DATA);
tableRow.addCell();
tableRow.addCell(1,2).addHighlight("fade offset").addContent(T_help_wf_step3);
/*
* The collection submitters
*/
tableRow = rolesTable.addRow(Row.ROLE_DATA);
tableRow.addCell(Cell.ROLE_HEADER).addContent(T_label_submitters);
if (submitters != null)
{
tableRow.addCell().addXref(baseURL + "&submit_edit_submit", submitters.getName());
tableRow.addCell();
}
else
{
tableRow.addCell().addContent(T_no_role);
addAdministratorOnlyButton(tableRow.addCell(),"submit_create_submit",T_create);
}
// help and directions row
tableRow = rolesTable.addRow(Row.ROLE_DATA);
tableRow.addCell();
tableRow.addCell(1,2).addHighlight("fade offset").addContent(T_help_submitters);
/*
* The collection's default read authorizations
*/
tableRow = rolesTable.addRow(Row.ROLE_DATA);
tableRow.addCell(Cell.ROLE_HEADER).addContent(T_label_default_read);
if (defaultRead == null)
{
// Custome reading permissions, we can't handle it, just provide a link to the
// authorizations manager.
tableRow.addCell(1,2).addContent(T_default_read_custom);
}
else if (defaultRead.getID() == 0) {
// Anonymous reading
tableRow.addCell().addContent(T_default_read_anonymous);
addAdministratorOnlyButton(tableRow.addCell(),"submit_create_default_read",T_restrict);
}
else
{
// A specific group is dedicated to reading.
tableRow.addCell().addXref(baseURL + "&submit_edit_default_read", defaultRead.getName());
addAdministratorOnlyButton(tableRow.addCell(),"submit_delete_default_read",T_delete);
}
// help and directions row
tableRow = rolesTable.addRow(Row.ROLE_DATA);
tableRow.addCell();
tableRow.addCell(1,2).addHighlight("fade offset").addContent(T_help_default_read);
if (AuthorizeManager.isAdmin(context))
{
// add one last link to edit the raw authorizations
Cell authCell =rolesTable.addRow().addCell(1,3);
authCell.addXref(baseURL + "&submit_authorizations", T_edit_authorization);
}
Para buttonList = main.addPara();
buttonList.addButton("submit_return").setValue(T_submit_return);
main.addHidden("administrative-continue").setValue(knot.getId());
}
private void addAdministratorOnlyButton(Cell cell, String buttonName, Message buttonLabel) throws WingException, SQLException
{
Button button = cell.addButton(buttonName);
button.setValue(buttonLabel);
if (!AuthorizeManager.isAdmin(context))
{
// Only admins can create or delete
button.setDisabled();
cell.addHighlight("fade").addContent(T_sysadmins_only);
}
}
}

View File

@@ -0,0 +1,149 @@
/*
* EditCollectionMetadataForm.java
*
* Version: $Revision: 1.0 $
*
* Date: $Date: 2006/07/13 23:20:54 $
*
* Copyright (c) 2002, Hewlett-Packard Company and Massachusetts
* Institute of Technology. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* - 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.
*
* - Neither the name of the Hewlett-Packard Company nor the name of the
* Massachusetts Institute of Technology nor the names of their
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS 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 COPYRIGHT
* HOLDERS OR 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.
*/
package org.dspace.app.xmlui.aspect.administrative.collection;
import java.sql.SQLException;
import org.dspace.app.xmlui.cocoon.AbstractDSpaceTransformer;
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.List;
import org.dspace.app.xmlui.wing.element.PageMeta;
import org.dspace.app.xmlui.wing.element.Para;
import org.dspace.app.xmlui.wing.element.Text;
import org.dspace.app.xmlui.wing.element.TextArea;
import org.dspace.authorize.AuthorizeException;
import org.dspace.content.Community;
/**
* Presents the user with a form to enter the initial metadata for creation of a new collection
* @author Alexey Maslov
*/
public class CreateCollectionForm extends AbstractDSpaceTransformer
{
/** Language Strings */
private static final Message T_dspace_home =
message("xmlui.general.dspace_home");
private static final Message T_title = message("xmlui.administrative.collection.CreateCollectionForm.title");
private static final Message T_trail = message("xmlui.administrative.collection.CreateCollectionForm.trail");
private static final Message T_main_head = message("xmlui.administrative.collection.CreateCollectionForm.main_head");
private static final Message T_label_name = message("xmlui.administrative.collection.EditCollectionMetadataForm.label_name");
private static final Message T_label_short_description = message("xmlui.administrative.collection.EditCollectionMetadataForm.label_short_description");
private static final Message T_label_introductory_text = message("xmlui.administrative.collection.EditCollectionMetadataForm.label_introductory_text");
private static final Message T_label_copyright_text = message("xmlui.administrative.collection.EditCollectionMetadataForm.label_copyright_text");
private static final Message T_label_side_bar_text = message("xmlui.administrative.collection.EditCollectionMetadataForm.label_side_bar_text");
private static final Message T_label_license = message("xmlui.administrative.collection.EditCollectionMetadataForm.label_license");
private static final Message T_label_provenance_description = message("xmlui.administrative.collection.EditCollectionMetadataForm.label_provenance_description");
private static final Message T_label_logo = message("xmlui.administrative.collection.EditCollectionMetadataForm.label_logo");
private static final Message T_submit_save = message("xmlui.administrative.collection.CreateCollectionForm.submit_save");
private static final Message T_submit_cancel = message("xmlui.administrative.collection.CreateCollectionForm.submit_cancel");
public void addPageMeta(PageMeta pageMeta) throws WingException
{
pageMeta.addMetadata("title").addContent(T_title);
pageMeta.addTrailLink(contextPath + "/", T_dspace_home);
pageMeta.addTrail().addContent(T_trail);
}
public void addBody(Body body) throws WingException, SQLException, AuthorizeException
{
int communityID = parameters.getParameterAsInteger("communityID", -1);
Community parentCommunity = Community.find(context, communityID);
// DIVISION: main
Division main = body.addInteractiveDivision("create-collection",contextPath+"/admin/collection",Division.METHOD_MULTIPART,"primary administrative collection");
main.setHead(T_main_head.parameterize(parentCommunity.getMetadata("name")));
// The grand list of metadata options
List metadataList = main.addList("metadataList", "form");
// collection name
metadataList.addLabel(T_label_name);
Text name = metadataList.addItem().addText("name");
name.setSize(40);
// short description
metadataList.addLabel(T_label_short_description);
Text short_description = metadataList.addItem().addText("short_description");
short_description.setSize(40);
// introductory text
metadataList.addLabel(T_label_introductory_text);
TextArea introductory_text = metadataList.addItem().addTextArea("introductory_text");
introductory_text.setSize(6, 40);
// copyright text
metadataList.addLabel(T_label_copyright_text);
TextArea copyright_text = metadataList.addItem().addTextArea("copyright_text");
copyright_text.setSize(6, 40);
// legacy sidebar text; may or may not be used for news
metadataList.addLabel(T_label_side_bar_text);
TextArea side_bar_text = metadataList.addItem().addTextArea("side_bar_text");
side_bar_text.setSize(6, 40);
// license text
metadataList.addLabel(T_label_license);
TextArea license = metadataList.addItem().addTextArea("license");
license.setSize(6, 40);
// provenance description
metadataList.addLabel(T_label_provenance_description);
TextArea provenance_description = metadataList.addItem().addTextArea("provenance_description");
provenance_description.setSize(6, 40);
// the row to upload a new logo
metadataList.addLabel(T_label_logo);
metadataList.addItem().addFile("logo");
Para buttonList = main.addPara();
buttonList.addButton("submit_save").setValue(T_submit_save);
buttonList.addButton("submit_cancel").setValue(T_submit_cancel);
main.addHidden("administrative-continue").setValue(knot.getId());
}
}

View File

@@ -0,0 +1,106 @@
/*
* DeleteCollectionConfirm.java
*
* Version: $Revision: 1.0 $
*
* Date: $Date: 2006/07/13 23:20:54 $
*
* Copyright (c) 2002, Hewlett-Packard Company and Massachusetts
* Institute of Technology. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* - 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.
*
* - Neither the name of the Hewlett-Packard Company nor the name of the
* Massachusetts Institute of Technology nor the names of their
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS 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 COPYRIGHT
* HOLDERS OR 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.
*/
package org.dspace.app.xmlui.aspect.administrative.collection;
import java.sql.SQLException;
import org.dspace.app.xmlui.cocoon.AbstractDSpaceTransformer;
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.List;
import org.dspace.app.xmlui.wing.element.PageMeta;
import org.dspace.app.xmlui.wing.element.Para;
import org.dspace.authorize.AuthorizeException;
import org.dspace.content.Collection;
/**
* Confirmation step for the deletion of an entire collection
* @author Alexey Maslov
*/
public class DeleteCollectionConfirm extends AbstractDSpaceTransformer
{
/** Language Strings */
private static final Message T_dspace_home =
message("xmlui.general.dspace_home");
private static final Message T_title = message("xmlui.administrative.collection.DeleteCollectionConfirm.title");
private static final Message T_trail = message("xmlui.administrative.collection.DeleteCollectionConfirm.trail");
private static final Message T_main_head = message("xmlui.administrative.collection.DeleteCollectionConfirm.main_head");
private static final Message T_main_para = message("xmlui.administrative.collection.DeleteCollectionConfirm.main_para");
private static final Message T_confirm_item1 = message("xmlui.administrative.collection.DeleteCollectionConfirm.confirm_item1");
private static final Message T_confirm_item2 = message("xmlui.administrative.collection.DeleteCollectionConfirm.confirm_item2");
private static final Message T_confirm_item3 = message("xmlui.administrative.collection.DeleteCollectionConfirm.confirm_item3");
private static final Message T_submit_confirm = message("xmlui.general.delete");
private static final Message T_submit_cancel = message("xmlui.general.cancel");
public void addPageMeta(PageMeta pageMeta) throws WingException
{
pageMeta.addMetadata("title").addContent(T_title);
pageMeta.addTrailLink(contextPath + "/", T_dspace_home);
pageMeta.addTrail().addContent(T_trail);
}
public void addBody(Body body) throws WingException, SQLException, AuthorizeException
{
int collectionID = parameters.getParameterAsInteger("collectionID", -1);
Collection thisCollection = Collection.find(context, collectionID);
// DIVISION: main
Division main = body.addInteractiveDivision("collection-confirm-delete",contextPath+"/admin/collection",Division.METHOD_POST,"primary administrative collection");
main.setHead(T_main_head.parameterize(collectionID));
main.addPara(T_main_para.parameterize(thisCollection.getMetadata("name")));
List deleteConfirmHelp = main.addList("consequences",List.TYPE_BULLETED);
deleteConfirmHelp.addItem(T_confirm_item1);
deleteConfirmHelp.addItem(T_confirm_item2);
deleteConfirmHelp.addItem(T_confirm_item3);
Para buttonList = main.addPara();
buttonList.addButton("submit_confirm").setValue(T_submit_confirm);
buttonList.addButton("submit_cancel").setValue(T_submit_cancel);
main.addHidden("administrative-continue").setValue(knot.getId());
}
}

View File

@@ -0,0 +1,105 @@
/*
* DeleteCollectionRoleConfirm.java
*
* Version: $Revision: 1.0 $
*
* Date: $Date: 2006/07/13 23:20:54 $
*
* Copyright (c) 2002, Hewlett-Packard Company and Massachusetts
* Institute of Technology. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* - 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.
*
* - Neither the name of the Hewlett-Packard Company nor the name of the
* Massachusetts Institute of Technology nor the names of their
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS 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 COPYRIGHT
* HOLDERS OR 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.
*/
package org.dspace.app.xmlui.aspect.administrative.collection;
import java.sql.SQLException;
import org.dspace.app.xmlui.cocoon.AbstractDSpaceTransformer;
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.PageMeta;
import org.dspace.app.xmlui.wing.element.Para;
import org.dspace.authorize.AuthorizeException;
import org.dspace.eperson.Group;
/**
* Confirmation step for the deletion a collection's role
* @author Alexey Maslov
*/
public class DeleteCollectionRoleConfirm extends AbstractDSpaceTransformer
{
/** Language Strings */
private static final Message T_dspace_home =
message("xmlui.general.dspace_home");
private static final Message T_title = message("xmlui.administrative.collection.DeleteCollectionRoleConfirm.title");
private static final Message T_trail = message("xmlui.administrative.collection.DeleteCollectionRoleConfirm.trail");
private static final Message T_main_head = message("xmlui.administrative.collection.DeleteCollectionRoleConfirm.main_head");
private static final Message T_main_para_read = message("xmlui.administrative.collection.DeleteCollectionRoleConfirm.main_para_read");
private static final Message T_main_para = message("xmlui.administrative.collection.DeleteCollectionRoleConfirm.main_para");
private static final Message T_submit_confirm = message("xmlui.general.delete");
private static final Message T_submit_cancel = message("xmlui.general.cancel");
public void addPageMeta(PageMeta pageMeta) throws WingException
{
pageMeta.addMetadata("title").addContent(T_title);
pageMeta.addTrailLink(contextPath + "/", T_dspace_home);
pageMeta.addTrail().addContent(T_trail);
}
public void addBody(Body body) throws WingException, SQLException, AuthorizeException
{
String role = parameters.getParameter("role", null);
int groupID = parameters.getParameterAsInteger("groupID", -1);
Group toBeDeleted = Group.find(context, groupID);
// DIVISION: main
Division main = body.addInteractiveDivision("collection-role-delete",contextPath+"/admin/collection",Division.METHOD_POST,"primary administrative collection");
main.setHead(T_main_head.parameterize(role));
// Different help message for the default read group to enforce its non-retroactive nature
if (role == "DEFAULT_READ")
main.addPara(T_main_para_read.parameterize(toBeDeleted.getName()));
else
main.addPara(T_main_para.parameterize(toBeDeleted.getName()));
Para buttonList = main.addPara();
buttonList.addButton("submit_confirm").setValue(T_submit_confirm);
buttonList.addButton("submit_cancel").setValue(T_submit_cancel);
main.addHidden("administrative-continue").setValue(knot.getId());
}
}

View File

@@ -0,0 +1,242 @@
/*
* EditCollectionMetadataForm.java
*
* Version: $Revision: 1.0 $
*
* Date: $Date: 2006/07/13 23:20:54 $
*
* Copyright (c) 2002, Hewlett-Packard Company and Massachusetts
* Institute of Technology. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* - 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.
*
* - Neither the name of the Hewlett-Packard Company nor the name of the
* Massachusetts Institute of Technology nor the names of their
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS 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 COPYRIGHT
* HOLDERS OR 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.
*/
package org.dspace.app.xmlui.aspect.administrative.collection;
import java.sql.SQLException;
import org.dspace.app.xmlui.aspect.administrative.FlowContainerUtils;
import org.dspace.app.xmlui.cocoon.AbstractDSpaceTransformer;
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.Button;
import org.dspace.app.xmlui.wing.element.Division;
import org.dspace.app.xmlui.wing.element.Item;
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.Text;
import org.dspace.app.xmlui.wing.element.TextArea;
import org.dspace.authorize.AuthorizeException;
import org.dspace.authorize.AuthorizeManager;
import org.dspace.content.Collection;
/**
* Presents the user (in this case an administrator over the collection) with the
* form to edit that collection's metadata, logo, and item template.
* @author Alexey Maslov
*/
public class EditCollectionMetadataForm extends AbstractDSpaceTransformer
{
/** Language Strings */
private static final Message T_dspace_home =
message("xmlui.general.dspace_home");
private static final Message T_collection_trail = message("xmlui.administrative.collection.general.collection_trail");
private static final Message T_options_metadata = message("xmlui.administrative.collection.general.options_metadata");
private static final Message T_options_roles = message("xmlui.administrative.collection.general.options_roles");
private static final Message T_submit_return = message("xmlui.general.return");
private static final Message T_title = message("xmlui.administrative.collection.EditCollectionMetadataForm.title");
private static final Message T_trail = message("xmlui.administrative.collection.EditCollectionMetadataForm.trail");
private static final Message T_main_head = message("xmlui.administrative.collection.EditCollectionMetadataForm.main_head");
private static final Message T_label_name = message("xmlui.administrative.collection.EditCollectionMetadataForm.label_name");
private static final Message T_label_short_description = message("xmlui.administrative.collection.EditCollectionMetadataForm.label_short_description");
private static final Message T_label_introductory_text = message("xmlui.administrative.collection.EditCollectionMetadataForm.label_introductory_text");
private static final Message T_label_copyright_text = message("xmlui.administrative.collection.EditCollectionMetadataForm.label_copyright_text");
private static final Message T_label_side_bar_text = message("xmlui.administrative.collection.EditCollectionMetadataForm.label_side_bar_text");
private static final Message T_label_license = message("xmlui.administrative.collection.EditCollectionMetadataForm.label_license");
private static final Message T_label_provenance_description = message("xmlui.administrative.collection.EditCollectionMetadataForm.label_provenance_description");
private static final Message T_label_logo = message("xmlui.administrative.collection.EditCollectionMetadataForm.label_logo");
private static final Message T_label_existing_logo = message("xmlui.administrative.collection.EditCollectionMetadataForm.label_existing_logo");
private static final Message T_label_item_template = message("xmlui.administrative.collection.EditCollectionMetadataForm.label_item_template");
private static final Message T_submit_create_template = message("xmlui.administrative.collection.EditCollectionMetadataForm.submit_create_template");
private static final Message T_submit_edit_template = message("xmlui.administrative.collection.EditCollectionMetadataForm.submit_edit_template");
private static final Message T_submit_delete_template = message("xmlui.administrative.collection.EditCollectionMetadataForm.submit_delete_template");
private static final Message T_submit_delete_logo = message("xmlui.administrative.collection.EditCollectionMetadataForm.submit_delete_logo");
private static final Message T_submit_delete = message("xmlui.administrative.collection.EditCollectionMetadataForm.submit_delete");
private static final Message T_submit_save = message("xmlui.administrative.collection.EditCollectionMetadataForm.submit_save");
private static final Message T_sysadmins_only = message("xmlui.administrative.collection.EditCollectionMetadataForm.sysadmins_only");
public void addPageMeta(PageMeta pageMeta) throws WingException
{
pageMeta.addMetadata("title").addContent(T_title);
pageMeta.addTrailLink(contextPath + "/", T_dspace_home);
pageMeta.addTrail().addContent(T_collection_trail);
pageMeta.addTrail().addContent(T_trail);
}
public void addBody(Body body) throws WingException, SQLException, AuthorizeException
{
int collectionID = parameters.getParameterAsInteger("collectionID", -1);
Collection thisCollection = Collection.find(context, collectionID);
String baseURL = contextPath + "/admin/collection?administrative-continue=" + knot.getId();
String short_description_error = FlowContainerUtils.checkXMLFragment(thisCollection.getMetadata("short_description"));
String introductory_text_error = FlowContainerUtils.checkXMLFragment(thisCollection.getMetadata("introductory_text"));
String copyright_text_error = FlowContainerUtils.checkXMLFragment(thisCollection.getMetadata("copyright_text"));
String side_bar_text_error = FlowContainerUtils.checkXMLFragment(thisCollection.getMetadata("side_bar_text"));
String license_error = FlowContainerUtils.checkXMLFragment(thisCollection.getMetadata("license"));
String provenance_description_error = FlowContainerUtils.checkXMLFragment(thisCollection.getMetadata("provenance_description"));
// DIVISION: main
Division main = body.addInteractiveDivision("collection-metadata-edit",contextPath+"/admin/collection",Division.METHOD_MULTIPART,"primary administrative collection");
main.setHead(T_main_head.parameterize(thisCollection.getMetadata("name")));
List options = main.addList("options",List.TYPE_SIMPLE,"horizontal");
options.addItem().addHighlight("bold").addXref(baseURL+"&submit_metadata",T_options_metadata);
options.addItem().addXref(baseURL+"&submit_roles",T_options_roles);
// The grand list of metadata options
List metadataList = main.addList("metadataList", "form");
// collection name
metadataList.addLabel(T_label_name);
Text name = metadataList.addItem().addText("name");
name.setSize(40);
name.setValue(thisCollection.getMetadata("name"));
// short description
metadataList.addLabel(T_label_short_description);
Text short_description = metadataList.addItem().addText("short_description");
short_description.setValue(thisCollection.getMetadata("short_description"));
short_description.setSize(40);
if (short_description_error != null)
short_description.addError(short_description_error);
// introductory text
metadataList.addLabel(T_label_introductory_text);
TextArea introductory_text = metadataList.addItem().addTextArea("introductory_text");
introductory_text.setValue(thisCollection.getMetadata("introductory_text"));
introductory_text.setSize(6, 40);
if (introductory_text_error != null)
introductory_text.addError(introductory_text_error);
// copyright text
metadataList.addLabel(T_label_copyright_text);
TextArea copyright_text = metadataList.addItem().addTextArea("copyright_text");
copyright_text.setValue(thisCollection.getMetadata("copyright_text"));
copyright_text.setSize(6, 40);
if (copyright_text_error != null)
copyright_text.addError(copyright_text_error);
// legacy sidebar text; may or may not be used for news
metadataList.addLabel(T_label_side_bar_text);
TextArea side_bar_text = metadataList.addItem().addTextArea("side_bar_text");
side_bar_text.setValue(thisCollection.getMetadata("side_bar_text"));
side_bar_text.setSize(6, 40);
if (side_bar_text_error != null)
side_bar_text.addError(side_bar_text_error);
// license text
metadataList.addLabel(T_label_license);
TextArea license = metadataList.addItem().addTextArea("license");
license.setValue(thisCollection.getMetadata("license"));
license.setSize(6, 40);
if (license_error != null)
license.addError(license_error);
// provenance description
metadataList.addLabel(T_label_provenance_description);
TextArea provenance_description = metadataList.addItem().addTextArea("provenance_description");
provenance_description.setValue(thisCollection.getMetadata("provenance_description"));
provenance_description.setSize(6, 40);
if (provenance_description_error != null)
provenance_description.addError(provenance_description_error);
// the row to upload a new logo
metadataList.addLabel(T_label_logo);
metadataList.addItem().addFile("logo");
// the row displaying an existing logo
Item item;
if (thisCollection.getLogo() != null) {
metadataList.addLabel(T_label_existing_logo);
item = metadataList.addItem();
item.addFigure(contextPath + "/bitstream/id/" + thisCollection.getLogo().getID() + "/bob.jpg", null, null);
item.addButton("submit_delete_logo").setValue(T_submit_delete_logo);
}
// item template creation and removal
metadataList.addLabel(T_label_item_template);
item = metadataList.addItem();
if (thisCollection.getTemplateItem() == null)
addAdministratorOnlyButton(item, "submit_create_template", T_submit_create_template);
else
{
item.addButton("submit_edit_template").setValue(T_submit_edit_template);
addAdministratorOnlyButton(item, "submit_delete_template", T_submit_delete_template);
}
Para buttonList = main.addPara();
buttonList.addButton("submit_save").setValue(T_submit_save);
if (AuthorizeManager.isAdmin(context))
buttonList.addButton("submit_delete").setValue(T_submit_delete);
buttonList.addButton("submit_return").setValue(T_submit_return);
main.addHidden("administrative-continue").setValue(knot.getId());
}
private void addAdministratorOnlyButton(Item item, String buttonName, Message buttonLabel) throws WingException, SQLException
{
Button button = item.addButton(buttonName);
button.setValue(buttonLabel);
if (!AuthorizeManager.isAdmin(context))
{
// Only admins can create or delete
button.setDisabled();
item.addHighlight("fade").addContent(T_sysadmins_only);
}
}
}

View File

@@ -0,0 +1,145 @@
/*
* EditCollectionMetadataForm.java
*
* Version: $Revision: 1.0 $
*
* Date: $Date: 2006/07/13 23:20:54 $
*
* Copyright (c) 2002, Hewlett-Packard Company and Massachusetts
* Institute of Technology. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* - 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.
*
* - Neither the name of the Hewlett-Packard Company nor the name of the
* Massachusetts Institute of Technology nor the names of their
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS 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 COPYRIGHT
* HOLDERS OR 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.
*/
package org.dspace.app.xmlui.aspect.administrative.community;
import java.sql.SQLException;
import org.dspace.app.xmlui.cocoon.AbstractDSpaceTransformer;
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.List;
import org.dspace.app.xmlui.wing.element.PageMeta;
import org.dspace.app.xmlui.wing.element.Para;
import org.dspace.app.xmlui.wing.element.Text;
import org.dspace.app.xmlui.wing.element.TextArea;
import org.dspace.authorize.AuthorizeException;
import org.dspace.content.Community;
/**
* Presents the user with a form to enter the initial metadata for creation of a new community
* @author Alexey Maslov
*/
public class CreateCommunityForm extends AbstractDSpaceTransformer
{
/** Language Strings */
private static final Message T_dspace_home =
message("xmlui.general.dspace_home");
private static final Message T_title = message("xmlui.administrative.community.CreateCommunityForm.title");
private static final Message T_trail = message("xmlui.administrative.community.CreateCommunityForm.trail");
private static final Message T_main_head_sub = message("xmlui.administrative.community.CreateCommunityForm.main_head_sub");
private static final Message T_main_head_top = message("xmlui.administrative.community.CreateCommunityForm.main_head_top");
private static final Message T_label_name = message("xmlui.administrative.community.EditCommunityMetadataForm.label_name");
private static final Message T_label_short_description = message("xmlui.administrative.community.EditCommunityMetadataForm.label_short_description");
private static final Message T_label_introductory_text = message("xmlui.administrative.community.EditCommunityMetadataForm.label_introductory_text");
private static final Message T_label_copyright_text = message("xmlui.administrative.community.EditCommunityMetadataForm.label_copyright_text");
private static final Message T_label_side_bar_text = message("xmlui.administrative.community.EditCommunityMetadataForm.label_side_bar_text");
private static final Message T_label_logo = message("xmlui.administrative.community.EditCommunityMetadataForm.label_logo");
private static final Message T_submit_save = message("xmlui.administrative.community.CreateCommunityForm.submit_save");
private static final Message T_submit_cancel = message("xmlui.administrative.community.CreateCommunityForm.submit_cancel");
public void addPageMeta(PageMeta pageMeta) throws WingException
{
pageMeta.addMetadata("title").addContent(T_title);
pageMeta.addTrailLink(contextPath + "/", T_dspace_home);
pageMeta.addTrail().addContent(T_trail);
}
public void addBody(Body body) throws WingException, SQLException, AuthorizeException
{
int communityID = parameters.getParameterAsInteger("communityID", -1);
Community parentCommunity = Community.find(context, communityID);
// DIVISION: main
Division main = body.addInteractiveDivision("create-community",contextPath+"/admin/community",Division.METHOD_MULTIPART,"primary administrative community");
/* Whether the parent community is null is what determines if
we are creating a top-level community or a sub-community */
if (parentCommunity != null)
main.setHead(T_main_head_sub.parameterize(parentCommunity.getMetadata("name")));
else
main.setHead(T_main_head_top);
// The grand list of metadata options
List metadataList = main.addList("metadataList", "form");
// community name
metadataList.addLabel(T_label_name);
Text name = metadataList.addItem().addText("name");
name.setSize(40);
// short description
metadataList.addLabel(T_label_short_description);
Text short_description = metadataList.addItem().addText("short_description");
short_description.setSize(40);
// introductory text
metadataList.addLabel(T_label_introductory_text);
TextArea introductory_text = metadataList.addItem().addTextArea("introductory_text");
introductory_text.setSize(6, 40);
// copyright text
metadataList.addLabel(T_label_copyright_text);
TextArea copyright_text = metadataList.addItem().addTextArea("copyright_text");
copyright_text.setSize(6, 40);
// legacy sidebar text; may or may not be used for news
metadataList.addLabel(T_label_side_bar_text);
TextArea side_bar_text = metadataList.addItem().addTextArea("side_bar_text");
side_bar_text.setSize(6, 40);
// the row to upload a new logo
metadataList.addLabel(T_label_logo);
metadataList.addItem().addFile("logo");
Para buttonList = main.addPara();
buttonList.addButton("submit_save").setValue(T_submit_save);
buttonList.addButton("submit_cancel").setValue(T_submit_cancel);
main.addHidden("administrative-continue").setValue(knot.getId());
}
}

View File

@@ -0,0 +1,108 @@
/*
* DeleteCommunityConfirm.java
*
* Version: $Revision: 1.0 $
*
* Date: $Date: 2006/07/13 23:20:54 $
*
* Copyright (c) 2002, Hewlett-Packard Company and Massachusetts
* Institute of Technology. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* - 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.
*
* - Neither the name of the Hewlett-Packard Company nor the name of the
* Massachusetts Institute of Technology nor the names of their
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS 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 COPYRIGHT
* HOLDERS OR 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.
*/
package org.dspace.app.xmlui.aspect.administrative.community;
import java.sql.SQLException;
import org.dspace.app.xmlui.cocoon.AbstractDSpaceTransformer;
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.List;
import org.dspace.app.xmlui.wing.element.PageMeta;
import org.dspace.app.xmlui.wing.element.Para;
import org.dspace.authorize.AuthorizeException;
import org.dspace.content.Community;
/**
* Confirmation step for the deletion of an entire community
* @author Alexey Maslov
*/
public class DeleteCommunityConfirm extends AbstractDSpaceTransformer
{
/** Language Strings */
private static final Message T_dspace_home = message("xmlui.general.dspace_home");
private static final Message T_title = message("xmlui.administrative.community.DeleteCommunityConfirm.title");
private static final Message T_trail = message("xmlui.administrative.community.DeleteCommunityConfirm.trail");
private static final Message T_main_head = message("xmlui.administrative.community.DeleteCommunityConfirm.main_head");
private static final Message T_main_para = message("xmlui.administrative.community.DeleteCommunityConfirm.main_para");
private static final Message T_confirm_item1 = message("xmlui.administrative.community.DeleteCommunityConfirm.confirm_item1");
private static final Message T_confirm_item2 = message("xmlui.administrative.community.DeleteCommunityConfirm.confirm_item2");
private static final Message T_confirm_item3 = message("xmlui.administrative.community.DeleteCommunityConfirm.confirm_item3");
private static final Message T_confirm_item4 = message("xmlui.administrative.community.DeleteCommunityConfirm.confirm_item4");
private static final Message T_submit_confirm = message("xmlui.general.delete");
private static final Message T_submit_cancel = message("xmlui.general.cancel");
public void addPageMeta(PageMeta pageMeta) throws WingException
{
pageMeta.addMetadata("title").addContent(T_title);
pageMeta.addTrailLink(contextPath + "/", T_dspace_home);
pageMeta.addTrail().addContent(T_trail);
}
public void addBody(Body body) throws WingException, SQLException, AuthorizeException
{
int communityID = parameters.getParameterAsInteger("communityID", -1);
Community thisCommunity = Community.find(context, communityID);
// DIVISION: main
Division main = body.addInteractiveDivision("community-confirm-delete",contextPath+"/admin/community",Division.METHOD_POST,"primary administrative community");
main.setHead(T_main_head.parameterize(communityID));
main.addPara(T_main_para.parameterize(thisCommunity.getMetadata("name")));
List deleteConfirmHelp = main.addList("consequences",List.TYPE_BULLETED);
deleteConfirmHelp.addItem(T_confirm_item1);
deleteConfirmHelp.addItem(T_confirm_item2);
deleteConfirmHelp.addItem(T_confirm_item3);
deleteConfirmHelp.addItem(T_confirm_item4);
Para buttonList = main.addPara();
buttonList.addButton("submit_confirm").setValue(T_submit_confirm);
buttonList.addButton("submit_cancel").setValue(T_submit_cancel);
main.addHidden("administrative-continue").setValue(knot.getId());
}
}

View File

@@ -0,0 +1,178 @@
/*
* EditCommunityMetadataForm.java
*
* Version: $Revision: 1.0 $
*
* Date: $Date: 2006/07/13 23:20:54 $
*
* Copyright (c) 2002, Hewlett-Packard Company and Massachusetts
* Institute of Technology. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* - 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.
*
* - Neither the name of the Hewlett-Packard Company nor the name of the
* Massachusetts Institute of Technology nor the names of their
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS 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 COPYRIGHT
* HOLDERS OR 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.
*/
package org.dspace.app.xmlui.aspect.administrative.community;
import java.sql.SQLException;
import org.dspace.app.xmlui.aspect.administrative.FlowContainerUtils;
import org.dspace.app.xmlui.cocoon.AbstractDSpaceTransformer;
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.Item;
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.Text;
import org.dspace.app.xmlui.wing.element.TextArea;
import org.dspace.authorize.AuthorizeException;
import org.dspace.authorize.AuthorizeManager;
import org.dspace.content.Community;
/**
* Presents the user (in this case an administrator over the community) with the
* form to edit that community's metadata and logo.
* @author Alexey Maslov
*/
public class EditCommunityMetadataForm extends AbstractDSpaceTransformer
{
/** Language Strings */
private static final Message T_dspace_home = message("xmlui.general.dspace_home");
private static final Message T_title = message("xmlui.administrative.community.EditCommunityMetadataForm.title");
private static final Message T_trail = message("xmlui.administrative.community.EditCommunityMetadataForm.trail");
private static final Message T_main_head = message("xmlui.administrative.community.EditCommunityMetadataForm.main_head");
private static final Message T_edit_authorizations = message("xmlui.administrative.community.EditCommunityMetadataForm.edit_authorizations");
private static final Message T_label_name = message("xmlui.administrative.community.EditCommunityMetadataForm.label_name");
private static final Message T_label_short_description = message("xmlui.administrative.community.EditCommunityMetadataForm.label_short_description");
private static final Message T_label_introductory_text = message("xmlui.administrative.community.EditCommunityMetadataForm.label_introductory_text");
private static final Message T_label_copyright_text = message("xmlui.administrative.community.EditCommunityMetadataForm.label_copyright_text");
private static final Message T_label_side_bar_text = message("xmlui.administrative.community.EditCommunityMetadataForm.label_side_bar_text");
private static final Message T_label_logo = message("xmlui.administrative.community.EditCommunityMetadataForm.label_logo");
private static final Message T_label_existing_logo = message("xmlui.administrative.community.EditCommunityMetadataForm.label_existing_logo");
private static final Message T_submit_delete_logo = message("xmlui.administrative.community.EditCommunityMetadataForm.submit_delete_logo");
private static final Message T_submit_delete = message("xmlui.administrative.community.EditCommunityMetadataForm.submit_delete");
private static final Message T_submit_save = message("xmlui.administrative.community.EditCommunityMetadataForm.submit_save");
public void addPageMeta(PageMeta pageMeta) throws WingException
{
pageMeta.addMetadata("title").addContent(T_title);
pageMeta.addTrailLink(contextPath + "/", T_dspace_home);
pageMeta.addTrail().addContent(T_trail);
}
public void addBody(Body body) throws WingException, SQLException, AuthorizeException
{
int communityID = parameters.getParameterAsInteger("communityID", -1);
Community thisCommunity = Community.find(context, communityID);
String short_description_error = FlowContainerUtils.checkXMLFragment(thisCommunity.getMetadata("short_description"));
String introductory_text_error = FlowContainerUtils.checkXMLFragment(thisCommunity.getMetadata("introductory_text"));
String copyright_text_error = FlowContainerUtils.checkXMLFragment(thisCommunity.getMetadata("copyright_text"));
String side_bar_text_error = FlowContainerUtils.checkXMLFragment(thisCommunity.getMetadata("side_bar_text"));
// DIVISION: main
Division main = body.addInteractiveDivision("community-metadata-edit",contextPath+"/admin/community",Division.METHOD_MULTIPART,"primary administrative community");
main.setHead(T_main_head.parameterize(thisCommunity.getHandle()));
if (AuthorizeManager.isAdmin(context))
{
// Provide link to general authorizations if the user is a super admin.
main.addPara().addXref(contextPath + "/admin/community?administrative-continue=" + knot.getId() + "&submit_authorizations", T_edit_authorizations);
}
// The grand list of metadata options
List metadataList = main.addList("metadataList", "form");
// community name
metadataList.addLabel(T_label_name);
Text name = metadataList.addItem().addText("name");
name.setSize(40);
name.setValue(thisCommunity.getMetadata("name"));
// short description
metadataList.addLabel(T_label_short_description);
Text short_description = metadataList.addItem().addText("short_description");
short_description.setValue(thisCommunity.getMetadata("short_description"));
short_description.setSize(40);
if (short_description_error != null)
short_description.addError(short_description_error);
// introductory text
metadataList.addLabel(T_label_introductory_text);
TextArea introductory_text = metadataList.addItem().addTextArea("introductory_text");
introductory_text.setValue(thisCommunity.getMetadata("introductory_text"));
introductory_text.setSize(6, 40);
if (introductory_text_error != null)
introductory_text.addError(introductory_text_error);
// copyright text
metadataList.addLabel(T_label_copyright_text);
TextArea copyright_text = metadataList.addItem().addTextArea("copyright_text");
copyright_text.setValue(thisCommunity.getMetadata("copyright_text"));
copyright_text.setSize(6, 40);
if (copyright_text_error != null)
copyright_text.addError(copyright_text_error);
// legacy sidebar text; may or may not be used for news
metadataList.addLabel(T_label_side_bar_text);
TextArea side_bar_text = metadataList.addItem().addTextArea("side_bar_text");
side_bar_text.setValue(thisCommunity.getMetadata("side_bar_text"));
side_bar_text.setSize(6, 40);
if (side_bar_text_error != null)
side_bar_text.addError(side_bar_text_error);
// the row to upload a new logo
metadataList.addLabel(T_label_logo);
metadataList.addItem().addFile("logo");
// the row displaying an existing logo
Item item;
if (thisCommunity.getLogo() != null) {
metadataList.addLabel(T_label_existing_logo);
item = metadataList.addItem();
item.addFigure(contextPath + "/bitstream/id/" + thisCommunity.getLogo().getID() + "/bob.jpg", null, null);
item.addButton("submit_delete_logo").setValue(T_submit_delete_logo);
}
Para buttonList = main.addPara();
buttonList.addButton("submit_save").setValue(T_submit_save);
buttonList.addButton("submit_delete").setValue(T_submit_delete);
main.addHidden("administrative-continue").setValue(knot.getId());
}
}

View File

@@ -0,0 +1,225 @@
/*
* AddEPersonForm.java
*
* Version: $Revision: 1.0 $
*
* Date: $Date: 2006/07/13 23:20:54 $
*
* Copyright (c) 2002, Hewlett-Packard Company and Massachusetts
* Institute of Technology. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* - 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.
*
* - Neither the name of the Hewlett-Packard Company nor the name of the
* Massachusetts Institute of Technology nor the names of their
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS 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 COPYRIGHT
* HOLDERS OR 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.
*/
package org.dspace.app.xmlui.aspect.administrative.eperson;
import java.sql.SQLException;
import java.util.ArrayList;
import org.apache.cocoon.environment.ObjectModelHelper;
import org.apache.cocoon.environment.Request;
import org.dspace.app.xmlui.cocoon.AbstractDSpaceTransformer;
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.CheckBox;
import org.dspace.app.xmlui.wing.element.Division;
import org.dspace.app.xmlui.wing.element.Item;
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.Text;
import org.dspace.authorize.AuthorizeException;
/**
* Present the user with all the eperson metadata fields so that they
* can describe the new eperson before being created. If the user's
* input is incorrect in someway then they may be returning here with
* some fields in error. In particular there is a special case for the
* condition when the email-adress entered is allready in use by
* another user.
*
* @author Alexey Maslov
*/
public class AddEPersonForm extends AbstractDSpaceTransformer
{
/** Language Strings */
private static final Message T_dspace_home =
message("xmlui.general.dspace_home");
private static final Message T_eperson_trail =
message("xmlui.administrative.eperson.general.epeople_trail");
private static final Message T_title =
message("xmlui.administrative.eperson.AddEPersonForm.title");
private static final Message T_trail =
message("xmlui.administrative.eperson.AddEPersonForm.trail");
private static final Message T_head1 =
message("xmlui.administrative.eperson.AddEPersonForm.head1");
private static final Message T_email_taken =
message("xmlui.administrative.eperson.AddEPersonForm.email_taken");
private static final Message T_head2 =
message("xmlui.administrative.eperson.AddEPersonForm.head2");
private static final Message T_error_email_unique =
message("xmlui.administrative.eperson.AddEPersonForm.error_email_unique");
private static final Message T_error_email =
message("xmlui.administrative.eperson.AddEPersonForm.error_email");
private static final Message T_error_fname =
message("xmlui.administrative.eperson.AddEPersonForm.error_fname");
private static final Message T_error_lname =
message("xmlui.administrative.eperson.AddEPersonForm.error_lname");
private static final Message T_req_certs =
message("xmlui.administrative.eperson.AddEPersonForm.req_certs");
private static final Message T_can_log_in =
message("xmlui.administrative.eperson.AddEPersonForm.can_log_in");
private static final Message T_submit_create =
message("xmlui.administrative.eperson.AddEPersonForm.submit_create");
private static final Message T_submit_cancel =
message("xmlui.general.cancel");
/** Language string used from other aspects: */
private static final Message T_email_address =
message("xmlui.EPerson.EditProfile.email_address");
private static final Message T_first_name =
message("xmlui.EPerson.EditProfile.first_name");
private static final Message T_last_name =
message("xmlui.EPerson.EditProfile.last_name");
private static final Message T_telephone =
message("xmlui.EPerson.EditProfile.telephone");
public void addPageMeta(PageMeta pageMeta) throws WingException
{
pageMeta.addMetadata("title").addContent(T_title);
pageMeta.addTrailLink(contextPath + "/", T_dspace_home);
pageMeta.addTrailLink(contextPath + "/admin/epeople",T_eperson_trail);
pageMeta.addTrail().addContent(T_trail);
}
public void addBody(Body body) throws WingException, SQLException, AuthorizeException
{
// Get all our parameters
Request request = ObjectModelHelper.getRequest(objectModel);
String errorString = parameters.getParameter("errors",null);
ArrayList<String> errors = new ArrayList<String>();
if (errorString != null)
{
for (String error : errorString.split(","))
errors.add(error);
}
String emailValue = request.getParameter("email_address");
String firstValue = request.getParameter("first_name");
String lastValue = request.getParameter("last_name");
String phoneValue = request.getParameter("phone");
boolean canLogInValue = (request.getParameter("can_log_in") == null) ? false : true;
boolean certificateValue = (request.getParameter("certificate") == null) ? false : true;
// DIVISION: eperson-add
Division add = body.addInteractiveDivision("eperson-add",contextPath+"/admin/epeople",Division.METHOD_POST,"primary administrative eperson");
add.setHead(T_head1);
if (errors.contains("eperson_email_key")) {
Para problem = add.addPara();
problem.addHighlight("bold").addContent(T_email_taken);
}
List identity = add.addList("identity",List.TYPE_FORM);
identity.setHead(T_head2);
Text email = identity.addItem().addText("email_address");
email.setRequired();
email.setLabel(T_email_address);
email.setValue(emailValue);
if (errors.contains("eperson_email_key")) {
email.addError(T_error_email_unique);
}
else if (errors.contains("email_address")) {
email.addError(T_error_email);
}
Text firstName = identity.addItem().addText("first_name");
firstName.setRequired();
firstName.setLabel(T_first_name);
firstName.setValue(firstValue);
if (errors.contains("first_name")) {
firstName.addError(T_error_fname);
}
Text lastName = identity.addItem().addText("last_name");
lastName.setRequired();
lastName.setLabel(T_last_name);
lastName.setValue(lastValue);
if (errors.contains("last_name")) {
lastName.addError(T_error_lname);
}
Text phone = identity.addItem().addText("phone");
phone.setLabel(T_telephone);
phone.setValue(phoneValue);
CheckBox canLogIn = identity.addItem().addCheckBox("can_log_in");
canLogIn.setLabel(T_can_log_in);
canLogIn.addOption(canLogInValue, "yes");
CheckBox certificate = identity.addItem().addCheckBox("certificate");
certificate.setLabel(T_req_certs);
certificate.addOption(certificateValue,"yes");
Item buttons = identity.addItem();
buttons.addButton("submit_save").setValue(T_submit_create);
buttons.addButton("submit_cancel").setValue(T_submit_cancel);
add.addHidden("administrative-continue").setValue(knot.getId());
}
}

View File

@@ -0,0 +1,143 @@
/*
* DeleteEPeopleConfirm.java
*
* Version: $Revision: 1.0 $
*
* Date: $Date: 2006/07/13 23:20:54 $
*
* Copyright (c) 2002, Hewlett-Packard Company and Massachusetts
* Institute of Technology. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* - 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.
*
* - Neither the name of the Hewlett-Packard Company nor the name of the
* Massachusetts Institute of Technology nor the names of their
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS 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 COPYRIGHT
* HOLDERS OR 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.
*/
package org.dspace.app.xmlui.aspect.administrative.eperson;
import java.sql.SQLException;
import java.util.ArrayList;
import org.dspace.app.xmlui.cocoon.AbstractDSpaceTransformer;
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.PageMeta;
import org.dspace.app.xmlui.wing.element.Para;
import org.dspace.app.xmlui.wing.element.Row;
import org.dspace.app.xmlui.wing.element.Table;
import org.dspace.authorize.AuthorizeException;
import org.dspace.eperson.EPerson;
/**
* Present the user with a list of not-yet-but-soon-to-be-deleted-epeople.
*
* @author Alexey Maslov
*/
public class DeleteEPeopleConfirm extends AbstractDSpaceTransformer
{
/** Language Strings */
private static final Message T_dspace_home =
message("xmlui.general.dspace_home");
private static final Message T_eperson_trail =
message("xmlui.administrative.eperson.general.epeople_trail");
private static final Message T_title =
message("xmlui.administrative.eperson.DeleteEPeopleConfirm.title");
private static final Message T_trail =
message("xmlui.administrative.eperson.DeleteEPeopleConfirm.trail");
private static final Message T_confirm_head =
message("xmlui.administrative.eperson.DeleteEPeopleConfirm.confirm_head");
private static final Message T_confirm_para =
message("xmlui.administrative.eperson.DeleteEPeopleConfirm.confirm_para");
private static final Message T_head_id =
message("xmlui.administrative.eperson.DeleteEPeopleConfirm.head_id");
private static final Message T_head_name =
message("xmlui.administrative.eperson.DeleteEPeopleConfirm.head_name");
private static final Message T_head_email =
message("xmlui.administrative.eperson.DeleteEPeopleConfirm.head_email");
private static final Message T_submit_confirm =
message("xmlui.administrative.eperson.DeleteEPeopleConfirm.submit_confirm");
private static final Message T_submit_cancel =
message("xmlui.general.cancel");
public void addPageMeta(PageMeta pageMeta) throws WingException
{
pageMeta.addMetadata("title").addContent(T_title);
pageMeta.addTrailLink(contextPath + "/", T_dspace_home);
pageMeta.addTrailLink(contextPath + "/admin/epeople",T_eperson_trail);
pageMeta.addTrail().addContent(T_trail);
}
public void addBody(Body body) throws WingException, SQLException, AuthorizeException
{
// Get all our parameters
String idsString = parameters.getParameter("epeopleIDs", null);
ArrayList<EPerson> epeople = new ArrayList<EPerson>();
for (String id : idsString.split(","))
{
EPerson person = EPerson.find(context,Integer.valueOf(id));
epeople.add(person);
}
// DIVISION: epeople-confirm-delete
Division deleted = body.addInteractiveDivision("epeople-confirm-delete",contextPath+"/admin/epeople",Division.METHOD_POST,"primary administrative eperson");
deleted.setHead(T_confirm_head);
deleted.addPara(T_confirm_para);
Table table = deleted.addTable("epeople-confirm-delete",epeople.size() + 1, 1);
Row header = table.addRow(Row.ROLE_HEADER);
header.addCell().addContent(T_head_id);
header.addCell().addContent(T_head_name);
header.addCell().addContent(T_head_email);
for (EPerson eperson : epeople)
{
Row row = table.addRow();
row.addCell().addContent(eperson.getID());
row.addCell().addContent(eperson.getFullName());
row.addCell().addContent(eperson.getEmail());
}
Para buttons = deleted.addPara();
buttons.addButton("submit_confirm").setValue(T_submit_confirm);
buttons.addButton("submit_cancel").setValue(T_submit_cancel);
deleted.addHidden("administrative-continue").setValue(knot.getId());
}
}

View File

@@ -0,0 +1,371 @@
/*
* EditEPersonForm.java
*
* Version: $Revision: 1.0 $
*
* Date: $Date: 2006/07/13 23:20:54 $
*
* Copyright (c) 2002, Hewlett-Packard Company and Massachusetts
* Institute of Technology. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* - 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.
*
* - Neither the name of the Hewlett-Packard Company nor the name of the
* Massachusetts Institute of Technology nor the names of their
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS 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 COPYRIGHT
* HOLDERS OR 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.
*/
package org.dspace.app.xmlui.aspect.administrative.eperson;
import java.sql.SQLException;
import java.util.ArrayList;
import org.apache.cocoon.environment.ObjectModelHelper;
import org.apache.cocoon.environment.Request;
import org.dspace.app.xmlui.cocoon.AbstractDSpaceTransformer;
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.CheckBox;
import org.dspace.app.xmlui.wing.element.Division;
import org.dspace.app.xmlui.wing.element.Item;
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.Text;
import org.dspace.authorize.AuthorizeException;
import org.dspace.authorize.AuthorizeManager;
import org.dspace.eperson.EPerson;
import org.dspace.eperson.Group;
/**
* Edit an existing EPerson, display all the eperson's metadata
* along with two special options two reset the eperson's
* password and delete this user.
*
* @author Alexey Maslov
*/
public class EditEPersonForm extends AbstractDSpaceTransformer
{
/** Language Strings */
private static final Message T_dspace_home =
message("xmlui.general.dspace_home");
private static final Message T_submit_save =
message("xmlui.general.save");
private static final Message T_submit_cancel =
message("xmlui.general.cancel");
private static final Message T_title =
message("xmlui.administrative.eperson.EditEPersonForm.title");
private static final Message T_eperson_trail =
message("xmlui.administrative.eperson.general.epeople_trail");
private static final Message T_trail =
message("xmlui.administrative.eperson.EditEPersonForm.trail");
private static final Message T_head1 =
message("xmlui.administrative.eperson.EditEPersonForm.head1");
private static final Message T_email_taken =
message("xmlui.administrative.eperson.EditEPersonForm.email_taken");
private static final Message T_head2 =
message("xmlui.administrative.eperson.EditEPersonForm.head2");
private static final Message T_error_email_unique =
message("xmlui.administrative.eperson.EditEPersonForm.error_email_unique");
private static final Message T_error_email =
message("xmlui.administrative.eperson.EditEPersonForm.error_email");
private static final Message T_error_fname =
message("xmlui.administrative.eperson.EditEPersonForm.error_fname");
private static final Message T_error_lname =
message("xmlui.administrative.eperson.EditEPersonForm.error_lname");
private static final Message T_req_certs =
message("xmlui.administrative.eperson.EditEPersonForm.req_certs");
private static final Message T_can_log_in =
message("xmlui.administrative.eperson.EditEPersonForm.can_log_in");
private static final Message T_submit_reset_password =
message("xmlui.administrative.eperson.EditEPersonForm.submit_reset_password");
private static final Message T_special_help =
message("xmlui.administrative.eperson.EditEPersonForm.special_help");
private static final Message T_submit_delete =
message("xmlui.administrative.eperson.EditEPersonForm.submit_delete");
private static final Message T_member_head =
message("xmlui.administrative.eperson.EditEPersonForm.member_head");
private static final Message T_indirect_member =
message("xmlui.administrative.eperson.EditEPersonForm.indirect_member");
private static final Message T_member_none =
message("xmlui.administrative.eperson.EditEPersonForm.member_none");
/** Language string used: */
private static final Message T_email_address =
message("xmlui.EPerson.EditProfile.email_address");
private static final Message T_first_name =
message("xmlui.EPerson.EditProfile.first_name");
private static final Message T_last_name =
message("xmlui.EPerson.EditProfile.last_name");
private static final Message T_telephone =
message("xmlui.EPerson.EditProfile.telephone");
public void addPageMeta(PageMeta pageMeta) throws WingException
{
pageMeta.addMetadata("title").addContent(T_title);
pageMeta.addTrailLink(contextPath + "/", T_dspace_home);
pageMeta.addTrailLink(contextPath + "/admin/epeople",T_eperson_trail);
pageMeta.addTrail().addContent(T_trail);
}
public void addBody(Body body) throws WingException, SQLException, AuthorizeException
{
// Get all our parameters
boolean admin = AuthorizeManager.isAdmin(context);
Request request = ObjectModelHelper.getRequest(objectModel);
// Get our parameters;
int epersonID = parameters.getParameterAsInteger("epersonID",-1);
String errorString = parameters.getParameter("errors",null);
ArrayList<String> errors = new ArrayList<String>();
if (errorString != null)
{
for (String error : errorString.split(","))
errors.add(error);
}
// Grab the person in question
EPerson eperson = EPerson.find(context, epersonID);
if (eperson == null)
throw new UIException("Unable to find eperson for id:"+epersonID);
String emailValue = eperson.getEmail();
String firstValue = eperson.getFirstName();
String lastValue = eperson.getLastName();
String phoneValue = eperson.getMetadata("phone");
boolean canLogInValue = eperson.canLogIn();
boolean certificatValue = eperson.getRequireCertificate();
if (request.getParameter("email_address") != null)
emailValue = request.getParameter("email_address");
if (request.getParameter("first_name") != null)
firstValue = request.getParameter("first_name");
if (request.getParameter("last_name") != null)
lastValue = request.getParameter("last_name");
if (request.getParameter("phone") != null)
phoneValue = request.getParameter("phone");
// DIVISION: eperson-edit
Division edit = body.addInteractiveDivision("eperson-edit",contextPath+"/admin/epeople",Division.METHOD_POST,"primary administrative eperson");
edit.setHead(T_head1);
if (errors.contains("eperson_email_key")) {
Para problem = edit.addPara();
problem.addHighlight("bold").addContent(T_email_taken);
}
List identity = edit.addList("form",List.TYPE_FORM);
identity.setHead(T_head2.parameterize(eperson.getFullName()));
if (admin)
{
Text email = identity.addItem().addText("email_address");
email.setRequired();
email.setLabel(T_email_address);
email.setValue(emailValue);
if (errors.contains("eperson_email_key"))
email.addError(T_error_email_unique);
else if (errors.contains("email_address"))
email.addError(T_error_email);
}
else
{
identity.addLabel(T_email_address);
identity.addItem(emailValue);
}
if (admin)
{
Text firstName = identity.addItem().addText("first_name");
firstName.setRequired();
firstName.setLabel(T_first_name);
firstName.setValue(firstValue);
if (errors.contains("first_name"))
firstName.addError(T_error_fname);
}
else
{
identity.addLabel(T_first_name);
identity.addItem(firstValue);
}
if (admin)
{
Text lastName = identity.addItem().addText("last_name");
lastName.setRequired();
lastName.setLabel(T_last_name);
lastName.setValue(lastValue);
if (errors.contains("last_name"))
lastName.addError(T_error_lname);
}
else
{
identity.addLabel(T_last_name);
identity.addItem(lastValue);
}
if (admin)
{
Text phone = identity.addItem().addText("phone");
phone.setLabel(T_telephone);
phone.setValue(phoneValue);
}
else
{
identity.addLabel(T_telephone);
identity.addItem(phoneValue);
}
if (admin)
{
// Administrative options:
CheckBox canLogInField = identity.addItem().addCheckBox("can_log_in");
canLogInField.setLabel(T_can_log_in);
canLogInField.addOption(canLogInValue, "true");
CheckBox certificateField = identity.addItem().addCheckBox("certificate");
certificateField.setLabel(T_req_certs);
certificateField.addOption(certificatValue,"true");
identity.addItem().addHighlight("italic").addContent(T_special_help);
Item special = identity.addItem();
special.addButton("submit_reset_password").setValue(T_submit_reset_password);
special.addButton("submit_delete").setValue(T_submit_delete);
}
Item buttons = identity.addItem();
if (admin)
buttons.addButton("submit_save").setValue(T_submit_save);
buttons.addButton("submit_cancel").setValue(T_submit_cancel);
if (admin)
{
List member = edit.addList("eperson-member-of");
member.setHead(T_member_head);
Group[] groups = Group.allMemberGroups(context, eperson);
for (Group group : groups)
{
String url = contextPath + "/admin/groups?administrative-continue="+knot.getId()+"&submit_edit_group&groupID="+group.getID();
Item item = member.addItem();
item.addXref(url,group.getName());
// Check if this membership is via another group or not, if so then add a note.
Group via = findViaGroup(eperson, group);
if (via != null)
item.addHighlight("fade").addContent(T_indirect_member.parameterize(via.getName()));
}
if (groups.length <= 0)
member.addItem().addHighlight("italic").addContent(T_member_none);
}
edit.addHidden("administrative-continue").setValue(knot.getId());
}
/**
* Determine if the given eperson is a direct member of this group if
* they are not the return the group that membership is implied
* through (the via group!). This will only find one possible relation
* path, there may be multiple.
*
*
* @param eperson The source group to search from
* @param group The target group to search for.
* @return The group this member is related through or null if none found.
*/
private Group findViaGroup(EPerson eperson, Group group) throws SQLException
{
// First check if this eperson is a direct member of the group.
for (EPerson direct : group.getMembers())
{
if (direct.getID() == eperson.getID())
// Direct membership
return null;
}
// Otherwise check what group this eperson is a member through
Group[] targets = group.getMemberGroups();
Group[] groups = Group.allMemberGroups(context, eperson);
for (Group member : groups)
{
for (Group target : targets)
{
if (member.getID() == target.getID())
return member;
}
}
// This should never happen, but let's just say we couldn't find the relationship.
return null;
}
}

View File

@@ -0,0 +1,251 @@
/*
* ManageEPeopleMain.java
*
* Version: $Revision: 1.0 $
*
* Date: $Date: 2006/07/13 23:20:54 $
*
* Copyright (c) 2002, Hewlett-Packard Company and Massachusetts
* Institute of Technology. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* - 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.
*
* - Neither the name of the Hewlett-Packard Company nor the name of the
* Massachusetts Institute of Technology nor the names of their
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS 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 COPYRIGHT
* HOLDERS OR 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.
*/
package org.dspace.app.xmlui.aspect.administrative.eperson;
import java.sql.SQLException;
import org.dspace.app.xmlui.cocoon.AbstractDSpaceTransformer;
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.CheckBox;
import org.dspace.app.xmlui.wing.element.Division;
import org.dspace.app.xmlui.wing.element.List;
import org.dspace.app.xmlui.wing.element.PageMeta;
import org.dspace.app.xmlui.wing.element.Row;
import org.dspace.app.xmlui.wing.element.Table;
import org.dspace.app.xmlui.wing.element.Text;
import org.dspace.eperson.EPerson;
/**
* The manage epeople page is the starting point page for managing
* epeople. From here the user is able to browse or search for epeople,
* once identified the user can selected them for deletition by selecting
* the checkboxes and clicking delete or click their name to edit the
* eperson.
*
* @author Alexey Maslov
* @author Scott Phillips
*/
public class ManageEPeopleMain extends AbstractDSpaceTransformer
{
/** Language Strings */
private static final Message T_title =
message("xmlui.administrative.eperson.ManageEPeopleMain.title");
private static final Message T_eperson_trail =
message("xmlui.administrative.eperson.general.epeople_trail");
private static final Message T_main_head =
message("xmlui.administrative.eperson.ManageEPeopleMain.main_head");
private static final Message T_actions_head =
message("xmlui.administrative.eperson.ManageEPeopleMain.actions_head");
private static final Message T_actions_create =
message("xmlui.administrative.eperson.ManageEPeopleMain.actions_create");
private static final Message T_actions_create_link =
message("xmlui.administrative.eperson.ManageEPeopleMain.actions_create_link");
private static final Message T_actions_browse =
message("xmlui.administrative.eperson.ManageEPeopleMain.actions_browse");
private static final Message T_actions_browse_link =
message("xmlui.administrative.eperson.ManageEPeopleMain.actions_browse_link");
private static final Message T_actions_search =
message("xmlui.administrative.eperson.ManageEPeopleMain.actions_search");
private static final Message T_search_help =
message("xmlui.administrative.eperson.ManageEPeopleMain.search_help");
private static final Message T_dspace_home =
message("xmlui.general.dspace_home");
private static final Message T_go =
message("xmlui.general.go");
private static final Message T_search_head =
message("xmlui.administrative.eperson.ManageEPeopleMain.search_head");
private static final Message T_search_column1 =
message("xmlui.administrative.eperson.ManageEPeopleMain.search_column1");
private static final Message T_search_column2 =
message("xmlui.administrative.eperson.ManageEPeopleMain.search_column2");
private static final Message T_search_column3 =
message("xmlui.administrative.eperson.ManageEPeopleMain.search_column3");
private static final Message T_search_column4 =
message("xmlui.administrative.eperson.ManageEPeopleMain.search_column4");
private static final Message T_submit_delete =
message("xmlui.administrative.eperson.ManageEPeopleMain.submit_delete");
private static final Message T_no_results =
message("xmlui.administrative.eperson.ManageEPeopleMain.no_results");
/**
* The total number of entries to show on a page
*/
private static final int PAGE_SIZE = 15;
public void addPageMeta(PageMeta pageMeta) throws WingException
{
pageMeta.addMetadata("title").addContent(T_title);
pageMeta.addTrailLink(contextPath + "/", T_dspace_home);
pageMeta.addTrailLink(contextPath + "/admin/epeople",T_eperson_trail);
}
public void addBody(Body body) throws WingException, SQLException
{
/* Get and setup our parameters */
int page = parameters.getParameterAsInteger("page",0);
int highlightID = parameters.getParameterAsInteger("highlightID",-1);
String query = parameters.getParameter("query",null);
String baseURL = contextPath+"/admin/epeople?administrative-continue="+knot.getId();
int resultCount = EPerson.searchResultCount(context, query);
EPerson[] epeople = EPerson.search(context, query, page*PAGE_SIZE, PAGE_SIZE);
// DIVISION: eperson-main
Division main = body.addInteractiveDivision("epeople-main",contextPath+"/admin/epeople",Division.METHOD_POST,"primary administrative eperson");
main.setHead(T_main_head);
// DIVISION: eperson-actions
Division actions = main.addDivision("epeople-actions");
actions.setHead(T_actions_head);
List actionsList = actions.addList("actions");
actionsList.addLabel(T_actions_create);
actionsList.addItemXref(baseURL+"&submit_add", T_actions_create_link);
actionsList.addLabel(T_actions_browse);
actionsList.addItemXref(baseURL+"&query&submit_search",
T_actions_browse_link);
actionsList.addLabel(T_actions_search);
org.dspace.app.xmlui.wing.element.Item actionItem = actionsList.addItem();
Text queryField = actionItem.addText("query");
if (query != null)
queryField.setValue(query);
queryField.setHelp(T_search_help);
actionItem.addButton("submit_search").setValue(T_go);
// DIVISION: eperson-search
Division search = main.addDivision("eperson-search");
search.setHead(T_search_head);
// If there are more than 10 results the paginate the division.
if (resultCount > PAGE_SIZE)
{
// If there are enough results then paginate the results
int firstIndex = page*PAGE_SIZE+1;
int lastIndex = page*PAGE_SIZE + epeople.length;
String nextURL = null, prevURL = null;
if (page < (resultCount / PAGE_SIZE))
nextURL = baseURL+"&page="+(page+1);
if (page > 0)
prevURL = baseURL+"&page="+(page-1);
search.setSimplePagination(resultCount,firstIndex,lastIndex,prevURL, nextURL);
}
Table table = search.addTable("eperson-search-table", epeople.length + 1, 1);
Row header = table.addRow(Row.ROLE_HEADER);
header.addCell().addContent(T_search_column1);
header.addCell().addContent(T_search_column2);
header.addCell().addContent(T_search_column3);
header.addCell().addContent(T_search_column4);
CheckBox selectEPerson;
for (EPerson person : epeople)
{
String epersonID = String.valueOf(person.getID());
String fullName = person.getFullName();
String email = person.getEmail();
String url = baseURL+"&submit_edit&epersonID="+epersonID;
Row row;
if (person.getID() == highlightID)
// This is a highlighted eperson
row = table.addRow(null, null, "highlight");
else
row = table.addRow();
selectEPerson = row.addCell().addCheckBox("select_eperson");
selectEPerson.setLabel(epersonID);
selectEPerson.addOption(epersonID);
row.addCellContent(epersonID);
row.addCell().addXref(url, fullName);
row.addCell().addXref(url, email);
}
if (epeople.length <= 0)
{
Cell cell = table.addRow().addCell(1, 4);
cell.addHighlight("italic").addContent(T_no_results);
}
else
{
search.addPara().addButton("submit_delete").setValue(T_submit_delete);
}
main.addHidden("administrative-continue").setValue(knot.getId());
}
}

View File

@@ -0,0 +1,138 @@
/*
* DeleteGroupsConfirm.java
*
* Version: $Revision: 1.0 $
*
* Date: $Date: 2006/07/13 23:20:54 $
*
* Copyright (c) 2002, Hewlett-Packard Company and Massachusetts
* Institute of Technology. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* - 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.
*
* - Neither the name of the Hewlett-Packard Company nor the name of the
* Massachusetts Institute of Technology nor the names of their
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS 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 COPYRIGHT
* HOLDERS OR 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.
*/
package org.dspace.app.xmlui.aspect.administrative.group;
import java.sql.SQLException;
import java.util.ArrayList;
import org.dspace.app.xmlui.cocoon.AbstractDSpaceTransformer;
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.PageMeta;
import org.dspace.app.xmlui.wing.element.Para;
import org.dspace.app.xmlui.wing.element.Row;
import org.dspace.app.xmlui.wing.element.Table;
import org.dspace.authorize.AuthorizeException;
import org.dspace.eperson.Group;
/**
* Present the user with a list of soon-to-be-deleted Groups.
* If the user clicks confirm deletition then they will be
* deleted otherwise they will be spared the wrath of deletion.
* @author Scott Phillips
*/
public class DeleteGroupsConfirm extends AbstractDSpaceTransformer
{
/** Language Strings */
private static final Message T_dspace_home =
message("xmlui.general.dspace_home");
private static final Message T_group_trail =
message("xmlui.administrative.group.general.group_trail");
private static final Message T_title =
message("xmlui.administrative.group.DeleteGroupsConfirm.title");
private static final Message T_trail =
message("xmlui.administrative.group.DeleteGroupsConfirm.trail");
private static final Message T_head =
message("xmlui.administrative.group.DeleteGroupsConfirm.head");
private static final Message T_para =
message("xmlui.administrative.group.DeleteGroupsConfirm.para");
private static final Message T_column1 =
message("xmlui.administrative.group.DeleteGroupsConfirm.column1");
private static final Message T_column2 =
message("xmlui.administrative.group.DeleteGroupsConfirm.column2");
private static final Message T_column3 =
message("xmlui.administrative.group.DeleteGroupsConfirm.column3");
private static final Message T_column4 =
message("xmlui.administrative.group.DeleteGroupsConfirm.column4");
private static final Message T_submit_confirm =
message("xmlui.general.delete");
private static final Message T_submit_cancel =
message("xmlui.general.cancel");
public void addPageMeta(PageMeta pageMeta) throws WingException
{
pageMeta.addMetadata("title").addContent(T_title);
pageMeta.addTrailLink(contextPath + "/", T_dspace_home);
pageMeta.addTrailLink(contextPath + "/admin/groups",T_group_trail);
pageMeta.addTrail().addContent(T_trail);
}
public void addBody(Body body) throws WingException, SQLException, AuthorizeException
{
String idsString = parameters.getParameter("groupIDs", null);
ArrayList<Group> groups = new ArrayList<Group>();
for (String id : idsString.split(","))
{
Group group = Group.find(context,Integer.valueOf(id));
groups.add(group);
}
Division deleted = body.addInteractiveDivision("group-confirm-delete",
contextPath+"/admin/epeople",Division.METHOD_POST,"primary administrative groups");
deleted.setHead(T_head);
deleted.addPara(T_para);
Table table = deleted.addTable("groups-list",groups.size() + 1, 3);
Row header = table.addRow(Row.ROLE_HEADER);
header.addCell().addContent(T_column1);
header.addCell().addContent(T_column2);
header.addCell().addContent(T_column3);
header.addCell().addContent(T_column4);
for (Group group : groups)
{
Row row = table.addRow();
row.addCell().addContent(group.getID());
row.addCell().addContent(group.getName());
row.addCell().addContent(group.getMembers().length);
row.addCell().addContent(group.getMemberGroups().length);
}
Para buttons = deleted.addPara();
buttons.addButton("submit_confirm").setValue(T_submit_confirm);
buttons.addButton("submit_cancel").setValue(T_submit_cancel);
deleted.addHidden("administrative-continue").setValue(knot.getId());
}
}

View File

@@ -0,0 +1,722 @@
/*
* GroupEditForm.java
*
* Version: $Revision: 1.3 $
*
* Date: $Date: 2006/07/13 23:20:54 $
*
* Copyright (c) 2002, Hewlett-Packard Company and Massachusetts
* Institute of Technology. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* - 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.
*
* - Neither the name of the Hewlett-Packard Company nor the name of the
* Massachusetts Institute of Technology nor the names of their
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS 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 COPYRIGHT
* HOLDERS OR 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.
*/
package org.dspace.app.xmlui.aspect.administrative.group;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.LinkedList;
import java.util.Queue;
import org.dspace.app.xmlui.aspect.administrative.FlowGroupUtils;
import org.dspace.app.xmlui.cocoon.AbstractDSpaceTransformer;
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.Highlight;
import org.dspace.app.xmlui.wing.element.PageMeta;
import org.dspace.app.xmlui.wing.element.Para;
import org.dspace.app.xmlui.wing.element.Row;
import org.dspace.app.xmlui.wing.element.Table;
import org.dspace.app.xmlui.wing.element.Text;
import org.dspace.authorize.AuthorizeManager;
import org.dspace.content.Collection;
import org.dspace.eperson.EPerson;
import org.dspace.eperson.Group;
/**
* Present the user with the group's current state. The user may select to
* change the group's name, OR search for new epeople / groups to add, OR select
* current group members for removal.
*
* @author Alexey Maslov
* @author Scott Phillips
*/
public class EditGroupForm extends AbstractDSpaceTransformer
{
/** Language Strings */
private static final Message T_dspace_home =
message("xmlui.general.dspace_home");
private static final Message T_group_trail =
message("xmlui.administrative.group.general.group_trail");
private static final Message T_title =
message("xmlui.administrative.group.EditGroupForm.title");
private static final Message T_trail =
message("xmlui.administrative.group.EditGroupForm.trail");
private static final Message T_main_head =
message("xmlui.administrative.group.EditGroupForm.main_head");
private static final Message T_collection_para =
message("xmlui.administrative.group.EditGroupForm.collection_para");
private static final Message T_label_name =
message("xmlui.administrative.group.EditGroupForm.label_name");
private static final Message T_label_instructions =
message("xmlui.administrative.group.EditGroupForm.label_instructions");
private static final Message T_label_search =
message("xmlui.administrative.group.EditGroupForm.label_search");
private static final Message T_submit_search_people =
message("xmlui.administrative.group.EditGroupForm.submit_search_people");
private static final Message T_submit_search_groups =
message("xmlui.administrative.group.EditGroupForm.submit_search_groups");
private static final Message T_no_results =
message("xmlui.administrative.group.EditGroupForm.no_results");
private static final Message T_main_head_new =
message("xmlui.administrative.group.EditGroupForm.main_head_new");
private static final Message T_submit_clear =
message("xmlui.administrative.group.EditGroupForm.submit_clear");
private static final Message T_submit_save =
message("xmlui.general.save");
private static final Message T_submit_cancel =
message("xmlui.general.cancel");
private static final Message T_member =
message("xmlui.administrative.group.EditGroupForm.member");
private static final Message T_cycle =
message("xmlui.administrative.group.EditGroupForm.cycle");
private static final Message T_pending =
message("xmlui.administrative.group.EditGroupForm.pending");
private static final Message T_submit_add =
message("xmlui.administrative.group.EditGroupForm.submit_add");
private static final Message T_submit_remove =
message("xmlui.administrative.group.EditGroupForm.submit_remove");
// EPeople Search
private static final Message T_epeople_column1 =
message("xmlui.administrative.group.EditGroupForm.epeople_column1");
private static final Message T_epeople_column2 =
message("xmlui.administrative.group.EditGroupForm.epeople_column2");
private static final Message T_epeople_column3 =
message("xmlui.administrative.group.EditGroupForm.epeople_column3");
private static final Message T_epeople_column4 =
message("xmlui.administrative.group.EditGroupForm.epeople_column4");
// Group Search
private static final Message T_groups_column1 =
message("xmlui.administrative.group.EditGroupForm.groups_column1");
private static final Message T_groups_column2 =
message("xmlui.administrative.group.EditGroupForm.groups_column2");
private static final Message T_groups_column3 =
message("xmlui.administrative.group.EditGroupForm.groups_column3");
private static final Message T_groups_column4 =
message("xmlui.administrative.group.EditGroupForm.groups_column4");
private static final Message T_groups_column5 =
message("xmlui.administrative.group.EditGroupForm.groups_column5");
private static final Message T_groups_collection_link =
message("xmlui.administrative.group.ManageGroupsMain.groups_collection_link");
// Members
private static final Message T_members_head =
message("xmlui.administrative.group.EditGroupForm.members_head");
private static final Message T_members_column1 =
message("xmlui.administrative.group.EditGroupForm.members_column1");
private static final Message T_members_column2 =
message("xmlui.administrative.group.EditGroupForm.members_column2");
private static final Message T_members_column3 =
message("xmlui.administrative.group.EditGroupForm.members_column3");
private static final Message T_members_column4 =
message("xmlui.administrative.group.EditGroupForm.members_column4");
private static final Message T_members_group_name =
message("xmlui.administrative.group.EditGroupForm.members_group_name");
private static final Message T_members_pending =
message("xmlui.administrative.group.EditGroupForm.members_pending");
private static final Message T_members_none =
message("xmlui.administrative.group.EditGroupForm.members_none");
// How many results to show on a page.
private static final int RESULTS_PER_PAGE = 5;
/** The maximum size of a collection name allowed */
private static final int MAX_COLLECTION_NAME = 25;
public void addPageMeta(PageMeta pageMeta) throws WingException
{
pageMeta.addMetadata("title").addContent(T_title);
pageMeta.addTrailLink(contextPath + "/", T_dspace_home);
pageMeta.addTrailLink(contextPath + "/admin/groups",T_group_trail);
pageMeta.addTrail().addContent(T_trail);
}
public void addBody(Body body) throws WingException, SQLException
{
// Find the group in question
int groupID = parameters.getParameterAsInteger("groupID",-1);
String currentName = parameters.getParameter("groupName",null);
Group group = null;
if (groupID >= 0)
group = Group.find(context,groupID);
// Find the collection if applicable
Collection collection = null;
if (group != null)
{
int collectionID = FlowGroupUtils.getCollectionId(group.getName());
if(collectionID > -1)
collection = Collection.find(context, collectionID);
// If the collectionID was not found then reset the id back to -1. This
// happens when collections are deleted.
if (collection == null)
collectionID = -1;
}
// Get list of member groups
String memberGroupIDsString = parameters.getParameter("memberGroupIDs",null);
ArrayList<Integer> memberGroupIDs = new ArrayList<Integer>();
if (memberGroupIDsString != null)
{
for (String id : memberGroupIDsString.split(","))
{
if (id.length() > 0)
memberGroupIDs.add(Integer.valueOf(id));
}
}
// Get list of member epeople
String memberEPeopleIDsString = parameters.getParameter("memberEPeopleIDs",null);
ArrayList<Integer> memberEPeopleIDs = new ArrayList<Integer>();
if (memberEPeopleIDsString != null)
{
for (String id : memberEPeopleIDsString.split(","))
if (id.length() > 0)
memberEPeopleIDs.add(Integer.valueOf(id));
}
// Get highlight parameters
int highlightEPersonID = parameters.getParameterAsInteger("highlightEPersonID",-1);
int highlightGroupID = parameters.getParameterAsInteger("highlightGroupID",-1);
// Get search parameters
String query = parameters.getParameter("query",null);
int page = parameters.getParameterAsInteger("page",0);
String type = parameters.getParameter("type",null);
// Get any errors
String errorString = parameters.getParameter("errors",null);
ArrayList<String> errors = new ArrayList<String>();
if (errorString != null)
for (String error : errorString.split(","))
errors.add(error);
//DIVISION: group-edit
Division main = body.addInteractiveDivision("group-edit",contextPath+"/admin/groups",Division.METHOD_POST,"primary administrative groups");
if (group == null)
main.setHead(T_main_head_new);
else
main.setHead(T_main_head.parameterize(group.getName(),groupID));
if(collection != null)
{
Para para = main.addPara();
para.addContent(T_collection_para);
para.addXref(contextPath+"/handle/"+collection.getHandle(), collection.getMetadata("name"));
}
// DIVISION: group-actions
Division actions = main.addDivision("group-edit-actions");
Para groupName = actions.addPara();
groupName.addContent(T_label_name);
Text groupText = groupName.addText("group_name");
groupText.setValue(currentName);
if(collection != null)
{
// If this group is associated with a collection then it is special,
// thus they shouldn't be able to update it.
groupText.setDisabled();
groupText.setHelp(T_label_instructions);
}
else if (errors.contains("group_name") || errors.contains("group_name_duplicate"))
groupText.addError("");
Para searchBoxes = actions.addPara();
searchBoxes.addContent(T_label_search);
Text queryField = searchBoxes.addText("query");
queryField.setValue(query);
queryField.setSize(15);
searchBoxes.addButton("submit_search_epeople").setValue(T_submit_search_people);
searchBoxes.addButton("submit_search_groups").setValue(T_submit_search_groups);
if (query != null)
{
if ("eperson".equals(type))
{
searchBoxes.addButton("submit_clear").setValue(T_submit_clear);
addEPeopleSearch(main,query,page,group,memberEPeopleIDs);
}
else if ("group".equals(type))
{
searchBoxes.addButton("submit_clear").setValue(T_submit_clear);
addGroupSearch(main,group,query,page,group,memberGroupIDs);
}
}
boolean changes = false;
if (group != null)
changes = addMemberList(main,group,memberGroupIDs,memberEPeopleIDs,highlightEPersonID,highlightGroupID);
Para buttons = main.addPara();
buttons.addButton("submit_save").setValue(T_submit_save);
buttons.addButton("submit_cancel").setValue(T_submit_cancel);
if (changes)
main.addPara().addHighlight("warn").addContent("Note, pending changes are not saved until you click the save button.");
main.addHidden("administrative-continue").setValue(knot.getId());
}
/**
* Search for epeople to add to this group.
*/
private void addEPeopleSearch(Division div, String query, int page, Group group, ArrayList<Integer> memberEPeopleIDs) throws SQLException, WingException
{
int resultCount = EPerson.searchResultCount(context, query);
EPerson[] epeople = EPerson.search(context, query, page*RESULTS_PER_PAGE, RESULTS_PER_PAGE);
Division results = div.addDivision("results");
if (resultCount > RESULTS_PER_PAGE)
{
// If there are enough results then paginate the results
String baseURL = contextPath +"/admin/groups?administrative-continue="+knot.getId();
int firstIndex = page*RESULTS_PER_PAGE+1;
int lastIndex = page*RESULTS_PER_PAGE + epeople.length;
String nextURL = null, prevURL = null;
if (page < (resultCount / RESULTS_PER_PAGE))
nextURL = baseURL+"&page="+(page+1);
if (page > 0)
prevURL = baseURL+"&page="+(page-1);
results.setSimplePagination(resultCount,firstIndex,lastIndex,prevURL, nextURL);
}
/* Set up a table with search results (if there are any). */
Table table = results.addTable("group-edit-search-eperson",epeople.length + 1, 1);
Row header = table.addRow(Row.ROLE_HEADER);
header.addCell().addContent(T_epeople_column1);
header.addCell().addContent(T_epeople_column2);
header.addCell().addContent(T_epeople_column3);
header.addCell().addContent(T_epeople_column4);
for (EPerson person : epeople)
{
String epersonID = String.valueOf(person.getID());
String fullName = person.getFullName();
String email = person.getEmail();
String url = contextPath+"/admin/epeople?administrative-continue="+knot.getId()+"&submit_edit_eperson&epersonID="+epersonID;
Row personData = table.addRow();
personData.addCell().addContent(person.getID());
personData.addCell().addXref(url, fullName);
personData.addCell().addXref(url, email);
// check if they are allready a member of the group
if (memberEPeopleIDs.contains(person.getID()))
{
// Check if they really members or just pending members
if (group != null && group.isMember(person))
personData.addCellContent(T_member);
else
personData.addCell().addHighlight("warn").addContent(T_pending);
}
else
{
personData.addCell().addButton("submit_add_eperson_"+epersonID).setValue(T_submit_add);
}
}
if (epeople.length <= 0) {
table.addRow().addCell(1, 4).addContent(T_no_results);
}
}
/**
* Search for groups to add to this group.
*/
private void addGroupSearch(Division div, Group sourceGroup, String query, int page, Group parent, ArrayList<Integer> memberGroupIDs) throws WingException, SQLException
{
int resultCount = Group.searchResultCount(context, query);
Group[] groups = Group.search(context, query, page*RESULTS_PER_PAGE, RESULTS_PER_PAGE);
Division results = div.addDivision("results");
if (resultCount > RESULTS_PER_PAGE)
{
// If there are enough results then paginate the results
String baseURL = contextPath +"/admin/groups?administrative-continue="+knot.getId();
int firstIndex = page*RESULTS_PER_PAGE+1;
int lastIndex = page*RESULTS_PER_PAGE + groups.length;
String nextURL = null, prevURL = null;
if (page < (resultCount / RESULTS_PER_PAGE))
nextURL = baseURL+"&page="+(page+1);
if (page > 0)
prevURL = baseURL+"&page="+(page-1);
results.setSimplePagination(resultCount,firstIndex,lastIndex,prevURL, nextURL);
}
Table table = results.addTable("roup-edit-search-group",groups.length + 1, 1);
Row header = table.addRow(Row.ROLE_HEADER);
header.addCell().addContent(T_groups_column1);
header.addCell().addContent(T_groups_column2);
header.addCell().addContent(T_groups_column3);
header.addCell().addContent(T_groups_column4);
header.addCell().addContent(T_groups_column5);
for (Group group : groups)
{
String groupID = String.valueOf(group.getID());
String name = group.getName();
String url = contextPath+"/admin/groups?administrative-continue="+knot.getId()+"&submit_edit_group&groupID="+groupID;
int memberCount = group.getMembers().length + group.getMemberGroups().length;
Row row = table.addRow();
row.addCell().addContent(groupID);
if (AuthorizeManager.isAdmin(context))
// Only administrators can edit other groups.
row.addCell().addXref(url,name);
else
row.addCell().addContent(name);
row.addCell().addContent(memberCount == 0 ? "-" : String.valueOf(memberCount));
Cell cell = row.addCell();
if (FlowGroupUtils.getCollectionId(group.getName()) > -1)
{
Collection collection = Collection.find(context, FlowGroupUtils.getCollectionId(group.getName()) );
if (collection != null)
{
String collectionName = collection.getMetadata("name");
if (collectionName == null)
collectionName = "";
else if (collectionName.length() > MAX_COLLECTION_NAME)
collectionName = collectionName.substring(0,MAX_COLLECTION_NAME-3) + "...";
cell.addContent(collectionName+" ");
Highlight highlight = cell.addHighlight("fade");
highlight.addContent("[");
highlight.addXref(contextPath+"/handle/"+collection.getHandle(), T_groups_collection_link);
highlight.addContent("]");
}
}
// Check if the group is allready a member or would create a cycle.
if (memberGroupIDs.contains(group.getID()))
{
// Check if they really members or just pending members
if (parent != null && parent.isMember(group))
row.addCellContent(T_member);
else
row.addCell().addHighlight("warn").addContent(T_pending);
}
else if (isDescendant(sourceGroup, group, memberGroupIDs))
{
row.addCellContent(T_cycle);
}
else
{
row.addCell().addButton("submit_add_group_"+groupID).setValue(T_submit_add);
}
}
if (groups.length <= 0) {
table.addRow().addCell(1, 4).addContent(T_no_results);
}
}
/**
* Method to extensively check whether the first group has the second group as a distant
* parent. This is used to avoid creating cycles like A->B, B->C, C->D, D->A which leads
* all the groups involved to essentially include themselves.
*/
private boolean isDescendant(Group descendant, Group ancestor, ArrayList<Integer> memberGroupIDs) throws SQLException
{
Queue<Group> toVisit = new LinkedList<Group>();
Group currentGroup;
toVisit.offer(ancestor);
// Initialize by adding a list of our current list of group members.
for (Integer groupid : memberGroupIDs)
{
Group member = Group.find(context,groupid);
toVisit.offer(member);
}
while (!toVisit.isEmpty()) {
// 1. Grab a group from the queue
currentGroup = toVisit.poll();
// 2. See if it's the descendant we're looking for
if (currentGroup.equals(descendant)) return true;
// 3. If not, add that group's children to the queue
for (Group nextBatch : currentGroup.getMemberGroups()) {
toVisit.offer(nextBatch);
}
}
return false;
}
/**
* Add a table with all the current group's members to the specified division.
* @throws SQLException
*/
private boolean addMemberList(Division div, Group parent, ArrayList<Integer> memberGroupIDs, ArrayList<Integer> memberEPeopleIDs, int highlightEPersonID, int highlightGroupID) throws WingException, SQLException
{
// Flag to remember if there are any pending changes.
boolean changes = false;
Division members = div.addDivision("group-edit-members");
members.setHead(T_members_head);
Table table = members.addTable("group-edit-members-table",memberGroupIDs.size() + memberEPeopleIDs.size() + 1, 4);
Row header = table.addRow(Row.ROLE_HEADER);
header.addCell().addContent(T_members_column1);
header.addCell().addContent(T_members_column2);
header.addCell().addContent(T_members_column3);
header.addCell().addContent(T_members_column4);
// get all group members, pend or actual
@SuppressWarnings("unchecked") // the cast is correct
ArrayList<Integer> allMemberGroupIDs = (ArrayList<Integer>) memberGroupIDs.clone();
for (Group group : parent.getMemberGroups())
{
if (!allMemberGroupIDs.contains(group.getID()))
allMemberGroupIDs.add(group.getID());
}
// Sort them to a consistent ordering
Collections.sort(allMemberGroupIDs);
// Loop through all group ids and display them.
for (Integer groupID : allMemberGroupIDs)
{
Group group = Group.find(context,groupID);
boolean highlight = (group.getID() == highlightGroupID);
boolean pendingAddition = !parent.isMember(group);
boolean pendingRemoval = !memberGroupIDs.contains(groupID);
addMemberRow(table, group, highlight,pendingAddition,pendingRemoval);
if (pendingAddition || pendingRemoval)
changes = true;
}
// get all members, pend or actual
@SuppressWarnings("unchecked") // the cast is correct
ArrayList<Integer> allMemberEPeopleIDs = (ArrayList<Integer>) memberEPeopleIDs.clone();
for (EPerson eperson : parent.getMembers())
{
if (!allMemberEPeopleIDs.contains(eperson.getID()))
allMemberEPeopleIDs.add(eperson.getID());
}
// Sort them to a consistent ordering
Collections.sort(allMemberEPeopleIDs);
for (Integer epersonID : allMemberEPeopleIDs)
{
EPerson eperson = EPerson.find(context, epersonID);
boolean highlight = (eperson.getID() == highlightEPersonID);
boolean pendingAddition = !parent.isMember(eperson);
boolean pendingRemoval = !memberEPeopleIDs.contains(epersonID);
addMemberRow(table,eperson,highlight,pendingAddition,pendingRemoval);
if (pendingAddition || pendingRemoval)
changes = true;
}
if (allMemberGroupIDs.size() <= 0 && allMemberEPeopleIDs.size() <= 0)
{
table.addRow().addCell(1, 4).addContent(T_members_none);
}
return changes;
}
/**
* Add a singe member row for groups.
*
* @param table The table to add the row too.
* @param group The group being displayed in this row.
* @param highlight Should the row be highlighted.
* @param pendingAddition Is this group pending additition
* @param pendingRemoval Is this group pending removal
*/
private void addMemberRow(Table table,Group group, boolean highlight, boolean pendingAddition, boolean pendingRemoval) throws WingException, SQLException
{
String name = group.getName();
String url = contextPath+"/admin/groups?administrative-continue="+knot.getId()+"&submit_edit_group&groupID="+group.getID();
Row groupData = table.addRow(null,null,highlight ? "highlight" : null);
groupData.addCell().addHighlight("bold").addContent(group.getID());
// Mark if this member is pending or not.
Cell nameCell = groupData.addCell();
if (AuthorizeManager.isAdmin(context))
nameCell.addHighlight("bold").addXref(url,T_members_group_name.parameterize(name));
else
nameCell.addHighlight("bold").addContent(T_members_group_name.parameterize(name));
if (pendingAddition)
{
nameCell.addContent(" ");
nameCell.addHighlight("warn").addContent(T_members_pending);
}
groupData.addCell().addContent("-");
if (pendingRemoval)
groupData.addCell().addHighlight("warn").addContent(T_pending);
else
groupData.addCell().addButton("submit_remove_group_"+group.getID()).setValue(T_submit_remove);
}
/**
* Add a single member row for epeople.
*
* @param table The table to add a row too.
* @param eperson The eperson being displayed
* @param highlight Should this eperson be highlighted?
* @param pendingAddition Is this eperson pending addition?
* @param pendingRemoval Is this eperson pending removal?
*/
private void addMemberRow(Table table, EPerson eperson, boolean highlight, boolean pendingAddition, boolean pendingRemoval) throws WingException, SQLException
{
String fullName = eperson.getFullName();
String email = eperson.getEmail();
String url = contextPath+"/admin/epeople?administrative-continue="+knot.getId()+"&submit_edit_eperson&epersonID="+eperson.getID();
Row personData = table.addRow(null,null,highlight ? "highlight" : null);
personData.addCell().addContent(eperson.getID());
Cell nameCell = personData.addCell();
nameCell.addXref(url, fullName);
if (pendingAddition)
{
nameCell.addContent(" ");
nameCell.addHighlight("warn").addContent(T_members_pending);
}
personData.addCell().addXref(url, email);
if (pendingRemoval)
personData.addCell().addHighlight("warn").addContent(T_pending);
else
personData.addCell().addButton("submit_remove_eperson_"+eperson.getID()).setValue(T_submit_remove);
}
}

View File

@@ -0,0 +1,285 @@
/*
* ManageGroupsMain.java
*
* Version: $Revision: 1.0 $
*
* Date: $Date: 2006/07/13 23:20:54 $
*
* Copyright (c) 2002, Hewlett-Packard Company and Massachusetts
* Institute of Technology. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* - 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.
*
* - Neither the name of the Hewlett-Packard Company nor the name of the
* Massachusetts Institute of Technology nor the names of their
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS 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 COPYRIGHT
* HOLDERS OR 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.
*/
package org.dspace.app.xmlui.aspect.administrative.group;
import java.sql.SQLException;
import org.dspace.app.xmlui.aspect.administrative.FlowGroupUtils;
import org.dspace.app.xmlui.cocoon.AbstractDSpaceTransformer;
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.CheckBox;
import org.dspace.app.xmlui.wing.element.Division;
import org.dspace.app.xmlui.wing.element.Highlight;
import org.dspace.app.xmlui.wing.element.List;
import org.dspace.app.xmlui.wing.element.PageMeta;
import org.dspace.app.xmlui.wing.element.Row;
import org.dspace.app.xmlui.wing.element.Table;
import org.dspace.app.xmlui.wing.element.Text;
import org.dspace.content.Collection;
import org.dspace.eperson.Group;
/**
* Manage groups page is the entry point for group management. From here the user
* may browse/search a the list of groups, they may also add new groups or select
* exiting groups to edit or delete.
*
* @author Alexey Maslov
* @author Scott Phillips
*/
public class ManageGroupsMain extends AbstractDSpaceTransformer
{
/** Language Strings */
private static final Message T_dspace_home =
message("xmlui.general.dspace_home");
private static final Message T_group_trail =
message("xmlui.administrative.group.general.group_trail");
private static final Message T_title =
message("xmlui.administrative.group.ManageGroupsMain.title");
private static final Message T_main_head =
message("xmlui.administrative.group.ManageGroupsMain.main_head");
private static final Message T_actions_head =
message("xmlui.administrative.group.ManageGroupsMain.actions_head");
private static final Message T_actions_create=
message("xmlui.administrative.group.ManageGroupsMain.actions_create");
private static final Message T_actions_create_link =
message("xmlui.administrative.group.ManageGroupsMain.actions_create_link");
private static final Message T_actions_browse =
message("xmlui.administrative.group.ManageGroupsMain.actions_browse");
private static final Message T_actions_browse_link =
message("xmlui.administrative.group.ManageGroupsMain.actions_browse_link");
private static final Message T_actions_search =
message("xmlui.administrative.group.ManageGroupsMain.actions_search");
private static final Message T_search_help =
message("xmlui.administrative.group.ManageGroupsMain.search_help");
private static final Message T_go =
message("xmlui.general.go");
private static final Message T_search_head =
message("xmlui.administrative.group.ManageGroupsMain.search_head");
private static final Message T_search_column1 =
message("xmlui.administrative.group.ManageGroupsMain.search_column1");
private static final Message T_search_column2 =
message("xmlui.administrative.group.ManageGroupsMain.search_column2");
private static final Message T_search_column3 =
message("xmlui.administrative.group.ManageGroupsMain.search_column3");
private static final Message T_search_column4 =
message("xmlui.administrative.group.ManageGroupsMain.search_column4");
private static final Message T_search_column5 =
message("xmlui.administrative.group.ManageGroupsMain.search_column5");
private static final Message T_collection_link =
message("xmlui.administrative.group.ManageGroupsMain.collection_link");
private static final Message T_submit_delete =
message("xmlui.administrative.group.ManageGroupsMain.submit_delete");
private static final Message T_no_results =
message("xmlui.administrative.group.ManageGroupsMain.no_results");
/** The number of results to show on one page. */
private static final int PAGE_SIZE = 15;
/** The maximum size of a collection name allowed */
private static final int MAX_COLLECTION_NAME = 30;
public void addPageMeta(PageMeta pageMeta) throws WingException
{
pageMeta.addMetadata("title").addContent(T_title);
pageMeta.addTrailLink(contextPath + "/", T_dspace_home);
pageMeta.addTrailLink(contextPath + "/admin/groups",T_group_trail);
}
public void addBody(Body body) throws WingException, SQLException
{
// Get all our parameters
String baseURL = contextPath +"/admin/groups?administrative-continue="+knot.getId();
String query = parameters.getParameter("query","");
int page = parameters.getParameterAsInteger("page",0);
int highlightID = parameters.getParameterAsInteger("highlightID",-1);
int resultCount = Group.searchResultCount(context, query);
Group[] groups = Group.search(context, query, page*PAGE_SIZE, PAGE_SIZE);
// DIVISION: groups-main
Division main = body.addInteractiveDivision("groups-main",contextPath +"/admin/groups",Division.METHOD_POST,"primary administrative groups");
main.setHead(T_main_head);
// DIVISION: group-actions
Division actions = main.addDivision("group-actions");
actions.setHead(T_actions_head);
// Browse Epeople
List actionsList = actions.addList("actions");
actionsList.addLabel(T_actions_create);
actionsList.addItemXref(baseURL+"&submit_add", T_actions_create_link);
actionsList.addLabel(T_actions_browse);
actionsList.addItemXref(baseURL+"&query&submit_search",T_actions_browse_link);
actionsList.addLabel(T_actions_search);
org.dspace.app.xmlui.wing.element.Item actionItem = actionsList.addItem();
Text queryField = actionItem.addText("query");
if (query != null)
queryField.setValue(query);
queryField.setHelp(T_search_help);
actionItem.addButton("submit_search").setValue(T_go);
// DIVISION: group-search
Division search = main.addDivision("group-search");
search.setHead(T_search_head);
if (resultCount > PAGE_SIZE)
{
// If there are enough results then paginate the results
int firstIndex = page*PAGE_SIZE+1;
int lastIndex = page*PAGE_SIZE + groups.length;
String nextURL = null, prevURL = null;
if (page < (resultCount / PAGE_SIZE))
nextURL = baseURL+"&page="+(page+1);
if (page > 0)
prevURL = baseURL+"&page="+(page-1);
search.setSimplePagination(resultCount,firstIndex,lastIndex,prevURL, nextURL);
}
Table table = search.addTable("groups-search-table",groups.length + 1, 1);
Row header = table.addRow(Row.ROLE_HEADER);
header.addCell().addContent(T_search_column1);
header.addCell().addContent(T_search_column2);
header.addCell().addContent(T_search_column3);
header.addCell().addContent(T_search_column4);
header.addCell().addContent(T_search_column5);
for (Group group : groups)
{
Row row;
if (group.getID() == highlightID)
row = table.addRow(null,null,"highlight");
else
row = table.addRow();
if (group.getID() > 1)
{
CheckBox select = row.addCell().addCheckBox("select_group");
select.setLabel(new Integer(group.getID()).toString());
select.addOption(new Integer(group.getID()).toString());
}
else
{
// Don't allow the user to remove the administrative (id:1) or
// anonymous group (id:0)
row.addCell();
}
row.addCell().addContent(group.getID());
row.addCell().addXref(baseURL+"&submit_edit&groupID="+group.getID(), group.getName());
int memberCount = group.getMembers().length + group.getMemberGroups().length;
row.addCell().addContent(memberCount == 0 ? "-" : String.valueOf(memberCount));
Cell cell = row.addCell();
if (FlowGroupUtils.getCollectionId(group.getName()) > -1)
{
Collection collection = Collection.find(context, FlowGroupUtils.getCollectionId(group.getName()) );
if (collection != null)
{
String collectionName = collection.getMetadata("name");
if (collectionName == null)
collectionName = "";
else if (collectionName.length() > MAX_COLLECTION_NAME)
collectionName = collectionName.substring(0,MAX_COLLECTION_NAME-3) + "...";
cell.addContent(collectionName+" ");
Highlight highlight = cell.addHighlight("fade");
highlight.addContent("[");
highlight.addXref(contextPath+"/handle/"+collection.getHandle(), T_collection_link);
highlight.addContent("]");
}
}
}
if (groups.length <= 0)
{
Cell cell = table.addRow().addCell(1,5);
cell.addHighlight("italic").addContent(T_no_results);
}
else
{
search.addPara().addButton("submit_delete").setValue(T_submit_delete);
}
search.addHidden("administrative-continue").setValue(knot.getId());
}
}

View File

@@ -0,0 +1,199 @@
/*
* AddBitstreamForm.java
*
* Version: $Revision: 1.4 $
*
* Date: $Date: 2006/07/13 23:20:54 $
*
* Copyright (c) 2002, Hewlett-Packard Company and Massachusetts
* Institute of Technology. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* - 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.
*
* - Neither the name of the Hewlett-Packard Company nor the name of the
* Massachusetts Institute of Technology nor the names of their
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS 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 COPYRIGHT
* HOLDERS OR 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.
*/
package org.dspace.app.xmlui.aspect.administrative.item;
import java.io.IOException;
import java.sql.SQLException;
import org.dspace.app.xmlui.aspect.submission.AbstractStep;
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.Button;
import org.dspace.app.xmlui.wing.element.Division;
import org.dspace.app.xmlui.wing.element.File;
import org.dspace.app.xmlui.wing.element.Item;
import org.dspace.app.xmlui.wing.element.List;
import org.dspace.app.xmlui.wing.element.PageMeta;
import org.dspace.app.xmlui.wing.element.Select;
import org.dspace.app.xmlui.wing.element.Text;
import org.dspace.authorize.AuthorizeException;
import org.dspace.authorize.AuthorizeManager;
import org.dspace.content.Bundle;
import org.dspace.core.Constants;
import org.xml.sax.SAXException;
/**
*
* Show a form that allows the user to upload a new bitstream. The
* user can select the new bitstream's bundle (which is unchangable
* after upload) and a description for the file.
*
* @author Scott Phillips
*/
public class AddBitstreamForm extends AbstractStep
{
/** Language strings */
private static final Message T_dspace_home = message("xmlui.general.dspace_home");
private static final Message T_submit_cancel = message("xmlui.general.cancel");
private static final Message T_item_trail = message("xmlui.administrative.item.general.item_trail");
private static final Message T_title = message("xmlui.administrative.item.AddBitstreamForm.title.");
private static final Message T_trail = message("xmlui.administrative.item.AddBitstreamForm.trail");
private static final Message T_head1 = message("xmlui.administrative.item.AddBitstreamForm.head1");
private static final Message T_bundle_label = message("xmlui.administrative.item.AddBitstreamForm.bundle_label");
private static final Message T_bundle_original = message("xmlui.administrative.item.AddBitstreamForm.bundle_original");
private static final Message T_bundle_metadata = message("xmlui.administrative.item.AddBitstreamForm.bundle_metadata");
private static final Message T_bundle_thumbnail = message("xmlui.administrative.item.AddBitstreamForm.bundle_thumbnail");
private static final Message T_bundle_license = message("xmlui.administrative.item.AddBitstreamForm.bundle_license");
private static final Message T_bundle_cc_license = message("xmlui.administrative.item.AddBitstreamForm.bundle_cc_license");
private static final Message T_file_label = message("xmlui.administrative.item.AddBitstreamForm.file_label");
private static final Message T_file_help = message("xmlui.administrative.item.AddBitstreamForm.file_help");
private static final Message T_description_label = message("xmlui.administrative.item.AddBitstreamForm.description_label");
private static final Message T_description_help = message("xmlui.administrative.item.AddBitstreamForm.description_help");
private static final Message T_submit_upload = message("xmlui.administrative.item.AddBitstreamForm.submit_upload");
private static final Message T_no_bundles = message("xmlui.administrative.item.AddBitstreamForm.no_bundles");
public void addPageMeta(PageMeta pageMeta) throws WingException
{
pageMeta.addMetadata("title").addContent(T_title);
pageMeta.addTrailLink(contextPath + "/", T_dspace_home);
pageMeta.addTrailLink(contextPath + "/admin/item",T_item_trail);
pageMeta.addTrail().addContent(T_trail);
}
public void addBody(Body body) throws SAXException, WingException,
UIException, SQLException, IOException, AuthorizeException
{
int itemID = parameters.getParameterAsInteger("itemID",-1);
org.dspace.content.Item item = org.dspace.content.Item.find(context,itemID);
// DIVISION: main div
Division div = body.addInteractiveDivision("add-bitstream", contextPath+"/admin/item", Division.METHOD_MULTIPART, "primary administrative item");
// LIST: upload form
List upload = div.addList("submit-upload-new", List.TYPE_FORM);
upload.setHead(T_head1);
int bundleCount = 0; // record how many bundles we are able to upload too.
Select select = upload.addItem().addSelect("bundle");
select.setLabel(T_bundle_label);
if (addBundleOption(item,select,"ORIGINAL", T_bundle_original))
bundleCount++;
if (addBundleOption(item,select,"METADATA", T_bundle_metadata))
bundleCount++;
if (addBundleOption(item,select,"THUMBNAIL", T_bundle_thumbnail))
bundleCount++;
if (addBundleOption(item,select,"LICENSE", T_bundle_license))
bundleCount++;
if (addBundleOption(item,select,"CC_LICENSE", T_bundle_cc_license))
bundleCount++;
select.setOptionSelected("ORIGINAL");
if (bundleCount == 0)
select.setDisabled();
File file = upload.addItem().addFile("file");
file.setLabel(T_file_label);
file.setHelp(T_file_help);
file.setRequired();
if (bundleCount == 0)
file.setDisabled();
Text description = upload.addItem().addText("description");
description.setLabel(T_description_label);
description.setHelp(T_description_help);
if (bundleCount == 0)
description.setDisabled();
if (bundleCount == 0)
upload.addItem().addContent(T_no_bundles);
// ITEM: actions
Item actions = upload.addItem();
Button button = actions.addButton("submit_upload");
button.setValue(T_submit_upload);
if (bundleCount == 0)
button.setDisabled();
actions.addButton("submit_cancel").setValue(T_submit_cancel);
div.addHidden("administrative-continue").setValue(knot.getId());
}
public boolean addBundleOption(org.dspace.content.Item item, Select select, String bundleName, Message bundleLabel) throws SQLException, WingException
{
// For some crazzy reason multiple bundles can share the same name
Bundle[] bundles = item.getBundles(bundleName);
if (bundles == null || bundles.length == 0)
{
// If the bundle does not exist then you have to be supper admin to be able
// to upload to this bundle because at upload time the bundle will be created but
// there is no way anyone but super admin could have access to add to the bundle.
if ( ! AuthorizeManager.isAdmin(context))
return false; // you can't upload to this bundle.
}
else
{
// At least one bundle exists, does the user have privleges to upload to it?
Bundle bundle = bundles[0];
if ( ! AuthorizeManager.authorizeActionBoolean(context, bundle, Constants.ADD))
return false; // you can't upload to this bundle.
// You also need the write privlege on the bundle.
if ( ! AuthorizeManager.authorizeActionBoolean(context, bundle, Constants.WRITE))
return false; // you can't upload.
}
// It's okay to upload.
select.addOption(bundleName, bundleLabel);
return true;
}
}

View File

@@ -0,0 +1,184 @@
/*
* ConfirmItemForm.java
*
* Version: $Revision: 1.3 $
*
* Date: $Date: 2006/07/13 23:20:54 $
*
* Copyright (c) 2002, Hewlett-Packard Company and Massachusetts
* Institute of Technology. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* - 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.
*
* - Neither the name of the Hewlett-Packard Company nor the name of the
* Massachusetts Institute of Technology nor the names of their
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS 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 COPYRIGHT
* HOLDERS OR 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.
*/
package org.dspace.app.xmlui.aspect.administrative.item;
import java.sql.SQLException;
import java.util.Arrays;
import java.util.Comparator;
import org.dspace.app.xmlui.cocoon.AbstractDSpaceTransformer;
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.Button;
import org.dspace.app.xmlui.wing.element.Division;
import org.dspace.app.xmlui.wing.element.List;
import org.dspace.app.xmlui.wing.element.PageMeta;
import org.dspace.app.xmlui.wing.element.Row;
import org.dspace.app.xmlui.wing.element.Table;
import org.dspace.content.DCValue;
import org.dspace.content.Item;
/**
* This page is used as a general confirmation page for any
* actions on items. It will display the item and ask if the
* user is sure they want to preform the action.
*
* The "confirm" parameter determines what action is confirmed.
* There are three possible values, "delete", "withdraw", or
* "reinstate"
*
* @author Jay Paz
* @author Scott Phillips
*/
public class ConfirmItemForm extends AbstractDSpaceTransformer {
/** Language strings */
private static final Message T_dspace_home = message("xmlui.general.dspace_home");
private static final Message T_item_trail = message("xmlui.administrative.item.general.item_trail");
private static final Message T_submit_cancel = message("xmlui.general.cancel");
private static final Message T_title = message("xmlui.administrative.item.ConfirmItemForm.title");
private static final Message T_trail = message("xmlui.administrative.item.ConfirmItemForm.trail");
private static final Message T_head1 = message("xmlui.administrative.item.ConfirmItemForm.head1");
private static final Message T_para_delete = message("xmlui.administrative.item.ConfirmItemForm.para_delete");
private static final Message T_para_withdraw = message("xmlui.administrative.item.ConfirmItemForm.para_withdraw");
private static final Message T_para_reinstate = message("xmlui.administrative.item.ConfirmItemForm.para_reinstate");
private static final Message T_column1 = message("xmlui.administrative.item.ConfirmItemForm.column1");
private static final Message T_column2 = message("xmlui.administrative.item.ConfirmItemForm.column2");
private static final Message T_column3 = message("xmlui.administrative.item.ConfirmItemForm.column3");
private static final Message T_submit_delete = message("xmlui.administrative.item.ConfirmItemForm.submit_delete");
private static final Message T_submit_withdraw = message("xmlui.administrative.item.ConfirmItemForm.submit_withdraw");
private static final Message T_submit_reinstate = message("xmlui.administrative.item.ConfirmItemForm.submit_reinstate");
public void addPageMeta(PageMeta pageMeta) throws WingException
{
pageMeta.addMetadata("title").addContent(T_title);
pageMeta.addTrailLink(contextPath + "/", T_dspace_home);
pageMeta.addTrailLink(contextPath+"/admin/item", T_item_trail);
pageMeta.addTrail().addContent(T_trail);
}
@SuppressWarnings("unchecked") // the cast is correct
public void addBody(Body body) throws WingException, SQLException
{
// Get our parameters and state
int itemID = parameters.getParameterAsInteger("itemID",-1);
Item item = Item.find(context, itemID);
final DCValue[] values = item.getMetadata(Item.ANY, Item.ANY, Item.ANY, Item.ANY);
Arrays.sort(values, new DCValueComparator());
String confirm = parameters.getParameter("confirm",null);
// DIVISION: Main
Division main = body.addInteractiveDivision("confirm-item", contextPath+"/admin/item", Division.METHOD_POST,"primary administrative item");
main.setHead(T_head1.parameterize(item.getHandle()));
// PARA: descriptive instructions
if("delete".equals(confirm))
{
main.addPara(T_para_delete);
}
else if ("reinstate".equals(confirm))
{
main.addPara(T_para_reinstate);
}
else if ("withdraw".equals(confirm))
{
main.addPara(T_para_withdraw);
}
// TABLE: metadata table
Table table = main.addTable("withdrawValues", values.length+1, 3);
final Row header = table.addRow(Row.ROLE_HEADER);
header.addCell().addContent(T_column1);
header.addCell().addContent(T_column2);
header.addCell().addContent(T_column3);
for(final DCValue value:values){
final String dcValue = value.schema + ". " + value.element + (value.qualifier==null?"":(". " + value.qualifier));
final Row row = table.addRow();
row.addCell().addContent(dcValue);
row.addCell().addContent(value.value);
row.addCell().addContent(value.language);
}
// LIST: actions, confirm or return
org.dspace.app.xmlui.wing.element.Item actions = main.addList("actions", List.TYPE_FORM).addItem();
Button confirmButton = actions.addButton("submit_confirm");
if("delete".equals(confirm))
{
confirmButton.setValue(T_submit_delete);
}
else if ("reinstate".equals(confirm))
{
confirmButton.setValue(T_submit_reinstate);
}
else if ("withdraw".equals(confirm))
{
confirmButton.setValue(T_submit_withdraw);
}
actions.addButton("submit_cancel").setValue(T_submit_cancel);
main.addHidden("administrative-continue").setValue(knot.getId());
}
/**
* Compare two metadata element's name so that they may be sorted.
*/
class DCValueComparator implements Comparator{
public int compare(Object arg0, Object arg1) {
final DCValue o1 = (DCValue)arg0;
final DCValue o2 = (DCValue)arg1;
final String s1 = o1.schema + o1.element + (o1.qualifier==null?"":("." + o1.qualifier));
final String s2 = o2.schema + o2.element + (o2.qualifier==null?"":("." + o2.qualifier));
return s1.compareTo(s2);
}
}
}

View File

@@ -0,0 +1,141 @@
/*
* DeleteBitstreamsConfirm.java
*
* Version: $Revision: 1.0 $
*
* Date: $Date: 2006/07/13 23:20:54 $
*
* Copyright (c) 2002, Hewlett-Packard Company and Massachusetts
* Institute of Technology. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* - 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.
*
* - Neither the name of the Hewlett-Packard Company nor the name of the
* Massachusetts Institute of Technology nor the names of their
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS 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 COPYRIGHT
* HOLDERS OR 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.
*/
package org.dspace.app.xmlui.aspect.administrative.item;
import java.sql.SQLException;
import java.util.ArrayList;
import org.dspace.app.xmlui.cocoon.AbstractDSpaceTransformer;
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.PageMeta;
import org.dspace.app.xmlui.wing.element.Para;
import org.dspace.app.xmlui.wing.element.Row;
import org.dspace.app.xmlui.wing.element.Table;
import org.dspace.authorize.AuthorizeException;
import org.dspace.content.Bitstream;
import org.dspace.content.BitstreamFormat;
/**
* Present the user with a list of not-yet-but-soon-to-be-deleted-bitstreams.
*
* @author Scott Phillips
*/
public class DeleteBitstreamsConfirm extends AbstractDSpaceTransformer
{
/** Language strings */
private static final Message T_dspace_home = message("xmlui.general.dspace_home");
private static final Message T_item_trail = message("xmlui.administrative.item.general.item_trail");
private static final Message T_title = message("xmlui.administrative.item.DeleteBitstreamConfirm.title");
private static final Message T_trail = message("xmlui.administrative.item.DeleteBitstreamConfirm.trail");
private static final Message T_head1 = message("xmlui.administrative.item.DeleteBitstreamConfirm.head1");
private static final Message T_para1 = message("xmlui.administrative.item.DeleteBitstreamConfirm.para1");
private static final Message T_column1 = message("xmlui.administrative.item.DeleteBitstreamConfirm.column1");
private static final Message T_column2 = message("xmlui.administrative.item.DeleteBitstreamConfirm.column2");
private static final Message T_column3 = message("xmlui.administrative.item.DeleteBitstreamConfirm.column3");
private static final Message T_submit_delete = message("xmlui.general.delete");
private static final Message T_submit_cancel = message("xmlui.general.cancel");
public void addPageMeta(PageMeta pageMeta) throws WingException
{
pageMeta.addMetadata("title").addContent(T_title);
pageMeta.addTrailLink(contextPath + "/", T_dspace_home);
pageMeta.addTrailLink(contextPath + "/admin/item",T_item_trail);
pageMeta.addTrail().addContent(T_trail);
}
public void addBody(Body body) throws WingException, SQLException, AuthorizeException
{
// Get all our parameters
String idsString = parameters.getParameter("bitstreamIDs", null);
ArrayList<Bitstream> bitstreams = new ArrayList<Bitstream>();
for (String id : idsString.split(","))
{
String[] parts = id.split("/");
if (parts.length != 2)
throw new UIException("Unable to parse id into bundle and bitstream id: "+id);
int bitstreamID = Integer.valueOf(parts[1]);
Bitstream bitstream = Bitstream.find(context,bitstreamID);
bitstreams.add(bitstream);
}
// DIVISION: bitstream-confirm-delete
Division deleted = body.addInteractiveDivision("bitstreams-confirm-delete",contextPath+"/admin/item",Division.METHOD_POST,"primary administrative item");
deleted.setHead(T_head1);
deleted.addPara(T_para1);
Table table = deleted.addTable("bitstreams-confirm-delete",bitstreams.size() + 1, 1);
Row header = table.addRow(Row.ROLE_HEADER);
header.addCellContent(T_column1);
header.addCellContent(T_column2);
header.addCellContent(T_column3);
for (Bitstream bitstream : bitstreams)
{
String format = null;
BitstreamFormat bitstreamFormat = bitstream.getFormat();
if (bitstreamFormat != null)
format = bitstreamFormat.getShortDescription();
Row row = table.addRow();
row.addCell().addContent(bitstream.getName());
row.addCell().addContent(bitstream.getDescription());
row.addCell().addContent(format);
}
Para buttons = deleted.addPara();
buttons.addButton("submit_confirm").setValue(T_submit_delete);
buttons.addButton("submit_cancel").setValue(T_submit_cancel);
deleted.addHidden("administrative-continue").setValue(knot.getId());
}
}

View File

@@ -0,0 +1,200 @@
/*
* EditBitstreamForm.java
*
* Version: $Revision: 1.4 $
*
* Date: $Date: 2006/07/13 23:20:54 $
*
* Copyright (c) 2002, Hewlett-Packard Company and Massachusetts
* Institute of Technology. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* - 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.
*
* - Neither the name of the Hewlett-Packard Company nor the name of the
* Massachusetts Institute of Technology nor the names of their
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS 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 COPYRIGHT
* HOLDERS OR 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.
*/
package org.dspace.app.xmlui.aspect.administrative.item;
import java.io.IOException;
import java.sql.SQLException;
import org.dspace.app.xmlui.cocoon.AbstractDSpaceTransformer;
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.List;
import org.dspace.app.xmlui.wing.element.PageMeta;
import org.dspace.app.xmlui.wing.element.Select;
import org.dspace.app.xmlui.wing.element.Text;
import org.dspace.authorize.AuthorizeException;
import org.dspace.content.Bitstream;
import org.dspace.content.BitstreamFormat;
import org.dspace.content.Bundle;
import org.xml.sax.SAXException;
/**
*
* Show a form allowing the user to edit a bitstream's metadata, the description & format.
*
* @author Scott Phillips
*/
public class EditBitstreamForm extends AbstractDSpaceTransformer
{
/** Language strings */
private static final Message T_dspace_home = message("xmlui.general.dspace_home");
private static final Message T_submit_save = message("xmlui.general.save");
private static final Message T_submit_cancel = message("xmlui.general.cancel");
private static final Message T_item_trail = message("xmlui.administrative.item.general.item_trail");
private static final Message T_title = message("xmlui.administrative.item.EditBitstreamForm.title");
private static final Message T_trail = message("xmlui.administrative.item.EditBitstreamForm.trail");
private static final Message T_head1 = message("xmlui.administrative.item.EditBitstreamForm.head1");
private static final Message T_file_label = message("xmlui.administrative.item.EditBitstreamForm.file_label");
private static final Message T_primary_label = message("xmlui.administrative.item.EditBitstreamForm.primary_label");
private static final Message T_primary_option_yes = message("xmlui.administrative.item.EditBitstreamForm.primary_option_yes");
private static final Message T_primary_option_no = message("xmlui.administrative.item.EditBitstreamForm.primary_option_no");
private static final Message T_description_label = message("xmlui.administrative.item.EditBitstreamForm.description_label");
private static final Message T_description_help = message("xmlui.administrative.item.EditBitstreamForm.description_help");
private static final Message T_para1 = message("xmlui.administrative.item.EditBitstreamForm.para1");
private static final Message T_format_label = message("xmlui.administrative.item.EditBitstreamForm.format_label");
private static final Message T_format_default = message("xmlui.administrative.item.EditBitstreamForm.format_default");
private static final Message T_para2 = message("xmlui.administrative.item.EditBitstreamForm.para2");
private static final Message T_user_label = message("xmlui.administrative.item.EditBitstreamForm.user_label");
private static final Message T_user_help = message("xmlui.administrative.item.EditBitstreamForm.user_help");
public void addPageMeta(PageMeta pageMeta) throws WingException
{
pageMeta.addMetadata("title").addContent(T_title);
pageMeta.addTrailLink(contextPath + "/", T_dspace_home);
pageMeta.addTrailLink(contextPath + "/admin/item",T_item_trail);
pageMeta.addTrail().addContent(T_trail);
}
public void addBody(Body body) throws SAXException, WingException,
UIException, SQLException, IOException, AuthorizeException
{
// Get our parameters
int bitstreamID = parameters.getParameterAsInteger("bitstreamID",-1);
// Get the bitstream and all the various formats
Bitstream bitstream = Bitstream.find(context, bitstreamID);
BitstreamFormat currentFormat = bitstream.getFormat();
BitstreamFormat[] bitstreamFormats = BitstreamFormat.findNonInternal(context);
boolean primaryBitstream = false;
Bundle[] bundles = bitstream.getBundles();
if (bundles != null && bundles.length > 0)
{
if (bitstreamID == bundles[0].getPrimaryBitstreamID())
{
primaryBitstream = true;
}
}
// File name & url
String fileUrl = contextPath + "/bitstream/id/" +bitstream.getID() + "/" + bitstream.getName();
String fileName = bitstream.getName();
// DIVISION: main
Division div = body.addInteractiveDivision("edit-bitstream", contextPath+"/admin/item", Division.METHOD_MULTIPART, "primary administrative item");
div.setHead(T_head1);
// LIST: edit form
List edit = div.addList("edit-bitstream-list", List.TYPE_FORM);
edit.addLabel(T_file_label);
edit.addItem().addXref(fileUrl, fileName);
Select primarySelect = edit.addItem().addSelect("primary");
primarySelect.setLabel(T_primary_label);
primarySelect.addOption(primaryBitstream,"yes",T_primary_option_yes);
primarySelect.addOption(!primaryBitstream,"no",T_primary_option_no);
Text description = edit.addItem().addText("description");
description.setLabel(T_description_label);
description.setHelp(T_description_help);
description.setValue(bitstream.getDescription());
edit.addItem(T_para1);
// System supported formats
Select format = edit.addItem().addSelect("formatID");
format.setLabel(T_format_label);
format.addOption(-1,T_format_default);
for (BitstreamFormat bitstreamFormat : bitstreamFormats)
{
String supportLevel = "Unknown";
if (bitstreamFormat.getSupportLevel() == BitstreamFormat.KNOWN)
supportLevel = "known";
else if (bitstreamFormat.getSupportLevel() == BitstreamFormat.SUPPORTED)
supportLevel = "Supported";
String name = bitstreamFormat.getShortDescription()+" ("+supportLevel+")";
int id = bitstreamFormat.getID();
format.addOption(id,name);
}
if (currentFormat != null)
{
format.setOptionSelected(currentFormat.getID());
}
else
{
format.setOptionSelected(-1);
}
edit.addItem(T_para2);
// User supplied format
Text userFormat = edit.addItem().addText("user_format");
userFormat.setLabel(T_user_label);
userFormat.setHelp(T_user_help);
userFormat.setValue(bitstream.getUserFormatDescription());
// ITEM: form actions
org.dspace.app.xmlui.wing.element.Item actions = edit.addItem();
actions.addButton("submit_save").setValue(T_submit_save);
actions.addButton("submit_cancel").setValue(T_submit_cancel);
div.addHidden("administrative-continue").setValue(knot.getId());
}
}

View File

@@ -0,0 +1,252 @@
/*
* EditItemBitstreamForm.java
*
* Version: $Revision: 1.3 $
*
* Date: $Date: 2006/07/13 23:20:54 $
*
* Copyright (c) 2002, Hewlett-Packard Company and Massachusetts
* Institute of Technology. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* - 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.
*
* - Neither the name of the Hewlett-Packard Company nor the name of the
* Massachusetts Institute of Technology nor the names of their
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS 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 COPYRIGHT
* HOLDERS OR 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.
*/
package org.dspace.app.xmlui.aspect.administrative.item;
import java.sql.SQLException;
import org.dspace.app.xmlui.cocoon.AbstractDSpaceTransformer;
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.Button;
import org.dspace.app.xmlui.wing.element.Cell;
import org.dspace.app.xmlui.wing.element.CheckBox;
import org.dspace.app.xmlui.wing.element.Division;
import org.dspace.app.xmlui.wing.element.Highlight;
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.Row;
import org.dspace.app.xmlui.wing.element.Table;
import org.dspace.authorize.AuthorizeManager;
import org.dspace.content.Bitstream;
import org.dspace.content.BitstreamFormat;
import org.dspace.content.Bundle;
import org.dspace.content.Item;
import org.dspace.core.Constants;
/**
* Show a list of the item's bitstreams allowing the user to delete them,
* edit them, or upload new bitstreams.
*
* @author Jay Paz
* @author Scott phillips
*/
public class EditItemBitstreamsForm extends AbstractDSpaceTransformer {
/** Language strings */
private static final Message T_dspace_home = message("xmlui.general.dspace_home");
private static final Message T_submit_return = message("xmlui.general.return");
private static final Message T_item_trail = message("xmlui.administrative.item.general.item_trail");
private static final Message T_option_head = message("xmlui.administrative.item.general.option_head");
private static final Message T_option_status = message("xmlui.administrative.item.general.option_status");
private static final Message T_option_bitstreams = message("xmlui.administrative.item.general.option_bitstreams");
private static final Message T_option_metadata = message("xmlui.administrative.item.general.option_metadata");
private static final Message T_option_view = message("xmlui.administrative.item.general.option_view");
private static final Message T_title = message("xmlui.administrative.item.EditItemBitstreamsForm.title");
private static final Message T_trail = message("xmlui.administrative.item.EditItemBitstreamsForm.trail");
private static final Message T_head1 = message("xmlui.administrative.item.EditItemBitstreamsForm.head1");
private static final Message T_column1 = message("xmlui.administrative.item.EditItemBitstreamsForm.column1");
private static final Message T_column2 = message("xmlui.administrative.item.EditItemBitstreamsForm.column2");
private static final Message T_column3 = message("xmlui.administrative.item.EditItemBitstreamsForm.column3");
private static final Message T_column4 = message("xmlui.administrative.item.EditItemBitstreamsForm.column4");
private static final Message T_column5 = message("xmlui.administrative.item.EditItemBitstreamsForm.column5");
private static final Message T_bundle_label = message("xmlui.administrative.item.EditItemBitstreamsForm.bundle_label");
private static final Message T_primary_label = message("xmlui.administrative.item.EditItemBitstreamsForm.primary_label");
private static final Message T_view_link = message("xmlui.administrative.item.EditItemBitstreamsForm.view_link");
private static final Message T_submit_add = message("xmlui.administrative.item.EditItemBitstreamsForm.submit_add");
private static final Message T_submit_delete = message("xmlui.administrative.item.EditItemBitstreamsForm.submit_delete");
private static final Message T_no_upload = message("xmlui.administrative.item.EditItemBitstreamsForm.no_upload");
private static final Message T_no_remove = message("xmlui.administrative.item.EditItemBitstreamsForm.no_remove");
public void addPageMeta(PageMeta pageMeta) throws WingException
{
pageMeta.addMetadata("title").addContent(T_title);
pageMeta.addTrailLink(contextPath + "/", T_dspace_home);
pageMeta.addTrailLink(contextPath + "/admin/item", T_item_trail);
pageMeta.addTrail().addContent(T_trail);
}
public void addBody(Body body) throws SQLException, WingException
{
// Get our parameters and state
int itemID = parameters.getParameterAsInteger("itemID",-1);
Item item = Item.find(context, itemID);
String baseURL = contextPath+"/admin/item?administrative-continue="+knot.getId();
// DIVISION: main div
Division main = body.addInteractiveDivision("edit-item-status", contextPath+"/admin/item", Division.METHOD_POST,"primary administrative item");
main.setHead(T_option_head);
// LIST: options
List options = main.addList("options",List.TYPE_SIMPLE,"horizontal");
options.addItem().addXref(baseURL+"&submit_status",T_option_status);
options.addItem().addHighlight("bold").addXref(baseURL+"&submit_bitstreams",T_option_bitstreams);
options.addItem().addXref(baseURL+"&submit_metadata",T_option_metadata);
options.addItem().addXref(baseURL + "&view_item", T_option_view);
// TABLE: Bitstream summary
Table files = main.addTable("editItemBitstreams", 1, 1);
files.setHead(T_head1);
Row header = files.addRow(Row.ROLE_HEADER);
header.addCellContent(T_column1);
header.addCellContent(T_column2);
header.addCellContent(T_column3);
header.addCellContent(T_column4);
header.addCellContent(T_column5);
Bundle[] bundles = item.getBundles();
for (Bundle bundle : bundles)
{
Cell bundleCell = files.addRow().addCell(1, 5);
bundleCell.addContent(T_bundle_label.parameterize(bundle.getName()));
Bitstream[] bitstreams = bundle.getBitstreams();
for (Bitstream bitstream : bitstreams)
{
boolean primary = (bundle.getPrimaryBitstreamID() == bitstream.getID());
String name = bitstream.getName();
if (name != null && name.length() > 50)
{
// If the fiel name is too long the shorten it so that it will display nicely.
String shortName = name.substring(0,15);
shortName += " ... ";
shortName += name.substring(name.length()-25,name.length());
name = shortName;
}
String description = bitstream.getDescription();
String format = null;
BitstreamFormat bitstreamFormat = bitstream.getFormat();
if (bitstreamFormat != null)
format = bitstreamFormat.getShortDescription();
String editURL = contextPath + "/admin/item?administrative-continue="+knot.getId()+"&bitstreamID="+bitstream.getID()+"&submit_edit";
String viewURL = contextPath + "/bitstream/id/"+bitstream.getID()+"/"+bitstream.getName();
Row row = files.addRow();
CheckBox remove = row.addCell().addCheckBox("remove");
remove.setLabel("remove");
remove.addOption(bundle.getID() + "/" +bitstream.getID() );
if (!AuthorizeManager.authorizeActionBoolean(context, item, Constants.REMOVE))
{
remove.setDisabled();
}
if (AuthorizeManager.authorizeActionBoolean(context, bitstream, Constants.WRITE))
{
// The user can edit the bitstream give them a link.
Cell cell = row.addCell();
cell.addXref(editURL,name);
if (primary)
cell.addXref(editURL,T_primary_label);
row.addCell().addXref(editURL,description);
row.addCell().addXref(editURL,format);
}
else
{
// The user can't edit the bitstream just show them it.
Cell cell = row.addCell();
cell.addContent(name);
if (primary)
cell.addContent(T_primary_label);
row.addCell().addContent(description);
row.addCell().addContent(format);
}
Highlight highlight = row.addCell().addHighlight("fade");
highlight.addContent("[");
highlight.addXref(viewURL,T_view_link);
highlight.addContent("]");
}
}
if (AuthorizeManager.authorizeActionBoolean(context, item, Constants.ADD))
{
Cell cell = files.addRow().addCell(1, 5);
cell.addXref(contextPath+"/admin/item?administrative-continue="+knot.getId()+"&submit_add",T_submit_add);
}
else
{
Cell cell = files.addRow().addCell(1, 5);
cell.addHighlight("fade").addContent(T_no_upload);
}
// PARA: actions
Para actions = main.addPara("editItemActionsP","editItemActionsP" );
if (AuthorizeManager.authorizeActionBoolean(context, item, Constants.REMOVE))
actions.addButton("submit_delete").setValue(T_submit_delete);
else
{
Button button = actions.addButton("submit_delete");
button.setValue(T_submit_delete);
button.setDisabled();
main.addPara().addHighlight("fade").addContent(T_no_remove);
}
actions.addButton("submit_return").setValue(T_submit_return);
main.addHidden("administrative-continue").setValue(knot.getId());
}
}

View File

@@ -0,0 +1,264 @@
/*
* EditItemMetadataForm.java
*
* Version: $Revision: 1.3 $
*
* Date: $Date: 2006/07/13 23:20:54 $
*
* Copyright (c) 2002, Hewlett-Packard Company and Massachusetts
* Institute of Technology. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* - 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.
*
* - Neither the name of the Hewlett-Packard Company nor the name of the
* Massachusetts Institute of Technology nor the names of their
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS 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 COPYRIGHT
* HOLDERS OR 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.
*/
package org.dspace.app.xmlui.aspect.administrative.item;
import java.sql.SQLException;
import java.util.Arrays;
import java.util.Comparator;
import org.apache.cocoon.environment.ObjectModelHelper;
import org.apache.cocoon.environment.Request;
import org.dspace.app.xmlui.cocoon.AbstractDSpaceTransformer;
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.CheckBox;
import org.dspace.app.xmlui.wing.element.Composite;
import org.dspace.app.xmlui.wing.element.Division;
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.Row;
import org.dspace.app.xmlui.wing.element.Select;
import org.dspace.app.xmlui.wing.element.Table;
import org.dspace.app.xmlui.wing.element.Text;
import org.dspace.app.xmlui.wing.element.TextArea;
import org.dspace.content.DCValue;
import org.dspace.content.Item;
import org.dspace.content.MetadataField;
import org.dspace.content.MetadataSchema;
/**
* Display a list of all metadata available for this item and allow the user to
* add, remove, or update it.
*
* @author Jay Paz
* @author Scott Phillips
*/
public class EditItemMetadataForm extends AbstractDSpaceTransformer {
/** Language strings */
private static final Message T_dspace_home = message("xmlui.general.dspace_home");
private static final Message T_submit_update = message("xmlui.general.update");
private static final Message T_submit_return = message("xmlui.general.return");
private static final Message T_item_trail = message("xmlui.administrative.item.general.item_trail");
private static final Message T_option_head = message("xmlui.administrative.item.general.option_head");
private static final Message T_option_status = message("xmlui.administrative.item.general.option_status");
private static final Message T_option_bitstreams = message("xmlui.administrative.item.general.option_bitstreams");
private static final Message T_option_metadata = message("xmlui.administrative.item.general.option_metadata");
private static final Message T_option_view = message("xmlui.administrative.item.general.option_view");
private static final Message T_title = message("xmlui.administrative.item.EditItemMetadataForm.title");
private static final Message T_trail = message("xmlui.administrative.item.EditItemMetadataForm.trail");
private static final Message T_head1 = message("xmlui.administrative.item.EditItemMetadataForm.head1");
private static final Message T_name_label = message("xmlui.administrative.item.EditItemMetadataForm.name_label");
private static final Message T_value_label = message("xmlui.administrative.item.EditItemMetadataForm.value_label");
private static final Message T_lang_label = message("xmlui.administrative.item.EditItemMetadataForm.lang_label");
private static final Message T_submit_add = message("xmlui.administrative.item.EditItemMetadataForm.submit_add");
private static final Message T_para1 = message("xmlui.administrative.item.EditItemMetadataForm.para1");
private static final Message T_head2 = message("xmlui.administrative.item.EditItemMetadataForm.head2");
private static final Message T_column1 = message("xmlui.administrative.item.EditItemMetadataForm.column1");
private static final Message T_column2 = message("xmlui.administrative.item.EditItemMetadataForm.column2");
private static final Message T_column3 = message("xmlui.administrative.item.EditItemMetadataForm.column3");
private static final Message T_column4 = message("xmlui.administrative.item.EditItemMetadataForm.column4");
public void addPageMeta(PageMeta pageMeta) throws WingException
{
pageMeta.addMetadata("title").addContent(T_title);
pageMeta.addTrailLink(contextPath + "/", T_dspace_home);
pageMeta.addTrailLink(contextPath + "/admin/item", T_item_trail);
pageMeta.addTrail().addContent(T_trail);
}
/**
* Add either the simple Ajax response document or the full
* document with header and full edit item form based on the
* mode parameter. Mode parameter values are set in the Flowscipt
* and can be either 'ajax' or 'normal'.
*/
@SuppressWarnings("unchecked") // the cast is correct
public void addBody(Body body) throws SQLException, WingException
{
// Get our parameters and state
int itemID = parameters.getParameterAsInteger("itemID",-1);
Item item = Item.find(context, itemID);
DCValue[] values = item.getMetadata(Item.ANY, Item.ANY, Item.ANY, Item.ANY);
Arrays.sort(values, new DCValueComparator());
String baseURL = contextPath+"/admin/item?administrative-continue="+knot.getId();
Request request = ObjectModelHelper.getRequest(objectModel);
String previousFieldID = request.getParameter("field");
// DIVISION: main
Division main = body.addInteractiveDivision("edit-item-status", contextPath+"/admin/item", Division.METHOD_POST,"primary administrative item");
main.setHead(T_option_head);
// LIST: options
List options = main.addList("options",List.TYPE_SIMPLE,"horizontal");
options.addItem().addXref(baseURL+"&submit_status",T_option_status);
options.addItem().addXref(baseURL+"&submit_bitstreams",T_option_bitstreams);
options.addItem().addHighlight("bold").addXref(baseURL+"&submit_metadata",T_option_metadata);
options.addItem().addXref(baseURL + "&view_item", T_option_view);
// LIST: add new metadata
List addForm = main.addList("addItemMetadata",List.TYPE_FORM);
addForm.setHead(T_head1);
Select addName = addForm.addItem().addSelect("field");
addName.setLabel(T_name_label);
MetadataField[] fields = MetadataField.findAll(context);
for (MetadataField field : fields)
{
int fieldID = field.getFieldID();
MetadataSchema schema = MetadataSchema.find(context, field.getSchemaID());
String name = schema.getName() +"."+field.getElement();
if (field.getQualifier() != null)
name += "."+field.getQualifier();
addName.addOption(fieldID, name);
}
if (previousFieldID != null)
addName.setOptionSelected(previousFieldID);
Composite addComposite = addForm.addItem().addComposite("value");
addComposite.setLabel(T_value_label);
TextArea addValue = addComposite.addTextArea("value");
Text addLang = addComposite.addText("language");
addValue.setSize(4, 35);
addLang.setLabel(T_lang_label);
addLang.setSize(6);
addForm.addItem().addButton("submit_add").setValue(T_submit_add);
// PARA: Disclaimer
main.addPara(T_para1);
Para actions = main.addPara(null,"edit-metadata-actions top" );
actions.addButton("submit_update").setValue(T_submit_update);
actions.addButton("submit_return").setValue(T_submit_return);
// TABLE: Metadata
main.addHidden("scope").setValue("*");
int index = 1;
Table table = main.addTable("editItemMetadata",1,1);
table.setHead(T_head2);
Row header = table.addRow(Row.ROLE_HEADER);
header.addCell().addContent(T_column1);
header.addCell().addContent(T_column2);
header.addCell().addContent(T_column3);
header.addCell().addContent(T_column4);
for(DCValue value : values)
{
String name = value.schema + "_" + value.element;
if (value.qualifier != null)
name += "_" + value.qualifier;
Row row = table.addRow(name,Row.ROLE_DATA,"metadata-value");
CheckBox remove = row.addCell().addCheckBox("remove_"+index);
remove.setLabel("remove");
remove.addOption(index);
Cell cell = row.addCell();
cell.addContent(name.replaceAll("_", ". "));
cell.addHidden("name_"+index).setValue(name);
TextArea mdValue = row.addCell().addTextArea("value_"+index);
mdValue.setSize(4,35);
mdValue.setValue(value.value);
Text mdLang = row.addCell().addText("language_"+index);
mdLang.setSize(6);
mdLang.setValue(value.language);
// Tick the index counter;
index++;
}
// PARA: actions
actions = main.addPara(null,"edit-metadata-actions bottom" );
actions.addButton("submit_update").setValue(T_submit_update);
actions.addButton("submit_return").setValue(T_submit_return);
main.addHidden("administrative-continue").setValue(knot.getId());
}
/**
* Compare two metadata element's name so that they may be sorted.
*/
class DCValueComparator implements Comparator{
public int compare(Object arg0, Object arg1) {
final DCValue o1 = (DCValue)arg0;
final DCValue o2 = (DCValue)arg1;
final String s1 = o1.schema + o1.element + (o1.qualifier==null?"":("." + o1.qualifier));
final String s2 = o2.schema + o2.element + (o2.qualifier==null?"":("." + o2.qualifier));
return s1.compareTo(s2);
}
}
}

View File

@@ -0,0 +1,207 @@
/*
* EditItemStatus.java
*
* Version: $Revision: 1.3 $
*
* Date: $Date: 2006/07/13 23:20:54 $
*
* Copyright (c) 2002, Hewlett-Packard Company and Massachusetts
* Institute of Technology. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* - 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.
*
* - Neither the name of the Hewlett-Packard Company nor the name of the
* Massachusetts Institute of Technology nor the names of their
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS 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 COPYRIGHT
* HOLDERS OR 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.
*/
package org.dspace.app.xmlui.aspect.administrative.item;
import java.sql.SQLException;
import org.dspace.app.xmlui.cocoon.AbstractDSpaceTransformer;
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.Button;
import org.dspace.app.xmlui.wing.element.Division;
import org.dspace.app.xmlui.wing.element.List;
import org.dspace.app.xmlui.wing.element.PageMeta;
import org.dspace.authorize.AuthorizeManager;
import org.dspace.content.Collection;
import org.dspace.content.Item;
import org.dspace.core.ConfigurationManager;
/**
* Display basic meta-meta information about the item and allow the user to change
* it's state such as withdraw or reinstate, possibily even completely deleting the item!
*
* @author Jay Paz
* @author Scott Phillips
*/
public class EditItemStatusForm extends AbstractDSpaceTransformer {
/** Language strings */
private static final Message T_dspace_home = message("xmlui.general.dspace_home");
private static final Message T_submit_return = message("xmlui.general.return");
private static final Message T_item_trail = message("xmlui.administrative.item.general.item_trail");
private static final Message T_option_head = message("xmlui.administrative.item.general.option_head");
private static final Message T_option_status = message("xmlui.administrative.item.general.option_status");
private static final Message T_option_bitstreams = message("xmlui.administrative.item.general.option_bitstreams");
private static final Message T_option_metadata = message("xmlui.administrative.item.general.option_metadata");
private static final Message T_option_view = message("xmlui.administrative.item.general.option_view");
private static final Message T_title = message("xmlui.administrative.item.EditItemStatusForm.title");
private static final Message T_trail = message("xmlui.administrative.item.EditItemStatusForm.trail");
private static final Message T_para1 = message("xmlui.administrative.item.EditItemStatusForm.para1");
private static final Message T_label_id = message("xmlui.administrative.item.EditItemStatusForm.label_id");
private static final Message T_label_handle = message("xmlui.administrative.item.EditItemStatusForm.label_handle");
private static final Message T_label_modified = message("xmlui.administrative.item.EditItemStatusForm.label_modified");
private static final Message T_label_in = message("xmlui.administrative.item.EditItemStatusForm.label_in");
private static final Message T_label_page = message("xmlui.administrative.item.EditItemStatusForm.label_page");
private static final Message T_label_auth = message("xmlui.administrative.item.EditItemStatusForm.label_auth");
private static final Message T_label_withdraw = message("xmlui.administrative.item.EditItemStatusForm.label_withdraw");
private static final Message T_label_reinstate = message("xmlui.administrative.item.EditItemStatusForm.label_reinstate");
private static final Message T_label_delete = message("xmlui.administrative.item.EditItemStatusForm.label_delete");
private static final Message T_submit_authorizations = message("xmlui.administrative.item.EditItemStatusForm.submit_authorizations");
private static final Message T_submit_withdraw = message("xmlui.administrative.item.EditItemStatusForm.submit_withdraw");
private static final Message T_submit_reinstate = message("xmlui.administrative.item.EditItemStatusForm.submit_reinstate");
private static final Message T_submit_delete = message("xmlui.administrative.item.EditItemStatusForm.submit_delete");
private static final Message T_na = message("xmlui.administrative.item.EditItemStatusForm.na");
private static final Message T_sysadmins_only = message("xmlui.administrative.item.EditItemStatusForm.sysadmins_only");
public void addPageMeta(PageMeta pageMeta) throws WingException
{
pageMeta.addMetadata("title").addContent(T_title);
pageMeta.addTrailLink(contextPath + "/", T_dspace_home);
pageMeta.addTrailLink(contextPath + "/admin/item",T_item_trail);
pageMeta.addTrail().addContent(T_trail);
}
public void addBody(Body body) throws SQLException, WingException
{
// Get our parameters and state
int itemID = parameters.getParameterAsInteger("itemID",-1);
Item item = Item.find(context, itemID);
String baseURL = contextPath+"/admin/item?administrative-continue="+knot.getId();
// DIVISION: main
Division main = body.addInteractiveDivision("edit-item-status", contextPath+"/admin/item", Division.METHOD_POST,"primary administrative edit-item-status");
main.setHead(T_option_head);
// LIST: options
List options = main.addList("options",List.TYPE_SIMPLE,"horizontal");
options.addItem().addHighlight("bold").addXref(baseURL+"&submit_status",T_option_status);
options.addItem().addXref(baseURL+"&submit_bitstreams",T_option_bitstreams);
options.addItem().addXref(baseURL+"&submit_metadata",T_option_metadata);
options.addItem().addXref(baseURL + "&view_item", T_option_view);
// PARA: Helpfull instructions
main.addPara(T_para1);
// LIST: Item meta-meta information
List itemInfo = main.addList("item-info");
itemInfo.addLabel(T_label_id);
itemInfo.addItem(String.valueOf(item.getID()));
itemInfo.addLabel(T_label_handle);
itemInfo.addItem(item.getHandle()==null?"None":item.getHandle());
itemInfo.addLabel(T_label_modified);
itemInfo.addItem(item.getLastModified().toString());
itemInfo.addLabel(T_label_in);
List subList = itemInfo.addList("collections", List.TYPE_SIMPLE);
Collection[] collections = item.getCollections();
for(Collection collection : collections) {
subList.addItem(collection.getMetadata("name"));
}
itemInfo.addLabel(T_label_page);
if(item.getHandle()==null){
itemInfo.addItem(T_na);
}
else{
itemInfo.addItem().addXref(ConfigurationManager.getProperty("dspace.url") + "/handle/" + item.getHandle(),ConfigurationManager.getProperty("dspace.url") + "/handle/" + item.getHandle());
}
itemInfo.addLabel(T_label_auth);
addAdministratorOnlyButton(itemInfo.addItem(), "submit_authorization", T_submit_authorizations);
if(!item.isWithdrawn())
{
itemInfo.addLabel(T_label_withdraw);
itemInfo.addItem().addButton("submit_withdraw").setValue(T_submit_withdraw);
}
else
{
itemInfo.addLabel(T_label_reinstate);
itemInfo.addItem().addButton("submit_reinstate").setValue(T_submit_reinstate);
}
itemInfo.addLabel(T_label_delete);
addAdministratorOnlyButton(itemInfo.addItem(), "submit_delete", T_submit_delete);
// PARA: main actions
main.addPara().addButton("submit_return").setValue(T_submit_return);
main.addHidden("administrative-continue").setValue(knot.getId());
}
private void addAdministratorOnlyButton(org.dspace.app.xmlui.wing.element.Item item, String buttonName, Message buttonLabel) throws WingException, SQLException
{
Button button = item.addButton(buttonName);
button.setValue(buttonLabel);
if (!AuthorizeManager.isAdmin(context))
{
// Only admins can create or delete
button.setDisabled();
item.addHighlight("fade").addContent(T_sysadmins_only);
}
}
}

View File

@@ -0,0 +1,108 @@
/*
* FindItemForm.java
*
* Version: $Revision: 1.3 $
*
* Date: $Date: 2006/07/13 23:20:54 $
*
* Copyright (c) 2002, Hewlett-Packard Company and Massachusetts
* Institute of Technology. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* - 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.
*
* - Neither the name of the Hewlett-Packard Company nor the name of the
* Massachusetts Institute of Technology nor the names of their
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS 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 COPYRIGHT
* HOLDERS OR 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.
*/
package org.dspace.app.xmlui.aspect.administrative.item;
import java.util.ArrayList;
import org.dspace.app.xmlui.cocoon.AbstractDSpaceTransformer;
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.List;
import org.dspace.app.xmlui.wing.element.PageMeta;
import org.dspace.app.xmlui.wing.element.Text;
import org.xml.sax.SAXException;
/**
* Query the user for an item's identifier.
*
* @author Jay Paz
*/
public class FindItemForm extends AbstractDSpaceTransformer {
/** Language strings */
private static final Message T_dspace_home = message("xmlui.general.dspace_home");
private static final Message T_item_trail = message("xmlui.administrative.item.general.item_trail");
private static final Message T_title = message("xmlui.administrative.item.FindItemForm.title");
private static final Message T_head1 = message("xmlui.administrative.item.FindItemForm.head1");
private static final Message T_identifier_label = message("xmlui.administrative.item.FindItemForm.identifier_label");
private static final Message T_identifier_error = message("xmlui.administrative.item.FindItemForm.identifier_error");
private static final Message T_find = message("xmlui.administrative.item.FindItemForm.find");
public void addPageMeta(PageMeta pageMeta) throws WingException
{
pageMeta.addTrailLink(contextPath + "/", T_dspace_home);
pageMeta.addTrail().addContent(T_item_trail);
pageMeta.addMetadata("title").addContent(T_title);
}
public void addBody(Body body) throws SAXException, WingException
{
// Get our parameters and state;
String identifier = parameters.getParameter("identifier",null);
String errorString = parameters.getParameter("errors",null);
ArrayList<String> errors = new ArrayList<String>();
if (errorString != null)
for (String error : errorString.split(","))
errors.add(error);
// DIVISION: find-item
Division findItem = body.addInteractiveDivision("find-item",contextPath + "/admin/item", Division.METHOD_GET,"primary administrative item");
findItem.setHead(T_head1);
List form = findItem.addList("find-item-form", List.TYPE_FORM);
Text id = form.addItem().addText("identifier");
id.setLabel(T_identifier_label);
if (identifier != null)
id.setValue(identifier);
if (errors.contains("identifier"))
id.addError(T_identifier_error);
form.addItem().addButton("submit_find").setValue(T_find);
findItem.addHidden("administrative-continue").setValue(knot.getId());
}
}

View File

@@ -0,0 +1,175 @@
/*
* EditItemStatus.java
*
* Version: $Revision: 1.3 $
*
* Date: $Date: 2006/07/13 23:20:54 $
*
* Copyright (c) 2002, Hewlett-Packard Company and Massachusetts
* Institute of Technology. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* - 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.
*
* - Neither the name of the Hewlett-Packard Company nor the name of the
* Massachusetts Institute of Technology nor the names of their
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS 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 COPYRIGHT
* HOLDERS OR 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.
*/
package org.dspace.app.xmlui.aspect.administrative.item;
import java.sql.SQLException;
import org.apache.cocoon.environment.ObjectModelHelper;
import org.apache.cocoon.environment.Request;
import org.dspace.app.xmlui.cocoon.AbstractDSpaceTransformer;
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.Button;
import org.dspace.app.xmlui.wing.element.Division;
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.AuthorizeManager;
import org.dspace.content.Collection;
import org.dspace.content.Item;
import org.dspace.core.ConfigurationManager;
/**
* Display basic meta-meta information about the item and allow the user to
* change it's state such as withdraw or reinstate, possibily even completely
* deleting the item!
*
* @author Jay Paz
* @author Scott Phillips
*/
public class ViewItem extends AbstractDSpaceTransformer {
/** Language strings */
private static final Message T_dspace_home = message("xmlui.general.dspace_home");
private static final Message T_item_trail = message("xmlui.administrative.item.general.item_trail");
private static final Message T_option_head = message("xmlui.administrative.item.general.option_head");
private static final Message T_option_status = message("xmlui.administrative.item.general.option_status");
private static final Message T_option_bitstreams = message("xmlui.administrative.item.general.option_bitstreams");
private static final Message T_option_metadata = message("xmlui.administrative.item.general.option_metadata");
private static final Message T_option_view = message("xmlui.administrative.item.general.option_view");
private static final Message T_title = message("xmlui.administrative.item.ViewItem.title");
private static final Message T_trail = message("xmlui.administrative.item.ViewItem.trail");
private static final Message T_head_parent_collections = message("xmlui.ArtifactBrowser.ItemViewer.head_parent_collections");
private static final Message T_show_simple =
message("xmlui.ArtifactBrowser.ItemViewer.show_simple");
private static final Message T_show_full =
message("xmlui.ArtifactBrowser.ItemViewer.show_full");
public void addPageMeta(PageMeta pageMeta) throws WingException {
pageMeta.addMetadata("title").addContent(T_title);
pageMeta.addTrailLink(contextPath + "/", T_dspace_home);
pageMeta.addTrailLink(contextPath + "/admin/item", T_item_trail);
pageMeta.addTrail().addContent(T_trail);
}
public void addBody(Body body) throws SQLException, WingException {
// Get our parameters and state
Request request = ObjectModelHelper.getRequest(objectModel);
String show = request.getParameter("show");
boolean showFullItem = false;
if (show != null && show.length() > 0)
showFullItem = true;
int itemID = parameters.getParameterAsInteger("itemID", -1);
Item item = Item.find(context, itemID);
String baseURL = contextPath + "/admin/item?administrative-continue="
+ knot.getId() ;
String link = baseURL + "&view_item" + (showFullItem?"":"&show=full");
String tabLink = baseURL + "&view_item" + (!showFullItem?"":"&show=full");
// DIVISION: main
Division main = body.addInteractiveDivision("edit-item-status",
contextPath + "/admin/item", Division.METHOD_POST,
"primary administrative edit-item-status");
main.setHead(T_option_head);
// LIST: options
List options = main.addList("options", List.TYPE_SIMPLE, "horizontal");
options.addItem().addXref(
baseURL + "&submit_status", T_option_status);
options.addItem().addXref(baseURL + "&submit_bitstreams",
T_option_bitstreams);
options.addItem().addXref(baseURL + "&submit_metadata",
T_option_metadata);
options.addItem().addHighlight("bold").addXref(tabLink, T_option_view);
// item
Para showfullPara = main.addPara(null, "item-view-toggle item-view-toggle-top");
if (showFullItem)
{
link = baseURL + "&view_item";
showfullPara.addXref(link).addContent(T_show_simple);
}
else
{
link = baseURL + "&view_item&show=full";
showfullPara.addXref(link).addContent(T_show_full);
}
ReferenceSet referenceSet;
referenceSet = main.addReferenceSet("collection-viewer",
showFullItem?ReferenceSet.TYPE_DETAIL_VIEW:ReferenceSet.TYPE_SUMMARY_VIEW);
// Refrence the actual Item
ReferenceSet appearsInclude = referenceSet.addReference(item)
.addReferenceSet(ReferenceSet.TYPE_DETAIL_LIST, null, "hierarchy");
appearsInclude.setHead(T_head_parent_collections);
// Reference all collections the item appears in.
for (Collection collection : item.getCollections()) {
appearsInclude.addReference(collection);
}
showfullPara = main.addPara(null, "item-view-toggle item-view-toggle-bottom");
if (showFullItem)
{
showfullPara.addXref(link).addContent(T_show_simple);
}
else
{
showfullPara.addXref(link).addContent(T_show_full);
}
}
}

View File

@@ -0,0 +1,210 @@
/*
* BrowseItemForm.java
*
* Version: $Revision: 1.3 $
*
* Date: $Date: 2006/07/13 23:20:54 $
*
* Copyright (c) 2002, Hewlett-Packard Company and Massachusetts
* Institute of Technology. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* - 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.
*
* - Neither the name of the Hewlett-Packard Company nor the name of the
* Massachusetts Institute of Technology nor the names of their
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS 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 COPYRIGHT
* HOLDERS OR 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.
*/
package org.dspace.app.xmlui.aspect.administrative.mapper;
import java.sql.SQLException;
import java.util.ArrayList;
import org.dspace.app.xmlui.cocoon.AbstractDSpaceTransformer;
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.Button;
import org.dspace.app.xmlui.wing.element.CheckBox;
import org.dspace.app.xmlui.wing.element.Division;
import org.dspace.app.xmlui.wing.element.PageMeta;
import org.dspace.app.xmlui.wing.element.Para;
import org.dspace.app.xmlui.wing.element.Row;
import org.dspace.app.xmlui.wing.element.Table;
import org.dspace.authorize.AuthorizeManager;
import org.dspace.content.Collection;
import org.dspace.content.DCValue;
import org.dspace.content.Item;
import org.dspace.content.ItemIterator;
import org.dspace.core.Constants;
import org.xml.sax.SAXException;
/**
* List all items in this collection that are mapped from other collections.
*
* @author Scott phillips
*/
public class BrowseItemForm extends AbstractDSpaceTransformer {
/** Language strings */
private static final Message T_dspace_home = message("xmlui.general.dspace_home");
private static final Message T_submit_return = message("xmlui.general.return");
private static final Message T_mapper_trail = message("xmlui.administrative.mapper.general.mapper_trail");
private static final Message T_title = message("xmlui.administrative.mapper.BrowseItemForm.title");
private static final Message T_trail = message("xmlui.administrative.mapper.BrowseItemForm.trail");
private static final Message T_head1 = message("xmlui.administrative.mapper.BrowseItemForm.head1");
private static final Message T_submit_unmap = message("xmlui.administrative.mapper.BrowseItemForm.submit_unmap");
private static final Message T_column1 = message("xmlui.administrative.mapper.BrowseItemForm.column1");
private static final Message T_column2 = message("xmlui.administrative.mapper.BrowseItemForm.column2");
private static final Message T_column3 = message("xmlui.administrative.mapper.BrowseItemForm.column3");
private static final Message T_column4 = message("xmlui.administrative.mapper.BrowseItemForm.column4");
private static final Message T_no_remove = message("xmlui.administrative.mapper.BrowseItemForm.no_remove");
public void addPageMeta(PageMeta pageMeta) throws WingException
{
pageMeta.addMetadata("title").addContent(T_title);
pageMeta.addTrailLink(contextPath + "/", T_dspace_home);
pageMeta.addTrail().addContent(T_mapper_trail);
pageMeta.addTrail().addContent(T_trail);
}
public void addBody(Body body) throws SAXException, WingException, SQLException
{
// Get our parameters and state;
int collectionID = parameters.getParameterAsInteger("collectionID",-1);
Collection collection = Collection.find(context,collectionID);
ArrayList<Item> items = getMappedItems(collection);
// DIVISION: browse-items
Division div = body.addInteractiveDivision("browse-items",contextPath + "/admin/mapper", Division.METHOD_GET,"primary administrative mapper");
div.setHead(T_head1);
if (AuthorizeManager.authorizeActionBoolean(context, collection, Constants.REMOVE))
{
Para actions = div.addPara();
actions.addButton("submit_unmap").setValue(T_submit_unmap);
actions.addButton("submit_return").setValue(T_submit_return);
}
else
{
Para actions = div.addPara();
Button button = actions.addButton("submit_unmap");
button.setValue(T_submit_unmap);
button.setDisabled();
actions.addButton("submit_return").setValue(T_submit_return);
div.addPara().addHighlight("fade").addContent(T_no_remove);
}
Table table = div.addTable("browse-items-table",1,1);
Row header = table.addRow(Row.ROLE_HEADER);
header.addCellContent(T_column1);
header.addCellContent(T_column2);
header.addCellContent(T_column3);
header.addCellContent(T_column4);
for (Item item : items)
{
String itemID = String.valueOf(item.getID());
Collection owningCollection = item.getOwningCollection();
String owning = owningCollection.getMetadata("name");
String author = "unkown";
DCValue[] dcAuthors = item.getDC("contributor",Item.ANY,Item.ANY);
if (dcAuthors != null && dcAuthors.length >= 1)
author = dcAuthors[0].value;
String title = "untitled";
DCValue[] dcTitles = item.getDC("title",null,Item.ANY);
if (dcTitles != null && dcTitles.length >= 1)
title = dcTitles[0].value;
String url = contextPath+"/handle/"+item.getHandle();
Row row = table.addRow();
CheckBox select = row.addCell().addCheckBox("itemID");
select.setLabel("Select");
select.addOption(itemID);
row.addCellContent(owning);
row.addCell().addXref(url,author);
row.addCell().addXref(url,title);
}
if (AuthorizeManager.authorizeActionBoolean(context, collection, Constants.REMOVE))
{
Para actions = div.addPara();
actions.addButton("submit_unmap").setValue(T_submit_unmap);
actions.addButton("submit_return").setValue(T_submit_return);
}
else
{
Para actions = div.addPara();
Button button = actions.addButton("submit_unmap");
button.setValue(T_submit_unmap);
button.setDisabled();
actions.addButton("submit_return").setValue(T_submit_return);
div.addPara().addHighlight("fade").addContent(T_no_remove);
}
div.addHidden("administrative-continue").setValue(knot.getId());
}
/**
* Get a list of all items that are mapped from other collections.
*
* @param collection The collection to look in.
*/
private ArrayList<Item> getMappedItems(Collection collection) throws SQLException
{
ArrayList<Item> items = new ArrayList<Item>();
// get all items from that collection
ItemIterator iterator = collection.getItems();
while (iterator.hasNext())
{
Item item = iterator.next();
if (! item.isOwningCollection(collection))
items.add(item);
}
return items;
}
}

View File

@@ -0,0 +1,179 @@
/*
* MapperMain.java
*
* Version: $Revision: 1.3 $
*
* Date: $Date: 2006/07/13 23:20:54 $
*
* Copyright (c) 2002, Hewlett-Packard Company and Massachusetts
* Institute of Technology. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* - 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.
*
* - Neither the name of the Hewlett-Packard Company nor the name of the
* Massachusetts Institute of Technology nor the names of their
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS 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 COPYRIGHT
* HOLDERS OR 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.
*/
package org.dspace.app.xmlui.aspect.administrative.mapper;
import java.sql.SQLException;
import org.dspace.app.xmlui.cocoon.AbstractDSpaceTransformer;
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.Button;
import org.dspace.app.xmlui.wing.element.Division;
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.Text;
import org.dspace.authorize.AuthorizeManager;
import org.dspace.content.Collection;
import org.dspace.content.Item;
import org.dspace.content.ItemIterator;
import org.dspace.core.Constants;
import org.xml.sax.SAXException;
/**
* Manage the mapping of items into this collection, allow the user to
* search for new items to import or browse a list of currently mapped
* items.
*
* @author Scott phillips
*/
public class MapperMain extends AbstractDSpaceTransformer {
/** Language strings */
private static final Message T_dspace_home = message("xmlui.general.dspace_home");
private static final Message T_submit_return = message("xmlui.general.return");
private static final Message T_mapper_trail = message("xmlui.administrative.mapper.general.mapper_trail");
private static final Message T_title = message("xmlui.administrative.mapper.MapperMain.title");
private static final Message T_head1 = message("xmlui.administrative.mapper.MapperMain.head1");
private static final Message T_para1 = message("xmlui.administrative.mapper.MapperMain.para1");
private static final Message T_para2 = message("xmlui.administrative.mapper.MapperMain.para2");
private static final Message T_stat_label = message("xmlui.administrative.mapper.MapperMain.stat_label");
private static final Message T_stat_info = message("xmlui.administrative.mapper.MapperMain.stat_info");
private static final Message T_search_label = message("xmlui.administrative.mapper.MapperMain.search_label");
private static final Message T_submit_search = message("xmlui.administrative.mapper.MapperMain.submit_search");
private static final Message T_submit_browse = message("xmlui.administrative.mapper.MapperMain.submit_browse");
private static final Message T_no_add = message("xmlui.administrative.mapper.MapperMain.no_add");
public void addPageMeta(PageMeta pageMeta) throws WingException
{
pageMeta.addMetadata("title").addContent(T_title);
pageMeta.addTrailLink(contextPath + "/", T_dspace_home);
pageMeta.addTrail().addContent(T_mapper_trail);
}
public void addBody(Body body) throws SAXException, WingException, SQLException
{
// Get our parameters and state;
int collectionID = parameters.getParameterAsInteger("collectionID",-1);
Collection collection = Collection.find(context,collectionID);
int[] counts = getNumberOfMappedAndUnmappedItems(collection);
int count_native = counts[0];
int count_import = counts[1];
// DIVISION: manage-mapper
Division div = body.addInteractiveDivision("manage-mapper",contextPath + "/admin/mapper", Division.METHOD_GET,"primary administrative mapper");
div.setHead(T_head1);
div.addPara(T_para1.parameterize(collection.getMetadata("name")));
div.addPara(T_para2);
// LIST: Author search form
List form = div.addList("mapper-form");
form.addLabel(T_stat_label);
form.addItem(T_stat_info.parameterize(count_import,count_native+count_import));
form.addLabel(T_search_label);
org.dspace.app.xmlui.wing.element.Item queryItem = form.addItem();
Text query = queryItem.addText("query");
Button button = queryItem.addButton("submit_author");
button.setValue(T_submit_search);
if (!AuthorizeManager.authorizeActionBoolean(context, collection, Constants.ADD))
{
query.setDisabled();
button.setDisabled();
queryItem.addHighlight("fade").addContent(T_no_add);
}
// PARA: actions
Para actions = div.addPara();
actions.addButton("submit_browse").setValue(T_submit_browse);
actions.addButton("submit_return").setValue(T_submit_return);
div.addHidden("administrative-continue").setValue(knot.getId());
}
/**
* Count the number of unmapped and mapped items in this collection
*
* @param collection The collection to count from.
* @return a two integer array of native items and imported items.
*/
private int[] getNumberOfMappedAndUnmappedItems(Collection collection) throws SQLException
{
int count_native = 0;
int count_import = 0;
// get all items from that collection
ItemIterator iterator = collection.getItems();
// iterate through the items in this collection, and count how many
// are native, and how many are imports, and which collections they
// came from
while (iterator.hasNext())
{
Item item = iterator.next();
if (item.isOwningCollection(collection))
count_native++;
else
count_import++;
}
int[] counts = new int[2];
counts[0] = count_native;
counts[1] = count_import;
return counts;
}
}

View File

@@ -0,0 +1,203 @@
/*
* SearchItemForm.java
*
* Version: $Revision: 1.3 $
*
* Date: $Date: 2006/07/13 23:20:54 $
*
* Copyright (c) 2002, Hewlett-Packard Company and Massachusetts
* Institute of Technology. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* - 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.
*
* - Neither the name of the Hewlett-Packard Company nor the name of the
* Massachusetts Institute of Technology nor the names of their
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS 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 COPYRIGHT
* HOLDERS OR 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.
*/
package org.dspace.app.xmlui.aspect.administrative.mapper;
import java.io.IOException;
import java.sql.SQLException;
import java.util.ArrayList;
import org.dspace.app.xmlui.cocoon.AbstractDSpaceTransformer;
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.CheckBox;
import org.dspace.app.xmlui.wing.element.Division;
import org.dspace.app.xmlui.wing.element.PageMeta;
import org.dspace.app.xmlui.wing.element.Para;
import org.dspace.app.xmlui.wing.element.Row;
import org.dspace.app.xmlui.wing.element.Table;
import org.dspace.content.Collection;
import org.dspace.content.DCValue;
import org.dspace.content.DSpaceObject;
import org.dspace.content.Item;
import org.dspace.handle.HandleManager;
import org.dspace.search.DSQuery;
import org.dspace.search.QueryArgs;
import org.dspace.search.QueryResults;
import org.xml.sax.SAXException;
/**
* Search for items from other collections to map into this collection.
*
* @author Scott phillips
*/
public class SearchItemForm extends AbstractDSpaceTransformer {
/** Language strings */
private static final Message T_dspace_home = message("xmlui.general.dspace_home");
private static final Message T_submit_cancel = message("xmlui.general.cancel");
private static final Message T_mapper_trail = message("xmlui.administrative.mapper.general.mapper_trail");
private static final Message T_title = message("xmlui.administrative.mapper.SearchItemForm.title");
private static final Message T_trail = message("xmlui.administrative.mapper.SearchItemForm.trail");
private static final Message T_head1 = message("xmlui.administrative.mapper.SearchItemForm.head1");
private static final Message T_submit_map = message("xmlui.administrative.mapper.SearchItemForm.submit_map");
private static final Message T_column1 = message("xmlui.administrative.mapper.SearchItemForm.column1");
private static final Message T_column2 = message("xmlui.administrative.mapper.SearchItemForm.column2");
private static final Message T_column3 = message("xmlui.administrative.mapper.SearchItemForm.column3");
private static final Message T_column4 = message("xmlui.administrative.mapper.SearchItemForm.column4");
public void addPageMeta(PageMeta pageMeta) throws WingException
{
pageMeta.addMetadata("title").addContent(T_title);
pageMeta.addTrailLink(contextPath + "/", T_dspace_home);
pageMeta.addTrail().addContent(T_mapper_trail);
pageMeta.addTrail().addContent(T_trail);
}
public void addBody(Body body) throws SAXException, WingException, SQLException, IOException
{
// Get our parameters and state;
int collectionID = parameters.getParameterAsInteger("collectionID",-1);
Collection collection = Collection.find(context,collectionID);
String query = parameters.getParameter("query",null);
ArrayList<Item> items = preformSearch(collection,query);
// DIVISION: manage-mapper
Division div = body.addInteractiveDivision("search-items",contextPath + "/admin/mapper", Division.METHOD_GET,"primary administrative mapper");
div.setHead(T_head1.parameterize(query));
Para actions = div.addPara();
actions.addButton("submit_map").setValue(T_submit_map);
actions.addButton("submit_cancel").setValue(T_submit_cancel);
Table table = div.addTable("search-items-table",1,1);
Row header = table.addRow(Row.ROLE_HEADER);
header.addCellContent(T_column1);
header.addCellContent(T_column2);
header.addCellContent(T_column3);
header.addCellContent(T_column4);
for (Item item : items)
{
String itemID = String.valueOf(item.getID());
Collection owningCollection = item.getOwningCollection();
String owning = owningCollection.getMetadata("name");
String author = "unkown";
DCValue[] dcAuthors = item.getDC("contributor",Item.ANY,Item.ANY);
if (dcAuthors != null && dcAuthors.length >= 1)
author = dcAuthors[0].value;
String title = "untitled";
DCValue[] dcTitles = item.getDC("title",null,Item.ANY);
if (dcTitles != null && dcTitles.length >= 1)
title = dcTitles[0].value;
String url = contextPath+"/handle/"+item.getHandle();
Row row = table.addRow();
CheckBox select = row.addCell().addCheckBox("itemID");
select.setLabel("Select");
select.addOption(itemID);
row.addCellContent(owning);
row.addCell().addXref(url,author);
row.addCell().addXref(url,title);
}
actions = div.addPara();
actions.addButton("submit_map").setValue(T_submit_map);
actions.addButton("submit_cancel").setValue(T_submit_cancel);
div.addHidden("administrative-continue").setValue(knot.getId());
}
/**
* Search the repository for items in other collections that can be mapped into this one.
*
* @param collection The collection to mapp into
* @param query The search query.
*/
private ArrayList<Item> preformSearch(Collection collection, String query) throws SQLException, IOException
{
// Search the repository
QueryArgs queryArgs = new QueryArgs();
queryArgs.setQuery(query);
queryArgs.setPageSize(Integer.MAX_VALUE);
QueryResults results = DSQuery.doQuery(context, queryArgs);
// Get a list of found items
ArrayList<Item> items = new ArrayList<Item>();
@SuppressWarnings("unchecked")
java.util.List<String> handles = results.getHitHandles();
for (String handle : handles)
{
DSpaceObject resultDSO = HandleManager.resolveToObject(context, handle);
if (resultDSO instanceof Item)
{
Item item = (Item) resultDSO;
if (!item.isOwningCollection(collection))
items.add(item);
}
}
return items;
}
}

View File

@@ -0,0 +1,146 @@
/*
* DeleteBitstreamFormatConfirm.java
*
* Version: $Revision: 1.0 $
*
* Date: $Date: 2006/07/13 23:20:54 $
*
* Copyright (c) 2002, Hewlett-Packard Company and Massachusetts
* Institute of Technology. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* - 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.
*
* - Neither the name of the Hewlett-Packard Company nor the name of the
* Massachusetts Institute of Technology nor the names of their
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS 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 COPYRIGHT
* HOLDERS OR 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.
*/
package org.dspace.app.xmlui.aspect.administrative.registries;
import java.sql.SQLException;
import java.util.ArrayList;
import org.dspace.app.xmlui.cocoon.AbstractDSpaceTransformer;
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.PageMeta;
import org.dspace.app.xmlui.wing.element.Para;
import org.dspace.app.xmlui.wing.element.Row;
import org.dspace.app.xmlui.wing.element.Table;
import org.dspace.authorize.AuthorizeException;
import org.dspace.content.BitstreamFormat;
/**
* Confirm the deletition of bitstream formats by listing to-be-deleted
* formats and asking the user for confirmation.
*
* @author Scott phillips
*/
public class DeleteBitstreamFormatsConfirm extends AbstractDSpaceTransformer
{
/** Language Strings */
private static final Message T_dspace_home =
message("xmlui.general.dspace_home");
private static final Message T_submit_delete =
message("xmlui.general.delete");
private static final Message T_submit_cancel =
message("xmlui.general.cancel");
private static final Message T_title =
message("xmlui.administrative.registries.DeleteBitstreamFormatsConfirm.title");
private static final Message T_format_registry_trail =
message("xmlui.administrative.registries.general.format_registry_trail");
private static final Message T_trail =
message("xmlui.administrative.registries.DeleteBitstreamFormatsConfirm.trail");
private static final Message T_head =
message("xmlui.administrative.registries.DeleteBitstreamFormatsConfirm.head");
private static final Message T_para1 =
message("xmlui.administrative.registries.DeleteBitstreamFormatsConfirm.para1");
private static final Message T_column1 =
message("xmlui.administrative.registries.DeleteBitstreamFormatsConfirm.column1");
private static final Message T_column2 =
message("xmlui.administrative.registries.DeleteBitstreamFormatsConfirm.column2");
private static final Message T_column3 =
message("xmlui.administrative.registries.DeleteBitstreamFormatsConfirm.column3");
public void addPageMeta(PageMeta pageMeta) throws WingException
{
pageMeta.addMetadata("title").addContent(T_title);
pageMeta.addTrailLink(contextPath + "/", T_dspace_home);
pageMeta.addTrailLink(contextPath + "/admin/format-registry",T_format_registry_trail);
pageMeta.addTrail().addContent(T_trail);
}
public void addBody(Body body) throws WingException, SQLException, AuthorizeException
{
// Get all our parameters
String idsString = parameters.getParameter("formatIDs", null);
ArrayList<BitstreamFormat> formats = new ArrayList<BitstreamFormat>();
for (String id : idsString.split(","))
{
BitstreamFormat format = BitstreamFormat.find(context,Integer.valueOf(id));
formats.add(format);
}
// DIVISION: bitstream-format-confirm-delete
Division deleted = body.addInteractiveDivision("bitstream-format-confirm-delete",contextPath+"/admin/format-registry",Division.METHOD_POST,"primary administrative format-registry");
deleted.setHead(T_head);
deleted.addPara(T_para1);
Table table = deleted.addTable("format-confirm-delete",formats.size() + 1, 3);
Row header = table.addRow(Row.ROLE_HEADER);
header.addCell().addContent(T_column1);
header.addCell().addContent(T_column2);
header.addCell().addContent(T_column3);
for (BitstreamFormat format : formats)
{
if (format == null)
continue;
String formatID = String.valueOf(format.getID());
String mimetype = format.getMIMEType();
String name = format.getShortDescription();
Row row = table.addRow();
row.addCell().addContent(formatID);
row.addCell().addContent(mimetype);
row.addCell().addContent(name);
}
Para buttons = deleted.addPara();
buttons.addButton("submit_confirm").setValue(T_submit_delete);
buttons.addButton("submit_cancel").setValue(T_submit_cancel);
deleted.addHidden("administrative-continue").setValue(knot.getId());
}
}

View File

@@ -0,0 +1,160 @@
/*
* DeleteMetadataFieldsConfirm.java
*
* Version: $Revision: 1.0 $
*
* Date: $Date: 2006/07/13 23:20:54 $
*
* Copyright (c) 2002, Hewlett-Packard Company and Massachusetts
* Institute of Technology. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* - 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.
*
* - Neither the name of the Hewlett-Packard Company nor the name of the
* Massachusetts Institute of Technology nor the names of their
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS 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 COPYRIGHT
* HOLDERS OR 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.
*/
package org.dspace.app.xmlui.aspect.administrative.registries;
import java.sql.SQLException;
import java.util.ArrayList;
import org.dspace.app.xmlui.cocoon.AbstractDSpaceTransformer;
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.PageMeta;
import org.dspace.app.xmlui.wing.element.Para;
import org.dspace.app.xmlui.wing.element.Row;
import org.dspace.app.xmlui.wing.element.Table;
import org.dspace.authorize.AuthorizeException;
import org.dspace.content.MetadataField;
import org.dspace.content.MetadataSchema;
/**
* Prompt the user with a list of to-be-deleted metadata fields and
* ask the user if they are sure they want them deleted.
*
* @author Scott phillips
*/
public class DeleteMetadataFieldsConfirm extends AbstractDSpaceTransformer
{
/** Language Strings */
private static final Message T_dspace_home =
message("xmlui.general.dspace_home");
private static final Message T_submit_delete =
message("xmlui.general.delete");
private static final Message T_submit_cancel =
message("xmlui.general.cancel");
private static final Message T_title =
message("xmlui.administrative.registries.DeleteMetadataFieldsConfirm.title");
private static final Message T_metadata_registry_trail =
message("xmlui.administrative.registries.general.metadata_registry_trail");
private static final Message T_trail =
message("xmlui.administrative.registries.DeleteMetadataFieldsConfirm.trail");
private static final Message T_head =
message("xmlui.administrative.registries.DeleteMetadataFieldsConfirm.head");
private static final Message T_para1 =
message("xmlui.administrative.registries.DeleteMetadataFieldsConfirm.para1");
private static final Message T_warning =
message("xmlui.administrative.registries.DeleteMetadataFieldsConfirm.warning");
private static final Message T_para2 =
message("xmlui.administrative.registries.DeleteMetadataFieldsConfirm.para2");
private static final Message T_column1 =
message("xmlui.administrative.registries.DeleteMetadataFieldsConfirm.column1");
private static final Message T_column2 =
message("xmlui.administrative.registries.DeleteMetadataFieldsConfirm.column2");
private static final Message T_column3 =
message("xmlui.administrative.registries.DeleteMetadataFieldsConfirm.column3");
public void addPageMeta(PageMeta pageMeta) throws WingException
{
pageMeta.addMetadata("title").addContent(T_title);
pageMeta.addTrailLink(contextPath + "/", T_dspace_home);
pageMeta.addTrailLink(contextPath + "/admin/metadata-registry",T_metadata_registry_trail);
pageMeta.addTrail().addContent(T_trail);
}
public void addBody(Body body) throws WingException, SQLException, AuthorizeException
{
// Get all our parameters
String idsString = parameters.getParameter("fieldIDs", null);
ArrayList<MetadataField> fields = new ArrayList<MetadataField>();
for (String id : idsString.split(","))
{
MetadataField field = MetadataField.find(context,Integer.valueOf(id));
fields.add(field);
}
// DIVISION: metadata-field-confirm-delete
Division deleted = body.addInteractiveDivision("metadata-field-confirm-delete",contextPath+"/admin/metadata-registry",Division.METHOD_POST,"primary administrative metadata-registry");
deleted.setHead(T_head);
deleted.addPara(T_para1);
Para warning = deleted.addPara();
warning.addHighlight("bold").addContent(T_warning);
warning.addContent(T_para2);
Table table = deleted.addTable("field-confirm-delete",fields.size() + 1, 3);
Row header = table.addRow(Row.ROLE_HEADER);
header.addCell().addContent(T_column1);
header.addCell().addContent(T_column2);
header.addCell().addContent(T_column3);
for (MetadataField field : fields)
{
if (field == null)
continue;
String fieldID = String.valueOf(field.getFieldID());
String fieldEelement = field.getElement();
String fieldQualifier = field.getQualifier();
MetadataSchema schema = MetadataSchema.find(context, field.getSchemaID());
String schemaName = schema.getName();
String fieldName = schemaName +"."+ fieldEelement;
if (fieldQualifier != null && fieldQualifier.length() > 0)
fieldName += "."+fieldQualifier;
String fieldScopeNote = field.getScopeNote();
Row row = table.addRow();
row.addCell().addContent(fieldID);
row.addCell().addContent(fieldName);
row.addCell().addContent(fieldScopeNote);
}
Para buttons = deleted.addPara();
buttons.addButton("submit_confirm").setValue(T_submit_delete);
buttons.addButton("submit_cancel").setValue(T_submit_cancel);
deleted.addHidden("administrative-continue").setValue(knot.getId());
}
}

View File

@@ -0,0 +1,141 @@
/*
* DeleteMetadataSchemaConfirm.java
*
* Version: $Revision: 1.0 $
*
* Date: $Date: 2006/07/13 23:20:54 $
*
* Copyright (c) 2002, Hewlett-Packard Company and Massachusetts
* Institute of Technology. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* - 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.
*
* - Neither the name of the Hewlett-Packard Company nor the name of the
* Massachusetts Institute of Technology nor the names of their
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS 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 COPYRIGHT
* HOLDERS OR 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.
*/
package org.dspace.app.xmlui.aspect.administrative.registries;
import java.sql.SQLException;
import java.util.ArrayList;
import org.dspace.app.xmlui.cocoon.AbstractDSpaceTransformer;
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.PageMeta;
import org.dspace.app.xmlui.wing.element.Para;
import org.dspace.app.xmlui.wing.element.Row;
import org.dspace.app.xmlui.wing.element.Table;
import org.dspace.authorize.AuthorizeException;
import org.dspace.content.MetadataSchema;
/**
* Prompt the user to determin if they really want to delete the displayed schemas.
*
* @author Scott phillips
*/
public class DeleteMetadataSchemaConfirm extends AbstractDSpaceTransformer
{
/** Language Strings */
private static final Message T_dspace_home =
message("xmlui.general.dspace_home");
private static final Message T_title =
message("xmlui.administrative.registries.DeleteMetadataSchemaConfirm.title");
private static final Message T_metadata_registry_trail =
message("xmlui.administrative.registries.general.metadata_registry_trail");
private static final Message T_trail =
message("xmlui.administrative.registries.DeleteMetadataSchemaConfirm.trail");
private static final Message T_head =
message("xmlui.administrative.registries.DeleteMetadataSchemaConfirm.head");
private static final Message T_para1 =
message("xmlui.administrative.registries.DeleteMetadataSchemaConfirm.para1");
private static final Message T_warning =
message("xmlui.administrative.registries.DeleteMetadataSchemaConfirm.warning");
private static final Message T_para2 =
message("xmlui.administrative.registries.DeleteMetadataSchemaConfirm.para2");
private static final Message T_column1 =
message("xmlui.administrative.registries.DeleteMetadataSchemaConfirm.column1");
private static final Message T_column2 =
message("xmlui.administrative.registries.DeleteMetadataSchemaConfirm.column2");
private static final Message T_column3 =
message("xmlui.administrative.registries.DeleteMetadataSchemaConfirm.column3");
private static final Message T_submit_delete =
message("xmlui.general.delete");
private static final Message T_submit_cancel =
message("xmlui.general.cancel");
public void addPageMeta(PageMeta pageMeta) throws WingException
{
pageMeta.addMetadata("title").addContent(T_title);
pageMeta.addTrailLink(contextPath + "/", T_dspace_home);
pageMeta.addTrailLink(contextPath + "/admin/metadata-registry",T_metadata_registry_trail);
pageMeta.addTrail().addContent(T_trail);
}
public void addBody(Body body) throws WingException, SQLException, AuthorizeException
{
// Get all our parameters
String idsString = parameters.getParameter("schemaIDs", null);
ArrayList<MetadataSchema> schemas = new ArrayList<MetadataSchema>();
for (String id : idsString.split(","))
{
MetadataSchema schema = MetadataSchema.find(context,Integer.valueOf(id));
schemas.add(schema);
}
// DIVISION: metadata-schema-confirm-delete
Division deleted = body.addInteractiveDivision("metadata-schema-confirm-delete",contextPath+"/admin/metadata-registry",Division.METHOD_POST,"primary administrative metadata-registry");
deleted.setHead(T_head);
deleted.addPara(T_para1);
Para warning = deleted.addPara();
warning.addHighlight("bold").addContent(T_warning);
warning.addContent(T_para2);
Table table = deleted.addTable("schema-confirm-delete",schemas.size() + 1, 3);
Row header = table.addRow(Row.ROLE_HEADER);
header.addCell().addContent(T_column1);
header.addCell().addContent(T_column2);
header.addCell().addContent(T_column3);
for (MetadataSchema schema : schemas)
{
Row row = table.addRow();
row.addCell().addContent(schema.getSchemaID());
row.addCell().addContent(schema.getNamespace());
row.addCell().addContent(schema.getName());
}
Para buttons = deleted.addPara();
buttons.addButton("submit_confirm").setValue(T_submit_delete);
buttons.addButton("submit_cancel").setValue(T_submit_cancel);
deleted.addHidden("administrative-continue").setValue(knot.getId());
}
}

View File

@@ -0,0 +1,244 @@
/*
* EditBitstreamFormat.java
*
* Version: $Revision: 1.0 $
*
* Date: $Date: 2006/07/13 23:20:54 $
*
* Copyright (c) 2002, Hewlett-Packard Company and Massachusetts
* Institute of Technology. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* - 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.
*
* - Neither the name of the Hewlett-Packard Company nor the name of the
* Massachusetts Institute of Technology nor the names of their
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS 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 COPYRIGHT
* HOLDERS OR 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.
*/
package org.dspace.app.xmlui.aspect.administrative.registries;
import java.sql.SQLException;
import java.util.ArrayList;
import org.apache.cocoon.environment.ObjectModelHelper;
import org.apache.cocoon.environment.Request;
import org.dspace.app.xmlui.cocoon.AbstractDSpaceTransformer;
import org.dspace.app.xmlui.utils.RequestUtils;
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.CheckBox;
import org.dspace.app.xmlui.wing.element.Division;
import org.dspace.app.xmlui.wing.element.Item;
import org.dspace.app.xmlui.wing.element.List;
import org.dspace.app.xmlui.wing.element.PageMeta;
import org.dspace.app.xmlui.wing.element.Select;
import org.dspace.app.xmlui.wing.element.Text;
import org.dspace.app.xmlui.wing.element.TextArea;
import org.dspace.content.BitstreamFormat;
/**
* Enable the user to edit a bitstream format's metadata.
*
* @author Scott Phillips
*/
public class EditBitstreamFormat extends AbstractDSpaceTransformer
{
/** Language Strings */
private static final Message T_dspace_home =
message("xmlui.general.dspace_home");
private static final Message T_title =
message("xmlui.administrative.registries.EditBitstreamFormat.title");
private static final Message T_format_registry_trail =
message("xmlui.administrative.registries.general.format_registry_trail");
private static final Message T_trail =
message("xmlui.administrative.registries.EditBitstreamFormat.trail");
private static final Message T_head1 =
message("xmlui.administrative.registries.EditBitstreamFormat.head1");
private static final Message T_head2 =
message("xmlui.administrative.registries.EditBitstreamFormat.head2");
private static final Message T_para1 =
message("xmlui.administrative.registries.EditBitstreamFormat.para1");
private static final Message T_name =
message("xmlui.administrative.registries.EditBitstreamFormat.name");
private static final Message T_name_help =
message("xmlui.administrative.registries.EditBitstreamFormat.name_help");
private static final Message T_name_error =
message("xmlui.administrative.registries.EditBitstreamFormat.name_error");
private static final Message T_mimetype =
message("xmlui.administrative.registries.EditBitstreamFormat.mimetype");
private static final Message T_mimetype_help =
message("xmlui.administrative.registries.EditBitstreamFormat.mimetype_help");
private static final Message T_description =
message("xmlui.administrative.registries.EditBitstreamFormat.description");
private static final Message T_support =
message("xmlui.administrative.registries.EditBitstreamFormat.support");
private static final Message T_support_help =
message("xmlui.administrative.registries.EditBitstreamFormat.support_help");
private static final Message T_support_0 =
message("xmlui.administrative.registries.EditBitstreamFormat.support_0");
private static final Message T_support_1 =
message("xmlui.administrative.registries.EditBitstreamFormat.support_1");
private static final Message T_support_2 =
message("xmlui.administrative.registries.EditBitstreamFormat.support_2");
private static final Message T_internal =
message("xmlui.administrative.registries.EditBitstreamFormat.internal");
private static final Message T_internal_help =
message("xmlui.administrative.registries.EditBitstreamFormat.internal_help");
private static final Message T_extensions =
message("xmlui.administrative.registries.EditBitstreamFormat.extensions");
private static final Message T_extensions_help =
message("xmlui.administrative.registries.EditBitstreamFormat.extensions_help");
private static final Message T_submit_save =
message("xmlui.general.save");
private static final Message T_submit_cancel =
message("xmlui.general.cancel");
public void addPageMeta(PageMeta pageMeta) throws WingException
{
pageMeta.addMetadata("title").addContent(T_title);
pageMeta.addTrailLink(contextPath + "/", T_dspace_home);
pageMeta.addTrailLink(contextPath + "/admin/format-registry",T_format_registry_trail);
pageMeta.addTrail().addContent(T_trail);
}
public void addBody(Body body) throws WingException, SQLException
{
// Get our parameters & state
int formatID = parameters.getParameterAsInteger("formatID",-1);
BitstreamFormat format = null;
if (formatID >= 0)
format = BitstreamFormat.find(context,formatID);
String errorString = parameters.getParameter("errors",null);
ArrayList<String> errors = new ArrayList<String>();
if (errorString != null)
for (String error : errorString.split(","))
errors.add(error);
Request request = ObjectModelHelper.getRequest(objectModel);
String mimetypeValue = request.getParameter("mimetype");
String nameValue = request.getParameter("short_description");
String descriptionValue = request.getParameter("description");
String supportLevelValue = request.getParameter("support_level");
String internalValue = request.getParameter("internal");
java.util.List<String> extensionsList = RequestUtils.getFieldValues(request, "extensions");
String[] extensionValues = extensionsList.toArray(new String[extensionsList.size()]);
// Remove leading periods from file extensions.
for (int i = 0; i < extensionValues.length; i++)
if (extensionValues[i].startsWith("."))
extensionValues[i] = extensionValues[i].substring(1);
if (format != null)
{
if (mimetypeValue == null)
mimetypeValue = format.getMIMEType();
if (nameValue == null)
nameValue = format.getShortDescription();
if (descriptionValue == null)
descriptionValue = format.getDescription();
if (supportLevelValue == null)
supportLevelValue = String.valueOf(format.getSupportLevel());
if (request.getParameter("mimetype") == null)
internalValue = format.isInternal() ? "true" : null;
if (request.getParameter("extensions") == null)
extensionValues = format.getExtensions();
}
// DIVISION: edit-bitstream-format
Division main = body.addInteractiveDivision("edit-bitstream-format",contextPath+"/admin/format-registry",Division.METHOD_POST,"primary administrative format-registry");
if (formatID == -1)
main.setHead(T_head1);
else
main.setHead(T_head2.parameterize(nameValue));
main.addPara(T_para1);
List form = main.addList("edit-bitstream-format",List.TYPE_FORM);
Text name = form.addItem().addText("short_description");
name.setRequired();
name.setLabel(T_name);
name.setHelp(T_name_help);
name.setValue(nameValue);
name.setSize(35);
if (errors.contains("short_description"))
name.addError(T_name_error);
Text mimeType = form.addItem().addText("mimetype");
mimeType.setLabel(T_mimetype);
mimeType.setHelp(T_mimetype_help);
mimeType.setValue(mimetypeValue);
mimeType.setSize(35);
// Do not allow anyone to change the name of the unknown format.
if (format != null && format.getID() == 1)
name.setDisabled();
TextArea description = form.addItem().addTextArea("description");
description.setLabel(T_description);
description.setValue(descriptionValue);
description.setSize(3, 35);
Select supportLevel = form.addItem().addSelect("support_level");
supportLevel.setLabel(T_support);
supportLevel.setHelp(T_support_help);
supportLevel.addOption(0,T_support_0);
supportLevel.addOption(1,T_support_1);
supportLevel.addOption(2,T_support_2);
supportLevel.setOptionSelected(supportLevelValue);
CheckBox internal = form.addItem().addCheckBox("internal");
internal.setLabel(T_internal);
internal.setHelp(T_internal_help);
internal.addOption((internalValue != null),"true");
Text extensions = form.addItem().addText("extensions");
extensions.setLabel(T_extensions);
extensions.setHelp(T_extensions_help);
extensions.enableAddOperation();
extensions.enableDeleteOperation();
for (String extensionValue : extensionValues)
{
extensions.addInstance().setValue(extensionValue);
}
Item actions = form.addItem();
actions.addButton("submit_save").setValue(T_submit_save);
actions.addButton("submit_cancel").setValue(T_submit_cancel);
main.addHidden("administrative-continue").setValue(knot.getId());
}
}

View File

@@ -0,0 +1,400 @@
/*
* EditMetadataSchema.java
*
* Version: $Revision: 1.0 $
*
* Date: $Date: 2006/07/13 23:20:54 $
*
* Copyright (c) 2002, Hewlett-Packard Company and Massachusetts
* Institute of Technology. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* - 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.
*
* - Neither the name of the Hewlett-Packard Company nor the name of the
* Massachusetts Institute of Technology nor the names of their
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS 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 COPYRIGHT
* HOLDERS OR 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.
*/
package org.dspace.app.xmlui.aspect.administrative.registries;
import java.sql.SQLException;
import java.util.ArrayList;
import org.apache.cocoon.environment.ObjectModelHelper;
import org.apache.cocoon.environment.Request;
import org.dspace.app.xmlui.cocoon.AbstractDSpaceTransformer;
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.CheckBox;
import org.dspace.app.xmlui.wing.element.Division;
import org.dspace.app.xmlui.wing.element.Highlight;
import org.dspace.app.xmlui.wing.element.Item;
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.Row;
import org.dspace.app.xmlui.wing.element.Table;
import org.dspace.app.xmlui.wing.element.Text;
import org.dspace.app.xmlui.wing.element.TextArea;
import org.dspace.content.MetadataField;
import org.dspace.content.MetadataSchema;
/**
* Edit a metadata schema by: listing all the existing fields in
* the schema, prompt the user to add a new field. If a current
* field is selected then the field may be updated in the same
* place where new field addition would be.
*
* @author Scott Phillips
*/
public class EditMetadataSchema extends AbstractDSpaceTransformer
{
/** Language Strings */
private static final Message T_dspace_home =
message("xmlui.general.dspace_home");
private static final Message T_title =
message("xmlui.administrative.registries.EditMetadataSchema.title");
private static final Message T_metadata_registry_trail =
message("xmlui.administrative.registries.general.metadata_registry_trail");
private static final Message T_trail =
message("xmlui.administrative.registries.EditMetadataSchema.trail");
private static final Message T_head1 =
message("xmlui.administrative.registries.EditMetadataSchema.head1");
private static final Message T_para1 =
message("xmlui.administrative.registries.EditMetadataSchema.para1");
private static final Message T_head2 =
message("xmlui.administrative.registries.EditMetadataSchema.head2");
private static final Message T_column1 =
message("xmlui.administrative.registries.EditMetadataSchema.column1");
private static final Message T_column2 =
message("xmlui.administrative.registries.EditMetadataSchema.column2");
private static final Message T_column3 =
message("xmlui.administrative.registries.EditMetadataSchema.column3");
private static final Message T_column4 =
message("xmlui.administrative.registries.EditMetadataSchema.column4");
private static final Message T_empty =
message("xmlui.administrative.registries.EditMetadataSchema.empty");
private static final Message T_submit_return =
message("xmlui.general.return");
private static final Message T_submit_delete =
message("xmlui.administrative.registries.EditMetadataSchema.submit_delete");
private static final Message T_submit_move =
message("xmlui.administrative.registries.EditMetadataSchema.submit_move");
private static final Message T_head3 =
message("xmlui.administrative.registries.EditMetadataSchema.head3");
private static final Message T_name =
message("xmlui.administrative.registries.EditMetadataSchema.name");
private static final Message T_note =
message("xmlui.administrative.registries.EditMetadataSchema.note");
private static final Message T_note_help =
message("xmlui.administrative.registries.EditMetadataSchema.note_help");
private static final Message T_submit_add =
message("xmlui.administrative.registries.EditMetadataSchema.submit_add");
private static final Message T_head4 =
message("xmlui.administrative.registries.EditMetadataSchema.head4");
private static final Message T_submit_update =
message("xmlui.administrative.registries.EditMetadataSchema.submit_update");
private static final Message T_submit_cancel =
message("xmlui.general.cancel");
private static final Message T_error =
message("xmlui.administrative.registries.EditMetadataSchema.error");
private static final Message T_error_duplicate_field =
message("xmlui.administrative.registries.EditMetadataSchema.error_duplicate_field");
private static final Message T_error_element_empty =
message("xmlui.administrative.registries.EditMetadataSchema.error_element_empty");
private static final Message T_error_element_badchar =
message("xmlui.administrative.registries.EditMetadataSchema.error_element_badchar");
private static final Message T_error_element_tolong =
message("xmlui.administrative.registries.EditMetadataSchema.error_element_tolong");
private static final Message T_error_qualifier_tolong =
message("xmlui.administrative.registries.EditMetadataSchema.error_qualifier_tolong");
private static final Message T_error_qualifier_badchar =
message("xmlui.administrative.registries.EditMetadataSchema.error_qualifier_badchar");
public void addPageMeta(PageMeta pageMeta) throws WingException
{
pageMeta.addMetadata("title").addContent(T_title);
pageMeta.addTrailLink(contextPath + "/",T_dspace_home);
pageMeta.addTrailLink(contextPath + "/admin/metadata-registry",T_metadata_registry_trail);
pageMeta.addTrail().addContent(T_trail);
}
public void addBody(Body body) throws WingException, SQLException
{
// Get our parameters & state
int schemaID = parameters.getParameterAsInteger("schemaID",-1);
int updateID = parameters.getParameterAsInteger("updateID",-1);
int highlightID = parameters.getParameterAsInteger("highlightID",-1);
MetadataSchema schema = MetadataSchema.find(context,schemaID);
MetadataField[] fields = MetadataField.findAllInSchema(context, schemaID);
String schemaName = schema.getName();
String schemaNamespace = schema.getNamespace();
String errorString = parameters.getParameter("errors",null);
ArrayList<String> errors = new ArrayList<String>();
if (errorString != null)
{
for (String error : errorString.split(","))
errors.add(error);
}
// DIVISION: edit-schema
Division main = body.addInteractiveDivision("metadata-schema-edit",contextPath+"/admin/metadata-registry",Division.METHOD_POST,"primary administrative metadata-registry");
main.setHead(T_head1.parameterize(schemaName));
main.addPara(T_para1.parameterize(schemaNamespace));
// DIVISION: add or updating a metadata field
if (updateID >= 0)
// Updating an existing field
addUpdateFieldForm(main, schemaName, updateID, errors);
else
// Add a new field
addNewFieldForm(main, schemaName, errors);
// DIVISION: existing fields
Division existingFields = main.addDivision("metadata-schema-edit-existing-fields");
existingFields.setHead(T_head2);
Table table = existingFields.addTable("metadata-schema-edit-existing-fields", fields.length+1, 5);
Row header = table.addRow(Row.ROLE_HEADER);
header.addCellContent(T_column1);
header.addCellContent(T_column2);
header.addCellContent(T_column3);
header.addCellContent(T_column4);
for (MetadataField field : fields)
{
String id = String.valueOf(field.getFieldID());
String fieldElement = field.getElement();
String fieldQualifier = field.getQualifier();
String fieldName = schemaName +"."+ fieldElement;
if (fieldQualifier != null && fieldQualifier.length() > 0)
fieldName += "."+fieldQualifier;
boolean highlight = false;
if (field.getFieldID() == highlightID)
highlight = true;
String fieldScopeNote = field.getScopeNote();
String url = contextPath + "/admin/metadata-registry?administrative-continue="+knot.getId()+"&submit_edit&fieldID="+id;
Row row;
if (highlight)
row = table.addRow(null,null,"highlight");
else
row = table.addRow();
CheckBox select = row.addCell().addCheckBox("select_field");
select.setLabel(id);
select.addOption(id);
row.addCell().addContent(id);
row.addCell().addXref(url,fieldName);
row.addCell().addContent(fieldScopeNote);
}
if (fields.length == 0)
{
// No fields, let the user know.
table.addRow().addCell(1,4).addHighlight("italic").addContent(T_empty);
main.addPara().addButton("submit_return").setValue(T_submit_return);
}
else
{
// Only show the actions if there are fields available to preform them on.
Para actions = main.addPara();
actions.addButton("submit_delete").setValue(T_submit_delete);
if (MetadataSchema.findAll(context).length > 1)
actions.addButton("submit_move").setValue(T_submit_move);
actions.addButton("submit_return").setValue(T_submit_return);
}
main.addHidden("administrative-continue").setValue(knot.getId());
}
/**
* Add a form prompting the user to add a new field to the this schema.
*
* @param div The division to add the form too.
* @param schemaName The schemaName currently being operated on.
* @param errors A list of errors from previous attempts at adding new fields.
*/
public void addNewFieldForm(Division div, String schemaName, ArrayList<String> errors) throws WingException
{
Request request = ObjectModelHelper.getRequest(objectModel);
String elementValue = request.getParameter("newElement");
String qualifierValue = request.getParameter("newQualifier");
String noteValue = request.getParameter("newNote");
Division newField = div.addDivision("edit-schema-new-field");
newField.setHead(T_head3);
List form = newField.addList("edit-schema-new-field-form",List.TYPE_FORM);
addFieldErrors(form, errors);
form.addLabel(T_name);
Highlight item =form.addItem().addHighlight("big");
item.addContent(schemaName+" . ");
Text element = item.addText("newElement");
item.addContent(" . ");
Text qualifier = item.addText("newQualifier");
element.setSize(15);
element.setValue(elementValue);
qualifier.setSize(15);
qualifier.setValue(qualifierValue);
TextArea scopeNote =form.addItem().addTextArea("newNote");
scopeNote.setLabel(T_note);
scopeNote.setHelp(T_note_help);
scopeNote.setSize(2, 35);
scopeNote.setValue(noteValue);
form.addItem().addButton("submit_add").setValue(T_submit_add);
}
/**
* Update an existing field by promting the user for it's values.
*
* @param div The division to add the form too.
* @param schemaName The schemaName currently being operated on.
* @param fieldID The id of the field being updated.
* @param errors A list of errors from previous attempts at updaating the field.
*/
public void addUpdateFieldForm(Division div, String schemaName, int fieldID, ArrayList<String> errors) throws WingException, SQLException
{
MetadataField field = MetadataField.find(context, fieldID);
Request request = ObjectModelHelper.getRequest(objectModel);
String elementValue = request.getParameter("updateElement");
String qualifierValue = request.getParameter("updateQualifier");
String noteValue = request.getParameter("updateNote");
if (elementValue == null)
elementValue = field.getElement();
if (qualifierValue == null)
qualifierValue = field.getQualifier();
if (noteValue == null)
noteValue = field.getScopeNote();
Division newField = div.addDivision("edit-schema-update-field");
newField.setHead(T_head4.parameterize(field.getFieldID()));
List form = newField.addList("edit-schema-update-field-form",List.TYPE_FORM);
addFieldErrors(form, errors);
form.addLabel(T_name);
Highlight item =form.addItem().addHighlight("big");
item.addContent(schemaName+" . ");
Text element = item.addText("updateElement");
item.addContent(" . ");
Text qualifier = item.addText("updateQualifier");
element.setSize(13);
element.setValue(elementValue);
qualifier.setSize(13);
qualifier.setValue(qualifierValue);
TextArea scopeNote =form.addItem().addTextArea("updateNote");
scopeNote.setLabel(T_note);
scopeNote.setHelp(T_note_help);
scopeNote.setSize(2, 35);
scopeNote.setValue(noteValue);
Item actions = form.addItem();
actions.addButton("submit_update").setValue(T_submit_update);
actions.addButton("submit_cancel").setValue(T_submit_cancel);
}
/**
* Determine if there were any special errors and display approparte
* text. Because of the inline nature of the element and qualifier
* fields these errors can not be placed on the field. Instead they
* have to be added as seperate items above the field.
*
* @param form The form to add errors to.
* @param errors A list of errors.
*/
public void addFieldErrors(List form, ArrayList<String> errors) throws WingException
{
if (errors.contains("duplicate_field"))
{
form.addLabel(T_error);
form.addItem(T_error_duplicate_field);
}
if (errors.contains("element_empty"))
{
form.addLabel(T_error);
form.addItem(T_error_element_empty);
}
if (errors.contains("element_badchar"))
{
form.addLabel(T_error);
form.addItem(T_error_element_badchar);
}
if (errors.contains("element_tolong"))
{
form.addLabel(T_error);
form.addItem(T_error_element_tolong);
}
if (errors.contains("qualifier_tolong"))
{
form.addLabel(T_error);
form.addItem(T_error_qualifier_tolong);
}
if (errors.contains("qualifier_badchar"))
{
form.addLabel(T_error);
form.addItem(T_error_qualifier_badchar);
}
}
}

View File

@@ -0,0 +1,196 @@
/*
* FormatRegistryMain.java
*
* Version: $Revision: 1.0 $
*
* Date: $Date: 2006/07/13 23:20:54 $
*
* Copyright (c) 2002, Hewlett-Packard Company and Massachusetts
* Institute of Technology. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* - 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.
*
* - Neither the name of the Hewlett-Packard Company nor the name of the
* Massachusetts Institute of Technology nor the names of their
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS 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 COPYRIGHT
* HOLDERS OR 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.
*/
package org.dspace.app.xmlui.aspect.administrative.registries;
import java.sql.SQLException;
import org.dspace.app.xmlui.cocoon.AbstractDSpaceTransformer;
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.CheckBox;
import org.dspace.app.xmlui.wing.element.Division;
import org.dspace.app.xmlui.wing.element.PageMeta;
import org.dspace.app.xmlui.wing.element.Row;
import org.dspace.app.xmlui.wing.element.Table;
import org.dspace.content.BitstreamFormat;
/**
* Main management page for bitstream formats, this page lists all known formats
* enabling the user to add more, updating existing, or delete formats.
*
* @author Scott Phillips
*/
public class FormatRegistryMain extends AbstractDSpaceTransformer
{
/** Language Strings */
private static final Message T_dspace_home =
message("xmlui.general.dspace_home");
private static final Message T_title =
message("xmlui.administrative.registries.FormatRegistryMain.title");
private static final Message T_format_registry_trail =
message("xmlui.administrative.registries.general.format_registry_trail");
private static final Message T_head =
message("xmlui.administrative.registries.FormatRegistryMain.head");
private static final Message T_para1 =
message("xmlui.administrative.registries.FormatRegistryMain.para1");
private static final Message T_new_link =
message("xmlui.administrative.registries.FormatRegistryMain.new_link");
private static final Message T_column1 =
message("xmlui.administrative.registries.FormatRegistryMain.column1");
private static final Message T_column2 =
message("xmlui.administrative.registries.FormatRegistryMain.column2");
private static final Message T_column3 =
message("xmlui.administrative.registries.FormatRegistryMain.column3");
private static final Message T_column4 =
message("xmlui.administrative.registries.FormatRegistryMain.column4");
private static final Message T_column5 =
message("xmlui.administrative.registries.FormatRegistryMain.column5");
private static final Message T_internal =
message("xmlui.administrative.registries.FormatRegistryMain.internal");
private static final Message T_support_0 =
message("xmlui.administrative.registries.FormatRegistryMain.support_0");
private static final Message T_support_1 =
message("xmlui.administrative.registries.FormatRegistryMain.support_1");
private static final Message T_support_2 =
message("xmlui.administrative.registries.FormatRegistryMain.support_2");
private static final Message T_submit_delete =
message("xmlui.administrative.registries.FormatRegistryMain.submit_delete");
public void addPageMeta(PageMeta pageMeta) throws WingException
{
pageMeta.addMetadata("title").addContent(T_title);
pageMeta.addTrailLink(contextPath + "/",T_dspace_home);
pageMeta.addTrailLink(contextPath + "/admin/format-registry",T_format_registry_trail);
}
public void addBody(Body body) throws WingException, SQLException
{
// Get our parameters & state
int highlightID = parameters.getParameterAsInteger("highlightID",-1);
BitstreamFormat[] formats = BitstreamFormat.findAll(context);
String addURL = contextPath+"/admin/format-registry?administrative-continue="+knot.getId()+"&submit_add";
// DIVISION: bitstream-format-registry
Division main = body.addInteractiveDivision("bitstream-format-registry",contextPath+"/admin/format-registry",Division.METHOD_POST,"primary administrative format-registry");
main.setHead(T_head);
main.addPara(T_para1);
main.addPara().addXref(addURL,T_new_link);
Table table = main.addTable("bitstream-format-registry", formats.length+1, 5);
Row header = table.addRow(Row.ROLE_HEADER);
header.addCellContent(T_column1);
header.addCellContent(T_column2);
header.addCellContent(T_column3);
header.addCellContent(T_column4);
header.addCellContent(T_column5);
for (BitstreamFormat format : formats)
{
String id = String.valueOf(format.getID());
String mimeType = format.getMIMEType();
String name = format.getShortDescription();
int supportLevel = format.getSupportLevel();
boolean internal = format.isInternal();
boolean highlight = false;
if (format.getID() == highlightID)
highlight = true;
String url = contextPath + "/admin/format-registry?administrative-continue="+knot.getId()+"&submit_edit&formatID="+id;
Row row;
if (highlight)
row = table.addRow(null,null,"highlight");
else
row = table.addRow();
// Select checkbox
Cell cell = row.addCell();
if (format.getID() > 1)
{
// Do not allow unknown to be removed.
CheckBox select = cell.addCheckBox("select_format");
select.setLabel(id);
select.addOption(id);
}
// ID
row.addCell().addContent(id);
// Name
row.addCell().addXref(url,name);
// Mime type
cell = row.addCell();
cell.addXref(url,mimeType);
if (internal)
{
cell.addContent(" ");
cell.addContent(T_internal);
}
// support level
switch (supportLevel)
{
case 0:
row.addCell().addXref(url,T_support_0); break;
case 1:
row.addCell().addXref(url,T_support_1); break;
case 2:
row.addCell().addXref(url,T_support_2); break;
}
}
main.addPara().addButton("submit_delete").setValue(T_submit_delete);
main.addHidden("administrative-continue").setValue(knot.getId());
}
}

View File

@@ -0,0 +1,209 @@
/*
* MetadataRegistryMain.java
*
* Version: $Revision: 1.0 $
*
* Date: $Date: 2006/07/13 23:20:54 $
*
* Copyright (c) 2002, Hewlett-Packard Company and Massachusetts
* Institute of Technology. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* - 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.
*
* - Neither the name of the Hewlett-Packard Company nor the name of the
* Massachusetts Institute of Technology nor the names of their
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS 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 COPYRIGHT
* HOLDERS OR 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.
*/
package org.dspace.app.xmlui.aspect.administrative.registries;
import java.sql.SQLException;
import java.util.ArrayList;
import org.apache.cocoon.environment.ObjectModelHelper;
import org.apache.cocoon.environment.Request;
import org.dspace.app.xmlui.cocoon.AbstractDSpaceTransformer;
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.CheckBox;
import org.dspace.app.xmlui.wing.element.Division;
import org.dspace.app.xmlui.wing.element.List;
import org.dspace.app.xmlui.wing.element.PageMeta;
import org.dspace.app.xmlui.wing.element.Row;
import org.dspace.app.xmlui.wing.element.Table;
import org.dspace.app.xmlui.wing.element.Text;
import org.dspace.content.MetadataSchema;
/**
* This is the main entry point for managing the metadata registry. This transformer
* shows the list of all current schemas and a form for adding new schema's to the
* registry.
*
* @author Scott Phillips
*/
public class MetadataRegistryMain extends AbstractDSpaceTransformer
{
/** Language Strings */
private static final Message T_dspace_home =
message("xmlui.general.dspace_home");
private static final Message T_title =
message("xmlui.administrative.registries.MetadataRegistryMain.title");
private static final Message T_metadata_registry_trail =
message("xmlui.administrative.registries.general.metadata_registry_trail");
private static final Message T_head1 =
message("xmlui.administrative.registries.MetadataRegistryMain.head1");
private static final Message T_para1 =
message("xmlui.administrative.registries.MetadataRegistryMain.para1");
private static final Message T_column1 =
message("xmlui.administrative.registries.MetadataRegistryMain.column1");
private static final Message T_column2 =
message("xmlui.administrative.registries.MetadataRegistryMain.column2");
private static final Message T_column3 =
message("xmlui.administrative.registries.MetadataRegistryMain.column3");
private static final Message T_column4 =
message("xmlui.administrative.registries.MetadataRegistryMain.column4");
private static final Message T_submit_delete =
message("xmlui.administrative.registries.MetadataRegistryMain.submit_delete");
private static final Message T_head2 =
message("xmlui.administrative.registries.MetadataRegistryMain.head2");
private static final Message T_namespace =
message("xmlui.administrative.registries.MetadataRegistryMain.namespace");
private static final Message T_namespace_help =
message("xmlui.administrative.registries.MetadataRegistryMain.namespace_help");
private static final Message T_namespace_error =
message("xmlui.administrative.registries.MetadataRegistryMain.namespace_error");
private static final Message T_name =
message("xmlui.administrative.registries.MetadataRegistryMain.name");
private static final Message T_name_help =
message("xmlui.administrative.registries.MetadataRegistryMain.name_help");
private static final Message T_name_error =
message("xmlui.administrative.registries.MetadataRegistryMain.name_error");
private static final Message T_submit_add =
message("xmlui.administrative.registries.MetadataRegistryMain.submit_add");
public void addPageMeta(PageMeta pageMeta) throws WingException
{
pageMeta.addMetadata("title").addContent(T_title);
pageMeta.addTrailLink(contextPath + "/", T_dspace_home);
pageMeta.addTrailLink(contextPath + "/admin/metadata-registry",T_metadata_registry_trail);
}
public void addBody(Body body) throws WingException, SQLException
{
// Get all our parameters first
Request request = ObjectModelHelper.getRequest(objectModel);
String namespaceValue = request.getParameter("namespace");
String nameValue = request.getParameter("name");
String errorString = parameters.getParameter("errors",null);
ArrayList<String> errors = new ArrayList<String>();
if (errorString != null)
{
for (String error : errorString.split(","))
errors.add(error);
}
MetadataSchema[] schemas = MetadataSchema.findAll(context);
// DIVISION: metadata-registry-main
Division main = body.addInteractiveDivision("metadata-registry-main",contextPath+"/admin/metadata-registry",Division.METHOD_POST,"primary administrative metadata-registry ");
main.setHead(T_head1);
main.addPara(T_para1);
Table table = main.addTable("metadata-registry-main-table", schemas.length+1, 5);
Row header = table.addRow(Row.ROLE_HEADER);
header.addCellContent(T_column1);
header.addCellContent(T_column2);
header.addCellContent(T_column3);
header.addCellContent(T_column4);
for (MetadataSchema schema : schemas)
{
int schemaID = schema.getSchemaID();
String namespace = schema.getNamespace();
String name = schema.getName();
String url = contextPath + "/admin/metadata-registry?administrative-continue="+knot.getId()+"&submit_edit&schemaID="+schemaID;
Row row = table.addRow();
if (schemaID > 1)
{
// If the schema is not in the required DC schema allow the user to delete it.
CheckBox select = row.addCell().addCheckBox("select_schema");
select.setLabel(String.valueOf(schemaID));
select.addOption(String.valueOf(schemaID));
}
else
{
// The DC schema can not be removed.
row.addCell();
}
row.addCell().addContent(schemaID);
row.addCell().addXref(url,namespace);
row.addCell().addXref(url,name);
}
if (schemas.length > 1)
{
// Only give the delete option if there are more schema's than the required dublin core.
main.addPara().addButton("submit_delete").setValue(T_submit_delete);
}
// DIVISION: add new schema
Division newSchema = main.addDivision("add-schema");
newSchema.setHead(T_head2);
List form = newSchema.addList("new-schema",List.TYPE_FORM);
Text namespace = form.addItem().addText("namespace");
namespace.setLabel(T_namespace);
namespace.setRequired();
namespace.setHelp(T_namespace_help);
if (namespaceValue != null)
namespace.setValue(namespaceValue);
if (errors.contains("namespace"))
namespace.addError(T_namespace_error);
Text name = form.addItem().addText("name");
name.setLabel(T_name);
name.setRequired();
name.setHelp(T_name_help);
if (nameValue != null)
name.setValue(nameValue);
if (errors.contains("name"))
name.addError(T_name_error);
form.addItem().addButton("submit_add").setValue(T_submit_add);
main.addHidden("administrative-continue").setValue(knot.getId());
}
}

View File

@@ -0,0 +1,167 @@
/*
* MoveMetadataFields.java
*
* Version: $Revision: 1.0 $
*
* Date: $Date: 2006/07/13 23:20:54 $
*
* Copyright (c) 2002, Hewlett-Packard Company and Massachusetts
* Institute of Technology. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* - 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.
*
* - Neither the name of the Hewlett-Packard Company nor the name of the
* Massachusetts Institute of Technology nor the names of their
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS 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 COPYRIGHT
* HOLDERS OR 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.
*/
package org.dspace.app.xmlui.aspect.administrative.registries;
import java.sql.SQLException;
import java.util.ArrayList;
import org.dspace.app.xmlui.cocoon.AbstractDSpaceTransformer;
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.PageMeta;
import org.dspace.app.xmlui.wing.element.Para;
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.authorize.AuthorizeException;
import org.dspace.content.MetadataField;
import org.dspace.content.MetadataSchema;
/**
* Show a list of selected fields, and prompt the user to enter a destination schema for these fields.
*
* @author Scott Phillips
*/
public class MoveMetadataFields extends AbstractDSpaceTransformer
{
/** Language Strings */
private static final Message T_dspace_home =
message("xmlui.general.dspace_home");
private static final Message T_title =
message("xmlui.administrative.registries.MoveMetadataField.title");
private static final Message T_metadata_registry_trail =
message("xmlui.administrative.registries.general.metadata_registry_trail");
private static final Message T_trail =
message("xmlui.administrative.registries.MoveMetadataField.trail");
private static final Message T_head1 =
message("xmlui.administrative.registries.MoveMetadataField.head1");
private static final Message T_para1 =
message("xmlui.administrative.registries.MoveMetadataField.para1");
private static final Message T_column1 =
message("xmlui.administrative.registries.MoveMetadataField.column1");
private static final Message T_column2 =
message("xmlui.administrative.registries.MoveMetadataField.column2");
private static final Message T_column3 =
message("xmlui.administrative.registries.MoveMetadataField.column3");
private static final Message T_para2 =
message("xmlui.administrative.registries.MoveMetadataField.para2");
private static final Message T_submit_move =
message("xmlui.administrative.registries.MoveMetadataField.submit_move");
private static final Message T_submit_cancel =
message("xmlui.administrative.registries.MoveMetadataField.submit_cancel");
public void addPageMeta(PageMeta pageMeta) throws WingException
{
pageMeta.addMetadata("title").addContent(T_title);
pageMeta.addTrailLink(contextPath + "/", T_dspace_home);
pageMeta.addTrailLink(contextPath + "/admin/metadata-registry",T_metadata_registry_trail);
pageMeta.addTrail().addContent(T_trail);
}
public void addBody(Body body) throws WingException, SQLException, AuthorizeException
{
// Get all our parameters
MetadataSchema[] schemas = MetadataSchema.findAll(context);
String idsString = parameters.getParameter("fieldIDs", null);
ArrayList<MetadataField> fields = new ArrayList<MetadataField>();
for (String id : idsString.split(","))
{
MetadataField field = MetadataField.find(context,Integer.valueOf(id));
fields.add(field);
}
// DIVISION: metadata-field-move
Division moved = body.addInteractiveDivision("metadata-field-move",contextPath+"/admin/metadata-registry",Division.METHOD_POST,"primary administrative metadata-registry");
moved.setHead(T_head1);
moved.addPara(T_para1);
Table table = moved.addTable("metadata-field-move",fields.size() + 1, 3);
Row header = table.addRow(Row.ROLE_HEADER);
header.addCell().addContent(T_column1);
header.addCell().addContent(T_column2);
header.addCell().addContent(T_column3);
for (MetadataField field : fields)
{
String fieldID = String.valueOf(field.getFieldID());
String fieldEelement = field.getElement();
String fieldQualifier = field.getQualifier();
MetadataSchema schema = MetadataSchema.find(context, field.getSchemaID());
String schemaName = schema.getName();
String fieldName = schemaName +"."+ fieldEelement;
if (fieldQualifier != null && fieldQualifier.length() > 0)
fieldName += "."+fieldQualifier;
String fieldScopeNote = field.getScopeNote();
Row row = table.addRow();
row.addCell().addContent(fieldID);
row.addCell().addContent(fieldName);
row.addCell().addContent(fieldScopeNote);
}
Row row = table.addRow();
Cell cell = row.addCell(1,3);
cell.addContent(T_para2);
Select toSchema = cell.addSelect("to_schema");
for (MetadataSchema schema : schemas)
{
toSchema.addOption(schema.getSchemaID(), schema.getNamespace());
}
Para buttons = moved.addPara();
buttons.addButton("submit_move").setValue(T_submit_move);
buttons.addButton("submit_cancel").setValue(T_submit_cancel);
moved.addHidden("administrative-continue").setValue(knot.getId());
}
}

View File

@@ -0,0 +1,374 @@
/*
* AbstractBrowse.java
*
* Version: $Revision: 1.2 $
*
* Date: $Date: 2006/04/25 15:24:23 $
*
* Copyright (c) 2002, Hewlett-Packard Company and Massachusetts
* Institute of Technology. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* - 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.
*
* - Neither the name of the Hewlett-Packard Company nor the name of the
* Massachusetts Institute of Technology nor the names of their
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS 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 COPYRIGHT
* HOLDERS OR 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.
*/
package org.dspace.app.xmlui.aspect.artifactbrowser;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.net.URLEncoder;
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.dspace.app.xmlui.cocoon.AbstractDSpaceTransformer;
import org.dspace.app.xmlui.utils.ContextUtil;
import org.dspace.app.xmlui.utils.HandleUtil;
import org.dspace.app.xmlui.utils.UIException;
import org.dspace.browse.Browse;
import org.dspace.browse.BrowseInfo;
import org.dspace.browse.BrowseScope;
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 org.dspace.core.Context;
import org.dspace.handle.HandleManager;
/**
* This is an abstract search page that may be specialized to the various forms:
* by titles, dates, or authors.
*
* FIXME: Needs Support browse by subject.
*
* @author Scott Phillips
* @author Paulo Jobim
*/
public class AbstractBrowse extends AbstractDSpaceTransformer
{
/** How many results should appear on one page? */
protected static final int RESULTS_PER_PAGE = 11;
/** The possible browsing modes */
protected static final int MODE_BY_TITLE = 1;
protected static final int MODE_BY_DATE = 2;
protected static final int MODE_BY_AUTHOR = 3;
protected static final int MODE_BY_AUTHOR_ITEM = 4;
protected static final int MODE_BY_SUBJECT = 5;
protected static final int MODE_BY_SUBJECT_ITEM = 6;
/**
* Browsing related parameters, the preformBrowse() method will
* determine these cached results.
*/
protected BrowseInfo browseInfo;
protected BrowseScope browseScope;
protected boolean browseItem;
/**
* Preform the browse for the given mode.
*
* @param mode
* The browsing mode.
*/
public void performBrowse(int mode) throws SQLException, UIException
{
// Check to see if we have the browse results cached.
if (this.browseInfo != null && this.browseScope != null)
return;
// We will resolve the HTTP request parameters into a scope
Context context = ContextUtil.obtainContext(objectModel);
Request request = ObjectModelHelper.getRequest(objectModel);
// HTTP Parameters
String top = request.getParameter("top");
String bottom = request.getParameter("bottom");
String startsWith = request.getParameter("startsWith");
String month = request.getParameter("month");
String year = request.getParameter("year");
String author = request.getParameter("author");
String subject = request.getParameter("subject");
try {
if (top != null)
top = URLDecoder.decode(top,Constants.DEFAULT_ENCODING);
if (bottom != null)
bottom = URLDecoder.decode(bottom,Constants.DEFAULT_ENCODING);
if (author != null)
author = URLDecoder.decode(author,Constants.DEFAULT_ENCODING);
if (subject != null)
subject = URLDecoder.decode(subject,Constants.DEFAULT_ENCODING);
}
catch (UnsupportedEncodingException uee)
{
throw new UIException("Unable to decode url parameters: top, bottom, subject or author.",uee);
}
// Buld the browse scope
BrowseScope scope = new BrowseScope(context);
scope.setTotal(RESULTS_PER_PAGE);
if (top != null && !"".equals(top))
{
if (mode == MODE_BY_AUTHOR || mode == MODE_BY_SUBJECT)
{
scope.setFocus(top);
scope.setNumberBefore(0);
}
else
{
Item item = (Item) HandleManager.resolveToObject(context, top);
scope.setFocus(item);
scope.setNumberBefore(0);
}
}
else if (bottom != null && !"".equals(bottom))
{
if (mode == MODE_BY_AUTHOR || mode == MODE_BY_SUBJECT)
{
scope.setFocus(bottom);
scope.setNumberBefore(RESULTS_PER_PAGE - 1);
}
else
{
Item item = (Item) HandleManager.resolveToObject(context, bottom);
scope.setFocus(item);
scope.setNumberBefore(RESULTS_PER_PAGE - 1);
}
}
else if (startsWith != null && !"".equals(startsWith))
{
scope.setFocus(startsWith);
scope.setNumberBefore(0);
}
else if (mode == MODE_BY_DATE && year != null
&& !"".equals(year))
{
if (month != null & !"-1".equals(month))
{
if (month.length() == 1)
month = "0" + month;
scope.setFocus(year + "-" + month);
scope.setNumberBefore(0);
}
else
{
scope.setFocus(year + "-01");
scope.setNumberBefore(0);
}
}
else if (mode == MODE_BY_AUTHOR_ITEM)
{
scope.setFocus(author);
}
else if (mode == MODE_BY_SUBJECT_ITEM)
{
scope.setFocus(subject);
}
// Are we in a community or collection?
DSpaceObject dso = HandleUtil.obtainHandle(objectModel);
if (dso instanceof Community)
scope.setScope((Community) dso);
if (dso instanceof Collection)
scope.setScope((Collection) dso);
// Query the browse index
BrowseInfo browseInfo;
if (mode == MODE_BY_TITLE)
{
browseInfo = Browse.getItemsByTitle(scope);
}
else if (mode == MODE_BY_DATE)
{
browseInfo = Browse.getItemsByDate(scope, false);
}
else if (mode == MODE_BY_AUTHOR)
{
browseInfo = Browse.getAuthors(scope);
}
else if (mode == MODE_BY_AUTHOR_ITEM)
{
browseInfo = Browse.getItemsByAuthor(scope, true);
}
else if (mode == MODE_BY_SUBJECT)
{
browseInfo = Browse.getSubjects(scope);
}
else if (mode == MODE_BY_SUBJECT_ITEM)
{
browseInfo = Browse.getItemsBySubject(scope, true);
}
else
{
throw new UIException("Unknown mode selected.");
}
// Save the search results for later access.
this.browseInfo = browseInfo;
this.browseScope = scope;
if (mode == MODE_BY_AUTHOR || mode == MODE_BY_SUBJECT)
this.browseItem = false;
else
this.browseItem = true;
}
/**
* The URL query string of of the previous page.
*
* Note: the query string does not start with a "?" or "&" those need to be
* added as approprate by the calle.
*
* @param objectModel
* Cocoon' object model.
* @return The query string if available, otherwise null.
*/
public String previousPageURL(String baseURL)
throws UIException
{
try
{
// A search must be preformed first.
if (browseInfo == null)
return null;
if (browseInfo.isFirst())
return null;
Map<String,String> parameters = new HashMap<String,String>();
if (browseItem)
{
Item[] items = browseInfo.getItemResults();
if (items == null || items.length <= 0)
return null;
String bottom = URLEncoder.encode(items[0].getHandle(),
Constants.DEFAULT_ENCODING);
parameters.put("bottom",bottom);
}
else
{
String[] strings = browseInfo.getStringResults();
if (strings == null || strings.length <= 0)
return null;
String bottom = URLEncoder.encode(strings[0],
Constants.DEFAULT_ENCODING);
parameters.put("bottom",bottom);
}
return super.generateURL(baseURL,parameters);
}
catch (UnsupportedEncodingException uee)
{
throw new UIException(uee);
}
}
/**
* The URL query string of of the next page.
*
* Note: the query string does not start with a "?" or "&" those need to be
* added as approprate by the calle.
*
* @param objectModel
* Cocoon' object model.
* @return The query string if available, otherwise null.
*/
public String nextPageURL(String baseURL) throws UIException
{
try
{
// A search must be preformed first.
if (browseInfo == null)
return null;
if (browseInfo.isLast())
return null;
Map<String,String> parameters = new HashMap<String,String>();
if (browseItem)
{
Item[] items = browseInfo.getItemResults();
if (items == null || items.length <= 0)
return null;
String top = URLEncoder.encode(items[items.length - 1].getHandle(),
Constants.DEFAULT_ENCODING);
parameters.put("top",top);
}
else
{
String[] strings = browseInfo.getStringResults();
if (strings == null || strings.length <= 0)
return null;
String top = URLEncoder.encode(strings[strings.length - 1],
Constants.DEFAULT_ENCODING);
parameters.put("top",top);
}
return super.generateURL(baseURL,parameters);
}
catch (UnsupportedEncodingException uee)
{
throw new UIException(uee);
}
}
/**
* Recyle
*/
public void recycle() {
this.browseInfo = null;
this.browseScope = null;
super.recycle();
}
}

View File

@@ -0,0 +1,503 @@
/*
* AbstractSearch.java
*
* Version: $Revision: 1.18 $
*
* Date: $Date: 2006/07/27 18:24:34 $
*
* Copyright (c) 2002, Hewlett-Packard Company and Massachusetts
* Institute of Technology. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* - 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.
*
* - Neither the name of the Hewlett-Packard Company nor the name of the
* Massachusetts Institute of Technology nor the names of their
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS 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 COPYRIGHT
* HOLDERS OR 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.
*/
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;
import org.apache.excalibur.source.SourceValidity;
import org.dspace.app.xmlui.cocoon.AbstractDSpaceTransformer;
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.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.Para;
import org.dspace.app.xmlui.wing.element.Select;
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.core.Context;
import org.dspace.handle.HandleManager;
import org.dspace.search.DSQuery;
import org.dspace.search.QueryArgs;
import org.dspace.search.QueryResults;
import org.xml.sax.SAXException;
/**
* This is an abstract search page. It is a collection of search methods that
* are common between diffrent search implementation. An implementer must
* implement at least three methods: addBody(), getQuery(), and generateURL().
*
* See the two implementors: SimpleSearch and AdvancedSearch.
*
* @author Scott Phillips
*/
public abstract class AbstractSearch extends AbstractDSpaceTransformer
{
/** Language strings */
private static final Message T_result_query =
message("xmlui.ArtifactBrowser.AbstractSearch.result_query");
private static final Message T_head1_community =
message("xmlui.ArtifactBrowser.AbstractSearch.head1_community");
private static final Message T_head1_collection =
message("xmlui.ArtifactBrowser.AbstractSearch.head1_collection");
private static final Message T_head1_none =
message("xmlui.ArtifactBrowser.AbstractSearch.head1_none");
private static final Message T_head2 =
message("xmlui.ArtifactBrowser.AbstractSearch.head2");
private static final Message T_head3 =
message("xmlui.ArtifactBrowser.AbstractSearch.head3");
private static final Message T_no_results =
message("xmlui.ArtifactBrowser.AbstractSearch.no_results");
private static final Message T_all_of_dspace =
message("xmlui.ArtifactBrowser.AbstractSearch.all_of_dspace");
/** How many results should appear on one page? */
public static final int RESULTS_PER_PAGE = 10;
/** Cached query results */
private QueryResults queryResults;
/** Cached validity object */
private SourceValidity validity;
/**
* Generate the unique caching key.
* This key must be unique inside the space of this component.
*/
public Serializable getKey()
{
try
{
String key = "";
// Page Parameter
Request request = ObjectModelHelper.getRequest(objectModel);
key += "-" + request.getParameter("page");
// What scope the search is at
DSpaceObject scope = getScope();
if (scope != null)
key += "-" + scope.getHandle();
// The actualy search query.
key += "-" + getQuery();
return HashUtil.hash(key);
}
catch (Exception e)
{
// Ignore all errors and just don't cache.
return "0";
}
}
/**
* Generate the cache validity object.
*
* This validity object should never "over cache" because it will
* preform the search, and serialize the results using the
* DSpaceValidity object.
*/
public SourceValidity getValidity()
{
if (this.validity == null)
{
try
{
DSpaceValidity validity = new DSpaceValidity();
DSpaceObject scope = getScope();
validity.add(scope);
performSearch();
@SuppressWarnings("unchecked") // This cast is correct
java.util.List<String> handles = queryResults.getHitHandles();
for (String handle : handles)
{
DSpaceObject resultDSO = HandleManager.resolveToObject(
context, handle);
validity.add(resultDSO);
}
this.validity = validity.complete();
}
catch (Exception e)
{
// Just ignore all errors and return an invalid cache.
}
}
return this.validity;
}
/**
* Build the resulting search DRI document.
*/
public abstract void addBody(Body body) throws SAXException, WingException,
UIException, SQLException, IOException, AuthorizeException;
/**
*
* Attach a division to the given search division named "search-results"
* which contains results for this search query.
*
* @param search
* The search division to contain the search-results division.
*/
protected void buildSearchResultsDivision(Division search)
throws IOException, SQLException, WingException
{
if (getQuery().length() > 0)
{
// Preform the actual search
performSearch();
DSpaceObject searchScope = getScope();
Para para = search.addPara("result-query","result-query");
String query = getQuery();
int hitCount = queryResults.getHitCount();
para.addContent(T_result_query.parameterize(query,hitCount));
Division results = search.addDivision("search-results","primary");
if (searchScope instanceof Community)
{
Community community = (Community) searchScope;
String communityName = community.getMetadata("name");
results.setHead(T_head1_community.parameterize(communityName));
}
else if (searchScope instanceof Collection)
{
Collection collection = (Collection) searchScope;
String collectionName = collection.getMetadata("name");
results.setHead(T_head1_collection.parameterize(collectionName));
}
else
{
results.setHead(T_head1_none);
}
if (queryResults.getHitCount() > 0)
{
// Pagination variables.
int itemsTotal = queryResults.getHitCount();
int firstItemIndex = queryResults.getStart() + 1;
int lastItemIndex = queryResults.getStart()
+ queryResults.getPageSize();
if (itemsTotal < lastItemIndex)
lastItemIndex = itemsTotal;
int currentPage = (queryResults.getStart() / queryResults
.getPageSize()) + 1;
int pagesTotal = ((queryResults.getHitCount() - 1) / queryResults
.getPageSize()) + 1;
Map<String, String> parameters = new HashMap<String, String>();
parameters.put("page", "{pageNum}");
String pageURLMask = generateURL(parameters);
results.setMaskedPagination(itemsTotal, firstItemIndex,
lastItemIndex, currentPage, pagesTotal, pageURLMask);
// Look for any communities or collections in the mix
ReferenceSet referenceSet = null;
boolean resultsContainsBothContainersAndItems = false;
@SuppressWarnings("unchecked") // This cast is correct
java.util.List<String> containerHandles = queryResults.getHitHandles();
for (String handle : containerHandles)
{
DSpaceObject resultDSO = HandleManager.resolveToObject(
context, handle);
if (resultDSO instanceof Community
|| resultDSO instanceof Collection)
{
if (referenceSet == null) {
referenceSet = results.addReferenceSet("search-results-repository",
ReferenceSet.TYPE_SUMMARY_LIST,null,"repository-search-results");
// Set a heading showing that we will be listing containers that matched:
referenceSet.setHead(T_head2);
resultsContainsBothContainersAndItems = true;
}
referenceSet.addReference(resultDSO);
}
}
// Look for any items in the result set.
referenceSet = null;
@SuppressWarnings("unchecked") // This cast is correct
java.util.List<String> itemHandles = queryResults.getHitHandles();
for (String handle : itemHandles)
{
DSpaceObject resultDSO = HandleManager.resolveToObject(
context, handle);
if (resultDSO instanceof Item)
{
if (referenceSet == null) {
referenceSet = results.addReferenceSet("search-results-repository",
ReferenceSet.TYPE_SUMMARY_LIST,null,"repository-search-results");
// Only set a heading if there are both containers and items.
if (resultsContainsBothContainersAndItems)
referenceSet.setHead(T_head3);
}
referenceSet.addReference(resultDSO);
}
}
}
else
{
results.addPara(T_no_results);
}
}// Empty query
}
/**
* Add options to the search scope field. This field determines in what
* communities or collections to search for the query.
*
* The scope list will depend upon the current search scope. There are three
* cases:
*
* No current scope: All top level communities are listed.
*
* The current scope is a community: All collections contained within the
* community are listed.
*
* The current scope is a collection: All parent communities are listed.
*
* @param scope
* The current scope field.
*/
protected void buildScopeList(Select scope) throws SQLException,
WingException
{
DSpaceObject scopeDSO = getScope();
if (scopeDSO == null)
{
// No scope, display all root level communities
scope.addOption("/",T_all_of_dspace);
scope.setOptionSelected("/");
for (Community community : Community.findAll(context))
{
scope.addOption(community.getHandle(),community.getMetadata("name"));
}
}
else if (scopeDSO instanceof Community)
{
// The scope is a community, display all collections contained
// within
Community community = (Community) scopeDSO;
scope.addOption("/",T_all_of_dspace);
scope.addOption(community.getHandle(),community.getMetadata("name"));
scope.setOptionSelected(community.getHandle());
for (Collection collection : community.getCollections())
{
scope.addOption(collection.getHandle(),collection.getMetadata("name"));
}
}
else if (scopeDSO instanceof Collection)
{
// The scope is a collection, display all parent collections.
Collection collection = (Collection) scopeDSO;
scope.addOption("/",T_all_of_dspace);
scope.addOption(collection.getHandle(),collection.getMetadata("name"));
scope.setOptionSelected(collection.getHandle());
Community[] communities = collection.getCommunities()[0]
.getAllParents();
for (Community community : communities)
{
scope.addOption(community.getHandle(),community.getMetadata("name"));
}
}
}
/**
* Query DSpace for a list of all items / collections / or communities that
* match the given search query.
*
* @return The associated query results.
*/
protected void performSearch() throws SQLException, IOException
{
if (queryResults != null)
return;
Context context = ContextUtil.obtainContext(objectModel);
Request request = ObjectModelHelper.getRequest(objectModel);
String query = getQuery();
DSpaceObject scope = getScope();
String page = request.getParameter("page");
int resultsPerPage = RESULTS_PER_PAGE;
try {
String resultsPerPageStr = request.getParameter("results_per_page");
resultsPerPage = Integer.valueOf(resultsPerPageStr);
}
catch (NumberFormatException nfe)
{
resultsPerPage = RESULTS_PER_PAGE;
}
QueryArgs qArgs = new QueryArgs();
qArgs.setPageSize(resultsPerPage);
qArgs.setQuery(query);
if (page != null)
qArgs.setStart((Integer.valueOf(page) - 1) * qArgs.getPageSize());
else
qArgs.setStart(0);
QueryResults qResults = null;
if (scope instanceof Community)
{
qResults = DSQuery.doQuery(context, qArgs, (Community) scope);
}
else if (scope instanceof Collection)
{
qResults = DSQuery.doQuery(context, qArgs, (Collection) scope);
}
else
{
qResults = DSQuery.doQuery(context, qArgs);
}
this.queryResults = qResults;
}
/**
* Determine the current scope. This may be derived from the current url
* handle if present or the scope parameter is given. If no scope is
* specified then null is returned.
*
* @return The current scope.
*/
protected DSpaceObject getScope() throws SQLException
{
Request request = ObjectModelHelper.getRequest(objectModel);
String scopeString = request.getParameter("scope");
// Are we in a community or collection?
DSpaceObject dso;
if (scopeString == null || "".equals(scopeString))
// get the search scope from the url handle
dso = HandleUtil.obtainHandle(objectModel);
else
// Get the search scope from the location parameter
dso = HandleManager.resolveToObject(context, scopeString);
return dso;
}
/**
* Determine if the scope of the search should fixed or is changeable by the
* user.
*
* The search scope when preformed by url, i.e. they are at the url handle/xxxx/xx/search
* then it is fixed. However at the global level the search is variable.
*
* @return true if the scope is variable, false otherwise.
*/
protected boolean variableScope() throws SQLException
{
if (HandleUtil.obtainHandle(objectModel) == null)
return true;
else
return false;
}
/**
* Extract the query string. Under most implementations this will be derived
* from the url parameters.
*
* @return The query string.
*/
abstract protected String getQuery();
/**
* Generate a url to the given search implementation with the associated
* parameters included.
*
* @param parameters
* @return The post URL
*/
abstract protected String generateURL(Map<String, String> parameters)
throws UIException;
/**
* Recycle
*/
public void recycle()
{
this.queryResults = null;
this.validity = null;
super.recycle();
}
}

View File

@@ -0,0 +1,515 @@
/*
* AdvancedSearch
*
* Version: $Revision: 1.14 $
*
* Date: $Date: 2006/07/27 18:24:34 $
*
* Copyright (c) 2002, Hewlett-Packard Company and Massachusetts
* Institute of Technology. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* - 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.
*
* - Neither the name of the Hewlett-Packard Company nor the name of the
* Massachusetts Institute of Technology nor the names of their
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS 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 COPYRIGHT
* HOLDERS OR 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.
*/
package org.dspace.app.xmlui.aspect.artifactbrowser;
import java.io.IOException;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import org.apache.cocoon.caching.CacheableProcessingComponent;
import org.apache.cocoon.environment.ObjectModelHelper;
import org.apache.cocoon.environment.Request;
import org.apache.oro.text.perl.Perl5Util;
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.Cell;
import org.dspace.app.xmlui.wing.element.Division;
import org.dspace.app.xmlui.wing.element.List;
import org.dspace.app.xmlui.wing.element.PageMeta;
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.Text;
import org.dspace.authorize.AuthorizeException;
import org.xml.sax.SAXException;
/**
* Preform an advanced search of the repository. The user is presented with
* three search parameters, that may be ORed, ANDed, NOTed together.
*
* At the present time only three fields are displayed however if the theme
* whishes to expand this they can by setting the num_search_fields to the
* desired number of search fields. Also the theme can change the number of
* results per the page by setting results_per_page
*
* FIXME: The list of what fields are search should come from a configurable
* place. Possibily the sitemap configuration.
*
* @author Scott Phillips
*/
public class AdvancedSearch extends AbstractSearch implements CacheableProcessingComponent
{
/** Language string used: */
private static final Message T_title =
message("xmlui.ArtifactBrowser.AdvancedSearch.title");
private static final Message T_dspace_home =
message("xmlui.general.dspace_home");
private static final Message T_trail =
message("xmlui.ArtifactBrowser.AdvancedSearch.trail");
private static final Message T_head =
message("xmlui.ArtifactBrowser.AdvancedSearch.head");
private static final Message T_search_scope =
message("xmlui.ArtifactBrowser.AdvancedSearch.search_scope");
private static final Message T_search_scope_help =
message("xmlui.ArtifactBrowser.AdvancedSearch.search_scope_help");
private static final Message T_conjunction =
message("xmlui.ArtifactBrowser.AdvancedSearch.conjunction");
private static final Message T_search_type =
message("xmlui.ArtifactBrowser.AdvancedSearch.search_type");
private static final Message T_search_for =
message("xmlui.ArtifactBrowser.AdvancedSearch.search_for");
private static final Message T_go =
message("xmlui.general.go");
private static final Message T_and =
message("xmlui.ArtifactBrowser.AdvancedSearch.and");
private static final Message T_or =
message("xmlui.ArtifactBrowser.AdvancedSearch.or");
private static final Message T_not =
message("xmlui.ArtifactBrowser.AdvancedSearch.not");
/** How many conjunction fields to display */
private static final int FIELD_DISPLAY_COUNT = 3;
private static final int FIELD_MAX_COUNT = 12;
/** A cache of extracted search fields */
private ArrayList<SearchField> fields;
/**
* Add Page metadata.
*/
public void addPageMeta(PageMeta pageMeta) throws WingException
{
pageMeta.addMetadata("title").addContent(T_title);
pageMeta.addTrailLink(contextPath + "/", T_dspace_home);
pageMeta.addTrail().addContent(T_trail);
}
/**
* Add the body
*/
public void addBody(Body body) throws SAXException, WingException,
UIException, SQLException, IOException, AuthorizeException
{
Request request = ObjectModelHelper.getRequest(objectModel);
String numSearchField = request.getParameter("num_search_field");
if (numSearchField == null || numSearchField.length() == 0)
numSearchField = "3";
// Build the DRI Body
Division search = body.addDivision("advanced-search","primary");
search.setHead(T_head);
Division query = search.addInteractiveDivision("search-query",
contextPath+"/advanced-search",Division.METHOD_POST,"secondary search");
// Use these fields to change the number of search fields, or change the results per page.
query.addHidden("num_search_field").setValue(numSearchField);
query.addHidden("results_per_page").setValue(RESULTS_PER_PAGE);
List queryList = query.addList("search-query",List.TYPE_FORM);
if (variableScope())
{
Select scope = queryList.addItem().addSelect("scope");
scope.setLabel(T_search_scope);
scope.setHelp(T_search_scope_help);
buildScopeList(scope);
}
Table queryTable = query.addTable("search-query", 4, 3);
Row header = queryTable.addRow(Row.ROLE_HEADER);
header.addCellContent(T_conjunction);
header.addCellContent(T_search_type);
header.addCellContent(T_search_for);
for (int i = 1; i <= FIELD_DISPLAY_COUNT; i++)
{
Row row = queryTable.addRow(Row.ROLE_DATA);
buildConjunctionField(i, row.addCell());
buildTypeField(i, row.addCell());
buildQueryField(i, row.addCell());
}
for (SearchField field : fields)
{
// Skip over all the fields we've displayed.
int i = field.getIndex();
if (i <= FIELD_DISPLAY_COUNT)
continue;
query.addHidden("conjunction"+i).setValue(field.getConjunction());
query.addHidden("field"+i).setValue(field.getField());
query.addHidden("query"+i).setValue(field.getQuery());
}
query.addPara(null, "button-list").addButton("submit").setValue(T_go);
// Add the result division
buildSearchResultsDivision(search);
}
/**
* Build a conjunction field in the given for the given cell. A
* conjunction consists of logical the operators AND, OR, NOT.
*
* @param row The current row
* @param cell The current cell
*/
private void buildConjunctionField(int row, Cell cell) throws WingException
{
// No conjunction for the first row.
if (row == 1)
return;
Request request = ObjectModelHelper.getRequest(objectModel);
String current = request.getParameter("conjunction" + row);
// default to AND if nothing specified.
if (current == null || current.length() == 0)
current = "AND";
Select select = cell.addSelect("conjunction" + row);
select.addOption("AND".equals(current), "AND").addContent(T_and);
select.addOption("OR".equals(current), "OR").addContent(T_or);
select.addOption("NOT".equals(current), "NOT").addContent(T_not);
}
/**
* Build a list of all the indexable fields in the given cell.
*
* FIXME: This needs to use the dspace.cfg data
*
* @param row The current row
* @param cell The current cell
*/
private void buildTypeField(int row, Cell cell) throws WingException
{
Request request = ObjectModelHelper.getRequest(objectModel);
String current = request.getParameter("field" + row);
Select select = cell.addSelect("field" + row);
// FIXME: this needs to come from a configurable source.
Map<String, Message> searchTypes = new HashMap<String, Message>();
searchTypes.put("author",
message("xmlui.ArtifactBrowser.AdvancedSearch.type_author"));
searchTypes.put("title",
message("xmlui.ArtifactBrowser.AdvancedSearch.type_title"));
searchTypes.put("keyword",
message("xmlui.ArtifactBrowser.AdvancedSearch.type_subject"));
searchTypes.put("abstract",
message("xmlui.ArtifactBrowser.AdvancedSearch.type_abstract"));
searchTypes.put("series",
message("xmlui.ArtifactBrowser.AdvancedSearch.type_series"));
searchTypes.put("sponsor",
message("xmlui.ArtifactBrowser.AdvancedSearch.type_sponsor"));
searchTypes.put("identifier",
message("xmlui.ArtifactBrowser.AdvancedSearch.type_identifier"));
searchTypes.put("language",
message("xmlui.ArtifactBrowser.AdvancedSearch.type_language"));
// Special case ANY
select.addOption((current == null), "ANY").addContent(
message("xmlui.ArtifactBrowser.AdvancedSearch.type_keyword"));
for (String key : searchTypes.keySet())
{
select.addOption(key.equals(current), key).addContent(
searchTypes.get(key));
}
}
/**
* Recycle
*/
public void recycle()
{
this.fields = null;
super.recycle();
}
/**
* Build the query field for the given cell.
*
* @param row The current row.
* @param cell The current cell.
*/
private void buildQueryField(int row, Cell cell) throws WingException
{
Request request = ObjectModelHelper.getRequest(objectModel);
String current = request.getParameter("query" + row);
Text text = cell.addText("query" + row);
if (current != null)
text.setValue(current);
}
/**
* Generate a URL for this search page which includes all the
* search parameters along with the added parameters.
*
* @param parameters URL parameters to be included in the generated url.
*/
protected String generateURL(Map<String, String> parameters)
throws UIException
{
Request request = ObjectModelHelper.getRequest(objectModel);
String numSearchField = request.getParameter("num_search_field");
if (numSearchField != null)
parameters.put("num_search_field", numSearchField);
String resultsPerPage = request.getParameter("results_per_page");
if (resultsPerPage != null)
parameters.put("results_per_page", resultsPerPage);
String scope = request.getParameter("scope");
if (scope != null)
parameters.put("scope", scope);
for (SearchField searchField : getSearchFields(request))
{
int index = searchField.getIndex();
String field = searchField.getField();
String query = searchField.getQuery();
String conjunction = searchField.getConjunction();
parameters.put("conjunction" + index, conjunction);
parameters.put("field" + index, field);
parameters.put("query" + index, query);
}
return super.generateURL("advanced-search", parameters);
}
/**
* Determine the search query for this search page.
*
* @return the query.
*/
protected String getQuery()
{
Request request = ObjectModelHelper.getRequest(objectModel);
return buildQuery(getSearchFields(request));
}
/**
* Given a list of search fields buld a lucene search query string.
*
* @param fields The search fields
* @return A string
*/
private String buildQuery(ArrayList<SearchField> fields)
{
Perl5Util util = new Perl5Util();
String query = "";
// Loop through the fields building the search query as we go.
for (SearchField field : fields)
{
// if the field is empty, then skip it and try a later one.
if (field.getQuery() == null)
continue;
// Add the conjunction for everything but the first field.
if (fields.indexOf(field) > 0)
query += " " + field.getConjunction() + " ";
// Two cases, one if a specific search field is specified or if
// ANY is given then just a general search is performed.
if ("ANY".equals(field.getField()))
{
// No field specified,
query += "(" + field.getQuery() + ")";
}
else
{
// Specific search field specified, add the field specific field.
// Replace singe quote's with double quotes (only if they match)
String subquery = util.substitute("s/\'(.*)\'/\"$1\"/g", field.getQuery());
// If the field is not quoted ...
if (!util.match("/\".*\"/", subquery))
{
// ... then seperate each word and re-specify the search field.
subquery = util.substitute("s/ / " + field.getField() + ":/g", subquery);
}
// Put the subquery into the general query
query += "("+field.getField()+":"+subquery+")";
}
}
if (query.length() == 0)
return "";
else
return "("+query+")";
}
/**
* Get a list of search fields from the request object
* and parse them into a linear array of fileds. The field's
* index is preserved, so if it comes in as index 17 it will
* be outputted as field 17.
*
* @param request The http request object
* @return Array of search fields
*/
public ArrayList<SearchField> getSearchFields(Request request)
{
if (this.fields != null)
return this.fields;
// Get how many fields to search
int numSearchField;
try {
String numSearchFieldStr = request.getParameter("num_search_field");
numSearchField = Integer.valueOf(numSearchFieldStr);
}
catch (NumberFormatException nfe)
{
numSearchField = FIELD_MAX_COUNT;
}
// Iterate over all the possible fields and add each one to the list of fields.
ArrayList<SearchField> fields = new ArrayList<SearchField>();
for (int i = 1; i <= numSearchField; i++)
{
String field = request.getParameter("field"+i);
String query = request.getParameter("query"+i);
String conjunction = request.getParameter("conjunction"+i);
if (field != null)
{
field = field.trim();
if (field.length() == 0)
field = null;
}
if (query != null)
{
query = query.trim();
if (query.length() == 0)
query = null;
}
if (conjunction != null)
{
conjunction = conjunction.trim();
if (conjunction.length() == 0)
conjunction = null;
}
if (field == null)
field = "ANY";
if (conjunction == null)
conjunction = "AND";
if (query != null)
fields.add(new SearchField(i,field,query,conjunction));
}
this.fields = fields;
return this.fields;
}
/**
* A private record keeping class to relate the various
* components of a search field together.
*/
private static class SearchField {
/** What index the search field is, typicaly there are just three - but the theme may exand this number */
private int index;
/** The field to search, ANY if none specified */
private String field;
/** The query string to search for */
private String query;
/** the conjunction: either "AND" or "OR" */
private String conjuction;
public SearchField(int index, String field, String query, String conjunction)
{
this.index = index;
this.field = field;
this.query = query;
this.conjuction = conjunction;
}
public int getIndex() { return this.index;}
public String getField() { return this.field;}
public String getQuery() { return this.query;}
public String getConjunction() { return this.conjuction;}
}
}

View File

@@ -0,0 +1,272 @@
/*
* BrowseAuthorItems.java
*
* Version: $Revision: 1.15 $
*
* Date: $Date: 2006/06/02 21:36:56 $
*
* Copyright (c) 2002, Hewlett-Packard Company and Massachusetts
* Institute of Technology. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* - 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.
*
* - Neither the name of the Hewlett-Packard Company nor the name of the
* Massachusetts Institute of Technology nor the names of their
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS 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 COPYRIGHT
* HOLDERS OR 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.
*/
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.environment.ObjectModelHelper;
import org.apache.cocoon.environment.Request;
import org.apache.cocoon.util.HashUtil;
import org.apache.excalibur.source.SourceValidity;
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.app.xmlui.wing.element.PageMeta;
import org.dspace.app.xmlui.wing.element.Xref;
import org.dspace.authorize.AuthorizeException;
import org.dspace.content.DSpaceObject;
import org.dspace.content.Item;
import org.xml.sax.SAXException;
/**
* Display the results of browsing items belonging to a particular author index.
* This component may either apply to all communities and collection or be
* scoped to just one community / collection depending upon the url.
*
* FIXME: Currently the Browse.getItemsByAuthor turns off pagination, this
* causes problems when a single author has published many items in DSpace. To
* limit the problem we implement simple pagination untop of the browse results
* using "authorTop" & "authorBottom" parameters similar to how they are used by
* the other browsers. This should be changed when the browse code is updated,
* so that the un-used items are not instanceated.
*
* @author Scott Phillips
*/
public class BrowseAuthorItems extends AbstractBrowse implements CacheableProcessingComponent
{
/** Language strings: */
private static final Message T_title =
message("xmlui.ArtifactBrowser.BrowseAuthorItems.title");
private static final Message T_dspace_home =
message("xmlui.general.dspace_home");
private static final Message T_trail =
message("xmlui.ArtifactBrowser.BrowseAuthorItems.trail");
private static final Message T_head =
message("xmlui.ArtifactBrowser.BrowseAuthorItems.head");
private static final Message T_back =
message("xmlui.ArtifactBrowser.BrowseAuthorItems.back");
/** How many items should appear on one page */
private static final int ITEMS_PER_PAGE = 20;
/** Cached validity object */
private SourceValidity validity;
/**
* Generate the unique caching key.
* This key must be unique inside the space of this component.
*/
public Serializable getKey()
{
Request request = ObjectModelHelper.getRequest(objectModel);
String key = "";
key += "-" + request.getParameter("top");
key += "-" + request.getParameter("bottom");
key += "-" + request.getParameter("startsWith");
key += "-" + request.getParameter("month");
key += "-" + request.getParameter("year");
key += "-" + request.getParameter("author");
key += "-" + request.getParameter("authorTop");
key += "-" + request.getParameter("authorBottom");
try
{
DSpaceObject dso = HandleUtil.obtainHandle(objectModel);
if (dso != null)
key += "-" + dso.getHandle();
return HashUtil.hash(key);
}
catch (Exception e)
{
// Ignore all errors and just don't cache.
return "0";
}
}
/**
* Generate the cache validity object.
*
* The validity object will include all items on this browse page, along
* with all bundles and bitstreams refrenced by them. The one change that
* will not be refelected in this cache is a change is community/collection
* hierarchy.
*/
public SourceValidity getValidity()
{
if (validity == null)
{
try
{
DSpaceValidity validity = new DSpaceValidity();
DSpaceObject dso = HandleUtil.obtainHandle(objectModel);
validity.add(dso);
performBrowse(MODE_BY_AUTHOR_ITEM);
for (Item item : browseInfo.getItemResults())
{
validity.add(item);
}
this.validity = validity.complete();
}
catch (Exception e)
{
// Just ignore all errors and return an invalid cache.
}
}
return this.validity;
}
/**
* Add Page metadata.
*/
public void addPageMeta(PageMeta pageMeta) throws SAXException,
WingException, UIException, SQLException, IOException,
AuthorizeException
{
pageMeta.addMetadata("title").addContent(T_title);
pageMeta.addTrailLink(contextPath, T_dspace_home);
DSpaceObject dso = HandleUtil.obtainHandle(objectModel);
if (dso != null)
HandleUtil.buildHandleTrail(dso, pageMeta,contextPath);
pageMeta.addTrail().addContent(T_trail);
}
/**
* Add the browse-author-item division.
*/
public void addBody(Body body) throws SAXException, WingException,
UIException, SQLException, IOException, AuthorizeException
{
// Preform the actual search
performBrowse(MODE_BY_AUTHOR_ITEM);
Request request = ObjectModelHelper.getRequest(objectModel);
Item[] items = browseInfo.getItemResults();
String top = request.getParameter("authorTop");
String bottom = request.getParameter("authorBottom");
String author = request.getParameter("author");
// Determine Pagination variables
int itemsTotal = items.length;
int firstItemIndex = 0;
int lastItemIndex = firstItemIndex + ITEMS_PER_PAGE;
// Should we shift the pagination view because of a top or bottom
// directive?
if (top != null)
{
// Move the indexs to match pagination
firstItemIndex = Integer.valueOf(top);
lastItemIndex = firstItemIndex + ITEMS_PER_PAGE;
}
else if (bottom != null)
{
lastItemIndex = Integer.valueOf(bottom);
firstItemIndex = lastItemIndex - ITEMS_PER_PAGE;
}
// Check four out of bounds indices.
if (firstItemIndex < 0)
firstItemIndex = 0;
if (lastItemIndex > items.length - 1)
lastItemIndex = items.length - 1;
// Determine the next & previous link;
String baseURL = "browse-author-items?author=" + URLEncode(author);
String previousPage = null;
String nextPage = null;
if (firstItemIndex > 0)
previousPage = baseURL + "&authorBottom=" + (firstItemIndex);
if (lastItemIndex < items.length - 1)
nextPage = baseURL + "&authorTop=" + (lastItemIndex);
// Build the DRI Body
Division div = body.addDivision("browse-by-author-item","primary");
div.setHead(T_head.parameterize(author));
// Navigatioal aid (really this is a poor version of pagination)
Division jump = div.addInteractiveDivision("browse-navigation",
"browse-author-items", Division.METHOD_POST,"secondary navigation");
Xref link = jump.addPara().addXref("browse-author?startsWith=" + URLEncode(author));
link.addContent(T_back);
// This div will hold the browsing results
Division results = div.addDivision("browse-by-author-item-results","primary");
results.setSimplePagination(itemsTotal, firstItemIndex + 1, lastItemIndex + 1,
previousPage, nextPage);
// Refrence all the browsed items
ReferenceSet referenceSet = results.addReferenceSet("browse-by-author-item",
ReferenceSet.TYPE_SUMMARY_LIST, "author", null);
for (int i = firstItemIndex; i <= lastItemIndex; i++)
{
referenceSet.addReference(items[i]);
}
}
/**
* Recycle
*/
public void recycle() {
this.validity = null;
super.recycle();
}
}

View File

@@ -0,0 +1,244 @@
/*
* BrowseAuthors.java
*
* Version: $Revision: 1.16 $
*
* Date: $Date: 2006/07/27 18:24:34 $
*
* Copyright (c) 2002, Hewlett-Packard Company and Massachusetts
* Institute of Technology. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* - 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.
*
* - Neither the name of the Hewlett-Packard Company nor the name of the
* Massachusetts Institute of Technology nor the names of their
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS 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 COPYRIGHT
* HOLDERS OR 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.
*/
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.environment.ObjectModelHelper;
import org.apache.cocoon.environment.Request;
import org.apache.cocoon.util.HashUtil;
import org.apache.excalibur.source.SourceValidity;
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.Cell;
import org.dspace.app.xmlui.wing.element.Division;
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.Row;
import org.dspace.app.xmlui.wing.element.Table;
import org.dspace.authorize.AuthorizeException;
import org.dspace.content.DSpaceObject;
import org.xml.sax.SAXException;
/**
* Display the results of browsing authors index. This component may either apply
* to all communities and collection or be scoped to just one community /
* collection depending upon the url.
*
* @author Scott Phillips
*/
public class BrowseAuthors extends AbstractBrowse implements CacheableProcessingComponent
{
/** Language Strings */
private static final Message T_title =
message("xmlui.ArtifactBrowser.BrowseAuthors.title");
private static final Message T_dspace_home =
message("xmlui.general.dspace_home");
private static final Message T_trail =
message("xmlui.ArtifactBrowser.BrowseAuthors.trail");
private static final Message T_head =
message("xmlui.ArtifactBrowser.BrowseAuthors.head");
private static final Message T_starts_with =
message("xmlui.ArtifactBrowser.BrowseAuthors.starts_with");
private static final Message T_go =
message("xmlui.general.go");
private static final Message T_column_heading =
message("xmlui.ArtifactBrowser.BrowseAuthors.column_heading");
/** Cached validity object */
private SourceValidity validity;
/**
* Generate the unique caching key.
* This key must be unique inside the space of this component.
*/
public Serializable getKey()
{
Request request = ObjectModelHelper.getRequest(objectModel);
String key = "";
key += "-" + request.getParameter("top");
key += "-" + request.getParameter("bottom");
key += "-" + request.getParameter("startsWith");
key += "-" + request.getParameter("month");
key += "-" + request.getParameter("year");
key += "-" + request.getParameter("author");
try
{
DSpaceObject dso = HandleUtil.obtainHandle(objectModel);
if (dso != null)
key += "-" + dso.getHandle();
return HashUtil.hash(key);
}
catch (Exception e)
{
// Ignore all errors and just don't cache.
return "0";
}
}
/**
* Generate the cache validity object.
*
* The validity object will include all items on this browse page, along
* with all bundles and bitstreams refrenced by them. The one change that
* will not be refelected in this cache is a change is community/collection
* hierarchy.
*/
public SourceValidity getValidity()
{
if (validity == null)
{
try
{
DSpaceValidity validity = new DSpaceValidity();
DSpaceObject dso = HandleUtil.obtainHandle(objectModel);
validity.add(dso);
performBrowse(MODE_BY_AUTHOR);
for (String author : browseInfo.getStringResults())
{
validity.add(author);
}
this.validity = validity.complete();
}
catch (Exception e)
{
// Just ignore all errors and return an invalid cache.
}
}
return this.validity;
}
/**
* Add Page metadata.
*/
public void addPageMeta(PageMeta pageMeta) throws SAXException,
WingException, UIException, SQLException, IOException,
AuthorizeException
{
pageMeta.addMetadata("title").addContent(T_title);
DSpaceObject dso = HandleUtil.obtainHandle(objectModel);
pageMeta.addTrailLink(contextPath + "/", T_dspace_home);
if (dso != null)
HandleUtil.buildHandleTrail(dso, pageMeta,contextPath);
pageMeta.addTrail().addContent(T_trail);
}
/**
* Add the browse-author division.
*/
public void addBody(Body body) throws SAXException, WingException,
UIException, SQLException, IOException, AuthorizeException
{
performBrowse(MODE_BY_AUTHOR);
// Pagination variables
int itemsTotal = browseInfo.getTotal();
int firstItemIndex = browseInfo.getOverallPosition() + 1;
int lastItemIndex = browseInfo.getOverallPosition()
+ browseInfo.getResultCount();
String previousPage = previousPageURL("browse-author");
String nextPage = nextPageURL("browse-author");
// Build the DRI Body
Division div = body.addDivision("browse-by-author","primary");
div.setHead(T_head);
// Navigatioal aid (really this is a poor version of pagination)
Division jump = div.addInteractiveDivision("browse-navigation",
"browse-author", Division.METHOD_POST,"secondary navigation");
List jumpList = jump.addList("jump-list", List.TYPE_SIMPLE, "alphabet");
for (char c = 'A'; c <= 'Z'; c++)
jumpList.addItemXref("browse-author?startsWith=" + c, String
.valueOf(c));
Para jumpForm = jump.addPara();
jumpForm.addContent(T_starts_with);
jumpForm.addText("startsWith");
jumpForm.addButton("submit").setValue(T_go);
// This div will hold the browsing results
Division results = div.addDivision("browse-by-author-results","primary");
results.setSimplePagination(itemsTotal, firstItemIndex, lastItemIndex,
previousPage, nextPage);
Table authorTable = results.addTable("browse-by-author-results",
browseInfo.getResultCount() + 1, 1);
authorTable.addRow(Row.ROLE_HEADER).addCell().addContent(T_column_heading);
for (String author : browseInfo.getStringResults())
{
Cell cell = authorTable.addRow().addCell();
cell.addXref("browse-author-items?author=" + URLEncode(author),
author);
}
}
/**
* Recycle
*/
public void recycle() {
this.validity = null;
super.recycle();
}
}

View File

@@ -0,0 +1,291 @@
/*
* BrowseDates.java
*
* Version: $Revision: 1.18 $
*
* Date: $Date: 2006/07/27 18:24:34 $
*
* Copyright (c) 2002, Hewlett-Packard Company and Massachusetts
* Institute of Technology. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* - 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.
*
* - Neither the name of the Hewlett-Packard Company nor the name of the
* Massachusetts Institute of Technology nor the names of their
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS 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 COPYRIGHT
* HOLDERS OR 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.
*/
package org.dspace.app.xmlui.aspect.artifactbrowser;
import java.io.IOException;
import java.io.Serializable;
import java.sql.SQLException;
import java.util.Locale;
import org.apache.cocoon.caching.CacheableProcessingComponent;
import org.apache.cocoon.environment.ObjectModelHelper;
import org.apache.cocoon.environment.Request;
import org.apache.cocoon.util.HashUtil;
import org.apache.excalibur.source.SourceValidity;
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.app.xmlui.wing.element.PageMeta;
import org.dspace.app.xmlui.wing.element.Para;
import org.dspace.app.xmlui.wing.element.Select;
import org.dspace.authorize.AuthorizeException;
import org.dspace.content.DCDate;
import org.dspace.content.DSpaceObject;
import org.dspace.content.Item;
import org.xml.sax.SAXException;
/**
* Display the results of browsing by dates index. This component may either
* apply to all communities and collection or be scoped to just one community /
* collection depending upon the url.
*
* @author Scott Phillips
*/
public class BrowseDates extends AbstractBrowse implements CacheableProcessingComponent
{
/** Languag strings */
private static final Message T_title =
message("xmlui.ArtifactBrowser.BrowseDates.title");
private static final Message T_dspace_home =
message("xmlui.general.dspace_home");
private static final Message T_trail =
message("xmlui.ArtifactBrowser.BrowseDates.trail");
private static final Message T_head =
message("xmlui.ArtifactBrowser.BrowseDates.head");
private static final Message T_jump_select =
message("xmlui.ArtifactBrowser.BrowseDates.jump_select");
private static final Message T_choose_month =
message("xmlui.ArtifactBrowser.BrowseDates.choose_month");
private static final Message T_choose_year =
message("xmlui.ArtifactBrowser.BrowseDates.choose_year");
private static final Message T_jump_year =
message("xmlui.ArtifactBrowser.BrowseDates.jump_year");
private static final Message T_jump_year_help =
message("xmlui.ArtifactBrowser.BrowseDates.jump_year_help");
private static final Message T_go =
message("xmlui.general.go");
/**
* These varables dictate when the drop down list of years is to break from
* 1 year increments, to 5 year increments, to 10 year increments, and
* finialy to stop.
*/
private static final int ONE_YEAR_LIMIT = 10;
private static final int FIVE_YEAR_LIMIT = 30;
private static final int TEN_YEAR_LIMIT = 100;
/** Cached validity object */
private SourceValidity validity;
/**
* Generate the unique caching key.
* This key must be unique inside the space of this component.
*/
public Serializable getKey()
{
Request request = ObjectModelHelper.getRequest(objectModel);
String key = "";
key += "-" + request.getParameter("top");
key += "-" + request.getParameter("bottom");
key += "-" + request.getParameter("startsWith");
key += "-" + request.getParameter("month");
key += "-" + request.getParameter("year");
key += "-" + request.getParameter("author");
try
{
DSpaceObject dso = HandleUtil.obtainHandle(objectModel);
if (dso != null)
key += "-" + dso.getHandle();
return HashUtil.hash(key);
}
catch (Exception e)
{
// Ignore all errors and just don't cache.
return "0";
}
}
/**
* Generate the cache validity object.
*
* The validity object will include all items on this browse page, along
* with all bundles and bitstreams refrenced by them. The one change that
* will not be refelected in this cache is a change is community/collection
* hierarchy.
*/
public SourceValidity getValidity()
{
if (this.validity == null)
{
try
{
DSpaceValidity validity = new DSpaceValidity();
DSpaceObject dso = HandleUtil.obtainHandle(objectModel);
validity.add(dso);
performBrowse(MODE_BY_DATE);
for (Item item : browseInfo.getItemResults())
{
validity.add(item);
}
this.validity = validity.complete();
}
catch (Exception e)
{
// Just ignore all errors and return an invalid cache.
}
}
return this.validity;
}
/**
* Add Page metadata.
*/
public void addPageMeta(PageMeta pageMeta) throws SAXException,
WingException, UIException, SQLException, IOException,
AuthorizeException
{
pageMeta.addMetadata("title").addContent(T_title);
DSpaceObject dso = HandleUtil.obtainHandle(objectModel);
pageMeta.addTrailLink(contextPath + "/", T_dspace_home);
if (dso != null)
HandleUtil.buildHandleTrail(dso, pageMeta,contextPath);
pageMeta.addTrail().addContent(T_trail);
}
/**
* Add the browse-date division.
*/
public void addBody(Body body) throws SAXException, WingException,
UIException, SQLException, IOException, AuthorizeException
{
this.performBrowse(MODE_BY_DATE);
// Pagination variables
int itemsTotal = browseInfo.getTotal();
int firstItemIndex = browseInfo.getOverallPosition() + 1;
int lastItemIndex = browseInfo.getOverallPosition()
+ browseInfo.getResultCount();
String previousPage = previousPageURL("browse-date");
String nextPage = nextPageURL("browse-date");
// Build the DRI Body
Division div = body.addDivision("browse-by-date","primary");
div.setHead(T_head);
// Navigatioal aid
Division jump = div.addInteractiveDivision("browse-navigation",
"browse-date", Division.METHOD_POST,"secondary navigation");
Para jumpForm = jump.addPara();
jumpForm.addContent(T_jump_select);
Select month = jumpForm.addSelect("month");
month.addOption(false, "-1", T_choose_month);
for (int i = 1; i <= 12; i++)
{
month.addOption(false, String.valueOf(i), DCDate.getMonthName(i, Locale.getDefault()));
}
Select year = jumpForm.addSelect("year");
year.addOption(false, "-1", T_choose_year);
int currentYear = DCDate.getCurrent().getYear();
int i = currentYear;
int oneYearBreak = ((currentYear - ONE_YEAR_LIMIT) / 5) * 5;
int fiveYearBreak = ((currentYear - FIVE_YEAR_LIMIT) / 10) * 10;
int tenYearBreak = (currentYear - TEN_YEAR_LIMIT);
do
{
year.addOption(false, String.valueOf(i), String.valueOf(i));
if (i <= fiveYearBreak)
i -= 10;
else if (i <= oneYearBreak)
i -= 5;
else
i--;
}
while (i > tenYearBreak);
jumpForm = jump.addPara();
jumpForm.addContent(T_jump_year);
jumpForm.addText("startsWith").setHelp(T_jump_year_help);
jumpForm.addButton("submit").setValue(T_go);
// This div will hold the browsing results
Division results = div.addDivision("browse-by-date-results","primary");
results.setSimplePagination(itemsTotal, firstItemIndex, lastItemIndex,
previousPage, nextPage);
// Refrence all the browsed items
ReferenceSet referenceSet = results.addReferenceSet("browse-by-date",
ReferenceSet.TYPE_SUMMARY_LIST, "date", null);
for (Item item : browseInfo.getItemResults())
{
referenceSet.addReference(item);
}
}
/**
* Recycle
*/
public void recycle() {
this.validity = null;
super.recycle();
}
}

View File

@@ -0,0 +1,266 @@
/*
* BrowseAuthorItems.java
*
* Version: $Revision: 1.15 $
*
* Date: $Date: 2006/06/02 21:36:56 $
*
* Copyright (c) 2002, Hewlett-Packard Company and Massachusetts
* Institute of Technology. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* - 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.
*
* - Neither the name of the Hewlett-Packard Company nor the name of the
* Massachusetts Institute of Technology nor the names of their
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS 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 COPYRIGHT
* HOLDERS OR 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.
*/
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.environment.ObjectModelHelper;
import org.apache.cocoon.environment.Request;
import org.apache.cocoon.util.HashUtil;
import org.apache.excalibur.source.SourceValidity;
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.app.xmlui.wing.element.PageMeta;
import org.dspace.app.xmlui.wing.element.Xref;
import org.dspace.authorize.AuthorizeException;
import org.dspace.content.DSpaceObject;
import org.dspace.content.Item;
import org.xml.sax.SAXException;
/**
* Display the results of browsing items belonging to a particular subject index.
* This component may either apply to all communities and collection or be
* scoped to just one community / collection depending upon the url.
*
* @author Paulo Jobim
* @author Alexey Maslov
*/
public class BrowseSubjectItems extends AbstractBrowse implements CacheableProcessingComponent
{
/** Language strings: */
private static final Message T_title =
message("xmlui.ArtifactBrowser.BrowseSubjectItems.title");
private static final Message T_dspace_home =
message("xmlui.general.dspace_home");
private static final Message T_trail =
message("xmlui.ArtifactBrowser.BrowseSubjectItems.trail");
private static final Message T_head =
message("xmlui.ArtifactBrowser.BrowseSubjectItems.head");
private static final Message T_back =
message("xmlui.ArtifactBrowser.BrowseSubjectItems.back");
/** How many items should appear on one page */
private static final int ITEMS_PER_PAGE = 20;
/** Cached validity object */
private SourceValidity validity;
/**
* Generate the unique caching key.
* This key must be unique inside the space of this component.
*/
public Serializable getKey()
{
Request request = ObjectModelHelper.getRequest(objectModel);
String key = "";
key += "-" + request.getParameter("top");
key += "-" + request.getParameter("bottom");
key += "-" + request.getParameter("startsWith");
key += "-" + request.getParameter("month");
key += "-" + request.getParameter("year");
key += "-" + request.getParameter("subject");
key += "-" + request.getParameter("subjectTop");
key += "-" + request.getParameter("subjectBottom");
try
{
DSpaceObject dso = HandleUtil.obtainHandle(objectModel);
if (dso != null)
key += "-" + dso.getHandle();
return HashUtil.hash(key);
}
catch (Exception e)
{
// Ignore all errors and just don't cache.
return "0";
}
}
/**
* Generate the cache validity object.
*
* The validity object will include all items on this browse page, along
* with all bundles and bitstreams refrenced by them. The one change that
* will not be refelected in this cache is a change is community/collection
* hierarchy.
*/
public SourceValidity getValidity()
{
if (validity == null)
{
try
{
DSpaceValidity validity = new DSpaceValidity();
DSpaceObject dso = HandleUtil.obtainHandle(objectModel);
validity.add(dso);
performBrowse(MODE_BY_SUBJECT_ITEM);
for (Item item : browseInfo.getItemResults())
{
validity.add(item);
}
this.validity = validity.complete();
}
catch (Exception e)
{
// Just ignore all errors and return an invalid cache.
}
}
return this.validity;
}
/**
* Add Page metadata.
*/
public void addPageMeta(PageMeta pageMeta) throws SAXException,
WingException, UIException, SQLException, IOException,
AuthorizeException
{
pageMeta.addMetadata("title").addContent(T_title);
pageMeta.addTrailLink(contextPath, T_dspace_home);
DSpaceObject dso = HandleUtil.obtainHandle(objectModel);
if (dso != null)
HandleUtil.buildHandleTrail(dso, pageMeta,contextPath);
pageMeta.addTrail().addContent(T_trail);
}
/**
* Add the browse-subject-item division.
*/
public void addBody(Body body) throws SAXException, WingException,
UIException, SQLException, IOException, AuthorizeException
{
// Preform the actual search
performBrowse(MODE_BY_SUBJECT_ITEM);
Request request = ObjectModelHelper.getRequest(objectModel);
Item[] items = browseInfo.getItemResults();
String top = request.getParameter("subjectTop");
String bottom = request.getParameter("subjectBottom");
String subject = request.getParameter("subject");
// Determine Pagination variables
int itemsTotal = items.length;
int firstItemIndex = 0;
int lastItemIndex = firstItemIndex + ITEMS_PER_PAGE;
// Should we shift the pagination view because of a top or bottom
// directive?
if (top != null)
{
// Move the indexs to match pagination
firstItemIndex = Integer.valueOf(top);
lastItemIndex = firstItemIndex + ITEMS_PER_PAGE;
}
else if (bottom != null)
{
lastItemIndex = Integer.valueOf(bottom);
firstItemIndex = lastItemIndex - ITEMS_PER_PAGE;
}
// Check four out of bounds indices.
if (firstItemIndex < 0)
firstItemIndex = 0;
if (lastItemIndex > items.length - 1)
lastItemIndex = items.length - 1;
// Determine the next & previous link;
String baseURL = "browse-subject-items?subject=" + URLEncode(subject);
String previousPage = null;
String nextPage = null;
if (firstItemIndex > 0)
previousPage = baseURL + "&subjectBottom=" + (firstItemIndex);
if (lastItemIndex < items.length - 1)
nextPage = baseURL + "&subjectTop=" + (lastItemIndex);
// Build the DRI Body
Division div = body.addDivision("browse-by-subject-item","primary");
div.setHead(T_head.parameterize(subject));
// Navigatioal aid (really this is a poor version of pagination)
Division jump = div.addInteractiveDivision("browse-navigation",
"browse-subject-items", Division.METHOD_POST,"secondary navigation");
Xref link = jump.addPara().addXref("browse-subject?startsWith=" + URLEncode(subject));
link.addContent(T_back);
// This div will hold the browsing results
Division results = div.addDivision("browse-by-subject-item-results","primary");
results.setSimplePagination(itemsTotal, firstItemIndex + 1, lastItemIndex + 1,
previousPage, nextPage);
// Refrence all the browsed items
ReferenceSet referenceSet = results.addReferenceSet("browse-by-subject-item",
ReferenceSet.TYPE_SUMMARY_LIST, "subject", null);
for (int i = firstItemIndex; i <= lastItemIndex; i++)
{
referenceSet.addReference(items[i]);
}
}
/**
* Recycle
*/
public void recycle() {
this.validity = null;
super.recycle();
}
}

View File

@@ -0,0 +1,245 @@
/*
* BrowseAuthors.java
*
* Version: $Revision: 1.16 $
*
* Date: $Date: 2006/07/27 18:24:34 $
*
* Copyright (c) 2002, Hewlett-Packard Company and Massachusetts
* Institute of Technology. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* - 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.
*
* - Neither the name of the Hewlett-Packard Company nor the name of the
* Massachusetts Institute of Technology nor the names of their
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS 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 COPYRIGHT
* HOLDERS OR 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.
*/
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.environment.ObjectModelHelper;
import org.apache.cocoon.environment.Request;
import org.apache.cocoon.util.HashUtil;
import org.apache.excalibur.source.SourceValidity;
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.Cell;
import org.dspace.app.xmlui.wing.element.Division;
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.Row;
import org.dspace.app.xmlui.wing.element.Table;
import org.dspace.authorize.AuthorizeException;
import org.dspace.content.DSpaceObject;
import org.xml.sax.SAXException;
/**
* Display the results of browsing subject index. This component may either apply
* to all communities and collection or be scoped to just one community /
* collection depending upon the url.
*
* @author Paulo Jobim
* @author Alexey Maslov
*/
public class BrowseSubjects extends AbstractBrowse implements CacheableProcessingComponent
{
/** Language Strings */
private static final Message T_title =
message("xmlui.ArtifactBrowser.BrowseSubjects.title");
private static final Message T_dspace_home =
message("xmlui.general.dspace_home");
private static final Message T_trail =
message("xmlui.ArtifactBrowser.BrowseSubjects.trail");
private static final Message T_head =
message("xmlui.ArtifactBrowser.BrowseSubjects.head");
private static final Message T_starts_with =
message("xmlui.ArtifactBrowser.BrowseSubjects.starts_with");
private static final Message T_go =
message("xmlui.general.go");
private static final Message T_column_heading =
message("xmlui.ArtifactBrowser.BrowseSubjects.column_heading");
/** Cached validity object */
private SourceValidity validity;
/**
* Generate the unique caching key.
* This key must be unique inside the space of this component.
*/
public Serializable getKey()
{
Request request = ObjectModelHelper.getRequest(objectModel);
String key = "";
key += "-" + request.getParameter("top");
key += "-" + request.getParameter("bottom");
key += "-" + request.getParameter("startsWith");
key += "-" + request.getParameter("month");
key += "-" + request.getParameter("year");
key += "-" + request.getParameter("subject");
try
{
DSpaceObject dso = HandleUtil.obtainHandle(objectModel);
if (dso != null)
key += "-" + dso.getHandle();
return HashUtil.hash(key);
}
catch (Exception e)
{
// Ignore all errors and just don't cache.
return "0";
}
}
/**
* Generate the cache validity object.
*
* The validity object will include all items on this browse page, along
* with all bundles and bitstreams refrenced by them. The one change that
* will not be refelected in this cache is a change is community/collection
* hierarchy.
*/
public SourceValidity getValidity()
{
if (validity == null)
{
try
{
DSpaceValidity validity = new DSpaceValidity();
DSpaceObject dso = HandleUtil.obtainHandle(objectModel);
validity.add(dso);
performBrowse(MODE_BY_SUBJECT);
for (String subject : browseInfo.getStringResults())
{
validity.add(subject);
}
this.validity = validity.complete();
}
catch (Exception e)
{
// Just ignore all errors and return an invalid cache.
}
}
return this.validity;
}
/**
* Add Page metadata.
*/
public void addPageMeta(PageMeta pageMeta) throws SAXException,
WingException, UIException, SQLException, IOException,
AuthorizeException
{
pageMeta.addMetadata("title").addContent(T_title);
DSpaceObject dso = HandleUtil.obtainHandle(objectModel);
pageMeta.addTrailLink(contextPath + "/", T_dspace_home);
if (dso != null)
HandleUtil.buildHandleTrail(dso, pageMeta,contextPath);
pageMeta.addTrail().addContent(T_trail);
}
/**
* Add the browse-subject division.
*/
public void addBody(Body body) throws SAXException, WingException,
UIException, SQLException, IOException, AuthorizeException
{
performBrowse(MODE_BY_SUBJECT);
// Pagination variables
int itemsTotal = browseInfo.getTotal();
int firstItemIndex = browseInfo.getOverallPosition() + 1;
int lastItemIndex = browseInfo.getOverallPosition()
+ browseInfo.getResultCount();
String previousPage = previousPageURL("browse-subject");
String nextPage = nextPageURL("browse-subject");
// Build the DRI Body
Division div = body.addDivision("browse-by-subject","primary");
div.setHead(T_head);
// Navigatioal aid (really this is a poor version of pagination)
Division jump = div.addInteractiveDivision("browse-navigation",
"browse-subject", Division.METHOD_POST,"secondary navigation");
List jumpList = jump.addList("jump-list", List.TYPE_SIMPLE, "alphabet");
for (char c = 'A'; c <= 'Z'; c++)
jumpList.addItemXref("browse-subject?startsWith=" + c, String
.valueOf(c));
Para jumpForm = jump.addPara();
jumpForm.addContent(T_starts_with);
jumpForm.addText("startsWith");
jumpForm.addButton("submit").setValue(T_go);
// This div will hold the browsing results
Division results = div.addDivision("browse-by-subject-results","primary");
results.setSimplePagination(itemsTotal, firstItemIndex, lastItemIndex,
previousPage, nextPage);
Table subjectTable = results.addTable("browse-by-subject-results",
browseInfo.getResultCount() + 1, 1);
subjectTable.addRow(Row.ROLE_HEADER).addCell().addContent(T_column_heading);
for (String subject : browseInfo.getStringResults())
{
Cell cell = subjectTable.addRow().addCell();
cell.addXref("browse-subject-items?subject=" + URLEncode(subject),
subject);
}
}
/**
* Recycle
*/
public void recycle() {
this.validity = null;
super.recycle();
}
}

View File

@@ -0,0 +1,245 @@
/*
* BrowseTitles.java
*
* Version: $Revision: 1.15 $
*
* Date: $Date: 2006/07/27 18:24:34 $
*
* Copyright (c) 2002, Hewlett-Packard Company and Massachusetts
* Institute of Technology. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* - 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.
*
* - Neither the name of the Hewlett-Packard Company nor the name of the
* Massachusetts Institute of Technology nor the names of their
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS 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 COPYRIGHT
* HOLDERS OR 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.
*/
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.environment.ObjectModelHelper;
import org.apache.cocoon.environment.Request;
import org.apache.cocoon.util.HashUtil;
import org.apache.excalibur.source.SourceValidity;
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.app.xmlui.wing.element.List;
import org.dspace.app.xmlui.wing.element.PageMeta;
import org.dspace.app.xmlui.wing.element.Para;
import org.dspace.authorize.AuthorizeException;
import org.dspace.content.DSpaceObject;
import org.dspace.content.Item;
import org.xml.sax.SAXException;
/**
* Display the results of browsing title index. This component may either apply
* to all communities and collection or be scoped to just one community /
* collection depending upon the url.
*
* @author Scott Phillips
*/
public class BrowseTitles extends AbstractBrowse implements CacheableProcessingComponent
{
/** Language strings */
private final static Message T_title =
message("xmlui.ArtifactBrowser.BrowseTitles.title");
private final static Message T_dspace_home =
message("xmlui.general.dspace_home");
private final static Message T_trail =
message("xmlui.ArtifactBrowser.BrowseTitles.trail");
private final static Message T_head =
message("xmlui.ArtifactBrowser.BrowseTitles.head");
private final static Message T_starts_with =
message("xmlui.ArtifactBrowser.BrowseTitles.starts_with");
private final static Message T_starts_with_help =
message("xmlui.ArtifactBrowser.BrowseTitles.starts_with_help");
private final static Message T_go =
message("xmlui.general.go");
/** Cached validity object */
private SourceValidity validity;
/**
* Generate the unique caching key.
* This key must be unique inside the space of this component.
*/
public Serializable getKey()
{
Request request = ObjectModelHelper.getRequest(objectModel);
String key = "";
key += "-" + request.getParameter("top");
key += "-" + request.getParameter("bottom");
key += "-" + request.getParameter("startsWith");
key += "-" + request.getParameter("month");
key += "-" + request.getParameter("year");
key += "-" + request.getParameter("author");
try
{
DSpaceObject dso = HandleUtil.obtainHandle(objectModel);
if (dso != null)
key += "-" + dso.getHandle();
return HashUtil.hash(key);
}
catch (Exception e)
{
// Ignore all errors and just don't cache.
return "0";
}
}
/**
* Generate the cache validity object.
*
* The validity object will include all items on this browse page, along
* with all bundles and bitstreams refrenced by them. The one change that
* will not be refelected in this cache is a change is community/collection
* hierarchy.
*/
public SourceValidity getValidity()
{
if (this.validity == null)
{
try
{
DSpaceValidity validity = new DSpaceValidity();
DSpaceObject dso = HandleUtil.obtainHandle(objectModel);
validity.add(dso);
performBrowse(MODE_BY_TITLE);
for (Item item : browseInfo.getItemResults())
{
validity.add(item);
}
this.validity = validity.complete();
}
catch (Exception e)
{
// Just ignore all errors and return an invalid cache.
}
}
return this.validity;
}
/**
* Add Page metadata.
*/
public void addPageMeta(PageMeta pageMeta) throws SAXException,
WingException, UIException, SQLException, IOException,
AuthorizeException
{
pageMeta.addMetadata("title").addContent(T_title);
DSpaceObject dso = HandleUtil.obtainHandle(objectModel);
pageMeta.addTrailLink(contextPath + "/", T_dspace_home);
if (dso != null)
HandleUtil.buildHandleTrail(dso, pageMeta,contextPath);
pageMeta.addTrail().addContent(T_trail);
}
/**
* Add the browse-title division.
*/
public void addBody(Body body) throws SAXException, WingException,
UIException, SQLException, IOException, AuthorizeException
{
performBrowse(MODE_BY_TITLE);
// Pagination variables
int itemsTotal = browseInfo.getTotal();
int firstItemIndex = browseInfo.getOverallPosition() + 1;
int lastItemIndex = browseInfo.getOverallPosition()
+ browseInfo.getResultCount();
String previousPage = previousPageURL("browse-title");
String nextPage = nextPageURL("browse-title");
// Build the DRI Body
Division div = body.addDivision("browse-by-title","primary");
div.setHead(T_head);
// Navigatioal aid (really this is a poor version of pagination)
Division jump = div.addInteractiveDivision("browse-navigation",
"browse-title", Division.METHOD_POST, "secondary navigation");
List jumpList = jump.addList("jump-list", List.TYPE_SIMPLE, "alphabet");
for (char c = 'A'; c <= 'Z'; c++)
jumpList.addItemXref("browse-title?startsWith=" + c, String
.valueOf(c));
Para jumpForm = jump.addPara();
jumpForm.addContent(T_starts_with);
jumpForm.addText("startsWith").setHelp(T_starts_with_help);
jumpForm.addButton("submit").setValue(T_go);
// This div will hold the browsing results
Division results = div.addDivision("browse-by-title-results","primary");
results.setSimplePagination(itemsTotal, firstItemIndex, lastItemIndex,
previousPage, nextPage);
// Refrence all the browsed items
ReferenceSet referenceSet = results.addReferenceSet("browse-by-title",
ReferenceSet.TYPE_SUMMARY_LIST, "title", null);
for (Item item : browseInfo.getItemResults())
{
referenceSet.addReference(item);
}
}
/**
* Recycle
*/
public void recycle() {
this.validity = null;
super.recycle();
}
}

View File

@@ -0,0 +1,321 @@
/*
* CollectionViewer.java
*
* Version: $Revision: 1.21 $
*
* Date: $Date: 2006/07/27 18:24:34 $
*
* Copyright (c) 2002, Hewlett-Packard Company and Massachusetts
* Institute of Technology. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* - 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.
*
* - Neither the name of the Hewlett-Packard Company nor the name of the
* Massachusetts Institute of Technology nor the names of their
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS 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 COPYRIGHT
* HOLDERS OR 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.
*/
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;
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.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.authorize.AuthorizeException;
import org.dspace.browse.Browse;
import org.dspace.browse.BrowseScope;
import org.dspace.content.Collection;
import org.dspace.content.DSpaceObject;
import org.dspace.content.Item;
import org.dspace.core.ConfigurationManager;
import org.xml.sax.SAXException;
/**
* Display a single collection. This includes a full text search, browse by
* list, community display and a list of recent submissions.
*
* @author Scott Phillips
*/
public class CollectionViewer extends AbstractDSpaceTransformer implements CacheableProcessingComponent
{
/** Language Strings */
private static final Message T_dspace_home =
message("xmlui.general.dspace_home");
private static final Message T_full_text_search =
message("xmlui.ArtifactBrowser.CollectionViewer.full_text_search");
private static final Message T_go =
message("xmlui.general.go");
private static final Message T_head_browse =
message("xmlui.ArtifactBrowser.CollectionViewer.head_browse");
private static final Message T_browse_titles =
message("xmlui.ArtifactBrowser.CollectionViewer.browse_titles");
private static final Message T_browse_authors =
message("xmlui.ArtifactBrowser.CollectionViewer.browse_authors");
private static final Message T_browse_dates =
message("xmlui.ArtifactBrowser.CollectionViewer.browse_dates");
private static final Message T_head_recent_submissions =
message("xmlui.ArtifactBrowser.CollectionViewer.head_recent_submissions");
/** How many recent submissions to include in the page */
private static final int RECENT_SUBMISISONS = 5;
/** The cache of recently submitted items */
private java.util.List<Item> recentSubmissionItems;
/** Cached validity object */
private SourceValidity validity;
/**
* 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";
return HashUtil.hash(dso.getHandle());
}
catch (SQLException sqle)
{
// Ignore all errors and just return that the component is not
// cachable.
return "0";
}
}
/**
* Generate the cache validity object.
*
* The validity object will include the collection being viewed and
* all recently submitted items. This does not include the community / collection
* hierarch, when this changes they will not be reflected in the cache.
*/
public SourceValidity getValidity()
{
if (this.validity == null)
{
try
{
DSpaceObject dso = HandleUtil.obtainHandle(objectModel);
if (dso == null)
return null;
if (!(dso instanceof Collection))
return null;
Collection collection = (Collection) dso;
DSpaceValidity validity = new DSpaceValidity();
// Add the actual collection;
validity.add(collection);
// add reciently submitted items
for(Item item : getRecientlySubmittedIems(collection))
{
validity.add(item);
}
this.validity = validity.complete();
}
catch (Exception e)
{
// Just ignore all errors and return an invalid cache.
}
}
return this.validity;
}
/**
* Add a page title and trail links.
*/
public void addPageMeta(PageMeta pageMeta) throws SAXException,
WingException, UIException, SQLException, IOException,
AuthorizeException
{
DSpaceObject dso = HandleUtil.obtainHandle(objectModel);
if (!(dso instanceof Collection))
return;
Collection collection = (Collection) dso;
// Set the page title
pageMeta.addMetadata("title")
.addContent(collection.getMetadata("name"));
pageMeta.addTrailLink(contextPath + "/",T_dspace_home);
HandleUtil.buildHandleTrail(collection,pageMeta,contextPath);
// Add RSS links if available
String formats = ConfigurationManager.getProperty("webui.feed.formats");
if ( formats != null )
{
for (String format : formats.split(","))
{
// Remove the protocol number, i.e. just list 'rss' or' atom'
String[] parts = format.split("_");
if (parts.length < 1)
continue;
String feedFormat = parts[0].trim()+"+xml";
String feedURL = contextPath+"/feed/"+collection.getHandle()+"/"+format.trim();
pageMeta.addMetadata("feed", feedFormat).addContent(feedURL);
}
}
}
/**
* Display a single collection
*/
public void addBody(Body body) throws SAXException, WingException,
UIException, SQLException, IOException, AuthorizeException
{
DSpaceObject dso = HandleUtil.obtainHandle(objectModel);
if (!(dso instanceof Collection))
return;
// Set up the major variables
Collection collection = (Collection) dso;
// Build the collection viewer division.
Division home = body.addDivision("collection-home", "primary repository collection");
home.setHead(collection.getMetadata("name"));
// The search / browse box.
{
Division search = home.addDivision("collection-search-browse",
"secondary search-browse");
// Search query
Division query = search.addInteractiveDivision("collection-search",
contextPath + "/handle/" + collection.getHandle() + "/search",
Division.METHOD_POST, "secondary search");
Para para = query.addPara("search-query", null);
para.addContent(T_full_text_search);
para.addContent(" ");
para.addText("query");
para.addContent(" ");
para.addButton("submit").setValue(T_go);
// Browse by list
Division browseDiv = search.addDivision("collection-browse","secondary browse");
List browse = browseDiv.addList("collection-browse", List.TYPE_SIMPLE,
"collection-browse");
browse.setHead(T_head_browse);
String url = contextPath + "/handle/" + collection.getHandle();
browse.addItemXref(url + "/browse-title",T_browse_titles);
browse.addItemXref(url + "/browse-author",T_browse_authors);
browse.addItemXref(url + "/browse-date",T_browse_dates);
}
// Add the refrence
{
Division viewer = home.addDivision("collection-view","secondary");
ReferenceSet mainInclude = viewer.addReferenceSet("collection-view",
ReferenceSet.TYPE_DETAIL_VIEW);
mainInclude.addReference(collection);
}
// Reciently submitted items
{
java.util.List<Item> items = getRecientlySubmittedIems(collection);
Division lastSubmittedDiv = home
.addDivision("collection-recent-submission","secondary recent-submission");
lastSubmittedDiv.setHead(T_head_recent_submissions);
ReferenceSet lastSubmitted = lastSubmittedDiv.addReferenceSet(
"collection-last-submitted", ReferenceSet.TYPE_SUMMARY_LIST,
null, "recent-submissions");
for (Item item : items)
{
lastSubmitted.addReference(item);
}
}
}
/**
* Get the recently submitted items for the given collection.
*
* @param collection The collection.
*/
@SuppressWarnings("unchecked") // The cast from getLastSubmitted is correct, it dose infact return a list of Items.
private java.util.List<Item> getRecientlySubmittedIems(Collection collection)
throws SQLException
{
if (recentSubmissionItems != null)
return recentSubmissionItems;
BrowseScope scope = new BrowseScope(context);
scope.setScope(collection);
scope.setTotal(RECENT_SUBMISISONS);
this.recentSubmissionItems = Browse.getLastSubmitted(scope);
return this.recentSubmissionItems;
}
/**
* Recycle
*/
public void recycle()
{
// Clear out our item's cache.
this.recentSubmissionItems = null;
this.validity = null;
super.recycle();
}
}

View File

@@ -0,0 +1,471 @@
/*
* CommunityBrowser.java
*
* Version: $Revision: 1.15 $
*
* Date: $Date: 2006/08/08 20:58:04 $
*
* Copyright (c) 2002, Hewlett-Packard Company and Massachusetts
* Institute of Technology. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* - 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.
*
* - Neither the name of the Hewlett-Packard Company nor the name of the
* Massachusetts Institute of Technology nor the names of their
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS 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 COPYRIGHT
* HOLDERS OR 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.
*/
package org.dspace.app.xmlui.aspect.artifactbrowser;
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;
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.DSpaceValidity;
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.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.content.Collection;
import org.dspace.content.Community;
import org.dspace.content.DSpaceObject;
import org.dspace.core.ConfigurationManager;
import org.dspace.core.Constants;
import org.xml.sax.SAXException;
/**
* Display a list of Communities and collections.
*
* This item may be configured so that it will only display to a specific depth,
* and may include or exclude collections from the tree.
*
* The configuration option available: <depth exclude-collections="true">999</depth>
*
* @author Scott Phillips
*/
public class CommunityBrowser extends AbstractDSpaceTransformer implements CacheableProcessingComponent
{
/** Language Strings */
public static final Message T_dspace_home =
message("xmlui.general.dspace_home");
public static final Message T_title =
message("xmlui.ArtifactBrowser.CommunityBrowser.title");
public static final Message T_trail =
message("xmlui.ArtifactBrowser.CommunityBrowser.trail");
public static final Message T_head =
message("xmlui.ArtifactBrowser.CommunityBrowser.head");
public static final Message T_select =
message("xmlui.ArtifactBrowser.CommunityBrowser.select");
/** 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;
/** Cached version the community / collection hierarch */
protected TreeNode root;
/** cached validity object */
private SourceValidity validity;
/**
* 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", DEFAULT_DEPTH);
excludeCollections = parameters.getParameterAsBoolean(
"exclude-collections", false);
}
/**
* Generate the unique caching key.
* This key must be unique inside the space of this component.
*/
public Serializable getKey()
{
boolean full = ConfigurationManager.getBooleanProperty("xmlui.community-list.render.full", true);
return HashUtil.hash(depth + "-" + excludeCollections + "-" + (full ? "true" : "false"));
}
/**
* Generate the cache validity object.
*
* The validity object will include a list of all communities
* & collection being browsed along with there logo bitstreams.
*/
public SourceValidity getValidity()
{
if (validity == null)
{
try {
DSpaceValidity validity = new DSpaceValidity();
TreeNode root = buildTree(Community.findAllTop(context));
Stack<TreeNode> stack = new Stack<TreeNode>();
stack.push(root);
int objectCount = 0;
while (!stack.empty())
{
objectCount++;
TreeNode node = stack.pop();
validity.add(node.getDSO());
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);
this.validity = validity.complete();
}
catch (SQLException sqle)
{
// ignore all errors and return an invalid cache.
}
}
return this.validity;
}
/**
* Add a page title and trail links.
*/
public void addPageMeta(PageMeta pageMeta) throws SAXException,
WingException, UIException, SQLException, IOException,
AuthorizeException
{
// Set the page title
pageMeta.addMetadata("title").addContent(T_title);
pageMeta.addTrailLink(contextPath + "/",T_dspace_home);
pageMeta.addTrail().addContent(T_trail);
}
/**
* Add a community-browser division that includes refrences to community and
* collection metadata.
*/
public void addBody(Body body) throws SAXException, WingException,
UIException, SQLException, IOException, AuthorizeException
{
Division division = body.addDivision("comunity-browser", "primary");
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");
ArrayList<TreeNode> rootNodes = root.getChildrenOfType(Constants.COMMUNITY);
for (TreeNode node : rootNodes)
{
buildReferenceSet(referenceSet,node);
}
}
else
{
List list = division.addList("comunity-browser");
ArrayList<TreeNode> rootNodes = root.getChildrenOfType(Constants.COMMUNITY);
for (TreeNode node : rootNodes)
{
buildList(list,node);
}
}
}
/**
* Recursively build an includeset of the community / collection hierarcher based upon
* the given NodeTree.
*
* @param referenceSet The include set
* @param node The current node of the hierarch.
*/
public void buildReferenceSet(ReferenceSet referenceSet, TreeNode node) throws WingException
{
DSpaceObject dso = node.getDSO();
Reference objectInclude = referenceSet.addReference(dso);
// Add all the sub-collections;
ArrayList<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
ArrayList<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 hierarchery based upon
* the given NodeTree.
*
* @param List The parent list
* @param node The current node of the hierarch.
*/
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;
ArrayList<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
ArrayList<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;
this.validity = null;
super.recycle();
}
/**
* construct a tree structure of communities and collections. The results
* of this hirarchy are cached so calling it multipletimes 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 hirarchy that this node is at. */
private int level;
/** All children of this node */
private ArrayList<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 hirarchy of this node.
*/
public int getLevel()
{
return this.level;
}
/**
* @return All children
*/
public ArrayList<TreeNode> getChildren()
{
return children;
}
/**
* @return All children of the given @type.
*/
public ArrayList<TreeNode> getChildrenOfType(int type)
{
ArrayList<TreeNode> results = new ArrayList<TreeNode>();
for (TreeNode node : children)
{
if (node.dso.getType() == type)
results.add(node);
}
return results;
}
}
}

View File

@@ -0,0 +1,372 @@
/*
* CommunityViewer.java
*
* Version: $Revision: 1.22 $
*
* Date: $Date: 2006/08/30 19:16:56 $
*
* Copyright (c) 2002, Hewlett-Packard Company and Massachusetts
* Institute of Technology. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* - 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.
*
* - Neither the name of the Hewlett-Packard Company nor the name of the
* Massachusetts Institute of Technology nor the names of their
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS 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 COPYRIGHT
* HOLDERS OR 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.
*/
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;
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.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.Reference;
import org.dspace.app.xmlui.wing.element.PageMeta;
import org.dspace.app.xmlui.wing.element.Para;
import org.dspace.authorize.AuthorizeException;
import org.dspace.browse.Browse;
import org.dspace.browse.BrowseScope;
import org.dspace.content.Collection;
import org.dspace.content.Community;
import org.dspace.content.DSpaceObject;
import org.dspace.content.Item;
import org.dspace.core.ConfigurationManager;
import org.xml.sax.SAXException;
/**
* Display a single community. This includes a full text search, browse by list,
* community display and a list of recent submissions.
*
* @author Scott Phillips
*/
public class CommunityViewer extends AbstractDSpaceTransformer implements CacheableProcessingComponent
{
/** Language Strings */
private static final Message T_dspace_home =
message("xmlui.general.dspace_home");
private static final Message T_full_text_search =
message("xmlui.ArtifactBrowser.CommunityViewer.full_text_search");
private static final Message T_go =
message("xmlui.general.go");
private static final Message T_head_browse =
message("xmlui.ArtifactBrowser.CommunityViewer.head_browse");
private static final Message T_browse_titles =
message("xmlui.ArtifactBrowser.CommunityViewer.browse_titles");
private static final Message T_browse_authors =
message("xmlui.ArtifactBrowser.CommunityViewer.browse_authors");
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");
private static final Message T_head_recent_submissions =
message("xmlui.ArtifactBrowser.CommunityViewer.head_recent_submissions");
/** How many recient submissions to list */
private static final int RECENT_SUBMISISONS = 5;
/** The cache of recently submitted items */
private java.util.List<Item> recentSubmittedItems;
/** Cached validity object */
private SourceValidity validity;
/**
* 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());
}
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 the community being viewed, all
* sub-communites (one level deep), all sub-collections, and
* recently submitted items.
*/
public SourceValidity getValidity()
{
if (this.validity == null)
{
try {
DSpaceObject dso = HandleUtil.obtainHandle(objectModel);
if (dso == null)
return null;
if (!(dso instanceof Community))
return null;
Community community = (Community) dso;
DSpaceValidity validity = new DSpaceValidity();
validity.add(community);
Community[] subCommunities = community.getSubcommunities();
Collection[] collections = community.getCollections();
// Sub communities
for (Community subCommunity : subCommunities)
{
validity.add(subCommunity);
}
// Sub collections
for (Collection collection : collections)
{
validity.add(collection);
}
// Recently submitted items
for (Item item : getRecientlySubmittedIems(community))
{
validity.add(item);
}
this.validity = validity.complete();
}
catch (Exception e)
{
// Ignore all errors and invalidate the cache.
}
}
return this.validity;
}
/**
* Add the community's title and trail links to the page's metadata
*/
public void addPageMeta(PageMeta pageMeta) throws SAXException,
WingException, UIException, SQLException, IOException,
AuthorizeException
{
DSpaceObject dso = HandleUtil.obtainHandle(objectModel);
if (!(dso instanceof Community))
return;
// Set up the major variables
Community community = (Community) dso;
// Set the page title
pageMeta.addMetadata("title").addContent(community.getMetadata("name"));
// Add the trail back to the repository root.
pageMeta.addTrailLink(contextPath + "/",T_dspace_home);
HandleUtil.buildHandleTrail(community, pageMeta,contextPath);
// Add RSS links if available
String formats = ConfigurationManager.getProperty("webui.feed.formats");
if ( formats != null )
{
for (String format : formats.split(","))
{
// Remove the protocol number, i.e. just list 'rss' or' atom'
String[] parts = format.split("_");
if (parts.length < 1)
continue;
String feedFormat = parts[0].trim()+"+xml";
String feedURL = contextPath+"/feed/"+community.getHandle()+"/"+format.trim();
pageMeta.addMetadata("feed", feedFormat).addContent(feedURL);
}
}
}
/**
* Display a single community (and refrence any sub communites or
* collections)
*/
public void addBody(Body body) throws SAXException, WingException,
UIException, SQLException, IOException, AuthorizeException
{
DSpaceObject dso = HandleUtil.obtainHandle(objectModel);
if (!(dso instanceof Community))
return;
// 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");
home.setHead(community.getMetadata("name"));
// The search / browse box.
{
Division search = home.addDivision("community-search-browse",
"secondary search-browse");
// Search query
Division query = search.addInteractiveDivision("community-search",
contextPath + "/handle/" + community.getHandle() + "/search",
Division.METHOD_POST, "secondary search");
Para para = query.addPara("search-query", null);
para.addContent(T_full_text_search);
para.addContent(" ");
para.addText("query");
para.addContent(" ");
para.addButton("submit").setValue(T_go);
// Browse by list
Division browseDiv = search.addDivision("community-browse","secondary browse");
List browse = browseDiv.addList("community-browse", List.TYPE_SIMPLE,
"community-browse");
browse.setHead(T_head_browse);
String url = contextPath + "/handle/" + community.getHandle();
browse.addItemXref(url + "/browse-title",T_browse_titles);
browse.addItemXref(url + "/browse-author",T_browse_authors);
browse.addItemXref(url + "/browse-date",T_browse_dates);
}
// Add main reference:
{
Division viewer = home.addDivision("community-view","secondary");
ReferenceSet referenceSet = viewer.addReferenceSet("community-view",
ReferenceSet.TYPE_DETAIL_VIEW);
Reference communityInclude = referenceSet.addReference(community);
// If the community has any children communities also refrence them.
if (subCommunities != null && subCommunities.length > 0)
{
ReferenceSet communityReferenceSet = communityInclude
.addReferenceSet(ReferenceSet.TYPE_SUMMARY_LIST,null,"hierarchy");
communityReferenceSet.setHead(T_head_sub_communities);
// Sub communities
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);
// Sub collections
for (Collection collection : collections)
{
communityReferenceSet.addReference(collection);
}
}
}// main refrence
// Reciently submitted items
{
java.util.List<Item> items = getRecientlySubmittedIems(community);
Division lastSubmittedDiv = home
.addDivision("community-recent-submission","secondary recent-submission");
lastSubmittedDiv.setHead(T_head_recent_submissions);
ReferenceSet lastSubmitted = lastSubmittedDiv.addReferenceSet(
"collection-last-submitted", ReferenceSet.TYPE_SUMMARY_LIST,
null, "recent-submissions");
for (Item item : items)
{
lastSubmitted.addReference(item);
}
}
}
/**
* Get the recently submitted items for the given community.
*
* @param community The community.
*/
@SuppressWarnings("unchecked")
private java.util.List<Item> getRecientlySubmittedIems(Community community)
throws SQLException
{
if (recentSubmittedItems != null)
return recentSubmittedItems;
BrowseScope scope = new BrowseScope(context);
scope.setScope(community);
scope.setTotal(RECENT_SUBMISISONS);
this.recentSubmittedItems = Browse.getLastSubmitted(scope);
return this.recentSubmittedItems;
}
/**
* Recycle
*/
public void recycle()
{
// Clear out our item's cache.
this.recentSubmittedItems = null;
this.validity = null;
super.recycle();
}
}

View File

@@ -0,0 +1,143 @@
/*
* Contact.java
*
* Version: $Revision: 1.2 $
*
* Date: $Date: 2006/06/02 21:36:57 $
*
* Copyright (c) 2002, Hewlett-Packard Company and Massachusetts
* Institute of Technology. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* - 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.
*
* - Neither the name of the Hewlett-Packard Company nor the name of the
* Massachusetts Institute of Technology nor the names of their
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS 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 COPYRIGHT
* HOLDERS OR 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.
*/
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.excalibur.source.SourceValidity;
import org.apache.excalibur.source.impl.validity.NOPValidity;
import org.dspace.app.xmlui.cocoon.AbstractDSpaceTransformer;
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.List;
import org.dspace.app.xmlui.wing.element.PageMeta;
import org.dspace.authorize.AuthorizeException;
import org.dspace.core.ConfigurationManager;
import org.xml.sax.SAXException;
/**
* Create a simple contact us page. Fancier contact us pages should be handled by the theme.
*
*
* @author Scott Phillips
*/
public class Contact extends AbstractDSpaceTransformer implements CacheableProcessingComponent
{
/** language strings */
private static final Message T_title =
message("xmlui.ArtifactBrowser.Contact.title");
private static final Message T_dspace_home =
message("xmlui.general.dspace_home");
private static final Message T_trail =
message("xmlui.ArtifactBrowser.Contact.trail");
private static final Message T_head =
message("xmlui.ArtifactBrowser.Contact.head");
private static final Message T_para1 =
message("xmlui.ArtifactBrowser.Contact.para1");
private static final Message T_feedback_label =
message("xmlui.ArtifactBrowser.Contact.feedback_label");
private static final Message T_feedback_link =
message("xmlui.ArtifactBrowser.Contact.feedback_link");
private static final Message T_email =
message("xmlui.ArtifactBrowser.Contact.email");
/**
* Generate the unique caching key.
* This key must be unique inside the space of this component.
*/
public Serializable getKey()
{
return "1";
}
/**
* Generate the cache validity object.
*/
public SourceValidity getValidity()
{
return NOPValidity.SHARED_INSTANCE;
}
public void addPageMeta(PageMeta pageMeta) throws SAXException,
WingException, UIException, SQLException, IOException,
AuthorizeException
{
pageMeta.addMetadata("title").addContent(T_title);
pageMeta.addTrailLink(contextPath + "/",T_dspace_home);
pageMeta.addTrail().addContent(T_trail);
}
public void addBody(Body body) throws SAXException, WingException,
UIException, SQLException, IOException, AuthorizeException
{
Division contact = body.addDivision("contact","primary");
contact.setHead(T_head);
String name = ConfigurationManager.getProperty("dspace.name");
contact.addPara(T_para1.parameterize(name));
List list = contact.addList("contact");
list.addLabel(T_feedback_label);
list.addItem().addXref(contextPath+"/feedback",T_feedback_link);
list.addLabel(T_email);
String email = ConfigurationManager.getProperty("mail.admin");
list.addItem().addXref("mailto:"+email,email);
}
}

View File

@@ -0,0 +1,158 @@
/*
* FeedbackForm.java
*
* Version: $Revision: 1.4 $
*
* Date: $Date: 2006/07/27 18:24:34 $
*
* Copyright (c) 2002, Hewlett-Packard Company and Massachusetts
* Institute of Technology. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* - 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.
*
* - Neither the name of the Hewlett-Packard Company nor the name of the
* Massachusetts Institute of Technology nor the names of their
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS 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 COPYRIGHT
* HOLDERS OR 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.
*/
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;
import org.apache.excalibur.source.impl.validity.NOPValidity;
import org.dspace.app.xmlui.cocoon.AbstractDSpaceTransformer;
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.List;
import org.dspace.app.xmlui.wing.element.PageMeta;
import org.dspace.app.xmlui.wing.element.Text;
import org.dspace.app.xmlui.wing.element.TextArea;
import org.dspace.authorize.AuthorizeException;
import org.xml.sax.SAXException;
/**
* Display to the user a simple form letting the user give feedback.
*
* @author Scott Phillips
*/
public class FeedbackForm extends AbstractDSpaceTransformer implements CacheableProcessingComponent
{
/** Language Strings */
private static final Message T_title =
message("xmlui.ArtifactBrowser.FeedbackForm.title");
private static final Message T_dspace_home =
message("xmlui.general.dspace_home");
private static final Message T_trail =
message("xmlui.ArtifactBrowser.FeedbackForm.trail");
private static final Message T_head =
message("xmlui.ArtifactBrowser.FeedbackForm.head");
private static final Message T_para1 =
message("xmlui.ArtifactBrowser.FeedbackForm.para1");
private static final Message T_email =
message("xmlui.ArtifactBrowser.FeedbackForm.email");
private static final Message T_email_help =
message("xmlui.ArtifactBrowser.FeedbackForm.email_help");
private static final Message T_comments =
message("xmlui.ArtifactBrowser.FeedbackForm.comments");
private static final Message T_submit =
message("xmlui.ArtifactBrowser.FeedbackForm.submit");
/**
* Generate the unique caching key.
* This key must be unique inside the space of this component.
*/
public Serializable getKey() {
String email = parameters.getParameter("email","");
String comments = parameters.getParameter("comments","");
String page = parameters.getParameter("page","unknown");
return HashUtil.hash(email + "-" + comments + "-" + page);
}
/**
* Generate the cache validity object.
*/
public SourceValidity getValidity()
{
return NOPValidity.SHARED_INSTANCE;
}
public void addPageMeta(PageMeta pageMeta) throws SAXException,
WingException, UIException, SQLException, IOException,
AuthorizeException
{
pageMeta.addMetadata("title").addContent(T_title);
pageMeta.addTrailLink(contextPath + "/",T_dspace_home);
pageMeta.addTrail().addContent(T_trail);
}
public void addBody(Body body) throws SAXException, WingException,
UIException, SQLException, IOException, AuthorizeException
{
// Build the item viewer division.
Division feedback = body.addInteractiveDivision("feedback-form",
contextPath+"/feedback",Division.METHOD_POST,"primary");
feedback.setHead(T_head);
feedback.addPara(T_para1);
List form = feedback.addList("form",List.TYPE_FORM);
Text email = form.addItem().addText("email");
email.setLabel(T_email);
email.setHelp(T_email_help);
email.setValue(parameters.getParameter("email",""));
TextArea comments = form.addItem().addTextArea("comments");
comments.setLabel(T_comments);
comments.setSize(5,60);
comments.setValue(parameters.getParameter("comments",""));
form.addItem().addButton("submit").setValue(T_submit);
feedback.addHidden("page").setValue(parameters.getParameter("page","unknown"));
}
}

View File

@@ -0,0 +1,121 @@
/*
* FeedbackSent.java
*
* Version: $Revision: 1.2 $
*
* Date: $Date: 2006/06/02 21:36:57 $
*
* Copyright (c) 2002, Hewlett-Packard Company and Massachusetts
* Institute of Technology. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* - 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.
*
* - Neither the name of the Hewlett-Packard Company nor the name of the
* Massachusetts Institute of Technology nor the names of their
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS 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 COPYRIGHT
* HOLDERS OR 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.
*/
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.excalibur.source.SourceValidity;
import org.apache.excalibur.source.impl.validity.NOPValidity;
import org.dspace.app.xmlui.cocoon.AbstractDSpaceTransformer;
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.PageMeta;
import org.dspace.authorize.AuthorizeException;
import org.xml.sax.SAXException;
/**
* Simple page to let the user know their feedback has been sent.
*
* @author Scott Phillips
*/
public class FeedbackSent extends AbstractDSpaceTransformer implements CacheableProcessingComponent
{
/** language strings */
public static final Message T_title =
message("xmlui.ArtifactBrowser.FeedbackSent.title");
public static final Message T_dspace_home =
message("xmlui.general.dspace_home");
public static final Message T_trail =
message("xmlui.ArtifactBrowser.FeedbackSent.trail");
public static final Message T_head =
message("xmlui.ArtifactBrowser.FeedbackSent.head");
public static final Message T_para1 =
message("xmlui.ArtifactBrowser.FeedbackSent.para1");
/**
* Generate the unique caching key.
*/
public Serializable getKey() {
return "1";
}
/**
* Generate the cache validity object.
*/
public SourceValidity getValidity()
{
return NOPValidity.SHARED_INSTANCE;
}
public void addPageMeta(PageMeta pageMeta) throws SAXException,
WingException, UIException, SQLException, IOException,
AuthorizeException
{
pageMeta.addMetadata("title").addContent(T_title);
pageMeta.addTrailLink(contextPath + "/",T_dspace_home);
pageMeta.addTrail().addContent(T_trail);
}
public void addBody(Body body) throws SAXException, WingException,
UIException, SQLException, IOException, AuthorizeException
{
Division feedback = body.addDivision("feedback-sent","primary");
feedback.setHead(T_head);
feedback.addPara(T_para1);
}
}

View File

@@ -0,0 +1,144 @@
/*
* FrontPageSearch.java
*
* Version: $Revision: 1.1 $
*
* Date: $Date: 2006/08/08 20:58:15 $
*
* Copyright (c) 2002, Hewlett-Packard Company and Massachusetts
* Institute of Technology. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* - 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.
*
* - Neither the name of the Hewlett-Packard Company nor the name of the
* Massachusetts Institute of Technology nor the names of their
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS 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 COPYRIGHT
* HOLDERS OR 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.
*/
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.excalibur.source.SourceValidity;
import org.apache.excalibur.source.impl.validity.NOPValidity;
import org.dspace.app.xmlui.cocoon.AbstractDSpaceTransformer;
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.PageMeta;
import org.dspace.app.xmlui.wing.element.Para;
import org.dspace.authorize.AuthorizeException;
import org.dspace.core.ConfigurationManager;
import org.xml.sax.SAXException;
/**
* This simple component will add a Search Box. It is intended for use on the front page.
*
* @author Scott Phillips
*/
public class FrontPageSearch extends AbstractDSpaceTransformer implements CacheableProcessingComponent
{
/** Language Strings */
public static final Message T_dspace_home =
message("xmlui.general.dspace_home");
private static final Message T_head =
message("xmlui.ArtifactBrowser.FrontPageSearch.head");
private static final Message T_para1 =
message("xmlui.ArtifactBrowser.FrontPageSearch.para1");
private static final Message T_go =
message("xmlui.general.go");
/**
* Generate the unique caching key.
* This key must be unique inside the space of this component.
*/
public Serializable getKey()
{
return "1";
}
/**
* Generate the cache validity object.
*/
public SourceValidity getValidity()
{
return NOPValidity.SHARED_INSTANCE;
}
/**
* Add a page title and trail links.
*/
public void addPageMeta(PageMeta pageMeta) throws SAXException,
WingException, UIException, SQLException, IOException,
AuthorizeException
{
pageMeta.addMetadata("title").addContent(T_dspace_home);
pageMeta.addTrailLink(contextPath, T_dspace_home);
// Add RSS links if available
String formats = ConfigurationManager.getProperty("webui.feed.formats");
if ( formats != null )
{
for (String format : formats.split(","))
{
// Remove the protocol number, i.e. just list 'rss' or' atom'
String[] parts = format.split("_");
if (parts.length < 1)
continue;
String feedFormat = parts[0].trim()+"+xml";
String feedURL = contextPath+"/feed/"+format.trim();
pageMeta.addMetadata("feed", feedFormat).addContent(feedURL);
}
}
}
public void addBody(Body body) throws SAXException, WingException,
UIException, SQLException, IOException, AuthorizeException
{
Division search =
body.addInteractiveDivision("front-page-search",contextPath+"/search",Division.METHOD_POST,"primary");
search.setHead(T_head);
search.addPara(T_para1);
Para fields = search.addPara();
fields.addText("query");
fields.addButton("submit").setValue(T_go);
}
}

View File

@@ -0,0 +1,274 @@
/*
* ItemViewer.java
*
* Version: $Revision: 1.14 $
*
* Date: $Date: 2006/08/08 20:58:30 $
*
* Copyright (c) 2002, Hewlett-Packard Company and Massachusetts
* Institute of Technology. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* - 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.
*
* - Neither the name of the Hewlett-Packard Company nor the name of the
* Massachusetts Institute of Technology nor the names of their
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS 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 COPYRIGHT
* HOLDERS OR 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.
*/
package org.dspace.app.xmlui.aspect.artifactbrowser;
import java.io.IOException;
import java.io.Serializable;
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.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.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.PageMeta;
import org.dspace.app.xmlui.wing.element.Para;
import org.dspace.authorize.AuthorizeException;
import org.dspace.content.Collection;
import org.dspace.content.DCValue;
import org.dspace.content.DSpaceObject;
import org.dspace.content.Item;
import org.xml.sax.SAXException;
/**
* Display a single item.
*
* @author Scott Phillips
*/
public class ItemViewer extends AbstractDSpaceTransformer implements CacheableProcessingComponent
{
/** Language strings */
private static final Message T_dspace_home =
message("xmlui.general.dspace_home");
private static final Message T_trail =
message("xmlui.ArtifactBrowser.ItemViewer.trail");
private static final Message T_show_simple =
message("xmlui.ArtifactBrowser.ItemViewer.show_simple");
private static final Message T_show_full =
message("xmlui.ArtifactBrowser.ItemViewer.show_full");
private static final Message T_head_parent_collections =
message("xmlui.ArtifactBrowser.ItemViewer.head_parent_collections");
/** Cached validity object */
private SourceValidity validity = null;
/**
* 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() + "full:" + showFullItem(objectModel));
}
catch (SQLException sqle)
{
// Ignore all errors and just return that the component is not cachable.
return "0";
}
}
/**
* Generate the cache validity object.
*
* The validity object will include the item being viewed,
* along with all bundles & bitstreams.
*/
public SourceValidity getValidity()
{
if (this.validity == null)
{
try {
DSpaceObject dso = HandleUtil.obtainHandle(objectModel);
DSpaceValidity validity = new DSpaceValidity();
validity.add(dso);
this.validity = validity.complete();
}
catch (Exception e)
{
// Ignore all errors and just invalidate the cache.
}
}
return this.validity;
}
/**
* Add the item's title and trail links to the page's metadata.
*/
public void addPageMeta(PageMeta pageMeta) throws SAXException,
WingException, UIException, SQLException, IOException,
AuthorizeException
{
DSpaceObject dso = HandleUtil.obtainHandle(objectModel);
if (!(dso instanceof Item))
return;
Item item = (Item) dso;
// Set the page title
String title = getItemTitle(item);
if (title != null)
pageMeta.addMetadata("title").addContent(title);
else
pageMeta.addMetadata("title").addContent(item.getHandle());
pageMeta.addTrailLink(contextPath + "/",T_dspace_home);
HandleUtil.buildHandleTrail(item,pageMeta,contextPath);
pageMeta.addTrail().addContent(T_trail);
}
/**
* Display a single item
*/
public void addBody(Body body) throws SAXException, WingException,
UIException, SQLException, IOException, AuthorizeException
{
DSpaceObject dso = HandleUtil.obtainHandle(objectModel);
if (!(dso instanceof Item))
return;
Item item = (Item) dso;
// Build the item viewer division.
Division division = body.addDivision("item-view","primary");
String title = getItemTitle(item);
if (title != null)
division.setHead(title);
else
division.setHead(item.getHandle());
Para showfullPara = division.addPara(null, "item-view-toggle item-view-toggle-top");
if (showFullItem(objectModel))
{
String link = contextPath + "/handle/" + item.getHandle();
showfullPara.addXref(link).addContent(T_show_simple);
}
else
{
String link = contextPath + "/handle/" + item.getHandle()
+ "?show=full";
showfullPara.addXref(link).addContent(T_show_full);
}
ReferenceSet referenceSet;
if (showFullItem(objectModel))
{
referenceSet = division.addReferenceSet("collection-viewer",
ReferenceSet.TYPE_DETAIL_VIEW);
}
else
{
referenceSet = division.addReferenceSet("collection-viewer",
ReferenceSet.TYPE_SUMMARY_VIEW);
}
// Refrence the actual Item
ReferenceSet appearsInclude = referenceSet.addReference(item).addReferenceSet(ReferenceSet.TYPE_DETAIL_LIST,null,"hierarchy");
appearsInclude.setHead(T_head_parent_collections);
// Reference all collections the item appears in.
for (Collection collection : item.getCollections())
{
appearsInclude.addReference(collection);
}
showfullPara = division.addPara(null,"item-view-toggle item-view-toggle-bottom");
if (showFullItem(objectModel))
{
String link = contextPath + "/handle/" + item.getHandle();
showfullPara.addXref(link).addContent(T_show_simple);
}
else
{
String link = contextPath + "/handle/" + item.getHandle()
+ "?show=full";
showfullPara.addXref(link).addContent(T_show_full);
}
}
/**
* Determine if the full item should be referenced or just a summary.
*/
public static boolean showFullItem(Map objectModel)
{
Request request = ObjectModelHelper.getRequest(objectModel);
String show = request.getParameter("show");
if (show != null && show.length() > 0)
return true;
return false;
}
/**
* Obtain the item's title.
*/
public static String getItemTitle(Item item)
{
DCValue[] titles = item.getDC("title", Item.ANY, Item.ANY);
String title;
if (titles != null && titles.length > 0)
title = titles[0].value;
else
title = null;
return title;
}
/**
* Recycle
*/
public void recycle() {
this.validity = null;
super.recycle();
}
}

View File

@@ -0,0 +1,242 @@
/*
* Navigation.java
*
* Version: $Revision: 1.14 $
*
* Date: $Date: 2006/08/08 20:58:45 $
*
* Copyright (c) 2002, Hewlett-Packard Company and Massachusetts
* Institute of Technology. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* - 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.
*
* - Neither the name of the Hewlett-Packard Company nor the name of the
* Massachusetts Institute of Technology nor the names of their
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS 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 COPYRIGHT
* HOLDERS OR 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.
*/
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.environment.ObjectModelHelper;
import org.apache.cocoon.environment.Request;
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.wing.Message;
import org.dspace.app.xmlui.wing.WingException;
import org.dspace.app.xmlui.wing.element.List;
import org.dspace.app.xmlui.wing.element.Options;
import org.dspace.app.xmlui.wing.element.PageMeta;
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.xml.sax.SAXException;
/**
* This transform applys the basic navigational links that should be available
* on all pages generated by DSpace.
*
* @author Scott Phillips
*/
public class Navigation extends AbstractDSpaceTransformer implements CacheableProcessingComponent
{
/** Language Strings */
private static final Message T_head_all_of_dspace =
message("xmlui.ArtifactBrowser.Navigation.head_all_of_dspace");
private static final Message T_head_browse =
message("xmlui.ArtifactBrowser.Navigation.head_browse");
private static final Message T_communities_and_collections =
message("xmlui.ArtifactBrowser.Navigation.communities_and_collections");
private static final Message T_browse_titles =
message("xmlui.ArtifactBrowser.Navigation.browse_titles");
private static final Message T_browse_authors =
message("xmlui.ArtifactBrowser.Navigation.browse_authors");
private static final Message T_browse_subjects =
message("xmlui.ArtifactBrowser.Navigation.browse_subjects");
private static final Message T_browse_dates =
message("xmlui.ArtifactBrowser.Navigation.browse_dates");
private static final Message T_head_this_collection =
message("xmlui.ArtifactBrowser.Navigation.head_this_collection");
private static final Message T_head_this_community =
message("xmlui.ArtifactBrowser.Navigation.head_this_community");
/**
* Generate the unique caching key.
* This key must be unique inside the space of this component.
*/
public Serializable getKey() {
try {
Request request = ObjectModelHelper.getRequest(objectModel);
String key = request.getScheme() + request.getServerName() + request.getServerPort() + request.getSitemapURI() + request.getQueryString();
DSpaceObject dso = HandleUtil.obtainHandle(objectModel);
if (dso != null)
key += "-" + dso.getHandle();
return HashUtil.hash(key);
}
catch (SQLException sqle)
{
// Ignore all errors and just return that the component is not cachable.
return "0";
}
}
/**
* Generate the cache validity object.
*
* The cache is always valid.
*/
public SourceValidity getValidity() {
return NOPValidity.SHARED_INSTANCE;
}
/**
* Add the basic navigational options:
*
* Search - advanced search
*
* browse - browse by Titles - browse by Authors - browse by Dates
*
* language FIXME: add languages
*
* context no context options are added.
*
* action no action options are added.
*/
public void addOptions(Options options) throws SAXException, WingException,
UIException, SQLException, IOException, AuthorizeException
{
/* Create skeleton menu structure to ensure consistent order between aspects,
* even if they are never used
*/
List browse = options.addList("browse");
options.addList("account");
options.addList("context");
options.addList("administrative");
browse.setHead(T_head_browse);
List browseGlobal = browse.addList("global");
List browseContext = browse.addList("context");
browseGlobal.setHead(T_head_all_of_dspace);
browseGlobal.addItemXref(contextPath + "/community-list",T_communities_and_collections);
browseGlobal.addItemXref(contextPath + "/browse-title",T_browse_titles);
browseGlobal.addItemXref(contextPath + "/browse-author",T_browse_authors);
browseGlobal.addItemXref(contextPath + "/browse-subject",T_browse_subjects);
browseGlobal.addItemXref(contextPath + "/browse-date",T_browse_dates);
DSpaceObject dso = HandleUtil.obtainHandle(objectModel);
if (dso != null)
{
if (dso instanceof Item)
{
// If we are an item change the browse scope to the parent
// collection.
dso = ((Item) dso).getOwningCollection();
}
if (dso instanceof Collection)
{
browseContext.setHead(T_head_this_collection);
}
if (dso instanceof Community)
{
browseContext.setHead(T_head_this_community);
}
String handle = dso.getHandle();
browseContext.addItemXref(contextPath + "/handle/" + handle + "/browse-title",T_browse_titles);
browseContext.addItemXref(contextPath + "/handle/" + handle + "/browse-author",T_browse_authors);
browseContext.addItemXref(contextPath + "/handle/" + handle + "/browse-subject",T_browse_subjects);
browseContext.addItemXref(contextPath + "/handle/" + handle + "/browse-date",T_browse_dates);
}
}
/**
* Insure that the context path is added to the page meta.
*/
public void addPageMeta(PageMeta pageMeta) throws SAXException,
WingException, UIException, SQLException, IOException,
AuthorizeException
{
// FIXME: I don't think these should be set here, but there needed and I'm
// not sure where else it could go. Perhaps the linkResolver?
Request request = ObjectModelHelper.getRequest(objectModel);
pageMeta.addMetadata("contextPath").addContent(contextPath);
pageMeta.addMetadata("request","queryString").addContent(request.getQueryString());
pageMeta.addMetadata("request","scheme").addContent(request.getScheme());
pageMeta.addMetadata("request","serverPort").addContent(request.getServerPort());
pageMeta.addMetadata("request","serverName").addContent(request.getServerName());
pageMeta.addMetadata("request","URI").addContent(request.getSitemapURI());
// Add metadata for quick searches:
pageMeta.addMetadata("search", "simpleURL").addContent(
contextPath + "/search");
pageMeta.addMetadata("search", "advancedURL").addContent(
contextPath + "/advanced-search");
pageMeta.addMetadata("search", "queryField").addContent("query");
pageMeta.addMetadata("page","contactURL").addContent(contextPath + "/contact");
pageMeta.addMetadata("page","feedbackURL").addContent(contextPath + "/feedback");
DSpaceObject dso = HandleUtil.obtainHandle(objectModel);
if (dso != null)
{
if (dso instanceof Item)
{
pageMeta.addMetadata("focus","object").addContent("hdl:"+dso.getHandle());
this.getObjectManager().manageObject(dso);
dso = ((Item) dso).getOwningCollection();
}
if (dso instanceof Collection || dso instanceof Community)
{
pageMeta.addMetadata("focus","container").addContent("hdl:"+dso.getHandle());
this.getObjectManager().manageObject(dso);
}
}
}
}

View File

@@ -0,0 +1,138 @@
/*
* RestrictedItem.java
*
* Version: $Revision: 1.1 $
*
* Date: $Date: 2006/08/08 20:58:55 $
*
* Copyright (c) 2002, Hewlett-Packard Company and Massachusetts
* Institute of Technology. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* - 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.
*
* - Neither the name of the Hewlett-Packard Company nor the name of the
* Massachusetts Institute of Technology nor the names of their
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS 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 COPYRIGHT
* HOLDERS OR 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.
*/
package org.dspace.app.xmlui.aspect.artifactbrowser;
import java.io.IOException;
import java.sql.SQLException;
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.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.PageMeta;
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;
/**
* Display an item restricted message.
*
* @author Scott Phillips
*/
public class RestrictedItem extends AbstractDSpaceTransformer //implements CacheableProcessingComponent
{
/** language strings */
private static final Message T_title =
message("xmlui.ArtifactBrowser.RestrictedItem.title");
private static final Message T_dspace_home =
message("xmlui.general.dspace_home");
private static final Message T_trail =
message("xmlui.ArtifactBrowser.RestrictedItem.trail");
private static final Message T_head =
message("xmlui.ArtifactBrowser.RestrictedItem.head");
private static final Message T_para =
message("xmlui.ArtifactBrowser.RestrictedItem.para");
public void addPageMeta(PageMeta pageMeta) throws SAXException,
WingException, UIException, SQLException, IOException,
AuthorizeException
{
DSpaceObject dso = HandleUtil.obtainHandle(objectModel);
pageMeta.addMetadata("title").addContent(T_title);
pageMeta.addTrailLink(contextPath + "/",T_dspace_home);
if (dso != null)
HandleUtil.buildHandleTrail(dso,pageMeta,contextPath);
pageMeta.addTrail().addContent(T_trail);
}
public void addBody(Body body) throws SAXException, WingException,
UIException, SQLException, IOException, AuthorizeException
{
DSpaceObject dso = HandleUtil.obtainHandle(objectModel);
String identifier = null;
if (dso == null)
{
identifier = "unknown";
}
else if (dso instanceof Community)
{
Community community = (Community) dso;
identifier = community.getMetadata("name");
}
else if (dso instanceof Collection)
{
Collection collection = (Collection) dso;
identifier = collection.getMetadata("name");
}
else
{
String handle = dso.getHandle();
if (handle == null || "".equals(handle))
{
identifier = "internal ID: " + dso.getID();
}
else
{
identifier = "hdl:"+handle;
}
}
Division unauthorized = body.addDivision("unauthorized-item","primary");
unauthorized.setHead(T_head);
unauthorized.addPara(T_para.parameterize(identifier));
}
}

View File

@@ -0,0 +1,133 @@
/*
* SendFeedbackAction.java
*
* Version: $Revision: 1.1 $
*
* Date: $Date: 2006/05/01 22:33:39 $
*
* Copyright (c) 2002, Hewlett-Packard Company and Massachusetts
* Institute of Technology. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* - 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.
*
* - Neither the name of the Hewlett-Packard Company nor the name of the
* Massachusetts Institute of Technology nor the names of their
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS 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 COPYRIGHT
* HOLDERS OR 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.
*/
package org.dspace.app.xmlui.aspect.artifactbrowser;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import org.apache.avalon.framework.parameters.Parameters;
import org.apache.cocoon.acting.AbstractAction;
import org.apache.cocoon.environment.ObjectModelHelper;
import org.apache.cocoon.environment.Redirector;
import org.apache.cocoon.environment.Request;
import org.apache.cocoon.environment.SourceResolver;
import org.dspace.app.xmlui.utils.ContextUtil;
import org.dspace.core.ConfigurationManager;
import org.dspace.core.Context;
import org.dspace.core.Email;
import org.dspace.eperson.EPerson;
/**
* @author Scott Phillips
*/
public class SendFeedbackAction extends AbstractAction
{
/**
*
*/
public Map act(Redirector redirector, SourceResolver resolver, Map objectModel,
String source, Parameters parameters) throws Exception
{
Request request = ObjectModelHelper.getRequest(objectModel);
String page = request.getParameter("page");
String address = request.getParameter("email");
String agent = request.getHeader("User-Agent");
String session = request.getSession().getId();
String comments = request.getParameter("comments");
// User email from context
Context context = ContextUtil.obtainContext(objectModel);
EPerson loggedin = context.getCurrentUser();
String eperson = null;
if (loggedin != null)
eperson = loggedin.getEmail();
if (page == null || page.equals(""))
{
page = request.getHeader("Referer");
}
// Check all data is there
if ((address == null) || address.equals("")
|| (comments == null) || comments.equals(""))
{
// Either the user did not fill out the form or this is the
// first time they are visiting the page.
Map<String,String> map = new HashMap<String,String>();
map.put("page",page);
if (address == null || address.equals(""))
map.put("email",eperson);
else
map.put("email",address);
map.put("comments",comments);
return map;
}
// All data is there, send the email
Email email = ConfigurationManager.getEmail("feedback");
email.addRecipient(ConfigurationManager
.getProperty("feedback.recipient"));
email.addArgument(new Date()); // Date
email.addArgument(address); // Email
email.addArgument(eperson); // Logged in as
email.addArgument(page); // Referring page
email.addArgument(agent); // User agent
email.addArgument(session); // Session ID
email.addArgument(comments); // The feedback itself
// Replying to feedback will reply to email on form
email.setReplyTo(address);
// May generate MessageExceptions.
email.send();
// Finished, allow to pass.
return null;
}
}

View File

@@ -0,0 +1,173 @@
/*
* SimpleSearch.java
*
* Version: $Revision: 1.12 $
*
* Date: $Date: 2006/07/27 18:24:34 $
*
* Copyright (c) 2002, Hewlett-Packard Company and Massachusetts
* Institute of Technology. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* - 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.
*
* - Neither the name of the Hewlett-Packard Company nor the name of the
* Massachusetts Institute of Technology nor the names of their
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS 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 COPYRIGHT
* HOLDERS OR 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.
*/
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.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.List;
import org.dspace.app.xmlui.wing.element.PageMeta;
import org.dspace.app.xmlui.wing.element.Select;
import org.dspace.app.xmlui.wing.element.Text;
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;
/**
* 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.
*
* @author Scott Phillips
*/
public class SimpleSearch extends AbstractSearch implements CacheableProcessingComponent
{
/** Language Strings */
private static final Message T_title =
message("xmlui.ArtifactBrowser.SimpleSearch.title");
private static final Message T_dspace_home =
message("xmlui.general.dspace_home");
private static final Message T_trail =
message("xmlui.ArtifactBrowser.SimpleSearch.trail");
private static final Message T_head =
message("xmlui.ArtifactBrowser.SimpleSearch.head");
private static final Message T_search_scope =
message("xmlui.ArtifactBrowser.SimpleSearch.search_scope");
private static final Message T_full_text_search =
message("xmlui.ArtifactBrowser.SimpleSearch.full_text_search");
private static final Message T_go =
message("xmlui.general.go");
/**
* Add Page metadata.
*/
public void addPageMeta(PageMeta pageMeta) throws WingException, SQLException
{
pageMeta.addMetadata("title").addContent(T_title);
pageMeta.addTrailLink(contextPath + "/", T_dspace_home);
DSpaceObject dso = HandleUtil.obtainHandle(objectModel);
if ((dso instanceof Collection) || (dso instanceof Community))
{
HandleUtil.buildHandleTrail(dso,pageMeta,contextPath);
}
pageMeta.addTrail().addContent(T_trail);
}
/**
* build the DRI page representing the body of the search query. This
* provides a widget to generate a new query and list of search results if
* present.
*/
public void addBody(Body body) throws SAXException, WingException,
UIException, SQLException, IOException, AuthorizeException
{
String queryString = getQuery();
// Build the DRI Body
Division search = body.addDivision("search","primary");
search.setHead(T_head);
Division query = search.addInteractiveDivision("general-query",
"",Division.METHOD_POST,"secondary search");
List queryList = query.addList("search-query",List.TYPE_FORM);
if (variableScope())
{
Select scope = queryList.addItem().addSelect("scope");
scope.setLabel(T_search_scope);
buildScopeList(scope);
}
Text text = queryList.addItem().addText("query");
text.setLabel(T_full_text_search);
text.setValue(queryString);
queryList.addItem().addButton("submit").setValue(T_go);
// Add the result division
buildSearchResultsDivision(search);
}
/**
* Get the search query from the URL parameter, if none is found the empty
* string is returned.
*/
protected String getQuery()
{
Request request = ObjectModelHelper.getRequest(objectModel);
String query = request.getParameter("query");
if (query == null)
return "";
return query;
}
/**
* Generate a url to the simple search url.
*/
protected String generateURL(Map<String, String> parameters)
throws UIException
{
String query = getQuery();
if (!"".equals(query))
parameters.put("query", URLEncode(query));
return super.generateURL("search", parameters);
}
}

View File

@@ -0,0 +1,140 @@
/*
* AuthenticateAction.java
*
* Version: $Revision: 1.3 $
*
* Date: $Date: 2006/08/08 20:55:36 $
*
* Copyright (c) 2002, Hewlett-Packard Company and Massachusetts
* Institute of Technology. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* - 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.
*
* - Neither the name of the Hewlett-Packard Company nor the name of the
* Massachusetts Institute of Technology nor the names of their
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS 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 COPYRIGHT
* HOLDERS OR 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.
*/
package org.dspace.app.xmlui.aspect.eperson;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.Map;
import javax.servlet.http.HttpServletResponse;
import org.apache.avalon.framework.parameters.Parameters;
import org.apache.cocoon.acting.AbstractAction;
import org.apache.cocoon.environment.ObjectModelHelper;
import org.apache.cocoon.environment.Redirector;
import org.apache.cocoon.environment.Request;
import org.apache.cocoon.environment.SourceResolver;
import org.apache.cocoon.environment.http.HttpEnvironment;
import org.apache.cocoon.sitemap.PatternException;
import org.dspace.app.xmlui.utils.AuthenticationUtil;
import org.dspace.core.Context;
import org.dspace.eperson.EPerson;
/**
* Attempt to authenticate the user based upon their presented credentials.
* This action uses the http parameters of login_email, login_password, and
* login_realm as credentials.
*
* If the authentication attempt is successfull then an HTTP redirect will be
* sent to the browser redirecting them to their original location in the
* system before authenticated or if none is supplied back to the DSpace
* homepage. The action will also return true, thus contents of the action will
* be excuted.
*
* If the authentication attempt fails, the action returns false.
*
* Example use:
*
* <map:act name="Authenticate">
* <map:serialize type="xml"/>
* </map:act>
* <map:transform type="try-to-login-again-transformer">
*
* @author Scott Phillips
*/
public class AuthenticateAction extends AbstractAction
{
/**
* Attempt to authenticate the user.
*/
public Map act(Redirector redirector, SourceResolver resolver, Map objectModel,
String source, Parameters parameters) throws Exception
{
// First check if we are preforming a new login
Request request = ObjectModelHelper.getRequest(objectModel);
String email = request.getParameter("login_email");
String password = request.getParameter("login_password");
String realm = request.getParameter("login_realm");
try
{
Context context = AuthenticationUtil.Authenticate(objectModel, email,password, realm);
EPerson eperson = context.getCurrentUser();
if (eperson != null)
{
// The user has successfully logged in
String redirectURL = request.getContextPath();
if (AuthenticationUtil.isInterupptedRequest(objectModel))
{
// Resume the request and set the redirect target URL to
// that of the originaly interrupted request.
redirectURL += AuthenticationUtil.resumeInterruptedRequest(objectModel);
}
// Authentication successfull send a redirect.
final HttpServletResponse httpResponse = (HttpServletResponse) objectModel.get(HttpEnvironment.HTTP_RESPONSE_OBJECT);
httpResponse.sendRedirect(redirectURL);
// log the user out for the rest of this current request, however they will be reauthenticated
// fully when they come back from the redirect. This prevents caching problems where part of the
// request is preformed fore the user was authenticated and the other half after it succedded. This
// way the user is fully authenticated from the start of the request.
context.setCurrentUser(null);
return new HashMap();
}
}
catch (SQLException sqle)
{
throw new PatternException("Unable to preform authentication",
sqle);
}
return null;
}
}

View File

@@ -0,0 +1,82 @@
/*
* AuthenticationCountSelector.java
*
* Version: $Revision: 1.0 $
*
* Date: $Date: 2006/04/25 15:24:23 $
*
* Copyright (c) 2002, Hewlett-Packard Company and Massachusetts
* Institute of Technology. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* - 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.
*
* - Neither the name of the Hewlett-Packard Company nor the name of the
* Massachusetts Institute of Technology nor the names of their
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS 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 COPYRIGHT
* HOLDERS OR 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.
*/
package org.dspace.app.xmlui.aspect.eperson;
import java.util.Iterator;
import java.util.Map;
import org.apache.avalon.framework.parameters.Parameters;
import org.apache.cocoon.selection.Selector;
import org.dspace.eperson.AuthenticationManager;
/**
* Selector will count the number of AuthenticationMethods defined in the
* dpace configuration file
* @author Jay Paz
* @author Scott Phillips
*
*/
public class AuthenticationCountSelector implements Selector{
/**
* Returns true if the expression (in this case a number) is equal to the number
* of AuthenticationMethods defined in the dspace.cnf file
* @return
*/
public boolean select(String expression, Map objectModel, Parameters parameters) {
// get an iterator of all the AuthenticationMethods defined
final Iterator authMethods = AuthenticationManager
.authenticationMethodIterator();
int authMethodCount = 0;
// iterate to count the methods
while(authMethods.hasNext()){
authMethods.next();
authMethodCount++;
}
final Integer exp = new Integer(expression);
return (authMethodCount == exp);
}
}

View File

@@ -0,0 +1,94 @@
/*
* CannotRegister.java
*
* Version: $Revision: 1.2 $
*
* Date: $Date: 2006/06/02 21:37:46 $
*
* Copyright (c) 2002, Hewlett-Packard Company and Massachusetts
* Institute of Technology. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* - 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.
*
* - Neither the name of the Hewlett-Packard Company nor the name of the
* Massachusetts Institute of Technology nor the names of their
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS 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 COPYRIGHT
* HOLDERS OR 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.
*/
package org.dspace.app.xmlui.aspect.eperson;
import org.dspace.app.xmlui.cocoon.AbstractDSpaceTransformer;
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.PageMeta;
/**
* Inform the user that the email address they entered cannot be registered
* with DSpace. This is a state within the new user registration flow.
*
* @author Scott Phillips
*/
public class CannotRegister extends AbstractDSpaceTransformer
{
/** Language strings */
private static final Message T_title =
message("xmlui.EPerson.CannotRegister.title");
private static final Message T_dspace_home =
message("xmlui.general.dspace-home");
private static final Message T_trail_new_registration =
message("xmlui.EPerson.trail-new-registration");
private static final Message T_head =
message("xmlui.EPerson.CannotRegister.head");
private static final Message T_para1 =
message("xmlui.EPerson.CannotRegister.para1");
public void addPageMeta(PageMeta pageMeta) throws WingException
{
// Set the page title
pageMeta.addMetadata("title").addContent(T_title);
pageMeta.addTrailLink(contextPath + "/",T_dspace_home);
pageMeta.addTrail().addContent(T_trail_new_registration);
}
public void addBody(Body body) throws WingException
{
Division cannot = body.addDivision("register-cannot","primary");
cannot.setHead(T_head);
EPersonUtils.registrationProgressList(cannot, 0);
cannot.addPara(T_para1);
}
}

View File

@@ -0,0 +1,111 @@
/*
* EPersonUtils.java
*
* Version: $Revision: 1.3 $
*
* Date: $Date: 2006/04/25 21:35:09 $
*
* Copyright (c) 2002, Hewlett-Packard Company and Massachusetts
* Institute of Technology. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* - 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.
*
* - Neither the name of the Hewlett-Packard Company nor the name of the
* Massachusetts Institute of Technology nor the names of their
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS 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 COPYRIGHT
* HOLDERS OR 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.
*/
package org.dspace.app.xmlui.aspect.eperson;
import org.dspace.app.xmlui.wing.Message;
import org.dspace.app.xmlui.wing.WingException;
import org.dspace.app.xmlui.wing.element.Division;
import org.dspace.app.xmlui.wing.element.List;
/**
* A set of static utilities to help with EPerson workflows.
*
* @author Scott Phillips
*/
public class EPersonUtils
{
/**
* Create a progress list for the registration workflow.
*
* @param form The division of the current workflow step.
* @param step The current step of the workflow (-1 if no step)
*
*/
public static void registrationProgressList(Division form, int step) throws WingException
{
List progress = form.addList("registration-progress",
List.TYPE_PROGRESS);
new Message("default","xmlui.EPerson.EPersonUtils.register_verify_email");
progress.addItem("register-verify-email", render(step, 1)).addContent(
new Message("default","xmlui.EPerson.EPersonUtils.register_verify_email"));
progress.addItem("register-create-profile", render(step, 2)).addContent(
new Message("default","xmlui.EPerson.EPersonUtils.register_create_profile"));
progress.addItem("register-finished", render(step, 3)).addContent(
new Message("default","xmlui.EPerson.EPersonUtils.register_finished"));
}
/**
* Create a progress list for the forgot password workflow.
*
* @param form The division of the current workflow step
* @param step The current step of the workflow (-1 if no step)
*/
public static void forgottProgressList(Division form, int step) throws WingException
{
List progress = form.addList("forgot-password-progress",
List.TYPE_PROGRESS);
progress.addItem("forgot-verify-email", render(step, 1)).addContent(
new Message("default","xmlui.EPerson.EPersonUtils.forgot_verify_email"));
progress.addItem("forgot-reset-passowrd", render(step, 2)).addContent(
new Message("default","xmlui.EPerson.EPersonUtils.forgot_reset_password"));
progress.addItem("forgot-finished", render(step, 3)).addContent(
new Message("default","xmlui.EPerson.EPersonUtils.forgot_finished"));
}
private static String render(int givenStep, int step)
{
if (givenStep == step)
return "current";
else
return null;
}
}

View File

@@ -0,0 +1,403 @@
/*
* EditProfile.java
*
* Version: $Revision: 1.10 $
*
* Date: $Date: 2006/08/17 14:51:46 $
*
* Copyright (c) 2002, Hewlett-Packard Company and Massachusetts
* Institute of Technology. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* - 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.
*
* - Neither the name of the Hewlett-Packard Company nor the name of the
* Massachusetts Institute of Technology nor the names of their
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS 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 COPYRIGHT
* HOLDERS OR 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.
*/
package org.dspace.app.xmlui.aspect.eperson;
import java.io.IOException;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Map;
import org.apache.avalon.framework.parameters.Parameters;
import org.apache.cocoon.ProcessingException;
import org.apache.cocoon.environment.ObjectModelHelper;
import org.apache.cocoon.environment.Request;
import org.apache.cocoon.environment.SourceResolver;
import org.dspace.app.xmlui.cocoon.AbstractDSpaceTransformer;
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.Button;
import org.dspace.app.xmlui.wing.element.Division;
import org.dspace.app.xmlui.wing.element.Field;
import org.dspace.app.xmlui.wing.element.List;
import org.dspace.app.xmlui.wing.element.PageMeta;
import org.dspace.app.xmlui.wing.element.Select;
import org.dspace.app.xmlui.wing.element.Text;
import org.dspace.content.Collection;
import org.dspace.eperson.Group;
import org.dspace.eperson.Subscribe;
import org.xml.sax.SAXException;
/**
* Display a form that allows the user to edit their profile.
* There are two cases in which this can be used: 1) when an
* existing user is attempting to edit their own profile, and
* 2) when a new user is registering for the first time.
*
* There are several parameters this transformer accepts:
*
* email - The email address of the user registering for the first time.
*
* registering - A boolean value to indicate whether the user is registering for the first time.
*
* retryInformation - A boolean value to indicate whether there was an error with the user's profile.
*
* retryPassword - A boolean value to indicate whether there was an error with the user's password.
*
* allowSetPassword - A boolean value to indicate whether the user is allowed to set their own password.
*
* @author Scott Phillips
*/
public class EditProfile extends AbstractDSpaceTransformer
{
/** Language string used: */
private static final Message T_title_create =
message("xmlui.EPerson.EditProfile.title_create");
private static final Message T_title_update =
message("xmlui.EPerson.EditProfile.title_update");
private static final Message T_dspace_home =
message("xmlui.general.dspace_home");
private static final Message T_trail_new_registration =
message("xmlui.EPerson.trail_new_registration");
private static final Message T_trail_update =
message("xmlui.EPerson.EditProfile.trail_update");
private static final Message T_head_create =
message("xmlui.EPerson.EditProfile.head_create");
private static final Message T_head_update =
message("xmlui.EPerson.EditProfile.head_update");
private static final Message T_email_address =
message("xmlui.EPerson.EditProfile.email_address");
private static final Message T_first_name =
message("xmlui.EPerson.EditProfile.first_name");
private static final Message T_error_required =
message("xmlui.EPerson.EditProfile.error_required");
private static final Message T_last_name =
message("xmlui.EPerson.EditProfile.last_name");
private static final Message T_telephone =
message("xmlui.EPerson.EditProfile.telephone");
private static final Message T_create_password_instructions =
message("xmlui.EPerson.EditProfile.create_password_instructions");
private static final Message T_update_password_instructions =
message("xmlui.EPerson.EditProfile.update_password_instructions");
private static final Message T_password =
message("xmlui.EPerson.EditProfile.password");
private static final Message T_error_invalid_password =
message("xmlui.EPerson.EditProfile.error_invalid_password");
private static final Message T_confirm_password =
message("xmlui.EPerson.EditProfile.confirm_password");
private static final Message T_error_unconfirmed_password =
message("xmlui.EPerson.EditProfile.error_unconfirmed_password");
private static final Message T_submit_update =
message("xmlui.EPerson.EditProfile.submit_update");
private static final Message T_submit_create =
message("xmlui.EPerson.EditProfile.submit_create");
private static final Message T_subscriptions =
message("xmlui.EPerson.EditProfile.subscriptions");
private static final Message T_subscriptions_help =
message("xmlui.EPerson.EditProfile.subscriptions_help");
private static final Message T_email_subscriptions =
message("xmlui.EPerson.EditProfile.email_subscriptions");
private static final Message T_select_collection =
message("xmlui.EPerson.EditProfile.select_collection");
private static final Message T_head_auth =
message("xmlui.EPerson.EditProfile.head_auth");
/** The email address of the user registering for the first time.*/
private String email;
/** Determine if the user is registering for the first time */
private boolean registering;
/** Determine if the user is allowed to set their own password */
private boolean allowSetPassword;
/** A list of fields in error */
private java.util.List<String> errors;
public void setup(SourceResolver resolver, Map objectModel, String src,
Parameters parameters) throws ProcessingException, SAXException,
IOException
{
super.setup(resolver,objectModel,src,parameters);
this.email = parameters.getParameter("email","unknown");
this.registering = parameters.getParameterAsBoolean("registering",false);
this.allowSetPassword = parameters.getParameterAsBoolean("allowSetPassword",false);
String errors = parameters.getParameter("errors","");
if (errors.length() > 0)
this.errors = Arrays.asList(errors.split(","));
else
this.errors = new ArrayList<String>();
// Ensure that the email variable is set.
if (eperson != null)
this.email = eperson.getEmail();
}
public void addPageMeta(PageMeta pageMeta) throws WingException
{
// Set the page title
if (registering)
pageMeta.addMetadata("title").addContent(T_title_create);
else
pageMeta.addMetadata("title").addContent(T_title_update);
pageMeta.addTrailLink(contextPath + "/",T_dspace_home);
if (registering)
pageMeta.addTrail().addContent(T_trail_new_registration);
else
pageMeta.addTrail().addContent(T_trail_update);
}
public void addBody(Body body) throws WingException, SQLException
{
Request request = ObjectModelHelper.getRequest(objectModel);
String defaultFirstName="",defaultLastName="",defaultPhone="";
if (request.getParameter("submit") != null)
{
defaultFirstName = request.getParameter("first_name");
defaultLastName = request.getParameter("last_name");
defaultPhone = request.getParameter("phone");
}
else if (eperson != null)
{
defaultFirstName = eperson.getFirstName();
defaultLastName = eperson.getLastName();
defaultPhone = eperson.getMetadata("phone");
}
String action = contextPath;
if (registering)
action += "/register";
else
action += "/profile";
Division profile = body.addInteractiveDivision("information",
action,Division.METHOD_POST,"primary");
if (registering)
profile.setHead(T_head_create);
else
profile.setHead(T_head_update);
// Add the progress list if we are registering a new user
if (registering)
EPersonUtils.registrationProgressList(profile,2);
List form = profile.addList("form",List.TYPE_FORM);
List identity = form.addList("identity",List.TYPE_FORM);
identity.setHead("Identity");
// Email
identity.addLabel(T_email_address);
identity.addItem(email);
// First name
Text firstName = identity.addItem().addText("first_name");
firstName.setRequired();
firstName.setLabel(T_first_name);
firstName.setValue(defaultFirstName);
if (errors.contains("first_name"))
{
firstName.addError(T_error_required);
}
// Last name
Text lastName = identity.addItem().addText("last_name");
lastName.setRequired();
lastName.setLabel(T_last_name);
lastName.setValue(defaultLastName);
if (errors.contains("last_name"))
{
lastName.addError(T_error_required);
}
// Phone
Text phone = identity.addItem().addText("phone");
phone.setLabel(T_telephone);
phone.setValue(defaultPhone);
if (errors.contains("phone"))
{
phone.addError(T_error_required);
}
// Subscriptions
if (!registering)
{
List subscribe = form.addList("subscriptions",List.TYPE_FORM);
subscribe.setHead(T_subscriptions);
subscribe.addItem(T_subscriptions_help);
Collection[] currentList = Subscribe.getSubscriptions(context, context.getCurrentUser());
Collection[] possibleList = Collection.findAll(context);
Select subscriptions = subscribe.addItem().addSelect("subscriptions");
subscriptions.setLabel(T_email_subscriptions);
subscriptions.setHelp("");
subscriptions.enableAddOperation();
subscriptions.enableDeleteOperation();
subscriptions.addOption(-1,T_select_collection);
for (Collection possible : possibleList)
{
String name = possible.getMetadata("name");
if (name.length() > 50)
name = name.substring(0, 47) + "...";
subscriptions.addOption(possible.getID(), name);
}
for (Collection collection: currentList)
subscriptions.addInstance().setOptionSelected(collection.getID());
}
if (allowSetPassword)
{
List security = form.addList("security",List.TYPE_FORM);
security.setHead("Security");
if (registering)
{
security.addItem().addContent(T_create_password_instructions);
}
else
{
security.addItem().addContent(T_update_password_instructions);
}
Field password = security.addItem().addPassword("password");
password.setLabel(T_password);
if (registering)
password.setRequired();
if (errors.contains("password"))
{
password.addError(T_error_invalid_password);
}
Field passwordConfirm = security.addItem().addPassword("password_confirm");
passwordConfirm.setLabel(T_confirm_password);
if (registering)
passwordConfirm.setRequired();
if (errors.contains("password_confirm"))
{
passwordConfirm.addError(T_error_unconfirmed_password);
}
}
Button submit = form.addItem().addButton("submit");
if (registering)
submit.setValue(T_submit_update);
else
submit.setValue(T_submit_create);
profile.addHidden("eperson-continue").setValue(knot.getId());
if (!registering)
{
// Add a list of groups that this user is apart of.
Group[] memberships = Group.allMemberGroups(context, context.getCurrentUser());
// Not a member of any groups then don't do anything.
if (!(memberships.length > 0))
return;
List list = profile.addList("memberships");
list.setHead(T_head_auth);
for (Group group: memberships)
{
list.addItem(group.getName());
}
}
}
/**
* Recycle
*/
public void recycle()
{
this.email = null;
this.errors = null;
super.recycle();
}
}

View File

@@ -0,0 +1,64 @@
package org.dspace.app.xmlui.aspect.eperson;
import java.io.IOException;
import java.sql.SQLException;
import javax.servlet.http.HttpServletRequest;
import org.apache.cocoon.environment.ObjectModelHelper;
import org.apache.cocoon.environment.Request;
import org.dspace.app.xmlui.cocoon.AbstractDSpaceTransformer;
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.PageMeta;
import org.dspace.authorize.AuthorizeException;
import org.xml.sax.SAXException;
public class FailedAuthentication extends AbstractDSpaceTransformer {
private final static String SESSION_ATTRIBUTE_NAME = "xmlui.Eperson.FailedAuthentication.message";
public final static Message BAD_CREDENTIALS = message("xmlui.EPerson.FailedAuthentication.BadCreds");
public final static Message BAD_ARGUMENTS = message("xmlui.EPerson.FailedAuthentication.BadArgs");
public final static Message NO_SUCH_USER = message("xmlui.EPerson.FailedAuthentication.NoSuchUser");
/**language strings */
public static final Message T_title =
message("xmlui.EPerson.FailedAuthentication.title");
public static final Message T_dspace_home =
message("xmlui.general.dspace_home");
public static final Message T_trail =
message("xmlui.EPerson.FailedAuthentication.trail");
public static final Message T_h1 =
message("xmlui.EPerson.FailedAuthentication.h1");
public void addBody(Body body) throws SAXException, WingException, UIException, SQLException, IOException, AuthorizeException {
Request request = ObjectModelHelper.getRequest(objectModel);
Division div = body.addDivision("failed_auth");
div.setHead(T_h1);
div.addPara((Message)request.getSession().getAttribute(SESSION_ATTRIBUTE_NAME));
deRegisterErrorCode(request);
}
public void addPageMeta(PageMeta pageMeta) throws SAXException, WingException, UIException, SQLException, IOException, AuthorizeException {
pageMeta.addMetadata("title").addContent(T_title);
pageMeta.addTrailLink(contextPath + "/",T_dspace_home);
pageMeta.addTrail().addContent(T_trail);
}
public static void registerErrorCode(Message message, HttpServletRequest request){
request.getSession().setAttribute(SESSION_ATTRIBUTE_NAME, message);
}
private static void deRegisterErrorCode(Request request){
request.getSession().removeAttribute(SESSION_ATTRIBUTE_NAME);
}
}

View File

@@ -0,0 +1,98 @@
/*
* ForgotPasswordFinished.java
*
* Version: $Revision: 1.2 $
*
* Date: $Date: 2006/06/02 21:37:46 $
*
* Copyright (c) 2002, Hewlett-Packard Company and Massachusetts
* Institute of Technology. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* - 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.
*
* - Neither the name of the Hewlett-Packard Company nor the name of the
* Massachusetts Institute of Technology nor the names of their
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS 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 COPYRIGHT
* HOLDERS OR 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.
*/
package org.dspace.app.xmlui.aspect.eperson;
import org.dspace.app.xmlui.cocoon.AbstractDSpaceTransformer;
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.PageMeta;
/**
* Display to the user that their password has been successfully reset.
*
* @author Scott Phillips
*/
public class ForgotPasswordFinished extends AbstractDSpaceTransformer
{
private static final Message T_title =
message("xmlui.EPerson.ForgotPasswordFinished.title");
private static final Message T_dspace_home =
message("xmlui.general.dspace_home");
private static final Message T_trail_forgot_password =
message("xmlui.EPerson.trail_forgot_password");
private static final Message T_head =
message("xmlui.EPerson.ForgotPasswordFinished.head");
private static final Message T_para1 =
message("xmlui.EPerson.ForgotPasswordFinished.para1");
private static final Message T_go_home =
message("xmlui.general.go_home");
public void addPageMeta(PageMeta pageMeta) throws WingException
{
// Set the page title
pageMeta.addMetadata("title").addContent(T_title);
pageMeta.addTrailLink(contextPath + "/",T_dspace_home);
pageMeta.addTrail().addContent(T_trail_forgot_password);
}
public void addBody(Body body) throws WingException
{
Division reset = body.addDivision("password-reset", "primary");
reset.setHead(T_head);
EPersonUtils.forgottProgressList(reset, 3);
reset.addPara(T_para1);
reset.addPara().addXref(contextPath, T_go_home);
}
}

View File

@@ -0,0 +1,109 @@
/*
* InvalidToken.java
*
* Version: $Revision: 1.2 $
*
* Date: $Date: 2006/06/02 21:37:46 $
*
* Copyright (c) 2002, Hewlett-Packard Company and Massachusetts
* Institute of Technology. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* - 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.
*
* - Neither the name of the Hewlett-Packard Company nor the name of the
* Massachusetts Institute of Technology nor the names of their
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS 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 COPYRIGHT
* HOLDERS OR 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.
*/
package org.dspace.app.xmlui.aspect.eperson;
import org.dspace.app.xmlui.cocoon.AbstractDSpaceTransformer;
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.PageMeta;
import org.dspace.app.xmlui.wing.element.Para;
import org.dspace.core.ConfigurationManager;
/**
* Display to the user that the token provided was invalid.
*
* @author Scott Phillips
*/
public class InvalidToken extends AbstractDSpaceTransformer
{
/** language strings */
private static final Message T_title =
message("xmlui.EPerson.InvalidToken.title");
private static final Message T_dspace_home =
message("xmlui.general.dspace_home");
private static final Message T_trail =
message("xmlui.EPerson.InvalidToken.trail");
private static final Message T_head =
message("xmlui.EPerson.InvalidToken.head");
private static final Message T_para1 =
message("xmlui.EPerson.InvalidToken.para1");
private static final Message T_para2 =
message("xmlui.EPerson.InvalidToken.para2");
public void addPageMeta(PageMeta pageMeta) throws WingException
{
// Set the page title
pageMeta.addMetadata("title").addContent(T_title);
pageMeta.addTrailLink(contextPath + "/",T_dspace_home);
pageMeta.addTrail().addContent(T_trail);
}
public void addBody(Body body) throws WingException {
Division invalid = body.addDivision("invalid-token","primary");
invalid.setHead(T_head);
invalid.addPara(T_para1);
Para example1 = invalid.addPara("invalid-token-examlpe","code");
example1.addContent(ConfigurationManager.getProperty("dspace.url") + "/register?token=ABCDEFGHIJK");
Para example2 = invalid.addPara("invalid-token-examlpe","code");
example2.addContent("LMNOP");
invalid.addPara(T_para2);
Para example3 = invalid.addPara("valid-token-examlpe","code");
example3.addContent(ConfigurationManager.getProperty("dspace.url") + "/register?token=ABCDEFGHIJKLMNOP");
}
}

View File

@@ -0,0 +1,137 @@
/*
* LDAPAuthenticateAction.java
*
* Version: $Revision: 1.3 $
*
* Date: $Date: 2006/08/08 20:55:36 $
*
* Copyright (c) 2002, Hewlett-Packard Company and Massachusetts
* Institute of Technology. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* - 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.
*
* - Neither the name of the Hewlett-Packard Company nor the name of the
* Massachusetts Institute of Technology nor the names of their
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS 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 COPYRIGHT
* HOLDERS OR 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.
*/
package org.dspace.app.xmlui.aspect.eperson;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.Map;
import javax.servlet.http.HttpServletResponse;
import org.apache.avalon.framework.parameters.Parameters;
import org.apache.cocoon.acting.AbstractAction;
import org.apache.cocoon.environment.ObjectModelHelper;
import org.apache.cocoon.environment.Redirector;
import org.apache.cocoon.environment.Request;
import org.apache.cocoon.environment.SourceResolver;
import org.apache.cocoon.environment.http.HttpEnvironment;
import org.apache.cocoon.sitemap.PatternException;
import org.dspace.app.xmlui.utils.AuthenticationUtil;
import org.dspace.core.Context;
import org.dspace.eperson.EPerson;
/**
* Attempt to authenticate the user based upon their presented credentials. This
* action uses the http parameters of username, ldap_password, and login_realm
* as credentials.
*
* If the authentication attempt is successfull then an HTTP redirect will be
* sent to the browser redirecting them to their original location in the system
* before authenticated or if none is supplied back to the DSpace homepage. The
* action will also return true, thus contents of the action will be excuted.
*
* If the authentication attempt fails, the action returns false.
*
* Example use:
*
* <map:act name="LDAPAuthenticate"> <map:serialize type="xml"/> </map:act>
* <map:transform type="try-to-login-again-transformer">
*
* @author Jay Paz
*/
public class LDAPAuthenticateAction extends AbstractAction {
/**
* Attempt to authenticate the user.
*/
public Map act(Redirector redirector, SourceResolver resolver,
Map objectModel, String source, Parameters parameters)
throws Exception {
// First check if we are preforming a new login
Request request = ObjectModelHelper.getRequest(objectModel);
String username = request.getParameter("username");
String password = request.getParameter("ldap_password");
String realm = request.getParameter("login_realm");
try {
Context context = AuthenticationUtil.Authenticate(objectModel,
username, password, realm);
EPerson eperson = context.getCurrentUser();
if (eperson != null) {
// The user has successfully logged in
String redirectURL = request.getContextPath();
if (AuthenticationUtil.isInterupptedRequest(objectModel)) {
// Resume the request and set the redirect target URL to
// that of the originaly interrupted request.
redirectURL += AuthenticationUtil
.resumeInterruptedRequest(objectModel);
}
// Authentication successfull send a redirect.
final HttpServletResponse httpResponse = (HttpServletResponse) objectModel
.get(HttpEnvironment.HTTP_RESPONSE_OBJECT);
httpResponse.sendRedirect(redirectURL);
// log the user out for the rest of this current request,
// however they will be reauthenticated
// fully when they come back from the redirect. This prevents
// caching problems where part of the
// request is preformed fore the user was authenticated and the
// other half after it succedded. This
// way the user is fully authenticated from the start of the
// request.
context.setCurrentUser(null);
return new HashMap();
}
} catch (SQLException sqle) {
throw new PatternException("Unable to preform authentication", sqle);
}
return null;
}
}

View File

@@ -0,0 +1,215 @@
/*
* LDAPLogin.java
*
* Version: $Revision: 1.12 $
*
* Date: $Date: 2006/08/08 20:57:03 $
*
* Copyright (c) 2002-2005, Hewlett-Packard Company and Massachusetts
* Institute of Technology. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* - 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.
*
* - Neither the name of the Hewlett-Packard Company nor the name of the
* Massachusetts Institute of Technology nor the names of their
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS 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 COPYRIGHT
* HOLDERS OR 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.
*/
package org.dspace.app.xmlui.aspect.eperson;
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;
import org.apache.cocoon.environment.Session;
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.AuthenticationUtil;
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.Item;
import org.dspace.app.xmlui.wing.element.List;
import org.dspace.app.xmlui.wing.element.PageMeta;
import org.dspace.app.xmlui.wing.element.Password;
import org.dspace.app.xmlui.wing.element.Text;
import org.xml.sax.SAXException;
/**
* Query the user for their authentication credentials.
*
* The parameter "return-url" may be passed to give a location where to redirect
* the user to after sucessfully authenticating.
*
* @author Jay Paz
*/
public class LDAPLogin extends AbstractDSpaceTransformer implements
CacheableProcessingComponent {
/** language strings */
public static final Message T_title = message("xmlui.EPerson.LDAPLogin.title");
public static final Message T_dspace_home = message("xmlui.general.dspace_home");
public static final Message T_trail = message("xmlui.EPerson.LDAPLogin.trail");
public static final Message T_head1 = message("xmlui.EPerson.LDAPLogin.head1");
public static final Message T_userName = message("xmlui.EPerson.LDAPLogin.username");
public static final Message T_error_bad_login = message("xmlui.EPerson.LDAPLogin.error_bad_login");
public static final Message T_password = message("xmlui.EPerson.LDAPLogin.password");
public static final Message T_submit = message("xmlui.EPerson.LDAPLogin.submit");
/**
* Generate the unique caching key. This key must be unique inside the space
* of this component.
*/
public Serializable getKey() {
Request request = ObjectModelHelper.getRequest(objectModel);
String previous_username = request.getParameter("username");
// Get any message parameters
Session session = request.getSession();
String header = (String) session
.getAttribute(AuthenticationUtil.REQUEST_INTERRUPTED_HEADER);
String message = (String) session
.getAttribute(AuthenticationUtil.REQUEST_INTERRUPTED_MESSAGE);
String characters = (String) session
.getAttribute(AuthenticationUtil.REQUEST_INTERRUPTED_CHARACTERS);
// If there is a message or previous email attempt then the page is not
// cachable
if (header == null && message == null && characters == null
&& previous_username == null)
// cacheable
return "1";
else
// Uncachable
return "0";
}
/**
* Generate the cache validity object.
*/
public SourceValidity getValidity() {
Request request = ObjectModelHelper.getRequest(objectModel);
String previous_username = request.getParameter("username");
// Get any message parameters
Session session = request.getSession();
String header = (String) session
.getAttribute(AuthenticationUtil.REQUEST_INTERRUPTED_HEADER);
String message = (String) session
.getAttribute(AuthenticationUtil.REQUEST_INTERRUPTED_MESSAGE);
String characters = (String) session
.getAttribute(AuthenticationUtil.REQUEST_INTERRUPTED_CHARACTERS);
// If there is a message or previous email attempt then the page is not
// cachable
if (header == null && message == null && characters == null
&& previous_username == null)
// Always valid
return NOPValidity.SHARED_INSTANCE;
else
// invalid
return null;
}
/**
* Set the page title and trail.
*/
public void addPageMeta(PageMeta pageMeta) throws WingException {
pageMeta.addMetadata("title").addContent(T_title);
pageMeta.addTrailLink(contextPath + "/", T_dspace_home);
pageMeta.addTrail().addContent(T_trail);
}
/**
* Display the login form.
*/
public void addBody(Body body) throws SQLException, SAXException,
WingException {
// Check if the user has previously attempted to login.
Request request = ObjectModelHelper.getRequest(objectModel);
Session session = request.getSession();
String previousUserName = request.getParameter("username");
// Get any message parameters
String header = (String) session
.getAttribute(AuthenticationUtil.REQUEST_INTERRUPTED_HEADER);
String message = (String) session
.getAttribute(AuthenticationUtil.REQUEST_INTERRUPTED_MESSAGE);
String characters = (String) session
.getAttribute(AuthenticationUtil.REQUEST_INTERRUPTED_CHARACTERS);
if (header != null || message != null || characters != null) {
Division reason = body.addDivision("login-reason");
if (header != null)
reason.setHead(message(header));
else
// Allways have a head.
reason.setHead("Authentication Required");
if (message != null)
reason.addPara(message(message));
if (characters != null)
reason.addPara(characters);
}
Division login = body.addInteractiveDivision("login", contextPath
+ "/ldap-login", Division.METHOD_POST, "primary");
login.setHead(T_head1);
List list = login.addList("ldap-login", List.TYPE_FORM);
Text email = list.addItem().addText("username");
email.setRequired();
email.setLabel(T_userName);
if (previousUserName != null) {
email.setValue(previousUserName);
email.addError(T_error_bad_login);
}
Item item = list.addItem();
Password password = item.addPassword("ldap_password");
password.setRequired();
password.setLabel(T_password);
list.addLabel();
Item submit = list.addItem("login-in", null);
submit.addButton("submit").setValue(T_submit);
}
}

View File

@@ -0,0 +1,231 @@
/*
* LoginChooser.java
*
* Version: $Revision: 1 $
*
* Date: $Date: 2007/02/07 11:08:42 $
*
* Copyright (c) 2002-2005, Hewlett-Packard Company and Massachusetts
* Institute of Technology. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* - 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.
*
* - Neither the name of the Hewlett-Packard Company nor the name of the
* Massachusetts Institute of Technology nor the names of their
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS 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 COPYRIGHT
* HOLDERS OR 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.
*/
package org.dspace.app.xmlui.aspect.eperson;
import java.io.Serializable;
import java.sql.SQLException;
import java.util.Iterator;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.cocoon.caching.CacheableProcessingComponent;
import org.apache.cocoon.environment.ObjectModelHelper;
import org.apache.cocoon.environment.Request;
import org.apache.cocoon.environment.Session;
import org.apache.cocoon.environment.http.HttpEnvironment;
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.AuthenticationUtil;
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.Item;
import org.dspace.app.xmlui.wing.element.List;
import org.dspace.app.xmlui.wing.element.PageMeta;
import org.dspace.core.ConfigurationManager;
import org.dspace.eperson.AuthenticationManager;
import org.dspace.eperson.AuthenticationMethod;
import org.xml.sax.SAXException;
/**
* Displays a list of authentication methods. This page is displayed if more
* than one AuthenticationMethod is defined in the dpace config file.
*
* @author Jay Paz
*
*/
public class LoginChooser extends AbstractDSpaceTransformer implements
CacheableProcessingComponent {
public static final Message T_dspace_home = message("xmlui.general.dspace_home");
public static final Message T_title = message("xmlui.EPerson.LoginChooser.title");
public static final Message T_trail = message("xmlui.EPerson.LoginChooser.trail");
public static final Message T_head1 = message("xmlui.EPerson.LoginChooser.head1");
public static final Message T_para1 = message("xmlui.EPerson.LoginChooser.para1");
/**
* Generate the unique caching key. This key must be unique inside the space
* of this component.
*/
public Serializable getKey() {
Request request = ObjectModelHelper.getRequest(objectModel);
String previous_email = request.getParameter("login_email");
// Get any message parameters
Session session = request.getSession();
String header = (String) session
.getAttribute(AuthenticationUtil.REQUEST_INTERRUPTED_HEADER);
String message = (String) session
.getAttribute(AuthenticationUtil.REQUEST_INTERRUPTED_MESSAGE);
String characters = (String) session
.getAttribute(AuthenticationUtil.REQUEST_INTERRUPTED_CHARACTERS);
// If there is a message or previous email attempt then the page is not
// cachable
if (header == null && message == null && characters == null
&& previous_email == null)
// cacheable
return "1";
else
// Uncachable
return "0";
}
/**
* Generate the cache validity object.
*/
public SourceValidity getValidity() {
Request request = ObjectModelHelper.getRequest(objectModel);
String previous_email = request.getParameter("login_email");
// Get any message parameters
Session session = request.getSession();
String header = (String) session
.getAttribute(AuthenticationUtil.REQUEST_INTERRUPTED_HEADER);
String message = (String) session
.getAttribute(AuthenticationUtil.REQUEST_INTERRUPTED_MESSAGE);
String characters = (String) session
.getAttribute(AuthenticationUtil.REQUEST_INTERRUPTED_CHARACTERS);
// If there is a message or previous email attempt then the page is not
// cachable
if (header == null && message == null && characters == null
&& previous_email == null)
// Always valid
return NOPValidity.SHARED_INSTANCE;
else
// invalid
return null;
}
/**
* Set the page title and trail.
*/
public void addPageMeta(PageMeta pageMeta) throws WingException {
pageMeta.addMetadata("title").addContent(T_title);
pageMeta.addTrailLink(contextPath + "/", T_dspace_home);
pageMeta.addTrail().addContent(T_trail);
}
/**
* Display the login choices.
*/
public void addBody(Body body) throws SQLException, SAXException,
WingException {
Iterator authMethods = AuthenticationManager
.authenticationMethodIterator();
Request request = ObjectModelHelper.getRequest(objectModel);
Session session = request.getSession();
// Get any message parameters
String header = (String) session
.getAttribute(AuthenticationUtil.REQUEST_INTERRUPTED_HEADER);
String message = (String) session
.getAttribute(AuthenticationUtil.REQUEST_INTERRUPTED_MESSAGE);
String characters = (String) session
.getAttribute(AuthenticationUtil.REQUEST_INTERRUPTED_CHARACTERS);
if (header != null || message != null || characters != null) {
Division reason = body.addDivision("login-reason");
if (header != null)
reason.setHead(message(header));
else
// Allways have a head.
reason.setHead("Authentication Required");
if (message != null)
reason.addPara(message(message));
if (characters != null)
reason.addPara(characters);
}
Division loginChooser = body.addDivision("login-chooser");
loginChooser.setHead(T_head1);
loginChooser.addPara().addContent(T_para1);
List list = loginChooser.addList("login-options", List.TYPE_SIMPLE);
while (authMethods.hasNext()) {
final AuthenticationMethod authMethod = (AuthenticationMethod) authMethods
.next();
final Item item = list.addItem();
String loginURL;
if (ConfigurationManager.getBooleanProperty("xmlui.force.ssl")
&& !request.isSecure()) {
StringBuffer location = new StringBuffer("https://");
location
.append(ConfigurationManager.getProperty("dspace.hostname"))
.append(
authMethod
.loginPageURL(
context,
(HttpServletRequest) this.objectModel
.get(HttpEnvironment.HTTP_REQUEST_OBJECT),
(HttpServletResponse) this.objectModel
.get(HttpEnvironment.HTTP_RESPONSE_OBJECT)))
.append(
request.getQueryString() == null ? ""
: ("?" + request.getQueryString()));
loginURL = location.toString();
} else {
loginURL = authMethod.loginPageURL(context,
(HttpServletRequest) this.objectModel
.get(HttpEnvironment.HTTP_REQUEST_OBJECT),
(HttpServletResponse) this.objectModel
.get(HttpEnvironment.HTTP_RESPONSE_OBJECT));
}
item.addXref(loginURL, message(authMethod.loginPageTitle(context)));
}
}
}

View File

@@ -0,0 +1,106 @@
/*
* LoginRedirect.java
*
* Version: $Revision: 1.3 $
*
* Date: $Date: 2006/07/13 23:20:54 $
*
* Copyright (c) 2002, Hewlett-Packard Company and Massachusetts
* Institute of Technology. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* - 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.
*
* - Neither the name of the Hewlett-Packard Company nor the name of the
* Massachusetts Institute of Technology nor the names of their
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS 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 COPYRIGHT
* HOLDERS OR 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.
*/
package org.dspace.app.xmlui.aspect.eperson;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.avalon.framework.parameters.Parameters;
import org.apache.cocoon.acting.AbstractAction;
import org.apache.cocoon.environment.Redirector;
import org.apache.cocoon.environment.SourceResolver;
import org.apache.cocoon.environment.http.HttpEnvironment;
import org.dspace.app.xmlui.utils.ContextUtil;
import org.dspace.core.ConfigurationManager;
import org.dspace.eperson.AuthenticationManager;
import org.dspace.eperson.AuthenticationMethod;
/**
* When only one login method is defined in the dspace.cfg file this class will
* redirect to the URL provided by that AuthenticationMethod class
*
* @author Jay Paz
* @author Scott Phillips
*
*/
public class LoginRedirect extends AbstractAction {
public Map act(Redirector redirector, SourceResolver resolver,
Map objectModel, String source, Parameters parameters)
throws Exception {
final HttpServletResponse httpResponse = (HttpServletResponse) objectModel
.get(HttpEnvironment.HTTP_RESPONSE_OBJECT);
final HttpServletRequest httpRequest = (HttpServletRequest) objectModel
.get(HttpEnvironment.HTTP_REQUEST_OBJECT);
final Iterator authMethods = AuthenticationManager
.authenticationMethodIterator();
final String url = ((AuthenticationMethod) authMethods.next())
.loginPageURL(ContextUtil.obtainContext(objectModel),
httpRequest, httpResponse);
if (authMethods.hasNext()) {
throw new IllegalStateException(
"Multiple authentication methods found when only one was expected.");
}
// now we want to check for the force ssl property
if (ConfigurationManager.getBooleanProperty("xmlui.force.ssl")) {
if (!httpRequest.isSecure()) {
StringBuffer location = new StringBuffer("https://");
location.append(ConfigurationManager.getProperty("dspace.hostname")).append(url).append(
httpRequest.getQueryString() == null ? ""
: ("?" + httpRequest.getQueryString()));
httpResponse.sendRedirect(location.toString());
}
} else {
httpResponse.sendRedirect(url);
}
return new HashMap();
}
}

View File

@@ -0,0 +1,266 @@
/*
* Navigation.java
*
* Version: $Revision: 1.8 $
*
* Date: $Date: 2006/06/02 21:37:46 $
*
* Copyright (c) 2002, Hewlett-Packard Company and Massachusetts
* Institute of Technology. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* - 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.
*
* - Neither the name of the Hewlett-Packard Company nor the name of the
* Massachusetts Institute of Technology nor the names of their
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS 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 COPYRIGHT
* HOLDERS OR 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.
*/
package org.dspace.app.xmlui.aspect.eperson;
import java.io.IOException;
import java.io.Serializable;
import java.sql.SQLException;
import java.util.Enumeration;
import java.util.Locale;
import org.apache.cocoon.caching.CacheableProcessingComponent;
import org.apache.cocoon.environment.ObjectModelHelper;
import org.apache.cocoon.environment.Request;
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.DSpaceValidity;
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.List;
import org.dspace.app.xmlui.wing.element.Options;
import org.dspace.app.xmlui.wing.element.UserMeta;
import org.dspace.authorize.AuthorizeException;
import org.dspace.eperson.EPerson;
import org.dspace.eperson.Group;
import org.xml.sax.SAXException;
/**
* Add the eperson navigation items to the document. This includes:
*
* 1) Login and Logout links
*
* 2) Navigational links to register or edit their profile based
* upon wheather the user is authenticatied or not.
*
* 3) User metadata
*
* 4) The user's language prefrences (wheather someone is logged
* in or not)
*
* @author Scott Phillips
*/
public class Navigation extends AbstractDSpaceTransformer implements CacheableProcessingComponent
{
/** Language Strings */
private static final Message T_my_account =
message("xmlui.EPerson.Navigation.my_account");
private static final Message T_profile =
message("xmlui.EPerson.Navigation.profile");
private static final Message T_logout =
message("xmlui.EPerson.Navigation.logout");
private static final Message T_login =
message("xmlui.EPerson.Navigation.login");
private static final Message T_register =
message("xmlui.EPerson.Navigation.register");
/** Cached validity object */
private SourceValidity validity;
/**
* Generate the unique key.
* This key must be unique inside the space of this component.
*
* @return The generated key hashes the src
*/
public Serializable getKey()
{
Request request = ObjectModelHelper.getRequest(objectModel);
// Special case, don't cache anything if the user is logging
// in. The problem occures because of timming, this cache key
// is generated before we know whether the operation has
// succeded or failed. So we don't know whether to cache this
// under the user's specific cache or under the anonymous user.
if (request.getParameter("login_email") != null ||
request.getParameter("login_password") != null ||
request.getParameter("login_realm") != null )
{
return null;
}
// FIXME:
// Do not cache the home page. There is a bug that is causing the
// homepage to be cached with user's data after a logout. This
// polutes the cache. As a work-around this problem we just won't
// cache this page.
if (request.getSitemapURI().length() == 0)
{
return null;
}
String key;
if (context.getCurrentUser() != null)
key = context.getCurrentUser().getEmail();
else
key = "anonymous";
// Add the user's language
Enumeration locales = request.getLocales();
while (locales.hasMoreElements())
{
Locale locale = (Locale) locales.nextElement();
key += "-" + locale.toString();
}
return HashUtil.hash(key);
}
/**
* Generate the validity object.
*
* @return The generated validity object or <code>null</code> if the
* component is currently not cacheable.
*/
public SourceValidity getValidity()
{
if (this.validity == null)
{
// Only use the DSpaceValidity object is someone is logged in.
if (context.getCurrentUser() != null)
{
try {
DSpaceValidity validity = new DSpaceValidity();
validity.add(eperson);
Group[] groups = Group.allMemberGroups(context, eperson);
for (Group group : groups)
{
validity.add(group);
}
this.validity = validity.complete();
}
catch (SQLException sqle)
{
// Just ignore it and return invalid.
}
}
else
{
this.validity = NOPValidity.SHARED_INSTANCE;
}
}
return this.validity;
}
/**
* Add the eperson aspect navigational options.
*/
public void addOptions(Options options) throws SAXException, WingException,
UIException, SQLException, IOException, AuthorizeException
{
/* Create skeleton menu structure to ensure consistent order between aspects,
* even if they are never used
*/
options.addList("browse");
List account = options.addList("account");
options.addList("context");
options.addList("administrative");
account.setHead(T_my_account);
EPerson eperson = this.context.getCurrentUser();
if (eperson != null)
{
String fullName = eperson.getFullName();
account.addItemXref(contextPath+"/logout",T_logout);
account.addItemXref(contextPath+"/profile",T_profile.parameterize(fullName));
}
else
{
account.addItemXref(contextPath+"/login",T_login);
account.addItemXref(contextPath+"/register",T_register);
}
}
/**
* Add the user metadata
*/
public void addUserMeta(UserMeta userMeta) throws SAXException,
WingException, UIException, SQLException, IOException,
AuthorizeException
{
EPerson eperson = context.getCurrentUser();
if (eperson != null)
{
userMeta.setAuthenticated(true);
userMeta.addMetadata("identifier").addContent(eperson.getID());
userMeta.addMetadata("identifier","email").addContent(eperson.getEmail());
userMeta.addMetadata("identifier","firstName").addContent(eperson.getFirstName());
userMeta.addMetadata("identifier","lastName").addContent(eperson.getLastName());
userMeta.addMetadata("identifier","logoutURL").addContent(contextPath+"/logout");
userMeta.addMetadata("identifier","url").addContent(contextPath+"/profile");
}
else
{
userMeta.setAuthenticated(false);
}
// Allways have a login URL.
userMeta.addMetadata("identifier","loginURL").addContent(contextPath+"/login");
// Allways add language information
Request request = ObjectModelHelper.getRequest(objectModel);
Enumeration locales = request.getLocales();
while (locales.hasMoreElements())
{
Locale locale = (Locale) locales.nextElement();
userMeta.addMetadata("language","RFC3066").addContent(locale.toString());
}
}
/**
* recycle
*/
public void recycle()
{
this.validity = null;
super.recycle();
}
}

View File

@@ -0,0 +1,240 @@
/*
* PasswordLogin.java
*
* Version: $Revision: 1.12 $
*
* Date: $Date: 2006/08/08 20:57:03 $
*
* Copyright (c) 2002-2005, Hewlett-Packard Company and Massachusetts
* Institute of Technology. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* - 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.
*
* - Neither the name of the Hewlett-Packard Company nor the name of the
* Massachusetts Institute of Technology nor the names of their
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS 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 COPYRIGHT
* HOLDERS OR 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.
*/
package org.dspace.app.xmlui.aspect.eperson;
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;
import org.apache.cocoon.environment.Session;
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.AuthenticationUtil;
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.Item;
import org.dspace.app.xmlui.wing.element.List;
import org.dspace.app.xmlui.wing.element.PageMeta;
import org.dspace.app.xmlui.wing.element.Password;
import org.dspace.app.xmlui.wing.element.Text;
import org.xml.sax.SAXException;
/**
* Query the user for their authentication credentials.
*
* The parameter "return-url" may be passed to give a location
* where to redirect the user to after sucessfully authenticating.
*
* @author Sid
* @author Scott Phillips
*/
public class PasswordLogin extends AbstractDSpaceTransformer implements CacheableProcessingComponent
{
/**language strings */
public static final Message T_title =
message("xmlui.EPerson.PasswordLogin.title");
public static final Message T_dspace_home =
message("xmlui.general.dspace_home");
public static final Message T_trail =
message("xmlui.EPerson.PasswordLogin.trail");
public static final Message T_head1 =
message("xmlui.EPerson.PasswordLogin.head1");
public static final Message T_email_address =
message("xmlui.EPerson.PasswordLogin.email_address");
public static final Message T_error_bad_login =
message("xmlui.EPerson.PasswordLogin.error_bad_login");
public static final Message T_password =
message("xmlui.EPerson.PasswordLogin.password");
public static final Message T_forgot_link =
message("xmlui.EPerson.PasswordLogin.forgot_link");
public static final Message T_submit =
message("xmlui.EPerson.PasswordLogin.submit");
public static final Message T_head2 =
message("xmlui.EPerson.PasswordLogin.head2");
public static final Message T_para1 =
message("xmlui.EPerson.PasswordLogin.para1");
public static final Message T_register_link =
message("xmlui.EPerson.PasswordLogin.register_link");
/**
* Generate the unique caching key.
* This key must be unique inside the space of this component.
*/
public Serializable getKey()
{
Request request = ObjectModelHelper.getRequest(objectModel);
String previous_email = request.getParameter("login_email");
// Get any message parameters
Session session = request.getSession();
String header = (String) session.getAttribute(AuthenticationUtil.REQUEST_INTERRUPTED_HEADER);
String message = (String) session.getAttribute(AuthenticationUtil.REQUEST_INTERRUPTED_MESSAGE);
String characters = (String) session.getAttribute(AuthenticationUtil.REQUEST_INTERRUPTED_CHARACTERS);
// If there is a message or previous email attempt then the page is not cachable
if (header == null && message == null && characters == null && previous_email == null)
// cacheable
return "1";
else
// Uncachable
return "0";
}
/**
* Generate the cache validity object.
*/
public SourceValidity getValidity()
{
Request request = ObjectModelHelper.getRequest(objectModel);
String previous_email = request.getParameter("login_email");
// Get any message parameters
Session session = request.getSession();
String header = (String) session.getAttribute(AuthenticationUtil.REQUEST_INTERRUPTED_HEADER);
String message = (String) session.getAttribute(AuthenticationUtil.REQUEST_INTERRUPTED_MESSAGE);
String characters = (String) session.getAttribute(AuthenticationUtil.REQUEST_INTERRUPTED_CHARACTERS);
// If there is a message or previous email attempt then the page is not cachable
if (header == null && message == null && characters == null && previous_email == null)
// Always valid
return NOPValidity.SHARED_INSTANCE;
else
// invalid
return null;
}
/**
* Set the page title and trail.
*/
public void addPageMeta(PageMeta pageMeta) throws WingException
{
pageMeta.addMetadata("title").addContent(T_title);
pageMeta.addTrailLink(contextPath + "/",T_dspace_home);
pageMeta.addTrail().addContent(T_trail);
}
/**
* Display the login form.
*/
public void addBody(Body body) throws SQLException, SAXException,
WingException
{
// Check if the user has previously attempted to login.
Request request = ObjectModelHelper.getRequest(objectModel);
Session session = request.getSession();
String previousEmail = request.getParameter("login_email");
// Get any message parameters
String header = (String) session.getAttribute(AuthenticationUtil.REQUEST_INTERRUPTED_HEADER);
String message = (String) session.getAttribute(AuthenticationUtil.REQUEST_INTERRUPTED_MESSAGE);
String characters = (String) session.getAttribute(AuthenticationUtil.REQUEST_INTERRUPTED_CHARACTERS);
if (header != null || message != null || characters != null)
{
Division reason = body.addDivision("login-reason");
if (header != null)
reason.setHead(message(header));
else
// Allways have a head.
reason.setHead("Authentication Required");
if (message != null)
reason.addPara(message(message));
if (characters != null)
reason.addPara(characters);
}
Division login = body.addInteractiveDivision("login", contextPath
+ "/password-login", Division.METHOD_POST, "primary");
login.setHead(T_head1);
List list = login.addList("password-login",List.TYPE_FORM);
Text email = list.addItem().addText("login_email");
email.setRequired();
email.setLabel(T_email_address);
if (previousEmail != null)
{
email.setValue(previousEmail);
email.addError(T_error_bad_login);
}
Item item = list.addItem();
Password password = item.addPassword("login_password");
password.setRequired();
password.setLabel(T_password);
item.addXref(contextPath + "/forgot", T_forgot_link);
list.addLabel();
Item submit = list.addItem("login-in", null);
submit.addButton("submit").setValue(T_submit);
Division register = login.addDivision("register");
register.setHead(T_head2);
register.addPara(T_para1);
register.addPara().addXref(contextPath + "/register",T_register_link);
}
}

View File

@@ -0,0 +1,99 @@
/*
* ProfileUpdated.java
*
* Version: $Revision: 1.2 $
*
* Date: $Date: 2006/06/02 21:37:46 $
*
* Copyright (c) 2002, Hewlett-Packard Company and Massachusetts
* Institute of Technology. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* - 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.
*
* - Neither the name of the Hewlett-Packard Company nor the name of the
* Massachusetts Institute of Technology nor the names of their
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS 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 COPYRIGHT
* HOLDERS OR 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.
*/
package org.dspace.app.xmlui.aspect.eperson;
import org.dspace.app.xmlui.cocoon.AbstractDSpaceTransformer;
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.PageMeta;
/**
* Display to the user that their profile has been successfully updated.
*
* @author Scott Phillips
*/
public class ProfileUpdated extends AbstractDSpaceTransformer
{
/** Language string */
private static final Message T_title =
message("xmlui.EPerson.ProfileUpdated.title");
private static final Message T_dspace_home =
message("xmlui.general.dspace_home");
private static final Message T_trail =
message("xmlui.EPerson.ProfileUpdated.trail");
private static final Message T_head =
message("xmlui.EPerson.ProfileUpdated.head");
private static final Message T_para1 =
message("xmlui.EPerson.ProfileUpdated.para1");
private static final Message T_go_home =
message("xmlui.general.go_home");
public void addPageMeta(PageMeta pageMeta) throws WingException
{
// Set the page title
pageMeta.addMetadata("title").addContent(T_title);
pageMeta.addTrailLink(contextPath + "/", T_dspace_home);
pageMeta.addTrail().addContent(T_trail);
}
public void addBody(Body body) throws WingException
{
Division updated = body.addDivision("profile-updated", "primary");
updated.setHead(T_head);
updated.addPara(T_para1);
updated.addPara().addXref(contextPath, T_go_home);
}
}

View File

@@ -0,0 +1,100 @@
/*
* RegistrationFinished.java
*
* Version: $Revision: 1.2 $
*
* Date: $Date: 2006/06/02 21:37:46 $
*
* Copyright (c) 2002, Hewlett-Packard Company and Massachusetts
* Institute of Technology. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* - 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.
*
* - Neither the name of the Hewlett-Packard Company nor the name of the
* Massachusetts Institute of Technology nor the names of their
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS 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 COPYRIGHT
* HOLDERS OR 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.
*/
package org.dspace.app.xmlui.aspect.eperson;
import org.dspace.app.xmlui.cocoon.AbstractDSpaceTransformer;
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.PageMeta;
/**
* Display to the user that they have successfully registered.
*
* @author Scott Phillips
*/
public class RegistrationFinished extends AbstractDSpaceTransformer
{
/** Language strings */
private static final Message T_title =
message("xmlui.EPerson.RegistrationFinished.title");
private static final Message T_dspace_home =
message("xmlui.general.dspace_home");
private static final Message T_trail_new_registration =
message("xmlui.EPerson.trail_new_registration");
private static final Message T_head =
message("xmlui.EPerson.RegistrationFinished.head");
private static final Message T_para1 =
message("xmlui.EPerson.RegistrationFinished.para1");
private static final Message T_go_home =
message("xmlui.general.go_home");
public void addPageMeta(PageMeta pageMeta) throws WingException
{
// Set the page title
pageMeta.addMetadata("title").addContent(T_title);
pageMeta.addTrailLink(contextPath + "/", T_dspace_home);
pageMeta.addTrail().addContent(T_trail_new_registration);
}
public void addBody(Body body) throws WingException
{
Division finished = body.addDivision("registration-finished", "primary");
finished.setHead(T_head);
EPersonUtils.registrationProgressList(finished, 3);
finished.addPara(T_para1);
finished.addPara().addXref(contextPath, T_go_home);
}
}

View File

@@ -0,0 +1,173 @@
/*
* ResetPassword.java
*
* Version: $Revision: 1.8 $
*
* Date: $Date: 2006/07/28 20:08:18 $
*
* Copyright (c) 2002, Hewlett-Packard Company and Massachusetts
* Institute of Technology. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* - 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.
*
* - Neither the name of the Hewlett-Packard Company nor the name of the
* Massachusetts Institute of Technology nor the names of their
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS 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 COPYRIGHT
* HOLDERS OR 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.
*/
package org.dspace.app.xmlui.aspect.eperson;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Map;
import org.apache.avalon.framework.parameters.Parameters;
import org.apache.cocoon.ProcessingException;
import org.apache.cocoon.environment.SourceResolver;
import org.dspace.app.xmlui.cocoon.AbstractDSpaceTransformer;
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.Field;
import org.dspace.app.xmlui.wing.element.List;
import org.dspace.app.xmlui.wing.element.PageMeta;
import org.xml.sax.SAXException;
/**
* Display a reset password form allowing the user to select a new password.
*
* @author Scott Phillips
*/
public class ResetPassword extends AbstractDSpaceTransformer
{
/** Language strings */
private final static Message T_title =
message("xmlui.EPerson.ResetPassword.title");
private final static Message T_dspace_home =
message("xmlui.general.dspace_home");
private final static Message T_trail_forgot_password =
message("xmlui.EPerson.trail_forgot_password");
private final static Message T_head =
message("xmlui.EPerson.ResetPassword.head");
private final static Message T_para1 =
message("xmlui.EPerson.ResetPassword.para1");
private final static Message T_email_address =
message("xmlui.EPerson.ResetPassword.email_address");
private final static Message T_new_password =
message("xmlui.EPerson.ResetPassword.new_password");
private final static Message T_error_invalid_password =
message("xmlui.EPerson.ResetPassword.error_invalid_password");
private final static Message T_confirm_password =
message("xmlui.EPerson.ResetPassword.confirm_password");
private final static Message T_error_unconfirmed_password =
message("xmlui.EPerson.ResetPassword.error_unconfirmed_password");
private final static Message T_submit =
message("xmlui.EPerson.ResetPassword.submit");
private String email;
private java.util.List<String> errors;
public void setup(SourceResolver resolver, Map objectModel, String src,
Parameters parameters) throws ProcessingException, SAXException,
IOException
{
super.setup(resolver,objectModel,src,parameters);
this.email = parameters.getParameter("email","unknown");
String errors = parameters.getParameter("errors","");
if (errors.length() > 0)
this.errors = Arrays.asList(errors.split(","));
else
this.errors = new ArrayList<String>();
}
public void addPageMeta(PageMeta pageMeta) throws WingException
{
// Set the page title
pageMeta.addMetadata("title").addContent(T_title);
pageMeta.addTrailLink(contextPath + "/",T_dspace_home);
pageMeta.addTrail().addContent(T_trail_forgot_password);
}
public void addBody(Body body) throws WingException {
Division register = body.addInteractiveDivision("reset-password",
contextPath+"/register",Division.METHOD_POST,"primary");
register.setHead(T_head);
EPersonUtils.forgottProgressList(register,2);
register.addPara(T_para1);
List form = register.addList("form",List.TYPE_FORM);
form.addLabel(T_email_address);
form.addItem(email);
Field password = form.addItem().addPassword("password");
password.setRequired();
password.setLabel(T_new_password);
if (errors.contains("password"))
{
password.addError(T_error_invalid_password);
}
Field passwordConfirm = form.addItem().addPassword("password_confirm");
passwordConfirm.setRequired();
passwordConfirm.setLabel(T_confirm_password);
if (errors.contains("password_confirm"))
{
passwordConfirm.addError(T_error_unconfirmed_password);
}
form.addItem().addButton("submit").setValue(T_submit);
register.addHidden("eperson-continue").setValue(knot.getId());
}
}

View File

@@ -0,0 +1,120 @@
/*
* StartAuthenticationAction.java
*
* Version: $Revision: 1.1 $
*
* Date: $Date: 2006/04/06 15:15:59 $
*
* Copyright (c) 2002-2005, Hewlett-Packard Company and Massachusetts
* Institute of Technology. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* - 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.
*
* - Neither the name of the Hewlett-Packard Company nor the name of the
* Massachusetts Institute of Technology nor the names of their
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS 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 COPYRIGHT
* HOLDERS OR 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.
*/
package org.dspace.app.xmlui.aspect.eperson;
import java.util.HashMap;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.avalon.framework.parameters.Parameters;
import org.apache.cocoon.acting.AbstractAction;
import org.apache.cocoon.environment.Redirector;
import org.apache.cocoon.environment.SourceResolver;
import org.apache.cocoon.environment.http.HttpEnvironment;
import org.dspace.app.xmlui.utils.AuthenticationUtil;
/**
*
* This action will start the nessary steps to authenticate a user. After the user
* successfully authenticates the user will resume this request with all parameters
* and attributes intact. An optional message can be added that will be displayed
* on the login form. This could be used to provide a reason why the user is being
* queried for a user name and password.
*
* Possible parameter are:
*
* header: An i18n message that will be used as the header for the message.
*
* message: An i18n message tag.
*
* characters: Characters to be displayed, possibly for untranslated error messages
*
*
* <map:action name="StartAuthenticationAction" src="org.dspace.app.xmlui.eperson.StartAuthenticationAction"/>
*
*
* <map:act type="StartAuthenticationAction"/>
*
*
* Typicaly this is used in conjunction with the AuthenticatedSelector as:
*
* <map:select type="AuthenticatedSelector">
* <map:when test="eperson">
* ...
* </map:when>
* <map:otherwise>
* <map:act type="startAuthenticationAction">
* <map:parameter name="message" value="xmlui.Aspect.component.tag"/>
* </map:act>
* </map:otherwise>
* </map:select>
*
* @author Scott Phillips
*/
public class StartAuthenticationAction extends AbstractAction
{
/**
* Redirect the user to the login page.
*/
public Map act(Redirector redirector, SourceResolver resolver,
Map objectModel, String source, Parameters parameters)
throws Exception
{
String header = parameters.getParameter("header",null);
String message = parameters.getParameter("message",null);
String characters = parameters.getParameter("characters",null);
// Interupt this request
AuthenticationUtil.interruptRequest(objectModel,header,message,characters);
final HttpServletRequest httpRequest = (HttpServletRequest) objectModel.get(HttpEnvironment.HTTP_REQUEST_OBJECT);
final HttpServletResponse httpResponse = (HttpServletResponse) objectModel.get(HttpEnvironment.HTTP_RESPONSE_OBJECT);
httpResponse.sendRedirect(httpRequest.getContextPath() + "/login");
return new HashMap();
}
}

View File

@@ -0,0 +1,177 @@
/*
* StartForgotPassword.java
*
* Version: $Revision: 1.8 $
*
* Date: $Date: 2006/08/08 20:57:24 $
*
* Copyright (c) 2002, Hewlett-Packard Company and Massachusetts
* Institute of Technology. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* - 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.
*
* - Neither the name of the Hewlett-Packard Company nor the name of the
* Massachusetts Institute of Technology nor the names of their
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS 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 COPYRIGHT
* HOLDERS OR 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.
*/
package org.dspace.app.xmlui.aspect.eperson;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Map;
import org.apache.avalon.framework.parameters.Parameters;
import org.apache.cocoon.ProcessingException;
import org.apache.cocoon.environment.SourceResolver;
import org.dspace.app.xmlui.cocoon.AbstractDSpaceTransformer;
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.Item;
import org.dspace.app.xmlui.wing.element.List;
import org.dspace.app.xmlui.wing.element.PageMeta;
import org.dspace.app.xmlui.wing.element.Text;
import org.xml.sax.SAXException;
/**
* Display the forgot password form, allowing the user to enter
* in an email address and have the system verify the email address
* before allowing the user to reset their password.
*
* There are two parameters that may be given to the form:
*
* email - The email of the forgotten account
*
* retry - A boolean value indicating that the previously entered email was invalid.
*
* @author Scott Phillips
*/
public class StartForgotPassword extends AbstractDSpaceTransformer
{
/** Language strings */
private final static Message T_title =
message("xmlui.EPerson.StartForgotPassword.title");
private final static Message T_dspace_home =
message("xmlui.general.dspace_home");
private final static Message T_trail_forgot_password =
message("xmlui.EPerson.trail_forgot_password");
private final static Message T_head =
message("xmlui.EPerson.StartForgotPassword.head");
private final static Message T_para1 =
message("xmlui.EPerson.StartForgotPassword.para1");
private final static Message T_email_address =
message("xmlui.EPerson.StartForgotPassword.email_address");
private final static Message T_email_address_help =
message("xmlui.EPerson.StartForgotPassword.email_address_help");
private final static Message T_error_not_found =
message("xmlui.EPerson.StartForgotPassword.error_not_found");
private final static Message T_submit =
message("xmlui.EPerson.StartForgotPassword.submit");
/** The email of the forgotten account */
private String email;
/** A list of fields in error */
private java.util.List<String> errors;
public void setup(SourceResolver resolver, Map objectModel, String src,
Parameters parameters) throws ProcessingException, SAXException,
IOException
{
super.setup(resolver,objectModel,src,parameters);
this.email = parameters.getParameter("email","");
String errors = parameters.getParameter("errors","");
if (errors.length() > 0)
this.errors = Arrays.asList(errors.split(","));
else
this.errors = new ArrayList<String>();
}
public void addPageMeta(PageMeta pageMeta) throws WingException
{
// Set the page title
pageMeta.addMetadata("title").addContent(T_title);
pageMeta.addTrailLink(contextPath + "/",T_dspace_home);
pageMeta.addTrail().addContent(T_trail_forgot_password);
}
public void addBody(Body body) throws WingException {
Division forgot = body.addInteractiveDivision("start-forgot-password",
contextPath+"/forgot",Division.METHOD_POST,"primary");
forgot.setHead(T_head);
EPersonUtils.forgottProgressList(forgot,1);
forgot.addPara(T_para1);
List form = forgot.addList("form",List.TYPE_FORM);
Text email = form.addItem().addText("email");
email.setRequired();
email.setLabel(T_email_address);
email.setHelp(T_email_address_help);
// Prefill with invalid email if this is a retry attempt.
if (email != null)
email.setValue(this.email);
if (errors.contains("email"))
email.addError(T_error_not_found);
Item submit = form.addItem();
submit.addButton("submit").setValue(T_submit);
forgot.addHidden("eperson-continue").setValue(knot.getId());
}
/**
* Recycle
*/
public void recycle()
{
this.email = null;
super.recycle();
}
}

View File

@@ -0,0 +1,249 @@
/*
* StartRegistration.java
*
* Version: $Revision: 1.7 $
*
* Date: $Date: 2006/07/28 20:08:18 $
*
* Copyright (c) 2002, Hewlett-Packard Company and Massachusetts
* Institute of Technology. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* - 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.
*
* - Neither the name of the Hewlett-Packard Company nor the name of the
* Massachusetts Institute of Technology nor the names of their
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS 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 COPYRIGHT
* HOLDERS OR 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.
*/
package org.dspace.app.xmlui.aspect.eperson;
import java.io.IOException;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Map;
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.excalibur.source.SourceValidity;
import org.apache.excalibur.source.impl.validity.NOPValidity;
import org.dspace.app.xmlui.cocoon.AbstractDSpaceTransformer;
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.Item;
import org.dspace.app.xmlui.wing.element.List;
import org.dspace.app.xmlui.wing.element.PageMeta;
import org.dspace.app.xmlui.wing.element.Text;
import org.xml.sax.SAXException;
/**
* Display the new user registration form, allowing the user to enter
* in an email address and have the system verify the email address
* before allowing the user create an account
*
* There are two parameters that may be given to the form:
*
* email - The email of the new account account
*
* retry - A boolean value indicating that the previously entered email was invalid.
*
* accountExists - A boolean value indicating the email previously entered allready
* belongs to a user.
*
* @author Scott Phillips
*/
public class StartRegistration extends AbstractDSpaceTransformer implements CacheableProcessingComponent
{
/** language strings */
private static final Message T_title =
message("xmlui.EPerson.StartRegistration.title");
private static final Message T_dspace_home =
message("xmlui.general.dspace_home");
private static final Message T_trail_new_registration =
message("xmlui.EPerson.trail_new_registration");
private static final Message T_head1 =
message("xmlui.EPerson.StartRegistration.head1");
private static final Message T_para1 =
message("xmlui.EPerson.StartRegistration.para1");
private static final Message T_reset_password_for =
message("xmlui.EPerson.StartRegistration.reset_password_for");
private static final Message T_submit_reset =
message("xmlui.EPerson.StartRegistration.submit_reset");
private static final Message T_head2 =
message("xmlui.EPerson.StartRegistration.head2");
private static final Message T_para2 =
message("xmlui.EPerson.StartRegistration.para2");
private static final Message T_email_address =
message("xmlui.EPerson.StartRegistration.email_address");
private static final Message T_email_address_help =
message("xmlui.EPerson.StartRegistration.email_address_help");
private static final Message T_error_bad_email =
message("xmlui.EPerson.StartRegistration.error_bad_email");
private static final Message T_submit_register =
message("xmlui.EPerson.StartRegistration.submit_register");
/** The email address previously entered */
private String email;
/** Determine if the user failed on their last attempt to enter an email address */
private java.util.List<String> errors;
/**
* Determine if the last failed attempt was because an account allready
* existed for the given email address
*/
private boolean accountExists;
public void setup(SourceResolver resolver, Map objectModel, String src,
Parameters parameters) throws ProcessingException, SAXException,
IOException
{
super.setup(resolver,objectModel,src,parameters);
this.email = parameters.getParameter("email","");
this.accountExists = parameters.getParameterAsBoolean("accountExists",false);
String errors = parameters.getParameter("errors","");
if (errors.length() > 0)
this.errors = Arrays.asList(errors.split(","));
else
this.errors = new ArrayList<String>();
}
/**
* Generate the unique caching key.
* This key must be unique inside the space of this component.
*/
public Serializable getKey()
{
// Only cache on the first attempt.
if (email == null && accountExists == false && errors != null && errors.size() == 0)
// cacheable
return "1";
else
// Uncachable
return "0";
}
/**
* Generate the cache validity object.
*/
public SourceValidity getValidity()
{
if (email == null && accountExists == false && errors != null && errors.size() == 0)
// Always valid
return NOPValidity.SHARED_INSTANCE;
else
// invalid
return null;
}
public void addPageMeta(PageMeta pageMeta) throws WingException
{
// Set the page title
pageMeta.addMetadata("title").addContent(T_title);
pageMeta.addTrailLink(contextPath + "/",T_dspace_home);
pageMeta.addTrail().addContent(T_trail_new_registration);
}
public void addBody(Body body) throws WingException {
if (accountExists) {
Division exists = body.addInteractiveDivision("register-account-exists",contextPath+"/register",Division.METHOD_POST,"primary");
exists.setHead(T_head1);
exists.addPara(T_para1);
List form = exists.addList("form");
form.addLabel(T_reset_password_for);
form.addItem(this.email);
form.addLabel();
Item submit = form.addItem();
submit.addButton("submit_forgot").setValue(T_submit_reset);
exists.addHidden("email").setValue(this.email);
exists.addHidden("eperson-continue").setValue(knot.getId());
}
Division register = body.addInteractiveDivision("register",
contextPath+"/register",Division.METHOD_POST,"primary");
register.setHead(T_head2);
EPersonUtils.registrationProgressList(register,1);
register.addPara(T_para2);
List form = register.addList("form",List.TYPE_FORM);
Text email = form.addItem().addText("email");
email.setRequired();
email.setLabel(T_email_address);
email.setHelp(T_email_address_help);
email.setValue(this.email);
if (errors.contains("email"))
email.addError(T_error_bad_email);
Item submit = form.addItem();
submit.addButton("submit").setValue(T_submit_register);
register.addHidden("eperson-continue").setValue(knot.getId());
}
/**
* Recycle
*/
public void recycle()
{
this.email = null;
this.errors = null;
super.recycle();
}
}

View File

@@ -0,0 +1,121 @@
/*
* UnAuthenticatedAction.java
*
* Version: $Revision: 1.1 $
*
* Date: $Date: 2006/04/06 15:15:59 $
*
* Copyright (c) 2002-2005, Hewlett-Packard Company and Massachusetts
* Institute of Technology. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* - 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.
*
* - Neither the name of the Hewlett-Packard Company nor the name of the
* Massachusetts Institute of Technology nor the names of their
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS 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 COPYRIGHT
* HOLDERS OR 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.
*/
package org.dspace.app.xmlui.aspect.eperson;
import java.util.HashMap;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.avalon.framework.parameters.Parameters;
import org.apache.cocoon.acting.AbstractAction;
import org.apache.cocoon.environment.Redirector;
import org.apache.cocoon.environment.SourceResolver;
import org.apache.cocoon.environment.http.HttpEnvironment;
import org.dspace.app.xmlui.utils.AuthenticationUtil;
import org.dspace.app.xmlui.utils.ContextUtil;
import org.dspace.core.ConfigurationManager;
import org.dspace.core.Context;
import org.dspace.eperson.EPerson;
/**
* Unauthenticate the current user. There is no way this action will fail,
* so any components inside the action will be exceuted.
*
* This aciton will always send an HTTP redirect to the DSpace homepage.
*
* Example:
*
* <map:action name="UnAuthenticateAction" src="org.dspace.app.xmlui.eperson.UnAuthenticateAction"/>
*
* <map:act type="UnAuthenticateAction">
* <map:serialize type="xml"/>
* </map:act>
*
* @author Scott Phillips
*/
public class UnAuthenticateAction extends AbstractAction
{
/**
* Logout the current user.
*
* @param pattern
* un-used.
* @param objectModel
* Cocoon's object model
*/
public Map act(Redirector redirector, SourceResolver resolver, Map objectModel,
String source, Parameters parameters) throws Exception
{
Context context = ContextUtil.obtainContext(objectModel);
final HttpServletRequest httpRequest =
(HttpServletRequest) objectModel.get(HttpEnvironment.HTTP_REQUEST_OBJECT);
final HttpServletResponse httpResponse =
(HttpServletResponse) objectModel.get(HttpEnvironment.HTTP_RESPONSE_OBJECT);
EPerson eperson = context.getCurrentUser();
// Actualy log the user out.
AuthenticationUtil.loggedOut(context,httpRequest);
// Set the user as logged in for the rest of this request so that the cache does not get spoiled.
context.setCurrentUser(eperson);
// Forward the user to the home page.
if((ConfigurationManager.getBooleanProperty("xmlui.public.logout")) && (httpRequest.isSecure())) {
StringBuffer location = new StringBuffer("http://");
location.append(ConfigurationManager.getProperty("dspace.hostname")).append(
httpRequest.getContextPath());
httpResponse.sendRedirect(location.toString());
}
else{
httpResponse.sendRedirect(httpRequest.getContextPath());
}
return new HashMap();
}
}

View File

@@ -0,0 +1,158 @@
/*
* VerifyEmail.java
*
* Version: $Revision: 1.3 $
*
* Date: $Date: 2006/06/02 21:37:46 $
*
* Copyright (c) 2002, Hewlett-Packard Company and Massachusetts
* Institute of Technology. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* - 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.
*
* - Neither the name of the Hewlett-Packard Company nor the name of the
* Massachusetts Institute of Technology nor the names of their
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS 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 COPYRIGHT
* HOLDERS OR 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.
*/
package org.dspace.app.xmlui.aspect.eperson;
import java.io.IOException;
import java.util.Map;
import org.apache.avalon.framework.parameters.ParameterException;
import org.apache.avalon.framework.parameters.Parameters;
import org.apache.cocoon.ProcessingException;
import org.apache.cocoon.environment.SourceResolver;
import org.dspace.app.xmlui.cocoon.AbstractDSpaceTransformer;
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.PageMeta;
import org.xml.sax.SAXException;
/**
* Display to the user that a verification email has been set.
*
* There are two parameters this transformer expects:
*
* email - The email of the to-be-verrified account.
*
* forgot - A boolean value indicating that this is part of the forgotten password workflow.
*
* @author Scott Phillips
*/
public class VerifyEmail extends AbstractDSpaceTransformer
{
/** language strings */
private final static Message T_title =
message("xmlui.EPerson.VerifyEmail.title");
private final static Message T_dspace_home =
message("xmlui.general.dspace_home");
private final static Message T_trail_forgot_password =
message("xmlui.EPerson.trail_forgot_password");
private final static Message T_trail_new_registration =
message("xmlui.EPerson.trail_new_registration");
private final static Message T_head =
message("xmlui.EPerson.VerifyEmail.head");
private final static Message T_para =
message("xmlui.EPerson.VerifyEmail.para");
/** The email address being verrified */
private String email;
/** Determine if this is part of the forgot password workflow */
private boolean forgot;
public void setup(SourceResolver resolver, Map objectModel, String src,
Parameters parameters) throws ProcessingException, SAXException,
IOException
{
super.setup(resolver,objectModel,src,parameters);
try
{
this.email = parameters.getParameter("email");
this.forgot = parameters.getParameterAsBoolean("forgot");
}
catch (ParameterException pe)
{
throw new ProcessingException(pe);
}
}
public void addPageMeta(PageMeta pageMeta) throws WingException
{
// Set the page title
pageMeta.addMetadata("title").addContent(T_title);
pageMeta.addTrailLink(contextPath + "/",T_dspace_home);
if (forgot)
{
pageMeta.addTrail().addContent(T_trail_forgot_password);
}
else
{
pageMeta.addTrail().addContent(T_trail_new_registration);
}
}
public void addBody(Body body) throws WingException
{
Division verify = body.addDivision("verify-email","primary");
verify.setHead(T_head);
if (forgot)
{
EPersonUtils.forgottProgressList(verify, 1);
}
else
{
EPersonUtils.registrationProgressList(verify,1);
}
verify.addPara(T_para.parameterize(email));
}
/**
* Recycle
*/
public void recycle()
{
this.email = null;
super.recycle();
}
}

View File

@@ -0,0 +1,133 @@
/*
* AuthenticatedSelector.java
*
* Version: $Revision: 1.1 $
*
* Date: $Date: 2006/04/06 15:15:46 $
*
* Copyright (c) 2002-2005, Hewlett-Packard Company and Massachusetts
* Institute of Technology. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* - 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.
*
* - Neither the name of the Hewlett-Packard Company nor the name of the
* Massachusetts Institute of Technology nor the names of their
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS 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 COPYRIGHT
* HOLDERS OR 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.
*/
package org.dspace.app.xmlui.aspect.general;
import java.util.Map;
import org.apache.avalon.framework.logger.AbstractLogEnabled;
import org.apache.avalon.framework.parameters.Parameters;
import org.apache.cocoon.selection.Selector;
import org.apache.log4j.Logger;
import org.dspace.app.xmlui.utils.ContextUtil;
import org.dspace.authorize.AuthorizeManager;
import org.dspace.core.Context;
import org.dspace.eperson.EPerson;
/**
* This simple selector operates on the authenticated DSpace user and selects
* between two levels of access.
*
* <map:selector name="AuthenticatedSelector" src="org.dspace.app.xmlui.AuthenticatedSelector"/>
*
*
*
* <map:select type="AuthenticatedSelector">
* <map:when test="administrator">
* ...
* </map:when>
* <map:when test="eperson">
* ...
* </map:when>
* <map:otherwise>
* ...
* </map:otherwise>
* </map:select>
*
* There are only two defined test expressions: "administrator" and "eperson".
* Remember an administrator is also an eperson so if you need to check for
* administrators distinct from epersons that select must come first.
*
* @author Scott Phillips
*/
public class AuthenticatedSelector extends AbstractLogEnabled implements
Selector
{
private static Logger log = Logger.getLogger(AuthenticatedSelector.class);
/** Test expressiots */
public static final String EPERSON = "eperson";
public static final String ADMINISTRATOR = "administrator";
/**
* Determine if the authenticated eperson matches the given expression.
*/
public boolean select(String expression, Map objectModel,
Parameters parameters)
{
try
{
Context context = ContextUtil.obtainContext(objectModel);
EPerson eperson = context.getCurrentUser();
if (eperson == null)
// No one is authenticated.
return false;
if (EPERSON.equals(expression))
{
// At least someone is authenticated.
return true;
}
else if (ADMINISTRATOR.equals(expression))
{
// Is this eperson an administrator?
return AuthorizeManager.isAdmin(context);
}
// Otherwise return false;
return false;
}
catch (Exception e)
{
// Log it and returned no match.
log.error("Error selecting based on authentication status: "
+ e.getMessage());
return false;
}
}
}

View File

@@ -0,0 +1,179 @@
/*
* DSpaceResourceManager.java
*
* Version: $Revision: 1.3 $
*
* Date: $Date: 2006/04/25 15:29:13 $
*
* Copyright (c) 2002, Hewlett-Packard Company and Massachusetts
* Institute of Technology. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* - 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.
*
* - Neither the name of the Hewlett-Packard Company nor the name of the
* Massachusetts Institute of Technology nor the names of their
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS 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 COPYRIGHT
* HOLDERS OR 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.
*/
package org.dspace.app.xmlui.aspect.general;
import java.io.IOException;
import java.io.Serializable;
import java.sql.SQLException;
import java.util.Map;
import org.apache.avalon.excalibur.pool.Recyclable;
import org.apache.avalon.framework.activity.Disposable;
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.transformation.AbstractTransformer;
import org.apache.excalibur.source.SourceValidity;
import org.apache.excalibur.source.impl.validity.NOPValidity;
import org.dspace.app.xmlui.utils.AuthenticationUtil;
import org.dspace.app.xmlui.utils.ContextUtil;
import org.dspace.core.Context;
import org.dspace.eperson.EPerson;
import org.xml.sax.SAXException;
/**
* The DSpace resource manager ensures that all DSpace resources used by the
* pipeline are properly closed. At the present time this just means the DSpace
* context, if one is available after the endDocument sax event has been sent
* then close the context.
*
* @author Scott Phillips
*/
public class DSpaceResourceManager extends AbstractTransformer implements CacheableProcessingComponent, Recyclable, Disposable
{
/** The Cocoon objectModel used by the ContextUtil class */
private Map objectModel = null;
/**
* Set up the manager.
*
* @param resolver
* The resolver (not used).
* @param objectModel
* The pipeline's mode (not used).
* @param src
* The source attribute (not used).
* @param parameters
* Parameters passed to us from the Cocoon pipeline (not used).
*/
public void setup(SourceResolver resolver, Map objectModel, String src,
Parameters parameters) throws ProcessingException, SAXException,
IOException
{
this.objectModel = objectModel;
// Check if a user is currently logged in. If no one is check to see if
// we can implicitly authenticate the request.
try
{
Context context = ContextUtil.obtainContext(objectModel);
EPerson eperson = context.getCurrentUser();
if (eperson == null)
{
// Attempt to implicitly authenticate this request.
AuthenticationUtil.AuthenticateImplicit(objectModel);
}
}
catch (SQLException sqle)
{
throw new ProcessingException(
"Unable attempt implicit authentication.", sqle);
}
}
/**
* Generate the unique key.
* This key must be unique inside the space of this component.
*
* @return The generated key hashes the src
*/
public Serializable getKey() {
return "1";
}
/**
* Generate the validity object.
*
* @return The generated validity object or <code>null</code> if the
* component is currently not cacheable.
*/
public SourceValidity getValidity() {
return NOPValidity.SHARED_INSTANCE;
}
// /**
// * Receive notification of the end of a document. If any DSpace resources
// * are being used make sure they are closed.
// */
// public void endDocument() throws SAXException
// {
// super.endDocument();
// try
// {
// ContextUtil.closeContext(objectModel);
// }
// catch (SQLException sqle)
// {
// throw new SAXException(sqle);
// }
// }
public void recycle() {
try
{
ContextUtil.closeContext(objectModel);
}
catch (SQLException sqle)
{
getLogger().error("Error encountered while attempting to recycle the DSpaceResourceManager: "+sqle.getMessage());
}
}
public void dispose() {
try
{
ContextUtil.closeContext(objectModel);
}
catch (SQLException sqle)
{
getLogger().error("Error encountered while attempting to dispose the DSpaceResourceManager: "+sqle.getMessage());
}
}
}

Some files were not shown because too many files have changed in this diff Show More