01 /*
02  * Copyright 2007 Roberto Fasciolo
03  
04  * This file is part of vsitegen.
05  
06  * vsitegen is free software; you can redistribute it and/or modify
07  * it under the terms of the GNU General Public License as published by
08  * the Free Software Foundation; either version 2 of the License, or
09  * (at your option) any later version.
10  
11  * vsitegen is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  
16  * You should have received a copy of the GNU General Public License
17  * along with vsitegen; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
19  */
20 package net.robyf.vsitegen.model;
21 
22 import java.io.IOException;
23 import java.io.InputStream;
24 import java.util.ArrayList;
25 import java.util.Collections;
26 import java.util.List;
27 
28 import org.apache.commons.digester.Digester;
29 import org.apache.commons.digester.xmlrules.DigesterLoader;
30 import org.xml.sax.SAXException;
31 
32 public final class Navigation {
33 
34     private final List<Section> sections = new ArrayList<>();
35 
36     public static Navigation build(final InputStream inputFile) {
37         Navigation navigation = new Navigation();
38         Digester digester = 
39             DigesterLoader.createDigester(
40                 Navigation.class.getResource("/config/navigation-digesterRules.xml"));
41         digester.push(navigation);
42         try {
43             digester.parse(inputFile);
44         catch (IOException e) {
45             throw new ParserException("Error reading a navigation file", e);
46         catch (SAXException e) {
47             throw new ParserException("Error parsing a navigation file", e);
48         }
49         return navigation;
50     }
51 
52     public void addSection(final Section section) {
53         this.sections.add(section);
54     }
55 
56     public List<Section> getSections() {
57         return Collections.unmodifiableList(this.sections);
58     }
59 }