Package com.google.json.serialization

Examples of com.google.json.serialization.JsonObject$Iter


* Test for {@link JsonTraverser} class.
*/
public class JsonTraverserTest extends TestCase {

  private JsonObject makeChild(String property, long value) {
    JsonObject result = new JsonObject();
    result.put(property, value);
    return result;
  }
View Full Code Here


    result.put(property, value);
    return result;
  }

  public void testTraversePostorder() throws JsonException {
    JsonObject root = new JsonObject();
    root.put("value", 3);
    JsonArray children = new JsonArray();
    children.add(makeChild("value", 1));
    children.add(makeChild("value", 2));
    root.put("children", children);

    JsonTraverser.get().traversePostOrder(root, new JsonVisitor() {
      private long curr = 0;

      public void postProcess() {
View Full Code Here

      }
    });
  }

  public void testTraversePreorder() throws JsonException {
    JsonObject root = new JsonObject();
    root.put("value", 1);
    JsonArray children = new JsonArray();
    children.add(makeChild("value", 2));
    children.add(makeChild("value", 3));
    root.put("children", children);

    JsonTraverser.get().traversePreOrder(root, new JsonVisitor() {
      private long curr = 0;

      public void postProcess() {
View Full Code Here

      }
    });
  }

  public void testTraversePostorderNumber() throws JsonException {
    JsonObject root = new JsonObject();
    root.put("value", 3);
    JsonArray children = new JsonArray();
    children.add(makeChild("value", 1));
    children.add(makeChild("value", 2));
    root.put("children", children);

    JsonTraverser.get().traverse(root, new JsonVisitorDouble() {
      private long curr = 0;

      public void postProcess() {
View Full Code Here

      throw new UnableToCompleteException();
    }
  }

  private static JsonValue createBgScriptsObject(String bgScriptName) {
    final JsonObject obj = JsonObject.create();
    final JsonArray scriptsArray = JsonArray.create();
    scriptsArray.add(bgScriptName);   
    obj.put("scripts", scriptsArray);
    return obj;
  }
View Full Code Here

  private static JsonValue createContentScriptsArray(
      SortedSet<ContentScriptArtifact> contentScripts) {
    final JsonArray array = JsonArray.create();
    for (ContentScriptArtifact contentScript : contentScripts) {
      JsonObject entry = JsonObject.create();
      JsonArray whiteList = JsonArray.create();
      String[] patterns = contentScript.getWhiteList();
      for (String pattern : patterns) {
        whiteList.add(pattern);
      }
      entry.put("matches", whiteList);
      JsonArray path = JsonArray.create();
      path.add(contentScript.getPath());
      entry.put("js", path);
      entry.put("run_at", contentScript.getRunAt());
      array.add(entry);
    }
    return array;
  }
View Full Code Here

  private static JsonValue createPageActionsArray(
      SortedSet<PageActionArtifact> pageActions) {
    final JsonArray pageActionArray = JsonArray.create();
    for (PageActionArtifact pageAction : pageActions) {
      final JsonObject pageActionObject = JsonObject.create();
      pageActionObject.put("id", pageAction.getId());
      pageActionObject.put("name", pageAction.getName());
      final JsonArray iconsArray = JsonArray.create();
      String[] icons = pageAction.getIcons();
      for (String icon : icons) {
        iconsArray.add(icon);
      }
      pageActionObject.put("icons", iconsArray);
      pageActionArray.add(pageActionObject);
    }
    return pageActionArray;
  }
View Full Code Here

  }

  private static JsonValue createPluginsArray(SortedSet<PluginArtifact> plugins) {
    JsonArray pluginsArray = JsonArray.create();
    for (PluginArtifact plugin : plugins) {
      JsonObject pluginObject = JsonObject.create();
      pluginObject.put("path", plugin.getPath());
      pluginObject.put("public", plugin.isPublic());
      pluginsArray.add(pluginObject);
    }
    return pluginsArray;
  }
View Full Code Here

    }
    // TODO(jaimeyap): This should really be a user error and not an assertion
    // failure.
    assert (size == 1) : "Only 1 BrowserAction per extension allowed.";
    BrowserActionArtifact browserAction = browserActions.first();
    final JsonObject browserActionObject = JsonObject.create();
    browserActionObject.put("name", browserAction.getName());
    final JsonArray iconsArray = JsonArray.create();
    String[] icons = browserAction.getIcons();
    for (String icon : icons) {
      iconsArray.add(icon);
    }
    browserActionObject.put("icons", iconsArray);
    browserActionObject.put("default_icon", browserAction.getDefaultIcon());

    return browserActionObject;
  }
View Full Code Here

      String backgroundPageFileName, ExtensionArtifact extension,
      SortedSet<PageActionArtifact> pageActions,
      SortedSet<BrowserActionArtifact> browserActions,
      SortedSet<ContentScriptArtifact> contentScripts,
      SortedSet<PluginArtifact> plugins) throws UnableToCompleteException {
    final JsonObject config = JsonObject.create();
    config.put("name", extension.getName());
    config.put("version", extension.getVersion());

    if (!extension.getUpdateUrl().equals(Extension.NO_UPDATE_URL)) {
      config.put("update_url", extension.getUpdateUrl());
    }

    // All other fields in the manifest are optional
    if (extension.getDescription().length() > 0) {
      config.put("description", extension.getDescription());
    }
    if (backgroundPageFileName.length() > 0) {
      config.put("background", createBgScriptsObject(backgroundPageFileName));
    }
    if (contentScripts.size() > 0) {
      config.put("content_scripts", createContentScriptsArray(contentScripts));
    }
    if (pageActions.size() > 0) {
      config.put("page_actions", createPageActionsArray(pageActions));
    }

    if (browserActions.size() > 0) {
      JsonValue browserAction = createBrowserAction(browserActions);
      if (browserAction != null) {
        config.put("browser_action", browserAction);
      }
    }

    if (plugins.size() > 0) {
      config.put("plugins", createPluginsArray(plugins));
    }

    if (extension.getPermissions().length > 0) {
      final JsonArray perms = JsonArray.create();
      for (String perm : extension.getPermissions()) {
        perms.add(perm);
      }
      config.put("permissions", perms);
    }

    if (extension.getIcons().length > 0) {
      JsonObject icons = JsonObject.create();
      for (IconInfo info : extension.getIcons()) {
        icons.put(Integer.toString(info.getSize()), info.getFilename());
      }
      config.put("icons", icons);
    }

    if (extension.getPublicKey().length() > 0) {
View Full Code Here

TOP

Related Classes of com.google.json.serialization.JsonObject$Iter

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.