View Javadoc
1   /*
2    * Copyright 2011 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.include;
17  
18  import java.util.HashMap;
19  import java.util.Map;
20  
21  import org.springframework.util.Assert;
22  
23  import COM.FutureTense.Interfaces.ICS;
24  
25  import com.fatwire.assetapi.data.AssetId;
26  import com.fatwire.gst.foundation.facade.runtag.render.CallTemplate.Style;
27  
28  /**
29   * @author Dolf Dijkstra
30   * @since Apr 13, 2011
31   */
32  public class DefaultIncludeService implements IncludeService {
33  
34      private final ICS ics;
35      private final Map<String, Include> map = new HashMap<String, Include>();
36  
37      public DefaultIncludeService(final ICS ics) {
38          this.ics = ics;
39      }
40  
41      public IncludeElement element(final String name, final String elementname) {
42          Assert.hasText(name);
43          Assert.hasText(elementname);
44          final IncludeElement i = new IncludeElement(ics, elementname);
45          map.put(name, i);
46          return i;
47      }
48  
49      public IncludePage page(final String name, final String pagename, final Style style) {
50          Assert.hasText(name);
51          Assert.hasText(pagename);
52  //        if (Style.element == style)
53  //            throw new IllegalArgumentException(
54  //                    "IncludeService#page cannot handle style 'element'. Please use IncludeService#element.");
55          final IncludePage i = new IncludePage(ics, pagename, style == null ? Style.pagelet : style);
56          map.put(name, i);
57          return i;
58  
59      }
60  
61      public IncludeTemplate template(final String name, final AssetId asset, final String tname) {
62          Assert.hasText(name);
63          Assert.hasText(tname);
64          Assert.notNull(asset);
65          final IncludeTemplate i = new IncludeTemplate(ics, asset, tname);
66          map.put(name, i);
67          return i;
68  
69      }
70  
71      public Include find(final String name) {
72          return map.get(name);
73      }
74  
75  }