本文整理汇总了Java中org.w3c.dom.css.CSSRule类的典型用法代码示例。如果您正苦于以下问题:Java CSSRule类的具体用法?Java CSSRule怎么用?Java CSSRule使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
CSSRule类属于org.w3c.dom.css包,在下文中一共展示了CSSRule类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: init
import org.w3c.dom.css.CSSRule; //导入依赖的package包/类
private void init() {
if (style != null) {
String styleContent = style.getValue().getText();
if (styleContent != null && !styleContent.isEmpty()) {
InputSource source = new InputSource(new StringReader(styleContent));
CSSOMParser parser = new CSSOMParser(new SACParserCSS3());
parser.setErrorHandler(new ParserErrorHandler());
try {
styleSheet = parser.parseStyleSheet(source, null, null);
cssFormat = new CSSFormat().setRgbAsHex(true);
CSSRuleList rules = styleSheet.getCssRules();
for (int i = 0; i < rules.getLength(); i++) {
final CSSRule rule = rules.item(i);
if (rule instanceof CSSStyleRuleImpl) {
styleRuleMap.put(((CSSStyleRuleImpl) rule).getSelectorText(), (CSSStyleRuleImpl) rule);
}
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
示例2: checkForCSSPseudoRules
import org.w3c.dom.css.CSSRule; //导入依赖的package包/类
private void checkForCSSPseudoRules() {
Collection ss = document.getStyleSheets();
java.util.Iterator itss = ss.iterator();
Pattern patRule = Pattern.compile("^([^:]+?):(link|active|visited|hover)\\s+(\\{.+)$");
HashSet newRules = new HashSet();
while (itss.hasNext()) {
CSSStyleSheetImpl ss1 = (CSSStyleSheetImpl)itss.next();
CSSRuleList ruleList = ss1.getCssRules();
for (int i=0; i < ruleList.getLength(); i++) {
CSSRule rule = ruleList.item(i);
String ruleText = rule.getCssText();
// System.out.println("rule : "+ruleText);
Matcher mpatRule = patRule.matcher(ruleText);
if (mpatRule.find()) {
String newRuleText = mpatRule.group(1)+" "+mpatRule.group(3);
if (!newRules.contains(mpatRule.group(1))) {
newRules.add(mpatRule.group(1));
// System.out.println("***new rule : "+newRuleText);
ss1.insertRule(newRuleText, i++);
}
}
}
}
}
示例3: readObject
import org.w3c.dom.css.CSSRule; //导入依赖的package包/类
private void readObject(final ObjectInputStream in) throws IOException, ClassNotFoundException {
baseUri_ = (String) in.readObject();
cssRules_ = (CSSRuleList) in.readObject();
if (cssRules_ != null) {
for (int i = 0; i < cssRules_.getLength(); i++) {
final CSSRule cssRule = cssRules_.item(i);
if (cssRule instanceof AbstractCSSRuleImpl) {
((AbstractCSSRuleImpl) cssRule).setParentStyleSheet(this);
}
}
}
disabled_ = in.readBoolean();
href_ = (String) in.readObject();
media_ = (MediaList) in.readObject();
// TODO ownerNode may not be serializable!
// ownerNode = (Node) in.readObject();
readOnly_ = in.readBoolean();
title_ = (String) in.readObject();
}
示例4: showStyleSheet
import org.w3c.dom.css.CSSRule; //导入依赖的package包/类
/**
* Show style sheet.
*
* @param styleSheet
* the style sheet
*/
private void showStyleSheet(CSSStyleSheet styleSheet) {
StringWriter stringWriter = new StringWriter();
PrintWriter writer = new PrintWriter(stringWriter);
writer.println("<DL>");
CSSRuleList ruleList = styleSheet.getCssRules();
int length = ruleList.getLength();
for (int i = 0; i < length; i++) {
CSSRule rule = ruleList.item(i);
writer.println("<DT><strong>Rule: type=" + rule.getType() + ",class=" + rule.getClass().getName()
+ "</strong></DT>");
writer.println("<DD>");
this.writeRuleInfo(writer, rule);
writer.println("</DD>");
}
writer.println("</DL>");
writer.flush();
String html = stringWriter.toString();
HtmlRendererContext rcontext = new SimpleHtmlRendererContext(this.cssOutput, (UserAgentContext) null);
this.cssOutput.setHtml(html, "about:css", rcontext);
}
示例5: parseStyleSheetDefinition
import org.w3c.dom.css.CSSRule; //导入依赖的package包/类
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;
}
示例6: jdkClasses
import org.w3c.dom.css.CSSRule; //导入依赖的package包/类
@DataProvider(name = "jdkClasses")
public Object[][] jdkClasses() {
return new Object[][] {
{ java.awt.Button.class, null },
{ java.lang.Object.class, null },
{ org.w3c.dom.css.CSSRule.class, null },
{ loadClass("org.w3c.dom.css.Fake"), loadClass("org.w3c.dom.css.FakePackage") },
};
}
示例7: CSSOMSVGStyleDeclaration
import org.w3c.dom.css.CSSRule; //导入依赖的package包/类
/**
* Creates a new CSSOMSVGStyleDeclaration.
*/
public CSSOMSVGStyleDeclaration(ValueProvider vp,
CSSRule parent,
CSSEngine eng) {
super(vp, parent);
cssEngine = eng;
}
示例8: getParentRule
import org.w3c.dom.css.CSSRule; //导入依赖的package包/类
private CSSRule getParentRule() {
if (!nodeStack_.empty() && nodeStack_.size() > 1) {
final Object node = nodeStack_.get(nodeStack_.size() - 2);
if (node instanceof CSSRule) {
return (CSSRule) node;
}
}
return null;
}
示例9: getCssText
import org.w3c.dom.css.CSSRule; //导入依赖的package包/类
/**
* {@inheritDoc}
*/
@Override
public String getCssText(final CSSFormat format) {
final StringBuilder sb = new StringBuilder("@media ");
sb.append(((MediaListImpl) getMedia()).getMediaText(format));
sb.append(" {");
for (int i = 0; i < getCssRules().getLength(); i++) {
final CSSRule rule = getCssRules().item(i);
sb.append(rule.getCssText()).append(" ");
}
sb.append("}");
return sb.toString();
}
示例10: readObject
import org.w3c.dom.css.CSSRule; //导入依赖的package包/类
private void readObject(final ObjectInputStream in) throws IOException, ClassNotFoundException {
cssRules_ = (CSSRuleList) in.readObject();
if (cssRules_ != null) {
for (int i = 0; i < cssRules_.getLength(); i++) {
final CSSRule cssRule = cssRules_.item(i);
if (cssRule instanceof AbstractCSSRuleImpl) {
((AbstractCSSRuleImpl) cssRule).setParentRule(this);
((AbstractCSSRuleImpl) cssRule).setParentStyleSheet(getParentStyleSheetImpl());
}
}
}
media_ = (MediaList) in.readObject();
}
示例11: equals
import org.w3c.dom.css.CSSRule; //导入依赖的package包/类
@Override
public boolean equals(final Object obj) {
if (this == obj) {
return true;
}
if (!(obj instanceof CSSRule)) {
return false;
}
return super.equals(obj);
// don't use parentRule and parentStyleSheet in equals()
// recursive loop -> stack overflow!
}
示例12: item
import org.w3c.dom.css.CSSRule; //导入依赖的package包/类
@Override
public CSSRule item(final int index) {
if (index < 0 || null == rules_ || index >= rules_.size()) {
return null;
}
return rules_.get(index);
}
示例13: getCssText
import org.w3c.dom.css.CSSRule; //导入依赖的package包/类
/**
* {@inheritDoc}
*/
@Override
public String getCssText(final CSSFormat format) {
final StringBuilder sb = new StringBuilder();
for (int i = 0; i < getLength(); i++) {
if (i > 0) {
sb.append("\r\n");
}
final CSSRule rule = item(i);
sb.append(((CSSFormatable) rule).getCssText(format));
}
return sb.toString();
}
示例14: equalsRules
import org.w3c.dom.css.CSSRule; //导入依赖的package包/类
private boolean equalsRules(final CSSRuleList crl) {
if ((crl == null) || (getLength() != crl.getLength())) {
return false;
}
for (int i = 0; i < getLength(); i++) {
final CSSRule cssRule1 = item(i);
final CSSRule cssRule2 = crl.item(i);
if (!LangUtils.equals(cssRule1, cssRule2)) {
return false;
}
}
return true;
}
示例15: addStyleSheet
import org.w3c.dom.css.CSSRule; //导入依赖的package包/类
/**
* Adds the style sheet.
*
* @param styleSheet
* the style sheet
* @throws MalformedURLException
* the malformed url exception
* @throws UnsupportedEncodingException
*/
private final void addStyleSheet(CSSStyleSheet styleSheet)
throws MalformedURLException, UnsupportedEncodingException {
CSSRuleList ruleList = styleSheet.getCssRules();
int length = ruleList.getLength();
for (int i = 0; i < length; i++) {
CSSRule rule = ruleList.item(i);
this.addRule(styleSheet, rule);
}
}