SimpleFormHandler handler = new SimpleFormHandler(status);
status.clear();
String graphicElement = request.getParameter("graphicElement");
if (graphicElement == null || "".equals(graphicElement)) {
log.error("Missing required parameter: graphicElement.");
return new ShowCurrentScreenResponse();
}
String graphicElementClassName = graphicElement.substring(0, 1).toUpperCase() + graphicElement.substring(1);
Class graphicElementClass = Class.forName("org.jboss.dashboard.ui.resources." + graphicElementClassName);
String workspaceId = handler.validateString(request, "workspaceId", false);
String sectionId = handler.validateString(request, "sectionId", false);
String panelId = handler.validateString(request, "panelId", false);
String id = handler.validateString(request, graphicElement + "Id", true);
if (!isValidId(id)) {
status.addWrongField(graphicElement + "Id");
}
try {
if (request.getUploadedFilesCount() == 1) {
if (status.isValidated()) {
log.debug("Creating preview.");
try {
Method previewGetter = graphicElementClass.getMethod("getPreviewInstance", new Class[]{File.class, String.class, Long.class, Long.class, String.class});
GraphicElementPreview preview = (GraphicElementPreview) previewGetter.invoke(null, new Object[]{request.getFilesByParamName().get("file"), workspaceId, sectionId == null ? null : new Long(sectionId), panelId == null ? null : new Long(panelId), id});
request.getSessionObject().setAttribute(PREVIEW_ATTRIBUTE, preview);
log.debug("Created preview " + preview);
} catch (Exception e) {
log.error("Error making preview: ", e);
}
}
} else {
log.debug("Status is not valid. Number of files is not 1, it is " + request.getUploadedFilesCount());
status.addWrongField("zipFile");
}
} catch (Exception e) {
status.addError(e.getMessage());
}
if (status.isValidated()) {
String previewPage = request.getParameter("previewPage");
if (previewPage != null) {
return new ShowScreenResponse(previewPage);
}
}
return new ShowCurrentScreenResponse();
}