Search in sources :

Example 1 with IStructuredTextPartitioner

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

the class TestStructuredPartitionerHTML method testGetPartitionType.

public void testGetPartitionType() {
    IStructuredModel model = null;
    try {
        model = getModelForEdit("testfiles/html/example01.xml");
        if (model != null) {
            IStructuredDocument sDoc = model.getStructuredDocument();
            assertTrue("sDoc implementation not instance of IDocumentExtension3", sDoc instanceof IDocumentExtension3);
            IDocumentPartitioner partitioner = ((IDocumentExtension3) sDoc).getDocumentPartitioner(IStructuredPartitioning.DEFAULT_STRUCTURED_PARTITIONING);
            assertTrue("paritioner doesn't implement IStructuredTextPartitioner", partitioner instanceof IStructuredTextPartitioner);
            IStructuredTextPartitioner stp = (IStructuredTextPartitioner) partitioner;
            String defaultPartitionType = stp.getDefaultPartitionType();
            assertTrue("wrong default partition type was: [" + defaultPartitionType + "] should be: [" + IXMLPartitions.XML_DEFAULT + "]", defaultPartitionType.equals(IXMLPartitions.XML_DEFAULT));
        } else {
            assertTrue("could not retrieve structured model", false);
        }
    } finally {
        if (model != null)
            model.releaseFromEdit();
    }
}
Also used : IDocumentExtension3(org.eclipse.jface.text.IDocumentExtension3) IDocumentPartitioner(org.eclipse.jface.text.IDocumentPartitioner) IStructuredDocument(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument) IStructuredModel(org.eclipse.wst.sse.core.internal.provisional.IStructuredModel) IStructuredTextPartitioner(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredTextPartitioner)

Example 2 with IStructuredTextPartitioner

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

the class TestStructuredPartitionerHTML method testDisconnectConnect.

public void testDisconnectConnect() {
    IStructuredModel model = null;
    try {
        model = getModelForEdit("testfiles/html/example01.xml");
        if (model != null) {
            IStructuredDocument sDoc = model.getStructuredDocument();
            assertTrue("sDoc implementation not instance of IDocumentExtension3", sDoc instanceof IDocumentExtension3);
            IDocumentPartitioner partitioner = ((IDocumentExtension3) sDoc).getDocumentPartitioner(IStructuredPartitioning.DEFAULT_STRUCTURED_PARTITIONING);
            assertTrue("partitioner doesn't implement IStructuredTextPartitioner", partitioner instanceof IStructuredTextPartitioner);
            IStructuredTextPartitioner stp = (IStructuredTextPartitioner) partitioner;
            assertNotNull("partitioner was null for sDoc:" + sDoc, partitioner);
            try {
                stp.disconnect();
            } catch (Exception e) {
                assertTrue("problem disconnecting w/:" + sDoc + "/n" + e, false);
            }
            try {
                stp.connect(sDoc);
            } catch (Exception e) {
                assertTrue("problem connecting w/:" + sDoc + "/n" + e, false);
            }
        } else {
            assertTrue("could not retrieve structured model", false);
        }
    } finally {
        if (model != null)
            model.releaseFromEdit();
    }
}
Also used : IDocumentExtension3(org.eclipse.jface.text.IDocumentExtension3) IDocumentPartitioner(org.eclipse.jface.text.IDocumentPartitioner) IStructuredDocument(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument) IStructuredModel(org.eclipse.wst.sse.core.internal.provisional.IStructuredModel) IStructuredTextPartitioner(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredTextPartitioner) IOException(java.io.IOException) BadLocationException(org.eclipse.jface.text.BadLocationException)

Example 3 with IStructuredTextPartitioner

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

the class StructuredTextPartitionerForJSP method createStructuredTextPartitioner.

private IStructuredTextPartitioner createStructuredTextPartitioner(IStructuredDocument structuredDocument) {
    IStructuredTextPartitioner result = null;
    // this same detector should underly content describer, to have consistent results
    JSPDocumentHeadContentDetector jspHeadContentDetector = new JSPDocumentHeadContentDetector();
    jspHeadContentDetector.set(structuredDocument);
    String contentType = null;
    try {
        contentType = jspHeadContentDetector.getContentType();
        // if XHTML or WML, that trumps what is in the page directive
        if (jspHeadContentDetector.isXHTML() || jspHeadContentDetector.isWML()) {
            contentType = "text/html";
        }
    } catch (IOException e) {
        // impossible in this context, since working with document stream
        throw new Error(e);
    }
    // null or empty, treat as "default"
    if (contentType == null || contentType.length() == 0) {
        // $NON-NLS-1$
        contentType = "text/html";
    }
    // make or tie-in to existing registry.
    if (contentType.equalsIgnoreCase(HTML_MIME_TYPE) || contentType.equalsIgnoreCase(VND_WAP_WML)) {
        result = new StructuredTextPartitionerForHTML();
        result.connect(structuredDocument);
    } else if (contentType.equalsIgnoreCase(XHTML_MIME_TYPE)) {
        result = new StructuredTextPartitionerForHTML();
        result.connect(structuredDocument);
    } else if (contentType.equalsIgnoreCase(XML_MIME_TYPE) || contentType.endsWith("+xml")) {
        // $NON-NLS-1$
        result = new StructuredTextPartitionerForXML();
        result.connect(structuredDocument);
    } else {
        result = new StructuredTextPartitioner();
        result.connect(structuredDocument);
    }
    return result;
}
Also used : JSPDocumentHeadContentDetector(org.eclipse.jst.jsp.core.internal.encoding.JSPDocumentHeadContentDetector) StructuredTextPartitionerForXML(org.eclipse.wst.xml.core.internal.text.rules.StructuredTextPartitionerForXML) StructuredTextPartitionerForHTML(org.eclipse.wst.html.core.internal.text.StructuredTextPartitionerForHTML) IOException(java.io.IOException) IStructuredTextPartitioner(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredTextPartitioner) StructuredTextPartitioner(org.eclipse.wst.sse.core.internal.text.rules.StructuredTextPartitioner) IStructuredTextPartitioner(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredTextPartitioner)

Example 4 with IStructuredTextPartitioner

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

the class TestStructuredPartitionerXML method testGetPartitionType.

public void testGetPartitionType() {
    IStructuredModel model = null;
    try {
        model = getModelForEdit("testfiles/xml/example01.xml");
        if (model != null) {
            IStructuredDocument sDoc = model.getStructuredDocument();
            assertTrue("sDoc implementation not instance of IDocumentExtension3", sDoc instanceof IDocumentExtension3);
            IDocumentPartitioner partitioner = ((IDocumentExtension3) sDoc).getDocumentPartitioner(IStructuredPartitioning.DEFAULT_STRUCTURED_PARTITIONING);
            assertTrue("paritioner doesn't implement IStructuredTextPartitioner", partitioner instanceof IStructuredTextPartitioner);
            IStructuredTextPartitioner stp = (IStructuredTextPartitioner) partitioner;
            String defaultPartitionType = stp.getDefaultPartitionType();
            assertTrue("wrong default partition type was: [" + defaultPartitionType + "] should be: [" + IXMLPartitions.XML_DEFAULT + "]", defaultPartitionType.equals(IXMLPartitions.XML_DEFAULT));
        } else {
            assertTrue("could not retrieve structured model", false);
        }
    } finally {
        if (model != null)
            model.releaseFromEdit();
    }
}
Also used : IDocumentExtension3(org.eclipse.jface.text.IDocumentExtension3) IDocumentPartitioner(org.eclipse.jface.text.IDocumentPartitioner) IStructuredDocument(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument) IStructuredModel(org.eclipse.wst.sse.core.internal.provisional.IStructuredModel) IStructuredTextPartitioner(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredTextPartitioner)

Example 5 with IStructuredTextPartitioner

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

the class TestStructuredPartitionerHTML method testGetDefaultPartitionType.

public void testGetDefaultPartitionType() {
    IStructuredModel model = null;
    try {
        model = getModelForEdit("testfiles/html/example01.xml");
        if (model != null) {
            IStructuredDocument sDoc = model.getStructuredDocument();
            assertTrue("sDoc implementation not instance of IDocumentExtension3", sDoc instanceof IDocumentExtension3);
            IDocumentPartitioner partitioner = ((IDocumentExtension3) sDoc).getDocumentPartitioner(IStructuredPartitioning.DEFAULT_STRUCTURED_PARTITIONING);
            assertTrue("partitioner doesn't implement IStructuredTextPartitioner", partitioner instanceof IStructuredTextPartitioner);
            IStructuredTextPartitioner stp = (IStructuredTextPartitioner) partitioner;
            String defaultPartitionType = stp.getDefaultPartitionType();
            assertTrue("wrong default partition type was: [" + defaultPartitionType + "] should be: [" + IXMLPartitions.XML_DEFAULT + "]", defaultPartitionType.equals(IXMLPartitions.XML_DEFAULT));
        } else {
            assertTrue("could not retrieve structured model", false);
        }
    } finally {
        if (model != null)
            model.releaseFromEdit();
    }
}
Also used : IDocumentExtension3(org.eclipse.jface.text.IDocumentExtension3) IDocumentPartitioner(org.eclipse.jface.text.IDocumentPartitioner) IStructuredDocument(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument) IStructuredModel(org.eclipse.wst.sse.core.internal.provisional.IStructuredModel) IStructuredTextPartitioner(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredTextPartitioner)

Aggregations

IStructuredTextPartitioner (org.eclipse.wst.sse.core.internal.provisional.text.IStructuredTextPartitioner)7 IDocumentExtension3 (org.eclipse.jface.text.IDocumentExtension3)6 IDocumentPartitioner (org.eclipse.jface.text.IDocumentPartitioner)6 IStructuredModel (org.eclipse.wst.sse.core.internal.provisional.IStructuredModel)6 IStructuredDocument (org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument)6 IOException (java.io.IOException)3 BadLocationException (org.eclipse.jface.text.BadLocationException)2 JSPDocumentHeadContentDetector (org.eclipse.jst.jsp.core.internal.encoding.JSPDocumentHeadContentDetector)1 StructuredTextPartitionerForHTML (org.eclipse.wst.html.core.internal.text.StructuredTextPartitionerForHTML)1 StructuredTextPartitioner (org.eclipse.wst.sse.core.internal.text.rules.StructuredTextPartitioner)1 StructuredTextPartitionerForXML (org.eclipse.wst.xml.core.internal.text.rules.StructuredTextPartitionerForXML)1