From: <df...@us...> - 2010-08-31 15:44:49
|
Revision: 2957 http://openutils.svn.sourceforge.net/openutils/?rev=2957&view=rev Author: dfghi Date: 2010-08-31 15:44:42 +0000 (Tue, 31 Aug 2010) Log Message: ----------- MEDIA-171 Added the possibility to set a zip importer class. Modified Paths: -------------- trunk/openutils-mgnlmedia/src/main/java/net/sourceforge/openutils/mgnlmedia/media/lifecycle/MediaModule.java trunk/openutils-mgnlmedia/src/main/java/net/sourceforge/openutils/mgnlmedia/media/pages/MediaBrowserPage.java Added Paths: ----------- trunk/openutils-mgnlmedia/src/main/java/net/sourceforge/openutils/mgnlmedia/media/zip/ trunk/openutils-mgnlmedia/src/main/java/net/sourceforge/openutils/mgnlmedia/media/zip/DefaultZipImporter.java trunk/openutils-mgnlmedia/src/main/java/net/sourceforge/openutils/mgnlmedia/media/zip/ZipImporter.java trunk/openutils-mgnlmedia/src/main/java/net/sourceforge/openutils/mgnlmedia/media/zip/ZipImporterException.java trunk/openutils-mgnlmedia/src/main/resources/mgnl-bootstrap/media/config.modules.media.config.zipimporter.xml Modified: trunk/openutils-mgnlmedia/src/main/java/net/sourceforge/openutils/mgnlmedia/media/lifecycle/MediaModule.java =================================================================== --- trunk/openutils-mgnlmedia/src/main/java/net/sourceforge/openutils/mgnlmedia/media/lifecycle/MediaModule.java 2010-08-31 08:38:10 UTC (rev 2956) +++ trunk/openutils-mgnlmedia/src/main/java/net/sourceforge/openutils/mgnlmedia/media/lifecycle/MediaModule.java 2010-08-31 15:44:42 UTC (rev 2957) @@ -21,10 +21,10 @@ import info.magnolia.module.ModuleLifecycle; import info.magnolia.module.ModuleLifecycleContext; -import net.sourceforge.openutils.mgnlmedia.media.advancedsearch.configuration.SearchMediaQueryConfiguration; import net.sourceforge.openutils.mgnlmedia.media.configuration.ImageProcessorsManager; import net.sourceforge.openutils.mgnlmedia.media.configuration.MediaConfigurationManager; import net.sourceforge.openutils.mgnlmedia.media.configuration.MediaUsedInManager; +import net.sourceforge.openutils.mgnlmedia.media.zip.ZipImporter; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -54,10 +54,8 @@ private String player = "player.swf"; private String version; - - private SearchMediaQueryConfiguration search; - private int folderViewItemsPerPage; + private ZipImporter zipimporter; /** * Constructor @@ -134,48 +132,23 @@ this.player = player; } - /** - * Returns the version. - * @return the version - */ - public String getVersion() + public ZipImporter getZipimporter() { - return version; + return zipimporter; } - - /** - * Returns the searchConfiguration. - * @return the searchConfiguration - */ - public SearchMediaQueryConfiguration getSearch() + + public void setZipimporter(ZipImporter zipimporter) { - return search; + this.zipimporter = zipimporter; } /** - * Sets the searchConfiguration. - * @param searchConfiguration the searchConfiguration to set + * Returns the version. + * @return the version */ - public void setSearch(SearchMediaQueryConfiguration search) + public String getVersion() { - this.search = search; + return version; } - /** - * Returns the folderViewItemsPerPage. - * @return the folderViewItemsPerPage - */ - public int getFolderViewItemsPerPage() - { - return folderViewItemsPerPage; - } - - /** - * Sets the folderViewItemsPerPage. - * @param folderViewItemsPerPage the folderViewItemsPerPage to set - */ - public void setFolderViewItemsPerPage(int folderViewItemsPerPage) - { - this.folderViewItemsPerPage = folderViewItemsPerPage; - } } 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 2010-08-31 08:38:10 UTC (rev 2956) +++ trunk/openutils-mgnlmedia/src/main/java/net/sourceforge/openutils/mgnlmedia/media/pages/MediaBrowserPage.java 2010-08-31 15:44:42 UTC (rev 2957) @@ -23,7 +23,6 @@ import info.magnolia.cms.core.Content; import info.magnolia.cms.core.HierarchyManager; import info.magnolia.cms.i18n.Messages; -import info.magnolia.cms.security.AccessDeniedException; import info.magnolia.context.MgnlContext; import java.io.File; @@ -31,8 +30,6 @@ import java.io.IOException; import java.io.InputStream; import java.util.Date; -import java.util.Enumeration; -import java.util.zip.ZipEntry; import java.util.zip.ZipFile; import javax.jcr.RepositoryException; @@ -41,7 +38,9 @@ import net.sourceforge.openutils.mgnlmedia.media.lifecycle.MediaModule; import net.sourceforge.openutils.mgnlmedia.media.tags.el.MediaEl; -import net.sourceforge.openutils.mgnlmedia.media.utils.MediaLoadUtils; +import net.sourceforge.openutils.mgnlmedia.media.zip.DefaultZipImporter; +import net.sourceforge.openutils.mgnlmedia.media.zip.ZipImporter; +import net.sourceforge.openutils.mgnlmedia.media.zip.ZipImporterException; import org.apache.commons.io.FileUtils; import org.apache.commons.io.IOUtils; @@ -51,7 +50,7 @@ /** - * Page that contains the tree and the foldere view. + * Page that contains the tree and the folders view. * @author molaschi * @version $Id$ */ @@ -130,59 +129,31 @@ zipStream = zipFile.getStream(); IOUtils.copy(zipStream, fos); - IOUtils.closeQuietly(fos); ZipFile zip = new ZipFile(temp); - Enumeration< ? extends ZipEntry> entries = zip.entries(); - while (entries.hasMoreElements()) - { - ZipEntry entry = entries.nextElement(); - - String path = entry.getName(); - - if (!entry.isDirectory()) - { - - InputStream inputStream = zip.getInputStream(entry); - - 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, "/fromzip"), - filename, - false); - - } + ZipImporter importer = MediaEl.module().getZipimporter(); + if (importer == null) + { // Fallback to the default if nothing is set. + importer = new DefaultZipImporter(); } + importer.importFromZip(zip, parentPath); + zip.close(); } catch (IOException e) { log.error(e.getMessage(), e); } - catch (AccessDeniedException e) + catch (ZipImporterException e) { + // TODO Maybe we should show something... log.error(e.getMessage(), e); } - catch (RepositoryException e) - { - log.error(e.getMessage(), e); - } finally { IOUtils.closeQuietly(zipStream); + FileUtils.deleteQuietly(temp); } - FileUtils.deleteQuietly(temp); - this.openPath = parentPath; return this.show(); Added: trunk/openutils-mgnlmedia/src/main/java/net/sourceforge/openutils/mgnlmedia/media/zip/DefaultZipImporter.java =================================================================== --- trunk/openutils-mgnlmedia/src/main/java/net/sourceforge/openutils/mgnlmedia/media/zip/DefaultZipImporter.java (rev 0) +++ trunk/openutils-mgnlmedia/src/main/java/net/sourceforge/openutils/mgnlmedia/media/zip/DefaultZipImporter.java 2010-08-31 15:44:42 UTC (rev 2957) @@ -0,0 +1,79 @@ +/** + * + * Magnolia SimpleMedia Module (http://www.openmindlab.com/lab/products/media.html) + * Copyright(C) 2008-2010, 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 + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * 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, see <http://www.gnu.org/licenses/>. + */ + +package net.sourceforge.openutils.mgnlmedia.media.zip; + +import java.io.InputStream; +import java.util.Enumeration; +import java.util.zip.ZipEntry; +import java.util.zip.ZipFile; + +import net.sourceforge.openutils.mgnlmedia.media.utils.MediaLoadUtils; + +import org.apache.commons.lang.StringUtils; + +/** + * Default zip importer. Simply takes files in the provided zip file and store them in the media repository. + * + * @author Danilo Ghirardelli + */ +public class DefaultZipImporter implements ZipImporter { + + /** + * {@inheritDoc} + */ + public void importFromZip(ZipFile zip, String parentPath) throws ZipImporterException { + try + { + Enumeration< ? extends ZipEntry> entries = zip.entries(); + while (entries.hasMoreElements()) + { + ZipEntry entry = entries.nextElement(); + + String path = entry.getName(); + + if (!entry.isDirectory()) + { + InputStream inputStream = zip.getInputStream(entry); + + 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, "/fromzip"), + filename, + false); + + } + } + } + catch (Exception e) + { + throw new ZipImporterException(e.getMessage(), e); + } + } +} Property changes on: trunk/openutils-mgnlmedia/src/main/java/net/sourceforge/openutils/mgnlmedia/media/zip/DefaultZipImporter.java ___________________________________________________________________ Added: svn:mime-type + text/plain Added: svn:keywords + Author Date Id Revision Added: svn:eol-style + native Added: trunk/openutils-mgnlmedia/src/main/java/net/sourceforge/openutils/mgnlmedia/media/zip/ZipImporter.java =================================================================== --- trunk/openutils-mgnlmedia/src/main/java/net/sourceforge/openutils/mgnlmedia/media/zip/ZipImporter.java (rev 0) +++ trunk/openutils-mgnlmedia/src/main/java/net/sourceforge/openutils/mgnlmedia/media/zip/ZipImporter.java 2010-08-31 15:44:42 UTC (rev 2957) @@ -0,0 +1,44 @@ +/** + * + * Magnolia SimpleMedia Module (http://www.openmindlab.com/lab/products/media.html) + * Copyright(C) 2008-2010, 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 + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * 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, see <http://www.gnu.org/licenses/>. + */ + +package net.sourceforge.openutils.mgnlmedia.media.zip; + +import java.util.zip.ZipFile; + + +/** + * Interface for zip importers. Using this, is possible to extract metadata from the zip file while importing the + * images. Common cases are: - Title, description or other metadata are included in the media file name or folder. - + * Metadata for all medias are included in a file (xml, txt) in the zip. - Metadata for the media is stored within the + * zip file metadata. Implementing this interface you can cover any of the aforementioned cases. + * + * @author Danilo Ghirardelli + */ +public interface ZipImporter { + + /** + * Stores in the media repository the images found in the zip file. Implementing this method you have control over + * the (eventual) metadata handling. + * + * @param zipFile The file from request + * @param parentPath Repo folder selected for storing the images. May be null. + * @throws ZipImporterException + */ + void importFromZip(ZipFile zip, String parentPath) throws ZipImporterException; +} Property changes on: trunk/openutils-mgnlmedia/src/main/java/net/sourceforge/openutils/mgnlmedia/media/zip/ZipImporter.java ___________________________________________________________________ Added: svn:mime-type + text/plain Added: svn:keywords + Author Date Id Revision Added: svn:eol-style + native Added: trunk/openutils-mgnlmedia/src/main/java/net/sourceforge/openutils/mgnlmedia/media/zip/ZipImporterException.java =================================================================== --- trunk/openutils-mgnlmedia/src/main/java/net/sourceforge/openutils/mgnlmedia/media/zip/ZipImporterException.java (rev 0) +++ trunk/openutils-mgnlmedia/src/main/java/net/sourceforge/openutils/mgnlmedia/media/zip/ZipImporterException.java 2010-08-31 15:44:42 UTC (rev 2957) @@ -0,0 +1,47 @@ +/** + * + * Magnolia SimpleMedia Module (http://www.openmindlab.com/lab/products/media.html) + * Copyright(C) 2008-2010, 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 + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * 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, see <http://www.gnu.org/licenses/>. + */ + +package net.sourceforge.openutils.mgnlmedia.media.zip; + +/** + * Exception for zip import. + * @author Danilo Ghirardelli + */ +public class ZipImporterException extends RuntimeException { + + /** + * Stable serialVersionUID. + */ + private static final long serialVersionUID = 42L; + + /** + * @param message + */ + public ZipImporterException(String message) { + super(message); + } + + /** + * @param message + * @param cause + */ + public ZipImporterException(String message, Throwable cause) { + super(message, cause); + } +} Property changes on: trunk/openutils-mgnlmedia/src/main/java/net/sourceforge/openutils/mgnlmedia/media/zip/ZipImporterException.java ___________________________________________________________________ Added: svn:mime-type + text/plain Added: svn:keywords + Author Date Id Revision Added: svn:eol-style + native Added: trunk/openutils-mgnlmedia/src/main/resources/mgnl-bootstrap/media/config.modules.media.config.zipimporter.xml =================================================================== --- trunk/openutils-mgnlmedia/src/main/resources/mgnl-bootstrap/media/config.modules.media.config.zipimporter.xml (rev 0) +++ trunk/openutils-mgnlmedia/src/main/resources/mgnl-bootstrap/media/config.modules.media.config.zipimporter.xml 2010-08-31 15:44:42 UTC (rev 2957) @@ -0,0 +1,29 @@ +<?xml version="1.0" encoding="UTF-8"?> +<sv:node sv:name="zipimporter" xmlns:sv="http://www.jcp.org/jcr/sv/1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> + <sv:property sv:name="jcr:primaryType" sv:type="Name"> + <sv:value>mgnl:contentNode</sv:value> + </sv:property> + <sv:property sv:name="jcr:mixinTypes" sv:type="Name"> + <sv:value>mix:lockable</sv:value> + </sv:property> + <sv:property sv:name="jcr:uuid" sv:type="String"> + <sv:value>7a187c96-87ac-4ca4-8669-ac75911b34f4</sv:value> + </sv:property> + <sv:property sv:name="class" sv:type="String"> + <sv:value>net.sourceforge.openutils.mgnlmedia.media.zip.DefaultZipImporter</sv:value> + </sv:property> + <sv:node sv:name="MetaData"> + <sv:property sv:name="jcr:primaryType" sv:type="Name"> + <sv:value>mgnl:metaData</sv:value> + </sv:property> + <sv:property sv:name="mgnl:authorid" sv:type="String"> + <sv:value>superuser</sv:value> + </sv:property> + <sv:property sv:name="mgnl:creationdate" sv:type="Date"> + <sv:value>2010-08-31T16:34:22.420+02:00</sv:value> + </sv:property> + <sv:property sv:name="mgnl:lastmodified" sv:type="Date"> + <sv:value>2010-08-31T16:35:13.535+02:00</sv:value> + </sv:property> + </sv:node> +</sv:node> Property changes on: trunk/openutils-mgnlmedia/src/main/resources/mgnl-bootstrap/media/config.modules.media.config.zipimporter.xml ___________________________________________________________________ Added: svn:mime-type + text/plain Added: eol-style + native This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |