1 15 package org.apache.tapestry.markup; 16 17 import java.io.PrintWriter ; 18 import java.util.Map ; 19 20 import org.apache.commons.logging.Log; 21 import org.apache.hivemind.util.Defense; 22 import org.apache.tapestry.IMarkupWriter; 23 import org.apache.tapestry.util.ContentType; 24 25 29 public class MarkupWriterSourceImpl implements MarkupWriterSource 30 { 31 private Log _log; 32 33 private MarkupFilter _defaultFilter = new AsciiMarkupFilter(); 34 35 private Map _contributions; 36 37 public void setContributions(Map contributions) 38 { 39 _contributions = contributions; 40 } 41 42 public IMarkupWriter newMarkupWriter(PrintWriter writer, ContentType contentType) 43 { 44 Defense.notNull(writer, "writer"); 45 Defense.notNull(contentType, "contentType"); 46 47 MarkupFilter filter = findFilter(contentType); 48 49 return new MarkupWriterImpl(contentType.toString(), writer, filter); 50 } 51 52 private MarkupFilter findFilter(ContentType contentType) 53 { 54 56 String key = contentType.toString().toLowerCase(); 57 58 MarkupFilter result = (MarkupFilter) _contributions.get(key); 59 60 if (result == null) 61 result = (MarkupFilter) _contributions.get(contentType.getMimeType()); 62 63 if (result == null) 64 { 65 _log.error(MarkupMessages.noFilterMatch(contentType)); 66 67 result = _defaultFilter; 68 } 69 70 return result; 71 } 72 73 public void setLog(Log log) 74 { 75 _log = log; 76 } 77 } | Popular Tags |