* @param url url for the widget
* @return
*/
public Widget getMetadata(String url) {
Widget widget = new WidgetImpl();
JSONObject jsonGadget = null;
try {
jsonGadget = (JSONObject) new JSONTokener(gadgetMetadataRepository.getGadgetMetadata(url)).nextValue();
if (jsonGadget != null) {
String query = jsonGadget.getString("modulePrefs");
if (query != null) {
JSONObject jsonModulePrefsObject = (JSONObject) new JSONTokener(query).nextValue();
if (jsonModulePrefsObject != null) {
widget.setTitle(parseProperty(jsonModulePrefsObject, "title"));
widget.setTitleUrl(parseProperty(jsonModulePrefsObject, "titleUrl"));
widget.setDescription(parseProperty(jsonModulePrefsObject, "description"));
widget.setAuthor(parseProperty(jsonModulePrefsObject, "author"));
widget.setAuthorEmail(parseProperty(jsonModulePrefsObject, "authorEmail"));
widget.setThumbnailUrl(parseProperty(jsonModulePrefsObject, "thumbnail"));
widget.setScreenshotUrl(parseProperty(jsonModulePrefsObject, "screenshot"));
widget.setUrl(url);
widget.setType(getSupportedContext());
}
}
}
} catch (JSONException e) {
try {
String query = jsonGadget.getString("error");
if (query != null) {
JSONObject jsonModuleErrorObject = (JSONObject) new JSONTokener(query).nextValue();
if (jsonModuleErrorObject != null) {
String errorMessage = jsonModuleErrorObject.getString("message");
String errorCode = jsonModuleErrorObject.getString("code");
throw new IllegalArgumentException("HTTP error: " + errorCode + ". Message: " + errorMessage);
}
}
} catch (JSONException e1) {
logger.info("Error while reading: " + e.getLocalizedMessage(), e);