?? parsingservicefacade.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 ParsingServiceFacade
{
ParsingPhotoSearch subsysone;
ParsingTagRelated subsystwo;
DisplayPS subsysthree;
DisplayTR subsysfour;
private ArrayList <PhotoPS> photosPS=new ArrayList<PhotoPS>();
private ArrayList <PhotoTR> photosTR=new ArrayList<PhotoTR>();
public ParsingServiceFacade(Document doc)
{
subsysone= new ParsingPhotoSearch(doc);
subsystwo = new ParsingTagRelated(doc);
}
public void parsingNodePS(int number_display)
{
this.photosPS=subsysone.parsing();
subsysthree = new DisplayPS(photosPS,number_display);
subsysthree.display();
}
public void parsingNodeTR(int number_display)
{
this.photosTR=subsystwo.parsing();
subsysfour = new DisplayTR(photosTR,number_display);
subsysfour.display();
}
}
//subsystem class one
class ParsingPhotoSearch{
private Document doc;
private ArrayList <PhotoPS> photosPS=new ArrayList<PhotoPS>();
//constructor
public ParsingPhotoSearch(Document doc){
this.doc=doc;
}
public ArrayList parsing(){
Element ebody=doc.getDocumentElement();
parseNode(ebody,photosPS);
return this.photosPS;
}
public void parseNode(Node node, ArrayList photos){
if(node.getNodeName().equals("photo")){
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++) {
parseNode(children.item(i),photos);
}
}
}
}
//subsystem class two
class ParsingTagRelated{
private Document doc;
private ArrayList <PhotoTR> photosTR=new ArrayList<PhotoTR>();
//constructor
public ParsingTagRelated(Document doc){
this.doc=doc;
}
public ArrayList parsing(){
Element ebody=doc.getDocumentElement();
parseNode(ebody,photosTR);
return this.photosTR;
}
public void parseNode(Node node, ArrayList photos){
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++) {
parseNode(children.item(i),photos);
}
}
}
}
//subsystem class three DisplayPS
class DisplayPS{
private ArrayList <PhotoPS> photosPS=new ArrayList<PhotoPS>();
int number_display;
//constructor
public DisplayPS(ArrayList photosPS,int number_display){
this.photosPS=photosPS;
this.number_display=number_display;
}
public void display(){
System.out.println("Matched Photos :");
for (int i =0; i < number_display; i ++){
photosPS.get(i).printPhotoInfo();
}
}
}
//subsystem class four DisplayTR
class DisplayTR{
private ArrayList <PhotoTR> photosTR=new ArrayList<PhotoTR>();
int number_display;
//constructor
public DisplayTR(ArrayList photosTR,int number_display){
this.photosTR=photosTR;
this.number_display=number_display;
}
public void display(){
System.out.println("Matched Tags:");
for (int i =0; i < number_display; i ++)
photosTR.get(i).printPhotoInfo();
}
}
//class PhotoPS
//photo object for flickr.photos.search
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(" Photo--->Id: " + id + " Owner: " + owner + " Secret: " + secret + " Server: " + server + " Farm: " + farm + " Title: " + title + " Ispublic: " + ispublic + " Isfriend: " + isfriend + " Isfamily: " + isfamily);
}
}
//class PhotoSR
//photo object for flickr.tags.getrelated
class PhotoTR{
String nodev;
public PhotoTR(String nodev){
this.nodev =nodev;
}
public void printPhotoInfo(){
System.out.println(" Tag--->: " + nodev );
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -