/*
* Created on 2005/02/01
* Author aki@www.xucker.jpn.org
* License Apache2.0 or Common Public License
*/
package org.jpn.xucker.taiyaku;
import java.util.List;
import java.util.Vector;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jpn.xucker.subplayer.SubPlayMain;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
/**
*
*
*/
public class TaiyakuParser {
private File baseDir;
public static Log log=
LogFactory.getLog(SubPlayMain.class);
public TaiyakuParser(File baseDir){
this.baseDir=baseDir;
if(!baseDir.exists() || baseDir.isFile()){
log.warn("invalid dir "+baseDir);
}
}
public TaiyakuData parse(String key,String lang){
if(!lang.equals(TaiyakuData.ENGLISH) && !lang.equals(TaiyakuData.JAPANESE)){
log.warn("invalid lang "+lang);
}
int last=key.indexOf(".");
if(last!=-1){
key=key.substring(0,last);
log.warn("invalid key and fix it");
}
String[] story=findStory(baseDir,key,lang);
if(story.length>0){
TaiyakuData data=new TaiyakuData();
return data;
}
log.info("story isn't exist:"+key);
return null;
}
public static String[] findStory(File base,String title,String lang){
List storyVector=new Vector();
try {
BufferedReader breader=new BufferedReader(new FileReader(new File(base,lang+".txt")));
String line;
boolean isSearch=false;
while((line=breader.readLine())!=null){
if(isSearch){
if(line.startsWith("##")){
break;
}
if(lang.equals(TaiyakuData.JAPANESE)){
//remove split
line=StringUtils.replace(line," ","");
}
storyVector.add(line);
}
else{
if(line.indexOf("##/"+title+".alml/##")!=-1){
isSearch=true;
}
}
}
breader.close();
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return (String[])storyVector.toArray(new String[storyVector.size()]);
}
}
|