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

📄 catalogsearchresponse.java

📁 基于jxta的文件共享和聊天系统源代码,下载下来分析吧
💻 JAVA
字号:
/* * Created on 10-ott-2006 * * TODO To change the template for this generated file go to * Window - Preferences - Java - Code Style - Code Templates */package catalog_search;import java.io.InputStream;import java.io.StringWriter;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;/** * @author magowiz * * TODO To change the template for this generated type comment go to * Window - Preferences - Java - Code Style - Code Templates */public class CatalogSearchResponse {	private  String []title;	private String []description;	private String []url;	private String []cname;		public CatalogSearchResponse(){}		public CatalogSearchResponse(String []t,String [] d,String []u,String []c)	{		title=t;		description=d;		url=u;		cname=c;	}		public Document getDocument(MimeMediaType asMimeType)  		  {				StructuredDocument document = (StructuredTextDocument)         StructuredDocumentFactory.newStructuredDocument(	              asMimeType, "example:ExampleResponse");	      Element element;	      	      	      for(int i=0;i<title.length;i++)	    	  	{	    	  		Element root = document.createElement("download");	    	  		document.appendChild(root);	    	  		element = document.createElement("searchTitle",title[i]);	    	  		root.appendChild(element);	    	  		element=document.createElement("searchDescription",description[i]);	    	  		root.appendChild(element);	    	  		element=document.createElement("searchUrl",url[i]);	    	  		root.appendChild(element);	    	  		if(cname.length<i)	    	  			{	    	  				element=document.createElement("cname",cname[cname.length-1]);	    	  				root.appendChild(element);	    	  			}	    	  		else 	    	  			{	    	  				element=document.createElement("cname",cname[i]);	    	  				root.appendChild(element);	    	  			}	      		}	      return document;		 		  	  }		public CatalogSearchResponse (InputStream stream) 	 {				StructuredTextDocument document=null;	    try{ 		 document = (StructuredTextDocument) 	         StructuredDocumentFactory.newStructuredDocument(	             new MimeMediaType("text/xml"), stream);	    }	    catch(Exception e){e.printStackTrace();}	    	     Enumeration elements = document.getChildren();	 	 int i=0;	    	     while (elements.hasMoreElements())	     {	    		     	Element el = (Element) elements.nextElement();	     	TextElement element = (TextElement) el;	        if (element.getName().equals("download"))	        {	        	Enumeration els= element.getChildren();	        			     	        		        		        	while(els.hasMoreElements())	        	{	        			        		Element a = (Element) els.nextElement();	        		TextElement et = (TextElement) a;	        			     				     		        		if (title==null)	        		{	        			title=new String[1];	        			description=new String[1];	        			url=new String[1];	        			cname=new String[1];	        			        			        			if (et.getName().equals("searchTitle"))	        			{	        					        				title[i]=et.getTextValue();	        				continue;	        			}	        			if (et.getName().equals("searchDescription"))	        			{	        				this.description[i]=et.getTextValue();	        				continue;	        		        			}	        			if (et.getName().equals("searchUrl"))	        			{	        				this.url[i]=et.getTextValue();	        				continue;	        		        			}	        			if (et.getName().equals("cname"))	        			{	        				this.cname[i]=et.getTextValue();	        				continue;	        		        			}	        	}	        	else	        	{	        		if (et.getName().equals("searchTitle"))        			{	        			String []t=new String[i+1];        				for(int j=0;j<title.length;j++)        					t[j]=title[j];	        			t[i]=et.getTextValue();          				title=t;        				continue;        			}        			if (et.getName().equals("searchDescription"))        			{        				String []d=new String[i+1];        				for(int j=0;j<description.length;j++)        					d[j]=description[j];	        			d[i]=et.getTextValue();        				description=d;        				continue;	        	        			}        			if (et.getName().equals("searchUrl"))        			{        				String []u=new String[i+1];        				for(int j=0;j<url.length;j++)        					u[j]=url[j];	        			u[i]=et.getTextValue();        				url=u;        				continue;	        	        			}        			if (et.getName().equals("cname"))        			{        				String []c=new String[i+1];        				for(int j=0;j<cname.length;j++)        					c[j]=cname[j];	        			c[i]=et.getTextValue();         				cname=c;        				continue;       	        			}	        	}	        		        	}	        	i++;	        }	        	     } 	     		 }	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 []getSearchTitles()	{		return this.title;	}	public String []getSearchDescriptions()	{		return this.description;	}		public String []getSearchUrls()	{		return this.url;	}		public String [] getSearchCName()	{		return this.cname;			}}

⌨️ 快捷键说明

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