use of org.dom4j.Attribute in project openolat by klemens.
the class OutcomesProcessingParser method parse.
/**
* @see org.olat.ims.qti.editor.beecom.IParser#parse(org.dom4j.Element)
*/
public Object parse(Element element) {
// assert element.getName().equalsIgnoreCase("outcomes_processing");
OutcomesProcessing outcomesProcessing = new OutcomesProcessing();
List decvars = element.selectNodes("*/decvar");
if (decvars.size() == 0)
return outcomesProcessing;
Element decvar = (Element) decvars.get(0);
for (Iterator iter = decvar.attributeIterator(); iter.hasNext(); ) {
Attribute attr = (Attribute) iter.next();
outcomesProcessing.setField(attr.getName(), attr.getValue());
}
return outcomesProcessing;
}
use of org.dom4j.Attribute in project Openfire by igniterealtime.
the class PluginManager method loadPlugin.
/**
* Loads a plugin.
*
* @param pluginDir the plugin directory.
*/
synchronized boolean loadPlugin(String canonicalName, Path pluginDir) {
final PluginMetadata metadata = PluginMetadata.getInstance(pluginDir);
pluginMetadata.put(canonicalName, metadata);
// Only load the admin plugin during setup mode.
if (XMPPServer.getInstance().isSetupMode() && !(canonicalName.equals("admin"))) {
return false;
}
if (failureToLoadCount.containsKey(canonicalName) && failureToLoadCount.get(canonicalName) > JiveGlobals.getIntProperty("plugins.loading.retries", 5)) {
Log.debug("The unloaded file for plugin '{}' is silently ignored, as it has failed to load repeatedly.", canonicalName);
return false;
}
Log.debug("Loading plugin '{}'...", canonicalName);
try {
final Path pluginConfig = pluginDir.resolve("plugin.xml");
if (!Files.exists(pluginConfig)) {
Log.warn("Plugin '{}' could not be loaded: no plugin.xml file found.", canonicalName);
// Don't retry - this cannot be recovered from.
failureToLoadCount.put(canonicalName, Integer.MAX_VALUE);
return false;
}
final Version currentServerVersion = XMPPServer.getInstance().getServerInfo().getVersion();
// See if the plugin specifies a minimum version of Openfire required to run.
if (metadata.getMinServerVersion() != null) {
// OF-1338: Ignore release status when comparing minimum server version requirement.
if (metadata.getMinServerVersion().isNewerThan(currentServerVersion.ignoringReleaseStatus())) {
Log.warn("Ignoring plugin '{}': requires server version {}. Current server version is {}.", canonicalName, metadata.getMinServerVersion(), currentServerVersion);
// Don't retry - this cannot be recovered from.
failureToLoadCount.put(canonicalName, Integer.MAX_VALUE);
return false;
}
}
// See if the plugin specifies a maximum version of Openfire required to run.
if (metadata.getPriorToServerVersion() != null) {
// OF-1338: Ignore release status when comparing maximum server version requirement.
final Version compareVersion = new Version(currentServerVersion.getMajor(), currentServerVersion.getMinor(), currentServerVersion.getMicro(), null, -1);
if (!metadata.getPriorToServerVersion().isNewerThan(compareVersion)) {
Log.warn("Ignoring plugin '{}': compatible with server versions up to but excluding {}. Current server version is {}.", canonicalName, metadata.getPriorToServerVersion(), currentServerVersion);
// Don't retry - this cannot be recovered from.
failureToLoadCount.put(canonicalName, Integer.MAX_VALUE);
return false;
}
}
// See if the plugin specifies a minimum version of Java required to run.
if (metadata.getMinJavaVersion() != null) {
final JavaSpecVersion runtimeVersion = new JavaSpecVersion(System.getProperty("java.specification.version"));
if (metadata.getMinJavaVersion().isNewerThan(runtimeVersion)) {
Log.warn("Ignoring plugin '{}': requires Java specification version {}. Openfire is currently running in Java {}.", canonicalName, metadata.getMinJavaVersion(), System.getProperty("java.specification.version"));
// Don't retry - this cannot be recovered from.
failureToLoadCount.put(canonicalName, Integer.MAX_VALUE);
return false;
}
}
// Initialize the plugin class loader, which is either a new instance, or a the loader from a parent plugin.
final 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.
String parentPluginName = null;
Plugin parentPlugin = null;
final String parentCanonicalName = PluginMetadataHelper.getParentPlugin(pluginDir);
if (parentCanonicalName != null) {
// The name of the parent plugin as specified in plugin.xml might have incorrect casing. Lookup the correct name.
for (final Map.Entry<String, Plugin> entry : pluginsLoaded.entrySet()) {
if (entry.getKey().equalsIgnoreCase(parentCanonicalName)) {
parentPluginName = entry.getKey();
parentPlugin = entry.getValue();
break;
}
}
// See if the parent is loaded.
if (parentPlugin == null) {
Log.info("Unable to load plugin '{}': parent plugin '{}' has not been loaded.", canonicalName, parentCanonicalName);
Integer count = failureToLoadCount.get(canonicalName);
if (count == null) {
count = 0;
}
failureToLoadCount.put(canonicalName, ++count);
return false;
}
pluginLoader = classloaders.get(parentPlugin);
} else {
// This is not a child plugin, so create a new class loader.
pluginLoader = new PluginClassLoader();
}
// Add the plugin sources to the classloaded.
pluginLoader.addDirectory(pluginDir.toFile());
// Initialise a logging context, if necessary
final Path path = pluginDir.resolve("classes/log4j2.xml");
if (Files.isRegularFile(path)) {
synchronized (PluginManager.class) {
final LoggerContext loggerContext = LogManager.getContext(pluginLoader, false, path.toUri());
loggerContext.getLogger("To avoid LOG4J2-1094");
}
}
// Instantiate the plugin!
final Document pluginXML = SAXReaderUtil.readDocument(pluginConfig.toFile());
final String className = pluginXML.selectSingleNode("/plugin/class").getText().trim();
final Plugin plugin;
final ClassLoader originalClassLoader = Thread.currentThread().getContextClassLoader();
try {
Thread.currentThread().setContextClassLoader(pluginLoader);
plugin = (Plugin) pluginLoader.loadClass(className).newInstance();
} finally {
Thread.currentThread().setContextClassLoader(originalClassLoader);
}
// Bookkeeping!
classloaders.put(plugin, pluginLoader);
pluginsLoaded.put(canonicalName, plugin);
pluginDirs.put(canonicalName, pluginDir);
// If this is a child plugin, register it as such.
if (parentPlugin != null) {
List<String> childrenPlugins = parentPluginMap.get(parentPlugin);
if (childrenPlugins == null) {
childrenPlugins = new ArrayList<>();
parentPluginMap.put(parentPlugin, childrenPlugins);
}
childrenPlugins.add(canonicalName);
// Also register child to parent relationship.
childPluginMap.put(plugin, parentPluginName);
}
// 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("Error while loading plugin '{}': {}", canonicalName, LocaleUtils.getLocalizedString("upgrade.database.failure"));
}
// Load any JSP's defined by the plugin.
final Path webXML = pluginDir.resolve("web").resolve("WEB-INF").resolve("web.xml");
if (Files.exists(webXML)) {
PluginServlet.registerServlets(this, plugin, webXML.toFile());
}
// Load any custom-defined servlets.
final Path customWebXML = pluginDir.resolve("web").resolve("WEB-INF").resolve("web-custom.xml");
if (Files.exists(customWebXML)) {
PluginServlet.registerServlets(this, plugin, customWebXML.toFile());
}
// Configure caches of the plugin
configureCaches(pluginDir, canonicalName);
// Initialze the plugin.
final ClassLoader oldLoader = Thread.currentThread().getContextClassLoader();
Thread.currentThread().setContextClassLoader(pluginLoader);
plugin.initializePlugin(this, pluginDir.toFile());
Log.debug("Initialized plugin '{}'.", canonicalName);
Thread.currentThread().setContextClassLoader(oldLoader);
// If there a <adminconsole> section defined, register it.
final Element adminElement = (Element) pluginXML.selectSingleNode("/plugin/adminconsole");
if (adminElement != null) {
final 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", canonicalName);
}
// If global images are specified, override their URL.
Element imageEl = (Element) adminElement.selectSingleNode("/plugin/adminconsole/global/logo-image");
if (imageEl != null) {
imageEl.setText("plugins/" + canonicalName + "/" + imageEl.getText());
// Set the plugin name so that the proper i18n String can be loaded.
imageEl.addAttribute("plugin", canonicalName);
}
imageEl = (Element) adminElement.selectSingleNode("/plugin/adminconsole/global/login-image");
if (imageEl != null) {
imageEl.setText("plugins/" + canonicalName + "/" + imageEl.getText());
// Set the plugin name so that the proper i18n String can be loaded.
imageEl.addAttribute("plugin", canonicalName);
}
// Modify all the URL's in the XML so that they are passed through the plugin servlet correctly.
final List urls = adminElement.selectNodes("//@url");
for (final Object url : urls) {
final Attribute attr = (Attribute) url;
attr.setValue("plugins/" + canonicalName + "/" + 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.
final String[] elementNames = new String[] { "tab", "sidebar", "item" };
for (final String elementName : elementNames) {
final List values = adminElement.selectNodes("//" + elementName);
for (final Object value : values) {
final Element element = (Element) value;
// Make sure there's a name or description. Otherwise, no need to i18n settings.
if (element.attribute("name") != null || element.attribute("value") != null) {
element.addAttribute("plugin", canonicalName);
}
}
}
AdminConsole.addModel(canonicalName, adminElement);
}
firePluginCreatedEvent(canonicalName, plugin);
Log.info("Successfully loaded plugin '{}'.", canonicalName);
return true;
} catch (Throwable e) {
Log.error("An exception occurred while loading plugin '{}':", canonicalName, e);
Integer count = failureToLoadCount.get(canonicalName);
if (count == null) {
count = 0;
}
failureToLoadCount.put(canonicalName, ++count);
if (e instanceof InterruptedException) {
Thread.currentThread().interrupt();
}
return false;
}
}
use of org.dom4j.Attribute in project ats-framework by Axway.
the class XmlText method getAttributes.
/**
* @param xpath XPath , pointing to a XML element
* @return a HashMap , containing the attributes and their values
* @throws XMLException
*/
@PublicAtsApi
public Map<String, String> getAttributes(String xpath) throws XMLException {
if (StringUtils.isNullOrEmpty(xpath)) {
throw new XMLException("Null/empty xpath is not allowed.");
}
Element element = findElement(xpath);
if (element == null) {
throw new XMLException("'" + xpath + "' is not a valid path");
}
HashMap<String, String> attributes = new HashMap<>(1);
Iterator<Attribute> it = element.attributeIterator();
while (it.hasNext()) {
Attribute attr = it.next();
attributes.put(attr.getName(), attr.getValue());
}
return attributes;
}
use of org.dom4j.Attribute in project cuba by cuba-platform.
the class UserSettingServiceBean method copySettings.
@Override
public void copySettings(User fromUser, User toUser) {
MetaClass metaClass = metadata.getClassNN(UserSetting.class);
if (!security.isEntityOpPermitted(metaClass, EntityOp.CREATE)) {
throw new AccessDeniedException(PermissionType.ENTITY_OP, metaClass.getName());
}
Map<UUID, Presentation> presentationsMap = copyPresentations(fromUser, toUser);
copyUserFolders(fromUser, toUser, presentationsMap);
Map<UUID, FilterEntity> filtersMap = copyFilters(fromUser, toUser);
try (Transaction tx = persistence.createTransaction()) {
EntityManager em = persistence.getEntityManager();
Query deleteSettingsQuery = em.createQuery("delete from sec$UserSetting s where s.user.id = ?1");
deleteSettingsQuery.setParameter(1, toUser.getId());
deleteSettingsQuery.executeUpdate();
tx.commitRetaining();
em = persistence.getEntityManager();
TypedQuery<UserSetting> q = em.createQuery("select s from sec$UserSetting s where s.user.id = ?1", UserSetting.class);
q.setParameter(1, fromUser.getId());
List<UserSetting> fromUserSettings = q.getResultList();
for (UserSetting currSetting : fromUserSettings) {
UserSetting newSetting = metadata.create(UserSetting.class);
newSetting.setUser(toUser);
newSetting.setClientType(currSetting.getClientType());
newSetting.setName(currSetting.getName());
try {
Document doc = dom4JTools.readDocument(currSetting.getValue());
List<Element> components = doc.getRootElement().element("components").elements("component");
for (Element component : components) {
Attribute presentationAttr = component.attribute("presentation");
if (presentationAttr != null) {
UUID presentationId = UuidProvider.fromString(presentationAttr.getValue());
Presentation newPresentation = presentationsMap.get(presentationId);
if (newPresentation != null) {
presentationAttr.setValue(newPresentation.getId().toString());
}
}
Element defaultFilterEl = component.element("defaultFilter");
if (defaultFilterEl != null) {
Attribute idAttr = defaultFilterEl.attribute("id");
if (idAttr != null) {
UUID filterId = UuidProvider.fromString(idAttr.getValue());
FilterEntity newFilter = filtersMap.get(filterId);
if (newFilter != null) {
idAttr.setValue(newFilter.getId().toString());
}
}
}
}
newSetting.setValue(dom4JTools.writeDocument(doc, true));
} catch (Exception e) {
newSetting.setValue(currSetting.getValue());
}
em.persist(newSetting);
}
tx.commit();
}
}
use of org.dom4j.Attribute in project cuba by cuba-platform.
the class FilterDelegateImpl method saveSettings.
@Override
public boolean saveSettings(Element element) {
boolean changed = false;
Element e = element.element("defaultFilter");
if (e == null)
e = element.addElement("defaultFilter");
UUID defaultId = null;
Boolean applyDefault = false;
for (FilterEntity filter : filterEntities) {
if (BooleanUtils.isTrue(filter.getIsDefault())) {
defaultId = filter.getId();
applyDefault = filter.getApplyDefault();
break;
}
}
String newDef = defaultId != null ? defaultId.toString() : null;
Attribute attr = e.attribute("id");
String oldDef = attr != null ? attr.getValue() : null;
if (!Objects.equals(oldDef, newDef)) {
if (newDef == null && attr != null) {
e.remove(attr);
} else {
if (attr == null)
e.addAttribute("id", newDef);
else
attr.setValue(newDef);
}
changed = true;
}
Boolean newApplyDef = BooleanUtils.isTrue(applyDefault);
Attribute applyDefaultAttr = e.attribute("applyDefault");
Boolean oldApplyDef = applyDefaultAttr != null ? Boolean.valueOf(applyDefaultAttr.getValue()) : false;
if (!Objects.equals(oldApplyDef, newApplyDef)) {
if (applyDefaultAttr != null) {
applyDefaultAttr.setValue(newApplyDef.toString());
} else {
e.addAttribute("applyDefault", newApplyDef.toString());
}
changed = true;
}
if (groupBoxExpandedChanged) {
Element groupBoxExpandedEl = element.element("groupBoxExpanded");
if (groupBoxExpandedEl == null)
groupBoxExpandedEl = element.addElement("groupBoxExpanded");
Boolean oldGroupBoxExpandedValue = groupBoxExpandedEl.getText().isEmpty() ? Boolean.TRUE : Boolean.valueOf(groupBoxExpandedEl.getText());
Boolean newGroupBoxExpandedValue = groupBoxLayout.isExpanded();
if (!Objects.equals(oldGroupBoxExpandedValue, newGroupBoxExpandedValue)) {
groupBoxExpandedEl.setText(newGroupBoxExpandedValue.toString());
changed = true;
}
}
if (isMaxResultsLayoutVisible()) {
if (maxResultValueChanged) {
Element maxResultsEl = element.element("maxResults");
if (maxResultsEl == null) {
maxResultsEl = element.addElement("maxResults");
}
Integer newMaxResultsValue = maxResultsField.getValue();
if (newMaxResultsValue != null) {
maxResultsEl.setText(newMaxResultsValue.toString());
changed = true;
}
}
}
return changed;
}
Aggregations