List of usage examples for io.vertx.core.json JsonArray add
public JsonArray add(Object value)
From source file:de.braintags.netrelay.controller.filemanager.elfinder.command.impl.AbstractCommand.java
License:Open Source License
protected JsonArray buildJsonFilesArray(ElFinderContext efContext, Collection<ITarget> targetList) { JsonArray returnArray = new JsonArray(); targetList.forEach(target -> returnArray.add(getTargetInfo(efContext, target))); return returnArray; }
From source file:de.braintags.netrelay.controller.filemanager.elfinder.command.impl.PasteCommand.java
License:Open Source License
@Override public void execute(ElFinderContext efContext, JsonObject json, Handler<AsyncResult<List<ITarget>>> handler) { List<String> targets = efContext.getParameterValues(ElFinderConstants.ELFINDER_PARAMETER_TARGETS); List<String> renames = efContext.getParameterValues(ElFinderConstants.ELFINDER_PARAMETER_RENAMES); final String destination = efContext.getParameter(ElFinderConstants.ELFINDER_PARAMETER_FILE_DESTINATION); final String src = efContext.getParameter(ElFinderConstants.ELFINDER_PARAMETER_SRC); final boolean cut = INT_CUT.equals(efContext.getParameter(ElFinderConstants.ELFINDER_PARAMETER_CUT)); List<ITarget> added = new ArrayList<>(); List<String> removed = new ArrayList<>(); ITarget vhDst = findTarget(efContext, destination); for (String target : targets) { ITarget vhTarget = findTarget(efContext, target); final String name = vhTarget.getName(); ITarget newFile = vhDst.createChildTarget(name); createAndCopy(vhTarget, newFile); added.add(newFile);//from w w w . j av a2 s .com if (cut) { vhTarget.delete(); removed.add(vhTarget.getHash()); } } json.put(ElFinderConstants.ELFINDER_JSON_RESPONSE_ADDED, buildJsonFilesArray(efContext, added)); JsonArray returnArray = new JsonArray(); removed.forEach(target -> returnArray.add(target)); json.put(ElFinderConstants.ELFINDER_JSON_RESPONSE_REMOVED, returnArray); handler.handle(createFuture(added)); }
From source file:de.braintags.netrelay.controller.filemanager.elfinder.command.impl.RenameCommand.java
License:Open Source License
@Override public void execute(ElFinderContext efContext, JsonObject json, Handler<AsyncResult<ITarget>> handler) { final String target = efContext.getParameter(ElFinderConstants.ELFINDER_PARAMETER_TARGET); final String newName = efContext.getParameter(ElFinderConstants.ELFINDER_PARAMETER_NAME); ITarget source = findTarget(efContext, target); ITarget destination = source.getParent().createChildTarget(newName); source.rename(destination);/*from www . j ava2s. com*/ JsonArray result = new JsonArray(); result.add(getTargetInfo(efContext, destination)); json.put(ElFinderConstants.ELFINDER_JSON_RESPONSE_ADDED, result); result = new JsonArray(); result.add(target); json.put(ElFinderConstants.ELFINDER_JSON_RESPONSE_REMOVED, result); handler.handle(createFuture(destination)); }
From source file:de.braintags.netrelay.controller.filemanager.elfinder.command.impl.RmCommand.java
License:Open Source License
@Override public void execute(ElFinderContext efContext, JsonObject json, Handler<AsyncResult<List<ITarget>>> handler) { List<String> targets = efContext.getParameterValues(ElFinderConstants.ELFINDER_PARAMETER_TARGETS); JsonArray removed = new JsonArray(); List<ITarget> rmTargets = new ArrayList<>(); for (String ts : targets) { ITarget target = findTarget(efContext, ts); if (!target.isFolder() || checkEmptyDirectory(target)) { target.delete();// w ww. j a v a 2 s . c om removed.add(target.getHash()); rmTargets.add(target); } else { json.put(ElFinderConstants.ELFINDER_JSON_RESPONSE_ERROR, "Directory not empty: " + target.getPath()); } } json.put(ElFinderConstants.ELFINDER_JSON_RESPONSE_REMOVED, removed); handler.handle(createFuture(rmTargets)); }
From source file:de.braintags.netrelay.controller.filemanager.elfinder.command.impl.SearchCommand.java
License:Open Source License
@Override public void execute(ElFinderContext efContext, JsonObject json, Handler<AsyncResult<List<ITarget>>> handler) { final String query = efContext.getParameter(ElFinderConstants.ELFINDER_PARAMETER_SEARCH_QUERY); List<ITarget> found = new ArrayList<>(); try {//from w w w .j a v a 2 s.c o m JsonArray objects = new JsonArray(); List<IVolume> volumes = efContext.getRootVolumes(); for (IVolume volume : volumes) { // checks volume security ITarget volumeRoot = volume.getRoot(); // search only in volumes that are readable if (volumeRoot.isReadable()) { // search for targets List<ITarget> targets = volume.search(query); if (targets != null) { // adds targets info in the return list targets.forEach(target -> objects.add(getTargetInfo(efContext, target))); } found.addAll(targets); } } json.put(ElFinderConstants.ELFINDER_PARAMETER_FILES, objects); } catch (Exception e) { json.put(ElFinderConstants.ELFINDER_JSON_RESPONSE_ERROR, "Unable to search! Error: " + e); } handler.handle(createFuture(found)); }
From source file:docoverride.json.Examples.java
License:Open Source License
public void example3() { JsonArray array = new JsonArray(); array.add("foo").add(123).add(false); }
From source file:fr.wseduc.rack.controllers.RackController.java
License:Open Source License
private void copyFiles(final HttpServerRequest request, final JsonArray idsArray, final String folder, final UserInfos user, final String destinationCollection) { String criteria = "{ \"_id\" : { \"$in\" : " + idsArray.encode() + "}"; criteria += ", \"to\" : \"" + user.getUserId() + "\" }"; mongo.find(collection, new JsonObject(criteria), new Handler<Message<JsonObject>>() { private void persist(final JsonArray insert, int remains) { if (remains == 0) { mongo.insert(destinationCollection, insert, new Handler<Message<JsonObject>>() { @Override//from ww w . jav a2s. co m public void handle(Message<JsonObject> inserted) { if ("ok".equals(inserted.body().getString("status"))) { /* Increment quota */ long totalSize = 0l; for (Object insertion : insert) { JsonObject added = (JsonObject) insertion; totalSize += added.getJsonObject("metadata", new JsonObject()).getLong("size", 0l); } updateUserQuota(user.getUserId(), totalSize); renderJson(request, inserted.body()); } else { renderError(request, inserted.body()); } } }); } } @Override public void handle(Message<JsonObject> r) { JsonObject src = r.body(); if ("ok".equals(src.getString("status")) && src.getJsonArray("results") != null) { final JsonArray origs = src.getJsonArray("results"); final JsonArray insert = new JsonArray(); final AtomicInteger number = new AtomicInteger(origs.size()); emptySize(user, new Handler<Long>() { @Override public void handle(Long emptySize) { long size = 0; /* Get total file size */ for (Object o : origs) { if (!(o instanceof JsonObject)) continue; JsonObject metadata = ((JsonObject) o).getJsonObject("metadata"); if (metadata != null) { size += metadata.getLong("size", 0l); } } /* If total file size is too big (> quota left) */ if (size > emptySize) { badRequest(request, "files.too.large"); return; } /* Process */ for (Object o : origs) { JsonObject orig = (JsonObject) o; final JsonObject dest = orig.copy(); String now = MongoDb.formatDate(new Date()); dest.remove("_id"); dest.remove("protected"); dest.remove("comments"); dest.put("application", WORKSPACE_NAME); dest.put("owner", user.getUserId()); dest.put("ownerName", dest.getString("toName")); dest.remove("to"); dest.remove("from"); dest.remove("toName"); dest.remove("fromName"); dest.put("created", now); dest.put("modified", now); if (folder != null && !folder.trim().isEmpty()) { dest.put("folder", folder); } else { dest.remove("folder"); } insert.add(dest); final String filePath = orig.getString("file"); if (folder != null && !folder.trim().isEmpty()) { //If the document has a new parent folder, replicate sharing rights String parentName, parentFolder; if (folder.lastIndexOf('_') < 0) { parentName = folder; parentFolder = folder; } else if (filePath != null) { String[] splittedPath = folder.split("_"); parentName = splittedPath[splittedPath.length - 1]; parentFolder = folder; } else { String[] splittedPath = folder.split("_"); parentName = splittedPath[splittedPath.length - 2]; parentFolder = folder.substring(0, folder.lastIndexOf("_")); } QueryBuilder parentFolderQuery = QueryBuilder.start("owner") .is(user.getUserId()).and("folder").is(parentFolder).and("name") .is(parentName); mongo.findOne(collection, MongoQueryBuilder.build(parentFolderQuery), new Handler<Message<JsonObject>>() { @Override public void handle(Message<JsonObject> event) { if ("ok".equals(event.body().getString("status"))) { JsonObject parent = event.body().getJsonObject("result"); if (parent != null && parent.getJsonArray("shared") != null && parent.getJsonArray("shared").size() > 0) dest.put("shared", parent.getJsonArray("shared")); if (filePath != null) { storage.copyFile(filePath, new Handler<JsonObject>() { @Override public void handle(JsonObject event) { if (event != null && "ok" .equals(event.getString("status"))) { dest.put("file", event.getString("_id")); persist(insert, number.decrementAndGet()); } } }); } else { persist(insert, number.decrementAndGet()); } } else { renderJson(request, event.body(), 404); } } }); } else if (filePath != null) { storage.copyFile(filePath, new Handler<JsonObject>() { @Override public void handle(JsonObject event) { if (event != null && "ok".equals(event.getString("status"))) { dest.put("file", event.getString("_id")); persist(insert, number.decrementAndGet()); } } }); } else { persist(insert, number.decrementAndGet()); } } } }); } else { notFound(request, src.toString()); } } }); }
From source file:fr.wseduc.rack.controllers.RackController.java
License:Open Source License
private void createThumbnails(List<String> thumbs, JsonObject srcFile, final String collection, final String documentId) { Pattern size = Pattern.compile("([0-9]+)x([0-9]+)"); JsonArray outputs = new JsonArray(); for (String thumb : thumbs) { Matcher m = size.matcher(thumb); if (m.matches()) { try { int width = Integer.parseInt(m.group(1)); int height = Integer.parseInt(m.group(2)); if (width == 0 && height == 0) continue; JsonObject j = new JsonObject().put("dest", storage.getProtocol() + "://" + storage.getBucket()); if (width != 0) { j.put("width", width); }/*from www. jav a 2s.co m*/ if (height != 0) { j.put("height", height); } outputs.add(j); } catch (NumberFormatException e) { log.error("Invalid thumbnail size.", e); } } } if (outputs.size() > 0) { JsonObject json = new JsonObject().put("action", "resizeMultiple") .put("src", storage.getProtocol() + "://" + storage.getBucket() + ":" + srcFile.getString("_id")) .put("destinations", outputs); eb.send(imageResizerAddress, json, new Handler<AsyncResult<Message<JsonObject>>>() { @Override public void handle(AsyncResult<Message<JsonObject>> event) { if (event.succeeded()) { JsonObject thumbnails = event.result().body().getJsonObject("outputs"); if ("ok".equals(event.result().body().getString("status")) && thumbnails != null) { mongo.update(collection, new JsonObject().put("_id", documentId), new JsonObject().put("$set", new JsonObject().put("thumbnails", thumbnails))); } } else { log.error("Error when resize image.", event.cause()); } } }); } }
From source file:io.apiman.gateway.platforms.vertx3.common.config.InheritingHttpServerOptionsConverter.java
License:Apache License
public static void toJson(InheritingHttpServerOptions obj, JsonObject json) { json.put("acceptBacklog", obj.getAcceptBacklog()); json.put("acceptUnmaskedFrames", obj.isAcceptUnmaskedFrames()); if (obj.getAlpnVersions() != null) { JsonArray array = new JsonArray(); obj.getAlpnVersions().forEach(item -> array.add(item.name())); json.put("alpnVersions", array); }/*from w ww .j a v a 2 s. c o m*/ if (obj.getClientAuth() != null) { json.put("clientAuth", obj.getClientAuth().name()); } json.put("clientAuthRequired", obj.isClientAuthRequired()); json.put("compressionLevel", obj.getCompressionLevel()); json.put("compressionSupported", obj.isCompressionSupported()); if (obj.getCrlPaths() != null) { JsonArray array = new JsonArray(); obj.getCrlPaths().forEach(item -> array.add(item)); json.put("crlPaths", array); } if (obj.getCrlValues() != null) { JsonArray array = new JsonArray(); obj.getCrlValues().forEach(item -> array.add(item.getBytes())); json.put("crlValues", array); } json.put("decompressionSupported", obj.isDecompressionSupported()); if (obj.getEnabledCipherSuites() != null) { JsonArray array = new JsonArray(); obj.getEnabledCipherSuites().forEach(item -> array.add(item)); json.put("enabledCipherSuites", array); } if (obj.getEnabledSecureTransportProtocols() != null) { JsonArray array = new JsonArray(); obj.getEnabledSecureTransportProtocols().forEach(item -> array.add(item)); json.put("enabledSecureTransportProtocols", array); } json.put("handle100ContinueAutomatically", obj.isHandle100ContinueAutomatically()); if (obj.getHost() != null) { json.put("host", obj.getHost()); } json.put("http2ConnectionWindowSize", obj.getHttp2ConnectionWindowSize()); json.put("idleTimeout", obj.getIdleTimeout()); if (obj.getInitialSettings() != null) { json.put("initialSettings", obj.getInitialSettings().toJson()); } if (obj.getJdkSslEngineOptions() != null) { json.put("jdkSslEngineOptions", obj.getJdkSslEngineOptions().toJson()); } if (obj.getKeyStoreOptions() != null) { json.put("keyStoreOptions", obj.getKeyStoreOptions().toJson()); } json.put("logActivity", obj.getLogActivity()); json.put("maxChunkSize", obj.getMaxChunkSize()); json.put("maxHeaderSize", obj.getMaxHeaderSize()); json.put("maxInitialLineLength", obj.getMaxInitialLineLength()); json.put("maxWebsocketFrameSize", obj.getMaxWebsocketFrameSize()); json.put("maxWebsocketMessageSize", obj.getMaxWebsocketMessageSize()); if (obj.getOpenSslEngineOptions() != null) { json.put("openSslEngineOptions", obj.getOpenSslEngineOptions().toJson()); } if (obj.getPemKeyCertOptions() != null) { json.put("pemKeyCertOptions", obj.getPemKeyCertOptions().toJson()); } if (obj.getPemTrustOptions() != null) { json.put("pemTrustOptions", obj.getPemTrustOptions().toJson()); } if (obj.getPfxKeyCertOptions() != null) { json.put("pfxKeyCertOptions", obj.getPfxKeyCertOptions().toJson()); } if (obj.getPfxTrustOptions() != null) { json.put("pfxTrustOptions", obj.getPfxTrustOptions().toJson()); } json.put("port", obj.getPort()); json.put("receiveBufferSize", obj.getReceiveBufferSize()); json.put("reuseAddress", obj.isReuseAddress()); json.put("sendBufferSize", obj.getSendBufferSize()); json.put("soLinger", obj.getSoLinger()); json.put("ssl", obj.isSsl()); json.put("tcpKeepAlive", obj.isTcpKeepAlive()); json.put("tcpNoDelay", obj.isTcpNoDelay()); json.put("trafficClass", obj.getTrafficClass()); if (obj.getTrustStoreOptions() != null) { json.put("trustStoreOptions", obj.getTrustStoreOptions().toJson()); } json.put("useAlpn", obj.isUseAlpn()); json.put("usePooledBuffers", obj.isUsePooledBuffers()); if (obj.getWebsocketSubProtocols() != null) { json.put("websocketSubProtocols", obj.getWebsocketSubProtocols()); } }
From source file:io.apiman.gateway.platforms.vertx3.components.jdbc.VertxJdbcConnection.java
License:Apache License
private JsonArray toJsonArray(Object[] params) { JsonArray jsonArray = new JsonArray(); for (Object o : params) { jsonArray.add(o); }//from w ww . j av a 2s . c om return jsonArray; }