/// <summary><inheritDoc/></summary> public virtual bool IsValid(String objectString) { if (objectString == null) { return(false); } if (CssUtils.IsInitialOrInheritOrUnset(objectString)) { return(true); } // Actually it's not shorthand but extractShorthandProperties method works exactly as needed in this case IList <IList <String> > extractedProperties = CssUtils.ExtractShorthandProperties(objectString); foreach (IList <String> propertyValues in extractedProperties) { if (propertyValues.IsEmpty() || propertyValues.Count > MAX_AMOUNT_OF_VALUES) { return(false); } for (int i = 0; i < propertyValues.Count; i++) { if (!IsValidProperty(propertyValues, i)) { return(false); } } } return(true); }
// With CSS3, you can apply multiple backgrounds to elements. These are layered atop one another // with the first background you provide on top and the last background listed in the back. Only // the last background can include a background color. /* (non-Javadoc) * @see com.itextpdf.styledxmlparser.css.resolve.shorthand.IShorthandResolver#resolveShorthand(java.lang.String) */ public virtual IList <CssDeclaration> ResolveShorthand(String shorthandExpression) { if (CssUtils.IsInitialOrInheritOrUnset(shorthandExpression)) { return(JavaUtil.ArraysAsList(new CssDeclaration(CommonCssConstants.BACKGROUND_COLOR, shorthandExpression), new CssDeclaration(CommonCssConstants.BACKGROUND_IMAGE, shorthandExpression), new CssDeclaration(CommonCssConstants .BACKGROUND_POSITION, shorthandExpression), new CssDeclaration(CommonCssConstants.BACKGROUND_SIZE, shorthandExpression ), new CssDeclaration(CommonCssConstants.BACKGROUND_REPEAT, shorthandExpression), new CssDeclaration(CommonCssConstants .BACKGROUND_ORIGIN, shorthandExpression), new CssDeclaration(CommonCssConstants.BACKGROUND_CLIP, shorthandExpression ), new CssDeclaration(CommonCssConstants.BACKGROUND_ATTACHMENT, shorthandExpression))); } if (String.IsNullOrEmpty(shorthandExpression.Trim())) { LOGGER.Error(MessageFormatUtil.Format(iText.StyledXmlParser.LogMessageConstant.SHORTHAND_PROPERTY_CANNOT_BE_EMPTY , CommonCssConstants.BACKGROUND)); return(new List <CssDeclaration>()); } IList <IList <String> > propsList = CssUtils.ExtractShorthandProperties(shorthandExpression); IDictionary <CssBackgroundUtils.BackgroundPropertyType, String> resolvedProps = new Dictionary <CssBackgroundUtils.BackgroundPropertyType , String>(); FillMapWithPropertiesTypes(resolvedProps); foreach (IList <String> props in propsList) { if (!ProcessProperties(props, resolvedProps)) { return(new List <CssDeclaration>()); } } if (resolvedProps.Get(CssBackgroundUtils.BackgroundPropertyType.BACKGROUND_COLOR) == null) { resolvedProps.Put(CssBackgroundUtils.BackgroundPropertyType.BACKGROUND_COLOR, CommonCssConstants.TRANSPARENT ); } if (!CheckProperties(resolvedProps)) { return(new List <CssDeclaration>()); } return(JavaUtil.ArraysAsList(new CssDeclaration(CssBackgroundUtils.GetBackgroundPropertyNameFromType(CssBackgroundUtils.BackgroundPropertyType .BACKGROUND_COLOR), resolvedProps.Get(CssBackgroundUtils.BackgroundPropertyType.BACKGROUND_COLOR)), new CssDeclaration(CssBackgroundUtils.GetBackgroundPropertyNameFromType(CssBackgroundUtils.BackgroundPropertyType .BACKGROUND_IMAGE), resolvedProps.Get(CssBackgroundUtils.BackgroundPropertyType.BACKGROUND_IMAGE)), new CssDeclaration(CssBackgroundUtils.GetBackgroundPropertyNameFromType(CssBackgroundUtils.BackgroundPropertyType .BACKGROUND_POSITION), resolvedProps.Get(CssBackgroundUtils.BackgroundPropertyType.BACKGROUND_POSITION )), new CssDeclaration(CssBackgroundUtils.GetBackgroundPropertyNameFromType(CssBackgroundUtils.BackgroundPropertyType .BACKGROUND_SIZE), resolvedProps.Get(CssBackgroundUtils.BackgroundPropertyType.BACKGROUND_SIZE)), new CssDeclaration(CssBackgroundUtils.GetBackgroundPropertyNameFromType(CssBackgroundUtils.BackgroundPropertyType .BACKGROUND_REPEAT), resolvedProps.Get(CssBackgroundUtils.BackgroundPropertyType.BACKGROUND_REPEAT)), new CssDeclaration(CssBackgroundUtils.GetBackgroundPropertyNameFromType(CssBackgroundUtils.BackgroundPropertyType .BACKGROUND_ORIGIN), resolvedProps.Get(CssBackgroundUtils.BackgroundPropertyType.BACKGROUND_ORIGIN)), new CssDeclaration(CssBackgroundUtils.GetBackgroundPropertyNameFromType(CssBackgroundUtils.BackgroundPropertyType .BACKGROUND_CLIP), resolvedProps.Get(CssBackgroundUtils.BackgroundPropertyType.BACKGROUND_CLIP)), new CssDeclaration(CssBackgroundUtils.GetBackgroundPropertyNameFromType(CssBackgroundUtils.BackgroundPropertyType .BACKGROUND_ATTACHMENT), resolvedProps.Get(CssBackgroundUtils.BackgroundPropertyType.BACKGROUND_ATTACHMENT )))); }
/// <summary><inheritDoc/></summary> public virtual IList <CssDeclaration> ResolveShorthand(String shorthandExpression) { if (CssUtils.IsInitialOrInheritOrUnset(shorthandExpression)) { return(JavaUtil.ArraysAsList(new CssDeclaration(CommonCssConstants.BACKGROUND_POSITION_X, shorthandExpression ), new CssDeclaration(CommonCssConstants.BACKGROUND_POSITION_Y, shorthandExpression))); } if (String.IsNullOrEmpty(shorthandExpression.Trim())) { LOGGER.Error(MessageFormatUtil.Format(iText.StyledXmlParser.LogMessageConstant.SHORTHAND_PROPERTY_CANNOT_BE_EMPTY , CommonCssConstants.BACKGROUND_POSITION)); return(new List <CssDeclaration>()); } IList <IList <String> > propsList = CssUtils.ExtractShorthandProperties(shorthandExpression); IDictionary <String, String> resolvedProps = new Dictionary <String, String>(); IDictionary <String, String> values = new Dictionary <String, String>(); foreach (IList <String> props in propsList) { if (props.IsEmpty()) { LOGGER.Error(MessageFormatUtil.Format(iText.StyledXmlParser.LogMessageConstant.SHORTHAND_PROPERTY_CANNOT_BE_EMPTY , CommonCssConstants.BACKGROUND_POSITION)); return(new List <CssDeclaration>()); } if (!ParsePositionShorthand(props, values)) { LOGGER.Error(MessageFormatUtil.Format(iText.StyledXmlParser.LogMessageConstant.INVALID_CSS_PROPERTY_DECLARATION , shorthandExpression)); return(new List <CssDeclaration>()); } UpdateValue(resolvedProps, values, CommonCssConstants.BACKGROUND_POSITION_X); UpdateValue(resolvedProps, values, CommonCssConstants.BACKGROUND_POSITION_Y); values.Clear(); } if (!CheckProperty(resolvedProps, CommonCssConstants.BACKGROUND_POSITION_X) || !CheckProperty(resolvedProps , CommonCssConstants.BACKGROUND_POSITION_Y)) { return(new List <CssDeclaration>()); } return(JavaUtil.ArraysAsList(new CssDeclaration(CommonCssConstants.BACKGROUND_POSITION_X, resolvedProps.Get (CommonCssConstants.BACKGROUND_POSITION_X)), new CssDeclaration(CommonCssConstants.BACKGROUND_POSITION_Y , resolvedProps.Get(CommonCssConstants.BACKGROUND_POSITION_Y)))); }