1 31 32 package org.opencms.jsp; 33 34 import org.opencms.file.CmsObject; 35 import org.opencms.file.CmsUser; 36 import org.opencms.flex.CmsFlexController; 37 import org.opencms.i18n.CmsMessageContainer; 38 import org.opencms.main.CmsLog; 39 40 import java.util.Arrays ; 41 import java.util.Iterator ; 42 import java.util.List ; 43 44 import javax.servlet.ServletRequest ; 45 import javax.servlet.jsp.tagext.TagSupport ; 46 47 import org.apache.commons.logging.Log; 48 49 58 public class CmsJspTagUser extends TagSupport { 59 60 61 private static final long serialVersionUID = 4520173761363738542L; 62 63 64 private static final Log LOG = CmsLog.getLog(CmsJspTagUser.class); 65 66 67 private static final String [] USER_PROPERTIES = { 68 "name", 69 "firstname", 70 "lastname", 71 "email", 72 "street", 73 "zip", 74 "city", 75 "description", 76 "group", 77 "currentgroup", 78 "defaultgroup", 79 "otherstuff"}; 80 81 82 private static final List USER_PROPERTIES_LIST = Arrays.asList(USER_PROPERTIES); 83 84 private String m_property; 86 87 94 public static String userTagAction(String property, ServletRequest req) { 95 96 CmsFlexController controller = CmsFlexController.getController(req); 97 98 CmsObject cms = controller.getCmsObject(); 99 CmsUser user = cms.getRequestContext().currentUser(); 100 101 if (property == null) { 102 property = USER_PROPERTIES[0]; 103 } 104 105 String result = null; 106 switch (USER_PROPERTIES_LIST.indexOf(property)) { 107 case 0: result = user.getName(); 109 break; 110 case 1: result = user.getFirstname(); 112 break; 113 case 2: result = user.getLastname(); 115 break; 116 case 3: result = user.getEmail(); 118 break; 119 case 4: result = user.getAddress(); 121 break; 122 case 5: result = user.getZipcode(); 124 break; 125 case 6: result = user.getCity(); 127 break; 128 case 7: result = user.getDescription(); 130 break; 131 case 8: case 9: case 10: result = ""; 135 break; 136 case 11: Iterator it = user.getAdditionalInfo().keySet().iterator(); 138 CmsMessageContainer msgContainer = Messages.get().container(Messages.GUI_TAG_USER_ADDITIONALINFO_0); 139 result = Messages.getLocalizedMessage(msgContainer, req); 140 while (it.hasNext()) { 141 Object o = it.next(); 142 result += " " + o + "=" + user.getAdditionalInfo((String )o); 143 } 144 break; 145 default: 146 msgContainer = Messages.get().container(Messages.GUI_ERR_INVALID_USER_PROP_1, property); 147 result = Messages.getLocalizedMessage(msgContainer, req); 148 149 } 150 151 return result; 152 } 153 154 157 public int doStartTag() throws javax.servlet.jsp.JspException { 158 159 javax.servlet.ServletRequest req = pageContext.getRequest(); 160 161 if (CmsFlexController.isCmsRequest(req)) { 163 164 try { 165 String result = userTagAction(m_property, req); 166 pageContext.getOut().print(result); 168 } catch (Exception ex) { 169 if (LOG.isErrorEnabled()) { 170 LOG.error(Messages.get().getBundle().key(Messages.ERR_PROCESS_TAG_1, "user"), ex); 171 } 172 throw new javax.servlet.jsp.JspException (ex); 173 } 174 } 175 return SKIP_BODY; 176 } 177 178 183 public String getProperty() { 184 185 return m_property != null ? m_property : ""; 186 } 187 188 191 public void release() { 192 193 super.release(); 194 m_property = null; 195 } 196 197 202 public void setProperty(String name) { 203 204 if (name != null) { 205 m_property = name.toLowerCase(); 206 } 207 } 208 209 } 210 | Popular Tags |