List of usage examples for org.dom4j Attribute getValue
String getValue();
From source file:org.jivesoftware.openfire.clearspace.ClearspaceMUCEventDelegate.java
License:Open Source License
@Override public Map<String, String> getRoomConfig(String roomName) { Map<String, String> roomConfig = new HashMap<String, String>(); IQ iq = new IQ(IQ.Type.get); iq.setFrom(csMucDomain);// www . j a va2 s . c om iq.setID("get_room_config_" + StringUtils.randomString(3)); Element child = iq.setChildElement("get-room-config", "http://jivesoftware.com/clearspace"); Element roomjidElement = child.addElement("roomjid"); JID roomJid = new JID(roomName + "@" + csMucDomain); roomjidElement.setText(roomJid.toBareJID()); IQ result = ClearspaceManager.getInstance().query(iq, 15000); if (result == null) { // No answer was received from Clearspace, so return null. Log.warn(GET_ROOM_CONFIG_WARNING + " Room: " + roomJid.toBareJID()); return null; } else if (result.getType() != IQ.Type.result) { // The reply was not a valid result containing the room configuration, so return null. Log.warn(GET_ROOM_CONFIG_WARNING + " Room: " + roomJid.toBareJID()); return null; } // Setup room configuration based on the configuration values in the result packet. Element query = result.getChildElement(); if (query == null) { Log.warn(GET_ROOM_CONFIG_WARNING + " Room: " + roomJid.toBareJID()); return null; } Element xElement = query.element("x"); if (xElement == null) { Log.warn(GET_ROOM_CONFIG_WARNING + " Room: " + roomJid.toBareJID()); return null; } @SuppressWarnings("unchecked") Iterator<Element> fields = xElement.elementIterator("field"); while (fields.hasNext()) { Element field = fields.next(); Attribute varAttribute = field.attribute("var"); if (varAttribute != null) { Element value = field.element("value"); if (value != null) { roomConfig.put(varAttribute.getValue(), value.getText()); } } } String ownerJid = roomJid.getNode() + "@" + csComponentAddress; roomConfig.put("muc#roomconfig_roomowners", ownerJid); return roomConfig; }
From source file:org.jivesoftware.openfire.container.PluginManager.java
License:Open Source License
/** * Loads a plug-in module into the container. Loading consists of the * following steps:<ul>/*w ww . ja va 2 s. c o m*/ * <p/> * <li>Add all jars in the <tt>lib</tt> dir (if it exists) to the class loader</li> * <li>Add all files in <tt>classes</tt> dir (if it exists) to the class loader</li> * <li>Locate and load <tt>module.xml</tt> into the context</li> * <li>For each jive.module entry, load the given class as a module and start it</li> * <p/> * </ul> * * @param pluginDir the plugin directory. */ private void loadPlugin(File pluginDir) { // Only load the admin plugin during setup mode. if (XMPPServer.getInstance().isSetupMode() && !(pluginDir.getName().equals("admin"))) { return; } Log.debug("PluginManager: Loading plugin " + pluginDir.getName()); Plugin plugin; try { File pluginConfig = new File(pluginDir, "plugin.xml"); if (pluginConfig.exists()) { SAXReader saxReader = new SAXReader(); saxReader.setEncoding("UTF-8"); Document pluginXML = saxReader.read(pluginConfig); // See if the plugin specifies a version of Openfire // required to run. Element minServerVersion = (Element) pluginXML.selectSingleNode("/plugin/minServerVersion"); if (minServerVersion != null) { Version requiredVersion = new Version(minServerVersion.getTextTrim()); Version currentVersion = XMPPServer.getInstance().getServerInfo().getVersion(); if (requiredVersion.isNewerThan(currentVersion)) { String msg = "Ignoring plugin " + pluginDir.getName() + ": requires " + "server version " + requiredVersion; Log.warn(msg); System.out.println(msg); return; } } PluginClassLoader pluginLoader; // Check to see if this is a child plugin of another plugin. If it is, we // re-use the parent plugin's class loader so that the plugins can interact. Element parentPluginNode = (Element) pluginXML.selectSingleNode("/plugin/parentPlugin"); String pluginName = pluginDir.getName(); String webRootKey = pluginName + ".webRoot"; String classesDirKey = pluginName + ".classes"; String webRoot = System.getProperty(webRootKey); String classesDir = System.getProperty(classesDirKey); if (webRoot != null) { final File compilationClassesDir = new File(pluginDir, "classes"); if (!compilationClassesDir.exists()) { compilationClassesDir.mkdir(); } compilationClassesDir.deleteOnExit(); } if (parentPluginNode != null) { String parentPlugin = parentPluginNode.getTextTrim(); // See if the parent is already loaded. if (plugins.containsKey(parentPlugin)) { pluginLoader = classloaders.get(getPlugin(parentPlugin)); pluginLoader.addDirectory(pluginDir, classesDir != null); } else { // See if the parent plugin exists but just hasn't been loaded yet. // This can only be the case if this plugin name is alphabetically before // the parent. if (pluginName.compareTo(parentPlugin) < 0) { // See if the parent exists. File file = new File(pluginDir.getParentFile(), parentPlugin + ".jar"); if (file.exists()) { // Silently return. The child plugin will get loaded up on the next // plugin load run after the parent. return; } else { file = new File(pluginDir.getParentFile(), parentPlugin + ".war"); if (file.exists()) { // Silently return. The child plugin will get loaded up on the next // plugin load run after the parent. return; } else { String msg = "Ignoring plugin " + pluginName + ": parent plugin " + parentPlugin + " not present."; Log.warn(msg); System.out.println(msg); return; } } } else { String msg = "Ignoring plugin " + pluginName + ": parent plugin " + parentPlugin + " not present."; Log.warn(msg); System.out.println(msg); return; } } } // This is not a child plugin, so create a new class loader. else { pluginLoader = new PluginClassLoader(); pluginLoader.addDirectory(pluginDir, classesDir != null); } // Check to see if development mode is turned on for the plugin. If it is, // configure dev mode. PluginDevEnvironment dev = null; if (webRoot != null || classesDir != null) { dev = new PluginDevEnvironment(); System.out.println("Plugin " + pluginName + " is running in development mode."); Log.info("Plugin " + pluginName + " is running in development mode."); if (webRoot != null) { File webRootDir = new File(webRoot); if (!webRootDir.exists()) { // Ok, let's try it relative from this plugin dir? webRootDir = new File(pluginDir, webRoot); } if (webRootDir.exists()) { dev.setWebRoot(webRootDir); } } if (classesDir != null) { File classes = new File(classesDir); if (!classes.exists()) { // ok, let's try it relative from this plugin dir? classes = new File(pluginDir, classesDir); } if (classes.exists()) { dev.setClassesDir(classes); pluginLoader.addURLFile(classes.getAbsoluteFile().toURI().toURL()); } } } String className = pluginXML.selectSingleNode("/plugin/class").getText().trim(); plugin = (Plugin) pluginLoader.loadClass(className).newInstance(); if (parentPluginNode != null) { String parentPlugin = parentPluginNode.getTextTrim(); // See if the parent is already loaded. if (plugins.containsKey(parentPlugin)) { pluginLoader = classloaders.get(getPlugin(parentPlugin)); classloaders.put(plugin, pluginLoader); } } plugins.put(pluginName, plugin); pluginDirs.put(plugin, pluginDir); // If this is a child plugin, register it as such. if (parentPluginNode != null) { String parentPlugin = parentPluginNode.getTextTrim(); List<String> childrenPlugins = parentPluginMap.get(plugins.get(parentPlugin)); if (childrenPlugins == null) { childrenPlugins = new ArrayList<String>(); parentPluginMap.put(plugins.get(parentPlugin), childrenPlugins); } childrenPlugins.add(pluginName); // Also register child to parent relationship. childPluginMap.put(plugin, parentPlugin); } else { // Only register the class loader in the case of this not being // a child plugin. classloaders.put(plugin, pluginLoader); } // Check the plugin's database schema (if it requires one). if (!DbConnectionManager.getSchemaManager().checkPluginSchema(plugin)) { // The schema was not there and auto-upgrade failed. Log.error(pluginName + " - " + LocaleUtils.getLocalizedString("upgrade.database.failure")); System.out.println( pluginName + " - " + LocaleUtils.getLocalizedString("upgrade.database.failure")); } // Load any JSP's defined by the plugin. File webXML = new File(pluginDir, "web" + File.separator + "WEB-INF" + File.separator + "web.xml"); if (webXML.exists()) { PluginServlet.registerServlets(this, plugin, webXML); } // Load any custom-defined servlets. File customWebXML = new File(pluginDir, "web" + File.separator + "WEB-INF" + File.separator + "web-custom.xml"); if (customWebXML.exists()) { PluginServlet.registerServlets(this, plugin, customWebXML); } if (dev != null) { pluginDevelopment.put(plugin, dev); } // Configure caches of the plugin configureCaches(pluginDir, pluginName); // Init the plugin. ClassLoader oldLoader = Thread.currentThread().getContextClassLoader(); Thread.currentThread().setContextClassLoader(pluginLoader); plugin.initializePlugin(this, pluginDir); Thread.currentThread().setContextClassLoader(oldLoader); // If there a <adminconsole> section defined, register it. Element adminElement = (Element) pluginXML.selectSingleNode("/plugin/adminconsole"); if (adminElement != null) { Element appName = (Element) adminElement .selectSingleNode("/plugin/adminconsole/global/appname"); if (appName != null) { // Set the plugin name so that the proper i18n String can be loaded. appName.addAttribute("plugin", pluginName); } // If global images are specified, override their URL. Element imageEl = (Element) adminElement .selectSingleNode("/plugin/adminconsole/global/logo-image"); if (imageEl != null) { imageEl.setText("plugins/" + pluginName + "/" + imageEl.getText()); // Set the plugin name so that the proper i18n String can be loaded. imageEl.addAttribute("plugin", pluginName); } imageEl = (Element) adminElement.selectSingleNode("/plugin/adminconsole/global/login-image"); if (imageEl != null) { imageEl.setText("plugins/" + pluginName + "/" + imageEl.getText()); // Set the plugin name so that the proper i18n String can be loaded. imageEl.addAttribute("plugin", pluginName); } // Modify all the URL's in the XML so that they are passed through // the plugin servlet correctly. List urls = adminElement.selectNodes("//@url"); for (Object url : urls) { Attribute attr = (Attribute) url; attr.setValue("plugins/" + pluginName + "/" + attr.getValue()); } // In order to internationalize the names and descriptions in the model, // we add a "plugin" attribute to each tab, sidebar, and item so that // the the renderer knows where to load the i18n Strings from. String[] elementNames = new String[] { "tab", "sidebar", "item" }; for (String elementName : elementNames) { List values = adminElement.selectNodes("//" + elementName); for (Object value : values) { Element element = (Element) value; // Make sure there's a name or description. Otherwise, no need to // override i18n settings. if (element.attribute("name") != null || element.attribute("value") != null) { element.addAttribute("plugin", pluginName); } } } AdminConsole.addModel(pluginName, adminElement); } firePluginCreatedEvent(pluginName, plugin); } else { Log.warn("Plugin " + pluginDir + " could not be loaded: no plugin.xml file found"); } } catch (Throwable e) { Log.error("Error loading plugin: " + pluginDir, e); } }
From source file:org.jivesoftware.openfire.handler.IQRosterHandler.java
License:Open Source License
/** * The packet is a typical 'set' or 'get' update targeted at the server. * Notice that the set could be a roster removal in which case we have to * generate a local roster removal update as well as a new roster removal * to send to the the roster item's owner. * * @param packet The packet that triggered this update * @return Either a response to the roster update or null if the packet is corrupt and the session was closed down *///from w w w . ja va 2s . co m private IQ manageRoster(org.xmpp.packet.Roster packet) throws UnauthorizedException, UserAlreadyExistsException, SharedGroupException { IQ returnPacket = null; JID sender = packet.getFrom(); IQ.Type type = packet.getType(); try { if ((sender.getNode() == null || !RosterManager.isRosterServiceEnabled() || !userManager.isRegisteredUser(sender.getNode())) && IQ.Type.get == type) { // If anonymous user asks for his roster or roster service is disabled then // return an empty roster IQ reply = IQ.createResultIQ(packet); reply.setChildElement("query", "jabber:iq:roster"); return reply; } if (!localServer.isLocal(sender)) { // Sender belongs to a remote server so discard this IQ request Log.warn("Discarding IQ roster packet of remote user: " + packet); return null; } Roster cachedRoster = userManager.getUser(sender.getNode()).getRoster(); if (IQ.Type.get == type) { Element query = packet.getChildElement(); long version = -1; if (query != null) { Attribute attribute = query.attribute("ver"); if (attribute != null) { version = 0; String v = attribute.getValue(); try { version = Long.parseLong(v); } catch (Exception e) { } } } returnPacket = cachedRoster.getReset(version); returnPacket.setType(IQ.Type.result); returnPacket.setTo(sender); returnPacket.setID(packet.getID()); // Force delivery of the response because we need to trigger // a presence probe from all contacts deliverer.deliver(returnPacket); returnPacket = null; } else if (IQ.Type.set == type) { for (org.xmpp.packet.Roster.Item item : packet.getItems()) { if (item.getSubscription() == org.xmpp.packet.Roster.Subscription.remove) { removeItem(cachedRoster, packet.getFrom(), item); } else { if (cachedRoster.isRosterItem(item.getJID())) { // existing item RosterItem cachedItem = cachedRoster.getRosterItem(item.getJID()); cachedItem.setAsCopyOf(item); cachedRoster.updateRosterItem(cachedItem); } else { // new item cachedRoster.createRosterItem(item); } } } returnPacket = IQ.createResultIQ(packet); } } catch (UserNotFoundException e) { throw new UnauthorizedException(e); } return returnPacket; }
From source file:org.jivesoftware.openfire.mediaproxy.MediaProxyService.java
License:Open Source License
private void processIQ(IQ iq) { IQ reply = IQ.createResultIQ(iq);//from www.ja v a 2 s .co m Element childElement = iq.getChildElement(); String namespace = childElement.getNamespaceURI(); Element childElementCopy = iq.getChildElement().createCopy(); reply.setChildElement(childElementCopy); if ("http://jabber.org/protocol/disco#info".equals(namespace)) { reply = XMPPServer.getInstance().getIQDiscoInfoHandler().handleIQ(iq); router.route(reply); return; } else if ("http://jabber.org/protocol/disco#items".equals(namespace)) { // a component reply = XMPPServer.getInstance().getIQDiscoItemsHandler().handleIQ(iq); router.route(reply); return; } else if (NAMESPACE.equals(namespace) && enabled) { Element candidateElement = childElementCopy.element("candidate"); String sid = childElementCopy.attribute("sid").getValue() + "-" + iq.getFrom(); if (candidateElement != null) { childElementCopy.remove(candidateElement); Element candidate = childElementCopy.addElement("candidate "); ProxyCandidate proxyCandidate = mediaProxy.addRelayAgent(sid, iq.getFrom().toString()); Log.debug("MediaProxyService: " + sid); proxyCandidate.start(); candidate.addAttribute("name", "voicechannel"); candidate.addAttribute("ip", mediaProxy.getPublicIP()); candidate.addAttribute("porta", String.valueOf(proxyCandidate.getLocalPortA())); candidate.addAttribute("portb", String.valueOf(proxyCandidate.getLocalPortB())); candidate.addAttribute("pass", proxyCandidate.getPass()); } else { candidateElement = childElementCopy.element("relay"); if (candidateElement != null) { MediaProxySession session = mediaProxy.getSession(sid); Log.debug("MediaProxyService: " + sid); if (session != null) { Attribute pass = candidateElement.attribute("pass"); if (pass != null && pass.getValue().trim().equals(session.getPass().trim())) { Attribute portA = candidateElement.attribute("porta"); Attribute portB = candidateElement.attribute("portb"); Attribute hostA = candidateElement.attribute("hosta"); Attribute hostB = candidateElement.attribute("hostb"); try { if (hostA != null && portA != null) { for (int i = 0; i < 2; i++) { session.sendFromPortA(hostB.getValue(), Integer.parseInt(portB.getValue())); } } } catch (Exception e) { Log.error(e.getMessage(), e); } } else { reply.setError(PacketError.Condition.forbidden); } } childElementCopy.remove(candidateElement); } else { candidateElement = childElementCopy.element("publicip"); if (candidateElement != null) { childElementCopy.remove(candidateElement); Element publicIp = childElementCopy.addElement("publicip"); try { String ip = sessionManager.getSession(iq.getFrom()).getHostAddress(); if (ip != null) { publicIp.addAttribute("ip", ip); } } catch (UnknownHostException e) { Log.error(e.getMessage(), e); } } else { childElementCopy.remove(candidateElement); reply.setError(PacketError.Condition.forbidden); } } } } else { // Answer an error since the server can't handle the requested namespace reply.setError(PacketError.Condition.service_unavailable); } try { if (Log.isDebugEnabled()) { Log.debug("MediaProxyService: RETURNED:" + reply.toXML()); } router.route(reply); } catch (Exception e) { Log.error(e.getMessage(), e); } }
From source file:org.jivesoftware.openfire.plugin.Xep227Exporter.java
License:Apache License
/** * Adding offline messages, if there are some. * /*from ww w.j a va 2 s. c om*/ * @param hostname * host name * @param userElement * DOM element * @param userName * user name */ @SuppressWarnings("unchecked") private void exportOfflineMessages(String hostname, Element userElement, String userName) { Collection<OfflineMessage> offlineMessages = offlineMessagesStore.getMessages(userName, false); if (!offlineMessages.isEmpty()) { Element offlineElement = userElement.addElement(OFFLINE_MESSAGES_ELEMENT_NAME); for (OfflineMessage offMessage : offlineMessages) { Element messageElement = offlineElement.addElement(new QName(MESSAGE_ELEMENT_NAME, JABBER_MSG_NS)); for (Object att : offMessage.getElement().attributes()) { Attribute attribute = (Attribute) att; messageElement.addAttribute(attribute.getQName(), attribute.getValue()); } for (Iterator<Element> iterator = offMessage.getElement().elementIterator(); iterator.hasNext();) { Element element = iterator.next(); messageElement.add(element.createCopy(new QName(element.getName(), (element.getNamespace() == Namespace.NO_NAMESPACE ? JABBER_MSG_NS : element.getNamespace())))); } /** * Adding delay element */ Element delayElement = messageElement.addElement("delay", "urn:xmpp:delay"); delayElement.addAttribute(FROM_NAME, hostname); delayElement.addAttribute("stamp", XMPPDateTimeFormat.format(offMessage.getCreationDate())); delayElement.addText("Offline Storage"); } } }
From source file:org.jogre.server.ServerProperties.java
License:Open Source License
/** * Return a list of connection ID's./*from w w w . ja v a2 s . com*/ * * @return */ public Vector getConnectionIDs() { List list = doc.selectNodes("server_properties/server_data/database/connection/@id"); Vector v = new Vector(); for (int i = 0; i < list.size(); i++) { Attribute att = (Attribute) list.get(i); v.add(att.getValue()); } return v; }
From source file:org.lushlife.guicexml.internal.xml.ComponentXmlReader.java
License:Apache License
public static Map<String, PropertyValue> createAttributeMap(Element element, PropertyManagement xmlManagement) { Map<String, PropertyValue> attribute = new HashMap<String, PropertyValue>(); for (Object obj : element.attributes()) { Attribute attr = (Attribute) obj; if (attr.getName().equals("name")) { continue; }//from w w w .j av a 2 s. c om if (attr.getName().equals("id")) { continue; } if (attr.getName().equals("qualifier")) { continue; } if (attr.getName().equals("class")) { continue; } if (attr.getName().equals("types")) { continue; } if (attr.getName().equals("scope")) { continue; } if (attr.getName().equals("startup")) { continue; } if (attr.getName().equals("constructor-parameter-types")) { continue; } if (attr.getName().equals("factory-method")) { continue; } if (attr.getName().equals("args")) { continue; } attribute.put(attr.getName(), xmlManagement.toPropertyValue(attr.getValue())); } for (Object obj : element.elements()) { Element ele = (Element) obj; if (ele.getName().equals("property")) { String stringValue = ele.attributeValue("value"); String k = ele.attributeValue("name"); PropertyValue v = (stringValue != null) ? xmlManagement.toPropertyValue(stringValue) : xmlManagement.toPropertyValue(ele); attribute.put(k, v); } else { String k = ele.getName(); PropertyValue v = xmlManagement.toPropertyValue(ele); attribute.put(k, v); } } return attribute; }
From source file:org.metaeffekt.dita.maven.glossary.GlossaryMapCreator.java
License:Apache License
private void scan(File file, Set<String> processed) throws DocumentException, IOException { if (!processed.contains(file.getCanonicalPath())) { Document document = readDocument(file); if (document != null) { processed.add(file.getCanonicalPath()); @SuppressWarnings("unchecked") List<Attribute> elements = document.selectNodes("//@href|//@conref"); for (Attribute element : elements) { String href = element.getValue(); final int hashIndex = href.indexOf("#"); if (hashIndex != -1) { href = href.substring(0, hashIndex); }//from w w w . j a v a 2 s. c o m File child = new File(file.getParent(), href); if (child.exists() && !processed.contains(child.getCanonicalPath())) { scan(child, processed); } } } } }
From source file:org.metaeffekt.dita.maven.glossary.GlossaryMapCreator.java
License:Apache License
private void extractCoveredKeys(File file, Set<String> coveredKeys) { Document document = readDocument(file); if (document != null) { @SuppressWarnings("unchecked") List<Attribute> elements = document.selectNodes("//@keys"); for (Attribute element : elements) { String keys = element.getValue(); String[] keyArray = keys.split(" "); for (String key : keyArray) { coveredKeys.add(key);//from w w w . j a v a 2s. c o m } } } }
From source file:org.mule.intents.AppBuilder.java
License:Open Source License
protected void addSchemaLocations(Document snippet) { Attribute att = snippet.getRootElement().attribute(xsiQN); if (att == null) { return;//from w ww . j a v a2 s .c o m } Attribute existing = config.getRootElement().attribute(xsiQN); if (existing == null) { config.getRootElement().addAttribute(xsiQN, ""); existing = config.getRootElement().attribute(xsiQN); } //save schemaLocations for (StringTokenizer tokenizer = new StringTokenizer(att.getValue(), " "); tokenizer.hasMoreTokens();) { String x = tokenizer.nextToken(); String y = tokenizer.nextToken(); schemaLocations.put(x, y); } StringBuilder buf = new StringBuilder(); for (String s : schemaLocations.keySet()) { buf.append(s).append(" ").append(schemaLocations.get(s)).append("\n"); } existing.setValue(buf.toString()); System.out.println("xsi:schemaLocation = " + existing.getValue()); }