Search in sources :

Example 11 with NullInputStream

use of org.eclipse.wst.sse.core.internal.encoding.util.NullInputStream in project webtools.sourceediting by eclipse.

the class FileUtil method createHTMLModel.

public static IDOMModel createHTMLModel() {
    IStructuredModel model = null;
    try {
        IModelManager modelManager = StructuredModelManager.getModelManager();
        // $NON-NLS-1$
        model = modelManager.getModelForEdit("test" + uniqueNum++ + ".html", new NullInputStream(), null);
        // always use the same line delimiter for these tests, regardless
        // of plaform or preference settings
        model.getStructuredDocument().setLineDelimiter(commonEOL);
    } catch (Exception e) {
        e.printStackTrace();
    }
    return (IDOMModel) model;
}
Also used : IDOMModel(org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel) IModelManager(org.eclipse.wst.sse.core.internal.provisional.IModelManager) IStructuredModel(org.eclipse.wst.sse.core.internal.provisional.IStructuredModel) IOException(java.io.IOException) NullInputStream(org.eclipse.wst.sse.core.internal.encoding.util.NullInputStream)

Example 12 with NullInputStream

use of org.eclipse.wst.sse.core.internal.encoding.util.NullInputStream in project webtools.sourceediting by eclipse.

the class ModelModifications method createJSPModel.

/**
 * Be sure to release any models obtained from this method.
 *
 * @return
 * @throws IOException
 * @throws UnsupportedEncodingException
 */
private static IDOMModel createJSPModel() throws UnsupportedEncodingException, IOException {
    IStructuredModel model = null;
    IModelManager modelManager = StructuredModelManager.getModelManager();
    model = modelManager.getModelForEdit("test.xml", new NullInputStream(), null);
    // always use the same line delimiter for these tests, regardless
    // of
    // plaform or preference settings
    model.getStructuredDocument().setLineDelimiter(TestWriter.commonEOL);
    return (IDOMModel) model;
}
Also used : IDOMModel(org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel) IModelManager(org.eclipse.wst.sse.core.internal.provisional.IModelManager) IStructuredModel(org.eclipse.wst.sse.core.internal.provisional.IStructuredModel) NullInputStream(org.eclipse.wst.sse.core.internal.encoding.util.NullInputStream)

Example 13 with NullInputStream

use of org.eclipse.wst.sse.core.internal.encoding.util.NullInputStream in project webtools.sourceediting by eclipse.

the class ModelModifications method createHTMLModel.

/**
 * Be sure to release any models obtained from this method.
 *
 * @return
 * @throws IOException
 * @throws UnsupportedEncodingException
 */
private static IDOMModel createHTMLModel() throws UnsupportedEncodingException, IOException {
    IStructuredModel model = null;
    IModelManager modelManager = StructuredModelManager.getModelManager();
    model = modelManager.getModelForEdit("test.html", new NullInputStream(), null);
    // always use the same line delimiter for these tests, regardless
    // of
    // plaform or preference settings
    model.getStructuredDocument().setLineDelimiter(TestWriter.commonEOL);
    return (IDOMModel) model;
}
Also used : IDOMModel(org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel) IModelManager(org.eclipse.wst.sse.core.internal.provisional.IModelManager) IStructuredModel(org.eclipse.wst.sse.core.internal.provisional.IStructuredModel) NullInputStream(org.eclipse.wst.sse.core.internal.encoding.util.NullInputStream)

Example 14 with NullInputStream

use of org.eclipse.wst.sse.core.internal.encoding.util.NullInputStream in project webtools.sourceediting by eclipse.

the class RegionChangedAdapterNotificationTests method testAppendWhitespaceToAttributeValue.

public void testAppendWhitespaceToAttributeValue() throws IOException {
    IDOMModel model = (IDOMModel) StructuredModelManager.getModelManager().getModelForEdit(getName() + ".xml", new NullInputStream(), null);
    try {
        Document document = model.getDocument();
        IStructuredDocument structuredDocument = model.getStructuredDocument();
        structuredDocument.setText(this, "<a b= c></a>");
        Node before = document.getFirstChild();
        final int[] changed = new int[] { -1 };
        INodeAdapter adapter = new INodeAdapter() {

            public boolean isAdapterForType(Object type) {
                return type.equals(RegionChangedAdapterNotificationTests.class);
            }

            public void notifyChanged(INodeNotifier notifier, int eventType, Object changedFeature, Object oldValue, Object newValue, int pos) {
                changed[0] = eventType;
            }
        };
        ((INodeNotifier) before).addAdapter(adapter);
        Object[] originalRegions = structuredDocument.getFirstStructuredDocumentRegion().getRegions().toArray();
        StructuredDocumentEvent fmEvent = structuredDocument.replaceText(null, 7, 0, " ");
        assertTrue("Region instances changed", Arrays.equals(originalRegions, structuredDocument.getFirstStructuredDocumentRegion().getRegions().toArray()));
        assertTrue(fmEvent instanceof RegionChangedEvent);
        Node after = document.getFirstChild();
        assertEquals("Node replaced", before, after);
        assertEquals("unexpected adapter notification event sent " + structuredDocument.get(), -1, changed[0]);
        assertEquals("unexpected document content", "<a b= c ></a>", structuredDocument.get());
    } finally {
        model.releaseFromEdit();
    }
}
Also used : StructuredDocumentEvent(org.eclipse.wst.sse.core.internal.provisional.events.StructuredDocumentEvent) INodeAdapter(org.eclipse.wst.sse.core.internal.provisional.INodeAdapter) RegionChangedEvent(org.eclipse.wst.sse.core.internal.provisional.events.RegionChangedEvent) IDOMModel(org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel) Node(org.w3c.dom.Node) IStructuredDocument(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument) Document(org.w3c.dom.Document) IStructuredDocument(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument) INodeNotifier(org.eclipse.wst.sse.core.internal.provisional.INodeNotifier) NullInputStream(org.eclipse.wst.sse.core.internal.encoding.util.NullInputStream)

Example 15 with NullInputStream

use of org.eclipse.wst.sse.core.internal.encoding.util.NullInputStream in project webtools.sourceediting by eclipse.

the class RegionChangedAdapterNotificationTests method testChangeTagName2.

public void testChangeTagName2() throws IOException {
    IDOMModel model = (IDOMModel) StructuredModelManager.getModelManager().getModelForEdit(getName() + ".xml", new NullInputStream(), null);
    try {
        Document document = model.getDocument();
        IStructuredDocument structuredDocument = model.getStructuredDocument();
        structuredDocument.setText(this, "<a b= c></a>");
        Node before = document.getFirstChild();
        final int[] changed = new int[] { -1 };
        INodeAdapter adapter = new INodeAdapter() {

            public boolean isAdapterForType(Object type) {
                return type.equals(RegionChangedAdapterNotificationTests.class);
            }

            public void notifyChanged(INodeNotifier notifier, int eventType, Object changedFeature, Object oldValue, Object newValue, int pos) {
                changed[0] = eventType;
            }
        };
        ((INodeNotifier) document).addAdapter(adapter);
        Object[] originalRegions = structuredDocument.getFirstStructuredDocumentRegion().getRegions().toArray();
        StructuredDocumentEvent fmEvent = structuredDocument.replaceText(null, 2, 0, "d");
        assertTrue("Region instances changed", Arrays.equals(originalRegions, structuredDocument.getFirstStructuredDocumentRegion().getRegions().toArray()));
        assertTrue(fmEvent instanceof RegionChangedEvent);
        Node after = document.getFirstChild();
        assertNotSame("DOM Node not replaced", before, after);
        assertEquals("Structure Changed notification not sent to adapter " + changed[0] + " to parent " + structuredDocument.get(), INodeNotifier.STRUCTURE_CHANGED, changed[0]);
        assertEquals("unexpected document content", "<ad b= c></a>", structuredDocument.get());
    } finally {
        model.releaseFromEdit();
    }
}
Also used : StructuredDocumentEvent(org.eclipse.wst.sse.core.internal.provisional.events.StructuredDocumentEvent) INodeAdapter(org.eclipse.wst.sse.core.internal.provisional.INodeAdapter) RegionChangedEvent(org.eclipse.wst.sse.core.internal.provisional.events.RegionChangedEvent) IDOMModel(org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel) Node(org.w3c.dom.Node) IStructuredDocument(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument) Document(org.w3c.dom.Document) IStructuredDocument(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument) INodeNotifier(org.eclipse.wst.sse.core.internal.provisional.INodeNotifier) NullInputStream(org.eclipse.wst.sse.core.internal.encoding.util.NullInputStream)

Aggregations

NullInputStream (org.eclipse.wst.sse.core.internal.encoding.util.NullInputStream)24 IDOMModel (org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel)22 INodeAdapter (org.eclipse.wst.sse.core.internal.provisional.INodeAdapter)18 INodeNotifier (org.eclipse.wst.sse.core.internal.provisional.INodeNotifier)18 RegionChangedEvent (org.eclipse.wst.sse.core.internal.provisional.events.RegionChangedEvent)18 StructuredDocumentEvent (org.eclipse.wst.sse.core.internal.provisional.events.StructuredDocumentEvent)18 IStructuredDocument (org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument)18 Document (org.w3c.dom.Document)18 Node (org.w3c.dom.Node)18 IModelManager (org.eclipse.wst.sse.core.internal.provisional.IModelManager)4 IStructuredModel (org.eclipse.wst.sse.core.internal.provisional.IStructuredModel)4 BufferedInputStream (java.io.BufferedInputStream)2 InputStream (java.io.InputStream)2 IOException (java.io.IOException)1 CoreException (org.eclipse.core.runtime.CoreException)1 IContentDescription (org.eclipse.core.runtime.content.IContentDescription)1 IContentTypeManager (org.eclipse.core.runtime.content.IContentTypeManager)1