📄 a_cmstoolhandler.java
字号:
public void setIconPath(String iconPath) {
m_iconPath = iconPath;
}
/**
* Sets the link.<p>
*
* @param link the link to set
*/
public void setLink(String link) {
m_link = link;
}
/**
* Sets the name.<p>
*
* @param name the name to set
*/
public void setName(String name) {
m_name = name;
}
/**
* Sets the parameter string.<p>
*
* @param paramString the parameter string to set
*/
public void setParameterString(String paramString) {
m_parameters = paramString;
}
/**
* Sets the path.<p>
*
* @param path the path to set
*/
public void setPath(String path) {
m_path = path;
}
/**
* Sets the position.<p>
*
* @param position the position to set
*/
public void setPosition(float position) {
m_position = position;
}
/**
* Sets the short name.<p>
*
* @param shortName the short name to set
*/
public void setShortName(String shortName) {
m_shortName = shortName;
}
/**
* Sets the small icon path.<p>
*
* @param smallIconPath the samll icon path to set
*/
public void setSmallIconPath(String smallIconPath) {
m_smallIconPath = smallIconPath;
}
/**
* Default implementation.
*
* It takes the icon path from <code>{@link org.opencms.file.CmsPropertyDefinition#PROPERTY_NAVIMAGE}</code> property,
* or uses a default icon if undefined, the name is taken from the
* <code>{@link org.opencms.file.CmsPropertyDefinition#PROPERTY_NAVTEXT}</code> property,
* or uses the <code>{@link org.opencms.file.CmsPropertyDefinition#PROPERTY_TITLE}</code> property if undefined,
* or an default text, if still undefined. if you want 2 different names, one for the big icon tools and one for
* the menu/navbar entries, use a <code>{@link A_CmsToolHandler#VALUE_SEPARATOR}</code> to separate them in the property.
* (if you do so, the first one is for big icons and the second one for menu/navbar entries). the help text is taken from the
* <code>{@link org.opencms.file.CmsPropertyDefinition#PROPERTY_DESCRIPTION}</code> property or a
* default text if undefined, if you want to customize a help text while disabled, use a
* <code>{@link A_CmsToolHandler#VALUE_SEPARATOR}</code> as a separator in the same property.<p>
*
* The group is taken from the <code>{@link org.opencms.file.CmsPropertyDefinition#PROPERTY_NAVINFO}</code> property,
* the position from the <code>{@link org.opencms.file.CmsPropertyDefinition#PROPERTY_NAVPOS}</code>
* and the install path is given by the folder structure if the <code>{@link #ARGS_PROPERTY_DEFINITION}</code>
* property does not include path information.<p>
*
* For the icon path you can specify 2 paths separated by a <code>{@link A_CmsToolHandler#VALUE_SEPARATOR}</code>,
* the first one will be used as a group icon (32x32), and the second as an menu icon (16x16). The paths are relative
* to the /system/workplace/resources/ folder. If the tool is disabled, the names of the icons are composed as
* ${name}_disabled.${ext}<p>
*
* The confirmation message is taken from the <code>{@link #ARGS_PROPERTY_DEFINITION}</code> with key
* <code>{@link #ARG_CONFIRMATION_NAME}</code>
*
* @see org.opencms.workplace.tools.I_CmsToolHandler#setup(org.opencms.file.CmsObject, CmsToolRootHandler, java.lang.String)
*/
public boolean setup(CmsObject cms, CmsToolRootHandler root, String resourcePath) {
CmsJspNavElement navElem = CmsJspNavBuilder.getNavigationForResource(cms, resourcePath);
String name = navElem.getNavText();
if (CmsMessages.isUnknownKey(name)) {
name = navElem.getTitle();
}
if (CmsStringUtil.isEmptyOrWhitespaceOnly(name)) {
name = "${key." + Messages.GUI_TOOLS_DEFAULT_NAME_0 + "}";
}
String shortName = name;
if (name.indexOf(VALUE_SEPARATOR) >= 0) {
shortName = name.substring(name.indexOf(VALUE_SEPARATOR) + 1);
name = name.substring(0, name.indexOf(VALUE_SEPARATOR));
}
setName(name);
setShortName(shortName);
String iconPath = navElem.getNavImage();
if (CmsStringUtil.isEmptyOrWhitespaceOnly(iconPath)) {
iconPath = "admin/images/default_tool_big.png:admin/images/default_tool_small.png";
}
String smallIconPath = iconPath;
if (iconPath.indexOf(VALUE_SEPARATOR) >= 0) {
smallIconPath = iconPath.substring(iconPath.indexOf(VALUE_SEPARATOR) + 1);
iconPath = iconPath.substring(0, iconPath.indexOf(VALUE_SEPARATOR));
}
setIconPath(iconPath);
setSmallIconPath(smallIconPath);
String helpText = navElem.getDescription();
if (CmsStringUtil.isEmptyOrWhitespaceOnly(helpText)) {
helpText = "${key." + Messages.GUI_TOOLS_DEFAULT_HELP_0 + "}";
}
String disabledHelpText = DEFAULT_DISABLED_HELPTEXT;
if (helpText.indexOf(VALUE_SEPARATOR) >= 0) {
disabledHelpText = helpText.substring(helpText.indexOf(VALUE_SEPARATOR) + 1);
helpText = helpText.substring(0, helpText.indexOf(VALUE_SEPARATOR));
}
setHelpText(helpText);
setDisabledHelpText(disabledHelpText);
String group = navElem.getInfo();
if (CmsStringUtil.isEmptyOrWhitespaceOnly(group)) {
group = "${key." + Messages.GUI_TOOLS_DEFAULT_GROUP_0 + "}";
}
String path = resourcePath;
setLink(cms, resourcePath);
try {
if (cms.readResource(resourcePath).isFolder()) {
path = CmsToolManager.TOOLPATH_SEPARATOR
+ resourcePath.substring(
root.getUri().length(),
resourcePath.lastIndexOf(CmsToolManager.TOOLPATH_SEPARATOR));
} else {
path = CmsToolManager.TOOLPATH_SEPARATOR
+ resourcePath.substring(root.getUri().length(), resourcePath.lastIndexOf('.'));
}
} catch (CmsException e) {
// ignore
}
// install point
setPath(path);
setGroup(group);
setPosition(navElem.getNavPosition());
// parameters
setParameters(cms, resourcePath);
return !path.equals(resourcePath);
}
/**
* @see java.lang.Object#toString()
*/
public String toString() {
return m_path + " - " + m_group + " - " + m_position;
}
/**
* Sets the link for the given resource.<p>
*
* Use the <code>resourcePath</code> as link if it is not a folder.
*
* If it is a folder, try to use the folder default file property value as link.
* if not use the {@link CmsToolManager#VIEW_JSPPAGE_LOCATION}.
*
* @param cms the cms context
* @param resourcePath the path to the resource to set the link for
*/
protected void setLink(CmsObject cms, String resourcePath) {
String link = resourcePath;
try {
// make sure the res is a folder
cms.readFolder(resourcePath);
// adjust the path
if (resourcePath.endsWith(CmsToolManager.TOOLPATH_SEPARATOR)) {
resourcePath = resourcePath.substring(0, resourcePath.lastIndexOf(CmsToolManager.TOOLPATH_SEPARATOR));
}
// set admin page as link
link = CmsToolManager.VIEW_JSPPAGE_LOCATION;
// try to use the folder def file as link
CmsProperty prop = cms.readPropertyObject(resourcePath, CmsPropertyDefinition.PROPERTY_DEFAULT_FILE, false);
String defFile = "index.jsp";
if (!prop.isNullProperty()) {
defFile = prop.getValue();
}
if (!defFile.startsWith(CmsToolManager.TOOLPATH_SEPARATOR)) {
// try to use this relative link
defFile = resourcePath + CmsToolManager.TOOLPATH_SEPARATOR + defFile;
}
if (defFile.indexOf("?") > 0) {
if (cms.existsResource(defFile.substring(0, defFile.indexOf("?")))) {
link = defFile;
}
} else if (cms.existsResource(defFile)) {
link = defFile;
}
} catch (CmsException e) {
// noop
}
setLink(link);
}
/**
* Sets the needed properties from the {@link #ARGS_PROPERTY_DEFINITION} property of the given resource.<p>
*
* @param cms the cms context
* @param resourcePath the path to the resource to read the property from
*/
protected void setParameters(CmsObject cms, String resourcePath) {
try {
CmsProperty prop = cms.readPropertyObject(resourcePath, ARGS_PROPERTY_DEFINITION, false);
if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(prop.getValue())) {
Map argsMap = new HashMap();
Iterator itArgs = CmsStringUtil.splitAsList(prop.getValue(), ARGUMENT_SEPARATOR).iterator();
while (itArgs.hasNext()) {
String arg = "";
try {
arg = (String)itArgs.next();
int pos = arg.indexOf(VALUE_SEPARATOR);
argsMap.put(arg.substring(0, pos), arg.substring(pos + 1));
} catch (StringIndexOutOfBoundsException e) {
LOG.error("sep: " + VALUE_SEPARATOR + "arg: " + arg);
throw e;
}
}
if (argsMap.get(ARG_PATH_NAME) != null) {
setPath((String)argsMap.get(ARG_PATH_NAME));
}
if (argsMap.get(ARG_CONFIRMATION_NAME) != null) {
setConfirmationMessage((String)argsMap.get(ARG_CONFIRMATION_NAME));
}
if (argsMap.get(ARG_PARAM_NAME) != null) {
setParameterString((String)argsMap.get(ARG_PARAM_NAME));
}
}
} catch (CmsException e) {
// noop
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -