Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Copyright (c) 2011 Michael Ruflin, Andr´┐Ż Locher, Claudia von Bastian. This file is part of Tatool. Tatool is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. Tatool is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with Tatool. If not, see <http://www.gnu.org/licenses/>. /
 
 package ch.tatool.core.module.creator;
 
 import java.io.File;
 
 
 
 public class FileDownloadWorker implements Worker {
 	private File file;
 	private String errorTitle;
 	private String errorText;
 	private Messages messages;

Loads the module file from the data server using the provided code.
 
 	public void loadFile(String urlint timeout) {
 		// give it a timeout to ensure the user does not wait forever in case of connectivity problems
 		HttpParams params = new BasicHttpParams();
 		if (timeout > 0) {
 			HttpConnectionParams.setConnectionTimeout(paramstimeout);
 			HttpConnectionParams.setSoTimeout(paramstimeout);
 		}
 		
 		// remove whitespaces since they are not allowed
 		url = url.replaceAll("\\s+""").trim();
 		
 		// create a http client
 		DefaultHttpClient httpclient = new DefaultHttpClient(params);
 		HttpGet httpGet = new HttpGet(url);
 
 		 = null;
 		 = null;
 		 = null;
 		try {
 			HttpResponse response = httpclient.execute(httpGet);
 			if (response.getStatusLine().getStatusCode() != .) {
 				 = .getString("General.errorMessage.windowTitle.error");
 				  = .getString("DataExportError.online.http");
 				 += "\n" + response.getStatusLine().getReasonPhrase()+ " (" + response.getStatusLine().getStatusCode() + ")";
 			} else {
 				// copy the response into a temporary file
 				HttpEntity entity = response.getEntity();
 				byte[] data = EntityUtils.toByteArray(entity);
 				String returnString = new String(data);
 				if (!returnString.startsWith("General")) {
 					File tmpFile = File.createTempFile("tatool_module""tmp");
 					FileUtils.writeByteArrayToFile(tmpFiledata);
 					tmpFile.deleteOnExit();
 					this. = tmpFile;
 				} else {
 					 = .getString("General.errorMessage.windowTitle.error");
 					 = .getString(returnString);
 				}
 			}
 		} catch (IOException ioe) {
 			 = .getString("General.errorMessage.windowTitle.error");
 			 = .getString("DataExportError.online.http");
 		} finally {
 			// make sure we close the connection manager
 			httpclient.getConnectionManager().shutdown();
 		}
 	}
 	
 	public boolean hasFinished() {
 		return  != null;
 	}
 
 	public File getFile() {
 		return ;
 	}
 
	public void setFile(File file) {
		this. = file;
	}
	public String getErrorTitle() {
		return ;
	}
	public void setErrorTitle(String errorTitle) {
		this. = errorTitle;
	}
	public String getErrorText() {
		return ;
	}
	public void setErrorText(String errorText) {
		this. = errorText;
	}
	public void setMessages(Messages messages) {
    	this. = messages;
    }
    
    public Messages getMessages() {
		return ;
	}
New to GrepCode? Check out our FAQ X