Search in sources :

Example 46 with IStructuredModel

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

the class WebResourceChangeHandler method initialize.

private void initialize() {
    IStructuredModel xmlModel = getModel();
    ResourcesPlugin.getWorkspace().addResourceChangeListener(this, IResourceChangeEvent.POST_CHANGE);
    xmlModel.addModelLifecycleListener(this);
    IStructuredDocument fJspDocument = xmlModel.getStructuredDocument();
    if (fJspDocument != null) {
        fJspDocument.addDocumentListener(this);
    }
    irritator = new ModelIrritantThread();
}
Also used : IStructuredDocument(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument) IStructuredModel(org.eclipse.wst.sse.core.internal.provisional.IStructuredModel)

Example 47 with IStructuredModel

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

the class FileBufferModelManager method getModel.

public IStructuredModel getModel(IFile file) {
    if (file == null) {
        // $NON-NLS-1$
        Exception iae = new IllegalArgumentException("can not get/create a model without an IFile");
        Logger.logException(iae);
        return null;
    }
    IStructuredModel model = null;
    ITextFileBufferManager bufferManager = FileBuffers.getTextFileBufferManager();
    try {
        if (Logger.DEBUG_FILEBUFFERMODELMANAGEMENT) {
            // $NON-NLS-1$
            Logger.log(Logger.INFO, "FileBufferModelManager connecting to IFile " + file.getFullPath());
        }
        // see TextFileDocumentProvider#createFileInfo about why we use
        // IFile#getFullPath
        // here, not IFile#getLocation.
        IPath location = file.getFullPath();
        if (location != null) {
            bufferManager.connect(location, LocationKind.IFILE, getProgressMonitor());
            ITextFileBuffer buffer = bufferManager.getTextFileBuffer(location, LocationKind.IFILE);
            if (buffer != null) {
                DocumentInfo info = (DocumentInfo) fDocumentMap.get(buffer.getDocument());
                if (info != null) {
                    /*
						 * Note: "info" being null at this point is a slight
						 * error.
						 * 
						 * The connect call from above (or at some time
						 * earlier in the session) would have notified the
						 * FileBufferMapper of the creation of the
						 * corresponding text buffer and created the
						 * DocumentInfo object for IStructuredDocuments.
						 */
                    info.selfConnected = true;
                    info.locationKind = LocationKind.IFILE;
                }
                /*
					 * Check the document type. Although returning null for
					 * unknown documents would be fair, try to get a model if
					 * the document is at least a valid type.
					 */
                IDocument bufferDocument = buffer.getDocument();
                if (bufferDocument instanceof IStructuredDocument) {
                    model = getModel((IStructuredDocument) bufferDocument);
                } else {
                    /*
						 * 190768 - Quick diff marks do not disappear in the
						 * vertical ruler of JavaScript editor and
						 * 
						 * 193805 - Changes are not thrown away when close
						 * with no save for files with no structured model
						 * associated with them (text files, javascript files,
						 * etc) in web project
						 */
                    bufferManager.disconnect(location, LocationKind.IFILE, getProgressMonitor());
                }
            }
        }
    } catch (CoreException e) {
        // $NON-NLS-1$
        Logger.logException("Error getting model for " + file.getFullPath(), e);
    }
    return model;
}
Also used : IPath(org.eclipse.core.runtime.IPath) CoreException(org.eclipse.core.runtime.CoreException) ITextFileBufferManager(org.eclipse.core.filebuffers.ITextFileBufferManager) ITextFileBuffer(org.eclipse.core.filebuffers.ITextFileBuffer) IStructuredDocument(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument) IStructuredModel(org.eclipse.wst.sse.core.internal.provisional.IStructuredModel) CoreException(org.eclipse.core.runtime.CoreException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) IDocument(org.eclipse.jface.text.IDocument)

Example 48 with IStructuredModel

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

the class AbstractStructuredCleanupProcessor method cleanupFile.

