1
0
Fork 0
mirror of https://codeberg.org/Mercury-IM/Smack synced 2025-12-10 15:11:08 +01:00

Smack 1.5.1 + SMACK-73. Branch generated to include TLS support in HEAD.

git-svn-id: http://svn.igniterealtime.org/svn/repos/smack/trunk@2716 b35dd754-fafc-0310-a699-88a17e54d16e
This commit is contained in:
Gaston Dombiak 2005-08-24 17:52:52 +00:00 committed by gato
parent ca9c6aea93
commit 171af4b325
276 changed files with 40441 additions and 0 deletions

View file

@ -0,0 +1,160 @@
/**
* $RCSfile$
* $Revision$
* $Date$
*
* Copyright 2003-2004 Jive Software.
*
* All rights reserved. Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jivesoftware.smackx.provider;
import java.util.ArrayList;
import java.util.List;
import org.jivesoftware.smack.packet.PacketExtension;
import org.jivesoftware.smack.provider.PacketExtensionProvider;
import org.jivesoftware.smackx.FormField;
import org.jivesoftware.smackx.packet.DataForm;
import org.xmlpull.v1.XmlPullParser;
/**
* The DataFormProvider parses DataForm packets.
*
* @author Gaston Dombiak
*/
public class DataFormProvider implements PacketExtensionProvider {
/**
* Creates a new DataFormProvider.
* ProviderManager requires that every PacketExtensionProvider has a public, no-argument constructor
*/
public DataFormProvider() {
}
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;
}
private FormField parseField(XmlPullParser parser) throws Exception {
boolean done = false;
FormField formField = new FormField(parser.getAttributeValue("", "var"));
formField.setLabel(parser.getAttributeValue("", "label"));
formField.setType(parser.getAttributeValue("", "type"));
while (!done) {
int eventType = parser.next();
if (eventType == XmlPullParser.START_TAG) {
if (parser.getName().equals("desc")) {
formField.setDescription(parser.nextText());
}
else if (parser.getName().equals("value")) {
formField.addValue(parser.nextText());
}
else if (parser.getName().equals("required")) {
formField.setRequired(true);
}
else if (parser.getName().equals("option")) {
formField.addOption(parseOption(parser));
}
} else if (eventType == XmlPullParser.END_TAG) {
if (parser.getName().equals("field")) {
done = true;
}
}
}
return formField;
}
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);
}
private FormField.Option parseOption(XmlPullParser parser) throws Exception {
boolean done = false;
FormField.Option option = null;
String label = parser.getAttributeValue("", "label");
while (!done) {
int eventType = parser.next();
if (eventType == XmlPullParser.START_TAG) {
if (parser.getName().equals("value")) {
option = new FormField.Option(label, parser.nextText());
}
} else if (eventType == XmlPullParser.END_TAG) {
if (parser.getName().equals("option")) {
done = true;
}
}
}
return option;
}
}

View file

@ -0,0 +1,71 @@
/**
* $RCSfile$
* $Revision$
* $Date$
*
* Copyright 2003-2004 Jive Software.
*
* All rights reserved. Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jivesoftware.smackx.provider;
import org.jivesoftware.smack.packet.PacketExtension;
import org.jivesoftware.smack.provider.PacketExtensionProvider;
import org.jivesoftware.smackx.packet.DelayInformation;
import org.xmlpull.v1.XmlPullParser;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.TimeZone;
/**
* The DelayInformationProvider parses DelayInformation packets.
*
* @author Gaston Dombiak
*/
public class DelayInformationProvider implements PacketExtensionProvider {
/**
* Creates a new DeliveryInformationProvider.
* ProviderManager requires that every PacketExtensionProvider has a public, no-argument
* constructor
*/
public DelayInformationProvider() {
}
public PacketExtension parseExtension(XmlPullParser parser) throws Exception {
Date stamp = null;
try {
stamp = DelayInformation.UTC_FORMAT.parse(parser.getAttributeValue("", "stamp"));
} catch (ParseException e) {
// Try again but assuming that the date follows JEP-82 format
// (Jabber Date and Time Profiles)
try {
stamp = DelayInformation.NEW_UTC_FORMAT
.parse(parser.getAttributeValue("", "stamp"));
} catch (ParseException e1) {
// Last attempt. Try parsing the date assuming that it does not include milliseconds
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
formatter.setTimeZone(TimeZone.getTimeZone("UTC"));
stamp = formatter.parse(parser.getAttributeValue("", "stamp"));
}
}
DelayInformation delayInformation = new DelayInformation(stamp);
delayInformation.setFrom(parser.getAttributeValue("", "from"));
delayInformation.setReason(parser.nextText());
return delayInformation;
}
}

