List of usage examples for org.dom4j QName get
public static QName get(String qualifiedName, String uri)
From source file:org.frogx.service.core.DefaultMUGOccupant.java
License:Open Source License
/** * Sets a new presence information for the occupant.<br> <b>Note:</b> This doesn't include to announce the new presence in the room. * @param presence The new presence for the occupant. * @uml.property name="presence"/* w w w . j a va2s.c o m*/ */ public void setPresence(Presence presence) { Element element = presence.getElement().element(QName.get("game", MUGService.mugNS)); if (element != null) { presence.getElement().remove(element); } this.presence = presence; this.presence.setFrom(getRoomAddress()); }
From source file:org.frogx.service.core.iq.IQOwnerHandler.java
License:Open Source License
/** * Set the current room configuration as default values of the configuration form *//* w w w . j a v a2s . com*/ private void refreshConfigurationFormValues() { FormField field = configurationForm.getField("mug#roomconfig_roomname"); field.clearValues(); field.addValue(room.getNaturalLanguageName()); field = configurationForm.getField("mug#roomconfig_matchdesc"); field.clearValues(); field.addValue(room.getDescription()); field = configurationForm.getField("mug#roomconfig_moderated"); field.clearValues(); field.addValue((room.isModerated() ? "1" : "0")); field = configurationForm.getField("mug#roomconfig_allowinvites"); field.clearValues(); field.addValue((room.canOccupantsInvite() ? "1" : "0")); field = configurationForm.getField("mug#roomconfig_maxusers"); field.clearValues(); field.addValue(Integer.toString(room.getMaxOccupants())); field = configurationForm.getField("mug#roomconfig_publicroom"); field.clearValues(); field.addValue((room.isPublicRoom() ? "1" : "0")); field = configurationForm.getField("mug#roomconfig_membersonly"); field.clearValues(); field.addValue((room.isMembersOnly() ? "1" : "0")); field = configurationForm.getField("mug#roomconfig_anonymity"); field.clearValues(); if (room.isFullyAnonymous()) field.addValue("fully-anonymous"); else if (room.isNonAnonymous()) field.addValue("non-anonymous"); else field.addValue("semi-anonymous"); field = configurationForm.getField("mug#roomconfig_passwordprotectedroom"); field.clearValues(); field.addValue((room.isPasswordProtected() ? "1" : "0")); field = configurationForm.getField("mug#roomconfig_roomsecret"); field.clearValues(); if (room.isPasswordProtected()) field.addValue(room.getPassword()); // Remove the old element gameOptionsElement.remove(gameOptionsElement.element(QName.get("x", "jabber:x:data"))); // Add the new representation of configurationForm as an element gameOptionsElement.add(configurationForm.getElement()); gameOptionsElement.remove(gameOptionsElement.element(QName.get("options", room.getGame().getNamespace()))); Element gameOptions = gameOptionsElement.addElement("options", room.getGame().getNamespace()); Collection<Element> gameConfig = room.getMatch().getConfigurationForm(); if (gameConfig != null) { for (Iterator<Element> it = gameConfig.iterator(); it.hasNext();) { gameOptions.add(it.next()); } } }
From source file:org.frogx.service.core.iq.IQOwnerHandler.java
License:Open Source License
/** * Generating the configuration form//from w ww. j av a2 s . c o m */ private void initConfigForm() { Element element = DocumentHelper.createElement(QName.get("query", MUGService.mugNS + "#owner")); configurationForm = new DataForm(DataForm.Type.form); configurationForm.setTitle(locale.getLocalizedString("mug.config.form.title.1") + " " + room.getName() + " " + locale.getLocalizedString("mug.config.form.title.2")); List<String> params = new ArrayList<String>(); params.add(room.getName()); configurationForm.addInstruction(locale.getLocalizedString("mug.config.form.instruction")); FormField field = configurationForm.addField(); field.setVariable("FORM_TYPE"); field.setType(FormField.Type.hidden); field.addValue(MUGService.mugNS + "#matchconfig"); field = configurationForm.addField(); field.setVariable("mug#roomconfig_roomname"); field.setType(FormField.Type.text_single); field.setLabel(locale.getLocalizedString("mug.config.form.name")); field = configurationForm.addField(); field.setVariable("mug#roomconfig_matchdesc"); field.setType(FormField.Type.text_single); field.setLabel(locale.getLocalizedString("mug.config.form.description")); field = configurationForm.addField(); field.setVariable("mug#roomconfig_moderated"); field.setType(FormField.Type.boolean_type); field.setLabel(locale.getLocalizedString("mug.config.form.moderated")); field = configurationForm.addField(); field.setVariable("mug#roomconfig_allowinvites"); field.setType(FormField.Type.boolean_type); field.setLabel(locale.getLocalizedString("mug.config.form.allowinvites")); field = configurationForm.addField(); field.setVariable("mug#roomconfig_maxusers"); field.setType(FormField.Type.list_single); field.setLabel(locale.getLocalizedString("mug.config.form.maxusers")); field.addOption("10", "10"); field.addOption("20", "20"); field.addOption("30", "30"); field.addOption("40", "40"); field.addOption("50", "50"); field = configurationForm.addField(); field.setVariable("mug#roomconfig_publicroom"); field.setType(FormField.Type.boolean_type); field.setLabel(locale.getLocalizedString("mug.config.form.publicroom")); field = configurationForm.addField(); field.setVariable("mug#roomconfig_membersonly"); field.setType(FormField.Type.boolean_type); field.setLabel(locale.getLocalizedString("mug.config.form.membersonly")); field = configurationForm.addField(); field.setVariable("mug#roomconfig_anonymity"); field.setType(FormField.Type.list_single); field.setLabel(locale.getLocalizedString("mug.config.form.anonymity")); field.addOption(locale.getLocalizedString("mug.config.form.anonymity.fully"), "fully-anonymous"); field.addOption(locale.getLocalizedString("mug.config.form.anonymity.semi"), "semi-anonymous"); field.addOption(locale.getLocalizedString("mug.config.form.anonymity.non"), "non-anonymous"); field = configurationForm.addField(); field.setVariable("mug#roomconfig_passwordprotectedroom"); field.setType(FormField.Type.boolean_type); field.setLabel(locale.getLocalizedString("mug.config.form.password.protected")); field = configurationForm.addField(); field.setType(FormField.Type.fixed); field.addValue(locale.getLocalizedString("mug.config.form.password.instruction")); field = configurationForm.addField(); field.setVariable("mug#roomconfig_roomsecret"); field.setType(FormField.Type.text_private); field.setLabel(locale.getLocalizedString("mug.config.form.password")); gameOptionsElement = element.addElement("options"); gameOptionsElement.add(configurationForm.getElement()); probeResult = element; }
From source file:org.frogx.service.core.iq.IQSearchHandler.java
License:Open Source License
/** * Handle a Jabber Search query and get the resulting IQ packet. * //from w ww . ja va 2 s .c o m * @param packet The IQ Query. * @return The IQ reply resulting from the query. */ public IQ handleIQ(IQ packet) { // Ignore packets with type error or result if (packet.getType() == IQ.Type.error || packet.getType() == IQ.Type.result) { return null; } IQ reply = IQ.createResultIQ(packet); Element query = packet.getChildElement(); Element formElement = query.element(QName.get("x", "jabber:x:data")); // check if its a jabber search request if (!query.getName().equals("query") || !query.getNamespaceURI().equals("jabber:iq:search")) { reply.setError(PacketError.Condition.bad_request); return reply; } if (formElement == null) { // return an empty form reply.setChildElement(getSearchForm()); } else { // get the list of the found rooms List<MUGRoom> mugrsm = processSearchForm(formElement); // handle jabber resulting set management Element set = query.element(QName.get("set", ResultSet.NAMESPACE_RESULT_SET_MANAGEMENT)); ResultSet<MUGRoom> resultSet = new ResultSetImpl<MUGRoom>(sortByUserAmount(mugrsm)); if (set != null) { if (!ResultSet.isValidRSMRequest(set)) { reply.setError(Condition.bad_request); return reply; } try { mugrsm = resultSet.applyRSMDirectives(set); } catch (NullPointerException e) { reply.setError(Condition.item_not_found); return reply; } } Element resultQuery = reply.setChildElement("query", "jabber:iq:search"); DataForm resultForm = createResultingForm(mugrsm); if (resultForm != null) { resultQuery.add(resultForm.getElement()); if (set != null) resultQuery.add(resultSet.generateSetElementFromResults(mugrsm)); } } return reply; }
From source file:org.frogx.service.core.iq.IQSearchHandler.java
License:Open Source License
/** * Creates a Jabber Search form and returns the XML query element. * /*from ww w . j a v a 2 s . com*/ * @return A search element with an empty form. */ private Element getSearchForm() { Element element = DocumentHelper.createElement(QName.get("query", "jabber:iq:search")); DataForm searchForm = new DataForm(DataForm.Type.form); Map<String, MultiUserGame> games = service.getSupportedGames(); searchForm.setTitle(locale.getLocalizedString("mug.search.form.title")); searchForm.addInstruction(locale.getLocalizedString("mug.search.form.instruction")); FormField field = searchForm.addField(); field.setVariable("FORM_TYPE"); field.setType(FormField.Type.hidden); field.addValue("jabber:iq:search"); field = searchForm.addField(); field.setVariable(nameField); field.setType(FormField.Type.text_single); field.setLabel(locale.getLocalizedString("mug.search.form.name")); field.setRequired(false); field = searchForm.addField(); field.setVariable(exactNameField); field.setType(FormField.Type.boolean_type); field.setLabel(locale.getLocalizedString("mug.search.form.exact_name")); field.setRequired(false); field = searchForm.addField(); field.setVariable(savedRoomsField); field.setType(FormField.Type.boolean_type); field.setLabel(locale.getLocalizedString("mug.search.form.saved")); field.setRequired(false); field = searchForm.addField(); field.setVariable(rolesField); field.setType(FormField.Type.list_single); field.setLabel(locale.getLocalizedString("mug.search.form.min_roles")); field.setRequired(false); for (int i = 0; i <= 15; i++) { field.addOption(Integer.toString(i), Integer.toString(i)); } field.addValue("0"); field = searchForm.addField(); field.setVariable(occupantsField); field.setType(FormField.Type.list_single); field.setLabel(locale.getLocalizedString("mug.search.form.max_occupants")); field.setRequired(false); for (int i = 5; i <= 40; i = i + 5) { field.addOption(Integer.toString(i), Integer.toString(i)); } field.addValue("20"); if (games != null && !games.isEmpty()) { Collection<String> categories = service.getGameCategories(); field = searchForm.addField(); field.setVariable(categoryField); field.setType(FormField.Type.list_single); field.setLabel(locale.getLocalizedString("mug.search.form.category")); field.setRequired(false); if (categories.size() > 1) { field.addOption("any", "any"); field.addValue("any"); } for (String category : categories) { field.addOption(category, category); } field = searchForm.addField(); field.setVariable(gameField); field.setType(FormField.Type.list_multi); field.setLabel(locale.getLocalizedString("mug.search.form.games")); field.setRequired(false); for (MultiUserGame game : games.values()) { field.addOption(game.getDescription(), game.getNamespace()); } } element.add(searchForm.getElement()); return element; }
From source file:org.jboss.rusheye.CommandCrawl.java
License:Open Source License
private void addDocumentRoot() { ns = Namespace.get(RushEye.NAMESPACE_VISUAL_SUITE); Element root = document.addElement(QName.get("visual-suite", ns)); Namespace xsi = Namespace.get("xsi", "http://www.w3.org/2001/XMLSchema-instance"); QName schemaLocation = QName.get("schemaLocation", xsi); root.addNamespace("", ns.getURI()); root.addNamespace(xsi.getPrefix(), xsi.getURI()); root.addAttribute(schemaLocation, ns.getURI() + " " + RushEye.SCHEMA_LOCATION_VISUAL_SUITE); Element globalConfiguration = root.addElement(QName.get("global-configuration", ns)); addSuiteListener(globalConfiguration); addRetrievers(globalConfiguration);// ww w . j ava 2s . c om addPerception(globalConfiguration); addMasksByType(base, globalConfiguration); addTests(base, root); }
From source file:org.jboss.rusheye.CommandCrawl.java
License:Open Source License
private void addSuiteListener(Element globalConfiguration) { Element suiteListener = globalConfiguration.addElement(QName.get("listener", ns)); suiteListener.addAttribute("type", CompareListener.class.getName()); suiteListener.addElement(QName.get("result-collector", ns)).addText(ResultCollectorImpl.class.getName()); suiteListener.addElement(QName.get("result-storage", ns)).addText(FileStorage.class.getName()); suiteListener.addElement(QName.get("result-writer", ns)).addText(FileResultWriter.class.getName()); suiteListener.addElement(QName.get("result-statistics", ns)).addText(OverallStatistics.class.getName()); }
From source file:org.jboss.rusheye.CommandCrawl.java
License:Open Source License
private void addRetrievers(Element globalConfiguration) { globalConfiguration.addElement(QName.get("pattern-retriever", ns)).addAttribute("type", FileRetriever.class.getName()); globalConfiguration.addElement(QName.get("mask-retriever", ns)).addAttribute("type", FileRetriever.class.getName()); globalConfiguration.addElement(QName.get("sample-retriever", ns)).addAttribute("type", FileSampleRetriever.class.getName()); }
From source file:org.jboss.rusheye.CommandCrawl.java
License:Open Source License
private void addPerception(Element base) { Element perception = base.addElement(QName.get("perception", ns)); if (onePixelTreshold != null) { perception.addElement(QName.get("one-pixel-treshold", ns)).addText(String.valueOf(onePixelTreshold)); }//from ww w.j a v a2 s . c o m if (globalDifferenceTreshold != null) { perception.addElement(QName.get("global-difference-treshold", ns)) .addText(String.valueOf(globalDifferenceTreshold)); } if (globalDifferenceAmount != null) { perception.addElement(QName.get("global-difference-amount", ns)).addText(globalDifferenceAmount); } }
From source file:org.jboss.rusheye.CommandCrawl.java
License:Open Source License
private void addMasks(File dir, Element base, MaskType maskType) { if (dir.exists() && dir.isDirectory()) { for (File file : dir.listFiles()) { String id = substringBeforeLast(file.getName(), "."); String source = getRelativePath(file); String info = substringAfterLast(id, "--"); String[] infoTokens = split(info, "-"); Element mask = base.addElement(QName.get("mask", ns)).addAttribute("id", id) .addAttribute("type", maskType.value()).addAttribute("source", source); for (String alignment : infoTokens) { String attribute = ArrayUtils.contains(new String[] { "top", "bottom" }, alignment) ? "vertical-align" : "horizontal-align"; mask.addAttribute(attribute, alignment); }/*from w ww .j a va 2 s. c om*/ } } }