Package com.facilita.fc.jni
Class ExtractionCursor
- java.lang.Object
-
- com.facilita.fc.jni.ExtractionCursor
-
public class ExtractionCursor extends java.lang.ObjectStores details of an extraction from aResponse. The current position in the page is stored, so anExtractionCursorobject 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 theExtractionCursorclass.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 anExtractionCursorobject.ExtractionCursor(long cPtr, boolean cMemoryOwn)For internal use only.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclearErrorMessage()Clears the current error message.voiddelete()static longgetCPtr(ExtractionCursor obj)For internal use only.java.lang.StringgetErrorMessage()Gets the error message that was set for an unsuccessful extract.intgetIndex()Gets the offset into theResponseat which the extracted text was found.voidreset()Resets this object for re-use.voidsetErrorMessage(java.lang.String errorMessage)Sets the error message for an unsuccessful extract.voidsetIndex(int index)Sets the offset into theResponseat which the extracted text was found.voidsetSucceeded(boolean succeeded)Sets whether the extract was successful.booleansucceeded()Returnstrueif 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 anExtractionCursorobject.
-
-
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 theResponseat which the extracted text was found.- Returns:
- the offset into the
Responseat which the extracted text was found
-
setIndex
public void setIndex(int index)
Sets the offset into theResponseat which the extracted text was found.- Parameters:
index- the offset into theResponseat which the extracted text was found
-
succeeded
public boolean succeeded()
Returnstrueif the extract was successful.- Returns:
trueif the extract was successful
-
setSucceeded
public void setSucceeded(boolean succeeded)
Sets whether the extract was successful.- Parameters:
succeeded-trueif 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.
-
-