String uuid = Utils.getUUID(req);
if (profile == null) {
profile = _profileService.findProfile(req, profileName);
}
Repository repository = profile.getRepository();
if(action != null && action.equals("getwidgets")) {
List<String> widgetList;
try {
widgetList = ServletUtil.getFormWidgetList(profile, repository, uuid);
} catch (Throwable t) {
widgetList = new ArrayList<String>();
}
JSONObject jsonObject = new JSONObject();
if(widgetList != null && widgetList.size() > 0) {
for(String widget : widgetList) {
try {
jsonObject.put(widget, widget);
} catch (Exception e) {
e.printStackTrace();
}
}
}
resp.setCharacterEncoding("UTF-8");
resp.setContentType("application/json");
resp.getWriter().write(jsonObject.toString());
} else if(action != null && action.equals("getwidgetsource")) {
try {
Asset<String> widgetAsset = repository.loadAssetFromPath(profile.getRepositoryGlobalDir( uuid ) + "/" + widgetName+".fw");
resp.setCharacterEncoding("UTF-8");
resp.setContentType("text/plain");
resp.getWriter().write(widgetAsset.getAssetContent());