Commit 93a98040 authored by Grigory Fedorov's avatar Grigory Fedorov

VCardManager rewritten to use Smack methods to get vCards.

 Unused code from xmpp/vcard removed.
parent 1866beba
...@@ -476,7 +476,7 @@ public class AvatarManager implements OnLoadListener, OnLowMemoryListener, OnPac ...@@ -476,7 +476,7 @@ public class AvatarManager implements OnLoadListener, OnLowMemoryListener, OnPac
String hash, byte[] value, Bitmap bitmap) { String hash, byte[] value, Bitmap bitmap) {
if (value == null) { if (value == null) {
if (SettingsManager.connectionLoadVCard()) { if (SettingsManager.connectionLoadVCard()) {
VCardManager.getInstance().request(account, bareAddress, hash); VCardManager.getInstance().request(account, bareAddress);
} }
} else { } else {
bitmaps.put(hash, bitmap == null ? EMPTY_BITMAP : bitmap); bitmaps.put(hash, bitmap == null ? EMPTY_BITMAP : bitmap);
......
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
package com.xabber.android.data.extension.vcard; package com.xabber.android.data.extension.vcard;
import com.xabber.android.data.BaseUIListener; import com.xabber.android.data.BaseUIListener;
import com.xabber.xmpp.vcard.VCard; import org.jivesoftware.smackx.vcardtemp.packet.VCard;
/** /**
* Listener for vCard to be received. * Listener for vCard to be received.
......
/**
* Copyright (c) 2013, Redsolution LTD. All rights reserved.
*
* This file is part of Xabber project; you can redistribute it and/or
* modify it under the terms of the GNU General Public License, Version 3.
*
* Xabber is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License,
* along with this program. If not, see http://www.gnu.org/licenses/.
*/
package com.xabber.android.data.extension.vcard;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import com.xabber.android.data.entity.BaseEntity;
/**
* Store information about vCard request for specified user.
*
* @author alexander.ivanov
*/
class VCardRequest extends BaseEntity {
private final String packetId;
/**
* List of intent avatar's hashes.
*/
private final HashSet<String> hashes;
public VCardRequest(String account, String bareAddress, String packetId) {
super(account, bareAddress);
this.packetId = packetId;
this.hashes = new HashSet<String>();
}
public String getPacketId() {
return packetId;
}
public Collection<String> getHashes() {
return Collections.unmodifiableCollection(hashes);
}
public void addHash(String hash) {
hashes.add(hash);
}
}
\ No newline at end of file
...@@ -1055,7 +1055,7 @@ public class SyncManager implements OnLoadListener, OnUnloadListener, ...@@ -1055,7 +1055,7 @@ public class SyncManager implements OnLoadListener, OnUnloadListener,
nickNamesForContacts.put(rosterContact, nickNamesForContacts.put(rosterContact,
rosterContact.getRealName()); rosterContact.getRealName());
StructuredName structuredName = VCardManager.getInstance() StructuredName structuredName = VCardManager.getInstance()
.getStructucedName(rosterContact.getUser()); .getStructuredName(rosterContact.getUser());
if (structuredName != null) if (structuredName != null)
structuredNamesForContacts.put(rosterContact, structuredNamesForContacts.put(rosterContact,
structuredName); structuredName);
......
/**
* Copyright (c) 2013, Redsolution LTD. All rights reserved.
*
* This file is part of Xabber project; you can redistribute it and/or
* modify it under the terms of the GNU General Public License, Version 3.
*
* Xabber is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License,
* along with this program. If not, see http://www.gnu.org/licenses/.
*/
package com.xabber.xmpp.vcard;
import com.xabber.xmpp.SerializerUtils;
import org.jivesoftware.smack.util.stringencoder.Base64;
import org.xmlpull.v1.XmlSerializer;
import java.io.IOException;
public abstract class AbstractBinaryData extends AbstractData {
/**
* Limit received encoded data size.
*/
public static final int MAX_ENCODED_DATA_SIZE = 256 * 1024;
public static final String TYPE_NAME = "TYPE";
public static final String BINVAL_NAME = "BINVAL";
private String type;
private byte[] data;
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public byte[] getData() {
return data;
}
public void setData(byte[] data) {
this.data = data;
}
@Override
public boolean isValid() {
return type != null && data != null;
}
@Override
protected void writeBody(XmlSerializer serializer) throws IOException {
SerializerUtils.addTextTag(serializer, TYPE_NAME, type);
SerializerUtils.addTextTag(serializer, BINVAL_NAME, Base64.encodeToString(data));
}
}
/**
* Copyright (c) 2013, Redsolution LTD. All rights reserved.
*
* This file is part of Xabber project; you can redistribute it and/or
* modify it under the terms of the GNU General Public License, Version 3.
*
* Xabber is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License,
* along with this program. If not, see http://www.gnu.org/licenses/.
*/
package com.xabber.xmpp.vcard;
import java.io.IOException;
import org.xmlpull.v1.XmlSerializer;
import com.xabber.xmpp.Instance;
public abstract class AbstractData implements Instance {
@Override
public void serialize(XmlSerializer serializer) throws IOException {
serializer.startTag(null, getElementName());
writeBody(serializer);
serializer.endTag(null, getElementName());
}
public abstract String getElementName();
protected abstract void writeBody(XmlSerializer serializer)
throws IOException;
}
/**
* Copyright (c) 2013, Redsolution LTD. All rights reserved.
*
* This file is part of Xabber project; you can redistribute it and/or
* modify it under the terms of the GNU General Public License, Version 3.
*
* Xabber is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License,
* along with this program. If not, see http://www.gnu.org/licenses/.
*/
package com.xabber.xmpp.vcard;
import com.xabber.xmpp.AbstractProvider;
import com.xabber.xmpp.Instance;
import com.xabber.xmpp.ProviderUtils;
import org.jivesoftware.smack.util.stringencoder.Base64;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
import java.io.IOException;
abstract class AbstractDataProvider<T extends Instance, Inner extends DataHolder<T>>
extends AbstractProvider<Inner> {
@Override
protected boolean parseInner(XmlPullParser parser, Inner instance) throws IOException, XmlPullParserException {
if (super.parseInner(parser, instance))
return true;
if (instance.getPayload() == null)
if (!createPayload(parser, instance))
return false;
return inflatePayload(parser, instance);
}
protected boolean createPayload(XmlPullParser parser, Inner instance) {
if (AbstractBinaryData.TYPE_NAME.equals(parser.getName())
|| AbstractBinaryData.BINVAL_NAME.equals(parser.getName()))
instance.setPayload(createBinaryData());
else if (AbstractExternalData.EXTVAL_NAME.equals(parser.getName()))
instance.setPayload(createExternalData());
else
return false;
return true;
}
protected abstract T createBinaryData();
protected abstract T createExternalData();
protected boolean inflatePayload(XmlPullParser parser, Inner instance) throws IOException, XmlPullParserException {
if (instance.getPayload() instanceof AbstractBinaryData)
return inflateBinaryData(parser,
(AbstractBinaryData) instance.getPayload());
else if (instance.getPayload() instanceof AbstractExternalData)
return inflateExternalData(parser,
(AbstractExternalData) instance.getPayload());
else
return false;
}
protected boolean inflateBinaryData(XmlPullParser parser, AbstractBinaryData payload) throws IOException, XmlPullParserException {
if (AbstractBinaryData.TYPE_NAME.equals(parser.getName()))
payload.setType(ProviderUtils.parseText(parser));
else if (AbstractBinaryData.BINVAL_NAME.equals(parser.getName())) {
String value;
try {
value = ProviderUtils.parseText(parser,
AbstractBinaryData.MAX_ENCODED_DATA_SIZE);
} catch (Exception e) {
return true;
}
payload.setData(Base64.decode(value));
} else
return false;
return true;
}
protected boolean inflateExternalData(XmlPullParser parser, AbstractExternalData payload) throws IOException, XmlPullParserException {
if (AbstractExternalData.EXTVAL_NAME.equals(parser.getName()))
payload.setValue(ProviderUtils.parseText(parser));
else
return false;
return true;
}
}
\ No newline at end of file
/**
* Copyright (c) 2013, Redsolution LTD. All rights reserved.
*
* This file is part of Xabber project; you can redistribute it and/or
* modify it under the terms of the GNU General Public License, Version 3.
*
* Xabber is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License,
* along with this program. If not, see http://www.gnu.org/licenses/.
*/
package com.xabber.xmpp.vcard;
import java.io.IOException;
import org.xmlpull.v1.XmlSerializer;
import com.xabber.xmpp.SerializerUtils;
public abstract class AbstractExternalData extends AbstractData {
public static final String EXTVAL_NAME = "EXTVAL";
private String value;
public String getValue() {
return value;
}
public void setValue(String value) {
this.value = value;
}
@Override
public boolean isValid() {
return value != null;
}
@Override
protected void writeBody(XmlSerializer serializer) throws IOException {
SerializerUtils.addTextTag(serializer, EXTVAL_NAME, value);
}
}
/**
* Copyright (c) 2013, Redsolution LTD. All rights reserved.
*
* This file is part of Xabber project; you can redistribute it and/or
* modify it under the terms of the GNU General Public License, Version 3.
*
* Xabber is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License,
* along with this program. If not, see http://www.gnu.org/licenses/.
*/
package com.xabber.xmpp.vcard;
import java.io.IOException;
import java.util.HashSet;
import java.util.Set;
import org.xmlpull.v1.XmlSerializer;
import com.xabber.xmpp.Instance;
public abstract class AbstractTypedData<Type extends Enum<?>> implements
Instance {
protected final Set<Type> types;
public AbstractTypedData() {
types = new HashSet<Type>();
}
@Override
public void serialize(XmlSerializer serializer) throws IOException {
serializer.startTag(null, getElementName());
for (Type type : types) {
serializer.startTag(null, type.toString());
serializer.endTag(null, type.toString());
}
writeBody(serializer);
serializer.endTag(null, getElementName());
}
protected abstract String getElementName();
protected abstract void writeBody(XmlSerializer serializer)
throws IOException;
public Set<Type> getTypes() {
return types;
}
}
/**
* Copyright (c) 2013, Redsolution LTD. All rights reserved.
*
* This file is part of Xabber project; you can redistribute it and/or
* modify it under the terms of the GNU General Public License, Version 3.
*
* Xabber is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License,
* along with this program. If not, see http://www.gnu.org/licenses/.
*/
package com.xabber.xmpp.vcard;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
import com.xabber.xmpp.AbstractProvider;
import com.xabber.xmpp.ProviderUtils;
import java.io.IOException;
abstract class AbstractTypedDataProvider<Type extends Enum<?>, Instance extends AbstractTypedData<Type>>
extends AbstractProvider<Instance> {
@Override
protected boolean parseInner(XmlPullParser parser, Instance instance) throws IOException, XmlPullParserException {
if (super.parseInner(parser, instance))
return true;
String name = parser.getName();
for (Type type : getTypes())
if (type.toString().equals(name)) {
instance.getTypes().add(type);
ProviderUtils.skipTag(parser);
return true;
}
return false;
}
protected abstract Type[] getTypes();
}
/**
* Copyright (c) 2013, Redsolution LTD. All rights reserved.
*
* This file is part of Xabber project; you can redistribute it and/or
* modify it under the terms of the GNU General Public License, Version 3.
*
* Xabber is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License,
* along with this program. If not, see http://www.gnu.org/licenses/.
*/
package com.xabber.xmpp.vcard;
import java.io.IOException;
import org.xmlpull.v1.XmlSerializer;
import com.xabber.xmpp.SerializerUtils;
public abstract class AbstractTypedDataWithValue<Type extends Enum<?>> extends
AbstractTypedData<Type> {
private String value;
public AbstractTypedDataWithValue() {
super();
}
public String getValue() {
return value;
}
public void setValue(String value) {
this.value = value;
}
protected abstract String getValueName();
@Override
protected void writeBody(XmlSerializer serializer) throws IOException {
SerializerUtils.addTextTag(serializer, getValueName(), value);
}
@Override
public boolean isValid() {
return value != null;
}
}
/**
* Copyright (c) 2013, Redsolution LTD. All rights reserved.
*
* This file is part of Xabber project; you can redistribute it and/or
* modify it under the terms of the GNU General Public License, Version 3.
*
* Xabber is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License,
* along with this program. If not, see http://www.gnu.org/licenses/.
*/
package com.xabber.xmpp.vcard;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
import com.xabber.xmpp.ProviderUtils;
import java.io.IOException;
public abstract class AbstractTypedDataWithValueProvider<Type extends Enum<?>, Instance extends AbstractTypedDataWithValue<Type>>
extends AbstractTypedDataProvider<Type, Instance> {
@Override
protected boolean parseInner(XmlPullParser parser, Instance instance) throws IOException, XmlPullParserException {
if (super.parseInner(parser, instance))
return true;
if (getValueName().equals(parser.getName())) {
instance.setValue(ProviderUtils.parseText(parser));
return true;
}
return false;
}
protected abstract String getValueName();
}
/**
* Copyright (c) 2013, Redsolution LTD. All rights reserved.
*
* This file is part of Xabber project; you can redistribute it and/or
* modify it under the terms of the GNU General Public License, Version 3.
*
* Xabber is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License,
* along with this program. If not, see http://www.gnu.org/licenses/.
*/
package com.xabber.xmpp.vcard;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
import org.xmlpull.v1.XmlSerializer;
import com.xabber.xmpp.SerializerUtils;
public class Address extends AbstractTypedData<AddressType> {
public static final String ELEMENT_NAME = "ADR";
protected final Map<AddressProperty, String> properties;
public Address() {
super();
properties = new HashMap<AddressProperty, String>();
}
public Map<AddressProperty, String> getProperties() {
return properties;
}
@Override
protected String getElementName() {
return ELEMENT_NAME;
}
@Override
protected void writeBody(XmlSerializer serializer) throws IOException {
for (Entry<AddressProperty, String> entry : properties.entrySet())
SerializerUtils.addTextTag(serializer, entry.getKey().toString(),
entry.getValue());
}
@Override
public boolean isValid() {
return AddressType.isValid(types);
}
}
/**
* Copyright (c) 2013, Redsolution LTD. All rights reserved.
*
* This file is part of Xabber project; you can redistribute it and/or
* modify it under the terms of the GNU General Public License, Version 3.
*
* Xabber is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License,
* along with this program. If not, see http://www.gnu.org/licenses/.
*/
package com.xabber.xmpp.vcard;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
import com.xabber.xmpp.ProviderUtils;
import java.io.IOException;
class AddressProvider extends AbstractTypedDataProvider<AddressType, Address> {
@Override
protected boolean parseInner(XmlPullParser parser, Address instance) throws IOException, XmlPullParserException {
if (super.parseInner(parser, instance))
return true;
String name = parser.getName();
for (AddressProperty key : AddressProperty.values())
if (key.toString().equals(name)) {
instance.getProperties().put(key,
ProviderUtils.parseText(parser));
return true;
}
return false;
}
@Override
protected AddressType[] getTypes() {
return AddressType.values();
}
@Override
protected Address createInstance(XmlPullParser parser) {
return new Address();
}
private AddressProvider() {
}
private static final AddressProvider instance = new AddressProvider();
public static AddressProvider getInstance() {
return instance;
}
}
/**
* Copyright (c) 2013, Redsolution LTD. All rights reserved.
*
* This file is part of Xabber project; you can redistribute it and/or
* modify it under the terms of the GNU General Public License, Version 3.
*
* Xabber is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License,
* along with this program. If not, see http://www.gnu.org/licenses/.
*/
package com.xabber.xmpp.vcard;
public class BinaryLogo extends AbstractBinaryData implements Logo {
@Override
public String getElementName() {
return Logo.ELEMENT_NAME;
}
}
/**
* Copyright (c) 2013, Redsolution LTD. All rights reserved.
*
* This file is part of Xabber project; you can redistribute it and/or
* modify it under the terms of the GNU General Public License, Version 3.
*
* Xabber is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License,
* along with this program. If not, see http://www.gnu.org/licenses/.
*/
package com.xabber.xmpp.vcard;
public class BinaryPhoto extends AbstractBinaryData implements Photo {
@Override
public String getElementName() {
return Photo.ELEMENT_NAME;
}
}
/**
* Copyright (c) 2013, Redsolution LTD. All rights reserved.
*
* This file is part of Xabber project; you can redistribute it and/or
* modify it under the terms of the GNU General Public License, Version 3.
*
* Xabber is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License,
* along with this program. If not, see http://www.gnu.org/licenses/.
*/
package com.xabber.xmpp.vcard;
public class BinarySound extends AbstractBinaryData implements Sound {
@Override
public String getElementName() {
return Sound.ELEMENT_NAME;
}
}
/**
* Copyright (c) 2013, Redsolution LTD. All rights reserved.
*
* This file is part of Xabber project; you can redistribute it and/or
* modify it under the terms of the GNU General Public License, Version 3.
*
* Xabber is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License,
* along with this program. If not, see http://www.gnu.org/licenses/.
*/
package com.xabber.xmpp.vcard;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
import com.xabber.xmpp.AbstractInflater;
import com.xabber.xmpp.ProviderUtils;
import java.io.IOException;
class CategoriesInflater extends AbstractInflater<VCard> {
@Override
protected boolean parseInner(XmlPullParser parser, VCard instance) throws IOException, XmlPullParserException {
if (super.parseInner(parser, instance))
return true;
if (VCard.KEYWORD_NAME.equals(parser.getName()))
instance.getCategories().add(ProviderUtils.parseText(parser));
else
return false;
return true;
}
private CategoriesInflater() {
}
private static final CategoriesInflater instance = new CategoriesInflater();
public static CategoriesInflater getInstance() {
return instance;
}
}
/**
* Copyright (c) 2013, Redsolution LTD. All rights reserved.
*
* This file is part of Xabber project; you can redistribute it and/or
* modify it under the terms of the GNU General Public License, Version 3.
*
* Xabber is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License,
* along with this program. If not, see http://www.gnu.org/licenses/.
*/
package com.xabber.xmpp.vcard;
public enum Classification {
PUBLIC,
PRIVATE,
CONFIDENTIAL
}
/**
* Copyright (c) 2013, Redsolution LTD. All rights reserved.
*
* This file is part of Xabber project; you can redistribute it and/or
* modify it under the terms of the GNU General Public License, Version 3.
*
* Xabber is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License,
* along with this program. If not, see http://www.gnu.org/licenses/.
*/
package com.xabber.xmpp.vcard;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
import com.xabber.xmpp.AbstractInflater;
import com.xabber.xmpp.ProviderUtils;
import java.io.IOException;
class ClassificationInflater extends AbstractInflater<VCard> {
@Override
protected boolean parseInner(XmlPullParser parser, VCard instance) throws IOException, XmlPullParserException {
if (super.parseInner(parser, instance))
return true;
String name = parser.getName();
for (Classification value : Classification.values())
if (value.toString().equals(name)) {
instance.setClassification(value);
ProviderUtils.skipTag(parser);
return true;
}
return false;
}
private ClassificationInflater() {
}
private static final ClassificationInflater instance = new ClassificationInflater();
public static ClassificationInflater getInstance() {
return instance;
}
}
/**
* Copyright (c) 2013, Redsolution LTD. All rights reserved.
*
* This file is part of Xabber project; you can redistribute it and/or
* modify it under the terms of the GNU General Public License, Version 3.
*
* Xabber is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License,
* along with this program. If not, see http://www.gnu.org/licenses/.
*/
package com.xabber.xmpp.vcard;
import java.io.IOException;
import org.xmlpull.v1.XmlSerializer;
import com.xabber.xmpp.Instance;
/**
* Holder for the some object.
*
* @param <T>
* @author alexander.ivanov
*/
class DataHolder<T extends Instance> implements Instance {
private T payload;
@Override
public boolean isValid() {
return payload != null && payload.isValid();
}
public T getPayload() {
return payload;
}
public void setPayload(T payload) {
this.payload = payload;
}
@Override
public void serialize(XmlSerializer serializer) throws IOException {
// TODO:
throw new UnsupportedOperationException();
}
}
\ No newline at end of file
/**
* Copyright (c) 2013, Redsolution LTD. All rights reserved.
*
* This file is part of Xabber project; you can redistribute it and/or
* modify it under the terms of the GNU General Public License, Version 3.
*
* Xabber is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License,
* along with this program. If not, see http://www.gnu.org/licenses/.
*/
package com.xabber.xmpp.vcard;
public class Email extends AbstractTypedDataWithValue<EmailType> {
public static final String ELEMENT_NAME = "EMAIL";
public static final String USERID_NAME = "USERID";
public Email() {
super();
}
@Override
protected String getElementName() {
return ELEMENT_NAME;
}
@Override
protected String getValueName() {
return USERID_NAME;
}
}
/**
* Copyright (c) 2013, Redsolution LTD. All rights reserved.
*
* This file is part of Xabber project; you can redistribute it and/or
* modify it under the terms of the GNU General Public License, Version 3.
*
* Xabber is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License,
* along with this program. If not, see http://www.gnu.org/licenses/.
*/
package com.xabber.xmpp.vcard;
import org.xmlpull.v1.XmlPullParser;
class EmailProvider extends
AbstractTypedDataWithValueProvider<EmailType, Email> {
@Override
protected String getValueName() {
return Email.USERID_NAME;
}
@Override
protected EmailType[] getTypes() {
return EmailType.values();
}
@Override
protected Email createInstance(XmlPullParser parser) {
return new Email();
}
private EmailProvider() {
}
private static final EmailProvider instance = new EmailProvider();
public static EmailProvider getInstance() {
return instance;
}
}
/**
* Copyright (c) 2013, Redsolution LTD. All rights reserved.
*
* This file is part of Xabber project; you can redistribute it and/or
* modify it under the terms of the GNU General Public License, Version 3.
*
* Xabber is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License,
* along with this program. If not, see http://www.gnu.org/licenses/.
*/
package com.xabber.xmpp.vcard;
public class ExternalLogo extends AbstractExternalData implements Logo {
@Override
public String getElementName() {
return Logo.ELEMENT_NAME;
}
}
/**
* Copyright (c) 2013, Redsolution LTD. All rights reserved.
*
* This file is part of Xabber project; you can redistribute it and/or
* modify it under the terms of the GNU General Public License, Version 3.
*
* Xabber is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License,
* along with this program. If not, see http://www.gnu.org/licenses/.
*/
package com.xabber.xmpp.vcard;
public class ExternalPhoto extends AbstractExternalData implements Photo {
@Override
public String getElementName() {
return Photo.ELEMENT_NAME;
}
}
/**
* Copyright (c) 2013, Redsolution LTD. All rights reserved.
*
* This file is part of Xabber project; you can redistribute it and/or
* modify it under the terms of the GNU General Public License, Version 3.
*
* Xabber is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License,
* along with this program. If not, see http://www.gnu.org/licenses/.
*/
package com.xabber.xmpp.vcard;
public class ExternalSound extends AbstractExternalData implements Sound {
@Override
public String getElementName() {
return Sound.ELEMENT_NAME;
}
}
/**
* Copyright (c) 2013, Redsolution LTD. All rights reserved.
*
* This file is part of Xabber project; you can redistribute it and/or
* modify it under the terms of the GNU General Public License, Version 3.
*
* Xabber is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License,
* along with this program. If not, see http://www.gnu.org/licenses/.
*/
package com.xabber.xmpp.vcard;
import java.io.IOException;
import org.xmlpull.v1.XmlSerializer;
import com.xabber.xmpp.Instance;
import com.xabber.xmpp.SerializerUtils;
public class Geo implements Instance {
public static final String ELEMENT_NAME = "GEO";
public static final String LAT_NAME = "LAT";
public static final String LON_NAME = "LON";
private String lat;
private String lon;
public String getLat() {
return lat;
}
public void setLat(String lat) {
this.lat = lat;
}
public String getLon() {
return lon;
}
public void setLon(String lon) {
this.lon = lon;
}
@Override
public boolean isValid() {
return lat != null && lon != null;
}
@Override
public void serialize(XmlSerializer serializer) throws IOException {
serializer.startTag(null, ELEMENT_NAME);
SerializerUtils.addTextTag(serializer, LAT_NAME, lat);
SerializerUtils.addTextTag(serializer, LON_NAME, lon);
serializer.endTag(null, ELEMENT_NAME);
}
}
/**
* Copyright (c) 2013, Redsolution LTD. All rights reserved.
*
* This file is part of Xabber project; you can redistribute it and/or
* modify it under the terms of the GNU General Public License, Version 3.
*
* Xabber is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License,
* along with this program. If not, see http://www.gnu.org/licenses/.
*/
package com.xabber.xmpp.vcard;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
import com.xabber.xmpp.AbstractProvider;
import com.xabber.xmpp.ProviderUtils;
import java.io.IOException;
class GeoProvider extends AbstractProvider<Geo> {
@Override
protected boolean parseInner(XmlPullParser parser, Geo instance) throws IOException, XmlPullParserException {
if (super.parseInner(parser, instance))
return true;
if (Geo.LAT_NAME.equals(parser.getName()))
instance.setLat(ProviderUtils.parseText(parser));
else if (Geo.LON_NAME.equals(parser.getName()))
instance.setLon(ProviderUtils.parseText(parser));
else
return false;
return true;
}
@Override
protected Geo createInstance(XmlPullParser parser) {
return new Geo();
}
private GeoProvider() {
}
private static final GeoProvider instance = new GeoProvider();
public static GeoProvider getInstance() {
return instance;
}
}
/**
* Copyright (c) 2013, Redsolution LTD. All rights reserved.
*
* This file is part of Xabber project; you can redistribute it and/or
* modify it under the terms of the GNU General Public License, Version 3.
*
* Xabber is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License,
* along with this program. If not, see http://www.gnu.org/licenses/.
*/
package com.xabber.xmpp.vcard;
import java.io.IOException;
import org.xmlpull.v1.XmlSerializer;
import com.xabber.xmpp.Instance;
import com.xabber.xmpp.SerializerUtils;
public class Key implements Instance {
/**
* Limit received encoded data size.
*/
public static final int MAX_ENCODED_DATA_SIZE = 64 * 1024;
public static final String ELEMENT_NAME = "KEY";
public static final String TYPE_NAME = "TYPE";
public static final String CRED_NAME = "CRED";
private String type;
private String encodedData;
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public String getEncodedData() {
return encodedData;
}
public void setEncodedData(String encodedData) {
this.encodedData = encodedData;
}
@Override
public boolean isValid() {
return encodedData != null;
}
@Override
public void serialize(XmlSerializer serializer) throws IOException {
serializer.startTag(null, ELEMENT_NAME);
if (type != null)
SerializerUtils.addTextTag(serializer, TYPE_NAME, type);
SerializerUtils.addTextTag(serializer, CRED_NAME, encodedData);
serializer.endTag(null, ELEMENT_NAME);
}
}
/**
* Copyright (c) 2013, Redsolution LTD. All rights reserved.
*
* This file is part of Xabber project; you can redistribute it and/or
* modify it under the terms of the GNU General Public License, Version 3.
*
* Xabber is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License,
* along with this program. If not, see http://www.gnu.org/licenses/.
*/
package com.xabber.xmpp.vcard;
import com.xabber.xmpp.AbstractProvider;
import com.xabber.xmpp.ProviderUtils;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
import java.io.IOException;
class KeyProvider extends AbstractProvider<Key> {
@Override
protected boolean parseInner(XmlPullParser parser, Key instance) throws IOException, XmlPullParserException {
if (super.parseInner(parser, instance))
return true;
if (Key.TYPE_NAME.equals(parser.getName()))
instance.setType(ProviderUtils.parseText(parser));
else if (Key.CRED_NAME.equals(parser.getName())) {
String value;
try {
value = ProviderUtils.parseText(parser,
Key.MAX_ENCODED_DATA_SIZE);
} catch (Exception e) {
return true;
}
instance.setEncodedData(value);
} else
return false;
return true;
}
@Override
protected Key createInstance(XmlPullParser parser) {
return new Key();
}
private KeyProvider() {
}
private static final KeyProvider instance = new KeyProvider();
public static KeyProvider getInstance() {
return instance;
}
}
/**
* Copyright (c) 2013, Redsolution LTD. All rights reserved.
*
* This file is part of Xabber project; you can redistribute it and/or
* modify it under the terms of the GNU General Public License, Version 3.
*
* Xabber is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License,
* along with this program. If not, see http://www.gnu.org/licenses/.
*/
package com.xabber.xmpp.vcard;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import org.xmlpull.v1.XmlSerializer;
import com.xabber.xmpp.SerializerUtils;
public class Label extends AbstractTypedData<AddressType> {
public static final String ELEMENT_NAME = "LABEL";
public static final String LINE_NAME = "LINE";
private final List<String> lines;
public Label() {
super();
lines = new ArrayList<String>();
}
public List<String> getLines() {
return lines;
}
@Override
protected String getElementName() {
return ELEMENT_NAME;
}
@Override
protected void writeBody(XmlSerializer serializer) throws IOException {
for (String line : lines)
SerializerUtils.addTextTag(serializer, LINE_NAME, line);
}
@Override
public boolean isValid() {
return AddressType.isValid(types) && !lines.isEmpty();
}
}
/**
* Copyright (c) 2013, Redsolution LTD. All rights reserved.
*
* This file is part of Xabber project; you can redistribute it and/or
* modify it under the terms of the GNU General Public License, Version 3.
*
* Xabber is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License,
* along with this program. If not, see http://www.gnu.org/licenses/.
*/
package com.xabber.xmpp.vcard;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
import com.xabber.xmpp.ProviderUtils;
import java.io.IOException;
class LabelProvider extends AbstractTypedDataProvider<AddressType, Label> {
@Override
protected boolean parseInner(XmlPullParser parser, Label instance) throws IOException, XmlPullParserException {
if (super.parseInner(parser, instance))
return true;
if (Label.LINE_NAME.equals(parser.getName())) {
instance.getLines().add(ProviderUtils.parseText(parser));
return true;
}
return false;
}
@Override
protected AddressType[] getTypes() {
return AddressType.values();
}
@Override
protected Label createInstance(XmlPullParser parser) {
return new Label();
}
private LabelProvider() {
}
private static final LabelProvider instance = new LabelProvider();
public static LabelProvider getInstance() {
return instance;
}
}
/**
* Copyright (c) 2013, Redsolution LTD. All rights reserved.
*
* This file is part of Xabber project; you can redistribute it and/or
* modify it under the terms of the GNU General Public License, Version 3.
*
* Xabber is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License,
* along with this program. If not, see http://www.gnu.org/licenses/.
*/
package com.xabber.xmpp.vcard;
import com.xabber.xmpp.Instance;
public interface Logo extends Instance {
String ELEMENT_NAME = "LOGO";
}
/**
* Copyright (c) 2013, Redsolution LTD. All rights reserved.
*
* This file is part of Xabber project; you can redistribute it and/or
* modify it under the terms of the GNU General Public License, Version 3.
*
* Xabber is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License,
* along with this program. If not, see http://www.gnu.org/licenses/.
*/
package com.xabber.xmpp.vcard;
import org.xmlpull.v1.XmlPullParser;
class LogoHolderProvider extends AbstractDataProvider<Logo, DataHolder<Logo>> {
@Override
protected Logo createBinaryData() {
return new BinaryLogo();
}
@Override
protected Logo createExternalData() {
return new ExternalLogo();
}
@Override
protected DataHolder<Logo> createInstance(XmlPullParser parser) {
return new DataHolder<Logo>();
}
private LogoHolderProvider() {
}
private static final LogoHolderProvider instance = new LogoHolderProvider();
public static LogoHolderProvider getInstance() {
return instance;
}
}
\ No newline at end of file
/**
* Copyright (c) 2013, Redsolution LTD. All rights reserved.
*
* This file is part of Xabber project; you can redistribute it and/or
* modify it under the terms of the GNU General Public License, Version 3.
*
* Xabber is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License,
* along with this program. If not, see http://www.gnu.org/licenses/.
*/
package com.xabber.xmpp.vcard;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
import com.xabber.xmpp.AbstractInflater;
import com.xabber.xmpp.ProviderUtils;
import java.io.IOException;
class NameInflater extends AbstractInflater<VCard> {
@Override
protected boolean parseInner(XmlPullParser parser, VCard instance) throws IOException, XmlPullParserException {
if (super.parseInner(parser, instance))
return true;
String name = parser.getName();
for (NameProperty key : NameProperty.values())
if (key.toString().equals(name)) {
instance.getName().put(key, ProviderUtils.parseText(parser));
return true;
}
return false;
}
private NameInflater() {
}
private static final NameInflater instance = new NameInflater();
public static NameInflater getInstance() {
return instance;
}
}
/**
* Copyright (c) 2013, Redsolution LTD. All rights reserved.
*
* This file is part of Xabber project; you can redistribute it and/or
* modify it under the terms of the GNU General Public License, Version 3.
*
* Xabber is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License,
* along with this program. If not, see http://www.gnu.org/licenses/.
*/
package com.xabber.xmpp.vcard;
public enum NameProperty {
FAMILY,
GIVEN,
MIDDLE,
PREFIX,
SUFFIX
}
/**
* Copyright (c) 2013, Redsolution LTD. All rights reserved.
*
* This file is part of Xabber project; you can redistribute it and/or
* modify it under the terms of the GNU General Public License, Version 3.
*
* Xabber is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License,
* along with this program. If not, see http://www.gnu.org/licenses/.
*/
package com.xabber.xmpp.vcard;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import org.xmlpull.v1.XmlSerializer;
import com.xabber.xmpp.Instance;
import com.xabber.xmpp.SerializerUtils;
public class Organization implements Instance {
public static final String ELEMENT_NAME = "ORG";
public static final String ORGNAME_NAME = "ORGNAME";
public static final String ORGUNIT_NAME = "ORGUNIT";
private String name;
private final List<String> units;
public Organization() {
units = new ArrayList<String>();
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public List<String> getUnits() {
return units;
}
@Override
public boolean isValid() {
return name != null;
}
@Override
public void serialize(XmlSerializer serializer) throws IOException {
serializer.startTag(null, ELEMENT_NAME);
SerializerUtils.addTextTag(serializer, ORGNAME_NAME, name);
for (String unit : units)
SerializerUtils.addTextTag(serializer, ORGUNIT_NAME, unit);
serializer.endTag(null, ELEMENT_NAME);
}
}
/**
* Copyright (c) 2013, Redsolution LTD. All rights reserved.
*
* This file is part of Xabber project; you can redistribute it and/or
* modify it under the terms of the GNU General Public License, Version 3.
*
* Xabber is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License,
* along with this program. If not, see http://www.gnu.org/licenses/.
*/
package com.xabber.xmpp.vcard;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
import com.xabber.xmpp.AbstractProvider;
import com.xabber.xmpp.ProviderUtils;
import java.io.IOException;
class OrganizationProvider extends AbstractProvider<Organization> {
@Override
protected boolean parseInner(XmlPullParser parser, Organization instance) throws IOException, XmlPullParserException {
if (super.parseInner(parser, instance))
return true;
if (Organization.ORGNAME_NAME.equals(parser.getName()))
instance.setName(ProviderUtils.parseText(parser));
else if (Organization.ORGUNIT_NAME.equals(parser.getName()))
instance.getUnits().add(ProviderUtils.parseText(parser));
else
return false;
return true;
}
@Override
protected Organization createInstance(XmlPullParser parser) {
return new Organization();
}
private OrganizationProvider() {
}
private static final OrganizationProvider instance = new OrganizationProvider();
public static OrganizationProvider getInstance() {
return instance;
}
}
/**
* Copyright (c) 2013, Redsolution LTD. All rights reserved.
*
* This file is part of Xabber project; you can redistribute it and/or
* modify it under the terms of the GNU General Public License, Version 3.
*
* Xabber is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License,
* along with this program. If not, see http://www.gnu.org/licenses/.
*/
package com.xabber.xmpp.vcard;
import java.io.IOException;
import org.xmlpull.v1.XmlSerializer;
import com.xabber.xmpp.SerializerUtils;
public class PhoneticSound extends AbstractData implements Sound {
public static final String PHONETIC_NAME = "PHONETIC";
private String value;
public String getValue() {
return value;
}
public void setValue(String value) {
this.value = value;
}
@Override
public boolean isValid() {
return value != null;
}
@Override
protected void writeBody(XmlSerializer serializer) throws IOException {
SerializerUtils.addTextTag(serializer, PHONETIC_NAME, value);
}
@Override
public String getElementName() {
return Sound.ELEMENT_NAME;
}
}
/**
* Copyright (c) 2013, Redsolution LTD. All rights reserved.
*
* This file is part of Xabber project; you can redistribute it and/or
* modify it under the terms of the GNU General Public License, Version 3.
*
* Xabber is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License,
* along with this program. If not, see http://www.gnu.org/licenses/.
*/
package com.xabber.xmpp.vcard;
import com.xabber.xmpp.Instance;
public interface Photo extends Instance {
String ELEMENT_NAME = "PHOTO";
}
/**
* Copyright (c) 2013, Redsolution LTD. All rights reserved.
*
* This file is part of Xabber project; you can redistribute it and/or
* modify it under the terms of the GNU General Public License, Version 3.
*
* Xabber is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License,
* along with this program. If not, see http://www.gnu.org/licenses/.
*/
package com.xabber.xmpp.vcard;
import org.xmlpull.v1.XmlPullParser;
class PhotoHolderProvider extends
AbstractDataProvider<Photo, DataHolder<Photo>> {
@Override
protected Photo createBinaryData() {
return new BinaryPhoto();
}
@Override
protected Photo createExternalData() {
return new ExternalPhoto();
}
@Override
protected DataHolder<Photo> createInstance(XmlPullParser parser) {
return new DataHolder<Photo>();
}
private PhotoHolderProvider() {
}
private static final PhotoHolderProvider instance = new PhotoHolderProvider();
public static PhotoHolderProvider getInstance() {
return instance;
}
}
\ No newline at end of file
/**
* Copyright (c) 2013, Redsolution LTD. All rights reserved.
*
* This file is part of Xabber project; you can redistribute it and/or
* modify it under the terms of the GNU General Public License, Version 3.
*
* Xabber is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License,
* along with this program. If not, see http://www.gnu.org/licenses/.
*/
package com.xabber.xmpp.vcard;
import com.xabber.xmpp.Instance;
public interface Sound extends Instance {
String ELEMENT_NAME = "SOUND";
}
/**
* Copyright (c) 2013, Redsolution LTD. All rights reserved.
*
* This file is part of Xabber project; you can redistribute it and/or
* modify it under the terms of the GNU General Public License, Version 3.
*
* Xabber is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License,
* along with this program. If not, see http://www.gnu.org/licenses/.
*/
package com.xabber.xmpp.vcard;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
import com.xabber.xmpp.ProviderUtils;
import java.io.IOException;
class SoundHolderProvider extends
AbstractDataProvider<Sound, DataHolder<Sound>> {
@Override
protected boolean createPayload(XmlPullParser parser, DataHolder<Sound> instance) {
if (super.createPayload(parser, instance))
return true;
if (PhoneticSound.PHONETIC_NAME.equals(parser.getName()))
instance.setPayload(createPhoneticSound());
else
return false;
return true;
}
@Override
protected Sound createBinaryData() {
return new BinarySound();
}
@Override
protected Sound createExternalData() {
return new ExternalSound();
}
protected Sound createPhoneticSound() {
return new PhoneticSound();
}
@Override
protected boolean inflatePayload(XmlPullParser parser, DataHolder<Sound> instance) throws IOException, XmlPullParserException {
if (super.inflatePayload(parser, instance))
return true;
if (instance.getPayload() instanceof PhoneticSound)
return inflatePhoneticSound(parser,
(PhoneticSound) instance.getPayload());
else
return false;
}
protected boolean inflatePhoneticSound(XmlPullParser parser, PhoneticSound payload) throws IOException, XmlPullParserException {
if (PhoneticSound.PHONETIC_NAME.equals(parser.getName()))
payload.setValue(ProviderUtils.parseText(parser));
else
return false;
return true;
}
@Override
protected DataHolder<Sound> createInstance(XmlPullParser parser) {
return new DataHolder<Sound>();
}
private SoundHolderProvider() {
}
private static final SoundHolderProvider instance = new SoundHolderProvider();
public static SoundHolderProvider getInstance() {
return instance;
}
}
\ No newline at end of file
/**
* Copyright (c) 2013, Redsolution LTD. All rights reserved.
*
* This file is part of Xabber project; you can redistribute it and/or
* modify it under the terms of the GNU General Public License, Version 3.
*
* Xabber is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License,
* along with this program. If not, see http://www.gnu.org/licenses/.
*/
package com.xabber.xmpp.vcard;
public class Telephone extends AbstractTypedDataWithValue<TelephoneType> {
public static final String ELEMENT_NAME = "TEL";
public static final String NUMBER_NAME = "NUMBER";
public Telephone() {
super();
}
@Override
protected String getElementName() {
return ELEMENT_NAME;
}
@Override
protected String getValueName() {
return NUMBER_NAME;
}
}
/**
* Copyright (c) 2013, Redsolution LTD. All rights reserved.
*
* This file is part of Xabber project; you can redistribute it and/or
* modify it under the terms of the GNU General Public License, Version 3.
*
* Xabber is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License,
* along with this program. If not, see http://www.gnu.org/licenses/.
*/
package com.xabber.xmpp.vcard;
import org.xmlpull.v1.XmlPullParser;
class TelephoneProvider extends
AbstractTypedDataWithValueProvider<TelephoneType, Telephone> {
@Override
protected String getValueName() {
return Telephone.NUMBER_NAME;
}
@Override
protected TelephoneType[] getTypes() {
return TelephoneType.values();
}
@Override
protected Telephone createInstance(XmlPullParser parser) {
return new Telephone();
}
private TelephoneProvider() {
}
private static final TelephoneProvider instance = new TelephoneProvider();
public static TelephoneProvider getInstance() {
return instance;
}
}
/**
* Copyright (c) 2013, Redsolution LTD. All rights reserved.
*
* This file is part of Xabber project; you can redistribute it and/or
* modify it under the terms of the GNU General Public License, Version 3.
*
* Xabber is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License,
* along with this program. If not, see http://www.gnu.org/licenses/.
*/
package com.xabber.xmpp.vcard;
import java.io.IOException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import org.jivesoftware.smack.util.StringUtils;
import org.xmlpull.v1.XmlSerializer;
import com.xabber.xmpp.IQ;
import com.xabber.xmpp.SerializerUtils;
/**
* vCard-temp
* <p/>
* http://xmpp.org/extensions/xep-0054.html
*
* @author alexander.ivanov
*/
public class VCard extends IQ {
public static final String ELEMENT_NAME = "vCard";
public static final String NAMESPACE = "vcard-temp";
public static final String N_NAME = "N";
public static final String CLASS_NAME = "CLASS";
public static final String CATEGORIES_NAME = "CATEGORIES";
public static final String KEYWORD_NAME = "KEYWORD";
private String version;
private final Map<NameProperty, String> name;
private final Map<VCardProperty, String> properties;
private final List<Photo> photos;
private final List<Address> addresses;
private final List<Label> labels;
private final List<Telephone> telephones;
private final List<Email> emails;
private final List<Logo> logos;
private final List<Sound> sounds;
private final List<Geo> geos;
private final List<Organization> organizations;
private final List<String> categories;
private Classification classification;
private final List<Key> keys;
// TODO: Agent
public VCard() {
super(ELEMENT_NAME, NAMESPACE);
name = new HashMap<NameProperty, String>();
properties = new HashMap<VCardProperty, String>();
photos = new ArrayList<Photo>();
addresses = new ArrayList<Address>();
labels = new ArrayList<Label>();
telephones = new ArrayList<Telephone>();
emails = new ArrayList<Email>();
logos = new ArrayList<Logo>();
geos = new ArrayList<Geo>();
organizations = new ArrayList<Organization>();
categories = new ArrayList<String>();
sounds = new ArrayList<Sound>();
keys = new ArrayList<Key>();
}
private boolean isEmpty() {
return version == null && name.isEmpty() && properties.isEmpty()
&& photos.isEmpty() && addresses.isEmpty() && labels.isEmpty()
&& telephones.isEmpty() && emails.isEmpty() && logos.isEmpty()
&& sounds.isEmpty() && geos.isEmpty() && categories.isEmpty()
&& keys.isEmpty() && classification == null;
}
public String getVersion() {
return version;
}
public void setVersion(String version) {
this.version = version;
}
public List<Geo> getGeos() {
return geos;
}
public Classification getClassification() {
return classification;
}
public void setClassification(Classification classification) {
this.classification = classification;
}
public List<Key> getKeys() {
return keys;
}
public Map<NameProperty, String> getName() {
return name;
}
public Map<VCardProperty, String> getProperties() {
return properties;
}
public List<Photo> getPhotos() {
return photos;
}
public List<Address> getAddresses() {
return addresses;
}
public List<Label> getLabels() {
return labels;
}
public List<Telephone> getTelephones() {
return telephones;
}
public List<Email> getEmails() {
return emails;
}
public List<Logo> getLogos() {
return logos;
}
public List<Organization> getOrganizations() {
return organizations;
}
public List<String> getCategories() {
return categories;
}
public List<Sound> getSounds() {
return sounds;
}
public String getFormattedName() {
String value = properties.get(VCardProperty.FN);
if (value == null) {
StringBuilder builder = new StringBuilder();
append(builder, name.get(NameProperty.PREFIX));
append(builder, name.get(NameProperty.GIVEN));
append(builder, name.get(NameProperty.MIDDLE));
append(builder, name.get(NameProperty.FAMILY));
append(builder, name.get(NameProperty.SUFFIX));
return builder.toString();
}
return value;
}
public byte[] getAvatar() {
BinaryPhoto binaryPhoto = null;
for (Photo photo : photos)
if (photo instanceof BinaryPhoto) {
binaryPhoto = (BinaryPhoto) photo;
break;
}
if (binaryPhoto == null)
return null;
return binaryPhoto.getData();
}
public String getAvatarHash() {
byte[] data = getAvatar();
if (data == null)
return null;
MessageDigest digest;
try {
digest = MessageDigest.getInstance("SHA-1");
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
return null;
}
digest.update(data);
return StringUtils.encodeHex(digest.digest());
}
public String getField(VCardProperty property) {
return properties.get(property);
}
public String getField(NameProperty property) {
return name.get(property);
}
public String getNickName() {
return getField(VCardProperty.NICKNAME);
}
public String getFirstName() {
return getField(NameProperty.GIVEN);
}
public String getMiddleName() {
return getField(NameProperty.MIDDLE);
}
public String getLastName() {
return getField(NameProperty.FAMILY);
}
private void append(StringBuilder builder, String value) {
if (value == null || "".equals(value))
return;
if (builder.length() != 0)
builder.append(" ");
builder.append(value);
}
public void setFormattedName(String formattedName) {
properties.put(VCardProperty.FN, formattedName);
}
@Override
public String getElementName() {
return ELEMENT_NAME;
}
@Override
public String getNamespace() {
return NAMESPACE;
}
@Override
public void serializeContent(XmlSerializer serializer) throws IOException {
if (isEmpty())
return;
SerializerUtils.addTextTag(serializer, VCardProperty.FN.toString(),
getFormattedName());
serializer.startTag(null, N_NAME);
for (Entry<NameProperty, String> entry : name.entrySet())
SerializerUtils.addTextTag(serializer, entry.getKey().toString(),
entry.getValue());
serializer.endTag(null, N_NAME);
for (Entry<VCardProperty, String> entry : properties.entrySet())
if (entry.getKey() != VCardProperty.FN)
SerializerUtils.addTextTag(serializer, entry.getKey()
.toString(), entry.getValue());
for (Photo photo : photos)
photo.serialize(serializer);
for (Address address : addresses)
address.serialize(serializer);
for (Label label : labels)
label.serialize(serializer);
for (Telephone telephone : telephones)
telephone.serialize(serializer);
for (Email email : emails)
email.serialize(serializer);
for (Logo logo : logos)
logo.serialize(serializer);
for (Sound sound : sounds)
sound.serialize(serializer);
for (Geo geo : geos)
geo.serialize(serializer);
for (Organization organization : organizations)
organization.serialize(serializer);
if (!categories.isEmpty()) {
serializer.startTag(null, CATEGORIES_NAME);
for (String keyword : categories)
SerializerUtils.addTextTag(serializer, KEYWORD_NAME, keyword);
serializer.endTag(null, CATEGORIES_NAME);
}
if (classification != null)
SerializerUtils.addTextTag(serializer, CLASS_NAME,
classification.toString());
for (Key key : keys)
key.serialize(serializer);
}
@Override
public boolean isValid() {
return true;
}
@Override
protected IQChildElementXmlStringBuilder getIQChildElementBuilder(IQChildElementXmlStringBuilder xml) {
xml.setEmptyElement();
return xml;
}
}
/**
* Copyright (c) 2013, Redsolution LTD. All rights reserved.
*
* This file is part of Xabber project; you can redistribute it and/or
* modify it under the terms of the GNU General Public License, Version 3.
*
* Xabber is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License,
* along with this program. If not, see http://www.gnu.org/licenses/.
*/
package com.xabber.xmpp.vcard;
import org.jivesoftware.smack.SmackException;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
import com.xabber.xmpp.AbstractIQProvider;
import com.xabber.xmpp.ProviderUtils;
import java.io.IOException;
public class VCardProvider extends AbstractIQProvider<VCard> {
@Override
protected VCard createInstance(XmlPullParser parser) {
return new VCard();
}
@Override
protected boolean parseInner(XmlPullParser parser, VCard instance) throws XmlPullParserException, IOException, SmackException {
if (super.parseInner(parser, instance))
return true;
String name = parser.getName();
if (VCard.N_NAME.equals(name)) {
NameInflater.getInstance().parseTag(parser, instance);
} else if (Photo.ELEMENT_NAME.equals(name)) {
DataHolder<Photo> holder = PhotoHolderProvider.getInstance()
.provideInstance(parser);
if (holder.getPayload() != null && holder.getPayload().isValid())
instance.getPhotos().add(holder.getPayload());
} else if (Logo.ELEMENT_NAME.equals(name)) {
DataHolder<Logo> holder = LogoHolderProvider.getInstance()
.provideInstance(parser);
if (holder.getPayload() != null && holder.getPayload().isValid())
instance.getLogos().add(holder.getPayload());
} else if (Sound.ELEMENT_NAME.equals(name)) {
DataHolder<Sound> holder = SoundHolderProvider.getInstance()
.provideInstance(parser);
if (holder.getPayload() != null && holder.getPayload().isValid())
instance.getSounds().add(holder.getPayload());
} else if (Address.ELEMENT_NAME.equals(name)) {
Address value = AddressProvider.getInstance().provideInstance(
parser);
if (value.isValid())
instance.getAddresses().add(value);
} else if (Label.ELEMENT_NAME.equals(name)) {
Label value = LabelProvider.getInstance().provideInstance(parser);
if (value.isValid())
instance.getLabels().add(value);
} else if (Telephone.ELEMENT_NAME.equals(name)) {
Telephone value = TelephoneProvider.getInstance().provideInstance(
parser);
if (value.isValid())
instance.getTelephones().add(value);
} else if (Email.ELEMENT_NAME.equals(name)) {
Email value = EmailProvider.getInstance().provideInstance(parser);
if (value.isValid())
instance.getEmails().add(value);
} else if (Geo.ELEMENT_NAME.equals(name)) {
Geo value = GeoProvider.getInstance().provideInstance(parser);
if (value.isValid())
instance.getGeos().add(value);
} else if (Organization.ELEMENT_NAME.equals(name)) {
Organization value = OrganizationProvider.getInstance()
.provideInstance(parser);
if (value.isValid())
instance.getOrganizations().add(value);
} else if (VCard.CATEGORIES_NAME.equals(name)) {
CategoriesInflater.getInstance().parseTag(parser, instance);
} else if (VCard.CLASS_NAME.equals(name)) {
ClassificationInflater.getInstance().parseTag(parser, instance);
} else if (Key.ELEMENT_NAME.equals(name)) {
Key value = KeyProvider.getInstance().provideInstance(parser);
if (value.isValid())
instance.getKeys().add(value);
} else {
for (VCardProperty key : VCardProperty.values())
if (key.toString().equals(name)) {
instance.getProperties().put(key,
ProviderUtils.parseText(parser));
return true;
}
return false;
}
return true;
}
}
...@@ -2,13 +2,6 @@ ...@@ -2,13 +2,6 @@
<!-- Providers file for default Smack extensions --> <!-- Providers file for default Smack extensions -->
<smackProviders> <smackProviders>
<!-- VCard -->
<iqProvider>
<elementName>vCard</elementName>
<namespace>vcard-temp</namespace>
<className>com.xabber.xmpp.vcard.VCardProvider</className>
</iqProvider>
<!-- vCardUpdate --> <!-- vCardUpdate -->
<extensionProvider> <extensionProvider>
<elementName>x</elementName> <elementName>x</elementName>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment