KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jahia > services > homepages > HomepageTypes


1 //
2
// ____.
3
// __/\ ______| |__/\. _______
4
// __ .____| | \ | +----+ \
5
// _______| /--| | | - \ _ | : - \_________
6
// \\______: :---| : : | : | \________>
7
// |__\---\_____________:______: :____|____:_____\
8
// /_____|
9
//
10
// . . . i n j a h i a w e t r u s t . . .
11
//
12
//
13
// NK - 17 Dec. 2001 :
14
//
15

16 package org.jahia.services.homepages;
17
18 import java.util.Hashtable JavaDoc;
19
20 /**
21  * Map Homepage classes to homepage types.
22  *
23  * @author Khue ng
24  * @version 1.0
25  */

26 public class HomepageTypes {
27
28     public static final int HOMEPAGE_LINK = 1;
29     public static final int HOMEPAGE_COPY = 2;
30     public static final int HOMEPAGE_NEW = 3;
31
32     private static HomepageTypes instance;
33     private Hashtable JavaDoc types;
34     private Hashtable JavaDoc typeLabels;
35     private Hashtable JavaDoc classesNames;
36
37
38     /**
39      * Constructor
40      */

41     protected HomepageTypes()
42     {
43         types = new Hashtable JavaDoc();
44         types.put("LINK",new Integer JavaDoc(HOMEPAGE_LINK));
45         types.put("COPY",new Integer JavaDoc(HOMEPAGE_COPY));
46         types.put("NEW",new Integer JavaDoc(HOMEPAGE_NEW));
47
48         typeLabels = new Hashtable JavaDoc();
49         typeLabels.put(new Integer JavaDoc(HOMEPAGE_LINK),"LINK");
50         typeLabels.put(new Integer JavaDoc(HOMEPAGE_COPY),"COPY");
51         typeLabels.put(new Integer JavaDoc(HOMEPAGE_NEW),"NEW");
52
53         classesNames = new Hashtable JavaDoc();
54         classesNames.put( new Integer JavaDoc(HOMEPAGE_LINK), "org.jahia.services.homepages.JahiaHomepageLink");
55         classesNames.put( new Integer JavaDoc(HOMEPAGE_COPY), "org.jahia.services.homepages.JahiaHomepageCopy");
56         classesNames.put( new Integer JavaDoc(HOMEPAGE_NEW), "org.jahia.services.homepages.JahiaHomepageNew");
57     }
58
59     /**
60      * Returns the simgle instance of this site
61      *
62      * @return HomepageTypes
63      */

64     public static synchronized HomepageTypes getInstance()
65     {
66         if (instance == null) {
67             instance = new HomepageTypes();
68         }
69         return instance;
70     }
71
72     /**
73      * gets available homepage types
74      *
75      * @return Hashtable of homepage types
76      */

77     public Hashtable JavaDoc getTypes()
78     {
79         if ( types == null )
80             return null;
81         
82         /* Deactivate NEW and COPY
83         Hashtable hash = (Hashtable) types.clone();
84         */

85         Hashtable JavaDoc hash = new Hashtable JavaDoc();
86         hash.put("LINK",new Integer JavaDoc(HOMEPAGE_LINK));
87         
88         return hash;
89     }
90
91     /**
92      * Return a type looking at its key
93      *
94      * @param String type key
95      * @return int the type or -1 if not found
96      */

97     public int getType(String JavaDoc key)
98     {
99         if ( key == null )
100             return -1;
101             
102         Integer JavaDoc type = (Integer JavaDoc) types.get(key);
103         
104         if ( type == null )
105             return -1;
106         
107         return type.intValue();
108     }
109
110     /**
111      * Return a type's name ( readable value ).
112      *
113      * @param int the type value
114      * @return String the type's name
115      */

116     public String JavaDoc getTypeName(int type)
117     {
118         Integer JavaDoc I = new Integer JavaDoc(type);
119         String JavaDoc name = (String JavaDoc)typeLabels.get(I);
120
121         if ( name == null )
122             return "UNKNOWN";
123         
124         return name;
125     }
126
127
128     /**
129      * gets classesNames
130      *
131      * @return Hashtable of classes name
132      */

133     public Hashtable JavaDoc getClassesNames()
134     {
135         if ( classesNames == null )
136             classesNames = new Hashtable JavaDoc();
137             
138         Hashtable JavaDoc hash = (Hashtable JavaDoc) classesNames.clone();
139         return hash;
140         
141     }
142
143 }
Popular Tags