Example usage for org.apache.commons.exec.util StringUtils quoteArgument

List of usage examples for org.apache.commons.exec.util StringUtils quoteArgument

Introduction

In this page you can find the example usage for org.apache.commons.exec.util StringUtils quoteArgument.

Prototype

public static String quoteArgument(final String argument) 

Source Link

Document

Put quotes around the given String if necessary.

Usage

From source file:ch.vorburger.exec.ManagedProcessBuilder.java

/**
 * Adds a single argument to the command, composed of two parts and a given separator.
 * The two parts are independently escaped (see above), and then concatenated using the separator.
 *//*from   w  ww.  ja v a2 s .  co  m*/
protected ManagedProcessBuilder addArgument(String argPart1, String separator, String argPart2) {
    // @see MariaDB4j Issue #30 why 'quoting' (https://github.com/vorburger/MariaDB4j/issues/30)
    StringBuilder sb = new StringBuilder();
    sb.append(StringUtils.quoteArgument(argPart1));
    sb.append(separator);
    sb.append(StringUtils.quoteArgument(argPart2));
    // @see https://issues.apache.org/jira/browse/EXEC-93 why we have to use 'false' here
    // TODO Remove the false when commons-exec has a release including EXEC-93 fixed.
    addArgument(sb.toString(), false);
    return this;
}

From source file:com.silverpeas.util.FileUtil.java

public static String convertFilePath(File file) {
    if (OsEnum.getOS().isWindows()) {
        return StringUtils.quoteArgument(file.getAbsolutePath());
    }//from   w ww.j a v  a 2 s  .  c  om
    String path = file.getAbsolutePath();
    path = path.replaceAll("\\\\", "\\\\\\\\");
    path = path.replaceAll("\\s", "\\\\ ");
    path = path.replaceAll("<", "\\\\<");
    path = path.replaceAll(">", "\\\\>");
    path = path.replaceAll("'", "\\\\'");
    path = path.replaceAll("\"", "\\\\\"");
    path = path.replaceAll("\\{", "\\\\{");
    path = path.replaceAll("}", "\\\\}");
    path = path.replaceAll("\\(", "\\\\(");
    path = path.replaceAll("\\)", "\\\\)");
    path = path.replaceAll("\\[", "\\\\[");
    path = path.replaceAll("\\]", "\\\\]");
    path = path.replaceAll("\\&", "\\\\&");
    path = path.replaceAll("\\|", "\\\\|");
    return path;
}

From source file:npanday.executable.ArgUtils.java

/**
 * Takes care of quoting individually per part. For example,
 * if you pass <code>"/go:", new File("c:\\with space")</code>, it will yield
 * <code>/go:"c:\with space"</code>
 *//*from   ww w .ja va 2s .com*/
public static String combine(Object... objects) {
    StringBuilder command = new StringBuilder();
    for (Object item : objects) {
        if (item == null) {
            continue;
        }

        if (item instanceof File) {
            command.append(StringUtils
                    .quoteArgument(StringUtils.fixFileSeparatorChar(((File) item).getAbsolutePath())));
        } else if (item instanceof String) {
            command.append(StringUtils.quoteArgument((String) item));
        } else {
            command.append(StringUtils.quoteArgument(item.toString()));
        }
    }

    return command.toString();
}

From source file:uk.org.sappho.applications.transcript.service.registry.vcs.Command.java

private void addToSafeCommand(String part, boolean hide) {

    if (safeCommand.length() != 0) {
        safeCommand += " ";
    }//from   www.ja  v a2  s .  c o m
    if (hide) {
        safeCommand += "******";
    } else {
        safeCommand += StringUtils.quoteArgument(part);
    }
}