001
014
015 package com.liferay.taglib.util;
016
017 import com.liferay.portal.kernel.util.StringPool;
018
019 import java.util.HashMap;
020 import java.util.Map;
021
022 import javax.servlet.http.HttpServletRequest;
023 import javax.servlet.jsp.tagext.DynamicAttributes;
024
025
029 public class AttributesTagSupport
030 extends ParamAndPropertyAncestorTagImpl implements DynamicAttributes {
031
032 public void clearDynamicAttributes() {
033 _dynamicAttributes.clear();
034 }
035
036 public String getAttributeNamespace() {
037 return _attributeNamespace;
038 }
039
040 public Map<String, Object> getScopedAttributes() {
041 return _scopedAttributes;
042 }
043
044 @Override
045 public void release() {
046 super.release();
047
048 _attributeNamespace = null;
049 _dynamicAttributes = null;
050 _scopedAttributes = null;
051 }
052
053 public void setAttributeNamespace(String attributeNamespace) {
054 _attributeNamespace = attributeNamespace;
055 }
056
057 public void setDynamicAttribute(
058 String uri, String localName, Object value) {
059
060 _dynamicAttributes.put(localName, value);
061 }
062
063 public void setNamespacedAttribute(
064 HttpServletRequest request, String key, Object value) {
065
066 if (value instanceof Boolean) {
067 value = String.valueOf(value);
068 }
069 else if (value instanceof Number) {
070 value = String.valueOf(value);
071 }
072
073 request.setAttribute(_encodeKey(key), value);
074 }
075
076 public void setScopedAttribute(String name, Object value) {
077 _scopedAttributes.put(name, value);
078 }
079
080 protected Map<String, Object> getDynamicAttributes() {
081 return _dynamicAttributes;
082 }
083
084 private String _encodeKey(String key) {
085 if (_attributeNamespace.length() == 0) {
086 return key;
087 }
088 else {
089 return _attributeNamespace.concat(key);
090 }
091 }
092
093 private String _attributeNamespace = StringPool.BLANK;
094 private Map<String, Object> _dynamicAttributes =
095 new HashMap<String, Object>();
096 private Map<String, Object> _scopedAttributes =
097 new HashMap<String, Object>();
098
099 }