|
1 /** |
|
2 * Copyright (c) 2012, Ben Fortuna |
|
3 * All rights reserved. |
|
4 * |
|
5 * Redistribution and use in source and binary forms, with or without |
|
6 * modification, are permitted provided that the following conditions |
|
7 * are met: |
|
8 * |
|
9 * o Redistributions of source code must retain the above copyright |
|
10 * notice, this list of conditions and the following disclaimer. |
|
11 * |
|
12 * o Redistributions in binary form must reproduce the above copyright |
|
13 * notice, this list of conditions and the following disclaimer in the |
|
14 * documentation and/or other materials provided with the distribution. |
|
15 * |
|
16 * o Neither the name of Ben Fortuna nor the names of any other contributors |
|
17 * may be used to endorse or promote products derived from this software |
|
18 * without specific prior written permission. |
|
19 * |
|
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
|
21 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
|
22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
|
23 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR |
|
24 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
|
25 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
|
26 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
|
27 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF |
|
28 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
|
29 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
|
30 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
|
31 */ |
|
32 package net.fortuna.ical4j.util; |
|
33 |
|
34 import java.util.Map; |
|
35 |
|
36 import edu.emory.mathcs.backport.java.util.concurrent.ConcurrentHashMap; |
|
37 |
|
38 /** |
|
39 * $Id$ |
|
40 * |
|
41 * Created on 9/03/2006 |
|
42 * |
|
43 * A set of keys used to enable compatibility features. |
|
44 * |
|
45 * @author Ben Fortuna |
|
46 */ |
|
47 public final class CompatibilityHints { |
|
48 |
|
49 /** |
|
50 * A system property key to enable relaxed unfolding. Relaxed unfolding is enabled by setting this system property |
|
51 * to "true". |
|
52 */ |
|
53 public static final String KEY_RELAXED_UNFOLDING = "ical4j.unfolding.relaxed"; |
|
54 |
|
55 /** |
|
56 * A system property key to enable relaxed parsing. Relaxed parsing is enabled by setting this system property to |
|
57 * "true". |
|
58 */ |
|
59 public static final String KEY_RELAXED_PARSING = "ical4j.parsing.relaxed"; |
|
60 |
|
61 /** |
|
62 * A system property key to enable relaxed validation. Relaxed validation disables validation of certain conformance |
|
63 * rules that many iCalendar implementations do not conform to. Relaxed validation is enabled by setting this system |
|
64 * property to "true". |
|
65 */ |
|
66 public static final String KEY_RELAXED_VALIDATION = "ical4j.validation.relaxed"; |
|
67 |
|
68 /** |
|
69 * A system property key used to enable compatibility with Outlook/Exchange-generated iCalendar files. Outlook |
|
70 * compatibility is enabled by setting this system property to "true". |
|
71 */ |
|
72 public static final String KEY_OUTLOOK_COMPATIBILITY = "ical4j.compatibility.outlook"; |
|
73 |
|
74 /** |
|
75 * A system property key used to enable compatibility with Lotus Notes-generated iCalendar files. Notes |
|
76 * compatibility is enabled by setting this system property to "true". |
|
77 */ |
|
78 public static final String KEY_NOTES_COMPATIBILITY = "ical4j.compatibility.notes"; |
|
79 |
|
80 private static final Map HINTS = new ConcurrentHashMap(); |
|
81 // preload known hints from the configurator |
|
82 static { |
|
83 setHintEnabled(KEY_RELAXED_UNFOLDING, "true".equals(Configurator.getProperty(KEY_RELAXED_UNFOLDING))); |
|
84 setHintEnabled(KEY_RELAXED_PARSING, "true".equals(Configurator.getProperty(KEY_RELAXED_PARSING))); |
|
85 setHintEnabled(KEY_RELAXED_VALIDATION, "true".equals(Configurator.getProperty(KEY_RELAXED_VALIDATION))); |
|
86 setHintEnabled(KEY_OUTLOOK_COMPATIBILITY, "true".equals(Configurator.getProperty(KEY_OUTLOOK_COMPATIBILITY))); |
|
87 setHintEnabled(KEY_NOTES_COMPATIBILITY, "true".equals(Configurator.getProperty(KEY_NOTES_COMPATIBILITY))); |
|
88 } |
|
89 |
|
90 /** |
|
91 * Constructor made private to enforce static nature. |
|
92 */ |
|
93 private CompatibilityHints() { |
|
94 } |
|
95 |
|
96 /** |
|
97 * @param key |
|
98 * a compatibility hint key |
|
99 * @param enabled |
|
100 * indicates whether to enable or disable the compatibility hint |
|
101 */ |
|
102 public static void setHintEnabled(final String key, final boolean enabled) { |
|
103 HINTS.put(key, Boolean.valueOf(enabled)); |
|
104 } |
|
105 |
|
106 /** |
|
107 * @param key |
|
108 * a compatibility hint key |
|
109 */ |
|
110 public static void clearHintEnabled(final String key) { |
|
111 HINTS.remove(key); |
|
112 } |
|
113 |
|
114 /** |
|
115 * @param key |
|
116 * a compatibility hint key |
|
117 * @return true if the specified compatibility hint is enabled, otherwise false |
|
118 */ |
|
119 public static boolean isHintEnabled(final String key) { |
|
120 if (HINTS.get(key) != null) { |
|
121 return ((Boolean) HINTS.get(key)).booleanValue(); |
|
122 } |
|
123 return "true".equals(Configurator.getProperty(key)); |
|
124 } |
|
125 } |