?? parsingfacade.java
字號:
import java.net.URL;
import java.util.ArrayList;
import org.w3c.dom.*;
//Facade to provide general parsing services for flickr.photos.search and flickr.tags.getrelated
class ParsingFacade
{
Init subone;
ParsingNodePS subtwo;
ParsingNodeTR subthree;
public ParsingFacade(Document doc,String photo)
{
subone= new Init(doc,photo);
subtwo = new ParsingNodePS();
subthree = new ParsingNodeTR();
}
public void parsingPS(int no_display)
{
Element eboy=subone.getElement();
ArrayList photos=subone.iniArray();
subtwo.displayNode(eboy,photos,no_display);
// Only display the first no_display photos returned
// Photos are returned ordered by upload date and time
// Is consistent with visiting flickr.com through a browser and
// searching the tag and disly restult according to "most recent" order
// Throw exception when there is less than no_display photos returned
System.out.println("Photos:");
for (int i =0; i < no_display; i ++){
subone.photosPS.get(i).printPhotoInfo();
}
}
public void parsingTR(int no_display)
{
Element eboy=subone.getElement();
ArrayList photos=subone.iniArray();
subthree.displayNode(eboy,photos,no_display);
// Only display the first no_display photos returned
// Photos are returned ordered by upload date and time
// Is consistent with visiting flickr.com through a browser and
// searching the tag and disly restult according to "most recent" order
// Throw exception when there is less than no_display photos returned
System.out.println("Tags:");
for (int i =0; i < no_display; i ++)
subone.photosTR.get(i).printPhotoInfo();
}
}
//subsystem class initialize parsing
//this class is used for initialization before parsing
class Init{
private Document doc;
private String photo;
public ArrayList <PhotoPS> photosPS=new ArrayList<PhotoPS>();
public ArrayList <PhotoTR> photosTR=new ArrayList<PhotoTR>();
//constructor
public Init(Document doc,String photo){
this.doc=doc;
this.photo=photo;
}
public Element getElement(){
Element eboy=doc.getDocumentElement();
return eboy;
}
public ArrayList iniArray(){
if(photo=="PhotoPS"){
return this.photosPS;
}
else{
return this.photosTR;
}
}
}
//subsystem class ParsingNodePS
//this class is used for parsing Nodes when using flickr.photos.search
class ParsingNodePS{
//constructor
public ParsingNodePS(){
}
public void displayNode(Node node, ArrayList photos,int no_display){
if(node.getNodeName().equals("photo")){
// extract certain attributes ("owner", "id" and "title") from the returned xml message
// check flickr.photos.search's sample response format
NamedNodeMap nd = node.getAttributes();
photos.add(new PhotoPS(nd.getNamedItem("id").getNodeValue(),
nd.getNamedItem("owner").getNodeValue(),
nd.getNamedItem("secret").getNodeValue(),
nd.getNamedItem("server").getNodeValue(),
nd.getNamedItem("farm").getNodeValue(),
nd.getNamedItem("title").getNodeValue(),
nd.getNamedItem("ispublic").getNodeValue(),
nd.getNamedItem("isfriend").getNodeValue(),
nd.getNamedItem("isfamily").getNodeValue()));
}
NodeList children=node.getChildNodes();
if (children != null) {
for (int i=0; i<children.getLength(); i++) {
displayNode(children.item(i),photos,no_display);
}
}
}
}
//subsystem class ParsingNodeTR
//this class is used for parsing Nodes when using flickr.tags.related
class ParsingNodeTR{
//constructor
public ParsingNodeTR(){
}
public void displayNode(Node node, ArrayList photos,int no_display){
if(node.getNodeName().equals("tag")){
photos.add(new PhotoTR(node.getTextContent()));
}
NodeList children=node.getChildNodes();
if (children != null) {
for (int i=0; i<children.getLength(); i++) {
displayNode(children.item(i),photos,no_display);
}
}
}
}
//class PhotoPS
//this class is used to create photo object when using flickr.photos.search method
class PhotoPS{
String owner;
String id;
String title;
String secret;
String server;
String ispublic;
String isfriend;
String isfamily;
String farm;
public PhotoPS(String id, String owner, String secret,String server,String farm,String title,String ispublic,String isfriend,String isfamily){
this.owner = owner;
this.id = id;
this.title = title;
this.secret = secret;
this.server = server;
this.ispublic = ispublic;
this.isfriend = isfriend;
this.isfamily = isfamily;
this.farm=farm;
}
public void printPhotoInfo(){
System.out.println(" Id: " + id + " Owner: " + owner + " Secret: " + secret + " Server: " + server + " Farm: " + farm + " Title: " + title + " Ispublic: " + ispublic + " Isfriend: " + isfriend + " Isfamily: " + isfamily);
}
}
//class PhotoSR
//this class is used to create photo object when using flickr.tags.getrelated method
class PhotoTR{
String nodev;
public PhotoTR(String nodev){
this.nodev =nodev;
}
public void printPhotoInfo(){
System.out.println(" TagValue: " + nodev );
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -