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.html;
014
015import org.apache.juneau.*;
016import org.apache.juneau.parser.*;
017import org.apache.juneau.xml.*;
018
019/**
020 * Parses text generated by the {@link HtmlSerializer} class back into a POJO model.
021 *
022 * <h5 class='topic'>Media types</h5>
023 *
024 * Handles <code>Content-Type</code> types:  <code><b>text/html</b></code>
025 *
026 * <h5 class='topic'>Description</h5>
027 *
028 * See the {@link HtmlSerializer} class for a description of the HTML generated.
029 * <p>
030 * This class is used primarily for automated testing of the {@link HtmlSerializer} class.
031 */
032public class HtmlParser extends XmlParser {
033
034   //-------------------------------------------------------------------------------------------------------------------
035   // Predefined instances
036   //-------------------------------------------------------------------------------------------------------------------
037
038   /** Default parser, all default settings.*/
039   public static final HtmlParser DEFAULT = new HtmlParser(PropertyStore.DEFAULT);
040
041
042   //-------------------------------------------------------------------------------------------------------------------
043   // Instance
044   //-------------------------------------------------------------------------------------------------------------------
045
046   /**
047    * Constructor.
048    *
049    * @param ps The property store containing all the settings for this object.
050    */
051   public HtmlParser(PropertyStore ps) {
052      super(ps, "text/html", "text/html+stripped");
053   }
054
055   @Override /* Context */
056   public HtmlParserBuilder builder() {
057      return new HtmlParserBuilder(getPropertyStore());
058   }
059
060   /**
061    * Instantiates a new clean-slate {@link HtmlParserBuilder} object.
062    *
063    * <p>
064    * This is equivalent to simply calling <code><jk>new</jk> HtmlParserBuilder()</code>.
065    *
066    * <p>
067    * Note that this method creates a builder initialized to all default settings, whereas {@link #builder()} copies
068    * the settings of the object called on.
069    *
070    * @return A new {@link HtmlParserBuilder} object.
071    */
072   public static HtmlParserBuilder create() {
073      return new HtmlParserBuilder();
074   }
075
076   @Override /* Parser */
077   public HtmlParserSession createSession(ParserSessionArgs args) {
078      return new HtmlParserSession(this, args);
079   }
080
081   @Override /* Context */
082   public ObjectMap asMap() {
083      return super.asMap()
084         .append("HtmlParser", new ObjectMap());
085   }
086}