Index: src/edu/ucsb/nceas/metacat/ArchiveHandler.java
===================================================================
--- src/edu/ucsb/nceas/metacat/ArchiveHandler.java	(nonexistent)
+++ src/edu/ucsb/nceas/metacat/ArchiveHandler.java	(revision 4950)
@@ -0,0 +1,169 @@
+/**
+ *  '$RCSfile$'
+ *    Purpose: A Class that implements session utility methods 
+ *  Copyright: 2008 Regents of the University of California and the
+ *             National Center for Ecological Analysis and Synthesis
+ *    Authors: Michael Daigle
+ * 
+ *   '$Author: daigle $'
+ *     '$Date: 2009-03-25 13:41:15 -0800 (Wed, 25 Mar 2009) $'
+ * '$Revision: 4861 $'
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+package edu.ucsb.nceas.metacat;
+
+import java.sql.SQLException;
+import java.util.Hashtable;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.log4j.Logger;
+
+import edu.ucsb.nceas.metacat.service.PropertyService;
+import edu.ucsb.nceas.metacat.util.ErrorSendingErrorException;
+import edu.ucsb.nceas.metacat.util.ErrorUtil;
+import edu.ucsb.nceas.metacat.util.MetacatUtilException;
+import edu.ucsb.nceas.metacat.util.ResponseUtil;
+import edu.ucsb.nceas.utilities.FileUtil;
+import edu.ucsb.nceas.utilities.PropertyNotFoundException;
+import edu.ucsb.nceas.utilities.UtilException;
+
+public class ArchiveHandler  {
+	
+	private static ArchiveHandler archiveHandler = null;
+	
+	private static Logger logMetacat = Logger.getLogger(ArchiveHandler.class);
+
+	/**
+	 * private constructor since this is a singleton
+	 */
+	private ArchiveHandler() throws HandlerException {}
+	
+	/**
+	 * Get the single instance of SessionService.
+	 * 
+	 * @return the single instance of SessionService
+	 */
+	public static ArchiveHandler getInstance() throws HandlerException {
+		if (archiveHandler == null) {
+			archiveHandler = new ArchiveHandler();
+		}
+		return archiveHandler;
+	}
+	
+	public void readArchiveEntry(Hashtable<String, String[]> params, HttpServletRequest request,
+            HttpServletResponse response, String user, 
+            String passWord, String[] groups) throws HandlerException, ErrorSendingErrorException, ErrorHandledException {
+        	
+		String[] docs = new String[0];
+        String docid = "";
+        String qformat = "";
+        String[] archiveEntryNames = new String[0];
+        String archiveEntryName = "";
+        
+        try {          
+            // read the docid from params
+            if (params.containsKey("docid")) {
+                docs = params.get("docid");
+                docid = docs[0];
+            } else { 
+            	throw new HandlerException("Could not find doc id in params when reading archive entry");
+            } 
+            
+            // read the archive file entry name from params
+            if (params.containsKey("archiveEntryName")) {
+            	archiveEntryNames = params.get("archiveEntryName");
+            	archiveEntryName = archiveEntryNames[0];
+            } else { 
+            	throw new HandlerException("Could not find archiveEntryName in params when reading archive entry");
+            } 
+            
+            // qformat is used to hold the type of archive and the format of the content that we wish to 
+            // extract from the archive.  The default is jar-file for streaming a file from a jar.  If 
+            // we wanted to do some special processing for specific archive or content types, we would use 
+            // a different qformat (gzip-pdf for instance).
+            if (params.containsKey("qformat")) {
+                qformat = params.get("qformat")[0];
+            } else { 
+            	qformat = "jar-file";
+            }       
+            
+            //check the permission for read
+            try {
+            	if (!DocumentImpl.hasReadPermission(user, groups, docid)) {
+            		String errorString = "User " + user + " does not have permission"
+    					+ " to read the document with the docid " + docid;
+            		ErrorUtil.sendError(response, ErrorUtil.NO_READ_PERMISSION, errorString);
+            		return;
+            	}
+            } catch (McdbException mcdbe) {
+            	throw new HandlerException("Error getting permissions for docid: " 
+            			+ docid + " for user: " + user + " : " + mcdbe.getMessage());
+            } catch (SQLException sqle) {
+            	throw new HandlerException("SQL error getting permissions for docid: " 
+            			+ docid + " for user: " + user + " : " + sqle.getMessage());
+            } 
+            
+            // Get the path to the archive file
+            String archiveFileBasePath = PropertyService.getProperty("application.datafilepath");
+            String archiveFilePath = archiveFileBasePath + FileUtil.getFS() + docid;
+            
+            // Get the paths to the expanded archive directory and to the content file within
+            // that directory
+            String expandedArchiveBasePath = PropertyService.getProperty("application.expandedArchivePath");
+            String expandedArchivePath = expandedArchiveBasePath + FileUtil.getFS() + docid;
+            String entryFilePath = expandedArchivePath + FileUtil.getFS() + archiveEntryName;
+            
+            // If the expanded archive directory does not exist, create it.
+            if (!FileUtil.isDirectory(expandedArchivePath)) {
+            	FileUtil.createDirectory(expandedArchivePath);
+            }
+            
+            // If the entry we want does not exist, make sure it is actually in the archive
+            // file.  If so, go ahead and expand the archive into the expanded archive directory.
+            if (FileUtil.getFileStatus(entryFilePath) == FileUtil.DOES_NOT_EXIST) {
+            	if (FileUtil.getFileStatus(archiveFilePath) < FileUtil.EXISTS_READABLE) {
+            		throw new HandlerException("Could not find archive: " + archiveFilePath 
+            				+ " in order to get content file: " + archiveEntryName);
+            	}
+            	
+            	// extract the jar file to the expanded archive directory
+            	FileUtil.extractJarFile(archiveFilePath, expandedArchivePath);
+            }
+            
+            ResponseUtil.writeFileToOutput(response, expandedArchivePath, archiveEntryName);            
+                        
+        } catch (UtilException ue) {
+        	String errorString = "Utility error reading archive entry for docid: " 
+    			+ docid + " : " + ue.getMessage();
+        	ErrorUtil.sendError(response, ErrorUtil.GENERAL_UTILITY_ERROR, errorString);
+        	throw new ErrorHandledException(null);
+        } catch (PropertyNotFoundException pnfe) {
+        	String errorString = "Property error reading archive entry for docid: " 
+        		+ docid + " : " + pnfe.getMessage();
+        	ErrorUtil.sendError(response, ErrorUtil.PROPERTY_NOT_FOUND, errorString);
+        	throw new ErrorHandledException(null);
+        } catch (MetacatUtilException mue) {
+        	String errorString = "Metacat utility error reading archive entry for docid: " 
+        		+ docid + " : " + mue.getMessage();
+        	ErrorUtil.sendError(response, ErrorUtil.METACAT_UTILITY_ERROR, errorString);
+        	throw new ErrorHandledException(null);
+        } 
+	}
+
+}

Property changes on: src/edu/ucsb/nceas/metacat/ArchiveHandler.java
___________________________________________________________________
Added: svn:executable
## -0,0 +1 ##
+*
\ No newline at end of property
Index: src/edu/ucsb/nceas/metacat/MetaCatServlet.java
===================================================================
--- src/edu/ucsb/nceas/metacat/MetaCatServlet.java	(revision 4949)
+++ src/edu/ucsb/nceas/metacat/MetaCatServlet.java	(revision 4950)
@@ -47,7 +47,6 @@
 import java.util.HashMap;
 import java.util.Hashtable;
 import java.util.Iterator;
-import java.util.List;
 import java.util.Map;
 import java.util.Timer;
 import java.util.Vector;
@@ -76,6 +75,7 @@
 
 import edu.ucsb.nceas.metacat.cart.CartManager;
 import edu.ucsb.nceas.metacat.dataquery.DataQuery;
+import edu.ucsb.nceas.metacat.scheduler.SchedulerService;
 import edu.ucsb.nceas.metacat.service.DatabaseService;
 import edu.ucsb.nceas.metacat.service.PropertyService;
 import edu.ucsb.nceas.metacat.service.ServiceException;
@@ -86,11 +86,12 @@
 import edu.ucsb.nceas.metacat.spatial.SpatialHarvester;
 import edu.ucsb.nceas.metacat.spatial.SpatialQuery;
 import edu.ucsb.nceas.metacat.util.AuthUtil;
+import edu.ucsb.nceas.metacat.util.ErrorSendingErrorException;
 import edu.ucsb.nceas.metacat.util.MetacatUtil;
+import edu.ucsb.nceas.metacat.util.MetacatUtilException;
 import edu.ucsb.nceas.metacat.util.RequestUtil;
 import edu.ucsb.nceas.metacat.util.SystemUtil;
 import edu.ucsb.nceas.metacat.util.SessionData;
