Package com.gurock.smartinspect.contexts
Class TextContext
- java.lang.Object
-
- com.gurock.smartinspect.contexts.ViewerContext
-
- com.gurock.smartinspect.contexts.TextContext
-
- Direct Known Subclasses:
DataViewerContext,GraphicViewerContext,ListViewerContext,SourceViewerContext,WebViewerContext
public class TextContext extends ViewerContext
Is the base class for all viewer contexts, which deal with text data. A viewer context is the library-side representation of a viewer in the Console.This class is not guaranteed to be threadsafe.
-
-
Constructor Summary
Constructors Constructor Description TextContext(ViewerId vi)Creates and initializes a TextContent instance.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidappendLine(String line)Appends a line to the text data.voidappendText(String text)Appends text.voidclose()Overrides to release any resources of this text context.protected StringescapeLine(String line)Escapes a line.byte[]getViewerData()Overridden.voidloadFromFile(String fileName)Loads the text from a file.voidloadFromReader(Reader r)Loads the text from a reader.voidloadFromStream(InputStream is)Loads the text from a streamvoidloadFromText(String text)Loads the text.protected voidresetData()Resets the internal data.-
Methods inherited from class com.gurock.smartinspect.contexts.ViewerContext
getViewerId
-
-
-
-
Constructor Detail
-
TextContext
public TextContext(ViewerId vi)
Creates and initializes a TextContent instance.- Parameters:
vi- The viewer ID to use
-
-
Method Detail
-
getViewerData
public byte[] getViewerData()
Overridden. Returns the actual text data which will be displayed in the viewer specified by the getViewerId method- Specified by:
getViewerDatain classViewerContext- Returns:
- The actual text data which will be displayed in the viewer specified by the getViewerId method
-
resetData
protected void resetData()
Resets the internal data.This method is intended to reset the internal text data if custom handling of data is needed by derived classes.
-
loadFromFile
public void loadFromFile(String fileName) throws IOException
Loads the text from a file.- Parameters:
fileName- The name of the file to load the text from- Throws:
NullPointerException- If the fileName argument is nullIOException- If an I/O error occurred
-
loadFromStream
public void loadFromStream(InputStream is) throws IOException
Loads the text from a stream- Parameters:
is- The stream to load the text from- Throws:
NullPointerException- if the is argument is nullIOException- if an I/O error occurs
-
loadFromReader
public void loadFromReader(Reader r) throws IOException
Loads the text from a reader.- Parameters:
r- The reader to read the text from- Throws:
NullPointerException- If the r argument is nullIOException- If an I/O error occurred
-
loadFromText
public void loadFromText(String text)
Loads the text.- Parameters:
text- The text to load- Throws:
NullPointerException- If the text argument is null
-
appendText
public void appendText(String text)
Appends text.- Parameters:
text- The text to append- Throws:
NullPointerException- if the text argument is null
-
appendLine
public void appendLine(String line)
Appends a line to the text data. This method appends the supplied line and a carriage return + linefeed character to the internal text data after it has been escaped by the escapeLine method.- Parameters:
line- The line to append. It should not be null- Throws:
NullPointerException- if the line argument is null
-
escapeLine
protected String escapeLine(String line)
Escapes a line.If overriden in derived classes, this method escapes a line depending on the viewer format used. The default implementation does no escaping.
- Parameters:
line- The line to escape- Returns:
- The escaped line
-
close
public void close()
Overrides to release any resources of this text context.- Overrides:
closein classViewerContext
-
-