+ "/app:resources/" + data.getFileName();
}
private Gadget loadGadget(GadgetDefinition def) {
GadgetData data = def.getData();
Gadget gadget = new Gadget();
//
if (data instanceof LocalGadgetData) {
try {
String gadgetName = def.getName();
LocalGadgetData localData = (LocalGadgetData) data;
Resource resource = localData.getResources().getFile(localData.getFileName()).getContentResource();
String content = new String(resource.getData(), resource.getEncoding());
GadgetSpec gadgetSpec = new GadgetSpec(Uri.parse(getGadgetURL(gadgetName)), content);
ModulePrefs prefs = gadgetSpec.getModulePrefs();
String title = prefs.getDirectoryTitle();
if (title == null || title.trim().length() < 1) {
title = prefs.getTitle();
}
if (title == null || title.trim().length() < 1) {
title = gadgetName;
}
gadget.setName(def.getName());
gadget.setDescription(prefs.getDescription());
gadget.setLocal(true);
gadget.setTitle(title);
gadget.setReferenceUrl(prefs.getTitleUrl().toString());
gadget.setThumbnail(prefs.getThumbnail().toString());
gadget.setUrl(getJCRGadgetURL(localData));
} catch (Exception ex) {
log.error("Error while loading the content of local gadget " + def.getName(), ex);
}
} else {
RemoteGadgetData remoteData = (RemoteGadgetData) data;
gadget.setName(def.getName());
gadget.setDescription(def.getDescription());
gadget.setLocal(false);
gadget.setTitle(def.getTitle());
gadget.setReferenceUrl(def.getReferenceURL());
gadget.setThumbnail(def.getThumbnail());
gadget.setUrl(remoteData.getURL());
}
//
return gadget;
}