Search in sources :

Example 6 with CSSRuleList

use of org.w3c.dom.css.CSSRuleList in project webtools.sourceediting by eclipse.

the class CSSStyleSheetTest method testInsertRule.

public void testInsertRule() {
    CSSStyleSheet sheet = getStyleSheet();
    assertEquals(0, sheet.insertRule(RULE_H3, 0));
    assertEquals(0, sheet.insertRule(RULE_H1, 0));
    assertEquals(1, sheet.insertRule(RULE_H2, 1));
    CSSRuleList ruleList = sheet.getCssRules();
    CSSRule rule;
    rule = ruleList.item(0);
    assertEquals(RULE_H1, rule.getCssText());
    rule = ruleList.item(1);
    assertEquals(RULE_H2, rule.getCssText());
    rule = ruleList.item(2);
    assertEquals(RULE_H3, rule.getCssText());
}
Also used : CSSRule(org.w3c.dom.css.CSSRule) CSSStyleSheet(org.w3c.dom.css.CSSStyleSheet) CSSRuleList(org.w3c.dom.css.CSSRuleList)

Example 7 with CSSRuleList

use of org.w3c.dom.css.CSSRuleList in project webtools.sourceediting by eclipse.

the class CSSStyleSheetTest method testDeleteRule.

public void testDeleteRule() {
    CSSStyleSheet sheet = getStyleSheet();
    assertEquals(0, sheet.insertRule(RULE_H3, 0));
    assertEquals(0, sheet.insertRule(RULE_H1, 0));
    assertEquals(1, sheet.insertRule(RULE_H2, 1));
    CSSRuleList ruleList;
    CSSRule rule;
    sheet.deleteRule(1);
    ruleList = sheet.getCssRules();
    rule = ruleList.item(0);
    assertEquals(RULE_H1, rule.getCssText());
    rule = ruleList.item(1);
    assertEquals(RULE_H3, rule.getCssText());
    sheet.deleteRule(1);
    ruleList = sheet.getCssRules();
    rule = ruleList.item(0);
    assertEquals(RULE_H1, rule.getCssText());
    sheet.deleteRule(0);
    try {
        sheet.deleteRule(0);
    } catch (DOMException e) {
        assertEquals(DOMException.INDEX_SIZE_ERR, e.code);
    }
}
Also used : DOMException(org.w3c.dom.DOMException) CSSRule(org.w3c.dom.css.CSSRule) CSSStyleSheet(org.w3c.dom.css.CSSStyleSheet) CSSRuleList(org.w3c.dom.css.CSSRuleList)

Example 8 with CSSRuleList

use of org.w3c.dom.css.CSSRuleList in project webtools.sourceediting by eclipse.

the class StyleSheetTest method testImportFromParentDirectory.

/**
 * Tests for the import of a stylesheet in a parent directory
 * @throws Exception
 */
public void testImportFromParentDirectory() throws Exception {
    String filePath = "/" + PROJECT_NAME + "/WebContent/style/sub.css";
    IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(new Path(filePath));
    assertTrue("File doesn't exist: " + filePath, file.exists());
    IStructuredModel model = null;
    try {
        model = StructuredModelManager.getModelManager().getModelForRead(file);
        if (model instanceof ICSSModel) {
            ICSSDocument document = ((ICSSModel) model).getDocument();
            if (document instanceof ICSSStyleSheet) {
                CSSRuleList list = ((ICSSStyleSheet) document).getCssRules(true);
                assertTrue("There should be a total of 1 rule.", list.getLength() == 1);
                CSSRule rule = list.item(0);
                assertTrue("Rule should be a style rule. rule.getType() == " + rule.getType(), rule.getType() == ICSSNode.STYLERULE_NODE);
                assertEquals("Stylesheet reference is different than expected.", ((CSSStyleRule) rule).getSelectorText(), "#content");
            }
        }
    } finally {
        if (model != null)
            model.releaseFromRead();
    }
}
Also used : Path(org.eclipse.core.runtime.Path) IFile(org.eclipse.core.resources.IFile) CSSRule(org.w3c.dom.css.CSSRule) ICSSModel(org.eclipse.wst.css.core.internal.provisional.document.ICSSModel) IStructuredModel(org.eclipse.wst.sse.core.internal.provisional.IStructuredModel) ICSSDocument(org.eclipse.wst.css.core.internal.provisional.document.ICSSDocument) ICSSStyleSheet(org.eclipse.wst.css.core.internal.provisional.document.ICSSStyleSheet) CSSRuleList(org.w3c.dom.css.CSSRuleList)

Example 9 with CSSRuleList

use of org.w3c.dom.css.CSSRuleList in project webtools.sourceediting by eclipse.

the class StyleSheetTest method testImportCycle.

/**
 * Tests for cycles in imports. If a cycle is encountered, we should not get stuck
 * in a loop or re-import the stylesheet.
 * @throws Exception
 */
public void testImportCycle() throws Exception {
    String filePath = "/" + PROJECT_NAME + "/WebContent/cycle0.css";
    IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(new Path(filePath));
    assertTrue("File doesn't exist: " + filePath, file.exists());
    IStructuredModel model = null;
    try {
        model = StructuredModelManager.getModelManager().getModelForRead(file);
        if (model instanceof ICSSModel) {
            ICSSDocument document = ((ICSSModel) model).getDocument();
            if (document instanceof ICSSStyleSheet) {
                CSSRuleList list = ((ICSSStyleSheet) document).getCssRules(true);
                assertTrue("There should be a total of 3 rules supplied stylesheet.", list.getLength() == 3);
                for (int i = 0; i < list.getLength(); i++) {
                    CSSRule rule = list.item(i);
                    assertTrue("Rule should be a style rule. rule.getType() == " + rule.getType(), rule.getType() == ICSSNode.STYLERULE_NODE);
                    // Check that the rules are imported, it would start with the last imported stylesheet's rules and move up
                    assertEquals("Style rules are not equal.", ((CSSStyleRule) rule).getSelectorText(), "#cycle" + (2 - i));
                }
            }
        }
    } finally {
        if (model != null)
            model.releaseFromRead();
    }
}
Also used : Path(org.eclipse.core.runtime.Path) IFile(org.eclipse.core.resources.IFile) CSSRule(org.w3c.dom.css.CSSRule) ICSSModel(org.eclipse.wst.css.core.internal.provisional.document.ICSSModel) IStructuredModel(org.eclipse.wst.sse.core.internal.provisional.IStructuredModel) ICSSDocument(org.eclipse.wst.css.core.internal.provisional.document.ICSSDocument) ICSSStyleSheet(org.eclipse.wst.css.core.internal.provisional.document.ICSSStyleSheet) CSSRuleList(org.w3c.dom.css.CSSRuleList)

Example 10 with CSSRuleList

use of org.w3c.dom.css.CSSRuleList in project webtools.sourceediting by eclipse.

the class CSSFontFaceRuleTest method _testInsertText1.

public void _testInsertText1() throws IOException {
    ICSSModel model = getModel();
    IStructuredDocument structuredDocument = model.getStructuredDocument();
    structuredDocument.set(FileUtil.createString("src/org/eclipse/wst/css/core/tests/testfiles", "CSSFontFaceRuleTest.css"));
    CSSStyleSheet sheet = (CSSStyleSheet) model.getDocument();
    CSSRuleList ruleList = sheet.getCssRules();
    assertEquals(3, ruleList.getLength());
    CSSRule rule;
    CSSStyleDeclaration declaration;
    CSSValue value;
    CSSValueList valueList;
    // rule 1
    rule = ruleList.item(0);
    assertEquals(CSSRule.FONT_FACE_RULE, rule.getType());
    assertTrue(rule instanceof CSSFontFaceRule);
    declaration = ((CSSFontFaceRule) rule).getStyle();
    assertEquals(4, declaration.getLength());
    value = declaration.getPropertyCSSValue("font-family");
    checkPrimitiveString(value, new PrimitiveString(CSSPrimitiveValue.CSS_STRING, "Swiss 721"));
    value = declaration.getPropertyCSSValue("src");
    checkPrimitiveString(value, new PrimitiveString(CSSPrimitiveValue.CSS_URI, "swiss721blk.pfr"));
    value = declaration.getPropertyCSSValue("font-style");
    assertTrue(value instanceof CSSValueList);
    valueList = (CSSValueList) value;
    assertEquals(3, valueList.getLength());
    checkPrimitiveString(valueList.item(0), new PrimitiveString(CSSPrimitiveValue.CSS_IDENT, "normal"));
    checkPrimitiveString(valueList.item(1), new PrimitiveString(ICSSPrimitiveValue.CSS_COMMA, ","));
    checkPrimitiveString(valueList.item(2), new PrimitiveString(CSSPrimitiveValue.CSS_IDENT, "italic"));
    value = declaration.getPropertyCSSValue("font-weight");
    assertTrue(value instanceof CSSValueList);
    valueList = (CSSValueList) value;
    assertEquals(3, valueList.getLength());
    checkPrimitiveNumber(valueList.item(0), new PrimitiveNumber(ICSSPrimitiveValue.CSS_INTEGER, 800));
    checkPrimitiveString(valueList.item(1), new PrimitiveString(ICSSPrimitiveValue.CSS_COMMA, ","));
    checkPrimitiveNumber(valueList.item(2), new PrimitiveNumber(ICSSPrimitiveValue.CSS_INTEGER, 900));
}
Also used : CSSValue(org.w3c.dom.css.CSSValue) CSSValueList(org.w3c.dom.css.CSSValueList) CSSRule(org.w3c.dom.css.CSSRule) ICSSModel(org.eclipse.wst.css.core.internal.provisional.document.ICSSModel) CSSStyleSheet(org.w3c.dom.css.CSSStyleSheet) CSSFontFaceRule(org.w3c.dom.css.CSSFontFaceRule) IStructuredDocument(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument) CSSStyleDeclaration(org.w3c.dom.css.CSSStyleDeclaration) CSSRuleList(org.w3c.dom.css.CSSRuleList)

Aggregations

CSSRuleList (org.w3c.dom.css.CSSRuleList)30 CSSRule (org.w3c.dom.css.CSSRule)29 ICSSModel (org.eclipse.wst.css.core.internal.provisional.document.ICSSModel)19 CSSStyleSheet (org.w3c.dom.css.CSSStyleSheet)19 CSSStyleDeclaration (org.w3c.dom.css.CSSStyleDeclaration)17 CSSValue (org.w3c.dom.css.CSSValue)15 IStructuredDocument (org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument)14 ICSSStyleSheet (org.eclipse.wst.css.core.internal.provisional.document.ICSSStyleSheet)10 ICSSDocument (org.eclipse.wst.css.core.internal.provisional.document.ICSSDocument)8 CSSStyleRule (org.w3c.dom.css.CSSStyleRule)7 IFile (org.eclipse.core.resources.IFile)6 CSSPageRule (org.w3c.dom.css.CSSPageRule)6 Path (org.eclipse.core.runtime.Path)5 IStructuredModel (org.eclipse.wst.sse.core.internal.provisional.IStructuredModel)5 CSSValueList (org.w3c.dom.css.CSSValueList)5 CSSFontFaceRule (org.w3c.dom.css.CSSFontFaceRule)4 CSSStyleRuleImpl (com.steadystate.css.dom.CSSStyleRuleImpl)2 CSSStyleSheetImpl (com.steadystate.css.dom.CSSStyleSheetImpl)2 ICSSImportRule (org.eclipse.wst.css.core.internal.provisional.document.ICSSImportRule)2 ICSSValue (org.eclipse.wst.css.core.internal.provisional.document.ICSSValue)2