001: /*
002: * The Unified Mapping Platform (JUMP) is an extensible, interactive GUI
003: * for visualizing and manipulating spatial features with geometry and attributes.
004: *
005: * Copyright (C) 2003 Vivid Solutions
006: *
007: * This program is free software; you can redistribute it and/or
008: * modify it under the terms of the GNU General Public License
009: * as published by the Free Software Foundation; either version 2
010: * of the License, or (at your option) any later version.
011: *
012: * This program is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
015: * GNU General Public License for more details.
016: *
017: * You should have received a copy of the GNU General Public License
018: * along with this program; if not, write to the Free Software
019: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
020: *
021: * For more information, contact:
022: *
023: * Vivid Solutions
024: * Suite #1A
025: * 2328 Government Street
026: * Victoria BC V8T 5G5
027: * Canada
028: *
029: * (250)385-6040
030: * www.vividsolutions.com
031: */
032:
033: package com.vividsolutions.jump.workbench.driver;
034:
035: import java.io.File;
036: import java.io.FileNotFoundException;
037: import java.io.IOException;
038:
039: import com.vividsolutions.jump.feature.FeatureCollection;
040: import com.vividsolutions.jump.io.CompressedFile;
041: import com.vividsolutions.jump.io.DriverProperties;
042: import com.vividsolutions.jump.io.JMLReader;
043: import com.vividsolutions.jump.io.ParseException;
044: import com.vividsolutions.jump.workbench.model.Layer;
045: import com.vividsolutions.jump.workbench.model.LayerManager;
046: import com.vividsolutions.jump.workbench.ui.AbstractDriverPanel;
047: import com.vividsolutions.jump.workbench.ui.BasicFileDriverPanel;
048: import com.vividsolutions.jump.workbench.ui.ErrorHandler;
049: import com.vividsolutions.jump.workbench.ui.GUIUtil;
050: import com.vividsolutions.jump.workbench.ui.WorkbenchFileFilter;
051:
052: /**
053: * @author Alan Chang
054: * @version 1.0
055: *
056: * <p>Title: JMLFileInputDriver</p>
057: * <p>Description: Input Driver for JML type of files</p>
058: * <p>Copyright: Copyright (c) 2002</p>
059: * <p>Company: Vivid Solutions Inc.</p>
060: *
061:
062: */
063: public class JMLFileInputDriver extends AbstractInputDriver {
064: private BasicFileDriverPanel panel;
065: private DriverProperties dp = new DriverProperties();
066:
067: public JMLFileInputDriver() {
068: }
069:
070: /*
071: *return the description of the file
072: */
073: public String toString() {
074: return GUIUtil.jmlDesc;
075: }
076:
077: public AbstractDriverPanel getPanel() {
078: return panel;
079: }
080:
081: public void initialize(DriverManager driverManager,
082: ErrorHandler errorHandler) {
083: super .initialize(driverManager, errorHandler);
084: panel = new BasicFileDriverPanel(errorHandler);
085: panel.setFileDescription(GUIUtil.jmlDesc);
086: panel.setFileFilter(new WorkbenchFileFilter(GUIUtil.jmlDesc));
087: panel.setFileMustExist(true);
088: }
089:
090: public void input(LayerManager layerManager, String categoryName)
091: throws FileNotFoundException, IOException, ParseException,
092: com.vividsolutions.jts.io.ParseException,
093: com.vividsolutions.jump.io.IllegalParametersException,
094: Exception {
095: String extension;
096: File selectedFile = panel.getSelectedFile();
097: FeatureCollection featureCollection;
098: JMLReader jmlReader = new JMLReader();
099: String name = selectedFile.getAbsolutePath();
100:
101: extension = name.substring(name.length() - 3);
102: dp = new DriverProperties();
103:
104: if (extension.equalsIgnoreCase("zip")) {
105: String internalName;
106:
107: dp.set("CompressedFile", name);
108: internalName = CompressedFile
109: .getInternalZipFnameByExtension(".jml", name);
110:
111: if (internalName == null) {
112: internalName = CompressedFile
113: .getInternalZipFnameByExtension(".gml", name);
114: }
115:
116: if (internalName == null) {
117: internalName = CompressedFile
118: .getInternalZipFnameByExtension(".xml", name);
119: }
120:
121: if (internalName == null) {
122: throw new Exception(
123: "Couldnt find a .jml, .xml, or .gml file inside the .zip file: "
124: + name);
125: }
126:
127: dp.set("File", internalName);
128: } else if (extension.equalsIgnoreCase(".gz")) {
129: dp.set("CompressedFile", name);
130: dp.set("File", name); // not useed
131: } else {
132: dp.set("File", name);
133: }
134:
135: // no "TemplateFile" specified, so read it from the top of the "File"
136: featureCollection = jmlReader.read(dp);
137:
138: Layer layer = layerManager.addLayer(categoryName, GUIUtil
139: .nameWithoutExtension(selectedFile), featureCollection);
140: }
141: }
|