📄 cmspicturebrowser.java
字号:
}
/**
* Gets the filenames of all picture galleries
* <P>
* The given vectors <code>names</code> and <code>values</code> will
* be filled with the appropriate information to be used for building
* a select box. The values will be the paths to the galleries.
*
* @param cms CmsObject Object for accessing system resources.
* @param names Vector to be filled with the appropriate values in this method.
* @param values Vector to be filled with the appropriate values in this method.
* @param parameters Hashtable containing all user parameters <em>(not used here)</em>.
* @return Index of the selected Gallery
* @throws CmsException
*/
public Integer getPicGalleryNames(CmsObject cms, CmsXmlLanguageFile lang,
Vector names, Vector values, Hashtable parameters) throws CmsException {
return getGalleryNames(cms, getConfigFile(cms).getPicGalleryPath(), lang, names, values, parameters);
}
/**
* Indicates if the results of this class are cacheable.
*
* @param cms CmsObject Object for accessing system resources
* @param templateFile Filename of the template file
* @param elementName Element name of this template in our parent template.
* @param parameters Hashtable with all template class parameters.
* @param templateSelector template section that should be processed.
* @return <EM>true</EM> if cacheable, <EM>false</EM> otherwise.
*/
public boolean isCacheable(CmsObject cms, String templateFile, String elementName,
Hashtable parameters, String templateSelector) {
return false;
}
/**
* Checks, if the given filename ends with a typical picture suffix.
* @param filename filename to be checked.
* @return <code>true</code> if the is an image file, <code>false</code> otherwise.
*/
private boolean isImage(String filename) {
if(filename.toLowerCase().endsWith("gif") || filename.toLowerCase().endsWith("jpg")
|| filename.toLowerCase().endsWith("jpeg")) {
return true;
}
else {
return false;
}
}
/**
* User method to generate an URL for the pics folder.
* <P>
* All pictures should reside in the docroot of the webserver for
* performance reasons. This folder can be mounted into the OpenCms system to
* make it accessible for the OpenCms explorer.
* <P>
* The path to the docroot can be set in the workplace ini.
*
* @param cms CmsObject Object for accessing system resources.
* @param tagcontent Unused in this special case of a user method. Can be ignored.
* @param doc Reference to the A_CmsXmlContent object of the initiating XLM document <em>(not used here)</em>.
* @param userObj Hashtable with parameters <em>(not used here)</em>.
* @return String with the pics URL.
* @throws CmsException
*/
public Object pictureList(CmsObject cms, String tagcontent, A_CmsXmlContent doc,
Object userObj) throws CmsException {
I_CmsSession session = cms.getRequestContext().getSession(true);
Hashtable parameters = (Hashtable)userObj;
CmsXmlWpTemplateFile xmlTemplateDocument = (CmsXmlWpTemplateFile)doc;
CmsXmlLanguageFile lang = new CmsXmlLanguageFile(cms);
StringBuffer result = new StringBuffer();
String pageText = (String)parameters.get(C_PARA_PAGE);
// Filter the pics
Vector filteredPics = (Vector)parameters.get("_PICLIST_");
int numPics = filteredPics.size();
// Get limits for the requested page
int page = new Integer(pageText).intValue();
int from = (page - 1) * C_PICBROWSER_MAXIMAGES;
int to = ((from + C_PICBROWSER_MAXIMAGES) > numPics) ? numPics : (from + C_PICBROWSER_MAXIMAGES);
String folder = (String)parameters.get(C_PARA_FOLDER);
if(folder == null) {
folder = (String)session.getValue(C_PARA_FOLDER);
}
if(folder == null || "".equals(folder)) {
folder = getConfigFile(cms).getPicGalleryPath();
parameters.put(C_PARA_FOLDER, folder);
}
String picsUrl = cms.getRequestContext().getRequest().getServletUrl() + folder;
// Generate the picture list for all pictures on the selected page
for(int i = from;i < to;i++) {
CmsFile file = (CmsFile)filteredPics.elementAt(i);
String filename = file.getName();
String title = cms.readProperty(file.getAbsolutePath(), C_PROPERTY_TITLE);
// If no "Title" property is given, the title will be set to the filename
// without its postfix
int dotIndex = filename.lastIndexOf(".");
if(title == null) {
if(dotIndex > 0) {
title = filename.substring(0, dotIndex);
}
else {
title = filename;
}
}
// The displayed type will be generated from the filename postfix
String type;
if(dotIndex > 0) {
type = filename.substring(filename.lastIndexOf(".") + 1).toUpperCase() + "-Bild";
}
else {
type = lang.getLanguageValue("input.unknown");
}
// Set all datablocks for the current picture list entry
xmlTemplateDocument.setData("picsource", picsUrl + file.getName());
xmlTemplateDocument.setData("filepath", file.getAbsolutePath());
xmlTemplateDocument.setData("title", Encoder.escapeXml(title));
xmlTemplateDocument.setData("filename", filename);
xmlTemplateDocument.setData("size", file.getLength() + " Byte");
xmlTemplateDocument.setData("type", type);
if (cms.accessLock(file.getAbsolutePath())) {
xmlTemplateDocument.setData("delete", xmlTemplateDocument.getProcessedDataValue("deleteentry", this));
} else {
xmlTemplateDocument.setData("delete", " ");
}
// look if the onclick event must be set
//String paraSetOnClick = (String)parameters.get("setonclick");
String paraSetOnClick = (String)session.getValue("picBrowser_for_ext_nav");
String setOnClick = "";
if ("true".equals(paraSetOnClick)){
setOnClick = xmlTemplateDocument.getProcessedDataValue("clickentry");
}
xmlTemplateDocument.setData("toclickornot", setOnClick);
result.append(xmlTemplateDocument.getProcessedDataValue("piclistentry", this, userObj));
// if this is not the last entry on the current page,
// append a separator
if(i < (to - 1)) {
result.append(xmlTemplateDocument.getProcessedDataValue("part", this, userObj));
}
}
return result.toString();
}
/**
* Used by the workplace "back" button to decide whether the icon should
* be activated or not. A button will use this method if the attribute <code>method="showBackButton"</code>
* is defined in the <code><BUTTON></code> tag.
* <P>
* This method returns <code>false</code> if the currently displayed page is
* the first page.
*
* @param cms CmsObject Object for accessing system resources <em>(not used here)</em>.
* @param lang reference to the currently valid language file <em>(not used here)</em>.
* @param parameters Hashtable containing all user parameters <em>(not used here)</em>.
* @return <code>true</code> if the button should be enabled, <code>false</code> otherwise.
*/
public Boolean showBackButton(CmsObject cms, CmsXmlLanguageFile lang, Hashtable parameters) {
// Get the current page number
String pageText = (String)parameters.get(C_PARA_PAGE);
int page = new Integer(pageText).intValue();
return new Boolean(page > 1);
}
/**
* Used by the workplace "next" button to decide whether the icon should
* be activated or not. A button will use this method if the attribute <code>method="showNextButton"</code>
* is defined in the <code><BUTTON></code> tag.
* <P>
* This method returns <code>false</code> if the currently displayed page is
* the last page.
*
* @param cms CmsObject Object for accessing system resources <em>(not used here)</em>.
* @param lang reference to the currently valid language file <em>(not used here)</em>.
* @param parameters Hashtable containing all user parameters <em>(not used here)</em>.
* @return <code>true</code> if the button should be enabled, <code>false</code> otherwise.
*/
public Boolean showNextButton(CmsObject cms, CmsXmlLanguageFile lang, Hashtable parameters) {
// Get the current page number
String pageText = (String)parameters.get(C_PARA_PAGE);
int page = new Integer(pageText).intValue();
// get the number of pics
Vector filteredPics = (Vector)parameters.get("_PICLIST_");
int numPics = filteredPics.size();
// Get the maximum page number
int maxpage = ((numPics - 1) / C_PICBROWSER_MAXIMAGES) + 1;
return new Boolean(page < maxpage);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -