com.itextpdf.styledxmlparser.jsoup.parser.ParseSettings Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of styled-xml-parser Show documentation
Show all versions of styled-xml-parser Show documentation
Styled XML parser is used by iText modules to parse HTML and XML
/*
This file is part of the iText (R) project.
Copyright (c) 1998-2023 iText Group NV
Authors: iText Software.
This program is offered under a commercial and under the AGPL license.
For commercial licensing, contact us at https://itextpdf.com/sales. For AGPL licensing, see below.
AGPL licensing:
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see .
*/
package com.itextpdf.styledxmlparser.jsoup.parser;
import com.itextpdf.styledxmlparser.jsoup.internal.Normalizer;
import com.itextpdf.styledxmlparser.jsoup.nodes.Attributes;
/**
* Controls parser settings, to optionally preserve tag and/or attribute name case.
*/
public class ParseSettings {
/**
* HTML default settings: both tag and attribute names are lower-cased during parsing.
*/
public static final ParseSettings htmlDefault;
/**
* Preserve both tag and attribute case.
*/
public static final ParseSettings preserveCase;
static {
htmlDefault = new ParseSettings(false, false);
preserveCase = new ParseSettings(true, true);
}
private final boolean preserveTagCase;
private final boolean preserveAttributeCase;
/**
* Returns true if preserving tag name case.
*/
public boolean preserveTagCase() {
return preserveTagCase;
}
/**
* Returns true if preserving attribute case.
*/
public boolean preserveAttributeCase() {
return preserveAttributeCase;
}
/**
* Define parse settings.
* @param tag preserve tag case?
* @param attribute preserve attribute name case?
*/
public ParseSettings(boolean tag, boolean attribute) {
preserveTagCase = tag;
preserveAttributeCase = attribute;
}
ParseSettings(ParseSettings copy) {
this(copy.preserveTagCase, copy.preserveAttributeCase);
}
/**
* Normalizes a tag name according to the case preservation setting.
*/
public String normalizeTag(String name) {
name = name.trim();
if (!preserveTagCase)
name = Normalizer.lowerCase(name);
return name;
}
/**
* Normalizes an attribute according to the case preservation setting.
*/
public String normalizeAttribute(String name) {
name = name.trim();
if (!preserveAttributeCase)
name = Normalizer.lowerCase(name);
return name;
}
Attributes normalizeAttributes(Attributes attributes) {
if (attributes != null && !preserveAttributeCase) {
attributes.normalize();
}
return attributes;
}
}