From: <luc...@us...> - 2013-10-21 13:45:48
|
Revision: 4430 http://openutils.svn.sourceforge.net/openutils/?rev=4430&view=rev Author: lucaboati Date: 2013-10-21 13:45:43 +0000 (Mon, 21 Oct 2013) Log Message: ----------- fix for 4.5, read file from temp folder Modified Paths: -------------- magnoliamodules/trunk/openutils-mgnllms/src/main/java/net/sourceforge/openutils/mgnllms/filters/AggregatorServingZipFilter.java magnoliamodules/trunk/openutils-mgnllms/src/main/java/net/sourceforge/openutils/mgnllms/filters/RenderingServingZipFilter.java magnoliamodules/trunk/openutils-mgnllms/src/main/resources/mgnl-bootstrap/mgnllms/config.modules.mgnllms.virtualURIMapping.persistence.xml magnoliamodules/trunk/openutils-mgnllms/src/main/resources/mgnl-bootstrap/mgnllms/config.modules.mgnllms.virtualURIMapping.player.xml magnoliamodules/trunk/openutils-mgnllms/src/main/resources/mgnl-files/templates/samples-lms/courses.jsp magnoliamodules/trunk/openutils-mgnllms/src/main/resources/mgnl-files/templates/samples-lms/index.jsp Modified: magnoliamodules/trunk/openutils-mgnllms/src/main/java/net/sourceforge/openutils/mgnllms/filters/AggregatorServingZipFilter.java =================================================================== --- magnoliamodules/trunk/openutils-mgnllms/src/main/java/net/sourceforge/openutils/mgnllms/filters/AggregatorServingZipFilter.java 2013-10-21 12:24:28 UTC (rev 4429) +++ magnoliamodules/trunk/openutils-mgnllms/src/main/java/net/sourceforge/openutils/mgnllms/filters/AggregatorServingZipFilter.java 2013-10-21 13:45:43 UTC (rev 4430) @@ -1,7 +1,7 @@ -/** +/** * * E-learning Module for Magnolia CMS (http://www.openmindlab.com/lab/products/lms.html) - * Copyright(C) 2010-2013, Openmind S.r.l. http://www.openmindonline.it + * Copyright(C) 2010-2011, Openmind S.r.l. http://www.openmindonline.it * * 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 @@ -16,6 +16,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ + package net.sourceforge.openutils.mgnllms.filters; import info.magnolia.cms.beans.runtime.File; @@ -27,7 +28,6 @@ import info.magnolia.cms.filters.AggregatorFilter; import info.magnolia.context.MgnlContext; -import javax.jcr.PathNotFoundException; import javax.jcr.PropertyType; import javax.jcr.RepositoryException; @@ -67,7 +67,7 @@ { nonExistingN = hm.getNodeData(handleToCheck); } - catch (PathNotFoundException e) + catch (Exception e) { // go on } Modified: magnoliamodules/trunk/openutils-mgnllms/src/main/java/net/sourceforge/openutils/mgnllms/filters/RenderingServingZipFilter.java =================================================================== --- magnoliamodules/trunk/openutils-mgnllms/src/main/java/net/sourceforge/openutils/mgnllms/filters/RenderingServingZipFilter.java 2013-10-21 12:24:28 UTC (rev 4429) +++ magnoliamodules/trunk/openutils-mgnllms/src/main/java/net/sourceforge/openutils/mgnllms/filters/RenderingServingZipFilter.java 2013-10-21 13:45:43 UTC (rev 4430) @@ -1,7 +1,7 @@ /** * * E-learning Module for Magnolia CMS (http://www.openmindlab.com/lab/products/lms.html) - * Copyright(C) 2010-2013, Openmind S.r.l. http://www.openmindonline.it + * Copyright(C) 2010-2011, Openmind S.r.l. http://www.openmindonline.it * * 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 @@ -16,6 +16,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ + package net.sourceforge.openutils.mgnllms.filters; import info.magnolia.cms.core.AggregationState; @@ -26,12 +27,16 @@ import info.magnolia.rendering.engine.RenderingFilter; import info.magnolia.rendering.template.registry.TemplateDefinitionRegistry; +import java.io.BufferedInputStream; +import java.io.BufferedOutputStream; +import java.io.ByteArrayInputStream; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.util.Enumeration; import java.util.zip.ZipEntry; +import java.util.zip.ZipException; import java.util.zip.ZipFile; import javax.jcr.PathNotFoundException; @@ -42,6 +47,7 @@ import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; +import org.apache.commons.io.FileUtils; import org.apache.commons.io.IOUtils; import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.math.NumberUtils; @@ -62,7 +68,9 @@ */ private Logger log = LoggerFactory.getLogger(RenderingServingZipFilter.class); - public RenderingServingZipFilter(RenderingEngine renderingEngine, TemplateDefinitionRegistry templateDefinitionRegistry) + public RenderingServingZipFilter( + RenderingEngine renderingEngine, + TemplateDefinitionRegistry templateDefinitionRegistry) { super(renderingEngine, templateDefinitionRegistry); } @@ -82,28 +90,39 @@ HierarchyManager hm = MgnlContext.getHierarchyManager(aggregationState.getRepository()); + String tempDir = System.getProperty("java.io.tmpdir"); + File parentFile = new File(tempDir); + if (!parentFile.exists()) + { + parentFile.mkdirs(); + } + InputStream is = null; try { + + String zippedResourceURI = StringUtils.substringAfter(aggregationState.getCurrentURI(), resourceHandle); + if (StringUtils.isBlank(zippedResourceURI)) + { + zippedResourceURI = "/"; + } + zippedResourceURI = zippedResourceURI.substring(1); + String fileName = aggregationState.getFile().getFileName() + "." + aggregationState.getFile().getExtension(); - is = getNodedataAstream(resourceHandle, hm, response); - if (null != is) + + File requestResource = new File(parentFile, fileName); + if (!requestResource.exists()) { + is = getNodedataAstream(resourceHandle, hm, response); + } + if (null != is || requestResource.exists()) + { if ("zip".equals(aggregationState.getFile().getExtension())) { - String zippedResourceURI = StringUtils.substringAfter( - aggregationState.getCurrentURI(), - resourceHandle); - if (StringUtils.isBlank(zippedResourceURI)) - { - zippedResourceURI = "/"; - } - zippedResourceURI = zippedResourceURI.substring(1); - File temp = null; try { @@ -124,50 +143,74 @@ } else { - temp = File.createTempFile(fileName, ".zip"); - FileOutputStream fos = new FileOutputStream(temp); - IOUtils.copy(is, fos); - IOUtils.closeQuietly(fos); - IOUtils.closeQuietly(is); - - ZipFile zip = new ZipFile(temp); - - Enumeration< ? extends ZipEntry> entries = zip.entries(); - while (entries.hasMoreElements()) + temp = new File(parentFile, fileName); + if (!temp.exists()) { - ZipEntry entry = entries.nextElement(); + temp = new File(parentFile, fileName); - String path = entry.getName(); + FileOutputStream fos = new FileOutputStream(temp); + IOUtils.copy(is, fos); - if (zippedResourceURI.equals(path)) - { + unZipIt(fileName, tempDir); - InputStream inputStream = zip.getInputStream(entry); - response.setContentLength(((int) entry.getSize())); - sendUnCompressed(inputStream, response); - IOUtils.closeQuietly(inputStream); + IOUtils.closeQuietly(fos); + IOUtils.closeQuietly(is); - return; - - } } - log.debug("Resource not found, redirecting request for [{}] to 404 URI", request - .getRequestURI()); - if (!response.isCommitted()) + String newPath = temp.getAbsolutePath().substring( + 0, + temp.getAbsolutePath().length() - 4); + File requestFile = new File(newPath, zippedResourceURI); + if (requestFile.exists()) { - response.sendError(HttpServletResponse.SC_NOT_FOUND); + is = new ByteArrayInputStream(FileUtils.readFileToByteArray(requestFile)); + response.setContentLength(((int) requestFile.length())); + sendUnCompressed(is, response); + IOUtils.closeQuietly(is); + return; } - else - { - log.info( - "Unable to redirect to 404 page, response is already committed. URI was {}", - request.getRequestURI()); - } - // stop the chain - return; + } + + // ZipFile zip = new ZipFile(temp); + // + // Enumeration< ? extends ZipEntry> entries = zip.entries(); + // while (entries.hasMoreElements()) + // { + // ZipEntry entry = entries.nextElement(); + // + // String path = entry.getName(); + // + // if (zippedResourceURI.equals(path)) + // { + // + // InputStream inputStream = zip.getInputStream(entry); + // response.setContentLength(((int) entry.getSize())); + // sendUnCompressed(inputStream, response); + // IOUtils.closeQuietly(inputStream); + // + // return; + // + // } + // } + log.debug( + "Resource not found, redirecting request for [{}] to 404 URI", + request.getRequestURI()); + + if (!response.isCommitted()) + { + response.sendError(HttpServletResponse.SC_NOT_FOUND); + } + else + { + log.info( + "Unable to redirect to 404 page, response is already committed. URI was {}", + request.getRequestURI()); + } + // stop the chain + return; } catch (IOException e) { @@ -178,7 +221,7 @@ IOUtils.closeQuietly(is); if (temp != null) { - temp.delete(); + // temp.delete(); } } } @@ -221,6 +264,77 @@ } } + private void unZipIt(String zipFile, String tempDir) + { + + zipFile = tempDir + File.separator + zipFile; + log.debug(zipFile); + int BUFFER = 2048; + File file = new File(zipFile); + + ZipFile zip; + try + { + zip = new ZipFile(file); + + String newPath = zipFile.substring(0, zipFile.length() - 4); + + new File(newPath).mkdir(); + Enumeration zipFileEntries = zip.entries(); + + // Process each entry + while (zipFileEntries.hasMoreElements()) + { + // grab a zip file entry + ZipEntry entry = (ZipEntry) zipFileEntries.nextElement(); + String currentEntry = entry.getName(); + File destFile = new File(newPath, currentEntry); + // destFile = new File(newPath, destFile.getName()); + File destinationParent = destFile.getParentFile(); + + // create the parent directory structure if needed + destinationParent.mkdirs(); + + if (!entry.isDirectory()) + { + BufferedInputStream is = new BufferedInputStream(zip.getInputStream(entry)); + int currentByte; + // establish buffer for writing file + byte data[] = new byte[BUFFER]; + + // write the current file to disk + FileOutputStream fos = new FileOutputStream(destFile); + BufferedOutputStream dest = new BufferedOutputStream(fos, BUFFER); + + // read and write until last byte is encountered + while ((currentByte = is.read(data, 0, BUFFER)) != -1) + { + dest.write(data, 0, currentByte); + } + dest.flush(); + dest.close(); + is.close(); + } + +// if (currentEntry.endsWith(".zip")) +// { +// // found a zip file, try to open +// extractFolder(destFile.getAbsolutePath()); +// } + } + } + catch (ZipException e) + { + // TODO Auto-generated catch block + e.printStackTrace(); + } + catch (IOException e) + { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + /** * Send data as is. * @param is Input stream for the resource Modified: magnoliamodules/trunk/openutils-mgnllms/src/main/resources/mgnl-bootstrap/mgnllms/config.modules.mgnllms.virtualURIMapping.persistence.xml =================================================================== (Binary files differ) Modified: magnoliamodules/trunk/openutils-mgnllms/src/main/resources/mgnl-bootstrap/mgnllms/config.modules.mgnllms.virtualURIMapping.player.xml =================================================================== (Binary files differ) Modified: magnoliamodules/trunk/openutils-mgnllms/src/main/resources/mgnl-files/templates/samples-lms/courses.jsp =================================================================== --- magnoliamodules/trunk/openutils-mgnllms/src/main/resources/mgnl-files/templates/samples-lms/courses.jsp 2013-10-21 12:24:28 UTC (rev 4429) +++ magnoliamodules/trunk/openutils-mgnllms/src/main/resources/mgnl-files/templates/samples-lms/courses.jsp 2013-10-21 13:45:43 UTC (rev 4430) @@ -1,6 +1,7 @@ -<jsp:root version="2.0" xmlns:jsp="http://java.sun.com/JSP/Page" xmlns:cms="urn:jsptld:cms-taglib" xmlns:cmsu="urn:jsptld:cms-util-taglib" - xmlns:c="urn:jsptld:http://java.sun.com/jsp/jstl/core" xmlns:fmt="urn:jsptld:http://java.sun.com/jsp/jstl/fmt" - xmlns:cmsfn="http://www.magnolia.info/tlds/cmsfn-taglib.tld" xmlns:lmsfn="urn:jsptld:lms-fn"> +<jsp:root version="2.0" xmlns:jsp="http://java.sun.com/JSP/Page" xmlns:c="http://java.sun.com/jsp/jstl/core" + xmlns:fmt="http://java.sun.com/jsp/jstl/fmt" xmlns:fn="http://java.sun.com/jsp/jstl/functions" xmlns:cms="http://magnolia-cms.com/taglib/templating-components/cms" + xmlns:cmsu="cms-util-taglib" xmlns:cmsfn="http://magnolia-cms.com/taglib/templating-components/cmsfn" xmlns:media="http://net.sourceforge.openutils/mgnlMedia" + xmlns:lmsfn="urn:jsptld:lms-fn"> <jsp:directive.page contentType="text/html; charset=UTF-8" session="false" /> <jsp:text> <![CDATA[<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> ]]> @@ -9,7 +10,9 @@ <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>${actpage.title}</title> - <cms:links /> + <cms:init /> + <link rel="stylesheet" type="text/css" + href="${pageContext.request.contextPath}/.resources/media-samples/css/bootstrap.min.css" /> </head> <body> <h1>${actpage.title}</h1> Modified: magnoliamodules/trunk/openutils-mgnllms/src/main/resources/mgnl-files/templates/samples-lms/index.jsp =================================================================== --- magnoliamodules/trunk/openutils-mgnllms/src/main/resources/mgnl-files/templates/samples-lms/index.jsp 2013-10-21 12:24:28 UTC (rev 4429) +++ magnoliamodules/trunk/openutils-mgnllms/src/main/resources/mgnl-files/templates/samples-lms/index.jsp 2013-10-21 13:45:43 UTC (rev 4430) @@ -1,6 +1,7 @@ -<jsp:root version="2.0" xmlns:jsp="http://java.sun.com/JSP/Page" xmlns:cms="urn:jsptld:cms-taglib" xmlns:cmsu="urn:jsptld:cms-util-taglib" - xmlns:c="urn:jsptld:http://java.sun.com/jsp/jstl/core" xmlns:fmt="urn:jsptld:http://java.sun.com/jsp/jstl/fmt" - xmlns:cmsfn="http://www.magnolia.info/tlds/cmsfn-taglib.tld" xmlns:lmsfn="urn:jsptld:lms-fn"> +<jsp:root version="2.0" xmlns:jsp="http://java.sun.com/JSP/Page" xmlns:c="http://java.sun.com/jsp/jstl/core" + xmlns:fmt="http://java.sun.com/jsp/jstl/fmt" xmlns:fn="http://java.sun.com/jsp/jstl/functions" xmlns:cms="http://magnolia-cms.com/taglib/templating-components/cms" + xmlns:cmsu="cms-util-taglib" xmlns:cmsfn="http://magnolia-cms.com/taglib/templating-components/cmsfn" xmlns:media="http://net.sourceforge.openutils/mgnlMedia" + xmlns:lmsfn="urn:jsptld:lms-fn"> <jsp:directive.page contentType="text/html; charset=UTF-8" session="false" /> <jsp:text> <![CDATA[<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> ]]> @@ -9,7 +10,9 @@ <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>${actpage.title}</title> - <cms:links /> + <cms:init /> + <link rel="stylesheet" type="text/css" + href="${pageContext.request.contextPath}/.resources/media-samples/css/bootstrap.min.css" /> </head> <body> <h1>${actpage.title}</h1> @@ -45,18 +48,34 @@ </ul> <p>There are three roles, one for each folder:</p> <ul> - <li><b>std-level-1</b> which can view its courses but not subfolders</li> - <li><b>std-level-2a</b> which can view its courses but not subfolders</li> - <li><b>std-level-3a</b> which can view its courses but not subfolders</li> + <li> + <b>std-level-1</b> + which can view its courses but not subfolders + </li> + <li> + <b>std-level-2a</b> + which can view its courses but not subfolders + </li> + <li> + <b>std-level-3a</b> + which can view its courses but not subfolders + </li> </ul> - <p>The user student/student has the role std-level-1; there is an example listener (net.sourceforge.openutils.mgnllms.samples.listeners.StudentLevelListener defined in /modules/lms/lms-config/listeners/student-level), - that is called whenever a user complete a course and performs following actions: + <p> + The user student/student has the role std-level-1; there is an example listener + (net.sourceforge.openutils.mgnllms.samples.listeners.StudentLevelListener defined in + /modules/lms/lms-config/listeners/student-level), that is called whenever a user complete a course and performs + following actions: <ol> <li>check if the user has successfully completed all courses to which he has access</li> - <li>if true assign to user additional roles corresponding to the names of subfolders of the last completed course</li> + <li>if true assign to user additional roles corresponding to the names of subfolders of the last completed + course</li> </ol> </p> - <p><a href="${pageContext.request.contextPath}/sample-lms/courses.html">Go to the courses list!</a> (use student/student to access)</p> + <p> + <a href="${pageContext.request.contextPath}/sample-lms/courses.html">Go to the courses list!</a> + (use student/student to access) + </p> </body> </html> </jsp:root> \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |