|
|||||||||||||||||||
30 day Evaluation License registered to hlship@comcast.net Your 30 day evaluation period has expired. Please visit http://www.cenqua.com to obtain a licensed version of Clover | |||||||||||||||||||
Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
MarkupWriterSourceImpl.java | 75% | 85.7% | 100% | 86.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.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 | 41 | public void setContributions(Map contributions) |
38 | { | |
39 | 41 | _contributions = contributions; |
40 | } | |
41 | ||
42 | 141 | public IMarkupWriter newMarkupWriter(PrintWriter writer, ContentType contentType) |
43 | { | |
44 | 141 | Defense.notNull(writer, "writer"); |
45 | 141 | Defense.notNull(contentType, "contentType"); |
46 | ||
47 | 141 | MarkupFilter filter = findFilter(contentType); |
48 | ||
49 | 141 | return new MarkupWriterImpl(contentType.toString(), writer, filter); |
50 | } | |
51 | ||
52 | 141 | private MarkupFilter findFilter(ContentType contentType) |
53 | { | |
54 | // Look for an exact match (caseless). | |
55 | ||
56 | 141 | String key = contentType.toString().toLowerCase(); |
57 | ||
58 | 141 | MarkupFilter result = (MarkupFilter) _contributions.get(key); |
59 | ||
60 | 141 | if (result == null) |
61 | 23 | result = (MarkupFilter) _contributions.get(contentType.getMimeType()); |
62 | ||
63 | 141 | if (result == null) |
64 | { | |
65 | 0 | _log.error(MarkupMessages.noFilterMatch(contentType)); |
66 | ||
67 | 0 | result = _defaultFilter; |
68 | } | |
69 | ||
70 | 141 | return result; |
71 | } | |
72 | ||
73 | 41 | public void setLog(Log log) |
74 | { | |
75 | 41 | _log = log; |
76 | } | |
77 | } |
|