Skip to content

Instantly share code, notes, and snippets.

@brandhill
Forked from castorflex/URLUtils.java
Created August 11, 2014 06:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save brandhill/cca1893f39a32293d864 to your computer and use it in GitHub Desktop.
Save brandhill/cca1893f39a32293d864 to your computer and use it in GitHub Desktop.
public class URLUtils {
private static final String fGOOGLE_DOC_URL = "http://docs.google.com/gview?embedded=true&url=%s";
private enum GoogleDocType{
PDF(".pdf"), DOC(".doc"), XLS(".xls"), DOCX(".docx"), XLSX(".xlsx");
private String mSuffix;
GoogleDocType(String suffix){
mSuffix = suffix;
}
private boolean isTypeOf(String url){
return url.endsWith(mSuffix);
}
}
public static String buildGoogleDocURL(String url){
if(TextUtils.isEmpty(url)) return null;
for(GoogleDocType type : GoogleDocType.values())
if(type.isTypeOf(url))
return String.format(fGOOGLE_DOC_URL, url);
return url;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment