|
From: <mol...@us...> - 2009-08-26 10:58:29
|
Revision: 1313
http://openutils.svn.sourceforge.net/openutils/?rev=1313&view=rev
Author: molaschi
Date: 2009-08-26 10:58:20 +0000 (Wed, 26 Aug 2009)
Log Message:
-----------
MEDIA-10 set current node path as base path to explode zip file
Modified Paths:
--------------
trunk/openutils-mgnlmedia/src/main/java/net/sourceforge/openutils/mgnlmedia/media/pages/MediaBrowserPage.java
Modified: trunk/openutils-mgnlmedia/src/main/java/net/sourceforge/openutils/mgnlmedia/media/pages/MediaBrowserPage.java
===================================================================
--- trunk/openutils-mgnlmedia/src/main/java/net/sourceforge/openutils/mgnlmedia/media/pages/MediaBrowserPage.java 2009-08-25 16:16:27 UTC (rev 1312)
+++ trunk/openutils-mgnlmedia/src/main/java/net/sourceforge/openutils/mgnlmedia/media/pages/MediaBrowserPage.java 2009-08-26 10:58:20 UTC (rev 1313)
@@ -104,13 +104,16 @@
public String saveZip()
{
+ InputStream zipStream = null;
try
{
- HierarchyManager mgr = MgnlContext.getSystemContext().getHierarchyManager(MediaModule.REPO);
File temp = File.createTempFile("zipmedia", ".zip");
FileOutputStream fos = new FileOutputStream(temp);
- IOUtils.copy(zipFile.getStream(), fos);
- fos.close();
+
+ zipStream = zipFile.getStream();
+ IOUtils.copy(zipStream, fos);
+
+ IOUtils.closeQuietly(fos);
ZipFile zip = new ZipFile(temp);
Enumeration< ? extends ZipEntry> entries = zip.entries();
while (entries.hasMoreElements())
@@ -118,42 +121,47 @@
ZipEntry entry = entries.nextElement();
String path = entry.getName();
- path = StringUtils.replace(path, "\\", "/");
- if (!path.startsWith("/"))
- {
- path = "/" + path;
- }
- if (path.endsWith("/"))
- {
- path = path.substring(0, path.length() - 1);
- }
if (!entry.isDirectory())
{
InputStream inputStream = zip.getInputStream(entry);
- String parent = StringUtils.substringBeforeLast(path, "/");
- String filename = StringUtils.substringAfterLast(path, "/");
+ String parent = StringUtils.trimToEmpty(parentPath) + "/" + path;
+ parent = StringUtils.replace(parent, "\\", "/");
+ parent = StringUtils.replace(parent, "//", "/");
+ if (!parent.startsWith("/"))
+ {
+ parent = "/" + parent;
+ }
+ String filename = StringUtils.substringAfterLast(parent, "/");
+ parent = StringUtils.substringBeforeLast(parent, "/");
- MediaLoadUtils.loadEntry(inputStream, StringUtils.defaultIfEmpty(parent, "/"), filename, false);
+ MediaLoadUtils.loadEntry(
+ inputStream,
+ StringUtils.defaultIfEmpty(parent, "/fromzip"),
+ filename,
+ false);
}
-
}
}
catch (IOException e)
{
-
+ log.error(e.getMessage(), e);
}
catch (AccessDeniedException e)
{
-
+ log.error(e.getMessage(), e);
}
catch (RepositoryException e)
{
-
+ log.error(e.getMessage(), e);
}
+ finally
+ {
+ IOUtils.closeQuietly(zipStream);
+ }
this.openPath = parentPath;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|