~ubuntu-branches/ubuntu/lucid/monajat/lucid

« back to all changes in this revision

Viewing changes to src/monajat/doa/DoaReader.java

  • Committer: Bazaar Package Importer
  • Author(s): أحمد المحمودي (Ahmed El-Mahmoudy)
  • Date: 2009-12-21 10:36:41 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20091221103641-i7o1qicc69y4py8q
Tags: 2.3.1-0ubuntu1
* New upstream release. (LP: #506085)
* Code is re-written in python, hence packaging changed accordingly.
* Added manpages for monajat-applet & monajat-mod
* Added patch desktop.diff to:
  + Remove Encoding field.
  + Add X-Islamic-Software category.
  + Replace irrevelant categories with Utility.
* debian/copyright: Updated & converted to machine-readable format.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 *         Copyright (C) 2008 Fadi Al-katout (cutout) <cutout33@gmail.com>
3
 
 * 
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.
8
 
 * 
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.
13
 
 * 
14
 
 * You should have received a copy of  the GNU General Public Licence
15
 
 * along with Monajat; 
16
 
 * if not, write to  the Free Software Foundation, Inc.,
17
 
 * 51 Franklin Street, Fifth Floor,  Boston, MA  02110-1301, USA
18
 
 */
19
 
 
20
 
package monajat.doa;
21
 
 
22
 
import java.io.File;
23
 
import java.util.ArrayList;
24
 
import java.util.Iterator;
25
 
import java.util.List;
26
 
 
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;
32
 
 
33
 
import org.dom4j.Document;
34
 
import org.dom4j.Element;
35
 
import org.dom4j.io.SAXReader;
36
 
 
37
 
public class DoaReader {
38
 
        
39
 
        public Doa getDoa(File pFile) {
40
 
                try {
41
 
                        SAXParserFactory factory = SAXParserFactory.newInstance();
42
 
 
43
 
 
44
 
                        SchemaFactory schemaFactory = 
45
 
                            SchemaFactory.newInstance("http://www.w3.org/2001/XMLSchema");
46
 
 
47
 
 
48
 
                        factory.setSchema(schemaFactory.newSchema(
49
 
                            new Source[] {new StreamSource("config/doaTemplate.xsd")}));
50
 
 
51
 
 
52
 
                        SAXParser parser = factory.newSAXParser();
53
 
 
54
 
                        SAXReader reader = new SAXReader(parser.getXMLReader());
55
 
 
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);
60
 
                        
61
 
                } catch (Exception e) {
62
 
                        return null;
63
 
                }
64
 
        }
65
 
 
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());
71
 
        }
72
 
                return aLinesList;
73
 
    }
74
 
 
75
 
}