KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > mmbase > applications > media > filters > ClientFormatSorter


1  /*
2  
3 This software is OSI Certified Open Source Software.
4 OSI Certified is a certification mark of the Open Source Initiative.
5  
6 The license (Mozilla version 1.0) can be read at the MMBase site.
7 See http://www.MMBase.org/license
8  
9  */

10
11 package org.mmbase.applications.media.filters;
12
13 import org.mmbase.applications.media.urlcomposers.URLComposer;
14 import org.mmbase.applications.media.Format;
15 import java.util.*;
16 import org.mmbase.util.logging.*;
17
18 /**
19  * Client's preferred format can be different for every request. This
20  * Sorter uses the 'info' Map to sort the requested formats to the top
21  * of the urlcomposer list.
22  *
23  * @author Michiel Meeuwissen
24  * @version $Id: ClientFormatSorter.java,v 1.5 2005/01/30 16:46:35 nico Exp $
25  */

26 public class ClientFormatSorter extends PreferenceSorter {
27     private static Logger log = Logging.getLoggerInstance(ClientFormatSorter.class);
28
29
30     public ClientFormatSorter() {
31     }
32     
33     protected int getPreference(URLComposer ri) {
34         if (log.isDebugEnabled()) {
35             log.debug("ri: " + ri);
36             log.debug("info: " + ri.getInfo());
37         }
38
39         Object JavaDoc format = ri.getInfo().get("format");
40         if (log.isDebugEnabled()) { log.debug("Client's preference " + format); }
41         if (format == null) {
42             return 0; // no client preference given
43
} else {
44             if (format instanceof Format) {
45                 if (format == ri.getFormat()) return 100;
46             } else if (format instanceof String JavaDoc) {
47                 if (Format.get((String JavaDoc) format) == ri.getFormat()) return 100;
48             } else if (format instanceof List) {
49                 List formatList = (List) format;
50                 int i = formatList.indexOf(ri.getFormat().toString());
51                 return i == -1 ? -10000 : -i; // the higher in this list, the better, 0 is highest.
52

53             } else {
54                 log.error("Someting wrong in client's INFO, 'format' specified wrongly: " + format);
55                 return 0;
56             }
57         }
58         return 0;
59     }
60
61 }
62
63
Popular Tags