Home » struts-2.1.8.1-src » org.apache » struts2 » portlet » interceptor » [javadoc | source]

    1   /*
    2    * $Id: ServletPortletPreferences.java 651946 2008-04-27 13:41:38Z apetrelli $
    3    *
    4    * Licensed to the Apache Software Foundation (ASF) under one
    5    * or more contributor license agreements.  See the NOTICE file
    6    * distributed with this work for additional information
    7    * regarding copyright ownership.  The ASF licenses this file
    8    * to you under the Apache License, Version 2.0 (the
    9    * "License"); you may not use this file except in compliance
   10    * with the License.  You may obtain a copy of the License at
   11    *
   12    *  http://www.apache.org/licenses/LICENSE-2.0
   13    *
   14    * Unless required by applicable law or agreed to in writing,
   15    * software distributed under the License is distributed on an
   16    * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
   17    * KIND, either express or implied.  See the License for the
   18    * specific language governing permissions and limitations
   19    * under the License.
   20    */
   21   
   22   package org.apache.struts2.portlet.interceptor;
   23   
   24   import java.io.IOException;
   25   import java.util.Enumeration;
   26   import java.util.HashMap;
   27   import java.util.Map;
   28   import java.util.Vector;
   29   
   30   import javax.portlet.PortletPreferences;
   31   import javax.portlet.ReadOnlyException;
   32   import javax.portlet.ValidatorException;
   33   
   34   /**
   35    * Simple portlet preferences implementation that uses a map in the Session
   36    * as storage.
   37    */
   38   public class ServletPortletPreferences implements PortletPreferences {
   39   
   40       private Map session;
   41       private String PREFERENCES_KEY = "_portlet-preferences";
   42       
   43       public ServletPortletPreferences(Map session) {
   44           this.session = session;
   45       }
   46       
   47       public Map getMap() {
   48           Map map = (Map) session.get(PREFERENCES_KEY);
   49           if (map == null) {
   50               map = new HashMap();
   51               session.put(PREFERENCES_KEY, map);
   52           }
   53           return map;
   54       }
   55   
   56       public Enumeration getNames() {
   57           return new Vector(getMap().keySet()).elements();
   58       }
   59   
   60       public String getValue(String key, String def) {
   61           String val = (String) getMap().get(key);
   62           if (val == null) {
   63               val = def;
   64           }
   65           return val;
   66       }
   67   
   68       public String[] getValues(String key, String[] def) {
   69           String[] val = (String[]) getMap().get(key);
   70           if (val == null) {
   71               val = def;
   72           }
   73           return val;
   74       }
   75   
   76       public boolean isReadOnly(String arg0) {
   77           return false;
   78       }
   79   
   80       public void reset(String arg0) throws ReadOnlyException {
   81           session.put(PREFERENCES_KEY, new HashMap());
   82       }
   83   
   84       public void setValue(String key, String value) throws ReadOnlyException {
   85           getMap().put(key, value);
   86       }
   87   
   88       public void setValues(String key, String[] value) throws ReadOnlyException {
   89           getMap().put(key, value);
   90       }
   91   
   92       public void store() throws IOException, ValidatorException {
   93           
   94       }
   95   
   96   }

Home » struts-2.1.8.1-src » org.apache » struts2 » portlet » interceptor » [javadoc | source]