private DataForm createDefaultInitiationForm() { final DataForm form = new DataForm(Form.TYPE_FORM); final FormField field = new FormField(STREAM_DATA_FIELD_NAME); field.setType(FormField.TYPE_LIST_SINGLE); if (!IBB_ONLY) { field.addOption(new FormField.Option(Socks5BytestreamManager.NAMESPACE)); } field.addOption(new FormField.Option(InBandBytestreamManager.NAMESPACE)); form.addField(field); return form; }
private FormField getStreamMethodField(DataForm form) { FormField field = null; for (final Iterator<FormField> it = form.getFields(); it.hasNext(); ) { field = it.next(); if (field.getVariable().equals(STREAM_DATA_FIELD_NAME)) { break; } field = null; } return field; }
public static MultiUserChat createConferenceRoom( ImConnection talkConnection, String roomName, List<String> memberList) throws XMPPException { try { MultiUserChat muc = getMultiUserChat(talkConnection, roomName); if (muc != null) { // 创建聊天室 muc.join(talkConnection.getXMPPConnection().getUser()); // muc.create(roomName); // roomName房间的名字 // 获得聊天室的配置表单 Form form = muc.getConfigurationForm(); // 根据原始表单创建一个要提交的新表单。 Form submitForm = form.createAnswerForm(); // 向要提交的表单添加默认答复 for (Iterator<FormField> fields = form.getFields(); fields.hasNext(); ) { FormField field = (FormField) fields.next(); if (!FormField.TYPE_HIDDEN.equals(field.getType()) && field.getVariable() != null) { // 设置默认值作为答复 submitForm.setDefaultAnswer(field.getVariable()); } } // 设置聊天室的新拥有者 List<String> owners = new ArrayList<String>(); owners.add(talkConnection.getXMPPConnection().getUser()); // 用户JID submitForm.setAnswer("muc#roomconfig_roomowners", owners); // 设置聊天室是持久聊天室,即将要被保存下来 submitForm.setAnswer("muc#roomconfig_persistentroom", true); // 房间仅对成员开放 submitForm.setAnswer("muc#roomconfig_membersonly", false); // 允许占有者邀请其他人 submitForm.setAnswer("muc#roomconfig_allowinvites", true); // 登录房间对话 submitForm.setAnswer("muc#roomconfig_enablelogging", true); // 仅允许注册的昵称登录 submitForm.setAnswer("x-muc#roomconfig_reservednick", true); // 允许使用者修改昵称 submitForm.setAnswer("x-muc#roomconfig_canchangenick", false); // 允许用户注册房间 submitForm.setAnswer("x-muc#roomconfig_registration", false); // 发送已完成的表单(有默认值)到服务器来配置聊天室 submitForm.setAnswer("muc#roomconfig_passwordprotectedroom", true); // 添加群成员 for (String tempMember : memberList) { muc.grantMembership(tempMember); } // 发送已完成的表单(有默认值)到服务器来配置聊天室 muc.sendConfigurationForm(submitForm); } return muc; } catch (XMPPException e) { e.printStackTrace(); throw new XMPPException(""); } }
private StreamNegotiator getOutgoingNegotiator(final FormField field) throws XMPPException { String variable; boolean isByteStream = false; boolean isIBB = false; for (final Iterator<String> it = field.getValues(); it.hasNext(); ) { variable = it.next(); if (variable.equals(Socks5BytestreamManager.NAMESPACE) && !IBB_ONLY) { isByteStream = true; } else if (variable.equals(InBandBytestreamManager.NAMESPACE)) { isIBB = true; } } if (!isByteStream && !isIBB) { final XMPPError error = new XMPPError(XMPPError.Condition.bad_request, "No acceptable transfer mechanism"); throw new XMPPException(error.getMessage(), error); } if (isByteStream && isIBB) { return new FaultTolerantNegotiator( connection, byteStreamTransferManager, inbandTransferManager); } else if (isByteStream) { return byteStreamTransferManager; } else { return inbandTransferManager; } }
public void addFields(final DataForm serviceExtension) { for (PermissionType type : PermissionType.values()) { FormField field = new FormField(type.getSpecName()); field.setLabel(type.getLabel()); switch (type) { case readFile: field.setType(FormField.TYPE_LIST_MULTI); if (null != readPermissions) { addPermittedPaths(field, readPermissions); } break; case writeFile: field.setType(FormField.TYPE_LIST_MULTI); if (null != writePermissions) { addPermittedPaths(field, writePermissions); } break; case deleteFile: field.setType(FormField.TYPE_LIST_MULTI); if (null != deletePermissions) { addPermittedPaths(field, deletePermissions); } break; case executeProgram: field.setType(FormField.TYPE_LIST_MULTI); if (null != execPermissions) { addPermittedPaths(field, execPermissions); } break; case createFileLink: field.setType(FormField.TYPE_LIST_MULTI); if (null != linkPermissions) { addPermittedPaths(field, linkPermissions); } break; default: // Other types have no special formatting. field.setType(FormField.TYPE_BOOLEAN); field.addValue(permittedTypes.contains(type) ? "true" : "false"); } serviceExtension.addField(field); } }
/** * Creates a node with specified configuration. * * <p>Note: This is the only way to create a collection node. * * @param name The name of the node, which must be unique within the pubsub service * @param config The configuration for the node * @return The node that was created * @exception XMPPException */ public Node createNode(String name, Form config) throws XMPPException { PubSub request = createPubsubPacket(to, Type.SET, new NodeExtension(PubSubElementType.CREATE, name)); boolean isLeafNode = true; if (config != null) { request.addExtension(new FormNode(FormNodeType.CONFIGURE, config)); FormField nodeTypeField = config.getField(ConfigureNodeFields.node_type.getFieldName()); if (nodeTypeField != null) isLeafNode = nodeTypeField.getValues().next().equals(NodeType.leaf.toString()); } // Errors will cause exceptions in getReply, so it only returns // on success. sendPubsubPacket(con, to, Type.SET, request); Node newNode = isLeafNode ? new LeafNode(con, name) : new CollectionNode(con, name); newNode.setTo(to); nodeMap.put(newNode.getId(), newNode); return newNode; }
public String getJid() { try { System.out.println("getJid method executed"); ConnectionConfiguration config = new ConnectionConfiguration(DOMAIN, PORT); config.setSASLAuthenticationEnabled(true); XMPPConnection con = new XMPPConnection(config); con.connect(); System.out.println("Connection ok"); con.login("searchuser", "search"); System.out.println("Logged in"); UserSearchManager search = new UserSearchManager(con); System.out.println("User Search created"); Collection services = search.getSearchServices(); System.out.println("Search Services found:"); Iterator it = services.iterator(); while (it.hasNext()) { System.out.println(it.next()); } Form searchForm = search.getSearchForm("search." + "cuopencomm"); System.out.println("Available search fields:"); Iterator<FormField> fields = searchForm.getFields(); while (fields.hasNext()) { FormField field = fields.next(); System.out.println(field.getVariable() + " : " + field.getType()); } Form answerForm = searchForm.createAnswerForm(); answerForm.setAnswer("search", email); answerForm.setAnswer("Email", true); ReportedData data = search.getSearchResults(answerForm, "search." + "cuopencomm"); System.out.println("\nColumns that are included as part of the search results:"); Iterator<Column> columns = data.getColumns(); while (columns.hasNext()) { System.out.println(columns.next().getVariable()); } System.out.println("\nThe jids and emails from our each of our hits:"); Iterator<Row> rows = data.getRows(); while (rows.hasNext()) { Row row = rows.next(); Iterator<String> jids = row.getValues("jid"); Iterator<String> emails = row.getValues("email"); String jidFound = null; String emailFound = null; while (emails.hasNext() && jids.hasNext()) { jidFound = jids.next(); emailFound = emails.next(); System.out.println(jidFound); System.out.println(emailFound); if (emailFound.equalsIgnoreCase(email)) { jid = jidFound; String[] jidCleaned = jid.split("@"); jid = jidCleaned[0]; System.out.println(jid); } } } con.disconnect(); return jid; } catch (Exception ex) { System.out.println("Caught Exception :" + ex.getMessage()); return jid; } }
@Override public Set<FormField> toFormFields(String name) { Set<FormField> set = new HashSet<FormField>(); if (mOptions == null) return set; FormField f1 = new FormField(name); f1.setLabel(mLabel); f1.setDescription(mDescription); f1.setRequired(mRequired); if (mIsHidden) { f1.setType(FormField.TYPE_HIDDEN); } else { f1.setType(FormField.TYPE_LIST_SINGLE); } for (int i = 0; i < mOptions.size(); i++) { String label = mOptions.get(i).getLabel(); ArrayList<String> options = mOptions.get(i).getValues(); if ((options != null) && (options.size() > 0)) { String option = options.get(0); f1.addOption(new Option(label, option)); } } if (mValues.size() > 0) { f1.addValue(getValueAsString(0)); } set.add(f1); FormField f2 = new FormField(name + Specialization.SPECIALIZECHARACTER + Specialization.KEY_TYPE); f2.setType(FormField.TYPE_HIDDEN); f2.addValue(Parameter.TYPENAME_OPTION); set.add(f2); FormField f3 = new FormField(name + Specialization.SPECIALIZECHARACTER + Specialization.KEY_SUBTYPE); f3.setType(FormField.TYPE_HIDDEN); f3.addValue(mSubType); set.add(f3); if (mSubmitActionHint) { FormField f4 = new FormField( name + Specialization.SPECIALIZECHARACTER + Specialization.KEY_SUBMITACTIONHINT); f4.setType(FormField.TYPE_HIDDEN); f4.addValue(String.valueOf(mSubmitActionHint)); set.add(f4); } return set; }
public static void createMucChannel( String channelname, String channeltopic, int userid, int channelid) { try { if (!Application.mucchannels.containsKey(channelid)) { // create MUC MultiUserChat muc = new MultiUserChat(Application.conn, channelname + "@conference.webchat"); System.out.println("Channelname: " + channelname); muc.create(channelname); Application.mucchannels.put(channelid, muc); Form form = muc.getConfigurationForm(); Form submitForm = form.createAnswerForm(); for (Iterator<FormField> fields = form.getFields(); fields.hasNext(); ) { FormField field = (FormField) fields.next(); if (!FormField.TYPE_HIDDEN.equals(field.getType()) && field.getVariable() != null) { submitForm.setDefaultAnswer(field.getVariable()); } } List<String> owners = new ArrayList<String>(); owners.add("webchat@webchat"); submitForm.setAnswer("muc#roomconfig_roomowners", owners); muc.sendConfigurationForm(submitForm); muc.invite( models.User.find.byId(userid).username + "@webchat/Smack", "Einladung in Channel " + channelname); final int chanid = channelid; muc.sendMessage("Willkommen: Topic lautet " + channeltopic + "!"); muc.addMessageListener( new PacketListener() { @Override public void processPacket(Packet packet) { if (packet instanceof Message) { String[] temp; temp = ((Message) packet).getFrom().split("/"); if (!temp[1].equals(models.Channel.find.byId(chanid).name)) { System.out.println("Received user: "******"@webchat/Smack", "Einladung in Channel " + channelname); muc.sendMessage("Willkommen: Topic lautet" + channeltopic + "!"); } } catch (XMPPException exp) { exp.printStackTrace(); } }
/** * Calculates the <tt>String</tt> for a specific <tt>DiscoverInfo</tt> which is to be hashed in * order to compute the ver string for that <tt>DiscoverInfo</tt>. * * @param discoverInfo the <tt>DiscoverInfo</tt> for which the <tt>String</tt> to be hashed in * order to compute its ver string is to be calculated * @return the <tt>String</tt> for <tt>discoverInfo</tt> which is to be hashed in order to compute * its ver string */ private static String calculateEntityCapsString(DiscoverInfo discoverInfo) { StringBuilder bldr = new StringBuilder(); // Add identities { Iterator<DiscoverInfo.Identity> identities = discoverInfo.getIdentities(); SortedSet<DiscoverInfo.Identity> is = new TreeSet<DiscoverInfo.Identity>( new Comparator<DiscoverInfo.Identity>() { public int compare(DiscoverInfo.Identity i1, DiscoverInfo.Identity i2) { int category = i1.getCategory().compareTo(i2.getCategory()); if (category != 0) return category; int type = i1.getType().compareTo(i2.getType()); if (type != 0) return type; /* * TODO Sort by xml:lang. * * Since sort by xml:lang is currently missing, * use the last supported sort criterion i.e. * type. */ return type; } }); if (identities != null) while (identities.hasNext()) is.add(identities.next()); for (DiscoverInfo.Identity i : is) { bldr.append(i.getCategory()) .append('/') .append(i.getType()) .append("//") .append(i.getName()) .append('<'); } } // Add features { Iterator<DiscoverInfo.Feature> features = getDiscoverInfoFeatures(discoverInfo); SortedSet<String> fs = new TreeSet<String>(); if (features != null) while (features.hasNext()) fs.add(features.next().getVar()); for (String f : fs) bldr.append(f).append('<'); } DataForm extendedInfo = (DataForm) discoverInfo.getExtension("x", "jabber:x:data"); if (extendedInfo != null) { synchronized (extendedInfo) { SortedSet<FormField> fs = new TreeSet<FormField>( new Comparator<FormField>() { public int compare(FormField f1, FormField f2) { return f1.getVariable().compareTo(f2.getVariable()); } }); FormField formType = null; for (Iterator<FormField> fieldsIter = extendedInfo.getFields(); fieldsIter.hasNext(); ) { FormField f = fieldsIter.next(); if (!f.getVariable().equals("FORM_TYPE")) fs.add(f); else formType = f; } // Add FORM_TYPE values if (formType != null) formFieldValuesToCaps(formType.getValues(), bldr); // Add the other values for (FormField f : fs) { bldr.append(f.getVariable()).append('<'); formFieldValuesToCaps(f.getValues(), bldr); } } } return bldr.toString(); }
private void addPermittedPaths(final FormField field, final PathPermissions p) { for (String path : p.getPositiveRules()) { field.addValue(path); } }