raphael 2002/11/08 01:59:26
Modified: src/java/org/apache/jetspeed/capability
BaseCapabilityMap.java CapabilityMap.java
CapabilityMapFactory.java
Log:
Make sure factory never uses a null ClientEntry even if browser is unknown
Add media-type methods to the CapabilityMap interface
Revision Changes Path
1.7 +62 -1
jakarta-jetspeed/src/java/org/apache/jetspeed/capability/BaseCapabilityMap.java
Index: BaseCapabilityMap.java
===================================================================
RCS file:
/home/cvs/jakarta-jetspeed/src/java/org/apache/jetspeed/capability/BaseCapabilityMap.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- BaseCapabilityMap.java 7 Nov 2002 20:17:41 -0000 1.6
+++ BaseCapabilityMap.java 8 Nov 2002 09:59:26 -0000 1.7
@@ -58,11 +58,13 @@
import org.apache.jetspeed.util.MimeType;
import org.apache.jetspeed.om.registry.ClientEntry;
import org.apache.jetspeed.om.registry.MediaTypeEntry;
+import org.apache.jetspeed.om.registry.MediaTypeRegistry;
import org.apache.jetspeed.services.Registry;
//standard Java stuff
import java.util.Vector;
import java.util.Iterator;
+import java.util.Enumeration;
/**
* Read only wrapper around a ClientEntry registry entry that
@@ -89,6 +91,65 @@
public MimeType getPreferredType()
{
return entry.getMimetypeMap().getPreferredMimetype();
+ }
+
+ /**
+ Returns the preferred media type for the current user-agent
+ */
+ public String getPreferredMediaType()
+ {
+ Iterator i = listMediaTypes();
+
+ if (i.hasNext())
+ {
+ return (String)i.next();
+ }
+
+ return null;
+ }
+
+ /**
+ * Returns an ordered list of supported media-types, from most preferred
+ * to least preferred
+ */
+ public Iterator listMediaTypes()
+ {
+ Vector results = new Vector();
+ Vector types = new Vector();
+
+ // first copy the current media type list, ordered by global preference
+ Enumeration en =
((MediaTypeRegistry)Registry.get(Registry.MEDIA_TYPE)).getEntries();
+ while (en.hasMoreElements())
+ {
+ types.add(en.nextElement());
+ }
+
+ //then retrieve a list of supported mime-types, ordered by
+ //preference
+
+ Iterator mimes = entry.getMimetypeMap().getMimetypes();
+
+ //now, for each mime-type test if the media is supported
+ while(mimes.hasNext())
+ {
+ String mime = ((MimeType)mimes.next()).getContentType();
+ Iterator i = types.iterator();
+
+ while(i.hasNext())
+ {
+ MediaTypeEntry mte = (MediaTypeEntry)i.next();
+
+ if (mime.equals(mte.getMimeType()))
+ {
+ if
(entry.getCapabilityMap().containsAll(mte.getCapabilityMap()))
+ {
+ results.add(mte.getName());
+ }
+ }
+ }
+ }
+
+ return results.iterator();
}
/**
1.6 +12 -1
jakarta-jetspeed/src/java/org/apache/jetspeed/capability/CapabilityMap.java
Index: CapabilityMap.java
===================================================================
RCS file:
/home/cvs/jakarta-jetspeed/src/java/org/apache/jetspeed/capability/CapabilityMap.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- CapabilityMap.java 7 Nov 2002 20:17:41 -0000 1.5
+++ CapabilityMap.java 8 Nov 2002 09:59:26 -0000 1.6
@@ -120,6 +120,17 @@
public MimeType getPreferredType();
/**
+ Returns the preferred media type for the current user-agent
+ */
+ public String getPreferredMediaType();
+
+ /**
+ * Returns an ordered list of supported media-types, from most preferred
+ * to least preferred
+ */
+ public Iterator listMediaTypes();
+
+ /**
Returns the user-agent string
*/
public String getAgent();
1.12 +16 -5
jakarta-jetspeed/src/java/org/apache/jetspeed/capability/CapabilityMapFactory.java
Index: CapabilityMapFactory.java
===================================================================
RCS file:
/home/cvs/jakarta-jetspeed/src/java/org/apache/jetspeed/capability/CapabilityMapFactory.java,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -r1.11 -r1.12
--- CapabilityMapFactory.java 8 Nov 2002 09:47:25 -0000 1.11
+++ CapabilityMapFactory.java 8 Nov 2002 09:59:26 -0000 1.12
@@ -117,16 +117,27 @@
ClientRegistry registry = (ClientRegistry)Registry.get(Registry.CLIENT);
ClientEntry entry = registry.findEntry(useragent);
- map = new BaseCapabilityMap(useragent, entry);
- if ( (map == null) && (!useragent.equals(DEFAULT_AGENT)) )
+ if (entry == null)
{
- if (Log.getLogger().isDebugEnabled())
+ if (useragent.equals(DEFAULT_AGENT))
{
- Log.debug("CapabilityMap: useragent "+ useragent + "unknown,
falling back to default");
+ Log.error("CapabilityMap: Default agent not found in Client
Registry !");
+ }
+ else
+ {
+ if (Log.getLogger().isDebugEnabled())
+ {
+ Log.debug("CapabilityMap: useragent "+ useragent + "unknown,
falling back to default");
+ }
+ map = getDefaultCapabilityMap();
}
- map = getDefaultCapabilityMap();
}
+ else
+ {
+ map = new BaseCapabilityMap(useragent, entry);
+ }
+
if (Log.getLogger().isDebugEnabled())
{
--
To unsubscribe, e-mail: <mailto:jetspeed-dev-unsubscribe@;jakarta.apache.org>
For additional commands, e-mail: <mailto:jetspeed-dev-help@;jakarta.apache.org>