try {
List list = new ArrayList();
WriteableRepository repo = PortletManager.getWritableRepositories(actionRequest)[0];
File uploadFile = null;
File file = null;
String name = null;
String basename = null;
String fileType = null;
String artifact = null;
String version = null;
String group = null;
PortletFileUpload uploader = new PortletFileUpload(new DiskFileItemFactory());
try {
List items = uploader.parseRequest(actionRequest);
for (Iterator i = items.iterator(); i.hasNext();) {
FileItem item = (FileItem) i.next();
if (!item.isFormField()) {
String fieldName = item.getFieldName().trim();
name = item.getName().trim();
if (name.length() == 0) {
file = null;
} else {
// IE sends full path while Firefox sends just basename
// in the case of "FullName" we may be able to infer the group
// Note, we can't use File.separatorChar because the file separator
// is dependent upon the client and not the server.
String fileChar = "\\";
int fileNameIndex = name.lastIndexOf(fileChar);
if (fileNameIndex == -1) {
fileChar = "/";
fileNameIndex = name.lastIndexOf(fileChar);
}
if (fileNameIndex != -1) {
basename = name.substring(fileNameIndex + 1);
}
else {
basename = name;
}
// Create the temporary file to be used for import to the server
file = File.createTempFile("geronimo-import", "");
file.deleteOnExit();
log.debug("Writing repository import file to "+file.getAbsolutePath());
}
if ("local".equals(fieldName)) {
uploadFile = file;
}
if (file != null) {
try {
item.write(file);
} catch (Exception e) {
throw new PortletException(e);
}
}
// This is not the file itself, but one of the form fields for the URI
} else {
String fieldName = item.getFieldName().trim();
if ("group".equals(fieldName)) {
group = item.getString().trim();
} else if ("artifact".equals(fieldName)) {
artifact = item.getString().trim();
} else if ("version".equals(fieldName)) {
version = item.getString().trim();
} else if ("fileType".equals(fieldName)) {
fileType = item.getString().trim();
}
}
}
String uri = group + "/" + artifact + "/" + version + "/" + fileType;
repo.copyToRepository(file, new URI(uri), new FileWriteMonitor() {
public void writeStarted(String fileDescription) {
System.out.print("Copying into repository "+fileDescription+"...");
System.out.flush();
}