📄 cmsprogresswidget.java
字号:
result.append("\t\t\t} else {\n");
result.append("\t\t\t\tbar.style.width = \"100%\";\n");
result.append("\t\t\t}\n");
// fatal error returned by ajax
result.append("\t\t} else if (state == 'fatal') {\n");
result.append("\t\t\tprogressState = 0;\n");
result.append("\t\t\tsetProgressBarError(\"");
result.append(org.opencms.workplace.Messages.get().getBundle(getJsp().getRequestContext().getLocale()).key(
org.opencms.workplace.Messages.GUI_AJAX_REPORT_GIVEUP_0));
result.append("\");\n");
// error returned by ajax
result.append("\t\t} else if (state == 'error') {\n");
result.append("\t\t\tprogressState = 0;\n");
result.append("\t\t\tsetProgressBarError(\"");
result.append(org.opencms.workplace.Messages.get().getBundle(getJsp().getRequestContext().getLocale()).key(
org.opencms.workplace.Messages.GUI_AJAX_REPORT_ERROR_0));
result.append(" \" + msg);\n");
// wait returned by ajax -> display wait symbol
result.append("\t\t} else if (state == 'wait') {\n");
result.append("\t\t\tbar.parentNode.style.display = \"none\";\n");
result.append("\t\t\tpercent.style.display = \"none\";\n");
result.append("\t\t\twait.style.display = \"block\";\n");
result.append("\t\t}\n");
result.append("\t}\n");
// function set error
result.append("\tfunction setProgressBarError(msg) {\n");
result.append("\t\tvar error = document.getElementById(\"progressbar_error\");\n");
result.append("\t\tvar bar = document.getElementById(\"progressbar_bar\");\n");
result.append("\t\tvar percent = document.getElementById(\"progressbar_percent\");\n");
result.append("\t\tvar desc = document.getElementById(\"progressbar_desc\");\n");
result.append("\t\terror.innerHTML = msg;\n");
result.append("\t\terror.style.display = \"block\";\n");
result.append("\t\tbar.style.display = \"none\";\n");
result.append("\t\tpercent.style.display = \"none\";\n");
result.append("\t\tdesc.style.display = \"none\";\n");
result.append("\t}\n");
// function reset progress bar
result.append("\tfunction resetProgressBar() {\n");
result.append("\t\tvar bar = document.getElementById(\"progressbar_bar\");\n");
result.append("\t\tbar.parentNode.style.display = \"inline\";\n");
result.append("\t\tbar.style.width = \"0%\";\n");
result.append("\t\tbar.style.display = \"block\";\n");
result.append("\t\tvar percent = document.getElementById(\"progressbar_percent\");\n");
result.append("\t\tpercent.innerHTML = \"0%\";\n");
result.append("\t\tpercent.style.display = \"inline\";\n");
result.append("\t\tvar error = document.getElementById(\"progressbar_error\");\n");
result.append("\t\terror.innerHTML = \"\";\n");
result.append("\t\terror.style.display = \"none\";\n");
result.append("\t\tvar wait = document.getElementById(\"progressbar_wait\");\n");
result.append("\t\twait.style.display = \"none\";\n");
result.append("\t\tvar desc = document.getElementById(\"progressbar_desc\");\n");
result.append("\t\tdesc.style.display = \"block\";\n");
result.append("\t\tdesc.innerHTML = \"\";\n");
result.append("\t\t\t\t\tprogressResult = \"\";\n");
result.append("\t}\n");
// function start progress bar
result.append("\tfunction startProgressBar() {\n");
result.append("\t\tif (progressState > 0) {\n");
result.append("\t\t\tprogressState = 2;\n");
result.append("\t\t\twindow.setTimeout(\"startProgressBar()\",");
result.append(getRefreshRate());
result.append(");\n");
result.append("\t\t\treturn;\n");
result.append("\t\t}\n");
result.append("\t\tprogressState = 1;\n");
result.append("\t\tmakeRequest('");
result.append(getJsp().link("/system/workplace/commons/report-progress.jsp"));
result.append("', '");
result.append(PARAMETER_KEY);
result.append("=");
result.append(getKey());
result.append("&");
result.append(PARAMETER_SHOWWAITTIME);
result.append("=");
result.append(getShowWaitTime());
result.append("&");
result.append(PARAMETER_REFRESHRATE);
result.append("=");
result.append(getRefreshRate());
result.append("', 'updateProgressBar');\n");
result.append("\t}\n");
result.append("</script>\n");
return result.toString();
}
/**
* Returns the current JSP action element.<p>
*
* @return the the current JSP action element
*/
public CmsJspActionElement getJsp() {
return m_jsp;
}
/**
* Returns the unique key of the thread belonging to this widget.<p>
*
* @return the unique key of the thread belonging to this widget
*/
public String getKey() {
return m_key;
}
/**
* Returns the refresh rate in ms of the progress bar.<p>
*
* @return the refresh rate in ms of the progress bar
*/
public int getRefreshRate() {
return m_refreshRate;
}
/**
* Returns the time period the show the wait symbol before the progress bar is shown.<p>
*
* @return the time period the show the wait symbol before the progress bar is shown
*/
public int getShowWaitTime() {
return m_showWaitTime;
}
/**
* Generates the widget HTML for the progress bar.<p>
*
* @return the widget HTML for the progress bar
*/
public String getWidget() {
StringBuffer result = new StringBuffer();
CmsProgressThread thread = getProgressThread(getKey());
// if the thread is finished before the widget is rendered
// show directly the result
if ((thread != null) && (!thread.isAlive())) {
result.append("<script type=\"text/javascript\">\n");
result.append("\tprogressState = 0;\n");
result.append("\tprogressResult = '");
result.append(CmsStringUtil.escapeJavaScript(getActualProgress()));
result.append("';\n");
result.append("\t");
result.append(getJsFinishMethod());
result.append("();\n");
result.append("</script>\n");
} else {
// check if to show the wait symbol
boolean showWait = false;
if (getShowWaitTime() > 0) {
// show if the thread is running and the time running is smaller than the configured
if ((thread != null) && (thread.isAlive()) && (thread.getRuntime() < getShowWaitTime())) {
showWait = true;
} else if ((thread == null) && (getShowWaitTime() > 0)) {
// show if there is no thread
showWait = true;
}
}
result.append("<div id=\"progressbar_desc\" style=\"margin-bottom:5px;display:");
result.append(showWait ? "none" : "block");
result.append("\"></div>");
result.append("<div style=\"width:");
result.append(getWidth());
result.append(";border-width:1px;border-style:solid;padding:0px;margin:0px;float:left;display:");
result.append(showWait ? "none" : "inline");
result.append(";\">\n");
result.append("\t<div id=\"progressbar_bar\" style=\"width:0%;background-color:");
result.append(getColor());
result.append(";\"> </div>\n");
result.append("</div>\n");
result.append(" ");
result.append("<div id=\"progressbar_percent\" style=\"display:");
result.append(showWait ? "none" : "inline");
result.append(";\" >0%</div>\n");
result.append("<div id=\"progressbar_error\" style=\"display:none;color:#B40000;font-weight:bold;\"></div>\n");
result.append("<div id=\"progressbar_wait\" style=\"display:");
result.append(showWait ? "block" : "none");
result.append(";color:#000099;font-weight:bold;\"><img src=\"");
result.append(CmsWorkplace.getSkinUri());
result.append("commons/wait.gif\" width='32' height='32' alt='' align='absmiddle' />");
result.append(org.opencms.workplace.Messages.get().getBundle(getJsp().getRequestContext().getLocale()).key(
org.opencms.workplace.Messages.GUI_AJAX_REPORT_WAIT_0));
result.append("</div>\n");
result.append("<script type=\"text/javascript\">\n");
result.append("\tstartProgressBar();\n");
result.append("</script>\n");
}
return result.toString();
}
/**
* Returns the width of the progress bar.<p>
*
* @return the width of the progress bar
*/
public String getWidth() {
return m_width;
}
/**
* Sets the color of the progress bar.<p>
*
* @param color the color of the progress bar to set
*/
public void setColor(String color) {
m_color = color;
}
/**
* Sets the name of the JavaScript method to call after progress is finished.<p>
*
* @param jsFinishMethod the name of the JavaScript method to call after progress is finished to set
*/
public void setJsFinishMethod(String jsFinishMethod) {
m_jsFinishMethod = jsFinishMethod;
}
/**
* Sets the refresh rate in ms of the progress bar.<p>
*
* @param refreshRate the refresh rate in ms of the progress bar to set
*/
public void setRefreshRate(int refreshRate) {
m_refreshRate = refreshRate;
}
/**
* Sets the time period the show the wait symbol before the progress bar is shown.<p>
*
* @param showWaitTime the time period the show the wait symbol before the progress bar is shown to set
*/
public void setShowWaitTime(int showWaitTime) {
m_showWaitTime = showWaitTime;
}
/**
* Sets the width of the progress bar.<p>
*
* @param width the width of the progress bar to set
*/
public void setWidth(String width) {
m_width = width;
}
/**
* Starts a thread for the progress on the given list.<p>
*
* @param list the list to use for the progress bar
*/
public void startProgress(A_CmsListDialog list) {
startProgress(list, false);
}
/**
* Starts a thread for the progress on the given list.<p>
*
* @param list the list to use for the progress bar
* @param abortExisting if true then an already existing thread will be killed
*/
public void startProgress(A_CmsListDialog list, boolean abortExisting) {
// check the list
if (list == null) {
throw new CmsIllegalArgumentException(Messages.get().container(Messages.ERR_PROGRESS_START_INVALID_LIST_0));
}
// check if created key already exists
if (m_threads.get(getKey()) != null) {
if (abortExisting) {
if (LOG.isDebugEnabled()) {
LOG.debug(Messages.get().getBundle().key(Messages.LOG_PROGRESS_INTERRUPT_THREAD_1, getKey()));
}
Thread thread = (Thread)m_threads.get(getKey());
thread.interrupt();
} else {
throw new CmsIllegalStateException(
Messages.get().container(Messages.ERR_PROGRESS_START_THREAD_EXISTS_0));
}
}
// start the thread
Thread thread = new CmsProgressThread(list, getKey(), list.getLocale());
m_threads.put(getKey(), thread);
thread.start();
// clean up abandoned threads
Iterator iter = m_threads.entrySet().iterator();
while (iter.hasNext()) {
Map.Entry entry = (Map.Entry)iter.next();
CmsProgressThread value = (CmsProgressThread)entry.getValue();
if ((!thread.isAlive()) && (System.currentTimeMillis() - value.getFinishTime() > CLEANUP_PERIOD)) {
if (LOG.isDebugEnabled()) {
LOG.debug(Messages.get().getBundle().key(Messages.LOG_PROGRESS_CLEAN_UP_THREAD_1, getKey()));
}
m_threads.remove(entry.getKey());
}
}
}
/**
* Creates the html code for the given error message.<p>
*
* @param errorMsg the error message to place in the html code
*
* @return the html code for the error message
*/
private String createError(String errorMsg) {
StringBuffer result = new StringBuffer();
result.append("ERR");
result.append(errorMsg);
return result.toString();
}
/**
* Creates the html code for the given error message and the
* provided Exception.<p>
*
* @param errorMsg the error message to place in the html code
* @param t the exception to add to the error message
*
* @return the html code for the error message
*/
private String createError(String errorMsg, Throwable t) {
StringBuffer msg = new StringBuffer();
msg.append(errorMsg);
msg.append("\n");
msg.append(t.getMessage());
msg.append("\n");
msg.append(CmsException.getStackTraceAsString(t));
return createError(msg.toString());
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -