isMultipart = true;
//initialize a MultipartRequestHandler
MultipartRequestHandler multipart = null;
//get an instance of ActionServlet
ActionServlet servlet;
if (bean instanceof ActionForm) {
servlet = ((ActionForm) bean).getServlet();
} else {
throw new ServletException("bean that's supposed to be " +
"populated from a multipart request is not of type " +
"\"org.apache.struts.action.ActionForm\", but type " +
"\"" + bean.getClass().getName() + "\"");
}
String multipartClass = (String)
request.getAttribute(Action.MULTIPART_KEY);
request.removeAttribute(Action.MULTIPART_KEY);
if (multipartClass != null) {
//try to initialize the mapping specific request handler
try {
multipart = (MultipartRequestHandler) Class.forName(multipartClass).newInstance();
}
catch (ClassNotFoundException cnfe) {
servlet.log("MultipartRequestHandler class \"" +
multipartClass + "\" in mapping class not found, " +
"defaulting to global multipart class");
}
catch (InstantiationException ie) {
servlet.log("InstantiaionException when instantiating " +
"MultipartRequestHandler \"" + multipartClass + "\", " +
"defaulting to global multipart class, exception: " +
ie.getMessage());
}
catch (IllegalAccessException iae) {
servlet.log("IllegalAccessException when instantiating " +
"MultipartRequestHandler \"" + multipartClass + "\", " +
"defaulting to global multipart class, exception: " +
iae.getMessage());
}
}
if (multipart == null) {
//try to initialize the global multipart class
try {
multipart = (MultipartRequestHandler) Class.forName(servlet.getMultipartClass()).newInstance();
}
catch (ClassNotFoundException cnfe) {
throw new ServletException("Cannot find multipart class \"" +
servlet.getMultipartClass() + "\"" +
", exception: " + cnfe.getMessage());
}
catch (InstantiationException ie) {
throw new ServletException("InstantiaionException when instantiating " +
"multipart class \"" + servlet.getMultipartClass() +
"\", exception: " + ie.getMessage());
}
catch (IllegalAccessException iae) {
throw new ServletException("IllegalAccessException when instantiating " +
"multipart class \"" + servlet.getMultipartClass() +
"\", exception: " + iae.getMessage());
}
}