📄 cmstemplatebean.java
字号:
/**
* Returns the Map of found resource properties.<p>
*
* @return the Map of found resource properties
*/
public Map getProperties() {
return m_properties;
}
/**
* Returns the substituted path to the modules resource folder.<p>
*
* @return the substituted path to the modules resource folder
*/
public String getResourcePath() {
if (m_resPath == null) {
// resource path has not yet been determined, get it now
m_resPath = property(PROPERTY_RESOURCEPATH, "search", "na");
if ("na".equals(m_resPath)) {
// no property set, use default module resources
m_resPath = CmsWorkplace.VFS_PATH_MODULES + MODULE_NAME + "/resources/";
}
m_resPath = link(m_resPath);
}
return m_resPath;
}
/**
* Returns the search index name to use, depending on the current site.<p>
*
* Returns "[Projectname] project (VFS)" for the default site and the site root as index name for other sites.<p>
*
* @return the search index name to use, depending on the current site
*/
public String getSearchIndexName() {
String currentSite = getRequestContext().getSiteRoot();
if (currentSite.indexOf("sites/default") == -1) {
// return site root as index name
return currentSite;
} else {
// return default index
return getRequestContext().currentProject().getName() + " project (VFS)";
}
}
/**
* Returns the start folder for navigation and search results.<p>
*
* @return the start folder for navigation and search results
*/
public String getStartFolder() {
if (m_startFolder == null) {
// start folder has not yet been determined, so try to get it
int folderTypeId = -1;
try {
folderTypeId = OpenCms.getResourceManager().getResourceType(RESOURCE_TYPE_MICROSITE_NAME).getTypeId();
} catch (CmsLoaderException e) {
// resource type could not be determined
if (LOG.isErrorEnabled()) {
LOG.error(Messages.get().getBundle().key(Messages.LOG_MICROSITE_FOLDER_NOT_FOUND_0));
}
}
m_startFolder = "/";
try {
CmsFolder startFolder = getCmsObject().readAncestor(getRequestContext().getUri(), folderTypeId);
if (startFolder != null) {
m_startFolder = getCmsObject().getRequestContext().removeSiteRoot(startFolder.getRootPath());
}
} catch (CmsException e) {
// no matching start folder found
if (LOG.isErrorEnabled()) {
LOG.error(Messages.get().getBundle().key(Messages.LOG_MICROSITE_READ_START_FOLDER_0));
}
}
}
return m_startFolder;
}
/**
* Returns the URI of the CSS style sheet configuration file.<p>
*
* @return the URI of the CSS style sheet configuration file
*/
public String getStyleSheetConfigUri() {
String confUri = property(CmsTemplateStyleSheet.PROPERTY_CONFIGFILE, "search", "");
if ("".equals(confUri)) {
// property not set, try to get default configuration file
confUri = getConfigPath() + CmsTemplateStyleSheet.FILENAME_CONFIGFILE;
}
return confUri;
}
/**
* Returns the substituted URI of the CSS style sheet to use in the template.<p>
*
* @return the substituted URI of the CSS style sheet
*/
public String getStyleSheetUri() {
String fileName = FILE_CSS;
if (showAccessibleVersion()) {
// use accessible CSS version
fileName = FILE_CSS_ACCESSIBLE;
}
// generate substituted style sheet URI
return link(CmsWorkplace.VFS_PATH_MODULES + MODULE_NAME + "/resources/" + fileName);
}
/**
* Returns the substituted URI of the CSS style sheet to use in the template.<p>
*
* @param resPath the resource path
* @param config the uri to the configuration settings
* @param site the site
* @param locale the locale
*
* @return the substituted URI of the CSS style sheet
*/
public String getStyleSheetUri(String resPath, String config, String site, Locale locale) {
StringBuffer result = new StringBuffer(16);
// create absolute path to VFS module resource folder
result.append(CmsWorkplace.VFS_PATH_MODULES);
result.append(MODULE_NAME);
result.append("/resources/");
if (showAccessibleVersion()) {
// use accessible CSS version
result.append(FILE_CSS_ACCESSIBLE);
} else {
// use common CSS version
result.append(FILE_CSS);
}
// append the request parameters for the style sheet
result.append("?respath=");
result.append(resPath);
result.append("&config=");
result.append(config);
result.append("&site=");
result.append(site);
result.append("&__locale=");
result.append(locale);
// generate substituted style sheet URI
return link(result.toString());
}
/**
* Returns the template parts instance to use for including static JSP elements.<p>
*
* These element parts depend on the current Locale, the layout to display and the project.<p>
*
* @return the template parts instance
*/
public CmsTemplateParts getTemplateParts() {
return CmsTemplateParts.getInstance();
}
/**
* Returns the "Title" property value of the requested uri.<p>
*
* @param defaultValue the default value used when the property was not found
* @return the "Title" property value of the requested uri
*/
public String getTitle(String defaultValue) {
if (defaultValue == null) {
defaultValue = "";
}
return property(CmsPropertyDefinition.PROPERTY_TITLE, "search", defaultValue);
}
/**
* Includes the page elements if they are present.<p>
*
* The page elements are layouted in a 4 row, 2 columns layout.
* If one element of a single row is missing, the present element
* will be spanned across the 2 columns.<p>
*
* @throws IOException if writing the output fails
* @throws JspException if including an element fails
*/
public void includeElements() throws IOException, JspException {
// check if elements to show are present
boolean elementsPresent = template("text1,text2,text3,text4,text5,text6,text7,text8", false);
// get the list(s) of content items to display between elements
String configFile = (String)getProperties().get(PROPERTY_LAYOUT_CENTER);
List contents = new ArrayList();
if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(configFile) && !PROPERTY_VALUE_NONE.equals(configFile)) {
// get the content list(s) for the center area
contents = getContentListItems(configFile, CmsTemplateContentListItem.DISPLAYAREA_CENTER);
}
// determine if list can show page links
int size = contents.size();
boolean showPageLinks = true;
if (size > 1) {
// more than one list is displayed, do not show page links on lists
showPageLinks = false;
}
if (elementsPresent || size > 0) {
// at least one element or list is present, create writer
JspWriter out = getJspContext().getOut();
String elementName = FOLDER_ELEMENTS + "elements.jsp";
// create start part (common layout only)
out.print(getTemplateParts().includePart(elementName, "start", getLayout(), this));
// calculate start point for content lists
int startPoint = 3 - size;
int listIndex = 0;
for (int i = 0; i < 4; i++) {
int elementIndex = (i * 2) + 1;
// include the element row
includeContentRow("text" + (elementIndex), "text" + (elementIndex + 1), out);
if ((listIndex < size) && (i >= startPoint)) {
// include the list item
CmsTemplateContentListItem item = (CmsTemplateContentListItem)contents.get(listIndex);
out.print(getTemplateParts().includePart(elementName, "column_start", getLayout(), this));
out.print(getTemplateParts().includePart(elementName, "element_start_1", getLayout(), this));
item.includeListItem(this, showPageLinks);
out.print(getTemplateParts().includePart(elementName, "element_end", getLayout(), this));
out.print(getTemplateParts().includePart(elementName, "column_end", getLayout(), this));
listIndex++;
}
}
// create end part (common layout only)
out.print(getTemplateParts().includePart(elementName, "end", getLayout(), this));
}
}
/**
* Includes page elements useable on popup pages ("popuphead", "popupfoot").<p>
*
* @param element the element to display from the target
* @param title the title for the popup page
* @throws JspException if including the element fails
*/
public void includePopup(String element, String title) throws JspException {
Map properties = new HashMap();
if ("popuphead".equals(element)) {
// include the head part, put necessary information to Map
properties.put("stylesheeturi", getStyleSheetUri());
properties.put("resourcepath", getResourcePath());
properties.put("title", title);
properties.put(CmsTemplateStyleSheet.PARAM_CONFIGFILE, getStyleSheetConfigUri());
}
// include the element
include(CmsWorkplace.VFS_PATH_MODULES + MODULE_NAME + "/pages/popup_includes.jsp", element, properties);
}
/**
* Includes center list elements if defined.<p>
*
* @throws JspException if including an element fails
*/
public void includeRightLists() throws JspException {
String configFile = (String)getProperties().get(PROPERTY_LAYOUT_RIGHT);
if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(configFile) && !PROPERTY_VALUE_NONE.equals(configFile)) {
List contents = getContentListItems(configFile, CmsTemplateContentListItem.DISPLAYAREA_RIGHT);
int size = contents.size();
for (int i = 0; i < size; i++) {
CmsTemplateContentListItem item = (CmsTemplateContentListItem)contents.get(i);
item.includeListItem(this, false);
}
}
}
/**
* Initialize this bean with the current page context, request and response.<p>
*
* It is required to call one of the init() methods before you can use the
* instance of this bean.
*
* @param context the JSP page context object
* @param req the JSP request
* @param res the JSP response
*/
public void init(PageContext context, HttpServletRequest req, HttpServletResponse res) {
// call initialization of super class
super.init(context, req, res);
String className = getClass().getName();
if (className.endsWith("Bean")) {
// do some additional stuff if this is not called by a super class
m_properties = properties("search");
// check which page version to display
initPageVersion();
// check if the head navigation should be shown
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -