protected void saveAsset(ImportSource source, VFSFile root, AssetNode node) throws Exception { JSSnippet snippet = (JSSnippet) node.load(root); Document doc = getDatabase().createDocument(); try { setItemValue(doc, "Form", "CodeSnippet"); setItemValue( doc, "Author", doc.getParentDatabase() .getParent() .getUserName()); // Should we make this private (reader field)? setItemValue(doc, "Id", node.getUnid()); setItemValue(doc, "Category", node.getCategory()); setItemValue(doc, "Name", node.getName()); setItemValue(doc, "Description", snippet.getProperty("description")); setItemValue(doc, "Tags", snippet.getProperty("tags")); setItemValue(doc, "ImportSource", source.getName()); setItemValueRichText(doc, "Html", snippet.getHtml()); setItemValueRichText(doc, "Css", snippet.getCss()); setItemValueRichText(doc, "JavaScript", snippet.getJs()); setItemValueRichText(doc, "Properties", snippet.getPropertiesAsString()); setItemValueRichText(doc, "Documentation", snippet.getDocHtml()); doc.save(); } finally { doc.recycle(); } }
private static JSSnippet createSnippetFromXml(String xml) { try { Document document = DOMUtil.createDocument(xml); XResult unid = DOMUtil.evaluateXPath(document, "unid"); XResult js = DOMUtil.evaluateXPath(document.getDocumentElement(), "js"); XResult html = DOMUtil.evaluateXPath(document.getDocumentElement(), "html"); XResult css = DOMUtil.evaluateXPath(document.getDocumentElement(), "css"); XResult docHtml = DOMUtil.evaluateXPath(document.getDocumentElement(), "docHtml"); XResult theme = DOMUtil.evaluateXPath(document.getDocumentElement(), "theme"); XResult description = DOMUtil.evaluateXPath(document.getDocumentElement(), "description"); XResult tags = DOMUtil.evaluateXPath(document.getDocumentElement(), "tags"); XResult labels = DOMUtil.evaluateXPath(document.getDocumentElement(), "labels"); JSSnippet snippet = new JSSnippet(); if (unid != null) snippet.setUnid(unid.getStringValue()); if (js != null) snippet.setJs(js.getStringValue()); if (html != null) snippet.setHtml(html.getStringValue()); if (css != null) snippet.setCss(css.getStringValue()); if (docHtml != null) snippet.setDocHtml(docHtml.getStringValue()); Properties p = new Properties(); snippet.init(p); if (theme != null && theme.getStringValue() != null) snippet.setTheme(theme.getStringValue()); if (description != null && description.getStringValue() != null) snippet.setDescription(description.getStringValue()); if (tags != null && tags.getValues() != null) snippet.setTags(tags.getValues()); if (labels != null && labels.getValues() != null) snippet.setLabels(labels.getValues()); return snippet; } catch (Exception e) { return null; } }