001
014
015 package com.liferay.portal.kernel.servlet.taglib;
016
017 import com.liferay.portal.kernel.util.CharPool;
018 import com.liferay.portal.kernel.util.StringBundler;
019 import com.liferay.portal.kernel.util.Validator;
020
021
025 public class CustomAttributes {
026
027 public static CustomAttributes getInstance() {
028 return new CustomAttributes();
029 }
030
031 public static CustomAttributes getInstance(String keyPrefix) {
032 return new CustomAttributes(keyPrefix);
033 }
034
035 public CustomAttributes add(CustomAttributes customAttributes) {
036 _sb.append(customAttributes._sb);
037
038 return this;
039 }
040
041 public CustomAttributes add(Object... values) {
042 for (int i = 0; i < values.length; i += 2) {
043 add(String.valueOf(values[i]), values[i + 1]);
044 }
045
046 return this;
047 }
048
049 public CustomAttributes add(String key, boolean value) {
050 return add(key, String.valueOf(value));
051 }
052
053 public CustomAttributes add(String key, byte value) {
054 return add(key, String.valueOf(value));
055 }
056
057 public CustomAttributes add(String key, char value) {
058 return add(key, String.valueOf(value));
059 }
060
061 public CustomAttributes add(String key, double value) {
062 return add(key, String.valueOf(value));
063 }
064
065 public CustomAttributes add(String key, float value) {
066 return add(key, String.valueOf(value));
067 }
068
069 public CustomAttributes add(String key, int value) {
070 return add(key, String.valueOf(value));
071 }
072
073 public CustomAttributes add(String key, long value) {
074 return add(key, String.valueOf(value));
075 }
076
077 public CustomAttributes add(String key, Object value) {
078 return add(key, String.valueOf(value));
079 }
080
081 public CustomAttributes add(String key, short value) {
082 return add(key, String.valueOf(value));
083 }
084
085 public CustomAttributes add(String key, String value) {
086 if (_sb.length() > 0) {
087 _sb.append(CharPool.SPACE);
088 }
089
090 if (Validator.isNotNull(_keyPrefix)) {
091 _sb.append(_keyPrefix);
092 }
093
094 _sb.append(key);
095 _sb.append(CharPool.EQUAL);
096 _sb.append(CharPool.QUOTE);
097 _sb.append(value);
098 _sb.append(CharPool.QUOTE);
099
100 return this;
101 }
102
103 public void reset() {
104 _sb.setIndex(0);
105 }
106
107 @Override
108 public String toString() {
109 return _sb.toString();
110 }
111
112 private CustomAttributes() {
113 }
114
115 private CustomAttributes(String keyPrefix) {
116 _keyPrefix = keyPrefix;
117 }
118
119 private String _keyPrefix;
120 private StringBundler _sb = new StringBundler();
121
122 }