Search in sources :

Example 11 with CSSStyleDeclaration

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

the class CSSFontFaceRuleTest method testInsertRule.

public void testInsertRule() {
    final String RULE = "@font-face { font-family: \"Swiss 721\"; src: url(swiss721.pfr); /* The expanded Swiss 721 */ font-stretch: expanded; }";
    CSSStyleSheet sheet = getStyleSheet();
    assertEquals(0, sheet.insertRule(RULE, 0));
    CSSRuleList ruleList = sheet.getCssRules();
    CSSRule rule = ruleList.item(0);
    assertTrue(rule instanceof CSSFontFaceRule);
    CSSStyleDeclaration declaration = ((CSSFontFaceRule) rule).getStyle();
    assertEquals(3, declaration.getLength());
    CSSValue value;
    CSSPrimitiveValue primitiveValue;
    value = declaration.getPropertyCSSValue("font-family");
    assertTrue(value instanceof CSSPrimitiveValue);
    primitiveValue = (CSSPrimitiveValue) value;
    assertEquals(CSSPrimitiveValue.CSS_STRING, primitiveValue.getPrimitiveType());
    assertEquals("Swiss 721", primitiveValue.getStringValue());
    value = declaration.getPropertyCSSValue("src");
    assertTrue(value instanceof CSSPrimitiveValue);
    primitiveValue = (CSSPrimitiveValue) value;
    assertEquals(CSSPrimitiveValue.CSS_URI, primitiveValue.getPrimitiveType());
    assertEquals("swiss721.pfr", primitiveValue.getStringValue());
    value = declaration.getPropertyCSSValue("font-stretch");
    assertTrue(value instanceof CSSPrimitiveValue);
    primitiveValue = (CSSPrimitiveValue) value;
    assertEquals(CSSPrimitiveValue.CSS_IDENT, primitiveValue.getPrimitiveType());
    assertEquals("expanded", primitiveValue.getStringValue());
}
Also used : CSSValue(org.w3c.dom.css.CSSValue) CSSRule(org.w3c.dom.css.CSSRule) CSSStyleSheet(org.w3c.dom.css.CSSStyleSheet) CSSFontFaceRule(org.w3c.dom.css.CSSFontFaceRule) CSSPrimitiveValue(org.w3c.dom.css.CSSPrimitiveValue) ICSSPrimitiveValue(org.eclipse.wst.css.core.internal.provisional.document.ICSSPrimitiveValue) CSSStyleDeclaration(org.w3c.dom.css.CSSStyleDeclaration) CSSRuleList(org.w3c.dom.css.CSSRuleList)

Example 12 with CSSStyleDeclaration

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

the class CSSStyleRuleTest method testInsertTextStrings.

public void testInsertTextStrings() 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(1);
    assertEquals(CSSRule.STYLE_RULE, rule.getType());
    assertTrue(rule instanceof CSSStyleRule);
    declaration = ((CSSStyleRule) rule).getStyle();
    assertEquals(11, declaration.getLength());
    // 01
    value = declaration.getPropertyCSSValue("STRING");
    checkPrimitiveString(value, new PrimitiveString(CSSPrimitiveValue.CSS_STRING, "string"));
    // 02
    value = declaration.getPropertyCSSValue("URI");
    checkPrimitiveString(value, new PrimitiveString(CSSPrimitiveValue.CSS_URI, "http://www.ibm.com/"));
    // 03
    value = declaration.getPropertyCSSValue("IDENT");
    checkPrimitiveString(value, new PrimitiveString(CSSPrimitiveValue.CSS_IDENT, "left"));
    // 04
    value = declaration.getPropertyCSSValue("HASH");
    checkPrimitiveString(value, new PrimitiveString(ICSSPrimitiveValue.CSS_HASH, "#abcdef"));
    // 05
    value = declaration.getPropertyCSSValue("URANGE");
    checkPrimitiveString(value, new PrimitiveString(ICSSPrimitiveValue.CSS_URANGE, "U+20A7"));
    // 06
    value = declaration.getPropertyCSSValue("SLASH");
    checkPrimitiveString(value, new PrimitiveString(ICSSPrimitiveValue.CSS_SLASH, "/"));
    // 07
    value = declaration.getPropertyCSSValue("COMMA");
    checkPrimitiveString(value, new PrimitiveString(ICSSPrimitiveValue.CSS_COMMA, ","));
    // 08
    value = declaration.getPropertyCSSValue("INHERIT_PRIMITIVE");
    checkPrimitiveString(value, new PrimitiveString(ICSSPrimitiveValue.CSS_INHERIT_PRIMITIVE, "inherit"));
    // 09
    value = declaration.getPropertyCSSValue("ATTR");
    checkPrimitiveString(value, new PrimitiveString(CSSPrimitiveValue.CSS_ATTR, "KEY"));
    // 10
    value = declaration.getPropertyCSSValue("FORMAT");
    checkPrimitiveString(value, new PrimitiveString(ICSSPrimitiveValue.CSS_FORMAT, "truedoc"));
    // 11
    value = declaration.getPropertyCSSValue("LOCAL");
    checkPrimitiveString(value, new PrimitiveString(ICSSPrimitiveValue.CSS_LOCAL, "Excelsior Roman"));
}
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 13 with CSSStyleDeclaration

use of org.w3c.dom.css.CSSStyleDeclaration in project kie-wb-common by kiegroup.

the class SVGStyleTranslator method parseElementStyleDefinition.

private static StyleDefinition parseElementStyleDefinition(final String styleRaw) throws TranslatorException {
    final CSSStyleSheetImpl sheet = parseElementStyleSheet(styleRaw);
    final CSSRuleList cssRules = sheet.getCssRules();
    for (int i = 0; i < cssRules.getLength(); i++) {
        final CSSRule item = cssRules.item(i);
        if (CSSRule.STYLE_RULE == item.getType()) {
            final CSSStyleRuleImpl rule = (CSSStyleRuleImpl) item;
            final CSSStyleDeclaration declaration = rule.getStyle();
            return parseStyleDefinition(declaration);
        }
    }
    return null;
}
Also used : CSSRule(org.w3c.dom.css.CSSRule) CSSStyleSheetImpl(com.steadystate.css.dom.CSSStyleSheetImpl) CSSStyleRuleImpl(com.steadystate.css.dom.CSSStyleRuleImpl) CSSStyleDeclaration(org.w3c.dom.css.CSSStyleDeclaration) CSSRuleList(org.w3c.dom.css.CSSRuleList)

Example 14 with CSSStyleDeclaration

use of org.w3c.dom.css.CSSStyleDeclaration in project kie-wb-common by kiegroup.

the class SVGStyleTranslator method parseStyleSheetDefinition.

public static StyleSheetDefinition parseStyleSheetDefinition(final String cssPath, final InputStream cssStream) throws TranslatorException {
    final CSSStyleSheetImpl sheet = parseStyleSheet(new InputSource(new InputStreamReader(cssStream)));
    final CSSRuleList cssRules = sheet.getCssRules();
    final StyleSheetDefinition result = new StyleSheetDefinition(cssPath);
    for (int i = 0; i < cssRules.getLength(); i++) {
        final CSSRule item = cssRules.item(i);
        if (CSSRule.STYLE_RULE == item.getType()) {
            final CSSStyleRuleImpl rule = (CSSStyleRuleImpl) item;
            final String selectorText = rule.getSelectorText();
            final CSSStyleDeclaration declaration = rule.getStyle();
            final StyleDefinition styleDefinition = parseStyleDefinition(declaration);
            result.addStyle(selectorText, styleDefinition);
        }
    }
    return result;
}
Also used : InputSource(org.w3c.css.sac.InputSource) CSSRule(org.w3c.dom.css.CSSRule) CSSStyleSheetImpl(com.steadystate.css.dom.CSSStyleSheetImpl) InputStreamReader(java.io.InputStreamReader) CSSStyleRuleImpl(com.steadystate.css.dom.CSSStyleRuleImpl) StyleSheetDefinition(org.kie.workbench.common.stunner.svg.gen.model.StyleSheetDefinition) CSSStyleDeclaration(org.w3c.dom.css.CSSStyleDeclaration) StyleDefinition(org.kie.workbench.common.stunner.svg.gen.model.StyleDefinition) CSSRuleList(org.w3c.dom.css.CSSRuleList)

Example 15 with CSSStyleDeclaration

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

the class CSSFontFamilyTest method testValueModification.

public void testValueModification() throws IOException {
    ICSSModel model = getModel();
    IStructuredDocument structuredDocument = model.getStructuredDocument();
    structuredDocument.set(FileUtil.createString("src/org/eclipse/wst/css/core/tests/testfiles", "CSSFontFamilyTest.css"));
    CSSStyleSheet sheet = (CSSStyleSheet) model.getDocument();
    CSSRuleList rules = sheet.getCssRules();
    assertEquals(4, rules.getLength());
    // Rule 1: No whitespace
    CSSRule rule;
    CSSStyleDeclaration declaration;
    CSSValue value;
    // Rule 1: No whitespace
    rule = rules.item(0);
    assertEquals(CSSRule.STYLE_RULE, rule.getType());
    assertTrue(rule instanceof CSSStyleRule);
    declaration = ((CSSStyleRule) rule).getStyle();
    value = declaration.getPropertyCSSValue(FONT_FAMILY);
    checkPrimitiveString(value, new PrimitiveString(CSSPrimitiveValue.CSS_IDENT, "Courier"));
    declaration.setProperty(FONT_FAMILY, "\"Times New Roman\", Times, serif", "");
    value = declaration.getPropertyCSSValue(FONT_FAMILY);
    assertTrue(value instanceof ICSSValue);
    assertEquals("\"Times New Roman\", Times, serif", ((ICSSValue) value).getCSSValueText());
    declaration.setProperty(FONT_FAMILY, "\"Times New Roman\", Times", "");
    value = declaration.getPropertyCSSValue(FONT_FAMILY);
    assertTrue(value instanceof ICSSValue);
    assertEquals("\"Times New Roman\", Times", ((ICSSValue) value).getCSSValueText());
}
Also used : ICSSValue(org.eclipse.wst.css.core.internal.provisional.document.ICSSValue) CSSValue(org.w3c.dom.css.CSSValue) CSSRule(org.w3c.dom.css.CSSRule) ICSSValue(org.eclipse.wst.css.core.internal.provisional.document.ICSSValue) 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

CSSStyleDeclaration (org.w3c.dom.css.CSSStyleDeclaration)24 CSSRule (org.w3c.dom.css.CSSRule)17 CSSRuleList (org.w3c.dom.css.CSSRuleList)17 CSSStyleSheet (org.w3c.dom.css.CSSStyleSheet)15 CSSValue (org.w3c.dom.css.CSSValue)15 ICSSModel (org.eclipse.wst.css.core.internal.provisional.document.ICSSModel)14 IStructuredDocument (org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument)14 CSSPageRule (org.w3c.dom.css.CSSPageRule)6 CSSStyleRule (org.w3c.dom.css.CSSStyleRule)5 CSSValueList (org.w3c.dom.css.CSSValueList)5 ICSSNode (org.eclipse.wst.css.core.internal.provisional.document.ICSSNode)4 CSSFontFaceRule (org.w3c.dom.css.CSSFontFaceRule)4 ICSSStyleDeclItem (org.eclipse.wst.css.core.internal.provisional.document.ICSSStyleDeclItem)3 CSSStyleRuleImpl (com.steadystate.css.dom.CSSStyleRuleImpl)2 CSSStyleSheetImpl (com.steadystate.css.dom.CSSStyleSheetImpl)2 ICSSValue (org.eclipse.wst.css.core.internal.provisional.document.ICSSValue)2 InputSource (org.w3c.css.sac.InputSource)2 CSSStylableElement (io.sf.carte.doc.dom4j.CSSStylableElement)1 InputStreamReader (java.io.InputStreamReader)1 StringReader (java.io.StringReader)1