if(zipFile == null || !zipFile.exists()){
throw new InvalidParametersException(localizedMessages.getString("widgets.no-widget-file-uploaded")); //$NON-NLS-1$
}
W3CWidget widgetModel = null;
W3CWidgetFactory fac = null;
try {
//
// Parse and validate the zip as a widget
//
final String[] locales = properties.getStringArray("widget.locales");
fac = new W3CWidgetFactory();
fac.setLocales(locales);
fac.setLocalPath(tempUploadFolder);
fac.setOutputDirectory(tempUploadFolder);
fac.setFeatures(Features.getFeatureNames());
fac.setStartPageProcessor(new StartPageProcessor());
widgetModel = fac.parse(zipFile);
new WidgetJavascriptSyntaxAnalyzer(fac.getUnzippedWidgetDirectory());
returnXml(WidgetImportHelper.createXMLWidgetDocument(widgetModel, new File(fac.getUnzippedWidgetDirectory(), "config.xml"), getWookieServerURL(request, "").toString(), false), response);
//send back a 200 ok.
return false;
//
// Catch specific parsing and validation errors and throw exception with error message
//
} catch (InvalidStartFileException ex) {
_logger.error(ex);
throw new InvalidParametersException(
localizedMessages.getString("widgets.no-start-file") + "\n" + ex.getMessage()); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
} catch (BadManifestException ex) {
_logger.error(ex);
String message = ex.getMessage();
if (ex.getMessage() == null || ex.getMessage().equals(""))message = localizedMessages.getString("widgets.invalid-config-xml"); //$NON-NLS-1$
if (ex instanceof InvalidContentTypeException)
message = localizedMessages.getString("widgets.unsupported-content-type");//$NON-NLS-1$
throw new InvalidParametersException(message);
} catch (BadWidgetZipFileException ex) {
_logger.error(ex);
String message = ex.getMessage();
if (ex.getMessage() == null || ex.getMessage().equals(""))message = localizedMessages.getString("widgets.bad-zip-file"); //$NON-NLS-1$
throw new InvalidParametersException(message);
} catch (Exception ex) {
_logger.error(ex);
throw new InvalidParametersException(
localizedMessages.getString("widgets.cant-parse-config-xml") + "\n" + ex.getMessage()); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
} finally {
// ** No matter what always remove all the resources **
if(fac.getUnzippedWidgetDirectory() != null){
WidgetFileUtils.removeWidgetResources(tempUploadFolder, fac.getUnzippedWidgetDirectory().getName());
}
// also delete the uploaded wgt file
if(zipFile.exists()){
zipFile.delete();
}