Search in sources :

Example 41 with IModelManager

use of org.eclipse.wst.sse.core.internal.provisional.IModelManager in project webtools.sourceediting by eclipse.

the class TestContentFormatter method getModelForEdit.

/**
 * must release model (from edit) after
 *
 * @param filename
 *            relative to this class (TestFormatProcessorCSS)
 */
private IStructuredModel getModelForEdit(final String filename) {
    IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(new Path(filename));
    assertTrue("unable to find file: " + filename, file.exists());
    IStructuredModel model = null;
    try {
        IModelManager modelManager = StructuredModelManager.getModelManager();
        model = modelManager.getModelForEdit(file);
    } catch (CoreException ce) {
        ce.printStackTrace();
    } catch (IOException io) {
        io.printStackTrace();
    }
    return model;
}
Also used : Path(org.eclipse.core.runtime.Path) IFile(org.eclipse.core.resources.IFile) CoreException(org.eclipse.core.runtime.CoreException) IModelManager(org.eclipse.wst.sse.core.internal.provisional.IModelManager) IStructuredModel(org.eclipse.wst.sse.core.internal.provisional.IStructuredModel) IOException(java.io.IOException)

Example 42 with IModelManager

use of org.eclipse.wst.sse.core.internal.provisional.IModelManager in project webtools.sourceediting by eclipse.

the class TestModelRelease method testJSPModel.

public void testJSPModel() {
    IModelManager modelManager = getModelManager();
    IDOMModel structuredModel = (IDOMModel) modelManager.createUnManagedStructuredModelFor(ContentTypeIdForJSP.ContentTypeID_JSP);
    boolean test = structuredModel.getId().equals(IModelManager.UNMANAGED_MODEL);
    assertTrue(test);
    // even though model is unmanaged, release still required, since
    // adapter factories, etc., may be depending on it.
    structuredModel.releaseFromEdit();
    // if above complete's normally (with no exceptions)
    // consider passed.
    assertTrue(true);
}
Also used : IDOMModel(org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel) IModelManager(org.eclipse.wst.sse.core.internal.provisional.IModelManager)

Example 43 with IModelManager

use of org.eclipse.wst.sse.core.internal.provisional.IModelManager in project webtools.sourceediting by eclipse.

the class JSPedCSSSourceParserTest method createModel.

private ICSSModel createModel(boolean isFragment) {
    IStructuredModel model = null;
    try {
        IModelManager modelManager = StructuredModelManager.getModelManager();
        model = // $NON-NLS-1$
        !isFragment ? // $NON-NLS-1$
        modelManager.getModelForEdit("cssjsptest" + index_jsp++ + ".jsp", new NullInputStream(), null) : // $NON-NLS-1$
        modelManager.getModelForEdit("cssjsptest" + index_jspf++ + ".jspf", new NullInputStream(), null);
        // $NON-NLS-1$
        model.getStructuredDocument().setLineDelimiter(commonEOL);
    } catch (Exception e) {
        StringWriter s = new StringWriter();
        e.printStackTrace(new PrintWriter(s));
        fail(s.toString());
    }
    return (ICSSModel) model;
}
Also used : StringWriter(java.io.StringWriter) ICSSModel(org.eclipse.wst.css.core.internal.provisional.document.ICSSModel) IModelManager(org.eclipse.wst.sse.core.internal.provisional.IModelManager) IStructuredModel(org.eclipse.wst.sse.core.internal.provisional.IStructuredModel) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) NullInputStream(org.eclipse.jst.jsp.core.tests.NullInputStream) PrintWriter(java.io.PrintWriter)

Example 44 with IModelManager

use of org.eclipse.wst.sse.core.internal.provisional.IModelManager in project webtools.sourceediting by eclipse.

the class TestStructuredDocumentClone method testCloneStructuredDocumentXML.

public void testCloneStructuredDocumentXML() throws IOException {
    // First make (empty) structuredDocument
    IModelManager modelManager = StructuredModelManager.getModelManager();
    IStructuredDocument structuredDocument = modelManager.createStructuredDocumentFor("dummy.xml", (InputStream) null, null);
    assertTrue("structuredDocument could not be created!", structuredDocument != null);
    IStructuredDocument clonedStructuredDocument = structuredDocument.newInstance();
    // make sure the critical variables are NOT identical, but that new instances
    // have been made
    boolean passed = true;
    if (clonedStructuredDocument.getEncodingMemento() == structuredDocument.getEncodingMemento())
        passed = false;
    if (clonedStructuredDocument.getParser() == structuredDocument.getParser())
        passed = false;
    if (clonedStructuredDocument.getReParser() == structuredDocument.getReParser())
        passed = false;
    assertTrue("newInstance of XML structuredDocument is not correct", passed);
}
Also used : IModelManager(org.eclipse.wst.sse.core.internal.provisional.IModelManager) IStructuredDocument(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument)

Example 45 with IModelManager

use of org.eclipse.wst.sse.core.internal.provisional.IModelManager in project webtools.sourceediting by eclipse.

the class TestStructuredDocumentClone method testCloneStructuredDocumentJSP.

/**
 * This test is most useful to check breakpoints and dig deep in object
 * to check clones values
 */
public void testCloneStructuredDocumentJSP() throws IOException {
    // First make (empty) structuredDocument
    IModelManager modelManager = StructuredModelManager.getModelManager();
    IStructuredDocument structuredDocument = modelManager.createStructuredDocumentFor("dummy.jsp", (InputStream) null, null);
    assertTrue("structuredDocument could not be created!", structuredDocument != null);
    IStructuredDocument clonedStructuredDocument = structuredDocument.newInstance();
    // make sure the critical variables are NOT identical, but that new instances
    // have been made
    boolean passed = true;
    if (clonedStructuredDocument.getEncodingMemento() == structuredDocument.getEncodingMemento())
        passed = false;
    if (clonedStructuredDocument.getParser() == structuredDocument.getParser())
        passed = false;
    if (clonedStructuredDocument.getReParser() == structuredDocument.getReParser())
        passed = false;
    assertTrue("newInstance of JSP structuredDocument is not correct", passed);
}
Also used : IModelManager(org.eclipse.wst.sse.core.internal.provisional.IModelManager) IStructuredDocument(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument)

Aggregations

IModelManager (org.eclipse.wst.sse.core.internal.provisional.IModelManager)139 IStructuredModel (org.eclipse.wst.sse.core.internal.provisional.IStructuredModel)102 IDOMModel (org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel)45 IOException (java.io.IOException)37 InputStream (java.io.InputStream)27 IStructuredDocument (org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument)27 IFile (org.eclipse.core.resources.IFile)23 CoreException (org.eclipse.core.runtime.CoreException)21 BadLocationException (org.eclipse.jface.text.BadLocationException)13 FileNotFoundException (java.io.FileNotFoundException)12 IDOMDocument (org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument)11 Document (org.w3c.dom.Document)10 ArrayList (java.util.ArrayList)9 IProject (org.eclipse.core.resources.IProject)9 StringBufferInputStream (java.io.StringBufferInputStream)8 IDocumentPartitioner (org.eclipse.jface.text.IDocumentPartitioner)7 IDocument (org.eclipse.jface.text.IDocument)6 PageDirectiveAdapter (org.eclipse.jst.jsp.core.internal.document.PageDirectiveAdapter)6 ModelQuery (org.eclipse.wst.xml.core.internal.contentmodel.modelquery.ModelQuery)6 UnsupportedEncodingException (java.io.UnsupportedEncodingException)5