Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions src/nu/validator/htmlparser/common/TokenHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,22 @@ public void startTag(ElementName eltName, HtmlAttributes attributes,
*/
public void comment(@NoLength char[] buf, int start, int length) throws SAXException;

/**
* Receive a processing instruction token.
*
* @param target
* the target of the processing instruction
* @param buf
* a buffer holding the data
* @param start the offset into the buffer
* @param length
* the number of code units to read
* @throws SAXException
* if something went wrong
*/
public void processingInstruction(String target, @NoLength char[] buf,
int start, int length) throws SAXException;

/**
* Receive character tokens. This method has the same semantics as the SAX
* method of the same name.
Expand Down
30 changes: 30 additions & 0 deletions src/nu/validator/htmlparser/dom/DOMTreeBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,36 @@ protected DOMTreeBuilder(DOMImplementation implementation) {
}
}

/**
*
* @see nu.validator.htmlparser.impl.CoalescingTreeBuilder#appendProcessingInstruction(java.lang.Object,
* java.lang.String, java.lang.String)
*/
@Override protected void appendProcessingInstruction(Element parent,
String target, String data) throws SAXException {
try {
parent.appendChild(
document.createProcessingInstruction(target, data));
} catch (DOMException e) {
fatal(e);
}
}

/**
*
* @see nu.validator.htmlparser.impl.CoalescingTreeBuilder#appendProcessingInstructionToDocument(java.lang.String,
* java.lang.String)
*/
@Override protected void appendProcessingInstructionToDocument(
String target, String data) throws SAXException {
try {
document.appendChild(
document.createProcessingInstruction(target, data));
} catch (DOMException e) {
fatal(e);
}
}

/**
*
* @see nu.validator.htmlparser.impl.TreeBuilder#createElement(String, String, nu.validator.htmlparser.impl.HtmlAttributes, Object)
Expand Down
26 changes: 26 additions & 0 deletions src/nu/validator/htmlparser/impl/CoalescingTreeBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,32 @@ protected final void accumulateCharacters(@NoLength char[] buf, int start,

protected abstract void appendCommentToDocument(String comment) throws SAXException;

/**
* @see nu.validator.htmlparser.impl.TreeBuilder#appendProcessingInstruction(java.lang.Object, java.lang.String, char[], int, int)
*/
@Override final protected void appendProcessingInstruction(T parent,
String target, char[] buf, int start, int length)
throws SAXException {
appendProcessingInstruction(parent, target,
new String(buf, start, length));
}

protected abstract void appendProcessingInstruction(T parent,
String target, String data) throws SAXException;

/**
* @see nu.validator.htmlparser.impl.TreeBuilder#appendProcessingInstructionToDocument(java.lang.String, char[], int, int)
*/
@Override protected final void appendProcessingInstructionToDocument(
String target, char[] buf, int start, int length)
throws SAXException {
appendProcessingInstructionToDocument(target,
new String(buf, start, length));
}

protected abstract void appendProcessingInstructionToDocument(
String target, String data) throws SAXException;

/**
* @see nu.validator.htmlparser.impl.TreeBuilder#insertFosterParentedCharacters(char[], int, int, java.lang.Object, java.lang.Object)
*/
Expand Down
19 changes: 19 additions & 0 deletions src/nu/validator/htmlparser/impl/ErrorReportingTokenizer.java
Original file line number Diff line number Diff line change
Expand Up @@ -492,6 +492,25 @@ private boolean isAstralPrivateUse(int c) {
err("Saw \u201C<?\u201D. Probable cause: Attempt to use an XML processing instruction in HTML. (XML processing instructions are not supported in HTML.)");
}

@Override protected void errEofInProcessingInstruction() throws SAXException {
err("End of file inside processing instruction.");
}

@Override protected void errInvalidFirstCharacterOfProcessingInstructionTarget()
throws SAXException {
err("Invalid first character of processing instruction target. Treating the processing instruction as a comment.");
}

@Override protected void errInvalidProcessingInstructionTarget()
throws SAXException {
err("Invalid character in processing instruction target. Treating the processing instruction as a comment.");
}

@Override protected void errDisallowedProcessingInstructionTarget()
throws SAXException {
err("Processing instruction targets \u201Cxml\u201D and \u201Cxml-stylesheet\u201D are not allowed. Treating the processing instruction as a comment.");
}

@Override protected void errUnescapedAmpersandInterpretedAsCharacterReference()
throws SAXException {
if (errorHandler == null) {
Expand Down
Loading