Package org.apache.batik.dom.svg
Class AbstractSVGList
- java.lang.Object
-
- org.apache.batik.dom.svg.AbstractSVGList
-
- Direct Known Subclasses:
AbstractSVGLengthList,AbstractSVGNumberList,AbstractSVGPathSegList,AbstractSVGPointList,AbstractSVGTransformList
public abstract class AbstractSVGList extends java.lang.ObjectThis class is a base implementation for a live list representation of SVG attributes.This class provides support for an SVG list representation of an attribute. It implements basic list functionality that is common to all of the
SVG*Listinterfaces.For a specific attribute, it requires an
attribute value, aparser, and a method tocreate items.Whenever the attribute changes outside of the control of the list, this list must be
invalidated.- Version:
- $Id: AbstractSVGList.java 1804130 2017-08-04 14:41:11Z ssteiner $
-
-
Constructor Summary
Constructors Constructor Description AbstractSVGList()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected SVGItemappendItemImpl(java.lang.Object newItem)Inserts a new item at the end of the list.protected abstract voidcheckItemType(java.lang.Object newItem)Asserts that the given object is an appropriate SVG object for this list.voidclear()Removes all items from the list.protected voidclear(java.util.List list)Clears the list and sets the parent of the former list items to null.protected abstract org.w3c.dom.DOMExceptioncreateDOMException(short type, java.lang.String key, java.lang.Object[] args)Create a DOM Exception.protected abstract SVGItemcreateSVGItem(java.lang.Object newItem)Creates anSVGItemobject that has the same values as those in the specified SVG object.protected abstract voiddoParse(java.lang.String value, ListHandler builder)Parses the given attribute value and informs the specifiedListHandlerof the parsed list items.protected SVGItemgetItemImpl(int index)Returns the item from the list at the specified index.protected abstract java.lang.StringgetItemSeparator()Returns the separator string to use when constructing a string representation of the entire list.intgetNumberOfItems()Returns the number of items in the list.protected abstract java.lang.StringgetValueAsString()Returns the value of the DOM attribute containing the list.protected SVGIteminitializeImpl(java.lang.Object newItem)Removes all items from the list and adds the specified item to the list.protected SVGIteminsertItemBeforeImpl(java.lang.Object newItem, int index)Inserts a new item into the list at the specified position.voidinvalidate()Invalidates this list.voiditemChanged()Method to be called by a memberSVGItemobject when its value changes.protected SVGItemremoveIfNeeded(java.lang.Object newItem)Removes the specified object from its parent list if it is an item, or creates a new item if the specified object is not an item.protected voidremoveItem(SVGItem item)Removes an item from the list.protected SVGItemremoveItemImpl(int index)Removes an existing item from the list.protected SVGItemreplaceItemImpl(java.lang.Object newItem, int index)Replaces an existing item in the list with a new item.protected voidresetAttribute()Resets the value of the associated attribute.protected voidresetAttribute(SVGItem item)Appends the string representation of the givenSVGItemto the DOM attribute.protected voidrevalidate()Initializes the list, if needed.protected abstract voidsetAttributeValue(java.lang.String value)Sets the DOM attribute value containing the number list.protected voidsetValueAsString(java.util.List value)Sets the DOM attribute value to be the string representation of the given list.
-
-
-
Method Detail
-
getItemSeparator
protected abstract java.lang.String getItemSeparator()
Returns the separator string to use when constructing a string representation of the entire list.
-
createSVGItem
protected abstract SVGItem createSVGItem(java.lang.Object newItem)
Creates anSVGItemobject that has the same values as those in the specified SVG object.- Parameters:
newItem- the SVG object- Returns:
- the newly created
SVGItemobject
-
doParse
protected abstract void doParse(java.lang.String value, ListHandler builder) throws ParseExceptionParses the given attribute value and informs the specifiedListHandlerof the parsed list items.- Parameters:
value- the attribute value to be parsedbuilder- the object to be informed of the parsed list items- Throws:
ParseException
-
checkItemType
protected abstract void checkItemType(java.lang.Object newItem) throws org.w3c.dom.svg.SVGExceptionAsserts that the given object is an appropriate SVG object for this list.- Throws:
org.w3c.dom.svg.SVGException
-
getValueAsString
protected abstract java.lang.String getValueAsString()
Returns the value of the DOM attribute containing the list.
-
setAttributeValue
protected abstract void setAttributeValue(java.lang.String value)
Sets the DOM attribute value containing the number list.- Parameters:
value- the String representation of the list, or null if the list contains no items
-
createDOMException
protected abstract org.w3c.dom.DOMException createDOMException(short type, java.lang.String key, java.lang.Object[] args)Create a DOM Exception.
-
getNumberOfItems
public int getNumberOfItems()
Returns the number of items in the list.
-
clear
public void clear() throws org.w3c.dom.DOMExceptionRemoves all items from the list.- Throws:
org.w3c.dom.DOMException- NO_MODIFICATION_ALLOWED_ERR: Raised when the list cannot be modified.
-
initializeImpl
protected SVGItem initializeImpl(java.lang.Object newItem) throws org.w3c.dom.DOMException, org.w3c.dom.svg.SVGException
Removes all items from the list and adds the specified item to the list.- Parameters:
newItem- the item which should become the only member of the list.- Returns:
- the item being inserted into the list.
- Throws:
org.w3c.dom.DOMException- NO_MODIFICATION_ALLOWED_ERR: Raised when the list cannot be modified.org.w3c.dom.svg.SVGException- SVG_WRONG_TYPE_ERR: Raised if parameter newItem is the wrong type of object for the given list.
-
getItemImpl
protected SVGItem getItemImpl(int index) throws org.w3c.dom.DOMException
Returns the item from the list at the specified index.- Parameters:
index- The index of the item from the list which is to be returned. The first item is number 0.- Returns:
- The selected item.
- Throws:
org.w3c.dom.DOMException- INDEX_SIZE_ERR: Raised if the index number is negative or greater than or equal tonumberOfItems.
-
insertItemBeforeImpl
protected SVGItem insertItemBeforeImpl(java.lang.Object newItem, int index) throws org.w3c.dom.DOMException, org.w3c.dom.svg.SVGException
Inserts a new item into the list at the specified position.The first item is number 0. If
newItemis already in a list, it is removed from its previous list before it is inserted into this list.- Parameters:
newItem- The item which is to be inserted into the list.index- The index of the item before which the new item is to be inserted. The first item is number 0. If the index is equal to 0, then the new item is inserted at the front of the list. If the index is greater than or equal tonumberOfItems, then the new item is appended to the end of the list.- Returns:
- The inserted item.
- Throws:
org.w3c.dom.DOMException- NO_MODIFICATION_ALLOWED_ERR: Raised when the list cannot be modified.org.w3c.dom.svg.SVGException- SVG_WRONG_TYPE_ERR: Raised if parameternewItemis the wrong type of object for the given list.
-
replaceItemImpl
protected SVGItem replaceItemImpl(java.lang.Object newItem, int index) throws org.w3c.dom.DOMException, org.w3c.dom.svg.SVGException
Replaces an existing item in the list with a new item.If
newItemis already in a list, it is removed from its previous list before it is inserted into this list.- Parameters:
newItem- The item which is to be inserted into the list.index- The index of the item which is to be replaced. The first item is number 0.- Returns:
- The inserted item.
- Throws:
org.w3c.dom.DOMException- NO_MODIFICATION_ALLOWED_ERR: Raised when the list cannot be modified.org.w3c.dom.DOMException- INDEX_SIZE_ERR: Raised if the index number is negative or greater than or equal tonumberOfItems.org.w3c.dom.svg.SVGException- SVG_WRONG_TYPE_ERR: Raised if parameter newItem is the wrong type of object for the given list.
-
removeItemImpl
protected SVGItem removeItemImpl(int index) throws org.w3c.dom.DOMException
Removes an existing item from the list.- Parameters:
index- The index of the item which is to be removed. The first item is number 0.- Returns:
- The removed item.
- Throws:
org.w3c.dom.DOMException- NO_MODIFICATION_ALLOWED_ERR: Raised when the list cannot be modified.org.w3c.dom.DOMException- INDEX_SIZE_ERR: Raised if the index number is negative or greater than or equal tonumberOfItems.
-
appendItemImpl
protected SVGItem appendItemImpl(java.lang.Object newItem) throws org.w3c.dom.DOMException, org.w3c.dom.svg.SVGException
Inserts a new item at the end of the list. If newItem is already in a list, it is removed from its previous list before it is inserted into this list.- Parameters:
newItem- The item which is to be inserted into the list. The first item is number 0.- Returns:
- The inserted item.
- Throws:
org.w3c.dom.DOMException- NO_MODIFICATION_ALLOWED_ERR: Raised when the list cannot be modified.org.w3c.dom.svg.SVGException- SVG_WRONG_TYPE_ERR: Raised if parameter newItem is the wrong type of object for the given list.
-
removeIfNeeded
protected SVGItem removeIfNeeded(java.lang.Object newItem)
Removes the specified object from its parent list if it is an item, or creates a new item if the specified object is not an item.
-
revalidate
protected void revalidate()
Initializes the list, if needed.
-
setValueAsString
protected void setValueAsString(java.util.List value) throws org.w3c.dom.DOMExceptionSets the DOM attribute value to be the string representation of the given list.- Throws:
org.w3c.dom.DOMException
-
itemChanged
public void itemChanged()
Method to be called by a memberSVGItemobject when its value changes. This causes the DOM attribute to be reset.
-
resetAttribute
protected void resetAttribute()
Resets the value of the associated attribute.
-
resetAttribute
protected void resetAttribute(SVGItem item)
Appends the string representation of the givenSVGItemto the DOM attribute. This is called in response to an append to the list.
-
invalidate
public void invalidate()
Invalidates this list.
-
removeItem
protected void removeItem(SVGItem item)
Removes an item from the list. This operation takes place when an item was already in one list and is being added to another one.
-
clear
protected void clear(java.util.List list)
Clears the list and sets the parent of the former list items to null.
-
-