mirror of
https://github.com/vanitasvitae/Smack.git
synced 2025-12-12 22:11:07 +01:00
Prefix subprojects with 'smack-'
instead of using the old baseName=smack appendix=project.name approach, we are now going convention over configuration and renaming the subprojects directories to the proper name. Having a prefix is actually very helpful, because the resulting libraries will be named like the subproject. And a core-4.0.0-rc1.jar is not as explicit about what it actually *is* as a smack-core-4.0.0-rc1.jar. SMACK-265
This commit is contained in:
parent
b6fb1f3743
commit
91fd15ad86
758 changed files with 42 additions and 42 deletions
|
|
@ -0,0 +1,96 @@
|
|||
/**
|
||||
*
|
||||
* Copyright 2014 Georg Lukas.
|
||||
*
|
||||
* 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.smackx.iqversion;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
import java.util.WeakHashMap;
|
||||
|
||||
import org.jivesoftware.smack.SmackException.NotConnectedException;
|
||||
import org.jivesoftware.smack.XMPPConnection;
|
||||
import org.jivesoftware.smack.Manager;
|
||||
import org.jivesoftware.smack.PacketListener;
|
||||
import org.jivesoftware.smack.filter.AndFilter;
|
||||
import org.jivesoftware.smack.filter.IQTypeFilter;
|
||||
import org.jivesoftware.smack.filter.PacketTypeFilter;
|
||||
import org.jivesoftware.smack.packet.IQ.Type;
|
||||
import org.jivesoftware.smack.packet.Packet;
|
||||
import org.jivesoftware.smackx.disco.ServiceDiscoveryManager;
|
||||
import org.jivesoftware.smackx.iqversion.packet.Version;
|
||||
|
||||
/**
|
||||
* A Version Manager that automatically responds to version IQs with a predetermined reply.
|
||||
*
|
||||
* <p>
|
||||
* The VersionManager takes care of handling incoming version request IQs, according to
|
||||
* XEP-0092 (Software Version). You can configure the version reply for a given connection
|
||||
* by running the following code:
|
||||
* </p>
|
||||
*
|
||||
* <pre>
|
||||
* Version MY_VERSION = new Version("My Little XMPP Application", "v1.23", "OS/2 32-bit");
|
||||
* VersionManager.getInstanceFor(mConnection).setVersion(MY_VERSION);
|
||||
* </pre>
|
||||
*
|
||||
* @author Georg Lukas
|
||||
*/
|
||||
public class VersionManager extends Manager {
|
||||
private static final Map<XMPPConnection, VersionManager> instances =
|
||||
Collections.synchronizedMap(new WeakHashMap<XMPPConnection, VersionManager>());
|
||||
|
||||
private Version own_version;
|
||||
|
||||
private VersionManager(final XMPPConnection connection) {
|
||||
super(connection);
|
||||
instances.put(connection, this);
|
||||
|
||||
ServiceDiscoveryManager sdm = ServiceDiscoveryManager.getInstanceFor(connection);
|
||||
sdm.addFeature(Version.NAMESPACE);
|
||||
|
||||
connection.addPacketListener(new PacketListener() {
|
||||
/**
|
||||
* Sends a Version reply on request
|
||||
* @throws NotConnectedException
|
||||
*/
|
||||
public void processPacket(Packet packet) throws NotConnectedException {
|
||||
if (own_version == null)
|
||||
return;
|
||||
|
||||
Version reply = new Version(own_version);
|
||||
reply.setPacketID(packet.getPacketID());
|
||||
reply.setTo(packet.getFrom());
|
||||
connection().sendPacket(reply);
|
||||
}
|
||||
}
|
||||
, new AndFilter(new PacketTypeFilter(Version.class), new IQTypeFilter(Type.GET)));
|
||||
}
|
||||
|
||||
public static synchronized VersionManager getInstanceFor(XMPPConnection connection) {
|
||||
VersionManager versionManager = instances.get(connection);
|
||||
|
||||
if (versionManager == null) {
|
||||
versionManager = new VersionManager(connection);
|
||||
}
|
||||
|
||||
return versionManager;
|
||||
}
|
||||
|
||||
public void setVersion(Version v) {
|
||||
own_version = v;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,152 @@
|
|||
/**
|
||||
*
|
||||
* Copyright 2003-2007 Jive Software.
|
||||
*
|
||||
* 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.smackx.iqversion.packet;
|
||||
|
||||
|
||||
import org.jivesoftware.smack.packet.IQ;
|
||||
import org.jivesoftware.smack.util.StringUtils;
|
||||
|
||||
/**
|
||||
* A Version IQ packet, which is used by XMPP clients to discover version information
|
||||
* about the software running at another entity's JID.<p>
|
||||
*
|
||||
* An example to discover the version of the server:
|
||||
* <pre>
|
||||
* // Request the version from the server.
|
||||
* Version versionRequest = new Version();
|
||||
* timeRequest.setType(IQ.Type.GET);
|
||||
* timeRequest.setTo("example.com");
|
||||
*
|
||||
* // Create a packet collector to listen for a response.
|
||||
* PacketCollector collector = con.createPacketCollector(
|
||||
* new PacketIDFilter(versionRequest.getPacketID()));
|
||||
*
|
||||
* con.sendPacket(versionRequest);
|
||||
*
|
||||
* // Wait up to 5 seconds for a result.
|
||||
* IQ result = (IQ)collector.nextResult(5000);
|
||||
* if (result != null && result.getType() == IQ.Type.RESULT) {
|
||||
* Version versionResult = (Version)result;
|
||||
* // Do something with result...
|
||||
* }</pre><p>
|
||||
*
|
||||
* @author Gaston Dombiak
|
||||
*/
|
||||
public class Version extends IQ {
|
||||
public static final String NAMESPACE = "jabber:iq:version";
|
||||
|
||||
private String name;
|
||||
private String version;
|
||||
private String os;
|
||||
|
||||
/**
|
||||
* 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) {
|
||||
this.setType(IQ.Type.RESULT);
|
||||
this.name = name;
|
||||
this.version = version;
|
||||
this.os = os;
|
||||
}
|
||||
|
||||
public Version(Version original) {
|
||||
this(original.name, original.version, original.os);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the natural-language name of the software. This property will always be
|
||||
* present in a result.
|
||||
*
|
||||
* @return the natural-language name of the software.
|
||||
*/
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the natural-language name of the software. This message should only be
|
||||
* invoked when parsing the XML and setting the property to a Version instance.
|
||||
*
|
||||
* @param name the natural-language name of the software.
|
||||
*/
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the specific version of the software. This property will always be
|
||||
* present in a result.
|
||||
*
|
||||
* @return the specific version of the software.
|
||||
*/
|
||||
public String getVersion() {
|
||||
return version;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the specific version of the software. This message should only be
|
||||
* invoked when parsing the XML and setting the property to a Version instance.
|
||||
*
|
||||
* @param version the specific version of the software.
|
||||
*/
|
||||
public void setVersion(String version) {
|
||||
this.version = version;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the operating system of the queried entity. This property will always be
|
||||
* present in a result.
|
||||
*
|
||||
* @return the operating system of the queried entity.
|
||||
*/
|
||||
public String getOs() {
|
||||
return os;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the operating system of the queried entity. This message should only be
|
||||
* invoked when parsing the XML and setting the property to a Version instance.
|
||||
*
|
||||
* @param os operating system of the queried entity.
|
||||
*/
|
||||
public void setOs(String os) {
|
||||
this.os = os;
|
||||
}
|
||||
|
||||
public String getChildElementXML() {
|
||||
StringBuilder buf = new StringBuilder();
|
||||
buf.append("<query xmlns=\"");
|
||||
buf.append(Version.NAMESPACE);
|
||||
buf.append("\">");
|
||||
if (name != null) {
|
||||
buf.append("<name>").append(StringUtils.escapeForXML(name)).append("</name>");
|
||||
}
|
||||
if (version != null) {
|
||||
buf.append("<version>").append(StringUtils.escapeForXML(version)).append("</version>");
|
||||
}
|
||||
if (os != null) {
|
||||
buf.append("<os>").append(StringUtils.escapeForXML(os)).append("</os>");
|
||||
}
|
||||
buf.append("</query>");
|
||||
return buf.toString();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,49 @@
|
|||
/**
|
||||
*
|
||||
* Copyright 2014 Georg Lukas.
|
||||
*
|
||||
* 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.smackx.iqversion.provider;
|
||||
|
||||
import org.jivesoftware.smack.packet.IQ;
|
||||
import org.jivesoftware.smack.provider.IQProvider;
|
||||
import org.jivesoftware.smackx.iqversion.packet.Version;
|
||||
import org.xmlpull.v1.XmlPullParser;
|
||||
|
||||
public class VersionProvider implements IQProvider {
|
||||
public IQ parseIQ(XmlPullParser parser) throws Exception {
|
||||
String name = null, version = null, os = null;
|
||||
|
||||
boolean done = false;
|
||||
while (!done) {
|
||||
int eventType = parser.next();
|
||||
String tagName = parser.getName();
|
||||
if (eventType == XmlPullParser.START_TAG) {
|
||||
if (tagName.equals("name")) {
|
||||
name = parser.nextText();
|
||||
}
|
||||
else if (tagName.equals("version")) {
|
||||
version = parser.nextText();
|
||||
}
|
||||
else if (tagName.equals("os")) {
|
||||
os = parser.nextText();
|
||||
}
|
||||
} else if (eventType == XmlPullParser.END_TAG && tagName.equals("query")) {
|
||||
done = true;
|
||||
}
|
||||
}
|
||||
return new Version(name, version, os);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue