本文整理汇总了Java中org.w3c.css.sac.InputSource类的典型用法代码示例。如果您正苦于以下问题:Java InputSource类的具体用法?Java InputSource怎么用?Java InputSource使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
InputSource类属于org.w3c.css.sac包,在下文中一共展示了InputSource类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: init
import org.w3c.css.sac.InputSource; //导入依赖的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: apply
import org.w3c.css.sac.InputSource; //导入依赖的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();
}
}
示例3: parseStyleSheet
import org.w3c.css.sac.InputSource; //导入依赖的package包/类
/**
* Parses and creates a new style-sheet.
* @param is The input source used to read the document.
* @param uri The base URI.
* @param media The target media of the style-sheet.
*/
public StyleSheet parseStyleSheet(InputSource is, ParsedURL uri,
String media)
throws DOMException {
StyleSheet ss = new StyleSheet();
try {
ss.setMedia(parser.parseMedia(media));
parseStyleSheet(ss, is, uri);
} catch (Exception e) {
String m = e.getMessage();
if (m == null) m = "";
String u = ((documentURI == null)?"<unknown>":
documentURI.toString());
String s = Messages.formatMessage
("syntax.error.at", new Object[] { u, m });
DOMException de = new DOMException(DOMException.SYNTAX_ERR, s);
if (userAgent == null) throw de;
userAgent.displayError(de);
}
return ss;
}
示例4: createCSSEngine
import org.w3c.css.sac.InputSource; //导入依赖的package包/类
public CSSEngine createCSSEngine(AbstractStylableDocument doc,
CSSContext ctx,
ExtendedParser ep,
ValueManager [] vms,
ShorthandManager [] sms) {
ParsedURL durl = ((SVGOMDocument)doc).getParsedURL();
CSSEngine result = new SVGCSSEngine(doc, durl, ep, vms, sms, ctx);
URL url = getClass().getResource("resources/UserAgentStyleSheet.css");
if (url != null) {
ParsedURL purl = new ParsedURL(url);
InputSource is = new InputSource(purl.toString());
result.setUserAgentStyleSheet
(result.parseStyleSheet(is, purl, "all"));
}
return result;
}
示例5: createCSSEngine
import org.w3c.css.sac.InputSource; //导入依赖的package包/类
public CSSEngine createCSSEngine(AbstractStylableDocument doc,
CSSContext ctx,
ExtendedParser ep,
ValueManager [] vms,
ShorthandManager [] sms) {
ParsedURL durl = ((SVGOMDocument)doc).getParsedURL();
CSSEngine result = new SVG12CSSEngine(doc, durl, ep, vms, sms, ctx);
URL url = getClass().getResource("resources/UserAgentStyleSheet.css");
if (url != null) {
ParsedURL purl = new ParsedURL(url);
InputSource is = new InputSource(purl.toString());
result.setUserAgentStyleSheet
(result.parseStyleSheet(is, purl, "all"));
}
return result;
}
示例6: resolveNormalized
import org.w3c.css.sac.InputSource; //导入依赖的package包/类
@Override
public InputSource resolveNormalized(String identifier) {
String fileName = identifier;
if (!fileName.endsWith(".css")) {
fileName += ".scss";
}
try {
InputStream is = new FileInputStream(fileName);
InputSource source = new InputSource();
source.setByteStream(is);
source.setURI(fileName);
return source;
} catch (FileNotFoundException e) {
// not found, try something else
return null;
}
}
示例7: startDocument
import org.w3c.css.sac.InputSource; //导入依赖的package包/类
@Override
public void startDocument(final InputSource source) throws CSSException {
if (nodeStack_.empty()) {
final CSSStyleSheetImpl ss = new CSSStyleSheetImpl();
CSSOMParser.this.setParentStyleSheet(ss);
ss.setOwnerNode(getOwnerNode());
ss.setBaseUri(source.getURI());
ss.setHref(getHref());
ss.setMediaText(source.getMedia());
ss.setTitle(source.getTitle());
// Create the rule list
final CSSRuleListImpl rules = new CSSRuleListImpl();
ss.setCssRules(rules);
nodeStack_.push(ss);
nodeStack_.push(rules);
} else {
// Error
}
}
示例8: setProperty
import org.w3c.css.sac.InputSource; //导入依赖的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());
}
}
示例9: parseStyleDeclaration
import org.w3c.css.sac.InputSource; //导入依赖的package包/类
/**
* Parses and creates a style declaration.
*
* @param value
* The style declaration text.
*/
public CSSStyleDeclaration parseStyleDeclaration( String value )
{
styleDeclarationBuilder.styleDeclaration = new StyleDeclaration( this );
try
{
parser.setDocumentHandler( styleDeclarationBuilder );
parser.parseStyleDeclaration( new InputSource( new StringReader(
value ) ) );
}
catch ( Exception e )
{
/** @todo: logout the error message */
}
return styleDeclarationBuilder.styleDeclaration;
}
示例10: parseStyleSheet
import org.w3c.css.sac.InputSource; //导入依赖的package包/类
/**
* Parses a CSS resource and get the CSSStyleSheet as the output.
*
* @param source
* the source of the CSS resource
* @return the CSSStyleSheet if succeed
* @throws IOException
* if the resource is not well-located
*/
public CSSStyleSheet parseStyleSheet( InputSource source )
throws IOException
{
CssHandler handler = new CssHandler( );
parser.setDocumentHandler( handler );
parser.setErrorHandler( errorHandler );
try
{
parser.parseStyleSheet( source );
}
catch ( StringIndexOutOfBoundsException e )
{
throw new CSSException( CSSException.SAC_SYNTAX_ERR );
}
return (StyleSheet) handler.getRoot( );
}
示例11: getReader
import org.w3c.css.sac.InputSource; //导入依赖的package包/类
/**
* Convert the source into a Reader. Used only by DOM Level 2 parser methods.
*/
private Reader getReader(InputSource source) throws IOException {
if (source.getCharacterStream() != null) {
return source.getCharacterStream();
} else if (source.getByteStream() != null) {
// My DOM level 2 implementation doesn't use this case.
if (source.getEncoding() == null) {
// unknown encoding, use ASCII as default.
return new InputStreamReader(source.getByteStream(), "ASCII");
} else {
return new InputStreamReader(source.getByteStream(),
source.getEncoding());
}
} else {
// systemId
// @@TODO
throw new CSSException("not yet implemented");
}
}
示例12: parseStyleSheetDefinition
import org.w3c.css.sac.InputSource; //导入依赖的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;
}
示例13: escapeIFrameCss
import org.w3c.css.sac.InputSource; //导入依赖的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;
}
示例14: escapeImgCss
import org.w3c.css.sac.InputSource; //导入依赖的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;
}
示例15: CSSParser
import org.w3c.css.sac.InputSource; //导入依赖的package包/类
public CSSParser(InputSource source, Parser parser) throws CSSException, IOException {
this.handler = new CSSDocumentHandler();
parser.setDocumentHandler(handler);
parser.setConditionFactory(CSSConditionFactory.INSTANCE);
parser.setSelectorFactory(CSSSelectorFactory.INSTANCE);
parser.parseStyleSheet(source);
}