本文整理汇总了Java中com.osbcp.cssparser.Selector类的典型用法代码示例。如果您正苦于以下问题:Java Selector类的具体用法?Java Selector怎么用?Java Selector使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Selector类属于com.osbcp.cssparser包,在下文中一共展示了Selector类的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: parseRules
import com.osbcp.cssparser.Selector; //导入依赖的package包/类
/**
* This method parses TagBasedRules from CSS rules
* @param rules The CSS rules
* @return The tag-based rules
*/
public static List<TagBasedRule> parseRules(List<Rule> rules) {
List<TagBasedRule> result = new ArrayList<TagBasedRule>(rules.size());
for(Rule r : rules) {
for(Selector s : r.getSelectors()) {
try {
result.add(new TagBasedRule(s, new ArrayList<PropertyValue>(r.getPropertyValues())));
} catch (ParseException e) {
System.err.println(e.getMessage());
}
}
}
return result;
}
示例2: setupCss
import com.osbcp.cssparser.Selector; //导入依赖的package包/类
private void setupCss(Box box, String strStyle) throws Exception {
Rule style = CSSParser.parseStyle(strStyle);
if (style.getPropertyValues().size() > 0) {
box.addRule(style);
}
for (Rule rule : cssrules) {
for (Selector selector : rule.getSelectors()) {
if (match(selector, box)) {
logger.debug(String.format("box %s matches selector %s",
box.getTag(), selector.toString()));
box.addRule(rule);
break;
}
}
}
}
示例3: compile
import com.osbcp.cssparser.Selector; //导入依赖的package包/类
public static CompiledRule compile( Rule rule, HtmlSpanner spanner ) {
Log.d("CSSCompiler", "Compiling rule " + rule );
List<List<TagNodeMatcher>> matchers = new ArrayList<List<TagNodeMatcher>>();
List<StyleUpdater> styleUpdaters = new ArrayList<StyleUpdater>();
for ( Selector selector: rule.getSelectors() ) {
List<CSSCompiler.TagNodeMatcher> selMatchers = CSSCompiler.createMatchersFromSelector(selector);
matchers.add( selMatchers );
}
Style blank = new Style();
for ( PropertyValue propertyValue: rule.getPropertyValues() ) {
CSSCompiler.StyleUpdater updater = CSSCompiler.getStyleUpdater(propertyValue.getProperty(),
propertyValue.getValue());
if ( updater != null ) {
styleUpdaters.add( updater );
blank = updater.updateStyle(blank, spanner);
}
}
Log.d("CSSCompiler", "Compiled rule: " + blank );
String asText = rule.toString();
return new CompiledRule(spanner, matchers, styleUpdaters, asText );
}
示例4: createMatchersFromSelector
import com.osbcp.cssparser.Selector; //导入依赖的package包/类
public static List<TagNodeMatcher> createMatchersFromSelector( Selector selector ) {
List<TagNodeMatcher> matchers = new ArrayList<TagNodeMatcher>();
String selectorString = selector.toString();
String[] parts = selectorString.split("\\s");
//Create a reversed matcher list
for ( int i=parts.length -1; i >= 0; i-- ) {
matchers.add( createMatcherFromPart(parts[i]));
}
return matchers;
}
示例5: CssSpecificity
import com.osbcp.cssparser.Selector; //导入依赖的package包/类
public CssSpecificity(Rule rule) {
if(rule.getSelectors().size() == 0) {
inline++;
} else {
for(Selector selector : rule.getSelectors()) {
if(isIdSelector(selector)) {
id++;
} else if(isClassSelector(selector)) {
cssClass++;
} else {
element++;
}
}
}
}
示例6: match
import com.osbcp.cssparser.Selector; //导入依赖的package包/类
private boolean match(Selector selector, Box box) {
String s = selector.toString();
if (s.startsWith(".")) {
String cls = StringUtils.stripStart(s, ".");
return box.hasCssClass(cls);
} else {
return StringUtils.equals(box.getTag(), s);
}
}
示例7: parseCss
import com.osbcp.cssparser.Selector; //导入依赖的package包/类
private List<Rule> parseCss(String source) throws Exception {
List<Rule> rules = CSSParser.parse(source);
for (Rule rule : rules) {
for (Selector selector : rule.getSelectors()) {
if (StringUtils.equals("@font-face", selector.toString())) {
String family = rule.getPropertyValue("font-family");
String src = rule.getPropertyValue("src");
fontManager.registerFont(family, src);
}
}
}
return rules;
}
示例8: parseSelector
import com.osbcp.cssparser.Selector; //导入依赖的package包/类
/**
* Parse the tags in the given selector and sets the onTags map
* @param s The selector
* @throws ParseException If parsed selector is invalid
*/
private void parseSelector(Selector s) throws ParseException {
String v = s.toString();
String regex = "(\\w+|\\*)(\\[\\w+(:\\w+)*(=\\w+(:\\w+)*)?\\])*";
//Test if selector is recognized
if(!v.matches(regex)) {
throw new ParseException("Parsed selector '"+v+"' is invalid");
}
String[] textTags = v.split("\\[");
String tmp;
for(int i=0; i < textTags.length; i++) {
tmp = textTags[i];
if(i > 0) { tmp = tmp.substring(0, tmp.length()-1); } //Remove ending "]"
//Geometry rules
if(i == 0) {
switch(tmp) {
case "*":
break;
case "grid":
onTags.put("grid", "yes");
break;
case "link":
onTags.put("link", "yes");
break;
case "node":
onTags.put("node", "yes");
break;
case "meta":
onTags.put("meta", "yes");
break;
default:
throw new ParseException("Geometry selector: "+tmp+" is invalid");
}
}
//Tags rules
else {
String[] keyValue = tmp.split("=");
onTags.put(keyValue[0], (keyValue.length == 2) ? keyValue[1] : null);
}
}
}
示例9: isIdSelector
import com.osbcp.cssparser.Selector; //导入依赖的package包/类
private boolean isIdSelector(Selector selector) {
return selector.toString().startsWith("#");
}
示例10: isClassSelector
import com.osbcp.cssparser.Selector; //导入依赖的package包/类
private boolean isClassSelector(Selector selector) {
return selector.toString().startsWith(".");
}
示例11: TagBasedRule
import com.osbcp.cssparser.Selector; //导入依赖的package包/类
/**
* Class constructor
* @param s The CSS selector
* @param p The CSS properties
* @throws ParseException If an error occurs during parsing
*/
private TagBasedRule(Selector s, List<PropertyValue> p) throws ParseException {
properties = p;
onTags = new HashMap<String,String>(0);
parseSelector(s);
}