Revision 31 org.gvsig.sextante/trunk/org.gvsig.sextante.app/org.gvsig.sextante.app.extension/src/main/java/org/gvsig/sextante/app/extension/core/gvGeoAlgorithm.java

View differences:

gvGeoAlgorithm.java
5 5
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor;
6 6
import org.gvsig.fmap.dal.feature.FeatureStore;
7 7
import org.gvsig.fmap.dal.feature.FeatureType;
8
import org.gvsig.fmap.dal.serverexplorer.filesystem.FilesystemStoreParameters;
8 9

  
9 10
import es.unex.sextante.core.GeoAlgorithm;
10 11
import es.unex.sextante.core.Sextante;
11 12
import es.unex.sextante.dataObjects.IVectorLayer;
12 13
import es.unex.sextante.exceptions.UnsupportedOutputChannelException;
14
import es.unex.sextante.exceptions.WrongOutputIDException;
15
import es.unex.sextante.outputs.FileOutputChannel;
16
import es.unex.sextante.outputs.IOutputChannel;
17
import es.unex.sextante.outputs.Output;
18
import es.unex.sextante.outputs.OutputRasterLayer;
19
import es.unex.sextante.outputs.OutputTable;
20
import es.unex.sextante.outputs.OutputVectorLayer;
13 21

  
14 22
/**
15 23
 * Base class for gvSIG algorithms
......
126 134
				newName = newName + "I";
127 135
		return newName;
128 136
	}
137
	
138
	/*
139
	 * (non-Javadoc)
140
	 * @see es.unex.sextante.core.GeoAlgorithm#getOutputFilename(es.unex.sextante.outputs.Output)
141
	 */
142
	protected String getOutputFilename(Output out) {
143

  
144
		IOutputChannel channel = out.getOutputChannel();
145

  
146
		String sFilename = null;
147
		if(channel.getParameters() instanceof String)
148
			sFilename = (String)((FileOutputChannel)channel).getParameters();
149
		else 
150
			if(channel.getParameters() instanceof FilesystemStoreParameters)
151
				sFilename = ((FilesystemStoreParameters)channel.getParameters()).getFile().getAbsolutePath();
152
		if (sFilename == null){
153
			return null;
154
		}
155
		String[] exts = null;
156
		if (out instanceof OutputRasterLayer){
157
			exts = m_OutputFactory.getRasterLayerOutputExtensions();
158
		}
159
		else if (out instanceof OutputVectorLayer){
160
			exts = m_OutputFactory.getVectorLayerOutputExtensions();
161
		}
162
		else if (out instanceof OutputTable){
163
			exts = m_OutputFactory.getTableOutputExtensions();
164
		}
165
		else{
166
			return null;
167
		}
168

  
169
		for (int i = 0; i < exts.length; i++) {
170
			if (sFilename.endsWith(exts[i])){
171
				return sFilename;
172
			}
173
		}
174
		return sFilename +  "." + exts[0];
175
	}
176
	
177
	/*
178
	 * (non-Javadoc)
179
	 * @see es.unex.sextante.core.GeoAlgorithm#getOutputChannel(java.lang.String)
180
	 */
181
	protected IOutputChannel getOutputChannel(String sName) {
182
		Output out = null;
183
		IOutputChannel channel = null;
184
		try {
185
			out = m_OutputObjects.getOutput(sName);
186
			channel = out.getOutputChannel();
187
			if (channel == null)
188
				return new FileOutputChannel(m_OutputFactory.getTempFilename(out));
189
			else {
190
				String sFilename = getOutputFilename(out);
191
				if (sFilename == null)
192
					return new FileOutputChannel(m_OutputFactory.getTempFilename(out));
193
				else {
194
					if(channel instanceof FileOutputChannel)
195
						((FileOutputChannel) channel).setFilename(sFilename);
196
					return channel;
197
				}
198
			}
199
		} catch (WrongOutputIDException e) {
200
			return null;
201
		}
202
	}
129 203
}

Also available in: Unified diff