1 | // Copyright (C) 2010 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.service; |
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 cajoling service |
27 | * |
28 | * @author mikesamuel@gmail.com |
29 | * @author ihab.awad@gmail.com |
30 | */ |
31 | public enum ServiceMessageType implements MessageTypeInt { |
32 | CANNOT_FETCH_INPUT_URL("Cannot fetch input URL %s", MessageLevel.FATAL_ERROR), |
33 | EXCEPTION_IN_SERVICE("Service threw exception %s", MessageLevel.FATAL_ERROR), |
34 | INVALID_ARGUMENT("Invalid value %s for argument %s", |
35 | MessageLevel.FATAL_ERROR), |
36 | INVALID_INPUT_URL("Invalid input URL %s", MessageLevel.FATAL_ERROR), |
37 | IO_ERROR("I/O error: %s", MessageLevel.FATAL_ERROR), |
38 | MISSING_ARGUMENT("Missing argument %s", MessageLevel.FATAL_ERROR), |
39 | UNSUPPORTED_CONTENT_TYPES("Requested content types are unsupported", |
40 | MessageLevel.FATAL_ERROR), |
41 | UNEXPECTED_INPUT_MIME_TYPE("Expected input MIME type %s but found %s", |
42 | MessageLevel.FATAL_ERROR), |
43 | ; |
44 | |
45 | private final String formatString; |
46 | private final MessageLevel level; |
47 | private final int paramCount; |
48 | |
49 | ServiceMessageType(String formatString, MessageLevel level) { |
50 | this.formatString = formatString; |
51 | this.level = level; |
52 | this.paramCount = MessageType.formatStringArity(formatString); |
53 | } |
54 | |
55 | public int getParamCount() { |
56 | return paramCount; |
57 | } |
58 | |
59 | public void format(MessagePart[] parts, MessageContext context, |
60 | Appendable out) throws IOException { |
61 | MessageType.formatMessage(formatString, parts, context, out); |
62 | } |
63 | |
64 | public MessageLevel getLevel() { return level; } |
65 | } |