Search in sources :

Example 6 with IDocumentLoader

use of org.eclipse.wst.sse.core.internal.document.IDocumentLoader in project webtools.sourceediting by eclipse.

the class ModelManagerImpl method createStructuredDocumentFor.

/**
 * Factory method, since a proper IStructuredDocument must have a proper
 * parser assigned. Note: clients should verify IFile exists before using
 * this method. If this IFile does not exist, then
 * createNewStructuredDocument is the correct API to use.
 *
 * @throws ResourceInUse
 */
public IStructuredDocument createStructuredDocumentFor(IFile iFile) throws IOException, CoreException {
    if (!iFile.exists()) {
        throw new FileNotFoundException(iFile.getFullPath().toOSString());
    }
    // Will reconsider in future version
    // String id = calculateId(iFile);
    // if (isResourceInUse(id)) {
    // throw new ResourceInUse(iFile.getFullPath().toOSString());
    // }
    IDocumentLoader loader = null;
    IModelHandler handler = calculateType(iFile);
    loader = handler.getDocumentLoader();
    IStructuredDocument result = (IStructuredDocument) loader.createNewStructuredDocument(iFile);
    return result;
}
Also used : IDocumentLoader(org.eclipse.wst.sse.core.internal.document.IDocumentLoader) FileNotFoundException(java.io.FileNotFoundException) IStructuredDocument(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument) IModelHandler(org.eclipse.wst.sse.core.internal.ltk.modelhandler.IModelHandler)

Example 7 with IDocumentLoader

use of org.eclipse.wst.sse.core.internal.document.IDocumentLoader in project webtools.sourceediting by eclipse.

the class ModelManagerImpl method createStructuredDocumentFor.

/**
 * Convenience method. This method can be used when the resource does not
 * really exist (e.g. when content is being created, but hasn't been
 * written to disk yet). Note that since the content is being provided as
 * a String, it is assumed to already be decoded correctly so no
 * transformation is done.
 */
public IStructuredDocument createStructuredDocumentFor(String filename, String content, URIResolver resolver) throws IOException {
    IDocumentLoader loader = null;
    IModelHandler handler = calculateType(filename, null);
    loader = handler.getDocumentLoader();
    IStructuredDocument result = (IStructuredDocument) loader.createNewStructuredDocument();
    result.setEncodingMemento(new NullMemento());
    result.setText(this, content);
    return result;
}
Also used : IDocumentLoader(org.eclipse.wst.sse.core.internal.document.IDocumentLoader) NullMemento(org.eclipse.wst.sse.core.internal.NullMemento) IStructuredDocument(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument) IModelHandler(org.eclipse.wst.sse.core.internal.ltk.modelhandler.IModelHandler)

Example 8 with IDocumentLoader

use of org.eclipse.wst.sse.core.internal.document.IDocumentLoader in project webtools.sourceediting by eclipse.

the class ModelManagerImpl method createStructuredDocumentFor.

/**
 * Conveience method, since a proper IStructuredDocument must have a
 * proper parser assigned. It should only be used when an empty
 * structuredDocument is needed. Otherwise, use IFile form.
 *
 * @deprecated - TODO: to be removed by C4 do we really need this? I
 *             recommend to - use createStructuredDocumentFor(filename,
 *             null, null) - the filename does not need to represent a
 *             real - file, but can take for form of dummy.jsp, test.xml,
 *             etc. - That way we don't hard code the handler, but specify
 *             we - want the handler that "goes with" a certain type of -
 *             file.
 */
public IStructuredDocument createStructuredDocumentFor(String contentTypeId) {
    IDocumentLoader loader = null;
    ModelHandlerRegistry cr = getModelHandlerRegistry();
    IModelHandler handler = cr.getHandlerForContentTypeId(contentTypeId);
    if (handler == null)
        // $NON-NLS-1$
        Logger.log(Logger.ERROR, "Program error: no model handler found for " + contentTypeId);
    loader = handler.getDocumentLoader();
    IStructuredDocument result = (IStructuredDocument) loader.createNewStructuredDocument();
    return result;
}
Also used : ModelHandlerRegistry(org.eclipse.wst.sse.core.internal.modelhandler.ModelHandlerRegistry) IDocumentLoader(org.eclipse.wst.sse.core.internal.document.IDocumentLoader) IStructuredDocument(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument) IModelHandler(org.eclipse.wst.sse.core.internal.ltk.modelhandler.IModelHandler)

Aggregations

IDocumentLoader (org.eclipse.wst.sse.core.internal.document.IDocumentLoader)8 IStructuredDocument (org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument)7 IModelHandler (org.eclipse.wst.sse.core.internal.ltk.modelhandler.IModelHandler)4 CSSDocumentLoader (org.eclipse.wst.css.core.internal.encoding.CSSDocumentLoader)3 CSSSourceParser (org.eclipse.wst.css.core.internal.parser.CSSSourceParser)3 IStructuredDocumentRegion (org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion)3 FileNotFoundException (java.io.FileNotFoundException)1 NullMemento (org.eclipse.wst.sse.core.internal.NullMemento)1 ModelHandlerRegistry (org.eclipse.wst.sse.core.internal.modelhandler.ModelHandlerRegistry)1 IStructuredModel (org.eclipse.wst.sse.core.internal.provisional.IStructuredModel)1 IEncodedDocument (org.eclipse.wst.sse.core.internal.provisional.document.IEncodedDocument)1 ResourceAlreadyExists (org.eclipse.wst.sse.core.internal.provisional.exceptions.ResourceAlreadyExists)1