2
* Copyright (C) 2008 Fadi Al-katout (cutout) <cutout33@gmail.com>
4
* Monajat is free software; you can redistribute it and/or modify
5
* it under the terms of the GNU General Public Licence as published by the
6
* Free Software Foundation; either version 2 of the Licence,
7
* or(at your option) any later version.
9
* Monajat is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12
* See the GNU General Public Licence for more details.
14
* You should have received a copy of the GNU General Public Licence
16
* if not, write to the Free Software Foundation, Inc.,
17
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23
import java.util.ArrayList;
24
import java.util.Iterator;
25
import java.util.List;
27
import javax.xml.parsers.SAXParser;
28
import javax.xml.parsers.SAXParserFactory;
29
import javax.xml.transform.Source;
30
import javax.xml.transform.stream.StreamSource;
31
import javax.xml.validation.SchemaFactory;
33
import org.dom4j.Document;
34
import org.dom4j.Element;
35
import org.dom4j.io.SAXReader;
37
public class DoaReader {
39
public Doa getDoa(File pFile) {
41
SAXParserFactory factory = SAXParserFactory.newInstance();
44
SchemaFactory schemaFactory =
45
SchemaFactory.newInstance("http://www.w3.org/2001/XMLSchema");
48
factory.setSchema(schemaFactory.newSchema(
49
new Source[] {new StreamSource("config/doaTemplate.xsd")}));
52
SAXParser parser = factory.newSAXParser();
54
SAXReader reader = new SAXReader(parser.getXMLReader());
56
reader.setValidation(false);
57
Document document = reader.read(pFile.toURI().toURL());
58
List<String> aLinesList = treeWalk(document);
59
return new Doa( (String)((Element) document.getRootElement().elementIterator("description").next()).getText(), aLinesList);
61
} catch (Exception e) {
66
private static List<String> treeWalk(Document document) {
67
List<String> aLinesList = new ArrayList<String>();
68
for ( Iterator i = document.getRootElement().elementIterator("line"); i.hasNext(); ) {
69
Element aLine = (Element) i.next();
70
aLinesList.add(aLine.getText());