本文整理汇总了Java中com.steadystate.css.parser.CSSOMParser.parseStyleSheet方法的典型用法代码示例。如果您正苦于以下问题:Java CSSOMParser.parseStyleSheet方法的具体用法?Java CSSOMParser.parseStyleSheet怎么用?Java CSSOMParser.parseStyleSheet使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.steadystate.css.parser.CSSOMParser
的用法示例。
在下文中一共展示了CSSOMParser.parseStyleSheet方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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();
}
}
}
}
示例2: 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);
}
示例3: 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);
}
}
}
}
示例4: 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;
}
示例5: 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);
}
示例6: 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);
}
}
示例7: 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);
}
示例8: 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();
}
}