01: /*
02: * (c) Copyright 2004, 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP
03: * All rights reserved.
04: * [See end of file]
05: */
06:
07: package com.hp.hpl.jena.util;
08:
09: import com.hp.hpl.jena.shared.JenaException;
10: import java.io.*;
11: import java.util.zip.*;
12: import org.apache.commons.logging.*;
13:
14: /** Location files in a zip file
15: *
16: * @author Andy Seaborne
17: * @version $Id: LocatorZip.java,v 1.7 2008/01/02 12:07:44 andy_seaborne Exp $
18: */
19:
20: class LocatorZip implements Locator {
21: static Log log = LogFactory.getLog(LocatorZip.class);
22: String zipFileName = null;
23: ZipFile zipFile = null;
24:
25: public LocatorZip(String zfn) {
26: try {
27: zipFileName = zfn;
28: zipFile = new ZipFile(zipFileName);
29: } catch (IOException ex) {
30: throw new JenaException(
31: "Problems accessing " + zipFileName, ex);
32: }
33: }
34:
35: public TypedStream open(String filenameOrURI) {
36: ZipEntry entry = zipFile.getEntry(filenameOrURI);
37: if (entry == null) {
38: if (FileManager.logAllLookups && log.isDebugEnabled())
39: log.debug("Not found: " + zipFileName + " : "
40: + filenameOrURI);
41: return null;
42:
43: }
44: try {
45: InputStream in = zipFile.getInputStream(entry);
46:
47: if (in == null) {
48: if (FileManager.logAllLookups && log.isTraceEnabled())
49: log.trace("Not found: " + filenameOrURI);
50: return null;
51: }
52:
53: if (FileManager.logAllLookups && log.isTraceEnabled())
54: log.trace("Found: " + filenameOrURI);
55: return new TypedStream(in);
56: } catch (IOException ex) {
57: log
58: .warn("IO Exception opening zip entry: "
59: + filenameOrURI);
60: return null;
61: }
62: }
63:
64: public String getName() {
65: return "LocatorZip(" + zipFileName + ")";
66: }
67:
68: }
69: /*
70: * (c) Copyright 2004, 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP
71: * All rights reserved.
72: *
73: * Redistribution and use in source and binary forms, with or without
74: * modification, are permitted provided that the following conditions
75: * are met:
76: * 1. Redistributions of source code must retain the above copyright
77: * notice, this list of conditions and the following disclaimer.
78: * 2. Redistributions in binary form must reproduce the above copyright
79: * notice, this list of conditions and the following disclaimer in the
80: * documentation and/or other materials provided with the distribution.
81: * 3. The name of the author may not be used to endorse or promote products
82: * derived from this software without specific prior written permission.
83: *
84: * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
85: * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
86: * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
87: * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
88: * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
89: * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
90: * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
91: * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
92: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
93: * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
94: */
|