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

📄 catalogsearchdiscresponse.java

📁 基于jxta的文件共享和聊天系统源代码,下载下来分析吧
💻 JAVA
字号:
package catalog_search;import java.io.InputStream;import java.io.StringWriter;import java.net.URL;import java.util.Enumeration;import net.jxta.document.Document;import net.jxta.document.Element;import net.jxta.document.MimeMediaType;import net.jxta.document.StructuredDocument;import net.jxta.document.StructuredDocumentFactory;import net.jxta.document.StructuredTextDocument;import net.jxta.document.TextElement;import net.jxta.id.ID;import net.jxta.id.IDFactory;public class CatalogSearchDiscResponse {	private ID id;	private String catalog;	private boolean thereis;public CatalogSearchDiscResponse(){}		public CatalogSearchDiscResponse(ID i,String c,boolean t)	{		this.id=i;		this.thereis=t;		this.catalog=c;			}		public Document getDocument(MimeMediaType asMimeType)  		  {		 StructuredDocument document = (StructuredTextDocument) 	          StructuredDocumentFactory.newStructuredDocument(	              asMimeType, "example:ExampleResponse");		  Element element;	      element = document.createElement("peerID",id.toString());	      document.appendChild(element);	      element = document.createElement("searchCatalog",catalog);	      document.appendChild(element);	      String temp=null;	      if (thereis)	    	  temp="true";	      else temp="false";	      element=document.createElement("searchThereIs",temp);	      document.appendChild(element);		       	      return document;	  }		public CatalogSearchDiscResponse (InputStream stream) 	 {		StructuredTextDocument document=null;	    try{ 		 document = (StructuredTextDocument) 	         StructuredDocumentFactory.newStructuredDocument(	             new MimeMediaType("text/xml"), stream);	    }	    catch(Exception e){e.printStackTrace();}	     Enumeration elements = document.getChildren();	 	 	 	while (elements.hasMoreElements())	 	{		 		Element el = (Element) elements.nextElement();	 		TextElement element = (TextElement) el;	 		if (element.getName().equals("peerID"))	        {	 			try{id=IDFactory.fromURL(		                new URL((element.getTextValue())));}	             catch(Exception e){e.printStackTrace();}	        	continue;	        }	        	        if (element.getName().equals("searchCatalog"))	        {	        	catalog=element.getTextValue();	        	continue;	        }	        if (element.getName().equals("searchThereIs"))	        {	        	String t=element.getTextValue();	        	if(t.equals("true"))	        		thereis=true;	        	else	        		thereis=false;	        	continue;	        		        }	        	 	}		 }	public String toString()	 {	     try	     {	         StringWriter out = new StringWriter();	         StructuredTextDocument doc = 	             (StructuredTextDocument) getDocument(	                 new MimeMediaType("text/xml"));	         doc.sendToWriter(out);	         return out.toString();	     }	     catch (Exception e)	     {	        e.printStackTrace(); 	     	return "";	     }	 }		public String getSearchCatalog()	{		return this.catalog;	}		public boolean getThereIs()	{		return this.thereis;	}		public ID getId()	{		return this.id;			}}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -