• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java CSSOMParser类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中com.steadystate.css.parser.CSSOMParser的典型用法代码示例。如果您正苦于以下问题:Java CSSOMParser类的具体用法?Java CSSOMParser怎么用?Java CSSOMParser使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



CSSOMParser类属于com.steadystate.css.parser包,在下文中一共展示了CSSOMParser类的16个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: init

import com.steadystate.css.parser.CSSOMParser; //导入依赖的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();
            }
        }
    }
}
 
开发者ID:misakuo,项目名称:svgtoandroid,代码行数:26,代码来源:StyleParser.java


示例2: 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();
    }
}
 
开发者ID:VISNode,项目名称:VISNode,代码行数:23,代码来源:AbstractStyler.java


示例3: setProperty

import com.steadystate.css.parser.CSSOMParser; //导入依赖的package包/类
@Override
public void setProperty(final String propertyName, final String value, final String priority) throws DOMException {
	try {
		CSSValue expr = null;
		if (!value.isEmpty()) {
			final CSSOMParser parser = new CSSOMParser();
			final InputSource is = new InputSource(new StringReader(value));
			expr = parser.parsePropertyValue(is);
		}
		Property p = getPropertyDeclaration(propertyName);
		final boolean important = PRIORITY_IMPORTANT.equalsIgnoreCase(priority);
		if (p == null) {
			p = new Property(propertyName, expr, important);
			addProperty(p);
		} else {
			p.setValue(expr);
			p.setImportant(important);
		}
	} catch (final Exception e) {
		throw new DOMExceptionImpl(DOMException.SYNTAX_ERR, DOMExceptionImpl.SYNTAX_ERROR, e.getMessage());
	}
}
 
开发者ID:oswetto,项目名称:LoboEvolution,代码行数:23,代码来源:CSSStyleDeclarationImpl.java


示例4: 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;
}
 
开发者ID:Athou,项目名称:commafeed,代码行数:25,代码来源:FeedUtils.java


示例5: 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;
}
 
开发者ID:Athou,项目名称:commafeed,代码行数:25,代码来源:FeedUtils.java


示例6: setUp

import com.steadystate.css.parser.CSSOMParser; //导入依赖的package包/类
@Before
public void setUp() throws Exception {
	Bundle bundle = Platform.getBundle("us.nineworlds.xstreamer.templates");
	Path path = new Path("templates/squads/html/common/css_squads_common.ftl");
	URL url = FileLocator.find(bundle, path, null);
	
	InputSource source = new InputSource(new BufferedReader(new InputStreamReader(url.openStream())));
	
	parser = new CSSOMParser(new SACParserCSS3());
	
	styleSheet = parser.parseStyleSheet(source, null, null);
}
 
开发者ID:NineWorlds,项目名称:xstreamer,代码行数:13,代码来源:XWIngCommonCssTest.java


示例7: setMediaText

import com.steadystate.css.parser.CSSOMParser; //导入依赖的package包/类
public void setMediaText(final String mediaText) {
	final InputSource source = new InputSource(new StringReader(mediaText));
	try {
		final CSSOMParser parser = new CSSOMParser();
		final SACMediaList sml = parser.parseMedia(source);
		media_ = new MediaListImpl(sml);
	} catch (final IOException e) {
		// TODO handle exception
	}
}
 
开发者ID:oswetto,项目名称:LoboEvolution,代码行数:11,代码来源:CSSStyleSheetImpl.java


示例8: 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();
		final CSSValueImpl v2 = (CSSValueImpl) parser.parsePropertyValue(is);
		value_ = v2.value_;
		setUserDataMap(v2.getUserDataMap());
	} catch (final Exception e) {
		throw new DOMExceptionImpl(DOMException.SYNTAX_ERR, DOMExceptionImpl.SYNTAX_ERROR, e.getMessage());
	}
}
 
开发者ID:oswetto,项目名称:LoboEvolution,代码行数:13,代码来源:CSSValueImpl.java


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


示例10: processStyle

import com.steadystate.css.parser.CSSOMParser; //导入依赖的package包/类
/**
 * Process style.
 */
protected void processStyle() {
	this.styleSheet = null;
	UserAgentContext uacontext = this.getUserAgentContext();
	if (uacontext.isInternalCSSEnabled() && CSSUtilities.matchesMedia(this.getMedia(), this.getUserAgentContext())) {
		String text = this.getRawInnerText(true);
		if (text != null && !"".equals(text)) {
			HTMLDocumentImpl doc = (HTMLDocumentImpl) this.getOwnerDocument();
			try {
				CSSOMParser parser = new CSSOMParser(new SACParserCSS3());
				InputSource is = CSSUtilities.getCssInputSourceForStyleSheet(text, doc.getBaseURI());
				CSSStyleSheet sheet = parser.parseStyleSheet(is, null, null);
				if (sheet != null) {
					doc.addStyleSheet(sheet);
					this.styleSheet = sheet;
					if (sheet instanceof CSSStyleSheetImpl) {
						CSSStyleSheetImpl sheetImpl = (CSSStyleSheetImpl) sheet;
						sheetImpl.setDisabled(disabled);
					} else {
						sheet.setDisabled(this.disabled);
					}
				}
			} catch (Throwable err) {
				logger.error("Unable to parse style sheet", err);
			}
		}
	}
}
 
开发者ID:oswetto,项目名称:LoboEvolution,代码行数:31,代码来源:HTMLStyleElementImpl.java


示例11: 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;
}
 
开发者ID:oswetto,项目名称:LoboEvolution,代码行数:43,代码来源:HTMLElementImpl.java


示例12: extractCssStyleRules

import com.steadystate.css.parser.CSSOMParser; //导入依赖的package包/类
public HashMap<String, CSSStyleRule> extractCssStyleRules(String cssFile) throws IOException {
    TEST_FILE_SYSTEM.filesExists(cssFile);
    CSSOMParser cssParser = new CSSOMParser();
    CSSStyleSheet css = cssParser.parseStyleSheet(new InputSource(new FileReader(TEST_FILE_SYSTEM.file(cssFile))), null, null);
    CSSRuleList cssRules = css.getCssRules();
    HashMap<String, CSSStyleRule> rules = new HashMap<String, CSSStyleRule>();
    for (int i = 0; i < cssRules.getLength(); i++) {
        CSSRule rule = cssRules.item(i);
        if (rule instanceof CSSStyleRule) {
            rules.put(((CSSStyleRule) rule).getSelectorText(), (CSSStyleRule) rule);
        }
    }
    return rules;
}
 
开发者ID:slezier,项目名称:SimpleFunctionalTest,代码行数:15,代码来源:CssParser.java


示例13: getRuleList

import com.steadystate.css.parser.CSSOMParser; //导入依赖的package包/类
AttributeRuleList getRuleList(InputStream stream) throws IOException {
	InputSource source = new InputSource(new InputStreamReader(stream));
       CSSOMParser parser = new CSSOMParser(new SACParserCSS3());
       parser.setErrorHandler(ThrowCssExceptionErrorHandler.INSTANCE);
       CSSStyleSheet stylesheet = parser.parseStyleSheet(source, null, null);
       CSSRuleList ruleList = stylesheet.getCssRules();
       
       return new AttributeRuleList(ruleList);
}
 
开发者ID:connect-group,项目名称:thymesheet,代码行数:10,代码来源:ThymesheetPreprocessor.java


示例14: parseStyleSheet

import com.steadystate.css.parser.CSSOMParser; //导入依赖的package包/类
private static CSSStyleSheetImpl parseStyleSheet(final InputSource source) throws TranslatorException {
    try {
        CSSOMParser parser = new CSSOMParser(new SACParserCSS3());
        return (CSSStyleSheetImpl) parser.parseStyleSheet(source,
                                                          null,
                                                          null);
    } catch (final IOException e) {
        throw new TranslatorException("Exception while parsing some style defintion.",
                                      e);
    }
}
 
开发者ID:kiegroup,项目名称:kie-wb-common,代码行数:12,代码来源:SVGStyleTranslatorHelper.java


示例15: parse

import com.steadystate.css.parser.CSSOMParser; //导入依赖的package包/类
/**
 * @param href
 * @param href
 * @param doc
 * @return
 * @throws Exception
 */
public static CSSStyleSheet parse(String href, HTMLDocumentImpl doc) throws Exception {

	URL url = null;
	CSSOMParser parser = new CSSOMParser(new SACParserCSS3());

	URL baseURL = new URL(doc.getBaseURI());
	URL scriptURL = Urls.createURL(baseURL, href);
	String scriptURI = scriptURL == null ? href : scriptURL.toExternalForm();

	try {
		if (scriptURI.startsWith("//")) {
			scriptURI = "http:" + scriptURI;
		}
		url = new URL(scriptURI);
	} catch (MalformedURLException mfu) {
		int idx = scriptURI.indexOf(':');
		if (idx == -1 || idx == 1) {
			// try file
			url = new URL("file:" + scriptURI);
		} else {
			throw mfu;
		}
	}
	logger.info("process(): Loading URI=[" + scriptURI + "].");
	SSLCertificate.setCertificate();
	URLConnection connection = url.openConnection();
	connection.setRequestProperty("User-Agent", UserAgentContext.DEFAULT_USER_AGENT);
	connection.setRequestProperty("Cookie", "");
	if (connection instanceof HttpURLConnection) {
		HttpURLConnection hc = (HttpURLConnection) connection;
		hc.setInstanceFollowRedirects(true);
		int responseCode = hc.getResponseCode();
		logger.info("process(): HTTP response code: " + responseCode);
	}
	InputStream in = connection.getInputStream();
	byte[] content;
	try {
		content = IORoutines.load(in, 8192);
	} finally {
		in.close();
	}
	String source = new String(content, "UTF-8");

	InputSource is = getCssInputSourceForStyleSheet(source, doc.getBaseURI());
	return parser.parseStyleSheet(is, null, null);

}
 
开发者ID:oswetto,项目名称:LoboEvolution,代码行数:55,代码来源:CSSUtilities.java


示例16: process

import com.steadystate.css.parser.CSSOMParser; //导入依赖的package包/类
/**
 * Process.
 *
 * @param uri
 *            the uri
 */
private void process(String uri) {
	try {
		URL url;
		try {
			url = new URL(uri);
		} catch (MalformedURLException mfu) {
			int idx = uri.indexOf(':');
			if (idx == -1 || idx == 1) {
				// try file
				url = new URL("file:" + uri);
			} else {
				throw mfu;
			}
		}
		logger.info("process(): Loading URI=[" + uri + "].");
		long time0 = System.currentTimeMillis();
		SSLCertificate.setCertificate();
		URLConnection connection = url.openConnection();
		connection.setRequestProperty("User-Agent", "Mozilla/4.0 (compatible;) Cobra/0.96.1+");
		connection.setRequestProperty("Cookie", "");
		if (connection instanceof HttpURLConnection) {
			HttpURLConnection hc = (HttpURLConnection) connection;
			hc.setInstanceFollowRedirects(true);
			int responseCode = hc.getResponseCode();
			logger.info("process(): HTTP response code: " + responseCode);
		}
		InputStream in = connection.getInputStream();
		byte[] content;
		try {
			content = IORoutines.load(in, 8192);
		} finally {
			in.close();
		}
		String source = new String(content, "UTF-8");
		this.textArea.setText(source);
		long time1 = System.currentTimeMillis();
		CSSOMParser parser = new CSSOMParser();
		InputSource is = CSSUtilities.getCssInputSourceForStyleSheet(source, uri);
		CSSStyleSheet styleSheet = parser.parseStyleSheet(is, null, null);
		long time2 = System.currentTimeMillis();
		logger.info("Parsed URI=[" + uri + "]: Parse elapsed: " + (time2 - time1) + " ms. Load elapsed: "
				+ (time1 - time0) + " ms.");
		this.showStyleSheet(styleSheet);
	} catch (Exception err) {
		logger.log(Level.ERROR, "Error trying to load URI=[" + uri + "].", err);
		this.clearCssOutput();
	}
}
 
开发者ID:oswetto,项目名称:LoboEvolution,代码行数:55,代码来源:CssParserTest.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java MarshallingStrategy类代码示例发布时间:2022-05-23
下一篇:
Java BsonDocumentReader类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap