use of org.eclipse.wst.sse.core.internal.provisional.IModelManager 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.wst.sse.core.internal.provisional.IModelManager in project webtools.sourceediting by eclipse.
the class CreatingJSPExpression method testCreateJSPExpression.
public void testCreateJSPExpression() 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\" %>");
Document doc = ((IDOMModel) model).getDocument();
Element jspexpression = doc.createElement("jsp:expression");
((IDOMElement) jspexpression).setJSPTag(true);
doc.appendChild(jspexpression);
Text javacode = doc.createTextNode(" // some java code here; if (x <0) return new String(\"0\") else return new String (\"1\"); ");
jspexpression.appendChild(javacode);
Text cdatasection = doc.createCDATASection(" // some cdata java code here; if (x <0) return new String(\"0\") else return new String (\"1\"); ");
doc.appendChild(cdatasection);
// format's not needed, just prettier ... not sure why
// it won't work right on whole document.
new NodeFormatter().format(jspexpression);
new NodeFormatter().format(cdatasection);
System.out.println("document text: ");
System.out.println(model.getStructuredDocument().get());
}
use of org.eclipse.wst.sse.core.internal.provisional.IModelManager in project webtools.sourceediting by eclipse.
the class TestModelsFromFiles method doTestReload.
/**
* @param string
* @param class1
* @param class2
* @throws CoreException
* @throws IOException
* @throws ResourceInUse
* @throws ResourceAlreadyExists
*/
private void doTestReload(String filePath, Class expectedDocumentClass, Class expectedPartioner) throws ResourceAlreadyExists, ResourceInUse, IOException, CoreException {
IModelManager modelManager = StructuredModelManager.getModelManager();
IFile file = (IFile) fTestProject.findMember(filePath);
if (file == null) {
file = fTestProject.getFile(filePath);
}
IStructuredModel model = modelManager.getNewModelForEdit(file, true);
try {
assertNotNull(model);
IStructuredDocument document = model.getStructuredDocument();
assertNotNull(document);
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));
InputStream inStream = null;
try {
inStream = file.getContents();
model.reload(inStream);
assertNotNull(model);
IStructuredDocument documentReloaded = model.getStructuredDocument();
// note: NOT same instance of document
// FIXME: this test has to be changed back, once the reload
// API is
// fixed to work with different document.
// assertFalse(document == documentReloaded);
assertTrue(document == documentReloaded);
} finally {
if (inStream != null) {
inStream.close();
}
}
} finally {
if (model != null)
model.releaseFromEdit();
}
}
use of org.eclipse.wst.sse.core.internal.provisional.IModelManager in project webtools.sourceediting by eclipse.
the class TestModelsFromFiles method doTestCreateModelWithNonExistIFile.
/**
* @param string
* @param class1
* @param class2
* @throws CoreException
* @throws IOException
* @throws ResourceInUse
* @throws ResourceAlreadyExists
*/
private String doTestCreateModelWithNonExistIFile(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, false);
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));
} finally {
if (model != null)
model.releaseFromEdit();
}
return contents;
}
use of org.eclipse.wst.sse.core.internal.provisional.IModelManager in project webtools.sourceediting by eclipse.
the class TestFormatProcessorHTML method getModelForEdit.
/**
* must release model (from edit) after
*
* @param filename
* relative to this class (TestStructuredPartitioner)
*/
private IStructuredModel getModelForEdit(final String filename) {
IStructuredModel model = null;
try {
IModelManager modelManager = StructuredModelManager.getModelManager();
InputStream inStream = getClass().getResourceAsStream(filename);
if (inStream == null)
throw new FileNotFoundException("Can't file resource stream " + filename);
final String baseFile = getClass().getResource(filename).toString();
model = modelManager.getModelForEdit(baseFile, inStream, new URIResolver() {
String fBase = baseFile;
public String getFileBaseLocation() {
return fBase;
}
public String getLocationByURI(String uri) {
return getLocationByURI(uri, fBase);
}
public String getLocationByURI(String uri, boolean resolveCrossProjectLinks) {
return getLocationByURI(uri);
}
public String getLocationByURI(String uri, String baseReference) {
int lastSlash = baseReference.lastIndexOf("/");
if (lastSlash > 0)
return baseReference.substring(0, lastSlash + 1) + uri;
return baseReference;
}
public String getLocationByURI(String uri, String baseReference, boolean resolveCrossProjectLinks) {
return getLocationByURI(uri, baseReference);
}
public IProject getProject() {
return null;
}
public IContainer getRootLocation() {
return null;
}
public InputStream getURIStream(String uri) {
return getClass().getResourceAsStream(getLocationByURI(uri));
}
public void setFileBaseLocation(String newLocation) {
this.fBase = newLocation;
}
public void setProject(IProject newProject) {
}
});
} catch (IOException ex) {
ex.printStackTrace();
}
return model;
}
Aggregations