// Path: src/java/org/onesocialweb/openfire/exception/AuthenticationException.java
// @SuppressWarnings("serial")
// public class AuthenticationException extends Exception {
// 
// }
// 
// Path: src/java/org/onesocialweb/openfire/exception/InvalidParameterValueException.java
// @SuppressWarnings("serial")
// public class InvalidParameterValueException extends Exception {
// 
// 	private final String parameter;
// 	
// 	private final String value;
// 
// 	public InvalidParameterValueException(String parameter, String value) {
// 		this.parameter = parameter;
// 		this.value = value;
// 	}
// 	
// 	public String getParameter() {
// 		return parameter;
// 	}
// 
// 	public String getValue() {
// 		return value;
// 	}
// 	
// }
// 
// Path: src/java/org/onesocialweb/openfire/exception/MissingParameterException.java
// @SuppressWarnings("serial")
// public class MissingParameterException extends Exception {
// 
// 	private final String parameter;
// 	
// 	public MissingParameterException(String parameter) {
// 		this.parameter = parameter;
// 	}
// 	
// 	public String getParameter() {
// 		return parameter;
// 	}
// 	
// }
// 
// Path: src/java/org/onesocialweb/openfire/model/FileEntry.java
// public interface FileEntry {
// 
// 	public String getId();
// 
// 	public void setId(String id);
// 
// 	public String getName();
// 
// 	public void setName(String name);
// 
// 	public String getType();
// 
// 	public void setType(String type);
// 
// 	public String getOwner();
// 
// 	public void setOwner(String owner);
// 
// 	public long getSize();
// 
// 	public void setSize(long size);
// 
// }


import java.io.DataInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.List;
import java.util.UUID;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.fileupload.FileItem;
import org.apache.commons.fileupload.ProgressListener;
import org.apache.commons.fileupload.disk.DiskFileItemFactory;
import org.apache.commons.fileupload.servlet.ServletFileUpload;
import org.jivesoftware.admin.AuthCheckFilter;
import org.jivesoftware.util.JiveGlobals;
import org.onesocialweb.openfire.exception.AuthenticationException;
import org.onesocialweb.openfire.exception.InvalidParameterValueException;
import org.onesocialweb.openfire.exception.MissingParameterException;
import org.onesocialweb.openfire.model.FileEntry;
import org.xmpp.packet.JID;
			}
		};
		upload.setProgressListener(progressListener);

		// Process the upload
		List items = upload.parseRequest(request);
		for (Object objItem : items) {
			FileItem item = (FileItem) objItem;
			if (!item.isFormField()) {
				String fileID = UUID.randomUUID().toString();
				File target = new File(getUploadFolder(), fileID);
				item.write(target);
				UploadManager.getInstance().commitFile(user, target, item.getName(), requestId);
				break; // Store only one file
			}
		}
	}

	private void processGet(HttpServletRequest request, HttpServletResponse response) throws MissingParameterException, IOException, InvalidParameterValueException {

		// Validate the request token
		// TODO

		// Process the parameters
		String fileId = request.getParameter("fileId");
		if (fileId == null || fileId.isEmpty()) {
			throw new MissingParameterException("fileId");
		}

		// Get the file entry
// Path: src/java/org/onesocialweb/openfire/exception/AuthenticationException.java
// @SuppressWarnings("serial")
// public class AuthenticationException extends Exception {
// 
// }
// 
// Path: src/java/org/onesocialweb/openfire/exception/InvalidParameterValueException.java
// @SuppressWarnings("serial")
// public class InvalidParameterValueException extends Exception {
// 
// 	private final String parameter;
// 	
// 	private final String value;
// 
// 	public InvalidParameterValueException(String parameter, String value) {
// 		this.parameter = parameter;
// 		this.value = value;
// 	}
// 	
// 	public String getParameter() {
// 		return parameter;
// 	}
// 
// 	public String getValue() {
// 		return value;
// 	}
// 	
// }
// 
// Path: src/java/org/onesocialweb/openfire/exception/MissingParameterException.java
// @SuppressWarnings("serial")
// public class MissingParameterException extends Exception {
// 
// 	private final String parameter;
// 	
// 	public MissingParameterException(String parameter) {
// 		this.parameter = parameter;
// 	}
// 	
// 	public String getParameter() {
// 		return parameter;
// 	}
// 	
// }
// 
// Path: src/java/org/onesocialweb/openfire/model/FileEntry.java
// public interface FileEntry {
// 
// 	public String getId();
// 
// 	public void setId(String id);
// 
// 	public String getName();
// 
// 	public void setName(String name);
// 
// 	public String getType();
// 
// 	public void setType(String type);
// 
// 	public String getOwner();
// 
// 	public void setOwner(String owner);
// 
// 	public long getSize();
// 
// 	public void setSize(long size);
// 
// }


// Path: src/java/org/onesocialweb/openfire/web/FileServlet.java
import java.io.DataInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.List;
import java.util.UUID;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.fileupload.FileItem;
import org.apache.commons.fileupload.ProgressListener;
import org.apache.commons.fileupload.disk.DiskFileItemFactory;
import org.apache.commons.fileupload.servlet.ServletFileUpload;
import org.jivesoftware.admin.AuthCheckFilter;
import org.jivesoftware.util.JiveGlobals;
import org.onesocialweb.openfire.exception.AuthenticationException;
import org.onesocialweb.openfire.exception.InvalidParameterValueException;
import org.onesocialweb.openfire.exception.MissingParameterException;
import org.onesocialweb.openfire.model.FileEntry;
import org.xmpp.packet.JID;

			}
		};
		upload.setProgressListener(progressListener);

		// Process the upload
		List items = upload.parseRequest(request);
		for (Object objItem : items) {
			FileItem item = (FileItem) objItem;
			if (!item.isFormField()) {
				String fileID = UUID.randomUUID().toString();
				File target = new File(getUploadFolder(), fileID);
				item.write(target);
				UploadManager.getInstance().commitFile(user, target, item.getName(), requestId);
				break; // Store only one file
			}
		}
	}

	private void processGet(HttpServletRequest request, HttpServletResponse response) throws MissingParameterException, IOException, InvalidParameterValueException {

		// Validate the request token
		// TODO

		// Process the parameters
		String fileId = request.getParameter("fileId");
		if (fileId == null || fileId.isEmpty()) {
			throw new MissingParameterException("fileId");
		}

		// Get the file entry
		FileEntry fileEntry = UploadManager.getInstance().getFile(fileId);