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 CssFiles
cssFiles
private CssInheritanceRules
inherit
private FileRetrieve
retrieve
static java.lang.String
STYLE
private CssUtils
utils
-
Constructor Summary
Constructors Constructor Description StyleAttrCSSResolver()
Construct a newStyleAttrCSSResolver
with default settings.StyleAttrCSSResolver(CssFiles cssFiles)
Construct a new StyleAttrCSSResolver with the givenCssFiles
and theDefaultCssInheritanceRules
.StyleAttrCSSResolver(CssFiles cssFiles, CssUtils utils)
Construct a new StyleAttrCSSResolver with the givenCssFiles
andCssUtils
and 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 void
addCss(CssFile file)
Add a file to the CssFiles Collection.void
addCss(java.lang.String content, boolean isPersistent)
Add a piece of CSS code.void
addCss(java.lang.String content, java.lang.String charSet, boolean isPersistent)
Add a piece of CSS code.void
addCssFile(java.lang.String href, boolean isPersistent)
Add a file to the CssFiles Collection.private boolean
canInherite(Tag t, java.lang.String property)
Defaults to true if noCssInheritanceRules
implementation set.CSSResolver
clear()
private java.lang.String
mergeTextDecorationRules(java.lang.String oldRule, java.lang.String newRule)
private boolean
mustInherit(java.lang.String tag)
Defaults to true if noCssInheritanceRules
implementation set.void
resolveStyles(Tag t)
Also taking into account the CSS properties of any parent tag in the given tag.void
setCssInheritance(CssInheritanceRules cssInheritanceRules)
By setting an implementation ofCssInheritanceRules
a developer can set rules on what css selectors are inherited from parent tags.void
setCssInheritanceRules(CssInheritanceRules inherit)
void
setFileRetrieve(FileRetrieve retrieve)
TheFileRetrieve
implementation to use inaddCss(String, boolean)
.private void
splitRules(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 newStyleAttrCSSResolver
with default settings.
-
StyleAttrCSSResolver
public StyleAttrCSSResolver(CssFiles cssFiles)
Construct a new StyleAttrCSSResolver with the givenCssFiles
and theDefaultCssInheritanceRules
.- Parameters:
cssFiles
- aCssFiles
implementation.
-
StyleAttrCSSResolver
public StyleAttrCSSResolver(CssFiles cssFiles, CssUtils utils)
Construct a new StyleAttrCSSResolver with the givenCssFiles
andCssUtils
and theDefaultCssInheritanceRules
.- Parameters:
cssFiles
- aCssFiles
implementation.utils
- the CssUtils to use.
-
StyleAttrCSSResolver
public StyleAttrCSSResolver(CssInheritanceRules rules, CssFiles cssFiles, CssUtils utils)
- Parameters:
rules
- theCssInheritanceRules
to use.cssFiles
- aCssFiles
implementation.utils
- the CssUtils to use.
-
StyleAttrCSSResolver
public StyleAttrCSSResolver(CssInheritanceRules rules, CssFiles cssFiles, CssUtils utils, FileRetrieve fileRetrieve)
- Parameters:
rules
- theCssInheritanceRules
to use.cssFiles
- aCssFiles
implementation.utils
- the CssUtils to use.fileRetrieve
- theFileRetrieve
implementation
-
StyleAttrCSSResolver
public StyleAttrCSSResolver(CssFiles cssFiles, FileRetrieve r)
- Parameters:
cssFiles
- theCssFile
implementationr
- theFileRetrieve
implementation
-
-
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:
resolveStyles
in 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 ofCssInheritanceRules
a 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 noCssInheritanceRules
implementation set.- Parameters:
t
-property
-- Returns:
- true if may be inherited false otherwise
-
mustInherit
private boolean mustInherit(java.lang.String tag)
Defaults to true if noCssInheritanceRules
implementation 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 CssResolverException
Description copied from interface:CSSResolver
Add a piece of CSS code.- Specified by:
addCss
in 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 CssResolverException
Add a file to the CssFiles Collection.- Specified by:
addCssFile
in 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:
addCss
in interfaceCSSResolver
- Parameters:
file
- the CssFile to add.
-
addCss
public void addCss(java.lang.String content, boolean isPersistent) throws CssResolverException
Description copied from interface:CSSResolver
Add a piece of CSS code.- Specified by:
addCss
in 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)
TheFileRetrieve
implementation to use inaddCss(String, boolean)
.- Specified by:
setFileRetrieve
in interfaceCSSResolver
- Parameters:
retrieve
- the retrieve to set
-
clear
public CSSResolver clear() throws CssResolverException
- Specified by:
clear
in interfaceCSSResolver
- Returns:
- an instance of this resolver
- Throws:
CssResolverException
- thrown if something goes wrong
-
-