📄 cmsupdatebean.java
字号:
for (int i = 0; itModules.hasNext(); i++) {
String moduleName = (String)itModules.next();
CmsModule module = (CmsModule)getAvailableModules().get(moduleName);
if (!uptodate.contains(moduleName)) {
html.append(htmlModule(module, i));
hasModules = true;
} else {
html.append("<input type='hidden' name='availableModules' value='");
html.append(moduleName);
html.append("'>\n");
}
}
if (!hasModules) {
html.append("\t<tr>\n");
html.append("\t\t<td style='vertical-align: middle;'>\n");
html.append(Messages.get().getBundle().key(Messages.GUI_WARNING_ALL_MODULES_UPTODATE_0));
html.append("\t\t</td>\n");
html.append("\t</tr>\n");
}
return html.toString();
}
/**
* Creates a new instance of the setup Bean.<p>
*
* @param webAppRfsPath path to the OpenCms web application
* @param servletMapping the OpenCms servlet mapping
* @param defaultWebApplication the name of the default web application
*
*/
public void init(String webAppRfsPath, String servletMapping, String defaultWebApplication) {
try {
super.init(webAppRfsPath, servletMapping, defaultWebApplication);
if (m_workplaceUpdateThread != null) {
if (m_workplaceUpdateThread.isAlive()) {
m_workplaceUpdateThread.kill();
}
m_workplaceUpdateThread = null;
}
} catch (Exception e) {
e.printStackTrace();
throw new RuntimeException(e);
}
}
/**
* Prepares step 4 of the update wizard.<p>
*/
public void prepareUpdateStep5() {
if (isInitialized()) {
try {
String fileName = getWebAppRfsPath() + FOLDER_UPDATE + "cmsupdate";
// read the file
FileInputStream fis = new FileInputStream(fileName + CmsConfigurationManager.POSTFIX_ORI);
String script = "";
int readChar = fis.read();
while (readChar > -1) {
script += (char)readChar;
readChar = fis.read();
}
// substitute macros
script = CmsStringUtil.substitute(script, C_ADMIN_USER, getAdminUser());
script = CmsStringUtil.substitute(script, C_ADMIN_PWD, getAdminPwd());
script = CmsStringUtil.substitute(script, C_UPDATE_PROJECT, getUpdateProject());
script = CmsStringUtil.substitute(script, C_UPDATE_SITE, getUpdateSite());
script = CmsStringUtil.substitute(script, C_ADMIN_GROUP, getAdminGroup());
// write the new script
FileOutputStream fos = new FileOutputStream(fileName + ".txt");
fos.write(script.getBytes());
fos.close();
} catch (IOException e) {
e.printStackTrace();
throw new RuntimeException(e);
}
}
}
/**
* Prepares the update wizard.<p>
*/
public void prepareUpdateStep5b() {
if (!isInitialized()) {
return;
}
if ((m_workplaceUpdateThread != null) && (m_workplaceUpdateThread.isFinished())) {
// update is already finished, just wait for client to collect final data
return;
}
if (m_workplaceUpdateThread == null) {
m_workplaceUpdateThread = new CmsUpdateThread(this);
}
if (!m_workplaceUpdateThread.isAlive()) {
m_workplaceUpdateThread.start();
}
}
/**
* Generates the output for the update wizard.<p>
*
* @param out the JSP print stream
*
* @throws IOException in case errors occur while writing to "out"
*/
public void prepareUpdateStep5bOutput(JspWriter out) throws IOException {
m_oldLoggingOffset = m_newLoggingOffset;
m_newLoggingOffset = m_workplaceUpdateThread.getLoggingThread().getMessages().size();
if (isInitialized()) {
for (int i = m_oldLoggingOffset; i < m_newLoggingOffset; i++) {
String str = m_workplaceUpdateThread.getLoggingThread().getMessages().get(i).toString();
str = CmsEncoder.escapeWBlanks(str, CmsEncoder.ENCODING_UTF_8);
out.println("output[" + (i - m_oldLoggingOffset) + "] = \"" + str + "\";");
}
} else {
out.println("output[0] = 'ERROR';");
}
boolean threadFinished = m_workplaceUpdateThread.isFinished();
boolean allWritten = m_oldLoggingOffset >= m_workplaceUpdateThread.getLoggingThread().getMessages().size();
out.println("function initThread() {");
if (isInitialized()) {
out.print("send();");
if (threadFinished && allWritten) {
out.println("setTimeout('top.display.finish()', 500);");
} else {
int timeout = 5000;
if (getWorkplaceUpdateThread().getLoggingThread().getMessages().size() < 20) {
timeout = 1000;
}
out.println("setTimeout('location.reload()', " + timeout + ");");
}
}
out.println("}");
}
/**
* Prepares step 6 of the update wizard.<p>
*/
public void prepareUpdateStep6() {
if (isInitialized()) {
// lock the wizard for further use
lockWizard();
// save Properties to file "opencms.properties"
saveProperties(getProperties(), CmsSystemInfo.FILE_PROPERTIES, false);
}
}
/**
* Sets the admin Pwd.<p>
*
* @param adminPwd the admin Pwd to set
*/
public void setAdminPwd(String adminPwd) {
m_adminPwd = adminPwd;
}
/**
* Sets the admin User.<p>
*
* @param adminUser the admin User to set
*/
public void setAdminUser(String adminUser) {
m_adminUser = adminUser;
}
/**
* Sets the update Project.<p>
*
* @param updateProject the update Project to set
*/
public void setUpdateProject(String updateProject) {
m_updateProject = updateProject;
}
/**
* Sets the update site.<p>
*
* @param site the update site to set
*/
public void setUpdateSite(String site) {
m_updateSite = site;
}
/**
* @see org.opencms.main.I_CmsShellCommands#shellExit()
*/
public void shellExit() {
System.out.println();
System.out.println();
System.out.println("The update is finished!\nThe OpenCms system used for the update will now shut down.");
}
/**
* @see org.opencms.main.I_CmsShellCommands#shellStart()
*/
public void shellStart() {
System.out.println();
System.out.println("Starting Workplace update for OpenCms!");
String[] copy = org.opencms.main.Messages.COPYRIGHT_BY_ALKACON;
for (int i = copy.length - 1; i >= 0; i--) {
System.out.println(copy[i]);
}
System.out.println("This is OpenCms " + OpenCms.getSystemInfo().getVersionName());
System.out.println();
System.out.println();
}
/**
* Installed all modules that have been set using {@link #setInstallModules(String)}.<p>
*
* This method is invoked as a shell command.<p>
*
* @throws Exception if something goes wrong
*/
public void updateModulesFromUpdateBean() throws Exception {
// read here how the list of modules to be installed is passed from the setup bean to the
// setup thread, and finally to the shell process that executes the setup script:
// 1) the list with the package names of the modules to be installed is saved by setInstallModules
// 2) the setup thread gets initialized in a JSP of the setup wizard
// 3) the instance of the setup bean is passed to the setup thread by setAdditionalShellCommand
// 4) the setup bean is passed to the shell by startSetup
// 5) because the setup bean implements I_CmsShellCommands, the shell constructor can pass the shell's CmsObject back to the setup bean
// 6) thus, the setup bean can do things with the Cms
if (m_cms != null && m_installModules != null) {
Set utdModules = new HashSet(getUptodateModules());
I_CmsReport report = new CmsShellReport(m_cms.getRequestContext().getLocale());
for (int i = 0; i < m_installModules.size(); i++) {
String name = (String)m_installModules.get(i);
if (!utdModules.contains(name)) {
String filename = (String)m_moduleFilenames.get(name);
try {
updateModule(name, filename, report);
} catch (Exception e) {
// log a exception during module import, but make sure the next module is still imported
e.printStackTrace(System.err);
}
} else {
report.println(
Messages.get().container(Messages.RPT_MODULE_UPTODATE_1, name),
I_CmsReport.FORMAT_HEADLINE);
}
}
}
}
/**
* Returns the admin Group.<p>
*
* @return the admin Group
*/
protected String getAdminGroup() {
return m_adminGroup;
}
/**
* Sets the admin Group.<p>
*
* @param adminGroup the admin Group to set
*/
protected void setAdminGroup(String adminGroup) {
m_adminGroup = adminGroup;
}
/**
* Imports a module (zipfile) from the default module directory,
* creating a temporary project for this.<p>
*
* @param moduleName the name of the module to replace
* @param importFile the name of the import .zip file located in the update module directory
* @param report the shell report to write the output
*
* @throws Exception if something goes wrong
*
* @see org.opencms.importexport.CmsImportExportManager#importData(org.opencms.file.CmsObject, String, String, org.opencms.report.I_CmsReport)
*/
protected void updateModule(String moduleName, String importFile, I_CmsReport report) throws Exception {
String fileName = getModuleFolder() + importFile;
report.println(
Messages.get().container(Messages.RPT_BEGIN_UPDATE_MODULE_1, moduleName),
I_CmsReport.FORMAT_HEADLINE);
if (OpenCms.getModuleManager().getModule(moduleName) != null) {
OpenCms.getModuleManager().deleteModule(m_cms, moduleName, true, report);
}
OpenCms.getImportExportManager().importData(m_cms, fileName, null, report);
report.println(
Messages.get().container(Messages.RPT_END_UPDATE_MODULE_1, moduleName),
I_CmsReport.FORMAT_HEADLINE);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -