Package org.htmlunit
Class History
java.lang.Object
org.htmlunit.History
- All Implemented Interfaces:
Serializable
Representation of the navigation history of a single window.
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static final class
The single entry in the history. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final List
<History.HistoryEntry> TheHistory.HistoryEntry
s in this navigation history.private ThreadLocal
<Boolean> 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 int
The current index within the list of pages which make up this navigation history.private final WebWindow
The window to which this navigation history belongs. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected History.HistoryEntry
Adds a new page to the navigation history.back()
Goes back one step in the navigation history, if possible.forward()
Goes forward one step in the navigation history, if possible.Returns current state object.int
getIndex()
Returns the current (zero-based) index within the navigation history.int
Returns the length of the navigation history.getUrl
(int index) Returns the URL at the specified index in the navigation history, ornull
if the index is not valid.go
(int relativeIndex) Goes forward or backwards in the navigation history, according to whether the specified relative index is positive or negative.private void
Loads the URL at the current index into the window to which this navigation history belongs.private void
Initializes the transient fields.void
Allows to change history state and url if provided.private void
Re-initializes transient fields when an object of this type is deserialized.void
Removes the current URL from the history.void
replaceState
(Object state, URL url) Allows to change history state and url if provided.toString()
-
Field Details
-
window_
The window to which this navigation history belongs. -
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_
TheHistory.HistoryEntry
s in this navigation history. -
index_
private int index_The current index within the list of pages which make up this navigation history.
-
-
Constructor Details
-
History
Creates a new navigation history for the specified window.- Parameters:
window
- the window which owns the new navigation history
-
-
Method Details
-
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
Returns the URL at the specified index in the navigation history, ornull
if 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
null
if the index is not valid
-
back
Goes back one step in the navigation history, if possible.- Returns:
- this navigation history, after going back one step
- Throws:
IOException
- in case of error
-
forward
Goes forward one step in the navigation history, if possible.- Returns:
- this navigation history, after going forward one step
- Throws:
IOException
- in case of error
-
go
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:
IOException
- in case of error
-
toString
-
removeCurrent
public void removeCurrent()Removes the current URL from the history. -
addPage
Adds a new page to the navigation history.- Parameters:
page
- the page to add to the navigation history- Returns:
- the created history entry
-
goToUrlAtCurrentIndex
Loads the URL at the current index into the window to which this navigation history belongs.- Throws:
IOException
- if an IO error occurs
-
replaceState
Allows to change history state and url if provided.- Parameters:
state
- the new state to useurl
- the new url to use
-
pushState
Allows to change history state and url if provided.- Parameters:
state
- the new state to useurl
- the new url to use
-
getCurrentState
Returns current state object.- Returns:
- the current state object
-
readObject
Re-initializes transient fields when an object of this type is deserialized.- Parameters:
in
- the object input stream- Throws:
IOException
- if an error occursClassNotFoundException
- if an error occurs
-