/** * Creates a new Form of a given type from scratch.<p> * * Possible form types are: * <ul> * <li>form -> Indicates a form to fill out.</li> * <li>submit -> The form is filled out, and this is the data that is being returned from * the form.</li> * <li>cancel -> The form was cancelled. Tell the asker that piece of information.</li> * <li>result -> Data results being returned from a search, or some other query.</li> * </ul> * * @param type the form's type (e.g. form, submit,cancel,result). */ public Form(String type) { this.dataForm = new DataForm(type); }
/** * Adds a new field to complete as part of the form. * * @param field the field to complete. */ public void addField(FormField field) { dataForm.addField(field); }
public String toXML() { StringBuilder buf = new StringBuilder(); buf.append("<").append(getElementName()).append(" xmlns=\"").append(getNamespace()).append( "\" type=\"" + getType() +"\">"); if (getTitle() != null) { buf.append("<title>").append(getTitle()).append("</title>"); } for (Iterator it=getInstructions(); it.hasNext();) { buf.append("<instructions>").append(it.next()).append("</instructions>"); } // Append the list of fields returned from a search if (getReportedData() != null) { buf.append(getReportedData().toXML()); } // Loop through all the items returned from a search and append them to the string buffer for (Iterator i = getItems(); i.hasNext();) { Item item = (Item) i.next(); buf.append(item.toXML()); } // Loop through all the form fields and append them to the string buffer for (Iterator i = getFields(); i.hasNext();) { FormField field = (FormField) i.next(); buf.append(field.toXML()); } buf.append("</").append(getElementName()).append(">"); return buf.toString(); }
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 static void buildDataForm(SimpleUserSearch search, String instructions, XmlPullParser parser) throws Exception { DataForm dataForm = new DataForm(Form.TYPE_FORM); boolean done = false; dataForm.setTitle("User Search"); dataForm.addInstruction(instructions); while (!done) { int eventType = parser.next(); dataForm.addField(field);
/** * 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 it=getFields();it.hasNext();) { FormField field = (FormField)it.next(); if (field.getValues().hasNext()) { dataFormToSend.addField(field); } } return dataFormToSend; } return dataForm; }
for (Iterator fields = dataForm.getReportedData().getFields(); fields.hasNext();) { FormField field = (FormField)fields.next(); columns.add(new Column(field.getLabel(), field.getVariable(), field.getType())); for (Iterator items = dataForm.getItems(); items.hasNext();) { DataForm.Item item = (DataForm.Item)items.next(); List<Field> fieldList = new ArrayList<Field>(columns.size()); this.title = dataForm.getTitle();
/** * Returns an Iterator for the fields that are part of the form. * * @return an Iterator for the fields that are part of the form. */ public Iterator<FormField> getFields() { return dataForm.getFields(); }
/** * 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; }
/** * Returns the instructions that explain how to fill out the form and what the form is about. * * @return instructions that explain how to fill out the form. */ public String getInstructions() { StringBuilder sb = new StringBuilder(); // Join the list of instructions together separated by newlines for (Iterator it = dataForm.getInstructions(); it.hasNext();) { sb.append((String) it.next()); // If this is not the last instruction then append a newline if (it.hasNext()) { sb.append("\n"); } } return sb.toString(); }
if (extendedInfo != null && extendedInfo.hasHiddenFromTypeField()) { synchronized (extendedInfo) { for (Iterator<FormField> i = extendedInfo.getFields(); i.hasNext();) { FormField f = i.next(); if (!f.getVariable().equals("FORM_TYPE")) {
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 static void buildDataForm(SimpleUserSearch search, String instructions, XmlPullParser parser) throws Exception { DataForm dataForm = new DataForm(Form.TYPE_FORM); boolean done = false; dataForm.setTitle("User Search"); dataForm.addInstruction(instructions); while (!done) { int eventType = parser.next(); dataForm.addField(field);
/** * 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; }
for (Iterator fields = dataForm.getReportedData().getFields(); fields.hasNext();) { FormField field = (FormField)fields.next(); columns.add(new Column(field.getLabel(), field.getVariable(), field.getType())); for (Iterator items = dataForm.getItems(); items.hasNext();) { DataForm.Item item = (DataForm.Item)items.next(); List fieldList = new ArrayList(columns.size()); this.title = dataForm.getTitle();
/** * Returns an Iterator for the fields that are part of the form. * * @return an Iterator for the fields that are part of the form. */ public Iterator getFields() { return dataForm.getFields(); }
/** * 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; }
/** * Returns the instructions that explain how to fill out the form and what the form is about. * * @return instructions that explain how to fill out the form. */ public String getInstructions() { StringBuilder sb = new StringBuilder(); // Join the list of instructions together separated by newlines for (Iterator it = dataForm.getInstructions(); it.hasNext();) { sb.append((String) it.next()); // If this is not the last instruction then append a newline if (it.hasNext()) { sb.append("\n"); } } return sb.toString(); }
public String toXML() { StringBuffer buf = new StringBuffer(); buf.append("<").append(getElementName()).append(" xmlns=\"").append(getNamespace()).append( "\" type=\"" + getType() +"\">"); if (getTitle() != null) { buf.append("<title>").append(getTitle()).append("</title>"); } for (Iterator it=getInstructions(); it.hasNext();) { buf.append("<instructions>").append(it.next()).append("</instructions>"); } // Append the list of fields returned from a search if (getReportedData() != null) { buf.append(getReportedData().toXML()); } // Loop through all the items returned from a search and append them to the string buffer for (Iterator i = getItems(); i.hasNext();) { Item item = (Item) i.next(); buf.append(item.toXML()); } // Loop through all the form fields and append them to the string buffer for (Iterator i = getFields(); i.hasNext();) { FormField field = (FormField) i.next(); buf.append(field.toXML()); } buf.append("</").append(getElementName()).append(">"); return buf.toString(); }
public PacketExtension parseExtension(XmlPullParser parser) throws Exception { boolean done = false; StringBuffer 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; }