📄 cmsworkplace.java
字号:
if (CmsStringUtil.isEmpty(style)) {
style = "system";
}
result.append("<link rel=\"stylesheet\" type=\"text/css\" href=\"");
result.append(calendarPath);
result.append("calendar-");
result.append(style);
result.append(".css\">\n");
result.append("<script type=\"text/javascript\" src=\"");
result.append(calendarPath);
result.append("calendar.js\"></script>\n");
result.append("<script type=\"text/javascript\" src=\"");
result.append(calendarPath);
result.append("lang/calendar-");
result.append(getLocale().getLanguage());
result.append(".js\"></script>\n");
result.append("<script type=\"text/javascript\" src=\"");
result.append(calendarPath);
result.append("calendar-setup.js\"></script>\n");
return result.toString();
}
/**
* Initializes a javascript calendar element to be shown on a page.<p>
*
* This method must be called at the end of a HTML page, e.g. before the closing <body> tag.<p>
*
* @param inputFieldId the ID of the input field where the date is pasted to
* @param triggerButtonId the ID of the button which triggers the calendar
* @param align initial position of the calendar popup element
* @param singleClick if true, a single click selects a date and closes the calendar, otherwise calendar is closed by doubleclick
* @param weekNumbers show the week numbers in the calendar or not
* @param mondayFirst show monday as first day of week
* @param dateStatusFunc name of the function which determines if/how a date should be disabled
* @return the HTML code to initialize a calendar poup element
*/
public String calendarInit(
String inputFieldId,
String triggerButtonId,
String align,
boolean singleClick,
boolean weekNumbers,
boolean mondayFirst,
String dateStatusFunc) {
return calendarInit(
inputFieldId,
triggerButtonId,
align,
singleClick,
weekNumbers,
mondayFirst,
dateStatusFunc,
false);
}
/**
* Initializes a javascript calendar element to be shown on a page.<p>
*
* This method must be called at the end of a HTML page, e.g. before the closing <body> tag.<p>
*
* @param inputFieldId the ID of the input field where the date is pasted to
* @param triggerButtonId the ID of the button which triggers the calendar
* @param align initial position of the calendar popup element
* @param singleClick if true, a single click selects a date and closes the calendar, otherwise calendar is closed by doubleclick
* @param weekNumbers show the week numbers in the calendar or not
* @param mondayFirst show monday as first day of week
* @param dateStatusFunc name of the function which determines if/how a date should be disabled
* @param showTime true if the time selector should be shown, otherwise false
* @return the HTML code to initialize a calendar poup element
*/
public String calendarInit(
String inputFieldId,
String triggerButtonId,
String align,
boolean singleClick,
boolean weekNumbers,
boolean mondayFirst,
String dateStatusFunc,
boolean showTime) {
StringBuffer result = new StringBuffer(512);
if (CmsStringUtil.isEmpty(align)) {
align = "Bc";
}
result.append("<script type=\"text/javascript\">\n");
result.append("<!--\n");
result.append("\tCalendar.setup({\n");
result.append("\t\tinputField : \"");
result.append(inputFieldId);
result.append("\",\n");
result.append("\t\tifFormat : \"");
result.append(key(Messages.GUI_CALENDAR_DATE_FORMAT_0));
if (showTime) {
result.append(" ");
result.append(key(Messages.GUI_CALENDAR_TIME_FORMAT_0));
}
result.append("\",\n");
result.append("\t\tbutton : \"");
result.append(triggerButtonId);
result.append("\",\n");
result.append("\t\talign : \"");
result.append(align);
result.append("\",\n");
result.append("\t\tsingleClick : ");
result.append(singleClick);
result.append(",\n");
result.append("\t\tweekNumbers : ");
result.append(weekNumbers);
result.append(",\n");
result.append("\t\tmondayFirst : ");
result.append(mondayFirst);
result.append(",\n");
result.append("\t\tshowsTime : " + showTime);
if (showTime && key(Messages.GUI_CALENDAR_TIMEFORMAT_0).toLowerCase().indexOf("p") != -1) {
result.append(",\n\t\ttimeFormat : \"12\"");
}
if (CmsStringUtil.isNotEmpty(dateStatusFunc)) {
result.append(",\n\t\tdateStatusFunc : ");
result.append(dateStatusFunc);
}
result.append("\n\t});\n");
result.append("//-->\n");
result.append("</script>\n");
return result.toString();
}
/**
* Checks the lock state of the resource and locks it if the autolock feature is enabled.<p>
*
* @param resource the resource name which is checked
* @throws CmsException if reading or locking the resource fails
*/
public void checkLock(String resource) throws CmsException {
checkLock(resource, org.opencms.lock.CmsLock.COMMON);
}
/**
* Checks the lock state of the resource and locks it if the autolock feature is enabled.<p>
*
* @param resource the resource name which is checked
* @param mode flag indicating the mode (temporary or common) of a lock
* @throws CmsException if reading or locking the resource fails
*/
public void checkLock(String resource, int mode) throws CmsException {
CmsResource res = getCms().readResource(resource, CmsResourceFilter.ALL);
CmsLock lock = getCms().getLock(res);
if (OpenCms.getWorkplaceManager().autoLockResources()) {
// autolock is enabled, check the lock state of the resource
if (lock.isNullLock()) {
// resource is not locked, lock it automatically
getCms().lockResource(resource, mode);
} else if (!lock.getUserId().equals(getCms().getRequestContext().currentUser().getId())) {
throw new CmsException(Messages.get().container(Messages.ERR_WORKPLACE_LOCK_RESOURCE_1, resource));
}
} else {
if (lock.isNullLock()
|| (!lock.isNullLock() && !lock.getUserId().equals(getCms().getRequestContext().currentUser().getId()))) {
throw new CmsException(Messages.get().container(Messages.ERR_WORKPLACE_LOCK_RESOURCE_1, resource));
}
}
}
/**
* First sets site and project in the workplace settings, then fills all class parameter values from the data
* provided in the current request.<p>
*
* @param settings the workplace settings
* @param request the current request
*/
public void fillParamValues(CmsWorkplaceSettings settings, HttpServletRequest request) {
initSettings(settings, request);
fillParamValues(request);
}
/**
* Fills all class parameter values from the data provided in the current request.<p>
*
* All methods that start with "setParam" are possible candidates to be
* automatically filled. The remaining part of the method name is converted
* to lower case. Then a parameter of this name is searched in the request parameters.
* If the parameter is found, the "setParam" method is automatically invoked
* by reflection with the value of the parameter.<p>
*
* @param request the current JSP request
*/
public void fillParamValues(HttpServletRequest request) {
m_parameterMap = null;
// ensure a multipart request is pared only once (for "forward" screnarios with reports)
if (null == request.getAttribute(REQUEST_ATTRIBUTE_MULTIPART)) {
// check if this is a multipart request
m_multiPartFileItems = CmsRequestUtil.readMultipartFileItems(request);
if (m_multiPartFileItems != null) {
// this was indeed a multipart form request
m_parameterMap = CmsRequestUtil.readParameterMapFromMultiPart(
getCms().getRequestContext().getEncoding(),
m_multiPartFileItems);
request.setAttribute(REQUEST_ATTRIBUTE_MULTIPART, Boolean.TRUE);
}
}
if (m_parameterMap == null) {
// the request was a "normal" request
m_parameterMap = request.getParameterMap();
}
List methods = paramSetMethods();
Iterator i = methods.iterator();
while (i.hasNext()) {
Method m = (Method)i.next();
String name = m.getName().substring(8).toLowerCase();
String[] values = (String[])m_parameterMap.get(name);
String value = null;
if (values != null) {
// get the parameter value from the map
value = values[0];
}
if (CmsStringUtil.isEmpty(value)) {
value = null;
}
value = decodeParamValue(name, value);
try {
if (LOG.isDebugEnabled() && (value != null)) {
LOG.debug(Messages.get().getBundle().key(Messages.LOG_SET_PARAM_2, m.getName(), value));
}
m.invoke(this, new Object[] {value});
} catch (InvocationTargetException ite) {
// can usually be ignored
if (LOG.isInfoEnabled()) {
LOG.info(ite.getLocalizedMessage());
}
} catch (IllegalAccessException eae) {
// can usually be ignored
if (LOG.isInfoEnabled()) {
LOG.info(eae.getLocalizedMessage());
}
}
}
}
/**
* Returns the message String for the broadcast message alert of the workplace.<p>
*
* Caution: returns the pure message String (not escaped) or null, if no message is pending.<p>
*
* @return the message String for the broadcast message alert of the workplace
*/
public String getBroadcastMessageString() {
String sessionId = getSession().getId();
Buffer messageQueue = OpenCms.getSessionManager().getBroadcastQueue(sessionId);
if (!messageQueue.isEmpty()) {
// create message String
StringBuffer result = new StringBuffer(512);
// the user has pending messages, display them all
while (!messageQueue.isEmpty()) {
CmsBroadcast message = (CmsBroadcast)messageQueue.remove();
result.append('[');
result.append(getMessages().getDateTime(message.getSendTime()));
result.append("] ");
result.append(key(Messages.GUI_LABEL_BROADCASTMESSAGEFROM_0));
result.append(' ');
result.append(message.getUser().getName());
result.append(":\n");
result.append(message.getMessage());
result.append("\n\n");
}
return result.toString();
}
// no message pending, return null
return null;
}
/**
* Creates the time in milliseconds from the given parameter.<p>
*
* @param dateString the String representation of the date
* @param useTime true if the time should be parsed, too, otherwise false
* @return the time in milliseconds
* @throws ParseException if something goes wrong
*/
public long getCalendarDate(String dateString, boolean useTime) throws ParseException {
long dateLong = 0;
// substitute some chars because calendar syntax != DateFormat syntax
String dateFormat = key(Messages.GUI_CALENDAR_DATE_FORMAT_0);
if (useTime) {
dateFormat += " " + key(Messages.GUI_CALENDAR_TIME_FORMAT_0);
}
dateFormat = getCalendarJavaDateFormat(dateFormat);
SimpleDateFormat df = new SimpleDateFormat(dateFormat);
dateLong = df.parse(dateString).getTime();
return dateLong;
}
/**
* Returns the given timestamp as String formatted in a localized pattern.<p>
*
* @param timestamp the time to format
* @return the given timestamp as String formatted in a localized pattern
*/
public String getCalendarLocalizedTime(long timestamp) {
// get the current date & time
Locale locale = getLocale();
TimeZone zone = TimeZone.getDefault();
GregorianCalendar cal = new GregorianCalendar(zone, locale);
cal.setTimeInMillis(timestamp);
// format it nicely according to the localized pattern
DateFormat df = new SimpleDateFormat(getCalendarJavaDateFormat(key(Messages.GUI_CALENDAR_DATE_FORMAT_0)
+ " "
+ key(Messages.GUI_CALENDAR_TIME_FORMAT_0)));
return df.format(cal.getTime());
}
/**
* Returns the initialized cms object for the current user.<p>
*
* @return the initialized cms object for the current user
*/
public CmsObject getCms() {
return m_cms;
}
/**
* Returns the current workplace encoding.<p>
*
* @return the current workplace encoding
*/
public String getEncoding() {
return OpenCms.getWorkplaceManager().getEncoding();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -