use of org.w3c.dom.css.CSSRule 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());
}
use of org.w3c.dom.css.CSSRule 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);
}
}
use of org.w3c.dom.css.CSSRule 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();
}
}
use of org.w3c.dom.css.CSSRule 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();
}
}
use of org.w3c.dom.css.CSSRule in project webtools.sourceediting by eclipse.
the class JFaceNodeContentProviderCSS method addElements.
/**
* @deprecated
*/
protected 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