📄 cmsxmlformtemplatefile.java
字号:
// call the method for generating listbox elements
Method groupsMethod = null;
int selectedOption = 0;
try {
groupsMethod = callingObject.getClass().getMethod(radioMethod, new Class[] {
CmsObject.class, Vector.class, Vector.class, Hashtable.class
});
returnObject = (Integer)groupsMethod.invoke(callingObject, new Object[] {
m_cms, names, values, parameters
});
}
catch(NoSuchMethodException exc) {
// The requested method was not found.
throwException("Could not find radio button method " + radioMethod + " in calling class " + callingObject.getClass().getName()
+ " for generating select box content.", CmsException.C_NOT_FOUND);
}
catch(InvocationTargetException targetEx) {
// the method could be invoked, but throwed a exception
// itself. Get this exception and throw it again.
Throwable e = targetEx.getTargetException();
if(!(e instanceof CmsException)) {
// Only print an error if this is NO CmsException
throwException("Radio button method " + radioMethod + " in calling class " + callingObject.getClass().getName()
+ " throwed an exception. " + e, CmsException.C_UNKNOWN_EXCEPTION);
}
else {
// This is a CmsException
// Error printing should be done previously.
throw (CmsException)e;
}
}
catch(Exception exc2) {
throwException("Radio button method " + radioMethod + " in calling class " + callingObject.getClass().getName()
+ " was found but could not be invoked. " + exc2, CmsException.C_XML_NO_USER_METHOD);
}
// If the radio button method returned a value, use it for preselecting an option
if(returnObject != null) {
selectedOption = ((Integer)returnObject).intValue();
}
// process the vectors with the elelmetns of the radio buttons to be displayed.
int numValues = values.size();
CmsXmlTemplateFile radiodef = new CmsXmlTemplateFile(m_cms, "/content/internal/HTMLFormDefs");
if(radioClass == null || "".equals(radioClass)) {
radiodef.setData(C_RADIO_CLASS, "");
}
else {
radiodef.setData(C_RADIO_CLASSNAME, radioClass);
radiodef.setData(C_RADIO_CLASS, radiodef.getProcessedData(C_TAG_RADIO_CLASS));
}
for(int i = 0;i < numValues;i++) {
// Set values for this radiobutton entry
radiodef.setData(C_RADIO_RADIONAME, radioName);
radiodef.setData(C_RADIO_NAME, (String)names.elementAt(i));
radiodef.setData(C_RADIO_LINK, (String)values.elementAt(i));
// Check, if this should be the preselected option
if(i == selectedOption) {
radiodef.setData(C_RADIO_SELECTEDENTRY, radiodef.getDataValue("radiobuttons." + C_RADIO_SELECTEDOPTION));
}
else {
radiodef.setData(C_RADIO_SELECTEDENTRY, "");
}
// Now get output for this option
if(radioOrder.equals("col")) {
// Buttons should be displayed in one column
result.append(radiodef.getProcessedDataValue(C_TAG_RADIO_COLENTRY, callingObject));
}
else {
// Buttons should be displayed in a row.
result.append(radiodef.getProcessedDataValue(C_TAG_RADIO_ROWENTRY, callingObject));
}
}
return result.toString();
}
/**
* Handles any occurence of the special XML tag <code><SELECT></code> for
* generating HTML form select boxes.
* <P>
* The definition of a HTML selectbox will be taken from /content/internal/HTMLFormDefs.
* If the file is missing, this method will crash. Ensure this file is created and filled
* with all required XML tags.
* <P>
* Select boxes can be generated by adding the special XML tag
* <code><SELECT class="myClass" method="myMethod" name="myName" onchange="..." size="..."/></code>
* to the template file. This tag will be replaced with the correspondig select box
* while processing the template file. The <code>class</code> parameter is optional and
* The <code>method</code> parameter will be used to look up a user defined method
* in the template class assigned to the template file. This method should look like
* <br/>
* <code>public Integer myMethod(CmsObject cms, Vector names, Vector values, Hashtable parameters)</code><br/>
* and will be used to get the content of the requested select box group. The vectors <code>names</code>
* and <code>values</code> should be filled with the appropriate values. The return value should be an
* Integer containing the pre-selected option or -1, if no value should be pre-selected.
*
* @param n XML element containing the current special workplace tag.
* @param callingObject reference to the calling object.
* @param userObj hashtable containig all user parameters.
* @exception CmsException
*/
public Object handleSelectTag(Element n, Object callingObject, Object userObj) throws CmsException {
Hashtable parameters = (Hashtable)userObj;
// Here the different select box options will be stored
Vector values = new Vector();
Vector names = new Vector();
// StringBuffer for the generated output *
StringBuffer result = new StringBuffer();
// Read selectbox parameters
String selectClass = n.getAttribute(C_SELECTBOX_CLASS);
String selectName = n.getAttribute(C_SELECTBOX_NAME);
String selectMethod = n.getAttribute(C_SELECTBOX_METHOD);
String selectWidth = n.getAttribute(C_SELECTBOX_WIDTH);
String selectOnchange = n.getAttribute(C_SELECTBOX_ONCHANGE);
String selectSize = n.getAttribute(C_SELECTBOX_SIZE);
if((selectSize == null) || (selectSize.length() == 0)) {
selectSize = "1";
}
// Get input definition file
CmsXmlTemplateFile inputdef = new CmsXmlTemplateFile(m_cms, "/content/internal/HTMLFormDefs");
// Set the prefix string of the select box
if(selectClass == null || "".equals(selectClass)) {
inputdef.setData(C_SELECTBOX_CLASS, "");
}
else {
inputdef.setData(C_SELECTBOX_CLASSNAME, selectClass);
inputdef.setData(C_SELECTBOX_CLASS, inputdef.getProcessedData(C_TAG_SELECTBOX_CLASS));
}
if(selectWidth == null || "".equals(selectWidth)) {
inputdef.setData(C_SELECTBOX_WIDTH, "");
}
else {
inputdef.setData(C_SELECTBOX_WIDTHNAME, selectWidth);
inputdef.setData(C_SELECTBOX_WIDTH, inputdef.getProcessedData(C_TAG_SELECTBOX_WIDTH));
}
inputdef.setData(C_SELECTBOX_NAME, selectName);
inputdef.setData(C_SELECTBOX_ONCHANGE, selectOnchange);
inputdef.setData(C_SELECTBOX_SIZE, selectSize);
// move the prefix string of the select box to the result StringBuffer
result.append(inputdef.getProcessedDataValue(C_TAG_SELECTBOX_START));
// call the method for generating listbox elements
Method groupsMethod = null;
int selectedOption = 0;
try {
groupsMethod = callingObject.getClass().getMethod(selectMethod, new Class[] {
CmsObject.class, Vector.class, Vector.class, Hashtable.class
});
selectedOption = ((Integer)groupsMethod.invoke(callingObject, new Object[] {
m_cms, values, names, parameters
})).intValue();
}
catch(NoSuchMethodException exc) {
// The requested method was not found.
throwException("Could not find method " + selectMethod + " in calling class " + callingObject.getClass().getName()
+ " for generating select box content.", CmsException.C_NOT_FOUND);
}
catch(InvocationTargetException targetEx) {
// the method could be invoked, but throwed a exception
// itself. Get this exception and throw it again.
Throwable e = targetEx.getTargetException();
if(!(e instanceof CmsException)) {
// Only print an error if this is NO CmsException
throwException("User method " + selectMethod + " in calling class " + callingObject.getClass().getName()
+ " throwed an exception. " + e, CmsException.C_UNKNOWN_EXCEPTION);
}
else {
// This is a CmsException
// Error printing should be done previously.
throw (CmsException)e;
}
}
catch(Exception exc2) {
throwException("User method " + selectMethod + " in calling class " + callingObject.getClass().getName()
+ " was found but could not be invoked. " + exc2, CmsException.C_XML_NO_USER_METHOD);
}
// check the returned elements and put them into option tags.
// The element with index "selectedOption" has to get the "selected" tag.
int numValues = values.size();
for(int i = 0;i < numValues;i++) {
inputdef.setData(C_SELECTBOX_OPTIONNAME, (String)names.elementAt(i));
inputdef.setData(C_SELECTBOX_OPTIONVALUE, (String)values.elementAt(i));
if(i == selectedOption) {
result.append(inputdef.getProcessedDataValue(C_TAG_SELECTBOX_SELOPTION));
}
else {
result.append(inputdef.getProcessedDataValue(C_TAG_SELECTBOX_OPTION));
}
}
// get the processed selectbox end sequence.
result.append(inputdef.getProcessedDataValue(C_TAG_SELECTBOX_END));
return result.toString();
}
/**
* Registers the special tags for processing with
* processNode().
*/
private void registerMyTags() {
super.registerTag("SELECT", CmsXmlFormTemplateFile.class, "handleSelectTag", C_REGISTER_MAIN_RUN);
super.registerTag("RADIOBUTTON", CmsXmlFormTemplateFile.class, "handleRadiobuttonTag", C_REGISTER_MAIN_RUN);
// just to be sure this is in the workplace view always aktiv
super.registerTag("ELEMENT", CmsXmlTemplateFile.class, "handleElementTag", C_REGISTER_MAIN_RUN);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -