📄 cmsproperty.java
字号:
if(newproperty != null) {
// check if the ok button was selected
if(newproperty.equals("true")) {
String newValue = (String)parameters.get("NEWPROPERTYVALUE");
if((newValue != null) && (propertydef != null)) {
// test if this property is already existing
String testValue = cms.readProperty(filename, propertydef);
if(testValue == null) {
// add the property
cms.writeProperty(filename, propertydef, newValue);
template = "ownlocked";
}
else {
// the key already exists, this is ok
}
}
else {
template = "ownlocked";
}
}
}
// new propertydef was selected
if(newpropertydef != null) {
// check if the ok button was selected
if(newpropertydef.equals("true")) {
String newValue = (String)parameters.get("NEWPROPERTYDEF");
if(newValue != null) {
// try to add the property
I_CmsResourceType type = cms.getResourceType(file.getType());
try {
cms.createPropertydefinition(newValue, type.getResourceTypeName());
template = "ownlocked";
}
catch(CmsException e) {
// todo: add an error message that this key is already exisitng
StringBuffer errmesg = new StringBuffer();
errmesg.append(lang.getLanguageValue("error.reason.newprop1") + " '" + newValue + "' " + lang.getLanguageValue("error.reason.newprop2") + " '" + type.getResourceTypeName() + "' " + lang.getLanguageValue("error.reason.newprop3") + "\n\n");
errmesg.append(Utils.getStackTrace(e));
xmlTemplateDocument.setData("NEWDETAILS", errmesg.toString());
template = "newerror";
}
}
else {
template = "ownlocked";
}
}
}
// set the required datablocks
String title = cms.readProperty(file.getAbsolutePath(), C_PROPERTY_TITLE);
if(title == null) {
title = "";
}
CmsUser owner = cms.readOwner(file);
xmlTemplateDocument.setData("TITLE", Encoder.escapeXml(title));
xmlTemplateDocument.setData("STATE", getState(cms, file, lang));
xmlTemplateDocument.setData("OWNER", owner.getFirstname() + " " + owner.getLastname() + "(" + owner.getName() + ")");
xmlTemplateDocument.setData("GROUP", cms.readGroup(file).getName());
xmlTemplateDocument.setData("FILENAME", file.getName());
xmlTemplateDocument.setData("lasturl", lasturl);
// process the selected template
return startProcessing(cms, xmlTemplateDocument, "", parameters, template);
}
/**
* Gets all properties of a resource.<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.
*
* @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 representing the current value in the vectors.
* @throws CmsException
*/
public Integer getProperty(CmsObject cms, CmsXmlLanguageFile lang, Vector names, Vector values, Hashtable parameters) throws CmsException {
int retValue = -1;
I_CmsSession session = cms.getRequestContext().getSession(true);
String filename = (String)session.getValue(C_PARA_FILE);
if(filename != null) {
Map properties = cms.readProperties(filename);
Iterator i = properties.keySet().iterator();
while(i.hasNext()) {
String key = (String)i.next();
String value = (String)properties.get(key);
names.addElement(Encoder.escapeXml(key + ":" + value));
values.addElement(Encoder.escapeXml(key));
}
Collections.sort(names);
Collections.sort(values);
}
// no current user, set index to -1
return new Integer(retValue);
}
/**
* Gets all unused propertydefintions for the file.<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.
*
* @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 representing the current value in the vectors.
* @throws CmsException
*/
public Integer getPropertydef(CmsObject cms, CmsXmlLanguageFile lang, Vector names, Vector values, Hashtable parameters) throws CmsException {
int retValue = -1;
I_CmsSession session = cms.getRequestContext().getSession(true);
String filename = (String)session.getValue(C_PARA_FILE);
if(filename != null) {
CmsResource file = (CmsResource)cms.readFileHeader(filename);
I_CmsResourceType type = cms.getResourceType(file.getType());
// get all existing properties of this file
Map properties = cms.readProperties(filename);
// get all propertydefinitions for this type
Vector propertydef = cms.readAllPropertydefinitions(type.getResourceTypeName());
Enumeration enu = propertydef.elements();
while(enu.hasMoreElements()) {
CmsPropertydefinition prop = (CmsPropertydefinition)enu.nextElement();
String propertyvalue = (String)properties.get(prop.getName());
if(propertyvalue == null) {
names.addElement(Encoder.escapeXml(prop.getName()));
values.addElement(Encoder.escapeXml(prop.getName()));
}
}
Collections.sort(names);
Collections.sort(values);
}
// no current user, set index to -1
return new Integer(retValue);
}
/**
* Gets the value of selected property and sets it in the input field of the 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 input field.
* @throws CmsExeption if something goes wrong.
*/
public String getPropertyValue(CmsObject cms, CmsXmlLanguageFile lang, Hashtable parameters) throws CmsException {
String propertyValue = null;
I_CmsSession session = cms.getRequestContext().getSession(true);
// get the filename
String filename = (String)session.getValue(C_PARA_FILE);
if(filename != null) {
//get the propertydefinition
String propertydef = (String)session.getValue(C_PARA_PROPERTYDEF);
if(propertydef != null) {
// everything is there, so try to read the meteainfo
propertyValue = cms.readProperty(filename, propertydef);
if(propertyValue == null) {
propertyValue = "";
}
}
}
return Encoder.escapeXml(propertyValue);
}
/**
* Gets a formated file state string.
* @param cms The CmsObject.
* @param file The CmsResource.
* @param lang The content definition language file.
* @return Formated state string.
*/
private String getState(CmsObject cms, CmsResource file, CmsXmlLanguageFile lang) throws CmsException {
StringBuffer output = new StringBuffer();
if(file.inProject(cms.getRequestContext().currentProject())) {
int state = file.getState();
output.append(lang.getLanguageValue("explorer.state" + state));
}
else {
output.append(lang.getLanguageValue("explorer.statenip"));
}
return output.toString();
}
/**
* 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;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -