/** * * Copyright 2003-2007 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. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.jivesoftware.smack; import java.io.IOException; import java.io.InputStream; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; import java.util.List; import java.util.logging.Level; import java.util.logging.Logger; import org.jivesoftware.smack.parsing.ExceptionThrowingCallback; import org.jivesoftware.smack.parsing.ParsingExceptionCallback; import org.jivesoftware.smack.util.FileUtils; import org.xmlpull.mxp1.MXParser; import org.xmlpull.v1.XmlPullParser; /** * Represents the configuration of Smack. The configuration is used for: *
* * So far this means that: * 1) a set of classes will be loaded in order to execute their static init block * 2) retrieve and set the current Smack release */ /** * Sets the location of the config file on the classpath. Only required if changing from the default location of classpath:META-INF/smack-config.xml. * *
* This method must be called before accessing any other class in Smack. * * @param configFileUrl The location of the config file. * @param loader The classloader to use if the URL has a protocol of classpath> and the file is not located on the default classpath. * This can be set to null to use defaults and is ignored for all other protocols. * @throws IllegalArgumentException If the config URL is invalid in that it cannot open an {@link InputStream} */ public static void setConfigFileUrl(String configFileUrl, ClassLoader loader) { try { configFileStream = FileUtils.getStreamForUrl(configFileUrl, loader); } catch (Exception e) { throw new IllegalArgumentException("Failed to create input stream from specified file URL ["+ configFileUrl + "]", e); } initialize(); } /** * Sets the {@link InputStream} representing the smack configuration file. This can be used to override the default with something that is not on the classpath. *
* This method must be called before accessing any other class in Smack.
* @param configFile
*/
public static void setConfigFileStream(InputStream configFile) {
configFileStream = configFile;
initialize();
}
/**
* Returns the Smack version information, eg "1.3.0".
*
* @return the Smack version information.
*/
public static String getVersion() {
return SMACK_VERSION;
}
/**
* Returns the number of milliseconds to wait for a response from
* the server. The default value is 5000 ms.
*
* @return the milliseconds to wait for a response from the server
*/
public static int getPacketReplyTimeout() {
initialize();
// The timeout value must be greater than 0 otherwise we will answer the default value
if (packetReplyTimeout <= 0) {
packetReplyTimeout = 5000;
}
return packetReplyTimeout;
}
/**
* Sets the number of milliseconds to wait for a response from
* the server.
*
* @param timeout the milliseconds to wait for a response from the server
*/
public static void setPacketReplyTimeout(int timeout) {
initialize();
if (timeout <= 0) {
throw new IllegalArgumentException();
}
packetReplyTimeout = timeout;
}
/**
* Returns the number of milleseconds delay between sending keep-alive
* requests to the server. The default value is 30000 ms. A value of -1
* mean no keep-alive requests will be sent to the server.
*
* @return the milliseconds to wait between keep-alive requests, or -1 if
* no keep-alive should be sent.
*/
public static int getKeepAliveInterval() {
initialize();
return keepAliveInterval;
}
/**
* Sets the number of milleseconds delay between sending keep-alive
* requests to the server. The default value is 30000 ms. A value of -1
* mean no keep-alive requests will be sent to the server.
*
* @param interval the milliseconds to wait between keep-alive requests,
* or -1 if no keep-alive should be sent.
*/
public static void setKeepAliveInterval(int interval) {
initialize();
keepAliveInterval = interval;
}
/**
* Gets the default max size of a packet collector before it will delete
* the older packets.
*
* @return The number of packets to queue before deleting older packets.
*/
public static int getPacketCollectorSize() {
initialize();
return packetCollectorSize;
}
/**
* Sets the default max size of a packet collector before it will delete
* the older packets.
*
* @param The number of packets to queue before deleting older packets.
*/
public static void setPacketCollectorSize(int collectorSize) {
initialize();
packetCollectorSize = collectorSize;
}
/**
* Add a SASL mechanism to the list to be used.
*
* @param mech the SASL mechanism to be added
*/
public static void addSaslMech(String mech) {
initialize();
if(! defaultMechs.contains(mech) ) {
defaultMechs.add(mech);
}
}
/**
* Add a Collection of SASL mechanisms to the list to be used.
*
* @param mechs the Collection of SASL mechanisms to be added
*/
public static void addSaslMechs(Collection