Clover coverage report - Code Coverage for tapestry release 4.0.2
Coverage timestamp: Thu Apr 13 2006 10:52:06 EDT
file stats: LOC: 77   Methods: 4
NCLOC: 40   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
MarkupWriterSourceImpl.java 75% 85.7% 100% 86.4%
coverage coverage
 1    // Copyright 2005 The Apache Software Foundation
 2    //
 3    // Licensed under the Apache License, Version 2.0 (the "License");
 4    // you may not use this file except in compliance with the License.
 5    // You may obtain a copy of the License at
 6    //
 7    // http://www.apache.org/licenses/LICENSE-2.0
 8    //
 9    // Unless required by applicable law or agreed to in writing, software
 10    // distributed under the License is distributed on an "AS IS" BASIS,
 11    // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 12    // See the License for the specific language governing permissions and
 13    // limitations under the License.
 14   
 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    /**
 26    * @author Howard M. Lewis Ship
 27    * @since 4.0
 28    */
 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  39 public void setContributions(Map contributions)
 38    {
 39  39 _contributions = contributions;
 40    }
 41   
 42  130 public IMarkupWriter newMarkupWriter(PrintWriter writer, ContentType contentType)
 43    {
 44  130 Defense.notNull(writer, "writer");
 45  130 Defense.notNull(contentType, "contentType");
 46   
 47  130 MarkupFilter filter = findFilter(contentType);
 48   
 49  130 return new MarkupWriterImpl(contentType.toString(), writer, filter);
 50    }
 51   
 52  130 private MarkupFilter findFilter(ContentType contentType)
 53    {
 54    // Look for an exact match (caseless).
 55   
 56  130 String key = contentType.toString().toLowerCase();
 57   
 58  130 MarkupFilter result = (MarkupFilter) _contributions.get(key);
 59   
 60  130 if (result == null)
 61  23 result = (MarkupFilter) _contributions.get(contentType.getMimeType());
 62   
 63  130 if (result == null)
 64    {
 65  0 _log.error(MarkupMessages.noFilterMatch(contentType));
 66   
 67  0 result = _defaultFilter;
 68    }
 69   
 70  130 return result;
 71    }
 72   
 73  39 public void setLog(Log log)
 74    {
 75  39 _log = log;
 76    }
 77    }