⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 portletpreferencesimpl.java

📁 GridSphere 门户 提供一个基于 portlet 的高级开放源代码门户。GridSphere 是在欧盟提供基金的 GridLab 项目下开发的
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/* * @author <a href="mailto:novotny@gridsphere.org">Jason Novotny</a> * @version $Id: PortletPreferencesImpl.java 5032 2006-08-17 18:15:06Z novotny $ */package org.gridsphere.portlet.impl;import org.gridsphere.portletcontainer.impl.descriptor.Preference;import org.gridsphere.portletcontainer.impl.descriptor.Value;import org.gridsphere.services.core.persistence.PersistenceManagerException;import org.gridsphere.services.core.persistence.PersistenceManagerRdbms;import javax.portlet.PortletPreferences;import javax.portlet.PreferencesValidator;import javax.portlet.ReadOnlyException;import javax.portlet.ValidatorException;import java.io.IOException;import java.util.HashMap;import java.util.Iterator;import java.util.Map;/** * The <CODE>PortletPreferences</CODE> interface allows the portlet to store * configuration data. It is not the * purpose of this interface to replace general purpose databases. * <p/> * There are two different types of preferences: * <ul> * <li>modifiable preferences - these preferences can be changed by the * portlet in any standard portlet mode (<code>EDIT, HELP, VIEW</code>). * Per default every preference is modifiable. * <li>read-only preferences - these preferences cannot be changed by the * portlet in any standard portlet mode, but may be changed by administrative modes. * Preferences are read-only, if the are defined in the * deployment descriptor with <code>read-only</code> set to <code>true</code>, * or if the portlet container restricts write access. * </ul> * <p/> * Changes are persisted when the <code>store</code> method is called. The <code>store</code> method * can only be invoked within the scope of a <code>processAction</code> call. * Changes that are not persisted are discarded when the * <code>processAction</code> or <code>render</code> method ends. */public class PortletPreferencesImpl implements PortletPreferences {    public static final String NO_USER = "org.gridsphere.NO_USER";    private transient Map defaultPrefsMap = new HashMap();    private transient PreferencesValidator validator = null;    private transient PersistenceManagerRdbms pm = null;    private String oid = null;    /**     * The PortletId this data belongs to     */    private String portletId = "";    /**     * The unique userid this data belongs to     */    private String userId = NO_USER;    // key/value pairs    private Map attributes = new HashMap();    private boolean isRender = false;    public PortletPreferencesImpl() {    }    public void setPreferencesDesc(org.gridsphere.portletcontainer.impl.descriptor.PortletPreferences portletPrefs) {        if (portletPrefs != null) {            Preference[] prefs = portletPrefs.getPreference();            for (int i = 0; i < prefs.length; i++) {                String name = prefs[i].getName().getContent();                defaultPrefsMap.put(name, prefs[i]);            }            if (attributes.isEmpty()) {                for (int i = 0; i < prefs.length; i++) {                    String name = prefs[i].getName().getContent();                    PersistencePreferenceAttribute ppa = new PersistencePreferenceAttribute();                    ppa.setName(name);                    String[] vals = new String[prefs[i].getValueCount()];                    Value[] prefVals = prefs[i].getValue();                    for (int j = 0; j < vals.length; j++) {                        vals[j] = prefVals[j].getContent();                    }                    ppa.setAValues(vals);                    ppa.setReadOnly(Boolean.valueOf(prefs[i].getReadOnly().getContent()).booleanValue());                    attributes.put(ppa.getName(), ppa);                }            }        }    }    public void setPersistenceManager(PersistenceManagerRdbms pm) {        this.pm = pm;    }    public String getOid() {        return oid;    }    public void setOid(String oid) {        this.oid = oid;    }    public PreferencesValidator getValidator() {        return validator;    }    public void setValidator(PreferencesValidator validator) {        this.validator = validator;    }    public void setRender(boolean isRender) {        this.isRender = isRender;    }    /**     * Returns true, if the value of this key cannot be modified by the user.     * <p/>     * Modifiable preferences can be changed by the     * portlet in any standard portlet mode (<code>EDIT, HELP, VIEW</code>).     * Per default every preference is modifiable.     * <p/>     * Read-only preferences cannot be changed by the     * portlet in any standard portlet mode, but inside of custom modes     * it may be allowed changing them.     * Preferences are read-only, if they are defined in the     * deployment descriptor with <code>read-only</code> set to <code>true</code>,     * or if the portlet container restricts write access.     *     * @return false, if the value of this key can be changed, or     *         if the key is not known     * @throws java.lang.IllegalArgumentException     *          if <code>key</code> is <code>null</code>.     */    public boolean isReadOnly(String key) {        if (key == null) throw new IllegalArgumentException("key is NULL");        PersistencePreferenceAttribute ppa = (PersistencePreferenceAttribute) attributes.get(key);        if (ppa == null) return false;        return ppa.isReadOnly();    }    /**     * Returns the first String value associated with the specified key of this preference.     * If there is one or more preference values associated with the given key     * it returns the first associated value.     * If there are no preference values associated with the given key, or the     * backing preference database is unavailable, it returns the given     * default value.     *     * @param key key for which the associated value is to be returned     * @param def the value to be returned in the event that there is no     *            value available associated with this <code>key</code>.     * @return the value associated with <code>key</code>, or <code>def</code>     *         if no value is associated with <code>key</code>, or the backing     *         store is inaccessible.     * @throws java.lang.IllegalArgumentException     *          if <code>key</code> is <code>null</code>. (A     *          <code>null</code> value for <code>def</code> <i>is</i> permitted.)     * @see #getValues(java.lang.String,java.lang.String[])     */    public String getValue(String key, String def) {        if (key == null) throw new IllegalArgumentException("key is NULL");        PersistencePreferenceAttribute ppa = (PersistencePreferenceAttribute) attributes.get(key);        if ((ppa == null) || (ppa.getAValues().length == 0)) return def;        return ppa.getValue();    }    /**     * Returns the String array value associated with the specified key in this preference.     * <p/>     * <p>Returns the specified default if there is no value     * associated with the key, or if the backing store is inaccessible.     * <p/>     * <p>If the implementation supports <i>stored defaults</i> and such a     * default exists and is accessible, it is used in favor of the     * specified default.     *     * @param key key for which associated value is to be returned.     * @param def the value to be returned in the event that this     *            preference node has no value associated with <code>key</code>     *            or the associated value cannot be interpreted as a String array,     *            or the backing store is inaccessible.     * @return the String array value associated with     *         <code>key</code>, or <code>def</code> if the     *         associated value does not exist.     * @throws java.lang.IllegalArgumentException     *          if <code>key</code> is <code>null</code>.  (A     *          <code>null</code> value for <code>def</code> <i>is</i> permitted.)     * @see #getValue(java.lang.String,java.lang.String)     */    public String[] getValues(String key, String[] def) {        if (key == null) throw new IllegalArgumentException("key is NULL");        PersistencePreferenceAttribute ppa = (PersistencePreferenceAttribute) attributes.get(key);        if ((ppa == null) || (ppa.getAValues().length == 0)) return def;        return ppa.getAValues();    }    /**     * Associates the specified String value with the specified key in this     * preference.     * <p/>     * The key cannot be <code>null</code>, but <code>null</code> values     * for the value parameter are allowed.     *     * @param key   key with which the specified value is to be associated.     * @param value value to be associated with the specified key.     * @throws javax.portlet.ReadOnlyException     *          if this preference cannot be modified for this request

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -