Example usage for io.vertx.core.json JsonObject put

List of usage examples for io.vertx.core.json JsonObject put

Introduction

In this page you can find the example usage for io.vertx.core.json JsonObject put.

Prototype

public JsonObject put(String key, Object value) 

Source Link

Document

Put an Object into the JSON object with the specified key.

Usage

From source file:de.braintags.netrelay.controller.filemanager.elfinder.command.impl.AbstractCommand.java

License:Open Source License

protected JsonObject getTargetInfo(ElFinderContext efContext, ITarget target) {
    JsonObject info = new JsonObject();

    info.put(ElFinderConstants.ELFINDER_PARAMETER_HASH, target.getHash());
    info.put(ElFinderConstants.ELFINDER_PARAMETER_MIME, target.getMimeType());
    info.put(ElFinderConstants.ELFINDER_PARAMETER_TIMESTAMP, target.getLastModified());
    info.put(ElFinderConstants.ELFINDER_PARAMETER_SIZE, target.getSize());
    info.put(ElFinderConstants.ELFINDER_PARAMETER_READ,
            target.isReadable() ? ElFinderConstants.ELFINDER_TRUE_RESPONSE
                    : ElFinderConstants.ELFINDER_FALSE_RESPONSE);
    info.put(ElFinderConstants.ELFINDER_PARAMETER_WRITE,
            target.isWritable() ? ElFinderConstants.ELFINDER_TRUE_RESPONSE
                    : ElFinderConstants.ELFINDER_FALSE_RESPONSE);
    info.put(ElFinderConstants.ELFINDER_PARAMETER_LOCKED,
            target.isLocked() ? ElFinderConstants.ELFINDER_TRUE_RESPONSE
                    : ElFinderConstants.ELFINDER_FALSE_RESPONSE);

    if (target.getMimeType() != null && target.getMimeType().startsWith("image")) {
        String uri = efContext.getRoutingContext().request().absoluteURI()
                + String.format(CMD_TMB_TARGET, target.getHash());
        info.put(ElFinderConstants.ELFINDER_PARAMETER_THUMBNAIL, uri);
    }/*from w ww  .j a  va2 s.  c o  m*/

    if (target.isRoot()) {
        info.put(ElFinderConstants.ELFINDER_PARAMETER_DIRECTORY_FILE_NAME, target.getVolume().getAlias());
        info.put(ElFinderConstants.ELFINDER_PARAMETER_VOLUME_ID, target.getVolume().getId());
    } else {
        info.put(ElFinderConstants.ELFINDER_PARAMETER_DIRECTORY_FILE_NAME, target.getName());
        info.put(ElFinderConstants.ELFINDER_PARAMETER_PARENTHASH, target.getParent().getHash());
    }

    if (target.isFolder()) {
        info.put(ElFinderConstants.ELFINDER_PARAMETER_HAS_DIR,
                target.hasChildFolder() ? ElFinderConstants.ELFINDER_TRUE_RESPONSE
                        : ElFinderConstants.ELFINDER_FALSE_RESPONSE);
    }
    return info;
}

From source file:de.braintags.netrelay.controller.filemanager.elfinder.command.impl.AbstractCommand.java

License:Open Source License

protected JsonObject getOptions(ElFinderContext efContext, ITarget target) {
    JsonObject options = new JsonObject();
    options.put(ElFinderConstants.ELFINDER_PARAMETER_PATH, target.getName());
    options.put(ElFinderConstants.ELFINDER_PARAMETER_COMMAND_DISABLED, new JsonArray());
    options.put(ElFinderConstants.ELFINDER_PARAMETER_FILE_SEPARATOR,
            ElFinderConstants.ELFINDER_PARAMETER_FILE_SEPARATOR);
    options.put(ElFinderConstants.ELFINDER_PARAMETER_OVERWRITE_FILE, ElFinderConstants.ELFINDER_TRUE_RESPONSE);
    // options.put(ElFinderConstants.ELFINDER_PARAMETER_ARCHIVERS, ArchiverOption.JSON_INSTANCE);
    return options;
}

From source file:de.braintags.netrelay.controller.filemanager.elfinder.command.impl.DimCommand.java

License:Open Source License

@Override
public void execute(ElFinderContext efContext, JsonObject json, Handler<AsyncResult<ITarget>> handler) {
    final String targetString = efContext.getParameter(ElFinderConstants.ELFINDER_PARAMETER_TARGET);

    BufferedImage image;/*ww  w . j  a va  2s.co  m*/
    ITarget target = findTarget(efContext, targetString);
    try {
        image = ImageIO.read(target.openInputStream());
        json.put(ElFinderConstants.ELFINDER_JSON_RESPONSE_DIM,
                image.getWidth() + SEPARATOR + image.getHeight());
        handler.handle(createFuture(target));
    } catch (IOException e) {
        handler.handle(Future.failedFuture(e));
    }
}

From source file:de.braintags.netrelay.controller.filemanager.elfinder.command.impl.DuplicateCommand.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<ITarget> added = new ArrayList<>();
    for (String targetString : targets) {
        final ITarget source = findTarget(efContext, targetString);
        final String name = source.getName();
        LOGGER.info("going to duplicate file " + name);
        String baseName = FilenameUtils.getBaseName(name);
        final String extension = FilenameUtils.getExtension(name);

        int i = 1;
        ITarget destination;/*from  ww w  . j  a v  a 2 s  .c om*/
        baseName = baseName.replaceAll("\\(\\d+\\)$", "");

        while (true) {
            String newName = String.format("%s(%d)%s", baseName, i,
                    extension == null || extension.isEmpty() ? "" : "." + extension);
            destination = source.getParent().createChildTarget(newName);

            if (!destination.exists()) {
                LOGGER.info("duplicate name will be " + newName);
                break;
            }
            i++;
        }
        createAndCopy(source, destination);
        added.add(destination);
    }
    json.put(ElFinderConstants.ELFINDER_JSON_RESPONSE_ADDED, buildJsonFilesArray(efContext, added));
    handler.handle(createFuture(added));
}

From source file:de.braintags.netrelay.controller.filemanager.elfinder.command.impl.GetCommand.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 ITarget vh = findTarget(efContext, target);
    final String content = vh.readFile().toString(ENCODING);
    json.put(ElFinderConstants.ELFINDER_PARAMETER_CONTENT, content);
    handler.handle(createFuture(vh));//from w ww  .j ava  2 s .  c o  m
}

From source file:de.braintags.netrelay.controller.filemanager.elfinder.command.impl.LsCommand.java

License:Open Source License

@Override
public void execute(ElFinderContext efContext, JsonObject json,
        Handler<AsyncResult<Map<String, ITarget>>> handler) {
    final String target = efContext.getParameter(ElFinderConstants.ELFINDER_PARAMETER_TARGET);
    Map<String, ITarget> files = new HashMap<>();
    ITarget source = findTarget(efContext, target);
    addChildren(efContext, files, source);
    json.put(ElFinderConstants.ELFINDER_PARAMETER_LIST, this.buildJsonFilesArray(efContext, files.values()));
    handler.handle(createFuture(files));
}

From source file:de.braintags.netrelay.controller.filemanager.elfinder.command.impl.MkdirCommand.java

License:Open Source License

@Override
public void execute(ElFinderContext efContext, JsonObject json, Handler<AsyncResult<ITarget>> handler) {
    final String targetHash = efContext.getParameter(ElFinderConstants.ELFINDER_PARAMETER_TARGET);
    final String fileName = efContext.getParameter(ElFinderConstants.ELFINDER_PARAMETER_NAME);
    ITarget target = findTarget(efContext, targetHash);
    ITarget newFile = target.createChildTarget(fileName);
    newFile.createFolder();//from w  ww .j  a v  a 2s .  co m
    JsonObject jo = getTargetInfo(efContext, newFile);
    json.put(ElFinderConstants.ELFINDER_JSON_RESPONSE_ADDED, new JsonArray().add(jo));
    handler.handle(createFuture(newFile));
}

From source file:de.braintags.netrelay.controller.filemanager.elfinder.command.impl.MkfileCommand.java

License:Open Source License

@Override
public void execute(ElFinderContext efContext, JsonObject json, Handler<AsyncResult<ITarget>> handler) {
    final String targetHash = efContext.getParameter(ElFinderConstants.ELFINDER_PARAMETER_TARGET);
    final String fileName = efContext.getParameter(ElFinderConstants.ELFINDER_PARAMETER_NAME);
    ITarget target = findTarget(efContext, targetHash);
    if (target == null) {
        throw new IllegalArgumentException("Folder does not exist: " + efContext.translateHash(targetHash));
    }/*from ww w  .jav a  2s . com*/
    ITarget newFile = target.createChildTarget(fileName);
    newFile.createFile();
    JsonObject jo = getTargetInfo(efContext, newFile);
    json.put(ElFinderConstants.ELFINDER_JSON_RESPONSE_ADDED, new JsonArray().add(jo));
    handler.handle(createFuture(newFile));
}

From source file:de.braintags.netrelay.controller.filemanager.elfinder.command.impl.OpenCommand.java

License:Open Source License

@Override
public void execute(ElFinderContext efContext, JsonObject json,
        Handler<AsyncResult<Map<String, ITarget>>> handler) {
    RoutingContext context = efContext.getRoutingContext();
    boolean init = context.request().getParam(ElFinderConstants.ELFINDER_PARAMETER_INIT) != null;
    boolean tree = context.request().getParam(ElFinderConstants.ELFINDER_PARAMETER_TREE) != null;
    String target = context.request().getParam(ElFinderConstants.ELFINDER_PARAMETER_TARGET);
    if (init) {/*from  w  w  w. jav  a 2  s  .com*/
        json.put(ElFinderConstants.ELFINDER_PARAMETER_API, ElFinderConstants.ELFINDER_VERSION_API);
        json.put(ElFinderConstants.ELFINDER_PARAMETER_NETDRIVERS, new JsonArray());
    }

    Map<String, ITarget> files = new LinkedHashMap<>();

    if (tree) {
        for (IVolume root : efContext.getRootVolumes()) {
            ITarget rootTarget = root.getRoot();
            String hash = ElFinderContext.getHash(rootTarget);
            files.put(hash, rootTarget);
            addSubFolders(efContext, files, rootTarget);
        }
    }

    ITarget cwd = findCwd(efContext, target);
    files.put(cwd.getHash(), cwd);
    addChildren(efContext, files, cwd);
    json.put(ElFinderConstants.ELFINDER_PARAMETER_FILES, buildJsonFilesArray(efContext, files.values()));
    json.put(ElFinderConstants.ELFINDER_PARAMETER_CWD, getTargetInfo(efContext, cwd));
    json.put(ElFinderConstants.ELFINDER_PARAMETER_OPTIONS, getOptions(efContext, cwd));
    handler.handle(createFuture(files));
}

From source file:de.braintags.netrelay.controller.filemanager.elfinder.command.impl.ParentsCommand.java

License:Open Source License

@Override
public void execute(ElFinderContext efContext, JsonObject json,
        Handler<AsyncResult<Map<String, ITarget>>> handler) {
    final String target = efContext.getParameter(ElFinderConstants.ELFINDER_PARAMETER_TARGET);

    Map<String, ITarget> files = new HashMap<>();
    ITarget source = findTarget(efContext, target);

    while (!source.isRoot()) {
        addSubFolders(efContext, files, source);
        source = source.getParent();/*from  ww w .jav a2s .  c o m*/
    }

    json.put(ElFinderConstants.ELFINDER_PARAMETER_TREE, buildJsonFilesArray(efContext, files.values()));
    handler.handle(createFuture(files));
}