当前位置: 首页>>代码示例>>Java>>正文


Java InputSource类代码示例

本文整理汇总了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();
            }
        }
    }
}
 
开发者ID:misakuo,项目名称:svgtoandroid,代码行数:26,代码来源:StyleParser.java

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

示例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;
}
 
开发者ID:git-moss,项目名称:Push2Display,代码行数:27,代码来源:CSSEngine.java

示例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;
}
 
开发者ID:git-moss,项目名称:Push2Display,代码行数:20,代码来源:SVGDOMImplementation.java

示例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;
}
 
开发者ID:git-moss,项目名称:Push2Display,代码行数:19,代码来源:SVG12DOMImplementation.java

示例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;
    }

}
 
开发者ID:fjalvingh,项目名称:domui,代码行数:21,代码来源:FilesystemResolver.java

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

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

示例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;
}
 
开发者ID:eclipse,项目名称:birt,代码行数:22,代码来源:CSSEngine.java

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

示例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");
    }
}
 
开发者ID:dmazinanian,项目名称:css-analyser,代码行数:22,代码来源:Parser.java

示例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;
}
 
开发者ID:kiegroup,项目名称:kie-wb-common,代码行数:18,代码来源:SVGStyleTranslatorHelper.java

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

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

示例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);
}
 
开发者ID:eclipse,项目名称:tm4e,代码行数:8,代码来源:CSSParser.java


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