use of org.jivesoftware.smack.xml.XmlPullParser in project Smack by igniterealtime.
the class DataLayoutTest method testLayoutFromFile.
@Test
public void testLayoutFromFile() throws Exception {
DataFormProvider pr = new DataFormProvider();
InputStreamReader inputStreamReader = new InputStreamReader(this.getClass().getResourceAsStream(TEST_INPUT_1), "UTF-8");
XmlPullParser parser = PacketParserUtils.getParserFor(inputStreamReader);
DataForm form = pr.parse(parser);
assertNotNull(form);
assertEquals(1, form.getExtensionElements().size());
DataLayout layout = (DataLayout) form.getExtensionElements().get(0);
assertEquals(5, layout.getPageLayout().size());
assertEquals("Label - & \u00E9 \u00E1 ", layout.getLabel());
Section section = (Section) layout.getPageLayout().get(1);
assertEquals("section Label - & \u00E9 \u00E1 ", section.getLabel());
Text text = (Text) layout.getPageLayout().get(2);
assertEquals("PageText - & \u00E9 \u00E1 ", text.getText());
section = (Section) layout.getPageLayout().get(3);
assertEquals("<html>Number of Persons by<br/> Nationality and Status</html>", section.getLabel());
text = (Text) layout.getPageLayout().get(4);
assertEquals("<html><font color='red'><em>DO NOT DELAY</em></font><br/>supply further information</html>", text.getText());
assertNotNull(layout.toXML());
String output = layout.toXML().toString();
assertEquals(TEST_OUTPUT_SPECIAL, output);
}
use of org.jivesoftware.smack.xml.XmlPullParser in project Smack by igniterealtime.
the class DataFormProviderTest method testRetrieveFieldWithEmptyLabel.
@Test
public void testRetrieveFieldWithEmptyLabel() throws XmlPullParserException, IOException, SmackParsingException {
String form = "<x xmlns='jabber:x:data' type='form'>" + " <title>Advanced User Search</title>" + " <instructions>The following fields are available for searching. Wildcard (*) characters are allowed as part of the query.</instructions>" + " <field var='FORM_TYPE' label='' type='hidden'>" + " <value>jabber:iq:search</value>" + " </field>" + " <field label='Search' var='search'>" + " <required/>" + " </field>" + " <field label='Username' var='Username' type='boolean'>" + " <value>true</value>" + " </field>" + " <field label='Name' var='Name' type='boolean'>" + " <value>true</value>" + " </field>" + " <field label='Email' var='Email' type='boolean'>" + " <value>true</value>" + " </field>" + "</x>";
XmlPullParser parser = PacketParserUtils.getParserFor(form);
DataForm dataForm = DataFormProvider.INSTANCE.parse(parser);
FormField usernameFormField = dataForm.getField("FORM_TYPE");
assertEquals(FormField.Type.hidden, usernameFormField.getType());
assertEquals("", usernameFormField.getLabel());
}
use of org.jivesoftware.smack.xml.XmlPullParser in project Smack by igniterealtime.
the class XHTMLExtensionProviderTest method parsesWell.
@Test
public void parsesWell() throws IOException, XmlPullParserException {
InputStream inputStream = getClass().getResourceAsStream(XHTML_EXTENSION_SAMPLE_RESOURCE_NAME);
XmlPullParser parser = PacketParserUtils.getParserFor(inputStream);
XHTMLExtensionProvider provider = new XHTMLExtensionProvider();
ExtensionElement extension = provider.parse(parser, parser.getDepth(), null);
assertThat(extension, instanceOf(XHTMLExtension.class));
XHTMLExtension attachmentsInfo = (XHTMLExtension) extension;
assertThat(sampleXhtml(), equalsCharSequence(attachmentsInfo.getBodies().get(0)));
}
use of org.jivesoftware.smack.xml.XmlPullParser in project Smack by igniterealtime.
the class OfferRequestProvider method parse.
// FIXME It seems because OfferRequestPacket is also defined here, we can
// not add it as generic to the provider, the provider and the packet should
// be split, but since this is legacy code, I don't think that this will
// happen anytime soon.
@Override
public OfferRequestPacket parse(XmlPullParser parser, int initialDepth, XmlEnvironment xmlEnvironment) throws XmlPullParserException, IOException, SmackParsingException {
XmlPullParser.Event eventType = parser.getEventType();
String sessionID = null;
int timeout = -1;
OfferContent content = null;
boolean done = false;
Map<String, List<String>> metaData = new HashMap<>();
if (eventType != XmlPullParser.Event.START_ELEMENT) {
// throw exception
}
Jid userJID = ParserUtils.getJidAttribute(parser);
// Default userID to the JID.
Jid userID = userJID;
while (!done) {
eventType = parser.next();
if (eventType == XmlPullParser.Event.START_ELEMENT) {
String elemName = parser.getName();
if ("timeout".equals(elemName)) {
timeout = Integer.parseInt(parser.nextText());
} else if (MetaData.ELEMENT_NAME.equals(elemName)) {
metaData = MetaDataUtils.parseMetaData(parser);
} else if (SessionID.ELEMENT_NAME.equals(elemName)) {
sessionID = parser.getAttributeValue("", "id");
} else if (UserID.ELEMENT_NAME.equals(elemName)) {
userID = ParserUtils.getJidAttribute(parser, "id");
} else if ("user-request".equals(elemName)) {
content = UserRequest.getInstance();
} else if (RoomInvitation.ELEMENT_NAME.equals(elemName)) {
RoomInvitation invitation = (RoomInvitation) PacketParserUtils.parseExtensionElement(RoomInvitation.ELEMENT_NAME, RoomInvitation.NAMESPACE, parser, xmlEnvironment);
content = new InvitationRequest(invitation.getInviter(), invitation.getRoom(), invitation.getReason());
} else if (RoomTransfer.ELEMENT_NAME.equals(elemName)) {
RoomTransfer transfer = (RoomTransfer) PacketParserUtils.parseExtensionElement(RoomTransfer.ELEMENT_NAME, RoomTransfer.NAMESPACE, parser, xmlEnvironment);
content = new TransferRequest(transfer.getInviter(), transfer.getRoom(), transfer.getReason());
}
} else if (eventType == XmlPullParser.Event.END_ELEMENT) {
if ("offer".equals(parser.getName())) {
done = true;
}
}
}
OfferRequestPacket offerRequest = new OfferRequestPacket(userJID, userID, timeout, metaData, sessionID, content);
offerRequest.setType(IQ.Type.set);
return offerRequest;
}
use of org.jivesoftware.smack.xml.XmlPullParser in project Smack by igniterealtime.
the class TranscriptsProvider method parseAgents.
private static List<Transcripts.AgentDetail> parseAgents(XmlPullParser parser) throws IOException, XmlPullParserException, ParseException {
List<Transcripts.AgentDetail> agents = new ArrayList<>();
String agentJID = null;
Date joinTime = null;
Date leftTime = null;
boolean done = false;
while (!done) {
XmlPullParser.Event eventType = parser.next();
if (eventType == XmlPullParser.Event.START_ELEMENT) {
if (parser.getName().equals("agentJID")) {
agentJID = parser.nextText();
} else if (parser.getName().equals("joinTime")) {
synchronized (UTC_FORMAT) {
joinTime = UTC_FORMAT.parse(parser.nextText());
}
} else if (parser.getName().equals("leftTime")) {
synchronized (UTC_FORMAT) {
leftTime = UTC_FORMAT.parse(parser.nextText());
}
} else if (parser.getName().equals("agent")) {
agentJID = null;
joinTime = null;
leftTime = null;
}
} else if (eventType == XmlPullParser.Event.END_ELEMENT) {
if (parser.getName().equals("agents")) {
done = true;
} else if (parser.getName().equals("agent")) {
agents.add(new Transcripts.AgentDetail(agentJID, joinTime, leftTime));
}
}
}
return agents;
}
Aggregations