Refine search
/** * Escape and encode a string regarded as the path component of an URI with * the default protocol charset. * * @param unescaped an unescaped string * @return the escaped string * * @throws URIException if the default protocol charset is not supported * * @see URI#getDefaultProtocolCharset * @see #encode */ public static String encodePath(String unescaped) throws URIException { return encodePath(unescaped, URI.getDefaultProtocolCharset()); }
/** * Escape and encode a string regarded as the query component of an URI with * the default protocol charset. * When a query string is not misunderstood the reserved special characters * ("&", "=", "+", ",", and "$") within a query component, this method * is recommended to use in encoding the whole query. * * @param unescaped an unescaped string * @return the escaped string * * @throws URIException if the default protocol charset is not supported * * @see URI#getDefaultProtocolCharset * @see #encode */ public static String encodeQuery(String unescaped) throws URIException { return encodeQuery(unescaped, URI.getDefaultProtocolCharset()); }
path = URIUtil.decode( new Path(System.getProperty("user.dir"), fromPath).toUri().toString()); } else {
protected void copyMessage(String sourceUrl, String targetFolder) throws IOException { String targetPath = URIUtil.encodePath(getFolderPath(targetFolder)) + '/' + UUID.randomUUID().toString(); CopyMethod method = new CopyMethod(URIUtil.encodePath(sourceUrl), targetPath, false); // allow rename if a message with the same name exists method.addRequestHeader("Allow-Rename", "t"); try { int statusCode = httpClient.executeMethod(method); if (statusCode == HttpStatus.SC_PRECONDITION_FAILED) { throw new DavMailException("EXCEPTION_UNABLE_TO_COPY_MESSAGE"); } else if (statusCode != HttpStatus.SC_CREATED) { throw DavGatewayHttpClientFacade.buildHttpException(method); } } finally { method.releaseConnection(); } }
/** * Get data as a String for the GET method for the given path. * * @param path the server relative path of the resource to get * @return the contents of the given resource as a string * @exception HttpException * @exception IOException */ public String getMethodDataAsString(String path) throws HttpException, IOException { setClient(); GetMethod method = new GetMethod(URIUtil.encodePathQuery(path)); generateTransactionHeader(method); int statusCode = client.executeMethod(method); setStatusCode(statusCode); return method.getResponseBodyAsString(); }
/** * Escape and encode a string regarded as the path and query components of * an URI with the default protocol charset. * * @param unescaped an unescaped string * @return the escaped string * * @throws URIException if the default protocol charset is not supported * * @see URI#getDefaultProtocolCharset * @see #encode */ public static String encodePathQuery(String unescaped) throws URIException { return encodePathQuery(unescaped, URI.getDefaultProtocolCharset()); }
static String encodePath(CaldavRequest request, String path) throws URIException { if (request.isIcal5()) { return URIUtil.encode(path, ical_allowed_abs_path, "UTF-8"); } else { return URIUtil.encodePath(path, "UTF-8"); } }
/** * Escape and encode a string regarded as within the query component of an * URI with the default protocol charset. * When a query comprise the name and value pairs, it is used in order * to encode each name and value string. The reserved special characters * within a query component are being included in encoding the query. * * @param unescaped an unescaped string * @return the escaped string * * @throws URIException if the default protocol charset is not supported * * @see URI#getDefaultProtocolCharset * @see #encode */ public static String encodeWithinQuery(String unescaped) throws URIException { return encodeWithinQuery(unescaped, URI.getDefaultProtocolCharset()); }
/** * Escape and encode a string regarded as the path component of an URI with * a given charset. * * @param unescaped an unescaped string * @param charset the charset * @return the escaped string * * @throws URIException if the charset is not supported * * @see #encode */ public static String encodePath(String unescaped, String charset) throws URIException { return encode(unescaped, URI.allowed_abs_path, charset); }
String href = response.getHref(); if (!href.startsWith("/")) href = URIUtil.getPath(href); href = decodeMarks(href); String escapedHref = URIUtil.decode(href); String myURI = httpURL.getEscapedURI(); char[] childURI = (myURI + (myURI.endsWith("/") ? "" : "/") + URIUtil.getName(href)).toCharArray(); HttpURL childURL = httpURL instanceof HttpsURL ? new HttpsURL(childURI)
/** * Get the basename of an URI. It's possibly an empty string. * * @param uri a string regarded an URI * @return the basename string; an empty string if the path ends with slash */ public static String getName(String uri) { if (uri == null || uri.length() == 0) { return uri; } String path = URIUtil.getPath(uri); int at = path.lastIndexOf("/"); int to = path.length(); return (at >= 0) ? path.substring(at + 1, to) : path; }
/** * Get the all escaped and encoded string with the default protocl charset. * It's the same function to use <code>encode(String unescaped, Bitset * empty, URI.getDefaultProtocolCharset())</code>. * * @param unescaped an unescaped string * @return the escaped string * * @throws URIException if the default protocol charset is not supported * * @see URI#getDefaultProtocolCharset * @see #encode */ public static String encodeAll(String unescaped) throws URIException { return encodeAll(unescaped, URI.getDefaultProtocolCharset()); }
protected void moveMessage(String sourceUrl, String targetFolder) throws IOException { String targetPath = URIUtil.encodePath(getFolderPath(targetFolder)) + '/' + UUID.randomUUID().toString(); MoveMethod method = new MoveMethod(URIUtil.encodePath(sourceUrl), targetPath, false); // allow rename if a message with the same name exists method.addRequestHeader("Allow-Rename", "t"); try { int statusCode = httpClient.executeMethod(method); if (statusCode == HttpStatus.SC_PRECONDITION_FAILED) { throw new DavMailException("EXCEPTION_UNABLE_TO_MOVE_MESSAGE"); } else if (statusCode != HttpStatus.SC_CREATED) { throw DavGatewayHttpClientFacade.buildHttpException(method); } } finally { method.releaseConnection(); } }
/** * Execute the HEAD method for the given path. * * @param path the server relative path of the resource to request * @return true if the method is succeeded. * @exception HttpException * @exception IOException */ public boolean headMethod(String path) throws HttpException, IOException { setClient(); HeadMethod method = new HeadMethod(URIUtil.encodePathQuery(path)); generateTransactionHeader(method); int statusCode = client.executeMethod(method); setStatusCode(statusCode); return (statusCode >= 200 && statusCode < 300) ? true : false; }
/** * Splits the given string on the first '?' then encodes the first half as a path (ignoring slashes and colons) * and the second half as a query segment (ignoring questionmarks, equals signs, etc...). * * @deprecated Prefer to use {@link HttpEncodingTools#encode(String)} instead for encoding specific * pieces of the URI. This method does not escape certain reserved characters, like '/', ':', '=', and '?'. * As such, this is not safe to use on URIs that may contain these reserved characters in the wrong places. */ @Deprecated public static String encodeUri(String uri) { try { return URIUtil.encodePathQuery(uri); } catch (URIException ex) { throw new EsHadoopIllegalArgumentException("Cannot escape uri [" + uri + "]", ex); } }
/** * Escape and encode a string regarded as within the query component of an URI. * @param value the value to encode * @return encoded query, null if the default charset is not supported */ public static String encodeQueryValue(final String value) { try { return URIUtil.encodeWithinQuery(value, "UTF-8"); } catch (URIException e) { throw new AssertionError("JVM does not support UTF-8"); // should never happen! } }
/** * Get the all escaped and encoded string with a given charset. * It's the same function to use <code>encode(String unescaped, Bitset * empty, String charset)</code>. * * @param unescaped an unescaped string * @param charset the charset * @return the escaped string * * @throws URIException if the charset is not supported * * @see #encode */ public static String encodeAll(String unescaped, String charset) throws URIException { return encode(unescaped, empty, charset); }
/** * Get the basename of an URI. It's possibly an empty string. * * @param uri a string regarded an URI * @return the basename string; an empty string if the path ends with slash */ public static String getName(String uri) { if (uri == null || uri.length() == 0) { return uri; } String path = URIUtil.getPath(uri); int at = path.lastIndexOf("/"); int to = path.length(); return (at >= 0) ? path.substring(at + 1, to) : path; }
public static String spinURL(String root, String type, String uri) throws AGHttpException { try { if (uri == null) { return root + "/" + SPIN + "/" + type; } else { return root + "/" + SPIN + "/" + type + "/" + URIUtil.encodeAll(uri); } } catch (URIException e) { throw new AGHttpException(e); } }