*/
public Widget getMetadata(String url) {
Widget widget = new Widget();
JSONObject jsonGadget = null;
try {
jsonGadget = (JSONObject) new JSONTokener(gadgetMetadataRepository.getGadgetMetadata(url)).nextValue();
if ( jsonGadget != null ) {
String query = jsonGadget.getString("modulePrefs");
JSONObject jsonModulePrefsObject = (JSONObject) new JSONTokener(query).nextValue();
if ( jsonModulePrefsObject != null ) {
String title = jsonModulePrefsObject.getString("title");
String titleUrl = jsonModulePrefsObject.getString("titleUrl");
String description = jsonModulePrefsObject.getString("description");
String author = jsonModulePrefsObject.getString("author");
String authorEmail = jsonModulePrefsObject.getString("authorEmail");
String thumbnailUrl = jsonModulePrefsObject.getString("thumbnail");
String screenShot = jsonModulePrefsObject.getString("screenshot");
widget.setTitle(title);
widget.setTitleUrl(titleUrl);
widget.setDescription(description);
widget.setAuthor(author);
widget.setAuthorEmail(authorEmail);
widget.setThumbnailUrl(thumbnailUrl);
widget.setScreenshotUrl(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);
}