Package org.apache.struts2.util.location
Class LocationAttributes
java.lang.Object
org.apache.struts2.util.location.LocationAttributes
A class to handle location information stored in attributes.
These attributes are typically setup using LocationAttributes.Pipe
which augments the SAX stream with additional attributes, e.g.:
<root xmlns:loc="http://struts.apache.org/xwork/location" loc:src="file://path/to/file.xml" loc:line="1" loc:column="1"> <foo loc:src="file://path/to/file.xml" loc:line="2" loc:column="3"/> </root>
- Since:
- 2.1.8
- See Also:
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
A SAX filter that adds the information available from theLocator
as attributes. -
Field Summary
Modifier and TypeFieldDescriptionstatic final String
Attribute name for the column numberstatic final String
Attribute name for the line numberstatic final String
Prefix for the location namespacestatic final String
Attribute qualified name for the column numberstatic final String
Attribute qualified name for the line numberstatic final String
Attribute qualified name for the location URIstatic final String
Attribute name for the location URIstatic final String
Namespace URI for location attributes -
Method Summary
Modifier and TypeMethodDescriptionstatic Attributes
addLocationAttributes
(Locator locator, Attributes attrs) Add location attributes to a set of SAX attributes.static int
Returns the column number of an element (DOM flavor)static int
getColumn
(Attributes attrs) Returns the column number of an element (SAX flavor)static int
Returns the line number of an element (DOM flavor)static int
getLine
(Attributes attrs) Returns the line number of an element (SAX flavor)static Location
getLocation
(Element elem) Same asgetLocation(elem, null)
.static Location
getLocation
(Element elem, String description) Returns theLocation
of an element (DOM flavor).static Location
getLocation
(Attributes attrs, String description) Returns theLocation
of an element (SAX flavor).static String
getLocationString
(Element elem) Returns the location of an element that has been processed by this pipe (DOM flavor).static String
getLocationString
(Attributes attrs) Returns the location of an element (SAX flavor).static String
Returns the URI of an element (DOM flavor)static String
getURI
(Attributes attrs) Returns the URI of an element (SAX flavor)static void
Remove the location attributes from a DOM element.
-
Field Details
-
PREFIX
Prefix for the location namespace- See Also:
-
URI
Namespace URI for location attributes- See Also:
-
SRC_ATTR
Attribute name for the location URI- See Also:
-
LINE_ATTR
Attribute name for the line number- See Also:
-
COL_ATTR
Attribute name for the column number- See Also:
-
Q_SRC_ATTR
Attribute qualified name for the location URI- See Also:
-
Q_LINE_ATTR
Attribute qualified name for the line number- See Also:
-
Q_COL_ATTR
Attribute qualified name for the column number- See Also:
-
-
Method Details
-
addLocationAttributes
Add location attributes to a set of SAX attributes.- Parameters:
locator
- theLocator
(can be null)attrs
- theAttributes
where locator information should be added- Returns:
- Location enabled Attributes.
-
getLocation
Returns theLocation
of an element (SAX flavor).- Parameters:
attrs
- the element's attributes that hold the location informationdescription
- a description for the location (can be null)- Returns:
- a
Location
object
-
getLocationString
Returns the location of an element (SAX flavor). If the location is to be kept into an object built from this element, consider usinggetLocation(Attributes, String)
and theLocatable
interface.- Parameters:
attrs
- the element's attributes that hold the location information- Returns:
- a location string as defined by
Location
.
-
getURI
Returns the URI of an element (SAX flavor)- Parameters:
attrs
- the element's attributes that hold the location information- Returns:
- the element's URI or "
[unknown location]
" ifattrs
has no location information.
-
getLine
Returns the line number of an element (SAX flavor)- Parameters:
attrs
- the element's attributes that hold the location information- Returns:
- the element's line number or
-1
ifattrs
has no location information.
-
getColumn
Returns the column number of an element (SAX flavor)- Parameters:
attrs
- the element's attributes that hold the location information- Returns:
- the element's column number or
-1
ifattrs
has no location information.
-
getLocation
Returns theLocation
of an element (DOM flavor).- Parameters:
elem
- the element that holds the location informationdescription
- a description for the location (ifnull
, the element's name is used)- Returns:
- a
Location
object
-
getLocation
Same asgetLocation(elem, null)
.- Parameters:
elem
- the element that holds the location information- Returns:
- a
Location
object
-
getLocationString
Returns the location of an element that has been processed by this pipe (DOM flavor). If the location is to be kept into an object built from this element, consider usinggetLocation(Element)
and theLocatable
interface.- Parameters:
elem
- the element that holds the location information- Returns:
- a location string as defined by
Location
.
-
getURI
Returns the URI of an element (DOM flavor)- Parameters:
elem
- the element that holds the location information- Returns:
- the element's URI or "
[unknown location]
" ifelem
has no location information.
-
getLine
Returns the line number of an element (DOM flavor)- Parameters:
elem
- the element that holds the location information- Returns:
- the element's line number or
-1
ifelem
has no location information.
-
getColumn
Returns the column number of an element (DOM flavor)- Parameters:
elem
- the element that holds the location information- Returns:
- the element's column number or
-1
ifelem
has no location information.
-
remove
Remove the location attributes from a DOM element.- Parameters:
elem
- the element to remove the location attributes from.recurse
- iftrue
, also remove location attributes on descendant elements.
-