0001: /*
0002: * File : $Source: /usr/local/cvs/opencms/src/org/opencms/workplace/CmsWorkplace.java,v $
0003: * Date : $Date: 2008-02-27 12:05:45 $
0004: * Version: $Revision: 1.172 $
0005: *
0006: * This library is part of OpenCms -
0007: * the Open Source Content Management System
0008: *
0009: * Copyright (c) 2002 - 2008 Alkacon Software GmbH (http://www.alkacon.com)
0010: *
0011: * This library is free software; you can redistribute it and/or
0012: * modify it under the terms of the GNU Lesser General Public
0013: * License as published by the Free Software Foundation; either
0014: * version 2.1 of the License, or (at your option) any later version.
0015: *
0016: * This library is distributed in the hope that it will be useful,
0017: * but WITHOUT ANY WARRANTY; without even the implied warranty of
0018: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
0019: * Lesser General Public License for more details.
0020: *
0021: * For further information about Alkacon Software GmbH, please see the
0022: * company website: http://www.alkacon.com
0023: *
0024: * For further information about OpenCms, please see the
0025: * project website: http://www.opencms.org
0026: *
0027: * You should have received a copy of the GNU Lesser General Public
0028: * License along with this library; if not, write to the Free Software
0029: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
0030: */
0031:
0032: package org.opencms.workplace;
0033:
0034: import org.opencms.db.CmsDbEntryNotFoundException;
0035: import org.opencms.db.CmsDriverManager;
0036: import org.opencms.db.CmsUserSettings;
0037: import org.opencms.file.CmsObject;
0038: import org.opencms.file.CmsProject;
0039: import org.opencms.file.CmsRequestContext;
0040: import org.opencms.file.CmsResource;
0041: import org.opencms.file.CmsResourceFilter;
0042: import org.opencms.file.CmsUser;
0043: import org.opencms.i18n.CmsEncoder;
0044: import org.opencms.i18n.CmsMessages;
0045: import org.opencms.i18n.CmsMultiMessages;
0046: import org.opencms.jsp.CmsJspActionElement;
0047: import org.opencms.lock.CmsLock;
0048: import org.opencms.lock.CmsLockType;
0049: import org.opencms.main.CmsBroadcast;
0050: import org.opencms.main.CmsContextInfo;
0051: import org.opencms.main.CmsException;
0052: import org.opencms.main.CmsIllegalStateException;
0053: import org.opencms.main.CmsLog;
0054: import org.opencms.main.CmsSessionInfo;
0055: import org.opencms.main.OpenCms;
0056: import org.opencms.security.CmsPermissionSet;
0057: import org.opencms.security.CmsRole;
0058: import org.opencms.security.CmsRoleViolationException;
0059: import org.opencms.site.CmsSite;
0060: import org.opencms.util.CmsMacroResolver;
0061: import org.opencms.util.CmsRequestUtil;
0062: import org.opencms.util.CmsStringUtil;
0063: import org.opencms.util.CmsUUID;
0064: import org.opencms.workplace.help.CmsHelpTemplateBean;
0065:
0066: import java.io.IOException;
0067: import java.lang.reflect.InvocationTargetException;
0068: import java.lang.reflect.Method;
0069: import java.util.ArrayList;
0070: import java.util.Collection;
0071: import java.util.HashMap;
0072: import java.util.Iterator;
0073: import java.util.List;
0074: import java.util.Locale;
0075: import java.util.Map;
0076:
0077: import javax.servlet.ServletException;
0078: import javax.servlet.http.HttpServletRequest;
0079: import javax.servlet.http.HttpServletResponse;
0080: import javax.servlet.http.HttpSession;
0081: import javax.servlet.jsp.PageContext;
0082:
0083: import org.apache.commons.collections.Buffer;
0084: import org.apache.commons.logging.Log;
0085:
0086: /**
0087: * Master class for the JSP based workplace which provides default methods and
0088: * session handling for all JSP workplace classes.<p>
0089: *
0090: * @author Alexander Kandzior
0091: *
0092: * @version $Revision: 1.172 $
0093: *
0094: * @since 6.0.0
0095: */
0096: public abstract class CmsWorkplace {
0097:
0098: /** The debug flag. */
0099: public static final boolean DEBUG = false;
0100:
0101: /** Parameter for the default locale. */
0102: public static final Locale DEFAULT_LOCALE = Locale.ENGLISH;
0103:
0104: /** Parameter for the default language. */
0105: public static final String DEFAULT_LANGUAGE = DEFAULT_LOCALE
0106: .getLanguage();
0107:
0108: /** Constant for the JSP explorer filelist file. */
0109: public static final String FILE_EXPLORER_FILELIST = CmsWorkplace.VFS_PATH_WORKPLACE
0110: + "views/explorer/explorer_files.jsp";
0111:
0112: /** Helper variable to deliver the html end part. */
0113: public static final int HTML_END = 1;
0114:
0115: /** Helper variable to deliver the html start part. */
0116: public static final int HTML_START = 0;
0117:
0118: /** The request parameter for the workplace project selection. */
0119: public static final String PARAM_WP_EXPLORER_RESOURCE = "wpExplorerResource";
0120:
0121: /** The request parameter for the workplace project selection. */
0122: public static final String PARAM_WP_PROJECT = "wpProject";
0123:
0124: /** The request parameter for the workplace site selection. */
0125: public static final String PARAM_WP_SITE = "wpSite";
0126:
0127: /** Path to system folder. */
0128: public static final String VFS_PATH_SYSTEM = "/system/";
0129:
0130: /** Path to the workplace. */
0131: public static final String VFS_PATH_WORKPLACE = VFS_PATH_SYSTEM
0132: + "workplace/";
0133:
0134: /** Constant for the JSP dialogs path. */
0135: public static final String PATH_DIALOGS = VFS_PATH_WORKPLACE
0136: + "commons/";
0137:
0138: /** Constant for the JSP workplace path. */
0139: public static final String PATH_WORKPLACE = VFS_PATH_WORKPLACE;
0140:
0141: /** Path to exported system image folder. */
0142: public static final String RFS_PATH_RESOURCES = "/resources/";
0143:
0144: /**
0145: * Prefix for temporary files in the VFS.
0146: *
0147: * @see #isTemporaryFile(CmsResource)
0148: * @see #isTemporaryFileName(String)
0149: * @see #getTemporaryFileName(String)
0150: */
0151: public static final String TEMP_FILE_PREFIX = CmsDriverManager.TEMP_FILE_PREFIX;
0152:
0153: /** Directory name of content default_bodies folder. */
0154: public static final String VFS_DIR_DEFAULTBODIES = "default_bodies/";
0155:
0156: /** Directory name of content templates folder. */
0157: public static final String VFS_DIR_TEMPLATES = "templates/";
0158:
0159: /** Path to commons. */
0160: public static final String VFS_PATH_COMMONS = VFS_PATH_WORKPLACE
0161: + "commons/";
0162:
0163: /** Path to the workplace editors. */
0164: public static final String VFS_PATH_EDITORS = VFS_PATH_WORKPLACE
0165: + "editors/";
0166:
0167: /** Path to the galleries. */
0168: public static final String VFS_PATH_GALLERIES = VFS_PATH_SYSTEM
0169: + "galleries/";
0170:
0171: /** Path to locales. */
0172: public static final String VFS_PATH_LOCALES = VFS_PATH_WORKPLACE
0173: + "locales/";
0174:
0175: /** Path to modules folder. */
0176: public static final String VFS_PATH_MODULES = VFS_PATH_SYSTEM
0177: + "modules/";
0178:
0179: /** Path to system image folder. */
0180: public static final String VFS_PATH_RESOURCES = VFS_PATH_WORKPLACE
0181: + "resources/";
0182:
0183: /** Path to workplace views. */
0184: public static final String VFS_PATH_VIEWS = VFS_PATH_WORKPLACE
0185: + "views/";
0186:
0187: /** Constant for the JSP common files (e.g. error page) path. */
0188: public static final String DIALOG_PATH_COMMON = PATH_DIALOGS
0189: + "includes/";
0190:
0191: /** Constant for the JSP common close dialog page. */
0192: public static final String FILE_DIALOG_CLOSE = DIALOG_PATH_COMMON
0193: + "closedialog.jsp";
0194:
0195: /** Constant for the JSP common confirmation dialog. */
0196: public static final String FILE_DIALOG_SCREEN_CONFIRM = DIALOG_PATH_COMMON
0197: + "confirmation.jsp";
0198:
0199: /** Constant for the JSP common error dialog. */
0200: public static final String FILE_DIALOG_SCREEN_ERROR = DIALOG_PATH_COMMON
0201: + "error.jsp";
0202:
0203: /** Constant for the JSP common error dialog. */
0204: public static final String FILE_DIALOG_SCREEN_ERRORPAGE = DIALOG_PATH_COMMON
0205: + "errorpage.jsp";
0206:
0207: /** Constant for the JSP common wait screen. */
0208: public static final String FILE_DIALOG_SCREEN_WAIT = DIALOG_PATH_COMMON
0209: + "wait.jsp";
0210:
0211: /** Constant for the JSP common report page. */
0212: public static final String FILE_REPORT_OUTPUT = DIALOG_PATH_COMMON
0213: + "report.jsp";
0214:
0215: /** Key name for the request attribute to indicate a multipart request was already parsed. */
0216: protected static final String REQUEST_ATTRIBUTE_MULTIPART = "__CmsWorkplace.MULTIPART";
0217:
0218: /** Key name for the request attribute to reload the folder tree view. */
0219: protected static final String REQUEST_ATTRIBUTE_RELOADTREE = "__CmsWorkplace.RELOADTREE";
0220:
0221: /** Key name for the session workplace class. */
0222: protected static final String SESSION_WORKPLACE_CLASS = "__CmsWorkplace.WORKPLACE_CLASS";
0223:
0224: /** The log object for this class. */
0225: private static final Log LOG = CmsLog.getLog(CmsWorkplace.class);
0226:
0227: /** The link to the explorer file list (cached for performance reasons). */
0228: private static String m_file_explorer_filelist;
0229:
0230: /** The URI to the skin resources (cached for performance reasons). */
0231: private static String m_skinUri;
0232:
0233: /** The URI to the stylesheet resources (cached for performance reasons). */
0234: private static String m_styleUri;
0235:
0236: /** The current users OpenCms context. */
0237: private CmsObject m_cms;
0238:
0239: /** Helper variable to store the id of the current project. */
0240: private CmsUUID m_currentProjectId = null;
0241:
0242: /** Flag for indicating that request forwarded was. */
0243: private boolean m_forwarded;
0244:
0245: /** The current JSP action element. */
0246: private CmsJspActionElement m_jsp;
0247:
0248: /** The macro resolver, this is cached to avoid multiple instance generation. */
0249: private CmsMacroResolver m_macroResolver;
0250:
0251: /** The currently used message bundle. */
0252: private CmsMultiMessages m_messages;
0253:
0254: /** The list of multi part file items (if available). */
0255: private List m_multiPartFileItems;
0256:
0257: /** The map of parameters read from the current request. */
0258: private Map m_parameterMap;
0259:
0260: /** The current resource URI. */
0261: private String m_resourceUri;
0262:
0263: /** The current OpenCms users http session. */
0264: private HttpSession m_session;
0265:
0266: /** The current OpenCms users workplace settings. */
0267: private CmsWorkplaceSettings m_settings;
0268:
0269: /**
0270: * Public constructor.<p>
0271: *
0272: * @param jsp the initialized JSP context
0273: */
0274: public CmsWorkplace(CmsJspActionElement jsp) {
0275:
0276: initWorkplaceMembers(jsp);
0277: }
0278:
0279: /**
0280: * Public constructor with JSP variables.<p>
0281: *
0282: * @param context the JSP page context
0283: * @param req the JSP request
0284: * @param res the JSP response
0285: */
0286: public CmsWorkplace(PageContext context, HttpServletRequest req,
0287: HttpServletResponse res) {
0288:
0289: this (new CmsJspActionElement(context, req, res));
0290: }
0291:
0292: /**
0293: * Generates a html select box out of the provided values.<p>
0294: *
0295: * @param parameters a string that will be inserted into the initial select tag,
0296: * if null no parameters will be inserted
0297: * @param options the options
0298: * @param values the option values, if null the select will have no value attributes
0299: * @param selected the index of the pre-selected option, if -1 no option is pre-selected
0300: * @param useLineFeed if true, adds some formatting "\n" to the output String
0301: * @return a String representing a html select box
0302: */
0303: public static String buildSelect(String parameters, List options,
0304: List values, int selected, boolean useLineFeed) {
0305:
0306: StringBuffer result = new StringBuffer(1024);
0307: result.append("<select ");
0308: if (parameters != null) {
0309: result.append(parameters);
0310: }
0311: result.append(">");
0312: if (useLineFeed) {
0313: result.append("\n");
0314: }
0315: int length = options.size();
0316: String value = null;
0317: for (int i = 0; i < length; i++) {
0318: if (values != null) {
0319: try {
0320: value = (String) values.get(i);
0321: } catch (Exception e) {
0322: // can usually be ignored
0323: if (LOG.isInfoEnabled()) {
0324: LOG.info(e.getLocalizedMessage());
0325: }
0326: // lists are not properly initialized, just don't use the value
0327: value = null;
0328: }
0329: }
0330: if (value == null) {
0331: result.append("<option");
0332: if (i == selected) {
0333: result.append(" selected=\"selected\"");
0334: }
0335: result.append(">");
0336: result.append(options.get(i));
0337: result.append("</option>");
0338: if (useLineFeed) {
0339: result.append("\n");
0340: }
0341: } else {
0342: result.append("<option value=\"");
0343: result.append(value);
0344: result.append("\"");
0345: if (i == selected) {
0346: result.append(" selected=\"selected\"");
0347: }
0348: result.append(">");
0349: result.append(options.get(i));
0350: result.append("</option>");
0351: if (useLineFeed) {
0352: result.append("\n");
0353: }
0354: }
0355: }
0356: result.append("</select>");
0357: if (useLineFeed) {
0358: result.append("\n");
0359: }
0360: return result.toString();
0361: }
0362:
0363: /**
0364: * Returns the full Workplace resource path to the selected resource.<p>
0365: *
0366: * @param resourceName the name of the resource to get the resource path for
0367: *
0368: * @return the full Workplace resource path to the selected resource
0369: */
0370: public static String getResourceUri(String resourceName) {
0371:
0372: StringBuffer result = new StringBuffer(256);
0373: result.append(getSkinUri());
0374: result.append(resourceName);
0375: return result.toString();
0376: }
0377:
0378: /**
0379: * Returns the path to the skin resources.<p>
0380: *
0381: * @return the path to the skin resources
0382: */
0383: public static String getSkinUri() {
0384:
0385: if (m_skinUri == null) {
0386: m_skinUri = OpenCms.getSystemInfo().getContextPath()
0387: + RFS_PATH_RESOURCES;
0388: }
0389: return m_skinUri;
0390: }
0391:
0392: /**
0393: * Returns the path to the cascading stylesheets.<p>
0394: *
0395: * @param jsp the JSP context
0396: * @return the path to the cascading stylesheets
0397: */
0398: public static String getStyleUri(CmsJspActionElement jsp) {
0399:
0400: if (m_styleUri == null) {
0401:
0402: CmsProject project = jsp.getCmsObject().getRequestContext()
0403: .currentProject();
0404: try {
0405: jsp.getCmsObject().getRequestContext()
0406: .setCurrentProject(
0407: jsp.getCmsObject().readProject(
0408: CmsProject.ONLINE_PROJECT_ID));
0409: m_styleUri = jsp
0410: .link("/system/workplace/commons/style/");
0411: } catch (CmsException e) {
0412: LOG.error(e.getLocalizedMessage());
0413: } finally {
0414: jsp.getCmsObject().getRequestContext()
0415: .setCurrentProject(project);
0416: }
0417: }
0418: return m_styleUri;
0419: }
0420:
0421: /**
0422: * Returns the path to the cascading stylesheets.<p>
0423: *
0424: * @param jsp the JSP context
0425: * @param filename the name of the stylesheet
0426: * @return the path to the cascading stylesheets
0427: */
0428: public static String getStyleUri(CmsJspActionElement jsp,
0429: String filename) {
0430:
0431: if (m_styleUri == null) {
0432: CmsProject project = jsp.getCmsObject().getRequestContext()
0433: .currentProject();
0434: try {
0435: jsp.getCmsObject().getRequestContext()
0436: .setCurrentProject(
0437: jsp.getCmsObject().readProject(
0438: CmsProject.ONLINE_PROJECT_ID));
0439: m_styleUri = jsp
0440: .link("/system/workplace/commons/style/");
0441: } catch (CmsException e) {
0442: if (LOG.isErrorEnabled()) {
0443: LOG.error(e.getLocalizedMessage(), e);
0444: }
0445: } finally {
0446: jsp.getCmsObject().getRequestContext()
0447: .setCurrentProject(project);
0448: }
0449: }
0450: return m_styleUri + filename;
0451: }
0452:
0453: /**
0454: * Returns the temporary file name for the given resource name.<p>
0455: *
0456: * To create a temporary file name of a resource name, the prefix char <code>'~'</code> (tilde)
0457: * is added to the file name after all parent folder names have been removed.<p>
0458: *
0459: * @param resourceName the resource name to return the temporary file name for
0460: *
0461: * @return the temporary file name for the given resource name
0462: *
0463: * @see #isTemporaryFileName(String)
0464: * @see #isTemporaryFile(CmsResource)
0465: */
0466: public static String getTemporaryFileName(String resourceName) {
0467:
0468: if (resourceName == null) {
0469: return null;
0470: }
0471: StringBuffer result = new StringBuffer(
0472: resourceName.length() + 2);
0473: result.append(CmsResource.getFolderPath(resourceName));
0474: result.append(TEMP_FILE_PREFIX);
0475: result.append(CmsResource.getName(resourceName));
0476: return result.toString();
0477: }
0478:
0479: /**
0480: * Updates the user settings in the given workplace settings for the current user, reading the user settings
0481: * from the database if required.<p>
0482: *
0483: * @param cms the cms object for the current user
0484: * @param settings the workplace settings to update (if <code>null</code> a new instance is created)
0485: * @param update flag indicating if settings are only updated (user preferences)
0486: *
0487: * @return the current users workplace settings
0488: *
0489: * @see #initWorkplaceSettings(CmsObject, CmsWorkplaceSettings, boolean)
0490: */
0491: public static CmsWorkplaceSettings initUserSettings(CmsObject cms,
0492: CmsWorkplaceSettings settings, boolean update) {
0493:
0494: if (settings == null) {
0495: settings = new CmsWorkplaceSettings();
0496: }
0497:
0498: // save current workplace user & user settings object
0499: CmsUser user;
0500: if (update) {
0501: try {
0502: // read the user from db to get the latest user information if required
0503: user = cms.readUser(cms.getRequestContext()
0504: .currentUser().getId());
0505: } catch (CmsException e) {
0506: // can usually be ignored
0507: if (LOG.isInfoEnabled()) {
0508: LOG.info(e.getLocalizedMessage());
0509: }
0510: user = cms.getRequestContext().currentUser();
0511: }
0512: } else {
0513: user = cms.getRequestContext().currentUser();
0514: }
0515: // store the user and it's settings in the Workplace settings
0516: settings.setUser(user);
0517: settings.setUserSettings(new CmsUserSettings(user));
0518:
0519: // return the result settings
0520: return settings;
0521: }
0522:
0523: /**
0524: * Updates the given workplace settings, also re-initializing
0525: * the state of the Workplace to the users preferences (for example setting the startup site and project).
0526: *
0527: * The user settings will also be updated by calling <code>{@link #initUserSettings(CmsObject, CmsWorkplaceSettings, boolean)}</code>
0528: * before updating the workplace project, selected site etc.<p>
0529: *
0530: * @param cms the cms object for the current user
0531: * @param settings the workplace settings to update (if <code>null</code> a new instance is created)
0532: * @param update flag indicating if settings are only updated (user preferences)
0533: *
0534: * @return the current users initialized workplace settings
0535: *
0536: * @see #initUserSettings(CmsObject, CmsWorkplaceSettings, boolean)
0537: */
0538: public static synchronized CmsWorkplaceSettings initWorkplaceSettings(
0539: CmsObject cms, CmsWorkplaceSettings settings, boolean update) {
0540:
0541: // init the workplace user settings
0542: settings = initUserSettings(cms, settings, update);
0543:
0544: // save current project
0545: settings.setProject(cms.getRequestContext().currentProject()
0546: .getUuid());
0547:
0548: // switch to users preferred site
0549: String siteRoot = settings.getUserSettings().getStartSite();
0550: if (siteRoot.endsWith("/")) {
0551: // remove trailing slash
0552: siteRoot = siteRoot.substring(0, siteRoot.length() - 1);
0553: }
0554: if (CmsStringUtil.isNotEmpty(siteRoot)
0555: && (OpenCms.getSiteManager().getSiteForSiteRoot(
0556: siteRoot) == null)) {
0557: // this is not the root site and the site is not in the list
0558: siteRoot = OpenCms.getWorkplaceManager()
0559: .getDefaultUserSettings().getStartSite();
0560: if (siteRoot.endsWith("/")) {
0561: // remove trailing slash
0562: siteRoot = siteRoot.substring(0, siteRoot.length() - 1);
0563: }
0564: }
0565: boolean access = false;
0566: CmsResource res = null;
0567: try {
0568: // check access to the site
0569: res = cms.readResource("/");
0570: access = cms.hasPermissions(res,
0571: CmsPermissionSet.ACCESS_VIEW, false,
0572: CmsResourceFilter.ONLY_VISIBLE);
0573: } catch (CmsException e) {
0574: // error reading site root, in this case we will use a readable default
0575: if (LOG.isInfoEnabled()) {
0576: LOG.info(e.getLocalizedMessage(), e);
0577: }
0578: }
0579: if ((res == null) || !access) {
0580: List sites = OpenCms.getSiteManager().getAvailableSites(
0581: cms, true);
0582: if (sites.size() > 0) {
0583: siteRoot = ((CmsSite) sites.get(0)).getSiteRoot();
0584: cms.getRequestContext().setSiteRoot(siteRoot);
0585: }
0586: }
0587: // set the current site
0588: settings.setSite(siteRoot);
0589:
0590: // set the preferred folder to display
0591: settings.setExplorerResource(settings.getUserSettings()
0592: .getStartFolder());
0593:
0594: // get the default view from the user settings
0595: settings.setViewUri(OpenCms.getLinkManager().substituteLink(
0596: cms, settings.getUserSettings().getStartView()));
0597:
0598: return settings;
0599: }
0600:
0601: /**
0602: * Returns <code>true</code> if the given resource is a temporary file.<p>
0603: *
0604: * A resource is considered a temporary file it is a file where the
0605: * {@link CmsResource#FLAG_TEMPFILE} flag has been set, or if the file name (without parent folders)
0606: * starts with the prefix char <code>'~'</code> (tilde).<p>
0607: *
0608: * @param resource the resource name to check
0609: *
0610: * @return <code>true</code> if the given resource name is a temporary file
0611: *
0612: * @see #getTemporaryFileName(String)
0613: * @see #isTemporaryFileName(String)
0614: */
0615: public static boolean isTemporaryFile(CmsResource resource) {
0616:
0617: return (resource != null)
0618: && ((resource.isFile() && (((resource.getFlags() & CmsResource.FLAG_TEMPFILE) > 0) || (isTemporaryFileName(resource
0619: .getName())))));
0620: }
0621:
0622: /**
0623: * Returns <code>true</code> if the given resource name is a temporary file name.<p>
0624: *
0625: * A resource name is considered a temporary file name if the name of the file
0626: * (without parent folders) starts with the prefix char <code>'~'</code> (tilde).<p>
0627: *
0628: * @param resourceName the resource name to check
0629: *
0630: * @return <code>true</code> if the given resource name is a temporary file name
0631: *
0632: * @see #getTemporaryFileName(String)
0633: * @see #isTemporaryFile(CmsResource)
0634: */
0635: public static boolean isTemporaryFileName(String resourceName) {
0636:
0637: return (resourceName != null)
0638: && (CmsResource.getName(resourceName)
0639: .startsWith(TEMP_FILE_PREFIX));
0640: }
0641:
0642: /**
0643: * Stores the settings in the given session.<p>
0644: *
0645: * @param session the session to store the settings in
0646: * @param settings the settings
0647: */
0648: static void storeSettings(HttpSession session,
0649: CmsWorkplaceSettings settings) {
0650:
0651: // save the workplace settings in the session
0652: session.setAttribute(
0653: CmsWorkplaceManager.SESSION_WORKPLACE_SETTINGS,
0654: settings);
0655: }
0656:
0657: /**
0658: * Returns all parameters of the current workplace class
0659: * as hidden field tags that can be inserted in a form.<p>
0660: *
0661: * @return all parameters of the current workplace class
0662: * as hidden field tags that can be inserted in a html form
0663: */
0664: public String allParamsAsHidden() {
0665:
0666: StringBuffer result = new StringBuffer(512);
0667: Map params = allParamValues();
0668: Iterator i = params.entrySet().iterator();
0669: while (i.hasNext()) {
0670: Map.Entry entry = (Map.Entry) i.next();
0671: result.append("<input type=\"hidden\" name=\"");
0672: result.append(entry.getKey());
0673: result.append("\" value=\"");
0674: String encoded = CmsEncoder.encode(entry.getValue()
0675: .toString(), getCms().getRequestContext()
0676: .getEncoding());
0677: result.append(encoded);
0678: result.append("\">\n");
0679: }
0680: return result.toString();
0681: }
0682:
0683: /**
0684: * Returns all present request parameters as String.<p>
0685: *
0686: * The String is formatted as a parameter String (<code>param1=val1&param2=val2</code>) with UTF-8 encoded values.<p>
0687: *
0688: * @return all present request parameters as String
0689: */
0690: public String allParamsAsRequest() {
0691:
0692: StringBuffer retValue = new StringBuffer(512);
0693: HttpServletRequest request = getJsp().getRequest();
0694: Iterator paramNames = request.getParameterMap().keySet()
0695: .iterator();
0696: while (paramNames.hasNext()) {
0697: String paramName = (String) paramNames.next();
0698: String paramValue = request.getParameter(paramName);
0699: retValue.append(paramName
0700: + "="
0701: + CmsEncoder.encode(paramValue, getCms()
0702: .getRequestContext().getEncoding()));
0703: if (paramNames.hasNext()) {
0704: retValue.append("&");
0705: }
0706: }
0707: return retValue.toString();
0708: }
0709:
0710: /**
0711: * Builds the end html of the body.<p>
0712: *
0713: * @return the end html of the body
0714: */
0715: public String bodyEnd() {
0716:
0717: return pageBody(HTML_END, null, null);
0718: }
0719:
0720: /**
0721: * Builds the start html of the body.<p>
0722: *
0723: * @param className optional class attribute to add to the body tag
0724: * @return the start html of the body
0725: */
0726: public String bodyStart(String className) {
0727:
0728: return pageBody(HTML_START, className, null);
0729: }
0730:
0731: /**
0732: * Builds the start html of the body.<p>
0733: *
0734: * @param className optional class attribute to add to the body tag
0735: * @param parameters optional parameters to add to the body tag
0736: * @return the start html of the body
0737: */
0738: public String bodyStart(String className, String parameters) {
0739:
0740: return pageBody(HTML_START, className, parameters);
0741: }
0742:
0743: /**
0744: * Generates a html select box out of the provided values.<p>
0745: *
0746: * @param parameters a string that will be inserted into the initial select tag,
0747: * if null no parameters will be inserted
0748: * @param options the options
0749: * @param values the option values, if null the select will have no value attributes
0750: * @param selected the index of the pre-selected option, if -1 no option is pre-selected
0751: * @return a formatted html String representing a html select box
0752: */
0753: public String buildSelect(String parameters, List options,
0754: List values, int selected) {
0755:
0756: return buildSelect(parameters, options, values, selected, true);
0757: }
0758:
0759: /**
0760: * Generates a button for the OpenCms workplace.<p>
0761: *
0762: * @param href the href link for the button, if none is given the button will be disabled
0763: * @param target the href link target for the button, if none is given the target will be same window
0764: * @param image the image name for the button, skin path will be automattically added as prefix
0765: * @param label the label for the text of the button
0766: * @param type 0: image only (default), 1: image and text, 2: text only
0767: *
0768: * @return a button for the OpenCms workplace
0769: */
0770: public String button(String href, String target, String image,
0771: String label, int type) {
0772:
0773: return button(href, target, image, label, type, getSkinUri()
0774: + "buttons/");
0775: }
0776:
0777: /**
0778: * Generates a button for the OpenCms workplace.<p>
0779: *
0780: * @param href the href link for the button, if none is given the button will be disabled
0781: * @param target the href link target for the button, if none is given the target will be same window
0782: * @param image the image name for the button, skin path will be automattically added as prefix
0783: * @param label the label for the text of the button
0784: * @param type 0: image only (default), 1: image and text, 2: text only
0785: * @param imagePath the path to the image
0786: *
0787: * @return a button for the OpenCms workplace
0788: */
0789: public String button(String href, String target, String image,
0790: String label, int type, String imagePath) {
0791:
0792: StringBuffer result = new StringBuffer(256);
0793:
0794: String anchorStart = "<a href=\"";
0795: if ((href != null)
0796: && href.toLowerCase().startsWith("javascript:")) {
0797: anchorStart = "<a href=\"#\" onclick=\"";
0798: }
0799:
0800: result.append("<td style=\"vertical-align: top;\">");
0801: switch (type) {
0802: case 1:
0803: // image and text
0804: if (href != null) {
0805: result.append(anchorStart);
0806: result.append(href);
0807: result.append("\" class=\"button\"");
0808: if (target != null) {
0809: result.append(" target=\"");
0810: result.append(target);
0811: result.append("\"");
0812: }
0813: result.append(">");
0814: }
0815: result.append("<span unselectable=\"on\" ");
0816: if (href != null) {
0817: result
0818: .append("class=\"norm\" onmouseover=\"className='over'\" onmouseout=\"className='norm'\" onmousedown=\"className='push'\" onmouseup=\"className='over'\"");
0819: } else {
0820: result.append("class=\"disabled\"");
0821: }
0822: result
0823: .append("><span unselectable=\"on\" class=\"combobutton\" ");
0824: result.append("style=\"background-image: url('");
0825: result.append(imagePath);
0826: result.append(image);
0827: if ((image != null) && (image.indexOf('.') == -1)) {
0828: // append default suffix for button images
0829: result.append(".png");
0830: }
0831: result.append("');\">");
0832: result.append(shortKey(label));
0833: result.append("</span></span>");
0834: if (href != null) {
0835: result.append("</a>");
0836: }
0837: break;
0838:
0839: case 2:
0840: // text only
0841: if (href != null) {
0842: result.append(anchorStart);
0843: result.append(href);
0844: result.append("\" class=\"button\"");
0845: if (target != null) {
0846: result.append(" target=\"");
0847: result.append(target);
0848: result.append("\"");
0849: }
0850: result.append(">");
0851: }
0852: result.append("<span unselectable=\"on\" ");
0853: if (href != null) {
0854: result
0855: .append("class=\"norm\" onmouseover=\"className='over'\" onmouseout=\"className='norm'\" onmousedown=\"className='push'\" onmouseup=\"className='over'\"");
0856: } else {
0857: result.append("class=\"disabled\"");
0858: }
0859: result
0860: .append("><span unselectable=\"on\" class=\"txtbutton\">");
0861: result.append(shortKey(label));
0862: result.append("</span></span>");
0863: if (href != null) {
0864: result.append("</a>");
0865: }
0866: break;
0867:
0868: default:
0869: // only image
0870: if (href != null) {
0871: result.append(anchorStart);
0872: result.append(href);
0873: result.append("\" class=\"button\"");
0874: if (target != null) {
0875: result.append(" target=\"");
0876: result.append(target);
0877: result.append("\"");
0878: }
0879: result.append(" title=\"");
0880: result.append(key(label));
0881: result.append("\">");
0882: }
0883: result.append("<span unselectable=\"on\" ");
0884: if (href != null) {
0885: result
0886: .append("class=\"norm\" onmouseover=\"className='over'\" onmouseout=\"className='norm'\" onmousedown=\"className='push'\" onmouseup=\"className='over'\"");
0887: } else {
0888: result.append("class=\"disabled\"");
0889: }
0890: result.append("><img class=\"button\" src=\"");
0891: result.append(imagePath);
0892: result.append(image);
0893: if ((image != null) && (image.indexOf('.') == -1)) {
0894: // append default suffix for button images
0895: result.append(".png");
0896: }
0897: result.append("\" alt=\"");
0898: result.append(key(label));
0899: result.append("\">");
0900: result.append("</span>");
0901: if (href != null) {
0902: result.append("</a>");
0903: }
0904: break;
0905: }
0906: result.append("</td>\n");
0907: return result.toString();
0908: }
0909:
0910: /**
0911: * Returns the html for a button bar.<p>
0912: *
0913: * @param segment the HTML segment (START / END)
0914: *
0915: * @return a button bar html start / end segment
0916: */
0917: public String buttonBar(int segment) {
0918:
0919: return buttonBar(segment, null);
0920: }
0921:
0922: /**
0923: * Returns the html for a button bar.<p>
0924: *
0925: * @param segment the HTML segment (START / END)
0926: * @param attributes optional attributes for the table tag
0927: *
0928: * @return a button bar html start / end segment
0929: */
0930: public String buttonBar(int segment, String attributes) {
0931:
0932: if (segment == HTML_START) {
0933: String result = "<table cellpadding=\"0\" cellspacing=\"0\" border=\"0\"";
0934: if (attributes != null) {
0935: result += " " + attributes;
0936: }
0937: return result + "><tr>\n";
0938: } else {
0939: return "</tr></table>";
0940: }
0941: }
0942:
0943: /**
0944: * Generates a horizontal button bar separator line with maximum width.<p>
0945: *
0946: * @return a horizontal button bar separator line
0947: */
0948: public String buttonBarHorizontalLine() {
0949:
0950: StringBuffer result = new StringBuffer(256);
0951: result
0952: .append("<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" class=\"maxwidth\">\n");
0953: result.append("<tr>\n");
0954: result.append("\t<td class=\"horseparator\" ><img src=\"");
0955: result.append(getSkinUri());
0956: result
0957: .append("tree/empty.gif\" border=\"0\" width=\"1\" height=\"1\" alt=\"\"></td>\n");
0958: result.append("</tr>\n");
0959: result.append("</table>\n");
0960: return result.toString();
0961: }
0962:
0963: /**
0964: * Generates a button bar label.<p>
0965: *
0966: * @param label the label to show
0967: *
0968: * @return a button bar label
0969: */
0970: public String buttonBarLabel(String label) {
0971:
0972: return buttonBarLabel(label, "norm");
0973: }
0974:
0975: /**
0976: * Generates a button bar label.<p>
0977: *
0978: * @param label the label to show
0979: * @param className the css class name for the formatting
0980: *
0981: * @return a button bar label
0982: */
0983: public String buttonBarLabel(String label, String className) {
0984:
0985: StringBuffer result = new StringBuffer(128);
0986: result.append("<td><span class=\"");
0987: result.append(className);
0988: result
0989: .append("\"><span unselectable=\"on\" class=\"txtbutton\">");
0990: result.append(key(label));
0991: result.append("</span></span></td>\n");
0992: return result.toString();
0993: }
0994:
0995: /**
0996: * Generates a variable button bar separator line.<p>
0997: *
0998: * @param leftPixel the amount of pixel left to the line
0999: * @param rightPixel the amount of pixel right to the line
1000: * @param className the css class name for the formatting
1001: *
1002: * @return a variable button bar separator line
1003: */
1004: public String buttonBarLine(int leftPixel, int rightPixel,
1005: String className) {
1006:
1007: StringBuffer result = new StringBuffer(512);
1008: if (leftPixel > 0) {
1009: result.append(buttonBarLineSpacer(leftPixel));
1010: }
1011: result.append("<td><span class=\"");
1012: result.append(className);
1013: result.append("\"></span></td>\n");
1014: if (rightPixel > 0) {
1015: result.append(buttonBarLineSpacer(rightPixel));
1016: }
1017: return result.toString();
1018: }
1019:
1020: /**
1021: * Generates a variable button bar separator line spacer.<p>
1022: *
1023: * @param pixel the amount of pixel space
1024: *
1025: * @return a variable button bar separator line spacer
1026: */
1027: public String buttonBarLineSpacer(int pixel) {
1028:
1029: StringBuffer result = new StringBuffer(128);
1030: result
1031: .append("<td><span class=\"norm\"><span unselectable=\"on\" class=\"txtbutton\" style=\"padding-right: 0px; padding-left: ");
1032: result.append(pixel);
1033: result.append("px;\"></span></span></td>\n");
1034: return result.toString();
1035: }
1036:
1037: /**
1038: * Generates a button bar separator.<p>
1039: *
1040: * @param leftPixel the amount of pixel left to the separator
1041: * @param rightPixel the amount of pixel right to the separator
1042: *
1043: * @return a button bar separator
1044: */
1045: public String buttonBarSeparator(int leftPixel, int rightPixel) {
1046:
1047: return buttonBarLine(leftPixel, rightPixel, "separator");
1048: }
1049:
1050: /**
1051: * Returns the html for an invisible spacer between button bar contents like buttons, labels, etc.<p>
1052: *
1053: * @param width the width of the invisible spacer
1054: * @return the html for the invisible spacer
1055: */
1056: public String buttonBarSpacer(int width) {
1057:
1058: StringBuffer result = new StringBuffer(128);
1059: result
1060: .append("<td><span class=\"norm\"><span unselectable=\"on\" class=\"txtbutton\" style=\"width: ");
1061: result.append(width);
1062: result.append("px;\"></span></span></td>\n");
1063: return result.toString();
1064: }
1065:
1066: /**
1067: * Generates a button bar starter tab.<p>
1068: *
1069: * @param leftPixel the amount of pixel left to the starter
1070: * @param rightPixel the amount of pixel right to the starter
1071: *
1072: * @return a button bar starter tab
1073: */
1074: public String buttonBarStartTab(int leftPixel, int rightPixel) {
1075:
1076: StringBuffer result = new StringBuffer(512);
1077: result.append(buttonBarLineSpacer(leftPixel));
1078: result
1079: .append("<td><span class=\"starttab\"><span style=\"width:1px; height:1px\"></span></span></td>\n");
1080: result.append(buttonBarLineSpacer(rightPixel));
1081: return result.toString();
1082: }
1083:
1084: /**
1085: * Checks the lock state of the resource and locks it if the autolock feature is enabled.<p>
1086: *
1087: * @param resource the resource name which is checked
1088: * @throws CmsException if reading or locking the resource fails
1089: */
1090: public void checkLock(String resource) throws CmsException {
1091:
1092: checkLock(resource, CmsLockType.EXCLUSIVE);
1093: }
1094:
1095: /**
1096: * Checks the lock state of the resource and locks it if the autolock feature is enabled.<p>
1097: *
1098: * @param resource the resource name which is checked
1099: * @param type indicates the mode {@link CmsLockType#EXCLUSIVE} or {@link CmsLockType#TEMPORARY}
1100: *
1101: * @throws CmsException if reading or locking the resource fails
1102: */
1103: public void checkLock(String resource, CmsLockType type)
1104: throws CmsException {
1105:
1106: CmsResource res = getCms().readResource(resource,
1107: CmsResourceFilter.ALL);
1108: CmsLock lock = getCms().getLock(res);
1109: boolean lockable = lock.isLockableBy(getCms()
1110: .getRequestContext().currentUser());
1111:
1112: if (OpenCms.getWorkplaceManager().autoLockResources()) {
1113: // autolock is enabled, check the lock state of the resource
1114: if (lockable) {
1115: // resource is lockable, so lock it automatically
1116: if (type == CmsLockType.TEMPORARY) {
1117: getCms().lockResourceTemporary(resource);
1118: } else {
1119: getCms().lockResource(resource);
1120: }
1121: } else {
1122: throw new CmsException(Messages.get().container(
1123: Messages.ERR_WORKPLACE_LOCK_RESOURCE_1,
1124: resource));
1125: }
1126: } else {
1127: if (!lockable) {
1128: throw new CmsException(Messages.get().container(
1129: Messages.ERR_WORKPLACE_LOCK_RESOURCE_1,
1130: resource));
1131: }
1132: }
1133: }
1134:
1135: /**
1136: * First sets site and project in the workplace settings, then fills all class parameter values from the data
1137: * provided in the current request.<p>
1138: *
1139: * @param settings the workplace settings
1140: * @param request the current request
1141: */
1142: public void fillParamValues(CmsWorkplaceSettings settings,
1143: HttpServletRequest request) {
1144:
1145: initSettings(settings, request);
1146: fillParamValues(request);
1147: }
1148:
1149: /**
1150: * Fills all class parameter values from the data provided in the current request.<p>
1151: *
1152: * All methods that start with "setParam" are possible candidates to be
1153: * automatically filled. The remaining part of the method name is converted
1154: * to lower case. Then a parameter of this name is searched in the request parameters.
1155: * If the parameter is found, the "setParam" method is automatically invoked
1156: * by reflection with the value of the parameter.<p>
1157: *
1158: * @param request the current JSP request
1159: */
1160: public void fillParamValues(HttpServletRequest request) {
1161:
1162: m_parameterMap = null;
1163: // ensure a multipart request is parsed only once (for "forward" scenarios with reports)
1164: if (null == request.getAttribute(REQUEST_ATTRIBUTE_MULTIPART)) {
1165: // check if this is a multipart request
1166: m_multiPartFileItems = CmsRequestUtil
1167: .readMultipartFileItems(request);
1168: if (m_multiPartFileItems != null) {
1169: // this was indeed a multipart form request
1170: m_parameterMap = CmsRequestUtil
1171: .readParameterMapFromMultiPart(getCms()
1172: .getRequestContext().getEncoding(),
1173: m_multiPartFileItems);
1174: request.setAttribute(REQUEST_ATTRIBUTE_MULTIPART,
1175: Boolean.TRUE);
1176: }
1177: }
1178: if (m_parameterMap == null) {
1179: // the request was a "normal" request
1180: m_parameterMap = request.getParameterMap();
1181: }
1182:
1183: List methods = paramSetMethods();
1184: Iterator i = methods.iterator();
1185: while (i.hasNext()) {
1186: Method m = (Method) i.next();
1187: String name = m.getName().substring(8).toLowerCase();
1188: String[] values = (String[]) m_parameterMap.get(name);
1189: String value = null;
1190: if (values != null) {
1191: // get the parameter value from the map
1192: value = values[0];
1193: }
1194: if (CmsStringUtil.isEmpty(value)) {
1195: value = null;
1196: }
1197:
1198: // TODO: this is very dangerous since most of the dialogs does not send encoded data
1199: // and by decoding not encoded data the data will get corrupted, for instance '1+2' will become '1 2'.
1200: // we should ensure that we decode the data only if the data has been encoded
1201: value = decodeParamValue(name, value);
1202: try {
1203: if (LOG.isDebugEnabled() && (value != null)) {
1204: LOG.debug(Messages.get().getBundle().key(
1205: Messages.LOG_SET_PARAM_2, m.getName(),
1206: value));
1207: }
1208: m.invoke(this , new Object[] { value });
1209: } catch (InvocationTargetException ite) {
1210: // can usually be ignored
1211: if (LOG.isInfoEnabled()) {
1212: LOG.info(ite.getLocalizedMessage());
1213: }
1214: } catch (IllegalAccessException eae) {
1215: // can usually be ignored
1216: if (LOG.isInfoEnabled()) {
1217: LOG.info(eae.getLocalizedMessage());
1218: }
1219: }
1220: }
1221: }
1222:
1223: /**
1224: * Returns the message String for the broadcast message alert of the workplace.<p>
1225: *
1226: * Caution: returns the pure message String (not escaped) or null, if no message is pending.<p>
1227: *
1228: * @return the message String for the broadcast message alert of the workplace
1229: */
1230: public String getBroadcastMessageString() {
1231:
1232: CmsSessionInfo sessionInfo = OpenCms.getSessionManager()
1233: .getSessionInfo(getSession());
1234: if (sessionInfo == null) {
1235: return null;
1236: }
1237: String sessionId = sessionInfo.getSessionId().toString();
1238: Buffer messageQueue = OpenCms.getSessionManager()
1239: .getBroadcastQueue(sessionId);
1240: if (!messageQueue.isEmpty()) {
1241: // create message String
1242: StringBuffer result = new StringBuffer(512);
1243: // the user has pending messages, display them all
1244: while (!messageQueue.isEmpty()) {
1245: CmsBroadcast message = (CmsBroadcast) messageQueue
1246: .remove();
1247: result.append('[');
1248: result.append(getMessages().getDateTime(
1249: message.getSendTime()));
1250: result.append("] ");
1251: result
1252: .append(key(Messages.GUI_LABEL_BROADCASTMESSAGEFROM_0));
1253: result.append(' ');
1254: if (message.getUser() != null) {
1255: result.append(message.getUser().getName());
1256: } else {
1257: // system message
1258: result
1259: .append(key(Messages.GUI_LABEL_BROADCAST_FROM_SYSTEM_0));
1260: }
1261: result.append(":\n");
1262: result.append(message.getMessage());
1263: result.append("\n\n");
1264: }
1265: return result.toString();
1266: }
1267: // no message pending, return null
1268: return null;
1269: }
1270:
1271: /**
1272: * Returns the initialized cms object for the current user.<p>
1273: *
1274: * @return the initialized cms object for the current user
1275: */
1276: public CmsObject getCms() {
1277:
1278: return m_cms;
1279: }
1280:
1281: /**
1282: * Returns the current workplace encoding.<p>
1283: *
1284: * @return the current workplace encoding
1285: */
1286: public String getEncoding() {
1287:
1288: return OpenCms.getWorkplaceManager().getEncoding();
1289: }
1290:
1291: /**
1292: * Returns the uri (including context path) to the explorer file list.<p>
1293: *
1294: * @return the uri (including context path) to the explorer file list
1295: */
1296: public String getExplorerFileListFullUri() {
1297:
1298: if (m_file_explorer_filelist != null) {
1299: return m_file_explorer_filelist;
1300: }
1301: synchronized (this ) {
1302: m_file_explorer_filelist = OpenCms.getLinkManager()
1303: .substituteLink(getCms(), FILE_EXPLORER_FILELIST);
1304: }
1305: return m_file_explorer_filelist;
1306: }
1307:
1308: /**
1309: * Returns the html for the frame name and source and stores this information in the workplace settings.<p>
1310: *
1311: * @param frameName the name of the frame
1312: * @param uri the absolute path of the frame
1313: * @return the html for the frame name and source
1314: */
1315: public String getFrameSource(String frameName, String uri) {
1316:
1317: String frameString = "name=\"" + frameName + "\" src=\"" + uri
1318: + "\"";
1319: int paramIndex = uri.indexOf("?");
1320: if (paramIndex != -1) {
1321: // remove request parameters from URI before putting it to Map
1322: uri = uri.substring(0, uri.indexOf("?"));
1323: }
1324: getSettings().getFrameUris().put(frameName, uri);
1325: return frameString;
1326: }
1327:
1328: /**
1329: * Returns the JSP action element.<p>
1330: *
1331: * @return the JSP action element
1332: */
1333: public CmsJspActionElement getJsp() {
1334:
1335: return m_jsp;
1336: }
1337:
1338: /**
1339: * Returns the current users workplace locale settings.<p>
1340: *
1341: * @return the current users workplace locale setting
1342: */
1343: public Locale getLocale() {
1344:
1345: return m_settings.getUserSettings().getLocale();
1346: }
1347:
1348: /**
1349: * Returns the current used macro resolver instance.<p>
1350: *
1351: * @return the macro resolver
1352: */
1353: public CmsMacroResolver getMacroResolver() {
1354:
1355: if (m_macroResolver == null) {
1356: // create a new macro resolver "with everything we got"
1357: m_macroResolver = CmsMacroResolver.newInstance()
1358: // initialize resolver with the objects available
1359: .setCmsObject(m_cms).setMessages(getMessages())
1360: .setJspPageContext(
1361: (m_jsp == null) ? null : m_jsp
1362: .getJspContext());
1363: }
1364: return m_macroResolver;
1365: }
1366:
1367: /**
1368: * Returns the current used message object.<p>
1369: *
1370: * @return the current used message object
1371: */
1372: public CmsMessages getMessages() {
1373:
1374: return m_messages;
1375: }
1376:
1377: /**
1378: * Returns a list of FileItem instances parsed from the request, in the order that they were transmitted.<p>
1379: *
1380: * This list is automatically initialized from the createParameterMapFromMultiPart(HttpServletRequest) method.<p>
1381: *
1382: * @return list of FileItem instances parsed from the request, in the order that they were transmitted
1383: */
1384: public List getMultiPartFileItems() {
1385:
1386: return m_multiPartFileItems;
1387: }
1388:
1389: /**
1390: * Returns the path to the workplace static resources.<p>
1391: *
1392: * Workplaces static resources are images, css files etc.
1393: * These are exported during the installation of OpenCms,
1394: * and are usually only read from this exported location to
1395: * avoid the overhaead of accessing the database later.<p>
1396: *
1397: * @return the path to the workplace static resources
1398: */
1399: public String getResourceUri() {
1400:
1401: if (m_resourceUri == null) {
1402: m_resourceUri = OpenCms.getSystemInfo().getContextPath()
1403: + CmsWorkplace.RFS_PATH_RESOURCES;
1404: }
1405: return m_resourceUri;
1406: }
1407:
1408: /**
1409: * Returns the current user http session.<p>
1410: *
1411: * @return the current user http session
1412: */
1413: public HttpSession getSession() {
1414:
1415: return m_session;
1416: }
1417:
1418: /**
1419: * Returns the current users workplace settings.<p>
1420: *
1421: * @return the current users workplace settings
1422: */
1423: public CmsWorkplaceSettings getSettings() {
1424:
1425: return m_settings;
1426: }
1427:
1428: /**
1429: * Returns the path to the cascading stylesheets.<p>
1430: *
1431: * @param filename the name of the stylesheet
1432: * @return the path to the cascading stylesheets
1433: */
1434: public String getStyleUri(String filename) {
1435:
1436: return getStyleUri(getJsp(), filename);
1437: }
1438:
1439: /**
1440: * Builds the end html of the page.<p>
1441: *
1442: * @return the end html of the page
1443: */
1444: public String htmlEnd() {
1445:
1446: return pageHtml(HTML_END, null);
1447: }
1448:
1449: /**
1450: * Builds the start html of the page, including setting of DOCTYPE and
1451: * inserting a header with the content-type.<p>
1452: *
1453: * @param title the content for the title tag
1454: * @return the start html of the page
1455: */
1456: public String htmlStart(String title) {
1457:
1458: return pageHtml(HTML_START, title);
1459: }
1460:
1461: /**
1462: * Sets site and project in the workplace settings with the request values of parameters
1463: * <code>{@link CmsWorkplace#PARAM_WP_SITE}</code> and <code>{@link CmsWorkplace#PARAM_WP_PROJECT}</code>.<p>
1464: *
1465: * @param settings the workplace settings
1466: * @param request the current request
1467: *
1468: * @return true, if a reload of the main body frame is required
1469: */
1470: public boolean initSettings(CmsWorkplaceSettings settings,
1471: HttpServletRequest request) {
1472:
1473: // check if the user requested a project change
1474: String project = request.getParameter(PARAM_WP_PROJECT);
1475: boolean reloadRequired = false;
1476: if (project != null) {
1477: reloadRequired = true;
1478: try {
1479: getCms().readProject(new CmsUUID(project));
1480: } catch (Exception e) {
1481: // project not found, set online project
1482: project = String.valueOf(CmsProject.ONLINE_PROJECT_ID);
1483: }
1484: try {
1485: m_cms.getRequestContext().setCurrentProject(
1486: getCms().readProject(new CmsUUID(project)));
1487: } catch (Exception e) {
1488: if (LOG.isInfoEnabled()) {
1489: LOG.info(e);
1490: }
1491: }
1492: settings.setProject(new CmsUUID(project));
1493: }
1494:
1495: // check if the user requested a site change
1496: String site = request.getParameter(PARAM_WP_SITE);
1497: if (site != null) {
1498: reloadRequired = true;
1499: m_cms.getRequestContext().setSiteRoot(site);
1500: settings.setSite(site);
1501: }
1502:
1503: // check which resource was requested
1504: String explorerResource = request
1505: .getParameter(PARAM_WP_EXPLORER_RESOURCE);
1506: if (explorerResource != null) {
1507: reloadRequired = true;
1508: settings.setExplorerResource(explorerResource);
1509: }
1510:
1511: return reloadRequired;
1512: }
1513:
1514: /**
1515: * Returns the forwarded flag.<p>
1516: *
1517: * @return the forwarded flag
1518: */
1519: public boolean isForwarded() {
1520:
1521: return m_forwarded;
1522: }
1523:
1524: /**
1525: * Returns true if the online help for the users current workplace language is installed.<p>
1526: *
1527: * @return true if the online help for the users current workplace language is installed
1528: */
1529: public boolean isHelpEnabled() {
1530:
1531: return getCms().existsResource(
1532: resolveMacros(CmsHelpTemplateBean.PATH_HELP),
1533: CmsResourceFilter.IGNORE_EXPIRATION);
1534: }
1535:
1536: /**
1537: * Returns true if the currently processed element is an included sub element.<p>
1538: *
1539: * @return true if the currently processed element is an included sub element
1540: */
1541: public boolean isSubElement() {
1542:
1543: return !getJsp().getRequestContext().getUri().equals(
1544: getJsp().info("opencms.request.element.uri"));
1545: }
1546:
1547: /**
1548: * Returns the localized resource string for a given message key,
1549: * checking the workplace default resources and all module bundles.<p>
1550: *
1551: * If the key was not found, the return value is
1552: * <code>"??? " + keyName + " ???"</code>.<p>
1553: *
1554: * If the key starts with <code>"help."</code> and is not found,
1555: * the value <code>"index.html"</code> is returned.<p>
1556: *
1557: * @param keyName the key for the desired string
1558: * @return the resource string for the given key
1559: *
1560: * @see CmsMessages#key(String)
1561: */
1562: public String key(String keyName) {
1563:
1564: return getMessages().key(keyName);
1565: }
1566:
1567: /**
1568: * Returns the localized resource string for a given message key,
1569: * with the provided replacement parameters.<p>
1570: *
1571: * If the key was found in the bundle, it will be formatted using
1572: * a <code>{@link java.text.MessageFormat}</code> using the provided parameters.<p>
1573: *
1574: * If the key was not found in the bundle, the return value is
1575: * <code>"??? " + keyName + " ???"</code>. This will also be returned
1576: * if the bundle was not properly initialized first.
1577: *
1578: * @param keyName the key for the desired string
1579: * @param params the parameters to use for formatting
1580: * @return the resource string for the given key
1581: *
1582: * @see CmsMessages#key(String)
1583: */
1584: public String key(String keyName, Object[] params) {
1585:
1586: return getMessages().key(keyName, params);
1587: }
1588:
1589: /**
1590: * Returns the localized resource string for the given message key,
1591: * checking the workplace default resources and all module bundles.<p>
1592: *
1593: * If the key was not found, the provided default value
1594: * is returned.<p>
1595: *
1596: * @param keyName the key for the desired string
1597: * @param defaultValue the default value in case the key does not exist in the bundle
1598: * @return the resource string for the given key it it exists, or the given default if not
1599: *
1600: * @see CmsMessages#keyDefault(String, String)
1601: */
1602: public String keyDefault(String keyName, String defaultValue) {
1603:
1604: return getMessages().keyDefault(keyName, defaultValue);
1605: }
1606:
1607: /**
1608: * Returns the empty String "" if the provided value is null, otherwise just returns
1609: * the provided value.<p>
1610: *
1611: * Use this method in forms if a getParamXXX method is used, but a String (not null)
1612: * is required.
1613: *
1614: * @param value the String to check
1615: * @return the empty String "" if the provided value is null, otherwise just returns
1616: * the provided value
1617: */
1618: public String nullToEmpty(String value) {
1619:
1620: if (value != null) {
1621: return value;
1622: }
1623: return "";
1624: }
1625:
1626: /**
1627: * Builds the html of the body.<p>
1628: *
1629: * @param segment the HTML segment (START / END)
1630: * @param className optional class attribute to add to the body tag
1631: * @param parameters optional parameters to add to the body tag
1632: * @return the html of the body
1633: */
1634: public String pageBody(int segment, String className,
1635: String parameters) {
1636:
1637: if (segment == HTML_START) {
1638: StringBuffer result = new StringBuffer(128);
1639: result.append("</head>\n<body unselectable=\"on\"");
1640: if (className != null) {
1641: result.append(" class=\"");
1642: result.append(className);
1643: result.append("\"");
1644: }
1645: if (CmsStringUtil.isNotEmpty(parameters)) {
1646: result.append(" ");
1647: result.append(parameters);
1648: }
1649: result.append(">\n");
1650: return result.toString();
1651: } else {
1652: return "</body>";
1653: }
1654: }
1655:
1656: /**
1657: * Returns the default html for a workplace page, including setting of DOCTYPE and
1658: * inserting a header with the content-type.<p>
1659: *
1660: * @param segment the HTML segment (START / END)
1661: * @param title the title of the page, if null no title tag is inserted
1662: * @return the default html for a workplace page
1663: */
1664: public String pageHtml(int segment, String title) {
1665:
1666: return pageHtmlStyle(segment, title, null);
1667: }
1668:
1669: /**
1670: * Returns the default html for a workplace page, including setting of DOCTYPE and
1671: * inserting a header with the content-type, allowing the selection of an individual style sheet.<p>
1672: *
1673: * @param segment the HTML segment (START / END)
1674: * @param title the title of the page, if null no title tag is inserted
1675: * @param stylesheet the used style sheet, if null the default stylesheet 'workplace.css' is inserted
1676: * @return the default html for a workplace page
1677: */
1678: public String pageHtmlStyle(int segment, String title,
1679: String stylesheet) {
1680:
1681: if (segment == HTML_START) {
1682: StringBuffer result = new StringBuffer(512);
1683: result
1684: .append("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01//EN\">\n");
1685: result.append("<html>\n<head>\n");
1686: if (title != null) {
1687: result.append("<title>");
1688: result.append(title);
1689: result.append("</title>\n");
1690: }
1691: result
1692: .append("<meta HTTP-EQUIV=\"Content-Type\" CONTENT=\"text/html; charset=");
1693: result.append(getEncoding());
1694: result.append("\">\n");
1695: result
1696: .append("<link rel=\"stylesheet\" type=\"text/css\" href=\"");
1697:
1698: result.append(getStyleUri(getJsp(),
1699: stylesheet == null ? "workplace.css" : stylesheet));
1700: result.append("\">\n");
1701: return result.toString();
1702: } else {
1703: return "</html>";
1704: }
1705: }
1706:
1707: /**
1708: * Returns all initialized parameters of the current workplace class
1709: * as hidden field tags that can be inserted in a form.<p>
1710: *
1711: * @return all initialized parameters of the current workplace class
1712: * as hidden field tags that can be inserted in a html form
1713: */
1714: public String paramsAsHidden() {
1715:
1716: return paramsAsHidden(null);
1717: }
1718:
1719: /**
1720: * Returns all initialized parameters of the current workplace class
1721: * that are not in the given exclusion list as hidden field tags that can be inserted in a form.<p>
1722: *
1723: * @param excludes the parameters to exclude
1724: *
1725: * @return all initialized parameters of the current workplace class
1726: * that are not in the given exclusion list as hidden field tags that can be inserted in a form
1727: */
1728: public String paramsAsHidden(Collection excludes) {
1729:
1730: StringBuffer result = new StringBuffer(512);
1731: Map params = paramValues();
1732: Iterator i = params.entrySet().iterator();
1733: while (i.hasNext()) {
1734: Map.Entry entry = (Map.Entry) i.next();
1735: String param = (String) entry.getKey();
1736: if ((excludes == null) || (!excludes.contains(param))) {
1737: result.append("<input type=\"hidden\" name=\"");
1738: result.append(param);
1739: result.append("\" value=\"");
1740: String encoded = CmsEncoder.encode(entry.getValue()
1741: .toString(), getCms().getRequestContext()
1742: .getEncoding());
1743: result.append(encoded);
1744: result.append("\">\n");
1745: }
1746: }
1747: return result.toString();
1748: }
1749:
1750: /**
1751: * Returns all initialized parameters of the current workplace class in the
1752: * form of a parameter map, i.e. the values are arrays.<p>
1753: *
1754: * @return all initialized parameters of the current workplace class in the
1755: * form of a parameter map
1756: */
1757: public Map paramsAsParameterMap() {
1758:
1759: return CmsRequestUtil.createParameterMap(paramValues());
1760: }
1761:
1762: /**
1763: * Returns all initialized parameters of the current workplace class
1764: * as request parameters, i.e. in the form <code>key1=value1&key2=value2</code> etc.
1765: *
1766: * @return all initialized parameters of the current workplace class
1767: * as request parameters
1768: */
1769: public String paramsAsRequest() {
1770:
1771: StringBuffer result = new StringBuffer(512);
1772: Map params = paramValues();
1773: Iterator i = params.entrySet().iterator();
1774: while (i.hasNext()) {
1775: Map.Entry entry = (Map.Entry) i.next();
1776: result.append(entry.getKey());
1777: result.append("=");
1778: result.append(CmsEncoder.encode(
1779: entry.getValue().toString(), getCms()
1780: .getRequestContext().getEncoding()));
1781: if (i.hasNext()) {
1782: result.append("&");
1783: }
1784: }
1785: return result.toString();
1786: }
1787:
1788: /**
1789: * Resolves the macros in the given String and replaces them by their localized keys.<p>
1790: *
1791: * The following macro contexts are available in the Workplace:<ul>
1792: * <li>Macros based on the current users OpenCms context (obtained from the current <code>{@link CmsObject}</code>).</li>
1793: * <li>Localized key macros (obtained from the current <code>{@link CmsMessages}</code>).</li>
1794: * <li>Macros from the current JSP page context (obtained by <code>{@link #getJsp()}</code>).</li>
1795: * </ul>
1796: *
1797: * @param input the input String containing the macros
1798: * @return the resolved String
1799: *
1800: * @see CmsMacroResolver#resolveMacros(String)
1801: */
1802: public String resolveMacros(String input) {
1803:
1804: // resolve the macros
1805: return getMacroResolver().resolveMacros(input);
1806: }
1807:
1808: /**
1809: * Sends a http redirect to the specified URI in the OpenCms VFS.<p>
1810: *
1811: * @param location the location the response is redirected to
1812: * @throws IOException in case redirection fails
1813: */
1814: public void sendCmsRedirect(String location) throws IOException {
1815:
1816: // TOOD: IBM Websphere v5 has problems here, use forward instead (which has other problems)
1817: getJsp().getResponse().sendRedirect(
1818: OpenCms.getSystemInfo().getOpenCmsContext() + location);
1819: }
1820:
1821: /**
1822: * Forwards to the specified location in the OpenCms VFS.<p>
1823: *
1824: * @param location the location the response is redirected to
1825: * @param params the map of parameters to use for the forwarded request
1826: *
1827: * @throws IOException in case the forward fails
1828: * @throws ServletException in case the forward fails
1829: */
1830: public void sendForward(String location, Map params)
1831: throws IOException, ServletException {
1832:
1833: setForwarded(true);
1834: // params must be arrays of String, ensure this is the case
1835: params = CmsRequestUtil.createParameterMap(params);
1836: CmsRequestUtil.forwardRequest(getJsp().link(location), params,
1837: getJsp().getRequest(), getJsp().getResponse());
1838: }
1839:
1840: /**
1841: * Sets the forwarded flag.<p>
1842: *
1843: * @param forwarded the forwarded flag to set
1844: */
1845: public void setForwarded(boolean forwarded) {
1846:
1847: m_forwarded = forwarded;
1848: }
1849:
1850: /**
1851: * Get a localized short key value for the workplace.<p>
1852: *
1853: * @param keyName name of the key
1854: * @return a localized short key value
1855: */
1856: public String shortKey(String keyName) {
1857:
1858: String value = keyDefault(keyName
1859: + CmsMessages.KEY_SHORT_SUFFIX, (String) null);
1860: if (value == null) {
1861: // short key value not found, return "long" key value
1862: return key(keyName);
1863: }
1864: return value;
1865: }
1866:
1867: /**
1868: * Auxiliary method for initialization of messages.<p>
1869: *
1870: * @param messages the {@link CmsMessages} to add
1871: */
1872: protected void addMessages(CmsMessages messages) {
1873:
1874: if (messages != null) {
1875: m_messages.addMessages(messages);
1876: }
1877: }
1878:
1879: /**
1880: * Auxiliary method for initialization of messages.<p>
1881: *
1882: * @param bundleName the resource bundle name to add
1883: */
1884: protected void addMessages(String bundleName) {
1885:
1886: addMessages(new CmsMessages(bundleName, getLocale()));
1887: }
1888:
1889: /**
1890: * Returns the values of all parameter methods of this workplace class instance.<p>
1891: *
1892: * @return the values of all parameter methods of this workplace class instance
1893: */
1894: protected Map allParamValues() {
1895:
1896: List methods = paramGetMethods();
1897: Map map = new HashMap(methods.size());
1898: Iterator i = methods.iterator();
1899: while (i.hasNext()) {
1900: Method m = (Method) i.next();
1901: Object o = null;
1902: try {
1903: o = m.invoke(this , new Object[0]);
1904: } catch (InvocationTargetException ite) {
1905: // can usually be ignored
1906: if (LOG.isInfoEnabled()) {
1907: LOG.info(ite);
1908: }
1909: } catch (IllegalAccessException eae) {
1910: // can usually be ignored
1911: if (LOG.isInfoEnabled()) {
1912: LOG.info(eae);
1913: }
1914: }
1915: if (o == null) {
1916: o = "";
1917: }
1918: map.put(m.getName().substring(8).toLowerCase(), o);
1919: }
1920: return map;
1921: }
1922:
1923: /**
1924: * Checks that the current user is a workplace user.<p>
1925: *
1926: * @throws CmsRoleViolationException if the user does not have the required role
1927: */
1928: protected void checkRole() throws CmsRoleViolationException {
1929:
1930: OpenCms.getRoleManager().checkRole(m_cms,
1931: CmsRole.WORKPLACE_USER);
1932: }
1933:
1934: /**
1935: * Decodes an individual parameter value.<p>
1936: *
1937: * In special cases some parameters might require a different-from-default
1938: * encoding. This is the case if the content of the parameter was
1939: * encoded using the JavaScript encodeURIComponent() method on the client,
1940: * which always encodes in UTF-8.<p>
1941: *
1942: * @param paramName the name of the parameter
1943: * @param paramValue the unencoded value of the parameter
1944: *
1945: * @return the encoded value of the parameter
1946: */
1947: protected String decodeParamValue(String paramName,
1948: String paramValue) {
1949:
1950: if ((paramName != null) && (paramValue != null)) {
1951: return CmsEncoder.decode(paramValue, getCms()
1952: .getRequestContext().getEncoding());
1953: } else {
1954: return null;
1955: }
1956: }
1957:
1958: /**
1959: * Returns the map of parameters read from the current request.<p>
1960: *
1961: * This method will also handle parameters from forms
1962: * of type <code>multipart/form-data</code>.<p>
1963: *
1964: * @return the map of parameters read from the current request
1965: */
1966: protected Map getParameterMap() {
1967:
1968: return m_parameterMap;
1969: }
1970:
1971: /**
1972: * Initializes the message object.<p>
1973: *
1974: * By default the {@link CmsWorkplaceMessages} are initialized.<p>
1975: *
1976: * You SHOULD override this method for setting the bundles you really need,
1977: * using the <code>{@link #addMessages(CmsMessages)}</code> or <code>{@link #addMessages(String)}</code> method.<p>
1978: */
1979: protected void initMessages() {
1980:
1981: // no bundles are added by default as all core bundles are added as part of the WorkplaceModuleMessages
1982: }
1983:
1984: /**
1985: * Sets the users time warp if configured and if the current timewarp setting is different or
1986: * clears the current time warp setting if the user has no configured timewarp.<p>
1987: *
1988: * Timwarping is controlled by the session attribute
1989: * {@link CmsContextInfo#ATTRIBUTE_REQUEST_TIME} with a value of type <code>Long</code>.<p>
1990: *
1991: * @param settings the user settings which are configured via the preferences dialog
1992: *
1993: * @param session the session of the user
1994: */
1995: protected void initTimeWarp(CmsUserSettings settings,
1996: HttpSession session) {
1997:
1998: long timeWarpConf = settings.getTimeWarp();
1999: Long timeWarpSetLong = (Long) session
2000: .getAttribute(CmsContextInfo.ATTRIBUTE_REQUEST_TIME);
2001: long timeWarpSet = (timeWarpSetLong != null) ? timeWarpSetLong
2002: .longValue() : CmsContextInfo.CURRENT_TIME;
2003:
2004: if (timeWarpConf == CmsContextInfo.CURRENT_TIME) {
2005: // delete:
2006: if (timeWarpSetLong != null) {
2007: // we may come from direct_edit.jsp: don't remove attribute, this is
2008: session
2009: .removeAttribute(CmsContextInfo.ATTRIBUTE_REQUEST_TIME);
2010: }
2011: } else {
2012: // this is dominant: if configured we will use it
2013: if (timeWarpSet != timeWarpConf) {
2014: session.setAttribute(
2015: CmsContextInfo.ATTRIBUTE_REQUEST_TIME,
2016: new Long(timeWarpConf));
2017: }
2018: }
2019: }
2020:
2021: /**
2022: * Initializes this workplace class instance.<p>
2023: *
2024: * This method can be used in case there a workplace class was generated using
2025: * {@link Class#forName(java.lang.String)} to initialize the class members.<p>
2026: *
2027: * @param jsp the initialized JSP context
2028: */
2029: protected void initWorkplaceMembers(CmsJspActionElement jsp) {
2030:
2031: if (jsp != null) {
2032: m_jsp = jsp;
2033: m_cms = m_jsp.getCmsObject();
2034: m_session = m_jsp.getRequest().getSession();
2035:
2036: // check role
2037: try {
2038: checkRole();
2039: } catch (CmsRoleViolationException e) {
2040: throw new CmsIllegalStateException(e
2041: .getMessageContainer(), e);
2042: }
2043:
2044: // get / create the workplace settings
2045: m_settings = (CmsWorkplaceSettings) m_session
2046: .getAttribute(CmsWorkplaceManager.SESSION_WORKPLACE_SETTINGS);
2047:
2048: if (m_settings == null) {
2049: // create the settings object
2050: m_settings = new CmsWorkplaceSettings();
2051: m_settings = initWorkplaceSettings(m_cms, m_settings,
2052: false);
2053:
2054: storeSettings(m_session, m_settings);
2055: }
2056:
2057: // initialize messages
2058: CmsMessages messages = OpenCms.getWorkplaceManager()
2059: .getMessages(getLocale());
2060: // generate a new multi messages object and add the messages from the workplace
2061: m_messages = new CmsMultiMessages(getLocale());
2062: m_messages.addMessages(messages);
2063: initMessages();
2064:
2065: // check request for changes in the workplace settings
2066: initWorkplaceRequestValues(m_settings, m_jsp.getRequest());
2067:
2068: // set cms context accordingly
2069: initWorkplaceCmsContext(m_settings, m_cms);
2070:
2071: // timewarp reset logic
2072: initTimeWarp(m_settings.getUserSettings(), m_session);
2073: }
2074: }
2075:
2076: /**
2077: * Analyzes the request for workplace parameters and adjusts the workplace
2078: * settings accordingly.<p>
2079: *
2080: * @param settings the workplace settings
2081: * @param request the current request
2082: */
2083: protected abstract void initWorkplaceRequestValues(
2084: CmsWorkplaceSettings settings, HttpServletRequest request);
2085:
2086: /**
2087: * Returns the values of all parameter methods of this workplace class instance.<p>
2088: *
2089: * @return the values of all parameter methods of this workplace class instance
2090: */
2091: protected Map paramValues() {
2092:
2093: List methods = paramGetMethods();
2094: Map map = new HashMap(methods.size());
2095: Iterator i = methods.iterator();
2096: while (i.hasNext()) {
2097: Method m = (Method) i.next();
2098: Object o = null;
2099: try {
2100: o = m.invoke(this , new Object[0]);
2101: } catch (InvocationTargetException ite) {
2102: // can usually be ignored
2103: if (LOG.isInfoEnabled()) {
2104: LOG.info(ite.getLocalizedMessage());
2105: }
2106: } catch (IllegalAccessException eae) {
2107: // can usually be ignored
2108: if (LOG.isInfoEnabled()) {
2109: LOG.info(eae.getLocalizedMessage());
2110: }
2111: }
2112: if (o != null) {
2113: map.put(m.getName().substring(8).toLowerCase(), o);
2114: }
2115: }
2116: return map;
2117: }
2118:
2119: /**
2120: * Helper method to change back from the temporary project to the current project.<p>
2121: *
2122: * @throws CmsException if switching back fails
2123: */
2124: protected void switchToCurrentProject() throws CmsException {
2125:
2126: if (m_currentProjectId != null) {
2127: // switch back to the current users project
2128: getCms().getRequestContext().setCurrentProject(
2129: getCms().readProject(m_currentProjectId));
2130: }
2131: }
2132:
2133: /**
2134: * Helper method to change the current project to the temporary file project.<p>
2135: *
2136: * The id of the old project is stored in a member variable to switch back.<p>
2137: *
2138: * @return the id of the tempfileproject
2139: * @throws CmsException if getting the tempfileproject id fails
2140: */
2141: protected CmsUUID switchToTempProject() throws CmsException {
2142:
2143: // store the current project id in member variable
2144: m_currentProjectId = getSettings().getProject();
2145: CmsUUID tempProjectId = OpenCms.getWorkplaceManager()
2146: .getTempFileProjectId();
2147: getCms().getRequestContext().setCurrentProject(
2148: getCms().readProject(tempProjectId));
2149: return tempProjectId;
2150: }
2151:
2152: /**
2153: * Sets the cms request context and other cms related settings to the
2154: * values stored in the workplace settings.<p>
2155: *
2156: * @param settings the workplace settings
2157: * @param cms the current cms object
2158: */
2159: private void initWorkplaceCmsContext(CmsWorkplaceSettings settings,
2160: CmsObject cms) {
2161:
2162: CmsRequestContext reqCont = cms.getRequestContext();
2163:
2164: // check project setting
2165: if (!settings.getProject().equals(
2166: reqCont.currentProject().getUuid())) {
2167: try {
2168: reqCont.setCurrentProject(cms.readProject(settings
2169: .getProject()));
2170: } catch (CmsDbEntryNotFoundException e) {
2171: try {
2172: // project not found, set current project and settings to online project
2173: reqCont.setCurrentProject(cms
2174: .readProject(CmsProject.ONLINE_PROJECT_ID));
2175: settings.setProject(CmsProject.ONLINE_PROJECT_ID);
2176: } catch (CmsException ex) {
2177: // log error
2178: if (LOG.isInfoEnabled()) {
2179: LOG.info(ex.getLocalizedMessage());
2180: }
2181: }
2182: } catch (CmsException e1) {
2183: if (LOG.isInfoEnabled()) {
2184: LOG.info(e1.getLocalizedMessage());
2185: }
2186: }
2187: }
2188:
2189: // check site setting
2190: if (!(settings.getSite().equals(reqCont.getSiteRoot()))) {
2191: // site was switched, set new site root
2192: reqCont.setSiteRoot(settings.getSite());
2193: // removed setting explorer resource to "/" to get the stored folder
2194: }
2195: }
2196:
2197: /**
2198: * Returns a list of all methods of the current class instance that
2199: * start with "getParam" and have no parameters.<p>
2200: *
2201: * @return a list of all methods of the current class instance that
2202: * start with "getParam" and have no parameters
2203: */
2204: private List paramGetMethods() {
2205:
2206: List list = new ArrayList();
2207: Method[] methods = this .getClass().getMethods();
2208: int length = methods.length;
2209: for (int i = 0; i < length; i++) {
2210: Method method = methods[i];
2211: if (method.getName().startsWith("getParam")
2212: && (method.getParameterTypes().length == 0)) {
2213: if (DEBUG) {
2214: System.err
2215: .println("getMethod: " + method.getName());
2216: }
2217: list.add(method);
2218: }
2219: }
2220: return list;
2221: }
2222:
2223: /**
2224: * Returns a list of all methods of the current class instance that
2225: * start with "setParam" and have exactly one String parameter.<p>
2226: *
2227: * @return a list of all methods of the current class instance that
2228: * start with "setParam" and have exactly one String parameter
2229: */
2230: private List paramSetMethods() {
2231:
2232: List list = new ArrayList();
2233: Method[] methods = this .getClass().getMethods();
2234: int length = methods.length;
2235: for (int i = 0; i < length; i++) {
2236: Method method = methods[i];
2237: if (method.getName().startsWith("setParam")
2238: && (method.getParameterTypes().length == 1)
2239: && (method.getParameterTypes()[0]
2240: .equals(java.lang.String.class))) {
2241: if (DEBUG) {
2242: System.err
2243: .println("setMethod: " + method.getName());
2244: }
2245: list.add(method);
2246: }
2247: }
2248: return list;
2249: }
2250: }
|