Index: lams_build/lib/lams/lams-contentrepository.jar =================================================================== diff -u -rc491b34e739baf80e27148e858236bc77a174b69 -re16f09694ef763b1acafa32958762c90332b8228 Binary files differ Index: lams_build/master-build.xml =================================================================== diff -u -r1e26978d5215108967e6c7a6550d3b471ed2f98d -re16f09694ef763b1acafa32958762c90332b8228 --- lams_build/master-build.xml (.../master-build.xml) (revision 1e26978d5215108967e6c7a6550d3b471ed2f98d) +++ lams_build/master-build.xml (.../master-build.xml) (revision e16f09694ef763b1acafa32958762c90332b8228) @@ -173,6 +173,10 @@ + + + Index: lams_build/shared.properties =================================================================== diff -u -r1e26978d5215108967e6c7a6550d3b471ed2f98d -re16f09694ef763b1acafa32958762c90332b8228 --- lams_build/shared.properties (.../shared.properties) (revision 1e26978d5215108967e6c7a6550d3b471ed2f98d) +++ lams_build/shared.properties (.../shared.properties) (revision e16f09694ef763b1acafa32958762c90332b8228) @@ -50,6 +50,6 @@ lams-contentrepository.jar=${lams_contentrepository}/${sub.build}/lams-contentrepository.jar # Known tools +tool_forum_dir=lams_tool_forum tool_imscp_dir=lams_tool_imscp tool_laqa_dir=lams_tool_laqa - Index: lams_contentrepository/src/java/org/lamsfoundation/lams/contentrepository/client/Download.java =================================================================== diff -u --- lams_contentrepository/src/java/org/lamsfoundation/lams/contentrepository/client/Download.java (revision 0) +++ lams_contentrepository/src/java/org/lamsfoundation/lams/contentrepository/client/Download.java (revision e16f09694ef763b1acafa32958762c90332b8228) @@ -0,0 +1,397 @@ +/* + Copyright (C) 2005 LAMS Foundation (http://lamsfoundation.org) + + 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 + + http://www.gnu.org/licenses/gpl.txt +*/ + +package org.lamsfoundation.lams.contentrepository.client; + +import java.io.BufferedInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; + +import javax.servlet.ServletException; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.apache.log4j.Logger; +import org.lamsfoundation.lams.contentrepository.AccessDeniedException; +import org.lamsfoundation.lams.contentrepository.FileException; +import org.lamsfoundation.lams.contentrepository.ITicket; +import org.lamsfoundation.lams.contentrepository.IValue; +import org.lamsfoundation.lams.contentrepository.IVersionedNode; +import org.lamsfoundation.lams.contentrepository.ItemNotFoundException; +import org.lamsfoundation.lams.contentrepository.NodeType; +import org.lamsfoundation.lams.contentrepository.PropertyName; +import org.lamsfoundation.lams.contentrepository.RepositoryCheckedException; +import org.lamsfoundation.lams.contentrepository.ValueFormatException; +import org.springframework.web.context.WebApplicationContext; +import org.springframework.web.context.support.WebApplicationContextUtils; + + +/** + * This is a specialised servlet that supports the downloading of single + * files and the rendering of packages. + * + * It has a rather odd format - you can call it initially with + * the file/package uuid (and optional version) using + * download?uuid=<uuid>&version=<version>. + * If it is a file, then the file is downloaded. If it is a package, then + * it redirects to download/<uuid>/<version>/relPath + * where the <uuid> and <version> are the uuid and version + * of the package node. + * + * The download/<uuid>/<version>/relPath should only be used + * internally - the servlet should be called with the parameter + * version initially. + * + * This / format allows the relative pathed links + * within an html file to work properly. + * + * If you want to try to download the file rather than display the file, + * add the parameter preferDownload=true to the url. This is only meaningful + * for a file - it is ignored for packages. + * + * The servlet accesses the content repository via a tool's ToolContentHandler + * implementation. It looks for the bean IToolContentHandler.SPRING_BEAN_NAME + * in the web based Spring context. If you do not have a ToolContentHandler + * implementation then this servlet will not work. If you have an implementation + * but you use a different name for the bean in the Spring context, then you + * will need to override the getToolContentHandler() method in this servlet. + * @see org.lamsfoundation.lams.contentrepository.client.IToolContentHandler + * + * @author Fiona Malikoff + */ + +/* A package node could be handled by either getting the + stream from the package node - this is the first file + in the package - or by using the property in the node + that specifies the path to the first file and go back + to the repository and get that node. In a roundabout + way, this servlet uses the second method - it redirects + to the path for the first file. + + method 1: the package node returns a stream which is the first file. + InputStream = node.getFile(); + set up any header variables + + + method 2: get initial path node and download that + IValue value = node.getProperty(PropertyName.INITIALPATH); + String initialPath = value != null ? value.getString() : null; + IVersionedNode childNode = getRepository().getFileItem(ticket,uuid, initialPath, null); + InputStream = node.getFile(); + + +*/ + +public class Download extends HttpServlet { + + public static final String UUID_NAME = "uuid"; + public static final String VERSION_NAME = "version"; + public static final String PREFER_DOWNLOAD = "preferDownload"; + + protected static Logger log = Logger.getLogger(Download.class); + protected static IToolContentHandler toolContentHandler = null; + + private static final String expectedFormat = + "Expected format /download?" + +UUID_NAME + +"&" + +VERSION_NAME + +"= (version number optional) or /download///"; + /** + * Constructor of the object. + */ + public Download() { + super(); + } + + /** + * Destruction of the servlet.
+ */ + public void destroy() { + super.destroy(); + } + + /** + * The doGet method of the servlet.
+ * + * This method is called when a form has its tag value method equals to get. + * + * @param request the request send by the client to the server + * @param response the response send by the server to the client + * @throws ServletException if an error occurred + * @throws IOException if an error occurred + */ + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + + try { + handleCall(request, response); + } catch (RepositoryCheckedException e) { + log.error("Exception occured in download. Exception "+e.getMessage() + +"Request URL was "+request.getRequestURL(),e); + throw new ServletException(e); + } + } + + private void handleCall(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException, RepositoryCheckedException { + + long start = System.currentTimeMillis(); + + ITicket ticket = getToolContentHandler().getTicket(false); + if ( ticket == null ) { + throw new RepositoryCheckedException("Unable to get ticket - getTicket(false) returned null"); + } + + Long uuid = getLong(request.getParameter(UUID_NAME)); + Long version = null; + boolean saveFile = getBoolean(request.getParameter(PREFER_DOWNLOAD)); + + String callId = null; + + if ( uuid != null ) { + + version = getLong(request.getParameter(VERSION_NAME)); + + IVersionedNode node = getFileItem(ticket, uuid, version,null); + + // update versionId in case it was null and we got the latest version... + version = node.getVersion(); + + if ( node.isNodeType(NodeType.PACKAGENODE) ) { + + // now get the path of the initial page in the package + IValue value = node.getProperty(PropertyName.INITIALPATH); + String initialPage = value != null ? value.getString() : null; + if ( initialPage == null || initialPage.length() ==0 ) { + throw new RepositoryCheckedException("No initial page found for this set of content. Node Data is "+node.toString()); + } + + // redirect to the initial path + // prepend with servlet and id - initial call doesn't include the id + // and depending on "/"s, the servlet name is sometimes lost by the redirect. + // make sure it displays the file - rather than trying to download it. + initialPage = request.getRequestURL() + "/" + uuid + + "/" + version + "/" + initialPage+"?preferDownload=false"; + log.debug("Attempting to redirect to initial page "+initialPage); + response.sendRedirect(initialPage); + + } else if ( node.isNodeType(NodeType.FILENODE) ) { + + handleFileNode(response, node, saveFile); + + } else { + throw new RepositoryCheckedException("Unsupported node type " + +node.getNodeType()+". Node Data is "+node.toString(),null); + } + + } else { + + // using the /download// format - must be a file node! + String pathString = request.getPathInfo(); + String[] strings = deriveIdFile(pathString); + uuid = getLong(strings[0]); + version = getLong(strings[1]); + String relPathString = strings[2]; + + callId = "download "+Math.random()+" "+uuid; + + if ( uuid == null ) { + throw new RepositoryCheckedException("UUID value is missing. "+expectedFormat); + } + + if ( version == null ) { + throw new RepositoryCheckedException("Version value is missing. "+expectedFormat); + } + + if ( relPathString == null ) { + throw new RepositoryCheckedException("Filename is missing. "+expectedFormat); + } + + IVersionedNode node = getFileItem(ticket, uuid, version, relPathString); + if ( ! node.isNodeType(NodeType.FILENODE) ) { + throw new RepositoryCheckedException("Unexpected type of node " + +node.getNodeType()+" Expected File node. Data is "+node); + } + handleFileNode(response, node, saveFile); + + } + } + + /** + * The call getFileItem was throwing a runtime hibernate/jdbc error when being + * thrash tested, and I couldn't work out the context, so I've wrapped + * the call here so it can be debugged. + */ + private IVersionedNode getFileItem(ITicket ticket, Long uuid, Long version, String relPathString) + throws AccessDeniedException, ItemNotFoundException, FileException { + try { + IVersionedNode node = null; + if ( relPathString != null ) { + // get file in package + node = getToolContentHandler().getRepositoryService().getFileItem(ticket,uuid, version, relPathString); + } else { + // get node + node = getToolContentHandler().getRepositoryService().getFileItem(ticket,uuid, version); + } + return node; + } catch ( RuntimeException e ) { + log.error("Exception thrown calling repository.getFileItem(," + +uuid+","+version+","+relPathString+"). "+e.getMessage(), e); + throw e; + } + } + + /** + * @param response + * @param aNode + * @throws IOException + */ + protected void handleFileNode(HttpServletResponse response, IVersionedNode fileNode, boolean saveFile) + throws IOException, FileException, ValueFormatException { + + // Try to get the mime type and set the response content type. + // Use the mime type was saved with the file, + // the type set up in the server (e.g. tomcat's config) or failing + // that, make it a octet stream. + IValue prop = fileNode.getProperty(PropertyName.MIMETYPE); + String mimeType = prop != null ? prop.getString() : null; + if ( mimeType == null ) { + prop = fileNode.getProperty(PropertyName.FILENAME); + if ( prop != null ) { + mimeType = getServletContext().getMimeType(prop.getString()); + } + } + if (mimeType == null) { + mimeType = "application/octet-stream"; + } + response.setContentType(mimeType); + + // Get the filename stored with the file + prop = fileNode.getProperty(PropertyName.FILENAME); + String filename = prop != null ? prop.getString() : null; + + log.debug("Downloading file " + filename + " mime type " + mimeType); + + if (saveFile) { + log.debug("Sending as attachment"); + response.setHeader("Content-Disposition","attachment;filename=" + filename); + } else { + log.debug("Sending as inline"); + response.setHeader("Content-Disposition","inline;filename=" + filename); + } + response.setHeader("Cache-control","must-revalidate"); + if ( filename != null ) { + response.addHeader("Content-Description", filename); + } + + InputStream in = new BufferedInputStream(fileNode.getFile()); + OutputStream out = response.getOutputStream(); + try { + int count = 0; + + int ch; + while ((ch = in.read()) != -1) + { + out.write((char) ch); + count++; + } + log.debug("Wrote out " + count + " bytes"); + response.setContentLength(count); + out.flush(); + } catch (IOException e) { + log.error( "Exception occured writing out file:" + e.getMessage()); + throw e; + } finally { + try { + if (in != null) in.close(); // very important + if (out != null) out.close(); + } + catch (IOException e) { + log.error("Error Closing file. File already written out - no exception being thrown.",e); + } + } + } + + // Expect format ///. No parts are optional. Filename may be a path. + // returns an array of three strings. + private String[] deriveIdFile(String pathInfo) { + String[] result = new String[3]; + + if ( pathInfo != null ) { + + String[] strings = pathInfo.split("/",4); + + for ( int i=0, j=0; i 0 ) { + result[j++] = strings[i]; + } + } + + } + log.debug("Split path into following strings: '" + +result[0] + +"' '"+result[1] + +"' '"+result[2]); + + return result; + } + + + /** + * The doPost method of the servlet.
+ * + * This method is called when a form has its tag value method equals to post. + * + * @param request the request send by the client to the server + * @param response the response send by the server to the client + * @throws ServletException if an error occurred + * @throws IOException if an error occurred + */ + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doGet(request, response); + } + + public IToolContentHandler getToolContentHandler() { + if ( toolContentHandler == null ) { + log.debug("Download servlet calling context and getting repository singleton."); + WebApplicationContext wac = WebApplicationContextUtils.getRequiredWebApplicationContext(getServletContext()); + toolContentHandler = (IToolContentHandler)wac.getBean(IToolContentHandler.SPRING_BEAN_NAME); + } + return toolContentHandler; + } + + protected static Long getLong(String longAsString) { + try { + return new Long(longAsString); + } catch ( NumberFormatException e ) { + return null; + } + } + + protected static boolean getBoolean(String booleanAsString) { + return Boolean.valueOf(booleanAsString).booleanValue(); + } +} Index: lams_contentrepository/src/java/org/lamsfoundation/lams/contentrepository/client/IToolContentHandler.java =================================================================== diff -u --- lams_contentrepository/src/java/org/lamsfoundation/lams/contentrepository/client/IToolContentHandler.java (revision 0) +++ lams_contentrepository/src/java/org/lamsfoundation/lams/contentrepository/client/IToolContentHandler.java (revision e16f09694ef763b1acafa32958762c90332b8228) @@ -0,0 +1,150 @@ +/* + Copyright (C) 2005 LAMS Foundation (http://lamsfoundation.org) + + 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 + + http://www.gnu.org/licenses/gpl.txt + */ +package org.lamsfoundation.lams.contentrepository.client; + +import java.io.InputStream; +import java.util.Set; + +import org.lamsfoundation.lams.contentrepository.FileException; +import org.lamsfoundation.lams.contentrepository.ITicket; +import org.lamsfoundation.lams.contentrepository.IVersionedNode; +import org.lamsfoundation.lams.contentrepository.InvalidParameterException; +import org.lamsfoundation.lams.contentrepository.ItemNotFoundException; +import org.lamsfoundation.lams.contentrepository.NodeKey; +import org.lamsfoundation.lams.contentrepository.RepositoryCheckedException; +import org.lamsfoundation.lams.contentrepository.service.IRepositoryService; + +/** + * ToolContentHander is an abstract class that implements most of the functionality + * of the interface. Each tool extends the abstract class and implements the remaining + * functionality (which is tool specific). + * + * This interface exists so that the Download servlet (@see org.lamsfoundation.lams.contentrepository.client.Download.java) + * can get to the Repository via ToolContentHandler. It needs to call the tool's + * concrete class, which must be defined in the Spring context as "toolContentHandler" + * (see SPRING_BEAN_NAME). The Download servlet looks for it by name, so if you change + * the name, you will also need to extend the Download servlet to use your own name. + * + * For more details on using this class, @see org.lamsfoundation.lams.contentrepository.client.ToolContentHandler. + * @author Fiona Malikoff + */ +public interface IToolContentHandler { + /** File is for Online Instructions */ + public final static String TYPE_ONLINE = "ONLINE"; + + /** File is for Offline Instructions */ + public final static String TYPE_OFFLINE = "OFFLINE"; + + /** The "name" used to store the online/offline property in the repository */ + public final static String FILE_TYPE_PROPERTY_NAME = "TYPE"; + + /** The concrete implementation must be configured as a bean in Spring, using + * this value as the name. */ + public final static String SPRING_BEAN_NAME = "toolContentHandler"; + + /** + * @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. + * + * @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. + * @param fileProperty is this for online or offline instructions? Should be TYPE_ONLINE or TYPE_OFFLINE. Mandatory. + * @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, String fileProperty) + 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; + + /** Get a file node. + * @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 IVersionedNode getFileNode(Long uuid) + throws ItemNotFoundException, FileException, + RepositoryCheckedException; + + /** Get just the properties of a file. Convenience method - equivalent of + * calling getFileNode(uuid).getProperties(). Useful if all you want are + * the properties and you don't want to access the file itself. + * + * @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 Set getFileProperties(Long uuid) + throws ItemNotFoundException, FileException, + RepositoryCheckedException; + + public abstract boolean isOffline(IVersionedNode node); + + public abstract boolean isOnline(IVersionedNode node); + + public abstract IRepositoryService getRepositoryService(); + + /** + * @param repositoryService The repositoryService to set. + */ + public abstract void setRepositoryService( + IRepositoryService repositoryService); +} \ No newline at end of file Index: lams_contentrepository/src/java/org/lamsfoundation/lams/contentrepository/client/ToolContentHandler.java =================================================================== diff -u -rae78f44a3cdb0d0ddfb02d50709d20604bcb01b8 -re16f09694ef763b1acafa32958762c90332b8228 --- lams_contentrepository/src/java/org/lamsfoundation/lams/contentrepository/client/ToolContentHandler.java (.../ToolContentHandler.java) (revision ae78f44a3cdb0d0ddfb02d50709d20604bcb01b8) +++ lams_contentrepository/src/java/org/lamsfoundation/lams/contentrepository/client/ToolContentHandler.java (.../ToolContentHandler.java) (revision e16f09694ef763b1acafa32958762c90332b8228) @@ -21,6 +21,7 @@ package org.lamsfoundation.lams.contentrepository.client; import java.io.InputStream; +import java.util.Set; import org.apache.log4j.Logger; import org.lamsfoundation.lams.contentrepository.AccessDeniedException; @@ -64,15 +65,18 @@ *
  • Define your Handler class as a bean in your own Spring context file. * It must include a parameter repositoryService, which references a local * value of repositoryService. The "repositoryService" is defined in the - * Content Repository's applicationContext.xml. + * Content Repository's applicationContext.xml. The name "toolContentHandler" + * (IToolContentHandler.SPRING_BEAN_NAME) is also essential as the Download servlet + * looks for it by this name. * * For example: *
      * 	<bean id="toolContentHandler" class="your class name here">
    - * 		<property name="repositoryService"><ref local="coreSessionFactory"/></property>
    + * 		<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. *

    @@ -100,19 +104,18 @@ *

    * If you want to see this class used, have a look at the test code in org.lamsfoundation.lams.contentrepository.client * in the test/java area. + *

    + * You may be wondering why we don't make the workspaceName, user, id, etc + * parameters in the Spring file, rather than creating a concrete class. Using + * the Spring file would be easier, but then the id (equivalent to passsword) + * is easier to hack. The id is a char[], rather than a String for + * security. If you don't care that your tool's id is stored as a String + * then you can include it in your Spring file. * * @author conradb, Fiona Malikoff */ -public abstract class ToolContentHandler { +public abstract class ToolContentHandler implements IToolContentHandler { - /** File is for Online Instructions */ - public final static String TYPE_ONLINE = "ONLINE"; - /** File is for Offline Instructions */ - public final static String TYPE_OFFLINE = "OFFLINE"; - - /** The "name" used to store the online/offline property in the repository */ - public final static String FILE_TYPE_PROPERTY_NAME = "TYPE"; - private IRepositoryService repositoryService; private ITicket ticket; private boolean productionMode = true; @@ -161,7 +164,7 @@ * if the repository loses the ticket. * @return the repository ticket */ - protected ITicket getTicket( boolean forceLogin ) throws RepositoryCheckedException { + public ITicket getTicket( boolean forceLogin ) throws RepositoryCheckedException { if ( ticket == null || forceLogin ) { ICredentials cred = new SimpleCredentials(getRepositoryUser(), getRepositoryId()); try { @@ -268,8 +271,35 @@ +"Repository Exception: "+e2.getMessage()+" Retry not possible."); throw e2; } -} + } + /** Get just the properties of a file. Convenience method - equivalent of + * calling getFileNode(uuid).getProperties(). Useful if all you want are + * the properties and you don't want to access the file itself. + * + * @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 Set getFileProperties(Long uuid) throws ItemNotFoundException, FileException, RepositoryCheckedException { + try { + try { + IVersionedNode node = getRepositoryService().getFileItem(getTicket(false), uuid, null); + return node != null ? node.getProperties() : null; + } catch (AccessDeniedException e) { + log.warn("Unable to access repository to get file id"+uuid + +"AccessDeniedException: "+e.getMessage()+" Retrying login."); + IVersionedNode node = getRepositoryService().getFileItem(getTicket(true), uuid, null); + return node != null ? node.getProperties() : null; + } + } catch (RepositoryCheckedException e2) { + log.warn("Unable to to get file id"+uuid + +"Repository Exception: "+e2.getMessage()+" Retry not possible."); + throw e2; + } + } + public boolean isOffline(IVersionedNode node) { return checkType(node, TYPE_OFFLINE); } Index: lams_tool_forum/build.xml =================================================================== diff -u -r4296cc24afab0a22b2075656b93b7bad7578e32f -re16f09694ef763b1acafa32958762c90332b8228 --- lams_tool_forum/build.xml (.../build.xml) (revision 4296cc24afab0a22b2075656b93b7bad7578e32f) +++ lams_tool_forum/build.xml (.../build.xml) (revision e16f09694ef763b1acafa32958762c90332b8228) @@ -275,7 +275,7 @@ classname="xdoclet.modules.web.WebDocletTask" classpathref="project.classpath" /> - Index: lams_tool_forum/conf/hibernate/mappings/org/lamsfoundation/lams/tool/forum/persistence/GenericEntity.hbm.xml =================================================================== diff -u -re2d5d907aabab2d2bc94f232285ff086fb11ed37 -re16f09694ef763b1acafa32958762c90332b8228 --- lams_tool_forum/conf/hibernate/mappings/org/lamsfoundation/lams/tool/forum/persistence/GenericEntity.hbm.xml (.../GenericEntity.hbm.xml) (revision e2d5d907aabab2d2bc94f232285ff086fb11ed37) +++ lams_tool_forum/conf/hibernate/mappings/org/lamsfoundation/lams/tool/forum/persistence/GenericEntity.hbm.xml (.../GenericEntity.hbm.xml) (revision e16f09694ef763b1acafa32958762c90332b8228) @@ -9,10 +9,6 @@ @@ -43,7 +38,6 @@ type="java.util.Date" update="true" insert="true" - access="property" column="UPDATED" /> @@ -52,7 +46,6 @@ type="java.lang.Long" update="true" insert="true" - access="property" column="CREATEDBY" /> @@ -61,7 +54,6 @@ type="java.lang.Long" update="true" insert="true" - access="property" column="MODIFIEDBY" /> @@ -74,18 +66,15 @@ - + @@ -94,7 +83,6 @@ type="text" update="true" insert="true" - access="property" column="BODY" /> @@ -103,7 +91,6 @@ type="boolean" update="true" insert="true" - access="property" column="ISAUTHORED" /> @@ -112,7 +99,6 @@ type="boolean" update="true" insert="true" - access="property" column="ISANNONYMOUS" /> @@ -125,14 +111,14 @@ sort="unsorted" > - - + + - + /> @@ -143,26 +129,22 @@ outer-join="auto" update="true" insert="true" - access="property" column="FORUM" /> - + @@ -171,7 +153,6 @@ type="boolean" update="true" insert="true" - access="property" column="ALLOWANNOMITY" /> @@ -180,7 +161,6 @@ type="boolean" update="true" insert="true" - access="property" column="FORCEOFFLINE" /> @@ -189,7 +169,6 @@ type="boolean" update="true" insert="true" - access="property" column="LOCKWHENFINISHED" /> @@ -198,7 +177,6 @@ type="java.lang.String" update="true" insert="true" - access="property" column="INSTRUCTIONS" /> @@ -207,7 +185,6 @@ type="java.lang.String" update="true" insert="true" - access="property" column="ONLINEINSTRUCTIONS" /> @@ -216,7 +193,6 @@ type="java.lang.String" update="true" insert="true" - access="property" column="OFFLINEINSTRUCTIONS" /> @@ -229,33 +205,30 @@ sort="unsorted" > - - + + - + /> - + @@ -264,7 +237,6 @@ type="java.lang.Long" update="true" insert="true" - access="property" column="VERSION" /> Index: lams_tool_forum/conf/xdoclet/servlet-mappings.xml =================================================================== diff -u -re2d5d907aabab2d2bc94f232285ff086fb11ed37 -re16f09694ef763b1acafa32958762c90332b8228 --- lams_tool_forum/conf/xdoclet/servlet-mappings.xml (.../servlet-mappings.xml) (revision e2d5d907aabab2d2bc94f232285ff086fb11ed37) +++ lams_tool_forum/conf/xdoclet/servlet-mappings.xml (.../servlet-mappings.xml) (revision e16f09694ef763b1acafa32958762c90332b8228) @@ -2,4 +2,10 @@ action *.do + + + Download + /download/* + + \ No newline at end of file Index: lams_tool_forum/conf/xdoclet/servlets.xml =================================================================== diff -u -re2d5d907aabab2d2bc94f232285ff086fb11ed37 -re16f09694ef763b1acafa32958762c90332b8228 --- lams_tool_forum/conf/xdoclet/servlets.xml (.../servlets.xml) (revision e2d5d907aabab2d2bc94f232285ff086fb11ed37) +++ lams_tool_forum/conf/xdoclet/servlets.xml (.../servlets.xml) (revision e16f09694ef763b1acafa32958762c90332b8228) @@ -39,5 +39,12 @@ 2 - + + + Download file(s) + Download file + Download + org.lamsfoundation.lams.tool.forum.web.actions.ForumDownload + + \ No newline at end of file Index: lams_tool_forum/conf/xdoclet/web-settings.xml =================================================================== diff -u -re2d5d907aabab2d2bc94f232285ff086fb11ed37 -re16f09694ef763b1acafa32958762c90332b8228 --- lams_tool_forum/conf/xdoclet/web-settings.xml (.../web-settings.xml) (revision e2d5d907aabab2d2bc94f232285ff086fb11ed37) +++ lams_tool_forum/conf/xdoclet/web-settings.xml (.../web-settings.xml) (revision e16f09694ef763b1acafa32958762c90332b8228) @@ -2,3 +2,21 @@ Forum tool + + + javax.servlet.jsp.jstl.fmt.localizationContext + org.lamsfoundation.lams.tool.imscp.web.ApplicationResources + + + contextConfigLocation + + classpath:/org/lamsfoundation/lams/contentrepository/applicationContext.xml + classpath:/forumApplicationContext.xml + + + + + org.springframework.web.context.ContextLoaderListener + + + \ No newline at end of file Index: lams_tool_forum/src/java/forumApplicationContext.xml =================================================================== diff -u -r4296cc24afab0a22b2075656b93b7bad7578e32f -re16f09694ef763b1acafa32958762c90332b8228 --- lams_tool_forum/src/java/forumApplicationContext.xml (.../forumApplicationContext.xml) (revision 4296cc24afab0a22b2075656b93b7bad7578e32f) +++ lams_tool_forum/src/java/forumApplicationContext.xml (.../forumApplicationContext.xml) (revision e16f09694ef763b1acafa32958762c90332b8228) @@ -130,4 +130,8 @@ + + + + Index: lams_tool_forum/src/java/org/lamsfoundation/lams/tool/forum/core/GenericObjectFactoryImpl.java =================================================================== diff -u -r544f493c47e6bbb0136e0c5dae6c8ea9c32eabd6 -re16f09694ef763b1acafa32958762c90332b8228 --- lams_tool_forum/src/java/org/lamsfoundation/lams/tool/forum/core/GenericObjectFactoryImpl.java (.../GenericObjectFactoryImpl.java) (revision 544f493c47e6bbb0136e0c5dae6c8ea9c32eabd6) +++ lams_tool_forum/src/java/org/lamsfoundation/lams/tool/forum/core/GenericObjectFactoryImpl.java (.../GenericObjectFactoryImpl.java) (revision e16f09694ef763b1acafa32958762c90332b8228) @@ -24,6 +24,7 @@ public static GenericObjectFactory getInstance() { if (genericObjectFactory == null) { genericObjectFactory = new GenericObjectFactoryImpl(); + addContext("/org/lamsfoundation/lams/contentrepository/applicationContext.xml"); addContext("/forumApplicationContext.xml"); } return genericObjectFactory; Index: lams_tool_forum/src/java/org/lamsfoundation/lams/tool/forum/service/ForumManagerImpl.java =================================================================== diff -u -rc8ee9a042cb63bf1a8b2416367789a674b4f437a -re16f09694ef763b1acafa32958762c90332b8228 --- lams_tool_forum/src/java/org/lamsfoundation/lams/tool/forum/service/ForumManagerImpl.java (.../ForumManagerImpl.java) (revision c8ee9a042cb63bf1a8b2416367789a674b4f437a) +++ lams_tool_forum/src/java/org/lamsfoundation/lams/tool/forum/service/ForumManagerImpl.java (.../ForumManagerImpl.java) (revision e16f09694ef763b1acafa32958762c90332b8228) @@ -5,8 +5,6 @@ import org.lamsfoundation.lams.tool.forum.persistence.Attachment; import org.lamsfoundation.lams.tool.forum.core.PersistenceDelegate; import org.lamsfoundation.lams.tool.forum.core.PersistenceException; -import org.lamsfoundation.lams.tool.forum.util.ContentHandler; -import org.lamsfoundation.lams.contentrepository.NodeKey; import java.util.*; Fisheye: Tag e16f09694ef763b1acafa32958762c90332b8228 refers to a dead (removed) revision in file `lams_tool_forum/src/java/org/lamsfoundation/lams/tool/forum/util/ContentHandler.java'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag e16f09694ef763b1acafa32958762c90332b8228 refers to a dead (removed) revision in file `lams_tool_forum/src/java/org/lamsfoundation/lams/tool/forum/util/FileUtils.java'. Fisheye: No comparison available. Pass `N' to diff? Index: lams_tool_forum/src/java/org/lamsfoundation/lams/tool/forum/util/ForumConstants.java =================================================================== diff -u -r2445d0ae722db3ba0495a6506b02c5fe5f70e551 -re16f09694ef763b1acafa32958762c90332b8228 --- lams_tool_forum/src/java/org/lamsfoundation/lams/tool/forum/util/ForumConstants.java (.../ForumConstants.java) (revision 2445d0ae722db3ba0495a6506b02c5fe5f70e551) +++ lams_tool_forum/src/java/org/lamsfoundation/lams/tool/forum/util/ForumConstants.java (.../ForumConstants.java) (revision e16f09694ef763b1acafa32958762c90332b8228) @@ -9,4 +9,8 @@ */ public interface ForumConstants { public final static int MAX_FILE_SIZE = 250 * 1000; + + public final static String FORUM_MANAGER = "forumManager"; + public final static String CONTENT_HANDLER = "toolContentHandler"; + } Index: lams_tool_forum/src/java/org/lamsfoundation/lams/tool/forum/util/ForumToolContentHandler.java =================================================================== diff -u --- lams_tool_forum/src/java/org/lamsfoundation/lams/tool/forum/util/ForumToolContentHandler.java (revision 0) +++ lams_tool_forum/src/java/org/lamsfoundation/lams/tool/forum/util/ForumToolContentHandler.java (revision e16f09694ef763b1acafa32958762c90332b8228) @@ -0,0 +1,64 @@ +/* +Copyright (C) 2005 LAMS Foundation (http://lamsfoundation.org) + +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 + +http://www.gnu.org/licenses/gpl.txt +*/ +package org.lamsfoundation.lams.tool.forum.util; + +import org.lamsfoundation.lams.contentrepository.client.ToolContentHandler; + +/** + * Simple client for accessing the content repository. + * + * @author Fiona Malikoff + */ +public class ForumToolContentHandler extends ToolContentHandler { + + private static String repositoryWorkspaceName = "forumworkspace"; + private static String repositoryUser = "forum"; + private static char[] repositoryId = {'l','a','m','s','-','f','o','r','u','m'}; + + /** + * + */ + public ForumToolContentHandler() { + super(); + } + + /* (non-Javadoc) + * @see org.lamsfoundation.lams.contentrepository.client.ToolContentHandler#getRepositoryWorkspaceName() + */ + public String getRepositoryWorkspaceName() { + return repositoryWorkspaceName; + } + + /* (non-Javadoc) + * @see org.lamsfoundation.lams.contentrepository.client.ToolContentHandler#getRepositoryUser() + */ + public String getRepositoryUser() { + return repositoryUser; + } + + /* (non-Javadoc) + * @see org.lamsfoundation.lams.contentrepository.client.ToolContentHandler#getRepositoryId() + */ + public char[] getRepositoryId() { + return repositoryId; + } + +} Index: lams_tool_forum/src/java/org/lamsfoundation/lams/tool/forum/web/ApplicationResources.properties =================================================================== diff -u -r4296cc24afab0a22b2075656b93b7bad7578e32f -re16f09694ef763b1acafa32958762c90332b8228 --- lams_tool_forum/src/java/org/lamsfoundation/lams/tool/forum/web/ApplicationResources.properties (.../ApplicationResources.properties) (revision 4296cc24afab0a22b2075656b93b7bad7578e32f) +++ lams_tool_forum/src/java/org/lamsfoundation/lams/tool/forum/web/ApplicationResources.properties (.../ApplicationResources.properties) (revision e16f09694ef763b1acafa32958762c90332b8228) @@ -51,6 +51,8 @@ ##Labels label.open = Open label.delete = Delete +label.download = Download +label.view = View ##Buttons button.upload = upload Index: lams_tool_forum/src/java/org/lamsfoundation/lams/tool/forum/web/actions/ForumAction.java =================================================================== diff -u -r389458c01689521566a59124e971ac5f8bab740d -re16f09694ef763b1acafa32958762c90332b8228 --- lams_tool_forum/src/java/org/lamsfoundation/lams/tool/forum/web/actions/ForumAction.java (.../ForumAction.java) (revision 389458c01689521566a59124e971ac5f8bab740d) +++ lams_tool_forum/src/java/org/lamsfoundation/lams/tool/forum/web/actions/ForumAction.java (.../ForumAction.java) (revision e16f09694ef763b1acafa32958762c90332b8228) @@ -1,28 +1,42 @@ package org.lamsfoundation.lams.tool.forum.web.actions; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import javax.servlet.ServletException; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.apache.log4j.Logger; import org.apache.struts.action.Action; +import org.apache.struts.action.ActionForm; import org.apache.struts.action.ActionForward; import org.apache.struts.action.ActionMapping; -import org.apache.struts.action.ActionForm; -import org.apache.log4j.Logger; -import org.lamsfoundation.lams.tool.forum.service.ForumManager; -import org.lamsfoundation.lams.tool.forum.core.GenericObjectFactoryImpl; +import org.apache.struts.upload.FormFile; +import org.lamsfoundation.lams.contentrepository.CrNodeVersionProperty; +import org.lamsfoundation.lams.contentrepository.InvalidParameterException; +import org.lamsfoundation.lams.contentrepository.NodeKey; +import org.lamsfoundation.lams.contentrepository.RepositoryCheckedException; import org.lamsfoundation.lams.tool.forum.core.PersistenceException; -import org.lamsfoundation.lams.tool.forum.web.forms.ForumForm; -import org.lamsfoundation.lams.tool.forum.web.forms.MessageForm; +import org.lamsfoundation.lams.tool.forum.persistence.Attachment; import org.lamsfoundation.lams.tool.forum.persistence.Forum; import org.lamsfoundation.lams.tool.forum.persistence.Message; -import org.lamsfoundation.lams.tool.forum.persistence.Attachment; -import org.lamsfoundation.lams.tool.forum.util.ContentHandler; -import org.lamsfoundation.lams.contentrepository.CrNodeVersionProperty; +import org.lamsfoundation.lams.tool.forum.service.ForumManager; +import org.lamsfoundation.lams.tool.forum.util.ForumConstants; +import org.lamsfoundation.lams.tool.forum.util.ForumToolContentHandler; +import org.lamsfoundation.lams.tool.forum.web.forms.ForumForm; +import org.lamsfoundation.lams.tool.forum.web.forms.MessageForm; +import org.springframework.web.context.WebApplicationContext; +import org.springframework.web.context.support.WebApplicationContextUtils; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import javax.servlet.ServletException; -import java.io.IOException; -import java.util.*; - /** * Created by IntelliJ IDEA. * User: conradb @@ -33,15 +47,34 @@ public class ForumAction extends Action { private static Logger log = Logger.getLogger(ForumAction.class.getName()); private ForumManager forumManager; + private ForumToolContentHandler toolContentHandler; public void setForumManager(ForumManager forumManager) { this.forumManager = forumManager; } - public ForumAction() { - this.forumManager = (ForumManager) GenericObjectFactoryImpl.getInstance().lookup("forumManager"); + //public ForumAction() { + //this.forumManager = (ForumManager) GenericObjectFactoryImpl.getInstance().lookup(ForumConstants.FORUM_MANAGER); + //this.toolContentHandler = (ForumToolContentHandler) GenericObjectFactoryImpl.getInstance().lookup(ForumConstants.CONTENT_HANDLER); //GenericObjectFactoryImpl.getInstance().configure(this); - } + //} + + private ForumManager getForumManager() { + if ( forumManager == null ) { + WebApplicationContext wac = WebApplicationContextUtils.getRequiredWebApplicationContext(getServlet().getServletContext()); + forumManager = (ForumManager) wac.getBean(ForumConstants.FORUM_MANAGER); + } + return forumManager; + } + + private ForumToolContentHandler getToolContentHandler() { + if ( toolContentHandler == null ) { + WebApplicationContext wac = WebApplicationContextUtils.getRequiredWebApplicationContext(getServlet().getServletContext()); + toolContentHandler = (ForumToolContentHandler) wac.getBean(ForumToolContentHandler.SPRING_BEAN_NAME); + } + return toolContentHandler; + } + public final ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { String param = mapping.getParameter(); @@ -84,11 +117,11 @@ Forum forum = forumForm.getForum(); Map topics = (Map) request.getSession().getAttribute("topics"); - forum = this.forumManager.createForum(forum, forumForm.getAttachments(), topics); + forum = getForumManager().createForum(forum, forumForm.getAttachments(), topics); forumForm.setForum(forum); //populate topics with new topics - List topicList = this.forumManager.getTopics(forum.getId()); + List topicList = getForumManager().getTopics(forum.getId()); topics = new HashMap(); Iterator it = topicList.iterator(); while (it.hasNext()) { @@ -109,7 +142,7 @@ ForumForm forumForm = (ForumForm) form; Forum forum = forumForm.getForum(); Map topics = (Map) request.getSession().getAttribute("topics"); - this.forumManager.editForum(forum, forumForm.getAttachments(), topics); + getForumManager().editForum(forum, forumForm.getAttachments(), topics); return mapping.findForward("success"); } @@ -119,8 +152,8 @@ HttpServletResponse response) throws IOException, ServletException, Exception { Long forumId = new Long((String) request.getParameter("forumId")); - Forum forum = forumManager.getForum(forumId); - List topicList = this.forumManager.getTopics(forum.getId()); + Forum forum = getForumManager().getForum(forumId); + List topicList = getForumManager().getTopics(forum.getId()); ForumForm forumForm = new ForumForm(); forumForm.setForum(forum); @@ -142,7 +175,7 @@ while (it.hasNext()) { Attachment attachment = (Attachment) it.next(); //ContentHandler handler = new ContentHandler(); - Set properties = ContentHandler.getFileProperties(attachment.getUuid()); + Set properties = getToolContentHandler().getFileProperties(attachment.getUuid()); Iterator propIt = properties.iterator(); while (propIt.hasNext()) { CrNodeVersionProperty property = (CrNodeVersionProperty) propIt.next(); @@ -168,7 +201,7 @@ HttpServletResponse response) throws IOException, ServletException, Exception { Long forumId = new Long((String) request.getParameter("forumId")); - forumManager.deleteForum(forumId); + getForumManager().deleteForum(forumId); return (mapping.findForward("success")); } @@ -195,12 +228,58 @@ HttpServletResponse response) throws IOException, ServletException, PersistenceException { ForumForm forumForm = (ForumForm) form; + + try { + processFile(forumForm, forumForm.getOnlineFile(), Attachment.TYPE_ONLINE); + processFile(forumForm, forumForm.getOfflineFile(), Attachment.TYPE_OFFLINE); + } catch (FileNotFoundException e) { + // TODO Create proper error message and return to user + log.error("Unable to uploadfile",e); + throw new IOException("Unable to upload file, exception was "+e.getMessage()); + } catch (IOException e) { + log.error("Unable to uploadfile",e); + throw new IOException("Unable to upload file, exception was "+e.getMessage()); + } catch (RepositoryCheckedException e) { + log.error("Unable to uploadfile",e); + throw new IOException("Unable to upload file, exception was "+e.getMessage()); + } + Collection entries = forumForm.getAttachments().values(); List attachmentList = new ArrayList(entries); request.getSession().setAttribute("attachmentList", attachmentList); return mapping.findForward("success"); } + /** + * Process an uploaded file. + * + * @param forumForm + * @throws FileNotFoundException + * @throws IOException + * @throws RepositoryCheckedException + * @throws InvalidParameterException + */ + private void processFile(ForumForm forumForm, FormFile file, String attachmentType) + throws InvalidParameterException, FileNotFoundException, RepositoryCheckedException, IOException { + + Map attachmentsMap = forumForm.getAttachments(); + if (file!= null && !(file.getFileName().trim().equals(""))) { + String fileName = file.getFileName(); + String keyName = fileName + "-" + attachmentType; + if (!attachmentsMap.containsKey(keyName)) { + NodeKey node = getToolContentHandler().uploadFile(file.getInputStream(), fileName, + file.getContentType(), attachmentType); + Attachment attachment = new Attachment(); + attachment.setName(fileName); + attachment.setStream(file.getInputStream()); + attachment.setUuid(node.getUuid()); + attachment.setType(attachmentType); + attachmentsMap.put(keyName, attachment); + forumForm.setOnlineFile(null); + } + } + } + public ActionForward deleteAttachment(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { ActionForward forward = new ActionForward(); forward.setPath(mapping.getInput()); @@ -209,9 +288,9 @@ ForumForm forumForm = (ForumForm) form; Map attachments = forumForm.getAttachments(); Attachment attachment = (Attachment) attachments.remove(fileName + "-" + type); - ContentHandler.deleteFile(attachment.getUuid()); + getToolContentHandler().deleteFile(attachment.getUuid()); if (attachment.getId() != null) { - this.forumManager.deleteForumAttachment(attachment.getId()); + getForumManager().deleteForumAttachment(attachment.getId()); } List attachmentList = new ArrayList(attachments.values()); request.getSession().setAttribute("attachmentList", attachmentList); @@ -223,7 +302,7 @@ Map topics = (Map) request.getSession().getAttribute("topics"); Message topic = (Message) topics.remove(topicName); if (topic.getId() != null) { - this.forumManager.deleteMessage(topic.getId()); + getForumManager().deleteMessage(topic.getId()); } request.getSession().setAttribute("topics", topics); request.getSession().setAttribute("topicList", new ArrayList(topics.values())); Index: lams_tool_forum/src/java/org/lamsfoundation/lams/tool/forum/web/actions/ForumDownload.java =================================================================== diff -u --- lams_tool_forum/src/java/org/lamsfoundation/lams/tool/forum/web/actions/ForumDownload.java (revision 0) +++ lams_tool_forum/src/java/org/lamsfoundation/lams/tool/forum/web/actions/ForumDownload.java (revision e16f09694ef763b1acafa32958762c90332b8228) @@ -0,0 +1,44 @@ +/* +Copyright (C) 2005 LAMS Foundation (http://lamsfoundation.org) + +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 + +http://www.gnu.org/licenses/gpl.txt +*/ +package org.lamsfoundation.lams.tool.forum.web.actions; + +import org.lamsfoundation.lams.contentrepository.struts.action.Download; + +/** + * @author FionaM + * + * Just testing why it can't access the download servlet. THis + * file is to be deleted. + * + * TODO To change the template for this generated type comment go to + * Window - Preferences - Java - Code Style - Code Templates + */ +public class ForumDownload extends Download { + + /** + * + */ + public ForumDownload() { + super(); + // TODO Auto-generated constructor stub + } + +} Index: lams_tool_forum/src/java/org/lamsfoundation/lams/tool/forum/web/forms/ForumForm.java =================================================================== diff -u -r7060aa6f074c868f788f691954fda90b391c9039 -re16f09694ef763b1acafa32958762c90332b8228 --- lams_tool_forum/src/java/org/lamsfoundation/lams/tool/forum/web/forms/ForumForm.java (.../ForumForm.java) (revision 7060aa6f074c868f788f691954fda90b391c9039) +++ lams_tool_forum/src/java/org/lamsfoundation/lams/tool/forum/web/forms/ForumForm.java (.../ForumForm.java) (revision e16f09694ef763b1acafa32958762c90332b8228) @@ -1,20 +1,17 @@ package org.lamsfoundation.lams.tool.forum.web.forms; -import org.apache.struts.validator.ValidatorForm; -import org.apache.struts.upload.FormFile; +import java.util.HashMap; +import java.util.Map; + +import org.apache.log4j.Logger; +import org.apache.struts.action.ActionError; import org.apache.struts.action.ActionErrors; import org.apache.struts.action.ActionMapping; -import org.apache.struts.action.ActionError; -import org.apache.log4j.Logger; +import org.apache.struts.upload.FormFile; +import org.apache.struts.validator.ValidatorForm; import org.lamsfoundation.lams.tool.forum.persistence.Forum; -import org.lamsfoundation.lams.tool.forum.persistence.Attachment; -import org.lamsfoundation.lams.tool.forum.util.ContentHandler; -import org.lamsfoundation.lams.tool.forum.util.ForumConstants; -import org.lamsfoundation.lams.contentrepository.NodeKey; +import org.lamsfoundation.lams.util.UploadFileUtil; -import java.util.Map; -import java.util.HashMap; - /** * * Message Form. @@ -34,7 +31,6 @@ protected boolean lockWhenFinished; protected boolean forceOffline; protected boolean allowAnnomity; - protected ContentHandler contentHander; private static Logger logger = Logger.getLogger(ForumForm.class.getName()); @@ -100,6 +96,10 @@ return this.attachments; } + private float convertToMeg( int numBytes ) { + return numBytes != 0 ? numBytes / 1024 / 1024 : 0; + } + public ActionErrors validate(ActionMapping mapping, javax.servlet.http.HttpServletRequest request) { ActionErrors errors = super.validate(mapping, request); @@ -109,43 +109,15 @@ ActionError error = new ActionError("error.valueReqd"); errors.add("forum.title", error); } - if (onlineFile != null && !(onlineFile.getFileName().trim().equals(""))) { - if (onlineFile.getFileSize() > ForumConstants.MAX_FILE_SIZE) { + if (onlineFile != null && !(onlineFile.getFileName().trim().equals("")) && + convertToMeg(onlineFile.getFileSize()) > UploadFileUtil.getMaxFileSize()) { ae = new ActionError("error.inputFileTooLarge"); errors.add("onlineFile", ae); - } else { - String fileName = onlineFile.getFileName(); - if (!attachments.containsKey(fileName +"-" + Attachment.TYPE_ONLINE)) { - NodeKey node = ContentHandler.uploadFile(onlineFile.getInputStream(), fileName, onlineFile.getContentType()); - ContentHandler.setProperty(node.getUuid(), node.getVersion(), "TYPE", Attachment.TYPE_ONLINE); - Attachment attachment = new Attachment(); - attachment.setName(fileName); - attachment.setStream(onlineFile.getInputStream()); - attachment.setUuid(node.getUuid()); - attachment.setType(Attachment.TYPE_ONLINE); - attachments.put(fileName + "-" + Attachment.TYPE_ONLINE, attachment); - onlineFile = null; - } - } } - if (offlineFile != null && !(offlineFile.getFileName().trim().equals(""))) { - if (offlineFile.getFileSize() > ForumConstants.MAX_FILE_SIZE) { + if (offlineFile != null && !(offlineFile.getFileName().trim().equals("")) && + convertToMeg(offlineFile.getFileSize()) > UploadFileUtil.getMaxFileSize()) { ae = new ActionError("error.inputFileTooLarge"); errors.add("offlineFile", ae); - } else { - String fileName = offlineFile.getFileName(); - if (!attachments.containsKey(fileName +"-" + Attachment.TYPE_OFFLINE)) { - NodeKey node = ContentHandler.uploadFile(offlineFile.getInputStream(), fileName, offlineFile.getContentType()); - ContentHandler.setProperty(node.getUuid(), node.getVersion(), "TYPE", Attachment.TYPE_OFFLINE); - Attachment attachment = new Attachment(); - attachment.setName(fileName); - attachment.setStream(offlineFile.getInputStream()); - attachment.setUuid(node.getUuid()); - attachment.setType(Attachment.TYPE_OFFLINE); - attachments.put(fileName + "-" + Attachment.TYPE_OFFLINE, attachment); - offlineFile = null; - } - } } } catch (Exception e) { logger.error("", e); Index: lams_tool_forum/web/WEB-INF/struts-config.xml =================================================================== diff -u -r4296cc24afab0a22b2075656b93b7bad7578e32f -re16f09694ef763b1acafa32958762c90332b8228 --- lams_tool_forum/web/WEB-INF/struts-config.xml (.../struts-config.xml) (revision 4296cc24afab0a22b2075656b93b7bad7578e32f) +++ lams_tool_forum/web/WEB-INF/struts-config.xml (.../struts-config.xml) (revision e16f09694ef763b1acafa32958762c90332b8228) @@ -258,7 +258,7 @@ + value="/WEB-INF/struts/validator-rules.xml,/WEB-INF/struts/validation.xml" /> Index: lams_tool_forum/web/WEB-INF/web.xml =================================================================== diff -u -r4296cc24afab0a22b2075656b93b7bad7578e32f -re16f09694ef763b1acafa32958762c90332b8228 --- lams_tool_forum/web/WEB-INF/web.xml (.../web.xml) (revision 4296cc24afab0a22b2075656b93b7bad7578e32f) +++ lams_tool_forum/web/WEB-INF/web.xml (.../web.xml) (revision e16f09694ef763b1acafa32958762c90332b8228) @@ -7,6 +7,22 @@ Forum tool + + javax.servlet.jsp.jstl.fmt.localizationContext + org.lamsfoundation.lams.tool.imscp.web.ApplicationResources + + + contextConfigLocation + + classpath:/org/lamsfoundation/lams/contentrepository/applicationContext.xml + classpath:/forumApplicationContext.xml + + + + + org.springframework.web.context.ContextLoaderListener + + + + Download file(s) + Download file + Download + org.lamsfoundation.lams.tool.forum.web.actions.ForumDownload + + action *.do + + Download + /download/* + 120 Index: lams_tool_forum/web/jsps/authoring/forum/editInstructions.jsp =================================================================== diff -u -r7c2b1a8f06af3cbdb52aa229c170fb80ec2022ad -re16f09694ef763b1acafa32958762c90332b8228 --- lams_tool_forum/web/jsps/authoring/forum/editInstructions.jsp (.../editInstructions.jsp) (revision 7c2b1a8f06af3cbdb52aa229c170fb80ec2022ad) +++ lams_tool_forum/web/jsps/authoring/forum/editInstructions.jsp (.../editInstructions.jsp) (revision e16f09694ef763b1acafa32958762c90332b8228) @@ -32,15 +32,18 @@ FILE NAME TYPE - + - + + + + Index: lams_tool_forum/web/jsps/authoring/forum/instructions.jsp =================================================================== diff -u -r7c2b1a8f06af3cbdb52aa229c170fb80ec2022ad -re16f09694ef763b1acafa32958762c90332b8228 --- lams_tool_forum/web/jsps/authoring/forum/instructions.jsp (.../instructions.jsp) (revision 7c2b1a8f06af3cbdb52aa229c170fb80ec2022ad) +++ lams_tool_forum/web/jsps/authoring/forum/instructions.jsp (.../instructions.jsp) (revision e16f09694ef763b1acafa32958762c90332b8228) @@ -30,15 +30,18 @@ FILE NAME TYPE - + - + + + +