org.rundeck.api.util.ParametersUtil Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of rundeck-api-java-client Show documentation
Show all versions of rundeck-api-java-client Show documentation
Java client for the Rundeck REST API
The newest version!
/*
* Copyright 2011 Vincent Behar
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.rundeck.api.util;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;
import java.util.Map.Entry;
import org.apache.commons.lang.StringUtils;
/**
* Utility class for API parameters that should be passed in URLs.
*
* @author Vincent Behar
*/
public class ParametersUtil {
/**
* URL-encode the given string
*
* @param input string to be encoded
* @return an url-encoded string
*/
public static String urlEncode(String input) {
if (StringUtils.isBlank(input)) {
return input;
}
try {
return URLEncoder.encode(input, "UTF-8");
} catch (UnsupportedEncodingException e) {
throw new RuntimeException(e);
}
}
/**
* Generates a Rundeck "argString" representing the given options. Format of the argString is
* "-key1 value1 -key2 'value 2 with spaces'"
. You might want to url-encode this string...
*
* @param options to be converted
* @return a string. null if options is null, empty if there are no valid options.
*/
public static String generateArgString(Properties options) {
if (options == null) {
return null;
}
StringBuilder argString = new StringBuilder();
for (Entry