List of usage examples for org.apache.commons.codec.net URLCodec encodeUrl
public static final byte[] encodeUrl(BitSet urlsafe, byte[] bytes)
From source file:lucee.commons.lang.URLEncoder.java
public static String encode(String str, java.nio.charset.Charset charset) throws UnsupportedEncodingException { return new String(URLCodec.encodeUrl(WWW_FORM_URL, str.getBytes(charset)), "us-ascii"); }
From source file:lucee.commons.lang.URLEncoder.java
public static String encode(String str, String encoding) throws UnsupportedEncodingException { return new String(URLCodec.encodeUrl(WWW_FORM_URL, str.getBytes(encoding)), "us-ascii"); }
From source file:eu.esdihumboldt.cst.doc.functions.internal.context.ONameUtil.java
/** * Encode text to a string that is a valid name. * /*www.ja v a2 s. co m*/ * @param text the text to encode * @return the encoded name */ public static String encodeName(String text) { if (text == null) { return null; } return new String(URLCodec.encodeUrl(ONAME, text.getBytes(Charsets.UTF_8)), Charsets.US_ASCII).replace('%', '_'); }
From source file:com.autonomy.aci.client.util.AciURLCodec.java
/** * Encodes a string into its URL safe form using the UTF-8 charset. Unsafe characters are escaped and the resulting * string is returned in the US-ASCII charset. * @param string The string to convert to a URL safe form * @return URL safe string//from w w w .j a v a 2 s . co m * @throws AciURLCodecException If there was a problem during the encoding */ public String encode(final String string) { // This is what we'll return... String returnValue = null; try { if (string != null) { returnValue = new String(URLCodec.encodeUrl(safeChars, string.getBytes(UTF8)), US_ASCII); } } catch (final UnsupportedEncodingException uee) { // This should never ever happen as both charsets are required by the Java Spec. throw new AciURLCodecException(uee); } // Return the result... return returnValue; }
From source file:com.jfrog.bintray.client.impl.util.URIUtil.java
/** * Escape and encode a given string with allowed characters not to be * escaped and a given charset./*w ww . j a va 2s . c om*/ * * @param unescaped a string * @param allowed allowed characters not to be escaped * @param charset the charset * @return the escaped string */ public static String encode(String unescaped, BitSet allowed, String charset) throws HttpException { byte[] rawdata = URLCodec.encodeUrl(allowed, EncodingUtils.getBytes(unescaped, charset)); return EncodingUtils.getAsciiString(rawdata); }
From source file:com.eucalyptus.auth.login.HmacLoginModuleSupport.java
protected String urlencode(final String text) { final byte[] textBytes = Strings.nullToEmpty(text).getBytes(Charsets.UTF_8); return new String(URLCodec.encodeUrl(URL_SAFE_CHARACTERS, textBytes), Charsets.US_ASCII); }
From source file:com.gargoylesoftware.htmlunit.util.UrlUtils.java
/** * Escapes and encodes the specified string. Based on HttpClient 3.1's <tt>URIUtil.encode()</tt> method. * * @param unescaped the string to encode * @param allowed allowed characters that shouldn't be escaped * @param charset the charset to use// www. j a va2s . c o m * @return the escaped string */ private static String encode(final String unescaped, final BitSet allowed, final String charset) { try { final byte[] bytes = unescaped.getBytes(charset); final byte[] bytes2 = URLCodec.encodeUrl(allowed, bytes); return encodePercentSign(bytes2); } catch (final UnsupportedEncodingException e) { // Should never happen. throw new RuntimeException(e); } }
From source file:com.zimbra.common.util.HttpUtil.java
/** * Used to encode filenames to be safe for browser headers * * Note: Due to browsers finally starting to implement RFC 5987 its better * to use the createContentDisposition() method below so it can * setup the filename= or filename*= correctly based on the browser * * @param browser/* ww w . ja v a2s. c o m*/ * @param filename * @return */ @Deprecated public static String encodeFilename(Browser browser, String filename) { filename = StringUtil.sanitizeFilename(filename); if (StringUtil.isAsciiString(filename) && filename.indexOf('"') == -1) { return '"' + filename + '"'; } try { switch (browser) { case IE: return new String(URLCodec.encodeUrl(IE_URL_SAFE, filename.getBytes(Charsets.UTF_8)), Charsets.ISO_8859_1); case CHROME: case SAFARI: // Safari doesn't support any encoding. The only solution is // to let Safari use the path-info in URL by returning no // filename here. return ""; case FIREFOX: default: return '"' + MimeUtility.encodeText(filename, "utf-8", "B") + '"'; } } catch (UnsupportedEncodingException uee) { return filename; } }
From source file:com.zimbra.common.util.HttpUtil.java
/** * Creates the content disposition value for a given filename. * @param request//from ww w . jav a2s . c o m * @param disposition * @param filename * @return */ public static String createContentDisposition(HttpServletRequest request, String disposition, String filename) { StringBuffer result = new StringBuffer(disposition); result.append("; "); // First, check to see if we're just dealing with a straight ascii filename // If that's the case nothing else needs to be done if (StringUtil.isAsciiString(filename) && filename.indexOf('"') == -1) { result.append("filename=").append("\"").append(filename).append("\""); return result.toString(); } // Now here's where it gets fun. Some browsers don't do well with any // encoding -- see <http://stackoverflow.com/questions/1361604> for a // list. Most browsers support RFC 5987 for encoding non-ascii // filenames. String pathInfo = request.getPathInfo(); String ua = request.getHeader("User-Agent"); Browser browser = guessBrowser(ua); int majorVer = browser.getMajorVersion(ua); if (pathInfo != null && pathInfo.endsWith(filename)) { // If we have a path info that matches our filename, we'll leave out the // filename= part of the header and let the browser use that } else if (browser == Browser.IE && majorVer < 9) { result.append("filename=").append(new String( URLCodec.encodeUrl(IE_URL_SAFE, filename.getBytes(Charsets.UTF_8)), Charsets.ISO_8859_1)); } else if (browser == Browser.SAFARI && majorVer < 6 || browser == Browser.CHROME && majorVer < 11) { // force it over to Latin 1 and '?' any of the characters we don't know. result.append("filename=") .append(new String(filename.getBytes(Charsets.ISO_8859_1), Charsets.ISO_8859_1)); } else { // use RFC 5987 result.append("filename*=") // note: the *= is not a typo .append("UTF-8''") // encode it just like IE .append(new String(URLCodec.encodeUrl(IE_URL_SAFE, filename.getBytes(Charsets.UTF_8)), Charsets.ISO_8859_1)); } return result.toString(); }
From source file:com.alexa.stock.utils.URIUtils.java
/** * Escape and encode a given string with allowed characters not to be * escaped and a given charset./* w w w .j a va2 s . co m*/ * * @param unescaped a string * @param allowed allowed characters not to be escaped * @param charset the charset * @return the escaped string */ public static String encode(String unescaped, BitSet allowed, String charset) throws URIException { byte[] rawdata = URLCodec.encodeUrl(allowed, EncodingUtils.getBytes(unescaped, charset)); return EncodingUtils.getAsciiString(rawdata); }