diff options
author | Alan Young <consult.awy@gmail.com> | 2014-11-13 06:42:37 (GMT) |
---|---|---|
committer | Alan Young <consult.awy@gmail.com> | 2015-04-10 06:50:58 (GMT) |
commit | 7d2101b93b6253c3ea15b663f7f3dc385cb21364 (patch) | |
tree | d81338baf0d117e83cdc07f882cbedd9471e834d /src/com/isode/stroke/serializer | |
parent | a20ca7ba40d837abe228462be0aba5d32d6831e3 (diff) | |
download | stroke-7d2101b93b6253c3ea15b663f7f3dc385cb21364.zip stroke-7d2101b93b6253c3ea15b663f7f3dc385cb21364.tar.bz2 |
Checkpoint - A bunch of initial stuff for Android
MemoryStorages, Storages
NickManager, NickResolver
CryptoProvider, Hash, SafeByteArray, JavaCryptoProvider
CapsInfoGenerator, CapsManager, CapsMemoryStorage, CapsProvider,
CapsStorage, CapsInfo
CapsInfoSerializer, CapsInfoParser
ClientDiscoManager, DiscoInfoResponder, EntityCapsManager,
EntityCapsProvider
GetDiscoInfoRequest
ChatState, Idle
Presence, PayloadAddingPresenceSender, PresenceOracle,
SubscriptionManager
StatusSerializer, StatusShowSerializer, StatusParser, StatusShowParser,
Replace, ReplaceParser, ReplaceSerializer
SecurityLabel, SecurityLabelsCatalog, GetSecurityLabelsCatalogRequest
VCard, GetVCardRequest, SetVCardRequest, VCardManager,
VCardMemoryStorage, VCardStorage
RosterMemoryStorage, RosterPushResponder, RosterStorage,
SetRosterRequest
XMPPRoster, XMPPRosterController, XMPPRosterImpl, XMPPRosterItem
GetRosterRequest, SetResponder
Add parsers and serializers for Idle, VCard, PrivateStorage & Stroage.
Add
parser for Subject.
Add impromptu flag to MUCInvitation.
Update copyrights.
Change-Id: I9949f506b70e60b3a64f1dadde8f9b235b322e1d
Diffstat (limited to 'src/com/isode/stroke/serializer')
12 files changed, 471 insertions, 29 deletions
diff --git a/src/com/isode/stroke/serializer/PresenceSerializer.java b/src/com/isode/stroke/serializer/PresenceSerializer.java index f5a2556..6611c8c 100644 --- a/src/com/isode/stroke/serializer/PresenceSerializer.java +++ b/src/com/isode/stroke/serializer/PresenceSerializer.java @@ -1,16 +1,11 @@ /* - * Copyright (c) 2010, Isode Limited, London, England. - * All rights reserved. - */ -/* - * Copyright (c) 2010, Remko Tronçon. + * Copyright (c) 2010-2015, Isode Limited, London, England. * All rights reserved. */ package com.isode.stroke.serializer; import com.isode.stroke.elements.Presence; -import com.isode.stroke.elements.Stanza; import com.isode.stroke.serializer.xml.XMLElement; public class PresenceSerializer extends GenericStanzaSerializer<Presence> { diff --git a/src/com/isode/stroke/serializer/payloadserializers/CapsInfoSerializer.java b/src/com/isode/stroke/serializer/payloadserializers/CapsInfoSerializer.java index b98a741..cfe1c25 100644 --- a/src/com/isode/stroke/serializer/payloadserializers/CapsInfoSerializer.java +++ b/src/com/isode/stroke/serializer/payloadserializers/CapsInfoSerializer.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010 Isode Limited. + * Copyright (c) 2010-2015 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ @@ -34,4 +34,4 @@ public class CapsInfoSerializer extends GenericPayloadSerializer<CapsInfo> { capsElement.setAttribute("ver", capsInfo.getVersion()); return capsElement.serialize(); } -}
\ No newline at end of file +} diff --git a/src/com/isode/stroke/serializer/payloadserializers/FullPayloadSerializerCollection.java b/src/com/isode/stroke/serializer/payloadserializers/FullPayloadSerializerCollection.java index 0b62e0f..f4caa29 100644 --- a/src/com/isode/stroke/serializer/payloadserializers/FullPayloadSerializerCollection.java +++ b/src/com/isode/stroke/serializer/payloadserializers/FullPayloadSerializerCollection.java @@ -1,9 +1,5 @@ /* - * Copyright (c) 2010-2012, Isode Limited, London, England. - * All rights reserved. - */ -/* - * Copyright (c) 2010, Remko Tronçon. + * Copyright (c) 2010-2015, Isode Limited, London, England. * All rights reserved. */ package com.isode.stroke.serializer.payloadserializers; @@ -34,8 +30,8 @@ public class FullPayloadSerializerCollection extends PayloadSerializerCollection addSerializer(new MUCOwnerPayloadSerializer(this)); addSerializer(new MUCUserPayloadSerializer(this)); addSerializer(new SoftwareVersionSerializer()); - //addSerializer(new StatusSerializer()); - //addSerializer(new StatusShowSerializer()); + addSerializer(new StatusSerializer()); + addSerializer(new StatusShowSerializer()); addSerializer(new DiscoInfoSerializer()); addSerializer(new DiscoItemsSerializer()); addSerializer(new CapsInfoSerializer()); @@ -45,17 +41,19 @@ public class FullPayloadSerializerCollection extends PayloadSerializerCollection //addSerializer(new SecurityLabelsCatalogSerializer()); //addSerializer(new StreamInitiationSerializer()); //addSerializer(new BytestreamsSerializer()); - //addSerializer(new VCardSerializer()); + addSerializer(new VCardSerializer()); //addSerializer(new VCardUpdateSerializer()); addSerializer(new RawXMLPayloadSerializer()); - //addSerializer(new StorageSerializer()); + addSerializer(new StorageSerializer()); addSerializer(new DelaySerializer()); addSerializer(new FormSerializer()); - //addSerializer(new PrivateStorageSerializer(this)); + addSerializer(new PrivateStorageSerializer(this)); addSerializer(new CommandSerializer()); //addSerializer(new NicknameSerializer()); addSerializer(new SearchPayloadSerializer()); + addSerializer(new ReplaceSerializer()); addSerializer(new LastSerializer()); + addSerializer(new IdleSerializer()); addSerializer(new PubSubSerializer(this)); addSerializer(new PubSubEventSerializer(this)); diff --git a/src/com/isode/stroke/serializer/payloadserializers/IdleSerializer.java b/src/com/isode/stroke/serializer/payloadserializers/IdleSerializer.java new file mode 100644 index 0000000..6d1ae93 --- /dev/null +++ b/src/com/isode/stroke/serializer/payloadserializers/IdleSerializer.java @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2015 Isode Limited, London, England. + * All rights reserved. + */ +/* + * Copyright (c) 2013 Tobias Markmann + * Licensed under the simplified BSD license. + * See Documentation/Licenses/BSD-simplified.txt for more information. + */ + +package com.isode.stroke.serializer.payloadserializers; + +import com.isode.stroke.base.DateTime; +import com.isode.stroke.elements.Idle; +import com.isode.stroke.serializer.GenericPayloadSerializer; + +public class IdleSerializer extends GenericPayloadSerializer<Idle> { + + public IdleSerializer() { + super(Idle.class); + } + + @Override + protected String serializePayload(Idle idle) { + return "<idle xmlns='urn:xmpp:idle:1' since='" + DateTime.dateToString(idle.getSince()) + "'/>"; + } +} diff --git a/src/com/isode/stroke/serializer/payloadserializers/MUCInvitationPayloadSerializer.java b/src/com/isode/stroke/serializer/payloadserializers/MUCInvitationPayloadSerializer.java index e149aa7..3281b0e 100644 --- a/src/com/isode/stroke/serializer/payloadserializers/MUCInvitationPayloadSerializer.java +++ b/src/com/isode/stroke/serializer/payloadserializers/MUCInvitationPayloadSerializer.java @@ -1,9 +1,5 @@ /* - * Copyright (c) 2012, Isode Limited, London, England. - * All rights reserved. - */ -/* - * Copyright (c) 2011, Kevin Smith + * Copyright (c) 2011-2015, Isode Limited, London, England. * All rights reserved. */ package com.isode.stroke.serializer.payloadserializers; @@ -41,6 +37,9 @@ public class MUCInvitationPayloadSerializer extends GenericPayloadSerializer<MUC if (payload.getThread() != null && !payload.getThread().isEmpty()) { mucElement.setAttribute("thread", payload.getThread()); } + if (payload.getIsImpromptu()) { + mucElement.addNode(new XMLElement("impromptu", "http://swift.im/impromptu")); + } return mucElement.serialize(); } } diff --git a/src/com/isode/stroke/serializer/payloadserializers/PrivateStorageSerializer.java b/src/com/isode/stroke/serializer/payloadserializers/PrivateStorageSerializer.java new file mode 100644 index 0000000..c863f71 --- /dev/null +++ b/src/com/isode/stroke/serializer/payloadserializers/PrivateStorageSerializer.java @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2010-2015, Isode Limited, London, England. + * All rights reserved. + */ + +package com.isode.stroke.serializer.payloadserializers; + +import com.isode.stroke.elements.Payload; +import com.isode.stroke.elements.PrivateStorage; +import com.isode.stroke.serializer.GenericPayloadSerializer; +import com.isode.stroke.serializer.PayloadSerializer; +import com.isode.stroke.serializer.PayloadSerializerCollection; +import com.isode.stroke.serializer.xml.XMLElement; +import com.isode.stroke.serializer.xml.XMLRawTextNode; + +class PrivateStorageSerializer extends GenericPayloadSerializer<PrivateStorage>{ + + private final PayloadSerializerCollection serializers; + + public PrivateStorageSerializer(PayloadSerializerCollection serializers) { + super(PrivateStorage.class); + this.serializers = serializers; + } + + + @Override + protected String serializePayload(PrivateStorage storage) { + XMLElement storageElement = new XMLElement("query", "jabber:iq:private"); + Payload payload = storage.getPayload(); + if (payload != null) { + PayloadSerializer serializer = serializers.getPayloadSerializer(payload); + if (serializer != null) { + storageElement.addNode(new XMLRawTextNode(serializer.serialize(payload))); + } + } + return storageElement.serialize(); + } + +} diff --git a/src/com/isode/stroke/serializer/payloadserializers/ReplaceSerializer.java b/src/com/isode/stroke/serializer/payloadserializers/ReplaceSerializer.java new file mode 100644 index 0000000..b6b49e2 --- /dev/null +++ b/src/com/isode/stroke/serializer/payloadserializers/ReplaceSerializer.java @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2012-2015, Isode Limited, London, England. + * All rights reserved. + */ +/* + * Copyright (c) 2011 Vlad Voicu + * Licensed under the Simplified BSD license. + * See Documentation/Licenses/BSD-simplified.txt for more information. + */ +package com.isode.stroke.serializer.payloadserializers; + +import com.isode.stroke.elements.Replace; +import com.isode.stroke.serializer.GenericPayloadSerializer; + +public class ReplaceSerializer extends GenericPayloadSerializer<Replace> { + + public ReplaceSerializer() { + super(Replace.class); + } + + protected String serializePayload(Replace replace) { + return "<replace id = '" + replace.getID() + "' xmlns='urn:xmpp:message-correct:0'/>"; + } + +} diff --git a/src/com/isode/stroke/serializer/payloadserializers/StatusSerializer.java b/src/com/isode/stroke/serializer/payloadserializers/StatusSerializer.java new file mode 100644 index 0000000..6a9bb23 --- /dev/null +++ b/src/com/isode/stroke/serializer/payloadserializers/StatusSerializer.java @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2010-2015, Isode Limited, London, England. + * All rights reserved. + */ +package com.isode.stroke.serializer.payloadserializers; + +import com.isode.stroke.elements.Status; +import com.isode.stroke.serializer.GenericPayloadSerializer; +import com.isode.stroke.serializer.xml.XMLElement; +import com.isode.stroke.serializer.xml.XMLTextNode; + +public class StatusSerializer extends GenericPayloadSerializer<Status> { + + public StatusSerializer() { + super(Status.class); + } + + protected String serializePayload(Status status) { + XMLElement element = new XMLElement("status"); + element.addNode(new XMLTextNode(status.getText())); + return element.serialize(); + } +} diff --git a/src/com/isode/stroke/serializer/payloadserializers/StatusShowSerializer.java b/src/com/isode/stroke/serializer/payloadserializers/StatusShowSerializer.java new file mode 100644 index 0000000..e7cb587 --- /dev/null +++ b/src/com/isode/stroke/serializer/payloadserializers/StatusShowSerializer.java @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2010-2015, Isode Limited, London, England. + * All rights reserved. + */ +package com.isode.stroke.serializer.payloadserializers; + +import com.isode.stroke.elements.StatusShow; +import com.isode.stroke.serializer.GenericPayloadSerializer; + +public class StatusShowSerializer extends GenericPayloadSerializer<StatusShow> { + + public StatusShowSerializer() { + super(StatusShow.class); + } + + protected String serializePayload(StatusShow statusShow) { + if (statusShow.getType () == StatusShow.Type.Online || statusShow.getType() == StatusShow.Type.None) { + return ""; + } + else { + String result = "<show>"; + switch (statusShow.getType()) { + case Away: result += "away"; break; + case XA: result += "xa"; break; + case FFC: result += "chat"; break; + case DND: result += "dnd"; break; + case Online: assert(false); break; + case None: assert(false); break; + } + result += "</show>"; + return result; + } + } + +} diff --git a/src/com/isode/stroke/serializer/payloadserializers/StorageSerializer.java b/src/com/isode/stroke/serializer/payloadserializers/StorageSerializer.java new file mode 100644 index 0000000..2a072ad --- /dev/null +++ b/src/com/isode/stroke/serializer/payloadserializers/StorageSerializer.java @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2010-2015, Isode Limited, London, England. + * All rights reserved. + */ + +package com.isode.stroke.serializer.payloadserializers; + +import com.isode.stroke.elements.Storage; +import com.isode.stroke.serializer.GenericPayloadSerializer; +import com.isode.stroke.serializer.xml.XMLElement; +import com.isode.stroke.serializer.xml.XMLTextNode; + +class StorageSerializer extends GenericPayloadSerializer<Storage>{ + + public StorageSerializer() { + super(Storage.class); + } + + @Override + protected String serializePayload(Storage storage) { + XMLElement storageElement = new XMLElement("storage", "storage:bookmarks"); + + for (final Storage.Room room : storage.getRooms()) { + XMLElement conferenceElement = new XMLElement("conference"); + conferenceElement.setAttribute("name", room.name); + conferenceElement.setAttribute("jid", room.jid.toString()); + conferenceElement.setAttribute("autojoin", room.autoJoin ? "1" : "0"); + if (room.nick != null && !room.nick.isEmpty()) { + XMLElement nickElement = new XMLElement("nick"); + nickElement.addNode(new XMLTextNode(room.nick)); + conferenceElement.addNode(nickElement); + } + if (room.password != null) { + XMLElement passwordElement = new XMLElement("password"); + passwordElement.addNode(new XMLTextNode(room.password)); + conferenceElement.addNode(passwordElement); + } + storageElement.addNode(conferenceElement); + } + + for (final Storage.URL url : storage.getURLs()) { + XMLElement urlElement = new XMLElement("url"); + urlElement.setAttribute("name", url.name); + urlElement.setAttribute("url", url.url); + storageElement.addNode(urlElement); + } + + return storageElement.serialize(); + } + +} diff --git a/src/com/isode/stroke/serializer/payloadserializers/VCardSerializer.java b/src/com/isode/stroke/serializer/payloadserializers/VCardSerializer.java new file mode 100644 index 0000000..8a98f46 --- /dev/null +++ b/src/com/isode/stroke/serializer/payloadserializers/VCardSerializer.java @@ -0,0 +1,254 @@ +/* + * Copyright (c) 2010-2015, Isode Limited, London, England. + * All rights reserved. + */ + +package com.isode.stroke.serializer.payloadserializers; + +import com.isode.stroke.base.DateTime; +import com.isode.stroke.elements.VCard; +import com.isode.stroke.jid.JID; +import com.isode.stroke.serializer.GenericPayloadSerializer; +import com.isode.stroke.serializer.xml.XMLElement; +import com.isode.stroke.serializer.xml.XMLRawTextNode; +import com.isode.stroke.stringcodecs.Base64; + +class VCardSerializer extends GenericPayloadSerializer<VCard>{ + + public VCardSerializer() { + super(VCard.class); + } + + @Override + protected String serializePayload(VCard vcard) { + XMLElement queryElement = new XMLElement("vCard", "vcard-temp"); + if (vcard.getVersion() != null && !vcard.getVersion().isEmpty()) { + queryElement.addNode(new XMLElement("VERSION", "", vcard.getVersion())); + } + if (vcard.getFullName() != null && !vcard.getFullName().isEmpty()) { + queryElement.addNode(new XMLElement("FN", "", vcard.getFullName())); + } + if (vcard.getGivenName() != null && !vcard.getGivenName().isEmpty() + || vcard.getFamilyName() != null && !vcard.getFamilyName().isEmpty() + || vcard.getMiddleName() != null && !vcard.getMiddleName().isEmpty() + || vcard.getPrefix() != null && !vcard.getPrefix().isEmpty() + || vcard.getSuffix() != null && !vcard.getSuffix().isEmpty()) { + XMLElement nameElement = new XMLElement("N"); + if (vcard.getFamilyName() != null && !vcard.getFamilyName().isEmpty()) { + nameElement.addNode(new XMLElement("FAMILY", "", vcard.getFamilyName())); + } + if (vcard.getGivenName() != null && !vcard.getGivenName().isEmpty()) { + nameElement.addNode(new XMLElement("GIVEN", "", vcard.getGivenName())); + } + if (vcard.getMiddleName() != null && !vcard.getMiddleName().isEmpty()) { + nameElement.addNode(new XMLElement("MIDDLE", "", vcard.getMiddleName())); + } + if (vcard.getPrefix() != null && !vcard.getPrefix().isEmpty()) { + nameElement.addNode(new XMLElement("PREFIX", "", vcard.getPrefix())); + } + if (vcard.getSuffix() != null && !vcard.getSuffix().isEmpty()) { + nameElement.addNode(new XMLElement("SUFFIX", "", vcard.getSuffix())); + } + queryElement.addNode(nameElement); + } + if (vcard.getEMailAddresses() != null) for (final VCard.EMailAddress emailAddress : vcard.getEMailAddresses()) { + XMLElement emailElement = new XMLElement("EMAIL"); + emailElement.addNode(new XMLElement("USERID", "", emailAddress.address)); + if (emailAddress.isHome) { + emailElement.addNode(new XMLElement("HOME")); + } + if (emailAddress.isWork) { + emailElement.addNode(new XMLElement("WORK")); + } + if (emailAddress.isInternet) { + emailElement.addNode(new XMLElement("INTERNET")); + } + if (emailAddress.isPreferred) { + emailElement.addNode(new XMLElement("PREF")); + } + if (emailAddress.isX400) { + emailElement.addNode(new XMLElement("X400")); + } + queryElement.addNode(emailElement); + } + if (vcard.getNickname() != null && !vcard.getNickname().isEmpty()) { + queryElement.addNode(new XMLElement("NICKNAME", "", vcard.getNickname())); + } + if (vcard.getPhoto() != null && !vcard.getPhoto().isEmpty() || vcard.getPhotoType() != null && !vcard.getPhotoType().isEmpty()) { + XMLElement photoElement = new XMLElement("PHOTO"); + if (vcard.getPhotoType() != null && !vcard.getPhotoType().isEmpty()) { + photoElement.addNode(new XMLElement("TYPE", "", vcard.getPhotoType())); + } + if (vcard.getPhoto() != null && !vcard.getPhoto().isEmpty()) { + photoElement.addNode(new XMLElement("BINVAL", "", Base64.encode(vcard.getPhoto()))); + } + queryElement.addNode(photoElement); + } + if (vcard.getBirthday() != null) { + queryElement.addNode(new XMLElement("BDAY", "", DateTime.dateToString(vcard.getBirthday()))); + } + + if (vcard.getTelephones() != null) for (final VCard.Telephone telephone : vcard.getTelephones()) { + XMLElement telElement = new XMLElement("TEL"); + telElement.addNode(new XMLElement("NUMBER", "", telephone.number)); + if (telephone.isHome) { + telElement.addNode(new XMLElement("HOME")); + } + if (telephone.isWork) { + telElement.addNode(new XMLElement("WORK")); + } + if (telephone.isVoice) { + telElement.addNode(new XMLElement("VOICE")); + } + if (telephone.isFax) { + telElement.addNode(new XMLElement("FAX")); + } + if (telephone.isPager) { + telElement.addNode(new XMLElement("PAGER")); + } + if (telephone.isMSG) { + telElement.addNode(new XMLElement("MSG")); + } + if (telephone.isCell) { + telElement.addNode(new XMLElement("CELL")); + } + if (telephone.isVideo) { + telElement.addNode(new XMLElement("VIDEO")); + } + if (telephone.isBBS) { + telElement.addNode(new XMLElement("BBS")); + } + if (telephone.isModem) { + telElement.addNode(new XMLElement("MODEM")); + } + if (telephone.isISDN) { + telElement.addNode(new XMLElement("ISDN")); + } + if (telephone.isPCS) { + telElement.addNode(new XMLElement("PCS")); + } + if (telephone.isPreferred) { + telElement.addNode(new XMLElement("PREF")); + } + queryElement.addNode(telElement); + } + + if (vcard.getAddresses() != null) for (final VCard.Address address : vcard.getAddresses()) { + XMLElement adrElement = new XMLElement("ADR"); + if (!address.poBox.isEmpty()) { + adrElement.addNode(new XMLElement("POBOX", "", address.poBox)); + } + if (!address.addressExtension.isEmpty()) { + adrElement.addNode(new XMLElement("EXTADD", "", address.addressExtension)); + } + if (!address.street.isEmpty()) { + adrElement.addNode(new XMLElement("STREET", "", address.street)); + } + if (!address.locality.isEmpty()) { + adrElement.addNode(new XMLElement("LOCALITY", "", address.locality)); + } + if (!address.region.isEmpty()) { + adrElement.addNode(new XMLElement("REGION", "", address.region)); + } + if (!address.postalCode.isEmpty()) { + adrElement.addNode(new XMLElement("PCODE", "", address.postalCode)); + } + if (!address.country.isEmpty()) { + adrElement.addNode(new XMLElement("CTRY", "", address.country)); + } + + if (address.isHome) { + adrElement.addNode(new XMLElement("HOME")); + } + if (address.isWork) { + adrElement.addNode(new XMLElement("WORK")); + } + if (address.isPostal) { + adrElement.addNode(new XMLElement("POSTAL")); + } + if (address.isParcel) { + adrElement.addNode(new XMLElement("PARCEL")); + } + if (address.deliveryType == VCard.DeliveryType.DomesticDelivery) { + adrElement.addNode(new XMLElement("DOM")); + } + if (address.deliveryType == VCard.DeliveryType.InternationalDelivery) { + adrElement.addNode(new XMLElement("INTL")); + } + if (address.isPreferred) { + adrElement.addNode(new XMLElement("PREF")); + } + queryElement.addNode(adrElement); + } + + if (vcard.getAddressLabels() != null) for (final VCard.AddressLabel addressLabel : vcard.getAddressLabels()) { + XMLElement labelElement = new XMLElement("LABEL"); + + for (final String line : addressLabel.lines) { + labelElement.addNode(new XMLElement("LINE", "", line)); + } + + if (addressLabel.isHome) { + labelElement.addNode(new XMLElement("HOME")); + } + if (addressLabel.isWork) { + labelElement.addNode(new XMLElement("WORK")); + } + if (addressLabel.isPostal) { + labelElement.addNode(new XMLElement("POSTAL")); + } + if (addressLabel.isParcel) { + labelElement.addNode(new XMLElement("PARCEL")); + } + if (addressLabel.deliveryType == VCard.DeliveryType.DomesticDelivery) { + labelElement.addNode(new XMLElement("DOM")); + } + if (addressLabel.deliveryType == VCard.DeliveryType.InternationalDelivery) { + labelElement.addNode(new XMLElement("INTL")); + } + if (addressLabel.isPreferred) { + labelElement.addNode(new XMLElement("PREF")); + } + queryElement.addNode(labelElement); + } + + if (vcard.getJIDs() != null) for (final JID jid : vcard.getJIDs()) { + queryElement.addNode(new XMLElement("JID", "", jid.toString())); + } + + if (vcard.getDescription() != null && !vcard.getDescription().isEmpty()) { + queryElement.addNode(new XMLElement("DESC", "", vcard.getDescription())); + } + + if (vcard.getOrganizations() != null) for (final VCard.Organization org : vcard.getOrganizations()) { + XMLElement orgElement = new XMLElement("ORG"); + if (!org.name.isEmpty()) { + orgElement.addNode(new XMLElement("ORGNAME", "", org.name)); + } + if (!org.units.isEmpty()) { + for (final String unit : org.units) { + orgElement.addNode(new XMLElement("ORGUNIT", "", unit)); + } + } + queryElement.addNode(orgElement); + } + + if (vcard.getTitles() != null) for (final String title : vcard.getTitles()) { + queryElement.addNode(new XMLElement("TITLE", "", title)); + } + + if (vcard.getRoles() != null) for (final String role : vcard.getRoles()) { + queryElement.addNode(new XMLElement("ROLE", "", role)); + } + + if (vcard.getURLs() != null) for (final String url : vcard.getURLs()) { + queryElement.addNode(new XMLElement("URL", "", url)); + } + + if (vcard.getUnknownContent() != null && !vcard.getUnknownContent().isEmpty()) { + queryElement.addNode(new XMLRawTextNode(vcard.getUnknownContent())); + } + return queryElement.serialize(); + } + +} diff --git a/src/com/isode/stroke/serializer/xml/XMLTextNode.java b/src/com/isode/stroke/serializer/xml/XMLTextNode.java index fa1881e..da1b03f 100644 --- a/src/com/isode/stroke/serializer/xml/XMLTextNode.java +++ b/src/com/isode/stroke/serializer/xml/XMLTextNode.java @@ -1,9 +1,5 @@ /* - * Copyright (c) 2010-2012, Isode Limited, London, England. - * All rights reserved. - */ -/* - * Copyright (c) 2010, Remko Tronçon. + * Copyright (c) 2010-2015, Isode Limited, London, England. * All rights reserved. */ package com.isode.stroke.serializer.xml; @@ -13,7 +9,7 @@ public class XMLTextNode implements XMLNode { private String text_; public XMLTextNode(String text) { - text_ = text; + text_ = text != null ? text : ""; text_ = text_.replaceAll("&", "&"); // Should come first text_ = text_.replaceAll("<", "<"); text_ = text_.replaceAll(">", ">"); |