Java Code Examples for org.jivesoftware.smack.util.StringUtils#requireNotNullNorEmpty()

The following examples show how to use org.jivesoftware.smack.util.StringUtils#requireNotNullNorEmpty() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SimplePayload.java    From Smack with Apache License 2.0 6 votes vote down vote up
/**
 * Construct a <code>SimplePayload</code> object with the specified element name,
 * namespace and content.  The content must be well formed XML.
 *
 * @param xmlPayload The payload data
 */
public SimplePayload(String xmlPayload) {
    XmlPullParser parser;
    try {
        parser = PacketParserUtils.getParserFor(xmlPayload);
    }
    catch (XmlPullParserException | IOException e) {
        throw new AssertionError(e);
    }
    QName qname = parser.getQName();

    payload = xmlPayload;

    elemName = StringUtils.requireNotNullNorEmpty(qname.getLocalPart(), "Could not determine element name from XML payload");
    ns = StringUtils.requireNotNullNorEmpty(qname.getNamespaceURI(), "Could not determine namespace from XML payload");
}
 
Example 2
Source File: ServiceDiscoveryManager.java    From Smack with Apache License 2.0 6 votes vote down vote up
/**
 * Registers extended discovery information of this XMPP entity. When this
 * client is queried for its information this data form will be returned as
 * specified by XEP-0128.
 * <p>
 *
 * Since no stanza is actually sent to the server it is safe to perform this
 * operation before logging to the server. In fact, you may want to
 * configure the extended info before logging to the server so that the
 * information is already available if it is required upon login.
 *
 * @param extendedInfo the data form that contains the extend service discovery information.
 * @return the old data form which got replaced (if any)
 * @since 4.4.0
 */
public DataForm addExtendedInfo(DataForm extendedInfo) {
    String formType = extendedInfo.getFormType();
    StringUtils.requireNotNullNorEmpty(formType, "The data form must have a form type set");

    DataForm removedDataForm;
    synchronized (this) {
        removedDataForm = DataForm.remove(extendedInfos, formType);

        extendedInfos.add(extendedInfo);

        // Notify others of a state change of SDM. In order to keep the state consistent, this
        // method is synchronized
        renewEntityCapsVersion();
    }
    return removedDataForm;
}
 
Example 3
Source File: StandardExtensionElement.java    From Smack with Apache License 2.0 5 votes vote down vote up
private StandardExtensionElement(String name, String namespace, Map<String, String> attributes, String text,
                MultiMap<QName, StandardExtensionElement> elements) {
    this.name = StringUtils.requireNotNullNorEmpty(name, "Name must not be null nor empty");
    this.namespace = StringUtils.requireNotNullNorEmpty(namespace, "Namespace must not be null nor empty");
    if (attributes == null) {
        this.attributes = Collections.emptyMap();
    }
    else {
        this.attributes = attributes;
    }
    this.text = text;
    this.elements = elements;
}
 
Example 4
Source File: Configuration.java    From Smack with Apache License 2.0 5 votes vote down vote up
public Builder setUsernamesAndPassword(String accountOneUsername, String accountOnePassword,
                String accountTwoUsername, String accountTwoPassword, String accountThreeUsername, String accountThreePassword) {
    this.accountOneUsername = StringUtils.requireNotNullNorEmpty(accountOneUsername, "accountOneUsername must not be null nor empty");
    this.accountOnePassword = StringUtils.requireNotNullNorEmpty(accountOnePassword, "accountOnePassword must not be null nor empty");
    this.accountTwoUsername = StringUtils.requireNotNullNorEmpty(accountTwoUsername, "accountTwoUsername must not be null nor empty");
    this.accountTwoPassword = StringUtils.requireNotNullNorEmpty(accountTwoPassword, "accountTwoPasswordmust not be null nor empty");
    this.accountThreeUsername = StringUtils.requireNotNullNorEmpty(accountThreeUsername, "accountThreeUsername must not be null nor empty");
    this.accountThreePassword = StringUtils.requireNotNullNorEmpty(accountThreePassword, "accountThreePassword must not be null nor empty");
    return this;
}
 
Example 5
Source File: PubSubManager.java    From Smack with Apache License 2.0 5 votes vote down vote up
/**
 * Retrieves the requested node, if it exists.  It will throw an
 * exception if it does not.
 *
 * @param id - The unique id of the node
 *
 * @return the node
 * @throws XMPPErrorException The node does not exist
 * @throws NoResponseException if there was no response from the server.
 * @throws NotConnectedException if the XMPP connection is not connected.
 * @throws InterruptedException if the calling thread was interrupted.
 * @throws NotAPubSubNodeException if a involved node is not a PubSub node.
 */
public Node getNode(String id) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException, NotAPubSubNodeException {
    StringUtils.requireNotNullNorEmpty(id, "The node ID can not be null or the empty string");
    Node node = nodeMap.get(id);

    if (node == null) {
        XMPPConnection connection = connection();
        DiscoverInfo info = DiscoverInfo.builder(connection)
                .to(pubSubService)
                .setNode(id)
                .build();

        DiscoverInfo infoReply = connection.createStanzaCollectorAndSend(info).nextResultOrThrow();

        if (infoReply.hasIdentity(PubSub.ELEMENT, "leaf")) {
            node = new LeafNode(this, id);
        }
        else if (infoReply.hasIdentity(PubSub.ELEMENT, "collection")) {
            node = new CollectionNode(this, id);
        }
        else {
            throw new PubSubException.NotAPubSubNodeException(id, infoReply);
        }
        nodeMap.put(id, node);
    }
    return node;
}
 
Example 6
Source File: StandardExtensionElement.java    From Smack with Apache License 2.0 5 votes vote down vote up
public Builder addAttribute(String name, String value) {
    StringUtils.requireNotNullNorEmpty(name, "Attribute name must be set");
    Objects.requireNonNull(value, "Attribute value must be not null");
    if (attributes == null) {
        attributes = new LinkedHashMap<>();
    }
    attributes.put(name, value);
    return this;
}
 
Example 7
Source File: OmemoBundleElement.java    From Smack with Apache License 2.0 5 votes vote down vote up
/**
 * Constructor to create a Bundle Element from base64 Strings.
 *
 * @param signedPreKeyId id
 * @param signedPreKeyB64 base64 encoded signedPreKey
 * @param signedPreKeySigB64 base64 encoded signedPreKeySignature
 * @param identityKeyB64 base64 encoded identityKey
 * @param preKeysB64 HashMap of base64 encoded preKeys
 */
public OmemoBundleElement(int signedPreKeyId, String signedPreKeyB64, String signedPreKeySigB64, String identityKeyB64, HashMap<Integer, String> preKeysB64) {
    if (signedPreKeyId < 0) {
        throw new IllegalArgumentException("signedPreKeyId MUST be greater than or equal to 0.");
    }
    this.signedPreKeyId = signedPreKeyId;
    this.signedPreKeyB64 = StringUtils.requireNotNullNorEmpty(signedPreKeyB64, "signedPreKeyB64 MUST NOT be null nor empty.");
    this.signedPreKeySignatureB64 = StringUtils.requireNotNullNorEmpty(signedPreKeySigB64, "signedPreKeySigB64 MUST NOT be null nor empty.");
    this.identityKeyB64 = StringUtils.requireNotNullNorEmpty(identityKeyB64, "identityKeyB64 MUST NOT be null nor empty.");

    if (preKeysB64 == null || preKeysB64.isEmpty()) {
        throw new IllegalArgumentException("PreKeys MUST NOT be null nor empty.");
    }
    this.preKeysB64 = preKeysB64;
}
 
Example 8
Source File: Version.java    From Smack with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a new Version object with given details.
 *
 * @param name The natural-language name of the software. This element is REQUIRED.
 * @param version The specific version of the software. This element is REQUIRED.
 * @param os The operating system of the queried entity. This element is OPTIONAL.
 */
public Version(String name, String version, String os) {
    super(ELEMENT, NAMESPACE);
    this.setType(IQ.Type.result);
    this.name = StringUtils.requireNotNullNorEmpty(name, "name must not be null");
    this.version = StringUtils.requireNotNullNorEmpty(version, "version must not be null");
    this.os = os;
}
 
Example 9
Source File: Tag.java    From Smack with Apache License 2.0 5 votes vote down vote up
public Tag(String name, Type type, String value) {
    // TODO According to XEP-0347 § 5.2 names are case insensitive. Uppercase them all?
    this.name = StringUtils.requireNotNullNorEmpty(name, "name must not be null nor empty");
    this.type = Objects.requireNonNull(type);
    this.value =  StringUtils.requireNotNullNorEmpty(value, "value must not be null nor empty");
    if (this.name.length() > 32) {
        throw new IllegalArgumentException("Meta Tag names must not be longer then 32 characters (XEP-0347 § 5.2");
    }
    if (this.type == Type.str && this.value.length() > 128) {
        throw new IllegalArgumentException("Meta Tag string values must not be longer then 128 characters (XEP-0347 § 5.2");
    }
}
 
Example 10
Source File: JingleS5BTransport.java    From Smack with Apache License 2.0 5 votes vote down vote up
protected JingleS5BTransport(List<JingleContentTransportCandidate> candidates, JingleContentTransportInfo info, String streamId, String dstAddr, Bytestream.Mode mode) {
    super(candidates, info);
    StringUtils.requireNotNullNorEmpty(streamId, "sid MUST be neither null, nor empty.");
    this.streamId = streamId;
    this.dstAddr = dstAddr;
    this.mode = mode;
}
 
Example 11
Source File: AbstractTextElement.java    From Smack with Apache License 2.0 4 votes vote down vote up
protected AbstractTextElement(String text, String lang) {
    this.text = StringUtils.requireNotNullNorEmpty(text, "Text must not be null nor empty");
    this.lang = lang;
}
 
Example 12
Source File: MediaElement.java    From Smack with Apache License 2.0 4 votes vote down vote up
public Uri(URI uri, String type) {
    this.uri = Objects.requireNonNull(uri);
    this.type = StringUtils.requireNotNullNorEmpty(type, "The 'type' argument must not be null or empty");
}
 
Example 13
Source File: OpenPgpElement.java    From Smack with Apache License 2.0 4 votes vote down vote up
public OpenPgpElement(String base64EncodedOpenPgpMessage) {
    this.base64EncodedOpenPgpMessage = StringUtils.requireNotNullNorEmpty(base64EncodedOpenPgpMessage,
            "base64 encoded message MUST NOT be null nor empty.");
}
 
Example 14
Source File: MessageCorrectExtension.java    From Smack with Apache License 2.0 4 votes vote down vote up
public MessageCorrectExtension(String idInitialMessage) {
    this.idInitialMessage = StringUtils.requireNotNullNorEmpty(idInitialMessage, "idInitialMessage must not be null");
}
 
Example 15
Source File: ExplicitMessageEncryptionElement.java    From Smack with Apache License 2.0 4 votes vote down vote up
public ExplicitMessageEncryptionElement(String encryptionNamespace, String name) {
    this.encryptionNamespace = StringUtils.requireNotNullNorEmpty(encryptionNamespace,
                    "encryptionNamespace must not be null");
    this.name = name;
}
 
Example 16
Source File: StanzaExtensionFilter.java    From Smack with Apache License 2.0 3 votes vote down vote up
/**
 * Creates a new stanza extension filter. Stanzas will pass the filter if
 * they have a stanza extension that matches the specified element name
 * and namespace.
 *
 * @param elementName the XML element name of the stanza extension.
 * @param namespace the XML namespace of the stanza extension.
 */
public StanzaExtensionFilter(String elementName, String namespace) {
    StringUtils.requireNotNullNorEmpty(namespace, "namespace must not be null nor empty");

    this.elementName = elementName;
    this.namespace = namespace;
}
 
Example 17
Source File: Affiliation.java    From Smack with Apache License 2.0 3 votes vote down vote up
/**
 * Constructs an affiliation.
 *
 * @param node The node the user is affiliated with.
 * @param affiliation the optional affiliation.
 * @param namespace the affiliation's namespace.
 */
public Affiliation(String node, Type affiliation, AffiliationNamespace namespace) {
    this.node = StringUtils.requireNotNullNorEmpty(node, "node must not be null nor empty");
    this.affiliation = affiliation;
    this.jid = null;
    this.namespace = Objects.requireNonNull(namespace);
}
 
Example 18
Source File: FormField.java    From Smack with Apache License 2.0 2 votes vote down vote up
/**
 * Sets the label of the question which should give enough information to the user to
 * fill out the form.
 *
 * @param label the label of the question.
 * @return a reference to this builder.
 */
public B setLabel(String label) {
    this.label = StringUtils.requireNotNullNorEmpty(label, "label must not be null or empty");
    return getThis();
}
 
Example 19
Source File: StanzaIdFilter.java    From Smack with Apache License 2.0 2 votes vote down vote up
/**
 * Creates a new stanza ID filter using the specified stanza ID.
 *
 * @param stanzaId the stanza ID to filter for.
 */
public StanzaIdFilter(String stanzaId) {
    this.stanzaId = StringUtils.requireNotNullNorEmpty(stanzaId, "Stanza ID must not be null nor empty.");
}
 
Example 20
Source File: ThreadFilter.java    From Smack with Apache License 2.0 2 votes vote down vote up
/**
 * Creates a new thread filter using the specified thread value.
 *
 * @param thread the thread value to filter for.
 */
public ThreadFilter(String thread) {
    StringUtils.requireNotNullNorEmpty(thread, "Thread must not be null nor empty.");
    this.thread = thread;
}