Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: ru/gammalabs/ice/publishing/framework/Template.java


1   /*
2    * $Id: Template.java,v 1.2 2003/01/01 22:10:08 dimitry Exp $
3    *
4    * ==================================================================
5    * This library is free software; you can redistribute it and/or
6    * modify it under the terms of the GNU Lesser General Public
7    * License as published by the Free Software Foundation; either
8    * version 2.1 of the License, or (at your option) any later version.
9    *
10   * This library is distributed in the hope that it will be useful,
11   * but WITHOUT ANY WARRANTY; without even the implied warranty of
12   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13   * Lesser General Public License for more details.
14   *
15   * You should have received a copy of the GNU Lesser General Public
16   * License along with this library; if not, write to the Free Software
17   * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18   * ==================================================================
19   *
20   */
21  
22  package ru.gammalabs.ice.publishing.framework;
23  
24  import java.util.*;
25  
26  /**
27   * Class implementing basic template model.
28   * It is supposed that each <code>Template</code> has several <code>TemplateStorage</code>s,
29   * one and only one <code>TemplateStorage</code> for each of the supported <code>Locale</code>s.
30   *
31   * @see TemplateStorage
32   * @author Vasily Antashov <vv@v6.ru>
33   * @version 1.1
34   */
35  public class Template
36  {
37    /**
38     * Template name.
39     */
40    protected String name = null;
41  
42    /**
43     * Template id (should not be used in business logic - consider using <code>name</code> instead).
44     */
45    protected Long id = null;
46  
47    /**
48     * Map containing <code>TemplateStorage</code>s of this template.
49     * Keys are <code>Locale</code>s supported by this template.
50     * Values are <code>TemplateStorage</code>s of this template.
51     * @see TemplateStorage
52     */
53    protected Map storages = null;
54  
55    /**
56     * Public constructor.
57     */
58    public Template()
59    {
60      this.storages = new HashMap();
61    }
62  
63    /**
64     * Gets template name.
65     * @return String containing template name
66     */
67    public String getName()
68    {
69      return this.name;
70    }
71  
72    /**
73     * Sets template name.
74     * @param name template name
75     */
76    public void setName(String name)
77    {
78      this.name = name;
79    }
80  
81    /**
82     * Gets template id.
83     * @return Long containing template id
84     */
85    public Long getId()
86    {
87      return this.id;
88    }
89  
90    /**
91     * Sets template id.
92     * @param id template id
93     */
94    public void setId(Long id)
95    {
96      this.id = id;
97    }
98  
99    /**
100    * Convenience method.
101    * Sets template id.
102    * @param id template id
103    */
104   public void setId(long id)
105   {
106     setId(new Long(id));
107   }
108 
109   /**
110    * Gets all of the locales supported by this template.
111    * @return Collection containing <code>Locale</code>s supported by this template
112    */
113   public Collection getLocales()
114   {
115     return this.storages.keySet();
116   }
117 
118   /**
119    * Gets all of the template storages of this template.
120    */
121   public Collection getAllTemplateStorages()
122   {
123     return this.storages.values();
124   }
125 
126   /**
127    * Gets <code>TemplateStorage</code> for the specified <code>locale</code>.
128    * @return <code>TemplateStorage</code> upon success; null in case <code>locale</code>
129    * is not supported by this template
130    */
131   public TemplateStorage getTemplateStorage(Locale locale)
132   {
133     return (TemplateStorage)this.storages.get(locale);
134   }
135 
136   /**
137    * Adds a template storage to the template.
138    * @param locale <code>Locale</code> to be supported by this template
139    * @param storage <code>TemplateStorage</code> to be added to this template
140    */
141   public void addTemplateStorage(Locale locale, TemplateStorage storage)
142   {
143     this.storages.put(locale, storage);
144   }
145 
146   /**
147    * Removes a template storage for the specified <code>locale</code>.
148    * @param locale <code>Locale</code> to be removed from those supported by this template
149    */
150   public void removeTemplateStorage(Locale locale)
151   {
152     this.storages.remove(locale);
153   }
154 
155   public String toString()
156   {
157     StringBuffer toReturn = new StringBuffer();
158     toReturn.append("\n");
159     toReturn.append("template name: " + this.name + "\n");
160     toReturn.append("template id: " + this.id + "\n");
161     toReturn.append("template storages:\n");
162     Collection templateStorages = this.getAllTemplateStorages();
163     Iterator i = templateStorages.iterator();
164     while (i.hasNext())
165     {
166       TemplateStorage templateStorage = (TemplateStorage)i.next();
167       if (templateStorage != null)
168         toReturn.append(templateStorage.toString());
169     }
170     return toReturn.toString();
171   }
172 
173   public boolean equals(Object o)
174   {
175         if (o == null) return false;
176     if (!(o instanceof Template)) return false;
177     Template t = (Template)o;
178     if (t.getName() == null) return false;
179     if (t.getName().equals(this.getName())) return true;
180     return false;
181   }
182 }