View file

@ -0,0 +1,83 @@
/**
* $RCSfile$
* $Revision$
* $Date$
*
* Copyright 2003-2004 Jive Software.
*
* All rights reserved. Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jivesoftware.smackx.provider;
import org.jivesoftware.smack.packet.IQ;
import org.jivesoftware.smack.provider.IQProvider;
import org.jivesoftware.smack.util.PacketParserUtils;
import org.jivesoftware.smackx.packet.DiscoverInfo;
import org.xmlpull.v1.XmlPullParser;
/**
* The DiscoverInfoProvider parses Service Discovery information packets.
*
* @author Gaston Dombiak
*/
public class DiscoverInfoProvider implements IQProvider {
public IQ parseIQ(XmlPullParser parser) throws Exception {
DiscoverInfo discoverInfo = new DiscoverInfo();
boolean done = false;
DiscoverInfo.Feature feature = null;
DiscoverInfo.Identity identity = null;
String category = "";
String name = "";
String type = "";
String variable = "";
discoverInfo.setNode(parser.getAttributeValue("", "node"));
while (!done) {
int eventType = parser.next();
if (eventType == XmlPullParser.START_TAG) {
if (parser.getName().equals("identity")) {
// Initialize the variables from the parsed XML
category = parser.getAttributeValue("", "category");
name = parser.getAttributeValue("", "name");
type = parser.getAttributeValue("", "type");
}
else if (parser.getName().equals("feature")) {
// Initialize the variables from the parsed XML
variable = parser.getAttributeValue("", "var");
}
// Otherwise, it must be a packet extension.
else {
discoverInfo.addExtension(PacketParserUtils.parsePacketExtension(parser
.getName(), parser.getNamespace(), parser));
}
} else if (eventType == XmlPullParser.END_TAG) {
if (parser.getName().equals("identity")) {
// Create a new identity and add it to the discovered info.
identity = new DiscoverInfo.Identity(category, name);
identity.setType(type);
discoverInfo.addIdentity(identity);
}
if (parser.getName().equals("feature")) {
// Create a new feature and add it to the discovered info.
discoverInfo.addFeature(variable);
}
if (parser.getName().equals("query")) {
done = true;
}
}
}
return discoverInfo;
}
}

View file

@ -0,0 +1,71 @@
/**
* $RCSfile$
* $Revision$
* $Date$
*
* Copyright 2003-2004 Jive Software.
*
* All rights reserved. Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jivesoftware.smackx.provider;
import org.jivesoftware.smack.packet.IQ;
import org.jivesoftware.smack.provider.IQProvider;
import org.jivesoftware.smackx.packet.*;
import org.xmlpull.v1.XmlPullParser;
/**
* The DiscoverInfoProvider parses Service Discovery items packets.
*
* @author Gaston Dombiak
*/
public class DiscoverItemsProvider implements IQProvider {
public IQ parseIQ(XmlPullParser parser) throws Exception {
DiscoverItems discoverItems = new DiscoverItems();
boolean done = false;
DiscoverItems.Item item = null;
String jid = "";
String name = "";
String action = "";
String node = "";
discoverItems.setNode(parser.getAttributeValue("", "node"));
while (!done) {
int eventType = parser.next();
if (eventType == XmlPullParser.START_TAG) {
if (parser.getName().equals("item")) {
// Initialize the variables from the parsed XML
jid = parser.getAttributeValue("", "jid");
name = parser.getAttributeValue("", "name");
node = parser.getAttributeValue("", "node");
action = parser.getAttributeValue("", "action");
}
} else if (eventType == XmlPullParser.END_TAG) {
if (parser.getName().equals("item")) {
// Create a new Item and add it to DiscoverItems.
item = new DiscoverItems.Item(jid);
item.setName(name);
item.setNode(node);
item.setAction(action);
discoverItems.addItem(item);
}
if (parser.getName().equals("query")) {
done = true;
}
}
}
return discoverItems;
}
}

View file

