mirror of https://github.com/sipwise/jitsi.git
parent
1a9fec5221
commit
8711c28292
Binary file not shown.
Binary file not shown.
@ -1,343 +0,0 @@
|
||||
/*
|
||||
* Jitsi, the OpenSource Java VoIP and Instant Messaging client.
|
||||
*
|
||||
* Copyright @ 2015 Atlassian Pty Ltd
|
||||
*
|
||||
* 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 net.java.sip.communicator.impl.protocol.dict;
|
||||
|
||||
import net.java.dict4j.*;
|
||||
import net.java.sip.communicator.service.protocol.*;
|
||||
import net.java.sip.communicator.util.*;
|
||||
|
||||
/**
|
||||
* An implementation of a Dict contact
|
||||
*
|
||||
* @author ROTH Damien
|
||||
* @author LITZELMANN Cedric
|
||||
*/
|
||||
public class ContactDictImpl
|
||||
extends AbstractContact
|
||||
{
|
||||
private Logger logger = Logger.getLogger(ContactDictImpl.class);
|
||||
|
||||
/**
|
||||
* Icon
|
||||
*/
|
||||
private static byte[] icon = DictActivator.getResources()
|
||||
.getImageInBytes("service.protocol.dict.DICT_64x64");
|
||||
|
||||
/**
|
||||
* The id of the contact.
|
||||
*/
|
||||
private String contactID = null;
|
||||
|
||||
/**
|
||||
* The provider that created us.
|
||||
*/
|
||||
private ProtocolProviderServiceDictImpl parentProvider = null;
|
||||
|
||||
/**
|
||||
* The group that belong to.
|
||||
*/
|
||||
private ContactGroupDictImpl parentGroup = null;
|
||||
|
||||
/**
|
||||
* The presence status of the contact.
|
||||
*/
|
||||
private PresenceStatus presenceStatus = DictStatusEnum.ONLINE;
|
||||
|
||||
/**
|
||||
* Determines whether this contact is persistent, i.e. member of the contact
|
||||
* list or whether it is here only temporarily.
|
||||
*/
|
||||
private boolean isPersistent = true;
|
||||
|
||||
/**
|
||||
* Determines whether the contact has been resolved (i.e. we have a
|
||||
* confirmation that it is still on the server contact list).
|
||||
*/
|
||||
private boolean isResolved = true;
|
||||
|
||||
/**
|
||||
* The string in a "humain readable and understandable representation" of
|
||||
* the dictionnaire. In brief this is a short description of the dictionary.
|
||||
*/
|
||||
private String dictName = null;
|
||||
|
||||
/**
|
||||
* Creates an instance of a meta contact with the specified string used
|
||||
* as a name and identifier.
|
||||
*
|
||||
* @param databaseCode The identifier of this contact (also used as a name).
|
||||
* @param parentProvider The provider that created us.
|
||||
*/
|
||||
public ContactDictImpl(
|
||||
String databaseCode,
|
||||
ProtocolProviderServiceDictImpl parentProvider)
|
||||
{
|
||||
this.contactID = databaseCode;
|
||||
this.parentProvider = parentProvider;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is only called when the contact is added to a new
|
||||
* <tt>ContactGroupDictImpl</tt> by the
|
||||
* <tt>ContactGroupDictImpl</tt> itself.
|
||||
*
|
||||
* @param newParentGroup the <tt>ContactGroupDictImpl</tt> that is now
|
||||
* parent of this <tt>ContactDictImpl</tt>
|
||||
*/
|
||||
void setParentGroup(ContactGroupDictImpl newParentGroup)
|
||||
{
|
||||
this.parentGroup = newParentGroup;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a String that can be used for identifying the contact.
|
||||
*
|
||||
* @return a String id representing and uniquely identifying the contact.
|
||||
*/
|
||||
public String getContactID()
|
||||
{
|
||||
return contactID;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a String that can be used for identifying the contact.
|
||||
*
|
||||
* @return a String id representing and uniquely identifying the contact.
|
||||
*/
|
||||
public String getAddress()
|
||||
{
|
||||
return contactID;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a String that could be used by any user interacting modules
|
||||
* for referring to this contact.
|
||||
*
|
||||
* @return a String that can be used for referring to this contact when
|
||||
* interacting with the user.
|
||||
*/
|
||||
public String getDisplayName()
|
||||
{
|
||||
if (dictName == null)
|
||||
{
|
||||
if (this.contactID.equals("*"))
|
||||
{
|
||||
this.dictName = DictActivator.getResources()
|
||||
.getI18NString("plugin.dictaccregwizz.ANY_DICTIONARY");
|
||||
}
|
||||
else if (this.contactID.equals("!"))
|
||||
{
|
||||
this.dictName = DictActivator.getResources()
|
||||
.getI18NString("plugin.dictaccregwizz.FIRST_MATCH");
|
||||
}
|
||||
else
|
||||
{
|
||||
try
|
||||
{
|
||||
this.dictName = this.parentProvider.getConnection()
|
||||
.getDictionaryName(this.contactID);
|
||||
}
|
||||
catch (DictException dx)
|
||||
{
|
||||
logger.error("Error while getting dictionary long name", dx);
|
||||
}
|
||||
|
||||
if (this.dictName == null)
|
||||
this.dictName = this.contactID;
|
||||
}
|
||||
}
|
||||
|
||||
return dictName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a byte array containing an image (most often a photo or an
|
||||
* avatar) that the contact uses as a representation.
|
||||
*
|
||||
* @return byte[] an image representing the contact.
|
||||
*/
|
||||
public byte[] getImage()
|
||||
{
|
||||
return icon;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the status of the contact.
|
||||
*
|
||||
* @return always DictStatusEnum.ONLINE.
|
||||
*/
|
||||
public PresenceStatus getPresenceStatus()
|
||||
{
|
||||
return this.presenceStatus;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets <tt>dictPresenceStatus</tt> as the PresenceStatus that this
|
||||
* contact is currently in.
|
||||
* @param dictPresenceStatus the <tt>DictPresenceStatus</tt>
|
||||
* currently valid for this contact.
|
||||
*/
|
||||
public void setPresenceStatus(PresenceStatus dictPresenceStatus)
|
||||
{
|
||||
this.presenceStatus = dictPresenceStatus;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a reference to the protocol provider that created the contact.
|
||||
*
|
||||
* @return a refererence to an instance of the ProtocolProviderService
|
||||
*/
|
||||
public ProtocolProviderService getProtocolProvider()
|
||||
{
|
||||
return parentProvider;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines whether or not this contact represents our own identity.
|
||||
*
|
||||
* @return true in case this is a contact that represents ourselves and
|
||||
* false otherwise.
|
||||
*/
|
||||
public boolean isLocal()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the group that contains this contact.
|
||||
* @return a reference to the <tt>ContactGroupDictImpl</tt> that
|
||||
* contains this contact.
|
||||
*/
|
||||
public ContactGroup getParentContactGroup()
|
||||
{
|
||||
return this.parentGroup;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a string representation of this contact, containing most of its
|
||||
* representative details.
|
||||
*
|
||||
* @return a string representation of this contact.
|
||||
*/
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
StringBuffer buff
|
||||
= new StringBuffer("ContactDictImpl[ DisplayName=")
|
||||
.append(getDisplayName()).append("]");
|
||||
|
||||
return buff.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines whether or not this contact is being stored by the server.
|
||||
* Non persistent contacts are common in the case of simple, non-persistent
|
||||
* presence operation sets. They could however also be seen in persistent
|
||||
* presence operation sets when for example we have received an event
|
||||
* from someone not on our contact list. Non persistent contacts are
|
||||
* volatile even when coming from a persistent presence op. set. They would
|
||||
* only exist until the application is closed and will not be there next
|
||||
* time it is loaded.
|
||||
*
|
||||
* @return true if the contact is persistent and false otherwise.
|
||||
*/
|
||||
public boolean isPersistent()
|
||||
{
|
||||
return isPersistent;
|
||||
}
|
||||
|
||||
/**
|
||||
* Specifies whether or not this contact is being stored by the server.
|
||||
* Non persistent contacts are common in the case of simple, non-persistent
|
||||
* presence operation sets. They could however also be seen in persistent
|
||||
* presence operation sets when for example we have received an event
|
||||
* from someone not on our contact list. Non persistent contacts are
|
||||
* volatile even when coming from a persistent presence op. set. They would
|
||||
* only exist until the application is closed and will not be there next
|
||||
* time it is loaded.
|
||||
*
|
||||
* @param isPersistent true if the contact is persistent and false
|
||||
* otherwise.
|
||||
*/
|
||||
public void setPersistent(boolean isPersistent)
|
||||
{
|
||||
this.isPersistent = isPersistent;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns null as no persistent data is required and the contact address is
|
||||
* sufficient for restoring the contact.
|
||||
* <p>
|
||||
* @return null as no such data is needed.
|
||||
*/
|
||||
public String getPersistentData()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines whether or not this contact has been resolved against the
|
||||
* server. Unresolved contacts are used when initially loading a contact
|
||||
* list that has been stored in a local file until the presence operation
|
||||
* set has managed to retrieve all the contact list from the server and has
|
||||
* properly mapped contacts to their on-line buddies.
|
||||
*
|
||||
* @return true if the contact has been resolved (mapped against a buddy)
|
||||
* and false otherwise.
|
||||
*/
|
||||
public boolean isResolved()
|
||||
{
|
||||
return isResolved;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the current status message of this contact.
|
||||
*
|
||||
* @return null as the protocol has currently no support of status messages
|
||||
*/
|
||||
public String getStatusMessage()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Makes the contact resolved or unresolved.
|
||||
*
|
||||
* @param resolved true to make the contact resolved; false to
|
||||
* make it unresolved
|
||||
*/
|
||||
public void setResolved(boolean resolved)
|
||||
{
|
||||
this.isResolved = resolved;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the persistent presence operation set that this contact belongs
|
||||
* to.
|
||||
*
|
||||
* @return the <tt>OperationSetPersistentPresenceGibberishImpl</tt> that
|
||||
* this contact belongs to.
|
||||
*/
|
||||
public OperationSetPersistentPresenceDictImpl
|
||||
getParentPresenceOperationSet()
|
||||
{
|
||||
return (OperationSetPersistentPresenceDictImpl) parentProvider
|
||||
.getOperationSet(OperationSetPersistentPresence.class);
|
||||
}
|
||||
}
|
||||
@ -1,588 +0,0 @@
|
||||
/*
|
||||
* Jitsi, the OpenSource Java VoIP and Instant Messaging client.
|
||||
*
|
||||
* Copyright @ 2015 Atlassian Pty Ltd
|
||||
*
|
||||
* 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 net.java.sip.communicator.impl.protocol.dict;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import net.java.sip.communicator.service.protocol.*;
|
||||
|
||||
/**
|
||||
* A simple, straightforward implementation of a dict ContactGroup. Since
|
||||
* the Dict protocol is not a real one, we simply store all group details
|
||||
* in class fields. You should know that when implementing a real protocol,
|
||||
* the contact group implementation would rather encapsulate group objects from
|
||||
* the protocol stack and group property values should be returned by consulting
|
||||
* the encapsulated object.
|
||||
*
|
||||
* @author ROTH Damien
|
||||
* @author LITZELMANN Cedric
|
||||
*/
|
||||
public class ContactGroupDictImpl
|
||||
implements ContactGroup
|
||||
{
|
||||
|
||||
/**
|
||||
* The name of this Dict contact group.
|
||||
*/
|
||||
private String groupName = null;
|
||||
|
||||
/**
|
||||
* The list of this group's members.
|
||||
*/
|
||||
private List<Contact> contacts = new ArrayList<Contact>();
|
||||
|
||||
/**
|
||||
* The list of sub groups belonging to this group.
|
||||
*/
|
||||
private List<ContactGroup> subGroups = new ArrayList<ContactGroup>();
|
||||
|
||||
/**
|
||||
* The group that this group belongs to (or null if this is the root group).
|
||||
*/
|
||||
private ContactGroupDictImpl parentGroup = null;
|
||||
|
||||
/**
|
||||
* Determines whether this group is really in the contact list or whether
|
||||
* it is here only temporarily and will be gone next time we restart.
|
||||
*/
|
||||
private boolean isPersistent = true;
|
||||
|
||||
/**
|
||||
* The protocol provider that created us.
|
||||
*/
|
||||
private ProtocolProviderServiceDictImpl parentProvider = null;
|
||||
|
||||
/**
|
||||
* Determines whether this group has been resolved on the server.
|
||||
* Unresolved groups are groups that were available on previous runs and
|
||||
* that the meta contact list has stored. During all next runs, when
|
||||
* bootstrapping, the meta contact list would create these groups as
|
||||
* unresolved. Once a protocol provider implementation confirms that the
|
||||
* groups are still on the server, it would issue an event indicating that
|
||||
* the groups are now resolved.
|
||||
*/
|
||||
private boolean isResolved = true;
|
||||
|
||||
/**
|
||||
* An id uniquely identifying the group. For many protocols this could be
|
||||
* the group name itself.
|
||||
*/
|
||||
private String uid = null;
|
||||
private static final String UID_SUFFIX = ".uid";
|
||||
|
||||
/**
|
||||
* Creates a ContactGroupDictImpl with the specified name.
|
||||
*
|
||||
* @param groupName the name of the group.
|
||||
* @param parentProvider the protocol provider that created this group.
|
||||
*/
|
||||
public ContactGroupDictImpl(
|
||||
String groupName,
|
||||
ProtocolProviderServiceDictImpl parentProvider)
|
||||
{
|
||||
this.groupName = groupName;
|
||||
this.uid = groupName + UID_SUFFIX;
|
||||
this.parentProvider = parentProvider;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines whether the group may contain subgroups or not.
|
||||
*
|
||||
* @return always true in this implementation.
|
||||
*/
|
||||
public boolean canContainSubgroups()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the protocol provider that this group belongs to.
|
||||
* @return a regerence to the ProtocolProviderService instance that this
|
||||
* ContactGroup belongs to.
|
||||
*/
|
||||
public ProtocolProviderService getProtocolProvider()
|
||||
{
|
||||
return parentProvider;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an Iterator over all contacts, member of this
|
||||
* <tt>ContactGroup</tt>.
|
||||
*
|
||||
* @return a java.util.Iterator over all contacts inside this
|
||||
* <tt>ContactGroup</tt>
|
||||
*/
|
||||
public Iterator<Contact> contacts()
|
||||
{
|
||||
return contacts.iterator();
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the specified contact to this group.
|
||||
* @param contactToAdd the ContactDictImpl to add to this group.
|
||||
*/
|
||||
public void addContact(ContactDictImpl contactToAdd)
|
||||
{
|
||||
this.contacts.add(contactToAdd);
|
||||
contactToAdd.setParentGroup(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the number of <tt>Contact</tt> members of this
|
||||
* <tt>ContactGroup</tt>
|
||||
*
|
||||
* @return an int indicating the number of <tt>Contact</tt>s, members of
|
||||
* this <tt>ContactGroup</tt>.
|
||||
*/
|
||||
public int countContacts()
|
||||
{
|
||||
return contacts.size();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the number of subgroups contained by this
|
||||
* <tt>ContactGroup</tt>.
|
||||
*
|
||||
* @return the number of subGroups currently added to this group.
|
||||
*/
|
||||
public int countSubgroups()
|
||||
{
|
||||
return subGroups.size();
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the specified contact group to the contained by this group.
|
||||
* @param subgroup the ContactGroupDictImpl to add as a subgroup to this group.
|
||||
*/
|
||||
public void addSubgroup(ContactGroupDictImpl subgroup)
|
||||
{
|
||||
this.subGroups.add(subgroup);
|
||||
subgroup.setParentGroup(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the group that is the new parent of this group
|
||||
* @param parent ContactGroupDictImpl
|
||||
*/
|
||||
void setParentGroup(ContactGroupDictImpl parent)
|
||||
{
|
||||
this.parentGroup = parent;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the contact group that currently contains this group or null if
|
||||
* this is the root contact group.
|
||||
* @return the contact group that currently contains this group or null if
|
||||
* this is the root contact group.
|
||||
*/
|
||||
public ContactGroup getParentContactGroup()
|
||||
{
|
||||
return this.parentGroup;
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes the specified contact group from the this group's subgroups.
|
||||
* @param subgroup the ContactGroupDictImpl subgroup to remove.
|
||||
*/
|
||||
public void removeSubGroup(ContactGroupDictImpl subgroup)
|
||||
{
|
||||
this.subGroups.remove(subgroup);
|
||||
subgroup.setParentGroup(null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the group that is parent of the specified dictGroup or null
|
||||
* if no parent was found.
|
||||
* @param dictGroup the group whose parent we're looking for.
|
||||
* @return the ContactGroupDictImpl instance that dictGroup
|
||||
* belongs to or null if no parent was found.
|
||||
*/
|
||||
public ContactGroupDictImpl findGroupParent(ContactGroupDictImpl dictGroup)
|
||||
{
|
||||
if ( subGroups.contains(dictGroup) )
|
||||
return this;
|
||||
|
||||
Iterator<ContactGroup> subGroupsIter = subgroups();
|
||||
while (subGroupsIter.hasNext())
|
||||
{
|
||||
ContactGroupDictImpl subgroup
|
||||
= (ContactGroupDictImpl) subGroupsIter.next();
|
||||
|
||||
ContactGroupDictImpl parent
|
||||
= subgroup.findGroupParent(dictGroup);
|
||||
|
||||
if(parent != null)
|
||||
return parent;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the group that is parent of the specified dictContact or
|
||||
* null if no parent was found.
|
||||
*
|
||||
* @param dictContact the contact whose parent we're looking for.
|
||||
* @return the ContactGroupDictImpl instance that dictContact
|
||||
* belongs to or <tt>null</tt> if no parent was found.
|
||||
*/
|
||||
public ContactGroupDictImpl findContactParent(
|
||||
ContactDictImpl dictContact)
|
||||
{
|
||||
if ( contacts.contains(dictContact) )
|
||||
return this;
|
||||
|
||||
Iterator<ContactGroup> subGroupsIter = subgroups();
|
||||
while (subGroupsIter.hasNext())
|
||||
{
|
||||
ContactGroupDictImpl subgroup
|
||||
= (ContactGroupDictImpl) subGroupsIter.next();
|
||||
|
||||
ContactGroupDictImpl parent
|
||||
= subgroup.findContactParent(dictContact);
|
||||
|
||||
if(parent != null)
|
||||
return parent;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Returns the <tt>Contact</tt> with the specified address or identifier.
|
||||
*
|
||||
* @param id the addres or identifier of the <tt>Contact</tt> we are
|
||||
* looking for.
|
||||
* @return the <tt>Contact</tt> with the specified id or address.
|
||||
*/
|
||||
public Contact getContact(String id)
|
||||
{
|
||||
Iterator<Contact> contactsIter = contacts();
|
||||
while (contactsIter.hasNext())
|
||||
{
|
||||
ContactDictImpl contact = (ContactDictImpl) contactsIter.next();
|
||||
if (contact.getAddress().equals(id))
|
||||
return contact;
|
||||
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the subgroup with the specified index.
|
||||
*
|
||||
* @param index the index of the <tt>ContactGroup</tt> to retrieve.
|
||||
* @return the <tt>ContactGroup</tt> with the specified index.
|
||||
*/
|
||||
public ContactGroup getGroup(int index)
|
||||
{
|
||||
return subGroups.get(index);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the subgroup with the specified name.
|
||||
*
|
||||
* @param groupName the name of the <tt>ContactGroup</tt> to retrieve.
|
||||
* @return the <tt>ContactGroup</tt> with the specified index.
|
||||
*/
|
||||
public ContactGroup getGroup(String groupName)
|
||||
{
|
||||
Iterator<ContactGroup> groupsIter = subgroups();
|
||||
while (groupsIter.hasNext())
|
||||
{
|
||||
ContactGroupDictImpl contactGroup
|
||||
= (ContactGroupDictImpl) groupsIter.next();
|
||||
if (contactGroup.getGroupName().equals(groupName))
|
||||
return contactGroup;
|
||||
|
||||
}
|
||||
return null;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the name of this group.
|
||||
*
|
||||
* @return a String containing the name of this group.
|
||||
*/
|
||||
public String getGroupName()
|
||||
{
|
||||
return this.groupName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets this group a new name.
|
||||
* @param newGrpName a String containing the new name of this group.
|
||||
*/
|
||||
public void setGroupName(String newGrpName)
|
||||
{
|
||||
this.groupName = newGrpName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an iterator over the sub groups that this
|
||||
* <tt>ContactGroup</tt> contains.
|
||||
*
|
||||
* @return a java.util.Iterator over the <tt>ContactGroup</tt> children
|
||||
* of this group (i.e. subgroups).
|
||||
*/
|
||||
public Iterator<ContactGroup> subgroups()
|
||||
{
|
||||
return subGroups.iterator();
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes the specified contact from this group.
|
||||
* @param contact the ContactDictImpl to remove from this group
|
||||
*/
|
||||
public void removeContact(ContactDictImpl contact)
|
||||
{
|
||||
this.contacts.remove(contact);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the contact with the specified id or null if no such contact
|
||||
* exists.
|
||||
* @param id the id of the contact we're looking for.
|
||||
* @return ContactDictImpl
|
||||
*/
|
||||
public ContactDictImpl findContactByID(String id)
|
||||
{
|
||||
//first go through the contacts that are direct children.
|
||||
Iterator<Contact> contactsIter = contacts();
|
||||
|
||||
while(contactsIter.hasNext())
|
||||
{
|
||||
ContactDictImpl mContact = (ContactDictImpl)contactsIter.next();
|
||||
|
||||
if( mContact.getAddress().equals(id) )
|
||||
return mContact;
|
||||
}
|
||||
|
||||
//if we didn't find it here, let's try in the subougroups
|
||||
Iterator<ContactGroup> groupsIter = subgroups();
|
||||
|
||||
while( groupsIter.hasNext() )
|
||||
{
|
||||
ContactGroupDictImpl mGroup = (ContactGroupDictImpl)groupsIter.next();
|
||||
|
||||
ContactDictImpl mContact = mGroup.findContactByID(id);
|
||||
|
||||
if (mContact != null)
|
||||
return mContact;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns a String representation of this group and the contacts it
|
||||
* contains (may turn out to be a relatively long string).
|
||||
* @return a String representing this group and its child contacts.
|
||||
*/
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
|
||||
StringBuffer buff = new StringBuffer(getGroupName());
|
||||
buff.append(".subGroups=" + countSubgroups() + ":\n");
|
||||
|
||||
Iterator<ContactGroup> subGroups = subgroups();
|
||||
while (subGroups.hasNext())
|
||||
{
|
||||
ContactGroupDictImpl group = (ContactGroupDictImpl)subGroups.next();
|
||||
buff.append(group.toString());
|
||||
if (subGroups.hasNext())
|
||||
buff.append("\n");
|
||||
}
|
||||
|
||||
buff.append("\nChildContacts="+countContacts()+":[");
|
||||
|
||||
Iterator<Contact> contacts = contacts();
|
||||
while (contacts.hasNext())
|
||||
{
|
||||
ContactDictImpl contact = (ContactDictImpl) contacts.next();
|
||||
buff.append(contact.toString());
|
||||
if(contacts.hasNext())
|
||||
buff.append(", ");
|
||||
}
|
||||
return buff.append("]").toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Specifies whether or not this contact group is being stored by the server.
|
||||
* Non persistent contact groups are common in the case of simple,
|
||||
* non-persistent presence operation sets. They could however also be seen
|
||||
* in persistent presence operation sets when for example we have received
|
||||
* an event from someone not on our contact list and the contact that we
|
||||
* associated with that user is placed in a non persistent group. Non
|
||||
* persistent contact groups are volatile even when coming from a persistent
|
||||
* presence op. set. They would only exist until the application is closed
|
||||
* and will not be there next time it is loaded.
|
||||
*
|
||||
* @param isPersistent true if the contact group is to be persistent and
|
||||
* false otherwise.
|
||||
*/
|
||||
public void setPersistent(boolean isPersistent)
|
||||
{
|
||||
this.isPersistent = isPersistent;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines whether or not this contact group is being stored by the
|
||||
* server. Non persistent contact groups exist for the sole purpose of
|
||||
* containing non persistent contacts.
|
||||
* @return true if the contact group is persistent and false otherwise.
|
||||
*/
|
||||
public boolean isPersistent()
|
||||
{
|
||||
return isPersistent;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns null as no persistent data is required and the contact address is
|
||||
* sufficient for restoring the contact.
|
||||
* <p>
|
||||
* @return null as no such data is needed.
|
||||
*/
|
||||
public String getPersistentData()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines whether or not this contact has been resolved against the
|
||||
* server. Unresolved contacts are used when initially loading a contact
|
||||
* list that has been stored in a local file until the presence operation
|
||||
* set has managed to retrieve all the contact list from the server and has
|
||||
* properly mapped contacts to their on-line buddies.
|
||||
* @return true if the contact has been resolved (mapped against a buddy)
|
||||
* and false otherwise.
|
||||
*/
|
||||
public boolean isResolved()
|
||||
{
|
||||
return isResolved;
|
||||
}
|
||||
|
||||
/**
|
||||
* Makes the group resolved or unresolved.
|
||||
*
|
||||
* @param resolved true to make the group resolved; false to
|
||||
* make it unresolved
|
||||
*/
|
||||
public void setResolved(boolean resolved)
|
||||
{
|
||||
this.isResolved = resolved;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a <tt>String</tt> that uniquely represnets the group inside
|
||||
* the current protocol. The string MUST be persistent (it must not change
|
||||
* across connections or runs of the application). In many cases (Jabber,
|
||||
* ICQ) the string may match the name of the group as these protocols
|
||||
* only allow a single level of contact groups and there is no danger of
|
||||
* having the same name twice in the same contact list. Other protocols
|
||||
* (no examples come to mind but that doesn't bother me ;) ) may be
|
||||
* supporting mutilple levels of grooups so it might be possible for group
|
||||
* A and group B to both contain groups named C. In such cases the
|
||||
* implementation must find a way to return a unique identifier in this
|
||||
* method and this UID should never change for a given group.
|
||||
*
|
||||
* @return a String representing this group in a unique and persistent
|
||||
* way.
|
||||
*/
|
||||
public String getUID()
|
||||
{
|
||||
return uid;
|
||||
}
|
||||
|
||||
/**
|
||||
* Ugly but tricky conversion method.
|
||||
* @param uid the uid we'd like to get a name from
|
||||
* @return the name of the group with the specified <tt>uid</tt>.
|
||||
*/
|
||||
static String createNameFromUID(String uid)
|
||||
{
|
||||
return uid.substring(0, uid.length() - (UID_SUFFIX.length()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicates whether some other object is "equal to" this one which in terms
|
||||
* of contact groups translates to having the equal names and matching
|
||||
* subgroups and child contacts. The resolved status of contactgroups and
|
||||
* contacts is deliberately ignored so that groups and/or contacts would
|
||||
* be assumed equal even if it differs.
|
||||
* <p>
|
||||
* @param obj the reference object with which to compare.
|
||||
* @return <code>true</code> if this contact group has the equal child
|
||||
* contacts and subgroups to those of the <code>obj</code> argument.
|
||||
*/
|
||||
@Override
|
||||
public boolean equals(Object obj)
|
||||
{
|
||||
if(obj == null
|
||||
|| !(obj instanceof ContactGroupDictImpl))
|
||||
return false;
|
||||
|
||||
ContactGroupDictImpl dictGroup
|
||||
= (ContactGroupDictImpl)obj;
|
||||
|
||||
if( ! dictGroup.getGroupName().equals(getGroupName())
|
||||
|| ! dictGroup.getUID().equals(getUID())
|
||||
|| dictGroup.countContacts() != countContacts()
|
||||
|| dictGroup.countSubgroups() != countSubgroups())
|
||||
return false;
|
||||
|
||||
//traverse child contacts
|
||||
Iterator<Contact> theirContacts = dictGroup.contacts();
|
||||
|
||||
while(theirContacts.hasNext())
|
||||
{
|
||||
ContactDictImpl theirContact
|
||||
= (ContactDictImpl)theirContacts.next();
|
||||
|
||||
ContactDictImpl ourContact
|
||||
= (ContactDictImpl)getContact(theirContact.getAddress());
|
||||
|
||||
if(ourContact == null
|
||||
|| !ourContact.equals(theirContact))
|
||||
return false;
|
||||
}
|
||||
|
||||
//traverse subgroups
|
||||
Iterator<ContactGroup> theirSubgroups = dictGroup.subgroups();
|
||||
|
||||
while(theirSubgroups.hasNext())
|
||||
{
|
||||
ContactGroupDictImpl theirSubgroup
|
||||
= (ContactGroupDictImpl)theirSubgroups.next();
|
||||
|
||||
ContactGroupDictImpl ourSubgroup
|
||||
= (ContactGroupDictImpl)getGroup(
|
||||
theirSubgroup.getGroupName());
|
||||
|
||||
if(ourSubgroup == null
|
||||
|| !ourSubgroup.equals(theirSubgroup))
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,70 +0,0 @@
|
||||
/*
|
||||
* Jitsi, the OpenSource Java VoIP and Instant Messaging client.
|
||||
*
|
||||
* Copyright @ 2015 Atlassian Pty Ltd
|
||||
*
|
||||
* 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 net.java.sip.communicator.impl.protocol.dict;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import net.java.sip.communicator.service.protocol.*;
|
||||
|
||||
/**
|
||||
* The Dict implementation of a sip-communicator account id.
|
||||
* @author LITZELMANN Cedric
|
||||
* @author ROTH Damien
|
||||
*/
|
||||
public class DictAccountID
|
||||
extends AccountID
|
||||
{
|
||||
/**
|
||||
* Creates an account id from the specified id and account properties.
|
||||
*
|
||||
* @param userID the user identifier correspnding to the account
|
||||
* @param accountProperties any other properties necessary for the account.
|
||||
*/
|
||||
DictAccountID(String userID, Map<String, String> accountProperties)
|
||||
{
|
||||
super(userID, accountProperties, ProtocolNames.DICT, "dict.org");
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the dict server adress
|
||||
* @return the dict server adress
|
||||
*/
|
||||
public String getHost()
|
||||
{
|
||||
return getAccountPropertyString(ProtocolProviderFactory.SERVER_ADDRESS);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the dict server port
|
||||
* @return the dict server port
|
||||
*/
|
||||
public int getPort()
|
||||
{
|
||||
return Integer
|
||||
.parseInt(getAccountPropertyString(ProtocolProviderFactory.SERVER_PORT));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the selected strategy
|
||||
* @return the selected strategy
|
||||
*/
|
||||
public String getStrategy()
|
||||
{
|
||||
return getAccountPropertyString(ProtocolProviderFactory.STRATEGY);
|
||||
}
|
||||
}
|
||||
@ -1,146 +0,0 @@
|
||||
/*
|
||||
* Jitsi, the OpenSource Java VoIP and Instant Messaging client.
|
||||
*
|
||||
* Copyright @ 2015 Atlassian Pty Ltd
|
||||
*
|
||||
* 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 net.java.sip.communicator.impl.protocol.dict;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import net.java.sip.communicator.service.protocol.*;
|
||||
import net.java.sip.communicator.util.*;
|
||||
|
||||
import org.jitsi.service.resources.*;
|
||||
import org.osgi.framework.*;
|
||||
|
||||
/**
|
||||
* Loads the Dict provider factory and registers its services in the OSGI
|
||||
* bundle context.
|
||||
*
|
||||
* @author ROTH Damien
|
||||
* @author LITZELMANN Cedric
|
||||
*/
|
||||
public class DictActivator
|
||||
implements BundleActivator
|
||||
{
|
||||
private static final Logger logger = Logger.getLogger(DictActivator.class);
|
||||
|
||||
/**
|
||||
* The currently valid bundle context.
|
||||
*/
|
||||
private static BundleContext bundleContext = null;
|
||||
|
||||
private ServiceRegistration dictPpFactoryServReg = null;
|
||||
private static ProtocolProviderFactoryDictImpl
|
||||
dictProviderFactory = null;
|
||||
|
||||
private static ResourceManagementService resourceService;
|
||||
|
||||
/**
|
||||
* Called when this bundle is started. In here we'll export the
|
||||
* dict ProtocolProviderFactory implementation so that it could be
|
||||
* possible to register accounts with it in SIP Communicator.
|
||||
*
|
||||
* @param context The execution context of the bundle being started.
|
||||
* @throws Exception If this method throws an exception, this bundle is
|
||||
* marked as stopped and the Framework will remove this bundle's
|
||||
* listeners, unregister all services registered by this bundle, and
|
||||
* release all services used by this bundle.
|
||||
*/
|
||||
public void start(BundleContext context)
|
||||
throws Exception
|
||||
{
|
||||
bundleContext = context;
|
||||
|
||||
Hashtable<String,String> hashtable = new Hashtable<String,String>();
|
||||
hashtable.put(ProtocolProviderFactory.PROTOCOL, ProtocolNames.DICT);
|
||||
|
||||
dictProviderFactory = new ProtocolProviderFactoryDictImpl();
|
||||
|
||||
//reg the dict provider factory.
|
||||
dictPpFactoryServReg = context.registerService(
|
||||
ProtocolProviderFactory.class.getName(),
|
||||
dictProviderFactory,
|
||||
hashtable);
|
||||
|
||||
if (logger.isInfoEnabled())
|
||||
logger.info("DICT protocol implementation [STARTED].");
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a reference to the bundle context that we were started with.
|
||||
* @return a reference to the BundleContext instance that we were started
|
||||
* witn.
|
||||
*/
|
||||
public static BundleContext getBundleContext()
|
||||
{
|
||||
return bundleContext;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when this bundle is stopped so the Framework can perform the
|
||||
* bundle-specific activities necessary to stop the bundle.
|
||||
*
|
||||
* @param context The execution context of the bundle being stopped.
|
||||
* @throws Exception If this method throws an exception, the bundle is
|
||||
* still marked as stopped, and the Framework will remove the bundle's
|
||||
* listeners, unregister all services registered by the bundle, and
|
||||
* release all services used by the bundle.
|
||||
*/
|
||||
public void stop(BundleContext context)
|
||||
throws Exception
|
||||
{
|
||||
|
||||
dictProviderFactory.stop();
|
||||
dictPpFactoryServReg.unregister();
|
||||
|
||||
if (logger.isInfoEnabled())
|
||||
logger.info("DICT protocol implementation [STOPPED].");
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a reference to the protocol provider factory that we have
|
||||
* registered.
|
||||
* @return a reference to the <tt>ProtocolProviderFactoryDictImpl</tt>
|
||||
* instance that we have registered from this package.
|
||||
*/
|
||||
public static ProtocolProviderFactoryDictImpl getProtocolProviderFactory()
|
||||
{
|
||||
return dictProviderFactory;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns the <tt>ResourceManagementService</tt>.
|
||||
*
|
||||
* @return the <tt>ResourceManagementService</tt>.
|
||||
*/
|
||||
public static ResourceManagementService getResources()
|
||||
{
|
||||
if (resourceService == null)
|
||||
{
|
||||
ServiceReference serviceReference = bundleContext
|
||||
.getServiceReference(ResourceManagementService.class.getName());
|
||||
|
||||
if(serviceReference == null)
|
||||
return null;
|
||||
|
||||
resourceService = (ResourceManagementService) bundleContext
|
||||
.getService(serviceReference);
|
||||
}
|
||||
|
||||
return resourceService;
|
||||
}
|
||||
}
|
||||
@ -1,88 +0,0 @@
|
||||
/*
|
||||
* Jitsi, the OpenSource Java VoIP and Instant Messaging client.
|
||||
*
|
||||
* Copyright @ 2015 Atlassian Pty Ltd
|
||||
*
|
||||
* 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 net.java.sip.communicator.impl.protocol.dict;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import net.java.sip.communicator.service.protocol.*;
|
||||
|
||||
/**
|
||||
* An implementation of <tt>PresenceStatus</tt> that enumerates all states that
|
||||
* a Dict contact can fall into.
|
||||
*
|
||||
* @author ROTH Damien
|
||||
* @author LITZELMANN Cedric
|
||||
*/
|
||||
public class DictStatusEnum
|
||||
extends PresenceStatus
|
||||
{
|
||||
|
||||
/**
|
||||
* Indicates an Offline status or status with 0 connectivity.
|
||||
*/
|
||||
public static final DictStatusEnum OFFLINE
|
||||
= new DictStatusEnum(
|
||||
0, "Offline",
|
||||
DictActivator.getResources()
|
||||
.getImageInBytes("service.protocol.dict.OFFLINE_STATUS_ICON"));
|
||||
|
||||
/**
|
||||
* The Online status. Indicate that the user is able and willing to
|
||||
* communicate.
|
||||
*/
|
||||
public static final DictStatusEnum ONLINE
|
||||
= new DictStatusEnum(
|
||||
65, "Online",
|
||||
DictActivator.getResources()
|
||||
.getImageInBytes("service.protocol.dict.DICT_16x16"));
|
||||
|
||||
/**
|
||||
* Initialize the list of supported status states.
|
||||
*/
|
||||
private static List<PresenceStatus> supportedStatusSet = new LinkedList<PresenceStatus>();
|
||||
static
|
||||
{
|
||||
supportedStatusSet.add(OFFLINE);
|
||||
supportedStatusSet.add(ONLINE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an instance of <tt>RssPresneceStatus</tt> with the
|
||||
* specified parameters.
|
||||
* @param status the connectivity level of the new presence status instance
|
||||
* @param statusName the name of the presence status.
|
||||
* @param statusIcon the icon associated with this status
|
||||
*/
|
||||
private DictStatusEnum(int status,
|
||||
String statusName,
|
||||
byte[] statusIcon)
|
||||
{
|
||||
super(status, statusName, statusIcon);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an iterator over all status instances supproted by the rss
|
||||
* provider.
|
||||
* @return an <tt>Iterator</tt> over all status instances supported by the
|
||||
* rss provider.
|
||||
*/
|
||||
static Iterator<PresenceStatus> supportedStatusSet()
|
||||
{
|
||||
return supportedStatusSet.iterator();
|
||||
}
|
||||
}
|
||||
@ -1,46 +0,0 @@
|
||||
/*
|
||||
* Jitsi, the OpenSource Java VoIP and Instant Messaging client.
|
||||
*
|
||||
* Copyright @ 2015 Atlassian Pty Ltd
|
||||
*
|
||||
* 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 net.java.sip.communicator.impl.protocol.dict;
|
||||
|
||||
import net.java.sip.communicator.service.protocol.*;
|
||||
|
||||
/**
|
||||
* Very simple message implementation for the Dict protocol.
|
||||
*
|
||||
* @author ROTH Damien
|
||||
* @author LITZELMANN Cedric
|
||||
* @author Lubomir Marinov
|
||||
*/
|
||||
public class MessageDictImpl
|
||||
extends AbstractMessage
|
||||
{
|
||||
|
||||
/**
|
||||
* Creates a message instance according to the specified parameters.
|
||||
*
|
||||
* @param content the message body
|
||||
* @param contentType message content type or null for text/plain
|
||||
* @param contentEncoding message encoding or null for UTF8
|
||||
* @param subject the subject of the message or null for no subject.
|
||||
*/
|
||||
public MessageDictImpl(String content, String contentType,
|
||||
String contentEncoding, String subject)
|
||||
{
|
||||
super(content, contentType, contentEncoding, subject);
|
||||
}
|
||||
}
|
||||
@ -1,412 +0,0 @@
|
||||
/*
|
||||
* Jitsi, the OpenSource Java VoIP and Instant Messaging client.
|
||||
*
|
||||
* Copyright @ 2015 Atlassian Pty Ltd
|
||||
*
|
||||
* 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 net.java.sip.communicator.impl.protocol.dict;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import net.java.dict4j.*;
|
||||
import net.java.sip.communicator.service.protocol.*;
|
||||
import net.java.sip.communicator.service.protocol.event.*;
|
||||
import net.java.sip.communicator.util.*;
|
||||
|
||||
/**
|
||||
* Instant messaging functionalities for the Dict protocol.
|
||||
*
|
||||
* @author ROTH Damien
|
||||
* @author LITZELMANN Cedric
|
||||
*/
|
||||
public class OperationSetBasicInstantMessagingDictImpl
|
||||
extends AbstractOperationSetBasicInstantMessaging
|
||||
implements RegistrationStateChangeListener
|
||||
{
|
||||
/**
|
||||
* The currently valid persistent presence operation set.
|
||||
*/
|
||||
private OperationSetPersistentPresenceDictImpl opSetPersPresence = null;
|
||||
|
||||
/**
|
||||
* The protocol provider that created us.
|
||||
*/
|
||||
private ProtocolProviderServiceDictImpl parentProvider = null;
|
||||
|
||||
private DictAccountID accountID;
|
||||
|
||||
/**
|
||||
* Creates an instance of this operation set keeping a reference to the
|
||||
* parent protocol provider and presence operation set.
|
||||
*
|
||||
* @param provider The provider instance that creates us.
|
||||
* @param opSetPersPresence the currently valid
|
||||
* <tt>OperationSetPersistentPresenceDictImpl</tt> instance.
|
||||
*/
|
||||
public OperationSetBasicInstantMessagingDictImpl(
|
||||
ProtocolProviderServiceDictImpl provider,
|
||||
OperationSetPersistentPresenceDictImpl opSetPersPresence)
|
||||
{
|
||||
this.opSetPersPresence = opSetPersPresence;
|
||||
this.parentProvider = provider;
|
||||
this.accountID = (DictAccountID) provider.getAccountID();
|
||||
|
||||
parentProvider.addRegistrationStateChangeListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Message createMessage(String content)
|
||||
{
|
||||
return new MessageDictImpl(content, HTML_MIME_TYPE,
|
||||
DEFAULT_MIME_ENCODING, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Message createMessage(String content, String contentType,
|
||||
String encoding, String subject)
|
||||
{
|
||||
return new MessageDictImpl(content, contentType, encoding, subject);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends the <tt>message</tt> to the destination indicated by the
|
||||
* <tt>to</tt> contact.
|
||||
*
|
||||
* @param to the <tt>Contact</tt> to send <tt>message</tt> to
|
||||
* @param message the <tt>Message</tt> to send.
|
||||
* @throws IllegalStateException if the underlying ICQ stack is not
|
||||
* registered and initialized.
|
||||
* @throws IllegalArgumentException if <tt>to</tt> is not an instance
|
||||
* belonging to the underlying implementation.
|
||||
*/
|
||||
public void sendInstantMessage(Contact to, Message message)
|
||||
throws IllegalStateException,
|
||||
IllegalArgumentException
|
||||
{
|
||||
if( !(to instanceof ContactDictImpl) )
|
||||
{
|
||||
throw new IllegalArgumentException(
|
||||
"The specified contact is not a Dict contact."
|
||||
+ to);
|
||||
}
|
||||
|
||||
// Remove all html tags from the message
|
||||
message = createMessage(Html2Text.extractText(message.getContent()));
|
||||
|
||||
// Display the queried word
|
||||
fireMessageDelivered(message, to);
|
||||
|
||||
this.submitDictQuery((ContactDictImpl) to, message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines whether the protocol provider (or the protocol itself) supports
|
||||
* sending and receiving offline messages. Most often this method would
|
||||
* return true for protocols that support offline messages and false for
|
||||
* those that don't. It is however possible for a protocol to support these
|
||||
* messages and yet have a particular account that does not (i.e. feature
|
||||
* not enabled on the protocol server). In cases like this it is possible
|
||||
* for this method to return true even when offline messaging is not
|
||||
* supported, and then have the sendMessage method throw an
|
||||
* OperationFailedException with code - OFFLINE_MESSAGES_NOT_SUPPORTED.
|
||||
*
|
||||
* @return <tt>true</tt> if the protocol supports offline messages and
|
||||
* <tt>false</tt> otherwise.
|
||||
*/
|
||||
public boolean isOfflineMessagingSupported()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines whether the protocol supports the supplied content type.
|
||||
*
|
||||
* @param contentType the type we want to check
|
||||
* @return <tt>true</tt> if the protocol supports it and
|
||||
* <tt>false</tt> otherwise.
|
||||
*/
|
||||
public boolean isContentTypeSupported(String contentType)
|
||||
{
|
||||
if(contentType.equals(DEFAULT_MIME_TYPE))
|
||||
return true;
|
||||
else if(contentType.equals(HTML_MIME_TYPE))
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the protocol provider that this operation set belongs to.
|
||||
*
|
||||
* @return a reference to the <tt>ProtocolProviderServiceDictImpl</tt>
|
||||
* instance that this operation set belongs to.
|
||||
*/
|
||||
public ProtocolProviderServiceDictImpl getParentProvider()
|
||||
{
|
||||
return this.parentProvider;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a reference to the presence operation set instance used by our
|
||||
* source provider.
|
||||
*
|
||||
* @return a reference to the <tt>OperationSetPersistentPresenceDictImpl</tt>
|
||||
* instance used by this provider.
|
||||
*/
|
||||
public OperationSetPersistentPresenceDictImpl getOpSetPersPresence()
|
||||
{
|
||||
return this.opSetPersPresence;
|
||||
}
|
||||
|
||||
/**
|
||||
* The method is called by the ProtocolProvider whenever a change in the
|
||||
* registration state of the corresponding provider has occurred.
|
||||
*
|
||||
* @param evt ProviderStatusChangeEvent the event describing the status
|
||||
* change.
|
||||
*/
|
||||
public void registrationStateChanged(RegistrationStateChangeEvent evt)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Create, execute and display a query to a dictionary (ContactDictImpl)
|
||||
*
|
||||
* @param dictContact the contact containing the database name
|
||||
* @param message the message containing the word
|
||||
*/
|
||||
private void submitDictQuery(ContactDictImpl dictContact, Message message)
|
||||
{
|
||||
Message msg = this.createMessage("");
|
||||
|
||||
String database = dictContact.getContactID();
|
||||
DictConnection conn = this.parentProvider.getConnection();
|
||||
boolean doMatch = false;
|
||||
|
||||
String word;
|
||||
|
||||
// Formatting the query message, if the word as one or more spaces we
|
||||
// put it between quotes to prevent errors
|
||||
word = message.getContent().replace("\"", "").trim();
|
||||
if (word.indexOf(' ') > 0)
|
||||
{
|
||||
word = "\"" + word + "\"";
|
||||
}
|
||||
|
||||
// Try to get the definition of the work
|
||||
try
|
||||
{
|
||||
List<Definition> definitions = conn.define(database, word);
|
||||
msg = this.createMessage(retrieveDefine(definitions, word));
|
||||
}
|
||||
catch(DictException dx)
|
||||
{
|
||||
if (dx.getErrorCode() == DictReturnCode.NO_MATCH)
|
||||
{ // No word found, we are going to try the match command
|
||||
doMatch = true;
|
||||
}
|
||||
else
|
||||
{ // Otherwise we display the error returned by the server
|
||||
msg = this.createMessage(manageException(dx, database));
|
||||
}
|
||||
}
|
||||
|
||||
if (doMatch)
|
||||
{
|
||||
// Trying the match command
|
||||
try
|
||||
{
|
||||
List<MatchWord> matchWords = conn.match(database, word,
|
||||
this.accountID.getStrategy());
|
||||
msg = this.createMessage(retrieveMatch(matchWords, word));
|
||||
}
|
||||
catch(DictException dx)
|
||||
{
|
||||
msg = this.createMessage(manageException(dx, database));
|
||||
}
|
||||
}
|
||||
|
||||
// Send message
|
||||
fireMessageReceived(msg, dictContact);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate the display of the results of the Define command
|
||||
*
|
||||
* @param data the result of the Define command
|
||||
* @param word the queried word
|
||||
* @return the formatted result
|
||||
*/
|
||||
private String retrieveDefine(List<Definition> data, String word)
|
||||
{
|
||||
StringBuffer res = new StringBuffer();
|
||||
Definition def;
|
||||
|
||||
for (int i=0; i<data.size(); i++)
|
||||
{
|
||||
def = data.get(i);
|
||||
|
||||
if(i != 0 && data.size() > 0)
|
||||
{
|
||||
res.append("<hr>");
|
||||
}
|
||||
res.append(def.getDefinition().replaceAll("\n", "<br>"))
|
||||
.append("<div align=\"right\"><font size=\"-2\">-- From ")
|
||||
.append(def.getDictionary())
|
||||
.append("</font></div>");
|
||||
}
|
||||
|
||||
String result = res.toString();
|
||||
result = formatResult(result, "\\\\", "<em>", "</em>");
|
||||
result = formatResult(result, "[\\[\\]]", "<cite>", "</cite>");
|
||||
result = formatResult(result, "[\\{\\}]", "<strong>", "</strong>");
|
||||
result = formatWordDefined(result, word);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Makes a stronger emphasis for the word defined.
|
||||
* @param result The text containing the definition of the word.
|
||||
* @param word The word defined to display with bold font. For this we
|
||||
* had the strong HTML tag.
|
||||
* @return Returns the result text with an strong emphasis of all
|
||||
* the occurences of the word defined.
|
||||
*/
|
||||
private String formatWordDefined(String result, String word)
|
||||
{
|
||||
String tmpWord;
|
||||
|
||||
tmpWord = word.toUpperCase();
|
||||
result = result.replaceAll("\\b" + tmpWord + "\\b", "<strong>" + tmpWord + "</strong>");
|
||||
tmpWord = word.toLowerCase();
|
||||
result = result.replaceAll("\\b" + tmpWord + "\\b", "<strong>" + tmpWord + "</strong>");
|
||||
if(tmpWord.length() > 1)
|
||||
{
|
||||
tmpWord = tmpWord.substring(0, 1).toUpperCase() + tmpWord.substring(1);
|
||||
result = result.replaceAll("\\b" + tmpWord + "\\b", "<strong>" + tmpWord + "</strong>");
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remplaces special characters into HTML tags to make some emphasis.
|
||||
* @param result The text containing the definition of the word.
|
||||
* @param regex The special character to replace with HTML tags.
|
||||
* @param startTag The start HTML tag to use.
|
||||
* @param endTag The end HTML tag to use.
|
||||
* @return The result with all special characters replaced by HTML
|
||||
* tags.
|
||||
*/
|
||||
private String formatResult(String result, String regex, String startTag, String endTag)
|
||||
{
|
||||
String[] tmp = result.split(regex);
|
||||
String res = "";
|
||||
|
||||
for(int i = 0; i < (tmp.length - 1); i += 2)
|
||||
{
|
||||
res += tmp[i] + startTag + tmp[i+1] + endTag;
|
||||
}
|
||||
if((tmp.length % 2) != 0)
|
||||
{
|
||||
res += tmp[tmp.length - 1];
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate the display of the results of the Match command
|
||||
*
|
||||
* @param data the result of the Match command
|
||||
* @param word the queried word
|
||||
* @return the formatted result
|
||||
*/
|
||||
private String retrieveMatch(List<MatchWord> data, String word)
|
||||
{
|
||||
StringBuffer result = new StringBuffer();
|
||||
boolean isStart = true;
|
||||
|
||||
result.append(DictActivator.getResources()
|
||||
.getI18NString("plugin.dictaccregwizz.MATCH_RESULT", new String[] {word}));
|
||||
|
||||
for (int i=0; i<data.size(); i++)
|
||||
{
|
||||
if (isStart)
|
||||
isStart = false;
|
||||
else
|
||||
result.append(", ");
|
||||
|
||||
result.append(data.get(i).getWord());
|
||||
}
|
||||
|
||||
return result.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Manages the return exception of a dict query.
|
||||
*
|
||||
* @param dix The exception returned by the adapter
|
||||
* @param database The dictionary used
|
||||
* @return Exception message
|
||||
*/
|
||||
private String manageException(DictException dix, String database)
|
||||
{
|
||||
int errorCode = dix.getErrorCode();
|
||||
|
||||
// We change the text only for exception 550 (invalid dictionary) and 551 (invalid strategy)
|
||||
if (errorCode == DictReturnCode.INVALID_DATABASE)
|
||||
{
|
||||
return DictActivator.getResources()
|
||||
.getI18NString("plugin.dictaccregwizz.INVALID_DATABASE", new String[] {database});
|
||||
}
|
||||
else if (errorCode == DictReturnCode.INVALID_STRATEGY)
|
||||
{
|
||||
return DictActivator.getResources()
|
||||
.getI18NString("plugin.dictaccregwizz.INVALID_STRATEGY");
|
||||
}
|
||||
else if (errorCode == DictReturnCode.NO_MATCH)
|
||||
{
|
||||
return DictActivator.getResources()
|
||||
.getI18NString("plugin.dictaccregwizz.NO_MATCH");
|
||||
}
|
||||
|
||||
return dix.getMessage();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends the <tt>message</tt> to the destination indicated by the
|
||||
* <tt>to</tt>. Resources are not supported by this operation set
|
||||
* implementation.
|
||||
*
|
||||
* @param to the <tt>Contact</tt> to send <tt>message</tt> to
|
||||
* @param toResource the resource to which the message should be send
|
||||
* @param message the <tt>Message</tt> to send.
|
||||
* @throws java.lang.IllegalStateException if the underlying ICQ stack is
|
||||
* not registered and initialized.
|
||||
* @throws java.lang.IllegalArgumentException if <tt>to</tt> is not an
|
||||
* instance belonging to the underlying implementation.
|
||||
*/
|
||||
@Override
|
||||
public void sendInstantMessage( Contact to,
|
||||
ContactResource toResource,
|
||||
Message message)
|
||||
throws IllegalStateException,
|
||||
IllegalArgumentException
|
||||
{
|
||||
sendInstantMessage(to, message);
|
||||
}
|
||||
}
|
||||
@ -1,988 +0,0 @@
|
||||
/*
|
||||
* Jitsi, the OpenSource Java VoIP and Instant Messaging client.
|
||||
*
|
||||
* Copyright @ 2015 Atlassian Pty Ltd
|
||||
*
|
||||
* 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 net.java.sip.communicator.impl.protocol.dict;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import net.java.sip.communicator.service.protocol.*;
|
||||
import net.java.sip.communicator.service.protocol.event.*;
|
||||
import net.java.sip.communicator.util.*;
|
||||
|
||||
import org.osgi.framework.*;
|
||||
|
||||
/**
|
||||
* A Dict implementation of a persistent presence operation set. In order
|
||||
* to simulate server persistence, this operation set would simply accept all
|
||||
* unresolved contacts and resolve them immediately. A real world protocol
|
||||
* implementation would save it on a server using methods provided by the
|
||||
* protocol stack.
|
||||
*
|
||||
* @author ROTH Damien
|
||||
* @author LITZELMANN Cedric
|
||||
*/
|
||||
public class OperationSetPersistentPresenceDictImpl
|
||||
extends AbstractOperationSetPersistentPresence<ProtocolProviderServiceDictImpl>
|
||||
{
|
||||
private static final Logger logger =
|
||||
Logger.getLogger(OperationSetPersistentPresenceDictImpl.class);
|
||||
|
||||
/**
|
||||
* The root of the dict contact list.
|
||||
*/
|
||||
private ContactGroupDictImpl contactListRoot = null;
|
||||
|
||||
/**
|
||||
* The currently active status message.
|
||||
*/
|
||||
private String statusMessage = "Default Status Message";
|
||||
|
||||
/**
|
||||
* Our presence status.
|
||||
*/
|
||||
private PresenceStatus presenceStatus = DictStatusEnum.ONLINE;
|
||||
|
||||
/**
|
||||
* The <tt>AuthorizationHandler</tt> instance that we'd have to transmit
|
||||
* authorization requests to for approval.
|
||||
*/
|
||||
private AuthorizationHandler authorizationHandler = null;
|
||||
|
||||
/**
|
||||
* Creates an instance of this operation set keeping a reference to the
|
||||
* specified parent <tt>provider</tt>.
|
||||
* @param provider the ProtocolProviderServiceDictImpl instance that
|
||||
* created us.
|
||||
*/
|
||||
public OperationSetPersistentPresenceDictImpl(
|
||||
ProtocolProviderServiceDictImpl provider)
|
||||
{
|
||||
super(provider);
|
||||
|
||||
contactListRoot = new ContactGroupDictImpl("RootGroup", provider);
|
||||
|
||||
//add our unregistration listener
|
||||
parentProvider.addRegistrationStateChangeListener(
|
||||
new UnregistrationListener());
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a group with the specified name and parent in the server
|
||||
* stored contact list.
|
||||
*
|
||||
* @param parent the group where the new group should be created
|
||||
* @param groupName the name of the new group to create.
|
||||
*/
|
||||
public void createServerStoredContactGroup(ContactGroup parent,
|
||||
String groupName)
|
||||
{
|
||||
ContactGroupDictImpl newGroup
|
||||
= new ContactGroupDictImpl(groupName, parentProvider);
|
||||
|
||||
((ContactGroupDictImpl)parent).addSubgroup(newGroup);
|
||||
|
||||
this.fireServerStoredGroupEvent(
|
||||
newGroup, ServerStoredGroupEvent.GROUP_CREATED_EVENT);
|
||||
}
|
||||
|
||||
/**
|
||||
* A Dict Provider method to use for fast filling of a contact list.
|
||||
*
|
||||
* @param contactGroup the group to add
|
||||
*/
|
||||
public void addDictGroup(ContactGroupDictImpl contactGroup)
|
||||
{
|
||||
contactListRoot.addSubgroup(contactGroup);
|
||||
}
|
||||
|
||||
/**
|
||||
* A Dict Provider method to use for fast filling of a contact list.
|
||||
* This method would add both the group and fire an event.
|
||||
*
|
||||
* @param parent the group where <tt>contactGroup</tt> should be added.
|
||||
* @param contactGroup the group to add
|
||||
*/
|
||||
public void addDictGroupAndFireEvent(
|
||||
ContactGroupDictImpl parent
|
||||
, ContactGroupDictImpl contactGroup)
|
||||
{
|
||||
parent.addSubgroup(contactGroup);
|
||||
|
||||
this.fireServerStoredGroupEvent(
|
||||
contactGroup, ServerStoredGroupEvent.GROUP_CREATED_EVENT);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns a reference to the contact with the specified ID in case we
|
||||
* have a subscription for it and null otherwise/
|
||||
*
|
||||
* @param contactID a String identifier of the contact which we're
|
||||
* seeking a reference of.
|
||||
* @return a reference to the Contact with the specified
|
||||
* <tt>contactID</tt> or null if we don't have a subscription for the
|
||||
* that identifier.
|
||||
*/
|
||||
public Contact findContactByID(String contactID)
|
||||
{
|
||||
return contactListRoot.findContactByID(contactID);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the specified status message.
|
||||
* @param statusMessage a String containing the new status message.
|
||||
*/
|
||||
public void setStatusMessage(String statusMessage)
|
||||
{
|
||||
this.statusMessage = statusMessage;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the status message that was last set through
|
||||
* setCurrentStatusMessage.
|
||||
*
|
||||
* @return the last status message that we have requested and the aim
|
||||
* server has confirmed.
|
||||
*/
|
||||
public String getCurrentStatusMessage()
|
||||
{
|
||||
return statusMessage;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the protocol specific contact instance representing the local
|
||||
* user.
|
||||
*
|
||||
* @return the Contact (address, phone number, or uin) that the Provider
|
||||
* implementation is communicating on behalf of.
|
||||
*/
|
||||
public Contact getLocalContact()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a PresenceStatus instance representing the state this provider
|
||||
* is currently in.
|
||||
*
|
||||
* @return the PresenceStatus last published by this provider.
|
||||
*/
|
||||
public PresenceStatus getPresenceStatus()
|
||||
{
|
||||
return presenceStatus;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the root group of the server stored contact list.
|
||||
*
|
||||
* @return the root ContactGroup for the ContactList stored by this
|
||||
* service.
|
||||
*/
|
||||
public ContactGroup getServerStoredContactListRoot()
|
||||
{
|
||||
return contactListRoot;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the set of PresenceStatus objects that a user of this service
|
||||
* may request the provider to enter.
|
||||
*
|
||||
* @return Iterator a PresenceStatus array containing "enterable" status
|
||||
* instances.
|
||||
*/
|
||||
public Iterator<PresenceStatus> getSupportedStatusSet()
|
||||
{
|
||||
return DictStatusEnum.supportedStatusSet();
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes the specified contact from its current parent and places it
|
||||
* under <tt>newParent</tt>.
|
||||
*
|
||||
* @param contactToMove the <tt>Contact</tt> to move
|
||||
* @param newParent the <tt>ContactGroup</tt> where <tt>Contact</tt>
|
||||
* would be placed.
|
||||
*/
|
||||
public void moveContactToGroup(Contact contactToMove,
|
||||
ContactGroup newParent)
|
||||
{
|
||||
ContactDictImpl dictContact
|
||||
= (ContactDictImpl)contactToMove;
|
||||
|
||||
ContactGroupDictImpl parentDictGroup
|
||||
= findContactParent(dictContact);
|
||||
|
||||
parentDictGroup.removeContact(dictContact);
|
||||
|
||||
//if this is a volatile contact then we haven't really subscribed to
|
||||
//them so we'd need to do so here
|
||||
if(!dictContact.isPersistent())
|
||||
{
|
||||
//first tell everyone that the volatile contact was removed
|
||||
fireSubscriptionEvent(dictContact
|
||||
, parentDictGroup
|
||||
, SubscriptionEvent.SUBSCRIPTION_REMOVED);
|
||||
|
||||
try
|
||||
{
|
||||
//now subscribe
|
||||
this.subscribe(newParent, contactToMove.getAddress());
|
||||
|
||||
//now tell everyone that we've added the contact
|
||||
fireSubscriptionEvent(dictContact
|
||||
, newParent
|
||||
, SubscriptionEvent.SUBSCRIPTION_CREATED);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.error("Failed to move contact "
|
||||
+ dictContact.getAddress()
|
||||
, ex);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
( (ContactGroupDictImpl) newParent)
|
||||
.addContact(dictContact);
|
||||
|
||||
fireSubscriptionMovedEvent(contactToMove
|
||||
, parentDictGroup
|
||||
, newParent);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Requests the provider to enter into a status corresponding to the
|
||||
* specified paramters.
|
||||
*
|
||||
* @param status the PresenceStatus as returned by
|
||||
* getRequestableStatusSet
|
||||
* @param statusMessage the message that should be set as the reason to
|
||||
* enter that status
|
||||
* @throws IllegalArgumentException if the status requested is not a
|
||||
* valid PresenceStatus supported by this provider.
|
||||
* @throws IllegalStateException if the provider is not currently
|
||||
* registered.
|
||||
* @throws OperationFailedException with code NETWORK_FAILURE if
|
||||
* publishing the status fails due to a network error.
|
||||
*/
|
||||
public void publishPresenceStatus(PresenceStatus status,
|
||||
String statusMessage) throws
|
||||
IllegalArgumentException, IllegalStateException,
|
||||
OperationFailedException
|
||||
{
|
||||
PresenceStatus oldPresenceStatus = this.presenceStatus;
|
||||
this.presenceStatus = status;
|
||||
this.statusMessage = statusMessage;
|
||||
|
||||
this.fireProviderStatusChangeEvent(oldPresenceStatus);
|
||||
|
||||
//since we are not a real protocol, we set the contact presence status
|
||||
//ourselves and make them have the same status as ours.
|
||||
changePresenceStatusForAllContacts( getServerStoredContactListRoot()
|
||||
, getPresenceStatus());
|
||||
|
||||
//now check whether we are in someone else's contact list and modify
|
||||
//our status there
|
||||
List<Contact> contacts = findContactsPointingToUs();
|
||||
|
||||
Iterator<Contact> contactsIter = contacts.iterator();
|
||||
while (contactsIter.hasNext())
|
||||
{
|
||||
ContactDictImpl contact
|
||||
= (ContactDictImpl) contactsIter.next();
|
||||
|
||||
PresenceStatus oldStatus = contact.getPresenceStatus();
|
||||
contact.setPresenceStatus(status);
|
||||
contact.getParentPresenceOperationSet()
|
||||
.fireContactPresenceStatusChangeEvent(
|
||||
contact
|
||||
, contact.getParentContactGroup()
|
||||
, oldStatus);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Get the PresenceStatus for a particular contact.
|
||||
*
|
||||
* @param contactIdentifier the identifier of the contact whose status
|
||||
* we're interested in.
|
||||
* @return PresenceStatus the <tt>PresenceStatus</tt> of the specified
|
||||
* <tt>contact</tt>
|
||||
* @throws IllegalArgumentException if <tt>contact</tt> is not a contact
|
||||
* known to the underlying protocol provider
|
||||
* @throws IllegalStateException if the underlying protocol provider is
|
||||
* not registered/signed on a public service.
|
||||
* @throws OperationFailedException with code NETWORK_FAILURE if
|
||||
* retrieving the status fails due to errors experienced during
|
||||
* network communication
|
||||
*/
|
||||
public PresenceStatus queryContactStatus(String contactIdentifier) throws
|
||||
IllegalArgumentException, IllegalStateException,
|
||||
OperationFailedException
|
||||
{
|
||||
return findContactByID(contactIdentifier).getPresenceStatus();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the presence status of <tt>contact</tt> to <tt>newStatus</tt>.
|
||||
*
|
||||
* @param contact the <tt>ContactDictImpl</tt> whose status we'd like
|
||||
* to set.
|
||||
* @param newStatus the new status we'd like to set to <tt>contact</tt>.
|
||||
*/
|
||||
private void changePresenceStatusForContact(
|
||||
ContactDictImpl contact
|
||||
, PresenceStatus newStatus)
|
||||
{
|
||||
PresenceStatus oldStatus = contact.getPresenceStatus();
|
||||
contact.setPresenceStatus(newStatus);
|
||||
|
||||
fireContactPresenceStatusChangeEvent(
|
||||
contact, findContactParent(contact), oldStatus);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the presence status of all <tt>contact</tt>s in our contact list
|
||||
* (except those that correspond to another provider registered with SC)
|
||||
* to <tt>newStatus</tt>.
|
||||
*
|
||||
* @param newStatus the new status we'd like to set to <tt>contact</tt>.
|
||||
* @param parent the group in which we'd have to update the status of all
|
||||
* direct and indirect child contacts.
|
||||
*/
|
||||
private void changePresenceStatusForAllContacts(ContactGroup parent,
|
||||
PresenceStatus newStatus)
|
||||
{
|
||||
//first set the status for contacts in this group
|
||||
Iterator<Contact> childContacts = parent.contacts();
|
||||
|
||||
while(childContacts.hasNext())
|
||||
{
|
||||
ContactDictImpl contact
|
||||
= (ContactDictImpl)childContacts.next();
|
||||
|
||||
if(findProviderForDictUserID(contact.getAddress()) != null)
|
||||
{
|
||||
//this is a contact corresponding to another SIP Communicator
|
||||
//provider so we won't change it's status here.
|
||||
continue;
|
||||
}
|
||||
PresenceStatus oldStatus = contact.getPresenceStatus();
|
||||
contact.setPresenceStatus(newStatus);
|
||||
|
||||
fireContactPresenceStatusChangeEvent(
|
||||
contact, parent, oldStatus);
|
||||
}
|
||||
|
||||
//now call this method recursively for all subgroups
|
||||
Iterator<ContactGroup> subgroups = parent.subgroups();
|
||||
|
||||
while(subgroups.hasNext())
|
||||
{
|
||||
ContactGroup subgroup = subgroups.next();
|
||||
changePresenceStatusForAllContacts(subgroup, newStatus);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the group that is parent of the specified dictGroup or null
|
||||
* if no parent was found.
|
||||
* @param dictGroup the group whose parent we're looking for.
|
||||
* @return the ContactGroupDictImpl instance that dictGroup
|
||||
* belongs to or null if no parent was found.
|
||||
*/
|
||||
public ContactGroupDictImpl findGroupParent(
|
||||
ContactGroupDictImpl dictGroup)
|
||||
{
|
||||
return contactListRoot.findGroupParent(dictGroup);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the group that is parent of the specified dictContact or
|
||||
* null if no parent was found.
|
||||
* @param dictContact the contact whose parent we're looking for.
|
||||
* @return the ContactGroupDictImpl instance that dictContact
|
||||
* belongs to or null if no parent was found.
|
||||
*/
|
||||
public ContactGroupDictImpl findContactParent(
|
||||
ContactDictImpl dictContact)
|
||||
{
|
||||
return (ContactGroupDictImpl)dictContact
|
||||
.getParentContactGroup();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Removes the specified group from the server stored contact list.
|
||||
*
|
||||
* @param group the group to remove.
|
||||
*
|
||||
* @throws IllegalArgumentException if <tt>group</tt> was not found in this
|
||||
* protocol's contact list.
|
||||
*/
|
||||
public void removeServerStoredContactGroup(ContactGroup group)
|
||||
throws IllegalArgumentException
|
||||
{
|
||||
ContactGroupDictImpl dictGroup
|
||||
= (ContactGroupDictImpl)group;
|
||||
|
||||
ContactGroupDictImpl parent = findGroupParent(dictGroup);
|
||||
|
||||
if(parent == null){
|
||||
throw new IllegalArgumentException(
|
||||
"group " + group
|
||||
+ " does not seem to belong to this protocol's contact list.");
|
||||
}
|
||||
|
||||
parent.removeSubGroup(dictGroup);
|
||||
|
||||
this.fireServerStoredGroupEvent(
|
||||
dictGroup, ServerStoredGroupEvent.GROUP_REMOVED_EVENT);
|
||||
}
|
||||
|
||||
/**
|
||||
* Renames the specified group from the server stored contact list.
|
||||
*
|
||||
* @param group the group to rename.
|
||||
* @param newName the new name of the group.
|
||||
*/
|
||||
public void renameServerStoredContactGroup(ContactGroup group,
|
||||
String newName)
|
||||
{
|
||||
((ContactGroupDictImpl)group).setGroupName(newName);
|
||||
|
||||
this.fireServerStoredGroupEvent(
|
||||
group, ServerStoredGroupEvent.GROUP_RENAMED_EVENT);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handler for incoming authorization requests.
|
||||
*
|
||||
* @param handler an instance of an AuthorizationHandler for
|
||||
* authorization requests coming from other users requesting
|
||||
* permission add us to their contact list.
|
||||
*/
|
||||
public void setAuthorizationHandler(AuthorizationHandler handler)
|
||||
{
|
||||
this.authorizationHandler = handler;
|
||||
}
|
||||
|
||||
/**
|
||||
* Persistently adds a subscription for the presence status of the
|
||||
* contact corresponding to the specified contactIdentifier and indicates
|
||||
* that it should be added to the specified group of the server stored
|
||||
* contact list.
|
||||
*
|
||||
* @param parent the parent group of the server stored contact list
|
||||
* where the contact should be added. <p>
|
||||
* @param contactIdentifier the contact whose status updates we are
|
||||
* subscribing for.
|
||||
* @throws IllegalArgumentException if <tt>contact</tt> or
|
||||
* <tt>parent</tt> are not a contact known to the underlying protocol
|
||||
* provider.
|
||||
* @throws IllegalStateException if the underlying protocol provider is
|
||||
* not registered/signed on a public service.
|
||||
* @throws OperationFailedException with code NETWORK_FAILURE if
|
||||
* subscribing fails due to errors experienced during network
|
||||
* communication
|
||||
*/
|
||||
public void subscribe(ContactGroup parent, String contactIdentifier) throws
|
||||
IllegalArgumentException, IllegalStateException,
|
||||
OperationFailedException
|
||||
{
|
||||
ContactDictImpl contact = new ContactDictImpl(
|
||||
contactIdentifier
|
||||
, parentProvider);
|
||||
|
||||
((ContactGroupDictImpl)parent).addContact(contact);
|
||||
|
||||
fireSubscriptionEvent(contact,
|
||||
parent,
|
||||
SubscriptionEvent.SUBSCRIPTION_CREATED);
|
||||
|
||||
//notify presence listeners for the status change.
|
||||
fireContactPresenceStatusChangeEvent(contact
|
||||
, parent
|
||||
, DictStatusEnum.ONLINE);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Depending on whether <tt>contact</tt> corresponds to another protocol
|
||||
* provider installed in sip-communicator, this method would either deliver
|
||||
* it to that provider or simulate a corresponding request from the
|
||||
* destination contact and make return a response after it has received
|
||||
* one If the destination contact matches us, then we'll ask the user to
|
||||
* act upon the request, and return the response.
|
||||
*
|
||||
* @param request the authorization request that we'd like to deliver to the
|
||||
* destination <tt>contact</tt>.
|
||||
* @param contact the <tt>Contact</tt> to notify
|
||||
*
|
||||
* @return the <tt>AuthorizationResponse</tt> that has been given or
|
||||
* generated in response to <tt>request</tt>.
|
||||
*/
|
||||
private AuthorizationResponse deliverAuthorizationRequest(
|
||||
AuthorizationRequest request,
|
||||
Contact contact)
|
||||
{
|
||||
String userID = contact.getAddress();
|
||||
|
||||
//if the user id is our own id, then this request is being routed to us
|
||||
//from another instance of the dict provider.
|
||||
if (userID.equals(this.parentProvider.getAccountID().getUserID()))
|
||||
{
|
||||
//check who is the provider sending the message
|
||||
String sourceUserID = contact.getProtocolProvider()
|
||||
.getAccountID().getUserID();
|
||||
|
||||
//check whether they are in our contact list
|
||||
Contact from = findContactByID(sourceUserID);
|
||||
|
||||
//and if not - add them there as volatile.
|
||||
if (from == null)
|
||||
{
|
||||
from = createVolatileContact(sourceUserID);
|
||||
}
|
||||
|
||||
//and now handle the request.
|
||||
return authorizationHandler.processAuthorisationRequest(
|
||||
request, from);
|
||||
}
|
||||
else
|
||||
{
|
||||
//if userID is not our own, try a check whether another provider
|
||||
//has that id and if yes - deliver the request to them.
|
||||
ProtocolProviderServiceDictImpl dictProvider
|
||||
= this.findProviderForDictUserID(userID);
|
||||
if (dictProvider != null)
|
||||
{
|
||||
OperationSetPersistentPresenceDictImpl opSetPersPresence
|
||||
= (OperationSetPersistentPresenceDictImpl)
|
||||
dictProvider.getOperationSet(
|
||||
OperationSetPersistentPresence.class);
|
||||
return opSetPersPresence
|
||||
.deliverAuthorizationRequest(request, contact);
|
||||
}
|
||||
else
|
||||
{
|
||||
//if we got here then "to" is simply someone in our contact
|
||||
//list so let's just simulate a reciproce request and generate
|
||||
//a response accordingly.
|
||||
|
||||
//pretend that the remote contact is asking for authorization
|
||||
authorizationHandler.processAuthorisationRequest(
|
||||
request, contact);
|
||||
|
||||
//and now pretend that the remote contact has granted us
|
||||
//authorization
|
||||
return new AuthorizationResponse(AuthorizationResponse.ACCEPT
|
||||
, "You are welcome!");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a subscription for the presence status of the contact
|
||||
* corresponding to the specified contactIdentifier.
|
||||
*
|
||||
* @param contactIdentifier the identifier of the contact whose status
|
||||
* updates we are subscribing for. <p>
|
||||
* @throws IllegalArgumentException if <tt>contact</tt> is not a contact
|
||||
* known to the underlying protocol provider
|
||||
* @throws IllegalStateException if the underlying protocol provider is
|
||||
* not registered/signed on a public service.
|
||||
* @throws OperationFailedException with code NETWORK_FAILURE if
|
||||
* subscribing fails due to errors experienced during network
|
||||
* communication
|
||||
*/
|
||||
public void subscribe(String contactIdentifier) throws
|
||||
IllegalArgumentException, IllegalStateException,
|
||||
OperationFailedException
|
||||
{
|
||||
//subscribe(contactListRoot, contactIdentifier);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes a subscription for the presence status of the specified
|
||||
* contact.
|
||||
*
|
||||
* @param contact the contact whose status updates we are unsubscribing
|
||||
* from.
|
||||
* @throws IllegalArgumentException if <tt>contact</tt> is not a contact
|
||||
* known to the underlying protocol provider
|
||||
* @throws IllegalStateException if the underlying protocol provider is
|
||||
* not registered/signed on a public service.
|
||||
* @throws OperationFailedException with code NETWORK_FAILURE if
|
||||
* unsubscribing fails due to errors experienced during network
|
||||
* communication
|
||||
*/
|
||||
public void unsubscribe(Contact contact) throws IllegalArgumentException,
|
||||
IllegalStateException, OperationFailedException
|
||||
{
|
||||
ContactGroupDictImpl parentGroup
|
||||
= (ContactGroupDictImpl)((ContactDictImpl)contact)
|
||||
.getParentContactGroup();
|
||||
|
||||
parentGroup.removeContact((ContactDictImpl)contact);
|
||||
|
||||
fireSubscriptionEvent(contact,
|
||||
((ContactDictImpl)contact).getParentContactGroup()
|
||||
, SubscriptionEvent.SUBSCRIPTION_REMOVED);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates and returns a unresolved contact from the specified
|
||||
* <tt>address</tt> and <tt>persistentData</tt>. The method will not try
|
||||
* to establish a network connection and resolve the newly created Contact
|
||||
* against the server. The protocol provider may will later try and resolve
|
||||
* the contact. When this happens the corresponding event would notify
|
||||
* interested subscription listeners.
|
||||
*
|
||||
* @param address an identifier of the contact that we'll be creating.
|
||||
* @param persistentData a String returned Contact's getPersistentData()
|
||||
* method during a previous run and that has been persistently stored
|
||||
* locally.
|
||||
* @return the unresolved <tt>Contact</tt> created from the specified
|
||||
* <tt>address</tt> and <tt>persistentData</tt>
|
||||
*/
|
||||
public Contact createUnresolvedContact(String address,
|
||||
String persistentData)
|
||||
{
|
||||
return createUnresolvedContact(address
|
||||
, persistentData
|
||||
, getServerStoredContactListRoot());
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates and returns a unresolved contact from the specified
|
||||
* <tt>address</tt> and <tt>persistentData</tt>. The method will not try
|
||||
* to establish a network connection and resolve the newly created Contact
|
||||
* against the server. The protocol provider may will later try and resolve
|
||||
* the contact. When this happens the corresponding event would notify
|
||||
* interested subscription listeners.
|
||||
*
|
||||
* @param address an identifier of the contact that we'll be creating.
|
||||
* @param persistentData a String returned Contact's getPersistentData()
|
||||
* method during a previous run and that has been persistently stored
|
||||
* locally.
|
||||
* @param parent the group where the unresolved contact is
|
||||
* supposed to belong to.
|
||||
*
|
||||
* @return the unresolved <tt>Contact</tt> created from the specified
|
||||
* <tt>address</tt> and <tt>persistentData</tt>
|
||||
*/
|
||||
public Contact createUnresolvedContact(String address,
|
||||
String persistentData,
|
||||
ContactGroup parent)
|
||||
{
|
||||
|
||||
ContactDictImpl contact = new ContactDictImpl(
|
||||
address
|
||||
, parentProvider);
|
||||
contact.setResolved(false);
|
||||
|
||||
( (ContactGroupDictImpl) parent).addContact(contact);
|
||||
|
||||
fireSubscriptionEvent(contact,
|
||||
parent,
|
||||
SubscriptionEvent.SUBSCRIPTION_CREATED);
|
||||
|
||||
//since we don't have any server, we'll simply resolve the contact
|
||||
//ourselves as if we've just received an event from the server telling
|
||||
//us that it has been resolved.
|
||||
contact.setResolved(true);
|
||||
fireSubscriptionEvent(contact, parent, SubscriptionEvent.SUBSCRIPTION_RESOLVED);
|
||||
|
||||
//since we are not a real protocol, we set the contact presence status
|
||||
//ourselves
|
||||
changePresenceStatusForContact( contact, getPresenceStatus());
|
||||
|
||||
return contact;
|
||||
}
|
||||
|
||||
/**
|
||||
* Looks for a dict protocol provider registered for a user id matching
|
||||
* <tt>dictUserID</tt>.
|
||||
*
|
||||
* @param dictUserID the ID of the Dict user whose corresponding
|
||||
* protocol provider we'd like to find.
|
||||
* @return ProtocolProviderServiceDictImpl a dict protocol
|
||||
* provider registered for a user with id <tt>dictUserID</tt> or null
|
||||
* if there is no such protocol provider.
|
||||
*/
|
||||
public ProtocolProviderServiceDictImpl
|
||||
findProviderForDictUserID(String dictUserID)
|
||||
{
|
||||
BundleContext bc = DictActivator.getBundleContext();
|
||||
|
||||
String osgiQuery = "(&"
|
||||
+ "(" + ProtocolProviderFactory.PROTOCOL
|
||||
+ "=Dict)"
|
||||
+ "(" + ProtocolProviderFactory.USER_ID
|
||||
+ "=" + dictUserID + ")"
|
||||
+ ")";
|
||||
|
||||
ServiceReference[] refs = null;
|
||||
try
|
||||
{
|
||||
refs = bc.getServiceReferences(
|
||||
ProtocolProviderService.class.getName()
|
||||
,osgiQuery);
|
||||
}
|
||||
catch (InvalidSyntaxException ex)
|
||||
{
|
||||
logger.error("Failed to execute the following osgi query: "
|
||||
+ osgiQuery
|
||||
, ex);
|
||||
}
|
||||
|
||||
if(refs != null && refs.length > 0)
|
||||
{
|
||||
return (ProtocolProviderServiceDictImpl)bc.getService(refs[0]);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Looks for dict protocol providers that have added us to their
|
||||
* contact list and returns list of all contacts representing us in these
|
||||
* providers.
|
||||
*
|
||||
* @return a list of all contacts in other providers' contact lists that
|
||||
* point to us.
|
||||
*/
|
||||
public List<Contact> findContactsPointingToUs()
|
||||
{
|
||||
List<Contact> contacts = new LinkedList<Contact>();
|
||||
BundleContext bc = DictActivator.getBundleContext();
|
||||
|
||||
String osgiQuery =
|
||||
"(" + ProtocolProviderFactory.PROTOCOL
|
||||
+ "=Dict)";
|
||||
|
||||
ServiceReference[] refs = null;
|
||||
try
|
||||
{
|
||||
refs = bc.getServiceReferences(
|
||||
ProtocolProviderService.class.getName()
|
||||
,osgiQuery);
|
||||
}
|
||||
catch (InvalidSyntaxException ex)
|
||||
{
|
||||
logger.error("Failed to execute the following osgi query: "
|
||||
+ osgiQuery
|
||||
, ex);
|
||||
}
|
||||
|
||||
for (int i =0; refs != null && i < refs.length; i++)
|
||||
{
|
||||
ProtocolProviderServiceDictImpl gibProvider
|
||||
= (ProtocolProviderServiceDictImpl)bc.getService(refs[i]);
|
||||
|
||||
OperationSetPersistentPresenceDictImpl opSetPersPresence
|
||||
= (OperationSetPersistentPresenceDictImpl)gibProvider
|
||||
.getOperationSet(OperationSetPersistentPresence.class);
|
||||
|
||||
Contact contact = opSetPersPresence.findContactByID(
|
||||
parentProvider.getAccountID().getUserID());
|
||||
|
||||
if (contact != null)
|
||||
contacts.add(contact);
|
||||
}
|
||||
|
||||
return contacts;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Creates and returns a unresolved contact group from the specified
|
||||
* <tt>address</tt> and <tt>persistentData</tt>. The method will not try
|
||||
* to establish a network connection and resolve the newly created
|
||||
* <tt>ContactGroup</tt> against the server or the contact itself. The
|
||||
* protocol provider will later resolve the contact group. When this happens
|
||||
* the corresponding event would notify interested subscription listeners.
|
||||
*
|
||||
* @param groupUID an identifier, returned by ContactGroup's getGroupUID,
|
||||
* that the protocol provider may use in order to create the group.
|
||||
* @param persistentData a String returned ContactGroups's
|
||||
* getPersistentData() method during a previous run and that has been
|
||||
* persistently stored locally.
|
||||
* @param parentGroup the group under which the new group is to be created
|
||||
* or null if this is group directly underneath the root.
|
||||
* @return the unresolved <tt>ContactGroup</tt> created from the specified
|
||||
* <tt>uid</tt> and <tt>persistentData</tt>
|
||||
*/
|
||||
public ContactGroup createUnresolvedContactGroup(String groupUID,
|
||||
String persistentData, ContactGroup parentGroup)
|
||||
{
|
||||
ContactGroupDictImpl newGroup
|
||||
= new ContactGroupDictImpl(
|
||||
ContactGroupDictImpl.createNameFromUID(groupUID)
|
||||
, parentProvider);
|
||||
newGroup.setResolved(false);
|
||||
|
||||
//if parent is null then we're adding under root.
|
||||
if(parentGroup == null)
|
||||
parentGroup = getServerStoredContactListRoot();
|
||||
|
||||
((ContactGroupDictImpl)parentGroup).addSubgroup(newGroup);
|
||||
|
||||
this.fireServerStoredGroupEvent(
|
||||
newGroup, ServerStoredGroupEvent.GROUP_CREATED_EVENT);
|
||||
|
||||
return newGroup;
|
||||
}
|
||||
|
||||
private class UnregistrationListener
|
||||
implements RegistrationStateChangeListener
|
||||
{
|
||||
/**
|
||||
* The method is called by a ProtocolProvider implementation whenver
|
||||
* a change in the registration state of the corresponding provider had
|
||||
* occurred. The method is particularly interested in events stating
|
||||
* that the dict provider has unregistered so that it would fire
|
||||
* status change events for all contacts in our buddy list.
|
||||
*
|
||||
* @param evt ProviderStatusChangeEvent the event describing the status
|
||||
* change.
|
||||
*/
|
||||
public void registrationStateChanged(RegistrationStateChangeEvent evt)
|
||||
{
|
||||
if (! evt.getNewState().equals(RegistrationState.UNREGISTERED)
|
||||
&& !evt.getNewState().equals(RegistrationState.AUTHENTICATION_FAILED)
|
||||
&& !evt.getNewState().equals(RegistrationState.CONNECTION_FAILED))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//send event notifications saying that all our buddies are
|
||||
//offline. The icq protocol does not implement top level buddies
|
||||
//nor subgroups for top level groups so a simple nested loop
|
||||
//would be enough.
|
||||
Iterator<ContactGroup> groupsIter = getServerStoredContactListRoot()
|
||||
.subgroups();
|
||||
while (groupsIter.hasNext())
|
||||
{
|
||||
ContactGroupDictImpl group
|
||||
= (ContactGroupDictImpl) groupsIter.next();
|
||||
|
||||
Iterator<Contact> contactsIter = group.contacts();
|
||||
|
||||
while (contactsIter.hasNext())
|
||||
{
|
||||
ContactDictImpl contact
|
||||
= (ContactDictImpl) contactsIter.next();
|
||||
|
||||
PresenceStatus oldContactStatus
|
||||
= contact.getPresenceStatus();
|
||||
|
||||
if (!oldContactStatus.isOnline())
|
||||
continue;
|
||||
|
||||
contact.setPresenceStatus(DictStatusEnum.OFFLINE);
|
||||
|
||||
fireContactPresenceStatusChangeEvent(
|
||||
contact
|
||||
, contact.getParentContactGroup()
|
||||
, oldContactStatus);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the volatile group or null if this group has not yet been
|
||||
* created.
|
||||
*
|
||||
* @return a volatile group existing in our contact list or <tt>null</tt>
|
||||
* if such a group has not yet been created.
|
||||
*/
|
||||
private ContactGroupDictImpl getNonPersistentGroup()
|
||||
{
|
||||
for (int i = 0
|
||||
; i < getServerStoredContactListRoot().countSubgroups()
|
||||
; i++)
|
||||
{
|
||||
ContactGroupDictImpl gr =
|
||||
(ContactGroupDictImpl)getServerStoredContactListRoot()
|
||||
.getGroup(i);
|
||||
|
||||
if(!gr.isPersistent())
|
||||
return gr;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Creates a non persistent contact for the specified address. This would
|
||||
* also create (if necessary) a group for volatile contacts that would not
|
||||
* be added to the server stored contact list. This method would have no
|
||||
* effect on the server stored contact list.
|
||||
*
|
||||
* @param contactAddress the address of the volatile contact we'd like to
|
||||
* create.
|
||||
* @return the newly created volatile contact.
|
||||
*/
|
||||
public ContactDictImpl createVolatileContact(String contactAddress)
|
||||
{
|
||||
//First create the new volatile contact;
|
||||
ContactDictImpl newVolatileContact
|
||||
= new ContactDictImpl(contactAddress
|
||||
, this.parentProvider);
|
||||
newVolatileContact.setPersistent(false);
|
||||
|
||||
|
||||
//Check whether a volatile group already exists and if not create
|
||||
//one
|
||||
ContactGroupDictImpl theVolatileGroup = getNonPersistentGroup();
|
||||
|
||||
|
||||
//if the parent volatile group is null then we create it
|
||||
if (theVolatileGroup == null)
|
||||
{
|
||||
theVolatileGroup = new ContactGroupDictImpl(
|
||||
DictActivator.getResources().getI18NString(
|
||||
"service.gui.NOT_IN_CONTACT_LIST_GROUP_NAME")
|
||||
, parentProvider);
|
||||
theVolatileGroup.setResolved(false);
|
||||
theVolatileGroup.setPersistent(false);
|
||||
|
||||
this.contactListRoot.addSubgroup(theVolatileGroup);
|
||||
|
||||
fireServerStoredGroupEvent(theVolatileGroup
|
||||
, ServerStoredGroupEvent.GROUP_CREATED_EVENT);
|
||||
}
|
||||
|
||||
//now add the volatile contact instide it
|
||||
theVolatileGroup.addContact(newVolatileContact);
|
||||
fireSubscriptionEvent(newVolatileContact
|
||||
, theVolatileGroup
|
||||
, SubscriptionEvent.SUBSCRIPTION_CREATED);
|
||||
|
||||
return newVolatileContact;
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,133 +0,0 @@
|
||||
/*
|
||||
* Jitsi, the OpenSource Java VoIP and Instant Messaging client.
|
||||
*
|
||||
* Copyright @ 2015 Atlassian Pty Ltd
|
||||
*
|
||||
* 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 net.java.sip.communicator.impl.protocol.dict;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import net.java.sip.communicator.service.protocol.*;
|
||||
|
||||
/**
|
||||
* Represents the Dict protocol icon. Implements the <tt>ProtocolIcon</tt>
|
||||
* interface in order to provide a Dict logo image in two different sizes.
|
||||
*
|
||||
* @author ROTH Damien
|
||||
* @author LITZELMANN Cedric
|
||||
*/
|
||||
public class ProtocolIconDictImpl
|
||||
implements ProtocolIcon
|
||||
{
|
||||
/**
|
||||
* A hash table containing the protocol icon in different sizes.
|
||||
*/
|
||||
private static Hashtable<String,byte[]> iconsTable
|
||||
= new Hashtable<String,byte[]>();
|
||||
static
|
||||
{
|
||||
iconsTable.put(ProtocolIcon.ICON_SIZE_16x16,
|
||||
DictActivator.getResources()
|
||||
.getImageInBytes("service.protocol.dict.DICT_16x16"));
|
||||
|
||||
iconsTable.put(ProtocolIcon.ICON_SIZE_32x32,
|
||||
DictActivator.getResources()
|
||||
.getImageInBytes("service.protocol.dict.DICT_32x32"));
|
||||
|
||||
iconsTable.put(ProtocolIcon.ICON_SIZE_48x48,
|
||||
DictActivator.getResources()
|
||||
.getImageInBytes("service.protocol.dict.DICT_48x48"));
|
||||
|
||||
iconsTable.put(ProtocolIcon.ICON_SIZE_64x64,
|
||||
DictActivator.getResources()
|
||||
.getImageInBytes("service.protocol.dict.DICT_64x64"));
|
||||
}
|
||||
|
||||
/**
|
||||
* A hash table containing the path to the protocol icon in different sizes.
|
||||
*/
|
||||
private static Hashtable<String, String> iconPathsTable
|
||||
= new Hashtable<String, String>();
|
||||
static
|
||||
{
|
||||
iconPathsTable.put(ProtocolIcon.ICON_SIZE_16x16,
|
||||
DictActivator.getResources()
|
||||
.getImagePath("service.protocol.dict.DICT_16x16"));
|
||||
|
||||
iconPathsTable.put(ProtocolIcon.ICON_SIZE_32x32,
|
||||
DictActivator.getResources()
|
||||
.getImagePath("service.protocol.dict.DICT_32x32"));
|
||||
|
||||
iconPathsTable.put(ProtocolIcon.ICON_SIZE_48x48,
|
||||
DictActivator.getResources()
|
||||
.getImagePath("service.protocol.dict.DICT_48x48"));
|
||||
|
||||
iconPathsTable.put(ProtocolIcon.ICON_SIZE_64x64,
|
||||
DictActivator.getResources()
|
||||
.getImagePath("service.protocol.dict.DICT_64x64"));
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements the <tt>ProtocolIcon.getSupportedSizes()</tt> method. Returns
|
||||
* an iterator to a set containing the supported icon sizes.
|
||||
* @return Returns an iterator to a set containing the supported icon sizes
|
||||
*/
|
||||
public Iterator<String> getSupportedSizes()
|
||||
{
|
||||
return iconsTable.keySet().iterator();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns TRUE if an icon with the given size is supported, FALSE otherwise.
|
||||
* @param iconSize The size of the icon, that we want to know if it is
|
||||
* supported.
|
||||
* @return Returns true if the size is supported. False otherwise.
|
||||
*/
|
||||
public boolean isSizeSupported(String iconSize)
|
||||
{
|
||||
return iconsTable.containsKey(iconSize);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the icon image in the given size.
|
||||
* @param iconSize The icon size one of ICON_SIZE_XXX constants
|
||||
* @return Returns a byte[] containing the pixels of the icon for the given
|
||||
* size.
|
||||
*/
|
||||
public byte[] getIcon(String iconSize)
|
||||
{
|
||||
return iconsTable.get(iconSize);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a path to the icon with the given size.
|
||||
* @param iconSize the size of the icon we're looking for
|
||||
* @return the path to the icon with the given size
|
||||
*/
|
||||
public String getIconPath(String iconSize)
|
||||
{
|
||||
return iconPathsTable.get(iconSize);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the icon image used to represent the protocol connecting state.
|
||||
* @return Returns the icon image used to represent the protocol connecting
|
||||
* state.
|
||||
*/
|
||||
public byte[] getConnectingIcon()
|
||||
{
|
||||
return iconsTable.get(ProtocolIcon.ICON_SIZE_16x16);
|
||||
}
|
||||
}
|
||||
@ -1,200 +0,0 @@
|
||||
/*
|
||||
* Jitsi, the OpenSource Java VoIP and Instant Messaging client.
|
||||
*
|
||||
* Copyright @ 2015 Atlassian Pty Ltd
|
||||
*
|
||||
* 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 net.java.sip.communicator.impl.protocol.dict;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import net.java.sip.communicator.service.contactlist.*;
|
||||
import net.java.sip.communicator.service.protocol.*;
|
||||
import net.java.sip.communicator.util.*;
|
||||
|
||||
import org.osgi.framework.*;
|
||||
|
||||
/**
|
||||
* The Dict protocol provider factory creates instances of the Dict
|
||||
* protocol provider service. One Service instance corresponds to one account.
|
||||
*
|
||||
* @author ROTH Damien
|
||||
* @author LITZELMANN Cedric
|
||||
*/
|
||||
public class ProtocolProviderFactoryDictImpl
|
||||
extends ProtocolProviderFactory
|
||||
{
|
||||
private static final Logger logger
|
||||
= Logger.getLogger(ProtocolProviderFactoryDictImpl.class);
|
||||
|
||||
/**
|
||||
* Creates an instance of the ProtocolProviderFactoryDictImpl.
|
||||
*/
|
||||
public ProtocolProviderFactoryDictImpl()
|
||||
{
|
||||
super(DictActivator.getBundleContext(), ProtocolNames.DICT);
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializaed and creates an account corresponding to the specified
|
||||
* accountProperties and registers the resulting ProtocolProvider in the
|
||||
* <tt>context</tt> BundleContext parameter.
|
||||
*
|
||||
* @param userIDStr The user identifier uniquely representing the newly
|
||||
* created account within the protocol namespace.
|
||||
* @param accountProperties a set of protocol (or implementation)
|
||||
* specific properties defining the new account.
|
||||
* @return the AccountID of the newly created account.
|
||||
*/
|
||||
@Override
|
||||
public AccountID installAccount( String userIDStr,
|
||||
Map<String, String> accountProperties)
|
||||
{
|
||||
BundleContext context = DictActivator.getBundleContext();
|
||||
if (context == null)
|
||||
{
|
||||
throw new NullPointerException("The specified BundleContext was null");
|
||||
}
|
||||
if (userIDStr == null)
|
||||
{
|
||||
throw new NullPointerException("The specified AccountID was null");
|
||||
}
|
||||
if (accountProperties == null)
|
||||
{
|
||||
throw new NullPointerException("The specified property map was null");
|
||||
}
|
||||
|
||||
accountProperties.put(USER_ID, userIDStr);
|
||||
|
||||
AccountID accountID = new DictAccountID(userIDStr, accountProperties);
|
||||
|
||||
//make sure we haven't seen this account id before.
|
||||
if (registeredAccounts.containsKey(accountID))
|
||||
{
|
||||
throw new IllegalStateException("An account for id " + userIDStr + " was already installed!");
|
||||
}
|
||||
|
||||
//first store the account and only then load it as the load generates
|
||||
//an osgi event, the osgi event triggers (through the UI) a call to the
|
||||
//ProtocolProviderService.register() method and it needs to acces
|
||||
//the configuration service and check for a stored password.
|
||||
this.storeAccount(accountID, false);
|
||||
|
||||
accountID = loadAccount(accountProperties);
|
||||
|
||||
// Creates the dict contact group.
|
||||
this.createGroup();
|
||||
// Creates the default conatct for this dict server.
|
||||
this.createDefaultContact(accountID);
|
||||
|
||||
return accountID;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected AccountID createAccountID(String userID, Map<String, String> accountProperties)
|
||||
{
|
||||
return new DictAccountID(userID, accountProperties);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ProtocolProviderService createService(String userID,
|
||||
AccountID accountID)
|
||||
{
|
||||
ProtocolProviderServiceDictImpl service =
|
||||
new ProtocolProviderServiceDictImpl();
|
||||
|
||||
service.initialize(userID, accountID);
|
||||
return service;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a group for the dict contacts
|
||||
*/
|
||||
private void createGroup()
|
||||
{
|
||||
// Get MetaContactListService
|
||||
BundleContext bundleContext = getBundleContext();
|
||||
ServiceReference<MetaContactListService> mfcServiceRef
|
||||
= bundleContext.getServiceReference(MetaContactListService.class);
|
||||
|
||||
MetaContactListService mcl = bundleContext.getService(mfcServiceRef);
|
||||
|
||||
try
|
||||
{
|
||||
String groupName = DictActivator.getResources()
|
||||
.getI18NString("service.protocol.DICTIONARIES");
|
||||
|
||||
mcl.createMetaContactGroup(mcl.getRoot(), groupName);
|
||||
}
|
||||
catch (MetaContactListException ex)
|
||||
{
|
||||
int errorCode = ex.getErrorCode();
|
||||
if (errorCode != MetaContactListException.CODE_GROUP_ALREADY_EXISTS_ERROR)
|
||||
{
|
||||
logger.error(ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a default contact for the new DICT server.
|
||||
* @param accountID The accountID of the dict protocol provider for which we
|
||||
* want to add a default contact.
|
||||
*/
|
||||
private void createDefaultContact(AccountID accountID)
|
||||
{
|
||||
// Gets the MetaContactListService.
|
||||
BundleContext bundleContext = getBundleContext();
|
||||
ServiceReference<MetaContactListService> mfcServiceRef
|
||||
= bundleContext.getServiceReference(MetaContactListService.class);
|
||||
MetaContactListService mcl = bundleContext.getService(mfcServiceRef);
|
||||
|
||||
// Gets the ProtocolProviderService.
|
||||
ServiceReference<ProtocolProviderService> serRef
|
||||
= getProviderForAccount(accountID);
|
||||
ProtocolProviderService protocolProvider
|
||||
= DictActivator.getBundleContext().getService(serRef);
|
||||
|
||||
// Gets group name
|
||||
String groupName = DictActivator.getResources()
|
||||
.getI18NString("service.protocol.DICTIONARIES");
|
||||
|
||||
// Gets contact name
|
||||
String contactName = DictActivator.getResources()
|
||||
.getI18NString("plugin.dictaccregwizz.ANY_DICTIONARY_FORM",
|
||||
new String[] {accountID.getUserID()});
|
||||
|
||||
// Gets the MetaContactGroup for the "dictionaries" group.
|
||||
MetaContactGroup group = mcl.getRoot().getMetaContactSubgroup(groupName);
|
||||
|
||||
// Sets the default contact identifier to "*" corresponding to "all the
|
||||
// dictionaries" available on the server (cf. RFC-2229).
|
||||
String dict_uin = "*";
|
||||
// Create the default contact.
|
||||
mcl.createMetaContact(protocolProvider, group, dict_uin);
|
||||
// Rename the default contact.
|
||||
mcl.renameMetaContact(
|
||||
group.getMetaContact(protocolProvider, dict_uin),
|
||||
contactName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void modifyAccount(
|
||||
ProtocolProviderService protocolProvider,
|
||||
Map<String, String> accountProperties)
|
||||
throws NullPointerException
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
}
|
||||
}
|
||||
@ -1,364 +0,0 @@
|
||||
/*
|
||||
* Jitsi, the OpenSource Java VoIP and Instant Messaging client.
|
||||
*
|
||||
* Copyright @ 2015 Atlassian Pty Ltd
|
||||
*
|
||||
* 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 net.java.sip.communicator.impl.protocol.dict;
|
||||
|
||||
import net.java.dict4j.*;
|
||||
import net.java.sip.communicator.service.protocol.*;
|
||||
import net.java.sip.communicator.service.protocol.event.*;
|
||||
import net.java.sip.communicator.util.*;
|
||||
|
||||
import org.jitsi.service.version.*;
|
||||
import org.osgi.framework.*;
|
||||
|
||||
/**
|
||||
* A Dict implementation of the ProtocolProviderService.
|
||||
*
|
||||
* @author ROTH Damien
|
||||
* @author LITZELMANN Cedric
|
||||
*/
|
||||
public class ProtocolProviderServiceDictImpl
|
||||
extends AbstractProtocolProviderService
|
||||
{
|
||||
private static final Logger logger
|
||||
= Logger.getLogger(ProtocolProviderServiceDictImpl.class);
|
||||
|
||||
/**
|
||||
* The name of this protocol.
|
||||
*/
|
||||
public static final String DICT_PROTOCOL_NAME = "Dict";
|
||||
|
||||
/**
|
||||
* The id of the account that this protocol provider represents.
|
||||
*/
|
||||
private DictAccountID accountID = null;
|
||||
|
||||
/**
|
||||
* We use this to lock access to initialization.
|
||||
*/
|
||||
private Object initializationLock = new Object();
|
||||
|
||||
/**
|
||||
* Indicates whether or not the provider is initialized and ready for use.
|
||||
*/
|
||||
private boolean isInitialized = false;
|
||||
|
||||
/**
|
||||
* The logo corresponding to the gibberish protocol.
|
||||
*/
|
||||
private ProtocolIconDictImpl dictIcon = new ProtocolIconDictImpl();
|
||||
|
||||
/**
|
||||
* The registration state that we are currently in. Note that in a real
|
||||
* world protocol implementation this field won't exist and the registration
|
||||
* state would be retrieved from the protocol stack.
|
||||
*/
|
||||
private RegistrationState currentRegistrationState
|
||||
= RegistrationState.UNREGISTERED;
|
||||
|
||||
/**
|
||||
* the <tt>DictConnection</tt> opened by this provider
|
||||
*/
|
||||
private DictConnection dictConnection;
|
||||
|
||||
/**
|
||||
* The default constructor for the Dict protocol provider.
|
||||
*/
|
||||
public ProtocolProviderServiceDictImpl()
|
||||
{
|
||||
if (logger.isTraceEnabled())
|
||||
logger.trace("Creating a Dict provider.");
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes the service implementation, and puts it in a sate where it
|
||||
* could interoperate with other services. It is strongly recomended that
|
||||
* properties in this Map be mapped to property names as specified by
|
||||
* <tt>AccountProperties</tt>.
|
||||
*
|
||||
* @param userID the user id of the gibberish account we're currently
|
||||
* initializing
|
||||
* @param accountID the identifier of the account that this protocol
|
||||
* provider represents.
|
||||
*
|
||||
* @see net.java.sip.communicator.service.protocol.AccountID
|
||||
*/
|
||||
protected void initialize(String userID,
|
||||
AccountID accountID)
|
||||
{
|
||||
synchronized(initializationLock)
|
||||
{
|
||||
this.accountID = (DictAccountID) accountID;
|
||||
|
||||
this.dictConnection = new DictConnection(this.accountID.getHost(),
|
||||
this.accountID.getPort());
|
||||
this.dictConnection.setClientName(getSCVersion());
|
||||
|
||||
//initialize the presence operationset
|
||||
OperationSetPersistentPresenceDictImpl persistentPresence =
|
||||
new OperationSetPersistentPresenceDictImpl(this);
|
||||
|
||||
addSupportedOperationSet(
|
||||
OperationSetPersistentPresence.class,
|
||||
persistentPresence);
|
||||
//register it once again for those that simply need presence and
|
||||
//won't be smart enough to check for a persistent presence
|
||||
//alternative
|
||||
addSupportedOperationSet(
|
||||
OperationSetPresence.class,
|
||||
persistentPresence);
|
||||
|
||||
//initialize the IM operation set
|
||||
addSupportedOperationSet(
|
||||
OperationSetBasicInstantMessaging.class,
|
||||
new OperationSetBasicInstantMessagingDictImpl(
|
||||
this,
|
||||
persistentPresence));
|
||||
|
||||
//initialize the typing notifications operation set
|
||||
/*OperationSetTypingNotifications typingNotifications =
|
||||
new OperationSetTypingNotificationsDictImpl(
|
||||
this, persistentPresence);
|
||||
|
||||
supportedOperationSets.put(
|
||||
OperationSetTypingNotifications.class.getName(),
|
||||
typingNotifications);
|
||||
*/
|
||||
isInitialized = true;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the <tt>DictConnection</tt> opened by this provider
|
||||
* @return the <tt>DictConnection</tt> opened by this provider
|
||||
*/
|
||||
public DictConnection getConnection()
|
||||
{
|
||||
return this.dictConnection;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the AccountID that uniquely identifies the account represented
|
||||
* by this instance of the ProtocolProviderService.
|
||||
*
|
||||
* @return the id of the account represented by this provider.
|
||||
*/
|
||||
public AccountID getAccountID()
|
||||
{
|
||||
return accountID;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the short name of the protocol that the implementation of this
|
||||
* provider is based upon (like SIP, Jabber, ICQ/AIM, or others for
|
||||
* example).
|
||||
*
|
||||
* @return a String containing the short name of the protocol this
|
||||
* service is implementing (most often that would be a name in
|
||||
* ProtocolNames).
|
||||
*/
|
||||
public String getProtocolName()
|
||||
{
|
||||
return DICT_PROTOCOL_NAME;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the dict protocol icon.
|
||||
* @return the dict protocol icon
|
||||
*/
|
||||
public ProtocolIcon getProtocolIcon()
|
||||
{
|
||||
return this.dictIcon;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the state of the registration of this protocol provider with
|
||||
* the corresponding registration service.
|
||||
*
|
||||
* @return ProviderRegistrationState
|
||||
*/
|
||||
public RegistrationState getRegistrationState()
|
||||
{
|
||||
return currentRegistrationState;
|
||||
}
|
||||
|
||||
/**
|
||||
* Starts the registration process.
|
||||
*
|
||||
* @param authority the security authority that will be used for
|
||||
* resolving any security challenges that may be returned during the
|
||||
* registration or at any moment while wer're registered.
|
||||
* @throws OperationFailedException with the corresponding code it the
|
||||
* registration fails for some reason (e.g. a networking error or an
|
||||
* implementation problem).
|
||||
*/
|
||||
public void register(SecurityAuthority authority)
|
||||
throws OperationFailedException
|
||||
{
|
||||
// Try to connect to the server
|
||||
boolean connected = connect();
|
||||
|
||||
if (connected)
|
||||
{
|
||||
fireRegistrationStateChanged(
|
||||
getRegistrationState(),
|
||||
RegistrationState.REGISTERED,
|
||||
RegistrationStateChangeEvent.REASON_USER_REQUEST,
|
||||
null);
|
||||
currentRegistrationState = RegistrationState.REGISTERED;
|
||||
}
|
||||
else
|
||||
{
|
||||
fireRegistrationStateChanged(
|
||||
getRegistrationState(),
|
||||
RegistrationState.CONNECTION_FAILED,
|
||||
RegistrationStateChangeEvent.REASON_SERVER_NOT_FOUND,
|
||||
null);
|
||||
currentRegistrationState = RegistrationState.UNREGISTERED;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the connection to the dict server is open
|
||||
* @return TRUE if the connection is open - FALSE otherwise
|
||||
*/
|
||||
private boolean connect()
|
||||
{
|
||||
if (this.dictConnection.isConnected())
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
return this.dictConnection.isAvailable();
|
||||
}
|
||||
catch (DictException dx)
|
||||
{
|
||||
if (logger.isInfoEnabled())
|
||||
logger.info(dx);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Makes the service implementation close all open sockets and release
|
||||
* any resources that it might have taken and prepare for
|
||||
* shutdown/garbage collection.
|
||||
*/
|
||||
public void shutdown()
|
||||
{
|
||||
if(!isInitialized)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (logger.isTraceEnabled())
|
||||
logger.trace("Killing the Dict Protocol Provider for account "
|
||||
+ this.accountID.getUserID());
|
||||
|
||||
closeConnection();
|
||||
|
||||
if(isRegistered())
|
||||
{
|
||||
try
|
||||
{
|
||||
//do the unregistration
|
||||
unregister();
|
||||
}
|
||||
catch (OperationFailedException ex)
|
||||
{
|
||||
//we're shutting down so we need to silence the exception here
|
||||
logger.error(
|
||||
"Failed to properly unregister before shutting down. "
|
||||
+ getAccountID()
|
||||
, ex);
|
||||
}
|
||||
}
|
||||
|
||||
isInitialized = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Ends the registration of this protocol provider with the current
|
||||
* registration service.
|
||||
*
|
||||
* @throws OperationFailedException with the corresponding code it the
|
||||
* registration fails for some reason (e.g. a networking error or an
|
||||
* implementation problem).
|
||||
*/
|
||||
public void unregister()
|
||||
throws OperationFailedException
|
||||
{
|
||||
closeConnection();
|
||||
|
||||
fireRegistrationStateChanged(
|
||||
getRegistrationState(),
|
||||
RegistrationState.UNREGISTERED,
|
||||
RegistrationStateChangeEvent.REASON_USER_REQUEST,
|
||||
null);
|
||||
}
|
||||
|
||||
/**
|
||||
* DICT has no support for secure transport.
|
||||
*/
|
||||
public boolean isSignalingTransportSecure()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the "transport" protocol of this instance used to carry the
|
||||
* control channel for the current protocol service.
|
||||
*
|
||||
* @return The "transport" protocol of this instance: TCP.
|
||||
*/
|
||||
public TransportProtocol getTransportProtocol()
|
||||
{
|
||||
return TransportProtocol.TCP;
|
||||
}
|
||||
|
||||
/**
|
||||
* Close the connection to the server
|
||||
*/
|
||||
private void closeConnection()
|
||||
{
|
||||
try
|
||||
{
|
||||
this.dictConnection.close();
|
||||
}
|
||||
catch (DictException dx)
|
||||
{
|
||||
if (logger.isInfoEnabled())
|
||||
logger.info(dx);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the current version of SIP-Communicator
|
||||
* @return the current version of SIP-Communicator
|
||||
*/
|
||||
private String getSCVersion()
|
||||
{
|
||||
BundleContext bc = DictActivator.getBundleContext();
|
||||
ServiceReference vsr = bc.getServiceReference(VersionService.class.getName());
|
||||
|
||||
VersionService vs = (VersionService) bc.getService(vsr);
|
||||
return vs.getCurrentVersion().toString();
|
||||
|
||||
}
|
||||
}
|
||||
@ -1,15 +0,0 @@
|
||||
Bundle-Activator: net.java.sip.communicator.impl.protocol.dict.DictActivator
|
||||
Bundle-Name: Dict Protocol Provider
|
||||
Bundle-Description: A bundle providing support for the Dict protocol.
|
||||
Bundle-Vendor: jitsi.org
|
||||
Bundle-Version: 1.0.0
|
||||
Bundle-SymbolicName: net.java.sip.communicator.protocol.dict
|
||||
Import-Package: org.osgi.framework,
|
||||
org.jitsi.service.version,
|
||||
net.java.sip.communicator.service.contactlist,
|
||||
org.jitsi.service.configuration,
|
||||
org.jitsi.service.resources, net.java.sip.communicator.service.resources,
|
||||
net.java.sip.communicator.util,
|
||||
net.java.sip.communicator.service.protocol,
|
||||
net.java.sip.communicator.service.protocol.event,
|
||||
Export-Package: net.java.dict4j
|
||||
@ -1,151 +0,0 @@
|
||||
/*
|
||||
* Jitsi, the OpenSource Java VoIP and Instant Messaging client.
|
||||
*
|
||||
* Copyright @ 2015 Atlassian Pty Ltd
|
||||
*
|
||||
* 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 net.java.sip.communicator.plugin.dictaccregwizz;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import net.java.sip.communicator.service.browserlauncher.*;
|
||||
import net.java.sip.communicator.service.gui.*;
|
||||
import net.java.sip.communicator.service.protocol.*;
|
||||
import net.java.sip.communicator.util.*;
|
||||
|
||||
import org.osgi.framework.*;
|
||||
|
||||
/**
|
||||
* Registers the <tt>DictAccountRegistrationWizard</tt> in the UI Service.
|
||||
*
|
||||
* @author ROTH Damien
|
||||
* @author LITZELMANN Cedric
|
||||
*/
|
||||
public class DictAccRegWizzActivator
|
||||
implements BundleActivator
|
||||
{
|
||||
/**
|
||||
* OSGi bundle context.
|
||||
*/
|
||||
public static BundleContext bundleContext;
|
||||
|
||||
private static Logger logger = Logger.getLogger(
|
||||
DictAccRegWizzActivator.class);
|
||||
|
||||
private static BrowserLauncherService browserLauncherService;
|
||||
|
||||
private static WizardContainer wizardContainer;
|
||||
|
||||
private static DictAccountRegistrationWizard dictWizard;
|
||||
|
||||
private static UIService uiService;
|
||||
|
||||
/**
|
||||
* Starts this bundle.
|
||||
*
|
||||
* @param bc The bundle context.
|
||||
*/
|
||||
public void start(BundleContext bc) throws Exception {
|
||||
|
||||
bundleContext = bc;
|
||||
|
||||
ServiceReference uiServiceRef = bundleContext
|
||||
.getServiceReference(UIService.class.getName());
|
||||
|
||||
uiService = (UIService) bundleContext.getService(uiServiceRef);
|
||||
|
||||
wizardContainer = uiService.getAccountRegWizardContainer();
|
||||
|
||||
dictWizard = new DictAccountRegistrationWizard(wizardContainer);
|
||||
|
||||
//wizardContainer.addAccountRegistrationWizard(dictWizard);
|
||||
Hashtable<String, String> containerFilter
|
||||
= new Hashtable<String, String>();
|
||||
|
||||
containerFilter.put(
|
||||
ProtocolProviderFactory.PROTOCOL,
|
||||
ProtocolNames.DICT);
|
||||
|
||||
bundleContext.registerService(
|
||||
AccountRegistrationWizard.class.getName(),
|
||||
dictWizard,
|
||||
containerFilter);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Stops this bundle.
|
||||
*
|
||||
* @param bundleContext The bundle context (unused).
|
||||
*
|
||||
* @throws Exception Throws an execption from the
|
||||
* "wizardContainer.removeAccountRegistrationWizard" method.
|
||||
*
|
||||
*/
|
||||
public void stop(BundleContext bundleContext) throws Exception
|
||||
{
|
||||
//wizardContainer.removeAccountRegistrationWizard(dictWizard);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the <tt>ProtocolProviderFactory</tt> for the Dict protocol.
|
||||
* @return the <tt>ProtocolProviderFactory</tt> for the Dict protocol
|
||||
*/
|
||||
public static ProtocolProviderFactory getDictProtocolProviderFactory() {
|
||||
|
||||
ServiceReference[] serRefs = null;
|
||||
|
||||
String osgiFilter = "("
|
||||
+ ProtocolProviderFactory.PROTOCOL
|
||||
+ "="+ProtocolNames.DICT+")";
|
||||
|
||||
try {
|
||||
serRefs = bundleContext.getServiceReferences(
|
||||
ProtocolProviderFactory.class.getName(), osgiFilter);
|
||||
}
|
||||
catch (InvalidSyntaxException ex){
|
||||
logger.error("DictAccRegWizzActivator : " + ex);
|
||||
}
|
||||
|
||||
return (ProtocolProviderFactory) bundleContext.getService(serRefs[0]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the <tt>BrowserLauncherService</tt> obtained from the bundle
|
||||
* context.
|
||||
* @return the <tt>BrowserLauncherService</tt> obtained from the bundle
|
||||
* context
|
||||
*/
|
||||
public static BrowserLauncherService getBrowserLauncher() {
|
||||
if (browserLauncherService == null) {
|
||||
ServiceReference serviceReference = bundleContext
|
||||
.getServiceReference(BrowserLauncherService.class.getName());
|
||||
|
||||
browserLauncherService = (BrowserLauncherService) bundleContext
|
||||
.getService(serviceReference);
|
||||
}
|
||||
|
||||
return browserLauncherService;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the <tt>UIService</tt>.
|
||||
*
|
||||
* @return the <tt>UIService</tt>
|
||||
*/
|
||||
public static UIService getUIService()
|
||||
{
|
||||
return uiService;
|
||||
}
|
||||
}
|
||||
@ -1,104 +0,0 @@
|
||||
/*
|
||||
* Jitsi, the OpenSource Java VoIP and Instant Messaging client.
|
||||
*
|
||||
* Copyright @ 2015 Atlassian Pty Ltd
|
||||
*
|
||||
* 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 net.java.sip.communicator.plugin.dictaccregwizz;
|
||||
|
||||
import net.java.dict4j.*;
|
||||
|
||||
/**
|
||||
* The <tt>DictAccountRegistration</tt> is used to store all user input data
|
||||
* through the <tt>DictAccountRegistrationWizard</tt>.
|
||||
*
|
||||
* @author ROTH Damien
|
||||
* @author LITZELMANN Cedric
|
||||
*/
|
||||
public class DictAccountRegistration
|
||||
{
|
||||
private String userID;
|
||||
|
||||
/**
|
||||
* The hostname of the DICT server.
|
||||
*/
|
||||
private String host;
|
||||
|
||||
/**
|
||||
* The port of the DICT server.
|
||||
*/
|
||||
private int port;
|
||||
|
||||
/**
|
||||
* The strategy selected for the matching of words in dictionaries.
|
||||
*/
|
||||
private Strategy strategy;
|
||||
|
||||
/**
|
||||
* Returns the User ID of the dict registration account.
|
||||
* @return the User ID of the dict registration account.
|
||||
*/
|
||||
public String getUserID()
|
||||
{
|
||||
return userID;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the port of the dict registration account.
|
||||
* @return the port of the dict registration account.
|
||||
*/
|
||||
public int getPort() {
|
||||
return this.port;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the port of the dict registration account.
|
||||
* @param port the port of the dict registration account.
|
||||
*/
|
||||
public void setPort(int port) {
|
||||
this.port = port;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the host of the dict registration account.
|
||||
* @return the host of the dict registration account.
|
||||
*/
|
||||
public String getHost() {
|
||||
return this.host;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the host of the dict registration account.
|
||||
* @param host The host of the dict registration account.
|
||||
*/
|
||||
public void setHost(String host) {
|
||||
this.host = host;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the strategy that will be used for this dict account.
|
||||
* @return the strategy that will be used for this dict account.
|
||||
*/
|
||||
public Strategy getStrategy() {
|
||||
return this.strategy;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the strategy for this dict account.
|
||||
* @param strategy the strategy for this dict account.
|
||||
*/
|
||||
public void setStrategy(Strategy strategy) {
|
||||
this.strategy = strategy;
|
||||
}
|
||||
}
|
||||
@ -1,429 +0,0 @@
|
||||
/*
|
||||
* Jitsi, the OpenSource Java VoIP and Instant Messaging client.
|
||||
*
|
||||
* Copyright @ 2015 Atlassian Pty Ltd
|
||||
*
|
||||
* 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 net.java.sip.communicator.plugin.dictaccregwizz;
|
||||
|
||||
import java.awt.*;
|
||||
import java.util.*;
|
||||
|
||||
import net.java.sip.communicator.service.gui.*;
|
||||
import net.java.sip.communicator.service.protocol.*;
|
||||
import net.java.sip.communicator.util.*;
|
||||
|
||||
import org.osgi.framework.*;
|
||||
|
||||
/**
|
||||
* The <tt>DictAccountRegistrationWizard</tt> is an implementation of the
|
||||
* <tt>AccountRegistrationWizard</tt> for the Dict protocol. It should allow
|
||||
* the user to create and configure a new Dict account.
|
||||
*
|
||||
* @author ROTH Damien
|
||||
* @author LITZELMANN Cedric
|
||||
*/
|
||||
public class DictAccountRegistrationWizard
|
||||
extends DesktopAccountRegistrationWizard
|
||||
{
|
||||
private final Logger logger
|
||||
= Logger.getLogger(DictAccountRegistrationWizard.class);
|
||||
|
||||
/**
|
||||
* The reference to the first page of the wizard.
|
||||
*/
|
||||
private FirstWizardPage firstWizardPage;
|
||||
|
||||
/**
|
||||
* The registration of the DICT account.
|
||||
*/
|
||||
private DictAccountRegistration registration = new DictAccountRegistration();
|
||||
|
||||
/**
|
||||
* The protocole provider.
|
||||
*/
|
||||
private ProtocolProviderService protocolProvider;
|
||||
|
||||
/**
|
||||
* Creates an instance of <tt>DictAccountRegistrationWizard</tt>.
|
||||
*
|
||||
* @param wizardContainer the wizard container, where this wizard is added
|
||||
*/
|
||||
public DictAccountRegistrationWizard(WizardContainer wizardContainer)
|
||||
{
|
||||
setWizardContainer(wizardContainer);
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements the <code>AccountRegistrationWizard.getIcon</code> method.
|
||||
* @return Returns the icon to be used for this wizard.
|
||||
*/
|
||||
@Override
|
||||
public byte[] getIcon()
|
||||
{
|
||||
return Resources.getImage(Resources.DICT_LOGO);
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements the <code>AccountRegistrationWizard.getPageImage</code>
|
||||
* method. Returns the image used to decorate the wizard page
|
||||
*
|
||||
* @return byte[] the image used to decorate the wizard page
|
||||
*/
|
||||
@Override
|
||||
public byte[] getPageImage()
|
||||
{
|
||||
return Resources.getImage(Resources.PAGE_IMAGE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements the <code>AccountRegistrationWizard.getProtocolName</code>
|
||||
* method.
|
||||
* @return Returns the protocol name for this wizard.
|
||||
*/
|
||||
@Override
|
||||
public String getProtocolName()
|
||||
{
|
||||
return Resources.getString("plugin.dictaccregwizz.PROTOCOL_NAME");
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements the <code>AccountRegistrationWizard.getProtocolDescription
|
||||
* </code> method.
|
||||
* @return Returns the description of the protocol for this wizard.
|
||||
*/
|
||||
@Override
|
||||
public String getProtocolDescription()
|
||||
{
|
||||
return Resources.getString("plugin.dictaccregwizz.PROTOCOL_DESCRIPTION");
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the set of pages contained in this wizard.
|
||||
*
|
||||
* @return Returns the set of pages contained in this wizard.
|
||||
*/
|
||||
@Override
|
||||
public Iterator<WizardPage> getPages()
|
||||
{
|
||||
java.util.List<WizardPage> pages = new ArrayList<WizardPage>();
|
||||
this.firstWizardPage = new FirstWizardPage(this);
|
||||
pages.add(this.firstWizardPage);
|
||||
return pages.iterator();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the set of data that user has entered through this wizard.
|
||||
* @return Returns the set of data that user has entered through this wizard.
|
||||
*/
|
||||
@Override
|
||||
public Iterator<Map.Entry<String, String>> getSummary()
|
||||
{
|
||||
Map<String, String> summaryTable = new LinkedHashMap<String, String>();
|
||||
|
||||
summaryTable.put("Host", registration.getHost());
|
||||
summaryTable.put("Port", String.valueOf(registration.getPort()));
|
||||
summaryTable.put("Strategy", registration.getStrategy().getName());
|
||||
|
||||
return summaryTable.entrySet().iterator();
|
||||
}
|
||||
|
||||
/**
|
||||
* Defines the operations that will be executed when the user clicks on
|
||||
* the wizard "Signin" button.
|
||||
* @return the created <tt>ProtocolProviderService</tt> corresponding to the
|
||||
* new account
|
||||
* @throws OperationFailedException if the operation didn't succeed
|
||||
*/
|
||||
@Override
|
||||
public ProtocolProviderService signin()
|
||||
throws OperationFailedException
|
||||
{
|
||||
firstWizardPage.commitPage();
|
||||
|
||||
return signin(registration.getUserID(), null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Defines the operations that will be executed when the user clicks on
|
||||
* the wizard "Signin" button.
|
||||
*
|
||||
* @param userName the user name to sign in with
|
||||
* @param password the password to sign in with
|
||||
* @return the created <tt>ProtocolProviderService</tt> corresponding to the
|
||||
* new account
|
||||
* @throws OperationFailedException if the operation didn't succeed
|
||||
*/
|
||||
@Override
|
||||
public ProtocolProviderService signin(String userName, String password)
|
||||
throws OperationFailedException
|
||||
{
|
||||
ProtocolProviderFactory factory
|
||||
= DictAccRegWizzActivator.getDictProtocolProviderFactory();
|
||||
|
||||
return this.installAccount(factory, registration.getHost(),
|
||||
registration.getPort(),
|
||||
registration.getStrategy().getCode());
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an account for the given user and password.
|
||||
*
|
||||
* @param providerFactory the ProtocolProviderFactory which will create the
|
||||
* account.
|
||||
* @param host The hostname of the DICT server.
|
||||
* @param port The port used by the DICT server.
|
||||
* @param strategy The strategy choosen for matching words in the
|
||||
* dictionnaries.
|
||||
* @return the <tt>ProtocolProviderService</tt> for the new account.
|
||||
*/
|
||||
public ProtocolProviderService installAccount(
|
||||
ProtocolProviderFactory providerFactory,
|
||||
String host,
|
||||
int port,
|
||||
String strategy)
|
||||
throws OperationFailedException
|
||||
{
|
||||
Hashtable<String, String> accountProperties
|
||||
= new Hashtable<String, String>();
|
||||
|
||||
accountProperties.put( ProtocolProviderFactory.ACCOUNT_ICON_PATH,
|
||||
"resources/images/protocol/dict/dict-32x32.png");
|
||||
|
||||
// Set this property to indicate that Dict account does not require
|
||||
// authentication.
|
||||
accountProperties.put(
|
||||
ProtocolProviderFactory.NO_PASSWORD_REQUIRED,
|
||||
new Boolean(true).toString());
|
||||
|
||||
// Save host
|
||||
accountProperties.put(ProtocolProviderFactory.SERVER_ADDRESS, host);
|
||||
// Save port
|
||||
accountProperties.put( ProtocolProviderFactory.SERVER_PORT,
|
||||
String.valueOf(port));
|
||||
// Save strategy
|
||||
accountProperties.put(ProtocolProviderFactory.STRATEGY, strategy);
|
||||
|
||||
if (isModification())
|
||||
{
|
||||
providerFactory.uninstallAccount(protocolProvider.getAccountID());
|
||||
this.protocolProvider = null;
|
||||
setModification(false);
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
String uid = this.generateUID();
|
||||
AccountID accountID =
|
||||
providerFactory.installAccount(uid, accountProperties);
|
||||
|
||||
ServiceReference serRef =
|
||||
providerFactory.getProviderForAccount(accountID);
|
||||
|
||||
protocolProvider =
|
||||
(ProtocolProviderService) DictAccRegWizzActivator.bundleContext
|
||||
.getService(serRef);
|
||||
}
|
||||
catch (IllegalStateException exc)
|
||||
{
|
||||
logger.warn(exc.getMessage());
|
||||
|
||||
throw new OperationFailedException(
|
||||
"Account already exists.",
|
||||
OperationFailedException.IDENTIFICATION_CONFLICT);
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
logger.warn(exc.getMessage());
|
||||
|
||||
throw new OperationFailedException(
|
||||
"Failed to add account",
|
||||
OperationFailedException.GENERAL_ERROR);
|
||||
}
|
||||
|
||||
|
||||
return protocolProvider;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fills the UIN and Password fields in this panel with the data coming
|
||||
* from the given protocolProvider.
|
||||
*
|
||||
* @param protocolProvider The <tt>ProtocolProviderService</tt> to load
|
||||
* the data from.
|
||||
*/
|
||||
@Override
|
||||
public void loadAccount(ProtocolProviderService protocolProvider)
|
||||
{
|
||||
setModification(true);
|
||||
|
||||
this.protocolProvider = protocolProvider;
|
||||
|
||||
this.registration = new DictAccountRegistration();
|
||||
|
||||
this.firstWizardPage.loadAccount(protocolProvider);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the registration object, which will store all the data through
|
||||
* the wizard.
|
||||
*
|
||||
* @return the registration object, which will store all the data through
|
||||
* the wizard
|
||||
*/
|
||||
public DictAccountRegistration getRegistration()
|
||||
{
|
||||
return registration;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the size of this wizard.
|
||||
* @return the size of this wizard
|
||||
*/
|
||||
@Override
|
||||
public Dimension getSize()
|
||||
{
|
||||
return new Dimension(300, 150);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the identifier of the page to show first in the wizard.
|
||||
* @return the identifier of the page to show first in the wizard.
|
||||
*/
|
||||
@Override
|
||||
public Object getFirstPageIdentifier()
|
||||
{
|
||||
return firstWizardPage.getIdentifier();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the identifier of the page to show last in the wizard.
|
||||
* @return the identifier of the page to show last in the wizard.
|
||||
*/
|
||||
@Override
|
||||
public Object getLastPageIdentifier()
|
||||
{
|
||||
return firstWizardPage.getIdentifier();
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate the UID for the acount
|
||||
* @return the new UID
|
||||
*/
|
||||
private String generateUID()
|
||||
{
|
||||
String uid;
|
||||
int nbAccounts = this.getNumberOfAccounts();
|
||||
String host = this.registration.getHost();
|
||||
int nbAccountsForHost = this.getNbAccountForHost(host);
|
||||
|
||||
if (nbAccounts == 0 || (this.isModification() && nbAccounts == 1) ||
|
||||
nbAccountsForHost == 0
|
||||
|| (this.isModification() && nbAccountsForHost == 1))
|
||||
{
|
||||
// We create the first account or we edit the onlyone
|
||||
// Or we create the first account for this server or edit the onlyone
|
||||
uid = host;
|
||||
}
|
||||
else
|
||||
{
|
||||
uid = host + ":" + this.registration.getPort();
|
||||
}
|
||||
|
||||
return uid;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the number of accounts stored for the protocol
|
||||
* @return the number of accounts stored for the protocol
|
||||
*/
|
||||
private int getNumberOfAccounts()
|
||||
{
|
||||
ProtocolProviderFactory factory =
|
||||
DictAccRegWizzActivator.getDictProtocolProviderFactory();
|
||||
|
||||
return factory.getRegisteredAccounts().size();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the number of account for a given host
|
||||
* @param hostName the host
|
||||
* @return the number of account for a given host
|
||||
*/
|
||||
private int getNbAccountForHost(String host)
|
||||
{
|
||||
ProtocolProviderFactory factory =
|
||||
DictAccRegWizzActivator.getDictProtocolProviderFactory();
|
||||
|
||||
ArrayList<AccountID> registeredAccounts
|
||||
= factory.getRegisteredAccounts();
|
||||
int total = 0;
|
||||
|
||||
for (int i = 0; i < registeredAccounts.size(); i++)
|
||||
{
|
||||
AccountID accountID = registeredAccounts.get(i);
|
||||
|
||||
// The host is always stored at the start
|
||||
if (accountID.getUserID().startsWith(host.toLowerCase()))
|
||||
{
|
||||
total++;
|
||||
}
|
||||
}
|
||||
return total;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an example string, which should indicate to the user how the
|
||||
* user name should look like.
|
||||
* @return an example string, which should indicate to the user how the
|
||||
* user name should look like.
|
||||
*/
|
||||
@Override
|
||||
public String getUserNameExample()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicates whether this wizard enables the simple "sign in" form shown
|
||||
* when the user opens the application for the first time. The simple
|
||||
* "sign in" form allows user to configure her account in one click, just
|
||||
* specifying her username and password and leaving any other configuration
|
||||
* as by default.
|
||||
* @return <code>true</code> if the simple "Sign in" form is enabled or
|
||||
* <code>false</code> otherwise.
|
||||
*/
|
||||
@Override
|
||||
public boolean isSimpleFormEnabled()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a simple account registration form that would be the first form
|
||||
* shown to the user. Only if the user needs more settings she'll choose
|
||||
* to open the advanced wizard, consisted by all pages.
|
||||
*
|
||||
* @param isCreateAccount indicates if the simple form should be opened as
|
||||
* a create account form or as a login form
|
||||
* @return a simple account registration form
|
||||
*/
|
||||
@Override
|
||||
public Object getSimpleForm(boolean isCreateAccount)
|
||||
{
|
||||
firstWizardPage = new FirstWizardPage(this);
|
||||
|
||||
return firstWizardPage.getSimpleForm();
|
||||
}
|
||||
}
|
||||
@ -1,637 +0,0 @@
|
||||
/*
|
||||
* Jitsi, the OpenSource Java VoIP and Instant Messaging client.
|
||||
*
|
||||
* Copyright @ 2015 Atlassian Pty Ltd
|
||||
*
|
||||
* 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 net.java.sip.communicator.plugin.dictaccregwizz;
|
||||
|
||||
import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
import java.util.List;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.event.*;
|
||||
|
||||
import net.java.dict4j.*;
|
||||
import net.java.sip.communicator.plugin.desktoputil.*;
|
||||
import net.java.sip.communicator.service.gui.*;
|
||||
import net.java.sip.communicator.service.protocol.*;
|
||||
|
||||
/**
|
||||
* The <tt>FirstWizardPage</tt> is the page, where user could enter the host,
|
||||
* port and the strategy of the account.
|
||||
*
|
||||
* @author ROTH Damien
|
||||
* @author LITZELMANN Cedric
|
||||
*/
|
||||
public class FirstWizardPage
|
||||
extends TransparentPanel
|
||||
implements WizardPage, DocumentListener, ActionListener
|
||||
{
|
||||
/**
|
||||
* Serial version UID.
|
||||
*/
|
||||
private static final long serialVersionUID = 0L;
|
||||
|
||||
public static final String FIRST_PAGE_IDENTIFIER = "FirstPageIdentifier";
|
||||
|
||||
private JPanel hostPortPanel = new TransparentPanel(new BorderLayout(10, 10));
|
||||
|
||||
private JPanel labelsPanel = new TransparentPanel();
|
||||
|
||||
private JPanel valuesPanel = new TransparentPanel();
|
||||
|
||||
private JLabel hostLabel
|
||||
= new JLabel(Resources.getString("plugin.dictaccregwizz.HOST"));
|
||||
|
||||
private JPanel emptyPanel = new TransparentPanel();
|
||||
|
||||
private JLabel hostExampleLabel = new JLabel("Ex: dict.org");
|
||||
|
||||
private JLabel portLabel
|
||||
= new JLabel(Resources.getString("service.gui.PORT"));
|
||||
|
||||
private JTextField hostField = new JTextField();
|
||||
|
||||
private JTextField portField = new JTextField("2628");
|
||||
|
||||
private JPanel strategyPanel = new TransparentPanel(new BorderLayout(10, 10));
|
||||
|
||||
private JPanel strategyTitleBloc = new TransparentPanel(new BorderLayout());
|
||||
|
||||
private JLabel strategyTitle = new JLabel(Resources.getString(
|
||||
"plugin.dictaccregwizz.STRATEGY_LIST"));
|
||||
|
||||
private JButton strategyLoader
|
||||
= new JButton(Resources.getString(
|
||||
"plugin.dictaccregwizz.SEARCH_STRATEGIES"));
|
||||
|
||||
private StrategiesList strategiesList;
|
||||
|
||||
private JTextArea strategyDescription
|
||||
= new JTextArea(Resources.getString(
|
||||
"plugin.dictaccregwizz.STRATEGY_DESCRIPTION"));
|
||||
|
||||
private ProgressPanel searchProgressPanel;
|
||||
|
||||
private JPanel mainPanel = new TransparentPanel(new BorderLayout());
|
||||
|
||||
private Object nextPageIdentifier = WizardPage.SUMMARY_PAGE_IDENTIFIER;
|
||||
|
||||
private DictAccountRegistrationWizard wizard;
|
||||
|
||||
private String initstrategy = "";
|
||||
|
||||
private ThreadManager searchThread = null;
|
||||
|
||||
private boolean firstAccount = false;
|
||||
|
||||
private boolean isPageCommitted = false;
|
||||
|
||||
/**
|
||||
* Initial AccountID (null if new account)
|
||||
* Used to check if there are modifications to the account
|
||||
*/
|
||||
private AccountID initAccountID = null;
|
||||
|
||||
/**
|
||||
* Creates an instance of <tt>FirstWizardPage</tt>.
|
||||
*
|
||||
* @param wizard the parent wizard
|
||||
*/
|
||||
public FirstWizardPage(DictAccountRegistrationWizard wizard)
|
||||
{
|
||||
super(new BorderLayout());
|
||||
|
||||
this.wizard = wizard;
|
||||
|
||||
this.setPreferredSize(new Dimension(300, 150));
|
||||
|
||||
mainPanel.setLayout(new BoxLayout(mainPanel, BoxLayout.Y_AXIS));
|
||||
|
||||
this.searchThread = new ThreadManager(this);
|
||||
this.searchProgressPanel = new ProgressPanel(this.searchThread);
|
||||
|
||||
this.firstAccount = !this.hasAccount();
|
||||
|
||||
if (this.firstAccount)
|
||||
{
|
||||
this.initFirstAccount();
|
||||
}
|
||||
else
|
||||
{
|
||||
this.init();
|
||||
}
|
||||
|
||||
this.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes all panels, buttons, etc.
|
||||
*/
|
||||
private void init()
|
||||
{
|
||||
// Host and port Field
|
||||
this.hostField = new JTextField();
|
||||
this.portField = new JTextField("2628");
|
||||
|
||||
this.hostField.getDocument().addDocumentListener(this);
|
||||
this.portField.getDocument().addDocumentListener(this);
|
||||
|
||||
this.hostExampleLabel.setForeground(Color.GRAY);
|
||||
this.hostExampleLabel.setFont(hostExampleLabel.getFont().deriveFont(8));
|
||||
this.emptyPanel.setMaximumSize(new Dimension(40, 35));
|
||||
this.hostExampleLabel.setBorder(BorderFactory.createEmptyBorder(0, 0, 8,
|
||||
0));
|
||||
|
||||
labelsPanel.add(hostLabel);
|
||||
labelsPanel.add(emptyPanel);
|
||||
labelsPanel.add(portLabel);
|
||||
|
||||
valuesPanel.add(hostField);
|
||||
valuesPanel.add(hostExampleLabel);
|
||||
valuesPanel.add(portField);
|
||||
|
||||
hostPortPanel.add(labelsPanel, BorderLayout.WEST);
|
||||
hostPortPanel.add(valuesPanel, BorderLayout.CENTER);
|
||||
|
||||
hostPortPanel.setBorder(BorderFactory.createTitledBorder(
|
||||
Resources.getString("plugin.dictaccregwizz.SERVER_INFO")));
|
||||
|
||||
this.labelsPanel.setLayout(new BoxLayout(labelsPanel, BoxLayout.Y_AXIS));
|
||||
this.valuesPanel.setLayout(new BoxLayout(valuesPanel, BoxLayout.Y_AXIS));
|
||||
|
||||
mainPanel.add(hostPortPanel);
|
||||
|
||||
this.portField.addKeyListener(new KeyListener() {
|
||||
public void keyTyped(KeyEvent evt)
|
||||
{
|
||||
// If evt isn't a digit, we don't add it
|
||||
if (!Character.isDigit(evt.getKeyChar()))
|
||||
{
|
||||
evt.consume();
|
||||
}
|
||||
}
|
||||
|
||||
// Not used
|
||||
public void keyPressed(KeyEvent evt) {;}
|
||||
public void keyReleased(KeyEvent evt) {;}
|
||||
});
|
||||
|
||||
// Strategies list
|
||||
this.strategiesList = new StrategiesList();
|
||||
|
||||
JScrollPane scrollPane = new JScrollPane();
|
||||
scrollPane.getViewport().add(this.strategiesList);
|
||||
this.strategyPanel.add(scrollPane);
|
||||
|
||||
// Strategy title + button
|
||||
this.strategyTitleBloc.add(this.strategyTitle, BorderLayout.WEST);
|
||||
this.strategyTitleBloc.add(this.strategyLoader, BorderLayout.EAST);
|
||||
|
||||
// Button action listener
|
||||
this.strategyLoader.setActionCommand("populateList");
|
||||
this.strategyLoader.addActionListener(this);
|
||||
|
||||
// South Panel
|
||||
JPanel sSouthPanel = new TransparentPanel(new BorderLayout());
|
||||
|
||||
// Description
|
||||
this.strategyDescription.setLineWrap(true);
|
||||
this.strategyDescription.setLineWrap(true);
|
||||
this.strategyDescription.setRows(4);
|
||||
this.strategyDescription.setWrapStyleWord(true);
|
||||
this.strategyDescription.setAutoscrolls(false);
|
||||
sSouthPanel.add(this.strategyDescription);
|
||||
|
||||
// Message
|
||||
sSouthPanel.add(this.searchProgressPanel, BorderLayout.SOUTH);
|
||||
|
||||
this.strategyPanel.add(sSouthPanel, BorderLayout.SOUTH);
|
||||
|
||||
this.strategyPanel.add(this.strategyTitleBloc, BorderLayout.NORTH);
|
||||
this.strategyPanel.setBorder(BorderFactory.createTitledBorder(
|
||||
Resources.getString("plugin.dictaccregwizz.STRATEGY_SELECTION")));
|
||||
mainPanel.add(this.strategyPanel);
|
||||
|
||||
this.add(mainPanel, BorderLayout.NORTH);
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize the UI for the first account
|
||||
*/
|
||||
private void initFirstAccount()
|
||||
{
|
||||
// Data init
|
||||
this.hostField = new JTextField("dict.org");
|
||||
this.portField = new JTextField("2628");
|
||||
|
||||
// Init strategies list
|
||||
this.strategiesList = new StrategiesList();
|
||||
|
||||
this.mainPanel = new TransparentPanel(new BorderLayout());
|
||||
|
||||
JPanel infoTitlePanel
|
||||
= new TransparentPanel(new FlowLayout(FlowLayout.CENTER));
|
||||
JTextArea firstDescription
|
||||
= new JTextArea(Resources.getString(
|
||||
"plugin.dictaccregwizz.FIRST_ACCOUNT"));
|
||||
JLabel title
|
||||
= new JLabel(Resources.getString(
|
||||
"plugin.dictaccregwizz.ACCOUNT_INFO_TITLE"));
|
||||
|
||||
// Title
|
||||
title.setFont(title.getFont().deriveFont(Font.BOLD, 14.0f));
|
||||
infoTitlePanel.add(title);
|
||||
this.mainPanel.add(infoTitlePanel, BorderLayout.NORTH);
|
||||
this.mainPanel.add(this.searchProgressPanel, BorderLayout.SOUTH);
|
||||
|
||||
// Description
|
||||
firstDescription.setLineWrap(true);
|
||||
firstDescription.setEditable(false);
|
||||
firstDescription.setOpaque(false);
|
||||
firstDescription.setRows(6);
|
||||
firstDescription.setWrapStyleWord(true);
|
||||
firstDescription.setAutoscrolls(false);
|
||||
this.mainPanel.add(firstDescription);
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements the <code>WizardPage.getIdentifier</code> to return this
|
||||
* page identifier.
|
||||
*
|
||||
* @return Returns the identifier of the current (the first) page of the
|
||||
* wizard.
|
||||
*/
|
||||
public Object getIdentifier()
|
||||
{
|
||||
return FIRST_PAGE_IDENTIFIER;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements the <code>WizardPage.getNextPageIdentifier</code> to return
|
||||
* the next page identifier - the summary page.
|
||||
*
|
||||
* @return Returns the identifier of the next page of the wizard.
|
||||
*/
|
||||
public Object getNextPageIdentifier()
|
||||
{
|
||||
return nextPageIdentifier;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements the <code>WizardPage.getBackPageIdentifier</code> to return
|
||||
* the back identifier, which is null as this is the first wizard page.
|
||||
*
|
||||
* @return the identifier of the previous page of the wizard.
|
||||
*/
|
||||
public Object getBackPageIdentifier()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements the <code>WizardPage.getWizardForm</code> to return this
|
||||
* panel.
|
||||
* @return Returns this form of the wizard.
|
||||
*/
|
||||
public Object getWizardForm()
|
||||
{
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Before this page is displayed enables or disables the "Next" wizard
|
||||
* button according to whether the UIN field is empty.
|
||||
*/
|
||||
public void pageShowing()
|
||||
{
|
||||
this.setNextButtonEnabled();
|
||||
}
|
||||
|
||||
/**
|
||||
* Saves the user input when the "Next" wizard buttons is clicked.
|
||||
*/
|
||||
public void commitPage()
|
||||
{
|
||||
String host = hostField.getText();
|
||||
int port = Integer.parseInt(portField.getText());
|
||||
boolean isModified = false;
|
||||
|
||||
if (this.initAccountID != null)
|
||||
{ // We check if there are modifications to the server
|
||||
String accHost =
|
||||
this.initAccountID.getAccountPropertyString(
|
||||
ProtocolProviderFactory.SERVER_ADDRESS);
|
||||
int accPort =
|
||||
Integer.parseInt(this.initAccountID
|
||||
.getAccountPropertyString(ProtocolProviderFactory.SERVER_PORT));
|
||||
|
||||
if (((accHost == null) ? (host != null) : !accHost.equals(host))
|
||||
|| (accPort != port))
|
||||
{
|
||||
isModified = true;
|
||||
}
|
||||
}
|
||||
|
||||
// We check if a strategy has been selected
|
||||
if (this.strategiesList.getModel().getSize() == 0)
|
||||
{ // No Strategy, we get them
|
||||
this.populateStrategies();
|
||||
|
||||
if (!this.searchThread.waitThread())
|
||||
{
|
||||
// TODO error dialog : thread interrupted ? no thread ?
|
||||
this.strategiesList.clear();
|
||||
}
|
||||
}
|
||||
|
||||
if (this.strategiesList.getModel().getSize() == 0)
|
||||
{
|
||||
// No strategy, maybe not connected
|
||||
// Information message is already on the wizard
|
||||
nextPageIdentifier = FIRST_PAGE_IDENTIFIER;
|
||||
this.revalidate();
|
||||
}
|
||||
else
|
||||
{
|
||||
nextPageIdentifier = SUMMARY_PAGE_IDENTIFIER;
|
||||
|
||||
DictAccountRegistration registration = wizard.getRegistration();
|
||||
|
||||
registration.setHost(host);
|
||||
registration.setPort(port);
|
||||
registration.setStrategy(
|
||||
(Strategy) this.strategiesList.getSelectedValue());
|
||||
}
|
||||
|
||||
isPageCommitted = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Enables or disables the "Next" wizard button according to whether the UIN
|
||||
* field is empty.
|
||||
*/
|
||||
private void setNextButtonEnabled()
|
||||
{
|
||||
boolean hostOK = DictConnection.isUrl(hostField.getText());
|
||||
boolean portOK = (this.portField.getText().length() != 0)
|
||||
&& Integer.parseInt(this.portField.getText()) > 10;
|
||||
|
||||
if (this.firstAccount)
|
||||
{
|
||||
wizard.getWizardContainer().setNextFinishButtonEnabled(true);
|
||||
}
|
||||
else if (hostOK && portOK)
|
||||
{
|
||||
this.strategyLoader.setEnabled(true);
|
||||
wizard.getWizardContainer().setNextFinishButtonEnabled(true);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Disable the finish button
|
||||
wizard.getWizardContainer().setNextFinishButtonEnabled(false);
|
||||
|
||||
// Clear the list and disable the button
|
||||
this.strategiesList.clear();
|
||||
this.strategyLoader.setEnabled(false);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles the <tt>DocumentEvent</tt> triggered when user types in the UIN
|
||||
* field. Enables or disables the "Next" wizard button according to whether
|
||||
* the UIN field is empty.
|
||||
*
|
||||
* @param e the <tt>DocumentEvent</tt> triggered when user types in the UIN
|
||||
* field.
|
||||
*/
|
||||
public void insertUpdate(DocumentEvent e)
|
||||
{
|
||||
this.setNextButtonEnabled();
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles the <tt>DocumentEvent</tt> triggered when user deletes letters
|
||||
* from the UIN field. Enables or disables the "Next" wizard button
|
||||
* according to whether the UIN field is empty.
|
||||
*
|
||||
* @param e The <tt>DocumentEvent</tt> triggered when user deletes letters
|
||||
* from the UIN field.
|
||||
*/
|
||||
public void removeUpdate(DocumentEvent e)
|
||||
{
|
||||
this.setNextButtonEnabled();
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles the <tt>DocumentEvent</tt> triggered when user changes an
|
||||
* attribute or set of attributes from the UIN field.
|
||||
* Currently this notification has no effect and is just here to implement
|
||||
* the DocumentListener interface.
|
||||
*
|
||||
* @param e The <tt>DocumentEvent</tt> triggered when an attribute or set of
|
||||
* attributes changed from the UIN field.
|
||||
*/
|
||||
public void changedUpdate(DocumentEvent e)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Invoked when this WizardPage will be hidden eighter because the user has
|
||||
* clicked "Back" or "Next".
|
||||
* This function has no effect.
|
||||
*/
|
||||
public void pageHiding()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Invoked when this WizardPage will be shown eighter because the user has
|
||||
* clicked "Back" on the next wizard page or "Next" on the previous one.
|
||||
* This function has no effect.
|
||||
*/
|
||||
public void pageShown()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Invoked when user clicks on the "Back" wizard button.
|
||||
* This function has no effect.
|
||||
*/
|
||||
public void pageBack()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Fills the Host, Port and Strategy fields in this panel with the data comming
|
||||
* from the given protocolProvider.
|
||||
*
|
||||
* @param protocolProvider The <tt>ProtocolProviderService</tt> to load
|
||||
* the data from.
|
||||
*/
|
||||
public void loadAccount(ProtocolProviderService protocolProvider)
|
||||
{
|
||||
AccountID accountID = protocolProvider.getAccountID();
|
||||
String host =
|
||||
accountID
|
||||
.getAccountPropertyString(ProtocolProviderFactory.SERVER_ADDRESS);
|
||||
String port =
|
||||
accountID
|
||||
.getAccountPropertyString(ProtocolProviderFactory.SERVER_PORT);
|
||||
String strategy =
|
||||
accountID
|
||||
.getAccountPropertyString(ProtocolProviderFactory.STRATEGY);
|
||||
|
||||
this.initAccountID = accountID;
|
||||
|
||||
// Host field
|
||||
this.hostField.setText(host);
|
||||
|
||||
// Port Field
|
||||
this.portField.setText(port);
|
||||
|
||||
// Load strategies
|
||||
this.initstrategy = strategy;
|
||||
this.populateStrategies();
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles the action of the button.
|
||||
*
|
||||
* @param e The event generated when the button is pressed.
|
||||
*/
|
||||
public void actionPerformed(ActionEvent e)
|
||||
{
|
||||
// Button action -> populate the list
|
||||
if (e.getActionCommand().equals("populateList"))
|
||||
{
|
||||
this.populateStrategies();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if an account is stored for this protocol
|
||||
* @return TRUE, if an account is stored - FALSE otherwise
|
||||
*/
|
||||
private boolean hasAccount()
|
||||
{
|
||||
ProtocolProviderFactory factory =
|
||||
DictAccRegWizzActivator.getDictProtocolProviderFactory();
|
||||
|
||||
return !factory.getRegisteredAccounts().isEmpty();
|
||||
}
|
||||
|
||||
/**
|
||||
* Start the thread which will populate the Strategies List
|
||||
*/
|
||||
public void populateStrategies()
|
||||
{
|
||||
// Clear ArrayList
|
||||
this.strategiesList.clear();
|
||||
|
||||
boolean ok = this.searchThread.submitRequest(this.hostField.getText(),
|
||||
Integer.parseInt(this.portField.getText()));
|
||||
|
||||
if (!ok)
|
||||
{
|
||||
// TODO Display error
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Automatic selection of a strategy
|
||||
*/
|
||||
public void autoSelectStrategy()
|
||||
{
|
||||
this.strategiesList.autoSelectStrategy(this.initstrategy);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param strategies
|
||||
*/
|
||||
public void setStrategies(List<Strategy> strategies)
|
||||
{
|
||||
this.strategiesList.setStrategies(strategies);
|
||||
}
|
||||
|
||||
/**
|
||||
* Informs the user of the current status of the search
|
||||
* Should only be called by the thread
|
||||
* @param message Search status
|
||||
*/
|
||||
public void progressMessage(String message)
|
||||
{
|
||||
this.searchProgressPanel.nextStep(message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Informs the wizard that the search of the strategies is complete.
|
||||
* Should only be called by the thread
|
||||
*/
|
||||
public void strategiesSearchComplete()
|
||||
{
|
||||
setStrategyButtonEnable(true);
|
||||
this.searchProgressPanel.finish();
|
||||
}
|
||||
|
||||
/**
|
||||
* Informs the wizard that the search of the strategies is a failure
|
||||
* Should only be called by the thread
|
||||
* @param reason Reason message
|
||||
* @param de Exception thrown
|
||||
*/
|
||||
public void strategiesSearchFailure(String reason, DictException de)
|
||||
{
|
||||
strategiesSearchComplete();
|
||||
// TODO SHOW ERROR MESSAGE
|
||||
}
|
||||
|
||||
/**
|
||||
* Enables or disable the Next Button and the Strategy Button
|
||||
* @param e TRUE enables - FALSE disables
|
||||
*/
|
||||
public void setStrategyButtonEnable(boolean e)
|
||||
{
|
||||
// During all the process the buttons and the fieldsset are in the same state
|
||||
|
||||
this.hostField.setEnabled(e);
|
||||
this.portField.setEnabled(e);
|
||||
|
||||
this.strategyLoader.setEnabled(e);
|
||||
wizard.getWizardContainer().setNextFinishButtonEnabled(e);
|
||||
}
|
||||
|
||||
public Object getSimpleForm()
|
||||
{
|
||||
return mainPanel;
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicates if this is the first dict account
|
||||
*
|
||||
* @return TRUE if this is the first dict account - FALSE otherwise
|
||||
*/
|
||||
public boolean isFirstAccount()
|
||||
{
|
||||
return this.firstAccount;
|
||||
}
|
||||
|
||||
public boolean isCommitted()
|
||||
{
|
||||
return isPageCommitted;
|
||||
}
|
||||
}
|
||||
@ -1,156 +0,0 @@
|
||||
/*
|
||||
* Jitsi, the OpenSource Java VoIP and Instant Messaging client.
|
||||
*
|
||||
* Copyright @ 2015 Atlassian Pty Ltd
|
||||
*
|
||||
* 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 net.java.sip.communicator.plugin.dictaccregwizz;
|
||||
|
||||
import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
|
||||
import javax.swing.*;
|
||||
|
||||
import net.java.sip.communicator.plugin.desktoputil.*;
|
||||
|
||||
/**
|
||||
* Panel showing the current status of the search of the strategies
|
||||
*
|
||||
* @author ROTH Damien
|
||||
*/
|
||||
public class ProgressPanel
|
||||
extends TransparentPanel
|
||||
implements ActionListener
|
||||
{
|
||||
/**
|
||||
* Serial version UID.
|
||||
*/
|
||||
private static final long serialVersionUID = 0L;
|
||||
|
||||
private JPanel rightPanel;
|
||||
|
||||
private JLabel messageLabel;
|
||||
private JLabel progressLabel;
|
||||
private JButton cancelButton;
|
||||
|
||||
private int currentStep;
|
||||
private int totalSteps;
|
||||
|
||||
private boolean isBuild;
|
||||
|
||||
private ThreadManager searchThread;
|
||||
|
||||
/**
|
||||
* Create an instance of <tt>ProgressPanel</tt>
|
||||
* @param searchThread The thread manager
|
||||
*/
|
||||
public ProgressPanel(ThreadManager searchThread)
|
||||
{
|
||||
super(new BorderLayout());
|
||||
|
||||
// Element creation
|
||||
this.messageLabel = new JLabel(" ");
|
||||
this.progressLabel = new JLabel(" ");
|
||||
this.cancelButton
|
||||
= new JButton(Resources.getString("service.gui.CANCEL"));
|
||||
this.cancelButton.addActionListener(this);
|
||||
|
||||
// Right panel init
|
||||
this.rightPanel = new TransparentPanel(new FlowLayout(FlowLayout.RIGHT));
|
||||
this.rightPanel.add(this.progressLabel);
|
||||
this.rightPanel.add(this.cancelButton);
|
||||
|
||||
this.searchThread = searchThread;
|
||||
|
||||
init();
|
||||
this.totalSteps = ThreadManager.NB_STEPS;
|
||||
}
|
||||
|
||||
/**
|
||||
* Init the values
|
||||
*/
|
||||
private void init()
|
||||
{
|
||||
this.isBuild = false;
|
||||
this.currentStep = 1;
|
||||
|
||||
this.add(this.messageLabel, BorderLayout.CENTER);
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the UI
|
||||
*/
|
||||
private void build()
|
||||
{
|
||||
if (this.isBuild)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
this.add(this.messageLabel, BorderLayout.CENTER);
|
||||
this.add(this.rightPanel, BorderLayout.EAST);
|
||||
|
||||
this.isBuild = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Move to the next step without updating the message
|
||||
*/
|
||||
public void nextStep()
|
||||
{
|
||||
nextStep(this.messageLabel.getText());
|
||||
}
|
||||
|
||||
/**
|
||||
* Mode to the next step with a new message
|
||||
* @param message Message
|
||||
*/
|
||||
public void nextStep(String message)
|
||||
{
|
||||
if (this.currentStep > this.totalSteps)
|
||||
{
|
||||
finish();
|
||||
}
|
||||
|
||||
build();
|
||||
this.messageLabel.setText(message);
|
||||
this.progressLabel.setText(currentStep + "/" + totalSteps);
|
||||
|
||||
this.currentStep++;
|
||||
}
|
||||
|
||||
/**
|
||||
* Informs the end of the progress. Remove all the components and
|
||||
* reset the values
|
||||
*/
|
||||
public void finish()
|
||||
{
|
||||
// Remove all elements
|
||||
this.removeAll();
|
||||
|
||||
// Re-init the panel
|
||||
this.messageLabel.setText(" ");
|
||||
this.progressLabel.setText(" ");
|
||||
init();
|
||||
|
||||
this.repaint();
|
||||
this.validate();
|
||||
}
|
||||
|
||||
public void actionPerformed(ActionEvent arg0)
|
||||
{
|
||||
this.searchThread.cancel();
|
||||
this.finish();
|
||||
}
|
||||
}
|
||||
@ -1,75 +0,0 @@
|
||||
/*
|
||||
* Jitsi, the OpenSource Java VoIP and Instant Messaging client.
|
||||
*
|
||||
* Copyright @ 2015 Atlassian Pty Ltd
|
||||
*
|
||||
* 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 net.java.sip.communicator.plugin.dictaccregwizz;
|
||||
|
||||
import net.java.sip.communicator.service.resources.*;
|
||||
|
||||
import org.jitsi.service.resources.*;
|
||||
|
||||
/**
|
||||
* The <tt>Resources</tt> class manages the access to the internationalization
|
||||
* properties files and the image resources used in this plugin.
|
||||
*
|
||||
* @author ROTH Damien
|
||||
* @author LITZELMAN Cedric
|
||||
*/
|
||||
public class Resources
|
||||
{
|
||||
private static ResourceManagementService resourcesService;
|
||||
|
||||
public static ImageID DICT_LOGO
|
||||
= new ImageID("service.protocol.dict.DICT_16x16");
|
||||
|
||||
public static ImageID PAGE_IMAGE
|
||||
= new ImageID("service.protocol.dict.DICT_64x64");
|
||||
|
||||
/**
|
||||
* Returns an internationalized string corresponding to the given key.
|
||||
*
|
||||
* @param key The key of the string.
|
||||
* @return An internationalized string corresponding to the given key.
|
||||
*/
|
||||
public static String getString(String key)
|
||||
{
|
||||
return getResources().getI18NString(key);
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads an image from a given image identifier.
|
||||
* @param imageID The identifier of the image.
|
||||
* @return The image for the given identifier.
|
||||
*/
|
||||
public static byte[] getImage(ImageID imageID)
|
||||
{
|
||||
return getResources().getImageInBytes(imageID.getId());
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the <tt>ResourceManagementService</tt>.
|
||||
*
|
||||
* @return the <tt>ResourceManagementService</tt>.
|
||||
*/
|
||||
public static ResourceManagementService getResources()
|
||||
{
|
||||
if (resourcesService == null)
|
||||
resourcesService =
|
||||
ResourceManagementServiceUtils
|
||||
.getService(DictAccRegWizzActivator.bundleContext);
|
||||
return resourcesService;
|
||||
}
|
||||
}
|
||||
@ -1,240 +0,0 @@
|
||||
/*
|
||||
* Jitsi, the OpenSource Java VoIP and Instant Messaging client.
|
||||
*
|
||||
* Copyright @ 2015 Atlassian Pty Ltd
|
||||
*
|
||||
* 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 net.java.sip.communicator.plugin.dictaccregwizz;
|
||||
|
||||
import java.awt.*;
|
||||
import java.util.*;
|
||||
import java.util.List;
|
||||
|
||||
import javax.swing.*;
|
||||
|
||||
import net.java.dict4j.*;
|
||||
|
||||
/**
|
||||
* Class managing the list of strategies
|
||||
*
|
||||
* @author ROTH Damien
|
||||
*/
|
||||
public class StrategiesList
|
||||
extends JList
|
||||
{
|
||||
/**
|
||||
* Serial version UID.
|
||||
*/
|
||||
private static final long serialVersionUID = 0L;
|
||||
|
||||
private ListModel model;
|
||||
private CellRenderer renderer;
|
||||
|
||||
/**
|
||||
* Create an instance of the <tt>StrategiesList</tt>
|
||||
*/
|
||||
public StrategiesList()
|
||||
{
|
||||
super();
|
||||
|
||||
this.model = new ListModel();
|
||||
this.renderer = new CellRenderer();
|
||||
|
||||
this.setCellRenderer(this.renderer);
|
||||
this.setModel(model);
|
||||
this.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
|
||||
this.setVisibleRowCount(6);
|
||||
}
|
||||
|
||||
/**
|
||||
* Stores a new set of strategies
|
||||
* @param strategies List of strategies
|
||||
*/
|
||||
public void setStrategies(List<Strategy> strategies)
|
||||
{
|
||||
this.model.setStrategies(strategies);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove all the strategies of the list
|
||||
*/
|
||||
public void clear()
|
||||
{
|
||||
this.model.clear();
|
||||
}
|
||||
|
||||
/**
|
||||
* Automatic selection of strategies
|
||||
* @param initStrategy
|
||||
*/
|
||||
public void autoSelectStrategy(String initStrategy)
|
||||
{
|
||||
int index = -1;
|
||||
|
||||
if (initStrategy.length() > 0)
|
||||
{ // saved strategy
|
||||
index = this.model.indexOf(initStrategy);
|
||||
}
|
||||
if (index < 0)
|
||||
{
|
||||
// First case : levenstein distance
|
||||
index = this.model.indexOf("lev");
|
||||
}
|
||||
if (index < 0)
|
||||
{
|
||||
// Second case : soundex
|
||||
index = this.model.indexOf("soundex");
|
||||
}
|
||||
if (index < 0)
|
||||
{
|
||||
// Last case : prefix
|
||||
index = this.model.indexOf("prefix");
|
||||
}
|
||||
|
||||
// If the index is still < 0, we select the first index
|
||||
if (index < 0)
|
||||
{
|
||||
index = 0;
|
||||
}
|
||||
if (index < this.getVisibleRowCount())
|
||||
{
|
||||
// If the index is visible row, we don't need to scroll
|
||||
this.setSelectedIndex(index);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Otherwise, we scroll to the selected value
|
||||
this.setSelectedValue(this.model.getElementAt(index), true);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Class managing the list datas
|
||||
*
|
||||
* @author ROTH Damien
|
||||
*/
|
||||
static class ListModel
|
||||
extends AbstractListModel
|
||||
{
|
||||
/**
|
||||
* Serial version UID.
|
||||
*/
|
||||
private static final long serialVersionUID = 0L;
|
||||
|
||||
private List<Strategy> data;
|
||||
|
||||
/**
|
||||
* Create an instance of <tt>ListModel</tt>
|
||||
*/
|
||||
public ListModel()
|
||||
{
|
||||
data = new ArrayList<Strategy>();
|
||||
}
|
||||
|
||||
/**
|
||||
* Stores the strategies into this model
|
||||
* @param strategies the strategies list
|
||||
*/
|
||||
public void setStrategies(List<Strategy> strategies)
|
||||
{
|
||||
data = strategies;
|
||||
fireContentsChanged(this, 0, data.size());
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove all the strategies of the list
|
||||
*/
|
||||
public void clear()
|
||||
{
|
||||
data.clear();
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements <tt>ListModel.getElementAt</tt>
|
||||
*/
|
||||
public Strategy getElementAt(int row)
|
||||
{
|
||||
return data.get(row);
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements <tt>ListModel.getSize</tt>
|
||||
*/
|
||||
public int getSize()
|
||||
{
|
||||
return data.size();
|
||||
}
|
||||
|
||||
/**
|
||||
* Find the index of a strategy.
|
||||
*
|
||||
* @param strategyCode the code of the strategy
|
||||
* @return the index of the strategy
|
||||
*/
|
||||
public int indexOf(String strategyCode)
|
||||
{
|
||||
for (int i = 0, size = data.size(); i < size; i++)
|
||||
{
|
||||
if (data.get(i).getCode().equals(strategyCode))
|
||||
return i;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Class managing the cell rendering
|
||||
*
|
||||
* @author ROTH Damien
|
||||
*/
|
||||
static class CellRenderer
|
||||
extends JLabel
|
||||
implements ListCellRenderer
|
||||
{
|
||||
/**
|
||||
* Serial version UID.
|
||||
*/
|
||||
private static final long serialVersionUID = 0L;
|
||||
|
||||
/**
|
||||
* implements <tt>ListCellRenderer.getListCellRendererComponent</tt>
|
||||
*/
|
||||
public Component getListCellRendererComponent(
|
||||
JList list,
|
||||
Object value,
|
||||
int index,
|
||||
boolean isSelected,
|
||||
boolean cellHasFocus)
|
||||
{
|
||||
setText(((Strategy) value).getName());
|
||||
|
||||
if (isSelected)
|
||||
{
|
||||
setBackground(list.getSelectionBackground());
|
||||
setForeground(list.getSelectionForeground());
|
||||
}
|
||||
else
|
||||
{
|
||||
setBackground(list.getBackground());
|
||||
setForeground(list.getForeground());
|
||||
}
|
||||
setEnabled(list.isEnabled());
|
||||
setFont(list.getFont());
|
||||
setOpaque(true);
|
||||
|
||||
return this;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,199 +0,0 @@
|
||||
/*
|
||||
* Jitsi, the OpenSource Java VoIP and Instant Messaging client.
|
||||
*
|
||||
* Copyright @ 2015 Atlassian Pty Ltd
|
||||
*
|
||||
* 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 net.java.sip.communicator.plugin.dictaccregwizz;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import net.java.dict4j.*;
|
||||
import net.java.sip.communicator.util.*;
|
||||
|
||||
/**
|
||||
* Class manager the thread called for searching the strategies' list
|
||||
*
|
||||
* @author ROTH Damien
|
||||
*/
|
||||
public class ThreadManager
|
||||
{
|
||||
protected static Logger logger = Logger.getLogger(ThreadManager.class);
|
||||
public static int NB_STEPS = 4;
|
||||
|
||||
private StrategyThread thread = null;
|
||||
private FirstWizardPage wizard = null;
|
||||
|
||||
/**
|
||||
* Create an instance of <tt>ThreadManager</tt>
|
||||
* @param wiz Wizard
|
||||
*/
|
||||
public ThreadManager(FirstWizardPage wiz)
|
||||
{
|
||||
this.wizard = wiz;
|
||||
}
|
||||
|
||||
/**
|
||||
* Submit a request to launch the thread
|
||||
* @param host Server host
|
||||
* @param port Server port
|
||||
* @return TRUE if the thread is started - FALSE otherwise
|
||||
*/
|
||||
public boolean submitRequest(String host, int port)
|
||||
{
|
||||
if (this.thread != null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
this.thread = new StrategyThread(this.wizard, host, port);
|
||||
this.thread.start();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Stop the thread
|
||||
*/
|
||||
public void cancel()
|
||||
{
|
||||
if (this.thread != null)
|
||||
{
|
||||
this.thread.interrupt();
|
||||
this.thread = null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Wait for the searching thread to stop
|
||||
* @return true if success, false otherwise
|
||||
*/
|
||||
public boolean waitThread()
|
||||
{
|
||||
if (this.thread == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
this.thread.join();
|
||||
}
|
||||
catch (InterruptedException e)
|
||||
{
|
||||
if (logger.isInfoEnabled())
|
||||
logger.info(e);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Thread used to search the strategies
|
||||
*
|
||||
* @author ROTH Damien, LITZELMANN Cedric
|
||||
*/
|
||||
static class StrategyThread
|
||||
extends Thread
|
||||
{
|
||||
private final FirstWizardPage wizard;
|
||||
private final String host;
|
||||
private final int port;
|
||||
|
||||
/**
|
||||
* Informations messages
|
||||
*/
|
||||
private String[] messages = new String[] {
|
||||
Resources.getString(
|
||||
"plugin.dictaccregwizz.THREAD_CONNECT"),
|
||||
Resources.getString(
|
||||
"plugin.dictaccregwizz.THREAD_CONNECT_FAILED"),
|
||||
Resources.getString(
|
||||
"plugin.dictaccregwizz.RETRIEVING_STRATEGIES"),
|
||||
Resources.getString(
|
||||
"plugin.dictaccregwizz.NO_STRATEGIES_FOUND"),
|
||||
Resources.getString(
|
||||
"plugin.dictaccregwizz.POPULATE_LIST"),
|
||||
Resources.getString(
|
||||
"plugin.dictaccregwizz.CLOSING_CONNECTION")
|
||||
};
|
||||
|
||||
/**
|
||||
* Create an instance of the thread
|
||||
* @param wizard The wizard who started the thread
|
||||
* @param host Server host
|
||||
* @param port Server port
|
||||
*/
|
||||
public StrategyThread(FirstWizardPage wizard, String host, int port)
|
||||
{
|
||||
this.wizard = wizard;
|
||||
this.host = host;
|
||||
this.port = port;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
List<Strategy> strategies = null;
|
||||
|
||||
DictConnection dictConnection = new DictConnection(host, port);
|
||||
|
||||
// Open the connection to the server
|
||||
this.wizard.progressMessage(messages[0]);
|
||||
try
|
||||
{
|
||||
dictConnection.connect();
|
||||
}
|
||||
catch (DictException e)
|
||||
{
|
||||
this.wizard.strategiesSearchFailure(this.messages[1], e);
|
||||
return;
|
||||
}
|
||||
|
||||
// Get the strategies
|
||||
this.wizard.progressMessage(messages[2]);
|
||||
try
|
||||
{
|
||||
strategies = dictConnection.getStrategies();
|
||||
}
|
||||
catch (DictException e)
|
||||
{
|
||||
this.wizard.strategiesSearchFailure(this.messages[3], e);
|
||||
return;
|
||||
}
|
||||
|
||||
// Store the strategies
|
||||
this.wizard.progressMessage(messages[4]);
|
||||
this.wizard.setStrategies(strategies);
|
||||
this.wizard.autoSelectStrategy();
|
||||
|
||||
// Close the connection
|
||||
this.wizard.progressMessage(messages[5]);
|
||||
try
|
||||
{
|
||||
dictConnection.close();
|
||||
}
|
||||
catch (DictException e)
|
||||
{
|
||||
// An error while closing the connection isn't very important
|
||||
// We just log it
|
||||
ThreadManager.logger.info("DICT search strategies thread : " +
|
||||
"Error while closing connection", e);
|
||||
}
|
||||
|
||||
// End of the search
|
||||
this.wizard.strategiesSearchComplete();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,34 +0,0 @@
|
||||
Bundle-Activator: net.java.sip.communicator.plugin.dictaccregwizz.DictAccRegWizzActivator
|
||||
Bundle-Name: Dict account registration wizard
|
||||
Bundle-Description: Dict account registration wizard.
|
||||
Bundle-Vendor: jitsi.org
|
||||
Bundle-Version: 0.0.1
|
||||
Bundle-SymbolicName: net.java.sip.communicator.plugin.dictaccregwizz
|
||||
Import-Package: org.osgi.framework,
|
||||
net.java.dict4j,
|
||||
net.java.sip.communicator.service.browserlauncher,
|
||||
org.jitsi.service.configuration,
|
||||
net.java.sip.communicator.service.contactlist,
|
||||
net.java.sip.communicator.service.contactlist.event,
|
||||
net.java.sip.communicator.service.gui,
|
||||
net.java.sip.communicator.service.gui.event,
|
||||
net.java.sip.communicator.service.protocol,
|
||||
net.java.sip.communicator.service.protocol.event,
|
||||
net.java.sip.communicator.service.protocol.icqconstants,
|
||||
org.jitsi.service.resources, net.java.sip.communicator.service.resources,
|
||||
net.java.sip.communicator.util,
|
||||
net.java.sip.communicator.plugin.desktoputil,
|
||||
javax.swing,
|
||||
javax.swing.event,
|
||||
javax.swing.table,
|
||||
javax.swing.text,
|
||||
javax.swing.text.html,
|
||||
javax.accessibility,
|
||||
javax.swing.plaf,
|
||||
javax.swing.plaf.metal,
|
||||
javax.swing.plaf.basic,
|
||||
javax.imageio,
|
||||
javax.swing.filechooser,
|
||||
javax.swing.tree,
|
||||
javax.swing.undo,
|
||||
javax.swing.border
|
||||
Loading…
Reference in new issue