use of org.eclipse.wst.sse.core.internal.ltk.modelhandler.EmbeddedTypeHandler in project webtools.sourceediting by eclipse.
the class JSPModelLoader method initEmbeddedTypePre.
protected void initEmbeddedTypePre(IStructuredModel model, IStructuredDocument structuredDocument) {
// note: this will currently only work for models backed by files
EmbeddedTypeHandler embeddedContentType = null;
IDOMModel domModel = (IDOMModel) model;
if (embeddedContentType == null) {
IContentDescription desc = getContentDescription(structuredDocument);
if (desc != null) {
Object prop = null;
prop = desc.getProperty(IContentDescriptionForJSP.CONTENT_FAMILY_ATTRIBUTE);
if (prop != null) {
if (ContentTypeFamilyForHTML.HTML_FAMILY.equals(prop)) {
embeddedContentType = EmbeddedTypeRegistryImpl.getInstance().getTypeFor("text/html");
}
}
if (embeddedContentType == null) {
prop = desc.getProperty(IContentDescriptionForJSP.CONTENT_TYPE_ATTRIBUTE);
if (prop != null) {
embeddedContentType = EmbeddedTypeRegistryImpl.getInstance().getTypeFor((String) prop);
}
}
}
}
IDOMDocument document = domModel.getDocument();
PageDirectiveAdapter pageDirectiveAdapter = (PageDirectiveAdapter) document.getAdapterFor(PageDirectiveAdapter.class);
if (embeddedContentType != null) {
pageDirectiveAdapter.setEmbeddedType(embeddedContentType);
embeddedContentType.initializeFactoryRegistry(model.getFactoryRegistry());
} else {
// use default embeddedType if it couldn't determine one
embeddedContentType = getJSPDefaultEmbeddedType(model);
pageDirectiveAdapter.setEmbeddedType(embeddedContentType);
embeddedContentType.initializeFactoryRegistry(model.getFactoryRegistry());
}
}
use of org.eclipse.wst.sse.core.internal.ltk.modelhandler.EmbeddedTypeHandler in project webtools.sourceediting by eclipse.
the class JSPModelLoader method getEmbeddedType.
private EmbeddedTypeHandler getEmbeddedType(IStructuredModel model) {
Document doc = ((IDOMModel) model).getDocument();
PageDirectiveAdapter pageDirectiveAdapter = (PageDirectiveAdapter) ((INodeNotifier) doc).getAdapterFor(PageDirectiveAdapter.class);
EmbeddedTypeHandler embeddedHandler = pageDirectiveAdapter.getEmbeddedType();
return embeddedHandler;
}
use of org.eclipse.wst.sse.core.internal.ltk.modelhandler.EmbeddedTypeHandler in project webtools.sourceediting by eclipse.
the class TestModelHandlers method testDirtyStateForMisspelledEmbeddedCharset.
public void testDirtyStateForMisspelledEmbeddedCharset() throws Exception {
String projectName = "TestModelHandlers." + getName();
IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName);
if (!project.isAccessible()) {
project = BundleResourceUtil.createSimpleProject(projectName, null, null);
}
IFile testFile = project.getFile("charaset.jsp");
String contents = "<%@ page language=\"java\" contentType=\"text/xml; charaset=UTF-8\" pageEncoding=\"UTF-8\"%>\n" + "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + "<Contents>\n" + "<Error state=\"fatal\" code=\"\">\n" + "</Error>\n" + "</Contents>";
if (!testFile.exists()) {
testFile.create(new ByteArrayInputStream(contents.getBytes("utf8")), IResource.FORCE, null);
} else {
testFile.setContents(new ByteArrayInputStream(contents.getBytes("utf8")), IResource.FORCE, null);
}
IStructuredModel model = null;
try {
model = StructuredModelManager.getModelManager().getModelForRead(testFile);
Document doc = ((IDOMModel) model).getDocument();
PageDirectiveAdapter pageDirectiveAdapter = (PageDirectiveAdapter) ((INodeNotifier) doc).getAdapterFor(PageDirectiveAdapter.class);
EmbeddedTypeHandler embeddedHandler = pageDirectiveAdapter.getEmbeddedType();
assertFalse("newly opened model was dirty, embedded handler changed? current family:" + embeddedHandler.getFamilyId(), model.isDirty());
} finally {
if (model != null)
model.releaseFromRead();
}
project.delete(true, null);
}
use of org.eclipse.wst.sse.core.internal.ltk.modelhandler.EmbeddedTypeHandler in project webtools.sourceediting by eclipse.
the class JSPDocumentLoader method getEmbeddedType.
/**
* Determine the MIME content type specified in a page directive. This
* should appear "as early as possible in the JSP page" according to the
* JSP v1.2 specification.
*/
private EmbeddedTypeHandler getEmbeddedType(IFile file) throws UnsupportedEncodingException, CoreException, IOException {
EmbeddedTypeHandler handler = null;
if (fFullPreparedReader == null) {
handler = getJSPDefaultEmbeddedType();
} else {
String mimeType = null;
IDocumentCharsetDetector jspProvider = getDocumentEncodingDetector();
Reader fullPreparedReader = getFullPreparedReader();
BufferedLimitedReader limitedReader = new BufferedLimitedReader(fullPreparedReader, CodedIO.MAX_BUF_SIZE);
jspProvider.set(limitedReader);
if (jspProvider instanceof IJSPHeadContentDetector) {
mimeType = ((IJSPHeadContentDetector) jspProvider).getContentType();
fullPreparedReader.reset();
}
EmbeddedTypeRegistry reg = getEmbeddedContentTypeRegistry();
if (mimeType == null || mimeType.length() == 0) {
handler = getJSPDefaultEmbeddedType();
} else {
handler = reg.getTypeFor(mimeType);
}
}
return handler;
}
Aggregations