⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 parsingservicefacade.java

📁 OO 图书馆系统
💻 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 + -