Search in sources :

Example 16 with IModelHandler

use of org.eclipse.wst.sse.core.internal.ltk.modelhandler.IModelHandler in project webtools.sourceediting by eclipse.

the class ModelHandlerRegistryTest method testGetHandler.

public void testGetHandler() throws Exception {
    IProject project = setUp(getName());
    IFile file = project.getFile(FILE);
    IModelHandler handler;
    try {
        handler = ModelHandlerRegistry.getInstance().getHandlerFor(file);
        assertNotNull("Model handler default should not be null.", handler);
        assertEquals("Proper default model handler was not returned.", handler.getId(), "org.eclipse.wst.xml.core.modelhandler");
    } catch (CoreException e) {
        fail("Caught exception: " + e);
    }
    tearDown(getName());
}
Also used : IFile(org.eclipse.core.resources.IFile) CoreException(org.eclipse.core.runtime.CoreException) IModelHandler(org.eclipse.wst.sse.core.internal.ltk.modelhandler.IModelHandler) IProject(org.eclipse.core.resources.IProject)

Example 17 with IModelHandler

use of org.eclipse.wst.sse.core.internal.ltk.modelhandler.IModelHandler in project webtools.sourceediting by eclipse.

the class ExclusivePositionUpdaterTest method createDocument.

private IDocument createDocument(String contents) {
    IModelHandler handler = ModelHandlerRegistry.getInstance().getHandlerForContentTypeId("org.eclipse.jst.jsp.jspsource");
    BasicStructuredDocument document = (BasicStructuredDocument) handler.getDocumentLoader().createNewStructuredDocument();
    document.set(contents);
    return document;
}
Also used : BasicStructuredDocument(org.eclipse.wst.sse.core.internal.text.BasicStructuredDocument) IModelHandler(org.eclipse.wst.sse.core.internal.ltk.modelhandler.IModelHandler)

Example 18 with IModelHandler

use of org.eclipse.wst.sse.core.internal.ltk.modelhandler.IModelHandler in project webtools.sourceediting by eclipse.

the class StructuredFileTaskScanner method findTasks.

private void findTasks(IFile file, final TaskTag[] taskTags, final IProgressMonitor monitor) {
    try {
        IModelHandler handler = ModelHandlerRegistry.getInstance().getHandlerFor(file);
        // records if the optimized streamish parse was possible
        boolean didStreamParse = false;
        final IEncodedDocument defaultDocument = handler.getDocumentLoader().createNewStructuredDocument();
        if (defaultDocument instanceof IStructuredDocument) {
            RegionParser parser = ((IStructuredDocument) defaultDocument).getParser();
            if (parser instanceof StructuredDocumentRegionParser) {
                didStreamParse = true;
                String charset = detectCharset(file);
                StructuredDocumentRegionParser documentParser = (StructuredDocumentRegionParser) parser;
                final IDocument textDocument = new Document();
                setDocumentContent(textDocument, file.getContents(true), charset);
                monitor.beginTask("", textDocument.getLength());
                documentParser.reset(new DocumentReader(textDocument));
                documentParser.addStructuredDocumentRegionHandler(new StructuredDocumentRegionHandler() {

                    public void nodeParsed(IStructuredDocumentRegion documentRegion) {
                        ITextRegionList regions = documentRegion.getRegions();
                        for (int j = 0; j < regions.size(); j++) {
                            ITextRegion comment = regions.get(j);
                            findTasks(textDocument, taskTags, documentRegion, comment);
                        }
                        // disconnect the document regions
                        if (documentRegion.getPrevious() != null) {
                            documentRegion.getPrevious().setPrevious(null);
                            documentRegion.getPrevious().setNext(null);
                        }
                        if (monitor.isCanceled()) {
                            // $NON-NLS-1$
                            textDocument.set("");
                        }
                        monitor.worked(documentRegion.getLength());
                    }

                    public void resetNodes() {
                    }
                });
                documentParser.getDocumentRegions();
            }
        }
        if (!didStreamParse) {
            // Use a StructuredDocument
            IEncodedDocument document = handler.getDocumentLoader().createNewStructuredDocument(file);
            monitor.beginTask("", document.getLength());
            if (document instanceof IStructuredDocument) {
                IStructuredDocumentRegion documentRegion = ((IStructuredDocument) document).getFirstStructuredDocumentRegion();
                while (documentRegion != null) {
                    ITextRegionList regions = documentRegion.getRegions();
                    for (int j = 0; j < regions.size(); j++) {
                        ITextRegion comment = regions.get(j);
                        findTasks(document, taskTags, documentRegion, comment);
                    }
                    monitor.worked(documentRegion.getLength());
                    documentRegion = documentRegion.getNext();
                }
            }
        }
    } catch (CoreException e) {
        // $NON-NLS-1$
        Logger.logException("Exception with " + file.getFullPath().toString(), e);
    } catch (CharacterCodingException e) {
        // $NON-NLS-1$
        Logger.log(Logger.INFO, "StructuredFileTaskScanner encountered CharacterCodingException reading " + file.getFullPath());
    } catch (Exception e) {
        // $NON-NLS-1$
        Logger.logException("Exception with " + file.getFullPath().toString(), e);
    }
    monitor.done();
}
Also used : IStructuredDocumentRegion(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion) StructuredDocumentRegionHandler(org.eclipse.wst.sse.core.internal.ltk.parser.StructuredDocumentRegionHandler) DocumentReader(org.eclipse.wst.sse.core.internal.document.DocumentReader) CharacterCodingException(java.nio.charset.CharacterCodingException) StructuredDocumentRegionParser(org.eclipse.wst.sse.core.internal.ltk.parser.StructuredDocumentRegionParser) RegionParser(org.eclipse.wst.sse.core.internal.ltk.parser.RegionParser) Document(org.eclipse.jface.text.Document) IDocument(org.eclipse.jface.text.IDocument) IEncodedDocument(org.eclipse.wst.sse.core.internal.provisional.document.IEncodedDocument) IStructuredDocument(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument) IModelHandler(org.eclipse.wst.sse.core.internal.ltk.modelhandler.IModelHandler) CharacterCodingException(java.nio.charset.CharacterCodingException) CoreException(org.eclipse.core.runtime.CoreException) BadLocationException(org.eclipse.jface.text.BadLocationException) IOException(java.io.IOException) StructuredDocumentRegionParser(org.eclipse.wst.sse.core.internal.ltk.parser.StructuredDocumentRegionParser) ITextRegionList(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList) CoreException(org.eclipse.core.runtime.CoreException) ITextRegion(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion) IStructuredDocument(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument) IEncodedDocument(org.eclipse.wst.sse.core.internal.provisional.document.IEncodedDocument) IDocument(org.eclipse.jface.text.IDocument)

Example 19 with IModelHandler

use of org.eclipse.wst.sse.core.internal.ltk.modelhandler.IModelHandler in project webtools.sourceediting by eclipse.

the class BasicStructuredDocumentFactory method createDocument.

/*
	 * (non-Javadoc)
	 * 
	 * @see org.eclipse.core.filebuffers.IDocumentFactory#createDocument()
	 */
public IDocument createDocument() {
    IDocument document = null;
    IContentType contentType = Platform.getContentTypeManager().getContentType(getContentTypeIdentifier());
    IModelHandler handler = null;
    while (handler == null && !IContentTypeManager.CT_TEXT.equals(contentType.getId())) {
        handler = ModelHandlerRegistry.getInstance().getHandlerForContentTypeId(contentType.getId());
        contentType = contentType.getBaseType();
    }
    if (handler != null) {
        document = handler.getDocumentLoader().createNewStructuredDocument();
    } else {
        document = new JobSafeStructuredDocument();
    }
    return document;
}
Also used : IContentType(org.eclipse.core.runtime.content.IContentType) JobSafeStructuredDocument(org.eclipse.wst.sse.core.internal.text.JobSafeStructuredDocument) IModelHandler(org.eclipse.wst.sse.core.internal.ltk.modelhandler.IModelHandler) IDocument(org.eclipse.jface.text.IDocument)

Example 20 with IModelHandler

use of org.eclipse.wst.sse.core.internal.ltk.modelhandler.IModelHandler in project webtools.sourceediting by eclipse.

the class AbstractUndoManagerTest method createDocument.

private IDocument createDocument(String contents) {
    IModelHandler handler = ModelHandlerRegistry.getInstance().getHandlerForContentTypeId("org.eclipse.core.runtime.xml");
    BasicStructuredDocument document = (BasicStructuredDocument) handler.getDocumentLoader().createNewStructuredDocument();
    document.set(contents);
    // return new Document(contents);
    return document;
}
Also used : BasicStructuredDocument(org.eclipse.wst.sse.core.internal.text.BasicStructuredDocument) IModelHandler(org.eclipse.wst.sse.core.internal.ltk.modelhandler.IModelHandler)

Aggregations

IModelHandler (org.eclipse.wst.sse.core.internal.ltk.modelhandler.IModelHandler)41 ModelHandlerRegistry (org.eclipse.wst.sse.core.internal.modelhandler.ModelHandlerRegistry)14 IStructuredModel (org.eclipse.wst.sse.core.internal.provisional.IStructuredModel)9 CoreException (org.eclipse.core.runtime.CoreException)6 IStructuredDocument (org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument)6 IContentType (org.eclipse.core.runtime.content.IContentType)5 IModelLoader (org.eclipse.wst.sse.core.internal.provisional.IModelLoader)5 InputStream (java.io.InputStream)4 IFile (org.eclipse.core.resources.IFile)4 IDocumentLoader (org.eclipse.wst.sse.core.internal.document.IDocumentLoader)4 ResourceInUse (org.eclipse.wst.sse.core.internal.provisional.exceptions.ResourceInUse)4 IOException (java.io.IOException)3 IProject (org.eclipse.core.resources.IProject)3 BasicStructuredDocument (org.eclipse.wst.sse.core.internal.text.BasicStructuredDocument)3 URIResolver (org.eclipse.wst.sse.core.internal.util.URIResolver)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 FileNotFoundException (java.io.FileNotFoundException)2 IConfigurationElement (org.eclipse.core.runtime.IConfigurationElement)2 IDocument (org.eclipse.jface.text.IDocument)2 IStructuredDocumentRegion (org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion)2