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"));
}
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;
}
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;
}
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;
}
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();
}
}
Aggregations