1 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 ; 17 import org.mmbase.util.logging.*; 18 import org.mmbase.util.xml.DocumentReader; 19 20 31 public class ServerFormatSorter extends PreferenceSorter { 32 private static Logger log = Logging.getLoggerInstance(ServerFormatSorter.class); 33 34 public static final String CONFIG_TAG = MainFilter.FILTERCONFIG_TAG + ".preferredSource"; 35 public static final String FORMAT_ATT = "format"; 36 37 protected List preferredFormats = new ArrayList(); 38 39 public ServerFormatSorter() {}; 40 41 public void configure(DocumentReader reader, Element el) { 42 preferredFormats.clear(); 43 for( Iterator e = reader.getChildElements(reader.getElementByPath(el, CONFIG_TAG));e.hasNext();) { 45 Element n3=(Element )e.next(); 46 String 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; if (log.isDebugEnabled()) log.debug("preference of format '" + format + "': " + index); 62 return index; 63 } 64 65 66 } 67 68 | Popular Tags |