当前位置: 首页>>代码示例>>Java>>正文


Java Selector类代码示例

本文整理汇总了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;
}
 
开发者ID:PanierAvide,项目名称:OpenNetworkMap,代码行数:21,代码来源:TagBasedRule.java

示例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;
      }
    }
  }
}
 
开发者ID:uq-eresearch,项目名称:aorra,代码行数:17,代码来源:Parser.java

示例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 );
    }
 
开发者ID:SysdataSpA,项目名称:SDHtmlTextView,代码行数:31,代码来源:CSSCompiler.java

示例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;
}
 
开发者ID:SysdataSpA,项目名称:SDHtmlTextView,代码行数:15,代码来源:CSSCompiler.java

示例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++;
            }
        }
    }
}
 
开发者ID:uq-eresearch,项目名称:aorra,代码行数:16,代码来源:CssSpecificity.java

示例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);
  }
}
 
开发者ID:uq-eresearch,项目名称:aorra,代码行数:10,代码来源:Parser.java

示例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;
}
 
开发者ID:uq-eresearch,项目名称:aorra,代码行数:14,代码来源:Parser.java

示例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);
		}
	}
}
 
开发者ID:PanierAvide,项目名称:OpenNetworkMap,代码行数:49,代码来源:TagBasedRule.java

示例9: isIdSelector

import com.osbcp.cssparser.Selector; //导入依赖的package包/类
private boolean isIdSelector(Selector selector) {
    return selector.toString().startsWith("#");
}
 
开发者ID:uq-eresearch,项目名称:aorra,代码行数:4,代码来源:CssSpecificity.java

示例10: isClassSelector

import com.osbcp.cssparser.Selector; //导入依赖的package包/类
private boolean isClassSelector(Selector selector) {
    return selector.toString().startsWith(".");
}
 
开发者ID:uq-eresearch,项目名称:aorra,代码行数:4,代码来源:CssSpecificity.java

示例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);
}
 
开发者ID:PanierAvide,项目名称:OpenNetworkMap,代码行数:12,代码来源:TagBasedRule.java


注:本文中的com.osbcp.cssparser.Selector类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。