Java Code Examples for cz.vutbr.web.css.RuleSet#getSelectors()
The following examples show how to use
cz.vutbr.web.css.RuleSet#getSelectors() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AnalyzerUtil.java From jStyleParser with GNU Lesser General Public License v3.0 | 5 votes |
static List<Declaration> computeDeclarations(final Element e, final PseudoElementType pseudo, final OrderedRule[] clist, final ElementMatcher matcher, final MatchCondition matchCond) { // resulting list of declaration for this element with no pseudo-selectors (main list)(local cache) final List<Declaration> eldecl = new ArrayList<Declaration>(); // for all candidates for (final OrderedRule orule : clist) { final RuleSet rule = orule.getRule(); final StyleSheet sheet = rule.getStyleSheet(); final StyleSheet.Origin origin = (sheet == null) ? StyleSheet.Origin.AGENT : sheet.getOrigin(); // for all selectors inside for (final CombinedSelector s : rule.getSelectors()) { if (!AnalyzerUtil.matchSelector(s, e, matcher, matchCond)) { log.trace("CombinedSelector \"{}\" NOT matched!", s); continue; } log.trace("CombinedSelector \"{}\" matched", s); final PseudoElementType ptype = s.getPseudoElementType(); if (ptype == pseudo) { // add to the resulting list final CombinedSelector.Specificity spec = s.computeSpecificity(); for (final Declaration d : rule) eldecl.add(new AssignedDeclaration(d, spec, origin)); } } } // sort declarations Collections.sort(eldecl); //sort the main list log.debug("Sorted {} declarations.", eldecl.size()); log.trace("With values: {}", eldecl); return eldecl; }
Example 2
Source File: EscapingTest.java From jStyleParser with GNU Lesser General Public License v3.0 | 5 votes |
@Test public void testAttributes() throws IOException, CSSException { StyleSheet ss = CSSFactory.parseString(TEST_STRING13, null); assertEquals("One rule is set", 1, ss.size()); RuleSet rule = (RuleSet) ss.get(0); assertEquals("One combined selector", rule.getSelectors().length, 1); CombinedSelector cs = rule.getSelectors()[0]; assertEquals("One selector", cs.size(), 1); ElementAttribute attr = (ElementAttribute) cs.get(0).get(1); assertEquals("The attribute value", "text/plain", attr.getValue()); }
Example 3
Source File: EscapingTest.java From jStyleParser with GNU Lesser General Public License v3.0 | 5 votes |
private void assertSingleClassName(String input, String className, boolean positive) throws IOException, CSSException { StyleSheet ss = CSSFactory.parseString(input, null); assertEquals("One rule is set", 1, ss.size()); RuleSet rule = (RuleSet) ss.get(0); assertEquals("One combined selector", rule.getSelectors().length, 1); CombinedSelector cs = rule.getSelectors()[0]; assertEquals("One selector", cs.size(), 1); if (positive) assertEquals("The class name is correct", className, cs.get(0).getClassName()); else assertNotEquals("The class name is correct", className, cs.get(0).getClassName()); }
Example 4
Source File: EscapingTest.java From jStyleParser with GNU Lesser General Public License v3.0 | 5 votes |
private void assertSingleId(String input, String className) throws IOException, CSSException { StyleSheet ss = CSSFactory.parseString(input, null); assertEquals("One rule is set", 1, ss.size()); RuleSet rule = (RuleSet) ss.get(0); assertEquals("One combined selector", rule.getSelectors().length, 1); CombinedSelector cs = rule.getSelectors()[0]; assertEquals("One selector", cs.size(), 1); assertEquals("The class name is correct", className, cs.get(0).getIDName()); }
Example 5
Source File: RuleSetImpl.java From jStyleParser with GNU Lesser General Public License v3.0 | 4 votes |
/** * Shallow copy constructor * @param rs RuleSet to share selectors and declarations with */ protected RuleSetImpl(RuleSet rs) { super(); this.selectors = rs.getSelectors(); this.replaceAll(rs.asList()); }
Example 6
Source File: SelectorTest.java From jStyleParser with GNU Lesser General Public License v3.0 | 3 votes |
@Test public void testElementName() throws CSSException, IOException { StyleSheet ss = CSSFactory.parseString(TEST_MULTIPLE, null); assertEquals("One rule is set", 1, ss.size()); RuleSet rule = (RuleSet) ss.get(0); CombinedSelector[] cslist = rule.getSelectors(); assertEquals("Rule rule contains two selectors", 2, cslist.length); // H1 CombinedSelector s = cslist[0]; assertEquals("CombinedSelector 1 contains one simple selector", 1, s .size()); assertEquals("CombinedSelector contains element name", "H1", s.get(0) .getElementName()); // DIV s = cslist[1]; assertEquals("CombinedSelector 2 contains one simple selector", 1, s .size()); assertEquals("CombinedSelector contains element name", "DIV", s.get(0) .getElementName()); }