1 | // Copyright (C) 2007 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.parser.html; |
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 Dom Parser |
27 | * |
28 | * @author mikesamuel@gmail.com |
29 | */ |
30 | public enum DomParserMessageType implements MessageTypeInt { |
31 | UNMATCHED_END("%s: end tag %s does not match open tag %s", |
32 | MessageLevel.FATAL_ERROR), |
33 | MISPLACED_CONTENT("%s: markup outside document", MessageLevel.ERROR), |
34 | UNCLOSED_TAG("%s: tag is not closed", MessageLevel.ERROR), |
35 | MISSING_END("%s: element %s at %s is not closed", MessageLevel.WARNING), |
36 | IGNORING_TOKEN("%s: ignoring token %s", MessageLevel.WARNING), |
37 | MOVING_TO_HEAD("%s: moving element %s to head", MessageLevel.LINT), |
38 | MISSING_DOCUMENT_ELEMENT("%s: no document element", MessageLevel.ERROR), |
39 | GENERIC_SAX_ERROR("%s: %s", MessageLevel.FATAL_ERROR), |
40 | ; |
41 | |
42 | private final String formatString; |
43 | private final MessageLevel level; |
44 | private final int paramCount; |
45 | |
46 | DomParserMessageType(String formatString, MessageLevel level) { |
47 | this.formatString = formatString; |
48 | this.level = level; |
49 | this.paramCount = MessageType.formatStringArity(formatString); |
50 | } |
51 | |
52 | public int getParamCount() { |
53 | return paramCount; |
54 | } |
55 | |
56 | public void format(MessagePart[] parts, MessageContext context, |
57 | Appendable out) throws IOException { |
58 | MessageType.formatMessage(formatString, parts, context, out); |
59 | } |
60 | |
61 | public MessageLevel getLevel() { return level; } |
62 | } |