Package org.apache.struts2.util.location
Class LocationUtils
java.lang.Object
org.apache.struts2.util.location.LocationUtils
Location-related utility methods.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceAn finder or object locations -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringThe string representation of an unknown location: "[unknown location]". -
Method Summary
Modifier and TypeMethodDescriptionstatic voidAdd aLocationUtils.LocationFinderto the list of finders that will be queried for an object's location bygetLocation(Object, String).static LocationgetLocation(Object obj) Get the location of an object.static LocationgetLocation(Object obj, String description) Get the location of an object.static booleanChecks if a location is known, i.e.static booleanChecks if a location is unknown, i.e.static LocationImplParse a location string of the form "uri:line:column" (e.g.static StringBuilds a string representation of a location, in the "descripton - uri:line:column" format (e.g.
-
Field Details
-
UNKNOWN_STRING
The string representation of an unknown location: "[unknown location]".- See Also:
-
-
Method Details
-
toString
Builds a string representation of a location, in the "descripton - uri:line:column" format (e.g. "foo - file://path/to/file.xml:3:40"). Foran unknown location, returnsUNKNOWN_STRING.- Parameters:
location- location object- Returns:
- the string representation
-
parse
Parse a location string of the form "uri:line:column" (e.g. "path/to/file.xml:3:40") to a Location object. Additionally, a description may also optionally be present, separated with an hyphen (e.g. "foo - path/to/file.xml:3.40").- Parameters:
text- the text to parse- Returns:
- the location (possibly
nullif text was null or in an incorrect format) - Throws:
IllegalArgumentException
-
isKnown
Checks if a location is known, i.e. it is not null nor equal toLocation.UNKNOWN.- Parameters:
location- the location to check- Returns:
trueif the location is known
-
isUnknown
Checks if a location is unknown, i.e. it is either null or equal toLocation.UNKNOWN.- Parameters:
location- the location to check- Returns:
trueif the location is unknown
-
addFinder
Add aLocationUtils.LocationFinderto the list of finders that will be queried for an object's location bygetLocation(Object, String).Important: LocationUtils internally stores a weak reference to the finder. This avoids creating strong links between the classloader holding this class and the finder's classloader, which can cause some weird memory leaks if the finder's classloader is to be reloaded. Therefore, you have to keep a strong reference to the finder in the calling code, e.g.:
private static LocationUtils.LocationFinder myFinder = new LocationUtils.LocationFinder() { public Location getLocation(Object obj, String desc) { ... } }; static { LocationUtils.addFinder(myFinder); }- Parameters:
finder- the location finder to add
-
getLocation
Get the location of an object. Some well-known located classes built in the JDK are handled by this method. Handling of other located classes can be handled by adding new location finders.- Parameters:
obj- the object of which to get the location- Returns:
- the object's location, or
Location.UNKNOWNif no location could be found
-
getLocation
Get the location of an object. Some well-known located classes built in the JDK are handled by this method. Handling of other located classes can be handled by adding new location finders.- Parameters:
obj- the object of which to get the locationdescription- an optional description of the object's location, used if a Location object has to be created.- Returns:
- the object's location, or
Location.UNKNOWNif no location could be found
-