Coverage Report - org.apache.tapestry.markup.MarkupWriterSourceImpl
 
Classes in this File Line Coverage Branch Coverage Complexity
MarkupWriterSourceImpl
0%
0/21
0%
0/4
1.4
 
 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.json.IJSONWriter;
 24  
 import org.apache.tapestry.util.ContentType;
 25  
 
 26  
 /**
 27  
  * @author Howard M. Lewis Ship
 28  
  * @since 4.0
 29  
  */
 30  0
 public class MarkupWriterSourceImpl implements MarkupWriterSource
 31  
 {
 32  
     private Log _log;
 33  
 
 34  0
     private MarkupFilter _defaultFilter = new AsciiMarkupFilter();
 35  
 
 36  
     private Map _contributions;
 37  
 
 38  
     public void setContributions(Map contributions)
 39  
     {
 40  0
         _contributions = contributions;
 41  0
     }
 42  
 
 43  
     public IMarkupWriter newMarkupWriter(PrintWriter writer, ContentType contentType)
 44  
     {
 45  0
         Defense.notNull(writer, "writer");
 46  0
         Defense.notNull(contentType, "contentType");
 47  
 
 48  0
         MarkupFilter filter = findFilter(contentType);
 49  
 
 50  0
         return new MarkupWriterImpl(contentType.toString(), writer, filter);
 51  
     }
 52  
     
 53  
     public IJSONWriter newJSONWriter(PrintWriter writer, ContentType contentType)
 54  
     {
 55  0
         Defense.notNull(writer, "writer");
 56  0
         Defense.notNull(contentType, "contentType");
 57  
         
 58  
         //TODO: Use the content type to add a filter
 59  
         //MarkupFilter filter = findFilter(contentType);
 60  
         
 61  0
         return new JSONWriterImpl(writer);
 62  
     }
 63  
     
 64  
     private MarkupFilter findFilter(ContentType contentType)
 65  
     {
 66  
         // Look for an exact match (caseless).
 67  
 
 68  0
         String key = contentType.toString().toLowerCase();
 69  
 
 70  0
         MarkupFilter result = (MarkupFilter) _contributions.get(key);
 71  
 
 72  0
         if (result == null)
 73  0
             result = (MarkupFilter) _contributions.get(contentType.getMimeType());
 74  
 
 75  0
         if (result == null)
 76  
         {
 77  0
             _log.error(MarkupMessages.noFilterMatch(contentType));
 78  
 
 79  0
             result = _defaultFilter;
 80  
         }
 81  
 
 82  0
         return result;
 83  
     }
 84  
 
 85  
     public void setLog(Log log)
 86  
     {
 87  0
         _log = log;
 88  0
     }
 89  
 }