package org.injac.indexing.util;

import org.apache.commons.httpclient.util.URIUtil;

public class PathManager {

	
	static public String renderURL(String webdavPath, String upnode, String baseURL){
		String renderPath = baseURL +"/nav"+ webdavPath.substring(webdavPath.indexOf(upnode)+upnode.length());
		return renderPath;
	}
	static public String encodeURL(String url){

		String encodePath = url;
		try{
		
			if (url.endsWith("/")) {
				encodePath = url.substring(0, url.length()-1);
			}	
	
			encodePath = URIUtil.encodePathQuery(encodePath);
			encodePath = encodePath.replaceAll(" ","%20");
			encodePath = encodePath.replaceAll("!","%21");			
			encodePath = encodePath.replaceAll("#","%23");
			encodePath = encodePath.replaceAll("\\$","%24");					
			encodePath = encodePath.replaceAll("&","%26");
			encodePath = encodePath.replaceAll("'","%27");
			encodePath = encodePath.replaceAll("\\(","%28");
			encodePath = encodePath.replaceAll("\\)","%29");		
			encodePath = encodePath.replaceAll("@","%40");		
			encodePath = encodePath.replaceAll("`","%60");
		}catch(Exception e)
		{
			System.out.println("Exc");
		}
		return encodePath;
	}
	
}
