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
Nested ClassesModifier and TypeClassDescriptionstatic classA SAX filter that adds the information available from theLocatoras attributes. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringAttribute name for the column numberstatic final StringAttribute name for the line numberstatic final StringPrefix for the location namespacestatic final StringAttribute qualified name for the column numberstatic final StringAttribute qualified name for the line numberstatic final StringAttribute qualified name for the location URIstatic final StringAttribute name for the location URIstatic final StringNamespace URI for location attributes -
Method Summary
Modifier and TypeMethodDescriptionstatic AttributesaddLocationAttributes(Locator locator, Attributes attrs) Add location attributes to a set of SAX attributes.static intReturns the column number of an element (DOM flavor)static intgetColumn(Attributes attrs) Returns the column number of an element (SAX flavor)static intReturns the line number of an element (DOM flavor)static intgetLine(Attributes attrs) Returns the line number of an element (SAX flavor)static LocationgetLocation(Element elem) Same asgetLocation(elem, null).static LocationgetLocation(Element elem, String description) Returns theLocationof an element (DOM flavor).static LocationgetLocation(Attributes attrs, String description) Returns theLocationof an element (SAX flavor).static StringgetLocationString(Element elem) Returns the location of an element that has been processed by this pipe (DOM flavor).static StringgetLocationString(Attributes attrs) Returns the location of an element (SAX flavor).static StringReturns the URI of an element (DOM flavor)static StringgetURI(Attributes attrs) Returns the URI of an element (SAX flavor)static voidRemove 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- theAttributeswhere locator information should be added- Returns:
- Location enabled Attributes.
-
getLocation
Returns theLocationof 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
Locationobject
-
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 theLocatableinterface.- 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]" ifattrshas 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
-1ifattrshas 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
-1ifattrshas no location information.
-
getLocation
Returns theLocationof 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
Locationobject
-
getLocation
Same asgetLocation(elem, null).- Parameters:
elem- the element that holds the location information- Returns:
- a
Locationobject
-
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 theLocatableinterface.- 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]" ifelemhas 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
-1ifelemhas 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
-1ifelemhas 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.
-