Search in sources :

Example 61 with IModelManager

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

the class TestStructuredPartitionerXML method getModelForEdit.

/**
 * must release model (from edit) after
 * @param filename relative to this class (TestStructuredPartitioner)
 */
private IStructuredModel getModelForEdit(String filename) {
    IStructuredModel model = null;
    try {
        IModelManager modelManager = StructuredModelManager.getModelManager();
        InputStream inStream = getClass().getResourceAsStream(filename);
        if (inStream == null)
            inStream = new NullStream();
        model = modelManager.getModelForEdit(filename, inStream, null);
    } catch (IOException ex) {
        ex.printStackTrace();
    }
    return model;
}
Also used : InputStream(java.io.InputStream) IModelManager(org.eclipse.wst.sse.core.internal.provisional.IModelManager) IStructuredModel(org.eclipse.wst.sse.core.internal.provisional.IStructuredModel) IOException(java.io.IOException)

Example 62 with IModelManager

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

the class TestXMLContentAssist method loadXMLFile.

protected void loadXMLFile() throws ResourceAlreadyExists, ResourceInUse, IOException, CoreException {
    IModelManager modelManager = StructuredModelManager.getModelManager();
    model = modelManager.getModelForEdit(file);
    document = model.getStructuredDocument();
}
Also used : IModelManager(org.eclipse.wst.sse.core.internal.provisional.IModelManager)

Example 63 with IModelManager

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

the class TestAttributesOrder method ensureDocumentHasGrammar.

/**
 * Reusable test to make sure the XML model for the given file has a grammar.
 *
 * @param file
 *          the file containing the XML document.
 */
private void ensureDocumentHasGrammar(IFile file) throws IOException, CoreException {
    IStructuredModel model = null;
    try {
        IModelManager modelManager = StructuredModelManager.getModelManager();
        model = modelManager.getModelForRead(file);
        // $NON-NLS-1$
        assertNotNull("failure loading model", model);
        IDOMModel domModel = (IDOMModel) model;
        IDOMDocument document = domModel.getDocument();
        // $NON-NLS-1$
        assertNotNull("failure getting document", document);
        ModelQuery modelQuery = ModelQueryUtil.getModelQuery(document);
        // $NON-NLS-1$
        assertNotNull("ModelQuery is missing", modelQuery);
        IDOMElement documentElement = (IDOMElement) document.getDocumentElement();
        // $NON-NLS-1$
        assertNotNull("missing document element", documentElement);
        CMElementDeclaration cmElementDeclaration = modelQuery.getCMElementDeclaration(documentElement);
        // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
        assertNotNull("No element declaration for" + documentElement.getNodeName() + " (" + documentElement.getNamespaceURI() + ")", cmElementDeclaration);
        assertNotNull("No content assist available for" + documentElement.getNodeName() + " (" + documentElement.getNamespaceURI() + ")", modelQuery.getAvailableContent(documentElement, cmElementDeclaration, ModelQuery.INCLUDE_CHILD_NODES));
    } finally {
        if (model != null) {
            model.releaseFromRead();
        }
    }
}
Also used : CMElementDeclaration(org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration) IDOMModel(org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel) IModelManager(org.eclipse.wst.sse.core.internal.provisional.IModelManager) IDOMDocument(org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument) ModelQuery(org.eclipse.wst.xml.core.internal.contentmodel.modelquery.ModelQuery) IStructuredModel(org.eclipse.wst.sse.core.internal.provisional.IStructuredModel) IDOMElement(org.eclipse.wst.xml.core.internal.provisional.document.IDOMElement)

Example 64 with IModelManager

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

the class TestCyclicGroupReferences method testCyclicGroupReferences.

/**
 * Test CMVisitor for cyclic group references.
 */
public void testCyclicGroupReferences() {
    // $NON-NLS-1$
    IFile file = getFile("Test.xml");
    CMVisitor cmVisitor = new CMVisitor();
    IStructuredModel model = null;
    try {
        IModelManager modelManager = StructuredModelManager.getModelManager();
        model = modelManager.getModelForRead(file);
        // $NON-NLS-1$
        assertNotNull("failure loading model", model);
        IDOMModel domModel = (IDOMModel) model;
        IDOMDocument document = domModel.getDocument();
        // $NON-NLS-1$
        assertNotNull("failure getting document", document);
        ModelQuery modelQuery = ModelQueryUtil.getModelQuery(model);
        // $NON-NLS-1$
        assertNotNull("ModelQuery is missing", modelQuery);
        IDOMElement documentElement = (IDOMElement) document.getDocumentElement();
        // $NON-NLS-1$
        assertNotNull("missing document element", documentElement);
        CMElementDeclaration cmElementDeclaration = modelQuery.getCMElementDeclaration(documentElement);
        assertNotNull("No element declaration for" + documentElement.getNodeName() + " (" + documentElement.getNamespaceURI() + ")", // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
        cmElementDeclaration);
        cmVisitor.visitCMElementDeclaration(cmElementDeclaration);
    } catch (Throwable th) {
        fail("Test failed :" + th.getClass().getName());
    } finally {
        if (model != null) {
            model.releaseFromRead();
        }
    }
}
Also used : IFile(org.eclipse.core.resources.IFile) CMElementDeclaration(org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration) IDOMModel(org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel) IModelManager(org.eclipse.wst.sse.core.internal.provisional.IModelManager) CMVisitor(org.eclipse.wst.xml.core.internal.contentmodel.util.CMVisitor) IDOMDocument(org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument) ModelQuery(org.eclipse.wst.xml.core.internal.contentmodel.modelquery.ModelQuery) IStructuredModel(org.eclipse.wst.sse.core.internal.provisional.IStructuredModel) IDOMElement(org.eclipse.wst.xml.core.internal.provisional.document.IDOMElement)

Example 65 with IModelManager

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

the class TestModelsFromFiles method doTestCreateIDs.

private void doTestCreateIDs(String filePath, Class class1, Class class2) 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);
        if (DEBUG) {
            System.out.println("ID: " + model.getId());
            System.out.println("BaseLocation" + model.getBaseLocation());
        }
    } finally {
        if (model != null) {
            model.releaseFromEdit();
        }
    }
}
Also used : IFile(org.eclipse.core.resources.IFile) IModelManager(org.eclipse.wst.sse.core.internal.provisional.IModelManager) IStructuredModel(org.eclipse.wst.sse.core.internal.provisional.IStructuredModel)

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