use of org.eclipse.wst.sse.core.internal.provisional.IStructuredModel in project webtools.sourceediting by eclipse.
the class TestPageDirective method testBasicPD.
public void testBasicPD() 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);
// Now, assigning use a page directive, but leaving embedded type the same as default
model.getStructuredDocument().setText(this, "<%@ page contentType=\"text/html\" language=\"java\" %>");
PageDirectiveAdapter pageDirectiveAdapter = (PageDirectiveAdapter) ((IDOMModel) model).getDocument().getAdapterFor(PageDirectiveAdapter.class);
String contentType = pageDirectiveAdapter.getContentType();
String language = pageDirectiveAdapter.getLanguage();
assertTrue("contentType should be html", "text/html".equals(contentType));
assertTrue("language should be java", "java".equals(language));
}
use of org.eclipse.wst.sse.core.internal.provisional.IStructuredModel in project webtools.sourceediting by eclipse.
the class TestModelsFromFiles method doTestCreate.
/**
* @param string
* @param class1
* @param class2
* @throws CoreException
* @throws IOException
* @throws ResourceInUse
* @throws ResourceAlreadyExists
*/
private String doTestCreate(String filePath, Class expectedDocumentClass, Class expectedPartioner) throws ResourceAlreadyExists, ResourceInUse, IOException, CoreException {
String contents = null;
IModelManager modelManager = StructuredModelManager.getModelManager();
IFile file = (IFile) fTestProject.findMember(filePath);
// file will be null if the resource does not exist
if (file == null) {
file = fTestProject.getFile(filePath);
}
IStructuredModel model = modelManager.getNewModelForEdit(file, true);
try {
assertNotNull(model);
IStructuredDocument document = model.getStructuredDocument();
assertNotNull(document);
contents = document.get();
assertTrue("wrong class of document", expectedDocumentClass.isInstance(document));
IDocumentPartitioner setupPartitioner = null;
if (Utilities.contains(expectedDocumentClass.getInterfaces(), IDocumentExtension3.class)) {
setupPartitioner = ((IDocumentExtension3) document).getDocumentPartitioner(IStructuredPartitioning.DEFAULT_STRUCTURED_PARTITIONING);
} else {
setupPartitioner = document.getDocumentPartitioner();
}
assertTrue("wrong partitioner in document.", expectedPartioner.isInstance(setupPartitioner));
testClone(model);
} finally {
if (model != null)
model.releaseFromEdit();
}
return contents;
}
use of org.eclipse.wst.sse.core.internal.provisional.IStructuredModel in project webtools.sourceediting by eclipse.
the class TestModelEmbeddedContentType method testStructuredModelEmbeddedXML.
public void testStructuredModelEmbeddedXML() throws IOException {
// First make (empty) structuredDocument
IModelManager modelManager = StructuredModelManager.getModelManager();
IStructuredModel model = modelManager.createUnManagedStructuredModelFor(ContentTypeIdForXML.ContentTypeID_XML);
assertTrue("model could not be created!", model != null);
// XML should NOT have an embedded type
Document doc = ((IDOMModel) model).getDocument();
EmbeddedTypeHandler embeddedHandler = (EmbeddedTypeHandler) ((INodeNotifier) doc).getAdapterFor(EmbeddedTypeHandler.class);
assertTrue("embededHanlder should be null for XML", embeddedHandler == null);
}
use of org.eclipse.wst.sse.core.internal.provisional.IStructuredModel in project webtools.sourceediting by eclipse.
the class TestModelEmbeddedContentType method testStructuredModelEmbeddedJSPChange.
public void testStructuredModelEmbeddedJSPChange() throws IOException {
// start with the full test case
IStructuredModel model = doStructuredModelEmbeddedJSP();
// change "html" to "xml"
model.getStructuredDocument().replaceText(this, 27, 4, "xml");
if (model.isReinitializationNeeded()) {
model.reinit();
}
// embedded type should now be XML
checkEmbeddedType(model, ModelHandlerUtility.getEmbeddedContentTypeFor("text/xml"));
}
use of org.eclipse.wst.sse.core.internal.provisional.IStructuredModel in project webtools.sourceediting by eclipse.
the class JSPJavaTranslatorTest method getStructuredModelForRead.
/**
* IMPORTANT whoever calls this must releaseFromRead after they are done
* using it.
*
* @param filename
* @return
* @throws IOException
* @throws UnsupportedEncodingException
*/
protected IStructuredModel getStructuredModelForRead(String filename) throws UnsupportedEncodingException, IOException {
// create model
IModelManager modelManager = StructuredModelManager.getModelManager();
InputStream inStream = getClass().getResourceAsStream(filename);
IStructuredModel sModel = modelManager.getModelForRead(filename, inStream, null);
return sModel;
}
Aggregations