Example usage for org.json.simple JSONArray addAll

List of usage examples for org.json.simple JSONArray addAll

Introduction

In this page you can find the example usage for org.json.simple JSONArray addAll.

Prototype

public boolean addAll(Collection<? extends E> c) 

Source Link

Document

Appends all of the elements in the specified collection to the end of this list, in the order that they are returned by the specified collection's Iterator.

Usage

From source file:biomine.bmvis2.pipeline.EdgeLabelOperation.java

public JSONObject toJSON() {
    JSONObject ret = new JSONObject();
    JSONArray enabled = new JSONArray();
    enabled.addAll(enabledLabels);
    ret.put("enabled", enabled);
    return ret;/*  w w  w . j  a  v a 2  s .  c o  m*/
}

From source file:biomine.bmvis2.pipeline.ManualGroupOperation.java

@Override
public JSONObject toJSON() {
    JSONObject ret = new JSONObject();
    JSONArray nodesArr = new JSONArray();
    nodesArr.addAll(nodes);
    ret.put("nodes", nodesArr);
    return ret;//w w  w.  j  a v  a2 s .c  o  m
}

From source file:biomine.bmvis2.pipeline.DeleteElementsOperation.java

public JSONObject toJSON() {
    JSONObject ret = new JSONObject();
    JSONArray nodes = new JSONArray();
    JSONArray edges = new JSONArray();

    nodes.addAll(this.deletedNodes);
    edges.addAll(this.deletedEdges);

    ret.put(DELETED_NODES_KEY, nodes);/*w w w .jav  a2 s.  c  om*/
    ret.put(DELETED_EDGES_KEY, edges);

    return ret;
}

From source file:edu.ucsd.library.xdre.web.ExcelImportController.java

public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws Exception {
    String ds = request.getParameter("ts");
    String collectionId = request.getParameter("category");
    String unit = request.getParameter("unit");
    String message = request.getParameter("message");
    String fileStore = request.getParameter("fs");
    String licenseBeginDate = request.getParameter("licenseBeginDate");
    String licenseEndDate = request.getParameter("licenseEndDate");

    HttpSession session = request.getSession();
    DAMSClient damsClient = null;//www  .j a  va2 s . c  om
    Map dataMap = new HashMap();
    try {

        // initiate column name and control values for validation
        String columns = request.getServletContext().getRealPath("files/valid_columns.xlsx");
        String cvs = request.getServletContext().getRealPath("files/valid_cv_values.xlsx");
        try {
            ExcelSource.initControlValues(new File(columns), new File(cvs));
        } catch (Exception e) {
            e.printStackTrace();
        }

        if (ds == null)
            ds = Constants.DEFAULT_TRIPLESTORE;

        damsClient = new DAMSClient(Constants.DAMS_STORAGE_URL);
        damsClient.setTripleStore(ds);

        Map<String, String> collectionMap = damsClient.listCollections();
        Map<String, String> unitsMap = damsClient.listUnits();
        List<String> tsSrcs = damsClient.listTripleStores();
        List<String> fsSrcs = damsClient.listFileStores();
        String fsDefault = damsClient.defaultFilestore();
        if (fileStore == null || fileStore.length() == 0)
            fileStore = fsDefault;

        message = (!StringUtils.isBlank(message) || StringUtils.isBlank(collectionId)) ? message
                : (String) session.getAttribute("message");
        session.removeAttribute("message");

        JSONArray accessValues = new JSONArray();
        accessValues.addAll(Arrays.asList(RecordUtil.ACCESS_VALUES));

        Map<String, String> countryCodes = MarcModsImportController.getCountryCodes(request);

        dataMap.put("categories", collectionMap);
        dataMap.put("category", collectionId);
        dataMap.put("units", unitsMap);
        dataMap.put("unit", unit);
        dataMap.put("message", message);
        dataMap.put("triplestore", ds);
        dataMap.put("triplestores", tsSrcs);
        dataMap.put("filestores", fsSrcs);
        dataMap.put("filestore", fileStore);
        dataMap.put("filestoreDefault", fsDefault);
        dataMap.put("copyrightStatus", RecordUtil.COPYRIGHT_VALUES);
        dataMap.put("program", RecordUtil.PROGRAM_VALUES);
        dataMap.put("accessOverride", accessValues);
        dataMap.put("licenseBeginDate", licenseBeginDate);
        dataMap.put("licenseEndDate", licenseEndDate);
        dataMap.put("countryCodes", countryCodes);

    } catch (Exception e) {
        e.printStackTrace();
        message += e.getMessage();
    } finally {
        if (damsClient != null)
            damsClient.close();
    }
    return new ModelAndView("excelImport", "model", dataMap);
}

From source file:edu.ucsd.library.xdre.web.MarcModsImportController.java

public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws Exception {
    String ds = request.getParameter("ts");
    String collectionId = request.getParameter("category");
    String unit = request.getParameter("unit");
    String reset = request.getParameter("reset");
    String message = request.getParameter("message");
    String fileStore = request.getParameter("fs");
    String source = request.getParameter("source");
    String bibNumber = request.getParameter("bib");
    String modsXml = request.getParameter("mods");
    String copyrightStatus = request.getParameter("copyrightStatus");
    String copyrightJurisdiction = request.getParameter("copyrightJurisdiction");
    String copyrightOwner = request.getParameter("copyrightOwner");
    String program = request.getParameter("program");
    String accessOverride = request.getParameter("accessOverride");
    String licenseBeginDate = request.getParameter("licenseBeginDate");
    String licenseEndDate = request.getParameter("licenseEndDate");

    HttpSession session = request.getSession();
    DAMSClient damsClient = null;//from   w  ww. ja v  a  2s  .  co m
    Map dataMap = new HashMap();
    try {
        if (ds == null)
            ds = Constants.DEFAULT_TRIPLESTORE;

        damsClient = new DAMSClient(Constants.DAMS_STORAGE_URL);
        damsClient.setTripleStore(ds);

        Map<String, String> collectionMap = damsClient.listCollections();
        Map<String, String> unitsMap = damsClient.listUnits();
        List<String> tsSrcs = damsClient.listTripleStores();
        List<String> fsSrcs = damsClient.listFileStores();
        String fsDefault = damsClient.defaultFilestore();
        if (fileStore == null || fileStore.length() == 0)
            fileStore = fsDefault;

        message = (!StringUtils.isBlank(message) || StringUtils.isBlank(collectionId)) ? message
                : (String) request.getSession().getAttribute("message");
        request.getSession().removeAttribute("message");

        JSONArray accessValues = new JSONArray();
        accessValues.addAll(Arrays.asList(RecordUtil.ACCESS_VALUES));

        Map<String, String> countryCodes = getCountryCodes(request);

        dataMap.put("categories", collectionMap);
        dataMap.put("category", collectionId);
        dataMap.put("units", unitsMap);
        dataMap.put("unit", unit);
        dataMap.put("message", message);
        dataMap.put("triplestore", ds);
        dataMap.put("triplestores", tsSrcs);
        dataMap.put("filestores", fsSrcs);
        dataMap.put("filestore", fileStore);
        dataMap.put("filestoreDefault", fsDefault);
        dataMap.put("copyrightStatus", RecordUtil.COPYRIGHT_VALUES);
        dataMap.put("program", RecordUtil.PROGRAM_VALUES);
        dataMap.put("accessOverride", accessValues);
        dataMap.put("licenseBeginDate", licenseBeginDate);
        dataMap.put("licenseEndDate", licenseEndDate);
        dataMap.put("countryCodes", countryCodes);

    } catch (Exception e) {
        e.printStackTrace();
        message += e.getMessage();
    } finally {
        if (damsClient != null)
            damsClient.close();
    }
    return new ModelAndView("marcModsImport", "model", dataMap);
}

From source file:com.valygard.aohruthless.utils.inventory.InventoryHandler.java

