Home | History | Annotate | Download | only in html
      1 /*
      2  * Copyright (C) 2009 The Android Open Source Project
      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 signature.io.html;
     18 
     19 import java.io.InputStream;
     20 import java.io.InputStreamReader;
     21 
     22 import org.antlr.stringtemplate.StringTemplate;
     23 import org.antlr.stringtemplate.StringTemplateGroup;
     24 import org.antlr.stringtemplate.language.DefaultTemplateLexer;
     25 
     26 public class TemplateStore {
     27 
     28     private static StringTemplateGroup group = initialize();
     29 
     30 
     31     private static StringTemplateGroup initialize() {
     32         InputStream modelStream = TemplateStore.class.getClassLoader()
     33                 .getResourceAsStream("model/model.stg");
     34         InputStreamReader modelReader = new InputStreamReader(modelStream);
     35         StringTemplateGroup modelGroup = new StringTemplateGroup(modelReader,
     36                 DefaultTemplateLexer.class);
     37 
     38         InputStream stream = TemplateStore.class.getClassLoader()
     39                 .getResourceAsStream("delta/deltas.stg");
     40         InputStreamReader reader = new InputStreamReader(stream);
     41         StringTemplateGroup deltaGroup = new StringTemplateGroup(reader,
     42                 DefaultTemplateLexer.class);
     43 
     44         StringTemplateGroup group = new StringTemplateGroup("signature", null,
     45                 DefaultTemplateLexer.class);
     46         group.setSuperGroup(deltaGroup);
     47 
     48         deltaGroup.setSuperGroup(modelGroup);
     49         return group;
     50     }
     51 
     52     private TemplateStore() {/* no instances allowed */
     53     }
     54 
     55     public static StringTemplate getStringTemplate(String name) {
     56         return group.getInstanceOf(name);
     57     }
     58 }
     59