Search in sources :

Example 6 with CSSStyleRule

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

the class StyleSheetTest method testSimpleImport.

/**
 * Tests the simple case of a basic @import or a stylesheet
 * @throws Exception
 */
public void testSimpleImport() throws Exception {
    String filePath = "/" + PROJECT_NAME + "/WebContent/site.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);
                String[] rules = new String[] { "#content", "a", "a:hover" };
                assertTrue("There should be a total of 3 rules supplied stylesheet.", list.getLength() == rules.length);
                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);
                    CSSStyleRule style = (CSSStyleRule) rule;
                    assertEquals("Selector text did not match.", rules[i], style.getSelectorText().trim());
                }
            }
        }
    } 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) CSSStyleRule(org.w3c.dom.css.CSSStyleRule) 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 7 with CSSStyleRule

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

the class CSSStyleRuleTest method testInsertTextNumbers.

public void testInsertTextNumbers() throws IOException {
    ICSSModel model = getModel();
    IStructuredDocument structuredDocument = model.getStructuredDocument();
    structuredDocument.set(FileUtil.createString("src/org/eclipse/wst/css/core/tests/testfiles", "CSSStyleRuleTest.css"));
    CSSStyleSheet sheet = (CSSStyleSheet) model.getDocument();
    CSSRuleList ruleList = sheet.getCssRules();
    assertEquals(3, ruleList.getLength());
    CSSRule rule;
    CSSStyleDeclaration declaration;
    CSSValue value;
    rule = ruleList.item(0);
    assertEquals(CSSRule.STYLE_RULE, rule.getType());
    assertTrue(rule instanceof CSSStyleRule);
    declaration = ((CSSStyleRule) rule).getStyle();
    assertEquals(20, declaration.getLength());
    // 01
    value = declaration.getPropertyCSSValue("NUMBER");
    checkPrimitiveNumber(value, new PrimitiveNumber(CSSPrimitiveValue.CSS_NUMBER, 123.456f));
    // 02
    value = declaration.getPropertyCSSValue("PERCENTAGE");
    checkPrimitiveNumber(value, new PrimitiveNumber(CSSPrimitiveValue.CSS_PERCENTAGE, 123.456f));
    // 03
    value = declaration.getPropertyCSSValue("EMS");
    checkPrimitiveNumber(value, new PrimitiveNumber(CSSPrimitiveValue.CSS_EMS, 123.456f));
    // 04
    value = declaration.getPropertyCSSValue("EXS");
    checkPrimitiveNumber(value, new PrimitiveNumber(CSSPrimitiveValue.CSS_EXS, 123.456f));
    // 05
    value = declaration.getPropertyCSSValue("PX");
    checkPrimitiveNumber(value, new PrimitiveNumber(CSSPrimitiveValue.CSS_PX, +123.456f));
    value = declaration.getPropertyCSSValue("PX2");
    checkPrimitiveNumber(value, new PrimitiveNumber(CSSPrimitiveValue.CSS_PX, -123f));
    // 06
    value = declaration.getPropertyCSSValue("CM");
    checkPrimitiveNumber(value, new PrimitiveNumber(CSSPrimitiveValue.CSS_CM, 123.456f));
    // 07
    value = declaration.getPropertyCSSValue("MM");
    checkPrimitiveNumber(value, new PrimitiveNumber(CSSPrimitiveValue.CSS_MM, 123.456f));
    // 08
    value = declaration.getPropertyCSSValue("IN");
    checkPrimitiveNumber(value, new PrimitiveNumber(CSSPrimitiveValue.CSS_IN, 123.456f));
    // 09
    value = declaration.getPropertyCSSValue("PT");
    checkPrimitiveNumber(value, new PrimitiveNumber(CSSPrimitiveValue.CSS_PT, 123.456f));
    // 10
    value = declaration.getPropertyCSSValue("PC");
    checkPrimitiveNumber(value, new PrimitiveNumber(CSSPrimitiveValue.CSS_PC, 123.456f));
    // 11
    value = declaration.getPropertyCSSValue("DEG");
    checkPrimitiveNumber(value, new PrimitiveNumber(CSSPrimitiveValue.CSS_DEG, -123.456f));
    // 12
    value = declaration.getPropertyCSSValue("RAD");
    checkPrimitiveNumber(value, new PrimitiveNumber(CSSPrimitiveValue.CSS_RAD, 123.456f));
    // 13
    value = declaration.getPropertyCSSValue("GRAD");
    checkPrimitiveNumber(value, new PrimitiveNumber(CSSPrimitiveValue.CSS_GRAD, 123.456f));
    // 14
    value = declaration.getPropertyCSSValue("MS");
    checkPrimitiveNumber(value, new PrimitiveNumber(CSSPrimitiveValue.CSS_MS, 123.456f));
    // 15
    value = declaration.getPropertyCSSValue("S");
    checkPrimitiveNumber(value, new PrimitiveNumber(CSSPrimitiveValue.CSS_S, 123.456f));
    // 16
    value = declaration.getPropertyCSSValue("HZ");
    checkPrimitiveNumber(value, new PrimitiveNumber(CSSPrimitiveValue.CSS_HZ, 123.456f));
    // 17
    value = declaration.getPropertyCSSValue("KHZ");
    checkPrimitiveNumber(value, new PrimitiveNumber(CSSPrimitiveValue.CSS_KHZ, 123.456f));
    // 18
    value = declaration.getPropertyCSSValue("DIMENSION");
    checkPrimitiveNumber(value, new PrimitiveNumber(CSSPrimitiveValue.CSS_DIMENSION, -123.456f));
    // 19
    value = declaration.getPropertyCSSValue("INTEGER");
    checkPrimitiveNumber(value, new PrimitiveNumber(ICSSPrimitiveValue.CSS_INTEGER, 123));
}
Also used : CSSValue(org.w3c.dom.css.CSSValue) CSSRule(org.w3c.dom.css.CSSRule) ICSSModel(org.eclipse.wst.css.core.internal.provisional.document.ICSSModel) CSSStyleRule(org.w3c.dom.css.CSSStyleRule) CSSStyleSheet(org.w3c.dom.css.CSSStyleSheet) IStructuredDocument(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument) CSSStyleDeclaration(org.w3c.dom.css.CSSStyleDeclaration) CSSRuleList(org.w3c.dom.css.CSSRuleList)

