use of org.tinystruct.ApplicationException in project bible-online by m0ver.
the class error method process.
public void process() throws ApplicationException {
this.request = (HttpServletRequest) this.context.getAttribute(HTTP_REQUEST);
this.response = (HttpServletResponse) this.context.getAttribute(HTTP_RESPONSE);
this.response.setStatus(HttpServletResponse.SC_FORBIDDEN);
this.reforward = new Reforward(this.request, this.response);
this.setVariable("from", this.reforward.getFromURL());
HttpSession session = this.request.getSession();
if (session.getAttribute("error") != null) {
ApplicationException exception = (ApplicationException) session.getAttribute("error");
String message = exception.getRootCause().getMessage();
if (message != null)
this.setVariable("exception.message", message);
else
this.setVariable("exception.message", "Unknown error");
this.setVariable("exception.details", this.getDetail(exception).toString());
this.response.setStatus(Integer.valueOf(exception.getStatus()));
} else {
this.reforward.forward();
}
}
use of org.tinystruct.ApplicationException in project bible-online by m0ver.
the class crawler method start.
public void start() throws MalformedURLException {
try {
bible bible = new bible();
bible.setTableName("zh_CN");
int partId;
String text;
URL url;
URLResourceLoader loader;
Row o;
StringBuilder content;
String words;
Pattern pat = Pattern.compile("<span class=\"verse\" id=\"(\\d+)\">.*</span>\\s*(.*)(\r\n)*");
Matcher mat;
Table list = null;
for (int i = 1; i <= 66; i++) {
o = bible.findOne("SELECT max(chapter_id) as n FROM zh_CN WHERE book_id=?", new Object[] { i });
int n = o.get(0).get("n").intValue();
url = new URL("https://www.wordplanet.org/kj/b" + (i < 10 ? "0" + i : i) + ".htm");
loader = new URLResourceLoader(url, true);
content = loader.getContent();
int j = 1;
KJV KJV = new KJV();
KJV.setBookId(i);
String defaults = "<h3>Chapter 1</h3>";
words = content.substring(content.indexOf(defaults) + defaults.length(), content.lastIndexOf("<div class=\"alignRight ym-noprint\">"));
words = words.replaceAll("<br/>", "\r\n");
mat = pat.matcher(words);
while (mat.find()) {
partId = Integer.parseInt(mat.group(1));
if (partId == 1) {
KJV.setChapterId(j);
// Check the chapter id if it's existing in the db.
list = KJV.find("SELECT * FROM KJV WHERE book_id = ? and chapter_id = ? order by part_id desc", new Object[] { KJV.getBookId(), KJV.getChapterId() });
j++;
}
if (null != list && !list.isEmpty() && list.firstElement().getFieldInfo("part_id").intValue() >= partId) {
continue;
}
KJV kjv = new KJV();
kjv.setBookId(i);
kjv.setChapterId(KJV.getChapterId());
text = mat.group().replaceAll("<span class=\"verse\" id=\"" + partId + "\">" + partId + "</span>\\s*", "");
kjv.setContent(text);
kjv.setPartId(partId++);
kjv.append();
System.out.println(text);
}
}
} catch (ApplicationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
use of org.tinystruct.ApplicationException in project bible-online by m0ver.
the class lection method init.
@Override
public void init() {
this.setAction("bible", "read");
this.setAction("bible/api", "api");
this.setAction("bible/feed", "feed");
this.book = new book();
this.data = Cache.getInstance();
if (this.data.keySet().isEmpty()) {
try {
Table list = book.findAll();
Iterator<Row> item = list.iterator();
String bookName;
while (item.hasNext()) {
book.setData(item.next());
bookName = book.getBookName().trim();
this.setAction(bookName, "viewByName");
this.data.set(bookName, book.getBookId());
}
} catch (ApplicationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
this.setText("application.keywords");
this.setText("application.description");
this.setText("application.title");
this.setText("application.language.name");
this.setText("page.welcome.caption");
this.setText("page.language-setting.title");
this.setText("page.logout.caption");
this.setText("page.reading.title");
this.setText("navigator.bible.caption");
this.setText("navigator.video.caption");
this.setText("navigator.document.caption");
this.setText("navigator.reader.caption");
this.setText("navigator.controller.caption");
this.setText("navigator.help.caption");
this.setText("holy.book.forward");
this.setText("holy.book.previous");
this.setText("holy.book.next");
this.setText("holy.bible");
this.setText("holy.bible.old-testament");
this.setText("holy.bible.new-testament");
this.setText("holy.bible.directory");
this.setText("holy.book.find-and-reading");
this.setText("holy.book.tools");
this.setText("holy.bible.version");
this.setText("footer.report-a-site-bug");
this.setText("footer.privacy");
this.setText("footer.register");
this.setText("footer.api");
this.setText("footer.updates-rss");
this.setText("holy.book.select");
this.setText("search.confirm.caption");
this.setText("search.submit.caption");
this.setText("invite.confirm.caption");
this.setText("invite.submit.caption");
this.setText("invite.email.default.tips");
this.setText("subscribe.plan");
this.setText("subscribe.bible.plan");
this.setText("subscribe.article.plan");
this.setText("subscribe.submit.caption");
this.setText("subscribe.email.caption");
this.setText("subscribe.email.default.tips");
this.setText("user.lastlogin.caption");
this.setText("holy.bible.download");
this.setText("holy.bible.chinese.download");
this.setVariable("TEMPLATES_DIR", "/themes", false);
this.setVariable("keyword", this.getVariable("keyword") == null ? "" : this.getVariable("keyword").getValue().toString());
this.setVariable("metas", "");
String username = "";
if (this.getVariable("username") != null) {
username = String.valueOf(this.getVariable("username").getValue());
}
this.setText("page.welcome.hello", (username == null || username.trim().length() == 0) ? "" : username + ",");
}
use of org.tinystruct.ApplicationException in project bible-online by m0ver.
the class login method http_client.
public String http_client(String url) throws ApplicationException {
HttpClient httpClient = new DefaultHttpClient();
HttpGet httpget = new HttpGet(url);
httpClient.getParams().setParameter(HttpProtocolParams.HTTP_CONTENT_CHARSET, "UTF-8");
HttpResponse http_response;
try {
http_response = httpClient.execute(httpget);
HeaderIterator iterator = http_response.headerIterator();
while (iterator.hasNext()) {
Header next = iterator.nextHeader();
System.out.println(next.getName() + ":" + next.getValue());
}
InputStream instream = http_response.getEntity().getContent();
ByteArrayOutputStream out = new ByteArrayOutputStream();
byte[] bytes = new byte[1024];
int len;
while ((len = instream.read(bytes)) != -1) {
out.write(bytes, 0, len);
}
instream.close();
out.close();
return new String(out.toByteArray(), "utf-8");
} catch (ClientProtocolException e) {
throw new ApplicationException(e.getMessage(), e);
} catch (IOException e) {
throw new ApplicationException(e.getMessage(), e);
}
}
use of org.tinystruct.ApplicationException in project bible-online by m0ver.
the class login method logout.
public void logout() {
HttpServletRequest request = (HttpServletRequest) this.context.getAttribute(HTTP_REQUEST);
HttpServletResponse response = (HttpServletResponse) this.context.getAttribute(HTTP_RESPONSE);
try {
this.passport = new passport(request, response, "waslogined");
this.passport.logout();
if (request.getCookies() != null) {
Cookie[] cookies = request.getCookies();
int i = 0;
Cookie cookie;
while (cookies.length > i) {
cookie = cookies[i];
cookie.setMaxAge(0);
cookie.setValue("");
response.addCookie(cookie);
i++;
}
}
Reforward reforward = new Reforward(request, response);
reforward.setDefault(this.getLink(this.getConfiguration("default.login.page")));
reforward.forward();
} catch (ApplicationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
Aggregations