cmstoolmanager.java
来自「找了很久才找到到源代码」· Java 代码 · 共 844 行 · 第 1/3 页
JAVA
844 行
*/
public CmsToolRootHandler getCurrentRoot(CmsWorkplace wp) {
CmsToolUserData userData = getUserData(wp);
String root = ROOTKEY_DEFAULT;
if (userData != null) {
if (m_roots.getObject(userData.getRootKey()) != null) {
root = userData.getRootKey();
} else {
if (LOG.isErrorEnabled()) {
LOG.error(Messages.get().getBundle().key(Messages.ERR_NOT_CONFIGURED_ROOT_1, userData.getRootKey()));
}
}
}
return (CmsToolRootHandler)m_roots.getObject(root);
}
/**
* Returns the current tool.<p>
*
* @param wp the workplace object
*
* @return the current tool
*/
public CmsTool getCurrentTool(CmsWorkplace wp) {
return resolveAdminTool(getCurrentRoot(wp).getKey(), getCurrentToolPath(wp));
}
/**
* Returns the current tool path.<p>
*
* @param wp the workplace object
*
* @return the current tool path
*/
public String getCurrentToolPath(CmsWorkplace wp) {
CmsToolUserData userData = getUserData(wp);
String path = getBaseToolPath(wp);
if (userData != null) {
path = userData.getCurrentToolPath(getCurrentRoot(wp).getKey());
}
return path;
}
/**
* Returns the path to the parent of the tool identified by the given tool path.<p>
*
* The parent of the root is the same root.<p>
*
* @param wp the workplace object
* @param toolPath the abstract tool path
*
* @return his parent
*/
public String getParent(CmsWorkplace wp, String toolPath) {
if (toolPath.equals(getBaseToolPath(wp))) {
return toolPath;
}
int pos = toolPath.lastIndexOf(TOOLPATH_SEPARATOR);
return pos <= 0 ? TOOLPATH_SEPARATOR : toolPath.substring(0, pos);
}
/**
* Returns a list with all registered tools.<p>
*
* @return list if <code>{@link CmsTool}</code>
*/
public List getToolHandlers() {
return m_tools.elementList();
}
/**
* Returns a list of tool roots.<p>
*
* @return a list of {@link CmsToolRootHandler} objects
*/
public List getToolRoots() {
return m_roots.elementList();
}
/**
* Returns a list of all tools in the given path.<p>
*
* @param wp the workplace context
* @param baseTool the path
* @param includeSubtools if the tools in subfolders should be also returned
*
* @return a list of {@link CmsTool} objects
*/
public List getToolsForPath(CmsWorkplace wp, String baseTool, boolean includeSubtools) {
List toolList = new ArrayList();
String rootKey = getCurrentRoot(wp).getKey();
Iterator itTools = m_tools.elementList().iterator();
while (itTools.hasNext()) {
CmsTool tool = (CmsTool)itTools.next();
String path = tool.getHandler().getPath();
if (resolveAdminTool(rootKey, path) != tool) {
continue;
}
if (path.equals(TOOLPATH_SEPARATOR)) {
continue;
}
// leave out everything above the base
if (!path.startsWith(baseTool)) {
continue;
}
// filter for path
if (baseTool.equals(TOOLPATH_SEPARATOR) || path.startsWith(baseTool + TOOLPATH_SEPARATOR)) {
// filter sub tree
if (includeSubtools || (path.indexOf(TOOLPATH_SEPARATOR, baseTool.length() + 1) < 0)) {
toolList.add(tool);
}
}
}
return toolList;
}
/**
* Returns the <code>{@link CmsToolUserData}</code> object for a given user.<p>
*
* @param wp the workplace object
*
* @return the current user data
*/
public CmsToolUserData getUserData(CmsWorkplace wp) {
CmsToolUserData userData = wp.getSettings().getToolUserData();
if (userData == null) {
userData = new CmsToolUserData();
userData.setRootKey(ROOTKEY_DEFAULT);
Iterator it = getToolRoots().iterator();
while (it.hasNext()) {
CmsToolRootHandler root = (CmsToolRootHandler)it.next();
userData.setCurrentToolPath(root.getKey(), TOOLPATH_SEPARATOR);
userData.setBaseTool(root.getKey(), TOOLPATH_SEPARATOR);
}
wp.getSettings().setToolUserData(userData);
}
return userData;
}
/**
* Returns <code>true</code> if there is at least one tool registered using the given url.<p>
*
* @param url the url of the tool
*
* @return <code>true</code> if there is at least one tool registered using the given url
*/
public boolean hasToolPathForUrl(String url) {
List toolPaths = (List)m_urls.getObject(url);
return ((toolPaths != null) && !toolPaths.isEmpty());
}
/**
* This method initializes the tool manager for the current user.<p>
*
* @param wp the jsp page comming from
*/
public synchronized void initParams(CmsToolDialog wp) {
setCurrentRoot(wp, wp.getParamRoot());
setCurrentToolPath(wp, wp.getParamPath());
setBaseToolPath(wp, wp.getParamBase());
// if the current tool path is not under the current root, set the current root as the current tool
if (!getCurrentToolPath(wp).startsWith(getBaseToolPath(wp))) {
setCurrentToolPath(wp, getBaseToolPath(wp));
}
wp.setParamPath(getCurrentToolPath(wp));
wp.setParamBase(getBaseToolPath(wp));
wp.setParamRoot(getCurrentRoot(wp).getKey());
}
/**
* Redirects to the given page with the given parameters.<p>
*
* @param wp the workplace object
* @param pagePath the path to the page to redirect to
* @param params the parameters to send
*
* @throws IOException in case of errors during forwarding
* @throws ServletException in case of errors during forwarding
*/
public void jspForwardPage(CmsWorkplace wp, String pagePath, Map params) throws IOException, ServletException {
Map newParams = createToolParams(wp, pagePath, params);
if (pagePath.indexOf("?") > 0) {
pagePath = pagePath.substring(0, pagePath.indexOf("?"));
}
wp.setForwarded(true);
// forward to the requested page uri
CmsRequestUtil.forwardRequest(
wp.getJsp().link(pagePath),
CmsRequestUtil.createParameterMap(newParams),
wp.getJsp().getRequest(),
wp.getJsp().getResponse());
}
/**
* Redirects to the given tool with the given parameters.<p>
*
* @param wp the workplace object
* @param toolPath the path to the tool to redirect to
* @param params the parameters to send
*
* @throws IOException in case of errors during forwarding
* @throws ServletException in case of errors during forwarding
*/
public void jspForwardTool(CmsWorkplace wp, String toolPath, Map params) throws IOException, ServletException {
Map newParams;
if (params == null) {
newParams = new HashMap();
} else {
newParams = new HashMap(params);
}
// update path param
newParams.put(CmsToolDialog.PARAM_PATH, toolPath);
jspForwardPage(wp, VIEW_JSPPAGE_LOCATION, newParams);
}
/**
* Returns the admin tool corresponding to the given abstract path.<p>
*
* @param rootKey the tool root
* @param toolPath the path
*
* @return the corresponding tool, or <code>null</code> if not found
*/
public CmsTool resolveAdminTool(String rootKey, String toolPath) {
return (CmsTool)m_tools.getObject(rootKey + ROOT_SEPARATOR + toolPath);
}
/**
* Sets the base tool path.<p>
*
* @param wp the workplace object
* @param baseToolPath the base tool path to set
*/
public void setBaseToolPath(CmsWorkplace wp, String baseToolPath) {
// use last used base if param empty
if (CmsStringUtil.isEmpty(baseToolPath) || baseToolPath.trim().equals("null")) {
baseToolPath = getBaseToolPath(wp);
}
baseToolPath = repairPath(wp, baseToolPath);
// set it
CmsToolUserData userData = getUserData(wp);
userData.setBaseTool(userData.getRootKey(), baseToolPath);
}
/**
* Sets the current user's root key.<p>
*
* @param wp the workplace context
* @param key the current user's root key to set
*/
public void setCurrentRoot(CmsWorkplace wp, String key) {
// use last used root if param empty
if (CmsStringUtil.isEmpty(key) || key.trim().equals("null")) {
key = getCurrentRoot(wp).getKey();
}
// set it
CmsToolUserData userData = getUserData(wp);
userData.setRootKey(key);
}
/**
* Sets the current tool path.<p>
*
* @param wp the workplace object
* @param currentToolPath the current tool path to set
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?