1 28 29 30 package com.opencms.workplace; 31 32 import org.opencms.file.CmsObject; 33 import org.opencms.main.CmsException; 34 35 import com.opencms.legacy.CmsLegacyException; 36 import com.opencms.template.A_CmsXmlContent; 37 38 import java.lang.reflect.InvocationTargetException ; 39 import java.lang.reflect.Method ; 40 import java.util.Hashtable ; 41 import java.util.Vector ; 42 43 import org.w3c.dom.Element ; 44 45 56 57 public class CmsRadioButtons extends A_CmsWpElement { 58 59 77 78 public Object handleSpecialWorkplaceTag(CmsObject cms, Element n, A_CmsXmlContent doc, 79 Object callingObject, Hashtable parameters, CmsXmlLanguageFile lang) throws CmsException { 80 81 82 StringBuffer result = new StringBuffer (); 83 84 85 Vector values = new Vector (); 86 Vector names = new Vector (); 87 Vector descriptions = new Vector (); 88 Integer returnObject = null; 89 String radioName = n.getAttribute(CmsWorkplaceDefault.C_RADIO_NAME); 90 String radioMethod = n.getAttribute(CmsWorkplaceDefault.C_RADIO_METHOD); 91 String radioOrder = n.getAttribute(CmsWorkplaceDefault.C_RADIO_ORDER); 92 if(radioOrder == null || ((!"row".equals(radioOrder)) && (!"col".equals(radioOrder)))) { 93 radioOrder = "col"; 94 } 95 96 Method groupsMethod = null; 98 int selectedOption = 0; 99 try { 100 groupsMethod = callingObject.getClass().getMethod(radioMethod, new Class [] { 101 CmsObject.class, CmsXmlLanguageFile.class, Vector .class, 102 Vector .class, Vector .class, Hashtable .class 103 }); 104 returnObject = (Integer )groupsMethod.invoke(callingObject, new Object [] { 105 cms, lang, names, values, descriptions, parameters 106 }); 107 } 108 catch(NoSuchMethodException exc) { 109 110 throwException("Could not find radio button method " + radioMethod 112 + " in calling class " + callingObject.getClass().getName() 113 + " for generating select box content.", CmsLegacyException.C_NOT_FOUND); 114 } 115 catch(InvocationTargetException targetEx) { 116 117 Throwable e = targetEx.getTargetException(); 120 if(!(e instanceof CmsException)) { 121 122 throwException("Radio button method " + radioMethod + " in calling class " 123 + callingObject.getClass().getName() + " throwed an exception. " 124 + e); 125 } 126 else { 127 128 throw (CmsException)e; 131 } 132 } 133 catch(Exception exc2) { 134 throwException("Radio button method " + radioMethod + " in calling class " + callingObject.getClass().getName() 135 + " was found but could not be invoked. " + exc2, CmsLegacyException.C_XML_NO_USER_METHOD); 136 } 137 138 if(returnObject != null) { 140 selectedOption = returnObject.intValue(); 141 } 142 143 int numValues = values.size(); 145 CmsXmlWpTemplateFile radiodef = getRadioDefinitions(cms); 146 for(int i = 0;i < numValues;i++) { 147 148 radiodef.setData(CmsWorkplaceDefault.C_RADIO_RADIONAME, radioName); 150 radiodef.setData(CmsWorkplaceDefault.C_RADIO_NAME, (String )descriptions.elementAt(i)); 151 radiodef.setData(CmsWorkplaceDefault.C_RADIO_LINK, (String )values.elementAt(i)); 152 153 if((String )names.elementAt(i) == null || "".equals(names.elementAt(i))) { 155 radiodef.setData(CmsWorkplaceDefault.C_RADIO_IMAGEENTRY, ""); 156 } 157 else { 158 radiodef.setData(CmsWorkplaceDefault.C_RADIO_IMAGENAME, "ic_" + (String )names.elementAt(i) + ".gif"); 159 radiodef.setData(CmsWorkplaceDefault.C_RADIO_IMAGEENTRY, radiodef.getProcessedDataValue("radiobuttons." 160 + CmsWorkplaceDefault.C_RADIO_IMAGEOPTION, callingObject)); 161 } 162 163 if(i == selectedOption) { 165 radiodef.setData(CmsWorkplaceDefault.C_RADIO_SELECTEDENTRY, radiodef.getDataValue("radiobuttons." + CmsWorkplaceDefault.C_RADIO_SELECTEDOPTION)); 166 } 167 else { 168 radiodef.setData(CmsWorkplaceDefault.C_RADIO_SELECTEDENTRY, ""); 169 } 170 171 if(radioOrder.equals("col")) { 173 174 result.append(radiodef.getProcessedDataValue("radiobuttons.colentry", callingObject)); 176 } 177 else { 178 179 result.append(radiodef.getProcessedDataValue("radiobuttons.rowentry", callingObject)); 181 } 182 } 183 return result.toString(); 184 } 185 } 186 | Popular Tags |