@ -0,0 +1,81 @@
/**
* $RCSfile$
* $Revision$
* $Date$
*
* Copyright 2003-2004 Jive Software.
*
* All rights reserved. Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jivesoftware.smackx.provider;
import org.jivesoftware.smack.packet.IQ;
import org.jivesoftware.smack.provider.IQProvider;
import org.jivesoftware.smackx.packet.MUCAdmin;
import org.xmlpull.v1.XmlPullParser;
/**
* The MUCAdminProvider parses MUCAdmin packets. (@see MUCAdmin)
*
* @author Gaston Dombiak
*/
public class MUCAdminProvider implements IQProvider {
public IQ parseIQ(XmlPullParser parser) throws Exception {
MUCAdmin mucAdmin = new MUCAdmin();
boolean done = false;
while (!done) {
int eventType = parser.next();
if (eventType == XmlPullParser.START_TAG) {
if (parser.getName().equals("item")) {
mucAdmin.addItem(parseItem(parser));
}
}
else if (eventType == XmlPullParser.END_TAG) {
if (parser.getName().equals("query")) {
done = true;
}
}
}
return mucAdmin;
}
private MUCAdmin.Item parseItem(XmlPullParser parser) throws Exception {
boolean done = false;
MUCAdmin.Item item =
new MUCAdmin.Item(
parser.getAttributeValue("", "affiliation"),
parser.getAttributeValue("", "role"));
item.setNick(parser.getAttributeValue("", "nick"));
item.setJid(parser.getAttributeValue("", "jid"));
while (!done) {
int eventType = parser.next();
if (eventType == XmlPullParser.START_TAG) {
if (parser.getName().equals("actor")) {
item.setActor(parser.getAttributeValue("", "jid"));
}
if (parser.getName().equals("reason")) {
item.setReason(parser.nextText());
}
}
else if (eventType == XmlPullParser.END_TAG) {
if (parser.getName().equals("item")) {
done = true;
}
}
}
return item;
}
}

View file

@ -0,0 +1,108 @@
/**
* $RCSfile$
* $Revision$
* $Date$
*
* Copyright 2003-2004 Jive Software.
*
* All rights reserved. Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jivesoftware.smackx.provider;
import org.jivesoftware.smack.packet.*;
import org.jivesoftware.smack.provider.*;
import org.jivesoftware.smack.util.PacketParserUtils;
import org.jivesoftware.smackx.packet.MUCOwner;
import org.xmlpull.v1.XmlPullParser;
/**
* The MUCOwnerProvider parses MUCOwner packets. (@see MUCOwner)
*
* @author Gaston Dombiak
*/
public class MUCOwnerProvider implements IQProvider {
public IQ parseIQ(XmlPullParser parser) throws Exception {
MUCOwner mucOwner = new MUCOwner();
boolean done = false;
while (!done) {
int eventType = parser.next();
if (eventType == XmlPullParser.START_TAG) {
if (parser.getName().equals("item")) {
mucOwner.addItem(parseItem(parser));
}
else if (parser.getName().equals("destroy")) {
mucOwner.setDestroy(parseDestroy(parser));
}
// Otherwise, it must be a packet extension.
else {
mucOwner.addExtension(PacketParserUtils.parsePacketExtension(parser.getName(),
parser.getNamespace(), parser));
}
}
else if (eventType == XmlPullParser.END_TAG) {
if (parser.getName().equals("query")) {
done = true;
}
}
}
return mucOwner;
}
private MUCOwner.Item parseItem(XmlPullParser parser) throws Exception {
boolean done = false;
MUCOwner.Item item = new MUCOwner.Item(parser.getAttributeValue("", "affiliation"));
item.setNick(parser.getAttributeValue("", "nick"));
item.setRole(parser.getAttributeValue("", "role"));
item.setJid(parser.getAttributeValue("", "jid"));
while (!done) {
int eventType = parser.next();
if (eventType == XmlPullParser.START_TAG) {
if (parser.getName().equals("actor")) {
item.setActor(parser.getAttributeValue("", "jid"));
}
if (parser.getName().equals("reason")) {
item.setReason(parser.nextText());
}
}
else if (eventType == XmlPullParser.END_TAG) {
if (parser.getName().equals("item")) {
done = true;
}
}
}
return item;
}
private MUCOwner.Destroy parseDestroy(XmlPullParser parser) throws Exception {
boolean done = false;
MUCOwner.Destroy destroy = new MUCOwner.Destroy();
destroy.setJid(parser.getAttributeValue("", "jid"));
while (!done) {
int eventType = parser.next();
if (eventType == XmlPullParser.START_TAG) {
if (parser.getName().equals("reason")) {
destroy.setReason(parser.nextText());
}
}
else if (eventType == XmlPullParser.END_TAG) {
if (parser.getName().equals("destroy")) {
done = true;
}
}
}
return destroy;
}
}

