001/**
002 *
003 * Copyright (c) 2014, the Railo Company Ltd. All rights reserved.
004 *
005 * This library is free software; you can redistribute it and/or
006 * modify it under the terms of the GNU Lesser General Public
007 * License as published by the Free Software Foundation; either 
008 * version 2.1 of the License, or (at your option) any later version.
009 * 
010 * This library is distributed in the hope that it will be useful,
011 * but WITHOUT ANY WARRANTY; without even the implied warranty of
012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
013 * Lesser General Public License for more details.
014 * 
015 * You should have received a copy of the GNU Lesser General Public 
016 * License along with this library.  If not, see <http://www.gnu.org/licenses/>.
017 * 
018 **/
019package lucee.commons.lang;
020
021import java.io.UnsupportedEncodingException;
022import java.util.BitSet;
023
024import lucee.commons.io.CharsetUtil;
025
026import org.apache.commons.codec.net.URLCodec;
027/** 
028 * @deprecated use instead lucee.commons.net.URLEncoder
029 * 
030 */
031public class URLEncoder {
032        
033        private static final BitSet WWW_FORM_URL = new BitSet(256);
034    
035    static {
036        // alpha characters
037        for (int i = 'a'; i <= 'z'; i++) {
038            WWW_FORM_URL.set(i);
039        }
040        for (int i = 'A'; i <= 'Z'; i++) {
041            WWW_FORM_URL.set(i);
042        }
043        // numeric characters
044        for (int i = '0'; i <= '9'; i++) {
045            WWW_FORM_URL.set(i);
046        }
047    }
048
049
050        public static String encode(String str, java.nio.charset.Charset charset) throws UnsupportedEncodingException {
051                return new String(URLCodec.encodeUrl(WWW_FORM_URL, str.getBytes(charset)),"us-ascii");
052        }
053        
054        public static String encode(String str, String encoding) throws UnsupportedEncodingException {
055                return new String(URLCodec.encodeUrl(WWW_FORM_URL, str.getBytes(encoding)),"us-ascii");
056        }
057        
058    
059        
060        public static String encode(String str) throws UnsupportedEncodingException {
061                return encode(str,CharsetUtil.UTF8);
062        }
063}