1 /*
2 * $Id: UnzipResourceJar.java 2992 2011-11-24 19:25:54Z andrewinkler $
3 * ============================================================================
4 * Project gluehloch-homepage-resource
5 * Copyright (c) 2004-2010 by Andre Winkler. All rights reserved.
6 * ============================================================================
7 * GNU LESSER GENERAL PUBLIC LICENSE
8 * TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
9 *
10 * This library is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU Lesser General Public
12 * License as published by the Free Software Foundation; either
13 * version 2.1 of the License, or (at your option) any later version.
14 *
15 * This library is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * Lesser General Public License for more details.
19 *
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with this library; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 *
24 */
25
26 package de.awtools.homegen;
27
28 import java.io.File;
29 import java.io.IOException;
30 import java.net.URI;
31 import java.net.URISyntaxException;
32
33 import org.apache.commons.io.FileUtils;
34 import org.slf4j.Logger;
35 import org.slf4j.LoggerFactory;
36
37 import de.awtools.homegen.FindResourceJar;
38 import de.awtools.homegen.UnzipJar;
39
40 /**
41 * Unzip der Web-Resourcen.
42 *
43 * @version $LastChangedRevision: 2992 $ $LastChangedDate: 2011-11-24 20:25:54 +0100 (Thu, 24 Nov 2011) $
44 * @author by Andre Winkler, $LastChangedBy: andrewinkler $
45 *
46 * @since 1.4
47 */
48 public final class UnzipResourceJar {
49
50 /** Ein Logger für diese Klasse. */
51 private final Logger log = LoggerFactory.getLogger(UnzipResourceJar.class);
52
53 /**
54 * Auspacken der Resourcen.
55 *
56 * @param unzipDirectory Das Zielverzeichnis.
57 * @throws IOException Da ging was schief.
58 * @throws URISyntaxException Jar-Resource nicht gefunden.
59 */
60 public void call(final String unzipDirectory) throws IOException,
61 URISyntaxException {
62
63 FindResourceJar finder = new FindResourceJar();
64 URI resourceUri = finder.call();
65
66 if (log.isDebugEnabled()) {
67 log.debug("JAR URI Scheme: " + resourceUri.getScheme());
68 log.debug("JAR URI: " + resourceUri);
69 }
70
71 if (resourceUri.toString().endsWith(".jar")) {
72 UnzipJar unzipJar = new UnzipJar();
73 unzipJar.setFilterInclude("plugin-resources");
74 unzipJar.setTargetDirectory(unzipDirectory);
75 unzipJar.setZipFileName(resourceUri);
76 unzipJar.call();
77 } else if ("file".equals(resourceUri.getScheme())) {
78 File targetDir = new File(unzipDirectory);
79 File sourceDir = new File(resourceUri.getPath(), "plugin-resources");
80 FileUtils.copyDirectory(sourceDir, targetDir);
81 } else {
82 throw new IllegalStateException(
83 "Unknown resource scheme: '" + resourceUri.getScheme());
84 }
85 }
86 }