-import edu.ucsb.nceas.metacat.util.MetacatUtilException;
 import edu.ucsb.nceas.utilities.FileUtil;
 import edu.ucsb.nceas.utilities.GeneralPropertyException;
 import edu.ucsb.nceas.utilities.PropertyNotFoundException;
@@ -233,6 +234,7 @@
 			logMetacat.debug("DBConnection pool initialized: " + connPool.toString());
 			
 			ServiceService.registerService("XMLSchemaService", XMLSchemaService.getInstance());
+			ServiceService.registerService("SchedulerService", SchedulerService.getInstance());
 
 			// check if eml201 document were corrected or not. if not, correct
 			// eml201 documents.
@@ -715,8 +717,13 @@
 
 					handleExportAction(params, response, userName, groupNames, password);
 				} else if (action.equals("read")) {
-					handleReadAction(params, request, response, userName, password,
-							groupNames);
+					if (params.get("archiveEntryName") != null) {
+						ArchiveHandler.getInstance().readArchiveEntry(params, request, response, 
+								userName, password,groupNames);
+					} else {
+						handleReadAction(params, request, response, userName, password,
+								groupNames);
+					}
 				} else if (action.equals("readinlinedata")) {
 					handleReadInlineDataAction(params, request, response, userName,
 							password, groupNames);
@@ -858,7 +865,11 @@
 					// MetacatAdminServlet
 					ServiceService.refreshService("XMLSchemaService");
 					return;
-				}else {
+				} else if (action.equals("schedule")) {
+					SchedulerService.getInstance().scheduleHandler(params, request, response, 
+							userName, groupNames);
+					return;
+				} else {
 					PrintWriter out = response.getWriter();
 					out.println("<?xml version=\"1.0\"?>");
 					out.println("<error>");
@@ -887,6 +898,17 @@
 			String errorString = "Service error: " + ue.getMessage();
 			logMetacat.error(errorString);
 			throw new ServletException(errorString);
+		} catch (HandlerException he) {
+			String errorString = "Handler error: " + he.getMessage();
+			logMetacat.error(errorString);
+			throw new ServletException(errorString);
+		} catch (ErrorSendingErrorException esee) {
+			String errorString = "Error sending error message: " + esee.getMessage();
+			logMetacat.error(errorString);
+			throw new ServletException(errorString);
+		} catch (ErrorHandledException ehe) {
+			// Nothing to do here.  We assume if we get here, the error has been 
+			// written to ouput.  Continue on and let it display.
 		}
 	}
     
Index: src/edu/ucsb/nceas/metacat/PermissionController.java
===================================================================
--- src/edu/ucsb/nceas/metacat/PermissionController.java	(revision 4949)
+++ src/edu/ucsb/nceas/metacat/PermissionController.java	(revision 4950)
@@ -96,7 +96,7 @@
     * @param myPermission  permission type to check for
     */
   public boolean hasPermission(String user, String[]groups, String myPermission)
