Search in sources :

Example 11 with IModelManager

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

the class StructuredModelManager method getModelManager.

/**
 * Provides access to the instance of IModelManager. Returns null if model
 * manager can not be created or is not valid (such as, when workbench is
 * shutting down).
 *
 * @return IModelManager - returns the one model manager for structured
 *         models or null if the owning bundle is neither active nor
 *         starting.
 */
public static IModelManager getModelManager() {
    boolean isReady = false;
    IModelManager modelManager = null;
    boolean interrupted = false;
    try {
        while (!isReady) {
            Bundle localBundle = Platform.getBundle(SSECorePlugin.ID);
            int state = localBundle.getState();
            if (state == Bundle.ACTIVE) {
                isReady = true;
                // getInstance is a synchronized static method.
                modelManager = ModelManagerImpl.getInstance();
            } else if (state == Bundle.STARTING) {
                try {
                    Thread.sleep(100);
                } catch (InterruptedException e) {
                    // ignore, just loop again
                    interrupted = true;
                }
            } else if (state == Bundle.STOPPING || state == Bundle.UNINSTALLED) {
                isReady = true;
                modelManager = null;
            } else {
                // not sure about other states, 'resolved', 'installed'
                isReady = true;
                modelManager = null;
            }
        }
    } finally {
        if (interrupted) {
            Thread.currentThread().interrupt();
        }
    }
    return modelManager;
}
Also used : Bundle(org.osgi.framework.Bundle) IModelManager(org.eclipse.wst.sse.core.internal.provisional.IModelManager)

Example 12 with IModelManager

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

the class CSSColorPage method setupPicker.

/**
 * setupPicker method comment.
 */
protected void setupPicker(StyledTextColorPicker picker) {
    IModelManager mmanager = StructuredModelManager.getModelManager();
    picker.setParser(mmanager.createStructuredDocumentFor(ContentTypeIdForCSS.ContentTypeID_CSS).getParser());
    Dictionary descriptions = new Hashtable();
    initDescriptions(descriptions);
    Dictionary contextStyleMap = new Hashtable();
    initContextStyleMap(contextStyleMap);
    ArrayList styleList = new ArrayList();
    initStyleList(styleList);
    picker.setContextStyleMap(contextStyleMap);
    picker.setDescriptions(descriptions);
    picker.setStyleList(styleList);
}
Also used : Dictionary(java.util.Dictionary) Hashtable(java.util.Hashtable) IModelManager(org.eclipse.wst.sse.core.internal.provisional.IModelManager) ArrayList(java.util.ArrayList)

Example 13 with IModelManager

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

the class StructuredDocumentToDOMUnitTests method testNodeDeletion.

/**
 * Unit test -- tests basic parsing results of inserting a test string
 * into an initial string.
 */
void testNodeDeletion() {
    // String initialString =
    // "<par><x>\ntextx\n</x>\n<y>\ntexty\n</y></par>";
    // String initialString = "<par><x>textx</x><y>texty</y></par>";
    // test cases for two text nodes left together (remove <b/>):
    // first case works, second doesn't
    // String initialString = "<a>a<b /></a>"; // -> <a>a</a>
    // String initialString = "<a>a<b />b</a>"; // -> <a>ab</a>
    // String initialString = getTestString1();
    String initialString = getTestString2();
    // print out what we always can
    System.out.println();
    System.out.println("----------------");
    System.out.println("Test Node Deletion");
    String outString = StringUtils.escape(initialString);
    System.out.println("Initial String: " + outString);
    // always start with fresh model
    IStructuredDocument f = null;
    IModelManager mm = StructuredModelManager.getModelManager();
    try {
        f = mm.createStructuredDocumentFor("dummy.xml", (InputStream) null, null);
    } catch (IOException e) {
    // do nothing, since dummy
    }
    // 
    // we'll listen to structuredDocument events to print out diagnostics
    f.addDocumentChangedListener(this);
    // 
    IDOMModel tree = new DOMModelImpl();
    f.addDocumentChangingListener((IStructuredDocumentListener) tree);
    // set text to structuredDocument (which updates tree)
    f.setText(null, initialString);
    // dump initial structuredDocument
    Debug.dump(f);
    // dump initial dom
    DebugDocument.dump(tree.getDocument());
    // 
    // 
    // makeChange1(tree);
    makeChange2(f);
    // display resulting text
    System.out.println("resultString (from structuredDocument): ");
    System.out.println(StringUtils.escape(f.getText()));
    // 
    // 
    // dump post change structuredDocument
    Debug.dump(f);
    // dump post change DOM
    DebugDocument.dump(tree.getDocument());
// 
}
Also used : InputStream(java.io.InputStream) IDOMModel(org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel) IModelManager(org.eclipse.wst.sse.core.internal.provisional.IModelManager) DOMModelImpl(org.eclipse.wst.xml.core.internal.document.DOMModelImpl) IStructuredDocument(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument) IOException(java.io.IOException)

Example 14 with IModelManager

use of org.eclipse.wst.sse.core.internal.provisional.IModelManager 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));
}
Also used : IDOMModel(org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel) IModelManager(org.eclipse.wst.sse.core.internal.provisional.IModelManager) PageDirectiveAdapter(org.eclipse.jst.jsp.core.internal.document.PageDirectiveAdapter) IStructuredModel(org.eclipse.wst.sse.core.internal.provisional.IStructuredModel)

Example 15 with IModelManager

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

the class TestModelsFromFiles method doTestNotEmptyDocument.

/**
 * @param string
 * @param class1
 * @param class2
 * @throws CoreException
 * @throws IOException
 * @throws ResourceInUse
 * @throws ResourceAlreadyExists
 */
private void doTestNotEmptyDocument(String filePath, Class expectedDocumentClass, Class expectedPartioner) throws ResourceAlreadyExists, ResourceInUse, IOException, CoreException {
    String contents = null;
    IModelManager modelManager = StructuredModelManager.getModelManager();
    IFile file = (IFile) fTestProject.findMember(filePath);
    if (file == null) {
        file = fTestProject.getFile(filePath);
    }
    IStructuredDocument document = modelManager.createStructuredDocumentFor(file);
    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));
    contents = document.get();
    assertNotNull("contents were null", contents);
    assertTrue("contents were empty", contents.length() > 0);
}
Also used : IFile(org.eclipse.core.resources.IFile) IDocumentPartitioner(org.eclipse.jface.text.IDocumentPartitioner) 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