/** * Creates the initiation acceptance packet to forward to the stream * initiator. * * @param streamInitiationOffer The offer from the stream initiator to connect for a stream. * @param namespaces The namespace that relates to the accepted means of transfer. * @return The response to be forwarded to the initiator. */ public StreamInitiation createInitiationAccept( StreamInitiation streamInitiationOffer, String[] namespaces) { StreamInitiation response = new StreamInitiation(); response.setTo(streamInitiationOffer.getFrom()); response.setFrom(streamInitiationOffer.getTo()); response.setType(IQ.Type.RESULT); response.setPacketID(streamInitiationOffer.getPacketID()); DataForm form = new DataForm(Form.TYPE_SUBMIT); FormField field = new FormField( FileTransferNegotiator.STREAM_DATA_FIELD_NAME); for (String namespace : namespaces) { field.addValue(namespace); } form.addField(field); response.setFeatureNegotiationForm(form); return response; }
private DataForm.Item parseItem(XmlPullParser parser) throws Exception { boolean done = false; List fields = new ArrayList(); while (!done) { int eventType = parser.next(); if (eventType == XmlPullParser.START_TAG) { if (parser.getName().equals("field")) { fields.add(parseField(parser)); } } else if (eventType == XmlPullParser.END_TAG) { if (parser.getName().equals("item")) { done = true; } } } return new DataForm.Item(fields); }
private DataForm.ReportedData parseReported(XmlPullParser parser) throws Exception { boolean done = false; List fields = new ArrayList(); while (!done) { int eventType = parser.next(); if (eventType == XmlPullParser.START_TAG) { if (parser.getName().equals("field")) { fields.add(parseField(parser)); } } else if (eventType == XmlPullParser.END_TAG) { if (parser.getName().equals("reported")) { done = true; } } } return new DataForm.ReportedData(fields); }
/** * * @param info * @return true if the packet extensions is ill-formed */ protected static boolean verifyPacketExtensions(DiscoverInfo info) { List<FormField> foundFormTypes = new LinkedList<FormField>(); for (Iterator<PacketExtension> i = info.getExtensions().iterator(); i.hasNext();) { PacketExtension pe = i.next(); if (pe.getNamespace().equals(Form.NAMESPACE)) { DataForm df = (DataForm) pe; for (Iterator<FormField> it = df.getFields(); it.hasNext();) { FormField f = it.next(); if (f.getVariable().equals("FORM_TYPE")) { for (FormField fft : foundFormTypes) { if (f.equals(fft)) return true; } foundFormTypes.add(f); } } } } return false; }
private DataForm.Item parseItem(XmlPullParser parser) throws Exception { boolean done = false; List<FormField> fields = new ArrayList<FormField>(); while (!done) { int eventType = parser.next(); if (eventType == XmlPullParser.START_TAG) { if (parser.getName().equals("field")) { fields.add(parseField(parser)); } } else if (eventType == XmlPullParser.END_TAG) { if (parser.getName().equals("item")) { done = true; } } } return new DataForm.Item(fields); }
private DataForm.ReportedData parseReported(XmlPullParser parser) throws Exception { boolean done = false; List<FormField> fields = new ArrayList<FormField>(); while (!done) { int eventType = parser.next(); if (eventType == XmlPullParser.START_TAG) { if (parser.getName().equals("field")) { fields.add(parseField(parser)); } } else if (eventType == XmlPullParser.END_TAG) { if (parser.getName().equals("reported")) { done = true; } } } return new DataForm.ReportedData(fields); }
/** * Creates the initiation acceptance packet to forward to the stream * initiator. * * @param streamInitiationOffer * The offer from the stream initiator to connect for a stream. * @param namespaces * The namespace that relates to the accepted means of transfer. * @return The response to be forwarded to the initiator. */ public StreamInitiation createInitiationAccept( StreamInitiation streamInitiationOffer, String[] namespaces) { StreamInitiation response = new StreamInitiation(); response.setTo(streamInitiationOffer.getFrom()); response.setFrom(streamInitiationOffer.getTo()); response.setType(IQ.Type.RESULT); response.setPacketID(streamInitiationOffer.getPacketID()); DataForm form = new DataForm(Form.TYPE_SUBMIT); FormField field = new FormField( FileTransferNegotiator.STREAM_DATA_FIELD_NAME); for (String namespace : namespaces) { field.addValue(namespace); } form.addField(field); response.setFeatureNegotiationForm(form); return response; }
/** * Creates the initiation acceptance packet to forward to the stream * initiator. * * @param streamInitiationOffer The offer from the stream initatior to connect for a stream. * @param namespaces The namespace that relates to the accepted means of transfer. * @return The response to be forwarded to the initator. */ public StreamInitiation createInitiationAccept( StreamInitiation streamInitiationOffer, String[] namespaces) { StreamInitiation response = new StreamInitiation(); response.setTo(streamInitiationOffer.getFrom()); response.setFrom(streamInitiationOffer.getTo()); response.setType(IQ.Type.RESULT); response.setPacketID(streamInitiationOffer.getPacketID()); DataForm form = new DataForm(Form.TYPE_SUBMIT); FormField field = new FormField( FileTransferNegotiator.STREAM_DATA_FIELD_NAME); for (String namespace : namespaces) { field.addValue(namespace); } form.addField(field); response.setFeatureNegotiationForm(form); return response; }
/** * Returns a new ReportedData if the packet is used for gathering data and includes an * extension that matches the elementName and namespace "x","jabber:x:data". * * @param packet the packet used for gathering data. * @return the data form parsed from the packet or <tt>null</tt> if there was not * a form in the packet. */ public static Form getFormFrom(Packet packet) { // Check if the packet includes the DataForm extension PacketExtension packetExtension = packet.getExtension("x","jabber:x:data"); if (packetExtension != null) { // Check if the existing DataForm is not a result of a search DataForm dataForm = (DataForm) packetExtension; if (dataForm.getReportedData() == null) return new Form(dataForm); } // Otherwise return null return null; }
/** * Returns a DataForm that serves to send this Form to the server. If the form is of type * submit, it may contain fields with no value. These fields will be removed since they only * exist to assist the user while editing/completing the form in a UI. * * @return the wrapped DataForm. */ public DataForm getDataFormToSend() { if (isSubmitType()) { // Create a new DataForm that contains only the answered fields DataForm dataFormToSend = new DataForm(getType()); for(Iterator<FormField> it=getFields();it.hasNext();) { FormField field = it.next(); if (field.getValues().hasNext()) { dataFormToSend.addField(field); } } return dataFormToSend; } return dataForm; }
@Override protected PacketExtension createReturnExtension(String currentElement, String currentNamespace, Map<String, String> attMap, List<? extends PacketExtension> content) { if (content.size() == 0) return new ConfigurationEvent(attMap.get("node")); else return new ConfigurationEvent(attMap.get("node"), new ConfigureForm((DataForm)content.iterator().next())); }
private FormField getStreamMethodField(DataForm form) { FormField field = null; for (Iterator<FormField> it = form.getFields(); it.hasNext();) { field = it.next(); if (field.getVariable().equals(STREAM_DATA_FIELD_NAME)) { break; } field = null; } return field; }
private DataForm createDefaultInitiationForm() { DataForm form = new DataForm(Form.TYPE_FORM); FormField field = new FormField(STREAM_DATA_FIELD_NAME); field.setType(FormField.TYPE_LIST_MULTI); if (!IBB_ONLY) { field.addOption(new FormField.Option(Socks5BytestreamManager.NAMESPACE)); } field.addOption(new FormField.Option(InBandBytestreamManager.NAMESPACE)); form.addField(field); return form; }
/** * Returns a new ReportedData if the packet is used for reporting data and includes an * extension that matches the elementName and namespace "x","jabber:x:data". * * @param packet the packet used for reporting data. */ public static ReportedData getReportedDataFrom(Packet packet) { // Check if the packet includes the DataForm extension PacketExtension packetExtension = packet.getExtension("x","jabber:x:data"); if (packetExtension != null) { // Check if the existing DataForm is a result of a search DataForm dataForm = (DataForm) packetExtension; if (dataForm.getReportedData() != null) return new ReportedData(dataForm); } // Otherwise return null return null; }
public PacketExtension parseExtension(XmlPullParser parser) throws Exception { boolean done = false; StringBuilder buffer = null; DataForm dataForm = new DataForm(parser.getAttributeValue("", "type")); while (!done) { int eventType = parser.next(); if (eventType == XmlPullParser.START_TAG) { if (parser.getName().equals("instructions")) { dataForm.addInstruction(parser.nextText()); } else if (parser.getName().equals("title")) { dataForm.setTitle(parser.nextText()); } else if (parser.getName().equals("field")) { dataForm.addField(parseField(parser)); } else if (parser.getName().equals("item")) { dataForm.addItem(parseItem(parser)); } else if (parser.getName().equals("reported")) { dataForm.setReportedData(parseReported(parser)); } } else if (eventType == XmlPullParser.END_TAG) { if (parser.getName().equals(dataForm.getElementName())) { done = true; } } } return dataForm; }
private DataForm createDefaultInitiationForm() { DataForm form = new DataForm(Form.TYPE_FORM); FormField field = new FormField(STREAM_DATA_FIELD_NAME); field.setType(FormField.TYPE_LIST_SINGLE); if (!IBB_ONLY) { field.addOption(new FormField.Option(Socks5BytestreamManager.NAMESPACE)); } field.addOption(new FormField.Option(InBandBytestreamManager.NAMESPACE)); form.addField(field); return form; }
/** * Returns a new ReportedData if the packet is used for gathering data and * includes an extension that matches the elementName and namespace * "x","jabber:x:data". * * @param packet * the packet used for gathering data. * @return the data form parsed from the packet or <tt>null</tt> if there * was not a form in the packet. */ public static Form getFormFrom(Packet packet) { // Check if the packet includes the DataForm extension PacketExtension packetExtension = packet.getExtension("x", "jabber:x:data"); if (packetExtension != null) { // Check if the existing DataForm is not a result of a search DataForm dataForm = (DataForm) packetExtension; if (dataForm.getReportedData() == null) return new Form(dataForm); } // Otherwise return null return null; }
/** * Returns a DataForm that serves to send this Form to the server. If the * form is of type submit, it may contain fields with no value. These fields * will be removed since they only exist to assist the user while * editing/completing the form in a UI. * * @return the wrapped DataForm. */ public DataForm getDataFormToSend() { if (isSubmitType()) { // Create a new DataForm that contains only the answered fields DataForm dataFormToSend = new DataForm(getType()); for (Iterator<FormField> it = getFields(); it.hasNext();) { FormField field = it.next(); if (field.getValues().hasNext()) { dataFormToSend.addField(field); } } return dataFormToSend; } return dataForm; }
@Override protected PacketExtension createReturnExtension(String currentElement, String currentNamespace, Map<String, String> attributeMap, List<? extends PacketExtension> content) { return new FormNode(FormNodeType.valueOfFromElementName(currentElement, currentNamespace), attributeMap.get("node"), new Form( (DataForm) content.iterator().next())); }