mirror of https://github.com/sipwise/jitsi.git
parent
27cc37a5b5
commit
d8f5668556
@ -0,0 +1,219 @@
|
||||
/*
|
||||
* SIP Communicator, the OpenSource Java VoIP and Instant Messaging client.
|
||||
*
|
||||
* Distributable under LGPL license.
|
||||
* See terms of license at gnu.org.
|
||||
*/
|
||||
package net.java.sip.communicator.impl.protocol.jabber;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import org.jivesoftware.smackx.*;
|
||||
|
||||
import net.java.sip.communicator.service.protocol.*;
|
||||
|
||||
/**
|
||||
* The Jabber protocol implementation of the
|
||||
* <tt>ChatRoomConfigurationFormField</tt>. This implementation is based on the
|
||||
* smack Form and FormField types.
|
||||
*
|
||||
* @author Yana Stamcheva
|
||||
*/
|
||||
public class ChatRoomConfigurationFormFieldJabberImpl
|
||||
implements ChatRoomConfigurationFormField
|
||||
{
|
||||
/**
|
||||
* The smack library for field.
|
||||
*/
|
||||
private FormField smackFormField;
|
||||
|
||||
/**
|
||||
* The smack library submit form field. It's the one that will care all
|
||||
* values set by user, before submitting the form.
|
||||
*/
|
||||
private FormField smackSubmitFormField;
|
||||
|
||||
/**
|
||||
* Creates an instance of <tt>ChatRoomConfigurationFormFieldJabberImpl</tt>
|
||||
* by passing to it the smack form field and the smack submit form, which
|
||||
* are the base of this implementation.
|
||||
*
|
||||
* @param formField the smack form field
|
||||
* @param submitForm the smack submit form
|
||||
*/
|
||||
public ChatRoomConfigurationFormFieldJabberImpl(
|
||||
FormField formField,
|
||||
Form submitForm)
|
||||
{
|
||||
this.smackFormField = formField;
|
||||
|
||||
if(!formField.getType().equals(FormField.TYPE_FIXED))
|
||||
this.smackSubmitFormField
|
||||
= submitForm.getField(formField.getVariable());
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the variable name of the corresponding smack property.
|
||||
*
|
||||
* @return the variable name of the corresponding smack property
|
||||
*/
|
||||
public String getName()
|
||||
{
|
||||
return smackFormField.getVariable();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the description of the corresponding smack property.
|
||||
*
|
||||
* @return the description of the corresponding smack property
|
||||
*/
|
||||
public String getDescription()
|
||||
{
|
||||
return smackFormField.getDescription();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the label of the corresponding smack property.
|
||||
*
|
||||
* @return the label of the corresponding smack property
|
||||
*/
|
||||
public String getLabel()
|
||||
{
|
||||
return smackFormField.getLabel();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the options of the corresponding smack property.
|
||||
*
|
||||
* @return the options of the corresponding smack property
|
||||
*/
|
||||
public Iterator getOptions()
|
||||
{
|
||||
List options = new ArrayList();
|
||||
Iterator smackOptions = smackFormField.getOptions();
|
||||
|
||||
while(smackOptions.hasNext())
|
||||
{
|
||||
FormField.Option smackOption
|
||||
= (FormField.Option) smackOptions.next();
|
||||
|
||||
options.add(smackOption.getValue());
|
||||
}
|
||||
|
||||
return Collections.unmodifiableList(options).iterator();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the isRequired property of the corresponding smack property.
|
||||
*
|
||||
* @return the isRequired property of the corresponding smack property
|
||||
*/
|
||||
public boolean isRequired()
|
||||
{
|
||||
return smackFormField.isRequired();
|
||||
}
|
||||
|
||||
/**
|
||||
* For each of the smack form field types returns the corresponding
|
||||
* <tt>ChatRoomConfigurationFormField</tt> type.
|
||||
*
|
||||
* @return the type of the property
|
||||
*/
|
||||
public String getType()
|
||||
{
|
||||
String smackType = smackFormField.getType();
|
||||
|
||||
if(smackType.equals(FormField.TYPE_BOOLEAN))
|
||||
return TYPE_BOOLEAN;
|
||||
if(smackType.equals(FormField.TYPE_FIXED))
|
||||
return TYPE_TEXT_FIXED;
|
||||
else if(smackType.equals(FormField.TYPE_TEXT_PRIVATE))
|
||||
return TYPE_TEXT_PRIVATE;
|
||||
else if(smackType.equals(FormField.TYPE_TEXT_SINGLE))
|
||||
return TYPE_TEXT_SINGLE;
|
||||
else if(smackType.equals(FormField.TYPE_TEXT_MULTI))
|
||||
return TYPE_TEXT_MULTI;
|
||||
else if(smackType.equals(FormField.TYPE_LIST_SINGLE))
|
||||
return TYPE_LIST_SINGLE;
|
||||
else if(smackType.equals(FormField.TYPE_LIST_MULTI))
|
||||
return TYPE_LIST_MULTI;
|
||||
else
|
||||
return TYPE_UNDEFINED;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an Iterator over the list of values of this field.
|
||||
*
|
||||
* @return an Iterator over the list of values of this field
|
||||
*/
|
||||
public Iterator getValues()
|
||||
{
|
||||
Iterator valuesIter = null;
|
||||
List values = new ArrayList();
|
||||
Iterator smackValues = smackFormField.getValues();
|
||||
|
||||
if(smackFormField.getType().equals(FormField.TYPE_BOOLEAN))
|
||||
{
|
||||
while(smackValues.hasNext())
|
||||
{
|
||||
String smackValue = (String) smackValues.next();
|
||||
|
||||
if(smackValue.equals("1") || smackValue.equals("true"))
|
||||
values.add(new Boolean(true));
|
||||
else
|
||||
values.add(new Boolean(false));
|
||||
}
|
||||
|
||||
valuesIter = values.iterator();
|
||||
}
|
||||
else
|
||||
valuesIter = smackValues;
|
||||
|
||||
return valuesIter;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the given value to the list of values of this field.
|
||||
*
|
||||
* @param value the value to add
|
||||
*/
|
||||
public void addValue(Object value)
|
||||
{
|
||||
if(value instanceof Boolean)
|
||||
{
|
||||
if(((Boolean)value).booleanValue())
|
||||
value = "1";
|
||||
else
|
||||
value = "0";
|
||||
}
|
||||
|
||||
smackSubmitFormField.addValue(value.toString());
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the given list of values to this field.
|
||||
*
|
||||
* @param newValues the list of values to set
|
||||
*/
|
||||
public void setValues(Object[] newValues)
|
||||
{
|
||||
ArrayList list = new ArrayList();
|
||||
|
||||
for(int i = 0; i < newValues.length; i ++)
|
||||
{
|
||||
Object value = newValues[i];
|
||||
|
||||
if(value instanceof Boolean)
|
||||
{
|
||||
if(((Boolean)value).booleanValue())
|
||||
value = "1";
|
||||
else
|
||||
value = "0";
|
||||
}
|
||||
|
||||
list.add(value);
|
||||
}
|
||||
|
||||
smackSubmitFormField.addValues(list);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,115 @@
|
||||
/*
|
||||
* SIP Communicator, the OpenSource Java VoIP and Instant Messaging client.
|
||||
*
|
||||
* Distributable under LGPL license.
|
||||
* See terms of license at gnu.org.
|
||||
*/
|
||||
package net.java.sip.communicator.impl.protocol.jabber;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import net.java.sip.communicator.service.protocol.*;
|
||||
import net.java.sip.communicator.util.*;
|
||||
|
||||
import org.jivesoftware.smack.*;
|
||||
import org.jivesoftware.smackx.*;
|
||||
import org.jivesoftware.smackx.muc.*;
|
||||
|
||||
/**
|
||||
* The Jabber implementation of the <tt>ChatRoomConfigurationForm</tt>
|
||||
* interface.
|
||||
*
|
||||
* @author Yana Stamcheva
|
||||
*/
|
||||
public class ChatRoomConfigurationFormJabberImpl
|
||||
implements ChatRoomConfigurationForm
|
||||
{
|
||||
private Logger logger
|
||||
= Logger.getLogger(ChatRoomConfigurationFormJabberImpl.class);
|
||||
|
||||
/**
|
||||
* The smack chat room configuration form.
|
||||
*/
|
||||
private Form smackConfigForm;
|
||||
|
||||
/**
|
||||
* The form that will be filled out and submitted by user.
|
||||
*/
|
||||
private Form smackSubmitForm;
|
||||
|
||||
/**
|
||||
* The smack multi user chat is the one to which we'll send the form once
|
||||
* filled out.
|
||||
*/
|
||||
private MultiUserChat smackMultiUserChat;
|
||||
|
||||
/**
|
||||
* Creates an instance of <tt>ChatRoomConfigurationFormJabberImpl</tt> by
|
||||
* specifying the corresponding smack multi user chat and smack
|
||||
* configuration form.
|
||||
*
|
||||
* @param multiUserChat the smack multi user chat, to which we'll send the
|
||||
* configuration form once filled out
|
||||
* @param smackConfigForm the smack configuration form
|
||||
*/
|
||||
public ChatRoomConfigurationFormJabberImpl(
|
||||
MultiUserChat multiUserChat, Form smackConfigForm)
|
||||
{
|
||||
this.smackMultiUserChat = multiUserChat;
|
||||
this.smackConfigForm = smackConfigForm;
|
||||
this.smackSubmitForm = smackConfigForm.createAnswerForm();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an Iterator over a list of
|
||||
* <tt>ChatRoomConfigurationFormFields</tt>.
|
||||
*
|
||||
* @return an Iterator over a list of
|
||||
* <tt>ChatRoomConfigurationFormFields</tt>
|
||||
*/
|
||||
public Iterator getConfigurationSet()
|
||||
{
|
||||
Vector configFormFields = new Vector();
|
||||
|
||||
Iterator smackFormFields = smackConfigForm.getFields();
|
||||
|
||||
while(smackFormFields.hasNext())
|
||||
{
|
||||
FormField smackFormField = (FormField) smackFormFields.next();
|
||||
|
||||
if(smackFormField == null
|
||||
|| smackFormField.getType().equals(FormField.TYPE_HIDDEN))
|
||||
continue;
|
||||
|
||||
ChatRoomConfigurationFormFieldJabberImpl jabberConfigField
|
||||
= new ChatRoomConfigurationFormFieldJabberImpl(
|
||||
smackFormField, smackSubmitForm);
|
||||
|
||||
configFormFields.add(jabberConfigField);
|
||||
}
|
||||
|
||||
return Collections.unmodifiableList(configFormFields).iterator();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends the ready smack configuration form to the multi user chat.
|
||||
*/
|
||||
public void submit()
|
||||
throws OperationFailedException
|
||||
{
|
||||
logger.trace("Sends chat room configuration form to the server.");
|
||||
|
||||
try
|
||||
{
|
||||
smackMultiUserChat.sendConfigurationForm(smackSubmitForm);
|
||||
}
|
||||
catch (XMPPException e)
|
||||
{
|
||||
logger.error("Failed to submit the configuration form.", e);
|
||||
|
||||
throw new OperationFailedException(
|
||||
"Failed to submit the configuration form.",
|
||||
OperationFailedException.GENERAL_ERROR);
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in new issue