source: josm/trunk/src/org/glassfish/json/JsonMessages.java@ 10063

Last change on this file since 10063 was 6756, checked in by Don-vip, 10 years ago

fix #9590 - replace org.json with GPL-compliant jsonp + remove mention of old world image removed in r1680

File size: 7.0 KB
Line 
1/*
2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3 *
4 * Copyright (c) 2013 Oracle and/or its affiliates. All rights reserved.
5 *
6 * The contents of this file are subject to the terms of either the GNU
7 * General Public License Version 2 only ("GPL") or the Common Development
8 * and Distribution License("CDDL") (collectively, the "License"). You
9 * may not use this file except in compliance with the License. You can
10 * obtain a copy of the License at
11 * https://glassfish.dev.java.net/public/CDDL+GPL_1_1.html
12 * or packager/legal/LICENSE.txt. See the License for the specific
13 * language governing permissions and limitations under the License.
14 *
15 * When distributing the software, include this License Header Notice in each
16 * file and include the License file at packager/legal/LICENSE.txt.
17 *
18 * GPL Classpath Exception:
19 * Oracle designates this particular file as subject to the "Classpath"
20 * exception as provided by Oracle in the GPL Version 2 section of the License
21 * file that accompanied this code.
22 *
23 * Modifications:
24 * If applicable, add the following below the License Header, with the fields
25 * enclosed by brackets [] replaced by your own identifying information:
26 * "Portions Copyright [year] [name of copyright owner]"
27 *
28 * Contributor(s):
29 * If you wish your version of this file to be governed by only the CDDL or
30 * only the GPL Version 2, indicate your decision by adding "[Contributor]
31 * elects to include this software in this distribution under the [CDDL or GPL
32 * Version 2] license." If you don't indicate a single choice of license, a
33 * recipient has the option to distribute your version of this file under
34 * either the CDDL, the GPL Version 2 or to extend the choice of license to
35 * its licensees as provided above. However, if you add GPL Version 2 code
36 * and therefore, elected the GPL Version 2 license, then the option applies
37 * only if the new code is made subject to such option by the copyright
38 * holder.
39 */
40
41package org.glassfish.json;
42
43
44import javax.json.stream.JsonLocation;
45import javax.json.stream.JsonParser;
46import java.text.MessageFormat;
47import java.util.ResourceBundle;
48
49/**
50 * Defines string formatting method for each constant in the resource file
51 *
52 * @author Jitendra Kotamraju
53 */
54final class JsonMessages {
55 private static final ResourceBundle BUNDLE =
56 ResourceBundle.getBundle("org.glassfish.json.messages");
57
58 // tokenizer messages
59 static String TOKENIZER_UNEXPECTED_CHAR(int unexpected, JsonLocation location) {
60 return localize("tokenizer.unexpected.char", unexpected, location);
61 }
62
63 static String TOKENIZER_EXPECTED_CHAR(int unexpected, JsonLocation location, char expected) {
64 return localize("tokenizer.expected.char", unexpected, location, expected);
65 }
66
67 static String TOKENIZER_IO_ERR() {
68 return localize("tokenizer.io.err");
69 }
70
71
72 // parser messages
73 static String PARSER_GETSTRING_ERR(JsonParser.Event event) {
74 return localize("parser.getString.err", event);
75 }
76
77 static String PARSER_ISINTEGRALNUMBER_ERR(JsonParser.Event event) {
78 return localize("parser.isIntegralNumber.err", event);
79 }
80
81 static String PARSER_GETINT_ERR(JsonParser.Event event) {
82 return localize("parser.getInt.err", event);
83 }
84
85 static String PARSER_GETLONG_ERR(JsonParser.Event event) {
86 return localize("parser.getLong.err", event);
87 }
88
89 static String PARSER_GETBIGDECIMAL_ERR(JsonParser.Event event) {
90 return localize("parser.getBigDecimal.err", event);
91 }
92
93 static String PARSER_EXPECTED_EOF(JsonTokenizer.JsonToken token) {
94 return localize("parser.expected.eof", token);
95 }
96
97 static String PARSER_TOKENIZER_CLOSE_IO() {
98 return localize("parser.tokenizer.close.io");
99 }
100
101 static String PARSER_INVALID_TOKEN(JsonTokenizer.JsonToken token, JsonLocation location, String expectedTokens) {
102 return localize("parser.invalid.token", token, location, expectedTokens);
103 }
104
105
106 // generator messages
107 static String GENERATOR_FLUSH_IO_ERR() {
108 return localize("generator.flush.io.err");
109 }
110
111 static String GENERATOR_CLOSE_IO_ERR() {
112 return localize("generator.close.io.err");
113 }
114
115 static String GENERATOR_WRITE_IO_ERR() {
116 return localize("generator.write.io.err");
117 }
118
119 static String GENERATOR_ILLEGAL_METHOD(Object scope) {
120 return localize("generator.illegal.method", scope);
121 }
122
123 static String GENERATOR_DOUBLE_INFINITE_NAN() {
124 return localize("generator.double.infinite.nan");
125 }
126
127 static String GENERATOR_INCOMPLETE_JSON() {
128 return localize("generator.incomplete.json");
129 }
130
131 static String GENERATOR_ILLEGAL_MULTIPLE_TEXT() {
132 return localize("generator.illegal.multiple.text");
133 }
134
135
136
137 // writer messages
138 static String WRITER_WRITE_ALREADY_CALLED() {
139 return localize("writer.write.already.called");
140 }
141
142
143 // reader messages
144 static String READER_READ_ALREADY_CALLED() {
145 return localize("reader.read.already.called");
146 }
147
148 static String READER_EXPECTED_ARRAY_GOT_OBJECT() {
149 return localize("reader.expected.array.got.object");
150 }
151
152 static String READER_EXPECTED_OBJECT_GOT_ARRAY() {
153 return localize("reader.expected.object.got.array");
154 }
155
156
157 // obj builder messages
158 static String OBJBUILDER_NAME_NULL() {
159 return localize("objbuilder.name.null");
160 }
161
162 static String OBJBUILDER_VALUE_NULL() {
163 return localize("objbuilder.value.null");
164 }
165
166 static String OBJBUILDER_OBJECT_BUILDER_NULL() {
167 return localize("objbuilder.object.builder.null");
168 }
169
170 static String OBJBUILDER_ARRAY_BUILDER_NULL() {
171 return localize("objbuilder.array.builder.null");
172 }
173
174
175 // array builder messages
176 static String ARRBUILDER_VALUE_NULL() {
177 return localize("arrbuilder.value.null");
178 }
179
180 static String ARRBUILDER_OBJECT_BUILDER_NULL() {
181 return localize("arrbuilder.object.builder.null");
182 }
183
184 static String ARRBUILDER_ARRAY_BUILDER_NULL() {
185 return localize("arrbuilder.array.builder.null");
186 }
187
188
189 private static String localize(String key, Object ... args) {
190 try {
191 String msg = BUNDLE.getString(key);
192 return MessageFormat.format(msg, args);
193 } catch (Exception e) {
194 return getDefaultMessage(key, args);
195 }
196 }
197
198 private static String getDefaultMessage(String key, Object ... args) {
199 StringBuilder sb = new StringBuilder();
200 sb.append("[failed to localize] ");
201 sb.append(key);
202 if (args != null) {
203 sb.append('(');
204 for (int i = 0; i < args.length; ++i) {
205 if (i != 0)
206 sb.append(", ");
207 sb.append(String.valueOf(args[i]));
208 }
209 sb.append(')');
210 }
211 return sb.toString();
212 }
213
214}
Note: See TracBrowser for help on using the repository browser.