public void cleanupFile(IFile file) throws IOException, CoreException {
    IStructuredModel structuredModel = null;
    // OutputStream outputStream = null;
    try {
        // setup structuredModel
        structuredModel = StructuredModelManager.getModelManager().getModelForRead(file);
        // cleanup
        cleanupModel(structuredModel, 0, structuredModel.getStructuredDocument().getLength());
        // save output to file
        // outputStream = new
        // FileOutputStream(file.getLocation().toString());
        structuredModel.save(file);
    } finally {
        // release from model manager
        if (structuredModel != null)
            structuredModel.releaseFromRead();
    }
}
Also used : IStructuredModel(org.eclipse.wst.sse.core.internal.provisional.IStructuredModel)

Example 49 with IStructuredModel

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

the class AbstractStructuredCleanupProcessor method cleanupContent.

public String cleanupContent(String input, int start, int length) throws IOException, CoreException {
    IStructuredModel structuredModel = null;
    InputStream inputStream = null;
    try {
        // setup structuredModel
        // $NON-NLS-1$
        inputStream = new ByteArrayInputStream(input.getBytes("UTF8"));
        String id = inputStream.toString() + getContentType();
        structuredModel = StructuredModelManager.getModelManager().getModelForRead(id, inputStream, null);
        // cleanup
        cleanupModel(structuredModel, start, length);
        // return output
        return structuredModel.getStructuredDocument().get();
    } finally {
        ensureClosed(null, inputStream);
        // release from model manager
        if (structuredModel != null)
            structuredModel.releaseFromRead();
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) IStructuredModel(org.eclipse.wst.sse.core.internal.provisional.IStructuredModel)

Example 50 with IStructuredModel

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

the class AbstractStructuredCleanupProcessor method cleanupContent.

// tests to skip refresh
// of cleanup preferences
// when it's set to false
public String cleanupContent(String input) throws IOException, CoreException {
    IStructuredModel structuredModel = null;
    InputStream inputStream = null;
    try {
        // setup structuredModel
        // $NON-NLS-1$
        inputStream = new ByteArrayInputStream(input.getBytes("UTF8"));
        String id = inputStream.toString() + getContentType();
        structuredModel = StructuredModelManager.getModelManager().getModelForRead(id, inputStream, null);
        // cleanup
        cleanupModel(structuredModel, 0, structuredModel.getStructuredDocument().getLength());
        // return output
        return structuredModel.getStructuredDocument().get();
    } finally {
        ensureClosed(null, inputStream);
        // release from model manager
        if (structuredModel != null)
            structuredModel.releaseFromRead();
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) IStructuredModel(org.eclipse.wst.sse.core.internal.provisional.IStructuredModel)

Aggregations

IStructuredModel (org.eclipse.wst.sse.core.internal.provisional.IStructuredModel)482 IDOMModel (org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel)110 IModelManager (org.eclipse.wst.sse.core.internal.provisional.IModelManager)102 IStructuredDocument (org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument)81 IFile (org.eclipse.core.resources.IFile)75 IOException (java.io.IOException)69 CoreException (org.eclipse.core.runtime.CoreException)49 IDocument (org.eclipse.jface.text.IDocument)46 IDOMDocument (org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument)42 InputStream (java.io.InputStream)40 IDOMNode (org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode)36 Path (org.eclipse.core.runtime.Path)35 BadLocationException (org.eclipse.jface.text.BadLocationException)34 IJsTranslation (org.eclipse.wst.jsdt.web.core.javascript.IJsTranslation)32 JsTranslationAdapter (org.eclipse.wst.jsdt.web.core.javascript.JsTranslationAdapter)32 IProject (org.eclipse.core.resources.IProject)31 IndexedRegion (org.eclipse.wst.sse.core.internal.provisional.IndexedRegion)31 IPath (org.eclipse.core.runtime.IPath)27 ByteArrayInputStream (java.io.ByteArrayInputStream)22 Document (org.w3c.dom.Document)19