/**
 * Store the player's inventory in the directory. Doesn't avoid overrides
 * because we are only saving the most recent inventory. This method stores
 * the inventory in memory and on disk for convenience.
 * /*from  w w w  . ja  v  a  2  s  .com*/
 * @param p
 */
@SuppressWarnings("unchecked")
public void storeInventory(Player p) {
    ItemStack[] items = p.getInventory().getContents();
    ItemStack[] armor = p.getInventory().getArmorContents();

    UUID uuid = p.getUniqueId();
    String name = p.getName();

    this.items.put(name, items);
    this.armor.put(name, armor);

    JsonConfiguration json = new JsonConfiguration(dir, uuid.toString());
    json.writeString("last-known-username", name).writeString("uuid", uuid.toString());

    JSONArray contents = new JSONArray();
    JSONArray armorContents = new JSONArray();

    contents.addAll(Arrays.asList(items));
    armorContents.addAll(Arrays.asList(armor));

    json.writeArray("items", contents).writeArray("armor", armorContents);

    contents.clear();
    armorContents.clear();

    // And clear the inventory
    InventoryUtils.clearInventory(p);
}

From source file:com.dnastack.ga4gh.impl.BeaconizeVariantImpl.java

/**
 * Queries the Variant API implementation for variants at the given position
 *
 * @param reference The reference (or chromosome)
 * @param position  Position on the reference
 * @param alt       The alternate allele to match against (currently not supported by GASearchVariantsRequest)
 * @return A JSON Object containing a GASearchVariantsResponse
 * @throws IOException    Problems contacting API
 * @throws ParseException Problems parsing response
 *//*from  www  . j  a v  a2s  .c  om*/
private JSONObject submitVariantSearchRequest(String reference, long position, String alt)
        throws IOException, ParseException {
    JSONObject obj = new JSONObject();

    JSONArray list = new JSONArray();
    list.addAll(Arrays.asList(variantSetIds));

    obj.put("variantSetIds", list);
    obj.put("referenceName", reference);
    obj.put("start", position);
    obj.put("end", (position + 1));

    String json = obj.toJSONString();

    URL url = new URL(fullVariantSearchURL);

    StringBuilder postData = new StringBuilder();
    postData.append(json);

    byte[] postDataBytes = postData.toString().getBytes("UTF-8");

    HttpURLConnection conn = (HttpURLConnection) url.openConnection();
    conn.setRequestMethod("POST");
    conn.setRequestProperty("Content-Type", "application/json");
    conn.setRequestProperty("Content-Length", String.valueOf(postDataBytes.length));
    conn.setDoOutput(true);
    conn.getOutputStream().write(postDataBytes);

    StringBuilder sb = new StringBuilder();

    Reader in = new BufferedReader(new InputStreamReader(conn.getInputStream(), "UTF-8"));
    for (int c; (c = in.read()) >= 0;) {
        sb.append((char) c);
    }

    String jsonString = sb.toString();

    return (JSONObject) JSONValue.parseWithException(jsonString);
}

From source file:be.iminds.aiolos.ui.ComponentServlet.java

@SuppressWarnings("unchecked")
@Override//from  w  w  w . j av a2 s .  c  om
protected void writeJSON(Writer w, Locale locale) throws IOException {
    Collection<ComponentDescription> components = getComponentsInfo();
    final Object[] status = getStatusLine(components);

    final JSONObject obj = new JSONObject();

    JSONArray stat = new JSONArray();
    for (int i = 0; i < status.length; i++)
        stat.add(status[i]);
    obj.put("status", stat);

    final JSONArray list = new JSONArray();
    for (ComponentDescription component : components) {
        JSONObject jsonComponent = new JSONObject();
        jsonComponent.put("id", component.componentId);
        jsonComponent.put("version", component.version);
        JSONArray jsonNodes = new JSONArray();
        jsonNodes.addAll(component.nodes);
        jsonComponent.put("nodes", jsonNodes);
        list.add(jsonComponent);
    }
    obj.put("components", list);

    w.write(obj.toJSONString());
}

