com.opensymphony.xwork2.util.location
Class LocationAttributes

java.lang.Object
  extended by com.opensymphony.xwork2.util.location.LocationAttributes

public class LocationAttributes
extends java.lang.Object

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://opensymphony.com/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
Version:
$Id: LocationAttributes.java 894087 2009-12-27 18:00:13Z martinc $
See Also:
LocationAttributes.Pipe

Nested Class Summary
static class LocationAttributes.Pipe
          A SAX filter that adds the information available from the Locator as attributes.
 
Field Summary
static java.lang.String COL_ATTR
          Attribute name for the column number
static java.lang.String LINE_ATTR
          Attribute name for the line number
static java.lang.String PREFIX
          Prefix for the location namespace
static java.lang.String Q_COL_ATTR
          Attribute qualified name for the column number
static java.lang.String Q_LINE_ATTR
          Attribute qualified name for the line number
static java.lang.String Q_SRC_ATTR
          Attribute qualified name for the location URI
static java.lang.String SRC_ATTR
          Attribute name for the location URI
static java.lang.String URI
          Namespace URI for location attributes
 
Method Summary
static org.xml.sax.Attributes addLocationAttributes(org.xml.sax.Locator locator, org.xml.sax.Attributes attrs)
          Add location attributes to a set of SAX attributes.
static int getColumn(org.xml.sax.Attributes attrs)
          Returns the column number of an element (SAX flavor)
static int getColumn(org.w3c.dom.Element elem)
          Returns the column number of an element (DOM flavor)
static int getLine(org.xml.sax.Attributes attrs)
          Returns the line number of an element (SAX flavor)
static int getLine(org.w3c.dom.Element elem)
          Returns the line number of an element (DOM flavor)
static Location getLocation(org.xml.sax.Attributes attrs, java.lang.String description)
          Returns the Location of an element (SAX flavor).
static Location getLocation(org.w3c.dom.Element elem)
          Same as getLocation(elem, null).
static Location getLocation(org.w3c.dom.Element elem, java.lang.String description)
          Returns the Location of an element (DOM flavor).
static java.lang.String getLocationString(org.xml.sax.Attributes attrs)
          Returns the location of an element (SAX flavor).
static java.lang.String getLocationString(org.w3c.dom.Element elem)
          Returns the location of an element that has been processed by this pipe (DOM flavor).
static java.lang.String getURI(org.xml.sax.Attributes attrs)
          Returns the URI of an element (SAX flavor)
static java.lang.String getURI(org.w3c.dom.Element elem)
          Returns the URI of an element (DOM flavor)
static void remove(org.w3c.dom.Element elem, boolean recurse)
          Remove the location attributes from a DOM element.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

PREFIX

public static final java.lang.String PREFIX
Prefix for the location namespace

See Also:
Constant Field Values

URI

public static final java.lang.String URI
Namespace URI for location attributes

See Also:
Constant Field Values

SRC_ATTR

public static final java.lang.String SRC_ATTR
Attribute name for the location URI

See Also:
Constant Field Values

LINE_ATTR

public static final java.lang.String LINE_ATTR
Attribute name for the line number

See Also:
Constant Field Values

COL_ATTR

public static final java.lang.String COL_ATTR
Attribute name for the column number

See Also:
Constant Field Values

Q_SRC_ATTR

public static final java.lang.String Q_SRC_ATTR
Attribute qualified name for the location URI

See Also:
Constant Field Values

Q_LINE_ATTR

public static final java.lang.String Q_LINE_ATTR
Attribute qualified name for the line number

See Also:
Constant Field Values

Q_COL_ATTR

public static final java.lang.String Q_COL_ATTR
Attribute qualified name for the column number

See Also:
Constant Field Values
Method Detail

addLocationAttributes

public static org.xml.sax.Attributes addLocationAttributes(org.xml.sax.Locator locator,
                                                           org.xml.sax.Attributes attrs)
Add location attributes to a set of SAX attributes.

Parameters:
locator - the Locator (can be null)
attrs - the Attributes where locator information should be added
Returns:
Location enabled Attributes.

getLocation

public static Location getLocation(org.xml.sax.Attributes attrs,
                                   java.lang.String description)
Returns the Location of an element (SAX flavor).

Parameters:
attrs - the element's attributes that hold the location information
description - a description for the location (can be null)
Returns:
a Location object

getLocationString

public static java.lang.String getLocationString(org.xml.sax.Attributes attrs)
Returns the location of an element (SAX flavor). If the location is to be kept into an object built from this element, consider using getLocation(Attributes, String) and the Locatable interface.

Parameters:
attrs - the element's attributes that hold the location information
Returns:
a location string as defined by Location.

getURI

public static java.lang.String getURI(org.xml.sax.Attributes attrs)
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]" if attrs has no location information.

getLine

public static int getLine(org.xml.sax.Attributes attrs)
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 if attrs has no location information.

getColumn

public static int getColumn(org.xml.sax.Attributes attrs)
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 if attrs has no location information.

getLocation

public static Location getLocation(org.w3c.dom.Element elem,
                                   java.lang.String description)
Returns the Location of an element (DOM flavor).

Parameters:
elem - the element that holds the location information
description - a description for the location (if null, the element's name is used)
Returns:
a Location object

getLocation

public static Location getLocation(org.w3c.dom.Element elem)
Same as getLocation(elem, null).


getLocationString

public static java.lang.String getLocationString(org.w3c.dom.Element elem)
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 using getLocation(Element) and the Locatable interface.

Parameters:
elem - the element that holds the location information
Returns:
a location string as defined by Location.

getURI

public static java.lang.String getURI(org.w3c.dom.Element elem)
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]" if elem has no location information.

getLine

public static int getLine(org.w3c.dom.Element elem)
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 if elem has no location information.

getColumn

public static int getColumn(org.w3c.dom.Element elem)
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 if elem has no location information.

remove

public static void remove(org.w3c.dom.Element elem,
                          boolean recurse)
Remove the location attributes from a DOM element.

Parameters:
elem - the element to remove the location attributes from.
recurse - if true, also remove location attributes on descendant elements.


Copyright © 2000-2011 Apache Software Foundation. All Rights Reserved.