View file

@ -0,0 +1,174 @@
/**
* $RCSfile$
* $Revision$
* $Date$
*
* Copyright 2003-2004 Jive Software.
*
* All rights reserved. Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jivesoftware.smackx.provider;
import org.jivesoftware.smack.packet.*;
import org.jivesoftware.smack.provider.*;
import org.jivesoftware.smackx.packet.*;
import org.xmlpull.v1.XmlPullParser;
/**
* The MUCUserProvider parses packets with extended presence information about
* roles and affiliations.
*
* @author Gaston Dombiak
*/
public class MUCUserProvider implements PacketExtensionProvider {
/**
* Creates a new MUCUserProvider.
* ProviderManager requires that every PacketExtensionProvider has a public, no-argument
* constructor
*/
public MUCUserProvider() {
}
/**
* Parses a MUCUser packet (extension sub-packet).
*
* @param parser the XML parser, positioned at the starting element of the extension.
* @return a PacketExtension.
* @throws Exception if a parsing error occurs.
*/
public PacketExtension parseExtension(XmlPullParser parser) throws Exception {
MUCUser mucUser = new MUCUser();
boolean done = false;
while (!done) {
int eventType = parser.next();
if (eventType == XmlPullParser.START_TAG) {
if (parser.getName().equals("invite")) {
mucUser.setInvite(parseInvite(parser));
}
if (parser.getName().equals("item")) {
mucUser.setItem(parseItem(parser));
}
if (parser.getName().equals("password")) {
mucUser.setPassword(parser.nextText());
}
if (parser.getName().equals("status")) {
mucUser.setStatus(new MUCUser.Status(parser.getAttributeValue("", "code")));
}
if (parser.getName().equals("decline")) {
mucUser.setDecline(parseDecline(parser));
}
if (parser.getName().equals("destroy")) {
mucUser.setDestroy(parseDestroy(parser));
}
}
else if (eventType == XmlPullParser.END_TAG) {
if (parser.getName().equals("x")) {
done = true;
}
}
}
return mucUser;
}
private MUCUser.Item parseItem(XmlPullParser parser) throws Exception {
boolean done = false;
MUCUser.Item item =
new MUCUser.Item(
parser.getAttributeValue("", "affiliation"),
parser.getAttributeValue("", "role"));
item.setNick(parser.getAttributeValue("", "nick"));
item.setJid(parser.getAttributeValue("", "jid"));
while (!done) {
int eventType = parser.next();
if (eventType == XmlPullParser.START_TAG) {
if (parser.getName().equals("actor")) {
item.setActor(parser.getAttributeValue("", "jid"));
}
if (parser.getName().equals("reason")) {
item.setReason(parser.nextText());
}
}
else if (eventType == XmlPullParser.END_TAG) {
if (parser.getName().equals("item")) {
done = true;
}
}
}
return item;
}
private MUCUser.Invite parseInvite(XmlPullParser parser) throws Exception {
boolean done = false;
MUCUser.Invite invite = new MUCUser.Invite();
invite.setFrom(parser.getAttributeValue("", "from"));
invite.setTo(parser.getAttributeValue("", "to"));
while (!done) {
int eventType = parser.next();
if (eventType == XmlPullParser.START_TAG) {
if (parser.getName().equals("reason")) {
invite.setReason(parser.nextText());
}
}
else if (eventType == XmlPullParser.END_TAG) {
if (parser.getName().equals("invite")) {
done = true;
}
}
}
return invite;
}
private MUCUser.Decline parseDecline(XmlPullParser parser) throws Exception {
boolean done = false;
MUCUser.Decline decline = new MUCUser.Decline();
decline.setFrom(parser.getAttributeValue("", "from"));
decline.setTo(parser.getAttributeValue("", "to"));
while (!done) {
int eventType = parser.next();
if (eventType == XmlPullParser.START_TAG) {
if (parser.getName().equals("reason")) {
decline.setReason(parser.nextText());
}
}
else if (eventType == XmlPullParser.END_TAG) {
if (parser.getName().equals("decline")) {
done = true;
}
}
}
return decline;
}
private MUCUser.Destroy parseDestroy(XmlPullParser parser) throws Exception {
boolean done = false;
MUCUser.Destroy destroy = new MUCUser.Destroy();
destroy.setJid(parser.getAttributeValue("", "jid"));
while (!done) {
int eventType = parser.next();
if (eventType == XmlPullParser.START_TAG) {
if (parser.getName().equals("reason")) {
destroy.setReason(parser.nextText());
}
}
else if (eventType == XmlPullParser.END_TAG) {
if (parser.getName().equals("destroy")) {
done = true;
}
}
}
return destroy;
}
}

