Skip to content

Commit

Permalink
vaadin#2730: configures JSoup to keep case of tags
Browse files Browse the repository at this point in the history
  • Loading branch information
paulroemer committed Oct 20, 2017
1 parent 97f6baf commit 05ebee5
Showing 1 changed file with 16 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
import org.jsoup.nodes.Element;
import org.jsoup.nodes.Node;
import org.jsoup.nodes.TextNode;
import org.jsoup.parser.ParseSettings;
import org.jsoup.parser.Parser;
import org.jsoup.select.Elements;
import org.jsoup.select.NodeTraversor;
import org.jsoup.select.NodeVisitor;
Expand Down Expand Up @@ -71,6 +73,14 @@ private TemplateParser() {
// Only static methods
}

private String convertStreamToString(java.io.InputStream is) {
try(java.util.Scanner s = new java.util.Scanner(is, "UTF-8")) {
return s.useDelimiter("\\A").hasNext() ? s.next() : "";
} catch (Exception e) {
throw new TemplateParseException("Error reading template data", e);
}
}

/**
* Parses the template from the given input stream to a tree of template
* nodes.
Expand All @@ -84,14 +94,14 @@ private TemplateParser() {
*/
public static TemplateNode parse(InputStream templateStream,
TemplateResolver templateResolver) {

assert templateStream != null;
try {
Document document = Jsoup.parse(templateStream, null, "");
String templateString = convertStreamToString(templateStream);
Parser parser = Parser.htmlParser();
parser.settings(new ParseSettings(true, true)); // tag, attribute preserve case
Document document = parser.parseInput(templateString, "");

return parse(document, templateResolver);
} catch (IOException e) {
throw new TemplateParseException("Error reading template data", e);
}
return parse(document, templateResolver);
}

/**
Expand Down

0 comments on commit 05ebee5

Please sign in to comment.