All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.archive.format.text.html.CDATALexer Maven / Gradle / Ivy

There is a newer version: 1.1.9
Show newest version
package org.archive.format.text.html;

import org.htmlparser.Node;
import org.htmlparser.lexer.Lexer;
import org.htmlparser.util.ParserException;

public class CDATALexer extends Lexer {
	private static final long serialVersionUID = -8513653556979405106L;
	private Node cached;
	private boolean inCSS;
	private boolean inJS;
	private boolean cachedJS = false;

	@Override
	public Node nextNode() throws ParserException {
		inJS = false;
		inCSS = false;
		if(cached != null) {
			Node tmp = cached;
			cached = null;
			inJS = cachedJS;
			inCSS = !cachedJS;
			return tmp;
		}
		Node got = super.nextNode();
		if(NodeUtils.isNonEmptyOpenTagNodeNamed(got, "SCRIPT")) {
			cached = super.parseCDATA(true);
			cachedJS = true;
		} else if (NodeUtils.isNonEmptyOpenTagNodeNamed(got, "STYLE")) {
			cached = super.parseCDATA(true);
			cachedJS = false;
		}
		return got;
	}
	public boolean inJS() {
		return inJS;
	}
	public boolean inCSS() {
		return inCSS;
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy