public static DocType parse(final String input, final JDOMFactory factory) 
			throws JDOMException {
		
		// Match the input to the DOCTYPE pattern matcher.
		final Matcher mat = pattern.matcher(input);
		if (!mat.matches()) {
			throw new JDOMException("Doctype input does not appear to be valid: " + input);
		}
		
		// Get the four data components.
		final String docemt = mat.group(1);
		final String sysid = getGroup(mat, 7, 9, 19, 21);
		final String pubid = getGroup(mat, 13, 15);
		final String internal = getGroup(mat, 23);
		
		// Use the appropriate constructor for the DocType.
		DocType dt = null;
		if (pubid != null) {
			dt = factory.docType(docemt, pubid, sysid);
		} else if (sysid != null) {
			dt = factory.docType(docemt, sysid);
		} else {
			dt = factory.docType(docemt);
		}
		// Set the internal subset, if any.
		if (internal != null) {
			dt.setInternalSubset(formatInternal(internal));
		}
		return dt;
	}