Document (DocType docType) { if (docType == null) { // Remove any existing doctype int docTypeIndex = content.indexOfDocType(); if (docTypeIndex >= 0) content.remove(docTypeIndex); return this; } if (docType.getParent() != null) { throw new IllegalAddException(docType, "The DocType already is attached to a document"); } // Add DocType to head if new, replace old otherwise int docTypeIndex = content.indexOfDocType(); if (docTypeIndex < 0) { content.add(0, docType); } else { content.set(docTypeIndex, docType); } return this; }