//
// Parse and validate the zip as a widget
//
final String[] locales = properties.getStringArray("widget.locales");
W3CWidgetFactory fac = new W3CWidgetFactory();
fac.setLocales(locales);
fac.setLocalPath(getServletContext().getContextPath() + properties.getString("widget.widgetfolder"));
fac.setOutputDirectory(WIDGETFOLDER);
fac.setFeatures(Features.getFeatureNames());
fac.setStartPageProcessor(new StartPageProcessor());
W3CWidget widgetModel = fac.parse(zipFile);
new WidgetJavascriptSyntaxAnalyzer(fac.getUnzippedWidgetDirectory());
// File f = new File();
//
// Check if the widget model corresponds to an existing installed widget
//
IPersistenceManager persistenceManager = PersistenceManagerFactory.getPersistenceManager();
if (persistenceManager.findWidgetByGuid(widgetModel.getIdentifier()) == null) {
//
// A new widget was created, so return 201
//
WidgetFactory.addNewWidget(widgetModel, zipFile,false);
returnXml(WidgetImportHelper.createXMLWidgetDocument(widgetModel, new File(fac.getUnzippedWidgetDirectory(), "config.xml"), getWookieServerURL(request, "").toString(), true), response);
return true;
} else {
//
// Widget already exists, so update the widget metadata and configuration details
// and return 200
//
WidgetFactory.update(widgetModel,persistenceManager.findWidgetByGuid(widgetModel.getIdentifier()),false, zipFile);
returnXml(WidgetImportHelper.createXMLWidgetDocument(widgetModel, new File(fac.getUnzippedWidgetDirectory(), "config.xml"), getWookieServerURL(request, "").toString(), true), response);
return false;
}
//