?? flickrphotosearch.java
字號:
import java.net.URL;
import org.w3c.dom.*;
//one sample application using flickr.photos.search method
public class FlickrPhotoSearch{
//rest---REST
//soap---SOAP
String requestformat;
String method="flickr.photos.search";
String tag;
String parameter="tags";
String api_key;
Integer no_display;
URL url;
public FlickrPhotoSearch (String api_key, String requestformat,String tag,Integer no_display){
this.api_key = api_key;
this.requestformat=requestformat;
this.tag=tag;
this.no_display = no_display;
}
public static void main(String args[]){
// set the firewall proxy to pass the SIT firewall
// comment out the following three lines if you are using the program at home
//System.setProperty("proxySet", "true");
//System.setProperty("http.proxyHost", "www-cache.cs.usyd.edu.au");
//System.setProperty("http.proxyPort","8000");
FlickrPhotoSearch flickrphotosearch = new FlickrPhotoSearch("596dcd0930202d1c338ebb17261fae8c", args[0], args[1], Integer.parseInt(args[2]));
flickrphotosearch.searchByTag();
}
/**
* Assumming only one tag is used to search
*
*/
public void searchByTag(){
try {
//REST
if(requestformat.equals("rest")){
//using factory MessageFormatFactory
this.url = new URL(MessageFormatFactory.generateRest(method,parameter,tag,api_key));
//using strategy to show searched photos
CommContext commcontext = new CommContext(new ConcreteStrategyREST(url,1,no_display));
commcontext.execute();
}
//SOAP
else if(requestformat.equals("soap")){
this.url=new URL("http://api.flickr.com/services/soap/");
CommContext commcontext = new CommContext(new ConcreteStrategySOAP(url,MessageFormatFactory.generateSoap(method,parameter,tag,api_key),1,no_display));
commcontext.execute();
}
else{
System.out.println("Invalid RequestFormat !");
return;
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -