Class ContextTools


  • public class ContextTools
    extends java.lang.Object
    Helper class to mark errors in text.
    • Constructor Summary

      Constructors 
      Constructor Description
      ContextTools()  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.lang.String getContext​(int fromPos, int toPos, java.lang.String contents)  
      private java.lang.StringBuilder getMarker​(int fromPos, int toPos, int textLength)  
      java.lang.String getPlainTextContext​(int fromPos, int toPos, java.lang.String contents)
      Get a plain text context that uses ^ characters in a new line as a marker of the given string region.
      void setContextSize​(int contextSize)
      The context size of the error.
      void setErrorMarkerEnd​(java.lang.String errorMarkerEnd)
      Set the string used to mark the end of an error, e.g.
      void setErrorMarkerStart​(java.lang.String errorMarkerStart)
      Set the string used to mark the beginning of an error, e.g.
      void setEscapeHtml​(boolean escapeHtml)
      Whether HTML special characters should be escaped.
      • Methods inherited from class java.lang.Object

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

      • contextSize

        private int contextSize
      • escapeHtml

        private boolean escapeHtml
      • errorMarkerStart

        private java.lang.String errorMarkerStart
      • errorMarkerEnd

        private java.lang.String errorMarkerEnd
    • Constructor Detail

      • ContextTools

        public ContextTools()
    • Method Detail

      • getContext

        public java.lang.String getContext​(int fromPos,
                                           int toPos,
                                           java.lang.String contents)
      • getPlainTextContext

        public java.lang.String getPlainTextContext​(int fromPos,
                                                    int toPos,
                                                    java.lang.String contents)
        Get a plain text context that uses ^ characters in a new line as a marker of the given string region. Ignores setEscapeHtml(boolean).
        Since:
        2.3
      • setErrorMarkerStart

        public void setErrorMarkerStart​(java.lang.String errorMarkerStart)
        Set the string used to mark the beginning of an error, e.g. <span class="error">
      • setErrorMarkerEnd

        public void setErrorMarkerEnd​(java.lang.String errorMarkerEnd)
        Set the string used to mark the end of an error, e.g. </span>
      • setContextSize

        public void setContextSize​(int contextSize)
        The context size of the error. This many characters of the original text will be used from the left and from the right context of the error.
      • setEscapeHtml

        public void setEscapeHtml​(boolean escapeHtml)
        Whether HTML special characters should be escaped.
      • getMarker

        private java.lang.StringBuilder getMarker​(int fromPos,
                                                  int toPos,
                                                  int textLength)