Class AdHocCommand

    • Constructor Detail

      • AdHocCommand

        public AdHocCommand()
    • Method Detail

      • getLabel

        public String getLabel()
      • setLabel

        public void setLabel​(String label)
      • hasPermission

        public boolean hasPermission​(org.xmpp.packet.JID requester)
        Returns true if the requester is allowed to execute this command. By default, only admins are allowed to execute commands. Subclasses may redefine this method with any specific logic. Note: The bare JID of the requester will be compared with the bare JID of the admins.
        Parameters:
        requester - the JID of the user requesting to execute this command.
        Returns:
        true if the requester is allowed to execute this command.
      • getCode

        public abstract String getCode()
        Returns the unique identifier for this command for the containing JID. The code will be used as the node in the disco#items or the node when executing the command.
        Returns:
        the unique identifier for this command for the containing JID.
      • getDefaultLabel

        public abstract String getDefaultLabel()
        Returns the default label used for describing this command. This information is usually used when returning commands as disco#items. Admins can later use setLabel(String) to set a new label and reset to the default value at any time.
        Returns:
        the default label used for describing this command.
      • getMaxStages

        public abstract int getMaxStages​(@Nonnull
                                         SessionData data)
        Returns the max number of stages for this command. The number of stages may vary according to the collected data in previous stages. Therefore, a SessionData object is passed as a parameter. When the max number of stages has been reached then the command is ready to be executed.
        Parameters:
        data - metadata and the gathered data through the command stages.
        Returns:
        the max number of stages for this command.
      • execute

        public abstract void execute​(@Nonnull
                                     SessionData data,
                                     org.dom4j.Element command)
        Executes the command with the specified session data.
        Parameters:
        data - metadata and the gathered data through the command stages.
        command - the command element to be sent to the command requester with a reported data result or note element with the answer of the execution.
      • addStageInformation

        protected abstract void addStageInformation​(@Nonnull
                                                    SessionData data,
                                                    org.dom4j.Element command)
        Adds to the command element the data form or notes required by the current stage. The current stage is specified in the SessionData. This method will never be invoked for commands that have no stages.
        Parameters:
        data - metadata and the gathered data through the command stages.
        command - the command element to be sent to the command requester.
      • getActions

        protected abstract List<AdHocCommand.Action> getActions​(@Nonnull
                                                                SessionData data)
        Returns a collection with the allowed actions based on the current stage as defined in the SessionData. Possible actions are: prev, next and complete. This method will never be invoked for commands that have no stages.
        Parameters:
        data - metadata and the gathered data through the command stages.
        Returns:
        a collection with the allowed actions based on the current stage as defined in the SessionData.
      • getExecuteAction

        protected abstract AdHocCommand.Action getExecuteAction​(@Nonnull
                                                                SessionData data)
        Returns which of the actions available for the current stage 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.
        Parameters:
        data - metadata and the gathered data through the command stages.
        Returns:
        which of the actions available for the current stage is considered the equivalent to "execute".
      • addNextStageInformation

        public void addNextStageInformation​(@Nonnull
                                            SessionData data,
                                            org.dom4j.Element command)
        Increments the stage number by one and adds to the command element the new data form and new allowed actions that the user might perform.
        Parameters:
        data - metadata and the gathered data through the command stages.
        command - the command element to be sent to the command requester.
      • addPreviousStageInformation

        public void addPreviousStageInformation​(@Nonnull
                                                SessionData data,
                                                org.dom4j.Element command)
        Decrements the stage number by one and adds to the command the data form and allowed actions that the user might perform of the previous stage.
        Parameters:
        data - metadata and the gathered data through the command stages.
        command - the command element to be sent to the command requester.
      • addStageActions

        protected void addStageActions​(@Nonnull
                                       SessionData data,
                                       org.dom4j.Element command)
        Adds the allowed actions to follow from the current stage. Possible actions are: prev, next and complete.
        Parameters:
        data - metadata and the gathered data through the command stages.
        command - the command element to be sent to the command requester.