use of org.eclipse.wst.sse.core.internal.ltk.modelhandler.EmbeddedTypeHandler in project webtools.sourceediting by eclipse.
the class JSPModelLoader method newStructuredDocument.
/**
* This method must return a new instance of IStructuredDocument, that has
* been initialized with appropriate parser. For many loaders, the
* (default) parser used is known for any input. For others, the correct
* parser (and its initialization) is normall dependent on the content of
* the file. This no-argument method should assume "empty input" and would
* therefore return the default parser for the default contentType.
*
* If the parser is to handle tag libraries, it must have a TaglibSupport
* object with a valid URIResolver and this IStructuredDocument attached
* to it before the contents are set on the IStructuredDocument.
*/
public IStructuredDocument newStructuredDocument() {
IStructuredDocument structuredDocument = StructuredDocumentFactory.getNewStructuredDocumentInstance(getParser());
((BasicStructuredDocument) structuredDocument).setReParser(new JSPReParser());
// structuredDocument.setDocumentPartitioner(new
// JSPJavaDocumentPartioner());
// even though this is an "empty model" ... we want it to have at
// least the
// default embeddeded content type handler
EmbeddedTypeHandler embeddedType = getJSPDefaultEmbeddedType(null);
embeddedType.initializeParser(structuredDocument.getParser());
return structuredDocument;
}
use of org.eclipse.wst.sse.core.internal.ltk.modelhandler.EmbeddedTypeHandler in project webtools.sourceediting by eclipse.
the class TestModelClone method getEmbeddedType.
private EmbeddedTypeHandler getEmbeddedType(IStructuredModel model) {
Document doc = ((IDOMModel) model).getDocument();
PageDirectiveAdapter pageDirectiveAdapter = (PageDirectiveAdapter) ((INodeNotifier) doc).getExistingAdapter(PageDirectiveAdapter.class);
assertNotNull("model did not have embedded adapter", pageDirectiveAdapter);
EmbeddedTypeHandler embeddedHandler = pageDirectiveAdapter.getEmbeddedType();
assertNotNull("model did not have embedded handler", embeddedHandler);
return embeddedHandler;
}
use of org.eclipse.wst.sse.core.internal.ltk.modelhandler.EmbeddedTypeHandler in project webtools.sourceediting by eclipse.
the class TestModelClone method checkEmbeddedType.
private void checkEmbeddedType(IStructuredModel model, Class expectedType) {
Document doc = ((IDOMModel) model).getDocument();
PageDirectiveAdapter pageDirectiveAdapter = (PageDirectiveAdapter) ((INodeNotifier) doc).getExistingAdapter(PageDirectiveAdapter.class);
assertNotNull("model did not have pageDirective", pageDirectiveAdapter);
EmbeddedTypeHandler embeddedHandler = pageDirectiveAdapter.getEmbeddedType();
assertNotNull("model did not have embedded handler", embeddedHandler);
assertEquals(expectedType, embeddedHandler.getClass());
}
use of org.eclipse.wst.sse.core.internal.ltk.modelhandler.EmbeddedTypeHandler in project webtools.sourceediting by eclipse.
the class TestModelClone method checkForSameEmbeddedFactories.
/**
* Method checkEmbeddedFactories.
* @param model
* @param clonedModel
* @return boolean
*/
private boolean checkForSameEmbeddedFactories(IStructuredModel model, IStructuredModel clonedModel) {
boolean result = true;
EmbeddedTypeHandler oldEmbeddedType = getEmbeddedType(model);
EmbeddedTypeHandler newEmbeddedType = getEmbeddedType(clonedModel);
// expect to be the same type
if (!oldEmbeddedType.getClass().equals(newEmbeddedType.getClass())) {
result = false;
assertTrue(result);
}
List oldFactories = oldEmbeddedType.getAdapterFactories();
List newFactories = newEmbeddedType.getAdapterFactories();
result = checkFactoriesListForEquivalence(oldFactories, newFactories);
return result;
}
use of org.eclipse.wst.sse.core.internal.ltk.modelhandler.EmbeddedTypeHandler in project webtools.sourceediting by eclipse.
the class TestModelHandlers method testDirtyStateForEmbeddedCharsetWithoutContentType.
public void testDirtyStateForEmbeddedCharsetWithoutContentType() 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=\"charset=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);
}
Aggregations