-                              throws SQLException, Exception
+                              throws SQLException //, Exception
   {
     boolean hasPermission=false;
     String [] userPackage=null;
Index: src/edu/ucsb/nceas/metacat/HandlerException.java
===================================================================
--- src/edu/ucsb/nceas/metacat/HandlerException.java	(nonexistent)
+++ src/edu/ucsb/nceas/metacat/HandlerException.java	(revision 4950)
@@ -0,0 +1,46 @@
+/**
+ *  '$RCSfile$'
+ *    Purpose: An Exception thrown when an error occurs because an 
+ *             AccessionNumber was invalid or used incorrectly
+ *  Copyright: 2008 Regents of the University of California and the
+ *             National Center for Ecological Analysis and Synthesis
+ *    Authors: Michael Daigle
+ *
+ *   '$Author: daigle $'
+ *     '$Date: 2008-07-06 21:25:34 -0700 (Sun, 06 Jul 2008) $'
+ * '$Revision: 4080 $'
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+package edu.ucsb.nceas.metacat;
+
+/**
+ * Exception thrown when an error occurs in a configuration administrative
+ * class
+ */
+public class HandlerException extends Exception {
+
+	private static final long serialVersionUID = 7997030775672963304L;
+
+	/**
+	 * Create a new AdminException.
+	 *
+	 * @param message The error or warning message.
+	 */
+	public HandlerException(String message) {
+		super(message);
+	}
+}

Property changes on: src/edu/ucsb/nceas/metacat/HandlerException.java
___________________________________________________________________
Added: svn:executable
## -0,0 +1 ##
+*
\ No newline at end of property
Index: src/edu/ucsb/nceas/metacat/DocumentImpl.java
===================================================================
--- src/edu/ucsb/nceas/metacat/DocumentImpl.java	(revision 4949)
+++ src/edu/ucsb/nceas/metacat/DocumentImpl.java	(revision 4950)
@@ -3310,7 +3310,7 @@
      * @param groups, user's group
      */
     public static boolean hasReadPermission(String user, String[] groups,
-            String docId) throws SQLException, Exception
+            String docId) throws SQLException, McdbException
     {
         // Check for READ permission on @docid for @user and/or @groups
         PermissionController controller = new PermissionController(docId);
Index: src/edu/ucsb/nceas/metacat/service/PropertyService.java
===================================================================
--- src/edu/ucsb/nceas/metacat/service/PropertyService.java	(revision 4949)
+++ src/edu/ucsb/nceas/metacat/service/PropertyService.java	(revision 4950)
@@ -45,7 +45,6 @@
 import edu.ucsb.nceas.utilities.PropertiesMetaData;
 import edu.ucsb.nceas.utilities.PropertyNotFoundException;
 import edu.ucsb.nceas.utilities.SortedProperties;
-import edu.ucsb.nceas.utilities.UtilException;
 
 /**
  * A suite of utility classes for the metadata configuration utility
@@ -223,7 +222,7 @@
 		} catch (GeneralPropertyException gpe) {
 			throw new ServiceException("General properties problem while loading properties: "
 					+ gpe.getMessage());
-		} catch (UtilException ue) {
+		} catch (MetacatUtilException ue) {
 			throw new ServiceException("Utilities problem while loading properties: "
 					+ ue.getMessage());
 		} 
Index: src/edu/ucsb/nceas/metacat/service/BaseService.java
===================================================================
--- src/edu/ucsb/nceas/metacat/service/BaseService.java	(revision 4949)
+++ src/edu/ucsb/nceas/metacat/service/BaseService.java	(revision 4950)
@@ -37,7 +37,7 @@
 
 	// package level method reporting if service is refreshable.  Basically,
 	// we only want ServiceService calling this.
-	abstract boolean refreshable();
+	public abstract boolean refreshable();
 	
 	// subclass must define doRefresh.  It is only called from the refresh() method.
 	protected abstract void doRefresh() throws ServiceException;
Index: src/edu/ucsb/nceas/metacat/admin/PropertiesAdmin.java
===================================================================
--- src/edu/ucsb/nceas/metacat/admin/PropertiesAdmin.java	(revision 4949)
+++ src/edu/ucsb/nceas/metacat/admin/PropertiesAdmin.java	(revision 4950)
@@ -47,6 +47,7 @@
 import edu.ucsb.nceas.utilities.GeneralPropertyException;
 import edu.ucsb.nceas.utilities.PropertiesMetaData;
 import edu.ucsb.nceas.utilities.SortedProperties;
+import edu.ucsb.nceas.utilities.UtilException;
 
 /**
  * Control the display of the main properties configuration page and the 
@@ -203,9 +204,9 @@
 				String dataDir = PropertyService.getProperty("application.datafilepath");
 				try {
 					FileUtil.createDirectory(dataDir);
-				} catch (IOException ioe) {
+				} catch (UtilException ue) {
 					String errorString = "Could not create directory: " + dataDir +
-						" : " + ioe.getMessage();
+					" : " + ue.getMessage();
 					logMetacat.error(errorString);
 					validationErrors.add(errorString);
 				}
@@ -214,9 +215,9 @@
 				String inlineDataDir = PropertyService.getProperty("application.inlinedatafilepath");
 				try {
 					FileUtil.createDirectory(inlineDataDir);
-				} catch (IOException ioe) {
+				} catch (UtilException ue) {
 					String errorString = "Could not create directory: " + inlineDataDir +
-						" : " + ioe.getMessage();
+						" : " + ue.getMessage();
 					logMetacat.error(errorString);
 					validationErrors.add(errorString);
 				}
@@ -225,9 +226,9 @@
 				String documentfilepath = PropertyService.getProperty("application.documentfilepath");
 				try {
 					FileUtil.createDirectory(documentfilepath);
-				} catch (IOException ioe) {	
+				} catch (UtilException ue) {	
 					String errorString = "Could not create directory: " + documentfilepath +
-						" : " + ioe.getMessage();
+						" : " + ue.getMessage();
 					logMetacat.error(errorString);
 					validationErrors.add(errorString);
 				}
@@ -236,9 +237,9 @@
 				String tempDir = PropertyService.getProperty("application.tempDir");
 				try {
 					FileUtil.createDirectory(tempDir);
-				} catch (IOException ioe) {		
+				} catch (UtilException ue) {		
 					String errorString = "Could not create directory: " + tempDir +
-						" : " + ioe.getMessage();
+						" : " + ue.getMessage();
 					logMetacat.error(errorString);
 					validationErrors.add(errorString);
 				}
@@ -247,9 +248,9 @@
 				String replLogDir = PropertyService.getProperty("replication.logdir");
 				try {
 					FileUtil.createDirectory(replLogDir);
-				} catch (IOException ioe) {		
+				} catch (UtilException ue) {		
 					String errorString = "Could not create directory: " + replLogDir +
-						" : " + ioe.getMessage();
+						" : " + ue.getMessage();
 					logMetacat.error(errorString);
 					validationErrors.add(errorString);
 				}
Index: src/edu/ucsb/nceas/metacat/admin/BackupAdmin.java
===================================================================
--- src/edu/ucsb/nceas/metacat/admin/BackupAdmin.java	(revision 4949)
+++ src/edu/ucsb/nceas/metacat/admin/BackupAdmin.java	(revision 4950)
@@ -38,6 +38,7 @@
 import edu.ucsb.nceas.metacat.service.PropertyService;
 import edu.ucsb.nceas.metacat.service.ServiceException;
 import edu.ucsb.nceas.metacat.service.ServiceService;
+import edu.ucsb.nceas.metacat.util.MetacatUtilException;
 import edu.ucsb.nceas.metacat.util.RequestUtil;
 import edu.ucsb.nceas.metacat.util.SystemUtil;
 import edu.ucsb.nceas.utilities.FileUtil;
@@ -119,9 +120,9 @@
 			} catch (ServletException se) {
 				throw new AdminException("Problem forwarding request while "
 						+ "initializing backup configuration page: " + se.getMessage());
-			} catch (UtilException ue) {
+			} catch (MetacatUtilException mue) {
 				throw new AdminException("Problem discovering backup directory while "
-						+ "initializing backup configuration page: " + ue.getMessage());
+						+ "initializing backup configuration page: " + mue.getMessage());
 			}
 		} else {
 			// The configuration form is being submitted and needs to be
@@ -151,7 +152,7 @@
 					
 					ServiceService.refreshService("SkinPropertyService");
 					SystemUtil.storeExternalDirLocation(backupDir);
-				} catch (IOException ue) {
+				} catch (UtilException ue) {
 					String errorMessage = "Could not create directory: " + hiddenBackupDir
 							+ " : " + ue.getMessage() + ". Please try again";
 					processingErrors.add(errorMessage);
Index: src/edu/ucsb/nceas/metacat/ErrorHandledException.java
===================================================================
--- src/edu/ucsb/nceas/metacat/ErrorHandledException.java	(nonexistent)
+++ src/edu/ucsb/nceas/metacat/ErrorHandledException.java	(revision 4950)
@@ -0,0 +1,46 @@
+/**
+ *  '$RCSfile$'
+ *    Purpose: An Exception thrown when an error occurs because an 
+ *             AccessionNumber was invalid or used incorrectly
+ *  Copyright: 2009 Regents of the University of California and the
+ *             National Center for Ecological Analysis and Synthesis
+ *    Authors: Michael Daigle
+ *
+ *   '$Author: daigle $'
+ *     '$Date: 2008-07-06 21:25:34 -0700 (Sun, 06 Jul 2008) $'
+ * '$Revision: 4080 $'
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+package edu.ucsb.nceas.metacat;
+
+/**
+ * Exception thrown when an error occurs in a configuration administrative
+ * class
+ */
+public class ErrorHandledException extends Exception {
+
+	private static final long serialVersionUID = 6155049982476516738L;
+
+	/**
+	 * Create a new AdminException.
+	 *
+	 * @param message The error or warning message.
+	 */
+	public ErrorHandledException(String message) {
+		super(message);
+	}
+}

Property changes on: src/edu/ucsb/nceas/metacat/ErrorHandledException.java
___________________________________________________________________
Added: svn:executable
## -0,0 +1 ##
+*
\ No newline at end of property
