mirror of
https://codeberg.org/Mercury-IM/Smack
synced 2025-09-10 18:59:41 +02:00
HTML and comment cleanup. Small API refactors. Moved use of StringBuffer to StringBuilder.
git-svn-id: http://svn.igniterealtime.org/svn/repos/smack/trunk@10865 b35dd754-fafc-0310-a699-88a17e54d16e
This commit is contained in:
parent
b927475caa
commit
334838d28e
32 changed files with 271 additions and 305 deletions
|
@ -274,7 +274,7 @@ public class Privacy extends IQ {
|
|||
}
|
||||
|
||||
public String getChildElementXML() {
|
||||
StringBuffer buf = new StringBuffer();
|
||||
StringBuilder buf = new StringBuilder();
|
||||
buf.append("<query xmlns=\"jabber:iq:privacy\">");
|
||||
|
||||
// Add the active tag
|
||||
|
|
|
@ -251,7 +251,7 @@ public class PrivacyItem {
|
|||
* @return the text xml representation.
|
||||
*/
|
||||
public String toXML() {
|
||||
StringBuffer buf = new StringBuffer();
|
||||
StringBuilder buf = new StringBuilder();
|
||||
buf.append("<item");
|
||||
if (this.isAllow()) {
|
||||
buf.append(" action=\"allow\"");
|
||||
|
|
|
@ -198,7 +198,7 @@ public class XMPPError {
|
|||
* @return the error as XML.
|
||||
*/
|
||||
public String toXML() {
|
||||
StringBuffer buf = new StringBuffer();
|
||||
StringBuilder buf = new StringBuilder();
|
||||
buf.append("<error code=\"").append(code).append("\"");
|
||||
if (type != null) {
|
||||
buf.append(" type=\"");
|
||||
|
@ -223,7 +223,7 @@ public class XMPPError {
|
|||
}
|
||||
|
||||
public String toString() {
|
||||
StringBuffer txt = new StringBuffer();
|
||||
StringBuilder txt = new StringBuilder();
|
||||
if (condition != null) {
|
||||
txt.append(condition);
|
||||
}
|
||||
|
|
|
@ -48,7 +48,7 @@ public class SASLAnonymous extends SASLMechanism {
|
|||
}
|
||||
|
||||
protected void authenticate() throws IOException {
|
||||
StringBuffer stanza = new StringBuffer();
|
||||
StringBuilder stanza = new StringBuilder();
|
||||
stanza.append("<auth mechanism=\"").append(getName());
|
||||
stanza.append("\" xmlns=\"urn:ietf:params:xml:ns:xmpp-sasl\">");
|
||||
stanza.append("</auth>");
|
||||
|
@ -59,7 +59,7 @@ public class SASLAnonymous extends SASLMechanism {
|
|||
|
||||
public void challengeReceived(String challenge) throws IOException {
|
||||
// Build the challenge response stanza encoding the response text
|
||||
StringBuffer stanza = new StringBuffer();
|
||||
StringBuilder stanza = new StringBuilder();
|
||||
stanza.append("<response xmlns=\"urn:ietf:params:xml:ns:xmpp-sasl\">");
|
||||
stanza.append("=");
|
||||
stanza.append("</response>");
|
||||
|
|
|
@ -110,7 +110,7 @@ public abstract class SASLMechanism implements CallbackHandler {
|
|||
}
|
||||
|
||||
protected void authenticate() throws IOException, XMPPException {
|
||||
StringBuffer stanza = new StringBuffer();
|
||||
StringBuilder stanza = new StringBuilder();
|
||||
stanza.append("<auth mechanism=\"").append(getName());
|
||||
stanza.append("\" xmlns=\"urn:ietf:params:xml:ns:xmpp-sasl\">");
|
||||
try {
|
||||
|
@ -140,7 +140,7 @@ public abstract class SASLMechanism implements CallbackHandler {
|
|||
*/
|
||||
public void challengeReceived(String challenge) throws IOException {
|
||||
// Build the challenge response stanza encoding the response text
|
||||
StringBuffer stanza = new StringBuffer();
|
||||
StringBuilder stanza = new StringBuilder();
|
||||
|
||||
byte response[];
|
||||
if(challenge != null) {
|
||||
|
|
|
@ -1071,7 +1071,7 @@ public class AbstractHashedMap <K,V> extends AbstractMap<K, V> implements Iterab
|
|||
}
|
||||
|
||||
public String toString() {
|
||||
return new StringBuffer().append(getKey()).append('=').append(getValue()).toString();
|
||||
return new StringBuilder().append(getKey()).append('=').append(getValue()).toString();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1316,7 +1316,7 @@ public class AbstractHashedMap <K,V> extends AbstractMap<K, V> implements Iterab
|
|||
if (size() == 0) {
|
||||
return "{}";
|
||||
}
|
||||
StringBuffer buf = new StringBuffer(32 * size());
|
||||
StringBuilder buf = new StringBuilder(32 * size());
|
||||
buf.append('{');
|
||||
|
||||
MapIterator it = mapIterator();
|
||||
|
|
|
@ -74,7 +74,7 @@ public abstract class AbstractKeyValue <K,V> implements KeyValue<K, V> {
|
|||
* @return a String view of the entry
|
||||
*/
|
||||
public String toString() {
|
||||
return new StringBuffer().append(getKey()).append('=').append(getValue()).toString();
|
||||
return new StringBuilder().append(getKey()).append('=').append(getValue()).toString();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -69,11 +69,11 @@ import java.util.List;
|
|||
*
|
||||
*/
|
||||
public abstract class AdHocCommand {
|
||||
// TODO Analize the redesign of command by having an ExecutionResponse as a
|
||||
// result to the execution of every action. That result should have all the
|
||||
// information related to the execution, e.g. the form to fill. Maybe this
|
||||
// design is more intuitive and simpler than the current one that has all in
|
||||
// one class.
|
||||
// TODO: Analize the redesign of command by having an ExecutionResponse as a
|
||||
// TODO: result to the execution of every action. That result should have all the
|
||||
// TODO: information related to the execution, e.g. the form to fill. Maybe this
|
||||
// TODO: design is more intuitive and simpler than the current one that has all in
|
||||
// TODO: one class.
|
||||
|
||||
private AdHocCommandData data;
|
||||
|
||||
|
@ -83,17 +83,15 @@ public abstract class AdHocCommand {
|
|||
}
|
||||
|
||||
/**
|
||||
* Returns the specific condition of the <code>error</code> or null if the
|
||||
* Returns the specific condition of the <code>error</code> or <tt>null</tt> if the
|
||||
* error doesn't have any.
|
||||
*
|
||||
* @param error
|
||||
* the error the get the specific condition from
|
||||
* @param error the error the get the specific condition from.
|
||||
* @return the specific condition of this error, or null if it doesn't have
|
||||
* any.
|
||||
*/
|
||||
public static SpecificErrorCondition getSpecificErrorConditionFrom(
|
||||
XMPPError error) {
|
||||
// This method is implemented to provied an easy way of getting a packet
|
||||
public static SpecificErrorCondition getSpecificErrorCondition(XMPPError error) {
|
||||
// This method is implemented to provide an easy way of getting a packet
|
||||
// extension of the XMPPError.
|
||||
for (SpecificErrorCondition condition : SpecificErrorCondition.values()) {
|
||||
if (error.getExtension(condition.toString(),
|
||||
|
@ -127,8 +125,7 @@ public abstract class AdHocCommand {
|
|||
* Sets the unique identifier of the command. This value must be unique for
|
||||
* the <code>OwnerJID</code>.
|
||||
*
|
||||
* @param node
|
||||
* the unique identifier of the command
|
||||
* @param node the unique identifier of the command.
|
||||
*/
|
||||
public void setNode(String node) {
|
||||
data.setNode(node);
|
||||
|
@ -138,14 +135,14 @@ public abstract class AdHocCommand {
|
|||
* Returns the unique identifier of the command. It is unique for the
|
||||
* <code>OwnerJID</code>.
|
||||
*
|
||||
* @return the unique identifier of the command
|
||||
* @return the unique identifier of the command.
|
||||
*/
|
||||
public String getNode() {
|
||||
return data.getNode();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the full JID of the owner of this command. This JID is the "to" of a
|
||||
* Returns the full JID of the owner of this command. This JID is the "to" of a
|
||||
* execution request.
|
||||
*
|
||||
* @return the owner JID.
|
||||
|
@ -164,7 +161,7 @@ public abstract class AdHocCommand {
|
|||
/**
|
||||
* Adds a note to the current stage. This should be used when setting a
|
||||
* response to the execution of an action. All the notes added here are
|
||||
* returned by the <code>getNotes</code> method during the current stage.
|
||||
* returned by the {@link #getNotes} method during the current stage.
|
||||
* Once the stage changes all the notes are discarded.
|
||||
*
|
||||
* @param note the note.
|
||||
|
@ -186,7 +183,8 @@ public abstract class AdHocCommand {
|
|||
public Form getForm() {
|
||||
if (data.getForm() == null) {
|
||||
return null;
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
return new Form(data.getForm());
|
||||
}
|
||||
}
|
||||
|
@ -196,9 +194,8 @@ public abstract class AdHocCommand {
|
|||
* response. It could be a form to fill out the information needed to go to
|
||||
* the next stage or the result of an execution.
|
||||
*
|
||||
* @param form
|
||||
* the form of the current stage to fill out or the result of the
|
||||
* execution.
|
||||
* @param form the form of the current stage to fill out or the result of the
|
||||
* execution.
|
||||
*/
|
||||
protected void setForm(Form form) {
|
||||
data.setForm(form.getDataFormToSend());
|
||||
|
@ -209,22 +206,19 @@ public abstract class AdHocCommand {
|
|||
* command. It is invoked on every command. If there is a problem executing
|
||||
* the command it throws an XMPPException.
|
||||
*
|
||||
* @throws XMPPException
|
||||
* if there is a problem executing the command.
|
||||
* @throws XMPPException if there is a problem executing the command.
|
||||
*/
|
||||
public abstract void execute() throws XMPPException;
|
||||
|
||||
/**
|
||||
* Executes the next action of the command with the information provided in
|
||||
* the <code>response</code>. This form must be the answer form of the
|
||||
* previous stage. This method will be only invoked for commands that have 1
|
||||
* previous stage. This method will be only invoked for commands that have one
|
||||
* or more stages. If there is a problem executing the command it throws an
|
||||
* XMPPException.
|
||||
*
|
||||
* @param response
|
||||
* the form answer of the previous stage.
|
||||
* @throws XMPPException
|
||||
* if there is a problem executing the command.
|
||||
* @param response the form answer of the previous stage.
|
||||
* @throws XMPPException if there is a problem executing the command.
|
||||
*/
|
||||
public abstract void next(Form response) throws XMPPException;
|
||||
|
||||
|
@ -235,10 +229,8 @@ public abstract class AdHocCommand {
|
|||
* or more stages. If there is a problem executing the command it throws an
|
||||
* XMPPException.
|
||||
*
|
||||
* @param response
|
||||
* the form answer of the previous stage.
|
||||
* @throws XMPPException
|
||||
* if there is a problem executing the command.
|
||||
* @param response the form answer of the previous stage.
|
||||
* @throws XMPPException if there is a problem executing the command.
|
||||
*/
|
||||
public abstract void complete(Form response) throws XMPPException;
|
||||
|
||||
|
@ -248,8 +240,7 @@ public abstract class AdHocCommand {
|
|||
* the previous one. If there is a problem executing the command it throws
|
||||
* an XMPPException.
|
||||
*
|
||||
* @throws XMPPException
|
||||
* if there is a problem executing the command.
|
||||
* @throws XMPPException if there is a problem executing the command.
|
||||
*/
|
||||
public abstract void prev() throws XMPPException;
|
||||
|
||||
|
@ -258,19 +249,18 @@ public abstract class AdHocCommand {
|
|||
* the execution. If there is a problem executing the command it throws an
|
||||
* XMPPException.
|
||||
*
|
||||
* @throws XMPPException
|
||||
* if there is a problem executing the command.
|
||||
* @throws XMPPException if there is a problem executing the command.
|
||||
*/
|
||||
public abstract void cancel() throws XMPPException;
|
||||
|
||||
/**
|
||||
* Returns a collection with the allowed actions based on the current stage
|
||||
* Possible actions are: <tt>prev</tt>, <tt>next</tt> and
|
||||
* <tt>complete</tt>. This method will be only invoked for commands that
|
||||
* have 1 or more stages.
|
||||
* Returns a collection with the allowed actions based on the current stage.
|
||||
* Possible actions are: {@link Action#prev prev}, {@link Action#next next} and
|
||||
* {@link Action#complete complete}. This method will be only invoked for commands that
|
||||
* have one or more stages.
|
||||
*
|
||||
* @return a collection with the allowed actions based on the current stage
|
||||
* as defined in the SessionData.
|
||||
* as defined in the SessionData.
|
||||
*/
|
||||
protected List<Action> getActions() {
|
||||
return data.getActions();
|
||||
|
@ -287,14 +277,14 @@ public abstract class AdHocCommand {
|
|||
}
|
||||
|
||||
/**
|
||||
* Returns which of the actions available for the current stage is
|
||||
* Returns the action available for the current stage which is
|
||||
* considered the equivalent to "execute". When the requester sends his
|
||||
* reply, if no action was defined in the command then the action will be
|
||||
* assumed "execute" thus assuming the action returned by this method. This
|
||||
* method will never be invoked for commands that have no stages.
|
||||
*
|
||||
* @return which of the actions available for the current stage is
|
||||
* considered the equivalent to "execute".
|
||||
* @return the action available for the current stage which is considered
|
||||
* the equivalent to "execute".
|
||||
*/
|
||||
protected Action getExecuteAction() {
|
||||
return data.getExecuteAction();
|
||||
|
@ -341,8 +331,8 @@ public abstract class AdHocCommand {
|
|||
}
|
||||
|
||||
/**
|
||||
* Returns if the <code>action</code> is available in the current stage.
|
||||
* The <code>Action.cancel</code> is always allowed. To define the
|
||||
* Returns true if the <code>action</code> is available in the current stage.
|
||||
* The {@link Action#cancel cancel} action is always allowed. To define the
|
||||
* available actions use the <code>addActionAvailable</code> method.
|
||||
*
|
||||
* @param action
|
||||
|
@ -353,6 +343,9 @@ public abstract class AdHocCommand {
|
|||
return getActions().contains(action) || Action.cancel.equals(action);
|
||||
}
|
||||
|
||||
/**
|
||||
* The status of the stage in the adhoc command.
|
||||
*/
|
||||
public enum Status {
|
||||
|
||||
/**
|
||||
|
@ -411,58 +404,43 @@ public abstract class AdHocCommand {
|
|||
/**
|
||||
* The responding JID cannot accept the specified action.
|
||||
*/
|
||||
badAction,
|
||||
badAction("bad-action"),
|
||||
|
||||
/**
|
||||
* The responding JID does not understand the specified action.
|
||||
*/
|
||||
malformedAction,
|
||||
malformedAction("malformed-action"),
|
||||
|
||||
/**
|
||||
* The responding JID cannot accept the specified language/locale.
|
||||
*/
|
||||
badLocale,
|
||||
badLocale("bad-locale"),
|
||||
|
||||
/**
|
||||
* The responding JID cannot accept the specified payload (e.g. the data
|
||||
* form did not provide one or more required fields).
|
||||
*/
|
||||
badPayload,
|
||||
badPayload("bad-payload"),
|
||||
|
||||
/**
|
||||
* The responding JID cannot accept the specified sessionid.
|
||||
*/
|
||||
badSessionid,
|
||||
badSessionid("bad-sessionid"),
|
||||
|
||||
/**
|
||||
* The requesting JID specified a sessionid that is no longer active
|
||||
* (either because it was completed, canceled, or timed out).
|
||||
*/
|
||||
sessionExpired;
|
||||
sessionExpired("session-expired");
|
||||
|
||||
private String value;
|
||||
|
||||
SpecificErrorCondition(String value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
String result = null;
|
||||
switch (this) {
|
||||
case badAction:
|
||||
result = "bad-action";
|
||||
break;
|
||||
case malformedAction:
|
||||
result = "malformed-action";
|
||||
break;
|
||||
case badLocale:
|
||||
result = "bad-locale";
|
||||
break;
|
||||
case badPayload:
|
||||
result = "bad-payload";
|
||||
break;
|
||||
case badSessionid:
|
||||
result = "bad-sessionid";
|
||||
break;
|
||||
case sessionExpired:
|
||||
result = "session-expired";
|
||||
break;
|
||||
}
|
||||
return result;
|
||||
return value;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -326,7 +326,7 @@ public class AdHocCommandManager {
|
|||
// processed packet. We must check if it still in the
|
||||
// map.
|
||||
if (command != null) {
|
||||
long creationStamp = command.getCreationStamp();
|
||||
long creationStamp = command.getCreationDate();
|
||||
// Check if the Session data has expired (default is
|
||||
// 10 minutes)
|
||||
// To remove it from the session list it waits for
|
||||
|
@ -443,7 +443,7 @@ public class AdHocCommandManager {
|
|||
|
||||
// Increase the state number, so the command knows in witch
|
||||
// stage it is
|
||||
command.increaseStage();
|
||||
command.incrementStage();
|
||||
// Executes the command
|
||||
command.execute();
|
||||
|
||||
|
@ -496,7 +496,7 @@ public class AdHocCommandManager {
|
|||
}
|
||||
|
||||
// Check if the Session data has expired (default is 10 minutes)
|
||||
long creationStamp = command.getCreationStamp();
|
||||
long creationStamp = command.getCreationDate();
|
||||
if (System.currentTimeMillis() - creationStamp > SESSION_TIMEOUT * 1000) {
|
||||
// Remove the expired session
|
||||
executingCommands.remove(sessionId);
|
||||
|
@ -549,7 +549,7 @@ public class AdHocCommandManager {
|
|||
command.setData(response);
|
||||
|
||||
if (Action.next.equals(action)) {
|
||||
command.increaseStage();
|
||||
command.incrementStage();
|
||||
command.next(new Form(requestData.getForm()));
|
||||
if (command.isLastStage()) {
|
||||
// If it is the last stage then the command is
|
||||
|
@ -562,14 +562,14 @@ public class AdHocCommandManager {
|
|||
}
|
||||
}
|
||||
else if (Action.complete.equals(action)) {
|
||||
command.increaseStage();
|
||||
command.incrementStage();
|
||||
command.complete(new Form(requestData.getForm()));
|
||||
response.setStatus(Status.completed);
|
||||
// Remove the completed session
|
||||
executingCommands.remove(sessionId);
|
||||
}
|
||||
else if (Action.prev.equals(action)) {
|
||||
command.decreaseStage();
|
||||
command.decrementStage();
|
||||
command.prev();
|
||||
}
|
||||
else if (Action.cancel.equals(action)) {
|
||||
|
|
|
@ -21,18 +21,21 @@
|
|||
package org.jivesoftware.smackx.commands;
|
||||
|
||||
/**
|
||||
* Notes can be added to a command execution response. A note has to attributes,
|
||||
* one is the value or message an the other is the type of the note.
|
||||
* Notes can be added to a command execution response. A note has a type and value.
|
||||
*
|
||||
* @author Gabriel Guardincerri
|
||||
*
|
||||
*/
|
||||
public class AdHocCommandNote {
|
||||
|
||||
private Type type;
|
||||
|
||||
private String value;
|
||||
|
||||
/**
|
||||
* Creates a new adhoc command note with the specified type and value.
|
||||
*
|
||||
* @param type the type of the note.
|
||||
* @param value the value of the note.
|
||||
*/
|
||||
public AdHocCommandNote(Type type, String value) {
|
||||
this.type = type;
|
||||
this.value = value;
|
||||
|
@ -57,10 +60,7 @@ public class AdHocCommandNote {
|
|||
}
|
||||
|
||||
/**
|
||||
* The types of the notes.
|
||||
*
|
||||
* @author Gabriel Guardincerri
|
||||
*
|
||||
* Represents a note type.
|
||||
*/
|
||||
public enum Type {
|
||||
|
||||
|
@ -74,7 +74,7 @@ public class AdHocCommandNote {
|
|||
* The note indicates a warning. Possibly due to illogical (yet valid)
|
||||
* data.
|
||||
*/
|
||||
warm,
|
||||
warn,
|
||||
|
||||
/**
|
||||
* The note indicates an error. The text should indicate the reason for
|
||||
|
@ -83,4 +83,4 @@ public class AdHocCommandNote {
|
|||
error
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -46,7 +46,7 @@ public abstract class LocalCommand extends AdHocCommand {
|
|||
/**
|
||||
* The time stamp of first invokation of the command. Used to implement the session timeout.
|
||||
*/
|
||||
private long creationStamp;
|
||||
private long creationDate;
|
||||
|
||||
/**
|
||||
* The unique ID of the execution of the command.
|
||||
|
@ -65,7 +65,7 @@ public abstract class LocalCommand extends AdHocCommand {
|
|||
|
||||
public LocalCommand() {
|
||||
super();
|
||||
this.creationStamp = System.currentTimeMillis();
|
||||
this.creationDate = System.currentTimeMillis();
|
||||
currenStage = -1;
|
||||
}
|
||||
|
||||
|
@ -106,13 +106,12 @@ public abstract class LocalCommand extends AdHocCommand {
|
|||
}
|
||||
|
||||
/**
|
||||
* Returns the time in milliseconds since this command was executed for
|
||||
* first time.
|
||||
* Returns the date the command was created.
|
||||
*
|
||||
* @return the time in milliseconds since the command was executed for the first time.
|
||||
* @return the date the command was created.
|
||||
*/
|
||||
public long getCreationStamp() {
|
||||
return creationStamp;
|
||||
public long getCreationDate() {
|
||||
return creationDate;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -122,7 +121,7 @@ public abstract class LocalCommand extends AdHocCommand {
|
|||
}
|
||||
|
||||
/**
|
||||
* Returns if the current stage is the last one. If it is, then the
|
||||
* Returns true if the current stage is the last one. If it is then the
|
||||
* execution of some action will complete the execution of the command.
|
||||
*
|
||||
* @return true if the command is in the last stage.
|
||||
|
@ -134,7 +133,7 @@ public abstract class LocalCommand extends AdHocCommand {
|
|||
* not be called.
|
||||
*
|
||||
*/
|
||||
void increaseStage() {
|
||||
void incrementStage() {
|
||||
currenStage++;
|
||||
}
|
||||
|
||||
|
@ -143,13 +142,13 @@ public abstract class LocalCommand extends AdHocCommand {
|
|||
* not be called.
|
||||
*
|
||||
*/
|
||||
void decreaseStage() {
|
||||
void decrementStage() {
|
||||
currenStage--;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the currently executing stage number. The first stage number is
|
||||
* 0. So during the execution of the first action this method will answer 0.
|
||||
* 0. During the execution of the first action this method will answer 0.
|
||||
*
|
||||
* @return the current stage number.
|
||||
*/
|
||||
|
@ -158,7 +157,7 @@ public abstract class LocalCommand extends AdHocCommand {
|
|||
}
|
||||
|
||||
/**
|
||||
* Returns if the specified requester has permission to execute all the
|
||||
* Returns true if the specified requester has permission to execute all the
|
||||
* stages of this action. This is checked when the first request is received,
|
||||
* if the permission is grant then the requester will be able to execute
|
||||
* all the stages of the command. It is not checked again during the
|
||||
|
|
|
@ -32,7 +32,9 @@ import org.jivesoftware.smackx.packet.AdHocCommandData;
|
|||
|
||||
/**
|
||||
* Represents a command that is in a remote location. Invoking one of the
|
||||
* execute, next, prev, cancel or complete methods results in executing that
|
||||
* {@link AdHocCommand.Action#execute execute}, {@link AdHocCommand.Action#next next},
|
||||
* {@link AdHocCommand.Action#prev prev}, {@link AdHocCommand.Action#cancel cancel} or
|
||||
* {@link AdHocCommand.Action#complete complete} actions results in executing that
|
||||
* action in the remote location. In response to that action the internal state
|
||||
* of the this command instance will change. For example, if the command is a
|
||||
* single stage command, then invoking the execute action will execute this
|
||||
|
@ -64,12 +66,9 @@ public class RemoteCommand extends AdHocCommand {
|
|||
* command identified by <code>node</code> in the host identified by
|
||||
* <code>jid</code>
|
||||
*
|
||||
* @param connection
|
||||
* the connection to use for the execution.
|
||||
* @param node
|
||||
* the identifier of the command.
|
||||
* @param jid
|
||||
* the JID of the host.
|
||||
* @param connection the connection to use for the execution.
|
||||
* @param node the identifier of the command.
|
||||
* @param jid the JID of the host.
|
||||
*/
|
||||
protected RemoteCommand(XMPPConnection connection, String node, String jid) {
|
||||
super();
|
||||
|
@ -99,7 +98,7 @@ public class RemoteCommand extends AdHocCommand {
|
|||
* there is a problem executing the command it throws an XMPPException.
|
||||
*
|
||||
* @param form the form anwser of the previous stage.
|
||||
* @throws XMPPException
|
||||
* @throws XMPPException if an error occurs.
|
||||
*/
|
||||
public void execute(Form form) throws XMPPException {
|
||||
executeAction(Action.execute, form);
|
||||
|
@ -122,15 +121,16 @@ public class RemoteCommand extends AdHocCommand {
|
|||
/**
|
||||
* Executes the <code>action</codo> with the <code>form</code>.
|
||||
* The action could be any of the available actions. The form must
|
||||
* be the anwser of the previous stage. It can be null if it is the first stage.
|
||||
* be the anwser of the previous stage. It can be <tt>null</tt> if it is the first stage.
|
||||
*
|
||||
* @param action the action to execute
|
||||
* @param form the form with the information
|
||||
* @throws XMPPException if there is a problem executing the command.
|
||||
*/
|
||||
private void executeAction(Action action, Form form) throws XMPPException {
|
||||
// TODO Check that all the requiered fields of the form were filled, if
|
||||
// not throw the corresponding exeption. This will make a faster response,
|
||||
// since the request is stoped before it's sended.
|
||||
// TODO: Check that all the required fields of the form were filled, if
|
||||
// TODO: not throw the corresponding exeption. This will make a faster response,
|
||||
// TODO: since the request is stoped before it's sent.
|
||||
AdHocCommandData data = new AdHocCommandData();
|
||||
data.setType(IQ.Type.SET);
|
||||
data.setTo(getOwnerJID());
|
||||
|
@ -142,13 +142,12 @@ public class RemoteCommand extends AdHocCommand {
|
|||
data.setForm(form.getDataFormToSend());
|
||||
}
|
||||
|
||||
PacketCollector collector = connection
|
||||
.createPacketCollector(new PacketIDFilter(data.getPacketID()));
|
||||
PacketCollector collector = connection.createPacketCollector(
|
||||
new PacketIDFilter(data.getPacketID()));
|
||||
|
||||
connection.sendPacket(data);
|
||||
|
||||
Packet response = collector.nextResult(SmackConfiguration
|
||||
.getPacketReplyTimeout());
|
||||
Packet response = collector.nextResult(SmackConfiguration.getPacketReplyTimeout());
|
||||
|
||||
// Cancel the collector.
|
||||
collector.cancel();
|
||||
|
@ -168,4 +167,4 @@ public class RemoteCommand extends AdHocCommand {
|
|||
public String getOwnerJID() {
|
||||
return jid;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -3,7 +3,7 @@
|
|||
* $Revision: $
|
||||
* $Date: $
|
||||
*
|
||||
* Copyright 2005-2007 Jive Software.
|
||||
* Copyright 2005-2008 Jive Software.
|
||||
*
|
||||
* All rights reserved. Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -31,10 +31,9 @@ import java.util.ArrayList;
|
|||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Represents the state and the request of the execution of a command.
|
||||
* Represents the state and the request of the execution of an adhoc command.
|
||||
*
|
||||
* @author Gabriel Guardincerri
|
||||
*
|
||||
*/
|
||||
public class AdHocCommandData extends IQ {
|
||||
|
||||
|
@ -121,7 +120,7 @@ public class AdHocCommandData extends IQ {
|
|||
buf.append("</note>");
|
||||
}
|
||||
|
||||
// TODO ERRORES
|
||||
// TODO ERRORS
|
||||
// if (getError() != null) {
|
||||
// buf.append(getError().toXML());
|
||||
// }
|
||||
|
@ -271,12 +270,10 @@ public class AdHocCommandData extends IQ {
|
|||
}
|
||||
|
||||
public String toXML() {
|
||||
StringBuffer sb = new StringBuffer();
|
||||
sb.append("<").append(getElementName());
|
||||
sb.append(" xmlns=\"").append(getNamespace()).append("\"/>");
|
||||
return sb.toString();
|
||||
StringBuilder buf = new StringBuilder();
|
||||
buf.append("<").append(getElementName());
|
||||
buf.append(" xmlns=\"").append(getNamespace()).append("\"/>");
|
||||
return buf.toString();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
|
@ -38,7 +38,6 @@ import org.xmlpull.v1.XmlPullParser;
|
|||
*
|
||||
* @author Gabriel Guardincerri
|
||||
*/
|
||||
|
||||
public class AdHocCommandDataProvider implements IQProvider {
|
||||
|
||||
public IQ parseIQ(XmlPullParser parser) throws Exception {
|
||||
|
@ -56,9 +55,11 @@ public class AdHocCommandDataProvider implements IQProvider {
|
|||
String status = parser.getAttributeValue("", "status");
|
||||
if (AdHocCommand.Status.executing.toString().equalsIgnoreCase(status)) {
|
||||
adHocCommandData.setStatus(AdHocCommand.Status.executing);
|
||||
} else if (AdHocCommand.Status.completed.toString().equalsIgnoreCase(status)) {
|
||||
}
|
||||
else if (AdHocCommand.Status.completed.toString().equalsIgnoreCase(status)) {
|
||||
adHocCommandData.setStatus(AdHocCommand.Status.completed);
|
||||
} else if (AdHocCommand.Status.canceled.toString().equalsIgnoreCase(status)) {
|
||||
}
|
||||
else if (AdHocCommand.Status.canceled.toString().equalsIgnoreCase(status)) {
|
||||
adHocCommandData.setStatus(AdHocCommand.Status.canceled);
|
||||
}
|
||||
|
||||
|
@ -68,7 +69,8 @@ public class AdHocCommandDataProvider implements IQProvider {
|
|||
Action realAction = AdHocCommand.Action.valueOf(action);
|
||||
if (realAction == null || realAction.equals(Action.unknown)) {
|
||||
adHocCommandData.setAction(Action.unknown);
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
adHocCommandData.setAction(realAction);
|
||||
}
|
||||
}
|
||||
|
@ -82,24 +84,31 @@ public class AdHocCommandDataProvider implements IQProvider {
|
|||
if (execute != null) {
|
||||
adHocCommandData.setExecuteAction(AdHocCommand.Action.valueOf(execute));
|
||||
}
|
||||
} else if (parser.getName().equals("next")) {
|
||||
}
|
||||
else if (parser.getName().equals("next")) {
|
||||
adHocCommandData.addAction(AdHocCommand.Action.next);
|
||||
} else if (parser.getName().equals("complete")) {
|
||||
}
|
||||
else if (parser.getName().equals("complete")) {
|
||||
adHocCommandData.addAction(AdHocCommand.Action.complete);
|
||||
} else if (parser.getName().equals("prev")) {
|
||||
}
|
||||
else if (parser.getName().equals("prev")) {
|
||||
adHocCommandData.addAction(AdHocCommand.Action.prev);
|
||||
} else if (elementName.equals("x") && namespace.equals("jabber:x:data")) {
|
||||
}
|
||||
else if (elementName.equals("x") && namespace.equals("jabber:x:data")) {
|
||||
adHocCommandData.setForm((DataForm) dataFormProvider.parseExtension(parser));
|
||||
} else if (parser.getName().equals("note")) {
|
||||
AdHocCommandNote.Type type = AdHocCommandNote.Type.valueOf(parser
|
||||
.getAttributeValue("", "type"));
|
||||
}
|
||||
else if (parser.getName().equals("note")) {
|
||||
AdHocCommandNote.Type type = AdHocCommandNote.Type.valueOf(
|
||||
parser.getAttributeValue("", "type"));
|
||||
String value = parser.nextText();
|
||||
adHocCommandData.addNote(new AdHocCommandNote(type, value));
|
||||
} else if (parser.getName().equals("error")) {
|
||||
}
|
||||
else if (parser.getName().equals("error")) {
|
||||
XMPPError error = PacketParserUtils.parseError(parser);
|
||||
adHocCommandData.setError(error);
|
||||
}
|
||||
} else if (eventType == XmlPullParser.END_TAG) {
|
||||
}
|
||||
else if (eventType == XmlPullParser.END_TAG) {
|
||||
if (parser.getName().equals("command")) {
|
||||
done = true;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue