001: /*
002: * DPWSRPPreferences.java
003: *
004: * Created on March 18, 2005, 10:39 AM
005: */
006:
007: package com.sun.portal.wsrp.producer.portletmanagement.impl;
008:
009: import com.sun.portal.portlet.impl.DPPortletPreferencesImpl;
010: import com.sun.portal.portletcontainercommon.PortletActions;
011: import com.sun.portal.providers.context.ProviderContextException;
012: import com.sun.portal.log.common.PortalLogger;
013:
014: import java.io.IOException;
015: import java.util.HashMap;
016: import java.util.HashSet;
017: import java.util.Iterator;
018: import java.util.Map;
019: import java.util.logging.Level;
020: import java.util.logging.Logger;
021: import javax.portlet.ValidatorException;
022: import javax.servlet.http.HttpServletRequest;
023:
024: /**
025: *
026: * @author Rajesh T
027: */
028: public class DPWSRPPreferences extends DPPortletPreferencesImpl {
029:
030: private DPWSRPRoleContext dc = null;
031: // Create a logger for this class
032: private static Logger debugLogger = PortalLogger
033: .getLogger(DPWSRPPreferences.class);
034:
035: public DPWSRPPreferences(HttpServletRequest req,
036: DPWSRPRoleContext dc, String channel, boolean readOnly,
037: Logger logger) {
038: super (req, channel, readOnly, logger);
039: this .dc = dc;
040: init();
041: }
042:
043: public void init() {
044: _prefPropertiesMap = dc.getCollectionProperty(_channel,
045: PORTLET_PREFERENCE_PROPS);
046:
047: if (_prefPropertiesMap == null) {
048: debugLogger.severe("PSPL_PCCSPPCI0002");
049: _prefPropertiesMap = new HashMap();
050: }
051: _predefinedPrefMap = new HashMap();
052: _modifiedList = new HashSet();
053:
054: _additionalPrefModified = false;
055:
056: }
057:
058: public void store() throws IOException, ValidatorException {
059:
060: boolean savePref = false;
061: savePref = dc.getBooleanProperty(_channel, ALLOW_SAVE_PREF);
062:
063: String currentAction = (String) _req
064: .getAttribute(CURRENT_ACTION);
065: if (!currentAction.equals(PortletActions.RENDER) || savePref) {
066: if (_pv != null) {
067: _pv.validate(this );
068: }
069: saveAdditionalPrefMap();
070: savePredefinedPrefMap();
071: } else {
072: throw new IllegalStateException();
073: }
074: }
075:
076: /**
077: * Loads all the additional preferences from the display profile and
078: * store them in the _additionalPrefMap.
079: **/
080: protected void loadAdditionalPrefMap() {
081: if (_additionalPrefMap == null) {
082: _additionalPrefMap = new HashMap();
083:
084: if (dc.existsCollectionProperty(_channel,
085: ADDITIONAL_PREFERENCE)) {
086: Map prefMap = (Map) dc.getCollectionProperty(_channel,
087: ADDITIONAL_PREFERENCE);
088: if (prefMap != null) {
089: _additionalPrefMap = cloneMap(prefMap);
090: }
091: } else {
092: debugLogger.warning("PSPL_PCCSPPCI0003");
093: }
094:
095: _additionalPrefModified = false;
096: }
097: }
098:
099: /**
100: * Loads a particular predefined preferences from the display profile and
101: * store it in the _predefinedPrefMap.
102: **/
103: protected void loadPredefinedPref(String prefName, String def) {
104: if (!_predefinedPrefMap.containsKey(prefName)) {
105: String pref = dc.getStringProperty(_channel,
106: (PORTLET_PREFERENCE_PREFIX + prefName), def);
107: debugLogger.log(Level.INFO, "PSPL_PCCSPPCI0004",
108: new Object[] {
109: (PORTLET_PREFERENCE_PREFIX + prefName),
110: pref });
111: _predefinedPrefMap.put(prefName, pref);
112:
113: }
114: }
115:
116: /**
117: * Writes all the changes made to the additional preferences back to
118: * display profile.
119: **/
120: protected void saveAdditionalPrefMap() {
121: if (_additionalPrefModified) {
122: dc.setCollectionProperty(_channel, ADDITIONAL_PREFERENCE,
123: cloneMap(_additionalPrefMap));
124: _additionalPrefModified = false;
125: }
126: }
127:
128: /**
129: * Writes all the changes made to the predefined preferences back to
130: * display profile and reset the modifiedList.
131: **/
132: protected void savePredefinedPrefMap() {
133: Iterator iter = _modifiedList.iterator();
134: while (iter.hasNext()) {
135: String key = (String) iter.next();
136: String value = (String) _predefinedPrefMap.get(key);
137: debugLogger.log(Level.INFO, "PSPL_PCCSPPCI0005",
138: new Object[] { key, value });
139: dc.setStringProperty(_channel, PORTLET_PREFERENCE_PREFIX
140: + key, value);
141: }
142: _modifiedList.clear();
143: }
144: }
|