- added assets folder and Quran content

This commit is contained in:
Edin Dazdarevic
2014-01-17 08:44:17 +01:00
parent a3cac920c0
commit 084d3cfac3
117 changed files with 7561 additions and 6 deletions

View File

@@ -0,0 +1,5 @@
package com.mhalka.qurantranslationdisplay;
public class InvalidChapterException extends Exception {
}

View File

@@ -0,0 +1,61 @@
package com.mhalka.qurantranslationdisplay;
import java.io.IOException;
import java.io.InputStream;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.xpath.XPath;
import javax.xml.xpath.XPathExpressionException;
import javax.xml.xpath.XPathFactory;
import org.w3c.dom.Document;
import org.xml.sax.SAXException;
import android.content.res.AssetManager;
public class QuranReader {
private AssetManager assetManager;
private XPath xPath;
private DocumentBuilder builder = null;
private Document document;
private String folder;
public QuranReader(AssetManager assetManager) throws ParserConfigurationException{
this(assetManager,null);
}
public QuranReader(AssetManager assetManager, String folder) throws ParserConfigurationException {
this.assetManager = assetManager;
this.folder = folder;
DocumentBuilderFactory builderFactory =
DocumentBuilderFactory.newInstance();
xPath = XPathFactory.newInstance().newXPath();
builder = builderFactory.newDocumentBuilder();
}
public void setChapter(int num) throws IOException, InvalidChapterException, SAXException {
if (num < 1 || num > 114)
throw new InvalidChapterException();
String chapterNum = String.format("%03d", num);
String folderPrefix = "";
if(this.folder != null && !this.folder.trim().equals("")){
folderPrefix = this.folder + "/";
}
InputStream is = this.assetManager.open(String.format("%sChapter%s.xml",folderPrefix,chapterNum ));;
document = builder.parse(is);
}
public String getVerse(int num) throws XPathExpressionException {
String expression = "/Chapter/Verse[@VerseID='"+num+"']/text()";
String text = xPath.compile(expression).evaluate(this.document);
return text;
}
}

View File

@@ -25,11 +25,10 @@ public class ShowAyah extends Activity {
final TextView ayah = (TextView) findViewById(R.id.ayah);
ayah.setMovementMethod(new ScrollingMovementMethod());
// Example of use of QuranReader
// AssetManager assetManager = getAssets();
// QuranReader reader = new QuranReader(assetManager, "quran_content");
// reader.setChapter(2);
// String verseText = reader.getVerse(16);
}
}