KickJava   Java API By Example, From Geeks To Geeks.

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


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.w3c.dom.Element JavaDoc;
17 import org.mmbase.util.logging.*;
18 import org.mmbase.util.xml.DocumentReader;
19
20 /**
21  * Sorts on format of the source, preferred formats can be can be
22  * configured with the filters.xml. This is called 'server'
23  * formatsorter, because this preference is configured on the server,
24  * rather then on the client, which is another logical option (which
25  * can be combined with this one).
26  *
27  * @author Michiel Meeuwissen
28  * @version $Id: ServerFormatSorter.java,v 1.8 2005/07/09 15:29:11 nklasens Exp $
29  * @see ClientFormatSorter
30  */

31 public class ServerFormatSorter extends PreferenceSorter {
32     private static Logger log = Logging.getLoggerInstance(ServerFormatSorter.class);
33
34     public static final String JavaDoc CONFIG_TAG = MainFilter.FILTERCONFIG_TAG + ".preferredSource";
35     public static final String JavaDoc FORMAT_ATT = "format";
36
37     protected List preferredFormats = new ArrayList();
38
39     public ServerFormatSorter() {};
40
41     public void configure(DocumentReader reader, Element JavaDoc el) {
42         preferredFormats.clear();
43         // reading preferredSource information
44
for( Iterator e = reader.getChildElements(reader.getElementByPath(el, CONFIG_TAG));e.hasNext();) {
45             Element JavaDoc n3=(Element JavaDoc)e.next();
46             String JavaDoc format = reader.getElementAttributeValue(n3, FORMAT_ATT);
47             preferredFormats.add(Format.get(format));
48             log.service("Adding preferredSource format: '"+format +"'");
49         }
50   
51     }
52     
53     protected int getPreference(URLComposer ri) {
54         Format format = ri.getFormat();
55         int index = preferredFormats.indexOf(format);
56         if (index == -1) {
57             if (log.isDebugEnabled()) log.debug("Not found format: '" + format + "' in" + preferredFormats);
58             index = preferredFormats.size() + 1;
59         }
60         index = -index; // low index = high preference
61
if (log.isDebugEnabled()) log.debug("preference of format '" + format + "': " + index);
62         return index;
63     }
64
65     
66 }
67
68
Popular Tags