Index: lams_learning/src/java/org/lamsfoundation/lams/learning/export/web/action/Bundler.java =================================================================== RCS file: /usr/local/cvsroot/lams_learning/src/java/org/lamsfoundation/lams/learning/export/web/action/Bundler.java,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ lams_learning/src/java/org/lamsfoundation/lams/learning/export/web/action/Bundler.java 8 Apr 2008 03:32:33 -0000 1.1 @@ -0,0 +1,104 @@ +/**************************************************************** + * 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: Bundler.java,v 1.1 2008/04/08 03:32:33 fmalikoff Exp $ */ +package org.lamsfoundation.lams.learning.export.web.action; + +import java.io.BufferedInputStream; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.OutputStream; +import java.util.List; + +import org.apache.log4j.Logger; + +/** + * Superclass for any files "bundled" as part of the export portfolio. For code reuse. + * + */ +public class Bundler { + + protected static Logger log = Logger.getLogger(Bundler.class); + + /** + * + */ + public Bundler() { + super(); + } + + protected void createDirectories(List directoriesRequired) { + + for ( String directoryPath: directoriesRequired) { + File dir = new File(directoryPath); + if ( ! dir.mkdirs() ) { + log.error("Unable to create directory for export portfolio: "+directoryPath); + } + } + } + + protected void copyFile(String filePath, File file) throws IOException { + + FileInputStream is = new FileInputStream(file); + OutputStream os = null; + try { + + int bufLen = 1024; // 1 Kbyte + byte[] buf = new byte[1024]; // output buffer + os = new FileOutputStream(filePath); + + BufferedInputStream in = new BufferedInputStream(is); + int len = 0; + while((len = in.read(buf,0,bufLen)) != -1){ + os.write(buf,0,len); + } + + } catch ( IOException e ) { + String message = "Unable to write out file needed for export portfolio. File was "+filePath; + log.error(message,e); + throw e; + + } finally { + + try { + if ( is != null ) + is.close(); + } catch (IOException e1) { + String message = "Unable to close input export portfolio file due to IOException"; + log.warn(message,e1); + } + + try { + if ( os != null ) + os.close(); + } catch (IOException e2) { + String message = "Unable to close output export portfolio file due to IOException"; + log.warn(message,e2); + } + } + + + } + +} \ No newline at end of file Index: lams_learning/src/java/org/lamsfoundation/lams/learning/export/web/action/CSSBundler.java =================================================================== RCS file: /usr/local/cvsroot/lams_learning/src/java/org/lamsfoundation/lams/learning/export/web/action/CSSBundler.java,v diff -u -r1.8 -r1.9 --- lams_learning/src/java/org/lamsfoundation/lams/learning/export/web/action/CSSBundler.java 23 May 2007 00:04:01 -0000 1.8 +++ lams_learning/src/java/org/lamsfoundation/lams/learning/export/web/action/CSSBundler.java 8 Apr 2008 03:32:33 -0000 1.9 @@ -24,13 +24,9 @@ package org.lamsfoundation.lams.learning.export.web.action; -import java.io.BufferedInputStream; import java.io.File; -import java.io.FileInputStream; import java.io.FileNotFoundException; -import java.io.FileOutputStream; import java.io.IOException; -import java.io.OutputStream; import java.net.MalformedURLException; import java.util.ArrayList; import java.util.Collection; @@ -41,27 +37,25 @@ import javax.servlet.http.Cookie; import javax.servlet.http.HttpServletRequest; -import org.apache.log4j.Logger; import org.lamsfoundation.lams.themes.CSSThemeVisualElement; import org.lamsfoundation.lams.util.Configuration; import org.lamsfoundation.lams.util.ConfigurationKeys; import org.lamsfoundation.lams.util.HttpUrlConnectionUtil; import org.lamsfoundation.lams.web.filter.LocaleFilter; -public class CSSBundler { +public class CSSBundler extends Bundler { - private static Logger log = Logger.getLogger(CSSBundler.class); private static final String RTL_DIR = "rtl"; // right-to-left direction Map filesToCopy = null; - List directoriesRequired = null; HttpServletRequest request = null; Cookie[] cookies = null; String outputDirectory = null; String centralPath = null; boolean rtl = false; Collection themes = null; - + List directoriesRequired; + /** * @param centralPath the directory path to the lams-central.war. Assumes that it is an expanded war. */ @@ -155,7 +149,7 @@ setupImageList(); // now copy all those files - createDirectories(); + createDirectories(directoriesRequired); for ( Map.Entry fileEntry : filesToCopy.entrySet() ) { copyFile((String)fileEntry.getKey(), (File)fileEntry.getValue()); } @@ -221,57 +215,4 @@ } } - - private void createDirectories() { - - for ( String directoryPath: directoriesRequired) { - File dir = new File(directoryPath); - if ( ! dir.mkdirs() ) { - log.error("Unable to create directory for export portfolio: "+directoryPath); - } - } - } - - private void copyFile(String filePath, File file) throws IOException { - - FileInputStream is = new FileInputStream(file); - OutputStream os = null; - try { - - int bufLen = 1024; // 1 Kbyte - byte[] buf = new byte[1024]; // output buffer - os = new FileOutputStream(filePath); - - BufferedInputStream in = new BufferedInputStream(is); - int len = 0; - while((len = in.read(buf,0,bufLen)) != -1){ - os.write(buf,0,len); - } - - } catch ( IOException e ) { - String message = "Unable to write out file needed for export portfolio. File was "+filePath; - log.error(message,e); - throw e; - - } finally { - - try { - if ( is != null ) - is.close(); - } catch (IOException e1) { - String message = "Unable to close input export portfolio file due to IOException"; - log.warn(message,e1); - } - - try { - if ( os != null ) - os.close(); - } catch (IOException e2) { - String message = "Unable to close output export portfolio file due to IOException"; - log.warn(message,e2); - } - } - - - } } Index: lams_learning/src/java/org/lamsfoundation/lams/learning/export/web/action/ImageBundler.java =================================================================== RCS file: /usr/local/cvsroot/lams_learning/src/java/org/lamsfoundation/lams/learning/export/web/action/ImageBundler.java,v diff -u -r1.1 -r1.2 --- lams_learning/src/java/org/lamsfoundation/lams/learning/export/web/action/ImageBundler.java 8 Feb 2008 00:53:39 -0000 1.1 +++ lams_learning/src/java/org/lamsfoundation/lams/learning/export/web/action/ImageBundler.java 8 Apr 2008 03:32:33 -0000 1.2 @@ -41,22 +41,23 @@ /** * Auxiliary class for supporting portfolio export. Copying all images and files - * uploaded by user into export temporary folder. + * uploaded by user into export temporary folder, plus the FCKEditor smileys, plus + * a few misc common images. * * @author AndreyB * */ -public class ImageBundler { +public class ImageBundler extends Bundler { private static Logger log = Logger.getLogger(ImageBundler.class); + private static String[] miscImages = new String[] {"fred.gif", "cross.gif", "error.jpg", "spacer.gif", "tick.gif", "tree_closed.gif", "tree_open.gif" }; Map filesToCopy = null; List directoriesRequired = null; String outputDirectory = null; String contentFolderId = null; String lamsWwwPath = null; String lamsCentralPath = null; - /** * @param outputDirectory directory for the export * @param contentFolderId the 32-character content folder name @@ -96,13 +97,16 @@ File central = new File(lamsCentralPath); if ( lamsCentralPath != null && central.canRead() && central.isDirectory() ) { log.debug("Copying FCKeditor smileys from path " + lamsCentralPath); - // build up a list of images to copy setupFCKEditorSmileysList(); + + // build up a list of the misc images to copy + setupMiscImages(); } + // now copy all those files - createDirectories(); + createDirectories(directoriesRequired); for ( Map.Entry fileEntry : filesToCopy.entrySet() ) { copyFile((String)fileEntry.getKey(), (File)fileEntry.getValue()); } @@ -176,58 +180,27 @@ } } } - - private void createDirectories() { - - for ( String directoryPath: directoriesRequired) { - File dir = new File(directoryPath); - if ( ! dir.mkdirs() ) { - log.error("Unable to create directory for export portfolio: "+directoryPath); - } - } - } - private void copyFile(String filePath, File file) throws IOException { + /** + * Creates list of misc image files that should be exported. + */ + private void setupMiscImages() { + String imageDirectory = lamsCentralPath+File.separatorChar+"images"; + String outputImageDirectory = outputDirectory+File.separatorChar+"images"; - FileInputStream is = new FileInputStream(file); - OutputStream os = null; - try { - - int bufLen = 1024; // 1 Kbyte - byte[] buf = new byte[1024]; // output buffer - os = new FileOutputStream(filePath); + directoriesRequired.add(outputImageDirectory); - BufferedInputStream in = new BufferedInputStream(is); - int len = 0; - while((len = in.read(buf,0,bufLen)) != -1){ - os.write(buf,0,len); - } + for ( String imageName: miscImages) { + String inputFilename = imageDirectory + File.separatorChar + imageName; + String outputFilename = outputImageDirectory + File.separatorChar + imageName; - } catch ( IOException e ) { - String message = "Unable to write out file needed for export portfolio. File was "+filePath; - log.error(message,e); - throw e; - - } finally { - - try { - if ( is != null ) - is.close(); - } catch (IOException e1) { - String message = "Unable to close input export portfolio file due to IOException"; - log.warn(message,e1); + File image = new File(inputFilename); + if ( ! image.canRead() || image.isDirectory() ) { + log.error("Unable to copy image "+inputFilename+" as file does not exist or cannot be read as a file."); + } else { + filesToCopy.put(outputFilename,image); } - - try { - if ( os != null ) - os.close(); - } catch (IOException e2) { - String message = "Unable to close output export portfolio file due to IOException"; - log.warn(message,e2); - } } - - } }