Package com.itextpdf.tool.xml.css
Class StyleAttrCSSResolver
- java.lang.Object
-
- com.itextpdf.tool.xml.css.StyleAttrCSSResolver
-
- All Implemented Interfaces:
CSSResolver
public class StyleAttrCSSResolver extends java.lang.Object implements CSSResolver
Resolves CSS properties.
-
-
Field Summary
Fields Modifier and Type Field Description private CssFilescssFilesprivate CssInheritanceRulesinheritprivate FileRetrieveretrievestatic java.lang.StringSTYLEprivate CssUtilsutils
-
Constructor Summary
Constructors Constructor Description StyleAttrCSSResolver()Construct a newStyleAttrCSSResolverwith default settings.StyleAttrCSSResolver(CssFiles cssFiles)Construct a new StyleAttrCSSResolver with the givenCssFilesand theDefaultCssInheritanceRules.StyleAttrCSSResolver(CssFiles cssFiles, CssUtils utils)Construct a new StyleAttrCSSResolver with the givenCssFilesandCssUtilsand theDefaultCssInheritanceRules.StyleAttrCSSResolver(CssFiles cssFiles, FileRetrieve r)StyleAttrCSSResolver(CssInheritanceRules rules, CssFiles cssFiles, CssUtils utils)StyleAttrCSSResolver(CssInheritanceRules rules, CssFiles cssFiles, CssUtils utils, FileRetrieve fileRetrieve)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddCss(CssFile file)Add a file to the CssFiles Collection.voidaddCss(java.lang.String content, boolean isPersistent)Add a piece of CSS code.voidaddCss(java.lang.String content, java.lang.String charSet, boolean isPersistent)Add a piece of CSS code.voidaddCssFile(java.lang.String href, boolean isPersistent)Add a file to the CssFiles Collection.private booleancanInherite(Tag t, java.lang.String property)Defaults to true if noCssInheritanceRulesimplementation set.CSSResolverclear()private java.lang.StringmergeTextDecorationRules(java.lang.String oldRule, java.lang.String newRule)private booleanmustInherit(java.lang.String tag)Defaults to true if noCssInheritanceRulesimplementation set.voidresolveStyles(Tag t)Also taking into account the CSS properties of any parent tag in the given tag.voidsetCssInheritance(CssInheritanceRules cssInheritanceRules)By setting an implementation ofCssInheritanceRulesa developer can set rules on what css selectors are inherited from parent tags.voidsetCssInheritanceRules(CssInheritanceRules inherit)voidsetFileRetrieve(FileRetrieve retrieve)TheFileRetrieveimplementation to use inaddCss(String, boolean).private voidsplitRules(java.util.Map<java.lang.String,java.lang.String> css, java.lang.String key, java.lang.String value)
-
-
-
Field Detail
-
STYLE
public static final java.lang.String STYLE
- See Also:
- Constant Field Values
-
utils
private final CssUtils utils
-
inherit
private CssInheritanceRules inherit
-
cssFiles
private final CssFiles cssFiles
-
retrieve
private FileRetrieve retrieve
-
-
Constructor Detail
-
StyleAttrCSSResolver
public StyleAttrCSSResolver()
Construct a newStyleAttrCSSResolverwith default settings.
-
StyleAttrCSSResolver
public StyleAttrCSSResolver(CssFiles cssFiles)
Construct a new StyleAttrCSSResolver with the givenCssFilesand theDefaultCssInheritanceRules.- Parameters:
cssFiles- aCssFilesimplementation.
-
StyleAttrCSSResolver
public StyleAttrCSSResolver(CssFiles cssFiles, CssUtils utils)
Construct a new StyleAttrCSSResolver with the givenCssFilesandCssUtilsand theDefaultCssInheritanceRules.- Parameters:
cssFiles- aCssFilesimplementation.utils- the CssUtils to use.
-
StyleAttrCSSResolver
public StyleAttrCSSResolver(CssInheritanceRules rules, CssFiles cssFiles, CssUtils utils)
- Parameters:
rules- theCssInheritanceRulesto use.cssFiles- aCssFilesimplementation.utils- the CssUtils to use.
-
StyleAttrCSSResolver
public StyleAttrCSSResolver(CssInheritanceRules rules, CssFiles cssFiles, CssUtils utils, FileRetrieve fileRetrieve)
- Parameters:
rules- theCssInheritanceRulesto use.cssFiles- aCssFilesimplementation.utils- the CssUtils to use.fileRetrieve- theFileRetrieveimplementation
-
StyleAttrCSSResolver
public StyleAttrCSSResolver(CssFiles cssFiles, FileRetrieve r)
- Parameters:
cssFiles- theCssFileimplementationr- theFileRetrieveimplementation
-
-
Method Detail
-
resolveStyles
public void resolveStyles(Tag t)
Also taking into account the CSS properties of any parent tag in the given tag.- Specified by:
resolveStylesin interfaceCSSResolver- Parameters:
t- the tag.- See Also:
CSSResolver.resolveStyles(com.itextpdf.tool.xml.Tag)
-
mergeTextDecorationRules
private java.lang.String mergeTextDecorationRules(java.lang.String oldRule, java.lang.String newRule)
-
splitRules
private void splitRules(java.util.Map<java.lang.String,java.lang.String> css, java.lang.String key, java.lang.String value)- Parameters:
css- the css map to populatekey- the propertyvalue- the value
-
setCssInheritance
public void setCssInheritance(CssInheritanceRules cssInheritanceRules)
By setting an implementation ofCssInheritanceRulesa developer can set rules on what css selectors are inherited from parent tags.- Parameters:
cssInheritanceRules- the inherit to set
-
canInherite
private boolean canInherite(Tag t, java.lang.String property)
Defaults to true if noCssInheritanceRulesimplementation set.- Parameters:
t-property-- Returns:
- true if may be inherited false otherwise
-
mustInherit
private boolean mustInherit(java.lang.String tag)
Defaults to true if noCssInheritanceRulesimplementation set.- Parameters:
tag-- Returns:
- true if must be inherited false otherwise
-
addCss
public void addCss(java.lang.String content, java.lang.String charSet, boolean isPersistent) throws CssResolverExceptionDescription copied from interface:CSSResolverAdd a piece of CSS code.- Specified by:
addCssin interfaceCSSResolver- Parameters:
content- the CSScharSet- a charsetisPersistent- true if the added css should not be deleted on a call to clear- Throws:
CssResolverException- thrown if something goes wrong
-
addCssFile
public void addCssFile(java.lang.String href, boolean isPersistent) throws CssResolverExceptionAdd a file to the CssFiles Collection.- Specified by:
addCssFilein interfaceCSSResolver- Parameters:
href- the path, if it starts with http we try to retrieve the file from the net, if not we try a normal file operation.isPersistent- true if the added css should not be deleted on a call to clear- Throws:
CssResolverException- thrown if something goes wrong
-
addCss
public void addCss(CssFile file)
Add a file to the CssFiles Collection.- Specified by:
addCssin interfaceCSSResolver- Parameters:
file- the CssFile to add.
-
addCss
public void addCss(java.lang.String content, boolean isPersistent) throws CssResolverExceptionDescription copied from interface:CSSResolverAdd a piece of CSS code.- Specified by:
addCssin interfaceCSSResolver- Parameters:
content- the content to parse to cssisPersistent- true if the added css should not be deleted on a call to clear- Throws:
CssResolverException- thrown if something goes wrong
-
setCssInheritanceRules
public void setCssInheritanceRules(CssInheritanceRules inherit)
- Parameters:
inherit- the inherit to set
-
setFileRetrieve
public void setFileRetrieve(FileRetrieve retrieve)
TheFileRetrieveimplementation to use inaddCss(String, boolean).- Specified by:
setFileRetrievein interfaceCSSResolver- Parameters:
retrieve- the retrieve to set
-
clear
public CSSResolver clear() throws CssResolverException
- Specified by:
clearin interfaceCSSResolver- Returns:
- an instance of this resolver
- Throws:
CssResolverException- thrown if something goes wrong
-
-