1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.jetspeed.om.registry.base;
18
19 import org.apache.jetspeed.om.registry.MediaTypeRegistry;
20 import org.apache.jetspeed.om.registry.MediaTypeEntry;
21 import org.apache.jetspeed.om.registry.RegistryEntry;
22 import org.apache.jetspeed.om.registry.InvalidEntryException;
23 import org.apache.jetspeed.om.registry.RegistryException;
24 import org.apache.jetspeed.services.Registry;
25 import org.apache.jetspeed.services.logging.JetspeedLogFactoryService;
26 import org.apache.jetspeed.services.logging.JetspeedLogger;
27 import org.apache.jetspeed.capability.CapabilityMap;
28
29 import java.util.Iterator;
30 import java.util.Enumeration;
31 import java.util.List;
32 import java.util.ArrayList;
33
34 /***
35 * Extends BaseRegistry implementation to override object creation
36 * method
37 *
38 * @author <a href="mailto:raphael@apache.org">Raphaël Luta</a>
39 * @version $Id: BaseMediaTypeRegistry.java,v 1.7 2004/02/23 03:08:26 jford Exp $
40 */
41 public class BaseMediaTypeRegistry extends BaseOrderedRegistry
42 implements MediaTypeRegistry
43 {
44
45 /***
46 * Static initialization of the logger for this class
47 */
48 private static final JetspeedLogger logger = JetspeedLogFactoryService.getLogger(BaseMediaTypeRegistry.class.getName());
49
50
51
52
53
54
55
56 public Iterator findForCapability(CapabilityMap cm)
57 {
58 if (cm == null)
59 {
60 return null;
61 }
62
63 String type = cm.getPreferredType().getContentType();
64 List result = new ArrayList();
65
66 if ( logger.isDebugEnabled() )
67 {
68 logger.debug("MediaTypeRegistry: looking for type " + type );
69 }
70
71 if (type == null)
72 {
73 return result.iterator();
74 }
75
76 try
77 {
78 Enumeration en = getEntries();
79 while(en.hasMoreElements())
80 {
81 MediaTypeEntry mte = (MediaTypeEntry)en.nextElement();
82
83 if ( logger.isDebugEnabled() )
84 {
85 logger.debug("MediaTypeRegistry: found MediaTypeEntry for type " + mte.getMimeType() );
86 }
87 if (type.equals(mte.getMimeType()))
88 {
89 result.add(mte);
90 }
91 }
92 }
93 catch(Exception e)
94 {
95 logger.error("Exception", e);
96 }
97
98 if ( logger.isDebugEnabled() )
99 {
100 logger.debug("MediaTypeRegistry: found " + result.size() + " entries." );
101 }
102
103 return result.iterator();
104
105 }
106
107 /***
108 @see Registry#setEntry
109 */
110 public void setEntry( RegistryEntry entry ) throws InvalidEntryException
111 {
112
113
114
115 try
116 {
117 Registry.addEntry(Registry.MEDIA_TYPE, entry);
118 }
119 catch (RegistryException e)
120 {
121 logger.error("Exception", e);
122 }
123 }
124
125 /***
126 @see Registry#addEntry
127 */
128 public void addEntry( RegistryEntry entry ) throws InvalidEntryException
129 {
130
131
132
133 try
134 {
135 Registry.addEntry(Registry.MEDIA_TYPE, entry);
136 }
137 catch (RegistryException e)
138 {
139 logger.error("Exception", e);
140 }
141 }
142
143 /***
144 @see Registry#removeEntry
145 */
146 public void removeEntry( String name )
147 {
148
149
150
151 Registry.removeEntry(Registry.MEDIA_TYPE, name);
152 }
153
154 /***
155 @see Registry#removeEntry
156 */
157 public void removeEntry( RegistryEntry entry )
158 {
159
160
161
162 if (entry != null)
163 {
164 Registry.removeEntry(Registry.MEDIA_TYPE, entry.getName());
165 }
166 }
167
168 /***
169 * Creates a new RegistryEntry instance compatible with the current
170 * Registry instance implementation
171 *
172 * @return the newly created RegistryEntry
173 */
174 public RegistryEntry createEntry()
175 {
176 return new BaseMediaTypeEntry();
177 }
178 }