001// ***************************************************************************************************************************
002// * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements.  See the NOTICE file *
003// * distributed with this work for additional information regarding copyright ownership.  The ASF licenses this file        *
004// * to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance            *
005// * with the License.  You may obtain a copy of the License at                                                              *
006// *                                                                                                                         *
007// *  http://www.apache.org/licenses/LICENSE-2.0                                                                             *
008// *                                                                                                                         *
009// * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an  *
010// * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the License for the        *
011// * specific language governing permissions and limitations under the License.                                              *
012// ***************************************************************************************************************************
013package org.apache.juneau.plaintext;
014
015import org.apache.juneau.*;
016import org.apache.juneau.parser.*;
017import org.apache.juneau.transform.*;
018
019/**
020 * Parsers HTTP plain text request bodies into Group 5 POJOs.
021 * 
022 * <p>
023 * See <a class="doclink" href="../../../../overview-summary.html#juneau-marshall.PojoCategories">Group 5 POJOs</a>.
024 * 
025 * <h5 class='topic'>Media types</h5>
026 * 
027 * Handles <code>Accept</code> types:  <code><b>text/plain</b></code>
028 * <p>
029 * Produces <code>Content-Type</code> types:  <code><b>text/plain</b></code>
030 * 
031 * <h5 class='topic'>Description</h5>
032 * 
033 * Essentially just converts plain text to POJOs via static <code>fromString()</code> or <code>valueOf()</code>, or
034 * through constructors that take a single string argument.
035 * 
036 * <p>
037 * Also parses objects using a transform if the object class has an {@link PojoSwap PojoSwap&lt;?,String&gt;} transform
038 * defined on it.
039 */
040public class PlainTextParser extends ReaderParser {
041
042   //-------------------------------------------------------------------------------------------------------------------
043   // Predefined subclasses
044   //-------------------------------------------------------------------------------------------------------------------
045
046   /** Default parser, all default settings.*/
047   public static final PlainTextParser DEFAULT = new PlainTextParser(PropertyStore.DEFAULT);
048
049
050   //-------------------------------------------------------------------------------------------------------------------
051   // Instance
052   //-------------------------------------------------------------------------------------------------------------------
053
054   /**
055    * Constructor.
056    * 
057    * @param ps The property store containing all the settings for this object.
058    */
059   public PlainTextParser(PropertyStore ps) {
060      this(ps, "text/plain");
061   }
062
063   /**
064    * Constructor.
065    * 
066    * @param ps The property store containing all the settings for this object.
067    * @param consumes The media types that this parser consumes.
068    *    <p>
069    *    Can contain meta-characters per the <code>media-type</code> specification of
070    *    <a class="doclink" href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.1">RFC2616/14.1</a>
071    */
072   public PlainTextParser(PropertyStore ps, String...consumes) {
073      super(ps, consumes);
074   }
075
076   @Override /* Context */
077   public PlainTextParserBuilder builder() {
078      return new PlainTextParserBuilder(getPropertyStore());
079   }
080
081   /**
082    * Instantiates a new clean-slate {@link PlainTextParserBuilder} object.
083    * 
084    * <p>
085    * This is equivalent to simply calling <code><jk>new</jk> PlainTextParserBuilder()</code>.
086    * 
087    * <p>
088    * Note that this method creates a builder initialized to all default settings, whereas {@link #builder()} copies 
089    * the settings of the object called on.
090    * 
091    * @return A new {@link PlainTextParserBuilder} object.
092    */
093   public static PlainTextParserBuilder create() {
094      return new PlainTextParserBuilder();
095   }
096
097   @Override /* Parser */
098   public ReaderParserSession createSession(ParserSessionArgs args) {
099      return new PlainTextParserSession(this, args);
100   }
101}