Home | History | Annotate | Download | only in data
      1 /*
      2  * Copyright (C) 2010 Google Inc.
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  * http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 package com.google.clearsilver.jsilver.data;
     18 
     19 import com.google.clearsilver.jsilver.resourceloader.ResourceLoader;
     20 
     21 import java.io.Reader;
     22 import java.io.IOException;
     23 
     24 /**
     25  * Parses data in HierachicalDataFormat (HDF), generating callbacks for data encountered in the
     26  * stream.
     27  */
     28 public interface Parser {
     29 
     30   /** Called whenever an error occurs. */
     31   public interface ErrorHandler {
     32     /**
     33      * Report an error to the ErrorHandler.
     34      *
     35      * @param line number of the line where error occurred. The value of -1 represents line number
     36      *        unknown
     37      * @param lineContent text of the line with error
     38      * @param fileName name of the file in which the error occurred
     39      * @param errorMessage description of an error
     40      */
     41     void error(int line, String lineContent, String fileName, String errorMessage);
     42   }
     43 
     44   /**
     45    * Reads in a stream of characters and parses data from it, putting it into the given Data object.
     46    *
     47    * @param reader Reader used to read in the formatted data.
     48    * @param output Data object that the read data structure will be dumped into.
     49    * @param errorHandler Error callback to be called on any error.
     50    * @param resourceLoader ResourceLoader to use to read in included files.
     51    * @param dataFileName Name of a file that is read with reader. It is needed for the purpose of
     52    *        handling include loops and error messages.
     53    * @param ignoreAttributes whether to store parsed HDF attributes in the Data object or not.
     54    * @throws IOException when errors occur reading input.
     55    */
     56   void parse(Reader reader, Data output, ErrorHandler errorHandler, ResourceLoader resourceLoader,
     57       String dataFileName, boolean ignoreAttributes) throws IOException;
     58 }
     59