use of org.eclipse.jst.jsp.core.internal.document.PageDirectiveAdapter in project webtools.sourceediting by eclipse.
the class TestPageDirective method testAddEmbeddedFactory.
public void testAddEmbeddedFactory() {
IDOMModel model = createUnmanagedHTMLModel();
PageDirectiveAdapter pageDirectiveAdapter = (PageDirectiveAdapter) model.getDocument().getAdapterFor(PageDirectiveAdapter.class);
pageDirectiveAdapter.addEmbeddedFactory(new MyEmbeddedFactory());
}
use of org.eclipse.jst.jsp.core.internal.document.PageDirectiveAdapter in project webtools.sourceediting by eclipse.
the class TestModelEmbeddedContentType method checkEmbeddedType.
protected void checkEmbeddedType(IStructuredModel clonedModel, Object expectedType) {
Document doc = ((IDOMModel) clonedModel).getDocument();
PageDirectiveAdapter embeddedTypeAdapter = (PageDirectiveAdapter) ((INodeNotifier) doc).getAdapterFor(PageDirectiveAdapter.class);
assertNotNull("cloned model did not have embedded adapter", embeddedTypeAdapter);
EmbeddedTypeHandler embeddedHandler = embeddedTypeAdapter.getEmbeddedType();
assertNotNull("cloned model did not have embedded handler", embeddedHandler);
assertTrue("cloned model embeddedHandler is wrong type", embeddedHandler.equals(expectedType));
}
use of org.eclipse.jst.jsp.core.internal.document.PageDirectiveAdapter in project webtools.sourceediting by eclipse.
the class TestModelEmbeddedContentType method doStructuredModelEmbeddedJSP.
protected IStructuredModel doStructuredModelEmbeddedJSP() throws IOException {
// First make (empty) structuredDocument
IModelManager modelManager = StructuredModelManager.getModelManager();
IStructuredModel model = modelManager.createUnManagedStructuredModelFor(ContentTypeIdForJSP.ContentTypeID_JSP);
assertTrue("model could not be created!", model != null);
// should have an embedded type
Document doc = ((IDOMModel) model).getDocument();
PageDirectiveAdapter embeddedHandler = (PageDirectiveAdapter) ((INodeNotifier) doc).getAdapterFor(PageDirectiveAdapter.class);
assertTrue("embededHanlder should NOT be null for JSP", embeddedHandler != null);
// embedded type should be HTML since no content
checkEmbeddedType(model, ModelHandlerUtility.getDefaultEmbeddedType());
String testContent = "<%@ page contentType=\"text/html\" %>";
model.getStructuredDocument().replaceText(this, 0, 0, testContent);
assertTrue("reinit should NOT be needed in this case", !model.isReinitializationNeeded());
// embedded type should STILL be HTML since no contentType was
// text/html
checkEmbeddedType(model, ModelHandlerUtility.getDefaultEmbeddedType());
return model;
//
}
use of org.eclipse.jst.jsp.core.internal.document.PageDirectiveAdapter in project webtools.sourceediting by eclipse.
the class TestModelClone method testCloneStructuredModelJSP.
public void testCloneStructuredModelJSP() throws IOException {
// First make (empty) structuredDocument
IModelManager modelManager = StructuredModelManager.getModelManager();
IStructuredModel model = modelManager.createUnManagedStructuredModelFor(ContentTypeIdForJSP.ContentTypeID_JSP);
assertTrue("model could not be created!", model != null);
IStructuredModel clonedModel = model.newInstance();
assertTrue("cloned model could not be created!", clonedModel != null);
// make sure the embedded type is correct
boolean passed = true;
Document doc = ((IDOMModel) clonedModel).getDocument();
PageDirectiveAdapter pageDirectiveAdapter = (PageDirectiveAdapter) ((INodeNotifier) doc).getExistingAdapter(PageDirectiveAdapter.class);
assertNotNull("cloned model did not have embedded adapter", pageDirectiveAdapter);
EmbeddedTypeHandler embeddedHandler = pageDirectiveAdapter.getEmbeddedType();
assertNotNull("cloned model did not have embedded handler", embeddedHandler);
// if (clonedModel.getEncodingMemento() == model.getEncodingMemento()) passed = false;
// if (clonedModel.getParser() == model.getParser()) passed = false;
// if (clonedModel.getReParser() == model.getReParser()) passed = false;
assertTrue("newInstance of structured model is not correct", passed);
}
use of org.eclipse.jst.jsp.core.internal.document.PageDirectiveAdapter in project webtools.sourceediting by eclipse.
the class TestModelClone method getEmbeddedModelQuery.
private ModelQuery getEmbeddedModelQuery(Node node) {
ModelQuery embeddedModelQuery = null;
if (node instanceof INodeNotifier) {
Node ownerNode = node.getOwnerDocument();
if (ownerNode == null) {
// then must be the document itself
ownerNode = node;
}
PageDirectiveAdapter pageDirectiveAdapter = (PageDirectiveAdapter) ((INodeNotifier) ownerNode).getAdapterFor(PageDirectiveAdapter.class);
if (pageDirectiveAdapter != null) {
String effectiveContentType = null;
ModelQuery potentialModelQueryObject = null;
String familyId = pageDirectiveAdapter.getEmbeddedType().getFamilyId();
// if (ContentTypeFamilyForHTML.HTML_FAMILY.equals(familyId)) {
if ("org.eclipse.wst.html.core.contentfamily.html".equals(familyId)) {
effectiveContentType = "text/html";
} else {
effectiveContentType = pageDirectiveAdapter.getContentType();
}
potentialModelQueryObject = (ModelQuery) embeddedModelQueries.get(effectiveContentType);
if (potentialModelQueryObject == null) {
ModelQueryAdapter embeddedAdapter = (ModelQueryAdapter) pageDirectiveAdapter.adapt((INodeNotifier) node, ModelQueryAdapter.class);
if (embeddedAdapter != null) {
// we will cache one model query per content type
embeddedModelQuery = embeddedAdapter.getModelQuery();
embeddedModelQueries.put(effectiveContentType, embeddedModelQuery);
}
} else {
embeddedModelQuery = potentialModelQueryObject;
}
}
}
return embeddedModelQuery;
}
Aggregations