
package org.apache.webdav.lib.methods;

import java.net.URLEncoder;
import java.io.UnsupportedEncodingException;

/**
 * This class help encode the path contains invalid characters.
 *
 * <P>     When path contains special characters such as '{', '}'
 *         or Unicode character. When the application executes
 *         PropFind, PropPatch, Move, Delete method etc..., can cause exception
 *         "invalid URI"
 *
 * <PRE>
 *         Example: When we fetch an entry of Calendar of MS Exchange server
 *
 *         path = PathEncoder.encode("exchange/user/calendar/{0994-232-EDSG-121}.eml", "UTF-8");
 *         // path is "exchange/user/calendar/7B0994-232-EDSG-1217B.eml"
 *         PropFindMethod pfm = new PropFindMethod(path,DepthSupport.DEPTH_0);
 *         // Now safe to execute this method
 *
 * </PRE>
 *
 *
 * @author <a href="mailto:truongnn@yahoo.com">Truong Nguyen Ngoc</a>
 */


 public class PathEncoder{

   /**
    @param path The path will pass through method
    @param enc The name of a supported character encoding.
    @    Standard Charset encoding:
    *    US-ASCII Seven-bit ASCII, a.k.a. ISO646-US, a.k.a. the Basic Latin block of the Unicode character set
    *    ISO-8859-1   ISO Latin Alphabet No. 1, a.k.a. ISO-LATIN-1
    *    UTF-8 Eight-bit UCS Transformation Format
    *    UTF-16BE Sixteen-bit UCS Transformation Format, big-endian byte order
    *    UTF-16LE Sixteen-bit UCS Transformation Format, little-endian byte order
    *    UTF-16 Sixteen-bit UCS Transformation Format, byte order identified by an optional byte-order mark
    *    etc.
    * @exception java.io.UnsupportedEncodingException
    */

   public static String encode(String path, String enc) throws UnsupportedEncodingException{
      return URLEncoder.encode(path, enc);
   }
 }

