public class GadgetUtil {
private static final Logger log = LoggerFactory.getLogger(GadgetUtil.class);
public static Gadget toGadget(String name, String path, boolean isLocal) throws Exception {
Gadget gadget = new Gadget();
gadget.setName(name);
gadget.setUrl(path);
gadget.setLocal(isLocal);
Map<String, String> metaData = getMapMetadata(reproduceUrl(path, isLocal));
if (metaData.containsKey("errors"))
throw new Exception("error on the server: " + metaData.get("errors"));
String title = metaData.get("directoryTitle");
if (title == null || title.trim().length() < 1)
title = metaData.get("title");
if (title == null || title.trim().length() < 1)
title = gadget.getName();
gadget.setTitle(title);
gadget.setDescription(metaData.get("description"));
gadget.setReferenceUrl(metaData.get("titleUrl"));
gadget.setThumbnail(metaData.get("thumbnail"));
return gadget;
}