View file

@ -0,0 +1,77 @@
/**
* $RCSfile$
* $Revision$
* $Date$
*
* Copyright 2003-2004 Jive Software.
*
* All rights reserved. Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jivesoftware.smackx.provider;
import org.jivesoftware.smack.packet.PacketExtension;
import org.jivesoftware.smack.provider.PacketExtensionProvider;
import org.jivesoftware.smackx.packet.MessageEvent;
import org.xmlpull.v1.XmlPullParser;
/**
*
* The MessageEventProvider parses Message Event packets.
*
* @author Gaston Dombiak
*/
public class MessageEventProvider implements PacketExtensionProvider {
/**
* Creates a new MessageEventProvider.
* ProviderManager requires that every PacketExtensionProvider has a public, no-argument constructor
*/
public MessageEventProvider() {
}
/**
* Parses a MessageEvent packet (extension sub-packet).
*
* @param parser the XML parser, positioned at the starting element of the extension.
* @return a PacketExtension.
* @throws Exception if a parsing error occurs.
*/
public PacketExtension parseExtension(XmlPullParser parser)
throws Exception {
MessageEvent messageEvent = new MessageEvent();
boolean done = false;
while (!done) {
int eventType = parser.next();
if (eventType == XmlPullParser.START_TAG) {
if (parser.getName().equals("id"))
messageEvent.setPacketID(parser.nextText());
if (parser.getName().equals(MessageEvent.COMPOSING))
messageEvent.setComposing(true);
if (parser.getName().equals(MessageEvent.DELIVERED))
messageEvent.setDelivered(true);
if (parser.getName().equals(MessageEvent.DISPLAYED))
messageEvent.setDisplayed(true);
if (parser.getName().equals(MessageEvent.OFFLINE))
messageEvent.setOffline(true);
} else if (eventType == XmlPullParser.END_TAG) {
if (parser.getName().equals("x")) {
done = true;
}
}
}
return messageEvent;
}
}

View file

@ -0,0 +1,46 @@
/**
* $RCSfile$
* $Revision$
* $Date$
*
* Copyright 2003-2004 Jive Software.
*
* All rights reserved. Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jivesoftware.smackx.provider;
import org.xmlpull.v1.XmlPullParser;
import org.jivesoftware.smackx.packet.PrivateData;
/**
* An interface for parsing custom private data. Each PrivateDataProvider must
* be registered with the PrivateDataManager class for it to be used. Every implementation
* of this interface <b>must</b> have a public, no-argument constructor.
*
* @author Matt Tucker
*/
public interface PrivateDataProvider {
/**
* Parse the private data sub-document and create a PrivateData instance. At the
* beginning of the method call, the xml parser will be positioned at the opening
* tag of the private data child element. At the end of the method call, the parser
* <b>must</b> be positioned on the closing tag of the child element.
*
* @param parser an XML parser.
* @return a new PrivateData instance.
* @throws Exception if an error occurs parsing the XML.
*/
public PrivateData parsePrivateData(XmlPullParser parser) throws Exception;
}

View file

