cmspicturebrowser.java
来自「java 编写的程序」· Java 代码 · 共 427 行 · 第 1/2 页
JAVA
427 行
if(chosenFolder.equals(currFolder.getAbsolutePath())) {
ret = i;
}
values.addElement(currFolder.getAbsolutePath());
names.addElement(name);
}
return new Integer(ret);
}
/**
* Checks, if the given filename matches the filter.
* @param filename filename to be checked.
* @param filter filter to be checked.
* @return <code>true</code> if the filename matches the filter, <code>false</code> otherwise.
*/
private boolean inFilter(String name, String filter) {
String compareName = name.toLowerCase();
String compareFilter = filter.toLowerCase();
if("".equals(compareFilter) || (compareName.indexOf(compareFilter) != -1)) {
return true;
}
else {
return false;
}
}
/**
* 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.
* @exception 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 = getConfigFile(cms).getCommonPictureUrl();
HttpServletRequest req = (HttpServletRequest)(cms.getRequestContext().getRequest().getOriginalRequest());
String hostName = ""; // no need for host information in editor any more
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.getDataValue("input.unknown");
}
// Set all datablocks for the current picture list entry
xmlTemplateDocument.setData("picsource", hostName + picsUrl + file.getName());
xmlTemplateDocument.setData("filepath", file.getAbsolutePath());
xmlTemplateDocument.setData("title", title);
xmlTemplateDocument.setData("filename", filename);
xmlTemplateDocument.setData("size", file.getLength() + " Byte");
xmlTemplateDocument.setData("type", type);
// 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 + =
减小字号Ctrl + -
显示快捷键?