本文整理匯總了Java中org.jivesoftware.smack.util.StringUtils類的典型用法代碼示例。如果您正苦於以下問題:Java StringUtils類的具體用法?Java StringUtils怎麽用?Java StringUtils使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
StringUtils類屬於org.jivesoftware.smack.util包,在下文中一共展示了StringUtils類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: init
import org.jivesoftware.smack.util.StringUtils; //導入依賴的package包/類
public void init() throws XMPPException {
new TrackRooms().addTo(conn);
new TrackStatus(getMonitorRoomJID().toLowerCase()).addTo(conn);
new ListenForChat().addTo(conn);
monitorRoom = new MultiUserChat(conn, getMonitorRoomJID());
monitorRoom.addMessageListener(this);
monitorRoom.addParticipantStatusListener(this);
monitorRoom.join(StringUtils.parseName(conn.getUser()));
try {
// This is necessary to create the room if it doesn't already exist
monitorRoom.sendConfigurationForm(new Form(Form.TYPE_SUBMIT));
}
catch (XMPPException ex) {
// 403 code means the room already exists and user is not an owner
if (ex.getXMPPError().getCode() != 403) {
throw ex;
}
}
sendStatus(me);
}
示例2: changeUserImage
import org.jivesoftware.smack.util.StringUtils; //導入依賴的package包/類
/**
* 修改用戶頭像
* @param xmppConnection
* @param file
*/
public static boolean changeUserImage(XMPPConnection xmppConnection,File file) {
try {
VCard vcard = new VCard();
vcard.load(xmppConnection);
byte[] bytes= MyFileUtil.getFileBytes(file);
String encodedImage = StringUtils.encodeBase64(bytes);
vcard.setAvatar(bytes, encodedImage);
vcard.setEncodedImage(encodedImage);
vcard.setField("PHOTO", "<TYPE>image/jpg</TYPE><BINVAL>" + encodedImage + "</BINVAL>", true);
vcard.save(xmppConnection);
return true;
} catch (Exception e) {
e.printStackTrace();
return false;
}
}
示例3: changeUserImage
import org.jivesoftware.smack.util.StringUtils; //導入依賴的package包/類
/**
* 修改用戶頭像
*
* @param xmppConnection
* @param file
*/
public static boolean changeUserImage(XMPPConnection xmppConnection, File file) {
try {
VCard vcard = new VCard();
vcard.load(xmppConnection);
byte[] bytes = MyFileUtil.getFileBytes(file);
String encodedImage = StringUtils.encodeBase64(bytes);
vcard.setAvatar(bytes, encodedImage);
vcard.setEncodedImage(encodedImage);
vcard.setField("PHOTO", "<TYPE>image/jpg</TYPE><BINVAL>" + encodedImage + "</BINVAL>", true);
vcard.save(xmppConnection);
return true;
} catch (Exception e) {
e.printStackTrace();
return false;
}
}
示例4: getIQHoxtChildElementBuilder
import org.jivesoftware.smack.util.StringUtils; //導入依賴的package包/類
@Override
protected IQChildElementXmlStringBuilder getIQHoxtChildElementBuilder(IQChildElementXmlStringBuilder builder) {
builder.append(" ");
builder.append("method='").append(method.toString()).append("'");
builder.append(" ");
builder.append("resource='").append(StringUtils.escapeForXML(resource)).append("'");
builder.append(" ");
builder.append("version='").append(StringUtils.escapeForXML(version)).append("'");
if (maxChunkSize != 0) {
builder.append(" ");
builder.append("maxChunkSize='").append(Integer.toString(maxChunkSize)).append("'");
}
builder.append(" ");
builder.append("sipub='").append(Boolean.toString(sipub)).append("'");
builder.append(" ");
builder.append("ibb='").append(Boolean.toString(ibb)).append("'");
builder.append(" ");
builder.append("jingle='").append(Boolean.toString(jingle)).append("'");
builder.append(">");
return builder;
}
示例5: StreamError
import org.jivesoftware.smack.util.StringUtils; //導入依賴的package包/類
public StreamError(Condition condition, String conditionText, Map<String, String> descriptiveTexts, List<ExtensionElement> extensions) {
super(descriptiveTexts, extensions);
// Some implementations may send the condition as non-empty element containing the empty string, that is
// <condition xmlns='foo'></condition>, in this case the parser may calls this constructor with the empty string
// as conditionText, therefore reset it to null if it's the empty string
if (StringUtils.isNullOrEmpty(conditionText)) {
conditionText = null;
}
if (conditionText != null) {
switch (condition) {
case see_other_host:
break;
default:
throw new IllegalArgumentException("The given condition '" + condition
+ "' can not contain a conditionText");
}
}
this.condition = condition;
this.conditionText = conditionText;
}
示例6: StreamOpen
import org.jivesoftware.smack.util.StringUtils; //導入依賴的package包/類
public StreamOpen(CharSequence to, CharSequence from, String id, String lang, StreamContentNamespace ns) {
this.to = StringUtils.maybeToString(to);
this.from = StringUtils.maybeToString(from);
this.id = id;
this.lang = lang;
switch (ns) {
case client:
this.contentNamespace = CLIENT_NAMESPACE;
break;
case server:
this.contentNamespace = SERVER_NAMESPACE;
break;
default:
throw new IllegalStateException();
}
}
示例7: serializeMetaData
import org.jivesoftware.smack.util.StringUtils; //導入依賴的package包/類
/**
* Serializes a Map of String name/value pairs into the meta-data XML format.
*
* @param metaData the Map of meta-data as Map<String,List<String>>
* @return the meta-data values in XML form.
*/
public static String serializeMetaData(Map<String, List<String>> metaData) {
StringBuilder buf = new StringBuilder();
if (metaData != null && metaData.size() > 0) {
buf.append("<metadata xmlns=\"http://jivesoftware.com/protocol/workgroup\">");
for (Iterator<String> i = metaData.keySet().iterator(); i.hasNext();) {
String key = i.next();
List<String> value = metaData.get(key);
for (Iterator<String> it = value.iterator(); it.hasNext();) {
String v = it.next();
buf.append("<value name=\"").append(key).append("\">");
buf.append(StringUtils.escapeForXML(v));
buf.append("</value>");
}
}
buf.append("</metadata>");
}
return buf.toString();
}
示例8: changeNickname
import org.jivesoftware.smack.util.StringUtils; //導入依賴的package包/類
/**
* Changes the occupant's nickname to a new nickname within the room. Each room occupant
* will receive two presence packets. One of type "unavailable" for the old nickname and one
* indicating availability for the new nickname. The unavailable presence will contain the new
* nickname and an appropriate status code (namely 303) as extended presence information. The
* status code 303 indicates that the occupant is changing his/her nickname.
*
* @param nickname the new nickname within the room.
* @throws XMPPErrorException if the new nickname is already in use by another occupant.
* @throws NoResponseException if there was no response from the server.
* @throws NotConnectedException
*/
public void changeNickname(String nickname) throws NoResponseException, XMPPErrorException, NotConnectedException {
StringUtils.requireNotNullOrEmpty(nickname, "Nickname must not be null or blank.");
// Check that we already have joined the room before attempting to change the
// nickname.
if (!joined) {
throw new IllegalStateException("Must be logged into the room to change nickname.");
}
// We change the nickname by sending a presence packet where the "to"
// field is in the form "[email protected]/nickname"
// We don't have to signal the MUC support again
Presence joinPresence = new Presence(Presence.Type.available);
joinPresence.setTo(room + "/" + nickname);
// Wait for a presence packet back from the server.
StanzaFilter responseFilter =
new AndFilter(
FromMatchesFilter.createFull(room + "/" + nickname),
new StanzaTypeFilter(Presence.class));
PacketCollector response = connection.createPacketCollectorAndSend(responseFilter, joinPresence);
// Wait up to a certain number of seconds for a reply. If there is a negative reply, an
// exception will be thrown
response.nextResultOrThrow();
this.nickname = nickname;
}
示例9: changeAvailabilityStatus
import org.jivesoftware.smack.util.StringUtils; //導入依賴的package包/類
/**
* Changes the occupant's availability status within the room. The presence type
* will remain available but with a new status that describes the presence update and
* a new presence mode (e.g. Extended away).
*
* @param status a text message describing the presence update.
* @param mode the mode type for the presence update.
* @throws NotConnectedException
*/
public void changeAvailabilityStatus(String status, Presence.Mode mode) throws NotConnectedException {
StringUtils.requireNotNullOrEmpty(nickname, "Nickname must not be null or blank.");
// Check that we already have joined the room before attempting to change the
// availability status.
if (!joined) {
throw new IllegalStateException(
"Must be logged into the room to change the " + "availability status.");
}
// We change the availability status by sending a presence packet to the room with the
// new presence status and mode
Presence joinPresence = new Presence(Presence.Type.available);
joinPresence.setStatus(status);
joinPresence.setMode(mode);
joinPresence.setTo(room + "/" + nickname);
// Send join packet.
connection.sendStanza(joinPresence);
}
示例10: getAvatarHash
import org.jivesoftware.smack.util.StringUtils; //導入依賴的package包/類
/**
* Returns the SHA-1 Hash of the Avatar image.
*
* @return the SHA-1 Hash of the Avatar image.
*/
public String getAvatarHash() {
byte[] bytes = getAvatar();
if (bytes == null) {
return null;
}
MessageDigest digest;
try {
digest = MessageDigest.getInstance("SHA-1");
}
catch (NoSuchAlgorithmException e) {
LOGGER.log(Level.SEVERE, "Failed to get message digest", e);
return null;
}
digest.update(bytes);
return StringUtils.encodeHex(digest.digest());
}
示例11: testSimpleDirectoryCache
import org.jivesoftware.smack.util.StringUtils; //導入依賴的package包/類
private void testSimpleDirectoryCache(StringEncoder stringEncoder) throws IOException {
EntityCapsPersistentCache cache = new SimpleDirectoryPersistentCache(createTempDirectory());
EntityCapsManager.setPersistentCache(cache);
DiscoverInfo di = createComplexSamplePacket();
CapsVersionAndHash versionAndHash = EntityCapsManager.generateVerificationString(di, StringUtils.SHA1);
String nodeVer = di.getNode() + "#" + versionAndHash.version;
// Save the data in EntityCapsManager
EntityCapsManager.addDiscoverInfoByNode(nodeVer, di);
// Lose all the data
EntityCapsManager.clearMemoryCache();
DiscoverInfo restored_di = EntityCapsManager.getDiscoveryInfoByNodeVer(nodeVer);
assertNotNull(restored_di);
assertEquals(di.toXML().toString(), restored_di.toXML().toString());
}
示例12: calcResponse
import org.jivesoftware.smack.util.StringUtils; //導入依賴的package包/類
private String calcResponse(DigestType digestType) {
StringBuilder a2 = new StringBuilder();
if (digestType == DigestType.ClientResponse) {
a2.append("AUTHENTICATE");
}
a2.append(':');
a2.append(digestUri);
String hex_hashed_a2 = StringUtils.encodeHex(MD5.bytes(a2.toString()));
StringBuilder kd_argument = new StringBuilder();
kd_argument.append(hex_hashed_a1);
kd_argument.append(':');
kd_argument.append(nonce);
kd_argument.append(':');
kd_argument.append(INITAL_NONCE);
kd_argument.append(':');
kd_argument.append(cnonce);
kd_argument.append(':');
kd_argument.append(QOP_VALUE);
kd_argument.append(':');
kd_argument.append(hex_hashed_a2);
byte[] kd = MD5.bytes(kd_argument.toString());
String responseValue = StringUtils.encodeHex(kd);
return responseValue;
}
示例13: presenceChanged
import org.jivesoftware.smack.util.StringUtils; //導入依賴的package包/類
@Override
public void presenceChanged(Presence presence)
{
log.fine("Presence change from " + presence.getFrom());
String name = StringUtils.parseName(presence.getFrom());
if (!isMultiplicityDevice(name))
{
return;
}
if (presence.isAvailable())
{
notifyDeviceAvailable(name);
}
else
{
notifyDeviceUnavailable(name);
}
}
示例14: getEntry
import org.jivesoftware.smack.util.StringUtils; //導入依賴的package包/類
/**
* Returns the roster entry associated with the given XMPP address or
* <tt>null</tt> if the user is not an entry in the group.
*
* @param user the XMPP address of the user (eg "[email protected]").
* @return the roster entry or <tt>null</tt> if it does not exist in the group.
*/
public RosterEntry getEntry(String user) {
if (user == null) {
return null;
}
// Roster entries never include a resource so remove the resource
// if it's a part of the XMPP address.
user = StringUtils.parseBareAddress(user);
String userLowerCase = user.toLowerCase();
synchronized (entries) {
for (RosterEntry entry : entries) {
if (entry.getUser().equals(userLowerCase)) {
return entry;
}
}
}
return null;
}
示例15: toXML
import org.jivesoftware.smack.util.StringUtils; //導入依賴的package包/類
public String toXML() {
StringBuilder buf = new StringBuilder();
buf.append("<item jid=\"").append(user).append("\"");
if (name != null) {
buf.append(" name=\"").append(StringUtils.escapeForXML(name)).append("\"");
}
if (itemType != null) {
buf.append(" subscription=\"").append(itemType).append("\"");
}
if (itemStatus != null) {
buf.append(" ask=\"").append(itemStatus).append("\"");
}
buf.append(">");
for (String groupName : groupNames) {
buf.append("<group>").append(StringUtils.escapeForXML(groupName)).append("</group>");
}
buf.append("</item>");
return buf.toString();
}