Class PagedRepresentation

java.lang.Object
org.restlet.representation.Variant
org.restlet.representation.RepresentationInfo
org.restlet.representation.Representation
org.restlet.representation.CharacterRepresentation
org.archive.crawler.restlet.PagedRepresentation

public class PagedRepresentation extends org.restlet.representation.CharacterRepresentation
Representation wrapping a FileRepresentation, displaying its contents in batches of lines at a time, with forward and backward navigation.
Author:
gojomo
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    wrapped EnhDirectoryResource; used to formulate self-links
    protected File
    File
    protected org.restlet.representation.FileRepresentation
    wrapped FileRepresentation
    protected int
    desired line count; negative to go back from position; default 128
    protected List<String>
    text lines
    protected long
    position in file around which to fetch lines
    protected org.apache.commons.lang.math.LongRange
    position range [start-of-first-line, past-end-of-last-line] in file
    protected boolean
    whether to display lines in reversed order (latest first)

    Fields inherited from class org.restlet.representation.Representation

    UNKNOWN_SIZE
  • Constructor Summary

    Constructors
    Constructor
    Description
    PagedRepresentation(org.restlet.representation.FileRepresentation representation, EnhDirectoryResource resource, String pos, String lines, String reverse)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    protected void
    emitBumper(PrintWriter pw, boolean atTop)
    Emit a "start" or "EOF" bumper as appropriate to prominently indicate if page borders start- or end- of-file.
    protected void
    Emit the navigational controls.
    protected String
    getControlUri(long pos, int lines, boolean reverse)
    Construct navigational URI for given parameters.
     
    Performs basic syntax highlighting of a crawl log line.
    protected void
    Actually read the requested lines, and reverses if appropriate.
    void
    write(Writer writer)
    Write the paged HTML.

    Methods inherited from class org.restlet.representation.CharacterRepresentation

    getChannel, getStream, write, write

    Methods inherited from class org.restlet.representation.Representation

    append, exhaust, getAvailableSize, getDigest, getDisposition, getExpirationDate, getRange, getRegistration, getSize, getText, hasKnownSize, isAvailable, isEmpty, isSelectable, isTransient, release, setAvailable, setDigest, setDisposition, setExpirationDate, setListener, setRange, setSize, setTransient

    Methods inherited from class org.restlet.representation.RepresentationInfo

    getModificationDate, getTag, setModificationDate, setTag

    Methods inherited from class org.restlet.representation.Variant

    createClientInfo, equals, getCharacterSet, getEncodings, getLanguages, getLocationRef, getMediaType, hashCode, includes, isCompatible, setCharacterSet, setEncodings, setLanguages, setLocationRef, setLocationRef, setMediaType, toString

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Field Details

    • fileRepresentation

      protected org.restlet.representation.FileRepresentation fileRepresentation
      wrapped FileRepresentation
    • dirResource

      protected EnhDirectoryResource dirResource
      wrapped EnhDirectoryResource; used to formulate self-links
    • position

      protected long position
      position in file around which to fetch lines
    • lineCount

      protected int lineCount
      desired line count; negative to go back from position; default 128
    • reversedOrder

      protected boolean reversedOrder
      whether to display lines in reversed order (latest first)
    • lines

      protected List<String> lines
      text lines
    • range

      protected org.apache.commons.lang.math.LongRange range
      position range [start-of-first-line, past-end-of-last-line] in file
    • file

      protected File file
      File
  • Constructor Details

  • Method Details

    • getReader

      public Reader getReader() throws IOException
      Specified by:
      getReader in class org.restlet.representation.Representation
      Throws:
      IOException
    • loadLines

      protected void loadLines() throws IOException
      Actually read the requested lines, and reverses if appropriate. If at file start, refuses to show fewer lines than are possible ('bounces' against start).
      Throws:
      IOException
    • write

      public void write(Writer writer) throws IOException
      Write the paged HTML.
      Specified by:
      write in class org.restlet.representation.Representation
      Throws:
      IOException
      See Also:
      • Representation.write(java.io.Writer)
    • highlightCrawlLogLine

      public String highlightCrawlLogLine(String line)
      Performs basic syntax highlighting of a crawl log line. Assumes the line is already HTML escaped.
    • emitBumper

      protected void emitBumper(PrintWriter pw, boolean atTop)
      Emit a "start" or "EOF" bumper as appropriate to prominently indicate if page borders start- or end- of-file.
      Parameters:
      pw - PrintWriter
      atTop - boolean, true if at top of page
    • emitControls

      protected void emitControls(PrintWriter pw)
      Emit the navigational controls. TODO: ugh! templatize, reduce duplication as possible
      Parameters:
      pw - PrintWriter
    • getControlUri

      protected String getControlUri(long pos, int lines, boolean reverse)
      Construct navigational URI for given parameters.
      Parameters:
      pos - desired position in file
      lines - desired signed line count
      reverse - if line ordering should be displayed in reverse
      Returns:
      String URI appropriate to navigate to desired view