Search in sources :

Example 1 with InputSource

use of org.w3c.css.sac.InputSource in project xwiki-platform by xwiki.

the class XWikiWikiModel method getImageDimension.

/**
 * Extracts the specified image dimension from the image parameters.
 *
 * @param dimension either {@code width} or {@code height}
 * @param imageParameters the image parameters; may include the {@code width}, {@code height} and {@code style}
 *            parameters
 * @return the value of the passed dimension if it is specified in the image parameters, {@code null} otherwise
 */
private String getImageDimension(String dimension, Map<String, String> imageParameters) {
    // Check first if the style parameter contains information about the given dimension. In-line style has priority
    // over the dimension parameters.
    String value = null;
    String style = imageParameters.get("style");
    if (StringUtils.isNotBlank(style)) {
        try {
            CSSStyleDeclaration sd = this.cssParser.parseStyleDeclaration(new InputSource(new StringReader(style)));
            value = sd.getPropertyValue(dimension);
        } catch (Exception e) {
            // Ignore the style parameter but log a warning to let the user know.
            this.logger.warn("Failed to parse CSS style [{}]", style);
        }
    }
    if (StringUtils.isBlank(value)) {
        // Fall back on the value of the dimension parameter.
        value = imageParameters.get(dimension);
    }
    return value;
}
Also used : InputSource(org.w3c.css.sac.InputSource) StringReader(java.io.StringReader) CSSStyleDeclaration(org.w3c.dom.css.CSSStyleDeclaration) WikiModelException(org.xwiki.rendering.wiki.WikiModelException) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Example 2 with InputSource

use of org.w3c.css.sac.InputSource in project onebusaway-application-modules by camsys.

the class CssResourceImpl method parse.

private String parse() throws IOException {
    InputStreamReader reader2 = new InputStreamReader(_cssUrl.openStream());
    InputSource source2 = new InputSource(reader2);
    Parser p = new SACParserCSS2();
    CssDocumentHandlerImpl handler = new CssDocumentHandlerImpl(_context, _parentBundle);
    p.setDocumentHandler(handler);
    p.parseStyleSheet(source2);
    reader2.close();
    return handler.getResults();
}
Also used : InputSource(org.w3c.css.sac.InputSource) InputStreamReader(java.io.InputStreamReader) SACParserCSS2(com.steadystate.css.parser.SACParserCSS2) Parser(org.w3c.css.sac.Parser)

Example 3 with InputSource

use of org.w3c.css.sac.InputSource in project tdi-studio-se by Talend.

the class CSSParserUtils method parserCSSSelectors.

public static CSSRuleList parserCSSSelectors(Reader read, String url) {
    CSSOMParser cssparser = new CSSOMParser();
    CSSStyleSheet css = null;
    try {
        if (read == null)
            //$NON-NLS-1$
            css = cssparser.parseStyleSheet(new InputSource("file:" + url), null, null);
        else
            css = cssparser.parseStyleSheet(new InputSource(read), null, null);
    } catch (IOException e) {
        ExceptionHandler.process(e);
        return null;
    }
    return css.getCssRules();
}
Also used : InputSource(org.w3c.css.sac.InputSource) CSSOMParser(com.steadystate.css.parser.CSSOMParser) CSSStyleSheet(org.w3c.dom.css.CSSStyleSheet) IOException(java.io.IOException)

Example 4 with InputSource

use of org.w3c.css.sac.InputSource in project kie-wb-common by kiegroup.

the class SVGStyleTranslator method parseStyleSheetDefinition.

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;
}
Also used : InputSource(org.w3c.css.sac.InputSource) CSSRule(org.w3c.dom.css.CSSRule) CSSStyleSheetImpl(com.steadystate.css.dom.CSSStyleSheetImpl) InputStreamReader(java.io.InputStreamReader) CSSStyleRuleImpl(com.steadystate.css.dom.CSSStyleRuleImpl) StyleSheetDefinition(org.kie.workbench.common.stunner.svg.gen.model.StyleSheetDefinition) CSSStyleDeclaration(org.w3c.dom.css.CSSStyleDeclaration) StyleDefinition(org.kie.workbench.common.stunner.svg.gen.model.StyleDefinition) CSSRuleList(org.w3c.dom.css.CSSRuleList)

Example 5 with InputSource

use of org.w3c.css.sac.InputSource in project onebusaway-application-modules by camsys.

the class CssDocumentHandlerImpl method parse.

private void parse(String snippet) throws CSSException {
    try {
        BufferedReader reader = new BufferedReader(new StringReader(snippet));
        InputSource source = new InputSource(reader);
        Parser p = new SACParserCSS2();
        p.setDocumentHandler(this);
        p.parseStyleSheet(source);
        reader.close();
    } catch (IOException ex) {
        throw new CSSException(ex);
    }
}
Also used : InputSource(org.w3c.css.sac.InputSource) SACParserCSS2(com.steadystate.css.parser.SACParserCSS2) BufferedReader(java.io.BufferedReader) StringReader(java.io.StringReader) CSSException(org.w3c.css.sac.CSSException) IOException(java.io.IOException) Parser(org.w3c.css.sac.Parser)

Aggregations

InputSource (org.w3c.css.sac.InputSource)6 SACParserCSS2 (com.steadystate.css.parser.SACParserCSS2)3 InputStreamReader (java.io.InputStreamReader)3 Parser (org.w3c.css.sac.Parser)3 IOException (java.io.IOException)2 StringReader (java.io.StringReader)2 CSSStyleDeclaration (org.w3c.dom.css.CSSStyleDeclaration)2 CSSStyleRuleImpl (com.steadystate.css.dom.CSSStyleRuleImpl)1 CSSStyleSheetImpl (com.steadystate.css.dom.CSSStyleSheetImpl)1 CSSOMParser (com.steadystate.css.parser.CSSOMParser)1 BufferedReader (java.io.BufferedReader)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 StyleDefinition (org.kie.workbench.common.stunner.svg.gen.model.StyleDefinition)1 StyleSheetDefinition (org.kie.workbench.common.stunner.svg.gen.model.StyleSheetDefinition)1 CSSException (org.w3c.css.sac.CSSException)1 CSSRule (org.w3c.dom.css.CSSRule)1 CSSRuleList (org.w3c.dom.css.CSSRuleList)1 CSSStyleSheet (org.w3c.dom.css.CSSStyleSheet)1 WikiModelException (org.xwiki.rendering.wiki.WikiModelException)1