@ -0,0 +1,90 @@
/**
* $RCSfile$
* $Revision$
* $Date$
*
* Copyright 2003-2004 Jive Software.
*
* All rights reserved. Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jivesoftware.smackx.provider;
import java.util.ArrayList;
import org.jivesoftware.smack.packet.PacketExtension;
import org.jivesoftware.smack.provider.PacketExtensionProvider;
import org.jivesoftware.smackx.*;
import org.jivesoftware.smackx.packet.*;
import org.xmlpull.v1.XmlPullParser;
/**
*
* The RosterExchangeProvider parses RosterExchange packets.
*
* @author Gaston Dombiak
*/
public class RosterExchangeProvider implements PacketExtensionProvider {
/**
* Creates a new RosterExchangeProvider.
* ProviderManager requires that every PacketExtensionProvider has a public, no-argument constructor
*/
public RosterExchangeProvider() {
}
/**
* Parses a RosterExchange packet (extension sub-packet).
*
* @param parser the XML parser, positioned at the starting element of the extension.
* @return a PacketExtension.
* @throws Exception if a parsing error occurs.
*/
public PacketExtension parseExtension(XmlPullParser parser) throws Exception {
RosterExchange rosterExchange = new RosterExchange();
boolean done = false;
RemoteRosterEntry remoteRosterEntry = null;
String jid = "";
String name = "";
ArrayList groupsName = new ArrayList();
while (!done) {
int eventType = parser.next();
if (eventType == XmlPullParser.START_TAG) {
if (parser.getName().equals("item")) {
// Reset this variable since they are optional for each item
groupsName = new ArrayList();
// Initialize the variables from the parsed XML
jid = parser.getAttributeValue("", "jid");
name = parser.getAttributeValue("", "name");
}
if (parser.getName().equals("group")) {
groupsName.add(parser.nextText());
}
} else if (eventType == XmlPullParser.END_TAG) {
if (parser.getName().equals("item")) {
// Create packet.
remoteRosterEntry = new RemoteRosterEntry(jid, name, (String[]) groupsName.toArray(new String[groupsName.size()]));
rosterExchange.addRosterEntry(remoteRosterEntry);
}
if (parser.getName().equals("x")) {
done = true;
}
}
}
return rosterExchange;
}
}

View file