From source file:de.themoep.chestshoptools.ShopInfoCommand.java

public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
    if (args.length > 0) {
        return false;
    }//from   ww  w .j  av  a  2  s . c om
    if (!(sender instanceof Player)) {
        sender.sendMessage(ChatColor.RED + "This command can only be run by a player!");
        return true;
    }
    Block lookingAt = ((Player) sender).getTargetBlock((Set<Material>) null, 10);
    if (lookingAt == null) {
        sender.sendMessage(
                ChatColor.RED + "Please look at a shop sign or chest!" + ChatColor.DARK_GRAY + " (0)");
        return true;
    }
    Sign shopSign = null;
    if (lookingAt.getState() instanceof Chest) {
        shopSign = uBlock.getConnectedSign((Chest) lookingAt.getState());
    } else if (lookingAt.getState() instanceof Sign && ChestShopSign.isValid(lookingAt)) {
        shopSign = (Sign) lookingAt.getState();
    }
    if (shopSign == null) {
        sender.sendMessage(
                ChatColor.RED + "Please look at a shop sign or chest!" + ChatColor.DARK_GRAY + " (1)");
        return true;
    }

    String name = shopSign.getLine(ChestShopSign.NAME_LINE);
    String quantity = shopSign.getLine(ChestShopSign.QUANTITY_LINE);
    String prices = shopSign.getLine(ChestShopSign.PRICE_LINE);
    String material = shopSign.getLine(ChestShopSign.ITEM_LINE);

    String ownerName = NameManager.getFullNameFor(NameManager.getUUIDFor(name));
    ItemStack item = MaterialUtil.getItem(material);

    if (item == null || !NumberUtil.isInteger(quantity)) {
        sender.sendMessage(Messages.prefix(Messages.INVALID_SHOP_DETECTED));
        return true;
    }

    sender.sendMessage(Messages.prefix(ChatColor.GREEN + "Besitzer: " + ChatColor.WHITE + ownerName));
    if (plugin.getShowItem() == null) {
        sender.sendMessage(Messages.prefix(ChatColor.GREEN + "Item: " + ChatColor.WHITE + material));
    } else {
        String itemJson = plugin.getShowItem().getItemConverter().itemToJson(item, Level.FINE);

        String icon = "";
        if (plugin.getShowItem().useIconRp()) {
            icon = plugin.getShowItem().getIconRpMap().getIcon(item, true);
        }

        JSONArray textJson = new JSONArray();

        textJson.add(new JSONObject(ImmutableMap.of("text", Messages.prefix(ChatColor.GREEN + "Item: "))));

        JSONObject hoverJson = new JSONObject();
        hoverJson.put("action", "show_item");
        hoverJson.put("value", itemJson);
        ChatColor nameColor = plugin.getShowItem().getItemConverter().getNameColor(item);

        if (plugin.getShowItem().useIconRp()) {
            JSONObject iconJson = new JSONObject();
            iconJson.put("text", icon);
            iconJson.put("hoverEvent", hoverJson);

            textJson.add(iconJson);
        }

        JSONObject typeJson = new JSONObject();
        typeJson.put("translate", plugin.getShowItem().getItemConverter().getTranslationKey(item));
        JSONArray translateWith = new JSONArray();
        translateWith.addAll(plugin.getShowItem().getItemConverter().getTranslateWith(item));
        if (!translateWith.isEmpty()) {
            typeJson.put("with", translateWith);
        }

        typeJson.put("hoverEvent", hoverJson);
        typeJson.put("color", nameColor.name().toLowerCase());

        textJson.add(typeJson);

        String itemName = plugin.getShowItem().getItemConverter().getCustomName(item);
        if (!itemName.isEmpty()) {
            textJson.add(new JSONObject(ImmutableMap.of("text", ": ", "color", "green")));

            JSONObject nameJson = new JSONObject();
            nameJson.put("text", itemName);
            nameJson.put("hoverEvent", hoverJson);
            nameJson.put("color", nameColor.name().toLowerCase());

            textJson.add(nameJson);
        }

        plugin.getShowItem().tellRaw((Player) sender, textJson.toString());
    }
    sender.sendMessage(Messages.prefix(ChatColor.GREEN + "Anzahl: " + ChatColor.WHITE + quantity));
    sender.sendMessage(Messages.prefix(ChatColor.GREEN + "Preis: " + ChatColor.WHITE + prices));

    return true;
}

