Index: lams_common/src/java/org/lamsfoundation/lams/contentrepository/ITicket.java =================================================================== diff -u --- lams_common/src/java/org/lamsfoundation/lams/contentrepository/ITicket.java (revision 0) +++ lams_common/src/java/org/lamsfoundation/lams/contentrepository/ITicket.java (revision 46fe95e04d6fbe8fec9e41f054a711e23c1e064c) @@ -0,0 +1,52 @@ +/**************************************************************** + * Copyright (C) 2005 LAMS Foundation (http://lamsfoundation.org) + * ============================================================= + * License Information: http://lamsfoundation.org/licensing/lams/2.0/ + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2.0 + * as published by the Free Software Foundation. + * + * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 + * USA + * + * http://www.gnu.org/licenses/gpl.txt + * **************************************************************** + */ + + +package org.lamsfoundation.lams.contentrepository; + +/** + * Ticket represents the "authorisation" key to the repository. When + * the tool logs in, a ticket is given. This ticket must be supplied + * whenever a node is accessed. When the tool is finished, it should call + * logout, which invalidates the ticket. + * + * A ticket is for one workspace only - to access more than one + * workspace requires more than one ticket. + * + * @author Fiona Malikoff + */ +public interface ITicket { + /** + * Get the workspace associated with this ticket + * Should only be accessed by the content repository package members. + */ + abstract Long getWorkspaceId(); + + /** + * @return Returns the ticketId. + */ + abstract String getTicketId(); + + /** Make this ticket unusable. Called by the repository on logout */ + abstract void clear(); +} \ No newline at end of file Index: lams_common/src/java/org/lamsfoundation/lams/contentrepository/NodeKey.java =================================================================== diff -u --- lams_common/src/java/org/lamsfoundation/lams/contentrepository/NodeKey.java (revision 0) +++ lams_common/src/java/org/lamsfoundation/lams/contentrepository/NodeKey.java (revision 46fe95e04d6fbe8fec9e41f054a711e23c1e064c) @@ -0,0 +1,85 @@ +/**************************************************************** + * Copyright (C) 2005 LAMS Foundation (http://lamsfoundation.org) + * ============================================================= + * License Information: http://lamsfoundation.org/licensing/lams/2.0/ + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2.0 + * as published by the Free Software Foundation. + * + * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 + * USA + * + * http://www.gnu.org/licenses/gpl.txt + * **************************************************************** + */ + + +package org.lamsfoundation.lams.contentrepository; + +import org.apache.commons.lang.builder.EqualsBuilder; +import org.apache.commons.lang.builder.HashCodeBuilder; +import org.apache.commons.lang.builder.ToStringBuilder; + +/** + * Represents the two part key - UUID and version. + * Version may be null; + * + * @author Fiona Malikoff + */ +public class NodeKey { + + private Long uuid = null; + private Long version = null; + + /** + * + */ + public NodeKey(Long uuid, Long version) { + this.uuid = uuid; + this.version = version; + } + + /** + * @return Returns the uuid. + */ + public Long getUuid() { + return uuid; + } + + /** + * @return Returns the version. + */ + public Long getVersion() { + return version; + } + + @Override + public String toString() { + return new ToStringBuilder(this).append("uuid", uuid).append("version", version).toString(); + } + + @Override + public boolean equals(Object other) { + if ((this == other)) { + return true; + } + if (!(other instanceof NodeKey)) { + return false; + } + NodeKey castOther = (NodeKey) other; + return new EqualsBuilder().append(uuid, castOther.getUuid()).append(version, castOther.getVersion()).isEquals(); + } + + @Override + public int hashCode() { + return new HashCodeBuilder().append(uuid).append(version).toHashCode(); + } +} Index: lams_common/src/java/org/lamsfoundation/lams/contentrepository/client/IToolContentHandler.java =================================================================== diff -u --- lams_common/src/java/org/lamsfoundation/lams/contentrepository/client/IToolContentHandler.java (revision 0) +++ lams_common/src/java/org/lamsfoundation/lams/contentrepository/client/IToolContentHandler.java (revision 46fe95e04d6fbe8fec9e41f054a711e23c1e064c) @@ -0,0 +1,199 @@ +/**************************************************************** + * Copyright (C) 2005 LAMS Foundation (http://lamsfoundation.org) + * ============================================================= + * License Information: http://lamsfoundation.org/licensing/lams/2.0/ + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2.0 + * as published by the Free Software Foundation. + * + * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 + * USA + * + * http://www.gnu.org/licenses/gpl.txt + * **************************************************************** + */ + + +package org.lamsfoundation.lams.contentrepository.client; + +import java.io.IOException; +import java.io.InputStream; +import java.util.Set; + +import org.lamsfoundation.lams.contentrepository.ITicket; +import org.lamsfoundation.lams.contentrepository.NodeKey; +import org.lamsfoundation.lams.contentrepository.exception.FileException; +import org.lamsfoundation.lams.contentrepository.exception.InvalidParameterException; +import org.lamsfoundation.lams.contentrepository.exception.ItemNotFoundException; +import org.lamsfoundation.lams.contentrepository.exception.RepositoryCheckedException; +import org.lamsfoundation.lams.contentrepository.service.IRepositoryService; + +/** + * IToolContentHandler defines the ContentHandler interface used by the tools. + * This interface exists so that the ToolDownload servlet can get to the + * Repository via ToolContentHandler. It needs to call the tool's + * concrete class, which must be defined in the servlet's init parameters. + * + * @see org.lamsfoundation.lams.contentrepository.client.ToolContentHandler + * @see org.lamsfoundation.lams.contentrepository.client.Download + * @author Fiona Malikoff + */ +public interface IToolContentHandler { + + /** + * @return Returns the repositoryWorkspaceName. + */ + public abstract String getRepositoryWorkspaceName(); + + /** + * @return Returns the repositoryUser. + */ + public abstract String getRepositoryUser(); + + /** + * @return Returns the repository identification string. This is the + * "password" field the credential. + */ + public abstract char[] getRepositoryId(); + + /** + * Get the ticket to access the repository. If the workspace/credential + * hasn't been set up, then it will be set up automatically. + * + * @param forceLogin + * set to true if tried to do something and got access denied. This may happen + * if the repository loses the ticket. + * @return the repository ticket + */ + public abstract ITicket getTicket(boolean forceLogin) throws RepositoryCheckedException; + + /** + * Save a file in the content repository. + * + * @param stream + * Input filestream. Mandatory. + * @param fileName + * Input filename. Mandatory. + * @param mimeType + * Mimetype of file. Optional. + * @return key to the new content repository node + * @throws InvalidParameterException + * One of the mandatory parameters is missing. + * @throws FileException + * An error occured writing the input stream to disk. + * @throws RepositoryCheckedException + * Some other error occured. + */ + public abstract NodeKey uploadFile(InputStream stream, String fileName, String mimeType) + throws RepositoryCheckedException, InvalidParameterException, RepositoryCheckedException; + + /** + * Update an existing file in the repository. This will create a new version of this file (its version number will + * be equal to the current one incremented by 1). + * + * @param uuid + * unique id of the updated file. Mandatory + * + * @param stream + * Input filestream. Mandatory. + * @param fileName + * Input filename. Mandatory. + * @param mimeType + * Mimetype of file. Optional. + * @return key to the new content repository node + * @throws InvalidParameterException + * One of the mandatory parameters is missing. + * @throws FileException + * An error occured writing the input stream to disk. + * @throws RepositoryCheckedException + * Some other error occured. + */ + public abstract NodeKey updateFile(Long uuid, InputStream stream, String fileName, String mimeType) + throws RepositoryCheckedException, InvalidParameterException, RepositoryCheckedException; + + /** + * Save a directory of files in the content repository. + * + * @param ticket + * ticket issued on login. Identifies tool and workspace - mandatory + * @param dirPath + * directory path containing files - mandatory + * @param startFile + * relative path of initial file - optional + * @return nodeKey (uuid and version) + * @throws InvalidParameterException + * One of the mandatory parameters is missing. + * @throws FileException + * An error occured writing the files to disk. + * @throws RepositoryCheckedException + * Some other error occured. + */ + public abstract NodeKey uploadPackage(String dirPath, String startFile) + throws RepositoryCheckedException, InvalidParameterException, RepositoryCheckedException; + + /** + * Delete a file node. If the node does not exist, then nothing happens (ie ItemNotFoundException is NOT thrown). + * + * @param uuid + * id of the file node. Mandatory + * @throws InvalidParameterException + * One of the mandatory parameters is missing. + * @throws RepositoryCheckedException + * Some other error occured. + */ + public abstract void deleteFile(Long uuid) throws InvalidParameterException, RepositoryCheckedException; + + /** + * Copy an entry in the content repository. + * + * @param uuid + * id of the file node. Mandatory + * @throws ItemNotFoundException + * Node to copy cannot be found + * @throws RepositoryCheckedException + * Some other error occured. + */ + public abstract NodeKey copyFile(Long uuid) throws ItemNotFoundException, RepositoryCheckedException; + + /** + * Get the file, as an inputstream. + * + * @param uuid + * id of the file node. Mandatory + * @throws FileException + * An error occured writing the input stream to disk. + * @throws ItemNotFoundException + * This file node does not exist, so cannot delete it. + * @throws RepositoryCheckedException + * Some other error occured. + */ + public abstract InputStream getFileInputStream(Long uuid) + throws ItemNotFoundException, FileException, RepositoryCheckedException; + + public abstract IRepositoryService getRepositoryService(); + + /** + * Save content in repository into local file by given toFileName. + * + *

+ * If the toFileName is null, file name use original file name instead + * and file save path will be system temporary directory. + * + * @param uuid + * @param toFileName + * file name to save. Using the original file name instead if null value given. + * @throws ItemNotFoundException + * @throws RepositoryCheckedException + * @throws IOException + */ + public void saveFile(Long uuid, String toFileName) + throws ItemNotFoundException, RepositoryCheckedException, IOException; +} \ No newline at end of file Index: lams_common/src/java/org/lamsfoundation/lams/contentrepository/client/ToolContentHandler.java =================================================================== diff -u --- lams_common/src/java/org/lamsfoundation/lams/contentrepository/client/ToolContentHandler.java (revision 0) +++ lams_common/src/java/org/lamsfoundation/lams/contentrepository/client/ToolContentHandler.java (revision 46fe95e04d6fbe8fec9e41f054a711e23c1e064c) @@ -0,0 +1,396 @@ +/**************************************************************** + * Copyright (C) 2005 LAMS Foundation (http://lamsfoundation.org) + * ============================================================= + * License Information: http://lamsfoundation.org/licensing/lams/2.0/ + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2.0 + * as published by the Free Software Foundation. + * + * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 + * USA + * + * http://www.gnu.org/licenses/gpl.txt + * **************************************************************** + */ + + +package org.lamsfoundation.lams.contentrepository.client; + +import java.io.IOException; +import java.io.InputStream; + +import org.apache.log4j.Logger; +import org.lamsfoundation.lams.contentrepository.ICredentials; +import org.lamsfoundation.lams.contentrepository.ITicket; +import org.lamsfoundation.lams.contentrepository.NodeKey; +import org.lamsfoundation.lams.contentrepository.exception.AccessDeniedException; +import org.lamsfoundation.lams.contentrepository.exception.FileException; +import org.lamsfoundation.lams.contentrepository.exception.InvalidParameterException; +import org.lamsfoundation.lams.contentrepository.exception.ItemNotFoundException; +import org.lamsfoundation.lams.contentrepository.exception.RepositoryCheckedException; +import org.lamsfoundation.lams.contentrepository.service.IRepositoryService; +import org.lamsfoundation.lams.contentrepository.service.SimpleCredentials; + +/** + * Handles the connection to the content repository, and allows a file + * to be stored and retrieved. + *

+ * It can be used by LAMS tools to do the handling the files. + *

+ * It is a very simple client, in that + * it only handles files (and not packages) and will not keep versions + * of files - to do a new version of a file, the old version is deleted + * and the new version added. + *

+ * To use this class: + *

+ * For example: + * + *
+ * 	<bean id="blahToolContentHandler" class="your class name here">
+ * 		<property name="repositoryService"> <ref bean="repositoryService"/</property>
+ *	</bean>
+ * 
+ * + * + * You do not need to include repositoryService as a instance variable + * in your own class as it is already defined in the ToolContentHandler abstract class. + *

+ * The methods you are likely to use are: + *