Class MarkupParser
- java.lang.Object
-
- java.util.AbstractMap<K,V>
-
- java.util.HashMap
-
- com.gitlab.pdftk_java.com.lowagie.text.markup.MarkupParser
-
- All Implemented Interfaces:
Serializable,Cloneable,Map
public class MarkupParser extends HashMap
This class is a HashMap that contains selectors (String) and styles (a Properties object). Given a tag and its attributes (id/class), this class can return an iText object with the according style.- Author:
- blowagie
- See Also:
- Serialized Form
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class java.util.AbstractMap
AbstractMap.SimpleEntry<K extends Object,V extends Object>, AbstractMap.SimpleImmutableEntry<K extends Object,V extends Object>
-
-
Field Summary
Fields Modifier and Type Field Description protected HashMapfontcacheHashMap with fonts for each known combination of tag/id/class.protected HashMapstylecacheHashMap with styles for each known combination of tag/id/class.
-
Constructor Summary
Constructors Constructor Description MarkupParser(String file)Creates new MarkupParser
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static ColordecodeColor(String color)Converts aColorinto a HTML representation of thisColor.FontgetFont(Properties attributes)Returns a font based on the ID and CLASS attributes of a tag.ElementgetObject(Properties attributes)Returns an object based on a tag and its attributes.booleangetPageBreakAfter(Properties attributes)Returns pagebreak information.booleangetPageBreakBefore(Properties attributes)Returns pagebreak information.RectanglegetRectangle(Properties attrs)Returns a rectangle based on the width and height attributes of a tag, can be overridden by the ID and CLASS attributes.static PropertiesparseAttributes(String string)This method parses a String with attributes and returns a Properties object.static floatparseLength(String string)Parses a length.static StringremoveComment(String string, String startComment, String endComment)Removes the comments sections of a String.FontretrieveFont(Properties styleAttributes)Retrieves a font from the FontFactory based on some style attributes.ElementretrieveParagraph(Font font, Properties styleattributes)Retrieves a Paragraph based on some style attributes.ElementretrievePhrase(Font font, Properties styleattributes)Retrieves a Phrase based on some style attributes.-
Methods inherited from class java.util.HashMap
clear, clone, compute, computeIfAbsent, computeIfPresent, containsKey, containsValue, entrySet, forEach, get, getOrDefault, isEmpty, keySet, merge, put, putAll, putIfAbsent, remove, remove, replace, replace, replaceAll, size, values
-
Methods inherited from class java.util.AbstractMap
equals, hashCode, toString
-
-
-
-
Field Detail
-
stylecache
protected HashMap stylecache
HashMap with styles for each known combination of tag/id/class. The key is a String-combination, the value a Properties object.
-
fontcache
protected HashMap fontcache
HashMap with fonts for each known combination of tag/id/class. The key is the same String-combination used for the stylecache.
-
-
Constructor Detail
-
MarkupParser
public MarkupParser(String file)
Creates new MarkupParser- Parameters:
file- the path to a CSS file.
-
-
Method Detail
-
removeComment
public static String removeComment(String string, String startComment, String endComment)
Removes the comments sections of a String.- Parameters:
string- the original StringstartComment- the String that marks the start of a Comment sectionendComment- the String that marks the end of a Comment section.- Returns:
- the String stripped of its comment section
-
parseAttributes
public static Properties parseAttributes(String string)
This method parses a String with attributes and returns a Properties object.- Parameters:
string- a String of this form: 'key1="value1"; key2="value2";... keyN="valueN" '- Returns:
- a Properties object
-
parseLength
public static float parseLength(String string)
Parses a length.- Parameters:
string- a length in the form of an optional + or -, followed by a number and a unit.- Returns:
- a float
-
decodeColor
public static Color decodeColor(String color)
Converts aColorinto a HTML representation of thisColor.- Parameters:
color- theColorthat has to be converted.- Returns:
- the HTML representation of this
Color
-
getPageBreakBefore
public boolean getPageBreakBefore(Properties attributes)
Returns pagebreak information.- Parameters:
attributes-- Returns:
- true if a page break is needed before the tag
-
getPageBreakAfter
public boolean getPageBreakAfter(Properties attributes)
Returns pagebreak information.- Parameters:
attributes-- Returns:
- true if a page break is needed after the tag
-
getObject
public Element getObject(Properties attributes)
Returns an object based on a tag and its attributes.- Parameters:
attributes- a Properties object with the tagname and the attributes of the tag.- Returns:
- an iText object
-
getFont
public Font getFont(Properties attributes)
Returns a font based on the ID and CLASS attributes of a tag.- Parameters:
attributes- a Properties object with the tagname and the attributes of the tag.- Returns:
- an iText Font;
-
getRectangle
public Rectangle getRectangle(Properties attrs)
Returns a rectangle based on the width and height attributes of a tag, can be overridden by the ID and CLASS attributes.- Parameters:
attrs- the attributes that came with the tag- Returns:
- an iText Rectangle object
-
retrievePhrase
public Element retrievePhrase(Font font, Properties styleattributes)
Retrieves a Phrase based on some style attributes.- Parameters:
font-styleattributes- a Properties object containing keys and values- Returns:
- an iText Phrase object
-
retrieveParagraph
public Element retrieveParagraph(Font font, Properties styleattributes)
Retrieves a Paragraph based on some style attributes.- Parameters:
font-styleattributes- a Properties object containing keys and values- Returns:
- an iText Paragraph object
-
retrieveFont
public Font retrieveFont(Properties styleAttributes)
Retrieves a font from the FontFactory based on some style attributes. Looks for the font-family, font-size, font-weight, font-style and color. Takes the default encoding and embedded value.- Parameters:
styleAttributes- a Properties object containing keys and values- Returns:
- an iText Font object
-
-