1   /**
2    * Copyright (c) 2000-2009 Liferay, Inc. All rights reserved.
3    *
4    * Permission is hereby granted, free of charge, to any person obtaining a copy
5    * of this software and associated documentation files (the "Software"), to deal
6    * in the Software without restriction, including without limitation the rights
7    * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8    * copies of the Software, and to permit persons to whom the Software is
9    * furnished to do so, subject to the following conditions:
10   *
11   * The above copyright notice and this permission notice shall be included in
12   * all copies or substantial portions of the Software.
13   *
14   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20   * SOFTWARE.
21   */
22  
23  package com.liferay.portal.model.impl;
24  
25  import com.liferay.portal.kernel.util.StringPool;
26  import com.liferay.portal.kernel.util.StringUtil;
27  import com.liferay.portal.kernel.util.Validator;
28  import com.liferay.portal.model.EventDefinition;
29  import com.liferay.portal.model.PortletApp;
30  import com.liferay.portal.model.PortletFilter;
31  import com.liferay.portal.model.PortletURLListener;
32  import com.liferay.portal.model.PublicRenderParameter;
33  import com.liferay.portal.model.SpriteImage;
34  
35  import java.util.HashMap;
36  import java.util.Iterator;
37  import java.util.LinkedHashMap;
38  import java.util.LinkedHashSet;
39  import java.util.Map;
40  import java.util.Properties;
41  import java.util.Set;
42  
43  import javax.xml.XMLConstants;
44  
45  /**
46   * <a href="PortletAppImpl.java.html"><b><i>View Source</i></b></a>
47   *
48   * @author Brian Wing Shun Chan
49   *
50   */
51  public class PortletAppImpl implements PortletApp {
52  
53      public PortletAppImpl(String servletContextName) {
54          _servletContextName = servletContextName;
55  
56          if (Validator.isNotNull(_servletContextName)) {
57              _warFile = true;
58          }
59          else {
60              _warFile = false;
61          }
62      }
63  
64      public String getServletContextName() {
65          return _servletContextName;
66      }
67  
68      public Set<String> getServletURLPatterns() {
69          return _servletURLPatterns;
70      }
71  
72      public Set<String> getUserAttributes() {
73          return _userAttributes;
74      }
75  
76      public Map<String, String> getCustomUserAttributes() {
77          return _customUserAttributes;
78      }
79  
80      public void addPortletFilter(PortletFilter portletFilter) {
81          _portletFilters.add(portletFilter);
82          _portletFiltersByFilterName.put(
83              portletFilter.getFilterName(), portletFilter);
84      }
85  
86      public PortletFilter getPortletFilter(String filterName) {
87          return _portletFiltersByFilterName.get(filterName);
88      }
89  
90      public Set<PortletFilter> getPortletFilters() {
91          return _portletFilters;
92      }
93  
94      public String getDefaultNamespace() {
95          return _defaultNamespace;
96      }
97  
98      public void setDefaultNamespace(String defaultNamespace) {
99          _defaultNamespace = defaultNamespace;
100     }
101 
102     public void addEventDefinition(EventDefinition eventDefinition) {
103         _eventDefinitions.add(eventDefinition);
104     }
105 
106     public void addPublicRenderParameter(
107         PublicRenderParameter publicRenderParameter) {
108 
109         _publicRenderParameters.add(publicRenderParameter);
110         _publicRenderParametersByIdentifier.put(
111             publicRenderParameter.getIdentifier(), publicRenderParameter);
112     }
113 
114     public PublicRenderParameter getPublicRenderParameter(String identifier) {
115         return _publicRenderParametersByIdentifier.get(identifier);
116     }
117 
118     public void addPortletURLListener(PortletURLListener portletURLListener) {
119         _portletURLListeners.add(portletURLListener);
120         _portletURLListenersByListenerClass.put(
121             portletURLListener.getListenerClass(), portletURLListener);
122     }
123 
124     public PortletURLListener getPortletURLListener(String listenerClass) {
125         return _portletURLListenersByListenerClass.get(listenerClass);
126     }
127 
128     public Set<PortletURLListener> getPortletURLListeners() {
129         return _portletURLListeners;
130     }
131 
132     public Map<String, String[]> getContainerRuntimeOptions() {
133         return _containerRuntimeOptions;
134     }
135 
136     public SpriteImage getSpriteImage(String fileName) {
137         return _spriteImagesMap.get(fileName);
138     }
139 
140     public void setSpriteImages(
141         String spriteFileName, Properties properties) {
142 
143         Iterator<Map.Entry<Object, Object>> itr =
144             properties.entrySet().iterator();
145 
146         while (itr.hasNext()) {
147             Map.Entry<Object, Object> entry = itr.next();
148 
149             String key = (String)entry.getKey();
150             String value = (String)entry.getValue();
151 
152             int[] values = StringUtil.split(value, 0);
153 
154             int offset = values[0];
155             int height = values[1];
156             int width = values[2];
157 
158             SpriteImage spriteImage = new SpriteImage(
159                 spriteFileName, key, offset, height, width);
160 
161             _spriteImagesMap.put(key, spriteImage);
162         }
163     }
164 
165     public boolean isWARFile() {
166         return _warFile;
167     }
168 
169     private String _servletContextName = StringPool.BLANK;
170     private Set<String> _servletURLPatterns = new LinkedHashSet<String>();
171     private Set<String> _userAttributes = new LinkedHashSet<String>();
172     private Map<String, String> _customUserAttributes =
173         new LinkedHashMap<String, String>();
174     private Set<PortletFilter> _portletFilters =
175         new LinkedHashSet<PortletFilter>();
176     private Map<String, PortletFilter> _portletFiltersByFilterName =
177         new HashMap<String, PortletFilter>();
178     private String _defaultNamespace = XMLConstants.NULL_NS_URI;
179     private Set<EventDefinition> _eventDefinitions =
180         new LinkedHashSet<EventDefinition>();
181     private Set<PublicRenderParameter> _publicRenderParameters =
182         new LinkedHashSet<PublicRenderParameter>();
183     private Map<String, PublicRenderParameter>
184         _publicRenderParametersByIdentifier =
185             new HashMap<String, PublicRenderParameter>();
186     private Set<PortletURLListener> _portletURLListeners =
187         new LinkedHashSet<PortletURLListener>();
188     private Map<String, PortletURLListener>
189         _portletURLListenersByListenerClass =
190             new HashMap<String, PortletURLListener>();
191     private Map<String, String[]> _containerRuntimeOptions =
192         new HashMap<String, String[]>();
193     private Map<String, SpriteImage> _spriteImagesMap =
194         new HashMap<String, SpriteImage>();
195     private boolean _warFile;
196 
197 }