public JabberDataBlock constructVCard() {
    JabberDataBlock vcardIq = new Iq(null, Iq.TYPE_SET, "vcard-set");
    JabberDataBlock vcardTemp = vcardIq.addChildNs("vCard", "vcard-temp");

    int itemsCount = getCount();

    for (int i = 0; i < itemsCount; i++) {
      String field = getVCardData(i);
      if (field == null) continue;

      String f1 = (String) VCard.vCardFields.elementAt(i);
      String f2 = (String) VCard.vCardFields2.elementAt(i);

      JabberDataBlock subLevel = vcardTemp;
      if (f2 != null) {
        subLevel = vcardTemp.getChildBlock(f2);
        if (subLevel == null) subLevel = vcardTemp.addChild(f2, null);
      }
      subLevel.addChild(f1, field);
    }
    if (photo != null) {
      String mime = getPhotoMIMEType();
      if (mime != null) {
        JabberDataBlock ph = vcardTemp.addChild("PHOTO", null);
        ph.addChild("BINVAL", strconv.toBase64(photo, -1));
        ph.addChild("TYPE", mime);
      }
    }
    // System.out.println(vcard.toString());
    return vcardIq;
  }
  public VCard(JabberDataBlock data) {
    this();
    jid = data.getAttribute("from");
    id = data.getAttribute("id");
    int itemsCount = getCount();
    vCardData = new Vector(itemsCount);
    vCardData.setSize(itemsCount);

    if (data == null) return;
    if (data.getTypeAttribute().equals("error")) return;
    JabberDataBlock vcard = data.findNamespace("vcard-temp");
    if (vcard == null) return; // "No vCard available"

    empty = false;

    for (int i = 0; i < itemsCount; i++) {
      try {
        String f1 = (String) VCard.vCardFields.elementAt(i);
        String f2 = (String) VCard.vCardFields2.elementAt(i);

        JabberDataBlock d2 = (f2 == null) ? vcard : vcard.getChildBlock(f2);

        String field = d2.getChildBlockText(f1);

        if (field.length() > 0) setVCardData(i, field);
      } catch (Exception e) {
        /**/
      }
    }

    try {
      JabberDataBlock photoXML = vcard.getChildBlock("PHOTO").getChildBlock("BINVAL");
      photo = (byte[]) photoXML.getChildBlocks().lastElement();
    } catch (Exception e) {
    }
    ;
  }
  public int blockArrived(JabberDataBlock data) {
    if (data instanceof Iq) {
      String id = data.getAttribute("id");

      JabberDataBlock si = data.getChildBlock("si");
      if (si != null) {
        // stream initiating
        String sid = si.getAttribute("id");

        JabberDataBlock file = si.getChildBlock("file");
        JabberDataBlock feature = si.getChildBlock("feature");

        String type = data.getTypeAttribute();
        if (type.equals("set")) {
          // sender initiates file sending process
          TransferTask task =
              new TransferTask(
                  data.getAttribute("from"),
                  id,
                  sid,
                  file.getAttribute("name"),
                  file.getChildBlockText("desc"),
                  Integer.parseInt(file.getAttribute("size")),
                  null);

          synchronized (taskList) {
            taskList.addElement(task);
          }

          eventNotify();
          StaticData.getInstance().roster.playNotify(0);
          return BLOCK_PROCESSED;
        }
        if (type.equals("result")) {
          // our file were accepted
          TransferTask task = getTransferBySid(id);
          task.initIBB();

          eventNotify();
          return BLOCK_PROCESSED;
        }
      }
      JabberDataBlock open = data.getChildBlock("open");
      if (open != null) {
        String sid = open.getAttribute("sid");
        TransferTask task = getTransferBySid(sid);

        JabberDataBlock accept = new Iq(task.jid, Iq.TYPE_RESULT, id);
        send(accept, true);
        eventNotify();
        return BLOCK_PROCESSED;
      }
      JabberDataBlock close = data.getChildBlock("close");
      if (close != null) {
        String sid = close.getAttribute("sid");
        TransferTask task = getTransferBySid(sid);

        JabberDataBlock done = new Iq(task.jid, Iq.TYPE_RESULT, id);
        send(done, true);
        task.closeFile();
        eventNotify();
        return BLOCK_PROCESSED;
      }
      if (data.getTypeAttribute().equals("result")) {
        TransferTask task = getTransferBySid(id);
        if (task != null) {
          task.startTransfer();
        }
      }
      if (data.getTypeAttribute().equals("error")) {
        TransferTask task = getTransferBySid(id);
        if (task != null) {
          task.cancel();
        }
      }
    }
    if (data instanceof Message) {
      JabberDataBlock bdata = data.getChildBlock("data");
      if (bdata == null) return BLOCK_REJECTED;
      if (!bdata.isJabberNameSpace("http://jabber.org/protocol/ibb")) return BLOCK_REJECTED;
      String sid = bdata.getAttribute("sid");
      TransferTask task = getTransferBySid(sid);

      byte b[] = strconv.fromBase64(bdata.getText());
      System.out.println("data chunk received");
      repaintNotify();
      task.writeFile(b);
    }
    return BLOCK_REJECTED;
  }