📄 portletpreferencesimpl.java
字号:
* @throws java.lang.IllegalArgumentException * if key is <code>null</code>, * or <code>key.length()</code> * or <code>value.length</code> are to long. The maximum length * for key and value are implementation specific. * @see #setValues(java.lang.String,java.lang.String[]) */ public void setValue(String key, String value) throws ReadOnlyException { if (key == null) throw new IllegalArgumentException("key is NULL"); PersistencePreferenceAttribute ppa = (PersistencePreferenceAttribute) attributes.get(key); if (ppa == null) { ppa = new PersistencePreferenceAttribute(); ppa.setName(key); ppa.setReadOnly(false); ppa.setValue(value); } else { if (ppa.isReadOnly()) throw new ReadOnlyException("PortletPreference is read-only!"); ppa.setValue(value); } attributes.put(key, ppa); } /** * Associates the specified String array value with the specified key in this * preference. * <p/> * The key cannot be <code>null</code>, but <code>null</code> values * in the values parameter are allowed. * * @param key key with which the value is to be associated * @param values values to be associated with key * @throws java.lang.IllegalArgumentException * if key is <code>null</code>, or * <code>key.length()</code> * is to long or <code>value.size</code> is to large. The maximum * length for key and maximum size for value are implementation specific. * @throws javax.portlet.ReadOnlyException * if this preference cannot be modified for this request * @see #setValue(java.lang.String,java.lang.String) */ public void setValues(String key, String[] values) throws ReadOnlyException { if (key == null) throw new IllegalArgumentException("key is NULL"); PersistencePreferenceAttribute ppa = (PersistencePreferenceAttribute) attributes.get(key); if (ppa == null) { ppa = new PersistencePreferenceAttribute(); ppa.setName(key); ppa.setReadOnly(false); ppa.setAValues(values); } else { if (ppa.isReadOnly()) throw new ReadOnlyException("PortletPreference is read-only!"); ppa.setAValues(values); } attributes.put(key, ppa); } /** * Returns all of the keys that have an associated value, * or an empty <code>Enumeration</code> if no keys are * available. * * @return an Enumeration of the keys that have an associated value, * or an empty <code>Enumeration</code> if no keys are * available. */ public java.util.Enumeration getNames() { return new Enumerator(attributes.keySet().iterator()); } /** * Returns a <code>Map</code> of the preferences. * <p/> * The values in the returned <code>Map</code> are from type * String array (<code>String[]</code>). * <p/> * If no preferences exist this method returns an empty <code>Map</code>. * * @return an immutable <code>Map</code> containing preference names as * keys and preference values as map values, or an empty <code>Map</code> * if no preference exist. The keys in the preference * map are of type String. The values in the preference map are of type * String array (<code>String[]</code>). */ public java.util.Map getMap() { Map map = new HashMap(); Iterator it = attributes.keySet().iterator(); while (it.hasNext()) { String key = (String) it.next(); String[] vals = this.getValues(key, null); map.put(key, vals); } return map; } /** * Resets or removes the value associated with the specified key. * <p/> * If this implementation supports stored defaults, and there is such * a default for the specified preference, the given key will be * reset to the stored default. * <p/> * If there is no default available the key will be removed. * * @param key to reset * @throws java.lang.IllegalArgumentException * if key is <code>null</code>. * @throws javax.portlet.ReadOnlyException * if this preference cannot be modified for this request */ public void reset(String key) throws ReadOnlyException { if (key == null) throw new IllegalArgumentException("key is NULL"); PersistencePreferenceAttribute ppa = (PersistencePreferenceAttribute) attributes.get(key); if (ppa != null) { if (ppa.isReadOnly()) throw new ReadOnlyException("PortletPreference is read-only!"); Preference defaultPref = (Preference) defaultPrefsMap.get(key); if (defaultPref != null) { Value[] defvals = defaultPref.getValue(); String[] vals = new String[defvals.length]; for (int i = 0; i < defvals.length; i++) { vals[i] = defvals[i].getContent(); } ppa.setAValues(vals); } else { attributes.remove(key); } } } /** * Commits all changes made to the preferences via the * <code>set</code> methods in the persistent store. * <p/> * If this call returns succesfull, all changes are made * persistent. If this call fails, no changes are made * in the persistent store. This call is an atomic operation * regardless of how many preference attributes have been modified. * <p/> * All changes made to preferences not followed by a call * to the <code>store</code> method are discarded when the * portlet finishes the <code>processAction</code> method. * <p/> * If a validator is defined for this preferences in the * deployment descriptor, this validator is called before * the actual store is performed to check wether the given * preferences are vaild. If this check fails a * <code>ValidatorException</code> is thrown. * * @throws java.io.IOException if changes cannot be written into * the backend store * @throws javax.portlet.ValidatorException * if the validation performed by the * associated validator fails * @throws java.lang.IllegalStateException * if this method is called inside a render call * @see javax.portlet.PreferencesValidator */ public void store() throws java.io.IOException, ValidatorException { if (isRender) throw new IllegalStateException("Cannot persist PortletPreferences in render method!"); if (validator != null) validator.validate(this); try {// if (oid!=null) pm.saveOrUpdate(this); else pm.create(this); pm.saveOrUpdate(this); } catch (PersistenceManagerException e) { throw new IOException(e.getMessage()); } } /** * Returns the user id of this portlet data * * @return the user id */ public String getUserId() { return userId; } /** * Sets the user id of this portlet data * * @param userId the concrete portlet id */ public void setUserId(String userId) { this.userId = userId; } /** * Returns the concrete portlet id of this portlet data * * @return the concrete portlet id */ public String getPortletId() { return portletId; } /** * Sets the concrete portlet id of this portlet data * * @param portletId the concrete portlet id */ public void setPortletId(String portletId) { this.portletId = portletId; } public Map getAttributes() { return attributes; } public void setAttributes(Map attributes) { this.attributes = attributes; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -