Search in sources :

Example 36 with ICSSModel

use of org.eclipse.wst.css.core.internal.provisional.document.ICSSModel in project webtools.sourceediting by eclipse.

the class TestCSSDecl method testInsertPropertyInExistingRule.

/**
 * To test https://bugs.eclipse.org/298111
 */
public void testInsertPropertyInExistingRule() {
    ICSSModel model = FileUtil.createModel();
    try {
        String originalDocument = "@CHARSET \"ISO-8859-1\";\r\n" + ".test {\r\n" + "}";
        IStructuredDocument structuredDocument = model.getStructuredDocument();
        structuredDocument.set(originalDocument);
        IndexedRegion indexedRegion = model.getIndexedRegion(28);
        assertTrue("Indexed region should be an ICSSStyleRule", indexedRegion instanceof ICSSStyleRule);
        ICSSStyleRule rule = (ICSSStyleRule) indexedRegion;
        ICSSStyleDeclaration declaration = (ICSSStyleDeclaration) rule.getStyle();
        declaration.setProperty("color", "#008040", null);
        CSSPropertyContext context = new CSSPropertyContext(declaration);
        context.applyModified(declaration);
        String newDocument = structuredDocument.get();
        String expectedNewDocument = "@CHARSET \"ISO-8859-1\";\r\n" + ".test {\r\n" + "\tcolor: #008040\r\n" + "}";
        assertEquals("The updated CSS document does not equal the expected", expectedNewDocument, newDocument);
    } finally {
        if (model != null) {
            model.releaseFromEdit();
        }
    }
}
Also used : ICSSModel(org.eclipse.wst.css.core.internal.provisional.document.ICSSModel) ICSSStyleDeclaration(org.eclipse.wst.css.core.internal.provisional.document.ICSSStyleDeclaration) IStructuredDocument(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument) IndexedRegion(org.eclipse.wst.sse.core.internal.provisional.IndexedRegion) ICSSStyleRule(org.eclipse.wst.css.core.internal.provisional.document.ICSSStyleRule) CSSPropertyContext(org.eclipse.wst.css.core.internal.util.declaration.CSSPropertyContext)

Example 37 with ICSSModel

use of org.eclipse.wst.css.core.internal.provisional.document.ICSSModel in project webtools.sourceediting by eclipse.

the class CSSSourceParserTest method readModelAppend.

private ICSSModel readModelAppend(String filename) throws IOException {
    String source = FileUtil.createString(FILES_DIR, filename);
    ICSSModel model = FileUtil.createModel();
    IStructuredDocument document = model.getStructuredDocument();
    for (int i = 0; i < source.length(); i++) {
        document.replaceText(null, i, 0, source.substring(i, i + 1));
    }
    return model;
}
Also used : ICSSModel(org.eclipse.wst.css.core.internal.provisional.document.ICSSModel) IStructuredDocument(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument)

Example 38 with ICSSModel

use of org.eclipse.wst.css.core.internal.provisional.document.ICSSModel in project webtools.sourceediting by eclipse.

the class CSSSourceParserTest method readModelOpen.

private ICSSModel readModelOpen(String filename) throws IOException {
    String source = FileUtil.createString(FILES_DIR, filename);
    ICSSModel model = FileUtil.createModel();
    IStructuredDocument document = model.getStructuredDocument();
    document.replaceText(null, 0, 0, source);
    return model;
}
Also used : ICSSModel(org.eclipse.wst.css.core.internal.provisional.document.ICSSModel) IStructuredDocument(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument)

Example 39 with ICSSModel

use of org.eclipse.wst.css.core.internal.provisional.document.ICSSModel in project webtools.sourceediting by eclipse.

the class CSSUrlTest method testDeclaration2.

/**
 * Declaration: without quotes, with surrounded space
 */
public void testDeclaration2() {
    ICSSModel model = FileUtil.createModel();
    IStructuredDocument document = model.getStructuredDocument();
    ((CSSSourceParser) document.getParser()).setParserMode(CSSSourceParser.MODE_DECLARATION_VALUE);
    // $NON-NLS-1$
    document.set("background-image: url(  white space.gif  );");
    UrlInfo[] urls = pickupUrl(document);
    assertEquals(1, urls.length);
    assertEquals(CSSRegionContexts.CSS_DECLARATION_VALUE_URI, urls[0].getType());
    // $NON-NLS-1$
    assertEquals("white space.gif", urls[0].getUrl());
}
Also used : ICSSModel(org.eclipse.wst.css.core.internal.provisional.document.ICSSModel) IStructuredDocument(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument) CSSSourceParser(org.eclipse.wst.css.core.internal.parser.CSSSourceParser)

Example 40 with ICSSModel

use of org.eclipse.wst.css.core.internal.provisional.document.ICSSModel in project webtools.sourceediting by eclipse.

the class CSSUrlTest method testFixError2.

/**
 * Import rule and style rule: Two urls but parenthesis are missed, so
 * concatenated url is identified. By adding parenthesis, urls are
 * corrected.
 */
public void testFixError2() {
    ICSSModel model = FileUtil.createModel();
    IStructuredDocument document = model.getStructuredDocument();
    // ____________01234567890123456789012345678901234567890123456789012345678901234567890123456789
    // $NON-NLS-1$
    document.set("@import url(white space.css;LI { background-image: urlwhite space.gif); }");
    UrlInfo[] urls = pickupUrl(document);
    assertEquals(1, urls.length);
    assertEquals(CSSRegionContexts.CSS_URI, urls[0].getType());
    // $NON-NLS-1$
    assertEquals("white space.css;LI { background-image: urlwhite space.gif", urls[0].getUrl());
    // correct first url
    // $NON-NLS-1$
    document.replaceText(null, 27, 0, ")");
    urls = pickupUrl(document);
    assertEquals(1, urls.length);
    assertEquals(CSSRegionContexts.CSS_URI, urls[0].getType());
    // $NON-NLS-1$
    assertEquals("white space.css", urls[0].getUrl());
    // correct second url
    // $NON-NLS-1$
    document.replaceText(null, 55, 0, "(");
    urls = pickupUrl(document);
    assertEquals(2, urls.length);
    assertEquals(CSSRegionContexts.CSS_URI, urls[0].getType());
    // $NON-NLS-1$
    assertEquals("white space.css", urls[0].getUrl());
    assertEquals(CSSRegionContexts.CSS_DECLARATION_VALUE_URI, urls[1].getType());
    // $NON-NLS-1$
    assertEquals("white space.gif", urls[1].getUrl());
}
Also used : ICSSModel(org.eclipse.wst.css.core.internal.provisional.document.ICSSModel) IStructuredDocument(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument)

Aggregations

ICSSModel (org.eclipse.wst.css.core.internal.provisional.document.ICSSModel)82 IStructuredDocument (org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument)41 CSSRule (org.w3c.dom.css.CSSRule)21 CSSRuleList (org.w3c.dom.css.CSSRuleList)20 IStructuredModel (org.eclipse.wst.sse.core.internal.provisional.IStructuredModel)15 CSSStyleDeclaration (org.w3c.dom.css.CSSStyleDeclaration)14 CSSStyleSheet (org.w3c.dom.css.CSSStyleSheet)14 CSSValue (org.w3c.dom.css.CSSValue)14 ICSSDocument (org.eclipse.wst.css.core.internal.provisional.document.ICSSDocument)12 IDOMNode (org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode)12 ICSSNode (org.eclipse.wst.css.core.internal.provisional.document.ICSSNode)11 IModelProvideAdapter (org.eclipse.wst.css.core.internal.provisional.adapters.IModelProvideAdapter)8 CSSSourceParser (org.eclipse.wst.css.core.internal.parser.CSSSourceParser)7 INodeNotifier (org.eclipse.wst.sse.core.internal.provisional.INodeNotifier)7 CSSStyleRule (org.w3c.dom.css.CSSStyleRule)7 IFile (org.eclipse.core.resources.IFile)6 Path (org.eclipse.core.runtime.Path)6 CSSSourceFormatter (org.eclipse.wst.css.core.internal.formatter.CSSSourceFormatter)6 IndexedRegion (org.eclipse.wst.sse.core.internal.provisional.IndexedRegion)6 Element (org.w3c.dom.Element)6