📄 flickrtaggetrelated.java
字号:
import java.net.URL;
import org.w3c.dom.*;
//one sample application using flickr.tags.getrelated method to find related tags of given tag
public class FlickrTagGetrelated{
//rest---REST
//soap---SOAP
String requestformat;
String method="flickr.tags.getrelated";
String tag;
String parameter="tag";
String api_key;
Integer no_display;
URL url;
public FlickrTagGetrelated (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;
}
// simulated client
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");
FlickrTagGetrelated flickrtaggetrelated = new FlickrTagGetrelated("596dcd0930202d1c338ebb17261fae8c", args[0], args[1], Integer.parseInt(args[2]));
flickrtaggetrelated.getRelatedTags();
}
/**
* Assumming only one tag is used to search
*
*/
public void getRelatedTags(){
try {
//REST
if(requestformat.equals("rest")){
//using factory MessageFormatFactory
this.url = new URL(MessageFormatFactory.generateRest(method,parameter,tag,api_key));
//using strategy to show related tags
CommContext commcontext = new CommContext(new ConcreteStrategyREST(url,2,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),2,no_display));
commcontext.execute();
}
else{
System.out.println("Invalid RequestFormat name!");
return;
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -