cmsnewresource.java
来自「找了很久才找到到源代码」· Java 代码 · 共 1,095 行 · 第 1/3 页
JAVA
1,095 行
*/
public void setParamNewResourceUri(String newResourceUri) {
m_paramNewResourceUri = newResourceUri;
}
/**
* Sets the paramPage.<p>
*
* @param paramPage the paramPage to set
*/
public void setParamPage(String paramPage) {
m_paramPage = paramPage;
}
/**
* Sets the boolean flag successfullyCreated.<p>
*
* @param successfullyCreated a boolean flag that indicates if the create resource operation was successfull or not
*/
public void setResourceCreated(boolean successfullyCreated) {
m_resourceCreated = successfullyCreated;
}
/**
* Appends a ".html" suffix to the given resource name if no suffix is present and the append suffix option is checked.<p>
*
* @param resourceName the resource name to check
* @param forceSuffix if true, the suffix is appended overriding the append suffix option
* @return the reource name with ".html" suffix if no suffix was present and the append suffix option is checked
*/
protected String appendSuffixHtml(String resourceName, boolean forceSuffix) {
// append the default suffix (".html") to new file if no standard type was provided
if ((forceSuffix || Boolean.valueOf(getParamAppendSuffixHtml()).booleanValue())) {
if (OpenCms.getResourceManager().getMimeType(resourceName, null, null) == null) {
resourceName += DEFAULT_SUFFIX;
}
}
return resourceName;
}
/**
* Appends the full path to the new resource name given in the resource parameter.<p>
*
* @return the full path of the new resource
*/
protected String computeFullResourceName() {
// return the full resource name
// get the current folder
String currentFolder = getParamCurrentFolder();
if (CmsStringUtil.isEmpty(currentFolder)) {
currentFolder = computeCurrentFolder();
}
return currentFolder + getParamResource();
}
/**
* Returns the properties to create automatically with the new VFS resource.<p>
*
* If configured, the Title and Navigation properties are set on resource creation.<p>
*
* @param resourceName the full resource name
* @param resTypeName the name of the resource type
* @param title the Title String to use for the property values
* @return the List of initialized property objects
*/
protected List createResourceProperties(String resourceName, String resTypeName, String title) {
return createResourceProperties(getCms(), resourceName, resTypeName, title);
}
/**
* @see org.opencms.workplace.list.A_CmsListDialog#customHtmlStart()
*/
protected String customHtmlStart() {
StringBuffer result = new StringBuffer(256);
result.append(super.customHtmlStart());
result.append("<script type='text/javascript'>\n");
result.append("function enableButton() {\n");
result.append("\tvar theButton = document.getElementById(\"nextButton\");\n");
result.append("\tif (theButton.disabled == true) {\n");
result.append("\t\ttheButton.disabled = false;\n");
result.append("\t}\n");
result.append("}\n");
result.append("function submitAdvanced() {\n");
result.append("\tdocument.forms[\""
+ getList().getId()
+ "-form\"].action.value = \""
+ DIALOG_ADVANCED
+ "\";\n");
result.append("\tdocument.forms[\"" + getList().getId() + "-form\"].submit();\n");
result.append("}\n");
result.append("</script>");
return result.toString();
}
/**
* @see org.opencms.workplace.CmsDialog#dialogButtonsHtml(java.lang.StringBuffer, int, java.lang.String)
*/
protected void dialogButtonsHtml(StringBuffer result, int button, String attribute) {
attribute = appendDelimiter(attribute);
switch (button) {
case BUTTON_NEXT:
result.append("<input name=\"next\" type=\"submit\" value=\"");
result.append(key(Messages.GUI_BUTTON_NEXTSCREEN_0));
result.append("\" class=\"dialogbutton\"");
result.append(attribute);
result.append(">\n");
break;
default:
super.dialogButtonsHtml(result, button, attribute);
}
}
/**
* @see org.opencms.workplace.list.A_CmsListDialog#getListItems()
*/
protected List getListItems() {
List ret = new ArrayList();
Iterator i;
if (m_limitedRestypes) {
// available resource types limited, create list iterator of given limited types
List newResTypes;
if (m_availableResTypes.indexOf(DELIM_PROPERTYVALUES) > -1) {
newResTypes = CmsStringUtil.splitAsList(m_availableResTypes, DELIM_PROPERTYVALUES);
} else {
newResTypes = CmsStringUtil.splitAsList(m_availableResTypes, CmsProperty.VALUE_LIST_DELIMITER);
}
Iterator k = newResTypes.iterator();
List settings = new ArrayList(newResTypes.size());
while (k.hasNext()) {
String resType = (String)k.next();
// get settings for resource type
CmsExplorerTypeSettings set = OpenCms.getWorkplaceManager().getExplorerTypeSetting(resType);
if (set != null) {
// add found setting to available resource types
settings.add(set);
}
}
// sort explorer type settings by their order
Collections.sort(settings);
i = settings.iterator();
} else {
// create list iterator from all configured resource types
i = OpenCms.getWorkplaceManager().getExplorerTypeSettings().iterator();
}
CmsResource resource = null;
try {
resource = getCms().readResource(getParamCurrentFolder());
} catch (CmsException e) {
// ignore
}
while (i.hasNext()) {
CmsExplorerTypeSettings settings = (CmsExplorerTypeSettings)i.next();
if (!m_limitedRestypes) {
// check for the "new resource" page
if (m_page == null) {
if (CmsStringUtil.isNotEmpty(settings.getNewResourcePage())) {
continue;
}
} else if (!m_page.equals(settings.getNewResourcePage())) {
continue;
}
}
if (CmsStringUtil.isEmpty(settings.getNewResourceUri())) {
// no new resource URI specified for the current settings, dont't show the type
continue;
}
// check permissions for the type
if (!settings.isEditable(getCms(), resource)) {
// the type has no permission for the current user to be created, don't show the type
continue;
}
// add found setting to list
CmsListItem item = getList().newItem(settings.getName());
item.set(LIST_COLUMN_NAME, key(settings.getKey()));
item.set(LIST_COLUMN_ICON, "<img src=\""
+ getSkinUri()
+ "filetypes/"
+ settings.getIcon()
+ "\" style=\"width: 16px; height: 16px;\" />");
item.set(LIST_COLUMN_URI, CmsEncoder.encode(settings.getNewResourceUri()));
ret.add(item);
}
return ret;
}
/**
* Returns the title to use for the dialog.<p>
*
* Checks if a custom title key is given in the explorer type settings
* and otherwise returns the default title from
* {@link CmsWorkplaceMessages#getNewResourceTitle(org.opencms.workplace.CmsWorkplace, String)}.<p>
*
* @return the title to use for the dialog
*/
protected String getTitle() {
String title = null;
CmsExplorerTypeSettings set = OpenCms.getWorkplaceManager().getExplorerTypeSetting(getParamNewResourceType());
if ((set != null) && (CmsStringUtil.isNotEmptyOrWhitespaceOnly(set.getTitleKey()))) {
title = getMessages().key(set.getTitleKey(), true);
}
if (CmsStringUtil.isEmptyOrWhitespaceOnly(title)) {
if (CmsStringUtil.isNotEmpty(getParamNewResourceType())) {
title = CmsWorkplaceMessages.getNewResourceTitle(this, getParamNewResourceType());
} else {
title = getParamTitle();
}
}
return title;
}
/**
* @see org.opencms.workplace.CmsWorkplace#initWorkplaceRequestValues(org.opencms.workplace.CmsWorkplaceSettings, javax.servlet.http.HttpServletRequest)
*/
protected void initWorkplaceRequestValues(CmsWorkplaceSettings settings, HttpServletRequest request) {
// set the dialog type
setParamDialogtype(DIALOG_TYPE);
// set default action
setAction(ACTION_DEFAULT);
super.initWorkplaceRequestValues(settings, request);
// build title for new resource dialog
setParamTitle(key(Messages.GUI_NEWRESOURCE_0));
if (CmsStringUtil.isNotEmpty(getParamPage())) {
m_page = getParamPage();
setParamPage(null);
if (CmsStringUtil.isEmptyOrWhitespaceOnly(getParamNewFormUri()) || getParamNewResourceUri().indexOf("?" + PARAM_PAGE) != -1) {
setParamNewFormUri(getParamNewResourceUri());
setParamNewResourceUri(null);
}
if ((DIALOG_NEWFORM.equals(getParamAction())) || (LIST_INDEPENDENT_ACTION.equals(getParamAction()))) {
setParamAction(null);
}
}
// set the action for the JSP switch
if (DIALOG_OK.equals(getParamAction())) {
setAction(ACTION_OK);
} else if (DIALOG_SUBMITFORM.equals(getParamAction())) {
setAction(ACTION_SUBMITFORM);
} else if (DIALOG_NEWFORM.equals(getParamAction())) {
// set resource name if we are in new folder wizard mode
setInitialResourceName();
setAction(ACTION_NEWFORM);
// set the correct title
setParamTitle(getTitle());
} else if (DIALOG_CANCEL.equals(getParamAction())) {
setAction(ACTION_CANCEL);
} else {
if (!DIALOG_ADVANCED.equals(getParamAction()) && CmsStringUtil.isEmpty(m_page)) {
// check for presence of property limiting the new resource types to create
String newResTypesProperty = "";
try {
newResTypesProperty = getCms().readPropertyObject(
getParamCurrentFolder(),
CmsPropertyDefinition.PROPERTY_RESTYPES_AVAILABLE,
true).getValue();
} catch (CmsException e) {
// ignore this exception, this is a minor issue
}
if (CmsStringUtil.isNotEmpty(newResTypesProperty) && !newResTypesProperty.equals(VALUE_DEFAULT)) {
m_limitedRestypes = true;
m_availableResTypes = newResTypesProperty;
}
}
}
}
/**
* @see org.opencms.workplace.list.A_CmsListDialog#setColumns(org.opencms.workplace.list.CmsListMetadata)
*/
protected void setColumns(CmsListMetadata metadata) {
super.setColumns(metadata);
// add column uri
CmsListColumnDefinition uriCol = new CmsListColumnDefinition(LIST_COLUMN_URI);
uriCol.setName(Messages.get().container(Messages.GUI_NEWRESOURCE_LIST_COLS_URI_0));
uriCol.setVisible(false);
metadata.addColumn(uriCol);
CmsListItemSelectionCustomAction action = (CmsListItemSelectionCustomAction)metadata.getColumnDefinition(
LIST_COLUMN_SELECT).getDirectAction(LIST_ACTION_SEL);
action.setFieldName(PARAM_NEWRESOURCEURI);
action.setColumn(LIST_COLUMN_URI);
action.setAttributes(" onclick=\"enableButton();\"");
}
/**
* Sets the initial resource name of the new page.<p>
*
* This is used for the "new" wizard after creating a new folder followed
* by the "create index file" procedure.<p>
*/
protected void setInitialResourceName() {
if (isCreateIndexMode()) {
// creation of an index file in a new folder, use default file name
String defaultFile = "";
try {
defaultFile = (String)OpenCms.getDefaultFiles().get(0);
} catch (IndexOutOfBoundsException e) {
// list is empty, ignore
}
if (CmsStringUtil.isEmpty(defaultFile)) {
// make sure that the default file name is not empty
defaultFile = "index.html";
}
setParamResource(defaultFile);
} else {
setParamResource("");
}
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?