Class ExtractionCursor


  • public class ExtractionCursor
    extends java.lang.Object
    Stores details of an extraction from a Response. The current position in the page is stored, so an ExtractionCursor object can be re-used to find successive matches in a Response.

    e.g.

    
     <setup>
         <token>477BF7E1EA0</token>
         <token>68189CA718B</token>
         <token>44D4C768874</token>
         <token>AC59664BBEF</token>
     </setup>
     
    If it is necessary to extract the tokens from this response and store them in a List<>, the following method could be written which makes use of the ExtractionCursor 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;
     }
     
    See Also:
    Response.extract(ExtractionCursor, String, String)
    • Constructor Summary

      Constructors 
      Constructor Description
      ExtractionCursor()
      Creates an ExtractionCursor 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 the Response 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 the Response at which the extracted text was found.
      void setSucceeded​(boolean succeeded)
      Sets whether the extract was successful.
      boolean succeeded()
      Returns true if the extract was successful.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • 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 object
        cMemoryOwn - indicates if this object is responsible for memory management of the CPP object
      • ExtractionCursor

        public ExtractionCursor()
        Creates an ExtractionCursor 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 the Response 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 the Response at which the extracted text was found.
        Parameters:
        index - the offset into the Response at which the extracted text was found
      • succeeded

        public boolean succeeded()
        Returns true 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.