📄 cmsnewresourcelink.java
字号:
}
// set lasturl
if(lastUrl == null) {
lastUrl = C_WP_EXPLORER_FILELIST;
}
xmlTemplateDocument.setData("lasturl", lastUrl);
// set the templateselector if there was an error
if(!checkurl){
xmlTemplateDocument.setData("folder", foldername);
xmlTemplateDocument.setData("newlink", notChange);
session.putValue(C_PARA_LINK, link.trim());
session.putValue(C_PARA_FILE, filename.trim());
session.putValue(C_PARA_NAVTEXT, navtitle);
session.putValue(C_PARA_NAVPOS, navpos);
templateSelector = "errorcheckurl";
}
if(!"".equals(error.trim())){
xmlTemplateDocument.setData("errordetails", error);
session.putValue(C_PARA_LINK, link.trim());
session.putValue(C_PARA_FILE, filename.trim());
session.putValue(C_PARA_NAVTEXT, navtitle);
session.putValue(C_PARA_NAVPOS, navpos);
templateSelector = "error";
}
// process the selected template
return startProcessing(cms, xmlTemplateDocument, elementName, parameters, templateSelector);
}
/**
* 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;
}
/**
* Sets the value of the new file input field of dialog.
* This method is directly called by the content definiton.
* @param Cms The CmsObject.
* @param lang The language file.
* @param parameters User parameters.
* @return Value that is set into the new file dialod.
* @throws CmsExeption if something goes wrong.
*/
public String setValue(CmsObject cms, CmsXmlLanguageFile lang, Hashtable parameters) throws CmsException {
I_CmsSession session = cms.getRequestContext().getSession(true);
// get a previous value from the session
String filename = (String)session.getValue(C_PARA_FILE);
if(filename == null) {
filename = "";
}
return filename;
}
/**
* Gets the files displayed in the navigation select box.
* @param cms The CmsObject.
* @param lang The langauge definitions.
* @param names The names of the new rescources.
* @param values The links that are connected with each resource.
* @param parameters Hashtable of parameters (not used yet).
* @return The vectors names and values are filled with data for building the navigation.
* @throws Throws CmsException if something goes wrong.
*/
public Integer getNavPos(CmsObject cms, CmsXmlLanguageFile lang, Vector names,
Vector values, Hashtable parameters) throws CmsException {
int retValue = -1;
I_CmsSession session = cms.getRequestContext().getSession(true);
String preselect = (String)session.getValue(C_PARA_NAVPOS);
// get the nav information
Hashtable storage = getNavData(cms);
if(storage.size() > 0) {
String[] nicenames = (String[])storage.get("NICENAMES");
int count = ((Integer)storage.get("COUNT")).intValue();
// finally fill the result vectors
for(int i = 0;i <= count;i++) {
names.addElement(Encoder.escapeHtml(nicenames[i]));
values.addElement(Encoder.escapeHtml(nicenames[i]));
if ((preselect != null) && (preselect.equals(nicenames[i]))){
retValue = values.size() -1;
}
}
}
else {
values = new Vector();
}
if (retValue == -1){
// set the default value to no change
return new Integer(values.size() - 1);
}else{
return new Integer(retValue);
}
}
/**
* Gets all required navigation information from the files and subfolders of a folder.
* A file list of all files and folder is created, for all those resources, the navigation
* property is read. The list is sorted by their navigation position.
* @param cms The CmsObject.
* @return Hashtable including three arrays of strings containing the filenames,
* nicenames and navigation positions.
* @throws Throws CmsException if something goes wrong.
*/
private Hashtable getNavData(CmsObject cms) throws CmsException {
I_CmsSession session = cms.getRequestContext().getSession(true);
CmsXmlLanguageFile lang = new CmsXmlLanguageFile(cms);
String[] filenames;
String[] nicenames;
String[] positions;
Hashtable storage = new Hashtable();
CmsFolder folder = null;
CmsFile file = null;
String nicename = null;
String currentFilelist = null;
int count = 1;
float max = 0;
// get the current folder
currentFilelist = (String)session.getValue(C_PARA_FILELIST);
if(currentFilelist == null) {
currentFilelist = cms.rootFolder().getAbsolutePath();
}
// get all files and folders in the current filelist.
Vector files = cms.getFilesInFolder(currentFilelist);
Vector folders = cms.getSubFolders(currentFilelist);
// combine folder and file vector
Vector filefolders = new Vector();
Enumeration enum = folders.elements();
while(enum.hasMoreElements()) {
folder = (CmsFolder)enum.nextElement();
filefolders.addElement(folder);
}
enum = files.elements();
while(enum.hasMoreElements()) {
file = (CmsFile)enum.nextElement();
filefolders.addElement(file);
}
if(filefolders.size() > 0) {
// Create some arrays to store filename, nicename and position for the
// nav in there. The dimension of this arrays is set to the number of
// found files and folders plus two more entrys for the first and last
// element.
filenames = new String[filefolders.size() + 2];
nicenames = new String[filefolders.size() + 2];
positions = new String[filefolders.size() + 2];
//now check files and folders that are not deleted and include navigation
// information
enum = filefolders.elements();
while(enum.hasMoreElements()) {
CmsResource res = (CmsResource)enum.nextElement();
// check if the resource is not marked as deleted
if(res.getState() != C_STATE_DELETED) {
String navpos = cms.readProperty(res.getAbsolutePath(), C_PROPERTY_NAVPOS);
// check if there is a navpos for this file/folder
if(navpos != null) {
nicename = cms.readProperty(res.getAbsolutePath(), C_PROPERTY_NAVTEXT);
if(nicename == null) {
nicename = res.getName();
}
// add this file/folder to the storage.
filenames[count] = res.getAbsolutePath();
nicenames[count] = nicename;
positions[count] = navpos;
if(new Float(navpos).floatValue() > max) {
max = new Float(navpos).floatValue();
}
count++;
}
}
}
}
else {
filenames = new String[2];
nicenames = new String[2];
positions = new String[2];
}
// now add the first and last value
filenames[0] = "FIRSTENTRY";
nicenames[0] = lang.getLanguageValue("input.firstelement");
positions[0] = "0";
filenames[count] = "LASTENTRY";
nicenames[count] = lang.getLanguageValue("input.lastelement");
positions[count] = new Float(max + 1).toString();
// finally sort the nav information.
sort(cms, filenames, nicenames, positions, count);
// put all arrays into a hashtable to return them to the calling method.
storage.put("FILENAMES", filenames);
storage.put("NICENAMES", nicenames);
storage.put("POSITIONS", positions);
storage.put("COUNT", new Integer(count));
return storage;
}
/**
* Sorts a set of three String arrays containing navigation information depending on
* their navigation positions.
* @param cms Cms Object for accessign files.
* @param filenames Array of filenames
* @param nicenames Array of well formed navigation names
* @param positions Array of navpostions
*/
private void sort(CmsObject cms, String[] filenames, String[] nicenames, String[] positions, int max) {
// Sorting algorithm
// This method uses an bubble sort, so replace this with something more
// efficient
for(int i = max - 1;i > 1;i--) {
for(int j = 1;j < i;j++) {
float a = new Float(positions[j]).floatValue();
float b = new Float(positions[j + 1]).floatValue();
if(a > b) {
String tempfilename = filenames[j];
String tempnicename = nicenames[j];
String tempposition = positions[j];
filenames[j] = filenames[j + 1];
nicenames[j] = nicenames[j + 1];
positions[j] = positions[j + 1];
filenames[j + 1] = tempfilename;
nicenames[j + 1] = tempnicename;
positions[j + 1] = tempposition;
}
}
}
}
/**
* Updates the navigation position of all resources in the actual folder.
* @param cms The CmsObject.
* @param newfile The new file added to the nav.
* @param navpos The file after which the new entry is sorted.
*/
private void updateNavPos(CmsObject cms, CmsResource newfile, String newpos) throws CmsException {
float newPos = 0;
// get the nav information
Hashtable storage = getNavData(cms);
if(storage.size() > 0) {
String[] nicenames = (String[])storage.get("NICENAMES");
String[] positions = (String[])storage.get("POSITIONS");
int count = ((Integer)storage.get("COUNT")).intValue();
// now find the file after which the new file is sorted
int pos = 0;
for(int i = 0;i < nicenames.length;i++) {
if(newpos.equals((String)nicenames[i])) {
pos = i;
}
}
if(pos < count) {
float low = new Float(positions[pos]).floatValue();
float high = new Float(positions[pos + 1]).floatValue();
newPos = (high + low) / 2;
}
else {
newPos = new Float(positions[pos]).floatValue() + 1;
}
}
else {
newPos = 1;
}
cms.writeProperty(newfile.getAbsolutePath(), C_PROPERTY_NAVPOS, new Float(newPos).toString());
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -