Class SnippetReader


  • public class SnippetReader
    extends java.lang.Object
    Utility class for reading snippets.
    Version:
    $Id$
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private java.lang.String encoding
      The encoding of the source.
      private static java.lang.String EOL
      System-dependent EOL.
      private java.net.URL source
      The source.
    • Constructor Summary

      Constructors 
      Constructor Description
      SnippetReader​(java.net.URL src)
      Constructor.
      SnippetReader​(java.net.URL src, java.lang.String encoding)
      Constructor.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      (package private) int indent​(java.lang.String line)
      Returns the indent of the given line.
      protected static boolean isDemarcator​(java.lang.String snippetId, java.lang.String what, java.lang.String line)
      Determines if the given line is a demarcator.
      protected boolean isEnd​(java.lang.String snippetId, java.lang.String line)
      Determines if the given line is an end demarcator.
      protected boolean isStart​(java.lang.String snippetId, java.lang.String line)
      Determines if the given line is a start demarcator.
      (package private) int minIndent​(java.util.List<java.lang.String> lines)
      Returns the minimal indent of all the lines in the given List.
      private java.util.List<java.lang.String> readLines​(java.lang.String snippetId)
      Reads the snippet and returns the lines in a List.
      java.lang.StringBuffer readSnippet​(java.lang.String snippetId)
      Reads the snippet with given id.
      • Methods inherited from class java.lang.Object

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

      • EOL

        private static final java.lang.String EOL
        System-dependent EOL.
      • source

        private java.net.URL source
        The source.
      • encoding

        private java.lang.String encoding
        The encoding of the source.
    • Constructor Detail

      • SnippetReader

        public SnippetReader​(java.net.URL src,
                             java.lang.String encoding)
        Constructor.
        Parameters:
        src - The source
        encoding - The file encoding
      • SnippetReader

        public SnippetReader​(java.net.URL src)
        Constructor.
        Parameters:
        src - The source
    • Method Detail

      • readSnippet

        public java.lang.StringBuffer readSnippet​(java.lang.String snippetId)
                                           throws java.io.IOException
        Reads the snippet with given id.
        Parameters:
        snippetId - The id of the snippet.
        Returns:
        The snippet.
        Throws:
        java.io.IOException - if something goes wrong.
      • minIndent

        int minIndent​(java.util.List<java.lang.String> lines)
        Returns the minimal indent of all the lines in the given List.
        Parameters:
        lines - A List of lines.
        Returns:
        the minimal indent.
      • indent

        int indent​(java.lang.String line)
        Returns the indent of the given line.
        Parameters:
        line - A line.
        Returns:
        the indent.
      • readLines

        private java.util.List<java.lang.String> readLines​(java.lang.String snippetId)
                                                    throws java.io.IOException
        Reads the snippet and returns the lines in a List.
        Parameters:
        snippetId - The id of the snippet.
        Returns:
        A List of lines.
        Throws:
        java.io.IOException - if something goes wrong.
      • isStart

        protected boolean isStart​(java.lang.String snippetId,
                                  java.lang.String line)
        Determines if the given line is a start demarcator.
        Parameters:
        snippetId - the id of the snippet.
        line - the line.
        Returns:
        True, if the line is a start demarcator.
      • isDemarcator

        protected static boolean isDemarcator​(java.lang.String snippetId,
                                              java.lang.String what,
                                              java.lang.String line)
        Determines if the given line is a demarcator.
        Parameters:
        snippetId - the id of the snippet.
        what - Identifier for the demarcator.
        line - the line.
        Returns:
        True, if the line is a start demarcator.
      • isEnd

        protected boolean isEnd​(java.lang.String snippetId,
                                java.lang.String line)
        Determines if the given line is an end demarcator.
        Parameters:
        snippetId - the id of the snippet.
        line - the line.
        Returns:
        True, if the line is an end demarcator.