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; }
public XDataForm(JabberDataBlock data, String id, String from) { this.id = id; this.from = from; cmdOk = new Command(SR.get(SR.MS_SEND), Command.OK /*Command.SCREEN*/, 1); cmdCancel = new Command(SR.get(SR.MS_BACK), Command.BACK, 99); // #ifdef DEBUG_CONSOLE // # midlet.BombusQD.debug.add("captcha<<< " + data.toString(),10); // #endif JabberDataBlock challenge = data.findNamespace("captcha", "urn:xmpp:captcha"); JabberDataBlock xdata = challenge.findNamespace("x", "jabber:x:data"); JabberDataBlock oob = data.findNamespace("x", "jabber:x:oob"); String url = oob.getChildBlockText("url"); String title = xdata.getChildBlockText("title"); Vector xData = xdata.getChildBlocks(); if (null == title) title = ""; f = new Form(title); items = new Vector(0); if (url.length() > 0) { TextField formItem = new TextField("URL", url, url.length(), TextField.UNEDITABLE); f.append(formItem); } XDataField field; String msgcid = ""; int size = xData.size(); for (int i = 0; i < size; ++i) { JabberDataBlock ch = (JabberDataBlock) xData.elementAt(i); if (ch.getTagName().equals("instructions")) { f.append(ch.getText()); f.append("\n"); continue; } ; if (!ch.getTagName().equals("field")) continue; field = new XDataField(ch); items.addElement(field); if (field.hidden) continue; if (field.media != null) msgcid = field.mediaUri.substring(4); f.append(field.formItem); } JabberDataBlock dataImage = data.findNamespace("data", "urn:xmpp:bob"); String cid = dataImage.getAttribute("cid"); if (cid.indexOf(msgcid) == 0) { try { byte[] bytes = Strconv.fromBase64(dataImage.getText()); Image img = Image.createImage(bytes, 0, bytes.length); f.append(new ImageItem(null, img, Item.LAYOUT_CENTER, null)); } catch (OutOfMemoryError eom) { // #ifdef DEBUG_CONSOLE // # midlet.BombusQD.debug.add("XDataForm OutOfMem",10); // #endif } catch (Exception e) { } } f.setCommandListener(this); f.addCommand(cmdOk); f.addCommand(cmdCancel); this.parentView = BombusQD.sd.canvas.getCanvas(); BombusQD.setCurrentView(f); }