📄 cmsxmlnav.java
字号:
}
return result;
}
/**
* gets the navigation of folders recursive.
*
* @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.
* @param userObj Hashtable with parameters.
* @return byte[] with the content of this subelement.
* @throws CmsException
*/
public Object getNavTree(CmsObject cms, String tagcontent, A_CmsXmlContent doc, Object userObject)
throws CmsException {
// template file
CmsXmlTemplateFile template=(CmsXmlTemplateFile)doc;
// check whether there exist entry datablock
if (!template.hasData("naventry")) {
return "".getBytes();
}
int level=1;
int depth=0;
int[] count={0};
String exact="false";
// if there is not any depth then it must not be tested in a if condition
boolean depthIsNull=true;
// if level is zero or null or negative then all folders recursive must
// be showed starting from root folder unless all folders stating from
// specified level of parent folder.
if (!tagcontent.equals("")) {
StringTokenizer st = new StringTokenizer(tagcontent,",");
String token1="",token2="",token3="";
if (st.hasMoreTokens())
token1=st.nextToken();
if (st.hasMoreTokens())
token2=st.nextToken();
if (st.hasMoreTokens())
token3=st.nextToken();
// now assign tokens to real values
if (!token3.equals(""))
exact=token3.toLowerCase();
if (!token2.equals("")) {
try {
depth=Integer.parseInt(token2);
} catch(NumberFormatException e) {
depth=0;
exact=token2.toLowerCase();
if (!exact.equals("true")) {
exact="false";
}
}
}
if (!token1.equals("")) {
try {
level=Integer.parseInt(token1);
} catch(NumberFormatException e) {
level=1;
exact=token1.toLowerCase();
if (!exact.equals("true")) {
exact="false";
}
}
}
}
// if level is not entered or it is less than zero then folder is the root folder
// otherwise the folder must be extracted accordeing to the entered level.
String folder=extractFolder(cms,level,exact);
if (folder.equals(""))
return "".getBytes();
if (depth>0) {
depthIsNull=false;
}
// register this folder for changes
Vector vfsDeps = new Vector();
vfsDeps.add(cms.readFolder(folder));
registerVariantDeps(cms, doc.getAbsoluteFilename(), null, null,
(Hashtable)userObject, vfsDeps, null, null);
// get all folders in specified folder
Vector resources=cms.getSubFolders(folder);
// get all files in specified folder
Vector allFile=cms.getFilesInFolder(folder);
// get a vector of all files und folders
resources.ensureCapacity(resources.size() + allFile.size());
Enumeration e = allFile.elements();
while (e.hasMoreElements()) {
resources.addElement(e.nextElement());
}
// get the uri,servletpath and current folder
String requestedUri = cms.getRequestContext().getUri();
String currentFolder=cms.getRequestContext().currentFolder().getAbsolutePath();
String servletPath = cms.getRequestContext().getRequest().getServletUrl();
String result="";
// check whether xml data blocks are defined.
// The main datablock is entry, it must be defined, the others will get
// the same datablock if they don't exist.
if (!template.hasData("navcurrent")) {
template.setData("navcurrent", template.getData("naventry"));
}
if (!template.hasData("navstart")) {
template.setData("navstart", "");
}
if (!template.hasData("navend")) {
template.setData("navend", "");
}
result=buildNavTree(cms,template,userObject,resources,requestedUri,currentFolder,servletPath,level,depth,depthIsNull,count);
return result.getBytes();
}
/**
* gets a specified property of current folder.
*
* @param cms A_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.
* @param userObj Hashtable with parameters.
* @return byte[] with the content of this subelement.
* @throws CmsException
*/
public Object getPropertyCurrent(CmsObject cms, String tagcontent, A_CmsXmlContent doc, Object userObject)
throws CmsException {
String property="";
// tagcontent must contain the property definition name.
if (!tagcontent.equals("")) {
String currentFolder=cms.getRequestContext().currentFolder().getAbsolutePath();
property=cms.readProperty(currentFolder, tagcontent);
property=(property!=null?property:"");
// register this folder for changes
Vector vfsDeps = new Vector();
vfsDeps.add(cms.readFolder(currentFolder));
registerVariantDeps(cms, doc.getAbsoluteFilename(), null, null,
(Hashtable)userObject, vfsDeps, null, null);
}
return (property.getBytes());
}
/**
* gets a specified property of specified folder starting from current folder.
*
* @param cms A_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.
* @param userObj Hashtable with parameters.
* @return byte[] with the content of this subelement.
* @throws CmsException
*/
public Object getPropertyParent(CmsObject cms, String tagcontent, A_CmsXmlContent doc, Object userObject)
throws CmsException {
int level=1;
String property="";
// tagcontent determines the parent folder starting from current folder and
// the property definition name sparated by a comma.
String exact="false";
// tagcontent determines the folder starting from root folder.
// if tagcontent is null, then the navigation of root folder must be showed.
if (!tagcontent.equals("")) {
try {
if (tagcontent.indexOf(",")!=-1) {
level=Integer.parseInt(tagcontent.substring(0,tagcontent.indexOf(",")));
exact=tagcontent.substring(tagcontent.indexOf(",")+1).toLowerCase();
} else {
level=Integer.parseInt(tagcontent);
}
} catch(NumberFormatException e) {
level=1;
exact=tagcontent.toLowerCase();
if (!exact.equals("true")) {
exact="false";
}
}
// level is converted to negative number, so I can use the method
// "extractFolder" for positive and negative numbers. Negative number
// determines the parent folder level starting from current folder and
// positive number determines the level starting ftom root folder.
String currentFolder=extractFolder(cms,((-1)*level),exact);
if (currentFolder.equals(""))
return "".getBytes();
property=cms.readProperty(currentFolder, tagcontent.substring(tagcontent.indexOf(",")+1));
property=(property!=null?property:"");
// register this folder for changes
Vector vfsDeps = new Vector();
vfsDeps.add(cms.readFolder(currentFolder));
registerVariantDeps(cms, doc.getAbsoluteFilename(), null, null,
(Hashtable)userObject, vfsDeps, null, null);
}
return (property.getBytes());
}
/**
* gets a specified property of specified folder starting from root.
*
* @param cms A_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.
* @param userObj Hashtable with parameters.
* @return byte[] with the content of this subelement.
* @throws CmsException
*/
public Object getPropertyRoot(CmsObject cms, String tagcontent, A_CmsXmlContent doc, Object userObject)
throws CmsException {
int level=1;
String property="";
String exact="false";
// tagcontent determines the folder starting from root folder.
// if tagcontent is null, then the navigation of root folder must be showed.
if (!tagcontent.equals("")) {
try {
if (tagcontent.indexOf(",")!=-1) {
level=Integer.parseInt(tagcontent.substring(0,tagcontent.indexOf(",")));
exact=tagcontent.substring(tagcontent.indexOf(",")+1).toLowerCase();
} else {
level=Integer.parseInt(tagcontent);
}
} catch(NumberFormatException e) {
level=1;
exact=tagcontent.toLowerCase();
if (!exact.equals("true")) {
exact="false";
}
}
String currentFolder=extractFolder(cms,level,exact);
if (currentFolder.equals(""))
return "".getBytes();
property=cms.readProperty(currentFolder, tagcontent.substring(tagcontent.indexOf(",")+1));
property=(property!=null?property:"");
// register this folder for changes
Vector vfsDeps = new Vector();
vfsDeps.add(cms.readFolder(currentFolder));
registerVariantDeps(cms, doc.getAbsoluteFilename(), null, null,
(Hashtable)userObject, vfsDeps, null, null);
}
return (property.getBytes());
}
/**
* gets a specified property of uri.
*
* @param cms A_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.
* @param userObj Hashtable with parameters.
* @return byte[] with the content of this subelement.
* @throws CmsException
*/
public Object getPropertyUri(CmsObject cms, String tagcontent, A_CmsXmlContent doc, Object userObject)
throws CmsException {
String property="";
String requestedUri = cms.getRequestContext().getUri();
property=cms.readProperty(requestedUri, tagcontent);
property=(property!=null?property:"");
// register this folder for changes
Vector vfsDeps = new Vector();
vfsDeps.add(cms.readFileHeader(requestedUri));
registerVariantDeps(cms, doc.getAbsoluteFilename(), null, null,
(Hashtable)userObject, vfsDeps, null, null);
return (property.getBytes());
}
/**
* gets the caching information from the current template class.
*
* @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 this class may stream it's results, <EM>false</EM> otherwise.
*/
public CmsCacheDirectives getCacheDirectives(CmsObject cms, String templateFile, String elementName, Hashtable parameters, String templateSelector) {
// First build our own cache directives.
CmsCache
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -