Search in sources :

Example 16 with CSSRule

use of org.w3c.dom.css.CSSRule 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 17 with CSSRule

use of org.w3c.dom.css.CSSRule in project tdi-studio-se by Talend.

the class CSSParserUtils method generateCssStyle.

public static String generateCssStyle(String cssFile, CSSRuleList ruleList, String content) {
    String cssContents = calculateValue(getContents(cssFile));
    content = calculateValue(content);
    for (int i = 0; i < ruleList.getLength(); i++) {
        CSSRule item = ruleList.item(i);
        String text = item.getCssText();
        //$NON-NLS-1$
        Pattern p = Pattern.compile(".+\\{.*?\\}");
        Matcher matcher = p.matcher(text);
        if (matcher.matches()) {
            //$NON-NLS-1$
            String value = text.substring(0, text.indexOf("{"));
            // sometimes jdk api don't think string contains charseq if start with "*."
            if (value.startsWith("*.")) {
                //$NON-NLS-1$
                value = value.substring(2);
            }
            if (content.indexOf(value) != -1) {
                String cssTemStrings = content.substring(content.indexOf(value));
                String cssPart = cssTemStrings.substring(value.length());
                String originalValue = cssTemStrings.substring(0, value.length()) + //$NON-NLS-1$
                cssPart.substring(0, cssPart.indexOf("}") + 1);
                if (cssContents.indexOf(value) != -1) {
                    String temStrings = cssContents.substring(cssContents.indexOf(value));
                    String part = temStrings.substring(value.length());
                    //$NON-NLS-1$
                    String newValue = temStrings.substring(0, value.length()) + part.substring(0, part.indexOf("}") + 1);
                    content = content.replace(originalValue, newValue);
                }
            }
        }
    }
    return content;
}
Also used : Pattern(java.util.regex.Pattern) CSSRule(org.w3c.dom.css.CSSRule) Matcher(java.util.regex.Matcher)

Example 18 with CSSRule

use of org.w3c.dom.css.CSSRule 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 19 with CSSRule

use of org.w3c.dom.css.CSSRule 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 20 with CSSRule

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

the class CSSNodeAdapter method addElements.

private void addElements(Object element, ArrayList v) {
    ICSSNode node;
    if (element instanceof ICSSModel) {
        ICSSModel model = (ICSSModel) element;
        ICSSDocument doc = model.getDocument();
        node = doc.getFirstChild();
    } else if (element instanceof ICSSNode) {
        node = ((ICSSNode) element).getFirstChild();
    } else
        return;
    while (node != null) {
        if (node instanceof CSSRule) {
            v.add(node);
        }
        node = node.getNextSibling();
    }
}
Also used : CSSRule(org.w3c.dom.css.CSSRule) ICSSModel(org.eclipse.wst.css.core.internal.provisional.document.ICSSModel) ICSSNode(org.eclipse.wst.css.core.internal.provisional.document.ICSSNode) ICSSDocument(org.eclipse.wst.css.core.internal.provisional.document.ICSSDocument)

Aggregations

CSSRule (org.w3c.dom.css.CSSRule)33 CSSRuleList (org.w3c.dom.css.CSSRuleList)29 ICSSModel (org.eclipse.wst.css.core.internal.provisional.document.ICSSModel)21 CSSStyleSheet (org.w3c.dom.css.CSSStyleSheet)20 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)11 ICSSDocument (org.eclipse.wst.css.core.internal.provisional.document.ICSSDocument)10 CSSStyleRule (org.w3c.dom.css.CSSStyleRule)7 CSSPageRule (org.w3c.dom.css.CSSPageRule)6 IFile (org.eclipse.core.resources.IFile)5 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 ICSSImportRule (org.eclipse.wst.css.core.internal.provisional.document.ICSSImportRule)3 ICSSNode (org.eclipse.wst.css.core.internal.provisional.document.ICSSNode)3 CSSStyleRuleImpl (com.steadystate.css.dom.CSSStyleRuleImpl)2 CSSStyleSheetImpl (com.steadystate.css.dom.CSSStyleSheetImpl)2