View Javadoc
1   /*
2    * Copyright (C) 2003-2008 eXo Platform SAS.
3    *
4    * This program is free software; you can redistribute it and/or
5    * modify it under the terms of the GNU Affero General Public License
6    * as published by the Free Software Foundation; either version 3
7    * of the License, or (at your option) any later version.
8    *
9    * This program is distributed in the hope that it will be useful,
10   * but WITHOUT ANY WARRANTY; without even the implied warranty of
11   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12   * GNU General Public License for more details.
13   *
14   * You should have received a copy of the GNU General Public License
15   * along with this program; if not, see<http://www.gnu.org/licenses/>.
16   */
17  package org.exoplatform.wcm.webui;
18  
19  import java.util.Iterator;
20  import java.util.concurrent.ConcurrentHashMap;
21  
22  import org.apache.commons.lang.StringUtils;
23  import org.exoplatform.container.xml.InitParams;
24  import org.exoplatform.container.xml.PropertiesParam;
25  
26  /**
27   * Created by The eXo Platform SAS
28   * Author : Hoa Pham
29   * hoa.phamvu@exoplatform.com
30   * Dec 13, 2008
31   */
32  public class WebUIPropertiesConfigService {
33  
34    /** The Constant SCV_POPUP_SIZE_EDIT_PORTLET_MODE. */
35    public final static String SCV_POPUP_SIZE_EDIT_PORTLET_MODE = "SCV.popup.size.in.edit.portlet.mode";
36  
37    /** The Constant SCV_POPUP_SIZE_QUICK_EDIT. */
38    public final static String SCV_POPUP_SIZE_QUICK_EDIT = "SCV.popup.size.in.quickdedit";
39  
40    /** The Constant CLV_POPUP_SIZE_EDIT_PORTLET_MODE. */
41    public final static String CLV_POPUP_SIZE_EDIT_PORTLET_MODE = "CLV.popup.size.in.edit.portlet.mode";
42  
43    /** The Constant CLV_POPUP_SIZE_QUICK_EDIT. */
44    public final static String CLV_POPUP_SIZE_QUICK_EDIT = "CLV.popup.size.in.quickedit";
45  
46    /** The properties map. */
47    private ConcurrentHashMap<String,Object> propertiesMap = new ConcurrentHashMap<String,Object>();
48  
49    /**
50     * Instantiates a new web ui properties config service.
51     *
52     * @param params the params
53     */
54    @SuppressWarnings("unchecked")
55    public WebUIPropertiesConfigService(InitParams params) {
56      for(Iterator iterator = params.getPropertiesParamIterator();iterator.hasNext();) {
57        PropertiesParam propertiesParam = (PropertiesParam)iterator.next();
58        if(SCV_POPUP_SIZE_EDIT_PORTLET_MODE.equalsIgnoreCase(propertiesParam.getName())) {
59          PopupWindowProperties properties = readPropertiesFromXML(propertiesParam);
60          propertiesMap.put(SCV_POPUP_SIZE_EDIT_PORTLET_MODE,properties);
61        }else if(SCV_POPUP_SIZE_QUICK_EDIT.equals(propertiesParam.getName())) {
62          PopupWindowProperties properties = readPropertiesFromXML(propertiesParam);
63          propertiesMap.put(SCV_POPUP_SIZE_QUICK_EDIT,properties);
64        }else if(CLV_POPUP_SIZE_QUICK_EDIT.equals(propertiesParam.getName())) {
65          PopupWindowProperties properties = readPropertiesFromXML(propertiesParam);
66          propertiesMap.put(CLV_POPUP_SIZE_QUICK_EDIT,properties);
67        }else if(CLV_POPUP_SIZE_EDIT_PORTLET_MODE.equals(propertiesParam.getName())) {
68          PopupWindowProperties properties = readPropertiesFromXML(propertiesParam);
69          propertiesMap.put(CLV_POPUP_SIZE_EDIT_PORTLET_MODE,properties);
70        }
71      }
72    }
73  
74    /**
75     * Gets the properties.
76     *
77     * @param name the name
78     *
79     * @return the properties
80     */
81    public Object getProperties(String name) {
82      return propertiesMap.get(name);
83    }
84  
85    /**
86     * Read properties from xml.
87     *
88     * @param param the param
89     *
90     * @return the popup window properties
91     */
92    private PopupWindowProperties readPropertiesFromXML(PropertiesParam param) {
93      PopupWindowProperties properties = new PopupWindowProperties();
94      String width = param.getProperty(PopupWindowProperties.WIDTH);
95      String height = param.getProperty(PopupWindowProperties.HEIGHT);
96      if(width != null && StringUtils.isNumeric(width)) {
97        properties.setWidth(Integer.parseInt(width));
98      }
99      if(height != null && StringUtils.isNumeric(height)) {
100       properties.setHeight(Integer.parseInt(height));
101     }
102     return properties;
103   }
104 
105   /**
106    * The Class PopupWindowProperties.
107    */
108   public static class PopupWindowProperties {
109 
110     /** The Constant WIDTH. */
111     public final static String WIDTH = "width";
112 
113     /** The Constant HEIGHT. */
114     public final static String HEIGHT = "height";
115 
116     /** The width. */
117     private int width = 500;
118 
119     /** The height. */
120     private int height = 300;
121 
122     /**
123      * Gets the width.
124      *
125      * @return the width
126      */
127     public int getWidth() { return width; }
128 
129     /**
130      * Sets the width.
131      *
132      * @param width the new width
133      */
134     public void setWidth(int width) { this.width = width;}
135 
136     /**
137      * Gets the height.
138      *
139      * @return the height
140      */
141     public int getHeight() { return height; }
142 
143     /**
144      * Sets the height.
145      *
146      * @param height the new height
147      */
148     public void setHeight(int height) { this.height = height; }
149   }
150 }