@ -0,0 +1,209 @@
/**
* $RCSfile$
* $Revision$
* $Date$
*
* Copyright 2003-2004 Jive Software.
*
* All rights reserved. Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jivesoftware.smackx.provider;
import org.jivesoftware.smack.packet.IQ;
import org.jivesoftware.smack.provider.IQProvider;
import org.jivesoftware.smackx.packet.VCard;
import org.w3c.dom.*;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import java.io.ByteArrayInputStream;
import java.io.IOException;
/**
* Created by IntelliJ IDEA.
* User: Gaston
* Date: Jun 18, 2005
* Time: 1:00:57 AM
* To change this template use File | Settings | File Templates.
*/
public class VCardProvider implements IQProvider {
public IQ parseIQ(XmlPullParser parser) throws Exception {
StringBuffer sb = new StringBuffer();
try {
int event = parser.getEventType();
// get the content
while (true) {
switch (event) {
case XmlPullParser.TEXT:
sb.append(parser.getText());
break;
case XmlPullParser.START_TAG:
sb.append('<' + parser.getName() + '>');
break;
case XmlPullParser.END_TAG:
sb.append("</" + parser.getName() + '>');
break;
default:
}
if (event == XmlPullParser.END_TAG && "vCard".equals(parser.getName())) break;
event = parser.next();
}
} catch (XmlPullParserException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
String xmlText = sb.toString();
VCard vCard = new VCard();
try {
DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
Document document = documentBuilder.parse(new ByteArrayInputStream(xmlText.getBytes()));
new VCardReader(vCard, document).initializeFields();
} catch (Exception e) {
e.printStackTrace(System.err);
}
return vCard;
}
private class VCardReader {
private final VCard vCard;
private final Document document;
VCardReader(VCard vCard, Document document) {
this.vCard = vCard;
this.document = document;
}
public void initializeFields() {
vCard.setFirstName(getTagContents("GIVEN"));
vCard.setLastName(getTagContents("FAMILY"));
vCard.setMiddleName(getTagContents("MIDDLE"));
setupEmails();
vCard.setOrganization(getTagContents("ORGNAME"));
vCard.setOrganizationUnit(getTagContents("ORGUNIT"));
setupSimpleFields();
setupPhones("WORK", true);
setupPhones("HOME", false);
setupAddress("WORK", true);
setupAddress("HOME", false);
}
private void setupEmails() {
NodeList nodes = document.getElementsByTagName("USERID");
for (int i = 0; i < nodes.getLength(); i++) {
Element element = (Element) nodes.item(i);
if ("WORK".equals(element.getParentNode().getFirstChild().getNodeName())) {
vCard.setEmailWork(getTextContent(element));
} else {
vCard.setEmailHome(getTextContent(element));
}
}
}
private void setupPhones(String type, boolean work) {
NodeList allPhones = document.getElementsByTagName("TEL");
for (int i = 0; i < allPhones.getLength(); i++) {
Element node = (Element) allPhones.item(i);
if (type.equals(node.getChildNodes().item(1).getNodeName())) {
String code = node.getFirstChild().getNodeName();
String value = getTextContent(node.getChildNodes().item(2));
if (work) {
vCard.setPhoneWork(code, value);
}
else {
vCard.setPhoneHome(code, value);
}
}
}
}
private void setupAddress(String type, boolean work) {
NodeList allAddresses = document.getElementsByTagName("ADR");
for (int i = 0; i < allAddresses.getLength(); i++) {
Element node = (Element) allAddresses.item(i);
NodeList childNodes = node.getChildNodes();
if (type.equals(childNodes.item(0).getNodeName())) {
for (int j = 1; j < childNodes.getLength(); j++) {
Node item = childNodes.item(j);
if (item instanceof Element) {
if (work) {
vCard.setAddressFieldWork(item.getNodeName(), getTextContent(item));
}
else {
vCard.setAddressFieldHome(item.getNodeName(), getTextContent(item));
}
}
}
}
}
}
private String getTagContents(String tag) {
NodeList nodes = document.getElementsByTagName(tag);
if (nodes.getLength() == 1) {
return getTextContent(nodes.item(0));
}
return null;
}
private void setupSimpleFields() {
NodeList childNodes = document.getDocumentElement().getChildNodes();
for (int i = 0; i < childNodes.getLength(); i++) {
Node node = childNodes.item(i);
if (node instanceof Element) {
Element element = (Element) node;
if ("FN".equals(element.getNodeName())) continue;
if (element.getChildNodes().getLength() == 0) {
vCard.setField(element.getNodeName(), "");
} else if (element.getChildNodes().getLength() == 1 &&
element.getChildNodes().item(0) instanceof Text) {
vCard.setField(element.getNodeName(), getTextContent(element));
}
}
}
}
private String getTextContent(Node node) {
StringBuffer result = new StringBuffer();
appendText(result, node);
return result.toString();
}
private void appendText(StringBuffer result, Node node) {
NodeList childNodes = node.getChildNodes();
for (int i = 0; i < childNodes.getLength(); i++) {
Node nd = childNodes.item(i);
String nodeValue = nd.getNodeValue();
if (nodeValue != null) {
result.append(nodeValue);
}
appendText(result, nd);
}
}
}
}

View file

@ -0,0 +1,78 @@
/**
* $RCSfile$
* $Revision$
* $Date$
*
* Copyright 2003-2004 Jive Software.
*
* All rights reserved. Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jivesoftware.smackx.provider;
import org.jivesoftware.smack.packet.PacketExtension;
import org.jivesoftware.smack.provider.PacketExtensionProvider;
import org.jivesoftware.smackx.packet.XHTMLExtension;
import org.xmlpull.v1.XmlPullParser;
/**
* The XHTMLExtensionProvider parses XHTML packets.
*
* @author Gaston Dombiak
*/
public class XHTMLExtensionProvider implements PacketExtensionProvider {
/**
* Creates a new XHTMLExtensionProvider.
* ProviderManager requires that every PacketExtensionProvider has a public, no-argument constructor
*/
public XHTMLExtensionProvider() {
}
/**
* Parses a XHTMLExtension packet (extension sub-packet).
*
* @param parser the XML parser, positioned at the starting element of the extension.
* @return a PacketExtension.
* @throws Exception if a parsing error occurs.
*/
public PacketExtension parseExtension(XmlPullParser parser)
throws Exception {
XHTMLExtension xhtmlExtension = new XHTMLExtension();
boolean done = false;
StringBuffer buffer = new StringBuffer();;
while (!done) {
int eventType = parser.next();
if (eventType == XmlPullParser.START_TAG) {
if (parser.getName().equals("body"))
buffer = new StringBuffer();
buffer.append(parser.getText());
} else if (eventType == XmlPullParser.TEXT) {
if (buffer != null) buffer.append(parser.getText());
} else if (eventType == XmlPullParser.END_TAG) {
if (parser.getName().equals("body")) {
buffer.append(parser.getText());
xhtmlExtension.addBody(buffer.toString());
}
else if (parser.getName().equals(xhtmlExtension.getElementName())) {
done = true;
}
else
buffer.append(parser.getText());
}
}
return xhtmlExtension;
}
}

View file

@ -0,0 +1 @@
<body>Provides pluggable parsing logic for Smack extensions.</body>