Package org.htmlunit
Class History
- java.lang.Object
-
- org.htmlunit.History
-
- All Implemented Interfaces:
java.io.Serializable
public class History extends java.lang.Object implements java.io.SerializableRepresentation of the navigation history of a single window.- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static classHistory.HistoryEntryThe single entry in the history.
-
Field Summary
Fields Modifier and Type Field Description private java.util.List<History.HistoryEntry>entries_TheHistory.HistoryEntrys in this navigation history.private java.lang.ThreadLocal<java.lang.Boolean>ignoreNewPages_Whether or not to ignore calls toaddPage(Page); this is a bit hackish (we should probably be using explicit boolean parameters in the various methods that load new pages), but it does the job for now -- without any new API cruft.private intindex_The current index within the list of pages which make up this navigation history.private WebWindowwindow_The window to which this navigation history belongs.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected History.HistoryEntryaddPage(Page page)Adds a new page to the navigation history.Historyback()Goes back one step in the navigation history, if possible.Historyforward()Goes forward one step in the navigation history, if possible.java.lang.ObjectgetCurrentState()Returns current state object.intgetIndex()Returns the current (zero-based) index within the navigation history.intgetLength()Returns the length of the navigation history.java.net.URLgetUrl(int index)Returns the URL at the specified index in the navigation history, ornullif the index is not valid.Historygo(int relativeIndex)Goes forward or backwards in the navigation history, according to whether the specified relative index is positive or negative.private voidgoToUrlAtCurrentIndex()Loads the URL at the current index into the window to which this navigation history belongs.private voidinitTransientFields()Initializes the transient fields.voidpushState(java.lang.Object state, java.net.URL url)Allows to change history state and url if provided.private voidreadObject(java.io.ObjectInputStream in)Re-initializes transient fields when an object of this type is deserialized.voidremoveCurrent()Removes the current URL from the history.voidreplaceState(java.lang.Object state, java.net.URL url)Allows to change history state and url if provided.java.lang.StringtoString()
-
-
-
Field Detail
-
window_
private final WebWindow window_
The window to which this navigation history belongs.
-
ignoreNewPages_
private transient java.lang.ThreadLocal<java.lang.Boolean> ignoreNewPages_
Whether or not to ignore calls toaddPage(Page); this is a bit hackish (we should probably be using explicit boolean parameters in the various methods that load new pages), but it does the job for now -- without any new API cruft.
-
entries_
private final java.util.List<History.HistoryEntry> entries_
TheHistory.HistoryEntrys in this navigation history.
-
index_
private int index_
The current index within the list of pages which make up this navigation history.
-
-
Constructor Detail
-
History
public History(WebWindow window)
Creates a new navigation history for the specified window.- Parameters:
window- the window which owns the new navigation history
-
-
Method Detail
-
initTransientFields
private void initTransientFields()
Initializes the transient fields.
-
getLength
public int getLength()
Returns the length of the navigation history.- Returns:
- the length of the navigation history
-
getIndex
public int getIndex()
Returns the current (zero-based) index within the navigation history.- Returns:
- the current (zero-based) index within the navigation history
-
getUrl
public java.net.URL getUrl(int index)
Returns the URL at the specified index in the navigation history, ornullif the index is not valid.- Parameters:
index- the index of the URL to be returned- Returns:
- the URL at the specified index in the navigation history, or
nullif the index is not valid
-
back
public History back() throws java.io.IOException
Goes back one step in the navigation history, if possible.- Returns:
- this navigation history, after going back one step
- Throws:
java.io.IOException- in case of error
-
forward
public History forward() throws java.io.IOException
Goes forward one step in the navigation history, if possible.- Returns:
- this navigation history, after going forward one step
- Throws:
java.io.IOException- in case of error
-
go
public History go(int relativeIndex) throws java.io.IOException
Goes forward or backwards in the navigation history, according to whether the specified relative index is positive or negative. If the specified index is0, this method reloads the current page.- Parameters:
relativeIndex- the index to move to, relative to the current index- Returns:
- this navigation history, after going forwards or backwards the specified number of steps
- Throws:
java.io.IOException- in case of error
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
removeCurrent
public void removeCurrent()
Removes the current URL from the history.
-
addPage
protected History.HistoryEntry addPage(Page page)
Adds a new page to the navigation history.- Parameters:
page- the page to add to the navigation history- Returns:
- the created history entry
-
goToUrlAtCurrentIndex
private void goToUrlAtCurrentIndex() throws java.io.IOExceptionLoads the URL at the current index into the window to which this navigation history belongs.- Throws:
java.io.IOException- if an IO error occurs
-
replaceState
public void replaceState(java.lang.Object state, java.net.URL url)Allows to change history state and url if provided.- Parameters:
state- the new state to useurl- the new url to use
-
pushState
public void pushState(java.lang.Object state, java.net.URL url)Allows to change history state and url if provided.- Parameters:
state- the new state to useurl- the new url to use
-
getCurrentState
public java.lang.Object getCurrentState()
Returns current state object.- Returns:
- the current state object
-
readObject
private void readObject(java.io.ObjectInputStream in) throws java.io.IOException, java.lang.ClassNotFoundExceptionRe-initializes transient fields when an object of this type is deserialized.- Parameters:
in- the object input stream- Throws:
java.io.IOException- if an error occursjava.lang.ClassNotFoundException- if an error occurs
-
-