Search in sources :

Example 1 with Row

use of org.tinystruct.data.component.Row 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 Row

use of org.tinystruct.data.component.Row 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 Row

use of org.tinystruct.data.component.Row 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 Row

use of org.tinystruct.data.component.Row 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 Row

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

the class search method feed.

public String feed(String query) throws ApplicationException {
    StringBuffer xml = new StringBuffer();
    String finded = "";
    String[] keywords;
    boolean noResult = true;
    int page = 1, pageSize = 20, startIndex = (page - 1) * pageSize;
    if (this.request.getParameter("page") == null || this.request.getParameter("page").toString().trim().length() <= 0) {
        page = 1;
    } else {
        page = Integer.parseInt(this.request.getParameter("page").toString());
    }
    if (query.trim().length() > 0) {
        keywords = query.split(" ");
    } else {
        return "<result>Error</result>";
    }
    String condition = "";
    for (int i = 0; i < keywords.length; i++) {
        if (condition.trim().length() == 0) {
            condition = " content like '%" + keywords[i] + "%' ";
        } else {
            condition += " or content like '%" + keywords[i] + "%' ";
        }
    }
    String SQL = "SELECT a.*,b.book_name FROM bible as a left join book as b on a.book_id=b.book_id where " + condition + " order by a.book_id,a.chapter_id limit " + startIndex + "," + pageSize;
    // String look = "SELECT FOUND_ROWS() AS size";
    bible bible = new bible();
    Table vtable = bible.find(SQL, new Object[] {});
    noResult = vtable.size() > 0;
    /*
		 * Row found=bible.findOne(look, new Object[]{});
		 * 
		 * Pager pager = new Pager(); pager.pageSize = pageSize; pager.currentPage =
		 * page; pager.size=found.getFieldInfo("size").intValue();
		 * pager.setListSize(vtable.size());
		 */
    Field field;
    // 此位置即为当前页的第一条记录的ID
    int next = startIndex + 1;
    for (Enumeration<Row> table = vtable.elements(); table.hasMoreElements(); ) {
        Row row = table.nextElement();
        Iterator<Field> iterator = row.iterator();
        while (iterator.hasNext()) {
            field = iterator.next();
            finded = field.get("content").value().toString();
            for (int j = 0; j < keywords.length; j++) {
                finded = StringUtilities.sign(finded, keywords[j]);
            }
            xml.append("<item id=\"" + next + "\" chapterid=\"" + field.get("chapter_id").value().toString() + "\" bookid=\"" + field.get("book_id").value().toString() + "\" " + field.get("book_name").value().toString() + " partid=\"" + field.get("part_id").value().toString() + "\">" + finded + "</item>\r\n");
            next++;
        }
    }
    for (int k = 0; k < keywords.length && noResult; k++) {
        keyword keyword = new keyword();
        keyword.setKeyword(keywords[k]);
        Row findRow = keyword.findOne("SELECT id,visit FROM keyword WHERE keyword='" + keywords[k] + "'", new Object[] {});
        if (findRow.size() == 0) {
            keyword.setVisit(0);
            keyword.append();
        } else {
            keyword.setId(findRow.getFieldInfo("id"));
            keyword.setVisit(findRow.getFieldInfo("visit").intValue() + 1);
            keyword.update();
        }
    }
    return xml.toString();
}
Also used : Field(org.tinystruct.data.component.Field) custom.objects.bible(custom.objects.bible) Table(org.tinystruct.data.component.Table) Row(org.tinystruct.data.component.Row) custom.objects.keyword(custom.objects.keyword)

Aggregations

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