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.FMEGMLReader;
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: public class FMEFileInputDriver extends AbstractInputDriver {
053: private BasicFileDriverPanel panel;
054: private DriverProperties dp = new DriverProperties();
055:
056: public FMEFileInputDriver() {
057: }
058:
059: public String toString() {
060: return GUIUtil.fmeDesc;
061: }
062:
063: public void initialize(DriverManager driverManager,
064: ErrorHandler errorHandler) {
065: super .initialize(driverManager, errorHandler);
066: panel = new BasicFileDriverPanel(errorHandler);
067: panel.setFileMustExist(true);
068: panel.setFileDescription(GUIUtil.fmeDesc);
069: panel.setFileFilter(new WorkbenchFileFilter(GUIUtil.fmeDesc));
070: }
071:
072: public void input(LayerManager layerManager, String categoryName)
073: throws FileNotFoundException, IOException, ParseException,
074: com.vividsolutions.jts.io.ParseException,
075: com.vividsolutions.jump.io.IllegalParametersException,
076: Exception {
077: String extension;
078: File selectedFile = panel.getSelectedFile();
079: FeatureCollection featureCollection;
080: FMEGMLReader fmeReader = new FMEGMLReader();
081: String name = selectedFile.getAbsolutePath();
082:
083: //<<TODO:DEFECT>> Must create a new DataProperties object. If I try to reuse
084: //the old one, FMEGMLReader seems to use the old filename. Need to investigate
085: //this. [Jon Aquino]
086: extension = name.substring(name.length() - 3);
087: dp = new DriverProperties();
088:
089: if (extension.equalsIgnoreCase("zip")) {
090: String internalName;
091:
092: dp.set("CompressedFile", name);
093: internalName = CompressedFile
094: .getInternalZipFnameByExtension(".fme", name);
095:
096: if (internalName == null) {
097: internalName = CompressedFile
098: .getInternalZipFnameByExtension(".xml", name);
099: }
100:
101: if (internalName == null) {
102: internalName = CompressedFile
103: .getInternalZipFnameByExtension(".gml", name);
104: }
105:
106: if (internalName == null) {
107: throw new Exception(
108: "Couldnt find a .fme, .xml, or .gml file inside the .zip file: "
109: + name);
110: }
111:
112: dp.set("File", internalName);
113: } else if (extension.equalsIgnoreCase(".gz")) {
114: dp.set("CompressedFile", name);
115: dp.set("File", name); // not useed
116: } else {
117: dp.set("File", name);
118: }
119:
120: // no "TemplateFile" specified, so read it from the top of the "File"
121: featureCollection = fmeReader.read(dp);
122:
123: Layer layer = layerManager.addLayer(categoryName, GUIUtil
124: .nameWithoutExtension(selectedFile), featureCollection);
125: }
126:
127: public AbstractDriverPanel getPanel() {
128: return panel;
129: }
130: }
|