Search in sources :

Example 1 with Table

use of org.tinystruct.data.component.Table in project bible-online by m0ver.

the class keywords method list.

public String list() throws ApplicationException {
    String keyword;
    this.request = (HttpServletRequest) this.context.getAttribute(HTTP_REQUEST);
    if (this.request.getParameter("keyword") != null && this.request.getParameter("keyword").equals("") == false && new StringUtilities(this.request.getParameter("keyword").toString()).safe()) {
        if (this.request.getMethod().equalsIgnoreCase("GET")) {
            keyword = this.request.getParameter("keyword").toString();
            try {
                keyword = new String(keyword.getBytes("ISO8859-1"), "UTF-8");
            } catch (UnsupportedEncodingException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        } else
            keyword = this.request.getParameter("keyword").toString();
    } else {
        keyword = null;
    }
    String javascript_block = "";
    String keywordlist = "", keywordvisit = "";
    keyword _keyword = new keyword();
    Table findTable = _keyword.findWith("WHERE keyword LIKE ? ORDER BY visit LIMIT 0,7", new Object[] { "%" + keyword + "%" });
    Row currentRow;
    String k = new String(""), v = new String(""), k_item = new String(""), v_item = new String("");
    Iterator<Row> iterator = findTable.iterator();
    while (iterator.hasNext()) {
        currentRow = iterator.next();
        k_item = currentRow.getFieldInfo("keyword").stringValue();
        if (k != null && k.trim().length() > 0) {
            k += ",\"" + k_item + "\"";
        } else {
            k = "\"" + k_item + "\"";
        }
        v_item = currentRow.getFieldInfo("visit").stringValue();
        if (v != null && v.trim().length() > 0) {
            v += ",\"" + v_item + "\"";
        } else {
            v = "\"" + v_item + "\"";
        }
    }
    keywordlist = "new Array(";
    keywordlist += k;
    keywordlist += ")";
    keywordvisit = "new Array(";
    keywordvisit += v;
    keywordvisit += ")";
    javascript_block = "window.listener.sendRPCDone(frameElement,\"" + keyword + "\"," + keywordlist + "," + keywordvisit + ",new Array(\"\"));";
    return javascript_block;
}
Also used : Table(org.tinystruct.data.component.Table) UnsupportedEncodingException(java.io.UnsupportedEncodingException) StringUtilities(org.tinystruct.system.util.StringUtilities) Row(org.tinystruct.data.component.Row) custom.objects.keyword(custom.objects.keyword)

Example 2 with Table

use of org.tinystruct.data.component.Table 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();
    }
}
Also used : Pattern(java.util.regex.Pattern) custom.objects.bible(custom.objects.bible) Table(org.tinystruct.data.component.Table) Matcher(java.util.regex.Matcher) URL(java.net.URL) ApplicationException(org.tinystruct.ApplicationException) URLResourceLoader(org.tinystruct.system.util.URLResourceLoader) KJV(custom.objects.KJV) Row(org.tinystruct.data.component.Row)

Example 3 with Table

use of org.tinystruct.data.component.Table in project bible-online by m0ver.

the class lection method bible.

public Object bible(int bookid, int chapterid, int partid) throws ApplicationException {
    StringBuffer xml = new StringBuffer();
    String finded = "";
    Table vtable = this.load(bookid, chapterid, partid);
    xml.append("<?xml version=\"1.0\" encoding=\"" + this.context.getAttribute("charset") + "\"?>");
    xml.append("<book id=\"book\" name=\"book\" bookid=\"" + this.bookid + "\" bookname=\"" + this.book.getBookName() + "\" chapterid=\"" + this.chapterid + "\" maxchapter=\"" + this.max_chapter + "\" lastchapter=\"" + this.lastchapterid + "\" nextchapter=\"" + this.nextchapterid + "\">\r\n");
    Field fields;
    for (Enumeration<Row> table = vtable.elements(); table.hasMoreElements(); ) {
        Row row = table.nextElement();
        Iterator<Field> iterator = row.iterator();
        while (iterator.hasNext()) {
            fields = iterator.next();
            finded = fields.get("content").value().toString();
            if (this.partid == Integer.parseInt(fields.get("part_id").value().toString())) {
                xml.append("<item uid=\"" + fields.get("id").value().toString() + "\" id=\"" + fields.get("part_id").value().toString() + "\" selected=\"true\">" + finded + "</item>");
            } else {
                xml.append("<item uid=\"" + fields.get("id").value().toString() + "\" id=\"" + fields.get("part_id").value().toString() + "\" selected=\"false\">" + finded + "</item>");
            }
        }
    }
    xml.append("</book>");
    return xml.toString();
}
Also used : Field(org.tinystruct.data.component.Field) Table(org.tinystruct.data.component.Table) Row(org.tinystruct.data.component.Row)

Example 4 with Table

use of org.tinystruct.data.component.Table 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 + ",");
}
Also used : Table(org.tinystruct.data.component.Table) ApplicationException(org.tinystruct.ApplicationException) custom.objects.book(custom.objects.book) Row(org.tinystruct.data.component.Row)

Example 5 with Table

use of org.tinystruct.data.component.Table in project bible-online by m0ver.

the class password method send.

public boolean send(String mailto) throws ApplicationException {
    User user = new User();
    Table table = user.findWith("WHERE email=?", new Object[] { mailto });
    if (table.size() > 0) {
        org.tinystruct.data.component.Row row = table.get(0);
        try {
            SimpleMail themail = new SimpleMail();
            themail.setFrom(this.getProperty("mail.default.from"));
            themail.setSubject("密码重置邮件");
            themail.setBody("亲爱的" + row.getFieldInfo("username").stringValue() + "用户,我们刚刚收到您的密码找回请求。为了保证您能及时使用我们提供的服务,请您于24小时内点击此链接重置您的密码。");
            themail.setTo(mailto);
            return themail.send();
        } catch (Exception ex) {
            throw new ApplicationException(ex.getMessage(), ex.getCause());
        }
    }
    return false;
}
Also used : User(custom.objects.User) Table(org.tinystruct.data.component.Table) SimpleMail(org.tinystruct.mail.SimpleMail) ApplicationException(org.tinystruct.ApplicationException) ApplicationException(org.tinystruct.ApplicationException)

Aggregations

Table (org.tinystruct.data.component.Table)21 Row (org.tinystruct.data.component.Row)17 ApplicationException (org.tinystruct.ApplicationException)14 custom.objects.bible (custom.objects.bible)8 custom.objects.book (custom.objects.book)7 HttpSession (javax.servlet.http.HttpSession)5 Field (org.tinystruct.data.component.Field)5 Element (org.tinystruct.dom.Element)5 SimpleDateFormat (java.text.SimpleDateFormat)4 custom.objects.keyword (custom.objects.keyword)3 custom.objects.vocabulary (custom.objects.vocabulary)3 URL (java.net.URL)3 Date (java.util.Date)3 Cookie (javax.servlet.http.Cookie)3 URLResourceLoader (org.tinystruct.system.util.URLResourceLoader)3 User (custom.objects.User)2 TaskDescriptor (custom.util.TaskDescriptor)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 Matcher (java.util.regex.Matcher)2 Pattern (java.util.regex.Pattern)2