/** * Listens for file transfer packets. * * @param packet packet to be processed */ public void processPacket(Packet packet) { if (!(packet instanceof StreamInitiation)) return; if (logger.isDebugEnabled()) logger.debug("Incoming Jabber file transfer request."); StreamInitiation streamInitiation = (StreamInitiation) packet; FileTransferRequest jabberRequest = new FileTransferRequest(manager, streamInitiation); // Create a global incoming file transfer request. IncomingFileTransferRequestJabberImpl incomingFileTransferRequest = new IncomingFileTransferRequestJabberImpl( jabberProvider, OperationSetFileTransferJabberImpl.this, jabberRequest); // Send a thumbnail request if a thumbnail is advertised in the // streamInitiation packet. org.jivesoftware.smackx.packet.StreamInitiation.File file = streamInitiation.getFile(); boolean isThumbnailedFile = false; if (file instanceof FileElement) { ThumbnailElement thumbnailElement = ((FileElement) file).getThumbnailElement(); if (thumbnailElement != null) { isThumbnailedFile = true; incomingFileTransferRequest.createThumbnailListeners(thumbnailElement.getCid()); ThumbnailIQ thumbnailRequest = new ThumbnailIQ( streamInitiation.getTo(), streamInitiation.getFrom(), thumbnailElement.getCid(), IQ.Type.GET); if (logger.isDebugEnabled()) logger.debug("Sending thumbnail request:" + thumbnailRequest.toXML()); jabberProvider.getConnection().sendPacket(thumbnailRequest); } } if (!isThumbnailedFile) { // Create an event associated to this global request. FileTransferRequestEvent fileTransferRequestEvent = new FileTransferRequestEvent( OperationSetFileTransferJabberImpl.this, incomingFileTransferRequest, new Date()); // Notify the global listener that a request has arrived. fireFileTransferRequest(fileTransferRequestEvent); } }
/** * Represents this <tt>FileElement</tt> in an XML. * * @see File#toXML() */ @Override public String toXML() { StringBuilder buffer = new StringBuilder(); buffer .append("<") .append(getElementName()) .append(" xmlns=\"") .append(getNamespace()) .append("\" "); if (getName() != null) { buffer.append("name=\"").append(StringUtils.escapeForXML(getName())).append("\" "); } if (getSize() > 0) { buffer.append("size=\"").append(getSize()).append("\" "); } if (getDate() != null) { buffer.append("date=\"").append(StringUtils.formatXEP0082Date(this.getDate())).append("\" "); } if (getHash() != null) { buffer.append("hash=\"").append(getHash()).append("\" "); } if ((this.getDesc() != null && getDesc().length() > 0) || isRanged() || thumbnail != null) { buffer.append(">"); if (getDesc() != null && getDesc().length() > 0) { buffer.append("<desc>").append(StringUtils.escapeForXML(getDesc())).append("</desc>"); } if (isRanged()) { buffer.append("<range/>"); } if (thumbnail != null) { buffer.append(thumbnail.toXML()); } buffer.append("</").append(getElementName()).append(">"); } else { buffer.append("/>"); } return buffer.toString(); }