001
014
015 package com.liferay.portal.template;
016
017 import com.liferay.portal.kernel.log.Log;
018 import com.liferay.portal.kernel.log.LogFactoryUtil;
019 import com.liferay.portal.kernel.util.AutoResetThreadLocal;
020 import com.liferay.portal.model.PortletConstants;
021 import com.liferay.portlet.PortletPreferencesFactoryUtil;
022 import com.liferay.portlet.PortletPreferencesImpl;
023
024 import javax.portlet.ReadOnlyException;
025
026
030 public class TemplatePortletPreferences {
031
032 public void reset() {
033 PortletPreferencesImpl portletPreferencesImpl =
034 _portletPreferencesImplThreadLocal.get();
035
036 portletPreferencesImpl.reset();
037 }
038
039 public void setValue(String key, String value) throws ReadOnlyException {
040 PortletPreferencesImpl portletPreferencesImpl =
041 _portletPreferencesImplThreadLocal.get();
042
043 portletPreferencesImpl.setValue(key, value);
044 }
045
046 public void setValues(String key, String[] values)
047 throws ReadOnlyException {
048
049 PortletPreferencesImpl portletPreferencesImpl =
050 _portletPreferencesImplThreadLocal.get();
051
052 portletPreferencesImpl.setValues(key, values);
053 }
054
055 @Override
056 public String toString() {
057 PortletPreferencesImpl portletPreferencesImpl =
058 _portletPreferencesImplThreadLocal.get();
059
060 try {
061 return PortletPreferencesFactoryUtil.toXML(portletPreferencesImpl);
062 }
063 catch (Exception e) {
064 _log.error(e, e);
065
066 return PortletConstants.DEFAULT_PREFERENCES;
067 }
068 }
069
070 private static final Log _log = LogFactoryUtil.getLog(
071 TemplatePortletPreferences.class);
072
073 private final ThreadLocal<PortletPreferencesImpl>
074 _portletPreferencesImplThreadLocal =
075 new AutoResetThreadLocal<PortletPreferencesImpl>(
076 TemplatePortletPreferences.class.getName()) {
077
078 @Override
079 protected PortletPreferencesImpl initialValue() {
080 return new PortletPreferencesImpl();
081 }
082
083 };
084
085 }