1
0
mirror of https://github.com/gnosygnu/xowa.git synced 2026-03-02 03:49:30 +00:00

uca category support and other changes

This commit is contained in:
gnosygnu
2016-10-12 08:57:22 -04:00
parent e3b393650d
commit 3fc2e0741f
187 changed files with 3486 additions and 2984 deletions

View File

@@ -0,0 +1,79 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.xtns.xowa_cmds.wiki_setups; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.xowa_cmds.*;
import gplx.langs.mustaches.*;
import gplx.xowa.addons.bldrs.centrals.dbs.*; import gplx.xowa.addons.bldrs.centrals.dbs.datas.*; import gplx.xowa.addons.bldrs.centrals.dbs.datas.imports.*; import gplx.xowa.addons.bldrs.centrals.hosts.*;
import gplx.xowa.addons.bldrs.exports.packs.files.*;
import gplx.xowa.parsers.*;
class Xop_wiki_setup_mgr {
private final Mustache_tkn_parser parser = new Mustache_tkn_parser();
private Xobc_data_db data_db;
public Xop_root_tkn Write(Xoae_app app, Xowe_wiki wiki, Xop_ctx ctx, Xoae_page wpg, byte[] language, byte[][] wiki_domains) {
Io_url mustache_url = app.Fsys_mgr().Bin_addon_dir().GenSubFil_nest("bldr", "wiki_setup", "wiki_setup_main.mustache.html");
Mustache_tkn_itm root = parser.Parse(Io_mgr.Instance.LoadFilBry(mustache_url));
Mustache_render_ctx mctx = new Mustache_render_ctx();
Bry_bfr tmp_bfr = Bry_bfr_.New();
Mustache_bfr mbfr = new Mustache_bfr(tmp_bfr);
this.data_db = Xobc_data_db.New(app.Fsys_mgr());
root.Render(mbfr, mctx.Init(Make_root(language, wiki_domains)));
return wiki.Parser_mgr().Main().Parse_text_to_wdom(Xop_ctx.New__sub(wiki, ctx, wpg), mbfr.To_bry_and_clear(), true);
}
private Xows_root_itm Make_root(byte[] language, byte[][] wiki_domains) {
Bry_bfr url_list_bfr = Bry_bfr_.New();
int len = wiki_domains.length;
Xows_wiki_itm[] wiki_ary = new Xows_wiki_itm[len];
for (int i = 0; i < len; ++i) {
byte[] wiki_domain = wiki_domains[i];
wiki_ary[i] = new Xows_wiki_itm(wiki_domain, Make_task_ary(url_list_bfr, wiki_domain));
}
return new Xows_root_itm(language, url_list_bfr.To_bry_and_clear(), wiki_ary);
}
private Xows_task_itm[] Make_task_ary(Bry_bfr url_list_bfr, byte[] wiki_domain) {
Xobc_task_regy_itm[] task_rows = data_db.Tbl__task_regy().Select_by_wiki(wiki_domain);
int len = task_rows.length;
Xows_task_itm[] rv = new Xows_task_itm[len];
for (int i = 0; i < len; ++i) {
Xobc_task_regy_itm task_row = task_rows[i];
String[] task_key_parts = Pack_file_mgr.Task_key__parse(String_.new_u8(task_row.Key()));
String task_key_type = task_key_parts[2];
if (String_.Eq(task_key_type, "html")) task_key_type = "Articles";
else if (String_.Eq(task_key_type, "file")) task_key_type = "Images";
Xows_file_itm[] files = Make_file_ary(url_list_bfr, wiki_domain, task_row.Id());
rv[i] = new Xows_task_itm(task_row.Seqn(), wiki_domain, task_row.Name(), Bry_.new_u8(task_key_type), Bry_.Replace(Bry_.new_u8(task_key_parts[1]), Byte_ascii.Dot, Byte_ascii.Dash), files);
}
Array_.Sort(rv, new Xows_task_itm_sorter());
return rv;
}
private Xows_file_itm[] Make_file_ary(Bry_bfr url_list_bfr, byte[] wiki_domain, int task_id) {
Xobc_import_step_itm[] rows = data_db.Tbl__import_step().Select_by_task_id(task_id);
int len = rows.length;
Xows_file_itm[] rv = new Xows_file_itm[len];
Host_eval_itm host_eval = new Host_eval_itm();
for (int i = 0; i < len; ++i) {
Xobc_import_step_itm row = rows[i];
String src_fil = host_eval.Eval_src_fil(data_db, row.Host_id, gplx.xowa.wikis.domains.Xow_domain_itm_.parse(wiki_domain), row.Import_name);
url_list_bfr.Add_str_u8(src_fil).Add_byte_nl();
rv[i] = new Xows_file_itm(row.Step_id, Bry_.new_u8(src_fil));
}
Array_.Sort(rv, new Xows_file_itm_sorter());
return rv;
}
}

View File

@@ -0,0 +1,52 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.xtns.xowa_cmds.wiki_setups; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.xowa_cmds.*;
import gplx.langs.htmls.*; import gplx.xowa.htmls.core.htmls.*;
import gplx.xowa.parsers.*; import gplx.xowa.parsers.xndes.*; import gplx.xowa.parsers.htmls.*;
import gplx.xowa.wikis.pages.*; import gplx.xowa.wikis.pages.tags.*; import gplx.xowa.wikis.pages.htmls.*;
public class Xop_wiki_setup_xnde implements Xox_xnde, Mwh_atr_itm_owner2 {
private byte[] language;
private byte[][] wikis_ary;
private Xop_root_tkn root;
public void Xatr__set(Xowe_wiki wiki, byte[] src, Mwh_atr_itm xatr, byte xatr_id) {
switch (xatr_id) {
case Xatr__language: language = xatr.Val_as_bry(); break;
case Xatr__wikis: wikis_ary = Bry_split_.Split(xatr.Val_as_bry(), Byte_ascii.Pipe_bry); break;
default: Gfo_usr_dlg_.Instance.Warn_many("", "", "unhandled xnde atr; key=~{0}", xatr.Key_bry()); break;
}
}
public void Xtn_parse(Xowe_wiki wiki, Xop_ctx ctx, Xop_root_tkn root, byte[] src, Xop_xnde_tkn xnde) {
if (!wiki.Sys_cfg().Xowa_cmd_enabled()) { // not allowed; warn and exit
wiki.Appe().Usr_dlg().Warn_many("", "", "xowa_wiki_setup only allowed in xowa_home");
return;
}
Xox_xnde_.Parse_xatrs(wiki, this, xatr_hash, src, xnde);
this.root = new Xop_wiki_setup_mgr().Write(wiki.Appe(), wiki, ctx, ctx.Page(), language, wikis_ary);
}
public void Xtn_write(Bry_bfr bfr, Xoae_app app, Xop_ctx ctx, Xoh_html_wtr html_wtr, Xoh_wtr_ctx hctx, Xoae_page wpg, Xop_xnde_tkn xnde, byte[] src) {
html_wtr.Write_tkn_to_html(bfr, ctx, hctx, root.Root_src(), xnde, Xoh_html_wtr.Sub_idx_null, root);
//
}
public Xop_root_tkn Xtn_root() {throw Err_.new_unimplemented_w_msg("xowa_wiki_setup.xtn_root should not be called");}
public byte[] Xtn_html() {throw Err_.new_unimplemented_w_msg("xowa_wiki_setup.xtn_html should not be called");}
private static final byte Xatr__language = 1, Xatr__wikis = 2;
private static final Hash_adp_bry xatr_hash = Hash_adp_bry.ci_a7().Add_str_byte("language", Xatr__language).Add_str_byte("wikis", Xatr__wikis);
}

View File

@@ -0,0 +1,108 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.xtns.xowa_cmds.wiki_setups; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.xowa_cmds.*;
import gplx.langs.mustaches.*;
class Xows_root_itm implements Mustache_doc_itm {
private final byte[] language, url_list;
private final Xows_wiki_itm[] wiki_ary;
public Xows_root_itm(byte[] language, byte[] url_list, Xows_wiki_itm[] wiki_ary) {
this.language = language;
this.url_list = url_list;
this.wiki_ary = wiki_ary;
}
public boolean Mustache__write(String key, Mustache_bfr bfr) {
if (String_.Eq(key, "language")) bfr.Add_bry(language);
else if (String_.Eq(key, "url_list")) bfr.Add_bry(url_list);
else if (String_.Eq(key, "wikis__1st")) bfr.Add_bry(wiki_ary[0].Wiki_domain());
else return false;
return false;
}
public Mustache_doc_itm[] Mustache__subs(String key) {
if (String_.Eq(key, "wikis")) return wiki_ary;
return Mustache_doc_itm_.Ary__empty;
}
}
class Xows_wiki_itm implements Mustache_doc_itm {
private final Xows_task_itm[] task_ary;
public Xows_wiki_itm(byte[] wiki_domain, Xows_task_itm[] task_ary) {
this.wiki_domain = wiki_domain;
this.task_ary = task_ary;
}
public byte[] Wiki_domain() {return wiki_domain;} private final byte[] wiki_domain;
public boolean Mustache__write(String key, Mustache_bfr bfr) {
if (String_.Eq(key, "wiki_domain")) bfr.Add_bry(wiki_domain);
else return false;
return true;
}
public Mustache_doc_itm[] Mustache__subs(String key) {
if (String_.Eq(key, "tasks")) return task_ary;
return Mustache_doc_itm_.Ary__empty;
}
}
class Xows_task_itm implements Mustache_doc_itm {
private final byte[] wiki_domain, task_full_name, task_name, task_date;
private final Xows_file_itm[] file_ary;
public Xows_task_itm(int seqn_id, byte[] wiki_domain, byte[] task_full_name, byte[] task_name, byte[] task_date, Xows_file_itm[] file_ary) {
this.seqn_id = seqn_id;
this.wiki_domain = wiki_domain; this.task_full_name = task_full_name; this.task_name = task_name; this.task_date = task_date;
this.file_ary = file_ary;
}
public int Seqn_id() {return seqn_id;} private final int seqn_id;
public boolean Mustache__write(String key, Mustache_bfr bfr) {
if (String_.Eq(key, "wiki_domain")) bfr.Add_bry(wiki_domain);
else if (String_.Eq(key, "task_name")) bfr.Add_bry(task_name);
else if (String_.Eq(key, "task_full_name")) bfr.Add_bry(task_full_name);
else if (String_.Eq(key, "task_date")) bfr.Add_bry(task_date);
else return false;
return true;
}
public Mustache_doc_itm[] Mustache__subs(String key) {
if (String_.Eq(key, "files")) return file_ary;
return Mustache_doc_itm_.Ary__empty;
}
}
class Xows_file_itm implements Mustache_doc_itm {
private final byte[] file_href;
public Xows_file_itm(int step_id, byte[] file_href) {
this.step_id = step_id;
this.file_href = file_href;
}
public int Step_id() {return step_id;} private final int step_id;
public boolean Mustache__write(String key, Mustache_bfr bfr) {
if (String_.Eq(key, "file_href")) bfr.Add_bry(file_href);
else return false;
return true;
}
public Mustache_doc_itm[] Mustache__subs(String key) {
return Mustache_doc_itm_.Ary__empty;
}
}
class Xows_task_itm_sorter implements gplx.core.lists.ComparerAble {
public int compare(Object lhsObj, Object rhsObj) {
Xows_task_itm lhs = (Xows_task_itm)lhsObj;
Xows_task_itm rhs = (Xows_task_itm)rhsObj;
return Int_.Compare(lhs.Seqn_id(), rhs.Seqn_id());
}
}
class Xows_file_itm_sorter implements gplx.core.lists.ComparerAble {
public int compare(Object lhsObj, Object rhsObj) {
Xows_file_itm lhs = (Xows_file_itm)lhsObj;
Xows_file_itm rhs = (Xows_file_itm)rhsObj;
return Int_.Compare(lhs.Step_id(), rhs.Step_id());
}
}