1 28 29 package com.opencms.defaults; 30 31 import org.opencms.file.CmsFile; 32 import org.opencms.file.CmsObject; 33 import org.opencms.main.CmsException; 34 35 import com.opencms.legacy.CmsLegacyException; 36 import com.opencms.template.CmsXmlTemplateFile; 37 import com.opencms.workplace.CmsWorkplaceDefault; 38 39 import java.lang.reflect.InvocationTargetException ; 40 import java.lang.reflect.Method ; 41 import java.util.Hashtable ; 42 import java.util.Vector ; 43 44 import org.w3c.dom.Element ; 45 46 57 public class CmsXmlFormTemplateFile extends CmsXmlTemplateFile { 58 59 64 public CmsXmlFormTemplateFile() throws CmsException { 65 super(); 66 registerMyTags(); 67 } 68 69 77 public CmsXmlFormTemplateFile(CmsObject cms, CmsFile file) throws CmsException { 78 super(); 79 registerMyTags(); 80 init(cms, file); 81 } 82 83 91 public CmsXmlFormTemplateFile(CmsObject cms, String filename) throws CmsException { 92 super(); 93 registerMyTags(); 94 init(cms, filename); 95 } 96 97 102 public String getXmlDocumentTagName() { 103 return "XMLTEMPLATE"; 104 } 105 106 132 public Object handleRadiobuttonTag(Element n, Object callingObject, Object userObj) throws CmsException { 133 Hashtable parameters = (Hashtable )userObj; 134 135 StringBuffer result = new StringBuffer (); 137 138 Vector values = new Vector (); 140 Vector names = new Vector (); 141 Integer returnObject = null; 142 143 String radioClass = n.getAttribute(CmsWorkplaceDefault.C_SELECTBOX_CLASS); 145 String radioName = n.getAttribute(CmsWorkplaceDefault.C_RADIO_NAME); 146 String radioMethod = n.getAttribute(CmsWorkplaceDefault.C_RADIO_METHOD); 147 String radioOrder = n.getAttribute(CmsWorkplaceDefault.C_RADIO_ORDER); 148 if (radioOrder == null || ((!"row".equals(radioOrder)) && (!"col".equals(radioOrder)))) { 149 radioOrder = "col"; 150 } 151 152 Method groupsMethod = null; 154 int selectedOption = 0; 155 try { 156 groupsMethod = callingObject.getClass().getMethod(radioMethod, new Class [] { 157 CmsObject.class, Vector .class, Vector .class, Hashtable .class 158 }); 159 returnObject = (Integer )groupsMethod.invoke(callingObject, new Object [] { 160 m_cms, names, values, parameters 161 }); 162 } catch (NoSuchMethodException exc) { 163 164 throwException("Could not find radio button method " + radioMethod + " in calling class " + callingObject.getClass().getName() 166 + " for generating select box content.", CmsLegacyException.C_NOT_FOUND); 167 } catch (InvocationTargetException targetEx) { 168 169 Throwable e = targetEx.getTargetException(); 172 if (!(e instanceof CmsException)) { 173 174 throwException("Radio button method " + radioMethod + " in calling class " + callingObject.getClass().getName() 176 + " throwed an exception. " + e, CmsLegacyException.C_UNKNOWN_EXCEPTION); 177 } else { 178 179 throw (CmsException)e; 182 } 183 } catch (Exception exc2) { 184 throwException("Radio button method " + radioMethod + " in calling class " + callingObject.getClass().getName() 185 + " was found but could not be invoked. " + exc2, CmsLegacyException.C_XML_NO_USER_METHOD); 186 } 187 188 if (returnObject != null) { 190 selectedOption = returnObject.intValue(); 191 } 192 193 int numValues = values.size(); 195 CmsXmlTemplateFile radiodef = new CmsXmlTemplateFile(m_cms, CmsWorkplaceDefault.C_VFS_PATH_DEFAULT_INTERNAL + "HTMLFormDefs"); 196 if (radioClass == null || "".equals(radioClass)) { 197 radiodef.setData(CmsWorkplaceDefault.C_RADIO_CLASS, ""); 198 } else { 199 radiodef.setData(CmsWorkplaceDefault.C_RADIO_CLASSNAME, radioClass); 200 radiodef.setData(CmsWorkplaceDefault.C_RADIO_CLASS, radiodef.getProcessedData(CmsWorkplaceDefault.C_TAG_RADIO_CLASS)); 201 } 202 for (int i = 0; i < numValues; i++) { 203 204 radiodef.setData(CmsWorkplaceDefault.C_RADIO_RADIONAME, radioName); 206 radiodef.setData(CmsWorkplaceDefault.C_RADIO_NAME, (String )names.elementAt(i)); 207 radiodef.setData(CmsWorkplaceDefault.C_RADIO_LINK, (String )values.elementAt(i)); 208 209 if (i == selectedOption) { 211 radiodef.setData(CmsWorkplaceDefault.C_RADIO_SELECTEDENTRY, radiodef.getDataValue("radiobuttons." + CmsWorkplaceDefault.C_RADIO_SELECTEDOPTION)); 212 } else { 213 radiodef.setData(CmsWorkplaceDefault.C_RADIO_SELECTEDENTRY, ""); 214 } 215 216 if (radioOrder.equals("col")) { 218 219 result.append(radiodef.getProcessedDataValue(CmsWorkplaceDefault.C_TAG_RADIO_COLENTRY, callingObject)); 221 } else { 222 223 result.append(radiodef.getProcessedDataValue(CmsWorkplaceDefault.C_TAG_RADIO_ROWENTRY, callingObject)); 225 } 226 } 227 return result.toString(); 228 } 229 230 256 public Object handleSelectTag(Element n, Object callingObject, Object userObj) throws CmsException { 257 258 Hashtable parameters = (Hashtable )userObj; 259 260 Vector values = new Vector (); 262 Vector names = new Vector (); 263 264 265 266 267 StringBuffer result = new StringBuffer (); 269 270 String selectClass = n.getAttribute(CmsWorkplaceDefault.C_SELECTBOX_CLASS); 272 String selectName = n.getAttribute(CmsWorkplaceDefault.C_SELECTBOX_NAME); 273 String selectMethod = n.getAttribute(CmsWorkplaceDefault.C_SELECTBOX_METHOD); 274 String selectWidth = n.getAttribute(CmsWorkplaceDefault.C_SELECTBOX_WIDTH); 275 String selectOnchange = n.getAttribute(CmsWorkplaceDefault.C_SELECTBOX_ONCHANGE); 276 String selectSize = n.getAttribute(CmsWorkplaceDefault.C_SELECTBOX_SIZE); 277 if ((selectSize == null) || (selectSize.length() == 0)) { 278 selectSize = "1"; 279 } 280 281 CmsXmlTemplateFile inputdef = new CmsXmlTemplateFile(m_cms, CmsWorkplaceDefault.C_VFS_PATH_DEFAULT_INTERNAL + "HTMLFormDefs"); 283 284 if (selectClass == null || "".equals(selectClass)) { 286 inputdef.setData(CmsWorkplaceDefault.C_SELECTBOX_CLASS, ""); 287 } else { 288 inputdef.setData(CmsWorkplaceDefault.C_SELECTBOX_CLASSNAME, selectClass); 289 inputdef.setData(CmsWorkplaceDefault.C_SELECTBOX_CLASS, inputdef.getProcessedData(CmsWorkplaceDefault.C_TAG_SELECTBOX_CLASS)); 290 } 291 if (selectWidth == null || "".equals(selectWidth)) { 292 inputdef.setData(CmsWorkplaceDefault.C_SELECTBOX_WIDTH, ""); 293 } else { 294 inputdef.setData(CmsWorkplaceDefault.C_SELECTBOX_WIDTHNAME, selectWidth); 295 inputdef.setData(CmsWorkplaceDefault.C_SELECTBOX_WIDTH, inputdef.getProcessedData(CmsWorkplaceDefault.C_TAG_SELECTBOX_WIDTH)); 296 } 297 inputdef.setData(CmsWorkplaceDefault.C_SELECTBOX_NAME, selectName); 298 inputdef.setData(CmsWorkplaceDefault.C_SELECTBOX_ONCHANGE, selectOnchange); 299 inputdef.setData(CmsWorkplaceDefault.C_SELECTBOX_SIZE, selectSize); 300 301 result.append(inputdef.getProcessedDataValue(CmsWorkplaceDefault.C_TAG_SELECTBOX_START)); 303 304 Method groupsMethod = null; 306 int selectedOption = 0; 307 try { 308 groupsMethod = callingObject.getClass().getMethod(selectMethod, new Class [] { 309 CmsObject.class, Vector .class, Vector .class, Hashtable .class 310 }); 311 selectedOption = ((Integer )groupsMethod.invoke(callingObject, new Object [] { 312 m_cms, values, names, parameters 313 })).intValue(); 314 } catch (NoSuchMethodException exc) { 315 316 throwException("Could not find method " + selectMethod + " in calling class " + callingObject.getClass().getName() 318 + " for generating select box content.", CmsLegacyException.C_NOT_FOUND); 319 } catch (InvocationTargetException targetEx) { 320 321 Throwable e = targetEx.getTargetException(); 324 if (!(e instanceof CmsException)) { 325 326 throwException("User method " + selectMethod + " in calling class " + callingObject.getClass().getName() 328 + " throwed an exception. " + e, CmsLegacyException.C_UNKNOWN_EXCEPTION); 329 } else { 330 331 throw (CmsException)e; 334 } 335 } catch (Exception exc2) { 336 throwException("User method " + selectMethod + " in calling class " + callingObject.getClass().getName() 337 + " was found but could not be invoked. " + exc2, CmsLegacyException.C_XML_NO_USER_METHOD); 338 } 339 340 int numValues = values.size(); 343 for (int i = 0; i < numValues; i++) { 344 inputdef.setData(CmsWorkplaceDefault.C_SELECTBOX_OPTIONNAME, (String )names.elementAt(i)); 345 inputdef.setData(CmsWorkplaceDefault.C_SELECTBOX_OPTIONVALUE, (String )values.elementAt(i)); 346 if (i == selectedOption) { 347 result.append(inputdef.getProcessedDataValue(CmsWorkplaceDefault.C_TAG_SELECTBOX_SELOPTION)); 348 } else { 349 result.append(inputdef.getProcessedDataValue(CmsWorkplaceDefault.C_TAG_SELECTBOX_OPTION)); 350 } 351 } 352 353 result.append(inputdef.getProcessedDataValue(CmsWorkplaceDefault.C_TAG_SELECTBOX_END)); 355 return result.toString(); 356 } 357 358 362 private void registerMyTags() { 363 super.registerTag("SELECT", CmsXmlFormTemplateFile.class, "handleSelectTag", C_REGISTER_MAIN_RUN); 364 super.registerTag("RADIOBUTTON", CmsXmlFormTemplateFile.class, "handleRadiobuttonTag", C_REGISTER_MAIN_RUN); 365 super.registerTag("ELEMENT", CmsXmlTemplateFile.class, "handleElementTag", C_REGISTER_MAIN_RUN); 367 } 368 } 369
| Popular Tags
|