1 /*
2 * Copyright 2010 FatWire Corporation. All Rights Reserved.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16 package com.fatwire.gst.foundation.taglib;
17
18 import java.io.IOException;
19 import java.util.HashMap;
20 import java.util.Map;
21 import javax.servlet.jsp.JspException;
22
23 import COM.FutureTense.Interfaces.ICS;
24
25 import com.fatwire.gst.foundation.properties.AssetApiPropertyDao;
26 import com.fatwire.gst.foundation.properties.PropertyDao;
27
28 /**
29 * Load property values from the property asset into the page scope
30 *
31 * @author Tony Field
32 * @since 2011-09-02
33 */
34 public class GetPropertiesTag extends GsfSimpleTag {
35
36 /*
37 * (non-Javadoc)
38 *
39 * @see javax.servlet.jsp.tagext.SimpleTagSupport#doTag()
40 */
41 @Override
42 public void doTag() throws JspException, IOException {
43 getJspContext().setAttribute("prop", getAllPropsAsMap());
44 super.doTag();
45 }
46
47 private Map<String, String> getAllPropsAsMap() {
48 final ICS ics = getICS();
49 PropertyDao propertyDao = AssetApiPropertyDao.getInstance(ics);
50 HashMap<String, String> map = new HashMap<String, String>();
51 for (String name : propertyDao.getPropertyNames()) {
52 map.put(name, propertyDao.getProperty(name).asString());
53 }
54 return map;
55 }
56
57 }