Package com.facilita.fc.jni
Class ExtractionCursor
- java.lang.Object
-
- com.facilita.fc.jni.ExtractionCursor
-
public class ExtractionCursor extends java.lang.Object
Stores details of an extraction from aResponse
. The current position in the page is stored, so anExtractionCursor
object can be re-used to find successive matches in aResponse
.e.g.
If it is necessary to extract the tokens from this response and store them in a<setup> <token>477BF7E1EA0</token> <token>68189CA718B</token> <token>44D4C768874</token> <token>AC59664BBEF</token> </setup>
List<>
, the following method could be written which makes use of theExtractionCursor
class.e.g.
public List<String> findTokens(Response response) throws Exception { // Create an ArrayList to store the tokens ArrayList<String> tokens = new ArrayList<String>(); // Use an ExtractionCursor to remember our current position within the Response ExtractionCursor cursor = new ExtractionCursor(); // Loop until we can't find any more tokens do { // Extract the next token String token = response.extract(cursor, "<token>", "</token>", ActionType.ACT_NONE); if (cursor.succeeded()) { writeMessage(String.format("Found token %s at position %d", token, cursor.getIndex())); tokens.add(token); } } while (cursor.succeeded()); return tokens; }
-
-
Constructor Summary
Constructors Constructor Description ExtractionCursor()
Creates anExtractionCursor
object.ExtractionCursor(long cPtr, boolean cMemoryOwn)
For internal use only.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
clearErrorMessage()
Clears the current error message.void
delete()
static long
getCPtr(ExtractionCursor obj)
For internal use only.java.lang.String
getErrorMessage()
Gets the error message that was set for an unsuccessful extract.int
getIndex()
Gets the offset into theResponse
at which the extracted text was found.void
reset()
Resets this object for re-use.void
setErrorMessage(java.lang.String errorMessage)
Sets the error message for an unsuccessful extract.void
setIndex(int index)
Sets the offset into theResponse
at which the extracted text was found.void
setSucceeded(boolean succeeded)
Sets whether the extract was successful.boolean
succeeded()
Returnstrue
if the extract was successful.
-
-
-
Constructor Detail
-
ExtractionCursor
public ExtractionCursor(long cPtr, boolean cMemoryOwn)
For internal use only. Of no interest to the user.- Parameters:
cPtr
- pointer to the CPP wrapped objectcMemoryOwn
- indicates if this object is responsible for memory management of the CPP object
-
ExtractionCursor
public ExtractionCursor()
Creates anExtractionCursor
object.
-
-
Method Detail
-
getCPtr
public static long getCPtr(ExtractionCursor obj)
For internal use only. Of no interest to the user.- Parameters:
obj
- a reference to an object of this class- Returns:
- a long containing the address of the CPP wrapped object
-
delete
public void delete()
-
getIndex
public int getIndex()
Gets the offset into theResponse
at which the extracted text was found.- Returns:
- the offset into the
Response
at which the extracted text was found
-
setIndex
public void setIndex(int index)
Sets the offset into theResponse
at which the extracted text was found.- Parameters:
index
- the offset into theResponse
at which the extracted text was found
-
succeeded
public boolean succeeded()
Returnstrue
if the extract was successful.- Returns:
true
if the extract was successful
-
setSucceeded
public void setSucceeded(boolean succeeded)
Sets whether the extract was successful.- Parameters:
succeeded
-true
if the extract was successful
-
getErrorMessage
public java.lang.String getErrorMessage()
Gets the error message that was set for an unsuccessful extract.- Returns:
- the error message that was set for an unsuccessful extract
-
reset
public void reset()
Resets this object for re-use.
-
setErrorMessage
public void setErrorMessage(java.lang.String errorMessage)
Sets the error message for an unsuccessful extract.- Parameters:
errorMessage
- the error message
-
clearErrorMessage
public void clearErrorMessage()
Clears the current error message.
-
-