org.w3c.dom.css.CSSStyleDeclaration Java Examples

The following examples show how to use org.w3c.dom.css.CSSStyleDeclaration. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CSSEngine.java    From birt with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * 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;
}
 
Example #2
Source File: StyleSheetLoader.java    From birt with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Gets all the name/value pairs from a CSS declaration and puts them into a
 * <code>LinkedHashMap</code>. All the name and value is of string type.
 * 
 * @param declaration
 *            the declaration of the style rule
 * @param errors
 *            the error list of the declaration
 * @return all the supported name/value pairs
 */

LinkedHashMap<String, ? extends Object> buildProperties(
		CSSStyleDeclaration declaration,
		List<StyleSheetParserException> errors )
{
	LinkedHashMap<String, String> properties = new LinkedHashMap<String, String>( );
	for ( int i = 0; i < declaration.getLength( ); i++ )
	{
		String cssName = declaration.item( i );
		String cssValue = declaration.getPropertyValue( cssName );
		if ( StringUtil.isBlank( cssName ) || StringUtil.isBlank( cssValue ) )
			continue;

		properties.put( cssName, cssValue );
	}

	return buildProperties( properties, errors );
}
 
Example #3
Source File: FeedUtils.java    From commafeed with Apache License 2.0 6 votes vote down vote up
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;
}
 
Example #4
Source File: FeedUtils.java    From commafeed with Apache License 2.0 6 votes vote down vote up
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;
}
 
Example #5
Source File: Report.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * add a style definition into the report.
 * 
 * @param style
 *            style definition.
 */
public void addStyle( String name, CSSStyleDeclaration style )
{
	assert ( style != null );
	this.styles.add( style );
	this.styleTable.put( name, style );
}
 
Example #6
Source File: CSSPaserTest.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
private String parseStyle( String cssText )
{
	try
	{
		CSSStyleDeclaration style = engine.parseStyleDeclaration( cssText );
		return style.getCssText( );
	}
	catch ( Exception ex )
	{
	}
	return "";
}
 
Example #7
Source File: SVGUtils.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
public static Color toSWTColor(Element element, String attributeName) {
	Document document = element.getOwnerDocument();
	ViewCSS viewCSS = (ViewCSS) document.getDocumentElement();
	CSSStyleDeclaration computedStyle = viewCSS.getComputedStyle(element, null);
	SVGPaint svgPaint = (SVGPaint) computedStyle.getPropertyCSSValue(attributeName);
	if (svgPaint.getPaintType() == SVGPaint.SVG_PAINTTYPE_RGBCOLOR) {
		RGBColor rgb = svgPaint.getRGBColor();
		float red = rgb.getRed().getFloatValue(CSSValue.CSS_PRIMITIVE_VALUE);
		float green = rgb.getGreen().getFloatValue(CSSValue.CSS_PRIMITIVE_VALUE);
		float blue = rgb.getBlue().getFloatValue(CSSValue.CSS_PRIMITIVE_VALUE);
		return new Color(Display.getCurrent(), (int) red, (int) green, (int) blue);
	}
	return null;
}
 
Example #8
Source File: StyleRule.java    From birt with Eclipse Public License 1.0 4 votes vote down vote up
public CSSStyleDeclaration getStyle( )
{
	return this.style;
}