001/*
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements.  See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License.  You may obtain a copy of the License at
008 *
009 *      http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017package org.apache.juneau.parser.annotation;
018
019import static java.lang.annotation.ElementType.*;
020import static java.lang.annotation.RetentionPolicy.*;
021
022import java.lang.annotation.*;
023import java.nio.charset.*;
024
025import org.apache.juneau.*;
026import org.apache.juneau.annotation.*;
027import org.apache.juneau.html.*;
028import org.apache.juneau.json.*;
029import org.apache.juneau.msgpack.*;
030import org.apache.juneau.parser.*;
031import org.apache.juneau.uon.*;
032import org.apache.juneau.xml.*;
033
034/**
035 * Annotation for specifying config properties defined in {@link Parser}, {@link InputStreamParser}, and {@link ReaderParser}.
036 *
037 * <p>
038 * Used primarily for specifying bean configuration properties on REST classes and methods.
039 *
040 * <h5 class='section'>See Also:</h5><ul>
041 *    <li class='link'><a class="doclink" href="https://juneau.apache.org/docs/topics/SerializersAndParsers">Serializers and Parsers</a>
042 * </ul>
043 */
044@Target({ TYPE, METHOD })
045@Retention(RUNTIME)
046@Inherited
047@ContextApply({ ParserConfigAnnotation.ParserApply.class, ParserConfigAnnotation.InputStreamParserApply.class, ParserConfigAnnotation.ReaderParserApply.class })
048public @interface ParserConfig {
049
050   /**
051    * Auto-close streams.
052    *
053    * <p>
054    * If <js>"true"</js>, <l>InputStreams</l> and <l>Readers</l> passed into parsers will be closed
055    * after parsing is complete.
056    *
057    * <ul class='values'>
058    *    <li><js>"true"</js>
059    *    <li><js>"false"</js> (default)
060    * </ul>
061    *
062    * <h5 class='section'>Notes:</h5><ul>
063    *    <li class='note'>
064    *       Supports <a class="doclink" href="https://juneau.apache.org/docs/topics/DefaultVarResolver">VarResolver.DEFAULT</a> (e.g. <js>"$C{myConfigVar}"</js>).
065    * </ul>
066    *
067    * <h5 class='section'>See Also:</h5><ul>
068    *    <li class='jm'>{@link org.apache.juneau.parser.Parser.Builder#autoCloseStreams()}
069    * </ul>
070    *
071    * @return The annotation value.
072    */
073   String autoCloseStreams() default "";
074
075   /**
076    * Binary input format.
077    *
078    * <p>
079    * When using the {@link Parser#parse(Object,Class)} method on stream-based parsers and the input is a string, this defines the format to use
080    * when converting the string into a byte array.
081    *
082    * <ul class='values'>
083    *    <li><js>"SPACED_HEX"</js>
084    *    <li><js>"HEX"</js> (default)
085    *    <li><js>"BASE64"</js>
086    * </ul>
087    *
088    * <h5 class='section'>Notes:</h5><ul>
089    *    <li class='note'>
090    *       Supports <a class="doclink" href="https://juneau.apache.org/docs/topics/DefaultVarResolver">VarResolver.DEFAULT</a> (e.g. <js>"$C{myConfigVar}"</js>).
091    * </ul>
092    *
093    * <h5 class='section'>See Also:</h5><ul>
094    *    <li class='jm'>{@link org.apache.juneau.parser.InputStreamParser.Builder#binaryFormat(BinaryFormat)}
095    * </ul>
096    *
097    * @return The annotation value.
098    */
099   String binaryFormat() default "";
100
101   /**
102    * Debug output lines.
103    *
104    * <p>
105    * When parse errors occur, this specifies the number of lines of input before and after the
106    * error location to be printed as part of the exception message.
107    *
108    * <h5 class='section'>Notes:</h5><ul>
109    *    <li class='note'>
110    *       Format: integer
111    *    <li class='note'>
112    *       Default: 5
113    *    <li class='note'>
114    *       Supports <a class="doclink" href="https://juneau.apache.org/docs/topics/DefaultVarResolver">VarResolver.DEFAULT</a> (e.g. <js>"$C{myConfigVar}"</js>).
115    * </ul>
116    *
117    * <h5 class='section'>See Also:</h5><ul>
118    *    <li class='jm'>{@link org.apache.juneau.parser.Parser.Builder#debugOutputLines(int)}
119    * </ul>
120    *
121    * @return The annotation value.
122    */
123   String debugOutputLines() default "";
124
125   /**
126    * File charset.
127    *
128    * <p>
129    * The character set to use for reading <c>Files</c> from the file system.
130    *
131    * <p>
132    * Used when passing in files to {@link Parser#parse(Object, Class)}.
133    *
134    * <h5 class='section'>Notes:</h5><ul>
135    *    <li class='note'>
136    *       <js>"DEFAULT"</js> can be used to indicate the JVM default file system charset.
137    *    <li class='note'>
138    *       Supports <a class="doclink" href="https://juneau.apache.org/docs/topics/DefaultVarResolver">VarResolver.DEFAULT</a> (e.g. <js>"$C{myConfigVar}"</js>).
139    * </ul>
140    *
141    * <h5 class='section'>See Also:</h5><ul>
142    *    <li class='jm'>{@link org.apache.juneau.parser.ReaderParser.Builder#fileCharset(Charset)}
143    * </ul>
144    *
145    * @return The annotation value.
146    */
147   String fileCharset() default "";
148
149   /**
150    * Parser listener.
151    *
152    * <p>
153    * Class used to listen for errors and warnings that occur during parsing.
154    *
155    * <h5 class='section'>See Also:</h5><ul>
156    *    <li class='jm'>{@link org.apache.juneau.parser.Parser.Builder#listener(Class)}
157    * </ul>
158    *
159    * @return The annotation value.
160    */
161   Class<? extends ParserListener> listener() default ParserListener.Void.class;
162
163   /**
164    * Optional rank for this config.
165    *
166    * <p>
167    * Can be used to override default ordering and application of config annotations.
168    *
169    * @return The annotation value.
170    */
171   int rank() default 0;
172
173   /**
174    * Input stream charset.
175    *
176    * <p>
177    * The character set to use for converting <c>InputStreams</c> and byte arrays to readers.
178    *
179    * <p>
180    * Used when passing in input streams and byte arrays to {@link Parser#parse(Object, Class)}.
181    *
182    * <h5 class='section'>Notes:</h5><ul>
183    *    <li class='note'>
184    *       <js>"DEFAULT"</js> can be used to indicate the JVM default file system charset.
185    *    <li class='note'>
186    *       Supports <a class="doclink" href="https://juneau.apache.org/docs/topics/DefaultVarResolver">VarResolver.DEFAULT</a> (e.g. <js>"$C{myConfigVar}"</js>).
187    * </ul>
188    *
189    * <h5 class='section'>See Also:</h5><ul>
190    *    <li class='jm'>{@link org.apache.juneau.parser.ReaderParser.Builder#streamCharset(Charset)}
191    * </ul>
192    *
193    * @return The annotation value.
194    */
195   String streamCharset() default "";
196
197   /**
198    * Strict mode.
199    *
200    * <p>
201    * If <js>"true"</js>, strict mode for the parser is enabled.
202    *
203    * <p>
204    * Strict mode can mean different things for different parsers.
205    *
206    * <table class='styled'>
207    *    <tr><th>Parser class</th><th>Strict behavior</th></tr>
208    *    <tr>
209    *       <td>All reader-based parsers</td>
210    *       <td>
211    *          When enabled, throws {@link ParseException ParseExceptions} on malformed charset input.
212    *          Otherwise, malformed input is ignored.
213    *       </td>
214    *    </tr>
215    *    <tr>
216    *       <td>{@link JsonParser}</td>
217    *       <td>
218    *          When enabled, throws exceptions on the following invalid JSON syntax:
219    *          <ul>
220    *             <li>Unquoted attributes.
221    *             <li>Missing attribute values.
222    *             <li>Concatenated strings.
223    *             <li>Javascript comments.
224    *             <li>Numbers and booleans when Strings are expected.
225    *             <li>Numbers valid in Java but not JSON (e.g. octal notation, etc...)
226    *          </ul>
227    *       </td>
228    *    </tr>
229    * </table>
230    *
231    * <ul class='values'>
232    *    <li><js>"true"</js>
233    *    <li><js>"false"</js> (default)
234    * </ul>
235    *
236    * <h5 class='section'>Notes:</h5><ul>
237    *    <li class='note'>
238    *       Supports <a class="doclink" href="https://juneau.apache.org/docs/topics/DefaultVarResolver">VarResolver.DEFAULT</a> (e.g. <js>"$C{myConfigVar}"</js>).
239    * </ul>
240    *
241    * <h5 class='section'>See Also:</h5><ul>
242    *    <li class='jm'>{@link org.apache.juneau.parser.Parser.Builder#strict()}
243    * </ul>
244    *
245    * @return The annotation value.
246    */
247   String strict() default "";
248
249   /**
250    * Trim parsed strings.
251    *
252    * <p>
253    * If <js>"true"</js>, string values will be trimmed of whitespace using {@link String#trim()} before being added to
254    * the POJO.
255    *
256    * <ul class='values'>
257    *    <li><js>"true"</js>
258    *    <li><js>"false"</js> (default)
259    * </ul>
260    *
261    * <h5 class='section'>Notes:</h5><ul>
262    *    <li class='note'>
263    *       Supports <a class="doclink" href="https://juneau.apache.org/docs/topics/DefaultVarResolver">VarResolver.DEFAULT</a> (e.g. <js>"$C{myConfigVar}"</js>).
264    * </ul>
265    *
266    * <h5 class='section'>See Also:</h5><ul>
267    *    <li class='jm'>{@link org.apache.juneau.parser.Parser.Builder#trimStrings()}
268    * </ul>
269    *
270    * @return The annotation value.
271    */
272   String trimStrings() default "";
273
274   /**
275    * Unbuffered.
276    *
277    * <p>
278    * If <js>"true"</js>, don't use internal buffering during parsing.
279    *
280    * <p>
281    * This is useful in cases when you want to parse the same input stream or reader multiple times
282    * because it may contain multiple independent POJOs to parse.
283    * <br>Buffering would cause the parser to read past the current POJO in the stream.
284    *
285    * <ul class='values'>
286    *    <li><js>"true"</js>
287    *    <li><js>"false"</js> (default)
288    * </ul>
289    *
290    * <h5 class='section'>Notes:</h5><ul>
291    *    <li class='note'>
292    *       This only allows for multi-input streams for the following parsers:
293    *       <ul>
294    *          <li class='jc'>{@link JsonParser}
295    *          <li class='jc'>{@link UonParser}
296    *       </ul>
297    *       It has no effect on the following parsers:
298    *       <ul>
299    *          <li class='jc'>{@link MsgPackParser} - It already doesn't use buffering.
300    *          <li class='jc'>{@link XmlParser}, {@link HtmlParser} - These use StAX which doesn't allow for more than one root element anyway.
301    *          <li>RDF parsers - These read everything into an internal model before any parsing begins.
302    *       </ul>
303    *    <li class='note'>
304    *       Supports <a class="doclink" href="https://juneau.apache.org/docs/topics/DefaultVarResolver">VarResolver.DEFAULT</a> (e.g. <js>"$C{myConfigVar}"</js>).
305    * </ul>
306    *
307    * <h5 class='section'>See Also:</h5><ul>
308    *    <li class='jm'>{@link org.apache.juneau.parser.Parser.Builder#unbuffered()}
309    * </ul>
310    *
311    * @return The annotation value.
312    */
313   String unbuffered() default "";
314}