001package org.jsoup.parser; 002 003import org.jsoup.nodes.Attributes; 004 005import static org.jsoup.internal.Normalizer.lowerCase; 006 007/** 008 * Controls parser settings, to optionally preserve tag and/or attribute name case. 009 */ 010public class ParseSettings { 011 /** 012 * HTML default settings: both tag and attribute names are lower-cased during parsing. 013 */ 014 public static final ParseSettings htmlDefault; 015 /** 016 * Preserve both tag and attribute case. 017 */ 018 public static final ParseSettings preserveCase; 019 020 static { 021 htmlDefault = new ParseSettings(false, false); 022 preserveCase = new ParseSettings(true, true); 023 } 024 025 private final boolean preserveTagCase; 026 private final boolean preserveAttributeCase; 027 028 /** 029 * Define parse settings. 030 * @param tag preserve tag case? 031 * @param attribute preserve attribute name case? 032 */ 033 public ParseSettings(boolean tag, boolean attribute) { 034 preserveTagCase = tag; 035 preserveAttributeCase = attribute; 036 } 037 038 String normalizeTag(String name) { 039 name = name.trim(); 040 if (!preserveTagCase) 041 name = lowerCase(name); 042 return name; 043 } 044 045 String normalizeAttribute(String name) { 046 name = name.trim(); 047 if (!preserveAttributeCase) 048 name = lowerCase(name); 049 return name; 050 } 051 052 Attributes normalizeAttributes(Attributes attributes) { 053 if (!preserveAttributeCase) { 054 attributes.normalize(); 055 } 056 return attributes; 057 } 058}