List of usage examples for org.dom4j QName get
public static QName get(String qualifiedName, String uri)
From source file:org.jboss.rusheye.CommandCrawl.java
License:Open Source License
private void addTests(File dir, Element root) { if (dir.exists() && dir.isDirectory()) { tests: for (File testFile : dir.listFiles()) { for (MaskType mask : MaskType.values()) { if (testFile.getName().equals("masks-" + mask.value())) { continue tests; }// w w w . j av a 2 s . c om } if (testFile.isDirectory() && testFile.listFiles().length > 0) { String name = testFile.getName(); Element test = root.addElement(QName.get("test", ns)); test.addAttribute("name", name); addPatterns(testFile, test); addMasksByType(testFile, test); } if (testFile.isFile()) { String name = substringBeforeLast(testFile.getName(), "."); Element test = root.addElement(QName.get("test", ns)); test.addAttribute("name", name); String source = getRelativePath(testFile); Element pattern = test.addElement(QName.get("pattern", ns)); pattern.addAttribute("name", name); pattern.addAttribute("source", source); } } } }
From source file:org.jboss.rusheye.CommandCrawl.java
License:Open Source License
private void addPatterns(File dir, Element test) { if (dir.exists() && dir.isDirectory()) { for (File file : dir.listFiles()) { if (file.isFile()) { String name = substringBeforeLast(file.getName(), "."); String source = getRelativePath(file); Element pattern = test.addElement(QName.get("pattern", ns)); pattern.addAttribute("name", name); pattern.addAttribute("source", source); }//from w w w .jav a2s.c o m } } }
From source file:org.jeedevframework.jpush.server.xmpp.handler.IQRegisterHandler.java
License:Open Source License
/** * Handles the received IQ packet./*from ww w . j a va 2 s . c o m*/ * * @param packet the packet * @return the response to send back * @throws UnauthorizedException if the user is not authorized */ public IQ handleIQ(IQ packet) throws UnauthorizedException { IQ reply = null; ClientSession session = sessionManager.getSession(packet.getFrom()); if (session == null) { log.error("Session not found for key " + packet.getFrom()); reply = IQ.createResultIQ(packet); reply.setChildElement(packet.getChildElement().createCopy()); reply.setError(PacketError.Condition.internal_server_error); return reply; } if (IQ.Type.get.equals(packet.getType())) { reply = IQ.createResultIQ(packet); if (session.getStatus() == Session.STATUS_AUTHENTICATED) { // TODO } else { reply.setTo((JID) null); reply.setChildElement(probeResponse.createCopy()); } } else if (IQ.Type.set.equals(packet.getType())) { try { Element query = packet.getChildElement(); if (query.element("remove") != null) { if (session.getStatus() == Session.STATUS_AUTHENTICATED) { // TODO } else { throw new UnauthorizedException(); } } else { String username = query.elementText("username"); String password = query.elementText("password"); String email = query.elementText("email"); String name = query.elementText("name"); // Verify the username if (username != null) { Stringprep.nodeprep(username); } // Deny registration of users with no password if (password == null || password.trim().length() == 0) { reply = IQ.createResultIQ(packet); reply.setChildElement(packet.getChildElement().createCopy()); reply.setError(PacketError.Condition.not_acceptable); return reply; } if (email != null && email.matches("\\s*")) { email = null; } if (name != null && name.matches("\\s*")) { name = null; } User user = null; if (session.getStatus() == Session.STATUS_AUTHENTICATED) { try { user = userService.getUserByUsername(session.getUsername()); } catch (UserNotFoundException e) { log.info(session.getUsername() + ":" + e.getMessage()); } } else { try { user = userService.getUserByUsername(session.getUsername()); } catch (UserNotFoundException e) { log.info(session.getUsername() + ":" + e.getMessage()); } } if ((user == null) || (user.getId() == null) || (user.getId() == 0)) { user = new User(); user.setUsername(username); user.setPassword(password); user.setEmail(email); user.setName(name); userService.saveUser(user); } //reply = IQ.createResultIQ(packet); Element userprobeResponse = DocumentHelper.createElement(QName.get("query", NAMESPACE)); userprobeResponse.addElement("username").setText(user.getUsername()); userprobeResponse.addElement("password").setText(user.getPassword()); reply = IQ.createResultIQ(packet); reply.setChildElement(userprobeResponse); } } catch (Exception ex) { log.error(ex); reply = IQ.createResultIQ(packet); reply.setChildElement(packet.getChildElement().createCopy()); if (ex instanceof UserExistsException) { reply.setError(PacketError.Condition.conflict); } else if (ex instanceof UserNotFoundException) { reply.setError(PacketError.Condition.bad_request); } else if (ex instanceof StringprepException) { reply.setError(PacketError.Condition.jid_malformed); } else if (ex instanceof IllegalArgumentException) { reply.setError(PacketError.Condition.not_acceptable); } else { reply.setError(PacketError.Condition.internal_server_error); } } } // Send the response directly to the session if (reply != null) { session.process(reply); } return null; }
From source file:org.jeedevframework.jpush.server.xmpp.push.NotificationManager.java
License:Open Source License
/** * Creates a new notification IQ and returns it. *//*from w w w . j a v a 2 s. co m*/ private IQ createNotificationIQ(String apiKey, String appId, String showType, String title, String message, String uri, Integer timeToLive) { //Random random = new Random(); //String id = Integer.toHexString(random.nextInt()); String id = String.valueOf(System.nanoTime()); Element notification = DocumentHelper.createElement(QName.get("notification", NOTIFICATION_NAMESPACE)); notification.addElement("id").setText(id); notification.addElement("apiKey").setText(apiKey); notification.addElement("showType").setText(showType); notification.addElement("title").setText(title); notification.addElement("message").setText(message); notification.addElement("uri").setText(uri); IQ iq = new IQ(); iq.setType(IQ.Type.set); iq.setChildElement(notification); return iq; }
From source file:org.jivesoftware.admin.LdapUserProfile.java
License:Open Source License
/** * Saves current configuration as XML/DB properties. *//*from w ww . j ava 2 s . co m*/ public void saveProperties() { Element vCard = DocumentHelper.createElement(QName.get("vCard", "vcard-temp")); Element subelement; // Add name if (name != null && name.trim().length() > 0) { subelement = vCard.addElement("N"); subelement.addElement("GIVEN").setText(name.trim()); } // Add email if (email != null && email.trim().length() > 0) { subelement = vCard.addElement("EMAIL"); subelement.addElement("INTERNET"); subelement.addElement("USERID").setText(email.trim()); } // Add Full Name vCard.addElement("FN").setText(fullName.trim()); // Add nickname if (nickname != null && nickname.trim().length() > 0) { vCard.addElement("NICKNAME").setText(nickname.trim()); } // Add birthday if (birthday != null && birthday.trim().length() > 0) { vCard.addElement("BDAY").setText(birthday.trim()); } // Add photo/avatar if (photo != null && photo.trim().length() > 0) { Element element = vCard.addElement("PHOTO"); element.addElement("TYPE").setText("image/jpeg"); element.addElement("BINVAL").setText(photo.trim()); } // Add home address subelement = vCard.addElement("ADR"); subelement.addElement("HOME"); if (homeStreet != null && homeStreet.trim().length() > 0) { subelement.addElement("STREET").setText(homeStreet.trim()); } if (homeCity != null && homeCity.trim().length() > 0) { subelement.addElement("LOCALITY").setText(homeCity.trim()); } if (homeState != null && homeState.trim().length() > 0) { subelement.addElement("REGION").setText(homeState.trim()); } if (homeZip != null && homeZip.trim().length() > 0) { subelement.addElement("PCODE").setText(homeZip.trim()); } if (homeCountry != null && homeCountry.trim().length() > 0) { subelement.addElement("CTRY").setText(homeCountry.trim()); } // Add business address subelement = vCard.addElement("ADR"); subelement.addElement("WORK"); if (businessStreet != null && businessStreet.trim().length() > 0) { subelement.addElement("STREET").setText(businessStreet.trim()); } if (businessCity != null && businessCity.trim().length() > 0) { subelement.addElement("LOCALITY").setText(businessCity.trim()); } if (businessState != null && businessState.trim().length() > 0) { subelement.addElement("REGION").setText(businessState.trim()); } if (businessZip != null && businessZip.trim().length() > 0) { subelement.addElement("PCODE").setText(businessZip.trim()); } if (businessCountry != null && businessCountry.trim().length() > 0) { subelement.addElement("CTRY").setText(businessCountry.trim()); } // Add home phone if (homePhone != null && homePhone.trim().length() > 0) { subelement = vCard.addElement("TEL"); subelement.addElement("HOME"); subelement.addElement("VOICE"); subelement.addElement("NUMBER").setText(homePhone.trim()); } // Add home mobile if (homeMobile != null && homeMobile.trim().length() > 0) { subelement = vCard.addElement("TEL"); subelement.addElement("HOME"); subelement.addElement("CELL"); subelement.addElement("NUMBER").setText(homeMobile.trim()); } // Add home fax if (homeFax != null && homeFax.trim().length() > 0) { subelement = vCard.addElement("TEL"); subelement.addElement("HOME"); subelement.addElement("FAX"); subelement.addElement("NUMBER").setText(homeFax.trim()); } // Add home pager if (homePager != null && homePager.trim().length() > 0) { subelement = vCard.addElement("TEL"); subelement.addElement("HOME"); subelement.addElement("PAGER"); subelement.addElement("NUMBER").setText(homePager.trim()); } // Add business phone if (businessPhone != null && businessPhone.trim().length() > 0) { subelement = vCard.addElement("TEL"); subelement.addElement("WORK"); subelement.addElement("VOICE"); subelement.addElement("NUMBER").setText(businessPhone.trim()); } // Add business mobile if (businessMobile != null && businessMobile.trim().length() > 0) { subelement = vCard.addElement("TEL"); subelement.addElement("WORK"); subelement.addElement("CELL"); subelement.addElement("NUMBER").setText(businessMobile.trim()); } // Add business fax if (businessFax != null && businessFax.trim().length() > 0) { subelement = vCard.addElement("TEL"); subelement.addElement("WORK"); subelement.addElement("FAX"); subelement.addElement("NUMBER").setText(businessFax.trim()); } // Add business pager if (businessPager != null && businessPager.trim().length() > 0) { subelement = vCard.addElement("TEL"); subelement.addElement("WORK"); subelement.addElement("PAGER"); subelement.addElement("NUMBER").setText(businessPager.trim()); } // Add job title if (businessJobTitle != null && businessJobTitle.trim().length() > 0) { vCard.addElement("TITLE").setText(businessJobTitle.trim()); } // Add job department if (businessDepartment != null && businessDepartment.trim().length() > 0) { vCard.addElement("ORG").addElement("ORGUNIT").setText(businessDepartment.trim()); } // Generate content to store in property String vcardXML; StringWriter writer = new StringWriter(); OutputFormat prettyPrinter = OutputFormat.createPrettyPrint(); XMLWriter xmlWriter = new XMLWriter(writer, prettyPrinter); try { xmlWriter.write(vCard); vcardXML = writer.toString(); } catch (IOException e) { Log.error("Error pretty formating XML", e); vcardXML = vCard.asXML(); } StringBuilder sb = new StringBuilder(vcardXML.length()); sb.append("<![CDATA[").append(vcardXML).append("]]>"); // Save mapping as an XML property JiveGlobals.setProperty("ldap.vcard-mapping", sb.toString()); // Set that the vcard provider is LdapVCardProvider JiveGlobals.setProperty("provider.vcard.className", LdapVCardProvider.class.getName()); // Save duplicated fields in LdapManager (should be removed in the future) LdapManager.getInstance().setNameField(name.replaceAll("(\\{)([\\d\\D&&[^}]]+)(})", "$2")); LdapManager.getInstance().setEmailField(email.replaceAll("(\\{)([\\d\\D&&[^}]]+)(})", "$2")); // Store the DB storage variable in the actual database. JiveGlobals.setProperty("ldap.override.avatar", avatarStoredInDB.toString()); }
From source file:org.jivesoftware.openfire.commands.AdHocCommandManager.java
License:Open Source License
/** * Stores in the SessionData the fields and their values as specified in the completed * data form by the user./*from w w w .ja va 2 s . c o m*/ * * @param iqCommand the command element containing the data form element. * @param session the SessionData for this command execution. */ private void saveCompletedForm(Element iqCommand, SessionData session) { Element formElement = iqCommand.element(QName.get("x", "jabber:x:data")); if (formElement != null) { // Generate a Map with the variable names and variables values Map<String, List<String>> data = new HashMap<String, List<String>>(); DataForm dataForm = new DataForm(formElement); for (FormField field : dataForm.getFields()) { data.put(field.getVariable(), field.getValues()); } // Store the variables and their values in the session data session.addStageForm(data); } }
From source file:org.jivesoftware.openfire.disco.IQDiscoItemsHandler.java
License:Open Source License
@Override public IQ handleIQ(IQ packet) { // Create a copy of the sent pack that will be used as the reply // we only need to add the requested items to the reply if any otherwise add // a not found error IQ reply = IQ.createResultIQ(packet); // TODO Implement publishing client items if (IQ.Type.set == packet.getType()) { reply.setChildElement(packet.getChildElement().createCopy()); reply.setError(PacketError.Condition.feature_not_implemented); return reply; }/*www .j a va 2 s . co m*/ // Look for a DiscoItemsProvider associated with the requested entity. // We consider the host of the recipient JID of the packet as the entity. It's the // DiscoItemsProvider responsibility to provide the items associated with the JID's name // together with any possible requested node. DiscoItemsProvider itemsProvider = getProvider( packet.getTo() == null ? XMPPServer.getInstance().getServerInfo().getXMPPDomain() : packet.getTo().getDomain()); if (itemsProvider != null) { // Get the JID's name String name = packet.getTo() == null ? null : packet.getTo().getNode(); if (name == null || name.trim().length() == 0) { name = null; } // Get the requested node Element iq = packet.getChildElement(); String node = iq.attributeValue("node"); // Check if we have items associated with the requested name and node Iterator<DiscoItem> itemsItr = itemsProvider.getItems(name, node, packet.getFrom()); if (itemsItr != null) { reply.setChildElement(iq.createCopy()); Element queryElement = reply.getChildElement(); // See if the requesting entity would like to apply 'result set // management' final Element rsmElement = packet.getChildElement() .element(QName.get("set", ResultSet.NAMESPACE_RESULT_SET_MANAGEMENT)); // apply RSM only if the element exists, and the (total) results // set is not empty. final boolean applyRSM = rsmElement != null && itemsItr.hasNext(); if (applyRSM) { if (!ResultSet.isValidRSMRequest(rsmElement)) { reply.setError(PacketError.Condition.bad_request); return reply; } // Calculate which results to include. final List<DiscoItem> rsmResults; final List<DiscoItem> allItems = new ArrayList<DiscoItem>(); while (itemsItr.hasNext()) { allItems.add(itemsItr.next()); } final ResultSet<DiscoItem> rs = new ResultSetImpl<DiscoItem>(allItems); try { rsmResults = rs.applyRSMDirectives(rsmElement); } catch (NullPointerException e) { final IQ itemNotFound = IQ.createResultIQ(packet); itemNotFound.setError(PacketError.Condition.item_not_found); return itemNotFound; } // add the applicable results to the IQ-result for (DiscoItem item : rsmResults) { final Element resultElement = item.getElement(); resultElement.setQName(new QName(resultElement.getName(), queryElement.getNamespace())); queryElement.add(resultElement.createCopy()); } // overwrite the 'set' element. queryElement.remove( queryElement.element(QName.get("set", ResultSet.NAMESPACE_RESULT_SET_MANAGEMENT))); queryElement.add(rs.generateSetElementFromResults(rsmResults)); } else { // don't apply RSM: // Add to the reply all the items provided by the DiscoItemsProvider Element item; while (itemsItr.hasNext()) { item = itemsItr.next().getElement(); item.setQName(new QName(item.getName(), queryElement.getNamespace())); queryElement.add(item.createCopy()); } } } else { // If the DiscoItemsProvider has no items for the requested name and node // then answer a not found error reply.setChildElement(packet.getChildElement().createCopy()); reply.setError(PacketError.Condition.item_not_found); } } else { // If we didn't find a DiscoItemsProvider then answer a not found error reply.setChildElement(packet.getChildElement().createCopy()); reply.setError(PacketError.Condition.item_not_found); } return reply; }
From source file:org.jivesoftware.openfire.entitycaps.EntityCapabilitiesManager.java
License:Open Source License
/** * Extracts a list of extended service discovery information from an IQ * packet./*from ww w . ja va2s. c o m*/ * * @param packet * the packet * @return a list of extended service discoverin information features. */ private static List<String> getExtendedDataForms(IQ packet) { List<String> results = new ArrayList<String>(); Element query = packet.getChildElement(); Iterator<Element> extensionIterator = query.elementIterator(QName.get("x", "jabber:x:data")); if (extensionIterator != null) { while (extensionIterator.hasNext()) { Element extensionElement = extensionIterator.next(); final StringBuilder formType = new StringBuilder(); Iterator<Element> fieldIterator = extensionElement.elementIterator("field"); List<String> vars = new ArrayList<String>(); while (fieldIterator != null && fieldIterator.hasNext()) { final Element fieldElement = fieldIterator.next(); if (fieldElement.attributeValue("var").equals("FORM_TYPE")) { formType.append(fieldElement.element("value").getText()); formType.append('<'); } else { final StringBuilder var = new StringBuilder(); var.append(fieldElement.attributeValue("var")); var.append('<'); Iterator<Element> valIter = fieldElement.elementIterator("value"); List<String> values = new ArrayList<String>(); while (valIter != null && valIter.hasNext()) { Element value = valIter.next(); values.add(value.getText()); } Collections.sort(values); for (String v : values) { var.append(v); var.append('<'); } vars.add(var.toString()); } } Collections.sort(vars); for (String v : vars) { formType.append(v); } results.add(formType.toString()); } } return results; }
From source file:org.jivesoftware.openfire.forms.spi.XDataFormImpl.java
License:Open Source License
public Element asXMLElement() { Element x = DocumentHelper.createElement(QName.get("x", "jabber:x:data")); if (getType() != null) { x.addAttribute("type", getType()); }//w w w . ja v a 2s . co m if (getTitle() != null) { x.addElement("title").addText(getTitle()); } if (instructions.size() > 0) { Iterator instrItr = getInstructions(); while (instrItr.hasNext()) { x.addElement("instructions").addText((String) instrItr.next()); } } // Append the list of fields returned from a search if (reportedFields.size() > 0) { Element reportedElement = x.addElement("reported"); Iterator fieldsItr = reportedFields.iterator(); while (fieldsItr.hasNext()) { XFormFieldImpl field = (XFormFieldImpl) fieldsItr.next(); reportedElement.add(field.asXMLElement()); } } // Append the list of items returned from a search // Note: each item contains a List of XFormFieldImpls if (reportedItems.size() > 0) { Iterator itemsItr = reportedItems.iterator(); while (itemsItr.hasNext()) { // Add a new item element for this list of fields Element itemElement = x.addElement("item"); List fields = (List) itemsItr.next(); Iterator fieldsItr = fields.iterator(); // Iterate on the fields and add them to the new item while (fieldsItr.hasNext()) { XFormFieldImpl field = (XFormFieldImpl) fieldsItr.next(); itemElement.add(field.asXMLElement()); } } } if (fields.size() > 0) { Iterator fieldsItr = getFields(); while (fieldsItr.hasNext()) { XFormFieldImpl field = (XFormFieldImpl) fieldsItr.next(); x.add(field.asXMLElement()); } } return x; }
From source file:org.jivesoftware.openfire.forms.spi.XFormFieldImpl.java
License:Open Source License
public Element asXMLElement() { Element field = DocumentHelper.createElement(QName.get("field", "jabber:x:data")); if (getLabel() != null) { field.addAttribute("label", getLabel()); }//from ww w. j ava2 s. c o m if (getVariable() != null) { field.addAttribute("var", getVariable()); } if (getType() != null) { field.addAttribute("type", getType()); } if (getDescription() != null) { field.addElement("desc").addText(getDescription()); } if (isRequired()) { field.addElement("required"); } // Loop through all the values and append them to the stream writer if (values.size() > 0) { Iterator<String> valuesItr = getValues(); while (valuesItr.hasNext()) { field.addElement("value").addText(valuesItr.next()); } } // Loop through all the options and append them to the stream writer if (options.size() > 0) { Iterator<Option> optionsItr = getOptions(); while (optionsItr.hasNext()) { field.add((optionsItr.next()).asXMLElement()); } } // Loop through all the values and append them to the stream writer /*Iterator frags = fragments.iterator(); while (frags.hasNext()){ XMPPFragment frag = (XMPPFragment) frags.next(); frag.send(xmlSerializer,version); }*/ return field; }