Search in sources :

Example 61 with IStructuredDocument

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

the class JSPDocumentLoader method createNewStructuredDocument.

public IEncodedDocument createNewStructuredDocument(String filename, InputStream inputStream) throws UnsupportedEncodingException, IOException {
    if (filename == null && inputStream == null) {
        // $NON-NLS-1$
        throw new IllegalArgumentException("can not have both null filename and inputstream");
    }
    IEncodedDocument structuredDocument = createNewStructuredDocument();
    CodedReaderCreator codedReaderCreator = new CodedReaderCreator();
    try {
        codedReaderCreator.set(filename, inputStream);
        fFullPreparedReader = codedReaderCreator.getCodedReader();
        fEncodingMemento = codedReaderCreator.getEncodingMemento();
        structuredDocument.setEncodingMemento(fEncodingMemento);
        // the fact that file is null means this method/code path is no
        // good for JSP fragments
        EmbeddedTypeHandler embeddedType = getEmbeddedType((IFile) null);
        fFullPreparedReader.reset();
        if (embeddedType != null)
            embeddedType.initializeParser(((IStructuredDocument) structuredDocument).getParser());
        setDocumentContentsFromReader(structuredDocument, fFullPreparedReader);
    } catch (CoreException e) {
        // impossible in this context
        throw new Error(e);
    } finally {
        if (fFullPreparedReader != null) {
            fFullPreparedReader.close();
        }
    }
    return structuredDocument;
}
Also used : EmbeddedTypeHandler(org.eclipse.wst.sse.core.internal.ltk.modelhandler.EmbeddedTypeHandler) CodedReaderCreator(org.eclipse.wst.sse.core.internal.encoding.CodedReaderCreator) CoreException(org.eclipse.core.runtime.CoreException) IStructuredDocument(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument) IEncodedDocument(org.eclipse.wst.sse.core.internal.provisional.document.IEncodedDocument)

Example 62 with IStructuredDocument

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

the class JSPDocumentLoader method createCodedDocument.

private IStructuredDocument createCodedDocument(IFile iFile) throws CoreException, UnsupportedEncodingException, IOException {
    IStructuredDocument structuredDocument = (IStructuredDocument) createNewStructuredDocument();
    getCodedReaderCreator().set(iFile);
    fFullPreparedReader = getCodedReaderCreator().getCodedReader();
    fEncodingMemento = getCodedReaderCreator().getEncodingMemento();
    structuredDocument.setEncodingMemento(getCodedReaderCreator().getEncodingMemento());
    return structuredDocument;
}
Also used : IStructuredDocument(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument)

Example 63 with IStructuredDocument

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

the class JSPDocumentLoader method newEncodedDocument.

/**
 * This method must return a new instance of IStructuredDocument, that has
 * been initialized with appropriate parser. For many loaders, the
 * (default) parser used is known for any input. For others, the correct
 * parser (and its initialization) is normall dependent on the content of
 * the file. This no-argument method should assume "empty input" and would
 * therefore return the default parser for the default contentType. If the
 * parser is to handle tag libraries, it must have a TaglibSupport object
 * with a valid URIResolver and this IStructuredDocument attached to it
 * before the contents are set on the IStructuredDocument.
 */
protected IEncodedDocument newEncodedDocument() {
    IStructuredDocument structuredDocument = StructuredDocumentFactory.getNewStructuredDocumentInstance(getParser());
    ((BasicStructuredDocument) structuredDocument).setReParser(new JSPReParser());
    // structuredDocument.setDocumentPartitioner(new
    // JSPJavaDocumentPartioner());
    // even though this is an "empty model" ... we want it to have at
    // least
    // the
    // default embeddeded content type handler
    EmbeddedTypeHandler embeddedType = getJSPDefaultEmbeddedType();
    embeddedType.initializeParser(structuredDocument.getParser());
    return structuredDocument;
}
Also used : EmbeddedTypeHandler(org.eclipse.wst.sse.core.internal.ltk.modelhandler.EmbeddedTypeHandler) BasicStructuredDocument(org.eclipse.wst.sse.core.internal.text.BasicStructuredDocument) IStructuredDocument(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument) JSPReParser(org.eclipse.jst.jsp.core.internal.parser.JSPReParser)

Example 64 with IStructuredDocument

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

the class JSONObjectDocumentChangesTest method insertCloseObject.

@Test
public void insertCloseObject() {
    IJSONModel model = TestUtil.loadModel("{");
    IJSONDocument document = model.getDocument();
    // Document contains an Object which is not closed
    Assert.assertNotNull(document.getFirstChild());
    Assert.assertTrue(document.getFirstChild() instanceof IJSONObject);
    IJSONObject object = (IJSONObject) document.getFirstChild();
    Assert.assertFalse(object.isClosed());
    IStructuredDocument structuredDocument = model.getStructuredDocument();
    // insert at end '}'
    structuredDocument.replaceText(structuredDocument, 1, 0, "}");
    object = (IJSONObject) document.getFirstChild();
    Assert.assertTrue(object.isClosed());
}
Also used : IStructuredDocument(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument) Test(org.junit.Test)

Example 65 with IStructuredDocument

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

the class JSONObjectDocumentChangesTest method removeObject.

@Test
public void removeObject() {
    IJSONModel model = TestUtil.loadModel("{}");
    IJSONDocument document = model.getDocument();
    // Document contains an Object which is not closed
    Assert.assertNotNull(document.getFirstChild());
    Assert.assertTrue(document.getFirstChild() instanceof IJSONObject);
    IJSONObject object = (IJSONObject) document.getFirstChild();
    Assert.assertTrue(object.isClosed());
    IStructuredDocument structuredDocument = model.getStructuredDocument();
    // remove {}
    structuredDocument.replaceText(structuredDocument, 0, 2, "");
    Assert.assertNull(document.getFirstChild());
}
Also used : IStructuredDocument(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument) Test(org.junit.Test)

Aggregations

IStructuredDocument (org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument)432 IDOMModel (org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel)96 IStructuredModel (org.eclipse.wst.sse.core.internal.provisional.IStructuredModel)79 IStructuredDocumentRegion (org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion)68 CSSCleanupStrategy (org.eclipse.wst.css.core.internal.cleanup.CSSCleanupStrategy)44 Node (org.w3c.dom.Node)42 ICSSModel (org.eclipse.wst.css.core.internal.provisional.document.ICSSModel)41 Document (org.w3c.dom.Document)36 BadLocationException (org.eclipse.jface.text.BadLocationException)35 IndexedRegion (org.eclipse.wst.sse.core.internal.provisional.IndexedRegion)34 IDOMNode (org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode)34 ITextRegion (org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion)33 Element (org.w3c.dom.Element)30 IDocument (org.eclipse.jface.text.IDocument)29 IDOMDocument (org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument)28 IModelManager (org.eclipse.wst.sse.core.internal.provisional.IModelManager)26 StructuredDocumentEvent (org.eclipse.wst.sse.core.internal.provisional.events.StructuredDocumentEvent)23 Test (org.junit.Test)22 INodeAdapter (org.eclipse.wst.sse.core.internal.provisional.INodeAdapter)20 RegionChangedEvent (org.eclipse.wst.sse.core.internal.provisional.events.RegionChangedEvent)20