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

📄 search.java

📁 网站即时通讯系统
💻 JAVA
字号:
package com.valhalla.jbother.jabber.smack;import org.jivesoftware.smack.packet.IQ;import org.jivesoftware.smackx.*;import org.jivesoftware.smackx.packet.*;import java.util.ArrayList;import java.util.HashMap;import java.util.Iterator;/** * Created by luke on Apr 1, 2005 12:53:47 PM *//** * class implementing packets used to search Jabber User Directory * * searching process, according to JEP-0055 looks as following: *   1) query the information repository regarding the possible search fields *   2) send search query *   3) receive search results * * Because search fields are not standard, they are kept in hash map: keys are names of the * fields and values are, well, values of those fields :-) * * TODO: search using data forms */public class Search extends IQ{  private static String fId = "$Id$";  public final String NAMESPACE = "jabber:iq:search";  String instructions = null;  HashMap searchFields = null;  ArrayList items = null;  DataForm searchDataForm = null;  public Search(String aInstructions, HashMap aSearchFields) {    instructions = aInstructions;    searchFields = aSearchFields;  }  public Search()  {}  public String getInstructions() {    return instructions;  }  public void setInstructions(String instructions) {    this.instructions = instructions;  }  public HashMap getSearchFields() {    return searchFields;  }  public void setSearchFields(HashMap searchFields) {    this.searchFields = searchFields;  }  public ArrayList getItems() {    return items;  }  public void setItems(ArrayList items) {    this.items = items;  }  public DataForm getSearchDataForm() {    return searchDataForm;  }  public void setSearchDataForm(DataForm searchDataForm) {    this.searchDataForm = searchDataForm;  }  public void addItem(Item aItem)  {    if(items == null) {      items = new ArrayList();    }    items.add(aItem);  }  public String getChildElementXML()  {    StringBuffer buf = new StringBuffer();    buf.append("<query xmlns=\"" + NAMESPACE + "\">");    if(instructions != null) {      buf.append("<instructions>" + instructions + "</instructions>");    }    if(searchFields != null)    {      Iterator iKeys = searchFields.keySet().iterator();      while(iKeys.hasNext())      {        String field = (String)iKeys.next();        buf.append( "<" + field + ">" );        buf.append( searchFields.get(field) );        buf.append( "</" + field + ">" );      }    }    if(items != null)    {      Iterator iItems = items.iterator();      while(iItems.hasNext()) {        buf.append(((Search.Item)iItems.next()).toXML());      }    }    if(searchDataForm != null) {      buf.append(searchDataForm.toXML());    }    buf.append("</query>");    return buf.toString();  }  /**   * inner class for representing "items", ie. the elements that are returned   * from querying the JUD   */  public static class Item  {    private String jid;    HashMap attributes;    public Item(String jid) {      this.jid = jid;    }    public String getJid() {      return jid;    }    public void setJid(String jid) {      this.jid = jid;    }    public HashMap getAttributes() {      return attributes;    }    public void setAttributes(HashMap attributes) {      this.attributes = attributes;    }    public String toXML()    {      StringBuffer out = new StringBuffer();      out.append( "<item jid=\"" + jid + "\">" );      Iterator iAttrs = attributes.keySet().iterator();      while(iAttrs.hasNext())      {        String attr = (String)iAttrs.next();        out.append( "<" + attr + ">" + attributes.get(attr) + "</" + attr + ">" );      }      out.append( "</item>" );      return out.toString();    }  }}

⌨️ 快捷键说明

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