|
|||||||||||||||||||
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 | |||||||||||||||
DefaultCharacterTranslatorSource.java | 0% | 0% | 0% | 0% |
|
1 | // Copyright 2004, 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.util.text; | |
16 | ||
17 | import java.util.HashMap; | |
18 | import java.util.Map; | |
19 | ||
20 | /** | |
21 | * The default implementation of a character translator source. | |
22 | * Returns a standard HTML translator that encodes everything that is non-safe | |
23 | * or an HTML translator that encodes only non-safe ASCII symbols | |
24 | * if the encoding is a unicode one. | |
25 | * | |
26 | * @author mb | |
27 | * @since 4.0 | |
28 | */ | |
29 | public class DefaultCharacterTranslatorSource implements ICharacterTranslatorSource | |
30 | { | |
31 | private static final ICharacterTranslator DEFAULT_TRANSLATOR = new MarkupCharacterTranslator(); | |
32 | private static final ICharacterTranslator UNICODE_TRANSLATOR = new MarkupCharacterTranslator(false); | |
33 | ||
34 | private final static Map _translators; | |
35 | ||
36 | static { | |
37 | 0 | _translators = new HashMap(); |
38 | 0 | _translators.put("UTF-8", UNICODE_TRANSLATOR); |
39 | 0 | _translators.put("UTF-7", UNICODE_TRANSLATOR); |
40 | 0 | _translators.put("UTF-16", UNICODE_TRANSLATOR); |
41 | 0 | _translators.put("UTF-16BE", UNICODE_TRANSLATOR); |
42 | 0 | _translators.put("UTF-16LE", UNICODE_TRANSLATOR); |
43 | } | |
44 | ||
45 | /** | |
46 | * Returns a translator that encodes all non-safe characters into their HTML equivalents. | |
47 | * | |
48 | * @see org.apache.tapestry.util.text.ICharacterTranslatorSource#getDefaultTranslator() | |
49 | */ | |
50 | 0 | public ICharacterTranslator getDefaultTranslator() { |
51 | 0 | return DEFAULT_TRANSLATOR; |
52 | } | |
53 | ||
54 | /** | |
55 | * If the encoding is a Unicode one, returns a translator that encodes only the | |
56 | * non-safe ASCII characters and leaves the others untouched. | |
57 | * Otherwise, returns the default translator. | |
58 | * | |
59 | * @see org.apache.tapestry.util.text.ICharacterTranslatorSource#getTranslator(java.lang.String) | |
60 | */ | |
61 | 0 | public ICharacterTranslator getTranslator(String encoding) { |
62 | 0 | ICharacterTranslator translator = (ICharacterTranslator) _translators.get(encoding.toUpperCase()); |
63 | 0 | if (translator != null) |
64 | 0 | return translator; |
65 | 0 | return getDefaultTranslator(); |
66 | } | |
67 | ||
68 | } |
|