📄 extensionstore.java
字号:
public ExtensionBundle getExtensionBundle(String bundleName) throws Exception {
if (!extensionBundles.containsKey(bundleName)) {
throw new Exception(bundleName + " is not a loaded application bundle");
}
return (ExtensionBundle) extensionBundles.get(bundleName);
}
public List reload() throws Exception {
if (log.isInfoEnabled())
log.info("Reloading all application bundles");
boolean reconnect = downloadableExtensions != null;
downloadableExtensions = null;
downloadableExtensionsLastUpdated = null;
deregisterApplicationPermissions();
List errors = reloadAll();
if (reconnect) {
getDownloadableExtensionStoreDescriptor(true);
}
return errors;
}
public void reload(String id) throws Exception {
if (log.isInfoEnabled())
log.info("Reloading application bundle " + id);
if (isExtensionLoaded(id)) {
ExtensionBundle bundle = getExtensionBundle(id);
try {
bundle.load();
} catch (FileNotFoundException fnfe) {
// Application was probably removed
log.warn("Extension description not found.", fnfe);
extensionBundles.remove(id);
extensionBundlesList.remove(bundle);
}
} else {
loadDir(new File(basedir, id));
}
Collections.sort(extensionBundlesList);
}
public File getUpdatedExtensionsDirectory() throws IOException {
File updatedExtensionsDir = new File(ContextHolder.getContext().getConfDirectory(), "updated-extensions");
if (!updatedExtensionsDir.exists() && !updatedExtensionsDir.mkdirs()) {
throw new IOException("The extension update directory " + updatedExtensionsDir.getAbsolutePath()
+ " could not be created.");
}
return updatedExtensionsDir;
}
public void removeExtensionBundle(ExtensionBundle bundle) throws Exception {
if (log.isInfoEnabled())
log.info("Removing extension bundle " + bundle.getId());
boolean containsPlugin = false;
try {
for (Iterator i = bundle.iterator(); i.hasNext();) {
ExtensionDescriptor app = (ExtensionDescriptor) i.next();
if (app.getExtensionType() instanceof PluginType) {
containsPlugin = true;
}
CoreServlet.getServlet().getSystemDatabase().removeApplicationShortcuts(app.getId());
}
if (!containsPlugin) {
if (log.isInfoEnabled())
log.info("Extension " + bundle.getId() + " doesnt contain any plugins, removing now.");
if (bundle.getBaseDir().exists()) {
if (!Util.delTree(bundle.getBaseDir())) {
throw new IOException("Failed to remove directory " + bundle.getBaseDir().getAbsolutePath());
}
}
} else {
if (!isRepositoryBacked()) {
if (log.isInfoEnabled())
log.info("Extension " + bundle.getId() + " contains plugins, deferring removal until restart.");
StringBuffer toRemove = new StringBuffer(STORE_PREF.get(DIRS_TO_REMOVE, ""));
if (toRemove.length() > 0) {
toRemove.append(",");
}
toRemove.append(bundle.getBaseDir());
STORE_PREF.put(DIRS_TO_REMOVE, toRemove.toString());
}
}
} catch (Exception e) {
throw e;
} finally {
if (!containsPlugin) {
extensionBundles.remove(bundle.getId());
extensionBundlesList.remove(bundle);
if (log.isInfoEnabled())
log.info("Extension Zip file " + bundle.getId() + ".zip" + " has been deleted.");
} else {
bundle.setType(ExtensionBundle.TYPE_PENDING_REMOVAL);
}
if (isRepositoryBacked()) {
RepositoryFactory.getRepository().getStore(ARCHIVE_STORE).removeEntry(bundle.getId() + ".zip");
}
Collections.sort(extensionBundlesList);
}
}
/**
* @param application
* @return
*/
public boolean isExtensionLoaded(String application) {
for (Iterator i = extensionBundlesList.iterator(); i.hasNext();) {
ExtensionBundle bundle = (ExtensionBundle) i.next();
if (bundle.containsApplication(application)) {
return true;
}
}
return false;
}
public ExtensionBundle installExtension(final String id, InputStream in, HttpServletRequest request) throws Exception {
ExtensionBundle bundle = null;
ExtensionStoreDescriptor store = ExtensionStore.getInstance().getDownloadableExtensionStoreDescriptor(true);
if (store == null) {
throw new Exception("No download applications.");
}
bundle = store.getApplicationBundle(id);
// defensive messages.
if (bundle != null && bundle.getRequiredHostVersion() != null
&& bundle.getRequiredHostVersion().compareTo(ContextHolder.getContext().getVersion()) > 0) {
ActionMessages msgs = new ActionMessages();
if (bundle != null) {
msgs.add(Constants.REQ_ATTR_WARNINGS, new BundleActionMessage("extensions", "extensionStore.message.wrongVersion",
bundle.getRequiredHostVersion(), ContextHolder.getContext().getVersion()));
} else {
msgs.add(Constants.REQ_ATTR_WARNINGS, new BundleActionMessage("extensions",
"extensionStore.message.unableToInstall"));
}
CoreUtil.addWarnings(request, msgs);
}
String dep;
ExtensionBundle current;
if (bundle != null) {
for (Enumeration e = bundle.getDependencies(); e.hasMoreElements();) {
dep = (String) e.nextElement();
try {
current = getExtensionBundle(dep);
PluginVersion v1 = new PluginVersion(bundle.getVersion().toString());
PluginVersion v2 = new PluginVersion(current.getVersion().toString());
if (v1.compareTo(v2) < 0) {
URLConnection con = ExtensionStore.getInstance().downloadExtension(dep);
InputStream in2 = con.getInputStream();
updateExtension(dep, in2, request);
}
} catch (Exception ex) {
URLConnection con = ExtensionStore.getInstance().downloadExtension(dep);
InputStream in2 = con.getInputStream();
installExtension(dep, in2, request);
}
}
}
final RepositoryStore repStore = RepositoryFactory.getRepository().getStore(ARCHIVE_STORE);
OutputStream out = null;
try {
out = repStore.getEntryOutputStream(id + ".zip");
Util.copy(in, out);
} finally {
Util.closeStream(in);
Util.closeStream(out);
}
ExtensionBundle newbund = null;
try {
ZipExtract.extractZipFile(ExtensionStore.getInstance().getExtensionStoreDirectory(), repStore.getEntryInputStream(id
+ ".zip"));
ExtensionStore.getInstance().reload(id);
newbund = ExtensionStore.getInstance().getExtensionBundle(id);
boolean containsType = false;
String type = null;
for (Iterator i = newbund.iterator(); !containsType && i.hasNext();) {
ExtensionDescriptor des = (ExtensionDescriptor) i.next();
if (des.getExtensionType() instanceof ExtensionType) {
type = des.getExtensionType().getType();
containsType = true;
}
}
} catch (Exception e) {
throw e;
}
final ExtensionBundle newBundle = ExtensionStore.getInstance().getExtensionBundle(id);
return newBundle;
}
public void licenseCheck(final ExtensionBundle newBundle, HttpServletRequest request, final ActionForward installedForward)
throws Exception {
final RepositoryStore repStore = RepositoryFactory.getRepository().getStore(ARCHIVE_STORE);
// If installing, there may be a license agreement to handle
File licenseFile = newBundle.getLicenseFile();
if (licenseFile != null && licenseFile.exists()) {
CoreUtil.requestLicenseAgreement(request.getSession(), new LicenseAgreement(newBundle.getName(), licenseFile,
new LicenseAgreementCallback() {
public void licenseAccepted(HttpServletRequest request) {
// Dont care
}
public void licenseRejected(HttpServletRequest request) {
// Remove the repository entry if it is in
// use
if (repositoryBacked) {
try {
repStore.removeEntry(newBundle.getId() + ".zip");
} catch (IOException ex) {
}
}
// Remove the expanded bundle
if (newBundle.getBaseDir().exists()) {
Util.delTree(newBundle.getBaseDir());
}
// Reload the extension store
try {
ExtensionStore.getInstance().reload(newBundle.getId());
} catch (Exception e) {
log.error("Failed to reload extension store.");
}
}
}, installedForward));
}
}
public void postInstallExtension(final ExtensionBundle newBundle, HttpServletRequest request) throws Exception {
/*
* Check if the bundle contains any plugins and reset the install flag
* so that the install method gets run on the next server startup
*/
boolean containsPlugin = false;
for (Iterator i = newBundle.iterator(); i.hasNext();) {
ExtensionDescriptor des = (ExtensionDescriptor) i.next();
if (des.getExtensionType() instanceof PluginType) {
CoreServlet.getServlet().getPluginManager().installOnNextStart(des.getId());
containsPlugin = true;
}
}
/*
* If they are any plugins in the bundle, defer the extension install
* tasks until the next start up, otherwise perform them now
*/
if (containsPlugin) {
CoreUtil.addMultipleGlobalWarning(GlobalWarning.MANAGEMENT_USERS, new BundleActionMessage("extensions",
"extensionStore.message.pluginInstalledRestartRequired"));
} else {
if (newBundle != null && newBundle.getInstaller() != null) {
newBundle.getInstaller().doInstall();
} else {
ActionMessages msgs = new ActionMessages();
msgs.add(Constants.REQ_ATTR_WARNINGS, new BundleActionMessage("extensions",
"extensionStore.message.unableToInstall"));
CoreUtil.addWarnings(request, msgs);
}
}
}
public ExtensionBundle updateExtension(final String id, InputStream in, HttpServletRequest request) throws Exception {
ExtensionBundle bundle = ExtensionStore.getInstance().getExtensionBundle(id);
try {
if (bundle == null) {
throw new Exception("No extension bundle named " + id
+ " could be located at the 3SP Application Store for this version of SSL-Explorer.");
}
// defensive messages.
if (bundle != null && bundle.getRequiredHostVersion() != null
&& bundle.getRequiredHostVersion().compareTo(ContextHolder.getContext().getVersion()) > 0) {
ActionMessages msgs = new ActionMessages();
if (bundle != null) {
msgs.add(Constants.REQ_ATTR_WARNINGS, new BundleActionMessage("extensions", "extensionStore.message.wrongVersion",
bundle.getRequiredHostVersion(), ContextHolder.getContext().getVersion()));
} else {
msgs.add(Constants.REQ_ATTR_WARNINGS, new BundleActionMessage("extensions",
"extensionStore.message.unableToInstall"));
}
CoreUtil.addWarnings(request, msgs);
}
final RepositoryStore repStore = RepositoryFactory.getRepository().getStore(ARCHIVE_STORE);
OutputStream out = null;
try {
out = repStore.getEntryOutputStream(id + ".zip");
Util.copy(in, out);
} finally {
Util.closeStream(in);
Util.closeStream(out);
}
CoreUtil.addMultipleGlobalWarning(GlobalWarning.MANAGEMENT_USERS, new BundleActionMessage("extensions",
"extensionStore.message.extensionUpdatedRestartRequired"));
boolean containsType = false;
String type = null;
for (Iterator i = bundle.iterator(); !containsType && i.hasNext();) {
ExtensionDescriptor des = (ExtensionDescriptor) i.next();
if (des.getExtensionType() instanceof ExtensionType) {
type = des.getExtensionType().getType();
containsType = true;
}
}
} catch (Exception e) {
throw e;
}
return bundle;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -