本文整理汇总了Java中com.steadystate.css.parser.CSSOMParser.parseStyleDeclaration方法的典型用法代码示例。如果您正苦于以下问题:Java CSSOMParser.parseStyleDeclaration方法的具体用法?Java CSSOMParser.parseStyleDeclaration怎么用?Java CSSOMParser.parseStyleDeclaration使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.steadystate.css.parser.CSSOMParser
的用法示例。
在下文中一共展示了CSSOMParser.parseStyleDeclaration方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: apply
import com.steadystate.css.parser.CSSOMParser; //导入方法依赖的package包/类
@Override
public void apply(String style) {
RuleMap rulemap = new RuleMap();
setup(rulemap);
try {
InputSource source = new InputSource(new StringReader(style));
CSSOMParser parser = new CSSOMParser(new SACParserCSS3());
CSSStyleDeclaration decl = parser.parseStyleDeclaration(source);
for (int i = 0; i < decl.getLength(); i++) {
final String propName = decl.item(i);
Rule rule = rulemap.get(propName);
if (rule == null) {
System.out.println("Unknown CSS property: " + propName);
continue;
}
rule.consumer.accept(StylerValueConverter.convert(decl.getPropertyCSSValue(propName), rule.type));
}
} catch(Exception e) {
e.printStackTrace();
}
}
示例2: escapeIFrameCss
import com.steadystate.css.parser.CSSOMParser; //导入方法依赖的package包/类
public static String escapeIFrameCss(String orig) {
String rule = "";
CSSOMParser parser = new CSSOMParser();
try {
List<String> rules = new ArrayList<>();
CSSStyleDeclaration decl = parser.parseStyleDeclaration(new InputSource(new StringReader(orig)));
for (int i = 0; i < decl.getLength(); i++) {
String property = decl.item(i);
String value = decl.getPropertyValue(property);
if (StringUtils.isBlank(property) || StringUtils.isBlank(value)) {
continue;
}
if (ALLOWED_IFRAME_CSS_RULES.contains(property) && StringUtils.containsNone(value, FORBIDDEN_CSS_RULE_CHARACTERS)) {
rules.add(property + ":" + decl.getPropertyValue(property) + ";");
}
}
rule = StringUtils.join(rules, "");
} catch (Exception e) {
log.error(e.getMessage(), e);
}
return rule;
}
示例3: escapeImgCss
import com.steadystate.css.parser.CSSOMParser; //导入方法依赖的package包/类
public static String escapeImgCss(String orig) {
String rule = "";
CSSOMParser parser = new CSSOMParser();
try {
List<String> rules = new ArrayList<>();
CSSStyleDeclaration decl = parser.parseStyleDeclaration(new InputSource(new StringReader(orig)));
for (int i = 0; i < decl.getLength(); i++) {
String property = decl.item(i);
String value = decl.getPropertyValue(property);
if (StringUtils.isBlank(property) || StringUtils.isBlank(value)) {
continue;
}
if (ALLOWED_IMG_CSS_RULES.contains(property) && StringUtils.containsNone(value, FORBIDDEN_CSS_RULE_CHARACTERS)) {
rules.add(property + ":" + decl.getPropertyValue(property) + ";");
}
}
rule = StringUtils.join(rules, "");
} catch (Exception e) {
log.error(e.getMessage(), e);
}
return rule;
}
示例4: setCssText
import com.steadystate.css.parser.CSSOMParser; //导入方法依赖的package包/类
@Override
public void setCssText(final String cssText) throws DOMException {
try {
final InputSource is = new InputSource(new StringReader(cssText));
final CSSOMParser parser = new CSSOMParser();
properties_.clear();
parser.parseStyleDeclaration(this, is);
} catch (final Exception e) {
throw new DOMExceptionImpl(DOMException.SYNTAX_ERR, DOMExceptionImpl.SYNTAX_ERROR, e.getMessage());
}
}
示例5: getStyle
import com.steadystate.css.parser.CSSOMParser; //导入方法依赖的package包/类
/**
* Gets the local style object associated with the element. The properties
* object returned only includes properties from the local style attribute.
* It may return null only if the type of element does not handle
* stylesheets.
*
* @return the style
*/
@Override
public AbstractCSSProperties getStyle() {
AbstractCSSProperties sds;
synchronized (this) {
sds = this.localStyleDeclarationState;
if (sds != null) {
return sds;
}
sds = new LocalCSSProperties(this);
// Add any declarations in style attribute (last takes precedence).
String style = this.getAttribute(STYLE_HTML);
if (style != null && style.length() != 0) {
CSSOMParser parser = new CSSOMParser(new SACParserCSS3());
InputSource inputSource = this.getCssInputSourceForDecl(style);
try {
CSSStyleDeclaration sd = parser.parseStyleDeclaration(inputSource);
sd.setCssText(style);
sds.addStyleDeclaration(sd);
} catch (Exception err) {
String id = this.getId();
String withId = id == null ? "" : " with ID '" + id + "'";
logger.error("Unable to parse style attribute value for element " + this.getTagName() + withId
+ " in " + this.getDocumentURL() + ".", err);
}
}
this.localStyleDeclarationState = sds;
}
// Synchronization note: Make sure getStyle() does not return multiple
// values.
return sds;
}