From source file:com.appcelerator.titanium.desktop.ui.wizard.TiManifest.java

/**
 * Writes the timanifest file based ont he passed in arguments and the existing metadata for the project. Does no
 * validation!/*from w w w.  j  av a 2s . c o  m*/
 * 
 * @param networkRuntime
 *            "network" || "include"
 * @param release
 *            Release to users?
 * @param visibility
 *            "public" || "private"
 * @param showSplash
 *            - Should the install splash screen be shown on first run of app? true || false
 */
@SuppressWarnings("unchecked")
IStatus write(Set<String> platforms, String networkRuntime, boolean release, String visibility,
        boolean showSplash, IProgressMonitor monitor) {
    SubMonitor sub = SubMonitor.convert(monitor, 5);

    JSONObject timanifest = new JSONObject();
    TitaniumProject tiProj = getTitaniumProject();
    timanifest.put(APPNAME, tiProj.getAppName());
    timanifest.put(APPID, tiProj.getAppID());
    timanifest.put(APPVERSION, tiProj.getVersion());
    timanifest.put(MID, getMID());
    timanifest.put(PUBLISHER, tiProj.getPublisher());
    timanifest.put(URL, tiProj.getURL());
    timanifest.put(DESC, tiProj.getDescription());
    timanifest.put(RELEASE, release);
    timanifest.put(NO_INSTALL, !showSplash);
    timanifest.put(GUID, getGUID());
    timanifest.put(VISIBILITY, visibility);
    JSONObject runtime = new JSONObject();
    try {
        runtime.put("version", getProjectSDKVersion()); //$NON-NLS-1$
    } catch (CoreException e) {
        return e.getStatus();
    }
    runtime.put(PACKAGE, networkRuntime);
    timanifest.put(RUNTIME, runtime);

    if (tiProj.getImage() != null) {
        // FIXME What should we do here?
        // var image = TFS.getFile(project.image);
        // timanifest.image = image.name();
        timanifest.put("image", tiProj.getImage()); //$NON-NLS-1$
    }
    sub.worked(1);

    // OS options
    JSONArray array = new JSONArray();
    array.addAll(platforms);
    timanifest.put(PLATFORMS, array);

    if (TitaniumConstants.DESKTOP_TYPE.equals(tiProj.getType())) {
        JSONArray modules = new JSONArray();

        Map<MODULE, String> moduleMap = tiProj.getModules();
        for (Map.Entry<MODULE, String> entry : moduleMap.entrySet()) {
            JSONObject m = new JSONObject();
            m.put("name", entry.getKey().getKey()); //$NON-NLS-1$
            m.put("version", entry.getValue()); //$NON-NLS-1$
            m.put(PACKAGE, networkRuntime);
            modules.add(m);
        }
        timanifest.put("modules", modules); //$NON-NLS-1$
    } else {
        timanifest.put("package_target", "test"); //$NON-NLS-1$ //$NON-NLS-2$
    }
    sub.worked(1);

    IFile file = project.getFile(FILENAME);
    try {
        if (!file.exists()) {
            file.create(new ByteArrayInputStream(timanifest.toJSONString().getBytes()), IResource.FORCE,
                    sub.newChild(1));
        } else {
            file.setContents(new ByteArrayInputStream(timanifest.toJSONString().getBytes()), IResource.FORCE,
                    sub.newChild(1));
        }
    } catch (CoreException e) {
        return e.getStatus();
    }

    sub.done();

    return Status.OK_STATUS;
}