use of org.apache.commons.httpclient.URIException in project knime-core by knime.
the class ListFilesNodeDialog method saveSettingsTo.
/**
* {@inheritDoc}
*/
@Override
protected void saveSettingsTo(final NodeSettingsWO settings) throws InvalidSettingsException {
// check if all entered Locations are valid
String location = m_locations.getEditor().getItem().toString();
if (location.trim().isEmpty()) {
throw new InvalidSettingsException("Please select a file!");
}
String[] files = location.split(";");
for (int i = 0; i < files.length; i++) {
File currentFile = new File(files[i]);
if (!currentFile.isDirectory()) {
// check if it was an URL;
String s = files[i];
try {
if (s.startsWith("file:")) {
s = s.substring(5);
}
currentFile = new File(URIUtil.decode(s));
} catch (URIException ex) {
throw new InvalidSettingsException("\"" + s + "\" does not exist or is not a directory", ex);
}
if (!currentFile.isDirectory()) {
throw new InvalidSettingsException("\"" + s + "\" does not exist or is not a directory");
}
}
}
ListFilesSettings set = new ListFilesSettings();
set.setLocationString(location);
set.setRecursive(m_recursive.isSelected());
set.setCaseSensitive(m_caseSensitive.isSelected());
String extensions = m_extensionField.getEditor().getItem().toString();
set.setExtensionsString(extensions);
// save the selected radio-Button
Filter filter;
if (m_filterALLRadio.isSelected()) {
filter = Filter.None;
} else if (m_filterExtensionsRadio.isSelected()) {
filter = Filter.Extensions;
} else if (m_filterRegExpRadio.isSelected()) {
if (extensions.trim().isEmpty()) {
throw new InvalidSettingsException("Enter valid regular expressin pattern");
}
try {
String pattern = extensions;
Pattern.compile(pattern);
} catch (PatternSyntaxException pse) {
throw new InvalidSettingsException("Error in pattern: ('" + pse.getMessage(), pse);
}
filter = Filter.RegExp;
} else if (m_filterWildCardsRadio.isSelected()) {
if ((extensions).length() <= 0) {
throw new InvalidSettingsException("Enter valid wildcard pattern");
}
try {
String pattern = extensions;
pattern = WildcardMatcher.wildcardToRegex(pattern);
Pattern.compile(pattern);
} catch (PatternSyntaxException pse) {
throw new InvalidSettingsException("Error in pattern: '" + pse.getMessage(), pse);
}
filter = Filter.Wildcards;
} else {
// one button must be selected though
filter = Filter.None;
}
set.setFilter(filter);
set.saveSettingsTo(settings);
}
use of org.apache.commons.httpclient.URIException in project knime-core by knime.
the class MultipleURLList method getSelectedURLs.
/**
* Returns a list with all selected URLs. Empty file selection panels are
* ignored. The list may contain invalid URLs the user has entered.
*
* @return a list with URLs
*/
public List<String> getSelectedURLs() {
List<String> urls = new ArrayList<String>();
// ConcurrentModificationExceptions; therefore the list is copied
for (MyFilePanel fp : new ArrayList<MyFilePanel>(m_filePanels)) {
if (fp.getSelectedFile().length() > 0) {
URL u = null;
String encUrl = fp.getSelectedFile();
try {
encUrl = URIUtil.encodePath(encUrl, "UTF-8");
u = new URL(encUrl);
} catch (MalformedURLException ex) {
if (!encUrl.startsWith("/")) {
encUrl = "/" + encUrl;
}
try {
u = new URL("file:" + encUrl);
encUrl = "file:" + encUrl;
fp.setSelectedFile(u);
} catch (MalformedURLException ex1) {
// ignore it
}
} catch (URIException ex) {
// ignore it
}
if (u != null) {
urls.add(encUrl);
}
}
}
return urls;
}
use of org.apache.commons.httpclient.URIException in project xwiki-platform by xwiki.
the class Utils method createURI.
/**
* Creates an URI to access the specified resource. The given path elements are encoded before being inserted into
* the resource path.
* <p>
* NOTE: We added this method because {@link UriBuilder#build(Object...)} doesn't encode all special characters. See
* https://github.com/restlet/restlet-framework-java/issues/601 .
*
* @param baseURI the base URI
* @param resourceClass the resource class, used to get the URI path
* @param pathElements the path elements to insert in the resource path
* @return an URI that can be used to access the specified resource
*/
public static URI createURI(URI baseURI, java.lang.Class<?> resourceClass, java.lang.Object... pathElements) {
UriBuilder uriBuilder = UriBuilder.fromUri(baseURI).path(resourceClass);
List<String> pathVariableNames = null;
if (pathElements.length > 0) {
// uriBuilder.toString() returns the path (see AbstractUriBuilder#toString())
// but it means UriBuilder must use AbstractUriBuilder from restlet.
// TODO: find a more generic way to not depend heavily on restlet.
pathVariableNames = getVariableNamesFromPathTemplate(uriBuilder.toString());
}
Object[] encodedPathElements = new String[pathElements.length];
for (int i = 0; i < pathElements.length; i++) {
Object pathElement = pathElements[i];
if (pathElement != null) {
try {
// see generateEncodedSpacesURISegment() to understand why we manually handle "spaceName"
if (i < pathVariableNames.size() && "spaceName".equals(pathVariableNames.get(i))) {
if (!(pathElement instanceof List)) {
throw new RuntimeException("The 'spaceName' parameter must be a list!");
}
encodedPathElements[i] = generateEncodedSpacesURISegment((List) pathElements[i]);
} else if (pathElement instanceof EncodedElement) {
encodedPathElements[i] = pathElement.toString();
} else {
encodedPathElements[i] = URIUtil.encodePath(pathElement.toString());
}
} catch (URIException e) {
throw new RuntimeException("Failed to encode path element: " + pathElements[i], e);
}
} else {
encodedPathElements[i] = null;
}
}
return uriBuilder.buildFromEncoded(encodedPathElements);
}
use of org.apache.commons.httpclient.URIException in project airavata by apache.
the class JSDLUtils method addDataStagingTargetElement.
public static void addDataStagingTargetElement(JobDefinitionType value, String fileSystem, String file, String uri, int flags) {
JobDescriptionType jobDescr = getOrCreateJobDescription(value);
DataStagingType newDS = jobDescr.addNewDataStaging();
CreationFlagEnumeration.Enum creationFlag = CreationFlagEnumeration.DONT_OVERWRITE;
if ((flags & FLAG_OVERWRITE) != 0)
creationFlag = CreationFlagEnumeration.OVERWRITE;
if ((flags & FLAG_APPEND) != 0)
creationFlag = CreationFlagEnumeration.APPEND;
boolean deleteOnTerminate = (flags & FLAG_DELETE_ON_TERMINATE) != 0;
newDS.setCreationFlag(creationFlag);
newDS.setDeleteOnTermination(deleteOnTerminate);
SourceTargetType target = newDS.addNewTarget();
try {
if (uri != null) {
URIUtils.encodeAll(uri);
target.setURI(uri);
}
} catch (URIException e) {
}
newDS.setFileName(file);
if (fileSystem != null && !fileSystem.equals("Work")) {
// $NON-NLS-1$
newDS.setFilesystemName(fileSystem);
}
}
use of org.apache.commons.httpclient.URIException in project dianping-open-sdk by dianping.
the class DemoApiTool method requestApi.
/**
* 请求API
*
* @param apiUrl
* @param appKey
* @param secret
* @param paramMap
* @return
*/
public static String requestApi(String apiUrl, String appKey, String secret, Map<String, String> paramMap) {
String queryString = getQueryString(appKey, secret, paramMap);
StringBuffer response = new StringBuffer();
HttpClientParams httpConnectionParams = new HttpClientParams();
httpConnectionParams.setConnectionManagerTimeout(1000);
HttpClient client = new HttpClient(httpConnectionParams);
HttpMethod method = new GetMethod(apiUrl);
try {
if (queryString != null && !queryString.isEmpty()) {
// Encode query string with UTF-8
String encodeQuery = URIUtil.encodeQuery(queryString, "UTF-8");
method.setQueryString(encodeQuery);
}
client.executeMethod(method);
BufferedReader reader = new BufferedReader(new InputStreamReader(method.getResponseBodyAsStream(), "UTF-8"));
String line = null;
while ((line = reader.readLine()) != null) {
response.append(line).append(System.getProperty("line.separator"));
}
reader.close();
} catch (URIException e) {
} catch (IOException e) {
} finally {
method.releaseConnection();
}
return response.toString();
}
Aggregations