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;
}
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();
}
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();
}
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;
}
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);
}
}
Aggregations