use of org.eclipse.jst.jsp.core.internal.encoding.JSPDocumentHeadContentDetector in project webtools.sourceediting by eclipse.
the class StructuredTextPartitionerForJSP method createStructuredTextPartitioner.
private IStructuredTextPartitioner createStructuredTextPartitioner(IStructuredDocument structuredDocument) {
IStructuredTextPartitioner result = null;
// this same detector should underly content describer, to have consistent results
JSPDocumentHeadContentDetector jspHeadContentDetector = new JSPDocumentHeadContentDetector();
jspHeadContentDetector.set(structuredDocument);
String contentType = null;
try {
contentType = jspHeadContentDetector.getContentType();
// if XHTML or WML, that trumps what is in the page directive
if (jspHeadContentDetector.isXHTML() || jspHeadContentDetector.isWML()) {
contentType = "text/html";
}
} catch (IOException e) {
// impossible in this context, since working with document stream
throw new Error(e);
}
// null or empty, treat as "default"
if (contentType == null || contentType.length() == 0) {
// $NON-NLS-1$
contentType = "text/html";
}
// make or tie-in to existing registry.
if (contentType.equalsIgnoreCase(HTML_MIME_TYPE) || contentType.equalsIgnoreCase(VND_WAP_WML)) {
result = new StructuredTextPartitionerForHTML();
result.connect(structuredDocument);
} else if (contentType.equalsIgnoreCase(XHTML_MIME_TYPE)) {
result = new StructuredTextPartitionerForHTML();
result.connect(structuredDocument);
} else if (contentType.equalsIgnoreCase(XML_MIME_TYPE) || contentType.endsWith("+xml")) {
// $NON-NLS-1$
result = new StructuredTextPartitionerForXML();
result.connect(structuredDocument);
} else {
result = new StructuredTextPartitioner();
result.connect(structuredDocument);
}
return result;
}
Aggregations