Index: lams_tool_forum/src/java/org/lamsfoundation/lams/tool/forum/util/ForumBundler.java =================================================================== diff -u --- lams_tool_forum/src/java/org/lamsfoundation/lams/tool/forum/util/ForumBundler.java (revision 0) +++ lams_tool_forum/src/java/org/lamsfoundation/lams/tool/forum/util/ForumBundler.java (revision 010304d6eaa3ba838d1f7539be292247a4d9262a) @@ -0,0 +1,123 @@ +/**************************************************************** + * 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 + * **************************************************************** + */ + +/* $Id$ */ +package org.lamsfoundation.lams.tool.forum.util; + +import java.io.File; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.net.MalformedURLException; +import java.util.ArrayList; +import java.util.List; + +import javax.servlet.http.Cookie; +import javax.servlet.http.HttpServletRequest; + +import org.lamsfoundation.lams.learning.export.web.action.Bundler; +import org.lamsfoundation.lams.util.Configuration; +import org.lamsfoundation.lams.util.ConfigurationKeys; +import org.lamsfoundation.lams.util.HttpUrlConnectionUtil; + +public class ForumBundler extends Bundler { + + private static final char URL_SEPARATOR = '/'; + + public ForumBundler() { + } + + /** + * This method bundles the files to the given output dir + * + * @param request + * the request for the export + * @param cookies + * cookies for the request + * @param outputDirectory + * the location where the files should be written + * @throws Exception + */ + public void bundle(HttpServletRequest request, Cookie[] cookies, String outputDirectory) throws Exception { + bundleViaHTTP(request, cookies, outputDirectory); + } + + /** + * See bundle + * + * @param request + * @param cookies + * @param outputDirectory + * @throws MalformedURLException + * @throws FileNotFoundException + * @throws IOException + */ + private void bundleViaHTTP(HttpServletRequest request, Cookie[] cookies, String outputDirectory) + throws MalformedURLException, FileNotFoundException, IOException { + String[] directoryNames = { "javascript", "images", "css" }; + List directories = new ArrayList(); + for (String directoryName : directoryNames) { + directories.add(outputDirectory + File.separator + directoryName); + } + this.createDirectories(directories); + + String[] imageNames = new String[] { "bg_jRatingInfos.png", "small.png", "stars.png" }; + for (String imageName : imageNames) { + String urlToConnectTo = getToolFolder() + "images" + URL_SEPARATOR + imageName; + String directoryToStoreFile = outputDirectory + File. separator + "images"; + HttpUrlConnectionUtil.writeResponseToFile(urlToConnectTo, directoryToStoreFile, imageName, cookies);// cookies aren't really needed here. + } + + final String includesFolder = getToolFolder() + "includes" + URL_SEPARATOR; + + // JS files + String urlToConnectTo = includesFolder + "javascript" + URL_SEPARATOR + "jquery.js"; + String directoryToStoreFile = outputDirectory + File.separator + "javascript"; + HttpUrlConnectionUtil.writeResponseToFile(urlToConnectTo, directoryToStoreFile, "jquery.js", cookies); + urlToConnectTo = includesFolder + "javascript" + URL_SEPARATOR + "jRating.jquery.js"; + directoryToStoreFile = outputDirectory + File.separator + "javascript"; + HttpUrlConnectionUtil.writeResponseToFile(urlToConnectTo, directoryToStoreFile, "jRating.jquery.js", cookies); + + //CSS files + urlToConnectTo = includesFolder + "css" + URL_SEPARATOR + "jRating.jquery.css"; + directoryToStoreFile = outputDirectory + File.separator + "css"; + HttpUrlConnectionUtil.writeResponseToFile(urlToConnectTo, directoryToStoreFile, "jRating.jquery.css", cookies); + urlToConnectTo = includesFolder + "css" + URL_SEPARATOR + "ratingStars.css"; + directoryToStoreFile = outputDirectory + File.separator + "css"; + HttpUrlConnectionUtil.writeResponseToFile(urlToConnectTo, directoryToStoreFile, "ratingStars.css", cookies); + + } + + private String getToolFolder() { + String serverUrlPath = Configuration.get(ConfigurationKeys.SERVER_URL); + if (serverUrlPath == null) { + log.error("Unable to get path to the LAMS Server URL from the configuration table. Q&A javascript files export failed"); + return ""; + } else { + if (!serverUrlPath.endsWith("/")) { + serverUrlPath += "/"; + } + + return serverUrlPath + "tool" + URL_SEPARATOR + ForumConstants.TOOL_SIGNATURE + URL_SEPARATOR; + } + } + +} Index: lams_tool_forum/src/java/org/lamsfoundation/lams/tool/forum/web/actions/ExportServlet.java =================================================================== diff -u -ra9209010ffcac47d0f6f3e529335d133c2374130 -r010304d6eaa3ba838d1f7539be292247a4d9262a --- lams_tool_forum/src/java/org/lamsfoundation/lams/tool/forum/web/actions/ExportServlet.java (.../ExportServlet.java) (revision a9209010ffcac47d0f6f3e529335d133c2374130) +++ lams_tool_forum/src/java/org/lamsfoundation/lams/tool/forum/web/actions/ExportServlet.java (.../ExportServlet.java) (revision 010304d6eaa3ba838d1f7539be292247a4d9262a) @@ -55,6 +55,7 @@ import org.lamsfoundation.lams.tool.forum.persistence.ForumUser; import org.lamsfoundation.lams.tool.forum.service.ForumServiceProxy; import org.lamsfoundation.lams.tool.forum.service.IForumService; +import org.lamsfoundation.lams.tool.forum.util.ForumBundler; import org.lamsfoundation.lams.tool.forum.util.ForumConstants; import org.lamsfoundation.lams.tool.forum.util.ForumToolContentHandler; import org.lamsfoundation.lams.usermanagement.dto.UserDTO; @@ -126,6 +127,15 @@ teacher(request,response,directoryName,cookies,sessionMap); } + // Attempting to export required images + try { + ForumBundler forumBundler = new ForumBundler(); + forumBundler.bundle(request, cookies, directoryName); + + } catch (Exception e) { + logger.error("Could not export Q&A javascript files, some files may be missing in export portfolio", e); + } + String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+request.getContextPath(); writeResponseToFile(basePath+"/jsps/export/exportportfolio.jsp?sessionMapID="+sessionMap.getSessionID() ,directoryName,FILENAME,cookies); @@ -175,6 +185,7 @@ sessionTopicMap.put(session.getSessionName(), pair); sessionMap.put(ForumConstants.ATTR_TOOL_CONTENT_TOPICS, sessionTopicMap); + sessionMap.put(ForumConstants.ATTR_ALLOW_RATE_MESSAGES, content.isAllowRateMessages()); // Set forum title sessionMap.put(ForumConstants.ATTR_FORUM_TITLE, content.getTitle()); @@ -225,6 +236,7 @@ topicsByUser.put(session.getSessionName(), pair); } sessionMap.put(ForumConstants.ATTR_TOOL_CONTENT_TOPICS,topicsByUser); + sessionMap.put(ForumConstants.ATTR_ALLOW_RATE_MESSAGES, content.isAllowRateMessages()); // Set forum title sessionMap.put(ForumConstants.ATTR_FORUM_TITLE, content.getTitle()); Index: lams_tool_forum/web/jsps/export/exportportfolio.jsp =================================================================== diff -u -r11ee5cc4fa5bb15f77be3f81056a9437c9e7c602 -r010304d6eaa3ba838d1f7539be292247a4d9262a --- lams_tool_forum/web/jsps/export/exportportfolio.jsp (.../exportportfolio.jsp) (revision 11ee5cc4fa5bb15f77be3f81056a9437c9e7c602) +++ lams_tool_forum/web/jsps/export/exportportfolio.jsp (.../exportportfolio.jsp) (revision 010304d6eaa3ba838d1f7539be292247a4d9262a) @@ -12,6 +12,22 @@ + + + + + + + @@ -115,6 +131,15 @@ + + + +
+ <%@ include file="/jsps/learning/rating/ratingStarsDisabled.jsp"%> +
+ + +