Index: lams_build/lib/lams/lams-learning.jar =================================================================== diff -u -rfdca3605f0b782b19e214abbe94df6f4a457b88e -r2a3453f202cde32a5df77825700a0d1b06fde070 Binary files differ Index: lams_learning/src/java/org/lamsfoundation/lams/learning/export/web/action/CustomToolImageBundler.java =================================================================== diff -u --- lams_learning/src/java/org/lamsfoundation/lams/learning/export/web/action/CustomToolImageBundler.java (revision 0) +++ lams_learning/src/java/org/lamsfoundation/lams/learning/export/web/action/CustomToolImageBundler.java (revision 2a3453f202cde32a5df77825700a0d1b06fde070) @@ -0,0 +1,72 @@ +package org.lamsfoundation.lams.learning.export.web.action; + +import java.io.File; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.net.MalformedURLException; +import javax.servlet.http.Cookie; +import javax.servlet.http.HttpServletRequest; + +import org.lamsfoundation.lams.util.HttpUrlConnectionUtil; +import org.lamsfoundation.lams.learning.export.web.action.Bundler; + +/** + * This class originally was made for bundling gmap images for export portfolio + * But now can be used for any tool that requires custom images + * + * @author lfoxton + * + */ +public class CustomToolImageBundler extends Bundler +{ + + public CustomToolImageBundler() {} + + /** + * 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 + * @param toolImageUrlDir the url location of the images directory + * @param fileNames an array of file-names (not paths) you wish to include in the bundle + * @throws Exception + */ + public void bundle(HttpServletRequest request, Cookie[] cookies, String outputDirectory, String toolImageUrlDir, String[] fileNames) throws Exception + { + bundleViaHTTP(request, cookies, outputDirectory, toolImageUrlDir, fileNames); + } + + /** + * See bundle + * + * @param request + * @param cookies + * @param outputDirectory + * @param toolImageUrlDir + * @param fileNames + * @throws MalformedURLException + * @throws FileNotFoundException + * @throws IOException + */ + private void bundleViaHTTP(HttpServletRequest request, Cookie[] cookies, String outputDirectory, String toolImageUrlDir, String[] fileNames) + throws MalformedURLException, FileNotFoundException, IOException + { + + String imagesDirStr = outputDirectory+File.separator+"tool_images"; + File imagesDir = new File(imagesDirStr); + imagesDir.mkdirs(); + + for (String imageName : fileNames) + { + String url = toolImageUrlDir + imageName; + HttpUrlConnectionUtil.writeResponseToFile(url, imagesDirStr, imageName , cookies); //cookies aren't really needed here. + + log.debug("Copying image from source: " + url + "to desitnation: " + imagesDirStr); + } + } + +} + + +