cmslayoutpagebean.java
来自「找了很久才找到到源代码」· Java 代码 · 共 1,164 行 · 第 1/3 页
JAVA
1,164 行
layout = COLUMNS_LAYOUT_1;
}
setColumnLayout(layout);
// set the size information values
setColPadding(colPadding);
setColSpacing(colSpacing);
setBodyWidth(bodyWith);
// initialize pattern Map
setLayoutPatterns(new HashMap(16));
}
/**
* Returns if the layout images should be fixed or calculated from the content area width.<p>
*
* @return if the layout images should be fixed or calculated from the content area width
*/
public boolean isFixedImageSize() {
return m_fixedImageSize;
}
/**
* Sets the width of the content area of the template.<p>
*
* @param bodyWidth the width of the content area of the template
*/
public void setBodyWidth(int bodyWidth) {
m_bodyWdith = bodyWidth;
}
/**
* Sets the JSP action element to get access to the OpenCms API.<p>
*
* @param jsp the JSP action element to get access to the OpenCms API
*/
public void setCmsJspActionElement(CmsJspActionElement jsp) {
m_jspActionElement = jsp;
}
/**
* Sets the padding of the columns in the content area.<p>
*
* @param colPadding the padding of the columns in the content area
*/
public void setColPadding(int colPadding) {
m_colPadding = colPadding;
}
/**
* Sets the spacing of the columns in the content area.<p>
*
* @param colSpacing the spacing of the columns in the content area
*/
public void setColSpacing(int colSpacing) {
m_colSpacing = colSpacing;
}
/**
* Sets the column layout of the parapgraphs in the content area.<p>
*
* @param colLayout the column layout of the parapgraphs in the content area
*/
public void setColumnLayout(String colLayout) {
m_columnLayout = colLayout;
}
/**
* Sets the XML content that stores the layout.<p>
*
* @param content the XML content that stores the layout
*/
public void setContent(CmsXmlContent content) {
m_content = content;
}
/**
* Sets if the layout images should be fixed or calculated from the content area width.<p>
*
* @param fixedImageSize if the layout images should be fixed or calculated from the content area width
*/
public void setFixedImageSize(boolean fixedImageSize) {
m_fixedImageSize = fixedImageSize;
}
/**
* Sets the image width to use for large images in fixed image size mode.<p>
*
* @param largeImgWidth the image width to use for large images in fixed image size mode
*/
public void setImgWidthLarge(int largeImgWidth) {
m_imgWidthLarge = largeImgWidth;
}
/**
* Sets the image width to use for medium images in fixed image size mode.<p>
*
* @param mediumImgWidth the image width to use for medium images in fixed image size mode
*/
public void setImgWidthMedium(int mediumImgWidth) {
m_imgWidthMedium = mediumImgWidth;
}
/**
* Sets the image width to use for small images in fixed image size mode.<p>
*
* @param smallImgWidth the image width to use for small images in fixed image size mode
*/
public void setImgWidthSmall(int smallImgWidth) {
m_imgWidthSmall = smallImgWidth;
}
/**
* Sets the paragraph layout patterns with the layout name as key, the value is the corresponding image width.<p>
*
* @param layoutPatterns the paragraph layout patterns with the layout name as key, the value is the corresponding image width
*/
public void setLayoutPatterns(Map layoutPatterns) {
m_layoutPatterns = layoutPatterns;
}
/**
* Sets the VFS path to the html snippet files to include to render the layout paragraphs.<p>
*
* @param pathLayoutElements the VFS path to the html snippet files to include to render the layout paragraphs
*/
public void setPathLayoutElements(String pathLayoutElements) {
m_pathLayoutElements = pathLayoutElements;
}
/**
* Sets the layout variant to show, e.g. "common", "print" or "accessibe".<p>
*
* @param variant the layout variant to show, e.g. "common", "print" or "accessibe"
*/
public void setVariant(String variant) {
m_variant = variant;
}
/**
* Calculates the actual column width to show depending on the chosen layout.<p>
*/
protected void calculateColumnWidth() {
// calculate the actual column width to show depending on the layout
if (getColumnLayout().indexOf(COLUMNS_LAYOUT_2) != -1) {
// 2 column layout
setColumnWidth(((getBodyWidth() - getColSpacing()) / 2) - (2 * getColPadding()));
} else {
// 1 colummn layout
setColumnWidth(getBodyWidth() - (2 * getColPadding()));
}
}
/**
* Returns the desired image width depending on the given image variant and the image mode (fixed or not).<p>
*
* @param imgWidthVariant the image width variant to use from the paragraph layout pattern Map
* @return the desired image width depending on the given image variant and the image mode (fixed or not)
*/
protected int calculateImageWidth(String imgWidthVariant) {
if (imgWidthVariant.equals(IMG_WIDTH_LARGE)) {
// large image
if (isFixedImageSize() && getImgWidthLarge() > 0) {
return getImgWidthLarge();
}
return getColumnWidth();
} else if (imgWidthVariant.equals(IMG_WIDTH_SMALL)) {
// small image
if (isFixedImageSize() && getImgWidthSmall() > 0) {
return getImgWidthSmall();
}
return (getColumnWidth() / 4);
} else {
// medium image
if (isFixedImageSize() && getImgWidthMedium() > 0) {
return getImgWidthMedium();
}
return (int)Math.round(getColumnWidth() / 2.3);
}
}
/**
* Returns the JSP action element to get access to the OpenCms API.<p>
*
* @return the JSP action element to get access to the OpenCms API
*/
protected CmsJspActionElement getCmsJspActionElement() {
return m_jspActionElement;
}
/**
* Returns the OpenCms user context to use.<p>
*
* @return the OpenCms user context to use
*/
protected CmsObject getCmsObject() {
return m_jspActionElement.getCmsObject();
}
/**
* Returns an initialized image scaler depending on the image align to use.<p>
*
* @param paragraphType the paragraph type to show
* @param imgSize the image size property value containing the original image information
* @return an initialized image scaler depending on the image align to use
*/
protected CmsImageScaler getImageScaler(String paragraphType, String imgSize) {
// get the image width variant to use from the paragraph layout pattern Map
String imgWidthVariant = (String)getLayoutPatterns().get(paragraphType);
if (CmsStringUtil.isEmpty(imgWidthVariant)) {
// did not find a value, provide a default width
imgWidthVariant = IMG_WIDTH_MEDIUM;
}
// calculate image width to use depending on the column width
int imgWidth = calculateImageWidth(imgWidthVariant);
// create scaler instance of original image
CmsImageScaler origImage = new CmsImageScaler(imgSize);
// create scaler with desired image width
CmsImageScaler scaler = new CmsImageScaler();
scaler.setWidth(imgWidth);
// return scaler with result image width
return origImage.getWidthScaler(scaler);
}
/**
* Creates a valid JavaScript link to open a larger image version in a new popup window.<p>
*
* @param imgUri the URI of the image to link to
* @param imgSize the image size property value containing the original image information
* @return a valid JavaScript link to open a larger image version in a new popup window
*/
protected String getLinkToLargeImage(String imgUri, String imgSize) {
StringBuffer elementLink = new StringBuffer(128);
elementLink.append(CmsWorkplace.VFS_PATH_MODULES);
elementLink.append(MODULE_NAME);
elementLink.append("/elements/popup-image.html?uri=");
elementLink.append(imgUri);
elementLink.append("&imgsize=");
elementLink.append(imgSize);
elementLink.append("&");
elementLink.append(CmsLocaleManager.PARAMETER_LOCALE);
elementLink.append("=");
elementLink.append(getCmsObject().getRequestContext().getLocale());
StringBuffer tempLink = new StringBuffer(256);
tempLink.append("javascript:window.open('");
tempLink.append(getCmsJspActionElement().link(elementLink.toString()));
tempLink.append("', 'largeImage', ");
tempLink.append("'width=620,height=400,location=no,menubar=no,toolbar=no,status=no,scrollbars=yes,resizable=yes');");
return tempLink.toString();
}
/**
* Returns an initialized macro wrapper that can be used for the paragraph output.<p>
*
* @return an initialized macro wrapper that can be used for the paragraph output
* @throws Exception if the initialization of the wrapper fails
*/
protected I_CmsMacroWrapper getMacroWrapper() throws Exception {
// create path to macro file to use
StringBuffer macroFile = new StringBuffer(256);
macroFile.append(getPathLayoutElements());
macroFile.append(getColumnLayout());
macroFile.append("_");
macroFile.append(getVariant());
macroFile.append(".");
macroFile.append(CmsMacroWrapperFreeMarker.FILE_SUFFIX);
String fileName = macroFile.toString();
if (!getCmsObject().existsResource(fileName)) {
// macro file not found, log error and throw exception
if (LOG.isErrorEnabled()) {
LOG.error(Messages.get().getBundle().key(Messages.LOG_ERR_VFS_RESOURCE_1, fileName));
}
throw new CmsException(Messages.get().container(Messages.LOG_ERR_VFS_RESOURCE_1, fileName));
}
return new CmsMacroWrapperFreeMarker(getCmsObject(), fileName);
}
/**
* Returns the String value of the xml content defined by the value(s) inside the given extended properties.<p>
*
* @param xmlElements the instance of ExtendedProperties for the integrated resource type, e.g. news.
* @param key key is used to identify the value inside the given map.
* @param xmlContentFileLink the xml content of the integrated file.
* @param locale the locale object.
* @return the String value of the xml content defined by the value(s) inside the given map.
*/
protected String getPropertiesValue(
ExtendedProperties xmlElements,
String key,
CmsXmlContent xmlContentFileLink,
Locale locale) {
Object value = xmlElements.get(key);
String result = "";
if (value != null) {
if (value instanceof String) {
// if value is a String object get the string value from the xml content
result = xmlContentFileLink.getStringValue(getCmsObject(), (String)value, locale);
} else if (value instanceof Vector) {
// if value is a vector iterate over it
Iterator it_title = ((Vector)value).iterator();
while (it_title.hasNext()) {
String next = (String)it_title.next();
if (!CmsStringUtil.isEmptyOrWhitespaceOnly(xmlContentFileLink.getStringValue(
getCmsObject(),
next,
locale))
&& !xmlContentFileLink.getStringValue(getCmsObject(), next, locale).equals("(none)")) {
if (result.length() > 1 && result.lastIndexOf(",") != result.length()) {
// only append ',' if the result String is already in use
result += ",";
}
// add the String value from the xml content for the given String of the vector
result += xmlContentFileLink.getStringValue(getCmsObject(), next, locale);
}
}
}
} else {
result = "";
}
return result;
}
/**
* Returns an instance of ExtendedProperties with key-values pairs which can be used to build e.g. the headline.<p>
*
* @param linkToFile xml content file which is integrated inside the layout page
* @return an instance of ExtendedProperties with key-value pairs which define the elements to use inside
* an integrated xml content, e.g. to build the headline
*/
protected ExtendedProperties getXmlElementsProperties(CmsFile linkToFile) {
ExtendedProperties properties = new ExtendedProperties();
try {
// get the type name for the integrated file
// type name is used as key for m_typeMappings
String typeName = OpenCms.getResourceManager().getResourceType(linkToFile.getTypeId()).getTypeName();
if (m_typeMappings.get(typeName) == null) {
// get key/value from the .properties file and store it in properties and m_typeMappings
properties.load(new ByteArrayInputStream(
getCmsObject().readFile(
CmsWorkplace.VFS_PATH_MODULES + MODULE_NAME + "/mappings/" + typeName + ".properties").getContents()));
m_typeMappings.put(typeName, properties);
} else {
// if typeName is already used inside m_typeProperties get properties from this map
properties = (ExtendedProperties)m_typeMappings.get(typeName);
}
} catch (Exception e) {
// ignore
}
return properties;
}
/**
* Sets the calculated width of a single paragraph column.<p>
*
* @param columnWidth the calculated width of a single paragraph column
*/
protected void setColumnWidth(int columnWidth) {
m_columnWidth = columnWidth;
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?