List of usage examples for org.dom4j Element getTextTrim
String getTextTrim();
From source file:org.b5chat.crossfire.core.plugin.PluginManager.java
License:Open Source License
/** * Loads a plug-in module into the container. Loading consists of the * following steps:<ul>/* w w w. jav a 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 b5chat.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()); IPlugin 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 crossfire // required to run. Element minServerVersion = (Element) pluginXML.selectSingleNode("/plugin/minServerVersion"); if (minServerVersion != null) { String requiredVersion = minServerVersion.getTextTrim(); Version version = XmppServer.getInstance().getServerInfo().getVersion(); String hasVersion = version.getMajor() + "." + version.getMinor() + "." + version.getMicro(); if (hasVersion.compareTo(requiredVersion) < 0) { 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("IPlugin " + pluginName + " is running in development mode."); Log.info("IPlugin " + 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 = (IPlugin) 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. @SuppressWarnings("unchecked") List<Object> 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) { @SuppressWarnings("unchecked") List<Object> 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("IPlugin " + pluginDir + " could not be loaded: no plugin.xml file found"); } } catch (Throwable e) { Log.error("Error loading plugin: " + pluginDir, e); } }
From source file:org.b5chat.crossfire.core.plugin.PluginManager.java
License:Open Source License
/** * Returns the value of an element selected via an xpath expression from * a IPlugin's plugin.xml file.// ww w . j ava2s . c o m * * @param plugin the plugin. * @param xpath the xpath expression. * @return the value of the element selected by the xpath expression. */ private String getElementValue(IPlugin plugin, String xpath) { File pluginDir = pluginDirs.get(plugin); if (pluginDir == null) { return null; } try { File pluginConfig = new File(pluginDir, "plugin.xml"); if (pluginConfig.exists()) { SAXReader saxReader = new SAXReader(); saxReader.setEncoding("UTF-8"); Document pluginXML = saxReader.read(pluginConfig); Element element = (Element) pluginXML.selectSingleNode(xpath); if (element != null) { return element.getTextTrim(); } } } catch (Exception e) { Log.error(e.getMessage(), e); } return null; }
From source file:org.buddycloud.pusher.handler.PasswordResetQueryHandler.java
License:Apache License
@SuppressWarnings("unchecked") @Override//from w ww. ja v a 2 s.c om protected IQ handleQuery(IQ iq) { Element queryElement = iq.getElement().element("query"); Element usernameEl = queryElement.element("username"); String username = usernameEl.getTextTrim(); String[] splitUsername = username.split("@"); String domain = splitUsername[1]; IQ issueCommandIq = new IQ(); issueCommandIq.setTo(domain); issueCommandIq.setFrom(iq.getTo()); issueCommandIq.setType(org.xmpp.packet.IQ.Type.set); Element issueCommandEl = issueCommandIq.getElement().addElement("command", "http://jabber.org/protocol/commands"); issueCommandEl.addAttribute("action", "execute"); issueCommandEl.addAttribute("node", "http://jabber.org/protocol/admin#change-user-password"); IQ changeCommandIq = xmppComponent.syncIQ(issueCommandIq); if (changeCommandIq.getError() != null) { return createResponse(iq, changeCommandIq); } String randomPassword = RandomStringUtils.randomAlphanumeric(8); changeCommandIq.setType(Type.set); changeCommandIq.setTo(domain); changeCommandIq.setFrom(iq.getTo()); Element xEl = changeCommandIq.getElement().element("command").element("x"); List<Element> fields = xEl.elements("field"); for (Element field : fields) { String var = field.attributeValue("var"); if (var.equals("accountjid")) { field.addElement("value").setText(username); } else if (var.equals("password")) { field.addElement("value").setText(randomPassword); } } IQ changeCommandReplyIq = xmppComponent.syncIQ(changeCommandIq); if (changeCommandReplyIq.getError() == null) { List<NotificationSettings> emailNotificationSettings = NotificationUtils .getNotificationSettingsByType(username, "email", getDataSource()); for (NotificationSettings notificationSettings : emailNotificationSettings) { String emailAddress = notificationSettings.getTarget(); Map<String, String> tokens = new HashMap<String, String>(); tokens.put("NEW_PASSWORD", randomPassword); tokens.put("EMAIL", emailAddress); tokens.put("USER_JID", username); Pushers.getInstance(getProperties()).get(EmailPusher.TYPE).push(emailAddress, Event.PASSWORD_RESET, tokens); } } return createResponse(iq, changeCommandReplyIq); }
From source file:org.codehaus.aspectwerkz.definition.DocumentParser.java
License:Open Source License
/** * Parses the global pointcuts./*from w w w. j a va 2 s .com*/ * * @param systemElement the system element * @return a list with the pointcuts */ private static List parseGlobalPointcutDefs(final Element systemElement) { final List globalPointcuts = new ArrayList(); for (Iterator it11 = systemElement.elementIterator("pointcut"); it11.hasNext();) { PointcutInfo pointcutInfo = new PointcutInfo(); Element globalPointcut = (Element) it11.next(); for (Iterator it2 = globalPointcut.attributeIterator(); it2.hasNext();) { Attribute attribute = (Attribute) it2.next(); final String name = attribute.getName().trim(); final String value = attribute.getValue().trim(); if (name.equalsIgnoreCase("name")) { pointcutInfo.name = value; } else if (name.equalsIgnoreCase("expression")) { pointcutInfo.expression = value; } } // pointcut CDATA is expression unless already specified as an attribute if (pointcutInfo.expression == null) { pointcutInfo.expression = globalPointcut.getTextTrim(); } globalPointcuts.add(pointcutInfo); } return globalPointcuts; }
From source file:org.codehaus.aspectwerkz.definition.DocumentParser.java
License:Open Source License
/** * Parses the global deployment-scope elements. * * @param systemElement the system element * @param definition/*from w w w. jav a 2s. c o m*/ */ private static void parseDeploymentScopeDefs(final Element systemElement, final SystemDefinition definition) { for (Iterator it11 = systemElement.elementIterator("deployment-scope"); it11.hasNext();) { String expression = null; String name = null; Element globalPointcut = (Element) it11.next(); for (Iterator it2 = globalPointcut.attributeIterator(); it2.hasNext();) { Attribute attribute = (Attribute) it2.next(); final String attrName = attribute.getName().trim(); final String attrValue = attribute.getValue().trim(); if (attrName.equalsIgnoreCase("name")) { name = attrValue; } else if (attrName.equalsIgnoreCase("expression")) { expression = attrValue; } } // pointcut CDATA is expression unless already specified as an attribute if (expression == null) { expression = globalPointcut.getTextTrim(); } DefinitionParserHelper.createAndAddDeploymentScopeDef(name, expression, definition); } }
From source file:org.codehaus.aspectwerkz.definition.DocumentParser.java
License:Open Source License
/** * Parses the global advisable elements. * * @param systemElement the system element * @param definition/*from www . ja v a 2 s. c o m*/ */ private static void parseAdvisableDefs(final Element systemElement, final SystemDefinition definition) { for (Iterator it11 = systemElement.elementIterator("advisable"); it11.hasNext();) { Element advisableElement = (Element) it11.next(); String expression = ""; String pointcutTypes = "all"; for (Iterator it2 = advisableElement.attributeIterator(); it2.hasNext();) { Attribute attribute = (Attribute) it2.next(); final String name = attribute.getName().trim(); final String value = attribute.getValue().trim(); if (name.equalsIgnoreCase("expression")) { expression = value; } else if (name.equalsIgnoreCase("pointcut-type")) { pointcutTypes = value; } } // pointcut CDATA is expression unless already specified as an attribute if (expression == null) { expression = advisableElement.getTextTrim(); } handleAdvisableDefinition(definition, expression, pointcutTypes); } }
From source file:org.codehaus.aspectwerkz.definition.DocumentParser.java
License:Open Source License
/** * Parses the pointcuts.//from w w w . ja v a2 s .com * * @param aspectElement the aspect element * @param aspectDef the system definition */ private static void parsePointcutElements(final Element aspectElement, final AspectDefinition aspectDef) { for (Iterator it2 = aspectElement.elementIterator(); it2.hasNext();) { Element pointcutElement = (Element) it2.next(); if (pointcutElement.getName().trim().equals("pointcut")) { String name = pointcutElement.attributeValue("name"); String expression = pointcutElement.attributeValue("expression"); // pointcut CDATA is expression unless already specified as an attribute if (expression == null) { expression = pointcutElement.getTextTrim(); } DefinitionParserHelper.createAndAddPointcutDefToAspectDef(name, expression, aspectDef); } else if (pointcutElement.getName().trim().equals("deployment-scope")) { String name = pointcutElement.attributeValue("name"); String expression = pointcutElement.attributeValue("expression"); // pointcut CDATA is expression unless already specified as an attribute if (expression == null) { expression = pointcutElement.getTextTrim(); } DefinitionParserHelper.createAndAddDeploymentScopeDef(name, expression, aspectDef.getSystemDefinition()); } else if (pointcutElement.getName().trim().equals("advisable")) { String expression = pointcutElement.attributeValue("expression"); String pointcutTypes = pointcutElement.attributeValue("pointcut-type"); if (expression == null) { expression = pointcutElement.getTextTrim(); } handleAdvisableDefinition(aspectDef.getSystemDefinition(), expression, pointcutTypes); } } }
From source file:org.cpsolver.exam.model.PredefinedExamRoomSharing.java
License:Open Source License
@Override public void load(Exam exam, Element element) { Element canShareRoom = element.element("canShareRoom"); if (canShareRoom == null) return;//from www . ja v a 2 s .co m for (String id : canShareRoom.getTextTrim().split(",")) addPair(exam.getId(), Long.valueOf(id.trim())); }
From source file:org.craftercms.core.processors.impl.IncludeDescriptorsProcessor.java
License:Open Source License
@SuppressWarnings("unchecked") protected void includeDescriptors(Context context, CachingOptions cachingOptions, Item item) throws ItemProcessingException { String descriptorUrl = item.getDescriptorUrl(); includedItemsStack.get().push(descriptorUrl); try {/*from w ww . jav a 2 s . c om*/ Document descriptorDom = item.getDescriptorDom(); List<Element> includeElements = descriptorDom.selectNodes(includeElementXPathQuery); if (CollectionUtils.isEmpty(includeElements)) { return; } if (logger.isDebugEnabled()) { logger.debug("Processing includes of item @ " + descriptorUrl); } for (Element includeElement : includeElements) { String itemToIncludePath = includeElement.getTextTrim(); if (StringUtils.isEmpty(itemToIncludePath)) { continue; } if (!isIncludeDisabled(includeElement)) { if (!includedItemsStack.get().contains(itemToIncludePath)) { Item itemToInclude = getItemToInclude(context, cachingOptions, itemToIncludePath); if (itemToInclude != null && itemToInclude.getDescriptorDom() != null) { if (logger.isDebugEnabled()) { logger.debug("Include found in " + descriptorUrl + ": " + itemToIncludePath); } doInclude(item, includeElement, itemToInclude); } else { logger.debug("No descriptor item found @ " + itemToIncludePath); } } else { logger.debug( "Circular inclusion detected. Item " + itemToIncludePath + " already included"); } } else { if (logger.isDebugEnabled()) { logger.debug("Ignoring include " + itemToIncludePath + ". It's currently disabled"); } } } } finally { includedItemsStack.get().pop(); } }
From source file:org.craftercms.core.processors.impl.PageAwareIncludeDescriptorsProcessor.java
License:Open Source License
@Override protected boolean isIncludeDisabled(Element includeElement) { return super.isIncludeDisabled(includeElement) || (disablePageInclusion && includeElement.getTextTrim().matches(pagesPathPattern)); }