package org.jerrymouse.cc.site.view.redirecter;

import java.io.UnsupportedEncodingException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URLEncoder;
import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jerrymouse.cc.site.bean.Resource;
import org.jerrymouse.cc.site.bean.Type;
import org.jerrymouse.cc.site.web.upload.Upload;
import org.jerrymouse.cc.site.web.upload.UploadToFtp;
import org.jerrymouse.cc.site.web.upload.UploadToGoogle;

/**
 * not finish
 * 
 * @author yankai
 * 
 */
public class GoogleDocRedirect implements Redirecter {

	Log log = LogFactory.getLog(GoogleDocRedirect.class);

	public URI view(Resource resource) {
		Upload upload=new UploadToGoogle();
		String url = upload.putResource(resource);
		return googleviewUrl(url);
	}

	private URI googleviewUrl(String url) {
		URI uri = null;
		try {
			String u = URLEncoder.encode(url, "utf-8");
			uri = new URI("http://docs.google.com/viewer?url=" + u);
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
		} catch (URISyntaxException e) {
			e.printStackTrace();
		}
		return uri;
	}

	public String getName() {
		return "google doc";
	}

	public List<Type> support() {
		String[] s = { "ppt", "pdf" };
		return Type.createTypes(s);
	}

}
