Class CmsRfsFileViewer

  • All Implemented Interfaces:
    java.lang.Cloneable

    public class CmsRfsFileViewer
    extends java.lang.Object
    implements java.lang.Cloneable
    The representation of a RFS file along with the settings to provide access to certain portions (amount of lines) of it.

    Most often the underlying file will be the OpenCms logfile.

    The portion of the file that is shown is defined by a "window" of "windowSize" lines of text at a position "windowPosition" which is an enumeration of windows in ascending order.

    Since:
    6.0.0
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected static org.apache.commons.logging.Log LOG
      The log object for this class.
      protected java.lang.String m_filePath
      The path to the underlying file.
      protected java.lang.String m_rootPath
      The path to the root for all accessible files.
      protected int m_windowPos
      The current window (numbered from zero to amount of possible different windows).
      protected int m_windowSize
      The amount of lines to show.
    • Constructor Summary

      Constructors 
      Constructor Description
      CmsRfsFileViewer()
      Creates an instance with default settings that tries to use the log file path obtained from OpenCms's CmsSystemInfo instance.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.lang.Object clone()
      Returns a clone of this file view settings that is not "frozen" and therefore allows modifications.
      java.lang.String getFileEncoding()
      Returns the canonical name of the character encoding of the underlying file.
      java.lang.String getFilePath()
      Returns the path denoting the file that is accessed.
      boolean getIsLogfile()
      Returns true if the view's internal file path points to a log file in standard OpenCms format.
      java.lang.String getRootPath()
      Returns the path denoting the root folder for all accessible files.
      int getWindowPos()
      Returns the start position of the current display.
      int getWindowSize()
      Get the amount of lines (or entries depending on whether a standard log file is shown) to display per page.
      boolean isEnabled()
      Returns true if this view upon the underlying file via readFilePortion() is enabled.
      java.lang.String readFilePortion()
      Return the view portion of lines of text from the underlying file or an empty String if isEnabled() returns false.
      void setAdditionalRoots​(java.util.List<java.lang.String> roots)
      Sets the additional root folders from which files can be viewed.
      void setEnabled​(boolean preview)
      Set the boolean that decides if the view to the underlying file via readFilePortion() is enabled.
      void setFileEncoding​(java.lang.String fileEncoding)
      Set the character encoding of the underlying file.
      void setFilePath​(java.lang.String path)
      Set the path in the real file system that points to the file that should be displayed.
      void setFrozen​(boolean frozen)
      Package friendly access that allows the CmsWorkplaceManager to "freeze" this instance within the system-wide assignment in it's CmsWorkplaceManager.setFileViewSettings(org.opencms.file.CmsObject, CmsRfsFileViewer) method.
      void setIsLogfile​(boolean isLogfile)
      Set if the internal file is in standard log file format (true) or not (false).
      void setRootPath​(java.lang.String path)
      Set the path in the real file system that points to the folder/tree containing the log files.
      void setWindowPos​(int windowPos)
      Sets the start position of the current display.
      void setWindowSize​(int windowSize)
      Set the amount of lines (or entries depending on whether a standard log file is shown) to display per page.
      • Methods inherited from class java.lang.Object

        equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • LOG

        protected static final org.apache.commons.logging.Log LOG
        The log object for this class.
      • m_filePath

        protected java.lang.String m_filePath
        The path to the underlying file.
      • m_rootPath

        protected java.lang.String m_rootPath
        The path to the root for all accessible files.
      • m_windowPos

        protected int m_windowPos
        The current window (numbered from zero to amount of possible different windows).
      • m_windowSize

        protected int m_windowSize
        The amount of lines to show.
    • Constructor Detail

      • CmsRfsFileViewer

        public CmsRfsFileViewer()
        Creates an instance with default settings that tries to use the log file path obtained from OpenCms's CmsSystemInfo instance.

        If the log file path is invalid or not configured correctly a logging is performed and the path remains empty to allow user-specified file selection.

    • Method Detail

      • clone

        public java.lang.Object clone()
        Returns a clone of this file view settings that is not "frozen" and therefore allows modifications.

        Every instance that plans to modify settings has to obtain a clone first that may be modified. The original instance returned from (CmsWorkplaceManager.getFileViewSettings()) will throw a CmsRuntimeException for each setter invocation.

        Overrides:
        clone in class java.lang.Object
        Returns:
        a clone of this file view settings that is not "frozen" and therefore allows modifications
      • getFileEncoding

        public java.lang.String getFileEncoding()
        Returns the canonical name of the character encoding of the underlying file.

        If no special choice is fed into setFileEncoding(String) before this call always the system default character encoding is returned.

        This value may be ignored outside and will be ignored inside if the underlying does not contain textual content.

        Returns:
        the canonical name of the character encoding of the underlying file
      • getFilePath

        public java.lang.String getFilePath()
        Returns the path denoting the file that is accessed.

        Returns:
        the path denoting the file that is accessed
      • getIsLogfile

        public boolean getIsLogfile()
        Returns true if the view's internal file path points to a log file in standard OpenCms format.

        Returns:
        true if the view's internal file path points to a log file in standard OpenCms format
      • getRootPath

        public java.lang.String getRootPath()
        Returns the path denoting the root folder for all accessible files.

        Returns:
        the path denoting the root folder for all accessible files
      • getWindowPos

        public int getWindowPos()
        Returns the start position of the current display.

        This is a count of "windows" that consist of viewable text with "windowSize" lines of text (for a non-standard log file) or log-entries (for a standard log file).

        Returns:
        the start position of the current display
      • getWindowSize

        public int getWindowSize()
        Get the amount of lines (or entries depending on whether a standard log file is shown) to display per page.

        Returns:
        the amount of lines to display per page
      • readFilePortion

        public java.lang.String readFilePortion()
                                         throws CmsRfsException
        Return the view portion of lines of text from the underlying file or an empty String if isEnabled() returns false.

        Returns:
        the view portion of lines of text from the underlying file or an empty String if isEnabled() returns false
        Throws:
        CmsRfsException - if something goes wrong
      • setAdditionalRoots

        public void setAdditionalRoots​(java.util.List<java.lang.String> roots)
        Sets the additional root folders from which files can be viewed.

        Parameters:
        roots - the list of additional root folders
      • setEnabled

        public void setEnabled​(boolean preview)
        Set the boolean that decides if the view to the underlying file via readFilePortion() is enabled.

        Parameters:
        preview - the boolean that decides if the view to the underlying file via readFilePortion() is enabled
      • setFileEncoding

        public void setFileEncoding​(java.lang.String fileEncoding)
        Set the character encoding of the underlying file.

        The given String has to match a valid char set name (canonical or alias) of one of the system's supported Charset instances (see Charset.forName(java.lang.String)).

        This setting will be used for reading the file. This enables to correctly display files with text in various encodings in UIs.

        Parameters:
        fileEncoding - the character encoding of the underlying file to set
      • setFilePath

        public void setFilePath​(java.lang.String path)
                         throws CmsRfsException,
                                CmsRuntimeException
        Set the path in the real file system that points to the file that should be displayed.

        This method will only success if the file specified by the path argument is valid within the file system, no folder and may be read by the OpenCms process on the current platform.

        Parameters:
        path - the path in the real file system that points to the file that should be displayed to set
        Throws:
        CmsRuntimeException - if the configuration of this instance has been frozen
        CmsRfsException - if the given path is invalid, does not point to a file or cannot be accessed
      • setIsLogfile

        public void setIsLogfile​(boolean isLogfile)
                          throws CmsRuntimeException
        Set if the internal file is in standard log file format (true) or not (false).

        If set to true the file might be treated / displayed in a more convenient format than standard files in future. Currently it is only inverted (last lines appear first) and only the last 'Window Size' lines of the file are displayed.

        Do not activate this (it is possible from the log file viewer settings in the workplace administration) if your selected file is no log file: The display will confuse you and be more expensive (imaging scrolling a 20 MB file to view the last 200 lines).

        Parameters:
        isLogfile - determines if the internal file is in standard log file format (true) or not (false)
        Throws:
        CmsRuntimeException - if the configuration of this instance has been frozen (setFrozen(boolean))
      • setRootPath

        public void setRootPath​(java.lang.String path)
                         throws CmsRfsException,
                                CmsRuntimeException
        Set the path in the real file system that points to the folder/tree containing the log files.

        This method will only success if the folder specified by the path argument is valid within the file system.

        Parameters:
        path - the path in the real file system that points to the folder containing the log files
        Throws:
        CmsRuntimeException - if the configuration of this instance has been frozen
        CmsRfsException - if the given path is invalid
      • setWindowPos

        public void setWindowPos​(int windowPos)
                          throws CmsRuntimeException
        Sets the start position of the current display.

        This is a count of "windows" that consist of viewable text with "windowSize" lines of text (for a non-standard log file) or log-entries (for a standard log file).

        Parameters:
        windowPos - the start position of the current display to set
        Throws:
        CmsRuntimeException - if the configuration of this instance has been frozen (setFrozen(boolean))
      • setWindowSize

        public void setWindowSize​(int windowSize)
                           throws CmsRuntimeException
        Set the amount of lines (or entries depending on whether a standard log file is shown) to display per page.

        Parameters:
        windowSize - the amount of lines to display per page
        Throws:
        CmsRuntimeException - if the configuration of this instance has been frozen (setFrozen(boolean))