1 | // Copyright (C) 2006 Google Inc. |
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 com.google.caja.plugin; |
16 | |
17 | import com.google.caja.reporting.MessageContext; |
18 | import com.google.caja.reporting.MessageLevel; |
19 | import com.google.caja.reporting.MessagePart; |
20 | import com.google.caja.reporting.MessageType; |
21 | import com.google.caja.reporting.MessageTypeInt; |
22 | |
23 | import java.io.IOException; |
24 | |
25 | /** |
26 | * Messages for the PluginCompiler |
27 | * |
28 | * @author mikesamuel@gmail.com |
29 | */ |
30 | public enum PluginMessageType implements MessageTypeInt { |
31 | ILLEGAL_GLOBAL_ACCESS( |
32 | "%s: access not allowed to global %s", MessageLevel.FATAL_ERROR), |
33 | UNSAFE_ACCESS( |
34 | "%s: unsafe access to protected namespace: %s", MessageLevel.FATAL_ERROR), |
35 | UNKNOWN_TAG("%s: unknown tag %s", MessageLevel.WARNING), |
36 | UNSAFE_TAG("%s: removing disallowed tag %s", MessageLevel.WARNING), |
37 | MISSING_ATTRIBUTE("%s: expected param %s on %s", MessageLevel.ERROR), |
38 | UNKNOWN_ATTRIBUTE("%s: removing unknown attribute %s on %s", |
39 | MessageLevel.WARNING), |
40 | UNSAFE_ATTRIBUTE("%s: removing disallowed attribute %s on tag %s", |
41 | MessageLevel.WARNING), |
42 | FOLDING_ELEMENT("%s: folding element %s into parent", MessageLevel.WARNING), |
43 | CANNOT_FOLD_ATTRIBUTE("%s: removing attribute %s when folding %s into parent", |
44 | MessageLevel.WARNING), |
45 | DISALLOWED_ATTRIBUTE_VALUE("%s: attribute %s cannot have value %s", |
46 | MessageLevel.WARNING), |
47 | BAD_IDENTIFIER("%s: bad identifier %s", MessageLevel.FATAL_ERROR), |
48 | ATTRIBUTE_CANNOT_BE_DYNAMIC( |
49 | "%s: tag %s cannot have dynamic attribute %s", MessageLevel.ERROR), |
50 | DISALLOWED_URI("%s: url %s cannot be linked to", MessageLevel.FATAL_ERROR), |
51 | MALFORMED_URL("%s: malformed url %s", MessageLevel.FATAL_ERROR), |
52 | MALFORMED_CSS_PROPERTY_VALUE( |
53 | "%s: css property %s has bad value: %s", MessageLevel.WARNING), |
54 | DISALLOWED_CSS_PROPERTY_IN_SELECTOR( |
55 | "%s: css property %s not allowed in :visited selector at %s", |
56 | MessageLevel.ERROR), |
57 | UNKNOWN_CSS_PROPERTY("%s: unknown css property %s", MessageLevel.ERROR), |
58 | CSS_VALUE_OUT_OF_RANGE( |
59 | "%s: css property %s with value %s not in range [%s, %s]", |
60 | MessageLevel.WARNING), |
61 | UNSAFE_CSS_IDENTIFIER( |
62 | "%s: css identifier '%s' contains characters that may not work" |
63 | + " on all browsers", MessageLevel.FATAL_ERROR), |
64 | UNSAFE_CSS_PROPERTY("%s: unsafe css property %s", MessageLevel.ERROR), |
65 | UNSAFE_CSS_PSEUDO_SELECTOR( |
66 | "%s: unsafe css pseudo-selector %s", MessageLevel.ERROR), |
67 | CSS_DASHMATCH_ATTRIBUTE_OPERATOR_NOT_ALLOWED( |
68 | "%s: css dash match attribute operation not allowed", MessageLevel.ERROR), |
69 | CSS_URI_VALUED_ATTRIBUTE_SELECTOR_NOT_ALLOWED( |
70 | "%s: css URI-valued attribute selector not allowed", MessageLevel.ERROR), |
71 | CSS_ATTRIBUTE_NAME_NOT_ALLOWED_IN_SELECTOR( |
72 | "%s: css attribute name %s not allowed in selector", MessageLevel.ERROR), |
73 | CSS_ATTRIBUTE_TYPE_NOT_ALLOWED_IN_SELECTOR( |
74 | "%s: css attribute type %s not allowed in selector", MessageLevel.ERROR), |
75 | CSS_LINK_PSEUDO_SELECTOR_NOT_ALLOWED_ON_NONANCHOR( |
76 | "%s: css :link and :visited pseudo selectors only allowed on A elements", |
77 | MessageLevel.ERROR), |
78 | SKIPPING_CSS_PROPERTY( |
79 | "%s: skipping invalid css property %s", MessageLevel.WARNING), |
80 | IMPORTS_NOT_ALLOWED_HERE("%s: @import not allowed here", MessageLevel.ERROR), |
81 | CYCLIC_INCLUDE("%s: cyclic include of %s", MessageLevel.ERROR), |
82 | FONT_FACE_NOT_ALLOWED("%s: @font-face not allowed", MessageLevel.ERROR), |
83 | FAILED_TO_LOAD_EXTERNAL_URL( |
84 | "%s: failed to load external url %s", MessageLevel.WARNING), |
85 | NO_CONTENT("%s: no content", MessageLevel.FATAL_ERROR), |
86 | UNRECOGNIZED_CONTENT_TYPE( |
87 | "%s: unrecognized content type %s for %s tag", MessageLevel.WARNING), |
88 | UNRECOGNIZED_MEDIA_TYPE( |
89 | "%s: unrecognized media type %s", MessageLevel.WARNING), |
90 | UNRECOGNIZED_ATTRIBUTE_VALUE( |
91 | "%s: unrecognized attribute value %s for %s attribute of %s tag", |
92 | MessageLevel.WARNING), |
93 | QUOTED_CSS_VALUE("%s: quoted unquoted css value %s", MessageLevel.LINT), |
94 | ASSUMING_PIXELS_FOR_LENGTH( |
95 | "%s: assuming pixels for length %s", MessageLevel.WARNING), |
96 | NON_STANDARD_COLOR( |
97 | "%s: replacing non-standard color %s with hex %s", MessageLevel.LINT), |
98 | MALFORMED_ENVELOPE( |
99 | "%s: malformed envelope around cajoled code", MessageLevel.ERROR), |
100 | SPECIALIZING_CSS_PROPERTY( |
101 | "%s: specialized CSS property %s to %s", MessageLevel.WARNING), |
102 | MISSING_XML_NAMESPACE( |
103 | "%s: XML %s has prefix but no namespace", MessageLevel.ERROR), |
104 | INVALID_PIPELINE("Cannot find plan from %s to %s", MessageLevel.FATAL_ERROR), |
105 | ; |
106 | |
107 | private final String formatString; |
108 | private final MessageLevel level; |
109 | private final int paramCount; |
110 | |
111 | PluginMessageType(String formatString, MessageLevel level) { |
112 | this.formatString = formatString; |
113 | this.level = level; |
114 | this.paramCount = MessageType.formatStringArity(formatString); |
115 | } |
116 | |
117 | public int getParamCount() { |
118 | return paramCount; |
119 | } |
120 | |
121 | public void format(MessagePart[] parts, MessageContext context, |
122 | Appendable out) throws IOException { |
123 | MessageType.formatMessage(formatString, parts, context, out); |
124 | } |
125 | |
126 | public MessageLevel getLevel() { return level; } |
127 | } |