/** * @param extension the extension * @return true if the extension is installed * @see InstalledExtension#isInstalled() */ public static boolean isInstalled(Extension extension) { return extension.getProperty(PKEY_INSTALLED, false); }
/** * @param extension the extension * @return the namespaces in which this extension is enabled. Null means root namespace (i.e all namespaces). */ public static Collection<String> getNamespaces(Extension extension) { Collection<String> namespaces; Object namespacesObject = extension.getProperty(PKEY_NAMESPACES); // RETRO-COMPATIBILITY: used to be a String collection with just the actual namespaces if (namespacesObject == null) { namespaces = null; } else if (namespacesObject instanceof Collection) { namespaces = (Collection<String>) namespacesObject; } else { namespaces = ((Map<String, Map<String, Object>>) namespacesObject).keySet(); } return namespaces; }
@Override public <T> T getProperty(String key) { if (this.overwrites.containsKey(Extension.FIELD_PROPERTIES + '_' + key)) { return (T) this.overwrites.get(Extension.FIELD_PROPERTIES + '_' + key); } return getWrapped().getProperty(key); }
@Override public <T> T getProperty(String key, T def) { if (this.overwrites.containsKey(Extension.FIELD_PROPERTIES + '_' + key)) { return (T) this.overwrites.get(Extension.FIELD_PROPERTIES + '_' + key); } return getWrapped().getProperty(key, def); }
/** * Indicate if the extension as been installed as a dependency of another one. * * @param extension the extension * @param namespace the namespace to look at, null indicate the root namespace * @return true if the the extension has been installed only because it was a dependency of another extension * @see InstalledExtension#isDependency(String) * @since 8.2RC1 */ public static boolean isDependency(Extension extension, String namespace) { boolean isDependency = false; if (namespace == null) { isDependency = extension.getProperty(PKEY_DEPENDENCY, false); } else { Object namespacesObject = extension.getProperty(PKEY_NAMESPACES); // RETRO-COMPATIBILITY: used to be a String collection with just the actual namespaces if (namespacesObject instanceof Map) { Map<String, Object> installedNamespace = ((Map<String, Map<String, Object>>) namespacesObject).get(namespace); isDependency = installedNamespace != null ? (installedNamespace.get(PKEY_NAMESPACES_DEPENDENCY) == Boolean.TRUE) : isDependency(extension, null); } else { isDependency = isDependency(extension, null); } } return isDependency; }
/** * Find of the passes extension if a webjar. * * @param extension the extension to test * @return true of the passed extension is a webjar, false otherwise * @since 9.0RC1 */ public static boolean isWebjar(Extension extension) { // Ideally webjar extensions should have "webjar" type if (extension.getType().equals(WEBJAR)) { return true; } /////////////////////////////// // But it's not the case for: // ** webjar.org releases (i.e. most of the webjars). We assume "org.webjars:*" id means it's a webjar if (StringUtils.startsWithAny(extension.getId().getId(), "org.webjars:", "org.webjars.")) { return true; } // ** contrib extensions which support version of XWiki older than 9.0RC1. We support a custom property which // does not have any effect on older versions of XWiki if (JarExtensionHandler.WEBJAR.equals(extension.getProperty(JarExtensionHandler.PROPERTY_TYPE))) { return true; } return false; }