return new GadgetSnippetNodeFactory();
}
@Override
protected void saveAsset(ImportSource source, VFSFile root, AssetNode node, Asset asset) throws Exception {
GadgetSnippet snippet = (GadgetSnippet)asset;
Document doc = getDatabase().createDocument();
try {
// The gadget are actually imported with their directory
// We adapt the category & unid consequently
String name = snippet.getTitle();
if(StringUtil.isEmpty(name)) {
name = createPrettyName(node.getParent().getName());
}
String cat = createPrettyName(node.getParent().getCategory());
String unid = PathUtil.concat(cat,node.getUnid(),Node.SEPARATOR);
unid = Node.encodeUnid(unid);
setItemValue(doc,"Form", FORM);
setItemValue(doc,"Author", doc.getParentDatabase().getParent().getEffectiveUserName()); // Should we make this private (reader field)?
setItemValue(doc,"Id", unid);
setItemValue(doc,"Category", cat);
setItemValue(doc,"Name", name);
setItemValue(doc,"FilterRuntimes", snippet.getProperty("runtimes"));
setItemValue(doc,"Description", snippet.getProperty("description"));
setItemValues(doc,"Tags", snippet.getProperty("tags"));
setItemValue(doc,"ImportSource", source.getName());
setItemValueRichText(doc,"Gadget", snippet.getGadgetXml());
setItemValueRichText(doc,"Html", snippet.getHtml());
setItemValueRichText(doc,"Css", snippet.getCss());
setItemValueRichText(doc,"JavaScript", snippet.getJs());
setItemValueRichText(doc,"Json", snippet.getJson());
snippet.getProperties().remove("endpoints");
snippet.getProperties().remove("description");
setItemValueRichText(doc,"Properties", snippet.getPropertiesAsString());
setItemValueRichText(doc,"Documentation", snippet.getDocHtml());
doc.save();
} finally {
doc.recycle();
}