Search in sources :

Example 36 with IStructuredDocument

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

the class StyleAttrAdapter method valueChanged.

/**
 */
private void valueChanged() {
    Element element = getElement();
    if (element == null)
        return;
    if (!isModelNecessary()) {
        // removed
        setModel(null);
        notifyStyleChanged(element);
        return;
    }
    ICSSModel model = getExistingModel();
    if (model == null)
        // defer
        return;
    IStructuredDocument structuredDocument = model.getStructuredDocument();
    if (structuredDocument == null)
        // error
        return;
    String value = null;
    Attr attr = element.getAttributeNode(org.eclipse.wst.html.core.internal.provisional.HTML40Namespace.ATTR_NAME_STYLE);
    if (attr != null)
        value = ((IDOMNode) attr).getValueSource();
    structuredDocument.setText(this, value);
    notifyStyleChanged(element);
}
Also used : ICSSModel(org.eclipse.wst.css.core.internal.provisional.document.ICSSModel) IDOMNode(org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode) Element(org.w3c.dom.Element) IStructuredDocument(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument) Attr(org.w3c.dom.Attr)

Example 37 with IStructuredDocument

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

the class TestHTMLValidator method testRemoveAndAddBackCommentEndTag.

/**
 * Regression test for Bug 285285
 *
 * @see org.eclipse.wst.xml.ui.internal.validation.TestDelegatingSourceValidatorForXML#testRemoveAndAddBackCommentEndTag
 * @see org.eclipse.wst.html.ui.tests.validation.TestHTMLValidator#testRemoveAndAddBackCommentEndTag
 * @see org.eclipse.jst.jsp.ui.tests.validation.JSPHTMLValidatorTest#testRemoveAndAddBackCommentEndTag
 */
public void testRemoveAndAddBackCommentEndTag() throws Exception {
    IFile testFile = null;
    IStructuredModel model = null;
    try {
        // get test file
        testFile = fProject.getFile("RemoveAndAddBackCommentEndTag.html");
        assertTrue("Test file " + testFile + " does not exist", testFile.exists());
        // get the document
        model = StructuredModelManager.getModelManager().getModelForEdit(testFile);
        IStructuredDocument document = model.getStructuredDocument();
        // set up for fValidator
        WorkbenchContext context = new WorkbenchContext();
        List fileList = new ArrayList();
        fileList.add(testFile.getFullPath().toPortableString());
        context.setValidationFileURIs(fileList);
        // validate clean file
        TestReporter reporter = new TestReporter();
        fValidator.validate(context, reporter);
        assertFalse("There should be no validation errors on " + testFile, reporter.isMessageReported());
        // need to dynamically find where the --> is because
        // its different on unix vs windows because of line endings
        String contents = document.get();
        int endCommentIndex = contents.indexOf("-->");
        // remove -->
        document.replace(endCommentIndex, 3, "");
        // validate file with error
        reporter = new TestReporter();
        fValidator.validate(context, reporter);
        assertTrue("There should be validation errors on " + testFile, reporter.isMessageReported());
        // replace -->
        document.replace(endCommentIndex, 0, "-->");
        // validate clean file
        reporter = new TestReporter();
        fValidator.validate(context, reporter);
        assertFalse("There should be no validation errors on " + testFile, reporter.isMessageReported());
    } finally {
        if (model != null) {
            model.releaseFromEdit();
        }
    }
}
Also used : IFile(org.eclipse.core.resources.IFile) WorkbenchContext(org.eclipse.wst.validation.internal.operations.WorkbenchContext) ArrayList(java.util.ArrayList) IStructuredDocument(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument) ArrayList(java.util.ArrayList) List(java.util.List) IStructuredModel(org.eclipse.wst.sse.core.internal.provisional.IStructuredModel)

Example 38 with IStructuredDocument

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

the class TestHTMLValidator method testInvalidateTagNameThenFix.

/**
 * Regression test for Bug 298472
 */
public void testInvalidateTagNameThenFix() throws Exception {
    IFile testFile = null;
    IStructuredModel model = null;
    try {
        // get test file
        testFile = fProject.getFile("InvalidateTagNameThenFix.html");
        assertTrue("Test file " + testFile + " does not exist", testFile.exists());
        // get the document
        model = StructuredModelManager.getModelManager().getModelForEdit(testFile);
        IStructuredDocument document = model.getStructuredDocument();
        // set up for validator
        WorkbenchContext context = new WorkbenchContext();
        List fileList = new ArrayList();
        fileList.add(testFile.getFullPath().toPortableString());
        context.setValidationFileURIs(fileList);
        // validate clean file
        TestReporter reporter = new TestReporter();
        fValidator.validate(context, reporter);
        assertFalse("There should be no validation errors on " + testFile, reporter.isMessageReported());
        // need to dynamically find where the --> is because
        // its different on unix vs windows because of line endings
        String contents = document.get();
        int endOfStartTagIndex = contents.indexOf("></div>");
        // change to <divx></div>
        document.replace(endOfStartTagIndex, 0, "x");
        // validate file with error
        reporter = new TestReporter();
        fValidator.validate(context, reporter);
        assertTrue("There should be validation errors on " + testFile, reporter.isMessageReported());
        // change back to <div></div>
        document.replace(endOfStartTagIndex, 1, "");
        // validate clean file
        reporter = new TestReporter();
        fValidator.validate(context, reporter);
        assertFalse("There should be no validation errors on " + testFile, reporter.isMessageReported());
    } finally {
        if (model != null) {
            model.releaseFromEdit();
        }
    }
}
Also used : IFile(org.eclipse.core.resources.IFile) WorkbenchContext(org.eclipse.wst.validation.internal.operations.WorkbenchContext) ArrayList(java.util.ArrayList) IStructuredDocument(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument) ArrayList(java.util.ArrayList) List(java.util.List) IStructuredModel(org.eclipse.wst.sse.core.internal.provisional.IStructuredModel)

Example 39 with IStructuredDocument

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

the class UpdaterTest13 method testModel.

public void testModel() {
    IDOMModel model = createXMLModel();
    try {
        IStructuredDocument structuredDocument = model.getStructuredDocument();
        Document document = model.getDocument();
        structuredDocument.replaceText(null, 0, 0, "<a>\r\n<b>\r\n</a>");
        Element a = (Element) document.getFirstChild();
        Element b = (Element) a.getLastChild();
        Text text = document.createTextNode("  ");
        a.appendChild(text);
        printSource(model);
        printTree(model);
        a.removeChild(b);
        printSource(model);
        printTree(model);
        saveAndCompareTestResults();
    } finally {
        model.releaseFromEdit();
    }
}
Also used : IDOMModel(org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel) Element(org.w3c.dom.Element) IStructuredDocument(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument) Text(org.w3c.dom.Text) Document(org.w3c.dom.Document) IStructuredDocument(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument)

Example 40 with IStructuredDocument

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

the class UpdaterTest5 method testModel.

public void testModel() {
    IDOMModel model = createXMLModel();
    try {
        Document document = model.getDocument();
        IStructuredDocument structuredDocument = model.getStructuredDocument();
        structuredDocument.setText(this, "<a>&apos;</a>");
        printSource(model);
        printTree(model);
        Node a = document.getFirstChild();
        Node t = a.getFirstChild();
        a.removeChild(t);
        a.appendChild(t);
        printSource(model);
        printTree(model);
        saveAndCompareTestResults();
    } finally {
        model.releaseFromEdit();
    }
}
Also used : 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)

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