FormNode.java

  1. /**
  2.  *
  3.  * Copyright the original author or authors
  4.  *
  5.  * Licensed under the Apache License, Version 2.0 (the "License");
  6.  * you may not use this file except in compliance with the License.
  7.  * You may obtain a copy of the License at
  8.  *
  9.  *     http://www.apache.org/licenses/LICENSE-2.0
  10.  *
  11.  * Unless required by applicable law or agreed to in writing, software
  12.  * distributed under the License is distributed on an "AS IS" BASIS,
  13.  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14.  * See the License for the specific language governing permissions and
  15.  * limitations under the License.
  16.  */
  17. package org.jivesoftware.smackx.pubsub;

  18. import org.jivesoftware.smack.util.XmlStringBuilder;

  19. import org.jivesoftware.smackx.xdata.packet.DataForm;

  20. /**
  21.  * Generic stanza extension which represents any PubSub form that is
  22.  * parsed from the incoming stream or being sent out to the server.
  23.  *
  24.  * Form types are defined in {@link FormNodeType}.
  25.  *
  26.  * @author Robin Collier
  27.  */
  28. public class FormNode extends NodeExtension {
  29.     private final DataForm configForm;

  30.     /**
  31.      * Create a {@link FormNode} which contains the specified form.
  32.      *
  33.      * @param formType The type of form being sent
  34.      * @param submitForm The form
  35.      */
  36.     public FormNode(FormNodeType formType, DataForm submitForm) {
  37.         this(formType, null, submitForm);
  38.     }

  39.     /**
  40.      * Create a {@link FormNode} which contains the specified form, which is
  41.      * associated with the specified node.
  42.      *
  43.      * @param formType The type of form being sent
  44.      * @param nodeId The node the form is associated with
  45.      * @param submitForm The form
  46.      */
  47.     public FormNode(FormNodeType formType, String nodeId, DataForm submitForm) {
  48.         super(formType.getNodeElement(), nodeId);
  49.         configForm = submitForm;
  50.     }

  51.     /**
  52.      * Get the Form that is to be sent, or was retrieved from the server.
  53.      *
  54.      * @return The form
  55.      */
  56.     public DataForm getForm() {
  57.         return configForm;
  58.     }

  59.     @Override
  60.     protected void addXml(XmlStringBuilder xml) {
  61.         if (configForm == null) {
  62.             xml.closeEmptyElement();
  63.             return;
  64.         }

  65.         xml.rightAngleBracket();
  66.         xml.append(configForm);
  67.         xml.closeElement(this);
  68.     }

  69. }