Example 8 with CSSStyleRule

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

the class CSSStyleRuleTest method testInsertTextFunctions.

public void testInsertTextFunctions() throws IOException {
    ICSSModel model = getModel();
    IStructuredDocument structuredDocument = model.getStructuredDocument();
    structuredDocument.set(FileUtil.createString("src/org/eclipse/wst/css/core/tests/testfiles", "CSSStyleRuleTest.css"));
    CSSStyleSheet sheet = (CSSStyleSheet) model.getDocument();
    CSSRuleList ruleList = sheet.getCssRules();
    assertEquals(3, ruleList.getLength());
    CSSRule rule;
    CSSStyleDeclaration declaration;
    CSSValue value;
    rule = ruleList.item(2);
    assertEquals(CSSRule.STYLE_RULE, rule.getType());
    assertTrue(rule instanceof CSSStyleRule);
    declaration = ((CSSStyleRule) rule).getStyle();
    assertEquals(3, declaration.getLength());
    value = declaration.getPropertyCSSValue("COUNTER");
    checkPrimitiveCounter(value, "par-num", "upper-roman", null);
    value = declaration.getPropertyCSSValue("RECT");
    checkPrimitiveRect(value, new Object[] { new PrimitiveNumber(ICSSPrimitiveValue.CSS_INTEGER, 12), new PrimitiveNumber(ICSSPrimitiveValue.CSS_INTEGER, 34), new PrimitiveNumber(ICSSPrimitiveValue.CSS_INTEGER, 56), new PrimitiveNumber(ICSSPrimitiveValue.CSS_INTEGER, 78) });
    value = declaration.getPropertyCSSValue("RGBCOLOR");
    checkPrimitiveRgb(value, new Object[] { new PrimitiveNumber(ICSSPrimitiveValue.CSS_INTEGER, 255), new PrimitiveNumber(ICSSPrimitiveValue.CSS_INTEGER, 128), new PrimitiveNumber(ICSSPrimitiveValue.CSS_INTEGER, 0) });
}
Also used : CSSValue(org.w3c.dom.css.CSSValue) CSSRule(org.w3c.dom.css.CSSRule) ICSSModel(org.eclipse.wst.css.core.internal.provisional.document.ICSSModel) CSSStyleRule(org.w3c.dom.css.CSSStyleRule) CSSStyleSheet(org.w3c.dom.css.CSSStyleSheet) IStructuredDocument(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument) CSSStyleDeclaration(org.w3c.dom.css.CSSStyleDeclaration) CSSRuleList(org.w3c.dom.css.CSSRuleList)

Aggregations

CSSStyleRule (org.w3c.dom.css.CSSStyleRule)8 ICSSModel (org.eclipse.wst.css.core.internal.provisional.document.ICSSModel)7 CSSRule (org.w3c.dom.css.CSSRule)7 CSSRuleList (org.w3c.dom.css.CSSRuleList)7 IStructuredDocument (org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument)5 CSSStyleDeclaration (org.w3c.dom.css.CSSStyleDeclaration)5 CSSStyleSheet (org.w3c.dom.css.CSSStyleSheet)5 CSSValue (org.w3c.dom.css.CSSValue)5 IFile (org.eclipse.core.resources.IFile)2 Path (org.eclipse.core.runtime.Path)2 ICSSDocument (org.eclipse.wst.css.core.internal.provisional.document.ICSSDocument)2 ICSSStyleSheet (org.eclipse.wst.css.core.internal.provisional.document.ICSSStyleSheet)2 ICSSValue (org.eclipse.wst.css.core.internal.provisional.document.ICSSValue)2 IStructuredModel (org.eclipse.wst.sse.core.internal.provisional.IStructuredModel)2