MamElementFactory.java

  1. /**
  2.  *
  3.  * Copyright © 2016-2021 Florian Schmaus and Frank Matheron
  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.mam.element;

  18. import java.util.List;

  19. import org.jivesoftware.smack.packet.Message;
  20. import org.jivesoftware.smack.xml.XmlPullParser;
  21. import org.jivesoftware.smackx.forward.packet.Forwarded;
  22. import org.jivesoftware.smackx.rsm.packet.RSMSet;
  23. import org.jivesoftware.smackx.xdata.packet.DataForm;

  24. import org.jxmpp.jid.Jid;

  25. /**
  26.  * Factory that creates MAM objects.
  27.  *
  28.  * @since 4.5.0
  29.  */
  30. public interface MamElementFactory {

  31.     /**
  32.      * Creates a new {@link MamElementFactory} for the parser based on the namespace of the parser.
  33.      * @param parser the XML parser to retrieve the MAM namespace from
  34.      * @return the factory suitable for the MAM namespace
  35.      */
  36.     static MamElementFactory forParser(XmlPullParser parser) {
  37.         String namespace = parser.getNamespace();
  38.         return MamVersion.fromNamespace(namespace).newElementFactory();
  39.     }

  40.     /**
  41.      * Create a MAM result extension class.
  42.      *
  43.      * @param queryId id of the query
  44.      * @param id the message's archive UID
  45.      * @param forwarded the original message as it was received
  46.      * @return the result extension
  47.      */
  48.     MamElements.MamResultExtension newResultExtension(String queryId, String id, Forwarded<Message> forwarded);

  49.     /**
  50.      * Create a MAM fin IQ class.
  51.      *
  52.      * @param queryId id of the query
  53.      * @param rsmSet the RSM set included in the {@code <fin/>}
  54.      * @param complete true if the results returned by the server are complete (no further paging in needed)
  55.      * @param stable false if the results returned by the sever are unstable (e.g. they might later change in sequence or content)
  56.      * @return the fin IQ
  57.      */
  58.     MamFinIQ newFinIQ(String queryId, RSMSet rsmSet, boolean complete, boolean stable);

  59.     /**
  60.      * Create a new MAM preferences IQ.
  61.      *
  62.      * @param alwaysJids JIDs for which all messages are archived by default
  63.      * @param neverJids JIDs for which messages are never archived
  64.      * @param defaultBehavior default archive behavior
  65.      * @return the prefs IQ
  66.      */
  67.     MamPrefsIQ newPrefsIQ(List<Jid> alwaysJids, List<Jid> neverJids, MamPrefsIQ.DefaultBehavior defaultBehavior);

  68.     /**
  69.      * Construct a new MAM {@code <prefs/>} IQ retrieval request (IQ type 'get').
  70.      *
  71.      * @return the prefs IQ
  72.      */
  73.     MamPrefsIQ newPrefsIQ();

  74.     /**
  75.      * Create a new MAM Query IQ.
  76.      *
  77.      * @param queryId id of the query
  78.      * @param node pubsub node id when querying a pubsub node, null when not querying a pubsub node
  79.      * @param dataForm the dataform containing the query parameters
  80.      * @return the query IQ
  81.      */
  82.     MamQueryIQ newQueryIQ(String queryId, String node, DataForm dataForm);

  83. }