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.annotation.*; 017import org.apache.juneau.parser.*; 018import org.apache.juneau.xml.*; 019 020/** 021 * Parses text generated by the {@link HtmlSerializer} class back into a POJO model. 022 * 023 * <h5 class='topic'>Media types</h5> 024 * 025 * Handles <c>Content-Type</c> types: <bc>text/html</bc> 026 * 027 * <h5 class='topic'>Description</h5> 028 * 029 * See the {@link HtmlSerializer} class for a description of the HTML generated. 030 * <p> 031 * This class is used primarily for automated testing of the {@link HtmlSerializer} class. 032 */ 033@ConfigurableContext 034public class HtmlParser extends XmlParser { 035 036 //------------------------------------------------------------------------------------------------------------------- 037 // Configurable properties 038 //------------------------------------------------------------------------------------------------------------------- 039 040 static final String PREFIX = "HtmlParser"; 041 042 //------------------------------------------------------------------------------------------------------------------- 043 // Predefined instances 044 //------------------------------------------------------------------------------------------------------------------- 045 046 /** Default parser, all default settings.*/ 047 public static final HtmlParser DEFAULT = new HtmlParser(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 HtmlParser(PropertyStore ps) { 060 super(ps, "text/html", "text/html+stripped"); 061 } 062 063 @Override /* Context */ 064 public HtmlParserBuilder builder() { 065 return new HtmlParserBuilder(getPropertyStore()); 066 } 067 068 /** 069 * Instantiates a new clean-slate {@link HtmlParserBuilder} object. 070 * 071 * <p> 072 * This is equivalent to simply calling <code><jk>new</jk> HtmlParserBuilder()</code>. 073 * 074 * <p> 075 * Note that this method creates a builder initialized to all default settings, whereas {@link #builder()} copies 076 * the settings of the object called on. 077 * 078 * @return A new {@link HtmlParserBuilder} object. 079 */ 080 public static HtmlParserBuilder create() { 081 return new HtmlParserBuilder(); 082 } 083 084 @Override /* Parser */ 085 public HtmlParserSession createSession() { 086 return createSession(createDefaultSessionArgs()); 087 } 088 089 @Override /* Parser */ 090 public HtmlParserSession createSession(ParserSessionArgs args) { 091 return new HtmlParserSession(this, args); 092 } 093 094 //----------------------------------------------------------------------------------------------------------------- 095 // Other methods 096 //----------------------------------------------------------------------------------------------------------------- 097 098 @Override /* Context */ 099 public ObjectMap toMap() { 100 return super.toMap() 101 .append("HtmlParser", new DefaultFilteringObjectMap()); 102 } 103}