Package com.ibm.sbt.playground.assets.jssnippets

Examples of com.ibm.sbt.playground.assets.jssnippets.JSSnippet


      String str = null;
      RootNode rootNode = SnippetFactory.getJsSnippets(getServletContext(), request);
      if (unid != null && unid.length() > 0) {
        VFSFile rootFile = SnippetFactory.getJsRootFile(getServletContext());
        JSSnippet snippet = (JSSnippet) rootNode.loadAsset(rootFile, unid);
        if (snippet == null) {
          service400(request, response, "Invalid unid: {0}", unid);
          return;
        }
        if (FORMAT_JSON.equals(format)) {
View Full Code Here


   * @param request
   * @param snippetName
   * @return JSSnippet corresponding to snippetName
   */
  public static JSSnippet getJsSnippet(ServletContext context, HttpServletRequest request, String snippetName) {
    JSSnippet snippet = (JSSnippet) getAsset(context, request, snippetName, new JSSnippetNodeFactory(), jsRootPath);
        if (snippet == null) {
            snippet = loadAssetRemote(context, request, snippetName);
        }
        return snippet;
    }
View Full Code Here

            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;
        }
View Full Code Here

   * @param request
   * @param snippetName
   * @return JSSnippet corresponding to snippetName
   */
  public static JSSnippet getJsSnippet(ServletContext context, HttpServletRequest request, String snippetName) {
    JSSnippet snippet = (JSSnippet) getAsset(context, request, snippetName, new JSSnippetNodeFactory(), jsRootPath);
        if (snippet == null) {
            snippet = loadAssetRemote(context, request, snippetName);
        }
        return snippet;
    }
View Full Code Here

            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;
        }
View Full Code Here

   *
   * @param snippetName
   * @return JSSnippet corresponding to snippetName
   */
  public static JSSnippet getJsSnippet(String snippetName) {
    JSSnippet snippet = (JSSnippet) getAsset(snippetName, new JSSnippetNodeFactory(), jsRootPath);
        return snippet;
    }
View Full Code Here

    return new JSSnippetNodeFactory();
  }

  @Override
  protected void saveAsset(ImportSource source, VFSFile root, AssetNode node, Asset asset) throws Exception {
    JSSnippet snippet = (JSSnippet)asset;
    Document doc = getDatabase().createDocument();
    try {
      setItemValue(doc,"Form", FORM);
      setItemValue(doc,"Author", doc.getParentDatabase().getParent().getEffectiveUserName()); // Should we make this private (reader field)?
      setItemValue(doc,"Id", node.getUnid());
      setItemValue(doc,"Category", node.getCategory());
      setItemValue(doc,"Name", node.getName());
      setItemValue(doc,"FilterRuntimes", snippet.getProperty("runtimes"));
      setItemValue(doc,"FilterLibraries", snippet.getProperty("jslibs"));
      setItemValues(doc,"Tags", snippet.getProperty("tags"));
      setItemValue(doc,"Description", snippet.getProperty("description"));
      setItemValue(doc,"ImportSource", source.getName());
      setItemValueRichText(doc,"Html", snippet.getHtml());
      setItemValueRichText(doc,"Css", snippet.getCss());
      setItemValueRichText(doc,"JavaScript", snippet.getJs());
      snippet.getProperties().remove("endpoints");
      snippet.getProperties().remove("jslibs");
      snippet.getProperties().remove("description");
      setItemValueRichText(doc,"Properties", snippet.getPropertiesAsString());
      setItemValueRichText(doc,"Documentation", snippet.getDocHtml());
     
      doc.save();
    } finally {
      doc.recycle();
    }
View Full Code Here

  public JavaScriptPreviewPage executeSnippet(String snippetName) {
    File f = new File(System.getProperty("user.dir")+"/../com.ibm.sbt.sample.web/src/main/webapp/samples/js");
    if (!f.exists()) throw new RuntimeException("File Not Found: " + f.getAbsolutePath());
    BaseFileLister.jsRootPath = f.getAbsolutePath();

    JSSnippet snippet = (JSSnippet) BaseFileLister
        .getJsSnippet(snippetName);
   
    if (snippet == null) {
      throw new IllegalArgumentException("Snippet "+snippetName+ " not found at " + BaseFileLister.jsRootPath);
    }
   
    if (snippet.getHtml()!= null) {
    String html = snippet.getHtml().replaceAll("'","\'").replaceAll("\n", "\\\\n").replaceAll("\r", "");
   
    String script = " "+
        "var __bdy = document.getElementsByTagName('body')[0]; \n" +
        "__bdy.innerHTML = '';\n" +
        "__bdy.innerHTML = '"+html+"';\n" +
View Full Code Here

TOP

Related Classes of com.ibm.sbt.playground.assets.jssnippets.JSSnippet

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.