Search in sources :

Example 66 with ICSSModel

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

the class CSSUrlTest method testFixError3.

/**
 * Import rule: Url has only one quote, so it is not identified as url. By
 * removing quote, url is corrected.
 */
public void testFixError3() {
    ICSSModel model = FileUtil.createModel();
    IStructuredDocument document = model.getStructuredDocument();
    // ____________0123456789012345678901234567890
    // $NON-NLS-1$
    document.set("@import url(white space.css\");");
    UrlInfo[] urls = pickupUrl(document);
    assertEquals(0, urls.length);
    // correct url
    // $NON-NLS-1$
    document.replaceText(null, 27, 1, "");
    urls = pickupUrl(document);
    assertEquals(1, urls.length);
    assertEquals(CSSRegionContexts.CSS_URI, urls[0].getType());
    // $NON-NLS-1$
    assertEquals("white space.css", 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)

Example 67 with ICSSModel

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

the class CSSUrlTest method testDeclaration4.

/**
 * Declaration: with double quote
 */
public void testDeclaration4() {
    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 68 with ICSSModel

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

the class CSSUrlTest method testDeclaration5.

/**
 * Declaration: two urls
 */
public void testDeclaration5() {
    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); list-style-image: url(style image.gif);");
    UrlInfo[] urls = pickupUrl(document);
    assertEquals(2, urls.length);
    assertEquals(CSSRegionContexts.CSS_DECLARATION_VALUE_URI, urls[0].getType());
    // $NON-NLS-1$
    assertEquals("white space.gif", urls[0].getUrl());
    assertEquals(CSSRegionContexts.CSS_DECLARATION_VALUE_URI, urls[1].getType());
    // $NON-NLS-1$
    assertEquals("style image.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) CSSSourceParser(org.eclipse.wst.css.core.internal.parser.CSSSourceParser)

Example 69 with ICSSModel

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

the class CSSUrlTest method testFixError1.

/**
 * Declaration: Two urls but parenthesis are missed, so concatenated url
 * is identified. By adding parenthesis, urls are corrected.
 */
public void testFixError1() {
    ICSSModel model = FileUtil.createModel();
    IStructuredDocument document = model.getStructuredDocument();
    ((CSSSourceParser) document.getParser()).setParserMode(CSSSourceParser.MODE_DECLARATION_VALUE);
    // ____________01234567890123456789012345678901234567890123456789012345678901234567890123456789
    // $NON-NLS-1$
    document.set("background-image: url(white space.gif; list-style-image: urlstyle image.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; list-style-image: urlstyle image.gif", urls[0].getUrl());
    // correct first url
    // $NON-NLS-1$
    document.replaceText(null, 37, 0, ")");
    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());
    // correct second url
    // $NON-NLS-1$
    document.replaceText(null, 61, 0, "(");
    urls = pickupUrl(document);
    assertEquals(2, urls.length);
    assertEquals(CSSRegionContexts.CSS_DECLARATION_VALUE_URI, urls[0].getType());
    // $NON-NLS-1$
    assertEquals("white space.gif", urls[0].getUrl());
    assertEquals(CSSRegionContexts.CSS_DECLARATION_VALUE_URI, urls[1].getType());
    // $NON-NLS-1$
    assertEquals("style image.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) CSSSourceParser(org.eclipse.wst.css.core.internal.parser.CSSSourceParser)

Example 70 with ICSSModel

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

the class CSSUrlTest method testStyleRule1.

/**
 * Style rule: two urls
 */
public void testStyleRule1() {
    ICSSModel model = FileUtil.createModel();
    IStructuredDocument document = model.getStructuredDocument();
    // $NON-NLS-1$
    document.set("LI { background-image: url(white space.gif);\r\nlist-style-image: url(style image.gif); }");
    UrlInfo[] urls = pickupUrl(document);
    assertEquals(2, urls.length);
    assertEquals(CSSRegionContexts.CSS_DECLARATION_VALUE_URI, urls[0].getType());
    // $NON-NLS-1$
    assertEquals("white space.gif", urls[0].getUrl());
    assertEquals(CSSRegionContexts.CSS_DECLARATION_VALUE_URI, urls[1].getType());
    // $NON-NLS-1$
    assertEquals("style image.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