Statistics
| Revision:

svn-gvsig-desktop / branches / CqCMSDvp / libraries / libCq CMS for java.old / src / org / cresques / io / ZipFileFolder.java @ 2312

History | View | Annotate | Download (2.47 KB)

1
/*
2
 * Cresques Mapping Suite. Graphic Library for constructing mapping applications.
3
 * 
4
 * Copyright (C) 2004-5. 
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 2
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
19
 *
20
 * For more information, contact:
21
 * 
22
 * cresques@gmail.com
23
 */
24
package org.cresques.io;
25

    
26
import java.io.IOException;
27
import java.io.InputStream;
28
import java.util.Enumeration;
29
import java.util.zip.ZipEntry;
30
import java.util.zip.ZipFile;
31

    
32
/**
33
 * @author "Luis W. Sevilla" <sevilla_lui@gva.es>* @author administrador
34
 */
35

    
36
public class ZipFileFolder extends FileFolder {
37
        String zName = null;
38
        public ZipFile file = null;
39
        
40
        public ZipFileFolder() {
41
                super();
42
        }
43
        
44
        /**
45
         * Constructor.
46
         * 
47
         * @param fname
48
         */
49
        
50
        public ZipFileFolder(String fName) throws IOException {
51
                fName = DataSource.normalize(fName);
52
                if (isUrl(fName))
53
                        zName = getZName(fName);
54
                else
55
                        zName = fName;
56
                file = new ZipFile(zName);
57
        }
58
        
59
        /**
60
         * Analiza un nombre de fichero en formato zip://zipname.zip?file.ext
61
         * @param urlName
62
         */
63
        
64
        public static boolean isUrl(String name) {
65
                String str = name.substring(0,3);
66
                str.toLowerCase();
67
                if (str.compareTo("zip") == 0)
68
                        return true;
69
                return false;
70
        }
71
        
72
        private String getZName(String urlName) {
73
                return urlName.substring(6,urlName.indexOf("?"));
74
        }
75
        private String getFName(String urlName) {
76
                return urlName.substring(urlName.indexOf("?")+1);
77
        }
78
        
79
        public ZipEntry getZipEntry(String fName) throws IOException {
80
                InputStream is = null;
81
                if (isUrl(fName))
82
                        fName = getFName(fName);
83
                return file.getEntry(fName);
84
        }
85
        
86
        public InputStream getInputStream(String fName) throws IOException {
87
                return file.getInputStream(getZipEntry(fName));
88
        }
89
        
90
        public InputStream getInputStream(ZipEntry ze) throws IOException {
91
                return file.getInputStream(ze);
92
        }
93
        
94
        public int count() { return file.size(); }
95
        
96
        public Enumeration entries() { return file.entries();}
97
}