+
Index: lams_central/src/java/org/lamsfoundation/lams/authoring/service/AuthoringService.java
===================================================================
diff -u -r9bef1de27d0d527d75191115a535bc2c4311ade9 -r8628fad036956ba43219abfd392f4913069c3dd8
--- lams_central/src/java/org/lamsfoundation/lams/authoring/service/AuthoringService.java (.../AuthoringService.java) (revision 9bef1de27d0d527d75191115a535bc2c4311ade9)
+++ lams_central/src/java/org/lamsfoundation/lams/authoring/service/AuthoringService.java (.../AuthoringService.java) (revision 8628fad036956ba43219abfd392f4913069c3dd8)
@@ -75,7 +75,9 @@
import org.lamsfoundation.lams.util.wddx.FlashMessage;
import org.lamsfoundation.lams.util.wddx.WDDXProcessor;
+import com.allaire.wddx.WddxDeserializationException;
+
/**
* @author Manpreet Minhas
*/
@@ -480,10 +482,10 @@
if(learningDesignDTO!=null){
LearningDesign design = extractor.extractLearningDesignObject(learningDesignDTO);
learningDesignDAO.insert(design);
- flashMessage = new FlashMessage("storeLearningDesignDetails",design.getLearningDesignId());
+ flashMessage = new FlashMessage(IAuthoringService.STORE_LD_MESSAGE_KEY,design.getLearningDesignId());
}
else
- flashMessage = new FlashMessage("storeLearningDesignDetails",
+ flashMessage = new FlashMessage(IAuthoringService.STORE_LD_MESSAGE_KEY,
"Invalid Object in WDDX packet",
FlashMessage.ERROR);
@@ -547,9 +549,11 @@
* @param wddxPacket The WDDX packet received from Flash
* @return String The acknowledgement in WDDX format that the theme has been
* successfully saved.
+ * @throws IOException
+ * @throws WddxDeserializationException
* @throws Exception
*/
- public String storeTheme(String wddxPacket) throws Exception{
+ public String storeTheme(String wddxPacket) throws Exception {
if(containsNulls(wddxPacket)){
flashMessage = new FlashMessage("storeTheme",
@@ -579,7 +583,7 @@
}
themeDAO.saveOrUpdateTheme(storedTheme);
- flashMessage = new FlashMessage("storeTheme",storedTheme.getId());
+ flashMessage = new FlashMessage(IAuthoringService.STORE_THEME_MESSAGE_KEY,storedTheme.getId());
return flashMessage.serializeMessage();
}
Index: lams_central/src/java/org/lamsfoundation/lams/authoring/service/IAuthoringService.java
===================================================================
diff -u -r9bef1de27d0d527d75191115a535bc2c4311ade9 -r8628fad036956ba43219abfd392f4913069c3dd8
--- lams_central/src/java/org/lamsfoundation/lams/authoring/service/IAuthoringService.java (.../IAuthoringService.java) (revision 9bef1de27d0d527d75191115a535bc2c4311ade9)
+++ lams_central/src/java/org/lamsfoundation/lams/authoring/service/IAuthoringService.java (.../IAuthoringService.java) (revision 8628fad036956ba43219abfd392f4913069c3dd8)
@@ -24,6 +24,7 @@
import java.io.IOException;
import java.util.List;
+
import org.lamsfoundation.lams.learningdesign.LearningDesign;
import org.lamsfoundation.lams.learningdesign.exception.LearningDesignException;
import org.lamsfoundation.lams.usermanagement.User;
@@ -36,7 +37,12 @@
*/
public interface IAuthoringService {
+ /** Message key returned by the storeTheme() method */
+ public static final String STORE_THEME_MESSAGE_KEY = "storeTheme";
+ /** Message key returned by the storeLearningDesignDetails() method */
+ public static final String STORE_LD_MESSAGE_KEY = "storeLearningDesignDetails";
+
/**
* Returns a populated LearningDesign object corresponding to the given learningDesignID
*
Index: lams_central/src/java/org/lamsfoundation/lams/authoring/web/AuthoringAction.java
===================================================================
diff -u -r1ace59e69b84f2bd60f2a60b124abef279c55368 -r8628fad036956ba43219abfd392f4913069c3dd8
--- lams_central/src/java/org/lamsfoundation/lams/authoring/web/AuthoringAction.java (.../AuthoringAction.java) (revision 1ace59e69b84f2bd60f2a60b124abef279c55368)
+++ lams_central/src/java/org/lamsfoundation/lams/authoring/web/AuthoringAction.java (.../AuthoringAction.java) (revision 8628fad036956ba43219abfd392f4913069c3dd8)
@@ -29,46 +29,45 @@
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
+import org.apache.log4j.Logger;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.actions.DispatchAction;
import org.lamsfoundation.lams.authoring.service.IAuthoringService;
import org.lamsfoundation.lams.learningdesign.exception.LearningDesignException;
import org.lamsfoundation.lams.usermanagement.exception.UserException;
-import org.lamsfoundation.lams.util.WebUtil;
import org.lamsfoundation.lams.usermanagement.exception.WorkspaceFolderException;
+import org.lamsfoundation.lams.util.WebUtil;
import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;
-import java.io.BufferedReader;
-
/**
* @author Manpreet Minhas
*
* @struts.action name = "AuthoringAction"
- * path = "/author"
+ * path = "/authoring/author"
* parameter = "method"
* validate = "false"
* @struts.action-forward name = "success" path = "/index.jsp"
*
*/
public class AuthoringAction extends DispatchAction{
- /** If you want the output given as a jsp, set the request parameter "jspoutput" to
+ private static Logger log = Logger.getLogger(AuthoringAction.class);
+
+ /** If you want the output given as a jsp, set the request parameter "jspoutput" to
* some value other than an empty string (e.g. 1, true, 0, false, blah).
* If you want it returned as a stream (ie for Flash), do not define this parameter
*/
public static String USE_JSP_OUTPUT = "jspoutput";
- /** Complete Theme to be stored in the db */
- public static final String THEME_PARAMETER = "theme";
/** Id of theme to be retrieved from the db */
- public static final String THEME_ID_PARAMETER = "themeid";
-
+ public static final String THEME_ID_PARAMETER = "themeID";
+
public IAuthoringService getAuthoringService(){
WebApplicationContext webContext = WebApplicationContextUtils.getRequiredWebApplicationContext(this.getServlet().getServletContext());
- return (IAuthoringService) webContext.getBean("authoringService");
+ return (IAuthoringService) webContext.getBean(AuthoringConstants.AUTHORING_SERVICE_BEAN_NAME);
}
/** Output the supplied WDDX packet. If the request parameter USE_JSP_OUTPUT
@@ -138,17 +137,7 @@
String wddxPacket = authoringService.getAllLearningDesignDetails();
return outputPacket(mapping, request, response, wddxPacket, "details");
}
- public ActionForward storeLearningDesignDetails(ActionMapping mapping,
- ActionForm form,
- HttpServletRequest request,
- HttpServletResponse response)throws ServletException, Exception{
- // String designDetails = WebUtil.readStrParam(request,"designDetails");
- String designDetails = getBody(request);
- IAuthoringService authoringService = getAuthoringService();
- String message = authoringService.storeLearningDesignDetails(designDetails);
- request.getSession().setAttribute("message",message);
- return outputPacket(mapping, request, response, message, "message");
- }
+
public ActionForward getAllLearningLibraryDetails(ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
@@ -158,23 +147,7 @@
return outputPacket(mapping, request, response, wddxPacket, "details");
}
- /**
- * Store a theme created on a client.
- * @return String The acknowledgement in WDDX format that the theme has been
- * successfully saved.
- * @throws Exception
- */
- public ActionForward storeTheme(ActionMapping mapping,
- ActionForm form,
- HttpServletRequest request,
- HttpServletResponse response)throws ServletException, Exception{
- String theme = WebUtil.readStrParam(request,THEME_PARAMETER);
- IAuthoringService authoringService = getAuthoringService();
- String message = authoringService.storeTheme(theme);
- request.getSession().setAttribute("message",message);
- return outputPacket(mapping, request, response, message, "message");
- }
/**
* Returns a string representing the requested theme in WDDX format
@@ -215,20 +188,5 @@
return outputPacket(mapping, request, response, message, "message");
}
- /* Get the post body */
- private String getBody(HttpServletRequest req)
- throws IOException
- {
- BufferedReader tempReader = req.getReader();
- int tempContentLength = req.getContentLength();
- StringBuffer tempStrBuf = new StringBuffer( tempContentLength>0 ? tempContentLength : 200 );
- String tempStr;
- tempStr = tempReader.readLine();
- while ( tempStr != null )
- {
- tempStrBuf.append(tempStr);
- tempStr = tempReader.readLine();
- }
- return(tempStrBuf.toString());
- }
+
}
Index: lams_central/src/java/org/lamsfoundation/lams/authoring/web/AuthoringConstants.java
===================================================================
diff -u
--- lams_central/src/java/org/lamsfoundation/lams/authoring/web/AuthoringConstants.java (revision 0)
+++ lams_central/src/java/org/lamsfoundation/lams/authoring/web/AuthoringConstants.java (revision 8628fad036956ba43219abfd392f4913069c3dd8)
@@ -0,0 +1,35 @@
+/***************************************************************************
+ * 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.authoring.web;
+
+/**
+ * Constants used by Authoring.
+ *
+ * @author Fiona Malikoff
+ */
+public class AuthoringConstants {
+
+ /** Spring context name for refering to the authoring service */
+ public static final String AUTHORING_SERVICE_BEAN_NAME = "authoringService";
+
+}
Index: lams_central/src/java/org/lamsfoundation/lams/authoring/web/StoreLDServlet.java
===================================================================
diff -u
--- lams_central/src/java/org/lamsfoundation/lams/authoring/web/StoreLDServlet.java (revision 0)
+++ lams_central/src/java/org/lamsfoundation/lams/authoring/web/StoreLDServlet.java (revision 8628fad036956ba43219abfd392f4913069c3dd8)
@@ -0,0 +1,61 @@
+/***************************************************************************
+ * 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.authoring.web;
+
+import javax.servlet.http.HttpServletRequest;
+
+import org.apache.log4j.Logger;
+import org.lamsfoundation.lams.authoring.service.IAuthoringService;
+import org.lamsfoundation.lams.web.servlet.AbstractStoreWDDXPacketServlet;
+import org.springframework.web.context.WebApplicationContext;
+import org.springframework.web.context.support.WebApplicationContextUtils;
+
+/**
+ * Store a learning design.
+ *
+ * @author Fiona Malikoff
+ *
+ * @web:servlet name="storeLD"
+ * @web:servlet-mapping url-pattern="/authoring/storeLearningDesignDetails"
+ */
+public class StoreLDServlet extends AbstractStoreWDDXPacketServlet {
+
+ private static Logger log = Logger.getLogger(AuthoringAction.class);
+
+ public IAuthoringService getAuthoringService(){
+ WebApplicationContext webContext = WebApplicationContextUtils.getRequiredWebApplicationContext(getServletContext());
+ return (IAuthoringService) webContext.getBean(AuthoringConstants.AUTHORING_SERVICE_BEAN_NAME);
+ }
+
+ protected String process(String designDetails, HttpServletRequest request)
+ throws Exception
+ {
+
+ IAuthoringService authoringService = getAuthoringService();
+ return authoringService.storeLearningDesignDetails(designDetails);
+ }
+
+ protected String getMessageKey(String designDetails, HttpServletRequest request) {
+ return IAuthoringService.STORE_LD_MESSAGE_KEY;
+ }
+
+}
Index: lams_central/src/java/org/lamsfoundation/lams/authoring/web/StoreThemeServlet.java
===================================================================
diff -u
--- lams_central/src/java/org/lamsfoundation/lams/authoring/web/StoreThemeServlet.java (revision 0)
+++ lams_central/src/java/org/lamsfoundation/lams/authoring/web/StoreThemeServlet.java (revision 8628fad036956ba43219abfd392f4913069c3dd8)
@@ -0,0 +1,59 @@
+/***************************************************************************
+ * 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.authoring.web;
+
+import javax.servlet.http.HttpServletRequest;
+
+import org.apache.log4j.Logger;
+import org.lamsfoundation.lams.authoring.service.IAuthoringService;
+import org.lamsfoundation.lams.web.servlet.AbstractStoreWDDXPacketServlet;
+import org.springframework.web.context.WebApplicationContext;
+import org.springframework.web.context.support.WebApplicationContextUtils;
+
+/**
+ * Store a theme created on a client.
+ *
+ * @author Fiona Malikoff
+ *
+ * @web:servlet name="storeTheme"
+ * @web:servlet-mapping url-pattern="/authoring/storeTheme"
+ */
+public class StoreThemeServlet extends AbstractStoreWDDXPacketServlet {
+
+ private static Logger log = Logger.getLogger(StoreThemeServlet.class);
+
+ public IAuthoringService getAuthoringService(){
+ WebApplicationContext webContext = WebApplicationContextUtils.getRequiredWebApplicationContext(getServletContext());
+ return (IAuthoringService) webContext.getBean(AuthoringConstants.AUTHORING_SERVICE_BEAN_NAME);
+ }
+
+ protected String process(String theme, HttpServletRequest request)
+ throws Exception
+ {
+ IAuthoringService authoringService = getAuthoringService();
+ return authoringService.storeTheme(theme);
+ }
+
+ protected String getMessageKey(String theme, HttpServletRequest request) {
+ return IAuthoringService.STORE_THEME_MESSAGE_KEY;
+ }
+}
Index: lams_central/src/java/org/lamsfoundation/lams/web/development/WDDXPostAction.java
===================================================================
diff -u
--- lams_central/src/java/org/lamsfoundation/lams/web/development/WDDXPostAction.java (revision 0)
+++ lams_central/src/java/org/lamsfoundation/lams/web/development/WDDXPostAction.java (revision 8628fad036956ba43219abfd392f4913069c3dd8)
@@ -0,0 +1,117 @@
+package org.lamsfoundation.lams.web.development;
+
+import java.io.BufferedReader;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.io.PrintWriter;
+import java.io.Writer;
+import java.net.HttpURLConnection;
+import java.net.URL;
+
+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.upload.FormFile;
+
+
+/**
+ * Takes a action ( URL ) and a file containing a WDDX packet
+ * and forwards the contents of the WDDX packet to the action.
+ *
+ * This is used to simulate Flash sending a WDDX packet to
+ * the server.
+ *
+ * The error handling just throws a RuntimeException if something
+ * goes wrong. Not nice but this is only run during development....
+ *
+ * @struts:action name="WDDXPostActionForm"
+ * path="/WDDXPost"
+ * validate="false"
+ * parameter="method"
+ */
+public class WDDXPostAction extends Action {
+
+ private static Logger log = Logger.getLogger(WDDXPostAction.class);
+
+ /**
+ * Process the request
+ */
+ public ActionForward execute(ActionMapping mapping, ActionForm form,
+ HttpServletRequest req, HttpServletResponse res)
+ throws IOException, ServletException {
+
+ WDDXPostActionForm postForm = (WDDXPostActionForm) form;
+
+ String action = postForm.getUrlAction();
+ if ( action == null ) {
+ RuntimeException e = new RuntimeException("Unable to process WDDX file, action is missing. Should be a URL");
+ log.error(e);
+ throw e;
+ }
+
+ FormFile file = postForm.getWddxFile();
+ if ( file == null ) {
+ RuntimeException e = new RuntimeException("Unable to process WDDX file, file is missing.");
+ log.error(e);
+ throw e;
+ }
+
+ // we've got the URL action and the WDDX input. Now try sending the WDDX to the URL
+ URL url = new URL(action);
+ HttpURLConnection urlConn = (HttpURLConnection) url.openConnection();
+ urlConn.setRequestMethod("POST");
+ urlConn.setDoInput (true);
+ urlConn.setDoOutput (true);
+ urlConn.setUseCaches (false);
+ urlConn.setAllowUserInteraction(false);
+ urlConn.setInstanceFollowRedirects(true);
+
+ // Get packet from input file
+ ByteArrayOutputStream byteStream = new ByteArrayOutputStream(512); // Grows if necessary
+ PrintWriter urlStreamWriter = new PrintWriter(byteStream, true);
+ BufferedReader wddxPacketStream = new BufferedReader(new InputStreamReader(file.getInputStream()));
+ String line = null;
+ while ((line = wddxPacketStream.readLine()) != null) {
+ urlStreamWriter.print(line);
+ }
+ urlStreamWriter.flush();
+ wddxPacketStream.close();
+ String packet = byteStream.toString();
+ String packetStart = packet != null ? packet.substring(0,11): "";
+ if ( ! packetStart.equalsIgnoreCase(" tag. Invalid format.");
+ }
+ log.debug("Sending packet "+packet);
+
+ // POST requests are required to have Content-Length
+ String lengthString = String.valueOf(byteStream.size());
+ urlConn.setRequestProperty("Content-Length", lengthString);
+
+ // Write POST data to real output stream
+ byteStream.writeTo(urlConn.getOutputStream());
+ urlConn.getOutputStream().flush();
+ urlConn.connect();
+
+ // pass the response from the action back to the calling form.
+ BufferedReader in = new BufferedReader(new InputStreamReader(urlConn.getInputStream()));
+ Writer writer = res.getWriter();
+ while ((line = in.readLine()) != null) {
+ writer.write(line);
+ }
+ in.close();
+
+ urlConn.disconnect();
+
+ return null;
+ }
+
+
+
+}
\ No newline at end of file
Index: lams_central/src/java/org/lamsfoundation/lams/web/development/WDDXPostActionForm.java
===================================================================
diff -u
--- lams_central/src/java/org/lamsfoundation/lams/web/development/WDDXPostActionForm.java (revision 0)
+++ lams_central/src/java/org/lamsfoundation/lams/web/development/WDDXPostActionForm.java (revision 8628fad036956ba43219abfd392f4913069c3dd8)
@@ -0,0 +1,63 @@
+package org.lamsfoundation.lams.web.development;
+
+import javax.servlet.http.HttpServletRequest;
+
+import org.apache.log4j.Logger;
+import org.apache.struts.action.ActionForm;
+import org.apache.struts.action.ActionMapping;
+import org.apache.struts.upload.FormFile;
+
+/**
+ * @author fmalikoff
+ *
+ * @struts:form name="WDDXPostActionForm"
+ * include-pk="true"
+ * include-all="true"
+ */
+public class WDDXPostActionForm extends ActionForm {
+
+ public static final String formName = "WDDXPostActionForm"; // must match name in @struts:action section above
+
+ private static Logger log = Logger.getLogger(WDDXPostActionForm.class);
+
+ /**
+ * @return Returns the action.
+ */
+ public String getUrlAction() {
+ return urlAction;
+ }
+ /**
+ * @param action The action to set.
+ */
+ public void setUrlAction(String action) {
+ this.urlAction = action;
+ }
+ /**
+ * @return Returns the wddxFile.
+ */
+ public FormFile getWddxFile() {
+ return wddxFile;
+ }
+ /**
+ * @param wddxFile The wddxFile to set.
+ */
+ public void setWddxFile(FormFile wddxFile) {
+ this.wddxFile = wddxFile;
+ }
+ private String urlAction;
+ private FormFile wddxFile;
+
+ public WDDXPostActionForm() {
+ }
+
+ /**
+ * Reset all properties to their default values.
+ *
+ * @param mapping The mapping used to select this instance
+ * @param request The servlet request we are processing
+ */
+ public void reset(ActionMapping mapping, HttpServletRequest request) {
+ }
+
+
+}
\ No newline at end of file
Index: lams_central/test/java/org/lamsfoundation/lams/authoring/service/TestAuthoringService.java
===================================================================
diff -u -r9bef1de27d0d527d75191115a535bc2c4311ade9 -r8628fad036956ba43219abfd392f4913069c3dd8
--- lams_central/test/java/org/lamsfoundation/lams/authoring/service/TestAuthoringService.java (.../TestAuthoringService.java) (revision 9bef1de27d0d527d75191115a535bc2c4311ade9)
+++ lams_central/test/java/org/lamsfoundation/lams/authoring/service/TestAuthoringService.java (.../TestAuthoringService.java) (revision 8628fad036956ba43219abfd392f4913069c3dd8)
@@ -85,13 +85,15 @@
String packet = authService.getAllLearningLibraryDetails();
System.out.println("Library Details: "+ packet);
}
- public void testStoreLearningDesignDetails() throws Exception{
- String str = authService.storeLearningDesignDetails(LEARNING_DESIGN_PART_A+"-111111"+LEARNING_DESIGN_PART_B);
+ public void testStoreLearningDesignDetails() throws Exception{
+ String design = LEARNING_DESIGN_PART_A+"-111111"+LEARNING_DESIGN_PART_B;
+ String str = authService.storeLearningDesignDetails(design);
assertTrue("storeLearningDesignDetails returned WDDX packet", str!=null && str.startsWith("