mirror of
https://github.com/gnosygnu/xowa.git
synced 2026-03-02 03:49:30 +00:00
v2.9.2.1
This commit is contained in:
@@ -58,7 +58,7 @@ public class Xoa_app_ {
|
||||
}
|
||||
}
|
||||
public static final String Name = "xowa";
|
||||
public static final String Version = "2.9.1.1";
|
||||
public static final String Version = "2.9.2.1";
|
||||
public static String Build_date = "2012-12-30 00:00:00";
|
||||
public static String Op_sys_str;
|
||||
public static String User_agent = "";
|
||||
|
||||
@@ -15,16 +15,14 @@ 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.math.parsers; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.math.*;
|
||||
interface Mwm_tkn {
|
||||
int Tid();
|
||||
Mwm_tkn__root Root();
|
||||
int Uid();
|
||||
int Src_bgn();
|
||||
int Src_end();
|
||||
void Src_end_(int v);
|
||||
Mwm_tkn Init(Mwm_tkn__root root, int tid, int uid, int src_bgn, int src_end);
|
||||
int Subs__len();
|
||||
Mwm_tkn Subs__get_at(int i);
|
||||
void To_bry(Bry_bfr bfr, int indent);
|
||||
package gplx.xowa; import gplx.*;
|
||||
import gplx.xowa.pages.*;
|
||||
public interface Xoa_page {
|
||||
Xow_wiki Wiki();
|
||||
Xoa_url Url();
|
||||
byte[] Url_bry_safe();
|
||||
Xoa_ttl Ttl();
|
||||
void Xtn_gallery_packed_exists_y_();
|
||||
boolean Exists();
|
||||
Xoa_page__commons_mgr Commons_mgr();
|
||||
}
|
||||
25
400_xowa/src/gplx/xowa/Xoa_page_.java
Normal file
25
400_xowa/src/gplx/xowa/Xoa_page_.java
Normal file
@@ -0,0 +1,25 @@
|
||||
/*
|
||||
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; import gplx.*;
|
||||
public class Xoa_page_ {
|
||||
public static final byte Edit_mode_create = 1, Edit_mode_update = 2;
|
||||
public static final String Main_page_str = "Main_Page";
|
||||
public static final byte[] Main_page_bry = Bry_.new_a7(Main_page_str); // NOTE; may not work for non-english wikis
|
||||
public static final byte[] Main_page_bry_empty = Bry_.Empty;
|
||||
public static final int Page_len_max = 2048 * Io_mgr.Len_kb; // REF.MW: DefaultSettings.php; $wgMaxArticleSize = 2048;
|
||||
}
|
||||
418
400_xowa/src/gplx/xowa/Xoa_ttl.java
Normal file
418
400_xowa/src/gplx/xowa/Xoa_ttl.java
Normal file
@@ -0,0 +1,418 @@
|
||||
/*
|
||||
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; import gplx.*;
|
||||
import gplx.core.primitives.*; import gplx.core.btries.*; import gplx.xowa.wikis.xwikis.*; import gplx.xowa.langs.cases.*;
|
||||
import gplx.xowa.parsers.amps.*; import gplx.xowa.parsers.miscs.*; import gplx.xowa.wikis.ttls.*;
|
||||
public class Xoa_ttl { // PAGE:en.w:http://en.wikipedia.org/wiki/Help:Link; REF.MW: Ttl.php|secureAndSplit;
|
||||
public Xow_ns Ns() {return ns;} private Xow_ns ns;
|
||||
public boolean ForceLiteralLink() {return forceLiteralLink;} private boolean forceLiteralLink;
|
||||
// NOTE: in procs below, all -1 are used to skip previous delimiters; they will only occur for end_pos arguments
|
||||
public boolean Eq_page_db(Xoa_ttl comp) {if (comp == null) return false; return Bry_.Eq(this.Page_db(), comp.Page_db());} // check page is same; ignores anchor and xwiki
|
||||
public boolean Eq_full_db(Xoa_ttl comp) {if (comp == null) return false; return Bry_.Eq(this.Full_db(), comp.Full_db());} // check page is same; ignores anchor and xwiki
|
||||
public byte[] Raw() {return raw;} private byte[] raw = Bry_.Empty;
|
||||
public byte[] Wik_txt() {return wik_bgn == -1 ? Bry_.Empty : Bry_.Mid(full_txt, wik_bgn, ns_bgn == -1 ? page_bgn - 1 : ns_bgn - 1);}
|
||||
public Xow_xwiki_itm Wik_itm() {return wik_itm;} private Xow_xwiki_itm wik_itm;
|
||||
public byte[] Full_txt() {
|
||||
int bgn = wik_bgn == -1 ? 0 : ns_bgn == -1 ? page_bgn : ns_bgn;
|
||||
int end = full_txt.length;
|
||||
if (anch_bgn != -1) end = anch_bgn - 1;
|
||||
return Bry_.Mid(full_txt, bgn, end);
|
||||
}
|
||||
public byte[] Full_txt_raw() {return full_txt;} private byte[] full_txt = Bry_.Empty;
|
||||
public byte[] Page_txt_w_anchor() {return Bry_.Mid(full_txt, page_bgn, qarg_bgn == -1 ? full_txt.length : qarg_bgn - 1);}
|
||||
public byte[] Page_txt() {return Bry_.Mid(full_txt, page_bgn, anch_bgn == -1 ? full_txt.length : anch_bgn - 1);}
|
||||
public byte[] Page_db() {
|
||||
byte[] rv = this.Page_txt();
|
||||
Bry_.Replace_reuse(rv, Byte_ascii.Space, Byte_ascii.Underline);
|
||||
return rv;
|
||||
}
|
||||
public String Page_db_as_str() {return String_.new_u8(Page_db());}
|
||||
public int Leaf_bgn() {return leaf_bgn;}
|
||||
public byte[] Base_txt() {return leaf_bgn == -1 ? Page_txt() : Bry_.Mid(full_txt, page_bgn, leaf_bgn - 1);}
|
||||
public byte[] Leaf_txt() {return leaf_bgn == -1 ? Page_txt() : Bry_.Mid(full_txt, leaf_bgn, anch_bgn == -1 ? full_txt.length : anch_bgn - 1);}
|
||||
public int Wik_bgn() {return wik_bgn;}
|
||||
public int Anch_bgn() {return anch_bgn;} // NOTE: anch_bgn is not correct when page has trailing ws; EX: [[A #b]] should have anch_bgn of 3 (1st char after #), but instead it is 2
|
||||
public byte[] Anch_txt() {return anch_bgn == -1 ? Bry_.Empty : Bry_.Mid(full_txt, anch_bgn, full_txt.length);}
|
||||
public byte[] Talk_txt() {return ns.Id_talk() ? Full_txt() : Bry_.Add(tors_txt, Page_txt());}
|
||||
public byte[] Subj_txt() {return ns.Id_subj() ? Full_txt() : Bry_.Add(tors_txt, Page_txt());}
|
||||
public byte[] Full_url() {return Xoa_url_encoder._.Encode(full_txt);}
|
||||
public String Full_db_as_str() {return String_.new_u8(Full_db());}
|
||||
public byte[] Full_db() {return ns.Gen_ttl(this.Page_db());}
|
||||
public byte[] Page_url() {return Xoa_url_encoder._.Encode(this.Page_txt());}
|
||||
public byte[] Leaf_url() {return Xoa_url_encoder._.Encode(this.Leaf_txt());}
|
||||
public byte[] Base_url() {return Xoa_url_encoder._.Encode(this.Base_txt());}
|
||||
public byte[] Root_txt() {return root_bgn == -1 ? Page_txt() : Bry_.Mid(full_txt, page_bgn, root_bgn - 1);}
|
||||
public byte[] Rest_txt() {return root_bgn == -1 ? Page_txt() : Bry_.Mid(full_txt, root_bgn, anch_bgn == -1 ? full_txt.length : anch_bgn - 1);}
|
||||
public byte[] Talk_url() {return Xoa_url_encoder._.Encode(this.Talk_txt());}
|
||||
public byte[] Subj_url() {return Xoa_url_encoder._.Encode(this.Subj_txt());}
|
||||
public int Qarg_bgn() {return qarg_bgn;} private int qarg_bgn = -1;
|
||||
public byte[] Qarg_txt() {return this.Qarg_bgn() == -1 ? null : Bry_.Mid(full_txt, this.Qarg_bgn(), full_txt.length);}
|
||||
public byte[] Base_txt_wo_qarg() {
|
||||
int bgn = page_bgn;
|
||||
int end = full_txt.length;
|
||||
if (leaf_bgn != -1) end = leaf_bgn - 1;
|
||||
else if (qarg_bgn != -1) end = qarg_bgn - 1;
|
||||
return Bry_.Mid(full_txt, bgn, end);
|
||||
}
|
||||
public byte[] Leaf_txt_wo_qarg() {
|
||||
int bgn = leaf_bgn == -1 ? 0 : leaf_bgn;
|
||||
int end = full_txt.length;
|
||||
if (anch_bgn != -1) end = anch_bgn - 1;
|
||||
else if (qarg_bgn != -1) end = qarg_bgn - 1;
|
||||
return Bry_.Mid(full_txt, bgn, end);
|
||||
}
|
||||
public byte[] Full_txt_wo_qarg() {
|
||||
int bgn = wik_bgn == -1 ? 0 : ns_bgn == -1 ? page_bgn : ns_bgn;
|
||||
int end = full_txt.length;
|
||||
if (anch_bgn != -1) end = anch_bgn - 1;
|
||||
else if (qarg_bgn != -1) end = qarg_bgn - 1;
|
||||
return Bry_.Mid(full_txt, bgn, end);
|
||||
}
|
||||
public byte[] Page_txt_wo_qargs() { // assume that no Special page has non-ascii characters
|
||||
int full_txt_len = full_txt.length;
|
||||
int ques_pos = Bry_finder.Find_bwd(full_txt, Byte_ascii.Question, full_txt_len, page_bgn);
|
||||
return Bry_.Mid(full_txt, page_bgn, ques_pos == Bry_.NotFound ? full_txt_len : ques_pos);
|
||||
}
|
||||
public static Xoa_ttl parse(Xowe_wiki wiki, int ns_id, byte[] ttl) {
|
||||
Xow_ns ns = wiki.Ns_mgr().Ids_get_or_null(ns_id);
|
||||
byte[] raw = Bry_.Add(ns.Name_db_w_colon(), ttl);
|
||||
return new_(wiki, wiki.Appe().Msg_log(), raw, 0, raw.length);
|
||||
}
|
||||
public static Xoa_ttl parse(Xowe_wiki wiki, byte[] raw) {return new_(wiki, wiki.Appe().Msg_log(), raw, 0, raw.length);}
|
||||
private static final Object thread_lock = new Object();
|
||||
// $dbkey = preg_replace( '/\xE2\x80[\x8E\x8F\xAA-\xAE]/S', '', $dbkey );
|
||||
// $dbkey = preg_replace( '/[ _\xA0\x{1680}\x{180E}\x{2000}-\x{200A}\x{2028}\x{2029}\x{202F}\x{205F}\x{3000}]+/u', '_', $dbkey );
|
||||
private static final int Char__bidi = 1, Char__ws = 2;
|
||||
private static final Btrie_slim_mgr char_trie = Btrie_slim_mgr.cs()
|
||||
.Add_many_int(Char__bidi , Bry_.ints_(0xE2, 0x80, 0x8E), Bry_.ints_(0xE2, 0x80, 0x8F), Bry_.ints_(0xE2, 0x80, 0xAA), Bry_.ints_(0xE2, 0x80, 0xAB), Bry_.ints_(0xE2, 0x80, 0xAC), Bry_.ints_(0xE2, 0x80, 0xAD), Bry_.ints_(0xE2, 0x80, 0xAE))
|
||||
.Add_many_int(Char__ws , "\u00A0", "\u1680", "\u180E", "\u2000", "\u2001", "\u2002", "\u2003", "\u2004", "\u2005", "\u2006", "\u2007", "\u2008", "\u2009", "\u200A", "\u2028", "\u2029", "\u202F", "\u205F", "\u3000")
|
||||
;
|
||||
public static Xoa_ttl new_(Xowe_wiki wiki, Gfo_msg_log msg_log, byte[] src, int bgn, int end) {
|
||||
Xoae_app app = wiki.Appe();
|
||||
Bry_bfr_mkr bry_mkr = app.Utl__bfr_mkr();
|
||||
return parse(bry_mkr, app.Parser_amp_mgr(), wiki.Lang().Case_mgr(), wiki.Xwiki_mgr(), wiki.Ns_mgr(), msg_log, src, bgn, end);
|
||||
} private Xoa_ttl() {}
|
||||
public static Xoa_ttl parse(Bry_bfr_mkr bry_mkr, Xop_amp_mgr amp_mgr, Xol_case_mgr case_mgr, Xow_xwiki_mgr xwiki_mgr, Xow_ns_mgr ns_mgr, Gfo_msg_log msg_log, byte[] src, int bgn, int end) {
|
||||
synchronized (thread_lock) {
|
||||
Xoa_ttl rv = new Xoa_ttl();
|
||||
Bry_bfr bfr = bry_mkr.Get_b512();
|
||||
try {
|
||||
boolean pass = rv.Parse(bfr, bry_mkr, amp_mgr, case_mgr, xwiki_mgr, ns_mgr, msg_log, src, bgn, end);
|
||||
return pass ? rv : null;
|
||||
}
|
||||
finally {bfr.Mkr_rls();}
|
||||
}
|
||||
}
|
||||
private boolean Parse(Bry_bfr bfr, Bry_bfr_mkr bry_mkr, Xop_amp_mgr amp_mgr, Xol_case_mgr case_mgr, Xow_xwiki_mgr xwiki_mgr, Xow_ns_mgr ns_mgr, Gfo_msg_log msg_log, byte[] src, int bgn, int end) {
|
||||
/* This proc will
|
||||
- identify all parts: Wiki, Namespace, Base/Leaf, Anchor; it will also identify Subject/Talk ns
|
||||
- trim whitespace around part delimiters; EX: "Help : Test" --> "Help:Test"; note that it will trim only if the ns part is real; EX: "Helpx : Test" is unchanged
|
||||
- replace multiple whitespaces with 1; EX: "Many ws" --> "Many ws"
|
||||
- capitalize the first letter of the page title
|
||||
note: a byte[] is needed b/c proc does collapsing and casing
|
||||
FUTURE:
|
||||
- "/", "a/" (should be page); "#" (not a page)
|
||||
- Talk:Help:a disallowed; Category talk:Help:a allowed
|
||||
- remove invalid characters $rxTc
|
||||
- forbid ./ /.
|
||||
- forbid ~~~
|
||||
- handle ip address urls for User and User talk
|
||||
*/
|
||||
Url_encoder anchor_encoder = null;
|
||||
Bry_bfr anchor_encoder_bfr = null;
|
||||
bfr.Clear();
|
||||
if (end - bgn == 0) {msg_log.Add_itm_none(Xop_ttl_log.Len_0, src, bgn, bgn); return false;}
|
||||
this.raw = src;
|
||||
ns = ns_mgr.Ns_main();
|
||||
boolean add_ws = false, ltr_bgn_reset = false;
|
||||
int ltr_bgn = -1, txt_bb_len = 0, colon_count = 0; bfr.Clear();
|
||||
Btrie_slim_mgr amp_trie = amp_mgr.Amp_trie();
|
||||
byte[] b_ary = null;
|
||||
int cur = bgn;
|
||||
int match_pos = -1;
|
||||
while (cur != end) {
|
||||
byte b = src[cur];
|
||||
switch (b) {
|
||||
case Byte_ascii.Colon:
|
||||
if (cur == bgn) { // initial colon; flag; note that " :" is not handled; note that colon_count is not incremented
|
||||
forceLiteralLink = true;
|
||||
++cur;
|
||||
if (cur < end && src[cur] == Byte_ascii.Colon)
|
||||
++cur;
|
||||
continue; // do not add to bfr
|
||||
}
|
||||
else {
|
||||
if (ltr_bgn == -1) {// no ltrs seen; treat as literal; occurs for ::fr:wikt:test and fr::Help:test
|
||||
++colon_count;
|
||||
break;
|
||||
}
|
||||
boolean part_found = false;
|
||||
if (colon_count == 0) {// 1st colon;
|
||||
Object o = ns_mgr.Names_get_or_null(bfr.Bfr(), ltr_bgn, txt_bb_len);
|
||||
if (o == null) { // not ns; try alias
|
||||
wik_itm = xwiki_mgr.Get_by_mid(bfr.Bfr(), ltr_bgn, txt_bb_len); // check if wiki; note: wiki is not possible for other colons
|
||||
if (wik_itm != null) {
|
||||
wik_bgn = 0; // wik_bgn can only start at 0
|
||||
part_found = true;
|
||||
anch_bgn = -1; // NOTE: do not allow anchors to begin before wiki_itm; breaks Full_txt for [[:#batch:Main Page]]; DATE:20130102
|
||||
}
|
||||
}
|
||||
else {
|
||||
ns = (Xow_ns)o;
|
||||
byte[] ns_name = ns.Name_txt();
|
||||
int ns_name_len = ns_name.length;
|
||||
int tmp_bfr_end = bfr.Len();
|
||||
if (!Bry_.Eq(ns_name, bfr.Bfr(), ltr_bgn, tmp_bfr_end) && ns_name_len == tmp_bfr_end - ltr_bgn) { // if (a) ns_name != bfr_txt (b) both are same length; note that (b) should not happen, but want to safeguard against mismatched arrays
|
||||
Bry_.Set(bfr.Bfr(), ltr_bgn, tmp_bfr_end, ns_name);
|
||||
}
|
||||
ns_bgn = ltr_bgn;
|
||||
part_found = true;
|
||||
}
|
||||
}
|
||||
if (part_found) {
|
||||
page_bgn = txt_bb_len + 1; // anticipate page_bgn;
|
||||
add_ws = false; // if there was an add_ws, ignore; EX: "Category :" should ignore space
|
||||
ltr_bgn_reset = true; // ltr_bgn_reset
|
||||
}
|
||||
colon_count++; // increment colon count
|
||||
break;
|
||||
}
|
||||
case Byte_ascii.Hash: anch_bgn = (txt_bb_len) + 1; break; // flag last anch_bgn
|
||||
case Byte_ascii.Slash:
|
||||
if (root_bgn == -1)
|
||||
root_bgn = (txt_bb_len) + 1;
|
||||
if (anch_bgn == -1) { // only set leaf if anchor found; guards against A#B/C and / setting leaf; DATE:2014-01-14
|
||||
leaf_bgn = (txt_bb_len) + 1;
|
||||
qarg_bgn = -1; // always reset qarg; handles ttls which have question_mark which are premptively assumed to be qarg; PAGE:en.w:Portal:Organized_Labour/Did_You_Know?/1 DATE:2014-06-08
|
||||
}
|
||||
break; // flag last leaf_bgn
|
||||
case Byte_ascii.Nl: // NOTE: for now, treat nl just like space; not sure if it should accept "a\nb" or "\nab"; need to handle trailing \n for "Argentina\n\n" in {{Infobox settlement|pushpin_map=Argentina|pushpin_label_position=|pushpin_map_alt=|pushpin_map_caption=Location of Salta in Argentina}};
|
||||
case Byte_ascii.Space: case Byte_ascii.Tab: case Byte_ascii.Cr: // added \t, \r; DATE:2013-03-27
|
||||
case Byte_ascii.Underline:if (ltr_bgn != -1) add_ws = true; ++cur;//cur = ttlTrie.Match_pos();
|
||||
continue; // only mark add_ws if ltr_seen; this ignores ws at bgn; also, note "continue"
|
||||
case Byte_ascii.Question:
|
||||
if (txt_bb_len + 1 < end) // guard against trailing ? (which shouldn't happen)
|
||||
qarg_bgn = txt_bb_len + 1;
|
||||
break;
|
||||
case Byte_ascii.Amp:
|
||||
int cur2 = cur + 1;//cur = ttlTrie.Match_pos();
|
||||
if (cur2 == end) {} // guards against terminating &; EX: [[Bisc &]]; NOTE: needed b/c Match_bgn does not do bounds checking for cur in src; src[src.length] will be called when & is last character;
|
||||
else {
|
||||
Object html_ent_obj = amp_trie.Match_bgn(src, cur2, end);
|
||||
if (html_ent_obj != null) {
|
||||
Xop_amp_trie_itm amp_itm = (Xop_amp_trie_itm)html_ent_obj;
|
||||
match_pos = amp_trie.Match_pos();
|
||||
if (amp_itm.Tid() == Xop_amp_trie_itm.Tid_name_std) {
|
||||
switch (amp_itm.Char_int()) {
|
||||
case 160: // NOTE:   must convert to space; EX:w:United States [[Image:Dust Bowl - Dallas, South Dakota 1936.jpg|220px|alt=]]
|
||||
if (ltr_bgn != -1) add_ws = true; // apply same ws rules as Space, NewLine; needed for converting multiple ws into one; EX:" " -> " " x> " "; PAGEen.w:Greek_government-debt_crisis; DATE:2014-09-25
|
||||
cur = match_pos; // set cur after ";"
|
||||
continue;
|
||||
case Byte_ascii.Amp:
|
||||
b_ary = Byte_ascii.Amp_bry; // NOTE: if & convert to &; PAGE:en.w:Amadou Bagayoko?redirect=n; DATE:2014-09-23
|
||||
break;
|
||||
case Byte_ascii.Quote:
|
||||
case Byte_ascii.Lt:
|
||||
case Byte_ascii.Gt:
|
||||
b_ary = amp_itm.Xml_name_bry();
|
||||
break;
|
||||
case Xop_amp_trie_itm.Char_int_null: // &#xx;
|
||||
int end_pos = Bry_finder.Find_fwd(src, Byte_ascii.Semic, match_pos, end);
|
||||
if (end_pos == Bry_.NotFound) {} // &# but no terminating ";" noop: defaults to current_byte which will be added below;
|
||||
else {
|
||||
b_ary = amp_itm.Xml_name_bry();
|
||||
match_pos = end_pos + 1;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
b_ary = amp_itm.U8_bry();
|
||||
break;
|
||||
}
|
||||
}
|
||||
else {
|
||||
boolean pass = amp_mgr.Parse_as_int(amp_itm.Tid() == Xop_amp_trie_itm.Tid_num_hex, src, end, cur2, match_pos);
|
||||
if (pass) {
|
||||
b_ary = gplx.intl.Utf16_.Encode_int_to_bry(amp_mgr.Rslt_val());
|
||||
if (b_ary.length == 1 && b_ary[0] == Byte_ascii.Hash) // NOTE: A#B should be interpreted as A#b; PAGE:en.s:The_English_Constitution_(1894) DATE:2014-09-07
|
||||
anch_bgn = (txt_bb_len) + 1;
|
||||
match_pos = amp_mgr.Rslt_pos();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case Byte_ascii.Lt:
|
||||
if (cur + 3 < end) {
|
||||
if ( src[cur + 1] == Byte_ascii.Bang
|
||||
&& src[cur + 2] == Byte_ascii.Dash
|
||||
&& src[cur + 3] == Byte_ascii.Dash
|
||||
) {
|
||||
int cur3 = cur + 3;//cur = ttlTrie.Match_pos();
|
||||
int find = Bry_finder.Find_fwd(src, Xop_comm_lxr.End_ary, cur3, end);
|
||||
if (find != -1) {
|
||||
cur = find + Xop_comm_lxr.End_ary.length;
|
||||
continue;
|
||||
}
|
||||
else {
|
||||
msg_log.Add_itm_none(Xop_ttl_log.Comment_eos, src, bgn, end);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (anch_bgn != -1) {
|
||||
if (anchor_encoder == null) {
|
||||
anchor_encoder = Url_encoder.new_html_id_();
|
||||
anchor_encoder_bfr = Bry_bfr.reset_(32);
|
||||
}
|
||||
anchor_encoder.Encode(anchor_encoder_bfr, src, cur, cur + 1);
|
||||
b_ary = anchor_encoder_bfr.Xto_bry_and_clear();
|
||||
match_pos = cur + 1;
|
||||
}
|
||||
break;
|
||||
// NOTE: DefaultSettings.php defines wgLegalTitleChars as " %!\"$&'()*,\\-.\\/0-9:;=?@A-Z\\\\^_`a-z~\\x80-\\xFF+"; the characters above are okay; those below are not
|
||||
case Byte_ascii.Gt: case Byte_ascii.Pipe:
|
||||
case Byte_ascii.Brack_bgn: case Byte_ascii.Brack_end: case Byte_ascii.Curly_bgn: case Byte_ascii.Curly_end:
|
||||
if (anch_bgn != -1) {
|
||||
if (anchor_encoder == null) {
|
||||
anchor_encoder = Url_encoder.new_html_id_();
|
||||
anchor_encoder_bfr = Bry_bfr.reset_(32);
|
||||
}
|
||||
anchor_encoder.Encode(anchor_encoder_bfr, src, cur, cur + 1);
|
||||
b_ary = anchor_encoder_bfr.Xto_bry_and_clear();
|
||||
match_pos = cur + 1;
|
||||
}
|
||||
else {
|
||||
msg_log.Add_itm_none(Xop_ttl_log.Invalid_char, src, bgn, end);
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
if ((b & 0xff) > 127) {// PATCH.JAVA:need to convert to unsigned byte
|
||||
Object char_obj = char_trie.Match_bgn_w_byte(b, src, cur, end);
|
||||
if (char_obj != null) {
|
||||
int tid = ((Int_obj_val)(char_obj)).Val();
|
||||
switch (tid) {
|
||||
case Char__bidi: // ignore bidi
|
||||
cur = char_trie.Match_pos();
|
||||
continue;
|
||||
case Char__ws: // treat extended_ws as space; PAGE:ja.w:Template:Location_map_USA New_York; DATE:2015-07-28
|
||||
cur = char_trie.Match_pos();
|
||||
if (ltr_bgn != -1) add_ws = true;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
++cur;
|
||||
if (add_ws) { // add ws and toggle flag
|
||||
bfr.Add_byte(Byte_ascii.Space); ++txt_bb_len;
|
||||
add_ws = false;
|
||||
}
|
||||
if (ltr_bgn == -1) ltr_bgn = txt_bb_len; // if 1st letter not seen, mark 1st letter
|
||||
if (b_ary == null) {bfr.Add_byte(b); ++txt_bb_len;} // add to bfr
|
||||
else {bfr.Add(b_ary); txt_bb_len += b_ary.length; b_ary = null; cur = match_pos;} // NOTE: b_ary != null only for amp_trie
|
||||
if (ltr_bgn_reset) {// colon found; set ws to bgn mode; note that # and / do not reset
|
||||
ltr_bgn_reset = false;
|
||||
ltr_bgn = -1;
|
||||
}
|
||||
}
|
||||
if (txt_bb_len == 0) {msg_log.Add_itm_none(Xop_ttl_log.Len_0, src, bgn, end); return false;}
|
||||
if (wik_bgn == -1 && page_bgn == txt_bb_len) { // if no wiki, but page_bgn is at end, then ttl is ns only; EX: "Help:"; NOTE: "fr:", "fr:Help" is allowed
|
||||
msg_log.Add_itm_none(Xop_ttl_log.Ttl_is_ns_only, src, bgn, end);
|
||||
return false;
|
||||
}
|
||||
full_txt = bfr.Xto_bry_and_clear();
|
||||
if ( ns.Case_match() == Xow_ns_case_.Id_1st
|
||||
&& wik_bgn == -1 ) { // do not check case if xwiki; EX: "fr:" would have a wik_bgn of 0 (and a wik_end of 3); "A" (and any non-xwiki ttl) would have a wik_bgn == -1
|
||||
byte char_1st = full_txt[page_bgn];
|
||||
int char_1st_len = gplx.intl.Utf8_.Len_of_char_by_1st_byte(char_1st);
|
||||
int page_end = page_bgn + char_1st_len;
|
||||
if ( char_1st_len > 1) { // 1st char is multi-byte char
|
||||
int full_txt_len = full_txt.length;
|
||||
if (page_end > full_txt_len) // ttl is too too short for 1st multi-byte char; EX: [[%D0]] is 208 but in utf8, 208 requires at least another char; DATE:2013-11-11
|
||||
return false; // ttl is invalid
|
||||
else { // ttl is long enough for 1st mult-byte char; need to use platform uppercasing; Xol_case_mgr_.Utf_8 is not sufficient
|
||||
Bry_bfr upper_1st = bry_mkr.Get_b512();
|
||||
byte[] page_txt = case_mgr.Case_build_1st_upper(upper_1st, full_txt, page_bgn, full_txt_len); // always build; never reuse; (multi-byte character will expand array)
|
||||
if (page_bgn == 0) // page only; EX: A
|
||||
full_txt = page_txt;
|
||||
else // ns + page; EX: Help:A
|
||||
full_txt = Bry_.Add(Bry_.Mid(full_txt, 0, page_bgn), page_txt); // add page_txt to exsiting ns
|
||||
upper_1st.Mkr_rls();
|
||||
}
|
||||
}
|
||||
else
|
||||
full_txt = case_mgr.Case_reuse_upper(full_txt, page_bgn, page_end);
|
||||
}
|
||||
Xow_ns tors_ns = ns.Id_talk() ? ns_mgr.Ords_get_at(ns.Ord_subj_id()) : ns_mgr.Ords_get_at(ns.Ord_talk_id());
|
||||
tors_txt = tors_ns.Name_txt_w_colon();
|
||||
return true;
|
||||
}
|
||||
public static byte[] Replace_spaces(byte[] raw) {return Bry_.Replace(raw, Byte_ascii.Space, Byte_ascii.Underline);}
|
||||
public static byte[] Replace_unders(byte[] raw) {return Bry_.Replace(raw, Byte_ascii.Underline, Byte_ascii.Space);}
|
||||
private int wik_bgn = -1, ns_bgn = -1, page_bgn = 0, leaf_bgn = -1, anch_bgn = -1, root_bgn = -1;
|
||||
private byte[] tors_txt;
|
||||
public static final int Wik_bgn_int = -1;
|
||||
public static final byte Subpage_spr = Byte_ascii.Slash; // EX: A/B/C
|
||||
public static final int Anch_bgn_anchor_only = 1; // signifies lnki which is only anchor; EX: [[#anchor]]
|
||||
public static final int Max_len = 2048; // ASSUME: max len of 256 * 8 bytes
|
||||
public static final int Null_wik_bgn = -1;
|
||||
public static final Xoa_ttl Null = null;
|
||||
}
|
||||
class Xoa_url_encoder {
|
||||
public byte[] Encode(byte[] src) {
|
||||
int src_len = src.length;
|
||||
for (int i = 0; i < src_len; i++) {
|
||||
byte b = src[i];
|
||||
switch (b) {
|
||||
case Byte_ascii.Space: bb.Add(Bry_underline); break;
|
||||
case Byte_ascii.Amp: bb.Add(Bry_amp); break;
|
||||
case Byte_ascii.Apos: bb.Add(Bry_apos); break;
|
||||
case Byte_ascii.Eq: bb.Add(Bry_eq); break;
|
||||
case Byte_ascii.Plus: bb.Add(Bry_plus); break;
|
||||
default: bb.Add_byte(b); break;
|
||||
// FUTURE: html_entities, etc:
|
||||
}
|
||||
}
|
||||
return bb.Xto_bry_and_clear();
|
||||
}
|
||||
private static final byte[] Bry_amp = Bry_.new_a7("%26"), Bry_eq = Bry_.new_a7("%3D")
|
||||
, Bry_plus = Bry_.new_a7("%2B"), Bry_apos = Bry_.new_a7("%27")
|
||||
, Bry_underline = new byte[] {Byte_ascii.Underline}
|
||||
;
|
||||
Bry_bfr bb = Bry_bfr.new_();
|
||||
public static final Xoa_url_encoder _ = new Xoa_url_encoder(); Xoa_url_encoder() {}
|
||||
}
|
||||
class Xoa_ttl_trie {
|
||||
public static Btrie_fast_mgr new_() {
|
||||
Btrie_fast_mgr rv = Btrie_fast_mgr.cs();
|
||||
rv.Add(Byte_ascii.Colon , Byte_obj_val.new_(Id_colon));
|
||||
rv.Add(Byte_ascii.Hash , Byte_obj_val.new_(Id_hash));
|
||||
rv.Add(Byte_ascii.Slash , Byte_obj_val.new_(Id_slash));
|
||||
rv.Add(Byte_ascii.Space , Byte_obj_val.new_(Id_space));
|
||||
rv.Add(Byte_ascii.Underline , Byte_obj_val.new_(Id_underline));
|
||||
rv.Add(Byte_ascii.Amp , Byte_obj_val.new_(Id_amp));
|
||||
rv.Add(Xop_comm_lxr.Bgn_ary , Byte_obj_val.new_(Id_comment_bgn));
|
||||
rv.Add(Byte_ascii.Nl , Byte_obj_val.new_(Id_newLine));
|
||||
rv.Add(Byte_ascii.Brack_bgn , Byte_obj_val.new_(Id_invalid));
|
||||
rv.Add(Byte_ascii.Curly_bgn , Byte_obj_val.new_(Id_invalid));
|
||||
return rv;
|
||||
}
|
||||
public static final byte Id_colon = 0, Id_hash = 1, Id_slash = 2, Id_space = 3, Id_underline = 4, Id_amp = 5, Id_comment_bgn = 6, Id_invalid = 7, Id_newLine = 8;
|
||||
}
|
||||
@@ -19,14 +19,15 @@ package gplx.xowa; import gplx.*;
|
||||
import gplx.core.btries.*; import gplx.core.flds.*; import gplx.ios.*; import gplx.core.threads.*; import gplx.core.json.*;
|
||||
import gplx.xowa.apps.*; import gplx.xowa.apps.caches.*; import gplx.xowa.apps.fsys.*; import gplx.xowa.apis.*; import gplx.xowa.apps.metas.*; import gplx.xowa.urls.encoders.*; import gplx.xowa.apps.progs.*;
|
||||
import gplx.xowa.langs.*; import gplx.xowa.specials.*; import gplx.xowa.cfgs2.*;
|
||||
import gplx.xowa.bldrs.css.*;
|
||||
import gplx.xowa.files.caches.*; import gplx.xowa.files.imgs.*;
|
||||
import gplx.xowa.bldrs.css.*; import gplx.xowa.bldrs.installs.*;
|
||||
import gplx.xowa.files.*; import gplx.xowa.files.caches.*; import gplx.xowa.files.imgs.*;
|
||||
import gplx.xowa.wikis.*; import gplx.xowa.users.*; import gplx.xowa.gui.*; import gplx.xowa.cfgs.*; import gplx.xowa.ctgs.*; import gplx.xowa.html.tocs.*; import gplx.xowa.fmtrs.*; import gplx.xowa.html.*;
|
||||
import gplx.xowa.html.hrefs.*; import gplx.xowa.html.wtrs.*; import gplx.xowa.html.ns_files.*; import gplx.xowa.html.bridges.*;
|
||||
import gplx.xowa.parsers.*; import gplx.xowa.parsers.amps.*; import gplx.xowa.parsers.tblws.*;
|
||||
import gplx.xowa.parsers.*; import gplx.xowa.parsers.amps.*; import gplx.xowa.parsers.tblws.*; import gplx.xowa.parsers.xndes.*;
|
||||
import gplx.xowa.xtns.*; import gplx.xowa.xtns.scribunto.*; import gplx.xowa.xtns.math.*;
|
||||
import gplx.xowa.parsers.logs.*; import gplx.xowa.servers.tcp.*; import gplx.xowa.servers.http.*;
|
||||
import gplx.xowa.parsers.utils.*; import gplx.xowa.parsers.logs.*; import gplx.xowa.servers.tcp.*; import gplx.xowa.servers.http.*;
|
||||
import gplx.xowa.wmfs.*;
|
||||
import gplx.xowa.tdbs.*; import gplx.xowa.tdbs.hives.*;
|
||||
public class Xoae_app implements Xoa_app, GfoInvkAble {
|
||||
public Xoae_app(Gfo_usr_dlg usr_dlg, Xoa_app_type app_type, Io_url root_dir, Io_url wiki_dir, Io_url file_dir, Io_url user_dir, Io_url css_dir, String bin_dir_name) {
|
||||
Xoa_app_.Usr_dlg_(usr_dlg);
|
||||
@@ -104,7 +105,6 @@ public class Xoae_app implements Xoa_app, GfoInvkAble {
|
||||
public Xoa_hive_mgr Hive_mgr() {return hive_mgr;} private Xoa_hive_mgr hive_mgr;
|
||||
public Xop_sanitizer Sanitizer() {return sanitizer;} private Xop_sanitizer sanitizer;
|
||||
public Xop_xatr_parser Xatr_parser() {return xatr_parser;} private Xop_xatr_parser xatr_parser = new Xop_xatr_parser();
|
||||
public Xop_xnde_tag_regy Xnde_tag_regy() {return xnde_tag_regy;} private Xop_xnde_tag_regy xnde_tag_regy = new Xop_xnde_tag_regy();
|
||||
public Xof_math_subst_regy Math_subst_regy() {return math_subst_regy;} private Xof_math_subst_regy math_subst_regy = new Xof_math_subst_regy();
|
||||
public Xoa_prog_mgr Prog_mgr() {return prog_mgr;} private final Xoa_prog_mgr prog_mgr = new Xoa_prog_mgr();
|
||||
public Gfo_async_mgr Async_mgr() {return async_mgr;} private Gfo_async_mgr async_mgr = new Gfo_async_mgr();
|
||||
|
||||
111
400_xowa/src/gplx/xowa/Xoae_page.java
Normal file
111
400_xowa/src/gplx/xowa/Xoae_page.java
Normal file
@@ -0,0 +1,111 @@
|
||||
/*
|
||||
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; import gplx.*;
|
||||
import gplx.xowa.gui.*; import gplx.xowa.gui.views.*; import gplx.xowa.html.*; import gplx.xowa.pages.*;
|
||||
import gplx.xowa.files.*; import gplx.xowa.files.xfers.*; import gplx.xowa.xtns.cite.*; import gplx.xowa.xtns.wdatas.*; import gplx.xowa.parsers.lnkis.redlinks.*; import gplx.xowa.html.tocs.*;
|
||||
import gplx.xowa.html.modules.popups.*; import gplx.xowa.html.hdumps.pages.*; import gplx.xowa.xtns.wdatas.pfuncs.*;
|
||||
import gplx.xowa.parsers.*;
|
||||
public class Xoae_page implements Xoa_page {
|
||||
Xoae_page(Xowe_wiki wiki, Xoa_ttl ttl) {
|
||||
this.wiki = wiki; this.ttl = ttl;
|
||||
this.lang = wiki.Lang(); // default to wiki.lang; can be override later by wikitext
|
||||
hdr_mgr = new Xow_hdr_mgr(this, Xoa_app_.Utl__encoder_mgr());
|
||||
redlink_lnki_list = new Xopg_redlink_lnki_list(ttl.Ns().Id_module());
|
||||
Ttl_(ttl);
|
||||
} Xoae_page() {} // called by Null
|
||||
public Xow_wiki Wiki() {return wiki;}
|
||||
public Xoa_ttl Ttl() {return ttl;} public Xoae_page Ttl_(Xoa_ttl v) {ttl = v; url.Wiki_bry_(wiki.Domain_bry()).Page_bry_(v.Full_url()); return this;} private Xoa_ttl ttl;
|
||||
public Xoa_url Url() {return url;} public Xoae_page Url_(Xoa_url v) {url = v; return this;} private Xoa_url url = Xoa_url.blank();
|
||||
public byte[] Url_bry_safe() {return url == null ? Bry_.Empty : url.Raw();}
|
||||
public void Xtn_gallery_packed_exists_y_() {html_data.Xtn_gallery_packed_exists_y_();}
|
||||
public boolean Exists() {return !Missing();}
|
||||
|
||||
public Xoa_page__commons_mgr Commons_mgr() {return commons_mgr;} private final Xoa_page__commons_mgr commons_mgr = new Xoa_page__commons_mgr();
|
||||
public Xopg_revision_data Revision_data() {return revision_data;} private Xopg_revision_data revision_data = new Xopg_revision_data();
|
||||
public Xowe_wiki Wikie() {return wiki;} private Xowe_wiki wiki;
|
||||
public Xopg_redlink_lnki_list Redlink_lnki_list() {return redlink_lnki_list;} private Xopg_redlink_lnki_list redlink_lnki_list;
|
||||
public Xol_lang Lang() {return lang;} public Xoae_page Lang_(Xol_lang v) {lang = v; return this;} private Xol_lang lang;
|
||||
public Xopg_html_data Html_data() {return html_data;} private Xopg_html_data html_data = new Xopg_html_data();
|
||||
public Xopg_tab_data Tab_data() {return tab_data;} private final Xopg_tab_data tab_data = new Xopg_tab_data();
|
||||
public Xopg_hdump_data Hdump_data() {return hdump_data;} private final Xopg_hdump_data hdump_data = new Xopg_hdump_data();
|
||||
public boolean Missing() {return missing;} public Xoae_page Missing_() {return Missing_(true);} public Xoae_page Missing_(boolean v) {missing = v; return this;} private boolean missing;
|
||||
public boolean Redirected() {return redirected;} public Xoae_page Redirected_(boolean v) {redirected = v; return this;} private boolean redirected;
|
||||
public List_adp Redirected_ttls() {return redirected_ttls;} private List_adp redirected_ttls = List_adp_.new_();
|
||||
public byte[] Redirected_ttls__itm_0() {return (byte[])redirected_ttls.Get_at(0);}
|
||||
public byte[] Redirected_src() {return redirected_src;} public void Redirected_src_(byte[] v) {this.redirected_src = v;} private byte[] redirected_src;
|
||||
public byte Edit_mode() {return edit_mode;} private byte edit_mode; public void Edit_mode_update_() {edit_mode = Xoa_page_.Edit_mode_update;}
|
||||
public Xop_root_tkn Root() {return root;} public Xoae_page Root_(Xop_root_tkn v) {root = v; return this;} private Xop_root_tkn root;
|
||||
public byte[] Data_raw() {return data_raw;} public Xoae_page Data_raw_(byte[] v) {data_raw = v; return this;} private byte[] data_raw = Bry_.Empty;
|
||||
public Xow_hdr_mgr Hdr_mgr() {return hdr_mgr;} private Xow_hdr_mgr hdr_mgr;
|
||||
public Xoh_cmd_mgr Html_cmd_mgr() {return html_cmd_mgr;} private Xoh_cmd_mgr html_cmd_mgr = new Xoh_cmd_mgr();
|
||||
public byte[][] Category_list() {return category_list;} public Xoae_page Category_list_(byte[][] v) {category_list = v; return this;} private byte[][] category_list = new byte[0][];
|
||||
public List_adp Lnki_list() {return lnki_list;} public void Lnki_list_(List_adp v) {this.lnki_list = v;} private List_adp lnki_list = List_adp_.new_();
|
||||
public Xof_xfer_queue File_queue() {return file_queue;} private Xof_xfer_queue file_queue = new Xof_xfer_queue();
|
||||
public List_adp File_math() {return file_math;} private List_adp file_math = List_adp_.new_();
|
||||
public Ref_itm_mgr Ref_mgr() {return ref_mgr;} private Ref_itm_mgr ref_mgr = new Ref_itm_mgr();
|
||||
public Xopg_popup_mgr Popup_mgr() {return popup_mgr;} private Xopg_popup_mgr popup_mgr = new Xopg_popup_mgr();
|
||||
public List_adp Slink_list() {return slink_list;} private List_adp slink_list = List_adp_.new_();
|
||||
public Wdata_external_lang_links_data Wdata_external_lang_links() {return wdata_external_lang_links;} private Wdata_external_lang_links_data wdata_external_lang_links = new Wdata_external_lang_links_data();
|
||||
public boolean Pages_recursed() {return pages_recursed;} public void Pages_recursed_(boolean v) {pages_recursed = v; } private boolean pages_recursed;
|
||||
public int Bldr__ns_ord() {return bldr__ns_ord;} public void Bldr__ns_ord_(int v) {bldr__ns_ord = v;} private int bldr__ns_ord;
|
||||
public Xopg_tmpl_prepend_mgr Tmpl_prepend_mgr() {return tmpl_prepend_mgr;} private Xopg_tmpl_prepend_mgr tmpl_prepend_mgr = new Xopg_tmpl_prepend_mgr();
|
||||
public void Tmpl_stack_del() {--tmpl_stack_ary_len;}
|
||||
public boolean Tmpl_stack_add(byte[] key) {
|
||||
for (int i = 0; i < tmpl_stack_ary_len; i++) {
|
||||
if (Bry_.Match(key, tmpl_stack_ary[i])) return false;
|
||||
}
|
||||
int new_len = tmpl_stack_ary_len + 1;
|
||||
if (new_len > tmpl_stack_ary_max) {
|
||||
tmpl_stack_ary_max = new_len * 2;
|
||||
tmpl_stack_ary = (byte[][])Array_.Resize(tmpl_stack_ary, tmpl_stack_ary_max);
|
||||
}
|
||||
tmpl_stack_ary[tmpl_stack_ary_len] = key;
|
||||
tmpl_stack_ary_len = new_len;
|
||||
return true;
|
||||
} private byte[][] tmpl_stack_ary = Bry_.Ary_empty; private int tmpl_stack_ary_len = 0, tmpl_stack_ary_max = 0;
|
||||
public void Clear() { // NOTE: this is called post-fetch but pre-parse; do not clear items set by post-fetch, such as id, ttl, redirected_ttls, data_raw
|
||||
hdr_mgr.Clear();
|
||||
lnki_list.Clear();
|
||||
file_math.Clear();
|
||||
file_queue.Clear();
|
||||
ref_mgr.Grps_clear();
|
||||
html_cmd_mgr.Clear();
|
||||
hdump_data.Clear();
|
||||
wdata_external_lang_links.Reset();
|
||||
gplx.xowa.xtns.scribunto.Scrib_core.Core_page_changed(this);
|
||||
slink_list.Clear();
|
||||
html_data.Clear();
|
||||
tab_data.Clear();
|
||||
pages_recursed = false;
|
||||
tmpl_stack_ary = Bry_.Ary_empty;
|
||||
tmpl_stack_ary_len = tmpl_stack_ary_max = 0;
|
||||
popup_mgr.Clear();
|
||||
revision_data.Clear();
|
||||
tmpl_prepend_mgr.Clear();
|
||||
commons_mgr.Clear();
|
||||
}
|
||||
public static final Xoae_page Null = null;
|
||||
public static final Xoae_page Empty = new Xoae_page().Missing_();
|
||||
public static Xoae_page test_(Xowe_wiki wiki, Xoa_ttl ttl) {return new Xoae_page(wiki, ttl);}
|
||||
public static Xoae_page new_(Xowe_wiki wiki, Xoa_ttl ttl) {return new Xoae_page(wiki, ttl);}
|
||||
public static Xoae_page create_(Xowe_wiki wiki, Xoa_ttl ttl) {
|
||||
Xoae_page rv = new Xoae_page(wiki, ttl);
|
||||
rv.edit_mode = Xoa_page_.Edit_mode_create;
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
419
400_xowa/src/gplx/xowa/Xop_fxt.java
Normal file
419
400_xowa/src/gplx/xowa/Xop_fxt.java
Normal file
@@ -0,0 +1,419 @@
|
||||
/*
|
||||
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; import gplx.*;
|
||||
import gplx.xowa.langs.*; import gplx.xowa.html.*;
|
||||
import gplx.xowa.parsers.*; import gplx.xowa.parsers.amps.*; import gplx.xowa.parsers.apos.*; import gplx.xowa.parsers.hdrs.*; import gplx.xowa.parsers.lists.*; import gplx.xowa.parsers.paras.*; import gplx.xowa.parsers.xndes.*; import gplx.xowa.parsers.tmpls.*; import gplx.xowa.parsers.miscs.*; import gplx.xowa.parsers.tblws.*; import gplx.xowa.parsers.lnkes.*; import gplx.xowa.parsers.lnkis.*;
|
||||
import gplx.xowa.files.exts.*; import gplx.xowa.files.repos.*;
|
||||
import gplx.xowa.tdbs.hives.*;
|
||||
public class Xop_fxt {
|
||||
public Xop_fxt() {
|
||||
Xoae_app app = Xoa_app_fxt.app_();
|
||||
wiki = Xoa_app_fxt.wiki_tst_(app);
|
||||
ctor(app, wiki);
|
||||
}
|
||||
public Xop_fxt(Xoae_app app, Xowe_wiki wiki) {
|
||||
this.ctor(app, wiki);
|
||||
}
|
||||
private void ctor(Xoae_app app, Xowe_wiki wiki) {
|
||||
this.app = app;
|
||||
this.wiki = wiki;
|
||||
app.Wiki_mgr().Add(wiki);
|
||||
app.File_mgr().Repo_mgr().Set("src:wiki", "mem/wiki/repo/src/", wiki.Domain_str()).Ext_rules_(Xof_rule_grp.Grp_app_default).Dir_depth_(2);
|
||||
app.File_mgr().Repo_mgr().Set("trg:wiki", "mem/wiki/repo/trg/", wiki.Domain_str()).Ext_rules_(Xof_rule_grp.Grp_app_default).Dir_depth_(2).Primary_(true);
|
||||
wiki.File_mgr().Repo_mgr().Add_repo(Bry_.new_a7("src:wiki"), Bry_.new_a7("trg:wiki"));
|
||||
ctx = wiki.Ctx();
|
||||
mock_wkr.Clear_commons(); // assume all files are in repo 0
|
||||
wiki.File_mgr().Repo_mgr().Page_finder_(mock_wkr);
|
||||
parser = wiki.Parser();
|
||||
tkn_mkr = app.Tkn_mkr();
|
||||
ctx.Para().Enabled_n_();
|
||||
hdom_wtr = wiki.Html_mgr().Html_wtr();
|
||||
wiki.Html_mgr().Img_suppress_missing_src_(false);
|
||||
wiki.Xtn_mgr().Init_by_wiki(wiki);
|
||||
Page_ttl_(Ttl_str);
|
||||
Xot_invk_tkn.Cache_enabled = false;// always disable cache for tests; can cause strange behavior when running entire suite and lnki_temp test turns on;
|
||||
}
|
||||
private Xofw_wiki_wkr_mock mock_wkr = new Xofw_wiki_wkr_mock();
|
||||
public Xoae_app App() {return app;} private Xoae_app app;
|
||||
public Xowe_wiki Wiki() {return wiki;} private Xowe_wiki wiki;
|
||||
public Xop_ctx Ctx() {return ctx;} private Xop_ctx ctx;
|
||||
public Xop_parser Parser() {return parser;} private Xop_parser parser;
|
||||
public Xoae_page Page() {return ctx.Cur_page();}
|
||||
public void Lang_by_id_(int id) {ctx.Cur_page().Lang_(wiki.Appe().Lang_mgr().Get_by_key_or_new(Xol_lang_itm_.Get_by_id(id).Key()));}
|
||||
public Xoh_html_wtr_cfg Wtr_cfg() {return hdom_wtr.Cfg();} private Xoh_html_wtr hdom_wtr;
|
||||
public Xop_fxt Reset() {
|
||||
ctx.Clear();
|
||||
ctx.App().Free_mem(false);
|
||||
ctx.Cur_page().Clear();
|
||||
wiki.Db_mgr().Load_mgr().Clear();
|
||||
app.Wiki_mgr().Clear();
|
||||
Io_mgr.I.InitEngine_mem(); // clear created pages
|
||||
wiki.Cfg_parser().Display_title_restrict_(false); // default to false, as a small number of tests assume restrict = false;
|
||||
return this;
|
||||
}
|
||||
public Xop_fxt Reset_for_msgs() {
|
||||
Io_mgr.I.InitEngine_mem();
|
||||
wiki.Lang().Msg_mgr().Clear(); // need to clear out lang
|
||||
wiki.Msg_mgr().Clear(); // need to clear out wiki.Msgs
|
||||
this.Reset();
|
||||
return this;
|
||||
}
|
||||
public Xoa_ttl Page_ttl_(String txt) {
|
||||
Xoa_ttl rv = Xoa_ttl.parse(wiki, Bry_.new_u8(txt));
|
||||
ctx.Cur_page().Ttl_(rv);
|
||||
return rv;
|
||||
}
|
||||
|
||||
public Xop_tkn_chkr_base tkn_bry_(int bgn, int end) {return new Xop_tkn_chkr_base().TypeId_dynamic(Xop_tkn_itm_.Tid_bry).Src_rng_(bgn, end);}
|
||||
public Xop_tkn_chkr_base tkn_txt_() {return tkn_txt_(String_.Pos_neg1, String_.Pos_neg1);}
|
||||
public Xop_tkn_chkr_base tkn_txt_(int bgn, int end) {return new Xop_tkn_chkr_base().TypeId_dynamic(Xop_tkn_itm_.Tid_txt).Src_rng_(bgn, end);}
|
||||
public Xop_tkn_chkr_base tkn_space_() {return tkn_space_(String_.Pos_neg1, String_.Pos_neg1);}
|
||||
public Xop_tkn_chkr_base tkn_space_(int bgn, int end) {return new Xop_tkn_chkr_base().TypeId_dynamic(Xop_tkn_itm_.Tid_space).Src_rng_(bgn, end);}
|
||||
public Xop_tkn_chkr_base tkn_eq_(int bgn) {return tkn_eq_(bgn, bgn + 1);}
|
||||
public Xop_tkn_chkr_base tkn_eq_(int bgn, int end) {return new Xop_tkn_chkr_base().TypeId_dynamic(Xop_tkn_itm_.Tid_eq).Src_rng_(bgn, end);}
|
||||
public Xop_tkn_chkr_base tkn_colon_(int bgn) {return new Xop_tkn_chkr_base().TypeId_dynamic(Xop_tkn_itm_.Tid_colon).Src_rng_(bgn, bgn + 1);}
|
||||
public Xop_tkn_chkr_base tkn_pipe_(int bgn) {return new Xop_tkn_chkr_base().TypeId_dynamic(Xop_tkn_itm_.Tid_pipe).Src_rng_(bgn, bgn + 1);}
|
||||
public Xop_tkn_chkr_base tkn_tab_(int bgn) {return new Xop_tkn_chkr_base().TypeId_dynamic(Xop_tkn_itm_.Tid_tab).Src_rng_(bgn, bgn + 1);}
|
||||
public Xop_apos_tkn_chkr tkn_apos_(int cmd) {return new Xop_apos_tkn_chkr().Apos_cmd_(cmd);}
|
||||
public Xop_tkn_chkr_base tkn_html_ref_(String v) {return new Xop_html_txt_tkn_chkr().Html_ref_key_(v);}
|
||||
public Xop_tkn_chkr_base tkn_html_ncr_(int v) {return new Xop_html_num_tkn_chkr().Html_ncr_val_(v);}
|
||||
public Xop_ignore_tkn_chkr tkn_comment_(int bgn, int end) {return tkn_ignore_(bgn, end, Xop_ignore_tkn.Ignore_tid_comment);}
|
||||
public Xop_ignore_tkn_chkr tkn_ignore_(int bgn, int end, byte t){return (Xop_ignore_tkn_chkr)new Xop_ignore_tkn_chkr().Ignore_tid_(t).Src_rng_(bgn, end);}
|
||||
public Xop_tkn_chkr_hr tkn_hr_(int bgn, int end) {return new Xop_tkn_chkr_hr(bgn, end).Hr_len_(Xop_hr_lxr.Hr_len);}
|
||||
public Xop_tblw_tb_tkn_chkr tkn_tblw_tb_(int bgn, int end) {return (Xop_tblw_tb_tkn_chkr)new Xop_tblw_tb_tkn_chkr().Src_rng_(bgn, end);}
|
||||
public Xop_tblw_tc_tkn_chkr tkn_tblw_tc_(int bgn, int end) {return (Xop_tblw_tc_tkn_chkr)new Xop_tblw_tc_tkn_chkr().Src_rng_(bgn, end);}
|
||||
public Xop_tblw_td_tkn_chkr tkn_tblw_td_(int bgn, int end) {return (Xop_tblw_td_tkn_chkr)new Xop_tblw_td_tkn_chkr().Src_rng_(bgn, end);}
|
||||
public Xop_tblw_th_tkn_chkr tkn_tblw_th_(int bgn, int end) {return (Xop_tblw_th_tkn_chkr)new Xop_tblw_th_tkn_chkr().Src_rng_(bgn, end);}
|
||||
public Xop_tblw_tr_tkn_chkr tkn_tblw_tr_(int bgn, int end) {return (Xop_tblw_tr_tkn_chkr)new Xop_tblw_tr_tkn_chkr().Src_rng_(bgn, end);}
|
||||
public Xop_hdr_tkn_chkr tkn_hdr_(int bgn, int end, int hdr_len) {return (Xop_hdr_tkn_chkr)new Xop_hdr_tkn_chkr().Hdr_len_(hdr_len).Src_rng_(bgn, end);}
|
||||
public Xop_xnde_tkn_chkr tkn_xnde_br_(int pos) {return tkn_xnde_(pos, pos).Xnde_tagId_(Xop_xnde_tag_.Tid_br);}
|
||||
public Xop_xnde_tkn_chkr tkn_xnde_() {return tkn_xnde_(String_.Pos_neg1, String_.Pos_neg1);}
|
||||
public Xop_xnde_tkn_chkr tkn_xnde_(int bgn, int end) {return (Xop_xnde_tkn_chkr)new Xop_xnde_tkn_chkr().Src_rng_(bgn, end);}
|
||||
public Xop_tkn_chkr_base tkn_curly_bgn_(int bgn) {return new Xop_tkn_chkr_base().TypeId_dynamic(Xop_tkn_itm_.Tid_tmpl_curly_bgn).Src_rng_(bgn, bgn + 2);}
|
||||
public Xop_tkn_chkr_base tkn_para_blank_(int pos) {return tkn_para_(pos, Xop_para_tkn.Tid_none, Xop_para_tkn.Tid_none);}
|
||||
public Xop_tkn_chkr_base tkn_para_bgn_pre_(int pos) {return tkn_para_(pos, Xop_para_tkn.Tid_none, Xop_para_tkn.Tid_pre);}
|
||||
public Xop_tkn_chkr_base tkn_para_bgn_para_(int pos) {return tkn_para_(pos, Xop_para_tkn.Tid_none, Xop_para_tkn.Tid_para);}
|
||||
public Xop_tkn_chkr_base tkn_para_mid_para_(int pos) {return tkn_para_(pos, Xop_para_tkn.Tid_para, Xop_para_tkn.Tid_para);}
|
||||
public Xop_tkn_chkr_base tkn_para_end_para_(int pos) {return tkn_para_(pos, Xop_para_tkn.Tid_para, Xop_para_tkn.Tid_none);}
|
||||
public Xop_tkn_chkr_base tkn_para_end_pre_bgn_para_(int pos) {return tkn_para_(pos, Xop_para_tkn.Tid_pre , Xop_para_tkn.Tid_para);}
|
||||
public Xop_tkn_chkr_base tkn_para_end_para_bgn_pre_(int pos) {return tkn_para_(pos, Xop_para_tkn.Tid_para, Xop_para_tkn.Tid_pre);}
|
||||
public Xop_tkn_chkr_base tkn_para_end_pre_(int pos) {return tkn_para_(pos, Xop_para_tkn.Tid_pre , Xop_para_tkn.Tid_none);}
|
||||
public Xop_tkn_chkr_base tkn_para_(int pos, byte end, byte bgn) {return new Xop_para_tkn_chkr().Para_end_(end).Para_bgn_(bgn).Src_rng_(pos, pos);}
|
||||
public Xop_tkn_chkr_base tkn_nl_char_(int bgn, int end) {return tkn_nl_(bgn, end, Xop_nl_tkn.Tid_char);}
|
||||
public Xop_tkn_chkr_base tkn_nl_char_len1_(int bgn) {return tkn_nl_(bgn, bgn + 1, Xop_nl_tkn.Tid_char);}
|
||||
public Xop_tkn_chkr_base tkn_nl_char_len0_(int pos) {return tkn_nl_(pos, pos, Xop_nl_tkn.Tid_char);}
|
||||
public Xop_tkn_chkr_base tkn_nl_(int bgn, int end, byte tid) {return new Xop_nl_tkn_chkr().Nl_tid_(tid).Src_rng_(bgn, end);}
|
||||
public Xop_list_tkn_chkr tkn_list_bgn_(int bgn, int end, byte listType) {return (Xop_list_tkn_chkr)new Xop_list_tkn_chkr().List_itmTyp_(listType).Src_rng_(bgn, end);}
|
||||
public Xop_list_tkn_chkr tkn_list_end_(int pos) {return (Xop_list_tkn_chkr)new Xop_list_tkn_chkr().Src_rng_(pos, pos);}
|
||||
public Xop_tkn_chkr_lnke tkn_lnke_(int bgn, int end) {return new Xop_tkn_chkr_lnke(bgn, end);}
|
||||
public Xop_lnki_tkn_chkr tkn_lnki_() {return tkn_lnki_(-1, -1);}
|
||||
public Xop_lnki_tkn_chkr tkn_lnki_(int bgn, int end) {return (Xop_lnki_tkn_chkr)new Xop_lnki_tkn_chkr().Src_rng_(bgn, end);}
|
||||
public Xop_arg_itm_tkn_chkr tkn_arg_itm_(Xop_tkn_chkr_base... subs) {return (Xop_arg_itm_tkn_chkr)new Xop_arg_itm_tkn_chkr().Subs_(subs);}
|
||||
public Xop_arg_nde_tkn_chkr tkn_arg_nde_() {return tkn_arg_nde_(String_.Pos_neg1, String_.Pos_neg1);}
|
||||
public Xop_arg_nde_tkn_chkr tkn_arg_nde_(int bgn, int end) {return (Xop_arg_nde_tkn_chkr)new Xop_arg_nde_tkn_chkr().Src_rng_(bgn, end);}
|
||||
public Xop_arg_nde_tkn_chkr tkn_arg_val_(Xop_tkn_chkr_base... subs) {
|
||||
Xop_arg_nde_tkn_chkr rv = new Xop_arg_nde_tkn_chkr();
|
||||
Xop_arg_itm_tkn_chkr val = new Xop_arg_itm_tkn_chkr();
|
||||
val.Subs_(subs);
|
||||
rv.Val_tkn_(val);
|
||||
return rv;
|
||||
}
|
||||
public Xop_arg_nde_tkn_chkr tkn_arg_val_txt_(int bgn, int end) {
|
||||
Xop_arg_nde_tkn_chkr rv = new Xop_arg_nde_tkn_chkr();
|
||||
Xop_arg_itm_tkn_chkr itm = new Xop_arg_itm_tkn_chkr();
|
||||
rv.Val_tkn_(itm);
|
||||
itm.Src_rng_(bgn, end).Subs_(tkn_txt_(bgn, end));
|
||||
return rv;
|
||||
}
|
||||
Xop_arg_nde_tkn_chkr tkn_arg_key_txt_(int bgn, int end) {
|
||||
Xop_arg_nde_tkn_chkr rv = new Xop_arg_nde_tkn_chkr();
|
||||
Xop_arg_itm_tkn_chkr itm = new Xop_arg_itm_tkn_chkr();
|
||||
rv.Key_tkn_(itm);
|
||||
itm.Src_rng_(bgn, end).Subs_(tkn_txt_(bgn, end));
|
||||
return rv;
|
||||
}
|
||||
public Xot_invk_tkn_chkr tkn_tmpl_invk_(int bgn, int end) {return (Xot_invk_tkn_chkr)new Xot_invk_tkn_chkr().Src_rng_(bgn, end);}
|
||||
public Xot_invk_tkn_chkr tkn_tmpl_invk_w_name(int bgn, int end, int name_bgn, int name_end) {
|
||||
Xot_invk_tkn_chkr rv = new Xot_invk_tkn_chkr();
|
||||
rv.Src_rng_(bgn, end);
|
||||
rv.Name_tkn_(tkn_arg_key_txt_(name_bgn, name_end));
|
||||
return rv;
|
||||
}
|
||||
public Xot_prm_chkr tkn_tmpl_prm_find_(Xop_tkn_chkr_base find) {
|
||||
Xot_prm_chkr rv = new Xot_prm_chkr();
|
||||
rv.Find_tkn_(tkn_arg_itm_(find));
|
||||
return rv;
|
||||
}
|
||||
public Xop_fxt Init_para_y_() {ctx.Para().Enabled_y_(); return this;}
|
||||
public Xop_fxt Init_para_n_() {ctx.Para().Enabled_n_(); return this;}
|
||||
public Xop_fxt Init_log_(Gfo_msg_itm... itms) {for (Gfo_msg_itm itm : itms) log_itms.Add(itm); return this;} List_adp log_itms = List_adp_.new_();
|
||||
public void Init_defn_add(String name, String text) {Init_defn_add(name, text, Xow_ns_case_.Id_all);}
|
||||
public void Init_defn_add(String name, String text, byte case_match) {
|
||||
Xot_defn_tmpl itm = run_Parse_tmpl(Bry_.new_a7(name), Bry_.new_u8(text));
|
||||
wiki.Cache_mgr().Defn_cache().Add(itm, case_match);
|
||||
}
|
||||
public void Init_defn_clear() {wiki.Cache_mgr().Defn_cache().Free_mem_all();}
|
||||
public Xop_fxt Init_id_create(int id, int fil_idx, int row_idx, boolean type_redirect, int itm_len, int ns_id, String ttl) {Xow_hive_mgr_fxt.Create_id(app, wiki.Hive_mgr(), id, fil_idx, row_idx, type_redirect, itm_len, ns_id, ttl); return this;}
|
||||
public Xop_fxt Init_ctg_create(String ctg, int... pages) {Xow_hive_mgr_fxt.Create_ctg(app, wiki.Hive_mgr(), ctg, pages); return this;}
|
||||
public Xop_fxt Init_page_create(String ttl) {return Init_page_create(wiki, ttl, "");}
|
||||
public Xop_fxt Init_page_create(String ttl, String txt) {return Init_page_create(wiki, ttl, txt);}
|
||||
public Xop_fxt Init_page_create(Xowe_wiki wiki, String ttl, String txt) {Init_page_create_static(wiki, ttl, txt);return this;}
|
||||
public static void Init_page_create_static(Xowe_wiki wiki, String ttl_str, String text_str) {
|
||||
Xoa_ttl ttl = Xoa_ttl.parse(wiki, Bry_.new_u8(ttl_str));
|
||||
byte[] text = Bry_.new_u8(text_str);
|
||||
wiki.Db_mgr().Save_mgr().Data_create(ttl, text);
|
||||
}
|
||||
public static void Init_msg(Xowe_wiki wiki, String key, String val) {
|
||||
wiki.Lang().Msg_mgr().Itm_by_key_or_new(key, val);
|
||||
}
|
||||
public Xop_fxt Init_page_update(String ttl, String txt) {return Init_page_update(wiki, ttl, txt);}
|
||||
public Xop_fxt Init_page_update(Xowe_wiki wiki, String ttl, String txt) {
|
||||
Xoa_ttl page_ttl = Xoa_ttl.parse(wiki, Bry_.new_u8(ttl));
|
||||
byte[] page_raw = Bry_.new_u8(txt);
|
||||
Xoae_page page = wiki.Data_mgr().Get_page(page_ttl, false);
|
||||
wiki.Db_mgr().Save_mgr().Data_update(page, page_raw);
|
||||
return this;
|
||||
}
|
||||
public Xop_fxt Init_xwiki_clear() {
|
||||
wiki.Xwiki_mgr().Clear();
|
||||
app.Usere().Wiki().Xwiki_mgr().Clear();
|
||||
return this;
|
||||
}
|
||||
public Xop_fxt Init_xwiki_add_wiki_and_user_(String alias, String domain) {
|
||||
wiki.Xwiki_mgr().Add_full(alias, domain);
|
||||
app.Usere().Wiki().Xwiki_mgr().Add_full(domain, domain);
|
||||
return this;
|
||||
}
|
||||
public Xop_fxt Init_xwiki_add_user_(String domain) {return Init_xwiki_add_user_(domain, domain);}
|
||||
public Xop_fxt Init_xwiki_add_user_(String alias, String domain) {
|
||||
app.Usere().Wiki().Xwiki_mgr().Add_full(alias, domain);
|
||||
return this;
|
||||
}
|
||||
public void Test_parse_template(String tmpl_raw, String expd) {Test_parse_tmpl_str_test(tmpl_raw, "{{test}}", expd);}
|
||||
public void Test_parse_tmpl_str_test(String tmpl_raw, String page_raw, String expd) {
|
||||
Init_defn_add("test", tmpl_raw);
|
||||
Test_parse_tmpl_str(page_raw, expd);
|
||||
}
|
||||
public void Test_parse_tmpl_str(String raw, String expd) {
|
||||
byte[] actl = Test_parse_tmpl_str_rv(raw);
|
||||
Tfds.Eq_str_lines(expd, String_.new_u8(actl));
|
||||
tst_Log_check();
|
||||
}
|
||||
public byte[] Test_parse_tmpl_str_rv(String raw) {
|
||||
byte[] raw_bry = Bry_.new_u8(raw);
|
||||
Xop_root_tkn root = tkn_mkr.Root(raw_bry);
|
||||
return parser.Parse_text_to_wtxt(root, ctx, tkn_mkr, raw_bry);
|
||||
}
|
||||
public Xot_defn_tmpl run_Parse_tmpl(byte[] name, byte[] raw) {return parser.Parse_text_to_defn_obj(ctx, ctx.Tkn_mkr(), wiki.Ns_mgr().Ns_template(), name, raw);}
|
||||
public void Test_parse_tmpl(String raw, Tst_chkr... expd) {
|
||||
byte[] raw_bry = Bry_.new_u8(raw);
|
||||
Xot_defn_tmpl itm = run_Parse_tmpl(Bry_.Empty, raw_bry);
|
||||
Parse_chk(raw_bry, itm.Root(), expd);
|
||||
}
|
||||
public void Test_parse_page_tmpl_str(String raw, String expd) {
|
||||
byte[] raw_bry = Bry_.new_u8(raw);
|
||||
Xop_root_tkn root = tkn_mkr.Root(raw_bry);
|
||||
byte[] actl = parser.Parse_text_to_wtxt(root, ctx, tkn_mkr, raw_bry);
|
||||
Tfds.Eq(expd, String_.new_u8(actl));
|
||||
tst_Log_check();
|
||||
}
|
||||
public Xop_root_tkn Test_parse_page_tmpl_tkn(String raw) {
|
||||
byte[] raw_bry = Bry_.new_u8(raw);
|
||||
Xop_root_tkn root = tkn_mkr.Root(raw_bry);
|
||||
parser.Parse_text_to_wtxt(root, ctx, tkn_mkr, raw_bry);
|
||||
return root;
|
||||
}
|
||||
public void Test_parse_page_tmpl(String raw, Tst_chkr... expd_ary) {
|
||||
byte[] raw_bry = Bry_.new_u8(raw);
|
||||
Xop_root_tkn root = tkn_mkr.Root(raw_bry);
|
||||
parser.Parse_text_to_wtxt(root, ctx, tkn_mkr, raw_bry);
|
||||
Parse_chk(raw_bry, root, expd_ary);
|
||||
}
|
||||
public void Test_parse_page_wiki(String raw, Tst_chkr... expd_ary) {
|
||||
byte[] raw_bry = Bry_.new_u8(raw);
|
||||
Xop_root_tkn root = Test_parse_page_wiki_root(raw_bry);
|
||||
Parse_chk(raw_bry, root, expd_ary);
|
||||
}
|
||||
public Xop_root_tkn Test_parse_page_wiki_root(String raw) {return Test_parse_page_wiki_root(Bry_.new_u8(raw));}
|
||||
Xop_root_tkn Test_parse_page_wiki_root(byte[] raw_bry) {
|
||||
Xop_root_tkn root = tkn_mkr.Root(raw_bry);
|
||||
parser.Parse_wtxt_to_wdom(root, ctx, tkn_mkr, raw_bry, Xop_parser_.Doc_bgn_bos);
|
||||
return root;
|
||||
}
|
||||
public void Test_parse_page_all(String raw, Tst_chkr... expd_ary) {
|
||||
byte[] raw_bry = Bry_.new_u8(raw);
|
||||
Xop_root_tkn root = Exec_parse_page_all_as_root(Bry_.new_u8(raw));
|
||||
Parse_chk(raw_bry, root, expd_ary);
|
||||
}
|
||||
public void Data_create(String ttl_str, String text_str) {Init_page_create(wiki, ttl_str, text_str);}
|
||||
public void Test_parse_page_all_str(String raw, String expd) {
|
||||
String actl = Exec_parse_page_all_as_str(raw);
|
||||
Tfds.Eq_ary_str(String_.SplitLines_nl(expd), String_.SplitLines_nl(actl), raw);
|
||||
}
|
||||
public void Test_parse_page_all_str_and_chk(String raw, String expd, Gfo_msg_itm... ary) {
|
||||
this.Init_log_(ary);
|
||||
Test_parse_page_all_str(raw, expd);
|
||||
this.tst_Log_check();
|
||||
}
|
||||
public Xop_root_tkn Exec_parse_page_all_as_root(byte[] raw_bry) {
|
||||
Xop_root_tkn root = tkn_mkr.Root(raw_bry);
|
||||
parser.Parse_page_all_clear(root, ctx, tkn_mkr, raw_bry);
|
||||
return root;
|
||||
}
|
||||
public String Exec_parse_page_all_as_str(String raw) {
|
||||
Xop_root_tkn root = Exec_parse_page_all_as_root(Bry_.new_u8(raw));
|
||||
Bry_bfr actl_bfr = Bry_bfr.new_();
|
||||
hdom_wtr.Write_all(actl_bfr, ctx, root.Root_src(), root);
|
||||
return actl_bfr.Xto_str_and_clear();
|
||||
}
|
||||
public String Exec_parse_page_wiki_as_str(String raw) {
|
||||
byte[] raw_bry = Bry_.new_u8(raw);
|
||||
Xop_root_tkn root = tkn_mkr.Root(raw_bry);
|
||||
parser.Parse_wtxt_to_wdom(root, ctx, tkn_mkr, raw_bry, Xop_parser_.Doc_bgn_bos);
|
||||
Bry_bfr actl_bfr = Bry_bfr.new_();
|
||||
hdom_wtr.Write_all(actl_bfr, ctx, raw_bry, root);
|
||||
return actl_bfr.Xto_str_and_clear();
|
||||
}
|
||||
private void Parse_chk(byte[] raw_bry, Xop_root_tkn root, Tst_chkr[] expd_ary) {
|
||||
int subs_len = root.Subs_len();
|
||||
Object[] actl_ary = new Object[subs_len];
|
||||
for (int i = 0; i < subs_len; i++)
|
||||
actl_ary[i] = root.Subs_get(i);
|
||||
tst_mgr.Vars().Clear().Add("raw_bry", raw_bry);
|
||||
tst_mgr.Tst_ary("tkns:", expd_ary, actl_ary);
|
||||
tst_Log_check();
|
||||
}
|
||||
public Xop_fxt Test_parse_page_wiki_str(String raw, String expd) {
|
||||
Tfds.Eq_str_lines(expd, Exec_parse_page_wiki_as_str(raw), raw);
|
||||
return this;
|
||||
}
|
||||
public void Log_clear() {ctx.App().Msg_log().Clear();}
|
||||
public String[] Log_xtoAry() {
|
||||
Gfo_msg_log msg_log = app.Msg_log();
|
||||
int len = msg_log.Ary_len();
|
||||
List_adp actl_list = List_adp_.new_();
|
||||
for (int i = 0; i < len; i++) {
|
||||
Gfo_msg_data eny = msg_log.Ary_get(i);
|
||||
if (eny.Item().Cmd() > Gfo_msg_itm_.Cmd_note) {
|
||||
actl_list.Add(String_.new_u8(eny.Item().Path_bry()));
|
||||
}
|
||||
}
|
||||
String[] actl = actl_list.To_str_ary();
|
||||
msg_log.Clear();
|
||||
return actl;
|
||||
}
|
||||
public Xop_fxt tst_Log_check() {
|
||||
int len = log_itms.Count();
|
||||
String[] expd = new String[len];
|
||||
for (int i = 0; i < len; i++) {
|
||||
Gfo_msg_itm itm = (Gfo_msg_itm)log_itms.Get_at(i);
|
||||
expd[i] = itm.Path_str();
|
||||
}
|
||||
log_itms.Clear();
|
||||
String[] actl = Log_xtoAry();
|
||||
Tfds.Eq_ary_str(expd, actl);
|
||||
return this;
|
||||
}
|
||||
public void tst_Warn(String... expd) {
|
||||
Gfo_usr_dlg usr_dlg = app.Usr_dlg();
|
||||
Gfo_usr_dlg__gui_test ui_wkr = (Gfo_usr_dlg__gui_test)usr_dlg.Gui_wkr();
|
||||
String[] actl = ui_wkr.Warns().To_str_ary();
|
||||
Tfds.Eq_ary_str(expd, actl);
|
||||
}
|
||||
public void Test_parse_page(String ttl, String expd) {
|
||||
byte[] actl = Load_page(wiki, ttl);
|
||||
Tfds.Eq(expd, String_.new_u8(actl));
|
||||
}
|
||||
public static byte[] Load_page(Xowe_wiki wiki, String ttl_str) {
|
||||
byte[] ttl_bry = Bry_.new_u8(ttl_str);
|
||||
Xoa_url page_url = Xoa_url.new_(wiki.Domain_bry(), ttl_bry);
|
||||
Xoa_ttl ttl = Xoa_ttl.parse(wiki, ttl_bry);
|
||||
return wiki.Load_page_by_ttl(page_url, ttl).Data_raw();
|
||||
}
|
||||
public static void Reg_xwiki_alias(Xowe_wiki wiki, String alias, String domain) {
|
||||
byte[] domain_bry = Bry_.new_a7(domain);
|
||||
wiki.Xwiki_mgr().Add_full(Bry_.new_a7(alias), domain_bry, Bry_.Add(domain_bry, Bry_.new_a7("/wiki/~{0}")));
|
||||
wiki.Appe().Usere().Wiki().Xwiki_mgr().Add_full(domain_bry, domain_bry);
|
||||
}
|
||||
public static String html_img_none(String trg, String alt, String src, String ttl) {
|
||||
return String_.Format(String_.Concat_lines_nl_skip_last("<a href=\"/wiki/{0}\" class=\"image\" xowa_title=\"{3}\"><img id=\"xowa_file_img_0\" alt=\"{1}\" src=\"{2}\" width=\"9\" height=\"8\" /></a>"), trg, alt, src, ttl);
|
||||
}
|
||||
private String Exec_html_full(String raw) {return this.Exec_parse_page_all_as_str(raw);}
|
||||
private String Exec_html_wiki(String raw) {return this.Exec_parse_page_wiki_as_str(raw);}
|
||||
public void Test_html_wiki_str(String raw, String expd) {Test_str_full(raw, expd, Exec_html_wiki(raw));}
|
||||
public void Test_html_full_str(String raw, String expd) {Test_str_full(raw, expd, Exec_html_full(raw));}
|
||||
public void Test_html_wiki_frag(String raw, String... expd_frags) {Test_str_part_y(Exec_html_wiki(raw), expd_frags);}
|
||||
public void Test_html_full_frag(String raw, String... expd_frags) {Test_str_part_y(Exec_html_full(raw), expd_frags);}
|
||||
public void Test_html_full_frag_n(String raw, String... expd_frags) {Test_str_part_n(Exec_html_full(raw), expd_frags);}
|
||||
|
||||
public void Test_str_full(String raw, String expd, String actl) {Tfds.Eq_str_lines(expd, actl, raw);}
|
||||
private void Test_str_part_y(String actl, String... expd_parts) {
|
||||
int expd_parts_len = expd_parts.length;
|
||||
for (int i = 0; i < expd_parts_len; i++) {
|
||||
String expd_part = expd_parts[i];
|
||||
boolean pass = String_.Has(actl, expd_part);
|
||||
if (!pass)
|
||||
Tfds.Eq_true(false, expd_part + "\n" + actl);
|
||||
}
|
||||
}
|
||||
private void Test_str_part_n(String actl, String... expd_parts) {
|
||||
int expd_parts_len = expd_parts.length;
|
||||
for (int i = 0; i < expd_parts_len; i++) {
|
||||
String expd_part = expd_parts[i];
|
||||
boolean has = String_.Has(actl, expd_part);
|
||||
if (has)
|
||||
Tfds.Eq_true(false, expd_part + "\n" + actl);
|
||||
}
|
||||
}
|
||||
public void Test_html_modules_js(String expd) {
|
||||
Bry_bfr bfr = app.Utl__bfr_mkr().Get_k004();
|
||||
this.Page().Html_data().Head_mgr().Init(app, wiki, this.Page());
|
||||
this.Page().Html_data().Head_mgr().XferAry(bfr, 0);
|
||||
bfr.Mkr_rls();
|
||||
Tfds.Eq_str_lines(expd, bfr.Xto_str_and_clear());
|
||||
}
|
||||
|
||||
private Tst_mgr tst_mgr = new Tst_mgr(); private Xop_tkn_mkr tkn_mkr;
|
||||
public static final String Ttl_str = "Test page";
|
||||
public Xop_fxt Init_lang_numbers_separators_en() {return Init_lang_numbers_separators(",", ".");}
|
||||
public Xop_fxt Init_lang_numbers_separators(String grp_spr, String dec_spr) {return Init_lang_numbers_separators(wiki.Lang(), grp_spr, dec_spr);}
|
||||
public Xop_fxt Init_lang_numbers_separators(Xol_lang lang, String grp_spr, String dec_spr) {
|
||||
gplx.xowa.langs.numbers.Xol_transform_mgr separator_mgr = lang.Num_mgr().Separators_mgr();
|
||||
separator_mgr.Clear();
|
||||
separator_mgr.Set(gplx.xowa.langs.numbers.Xol_num_mgr.Separators_key__grp, Bry_.new_u8(grp_spr));
|
||||
separator_mgr.Set(gplx.xowa.langs.numbers.Xol_num_mgr.Separators_key__dec, Bry_.new_u8(dec_spr));
|
||||
return this;
|
||||
}
|
||||
public void Init_lang_kwds(int kwd_id, boolean case_match, String... kwds) {Init_lang_kwds(wiki.Lang(), kwd_id, case_match, kwds);}
|
||||
public void Init_lang_kwds(Xol_lang lang, int kwd_id, boolean case_match, String... kwds) {
|
||||
Xol_kwd_mgr kwd_mgr = lang.Kwd_mgr();
|
||||
Xol_kwd_grp kwd_grp = kwd_mgr.Get_or_new(kwd_id);
|
||||
kwd_grp.Srl_load(case_match, Bry_.Ary(kwds));
|
||||
}
|
||||
public void Init_xtn_pages() {
|
||||
Io_mgr.I.InitEngine_mem();
|
||||
wiki.Xtn_mgr().Xtn_proofread().Enabled_y_();
|
||||
wiki.Db_mgr().Load_mgr().Clear(); // must clear; otherwise fails b/c files get deleted, but wiki.data_mgr caches the Xowd_regy_mgr (the .reg file) in memory;
|
||||
wiki.Ns_mgr().Add_new(Xowc_xtn_pages.Ns_page_id_default, "Page").Add_new(Xowc_xtn_pages.Ns_index_id_default, "Index").Init();
|
||||
}
|
||||
public void Clear_ref_mgr() {this.Page().Ref_mgr().Grps_clear();} // clear to reset count
|
||||
public static Xop_fxt new_nonwmf() {
|
||||
Xoae_app app = Xoa_app_fxt.app_();
|
||||
return new Xop_fxt(app, Xoa_app_fxt.wiki_nonwmf(app, "nethackwiki"));
|
||||
}
|
||||
}
|
||||
@@ -15,12 +15,11 @@ 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.math.parsers; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.math.*;
|
||||
class Mwm_lxr__leaf implements Mwm_lxr {
|
||||
public Mwm_lxr__leaf(int tkn_tid) {this.tkn_tid = tkn_tid;} private final int tkn_tid;
|
||||
public int Tid() {return Mwm_lxr_.Tid__raw;}
|
||||
public int Make_tkn(Mwm_ctx ctx, Mwm_tkn__root root, byte[] src, int src_len, int bgn_pos, int cur_pos) {
|
||||
root.Regy__add(tkn_tid, bgn_pos, cur_pos, null);
|
||||
return cur_pos;
|
||||
package gplx.xowa.apps; import gplx.*; import gplx.xowa.*;
|
||||
public class Xoa_app_eval implements Bry_fmtr_eval_mgr {
|
||||
public boolean Enabled() {return enabled;} public void Enabled_(boolean v) {enabled = v;} private boolean enabled = true;
|
||||
public byte[] Eval(byte[] cmd) {
|
||||
Object rslt = GfsCore._.Exec_bry(cmd);
|
||||
return Bry_.new_u8(Object_.Xto_str_strict_or_null_mark(rslt));
|
||||
}
|
||||
}
|
||||
41
400_xowa/src/gplx/xowa/apps/Xoa_app_eval_tst.java
Normal file
41
400_xowa/src/gplx/xowa/apps/Xoa_app_eval_tst.java
Normal file
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
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.apps; import gplx.*; import gplx.xowa.*;
|
||||
import org.junit.*;
|
||||
import gplx.xowa.apps.*;
|
||||
public class Xoa_app_eval_tst {
|
||||
Xoa_app_eval_fxt fxt = new Xoa_app_eval_fxt();
|
||||
@Before public void init() {fxt.Clear();}
|
||||
@Test public void Basic() {
|
||||
fxt.Eval_test("[~{<>app.sys_cfg.version;<>}]", "[" + Xoa_app_.Version + "]");
|
||||
}
|
||||
}
|
||||
class Xoa_app_eval_fxt {
|
||||
public void Clear() {
|
||||
if (app == null) {
|
||||
app = Xoa_app_fxt.app_();
|
||||
fmtr = Bry_fmtr.new_();
|
||||
eval = new Xoa_app_eval();
|
||||
fmtr.Eval_mgr_(eval);
|
||||
Xoa_gfs_mgr.Msg_parser_init();
|
||||
}
|
||||
} private Xoae_app app; Bry_fmtr fmtr; Xoa_app_eval eval;
|
||||
public void Eval_test(String raw, String expd) {
|
||||
Tfds.Eq(fmtr.Fmt_(raw).Bld_str_many(), expd);
|
||||
}
|
||||
}
|
||||
31
400_xowa/src/gplx/xowa/apps/Xoa_cur.java
Normal file
31
400_xowa/src/gplx/xowa/apps/Xoa_cur.java
Normal file
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
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.apps; import gplx.*; import gplx.xowa.*;
|
||||
import gplx.xowa.gui.views.*;
|
||||
public class Xoa_cur implements GfoInvkAble {
|
||||
public Xoa_cur(Xoae_app app) {this.app = app;} private Xoae_app app;
|
||||
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
|
||||
if (ctx.Match(k, Invk_wiki)) {
|
||||
Xog_win_itm win = app.Gui_mgr().Browser_win();
|
||||
return win.Active_tab() == null ? GfoInvkAble_.Null : win.Active_page().Wikie(); // null check when called from mass html gen; DATE:2014-06-04
|
||||
}
|
||||
else if (ctx.Match(k, Invk_win)) return app.Gui_mgr().Browser_win();
|
||||
else if (ctx.Match(k, Invk_user)) return app.Usere();
|
||||
else return GfoInvkAble_.Rv_unhandled;
|
||||
} private static final String Invk_wiki = "wiki", Invk_win = "win", Invk_user = "user";
|
||||
}
|
||||
85
400_xowa/src/gplx/xowa/apps/Xoa_sys_cfg.java
Normal file
85
400_xowa/src/gplx/xowa/apps/Xoa_sys_cfg.java
Normal file
@@ -0,0 +1,85 @@
|
||||
/*
|
||||
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.apps; import gplx.*; import gplx.xowa.*;
|
||||
import gplx.xowa.langs.*;
|
||||
public class Xoa_sys_cfg implements GfoInvkAble {
|
||||
private Xoae_app app;
|
||||
public Xoa_sys_cfg(Xoae_app app) {this.app = app;}
|
||||
public byte[] Lang() {return lang_key;}
|
||||
public Xoa_sys_cfg Lang_(byte[] v) {
|
||||
lang_key = Xol_lang_itm_.Get_by_key_or_en(v).Key();
|
||||
if (app.Stage() == gplx.xowa.apps.Xoa_stage_.Tid_launch) { // do not update user lang unless launched; DATE:2014-05-26
|
||||
Xol_lang lang = app.Lang_mgr().Get_by_key_or_load(lang_key);
|
||||
app.Usere().Lang_(lang);
|
||||
app.Usere().Wiki().Html_mgr().Portal_mgr().Init();
|
||||
}
|
||||
return this;
|
||||
} private byte[] lang_key = Xol_lang_.Key_en;
|
||||
public int Options_version() {return options_version;} public Xoa_sys_cfg Options_version_(int v) {options_version = v; return this;} private int options_version = 1;
|
||||
public KeyVal[] Options_lang_list() {if (options_lang_list == null) options_lang_list = Options_list_lang_.new_(); return options_lang_list;} private KeyVal[] options_lang_list;
|
||||
public long Free_mem_when() {return free_mem_when;} long free_mem_when;
|
||||
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
|
||||
if (ctx.Match(k, Invk_version)) return Xoa_app_.Version;
|
||||
else if (ctx.Match(k, Invk_build_date)) return Xoa_app_.Build_date;
|
||||
else if (ctx.Match(k, Invk_free_mem_when_)) free_mem_when = gplx.ios.Io_size_.parse_or(m.ReadStr("v"), Io_mgr.Len_mb * 5);
|
||||
else if (ctx.Match(k, Invk_lang)) return lang_key;
|
||||
else if (ctx.Match(k, Invk_lang_)) Lang_(m.ReadBry("v"));
|
||||
else if (ctx.Match(k, Invk_lang_list)) return Options_lang_list();
|
||||
else if (ctx.Match(k, Invk_options_version)) return options_version;
|
||||
else if (ctx.Match(k, Invk_options_version_)) options_version = m.ReadInt("v");
|
||||
else return GfoInvkAble_.Rv_unhandled;
|
||||
return this;
|
||||
}
|
||||
private static final String Invk_version = "version", Invk_build_date = "build_date", Invk_free_mem_when_ = "free_mem_when_", Invk_options_version = "options_version", Invk_options_version_ = "options_version_"
|
||||
, Invk_lang = "lang", Invk_lang_ = "lang_", Invk_lang_list = "lang_list";
|
||||
}
|
||||
class Options_list_lang_ {
|
||||
public static KeyVal[] new_() {
|
||||
Ordered_hash translated = Ordered_hash_.new_bry_();
|
||||
List_adp untranslated = List_adp_.new_();
|
||||
Add_itm_many(translated, Xol_lang_itm_.Id_en, Xol_lang_itm_.Id_de, Xol_lang_itm_.Id_pl, Xol_lang_itm_.Id_zh_hans, Xol_lang_itm_.Id_zh_hant); // add langs with translations first, so they alphabetize to top of list
|
||||
int len = Xol_lang_itm_.Id__max;
|
||||
for (int i = 0; i < len; i++) { // add rest of langs, but sort by code
|
||||
Xol_lang_itm itm = Xol_lang_itm_.Get_by_id(i);
|
||||
if (translated.Has(itm.Key())) continue;
|
||||
untranslated.Add(itm);
|
||||
}
|
||||
untranslated.Sort_by(Xol_lang_itm_.Comparer_key);
|
||||
|
||||
KeyVal[] rv = new KeyVal[len];
|
||||
int translated_max = translated.Count();
|
||||
for (int i = 0; i < translated_max; i++)
|
||||
rv[i] = new_itm((Xol_lang_itm)translated.Get_at(i));
|
||||
|
||||
for (int i = translated_max; i < len; i++)
|
||||
rv[i] = new_itm((Xol_lang_itm)untranslated.Get_at(i - translated_max));
|
||||
return rv;
|
||||
}
|
||||
private static KeyVal new_itm(Xol_lang_itm itm) {
|
||||
String key_str = String_.new_u8(itm.Key());
|
||||
String name_str = String_.new_u8(itm.Localized_name());
|
||||
return KeyVal_.new_(key_str, name_str + " [" + key_str + "]");
|
||||
}
|
||||
private static void Add_itm_many(Ordered_hash translated, int... langs) {
|
||||
int langs_len = langs.length;
|
||||
for (int i = 0; i < langs_len; i++) {
|
||||
Xol_lang_itm itm = Xol_lang_itm_.Get_by_id(langs[i]);
|
||||
translated.Add_if_dupe_use_nth(itm.Key(), itm);
|
||||
}
|
||||
}
|
||||
}
|
||||
75
400_xowa/src/gplx/xowa/apps/langs/Xoac_lang_grp.java
Normal file
75
400_xowa/src/gplx/xowa/apps/langs/Xoac_lang_grp.java
Normal file
@@ -0,0 +1,75 @@
|
||||
/*
|
||||
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.apps.langs; import gplx.*; import gplx.xowa.*; import gplx.xowa.apps.*;
|
||||
interface Xoac_lang_obj {}
|
||||
public class Xoac_lang_grp implements Cfg_nde_obj, Xoac_lang_obj {
|
||||
public Xoac_lang_grp(byte[] key) {this.key_bry = key; this.name_bry = key_bry;}
|
||||
public byte[] Key_bry() {return key_bry;} private byte[] key_bry;
|
||||
public byte[] Name_bry() {return name_bry;} public Xoac_lang_grp Name_bry_(byte[] v) {name_bry = v; return this;} private byte[] name_bry;
|
||||
public int Sort_idx() {return sort_idx;} private int sort_idx;
|
||||
public byte[] Nde_key() {return key_bry;}
|
||||
public boolean Nde_typ_is_grp() {return true;}
|
||||
public Cfg_nde_obj Nde_subs_make(byte[] itm_type, byte[] itm_key, byte[][] itm_atrs) {
|
||||
Cfg_nde_obj rv = null;
|
||||
if (Bry_.Eq(itm_type, Make_grp)) rv = new Xoac_lang_grp(itm_key);
|
||||
else if (Bry_.Eq(itm_type, Make_itm)) rv = new Xoac_lang_itm(itm_key);
|
||||
else throw Err_.new_unhandled(itm_type);
|
||||
rv.Nde_atrs_set(itm_atrs);
|
||||
return rv;
|
||||
}
|
||||
public int Nde_subs_len() {return itms.Count();}
|
||||
public Cfg_nde_obj Nde_subs_get_at(int i) {return (Cfg_nde_obj)itms.Get_at(i);}
|
||||
public Cfg_nde_obj Nde_subs_get(byte[] key) {return (Cfg_nde_obj)itms.Get_by(key);}
|
||||
public void Nde_subs_add(byte[] itm_key, Cfg_nde_obj itm_obj) {
|
||||
if (!itm_obj.Nde_typ_is_grp()) {
|
||||
Xoac_lang_itm itm = (Xoac_lang_itm)itm_obj;
|
||||
if (!regy.Has(itm.Key_bry())) regy.Add(itm.Key_bry(), itm);
|
||||
itm.Grp_(this);
|
||||
}
|
||||
itms.Add(itm_key, itm_obj);
|
||||
}
|
||||
public void Nde_subs_del(byte[] key) {
|
||||
Cfg_nde_obj cur_obj = (Cfg_nde_obj)Nde_subs_get(key);
|
||||
if (!cur_obj.Nde_typ_is_grp()) {
|
||||
Xoac_lang_itm cur_itm = (Xoac_lang_itm)cur_obj;
|
||||
Xoac_lang_itm reg_itm = (Xoac_lang_itm)regy.Get_by(key);
|
||||
if (cur_itm.Uid() == reg_itm.Uid()) regy.Del(cur_itm.Key_bry());
|
||||
}
|
||||
itms.Del(key);
|
||||
}
|
||||
public void Nde_atrs_set(byte[][] ary) {
|
||||
int ary_len = ary.length;
|
||||
if (ary_len > 0) name_bry = ary[0];
|
||||
if (ary_len > 1) sort_idx = Bry_.To_int_or(ary[1], -1);
|
||||
}
|
||||
public static final byte[] Make_grp = Bry_.new_a7("grp"), Make_itm = Bry_.new_a7("itm");
|
||||
public int Itms_len() {return itms.Count();}
|
||||
public Cfg_nde_obj Itms_get_at(int i) {return (Cfg_nde_obj)itms.Get_at(i);}
|
||||
Ordered_hash itms = Ordered_hash_.new_bry_();
|
||||
|
||||
private static Ordered_hash regy = Ordered_hash_.new_bry_();
|
||||
public static Xoac_lang_itm Regy_get_or_null(byte[] key) {return (Xoac_lang_itm)regy.Get_by(key);}
|
||||
public static Xoac_lang_itm Regy_get_or_new (byte[] key) {
|
||||
Xoac_lang_itm rv = Regy_get_or_null(key);
|
||||
if (rv == null) {
|
||||
rv = new Xoac_lang_itm(key);
|
||||
regy.Add(key, rv);
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
145
400_xowa/src/gplx/xowa/apps/langs/Xoac_lang_grp_tst.java
Normal file
145
400_xowa/src/gplx/xowa/apps/langs/Xoac_lang_grp_tst.java
Normal file
@@ -0,0 +1,145 @@
|
||||
/*
|
||||
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.apps.langs; import gplx.*; import gplx.xowa.*; import gplx.xowa.apps.*;
|
||||
import org.junit.*; import gplx.xowa.langs.*;
|
||||
public class Xoac_lang_grp_tst {
|
||||
Xoac_lang_grp_fxt fxt = new Xoac_lang_grp_fxt();
|
||||
@Before public void init() {fxt.Clear();}
|
||||
@Test public void Add_itm_new() {
|
||||
fxt.Define_bulk(String_.Concat_lines_nl
|
||||
( "+|euro|itm|fr|French"
|
||||
, "+|euro|itm|de|German"
|
||||
)
|
||||
, fxt.grp_("euro").Itms_
|
||||
( fxt.itm_("fr").Local_name_("French")
|
||||
, fxt.itm_("de").Local_name_("German")
|
||||
));
|
||||
}
|
||||
@Test public void Add_itm_nl() {
|
||||
fxt.Define_bulk(String_.Concat_lines_nl
|
||||
( ""
|
||||
, "+|euro|itm|fr|French"
|
||||
, ""
|
||||
)
|
||||
, fxt.grp_("euro").Itms_
|
||||
( fxt.itm_("fr").Local_name_("French")
|
||||
));
|
||||
}
|
||||
@Test public void Add_grp() {
|
||||
fxt.Define_bulk(String_.Concat_lines_nl
|
||||
( "+||grp|euro|European~1"
|
||||
, "+|euro|itm|fr|French"
|
||||
)
|
||||
, fxt.grp_("euro").Name_("European").Sort_idx_(1).Itms_
|
||||
( fxt.itm_("fr").Local_name_("French")
|
||||
));
|
||||
}
|
||||
@Test public void Set_grp() {
|
||||
fxt.Define_bulk(String_.Concat_lines_nl
|
||||
( "+|euro|itm|fr|French"
|
||||
, "+||grp|euro|European"
|
||||
)
|
||||
, fxt.grp_("euro").Name_("European").Itms_
|
||||
( fxt.itm_("fr").Local_name_("French")
|
||||
));
|
||||
}
|
||||
@Test public void Del() {
|
||||
fxt.Define_bulk(String_.Concat_lines_nl
|
||||
( "+|euro|itm|fr|French"
|
||||
, "+|euro|itm|de|German"
|
||||
, "-|euro|fr"
|
||||
)
|
||||
, fxt.grp_("euro").Itms_
|
||||
( fxt.itm_("de").Local_name_("German")
|
||||
));
|
||||
}
|
||||
@Test public void Add_grp_nest() {
|
||||
fxt.Define_bulk(String_.Concat_lines_nl
|
||||
( "+||grp|wiki"
|
||||
, "+|wiki|grp|euro|European"
|
||||
, "+|euro|itm|de|German"
|
||||
)
|
||||
, fxt.grp_("wiki").Itms_
|
||||
( fxt.grp_("euro").Itms_
|
||||
( fxt.itm_("de").Local_name_("German")
|
||||
)));
|
||||
}
|
||||
}
|
||||
class Xoac_lang_grp_fxt {
|
||||
Xoa_lang_mgr lang_mgr; Tst_mgr tst_mgr = new Tst_mgr();
|
||||
public void Clear() {
|
||||
Xoae_app app = Xoa_app_fxt.app_();
|
||||
lang_mgr = app.Lang_mgr();
|
||||
}
|
||||
public Xoac_lang_itm_chkr itm_(String key) {return new Xoac_lang_itm_chkr(key);}
|
||||
public Xoac_lang_grp_chkr grp_(String key) {return new Xoac_lang_grp_chkr(key);}
|
||||
public Xoac_lang_grp_fxt Define_bulk(String raw, Xoac_lang_grp_chkr... expd) {
|
||||
lang_mgr.Groups().Set_bulk(Bry_.new_u8(raw));
|
||||
tst_mgr.Tst_ary("", expd, To_ary(lang_mgr.Groups()));
|
||||
return this;
|
||||
}
|
||||
Xoac_lang_grp[] To_ary(Cfg_nde_root root) {
|
||||
int len = root.Root_len();
|
||||
Xoac_lang_grp[] rv = new Xoac_lang_grp[len];
|
||||
for (int i = 0; i < len; i++) {
|
||||
rv[i] = (Xoac_lang_grp)root.Root_get_at(i); // ASSUME: root only has grps (no itms)
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
abstract class Xoac_lang_chkr_base implements Tst_chkr {
|
||||
public abstract Class<?> TypeOf();
|
||||
public abstract int Chk(Tst_mgr mgr, String path, Object actl);
|
||||
}
|
||||
class Xoac_lang_itm_chkr extends Xoac_lang_chkr_base {
|
||||
public Xoac_lang_itm_chkr(String key) {this.key = key;}
|
||||
public String Key() {return key;} private String key;
|
||||
public Xoac_lang_itm_chkr Local_name_(String v) {local_name = v; return this;} private String local_name;
|
||||
@Override public Class<?> TypeOf() {return Xoac_lang_itm.class;}
|
||||
@Override public int Chk(Tst_mgr mgr, String path, Object actl_obj) {
|
||||
Xoac_lang_itm actl = (Xoac_lang_itm)actl_obj;
|
||||
int rv = 0;
|
||||
rv += mgr.Tst_val(key == null, path, "key", key, String_.new_u8(actl.Key_bry()));
|
||||
rv += mgr.Tst_val(local_name == null, path, "local_name", local_name, String_.new_u8(actl.Local_name_bry()));
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
class Xoac_lang_grp_chkr extends Xoac_lang_chkr_base {
|
||||
public Xoac_lang_grp_chkr(String key) {this.key = key;}
|
||||
public String Key() {return key;} private String key;
|
||||
public Xoac_lang_grp_chkr Name_(String v) {name = v; return this;} private String name;
|
||||
public Xoac_lang_grp_chkr Sort_idx_(int v) {sort_idx = v; return this;} private int sort_idx = -1;
|
||||
public Xoac_lang_grp_chkr Itms_(Xoac_lang_chkr_base... v) {this.itms = v; return this;} private Xoac_lang_chkr_base[] itms;
|
||||
@Override public Class<?> TypeOf() {return Xoac_lang_grp.class;}
|
||||
@Override public int Chk(Tst_mgr mgr, String path, Object actl_obj) {
|
||||
Xoac_lang_grp actl = (Xoac_lang_grp)actl_obj;
|
||||
int rv = 0;
|
||||
rv += mgr.Tst_val(key == null, path, "key", key, String_.new_u8(actl.Key_bry()));
|
||||
rv += mgr.Tst_val(name == null, path, "name", name, String_.new_u8(actl.Name_bry()));
|
||||
rv += mgr.Tst_val(sort_idx == -1, path, "sort_idx", sort_idx, actl.Sort_idx());
|
||||
rv += mgr.Tst_sub_ary(itms, To_ary(actl), path, rv);
|
||||
return rv;
|
||||
}
|
||||
Xoac_lang_obj[] To_ary(Xoac_lang_grp grp) {
|
||||
int len = grp.Itms_len();
|
||||
Xoac_lang_obj[] rv = new Xoac_lang_obj[len];
|
||||
for (int i = 0; i < len; i++)
|
||||
rv[i] = (Xoac_lang_obj)grp.Itms_get_at(i); // ASSUME: grp only has itms (no grps)
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
37
400_xowa/src/gplx/xowa/apps/langs/Xoac_lang_itm.java
Normal file
37
400_xowa/src/gplx/xowa/apps/langs/Xoac_lang_itm.java
Normal file
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
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.apps.langs; import gplx.*; import gplx.xowa.*; import gplx.xowa.apps.*;
|
||||
public class Xoac_lang_itm implements Cfg_nde_obj, Xoac_lang_obj {
|
||||
public Xoac_lang_itm(byte[] key) {this.key_bry = key; local_name_bry = key_bry; uid = uid_next++;} static int uid_next = 0;
|
||||
public Xoac_lang_grp Grp() {return grp;} public Xoac_lang_itm Grp_(Xoac_lang_grp v) {grp = v; return this;} private Xoac_lang_grp grp;
|
||||
public int Uid() {return uid;} private int uid;
|
||||
public byte[] Key_bry() {return key_bry;} private byte[] key_bry;
|
||||
public byte[] Local_name_bry() {return local_name_bry;} public Xoac_lang_itm Local_name_bry_(byte[] v) {local_name_bry = v; return this;} private byte[] local_name_bry;
|
||||
public byte[] Nde_key() {return key_bry;}
|
||||
public boolean Nde_typ_is_grp() {return false;}
|
||||
public Cfg_nde_obj Nde_subs_make(byte[] itm_type, byte[] itm_key, byte[][] itm_atrs) {throw Err_.new_wo_type("langs cannot have itms", "type", itm_type, "key", itm_key);}
|
||||
public Cfg_nde_obj Nde_subs_get(byte[] key) {throw Err_.new_wo_type("langs cannot have itms", "key", key);}
|
||||
public int Nde_subs_len() {return 0;}
|
||||
public Cfg_nde_obj Nde_subs_get_at(int i) {throw Err_.new_wo_type("langs cannot have itms", "idx", i);}
|
||||
public void Nde_subs_add(byte[] itm_key, Cfg_nde_obj itm_obj) {throw Err_.new_wo_type("langs cannot have itms", "key", String_.new_u8(itm_key));}
|
||||
public void Nde_subs_del(byte[] key) {throw Err_.new_wo_type("langs cannot delete itms", "key", String_.new_u8(key));}
|
||||
public void Nde_atrs_set(byte[][] ary) {
|
||||
if (ary.length != 1) throw Err_.new_wo_type("expecting name only", "name", String_.AryXtoStr(String_.Ary(ary)));
|
||||
local_name_bry = ary[0];
|
||||
}
|
||||
}
|
||||
@@ -16,9 +16,29 @@ 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.apps.metas; import gplx.*; import gplx.xowa.*; import gplx.xowa.apps.*;
|
||||
import gplx.xowa.wmfs.data.*;
|
||||
public class Xoa_meta_mgr {
|
||||
private final Xoa_app app;
|
||||
private final Hash_adp_bry ns__hash = Hash_adp_bry.cs();
|
||||
private Site_core_db core_db;
|
||||
public Xoa_meta_mgr(Xoa_app app) {
|
||||
this.ns_mgr = new Xoa_ns_mgr(app);
|
||||
this.app = app;
|
||||
}
|
||||
public void Ns__add(byte[] wiki_domain, Xow_ns_mgr ns_mgr) {ns__hash.Add(wiki_domain, ns_mgr);} // TEST:public
|
||||
public Xow_ns_mgr Ns__get_or_load(byte[] wiki_domain) {
|
||||
Xow_ns_mgr rv = (Xow_ns_mgr)ns__hash.Get_by_bry(wiki_domain);
|
||||
if (rv == null) {
|
||||
Core_db__assert();
|
||||
rv = core_db.Load_namespace(wiki_domain);
|
||||
Ns__add(wiki_domain, rv);
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
public void Init_by_wiki(Xow_wiki wiki) {
|
||||
Core_db__assert();
|
||||
core_db.Load_extensiontag(wiki.Domain_itm(), wiki.Mw_parser_mgr().Xnde_tag_regy());
|
||||
}
|
||||
private void Core_db__assert() {
|
||||
if (core_db == null) core_db = new Site_core_db(app.Fsys_mgr().Cfg_site_meta_fil());
|
||||
}
|
||||
public Xoa_ns_mgr Ns_mgr() {return ns_mgr;} private final Xoa_ns_mgr ns_mgr;
|
||||
}
|
||||
|
||||
@@ -1,40 +0,0 @@
|
||||
/*
|
||||
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.apps.metas; import gplx.*; import gplx.xowa.*; import gplx.xowa.apps.*;
|
||||
import gplx.dbs.*;
|
||||
import gplx.xowa.langs.cases.*;
|
||||
import gplx.xowa.wikis.domains.*;
|
||||
import gplx.xowa.wmfs.data.*;
|
||||
public class Xoa_ns_mgr {
|
||||
private final Xoa_app app;
|
||||
private final Hash_adp_bry hash = Hash_adp_bry.cs();
|
||||
private Site_core_db core_db;
|
||||
public Xoa_ns_mgr(Xoa_app app) {
|
||||
this.app = app;
|
||||
}
|
||||
public void Add(byte[] wiki_domain, Xow_ns_mgr ns_mgr) {hash.Add(wiki_domain, ns_mgr);} // TEST:
|
||||
public Xow_ns_mgr Get_or_load(byte[] wiki_domain) {
|
||||
Xow_ns_mgr rv = (Xow_ns_mgr)hash.Get_by_bry(wiki_domain);
|
||||
if (rv == null) {
|
||||
if (core_db == null) core_db = new Site_core_db(app.Fsys_mgr().Cfg_site_meta_fil());
|
||||
rv = core_db.Load_ns(wiki_domain);
|
||||
Add(wiki_domain, rv);
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
60
400_xowa/src/gplx/xowa/bldrs/Xob_sql_dump_base.java
Normal file
60
400_xowa/src/gplx/xowa/bldrs/Xob_sql_dump_base.java
Normal file
@@ -0,0 +1,60 @@
|
||||
/*
|
||||
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.bldrs; import gplx.*; import gplx.xowa.*;
|
||||
import gplx.core.flds.*; import gplx.ios.*; import gplx.xowa.tdbs.*;
|
||||
import gplx.xowa.bldrs.sqls.*;
|
||||
public abstract class Xob_sql_dump_base extends Xob_itm_dump_base implements Xob_cmd, GfoInvkAble {
|
||||
private final Sql_file_parser parser = new Sql_file_parser(); private boolean fail = false;
|
||||
public abstract String Cmd_key();
|
||||
public Io_url Src_fil() {return src_fil;} private Io_url src_fil;
|
||||
public Io_url_gen Make_url_gen() {return make_url_gen;} private Io_url_gen make_url_gen;
|
||||
public abstract String Sql_file_name();
|
||||
public void Cmd_init(Xob_bldr bldr) {}
|
||||
public void Cmd_bgn(Xob_bldr bldr) {
|
||||
this.Init_dump(this.Cmd_key());
|
||||
make_url_gen = Io_url_gen_.dir_(temp_dir.GenSubDir("make"));
|
||||
if (src_fil == null) {
|
||||
src_fil = Xotdb_fsys_mgr.Find_file_or_null(wiki.Fsys_mgr().Root_dir(), "*" + Sql_file_name() + "*", ".gz", ".sql");
|
||||
if (src_fil == null) {
|
||||
String msg = String_.Format(".sql file not found in dir.\nPlease download the file for your wiki from dumps.wikimedia.org.\nfile={0} dir={1}", Sql_file_name(), wiki.Fsys_mgr().Root_dir());
|
||||
app.Usr_dlg().Warn_many("", "", msg);
|
||||
app.Gui_mgr().Kit().Ask_ok("", "", msg);
|
||||
fail = true;
|
||||
return;
|
||||
}
|
||||
}
|
||||
parser.Src_fil_(src_fil).Trg_fil_gen_(dump_url_gen);
|
||||
Cmd_bgn_hook(bldr, parser);
|
||||
} protected Gfo_fld_wtr fld_wtr = Gfo_fld_wtr.xowa_();
|
||||
public abstract void Cmd_bgn_hook(Xob_bldr bldr, Sql_file_parser parser);
|
||||
public void Cmd_run() {
|
||||
if (fail) return;
|
||||
parser.Parse(bldr.Usr_dlg());
|
||||
}
|
||||
@gplx.Virtual public void Cmd_end() {
|
||||
if (fail) return;
|
||||
Xobdc_merger.Basic(bldr.Usr_dlg(), dump_url_gen, temp_dir.GenSubDir("sort"), sort_mem_len, Io_line_rdr_key_gen_all._, new Io_sort_fil_basic(bldr.Usr_dlg(), make_url_gen, make_fil_len));
|
||||
}
|
||||
public void Cmd_term() {}
|
||||
@Override public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
|
||||
if (ctx.Match(k, Invk_src_fil_)) src_fil = m.ReadIoUrl("v");
|
||||
else return super.Invk(ctx, ikey, k, m);
|
||||
return this;
|
||||
}
|
||||
public static final String Invk_src_fil_ = "src_fil_";
|
||||
}
|
||||
@@ -17,6 +17,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.bldrs.cfgs; import gplx.*; import gplx.xowa.*; import gplx.xowa.bldrs.*;
|
||||
import gplx.core.strings.*;
|
||||
import gplx.xowa.wikis.xwikis.cfgs.*;
|
||||
public class Xob_wiki_cfg_bldr implements GfoInvkAble {
|
||||
public Xob_wiki_cfg_bldr(Xob_bldr bldr) {this.app = bldr.App();} private Xoae_app app;
|
||||
public void Exec() {
|
||||
|
||||
@@ -18,6 +18,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
package gplx.xowa.bldrs.cmds; import gplx.*; import gplx.xowa.*; import gplx.xowa.bldrs.*;
|
||||
import gplx.dbs.*; import gplx.xowa.wikis.caches.*; import gplx.xowa.bldrs.cmds.files.*; import gplx.xowa.files.origs.*;
|
||||
import gplx.xowa.wikis.data.*; import gplx.xowa.dbs.*; import gplx.xowa.wikis.data.tbls.*;
|
||||
import gplx.xowa.parsers.*; import gplx.xowa.parsers.tmpls.*;
|
||||
public abstract class Xob_dump_mgr_base extends Xob_itm_basic_base implements Xob_cmd, GfoInvkAble {
|
||||
private Xob_dump_src_id page_src;
|
||||
private Xowd_db_mgr db_fsys_mgr; protected Xop_parser parser; protected Xop_ctx ctx; protected Xop_root_tkn root;
|
||||
@@ -176,9 +177,7 @@ public abstract class Xob_dump_mgr_base extends Xob_itm_basic_base implements Xo
|
||||
usr_dlg.Note_many("", "", "done: ~{0} ~{1}", exec_count, Decimal_adp_.divide_safe_(exec_count, Env_.TickCount_elapsed_in_sec(time_bgn)).To_str("#,###.000"));
|
||||
}
|
||||
private void Free() {
|
||||
ctx.App().Free_mem(true);
|
||||
gplx.xowa.xtns.scribunto.Scrib_core.Core_invalidate();
|
||||
wiki.Cache_mgr().Free_mem_all();
|
||||
Xow_wiki_.Rls_mem(wiki, true);
|
||||
}
|
||||
protected void Reset_db_y_() {this.reset_db = true;}
|
||||
@Override public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
|
||||
|
||||
@@ -17,6 +17,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.bldrs.cmds.ctgs; import gplx.*; import gplx.xowa.*; import gplx.xowa.bldrs.*; import gplx.xowa.bldrs.cmds.*;
|
||||
import gplx.core.brys.*; import gplx.ios.*; import gplx.xowa.ctgs.*;
|
||||
import gplx.xowa.bldrs.sqls.*;
|
||||
public abstract class Xob_categorylinks_base extends Xob_sql_dump_base implements Sql_file_parser_cmd {
|
||||
private DateAdp_parser date_parser = DateAdp_parser.new_(); private Sql_file_parser sql_parser; Uca_trie trie; private Bry_bfr uca_bfr = Bry_bfr.reset_(255);
|
||||
public abstract Io_sort_cmd Make_sort_cmd(Sql_file_parser sql_parser);
|
||||
|
||||
@@ -16,7 +16,8 @@ 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.bldrs.cmds.ctgs; import gplx.*; import gplx.xowa.*; import gplx.xowa.bldrs.*; import gplx.xowa.bldrs.cmds.*;
|
||||
import gplx.ios.*; import gplx.xowa.bldrs.*;
|
||||
import gplx.ios.*;
|
||||
import gplx.xowa.bldrs.sqls.*;
|
||||
public class Xob_categorylinks_sql extends Xob_categorylinks_base {
|
||||
private Db_idx_mode idx_mode = Db_idx_mode.Itm_end;
|
||||
public Xob_categorylinks_sql(Xob_bldr bldr, Xowe_wiki wiki) {this.Cmd_ctor(bldr, wiki); this.make_fil_len = Io_mgr.Len_mb;}
|
||||
|
||||
@@ -17,7 +17,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.bldrs.cmds.ctgs; import gplx.*; import gplx.xowa.*; import gplx.xowa.bldrs.*; import gplx.xowa.bldrs.cmds.*;
|
||||
import gplx.core.flds.*; import gplx.ios.*; import gplx.dbs.*; import gplx.xowa.dbs.*; import gplx.xowa.ctgs.*;
|
||||
import gplx.xowa.bldrs.*;
|
||||
import gplx.xowa.bldrs.sqls.*;
|
||||
import gplx.xowa.wikis.data.*; import gplx.xowa.wikis.data.tbls.*;
|
||||
public class Xob_categorylinks_sql_make implements Io_make_cmd {
|
||||
private Gfo_usr_dlg usr_dlg; private final Xowe_wiki wiki; private final Db_idx_mode idx_mode; private Xowd_db_mgr core_db_mgr;
|
||||
|
||||
@@ -17,6 +17,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.bldrs.cmds.ctgs; import gplx.*; import gplx.xowa.*; import gplx.xowa.bldrs.*; import gplx.xowa.bldrs.cmds.*;
|
||||
import gplx.ios.*;
|
||||
import gplx.xowa.bldrs.sqls.*;
|
||||
public class Xob_categorylinks_txt extends Xob_categorylinks_base {
|
||||
public Xob_categorylinks_txt(Xob_bldr bldr, Xowe_wiki wiki) {this.Cmd_ctor(bldr, wiki); this.make_fil_len = Io_mgr.Len_mb;}
|
||||
@Override public String Cmd_key() {return Xob_cmd_keys.Key_tdb_text_cat_link;}
|
||||
|
||||
@@ -17,6 +17,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.bldrs.cmds.ctgs; import gplx.*; import gplx.xowa.*; import gplx.xowa.bldrs.*; import gplx.xowa.bldrs.cmds.*;
|
||||
import gplx.ios.*;
|
||||
import gplx.xowa.bldrs.sqls.*;
|
||||
public abstract class Xoctg_hiddencat_parser_base extends Xob_sql_dump_base implements Sql_file_parser_cmd {
|
||||
public Xoctg_hiddencat_parser_base Ctor(Xob_bldr bldr, Xowe_wiki wiki) {this.Cmd_ctor(bldr, wiki); this.make_fil_len = Io_mgr.Len_mb; return this;}
|
||||
@Override public String Sql_file_name() {return "page_props";}
|
||||
|
||||
@@ -17,6 +17,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.bldrs.cmds.ctgs; import gplx.*; import gplx.xowa.*; import gplx.xowa.bldrs.*; import gplx.xowa.bldrs.cmds.*;
|
||||
import gplx.dbs.*; import gplx.xowa.dbs.*; import gplx.xowa.wikis.data.tbls.*;
|
||||
import gplx.xowa.bldrs.sqls.*;
|
||||
import gplx.xowa.wikis.data.*;
|
||||
public class Xoctg_hiddencat_parser_sql extends Xoctg_hiddencat_parser_base {
|
||||
private Xowd_cat_core_tbl tbl;
|
||||
|
||||
@@ -17,6 +17,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.bldrs.cmds.ctgs; import gplx.*; import gplx.xowa.*; import gplx.xowa.bldrs.*; import gplx.xowa.bldrs.cmds.*;
|
||||
import gplx.ios.*;
|
||||
import gplx.xowa.bldrs.sqls.*;
|
||||
public class Xoctg_hiddencat_parser_txt extends Xoctg_hiddencat_parser_base {
|
||||
public Xoctg_hiddencat_parser_txt(Xob_bldr bldr, Xowe_wiki wiki) {this.Ctor(bldr, wiki);}
|
||||
@Override public String Cmd_key() {return Xob_cmd_keys.Key_tdb_cat_hidden_sql;}
|
||||
|
||||
@@ -19,7 +19,8 @@ package gplx.xowa.bldrs.cmds.files; import gplx.*; import gplx.xowa.*; import gp
|
||||
import gplx.dbs.*; import gplx.dbs.cfgs.*; import gplx.xowa.wikis.data.tbls.*; import gplx.xowa.pages.*;
|
||||
import gplx.xowa.files.*;
|
||||
import gplx.xowa.wikis.*; import gplx.xowa.wikis.domains.*;
|
||||
import gplx.xowa.parsers.lnkis.redlinks.*; import gplx.xowa.parsers.logs.*; import gplx.xowa.html.hdumps.bldrs.*; import gplx.xowa.xtns.scribunto.*; import gplx.xowa.xtns.wdatas.*;
|
||||
import gplx.xowa.parsers.*; import gplx.xowa.parsers.logs.*; import gplx.xowa.parsers.lnkis.*; import gplx.xowa.parsers.lnkis.redlinks.*; import gplx.xowa.parsers.xndes.*;
|
||||
import gplx.xowa.html.hdumps.bldrs.*; import gplx.xowa.xtns.scribunto.*; import gplx.xowa.xtns.wdatas.*;
|
||||
import gplx.fsdb.meta.*; import gplx.xowa.files.fsdb.*; import gplx.fsdb.*;
|
||||
public class Xob_lnki_temp_wkr extends Xob_dump_mgr_base implements Xopg_redlink_logger {
|
||||
private Xob_lnki_temp_tbl tbl; private boolean wdata_enabled = true, xtn_ref_enabled = true, gen_html, gen_hdump;
|
||||
@@ -60,7 +61,7 @@ public class Xob_lnki_temp_wkr extends Xob_dump_mgr_base implements Xopg_redlink
|
||||
if (!xtn_ref_enabled) gplx.xowa.xtns.cite.References_nde.Enabled = false;
|
||||
gplx.xowa.xtns.gallery.Gallery_xnde.Log_wkr = log_mgr.Make_wkr().Save_src_str_(Bool_.Y);
|
||||
gplx.xowa.xtns.imaps.Imap_xnde.Log_wkr = log_mgr.Make_wkr();
|
||||
gplx.xowa.Xop_xnde_wkr.Timeline_log_wkr = log_mgr.Make_wkr();
|
||||
gplx.xowa.parsers.xndes.Xop_xnde_wkr.Timeline_log_wkr = log_mgr.Make_wkr();
|
||||
gplx.xowa.xtns.scores.Score_xnde.Log_wkr = log_mgr.Make_wkr();
|
||||
gplx.xowa.xtns.hieros.Hiero_xnde.Log_wkr = log_mgr.Make_wkr();
|
||||
gplx.xowa.xtns.math.Math_nde.Log_wkr = log_mgr.Make_wkr();
|
||||
|
||||
@@ -32,7 +32,7 @@ public class Xob_xfer_regy_update_cmd extends Xob_itm_basic_base implements Xob_
|
||||
this.Update_status(make_db_provider);
|
||||
}
|
||||
private void Copy_atrs_to_make_db(Db_conn make_db_provider) {
|
||||
wiki.File_mgr().Init_file_mgr_by_load(wiki);
|
||||
wiki.File_mgr().Init_file_mgr_by_load(wiki); // NOTE: this gets current fsdb to update from xfer_regy; this never uses -prv/ or /prv/ databases; DATE:2015-09-10
|
||||
Fsm_mnt_itm fsdb_abc_mgr = wiki.File_mgr().Fsdb_mgr().Mnt_mgr().Mnts__get_main(); // 0 = fsdb.main
|
||||
Db_conn conn = fsdb_abc_mgr.Atr_mgr().Db__core().Conn(); // 0 = fsdb.atr.00
|
||||
Io_url fsdb_atr_url = ((gplx.dbs.engines.sqlite.Sqlite_conn_info)conn.Conn_info()).Url();
|
||||
|
||||
@@ -17,6 +17,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.bldrs.cmds.files; import gplx.*; import gplx.xowa.*; import gplx.xowa.bldrs.*; import gplx.xowa.bldrs.cmds.*;
|
||||
import gplx.dbs.*; import gplx.xowa.dbs.*; import gplx.xowa.files.*; import gplx.xowa.files.exts.*;
|
||||
import gplx.xowa.parsers.lnkis.*;
|
||||
public class Xob_xfer_temp_cmd_orig extends Xob_itm_basic_base implements Xob_cmd {
|
||||
private byte[] ext_rules_key = Bry_.Empty;
|
||||
public Xob_xfer_temp_cmd_orig(Xob_bldr bldr, Xowe_wiki wiki) {this.Cmd_ctor(bldr, wiki);}
|
||||
|
||||
@@ -17,6 +17,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.bldrs.cmds.files; import gplx.*; import gplx.xowa.*; import gplx.xowa.bldrs.*; import gplx.xowa.bldrs.cmds.*;
|
||||
import gplx.dbs.*; import gplx.xowa.files.*;
|
||||
import gplx.xowa.parsers.lnkis.*;
|
||||
class Xob_xfer_temp_itm {
|
||||
public int Lnki_id() {return lnki_id;} private int lnki_id;
|
||||
public int Lnki_tier_id() {return lnki_tier_id;} private int lnki_tier_id;
|
||||
|
||||
@@ -18,6 +18,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
package gplx.xowa.bldrs.cmds.files; import gplx.*; import gplx.xowa.*; import gplx.xowa.bldrs.*; import gplx.xowa.bldrs.cmds.*;
|
||||
import org.junit.*;
|
||||
import gplx.stores.*; import gplx.xowa.files.*; import gplx.xowa.files.repos.*;
|
||||
import gplx.xowa.parsers.lnkis.*;
|
||||
public class Xob_xfer_temp_itm_tst {
|
||||
private Xob_xfer_temp_itm_fxt fxt = new Xob_xfer_temp_itm_fxt();
|
||||
@Before public void init() {fxt.Reset();}
|
||||
|
||||
@@ -18,7 +18,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
package gplx.xowa.bldrs.cmds.texts.sqls; import gplx.*; import gplx.xowa.*; import gplx.xowa.bldrs.*; import gplx.xowa.bldrs.cmds.*; import gplx.xowa.bldrs.cmds.texts.*;
|
||||
import gplx.dbs.*; import gplx.ios.*; import gplx.xowa.bldrs.cmds.*; import gplx.xowa.bldrs.cmds.wikis.*;
|
||||
import gplx.xowa.wikis.data.*; import gplx.xowa.wikis.data.tbls.*; import gplx.xowa.dbs.*;
|
||||
import gplx.xowa.wikis.*; import gplx.xowa.bldrs.filters.dansguardians.*; import gplx.xowa.apis.xowa.bldrs.imports.*;
|
||||
import gplx.xowa.wikis.*; import gplx.xowa.bldrs.filters.dansguardians.*; import gplx.xowa.apis.xowa.bldrs.imports.*;
|
||||
import gplx.xowa.parsers.utils.*;
|
||||
public class Xob_page_cmd extends Xob_itm_basic_base implements Xobd_wkr, GfoInvkAble {
|
||||
private Xowd_db_mgr db_mgr; private Db_idx_mode idx_mode = Db_idx_mode.Itm_end; private Xowd_page_tbl page_core_tbl; private Io_stream_zip_mgr text_zip_mgr; private byte text_zip_tid;
|
||||
private Xop_redirect_mgr redirect_mgr; private Xob_redirect_tbl redirect_tbl; private boolean redirect_id_enabled;
|
||||
|
||||
@@ -17,6 +17,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.bldrs.cmds.texts.sqls; import gplx.*; import gplx.xowa.*; import gplx.xowa.bldrs.*; import gplx.xowa.bldrs.cmds.*; import gplx.xowa.bldrs.cmds.texts.*;
|
||||
import gplx.dbs.*;
|
||||
import gplx.xowa.bldrs.sqls.*;
|
||||
import gplx.xowa.wikis.data.*; import gplx.xowa.wikis.data.tbls.*;
|
||||
public class Xob_pagelinks_parser_cmd extends Xob_sql_dump_base implements Sql_file_parser_cmd {
|
||||
private Db_conn core_conn;
|
||||
|
||||
@@ -16,7 +16,7 @@ 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.bldrs.cmds.texts.tdbs; import gplx.*; import gplx.xowa.*; import gplx.xowa.bldrs.*; import gplx.xowa.bldrs.cmds.*; import gplx.xowa.bldrs.cmds.texts.*;
|
||||
import gplx.xowa.tdbs.*; import gplx.xowa.wikis.data.tbls.*;
|
||||
import gplx.xowa.tdbs.*; import gplx.xowa.tdbs.hives.*; import gplx.xowa.wikis.data.tbls.*;
|
||||
public class Xob_calc_stats_cmd extends Xob_itm_basic_base implements Xob_cmd {
|
||||
public Xob_calc_stats_cmd(Xob_bldr bldr, Xowe_wiki wiki) {this.Cmd_ctor(bldr, wiki);}
|
||||
public String Cmd_key() {return Xob_cmd_keys.Key_tdb_calc_stats;}
|
||||
|
||||
@@ -17,6 +17,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.bldrs.cmds.texts.tdbs; import gplx.*; import gplx.xowa.*; import gplx.xowa.bldrs.*; import gplx.xowa.bldrs.cmds.*; import gplx.xowa.bldrs.cmds.texts.*;
|
||||
import gplx.ios.*; import gplx.xowa.tdbs.*; import gplx.xowa.wikis.data.tbls.*;
|
||||
import gplx.xowa.parsers.utils.*;
|
||||
public class Xob_page_txt extends Xob_itm_dump_base implements Xobd_wkr, GfoInvkAble {
|
||||
public Xob_page_txt(Xob_bldr bldr, Xowe_wiki wiki) {this.Cmd_ctor(bldr, wiki);}
|
||||
public String Wkr_key() {return Xob_cmd_keys.Key_tdb_make_page;}
|
||||
|
||||
@@ -16,7 +16,8 @@ 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.bldrs.cmds.utils; import gplx.*; import gplx.xowa.*; import gplx.xowa.bldrs.*; import gplx.xowa.bldrs.cmds.*;
|
||||
import gplx.xowa.bldrs.*; import gplx.xowa.tdbs.*;
|
||||
import gplx.ios.*; import gplx.xowa.bldrs.sqls.*;
|
||||
import gplx.xowa.tdbs.*;
|
||||
public class Xob_deploy_zip_cmd extends Xob_itm_basic_base implements Xob_cmd {
|
||||
public Xob_deploy_zip_cmd(Xob_bldr bldr, Xowe_wiki wiki) {this.Cmd_ctor(bldr, wiki);}
|
||||
public String Cmd_key() {return Xob_cmd_keys.Key_deploy_zip;}
|
||||
|
||||
@@ -17,6 +17,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.bldrs.cmds.wikis; import gplx.*; import gplx.xowa.*; import gplx.xowa.bldrs.*; import gplx.xowa.bldrs.cmds.*;
|
||||
import gplx.dbs.*; import gplx.ios.*; import gplx.xowa.files.*;
|
||||
import gplx.xowa.bldrs.sqls.*;
|
||||
public class Xob_image_cmd extends Xob_itm_dump_base implements Xob_cmd, GfoInvkAble, Sql_file_parser_cmd {
|
||||
private Db_conn conn = null; private Db_stmt stmt = null;
|
||||
private Xob_image_tbl tbl_image = new Xob_image_tbl();
|
||||
|
||||
@@ -17,6 +17,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.bldrs.cmds.wikis; import gplx.*; import gplx.xowa.*; import gplx.xowa.bldrs.*; import gplx.xowa.bldrs.cmds.*;
|
||||
import gplx.dbs.*; import gplx.dbs.cfgs.*; import gplx.xowa.dbs.*; import gplx.xowa.wikis.data.tbls.*;
|
||||
import gplx.xowa.parsers.utils.*;
|
||||
public class Xob_redirect_cmd extends Xob_dump_mgr_base {
|
||||
private Db_conn conn; private Xob_redirect_tbl redirect_tbl;
|
||||
private Xodb_mgr_sql db_mgr; private Xop_redirect_mgr redirect_mgr; private Url_encoder encoder;
|
||||
|
||||
113
400_xowa/src/gplx/xowa/bldrs/installs/Xoi_cmd_base.java
Normal file
113
400_xowa/src/gplx/xowa/bldrs/installs/Xoi_cmd_base.java
Normal file
@@ -0,0 +1,113 @@
|
||||
/*
|
||||
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.bldrs.installs; import gplx.*; import gplx.xowa.*; import gplx.xowa.bldrs.*;
|
||||
import gplx.core.threads.*; import gplx.xowa.bldrs.*;
|
||||
import gplx.xowa.wikis.domains.*;
|
||||
import gplx.xowa.wmfs.dumps.*;
|
||||
abstract class Xoi_cmd_base implements Gfo_thread_cmd {
|
||||
public void Ctor(Xoi_setup_mgr install_mgr, String wiki_key) {
|
||||
this.install_mgr = install_mgr; this.wiki_key = wiki_key;
|
||||
this.Owner_(install_mgr);
|
||||
} private Xoi_setup_mgr install_mgr; String wiki_key;
|
||||
@gplx.Virtual public void Cmd_ctor() {}
|
||||
public abstract String Async_key();
|
||||
public int Async_sleep_interval() {return Gfo_thread_cmd_.Async_sleep_interval_1_second;}
|
||||
public boolean Async_prog_enabled() {return false;}
|
||||
public void Async_prog_run(int async_sleep_sum) {}
|
||||
public byte Async_init() {return Gfo_thread_cmd_.Init_ok;}
|
||||
public boolean Async_term() {
|
||||
// install_mgr.App().Gui_wtr().Log_many(GRP_KEY, "import.end", "import.end ~{0} ~{1} ~{2}", wiki_key, wiki_date, dump_type);
|
||||
return true;
|
||||
}
|
||||
public GfoInvkAble Owner() {return owner;} public Xoi_cmd_base Owner_(GfoInvkAble v) {owner = v; return this;} GfoInvkAble owner;
|
||||
public Gfo_thread_cmd Async_next_cmd() {return next_cmd;} public void Async_next_cmd_(Gfo_thread_cmd v) {next_cmd = v;} Gfo_thread_cmd next_cmd;
|
||||
public void Async_run() {
|
||||
running = true;
|
||||
// install_mgr.App().Gui_wtr().Log_many(GRP_KEY, "import.bgn", "import.bgn ~{0} ~{1} ~{2}", wiki_key, wiki_date, dump_type);
|
||||
Thread_adp_.invk_(this.Async_key(), this, Invk_process_async).Start();
|
||||
}
|
||||
public boolean Async_running() {return running;} private boolean running;
|
||||
public void Process_async() {
|
||||
Xoae_app app = install_mgr.App();
|
||||
Xob_bldr bldr = app.Bldr();
|
||||
Xowe_wiki wiki = app.Wiki_mgr().Get_by_key_or_make(Bry_.new_a7(wiki_key));
|
||||
wiki.Init_assert();
|
||||
bldr.Cmd_mgr().Clear();
|
||||
Process_async_init(app, wiki, bldr);
|
||||
bldr.Pause_at_end_(false);
|
||||
try {bldr.Run();}
|
||||
catch (Exception e) {
|
||||
running = false;
|
||||
install_mgr.Cmd_mgr().Working_(Bool_.N);
|
||||
throw Err_.new_exc(e, "xo", "error during import");
|
||||
}
|
||||
app.Usr_dlg().Prog_none("", "clear", "");
|
||||
app.Usr_dlg().Note_none("", "clear", "");
|
||||
Process_async_done(app, wiki, bldr);
|
||||
running = false;
|
||||
}
|
||||
public abstract void Process_async_init(Xoae_app app, Xowe_wiki wiki, Xob_bldr bldr);
|
||||
public abstract void Process_async_done(Xoae_app app, Xowe_wiki wiki, Xob_bldr bldr);
|
||||
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
|
||||
if (ctx.Match(k, Invk_process_async)) Process_async();
|
||||
else if (ctx.Match(k, Invk_owner)) return owner;
|
||||
else return GfoInvkAble_.Rv_unhandled;
|
||||
return this;
|
||||
} private static final String Invk_process_async = "run_async", Invk_owner = "owner";
|
||||
}
|
||||
class Xoi_cmd_category2_page_props extends Xoi_cmd_wiki_download { public Xoi_cmd_category2_page_props(Xoi_setup_mgr install_mgr, String wiki_key, String dump_date) {this.Ctor_download_(install_mgr, wiki_key, dump_date, Xowm_dump_type_.Str__page_props);}
|
||||
@Override public String Download_file_ext() {return ".sql.gz2";}
|
||||
public static final String KEY_category2 = "wiki.category2.download.page_props";
|
||||
}
|
||||
class Xoi_cmd_category2_categorylinks extends Xoi_cmd_wiki_download { public Xoi_cmd_category2_categorylinks(Xoi_setup_mgr install_mgr, String wiki_key, String dump_date) {this.Ctor_download_(install_mgr, wiki_key, dump_date, Xowm_dump_type_.Str__categorylinks);}
|
||||
@Override public String Download_file_ext() {return ".sql.gz2";}
|
||||
public static final String KEY_category2 = "wiki.category2.download.categorylinks";
|
||||
}
|
||||
class Xoi_cmd_category2_build extends Xoi_cmd_base {
|
||||
public Xoi_cmd_category2_build(Xoi_setup_mgr install_mgr, String wiki_key) {this.Ctor(install_mgr, wiki_key); this.app = install_mgr.App(); this.wiki_key = wiki_key;} private Xoae_app app; private String wiki_key;
|
||||
@Override public void Cmd_ctor() {
|
||||
Xowe_wiki wiki = app.Wiki_mgr().Get_by_key_or_make(Bry_.new_u8(wiki_key));
|
||||
wiki.Import_cfg().Category_version_(gplx.xowa.ctgs.Xoa_ctg_mgr.Version_2);
|
||||
}
|
||||
@Override public String Async_key() {return KEY;} public static final String KEY = "wiki.category2.build";
|
||||
@Override public void Process_async_init(Xoae_app app, Xowe_wiki wiki, Xob_bldr bldr) {
|
||||
if (app.Setup_mgr().Dump_mgr().Wiki_storage_type_is_sql()) {
|
||||
wiki.Db_mgr_as_sql().Category_version_update(false);
|
||||
bldr.Cmd_mgr().Add_many(wiki, Xob_cmd_keys.Key_text_cat_core, Xob_cmd_keys.Key_text_cat_link, Xob_cmd_keys.Key_text_cat_hidden);
|
||||
}
|
||||
else
|
||||
bldr.Cmd_mgr().Add_many(wiki, Xob_cmd_keys.Key_tdb_cat_hidden_sql, Xob_cmd_keys.Key_tdb_cat_hidden_ttl, Xob_cmd_keys.Key_text_cat_link, Xob_cmd_keys.Key_tdb_ctg_link_idx);
|
||||
}
|
||||
@Override public void Process_async_done(Xoae_app app, Xowe_wiki wiki, Xob_bldr bldr) {
|
||||
app.Usr_dlg().Prog_many("", "", "category2 setup done");
|
||||
}
|
||||
}
|
||||
class Xoi_cmd_search2_build extends Xoi_cmd_base {
|
||||
public Xoi_cmd_search2_build(Xoi_setup_mgr install_mgr, String wiki_key) {this.Ctor(install_mgr, wiki_key);}
|
||||
@Override public String Async_key() {return KEY;} public static final String KEY = "wiki.search2.build";
|
||||
@Override public void Process_async_init(Xoae_app app, Xowe_wiki wiki, Xob_bldr bldr) {
|
||||
if (app.Setup_mgr().Dump_mgr().Wiki_storage_type_is_sql()) {
|
||||
wiki.Db_mgr_as_sql().Category_version_update(false);
|
||||
bldr.Cmd_mgr().Add_many(wiki, Xob_cmd_keys.Key_text_search_cmd);
|
||||
}
|
||||
}
|
||||
@Override public void Process_async_done(Xoae_app app, Xowe_wiki wiki, Xob_bldr bldr) {
|
||||
app.Usr_dlg().Prog_many("", "", "search2 setup done");
|
||||
wiki.Db_mgr().Search_version_refresh();
|
||||
}
|
||||
}
|
||||
60
400_xowa/src/gplx/xowa/bldrs/installs/Xoi_cmd_dumpfile.java
Normal file
60
400_xowa/src/gplx/xowa/bldrs/installs/Xoi_cmd_dumpfile.java
Normal file
@@ -0,0 +1,60 @@
|
||||
/*
|
||||
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.bldrs.installs; import gplx.*; import gplx.xowa.*; import gplx.xowa.bldrs.*;
|
||||
import gplx.core.threads.*;
|
||||
class Xoi_cmd_dumpfile {
|
||||
public byte[] Domain() {return domain;} private byte[] domain;
|
||||
public Io_url Bz2_url() {return bz2_url;} Io_url bz2_url;
|
||||
public Io_url Xml_url() {return xml_url;} Io_url xml_url;
|
||||
public boolean Bz2_unzip() {return bz2_unzip;} private boolean bz2_unzip;
|
||||
public void Clear() {domain = null; bz2_url = xml_url = null; bz2_unzip = false;}
|
||||
public Xoi_cmd_dumpfile Parse_msg(GfoMsg m) {
|
||||
Io_url dump_url = m.ReadIoUrl("url");
|
||||
domain = m.ReadBry("domain");
|
||||
if (Bry_.Len_eq_0(domain)) domain = Bry_.new_u8(dump_url.OwnerDir().NameOnly());
|
||||
bz2_unzip = String_.Eq(m.ReadStr("args"), "unzip");
|
||||
String dump_ext = dump_url.Ext();
|
||||
if (String_.Eq(dump_ext, ".bz2")) {
|
||||
bz2_url = dump_url;
|
||||
if (bz2_unzip) {
|
||||
xml_url = bz2_url.GenNewExt(""); // remove .bz2 extension (new file path should be .xml)
|
||||
if (!String_.Eq(xml_url.Ext(), ".xml"))
|
||||
xml_url = xml_url.GenNewExt(".xml");
|
||||
}
|
||||
}
|
||||
else if (String_.Eq(dump_ext, ".xml")) { // user selected xml file;
|
||||
bz2_url = null;
|
||||
xml_url = dump_url;
|
||||
bz2_unzip = false; // ignore unzip arge
|
||||
}
|
||||
return this;
|
||||
}
|
||||
public Gfo_thread_cmd Exec(Xoi_cmd_mgr cmd_mgr) {
|
||||
Xowe_wiki wiki = cmd_mgr.App().Wiki_mgr().Get_by_key_or_make(domain);
|
||||
if (bz2_unzip) { // unzip requested; add unzip cmd
|
||||
GfoMsg unzip_msg = GfoMsg_.new_parse_(Gfo_thread_cmd_unzip.KEY).Add("v", Gfo_thread_cmd_unzip.KEY).Add("src", bz2_url.Raw()).Add("trg", xml_url.Raw());
|
||||
Gfo_thread_cmd_unzip unzip_cmd = (Gfo_thread_cmd_unzip)cmd_mgr.Cmd_add(unzip_msg);
|
||||
unzip_cmd.Term_cmd_for_src_(Gfo_thread_cmd_unzip.Term_cmd_for_src_noop); // don't do anything with bz2 after unzip
|
||||
}
|
||||
if (xml_url == null)
|
||||
wiki.Import_cfg().Src_fil_bz2_(bz2_url);
|
||||
else
|
||||
wiki.Import_cfg().Src_fil_xml_(xml_url);
|
||||
return cmd_mgr.Dump_add_many_custom(String_.new_u8(domain), "", "", true);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
/*
|
||||
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.bldrs.installs; import gplx.*; import gplx.xowa.*; import gplx.xowa.bldrs.*;
|
||||
import org.junit.*;
|
||||
public class Xoi_cmd_dumpfile_tst {
|
||||
@Before public void init() {fxt.Clear();} private Xoi_cmd_dumpfile_fxt fxt = new Xoi_cmd_dumpfile_fxt();
|
||||
@Test public void Bz2__unzip() {
|
||||
fxt .Exec_parse_msg("mem/en.wikipedia.org/fil.xml.bz2", "", "unzip")
|
||||
.Test_domain("en.wikipedia.org")
|
||||
.Test_vals("mem/en.wikipedia.org/fil.xml.bz2", "mem/en.wikipedia.org/fil.xml", true)
|
||||
;
|
||||
}
|
||||
@Test public void Bz2__unzip__assert_xml_ext() { // xml ext relies on removing ".bz2" from ".xml.bz2"; if just ".bz2" add an ".xml"
|
||||
fxt .Exec_parse_msg("mem/en.wikipedia.org/fil.bz2", "", "unzip")
|
||||
.Test_vals("mem/en.wikipedia.org/fil.bz2", "mem/en.wikipedia.org/fil.xml", true)
|
||||
;
|
||||
}
|
||||
@Test public void Bz2__direct() {
|
||||
fxt .Exec_parse_msg("mem/en.wikipedia.org/fil.bz2", "", "")
|
||||
.Test_vals("mem/en.wikipedia.org/fil.bz2", null, false)
|
||||
;
|
||||
}
|
||||
@Test public void Xml__unzip_n() {
|
||||
fxt .Exec_parse_msg("mem/en.wikipedia.org/fil.xml", "", "")
|
||||
.Test_vals(null, "mem/en.wikipedia.org/fil.xml", false)
|
||||
;
|
||||
}
|
||||
@Test public void Xml__unzip_y() {
|
||||
fxt .Exec_parse_msg("mem/en.wikipedia.org/fil.xml", "", "")
|
||||
.Test_vals(null, "mem/en.wikipedia.org/fil.xml", false)
|
||||
;
|
||||
}
|
||||
}
|
||||
class Xoi_cmd_dumpfile_fxt {
|
||||
public void Clear() {
|
||||
dumpfile.Clear();
|
||||
} private Xoi_cmd_dumpfile dumpfile = new Xoi_cmd_dumpfile();
|
||||
public Xoi_cmd_dumpfile_fxt Exec_parse_msg(String url, String domain, String args) {
|
||||
GfoMsg m = GfoMsg_.new_parse_("").Add("url", url).Add("domain", domain).Add("args", args);
|
||||
dumpfile.Parse_msg(m);
|
||||
return this;
|
||||
}
|
||||
public Xoi_cmd_dumpfile_fxt Test_vals(String expd_bz2, String expd_xml, boolean expd_unzip) {
|
||||
Eq_url(expd_bz2, dumpfile.Bz2_url());
|
||||
Eq_url(expd_xml, dumpfile.Xml_url());
|
||||
Tfds.Eq(expd_unzip, dumpfile.Bz2_unzip());
|
||||
return this;
|
||||
}
|
||||
public Xoi_cmd_dumpfile_fxt Test_domain(String expd_domain) {
|
||||
Tfds.Eq(expd_domain, String_.new_u8(dumpfile.Domain()));
|
||||
return this;
|
||||
}
|
||||
private void Eq_url(String expd, Io_url actl) {
|
||||
if (expd == null && actl == null) return;
|
||||
else if (expd != null && actl != null) {
|
||||
Tfds.Eq(expd, actl.Raw());
|
||||
}
|
||||
else if (expd == null) throw Err_.new_wo_type("actl should be null", "expd", expd);
|
||||
else if (actl == null) throw Err_.new_wo_type("actl should not be null", "expd", expd);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
/*
|
||||
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.bldrs.installs; import gplx.*; import gplx.xowa.*; import gplx.xowa.bldrs.*;
|
||||
import gplx.gfui.*;
|
||||
import gplx.core.threads.*;
|
||||
class Xoi_cmd_imageMagick_download extends Gfo_thread_cmd_download implements Gfo_thread_cmd {// private static final byte[] Bry_windows_zip = Bry_.new_a7("-windows.zip");
|
||||
// static final String Src_imageMagick = "ftp://ftp.sunet.se/pub/multimedia/graphics/ImageMagick/binaries/";
|
||||
public Xoi_cmd_imageMagick_download(Gfo_usr_dlg usr_dlg, Gfui_kit kit, Io_url trg) {this.Ctor(usr_dlg, kit); this.trg = trg;} Io_url trg;
|
||||
@Override public byte Async_init() { // <a href="ImageMagick-6.8.1-9-Q16-x86-windows.zip">
|
||||
// byte[] raw = xrg.Exec_as_bry(Src_imageMagick);
|
||||
// int find_pos = Bry_finder.Find_fwd(raw, Bry_windows_zip); if (find_pos == Bry_.NotFound) return Fail();
|
||||
// int bgn_pos = Bry_finder.Find_bwd(raw, Byte_ascii.Quote, find_pos); if (bgn_pos == Bry_.NotFound) return Fail();
|
||||
// ++bgn_pos;
|
||||
// int end_pos = Bry_finder.Find_fwd(raw, Byte_ascii.Quote, bgn_pos); if (end_pos == Bry_.NotFound) return Fail();
|
||||
// String src = Src_imageMagick + String_.new_a7(Bry_.Mid(raw, bgn_pos, end_pos));
|
||||
String src = "http://ftp.sunet.se/pub/multimedia/graphics/ImageMagick/binaries/ImageMagick-6.8.8-1-Q16-x86-windows.zip";
|
||||
this.Init("downloading", src, trg);
|
||||
return super.Async_init();
|
||||
}
|
||||
byte Fail() {
|
||||
kit.Ask_ok(GRP_KEY, "windows_not_found", "Could not find Windows binary. Please download ImageMagick directly from the site.");
|
||||
return Gfo_thread_cmd_.Init_cancel_step;
|
||||
}
|
||||
public static final String KEY_imageMagick = "download.imageMagick";
|
||||
static final String GRP_KEY = "xowa.install.cmds.download.imageMagick";
|
||||
}
|
||||
class Xoi_cmd_msg_ok extends Gfo_thread_cmd_base implements Gfo_thread_cmd {
|
||||
public Xoi_cmd_msg_ok(Gfo_usr_dlg usr_dlg, Gfui_kit kit, String msg) {this.msg = msg; this.Ctor(usr_dlg, kit);} private String msg;
|
||||
@Override public boolean Async_term() {
|
||||
kit.Ask_ok("msg_ok", "msg", msg);
|
||||
return true;
|
||||
}
|
||||
public static final String KEY = "msg.ok";
|
||||
}
|
||||
// class Gfo_thread_exec_sync : Gfo_thread_cmd_base, Gfo_thread_cmd {
|
||||
// public Gfo_thread_exec_sync(Gfo_usr_dlg usr_dlg, Gfui_kit kit, Io_url exec_url, String exec_args) {this.Ctor(usr_dlg, kit); this.exec_url = exec_url; this.exec_args = exec_args;} Io_url exec_url; String exec_args;
|
||||
// public override byte Async_init() {
|
||||
// if (!kit.Ask_yes_no(GRP_KEY, "confirm", "You are about to run '~{0}'. Please confirm that XOWA requested you to run '~{0}' and that you trust it to run on your machine.", exec_url.NameAndExt())) {
|
||||
// usr_dlg.Warn_many(GRP_KEY, "confirm.fail", "program was untrusted: ~{0} ~{1}", exec_url.Raw(), exec_args);
|
||||
// return Gfo_thread_cmd_.Init_cancel_all;
|
||||
// }
|
||||
// usr_dlg.Prog_many("exec_sync", "bgn", "running process. please wait; ~{0} ~{1}", exec_url.Raw(), exec_args);
|
||||
// return Gfo_thread_cmd_.Init_ok;
|
||||
// }
|
||||
// public override void Async_run() {
|
||||
// ProcessAdp process = new ProcessAdp().Exe_url_(exec_url).Args_str_(exec_args).Prog_dlg_(usr_dlg);
|
||||
// process.Run_mode_(ProcessAdp.Run_mode_sync_block);
|
||||
// process.Run();
|
||||
// }
|
||||
// public static final String KEY = "exec.sync";
|
||||
// static final String GRP_KEY = "exec.sync";
|
||||
// }
|
||||
149
400_xowa/src/gplx/xowa/bldrs/installs/Xoi_cmd_mgr.java
Normal file
149
400_xowa/src/gplx/xowa/bldrs/installs/Xoi_cmd_mgr.java
Normal file
@@ -0,0 +1,149 @@
|
||||
/*
|
||||
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.bldrs.installs; import gplx.*; import gplx.xowa.*; import gplx.xowa.bldrs.*;
|
||||
import gplx.core.threads.*;
|
||||
public class Xoi_cmd_mgr implements GfoInvkAble {
|
||||
List_adp cmds = List_adp_.new_();
|
||||
public Xoi_cmd_mgr(Xoi_setup_mgr install_mgr) {this.app = install_mgr.App(); this.install_mgr = install_mgr;} private Xoae_app app; Xoi_setup_mgr install_mgr;
|
||||
public Xoae_app App() {return app;}
|
||||
public void Canceled_y_() {canceled = true;} private boolean canceled = false;
|
||||
public boolean Working() {return working;} private boolean working;
|
||||
public void Working_(boolean v) {
|
||||
working = v;
|
||||
app.Bldr__running_(v);
|
||||
}
|
||||
private void Process_async(Gfo_thread_cmd cmd) {
|
||||
byte init_rslt = cmd.Async_init();
|
||||
if (init_rslt == Gfo_thread_cmd_.Init_ok) {
|
||||
cmd.Async_run();
|
||||
int async_sleep_interval = cmd.Async_sleep_interval();
|
||||
boolean async_prog_enabled = cmd.Async_prog_enabled();
|
||||
int async_sleep_sum = 0;
|
||||
while (cmd.Async_running()) {
|
||||
if (canceled) {this.Working_(Bool_.N); return;}
|
||||
if (async_prog_enabled) cmd.Async_prog_run(async_sleep_sum);
|
||||
Thread_adp_.Sleep(async_sleep_interval);
|
||||
async_sleep_sum += async_sleep_interval; // NOTE: this is not exact
|
||||
}
|
||||
}
|
||||
boolean term_pass = cmd.Async_term();
|
||||
if (cmd.Async_next_cmd() != null && init_rslt != Gfo_thread_cmd_.Init_cancel_all && term_pass)
|
||||
Run_async(cmd.Async_next_cmd());
|
||||
else
|
||||
this.Working_(Bool_.N);
|
||||
}
|
||||
private void Run_async(Gfo_thread_cmd cmd) {Thread_adp_.invk_msg_(cmd.Async_key(), this, GfoMsg_.new_cast_(Invk_process_async).Add("v", cmd)).Start();}
|
||||
private void Cmds_run() {
|
||||
if (working) {
|
||||
app.Gui_mgr().Kit().Ask_ok("", "", "An import is in progress. Please wait for it to complete. If you want to do multiple imports at once, see Help:Import/Script.");
|
||||
return;
|
||||
}
|
||||
int cmds_len = cmds.Count();
|
||||
if (cmds_len == 0) return;
|
||||
for (int i = 0; i < cmds_len - 1; i++) {
|
||||
Gfo_thread_cmd cur_cmd = (Gfo_thread_cmd)cmds.Get_at(i);
|
||||
Gfo_thread_cmd nxt_cmd = (Gfo_thread_cmd)cmds.Get_at(i + 1);
|
||||
cur_cmd.Cmd_ctor();
|
||||
cur_cmd.Async_next_cmd_(nxt_cmd);
|
||||
}
|
||||
Gfo_thread_cmd cmd = (Gfo_thread_cmd)cmds.Get_at(0);
|
||||
cmds.Clear();
|
||||
this.Working_(Bool_.Y);
|
||||
app.Bldr__running_(true);
|
||||
this.Run_async(cmd);
|
||||
}
|
||||
Object Dump_add_many(GfoMsg m) {
|
||||
int args_len = m.Args_count();
|
||||
if (args_len < 4) throw Err_.new_wo_type("Please provide the following: wiki name, wiki date, dump_type, and one command; EX: ('simple.wikipedia.org', 'latest', 'pages-articles', 'wiki.download')");
|
||||
String wiki_key = m.Args_getAt(0).Val_to_str_or_empty();
|
||||
String wiki_date = m.Args_getAt(1).Val_to_str_or_empty();
|
||||
String dump_type = m.Args_getAt(2).Val_to_str_or_empty();
|
||||
Gfo_thread_cmd cmd = null;
|
||||
for (int i = 3; i < args_len; i++) {
|
||||
KeyVal kv = m.Args_getAt(i);
|
||||
String kv_val = kv.Val_to_str_or_empty();
|
||||
if (String_.Eq(kv_val, Wiki_cmd_custom))
|
||||
return Dump_add_many_custom(wiki_key, wiki_date, dump_type, false);
|
||||
else {
|
||||
cmd = Dump_cmd_new(wiki_key, wiki_date, dump_type, kv.Val_to_str_or_empty());
|
||||
cmds.Add(cmd);
|
||||
}
|
||||
}
|
||||
return cmd; // return last cmd
|
||||
}
|
||||
public Gfo_thread_cmd Dump_add_many_custom(String wiki_key, String wiki_date, String dump_type, boolean dumpfile_cmd) {
|
||||
String[] custom_cmds = app.Setup_mgr().Dump_mgr().Custom_cmds();
|
||||
int custom_cmds_len = custom_cmds.length;
|
||||
Gfo_thread_cmd cmd = null;
|
||||
for (int j = 0; j < custom_cmds_len; j++) {
|
||||
cmd = Dump_cmd_new(wiki_key, wiki_date, dump_type, custom_cmds[j]);
|
||||
if (dumpfile_cmd) {
|
||||
if (String_.Eq(cmd.Async_key(), Xoi_cmd_wiki_download.Key_wiki_download)) continue; // skip download if wiki.dump_file
|
||||
else if (String_.Eq(cmd.Async_key(), Xoi_cmd_wiki_unzip.KEY_dump)) {
|
||||
Xowe_wiki wiki = app.Wiki_mgr().Get_by_key_or_make(Bry_.new_u8(wiki_key));
|
||||
if (wiki.Import_cfg().Src_fil_xml() != null) continue; // skip unzip if xml exists
|
||||
}
|
||||
else if (String_.Eq(cmd.Async_key(), Xoi_cmd_wiki_import.KEY)) {
|
||||
((Xoi_cmd_wiki_import)cmd).Import_move_bz2_to_done_(false);
|
||||
}
|
||||
}
|
||||
cmds.Add(cmd);
|
||||
}
|
||||
return cmd;
|
||||
}
|
||||
Gfo_thread_cmd Dump_cmd_new(String wiki_key, String wiki_date, String dump_type, String cmd_key) {
|
||||
if (String_.Eq(cmd_key, Xoi_cmd_wiki_download.Key_wiki_download)) return new Xoi_cmd_wiki_download().Ctor_download_(install_mgr, wiki_key, wiki_date, dump_type).Owner_(this);
|
||||
else if (String_.Eq(cmd_key, Xoi_cmd_wiki_unzip.KEY_dump)) return new Xoi_cmd_wiki_unzip(install_mgr, wiki_key, wiki_date, dump_type).Owner_(this);
|
||||
else if (String_.Eq(cmd_key, Xoi_cmd_wiki_import.KEY)) return new Xoi_cmd_wiki_import(install_mgr, wiki_key, wiki_date, dump_type).Owner_(this);
|
||||
else if (String_.Eq(cmd_key, Xoi_cmd_wiki_zip.KEY)) return new Xoi_cmd_wiki_zip(install_mgr, wiki_key, wiki_date, dump_type).Owner_(this);
|
||||
else if (String_.Eq(cmd_key, Xoi_cmd_category2_build.KEY)) return new Xoi_cmd_category2_build(install_mgr, wiki_key).Owner_(this);
|
||||
else if (String_.Eq(cmd_key, Xoi_cmd_category2_page_props.KEY_category2)) return new Xoi_cmd_category2_page_props(install_mgr, wiki_key, wiki_date).Owner_(this);
|
||||
else if (String_.Eq(cmd_key, Xoi_cmd_category2_categorylinks.KEY_category2)) return new Xoi_cmd_category2_categorylinks(install_mgr, wiki_key, wiki_date).Owner_(this);
|
||||
else if (String_.Eq(cmd_key, Xoi_cmd_search2_build.KEY)) return new Xoi_cmd_search2_build(install_mgr, wiki_key).Owner_(this);
|
||||
else throw Err_.new_unhandled(cmd_key);
|
||||
}
|
||||
public static final String[] Wiki_cmds_valid = new String[] {Xoi_cmd_wiki_download.Key_wiki_download, Xoi_cmd_wiki_unzip.KEY_dump, Xoi_cmd_wiki_import.KEY, Xoi_cmd_wiki_zip.KEY, Xoi_cmd_category2_build.KEY, Xoi_cmd_category2_page_props.KEY_category2, Xoi_cmd_category2_categorylinks.KEY_category2};
|
||||
public static final String Wiki_cmd_custom = "wiki.custom", Wiki_cmd_dump_file = "wiki.dump_file";
|
||||
public Gfo_thread_cmd Cmd_add(GfoMsg m) {Gfo_thread_cmd rv = Cmd_new(m); cmds.Add(rv); return rv;}
|
||||
Gfo_thread_cmd Cmd_new(GfoMsg m) {
|
||||
String cmd_key = m.ReadStr("v");
|
||||
if (String_.Eq(cmd_key, Gfo_thread_cmd_download.KEY)) return new Gfo_thread_cmd_download().Init("downloading", m.ReadStr("src"), Bry_fmtr_eval_mgr_.Eval_url(app.Url_cmd_eval(), m.ReadBry("trg"))).Url_eval_mgr_(app.Url_cmd_eval()).Owner_(this).Ctor(app.Usr_dlg(), app.Gui_mgr().Kit());
|
||||
else if (String_.Eq(cmd_key, Gfo_thread_cmd_unzip.KEY)) return new Gfo_thread_cmd_unzip().Url_eval_mgr_(app.Url_cmd_eval()).Owner_(this).Init(app.Usr_dlg(), app.Gui_mgr().Kit(), app.Prog_mgr().App_decompress_bz2(), app.Prog_mgr().App_decompress_zip(), app.Prog_mgr().App_decompress_gz(), Bry_fmtr_eval_mgr_.Eval_url(app.Url_cmd_eval(), m.ReadBry("src")), Bry_fmtr_eval_mgr_.Eval_url(app.Url_cmd_eval(), m.ReadBry("trg")));
|
||||
else if (String_.Eq(cmd_key, Gfo_thread_cmd_replace.KEY)) return new Gfo_thread_cmd_replace().Url_eval_mgr_(app.Url_cmd_eval()).Owner_(this).Init(app.Usr_dlg(), app.Gui_mgr().Kit(), Bry_fmtr_eval_mgr_.Eval_url(app.Url_cmd_eval(), m.ReadBry("fil")));
|
||||
else if (String_.Eq(cmd_key, Xoi_cmd_wiki_image_cfg.KEY_dump)) return new Xoi_cmd_wiki_image_cfg(app, Bry_fmtr_eval_mgr_.Eval_url(app.Url_cmd_eval(), m.ReadBry("fil"))).Owner_(this);
|
||||
else if (String_.Eq(cmd_key, Xoi_cmd_wiki_goto_page.KEY)) return new Xoi_cmd_wiki_goto_page(app, m.ReadStr("v")).Owner_(this);
|
||||
else if (String_.Eq(cmd_key, Xoi_cmd_msg_ok.KEY)) return new Xoi_cmd_msg_ok(app.Usr_dlg(), app.Gui_mgr().Kit(), m.ReadStr("v")).Owner_(this);
|
||||
// else if (String_.Eq(cmd_key, Gfo_thread_exec_sync.KEY)) return new Gfo_thread_exec_sync(app.Usr_dlg(), app.Gui_mgr().Kit(), Bry_fmtr_eval_mgr_.Eval_url(app.Url_cmd_eval(), m.ReadBry("url")), m.ReadStr("args")).Owner_(this);
|
||||
else if (String_.Eq(cmd_key, Xoi_cmd_imageMagick_download.KEY_imageMagick)) return new Xoi_cmd_imageMagick_download(app.Usr_dlg(), app.Gui_mgr().Kit(), Bry_fmtr_eval_mgr_.Eval_url(app.Url_cmd_eval(), m.ReadBry("trg"))).Owner_(this);
|
||||
else if (String_.Eq(cmd_key, Wiki_cmd_dump_file)) return Wiki_cmd_dump_file_make(m);
|
||||
else throw Err_.new_unhandled(cmd_key);
|
||||
}
|
||||
Gfo_thread_cmd Wiki_cmd_dump_file_make(GfoMsg m) {
|
||||
Xoi_cmd_dumpfile dumpfile = new Xoi_cmd_dumpfile().Parse_msg(m);
|
||||
return dumpfile.Exec(this);
|
||||
}
|
||||
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
|
||||
if (ctx.Match(k, Invk_process_async)) Process_async((Gfo_thread_cmd)m.CastObj("v"));
|
||||
else if (ctx.Match(k, Invk_dump_add_many)) return Dump_add_many(m);
|
||||
else if (ctx.Match(k, Invk_cmd_add)) return Cmd_add(m);
|
||||
else if (ctx.Match(k, Invk_run)) Cmds_run();
|
||||
else return GfoInvkAble_.Rv_unhandled;
|
||||
return this;
|
||||
} private static final String Invk_process_async = "process_async", Invk_dump_add_many = "dump_add_many", Invk_run = "run", Invk_cmd_add = "cmd_add";
|
||||
static final String GRP_KEY = "xowa.install_mgr.cmd_mgr";
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
/*
|
||||
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.bldrs.installs; import gplx.*; import gplx.xowa.*; import gplx.xowa.bldrs.*;
|
||||
import gplx.gfui.*;
|
||||
import gplx.core.threads.*; import gplx.xowa.bldrs.*; import gplx.xowa.bldrs.cmds.utils.*;
|
||||
import gplx.xowa.wmfs.dumps.*;
|
||||
class Xoi_cmd_wiki_download extends Gfo_thread_cmd_download implements Gfo_thread_cmd { private Xoi_setup_mgr install_mgr; private String wiki_key, dump_date, dump_type;
|
||||
public Xoi_cmd_wiki_download Ctor_download_(Xoi_setup_mgr install_mgr, String wiki_key, String dump_date, String dump_type) {
|
||||
this.install_mgr = install_mgr;
|
||||
this.wiki_key = wiki_key;
|
||||
this.dump_date = dump_date;
|
||||
this.dump_type = dump_type;
|
||||
this.Owner_(install_mgr);
|
||||
return this;
|
||||
}
|
||||
@gplx.Virtual public String Download_file_ext() {return ".xml.bz2";} // wiki.download is primarily used for dump files; default to .xml.bz2; NOTE: changed from ".xml"; DATE:2013-11-07
|
||||
@Override public String Async_key() {return Key_wiki_download;} public static final String Key_wiki_download = "wiki.download";
|
||||
@Override public byte Async_init() {
|
||||
Xoae_app app = install_mgr.App();
|
||||
Xowm_dump_file dump_file = new Xowm_dump_file(wiki_key, dump_date, dump_type);
|
||||
boolean connected = Xowm_dump_file_.Connect_first(dump_file, install_mgr.Dump_mgr().Server_urls());
|
||||
if (connected)
|
||||
app.Usr_dlg().Note_many("", "", "url: ~{0}", dump_file.File_url());
|
||||
else {
|
||||
if (!Dump_servers_offline_msg_shown) {
|
||||
app.Gui_mgr().Kit().Ask_ok("", "", "all dump servers are offline: ~{0}", String_.AryXtoStr(install_mgr.Dump_mgr().Server_urls()));
|
||||
Dump_servers_offline_msg_shown = true;
|
||||
}
|
||||
}
|
||||
Xowe_wiki wiki = app.Wiki_mgr().Get_by_key_or_make(dump_file.Domain_itm().Domain_bry());
|
||||
Io_url root_dir = wiki.Fsys_mgr().Root_dir();
|
||||
Io_url[] trg_fil_ary = Io_mgr.I.QueryDir_args(root_dir).FilPath_("*." + dump_type + Download_file_ext() + "*").ExecAsUrlAry();
|
||||
Io_url trg = trg_fil_ary.length == 0 ? root_dir.GenSubFil(dump_file.File_name()) : trg_fil_ary[0];
|
||||
this.Ctor(app.Usr_dlg(), app.Gui_mgr().Kit());
|
||||
this.Init("download", dump_file.File_url(), trg);
|
||||
return super.Async_init();
|
||||
}
|
||||
private static boolean Dump_servers_offline_msg_shown = false;
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
/*
|
||||
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.bldrs.installs; import gplx.*; import gplx.xowa.*; import gplx.xowa.bldrs.*;
|
||||
import gplx.core.threads.*;
|
||||
class Xoi_cmd_wiki_goto_page extends Gfo_thread_cmd_base implements Gfo_thread_cmd {
|
||||
public Xoi_cmd_wiki_goto_page(Xoae_app app, String page) {this.app = app; this.page = page; this.Ctor(app.Usr_dlg(), app.Gui_mgr().Kit());} private Xoae_app app; String page;
|
||||
@Override public void Async_run() {kit.New_cmd_sync(this).Invk(GfsCtx.new_(), 0, Invk_goto_page, GfoMsg_.Null);}
|
||||
private void Goto_page(String page) {app.Gui_mgr().Browser_win().Page__navigate_by_url_bar(page);}
|
||||
@Override public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
|
||||
if (ctx.Match(k, Invk_goto_page)) Goto_page(page);
|
||||
else return super.Invk(ctx, ikey, k, m);
|
||||
return this;
|
||||
} private static final String Invk_goto_page = "goto_page";
|
||||
public static final String KEY = "wiki.goto_page";
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
/*
|
||||
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.bldrs.installs; import gplx.*; import gplx.xowa.*; import gplx.xowa.bldrs.*;
|
||||
import gplx.core.threads.*;
|
||||
class Xoi_cmd_wiki_image_cfg extends Gfo_thread_cmd_replace implements Gfo_thread_cmd { public Xoi_cmd_wiki_image_cfg(Xoae_app app, Io_url url) {this.app = app; super.Init(app.Usr_dlg(), app.Gui_mgr().Kit(), url);} private Xoae_app app;
|
||||
@Override public void Async_run() {
|
||||
super.Async_run();
|
||||
app.Cfg_mgr().Set_by_app("app.files.download.enabled", "y");
|
||||
app.Cfg_mgr().Db_save_txt();
|
||||
}
|
||||
static final String GRP_KEY = "xowa.thread.dump.image_cfg";
|
||||
public static final String KEY_dump = "wiki.image_cfg";
|
||||
}
|
||||
117
400_xowa/src/gplx/xowa/bldrs/installs/Xoi_cmd_wiki_import.java
Normal file
117
400_xowa/src/gplx/xowa/bldrs/installs/Xoi_cmd_wiki_import.java
Normal file
@@ -0,0 +1,117 @@
|
||||
/*
|
||||
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.bldrs.installs; import gplx.*; import gplx.xowa.*; import gplx.xowa.bldrs.*;
|
||||
import gplx.core.threads.*; import gplx.xowa.bldrs.*; import gplx.xowa.gui.views.*; import gplx.xowa.bldrs.cmds.utils.*;
|
||||
import gplx.xowa.html.hrefs.*;
|
||||
class Xoi_cmd_wiki_import implements Gfo_thread_cmd {
|
||||
public Xoi_cmd_wiki_import(Xoi_setup_mgr install_mgr, String wiki_key, String wiki_date, String dump_type) {this.install_mgr = install_mgr; this.Owner_(install_mgr); this.wiki_key = wiki_key; this.wiki_date = wiki_date; this.dump_type = dump_type;} private Xoi_setup_mgr install_mgr; String wiki_key, wiki_date, dump_type;
|
||||
public static final String KEY = "wiki.import";
|
||||
public void Cmd_ctor() {}
|
||||
public String Async_key() {return KEY;}
|
||||
public int Async_sleep_interval() {return Gfo_thread_cmd_.Async_sleep_interval_1_second;}
|
||||
public boolean Async_prog_enabled() {return false;}
|
||||
public void Async_prog_run(int async_sleep_sum) {}
|
||||
public byte Async_init() {return Gfo_thread_cmd_.Init_ok;}
|
||||
public boolean Async_term() {
|
||||
install_mgr.App().Usr_dlg().Log_many(GRP_KEY, "import.end", "import.end ~{0} ~{1} ~{2}", wiki_key, wiki_date, dump_type);
|
||||
return true;
|
||||
}
|
||||
public GfoInvkAble Owner() {return owner;} public Xoi_cmd_wiki_import Owner_(GfoInvkAble v) {owner = v; return this;} GfoInvkAble owner;
|
||||
public Gfo_thread_cmd Async_next_cmd() {return next_cmd;} public void Async_next_cmd_(Gfo_thread_cmd v) {next_cmd = v;} Gfo_thread_cmd next_cmd;
|
||||
public void Async_run() {
|
||||
running = true;
|
||||
install_mgr.App().Usr_dlg().Log_many(GRP_KEY, "import.bgn", "import.bgn ~{0} ~{1} ~{2}", wiki_key, wiki_date, dump_type);
|
||||
Thread_adp_.invk_(this.Async_key(), this, Invk_process_async).Start();
|
||||
}
|
||||
public boolean Async_running() {
|
||||
return running;
|
||||
}
|
||||
boolean running;
|
||||
public boolean Import_move_bz2_to_done() {return import_move_bz2_to_done;} public Xoi_cmd_wiki_import Import_move_bz2_to_done_(boolean v) {import_move_bz2_to_done = v; return this;} private boolean import_move_bz2_to_done = true;
|
||||
private void Process_txt(Xob_bldr bldr) {
|
||||
((Xob_cleanup_cmd)bldr.Cmd_mgr().Add_cmd(wiki, Xob_cmd_keys.Key_util_cleanup)).Delete_tdb_(true).Delete_sqlite3_(true);
|
||||
bldr.Cmd_mgr().Add_cmd(wiki, Xob_cmd_keys.Key_tdb_text_init);
|
||||
bldr.Cmd_mgr().Add_cmd(wiki, Xob_cmd_keys.Key_tdb_make_page);
|
||||
bldr.Cmd_mgr().Add_cmd(wiki, Xob_cmd_keys.Key_tdb_make_id);
|
||||
bldr.Cmd_mgr().Add_cmd(wiki, Xob_cmd_keys.Key_tdb_make_search_title);
|
||||
if (wiki.Import_cfg().Category_version() == gplx.xowa.ctgs.Xoa_ctg_mgr.Version_1)
|
||||
bldr.Cmd_mgr().Add_cmd(wiki, Xob_cmd_keys.Key_tdb_make_category);
|
||||
bldr.Cmd_mgr().Add_cmd(wiki, Xob_cmd_keys.Key_tdb_calc_stats);
|
||||
bldr.Cmd_mgr().Add_cmd(wiki, Xob_cmd_keys.Key_tdb_core_term);
|
||||
}
|
||||
private void Process_sql(Xob_bldr bldr) {
|
||||
((Xob_cleanup_cmd)bldr.Cmd_mgr().Add_cmd(wiki, Xob_cmd_keys.Key_util_cleanup)).Delete_tdb_(true).Delete_sqlite3_(true);
|
||||
bldr.Cmd_mgr().Add_cmd(wiki, Xob_cmd_keys.Key_text_init);
|
||||
bldr.Cmd_mgr().Add_cmd(wiki, Xob_cmd_keys.Key_text_page);
|
||||
bldr.Cmd_mgr().Add_cmd(wiki, Xob_cmd_keys.Key_text_css);
|
||||
if (wiki.Import_cfg().Category_version() == gplx.xowa.ctgs.Xoa_ctg_mgr.Version_1) {
|
||||
bldr.Cmd_mgr().Add_cmd(wiki, Xob_cmd_keys.Key_text_cat_core_v1);
|
||||
bldr.Cmd_mgr().Add_cmd(wiki, Xob_cmd_keys.Key_text_cat_core);
|
||||
bldr.Cmd_mgr().Add_cmd(wiki, Xob_cmd_keys.Key_text_cat_link);
|
||||
}
|
||||
if (wiki.Appe().Setup_mgr().Dump_mgr().Search_version() == gplx.xowa.specials.search.Xows_page__search.Version_2)
|
||||
bldr.Cmd_mgr().Add_cmd(wiki, Xob_cmd_keys.Key_text_search_wkr);
|
||||
bldr.Cmd_mgr().Add_cmd(wiki, Xob_cmd_keys.Key_text_term);
|
||||
}
|
||||
private void Process_async() {
|
||||
Xoae_app app = install_mgr.App();
|
||||
app.Usr_dlg().Prog_one("", "", "preparing import: ~{0}", wiki_key);
|
||||
Xob_bldr bldr = app.Bldr();
|
||||
wiki = app.Wiki_mgr().Get_by_key_or_make(Bry_.new_a7(wiki_key));
|
||||
wiki.Init_assert();
|
||||
bldr.Cmd_mgr().Clear();
|
||||
bldr.Pause_at_end_(false);
|
||||
Io_url src_url = wiki.Import_cfg().Src_rdr().Url();
|
||||
if (install_mgr.Dump_mgr().Wiki_storage_type_is_sql())
|
||||
Process_sql(bldr);
|
||||
else
|
||||
Process_txt(bldr);
|
||||
bldr.Run();
|
||||
app.Usr_dlg().Prog_none(GRP_KEY, "clear", ""); app.Usr_dlg().Note_none(GRP_KEY, "clear", "");
|
||||
app.Usere().Available_from_fsys();
|
||||
wiki.Init_needed_(true);
|
||||
wiki.Html_mgr().Page_wtr_mgr().Init_(true);
|
||||
wiki.Init_assert();
|
||||
if (String_.Eq(src_url.Ext(), ".xml")) {
|
||||
if (app.Setup_mgr().Dump_mgr().Delete_xml_file())
|
||||
Io_mgr.I.DeleteFil(src_url);
|
||||
}
|
||||
else if (String_.Eq(src_url.Ext(), ".bz2")) {
|
||||
Io_url trg_fil = app.Fsys_mgr().Wiki_dir().GenSubFil_nest("#dump", "done", src_url.NameAndExt());
|
||||
if (import_move_bz2_to_done)
|
||||
Io_mgr.I.MoveFil_args(src_url, trg_fil, true).Exec();
|
||||
}
|
||||
running = false;
|
||||
wiki.Import_cfg().Src_fil_xml_(null).Src_fil_bz2_(null); // reset file else error when going from Import/Script to Import/List
|
||||
app.Gui_mgr().Kit().New_cmd_sync(this).Invk(GfsCtx.new_(), 0, Invk_open_wiki, GfoMsg_.Null);
|
||||
} private Xowe_wiki wiki;
|
||||
private void Open_wiki(String wiki_key) {
|
||||
Xog_win_itm main_win = install_mgr.App().Gui_mgr().Browser_win();
|
||||
if (main_win.Active_page() == null) return; // will be null when invoked through cmd-line
|
||||
byte[] url = Bry_.Add(wiki.Domain_bry(), Xoh_href_.Bry__wiki, wiki.Props().Main_page());
|
||||
main_win.Page__navigate_by_url_bar(String_.new_u8(url));
|
||||
}
|
||||
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
|
||||
if (ctx.Match(k, Invk_process_async)) Process_async();
|
||||
else if (ctx.Match(k, Invk_owner)) return owner;
|
||||
else if (ctx.Match(k, Invk_open_wiki)) Open_wiki(wiki_key);
|
||||
else return GfoInvkAble_.Rv_unhandled;
|
||||
return this;
|
||||
} private static final String Invk_process_async = "run_async", Invk_owner = "owner", Invk_open_wiki = "open_wiki";
|
||||
static final String GRP_KEY = "xowa.thread.op.build";
|
||||
}
|
||||
129
400_xowa/src/gplx/xowa/bldrs/installs/Xoi_cmd_wiki_tst.java
Normal file
129
400_xowa/src/gplx/xowa/bldrs/installs/Xoi_cmd_wiki_tst.java
Normal file
@@ -0,0 +1,129 @@
|
||||
/*
|
||||
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.bldrs.installs; import gplx.*; import gplx.xowa.*; import gplx.xowa.bldrs.*;
|
||||
import org.junit.*;
|
||||
import gplx.core.consoles.*;
|
||||
import gplx.brys.*; import gplx.core.threads.*; import gplx.xowa.setup.maints.*; import gplx.xowa.xtns.wdatas.imports.*;
|
||||
import gplx.xowa.wikis.domains.*;
|
||||
import gplx.xowa.wmfs.*; import gplx.xowa.wmfs.dumps.*;
|
||||
public class Xoi_cmd_wiki_tst {
|
||||
@Test public void Run() { // MAINT
|
||||
// Bld_import_list(Xow_wmf_api_mgr.Wikis);
|
||||
// Bld_cfg_files(Xow_wmf_api_mgr.Wikis); // NOTE: remember to carry over the wikisource / page / index commands from the existing xowa_build_cfg.gfs; also, only run the xowa_build_cfg.gfs once; DATE:2013-10-15; last run: DATE:2014-09-09
|
||||
}
|
||||
public void Bld_import_list(String... ary) {
|
||||
int ary_len = ary.length;
|
||||
Bry_bfr bfr = Bry_bfr.reset_(255);
|
||||
Wmf_latest_parser parser = new Wmf_latest_parser();
|
||||
Bry_fmtr_arg_time time_fmtr = new Bry_fmtr_arg_time();
|
||||
for (int i = 0; i < ary_len; i++)
|
||||
Bld_import_list_itm2(bfr, parser, time_fmtr, ary, i);
|
||||
Io_mgr.I.SaveFilStr("C:\\temp.txt", bfr.Xto_str());
|
||||
}
|
||||
private void Bld_import_list_itm2(Bry_bfr bfr, Wmf_latest_parser parser, Bry_fmtr_arg_time time_fmtr, String[] ary, int i) {
|
||||
String domain_str = ary[i];
|
||||
byte[] domain_bry = Bry_.new_a7(domain_str);
|
||||
Xow_domain_itm domain_itm = Xow_domain_itm_.parse(domain_bry);
|
||||
byte[] wmf_key_bry = Bry_.Replace(Xow_abrv_wm_.To_abrv(domain_itm), Byte_ascii.Dash, Byte_ascii.Underline);
|
||||
String wmf_key = String_.new_u8(wmf_key_bry);
|
||||
String url = "https://dumps.wikimedia.org/" + wmf_key + "/latest";
|
||||
byte[] latest_html = null;
|
||||
for (int j = 0; j < 5; ++j) {
|
||||
latest_html = Io_mgr.I.DownloadFil_args("", Io_url_.Empty).Exec_as_bry(url);
|
||||
if (latest_html != null) break;
|
||||
Tfds.Write("fail|" + url);
|
||||
if (j == 4) return;
|
||||
}
|
||||
Tfds.Write("pass|" + url);
|
||||
parser.Parse(latest_html);
|
||||
Xowm_dump_file dump_file = new Xowm_dump_file(domain_str, "latest", Xowm_dump_type_.Str__pages_articles);
|
||||
dump_file.Server_url_(Xowm_dump_file_.Server_wmf_https);
|
||||
byte[] pages_articles_key = Bry_.new_a7(wmf_key + "-latest-pages-articles.xml.bz2");
|
||||
Wmf_latest_itm latest_itm = parser.Get_by(pages_articles_key);
|
||||
bfr.Add(domain_bry).Add_byte_pipe();
|
||||
bfr.Add_str(dump_file.File_url()).Add_byte_pipe();
|
||||
bfr.Add(Xow_domain_type_.Get_type_as_bry(domain_itm.Domain_type_id())).Add_byte_pipe();
|
||||
long src_size = latest_itm.Size();
|
||||
bfr.Add_long_variable(src_size).Add_byte_pipe();
|
||||
bfr.Add_str(gplx.ios.Io_size_.To_str(src_size)).Add_byte_pipe();
|
||||
time_fmtr.Seconds_(Math_.Div_safe_as_long(src_size, 1000000)).XferAry(bfr, 0);
|
||||
bfr.Add_byte_pipe();
|
||||
bfr.Add_str(latest_itm.Date().XtoStr_fmt_yyyy_MM_dd_HH_mm());
|
||||
bfr.Add_byte_pipe();
|
||||
bfr.Add_str(dump_file.Dump_date());
|
||||
bfr.Add_byte_nl();
|
||||
}
|
||||
/*
|
||||
private void Bld_import_list_itm(Bry_bfr bfr, Xowm_dump_file dump_file, Bry_fmtr_arg_time time_fmtr, String[] ary, int i) {
|
||||
String itm = ary[i];
|
||||
dump_file.Ctor(itm, "latest", Xowm_dump_type_.Str__pages_articles);
|
||||
int count = 0;
|
||||
while (count++ < 1) {
|
||||
dump_file.Server_url_(Xowm_dump_file_.Server_wmf);
|
||||
if (dump_file.Connect()) break;
|
||||
Tfds.WriteText(String_.Format("retrying: {0} {1}\n", count, dump_file.File_modified()));
|
||||
Thread_adp_.Sleep(15000); // wait for connection to reset
|
||||
}
|
||||
if (count == 10) {
|
||||
Tfds.WriteText(String_.Format("failed: {0}\n", dump_file.File_url()));
|
||||
return;
|
||||
}
|
||||
else
|
||||
Tfds.WriteText(String_.Format("passed: {0}\n", itm));
|
||||
bfr.Add_str(itm).Add_byte_pipe();
|
||||
bfr.Add_str(dump_file.File_url()).Add_byte_pipe();
|
||||
bfr.Add(Xow_domain_type_.Get_type_as_bry(dump_file.Wiki_type().Wiki_tid())).Add_byte_pipe();
|
||||
// Xol_lang_itm lang_itm = Xol_lang_itm_.Get_by_key(wiki_type.Lang_key());
|
||||
// if (lang_itm == null) lang_itm = Xol_lang_itm_.Get_by_key(Xol_lang_.Key_en); // commons, species, meta, etc will have no lang
|
||||
// bfr.Add(lang_itm.Local_name()).Add_byte_pipe();
|
||||
// bfr.Add(lang_itm.Canonical_name()).Add_byte_pipe();
|
||||
long src_size = dump_file.File_len();
|
||||
bfr.Add_long_variable(src_size).Add_byte_pipe();
|
||||
bfr.Add_str(gplx.ios.Io_size_.To_str(src_size)).Add_byte_pipe();
|
||||
time_fmtr.Seconds_(Math_.Div_safe_as_long(src_size, 1000000)).XferAry(bfr, 0);
|
||||
bfr.Add_byte_pipe();
|
||||
bfr.Add_str(dump_file.File_modified().XtoStr_fmt_yyyy_MM_dd_HH_mm());
|
||||
bfr.Add_byte_pipe();
|
||||
// bfr.Add_str(String_.Concat_with_obj(",", (Object[])dump_file.Dump_available_dates()));
|
||||
// bfr.Add_byte_pipe();
|
||||
bfr.Add_str(dump_file.Dump_date());
|
||||
bfr.Add_byte_nl();
|
||||
Thread_adp_.Sleep(1000);
|
||||
}
|
||||
*/
|
||||
public void Bld_cfg_files(String... ary) {
|
||||
Bry_bfr bfr = Bry_bfr.reset_(255);
|
||||
gplx.xowa.bldrs.wiki_cfgs.Xoi_wiki_props_api api = new gplx.xowa.bldrs.wiki_cfgs.Xoi_wiki_props_api();
|
||||
gplx.xowa.bldrs.wiki_cfgs.Xoi_wiki_props_wiki wiki = new gplx.xowa.bldrs.wiki_cfgs.Xoi_wiki_props_wiki();
|
||||
int ary_len = ary.length;
|
||||
for (int i = 0; i < ary_len; i++) {
|
||||
String wiki_domain = ary[i];
|
||||
try {
|
||||
byte[] xml = api.Exec_api(api.Api_src(wiki_domain));
|
||||
wiki.Wiki_domain_(Bry_.new_a7(wiki_domain));
|
||||
api.Parse(wiki, String_.new_u8(xml));
|
||||
api.Build_cfg(bfr, wiki);
|
||||
}
|
||||
catch (Exception e) {
|
||||
Console_adp__sys.I.Write_str_w_nl(Err_.Message_gplx_full(e));
|
||||
}
|
||||
}
|
||||
bfr.Add_str_a7("app.bldr.wiki_cfg_bldr.run;").Add_byte_nl();
|
||||
Io_mgr.I.SaveFilStr("C:\\xowa_build_cfg.gfs", bfr.Xto_str());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
/*
|
||||
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.bldrs.installs; import gplx.*; import gplx.xowa.*; import gplx.xowa.bldrs.*;
|
||||
import gplx.gfui.*;
|
||||
import gplx.core.threads.*;
|
||||
class Xoi_cmd_wiki_unzip extends Gfo_thread_cmd_unzip implements Gfo_thread_cmd { public static final String KEY_dump = "wiki.unzip";
|
||||
public Xoi_cmd_wiki_unzip(Xoi_setup_mgr install_mgr, String wiki_key, String dump_date, String dump_type) {this.install_mgr = install_mgr; this.Owner_(install_mgr); this.wiki_key = wiki_key; this.dump_date = dump_date; this.dump_type = dump_type;} private Xoi_setup_mgr install_mgr; String wiki_key, dump_date, dump_type;
|
||||
@Override public String Async_key() {return KEY_dump;}
|
||||
@Override public byte Async_init() {
|
||||
Xoae_app app = install_mgr.App(); Gfui_kit kit = app.Gui_mgr().Kit();
|
||||
Xowe_wiki wiki = app.Wiki_mgr().Get_by_key_or_make(Bry_.new_u8(wiki_key));
|
||||
Io_url wiki_dir = wiki.Import_cfg().Src_dir();
|
||||
Io_url[] urls = Io_mgr.I.QueryDir_args(wiki_dir).Recur_(false).FilPath_("*.xml.bz2").ExecAsUrlAry();
|
||||
if (urls.length == 0) {
|
||||
kit.Ask_ok(GRP_KEY, "dump.unzip_latest.file_missing", "Could not find a dump file for ~{0} in ~{1}", wiki_key, wiki_dir.Raw());
|
||||
return Gfo_thread_cmd_.Init_cancel_step;
|
||||
}
|
||||
Io_url src = urls[urls.length - 1];
|
||||
Io_url trg = app.Fsys_mgr().Wiki_dir().GenSubFil_nest(wiki_key, src.NameOnly()); // NOTE: NameOnly() will strip trailing .bz2; EX: a.xml.bz2 -> a.xml
|
||||
super.Init(app.Usr_dlg(), app.Gui_mgr().Kit(), app.Prog_mgr().App_decompress_bz2(), app.Prog_mgr().App_decompress_zip(), app.Prog_mgr().App_decompress_gz(), src, trg);
|
||||
this.Term_cmd_for_src_(Term_cmd_for_src_move);
|
||||
this.Term_cmd_for_src_url_(app.Fsys_mgr().Wiki_dir().GenSubFil_nest("#dump", "done", src.NameAndExt()));
|
||||
if (Io_mgr.I.ExistsFil(trg)) {
|
||||
int rslt = kit.Ask_yes_no_cancel(GRP_KEY, "target_exists", "Target file already exists: '~{0}'.\nDo you want to delete it?", trg.Raw());
|
||||
switch (rslt) {
|
||||
case Gfui_dlg_msg_.Btn_yes: Io_mgr.I.DeleteFil(trg); break;
|
||||
case Gfui_dlg_msg_.Btn_no: return Gfo_thread_cmd_.Init_cancel_step;
|
||||
case Gfui_dlg_msg_.Btn_cancel: return Gfo_thread_cmd_.Init_cancel_all;
|
||||
default: throw Err_.new_unhandled(rslt);
|
||||
}
|
||||
}
|
||||
return Gfo_thread_cmd_.Init_ok;
|
||||
}
|
||||
static final String GRP_KEY = "xowa.thread.dump.unzip";
|
||||
}
|
||||
69
400_xowa/src/gplx/xowa/bldrs/installs/Xoi_cmd_wiki_zip.java
Normal file
69
400_xowa/src/gplx/xowa/bldrs/installs/Xoi_cmd_wiki_zip.java
Normal file
@@ -0,0 +1,69 @@
|
||||
/*
|
||||
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.bldrs.installs; import gplx.*; import gplx.xowa.*; import gplx.xowa.bldrs.*;
|
||||
import gplx.core.threads.*;
|
||||
import gplx.xowa.bldrs.*; import gplx.xowa.bldrs.cmds.utils.*;
|
||||
class Xoi_cmd_wiki_zip implements Gfo_thread_cmd {
|
||||
public Xoi_cmd_wiki_zip(Xoi_setup_mgr install_mgr, String wiki_key, String wiki_date, String dump_type) {this.install_mgr = install_mgr; this.Owner_(install_mgr); this.wiki_key = wiki_key; this.wiki_date = wiki_date; this.dump_type = dump_type;} private Xoi_setup_mgr install_mgr; String wiki_key, wiki_date, dump_type;
|
||||
public static final String KEY = "wiki.zip";
|
||||
public void Cmd_ctor() {}
|
||||
public String Async_key() {return KEY;}
|
||||
public int Async_sleep_interval() {return Gfo_thread_cmd_.Async_sleep_interval_1_second;}
|
||||
public boolean Async_prog_enabled() {return false;}
|
||||
public void Async_prog_run(int async_sleep_sum) {}
|
||||
public byte Async_init() {return Gfo_thread_cmd_.Init_ok;}
|
||||
public boolean Async_term() {
|
||||
wiki.Tdb_fsys_mgr().Scan_dirs();
|
||||
install_mgr.App().Usr_dlg().Log_many(GRP_KEY, "zip.end", "zip.end ~{0}", wiki_key);
|
||||
install_mgr.App().Usr_dlg().Prog_many(GRP_KEY, "zip.done", "zip done");
|
||||
return true;
|
||||
}
|
||||
public GfoInvkAble Owner() {return owner;} public Xoi_cmd_wiki_zip Owner_(GfoInvkAble v) {owner = v; return this;} GfoInvkAble owner;
|
||||
public Gfo_thread_cmd Async_next_cmd() {return next_cmd;} public void Async_next_cmd_(Gfo_thread_cmd v) {next_cmd = v;} Gfo_thread_cmd next_cmd;
|
||||
public void Async_run() {
|
||||
running = true;
|
||||
install_mgr.App().Usr_dlg().Log_many(GRP_KEY, "zip.bgn", "zip.bgn ~{0}", wiki_key);
|
||||
Thread_adp_.invk_(this.Async_key(), this, Invk_process_async).Start();
|
||||
}
|
||||
public boolean Async_running() {
|
||||
return running;
|
||||
}
|
||||
boolean running, delete_dirs_page = true, notify_done = true;
|
||||
private void Process_async() {
|
||||
Xoae_app app = install_mgr.App();
|
||||
Xob_bldr bldr = app.Bldr();
|
||||
wiki = app.Wiki_mgr().Get_by_key_or_make(Bry_.new_a7(wiki_key));
|
||||
wiki.Init_assert();
|
||||
bldr.Cmd_mgr().Clear();
|
||||
bldr.Pause_at_end_(false);
|
||||
((Xob_deploy_zip_cmd)bldr.Cmd_mgr().Add_cmd(wiki, Xob_cmd_keys.Key_deploy_zip)).Delete_dirs_page_(delete_dirs_page);
|
||||
bldr.Run();
|
||||
app.Usr_dlg().Prog_none(GRP_KEY, "clear", "");
|
||||
app.Usr_dlg().Note_none(GRP_KEY, "clear", "");
|
||||
running = false;
|
||||
} private Xowe_wiki wiki;
|
||||
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
|
||||
if (ctx.Match(k, Invk_process_async)) Process_async();
|
||||
else if (ctx.Match(k, Invk_owner)) return owner;
|
||||
else if (ctx.Match(k, Invk_delete_dirs_page_)) delete_dirs_page = m.ReadYn("v");
|
||||
else if (ctx.Match(k, Invk_notify_done_)) notify_done = m.ReadYn("v");
|
||||
else return GfoInvkAble_.Rv_unhandled;
|
||||
return this;
|
||||
} private static final String Invk_process_async = "run_async", Invk_owner = "owner", Invk_delete_dirs_page_ = "delete_dirs_page_", Invk_notify_done_ = "notify_done_";
|
||||
private static final String GRP_KEY = "xowa.thread.op.wiki.zip";
|
||||
}
|
||||
98
400_xowa/src/gplx/xowa/bldrs/installs/Xoi_dump_mgr.java
Normal file
98
400_xowa/src/gplx/xowa/bldrs/installs/Xoi_dump_mgr.java
Normal file
@@ -0,0 +1,98 @@
|
||||
/*
|
||||
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.bldrs.installs; import gplx.*; import gplx.xowa.*; import gplx.xowa.bldrs.*;
|
||||
import gplx.ios.*;
|
||||
import gplx.xowa.wmfs.dumps.*;
|
||||
public class Xoi_dump_mgr implements GfoInvkAble {
|
||||
public String[] Server_urls() {return server_urls;} private String[] server_urls = String_.Ary(Xowm_dump_file_.Server_wmf_https, Xowm_dump_file_.Server_your_org, Xowm_dump_file_.Server_c3sl, Xowm_dump_file_.Server_masaryk);
|
||||
public String[] Custom_cmds() {return custom_cmds;} private String[] custom_cmds = String_.Ary(Xoi_cmd_wiki_download.Key_wiki_download, Xoi_cmd_wiki_import.KEY);
|
||||
public byte Data_storage_format() {return data_storage_format;} public Xoi_dump_mgr Data_storage_format_(byte v) {data_storage_format = v; return this;} private byte data_storage_format = gplx.ios.Io_stream_.Tid_gzip;
|
||||
public long Db_text_max() {return db_text_max;} private long db_text_max = (long)3000 * Io_mgr.Len_mb;
|
||||
public long Db_categorylinks_max() {return db_categorylinks_max;} private long db_categorylinks_max = (long)3600 * Io_mgr.Len_mb;
|
||||
public long Db_wikidata_max() {return db_wikidata_max;} private long db_wikidata_max = (long)3600 * Io_mgr.Len_mb;
|
||||
public byte Wiki_storage_type() {return wiki_storage_type;} private byte wiki_storage_type = Wiki_storage_type_sqlite;
|
||||
public boolean Wiki_storage_type_is_sql() {return wiki_storage_type == Wiki_storage_type_sqlite;}
|
||||
public String Db_ns_map() {return db_ns_map;} private String db_ns_map = "Template~Module";
|
||||
public boolean Css_wiki_update() {return css_wiki_update;} private boolean css_wiki_update = true;
|
||||
public boolean Css_commons_download() {return css_commons_download;} private boolean css_commons_download = true; // changed from false to true; DATE:2014-10-19
|
||||
public boolean Delete_xml_file() {return delete_xml_file;} private boolean delete_xml_file = true;
|
||||
public byte Search_version() {return search_version;} private byte search_version = gplx.xowa.specials.search.Xows_page__search.Version_2;
|
||||
public boolean Import_bz2_by_stdout() {return import_bz2_by_stdout;} private boolean import_bz2_by_stdout = true;
|
||||
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
|
||||
if (ctx.Match(k, Invk_server_urls)) return String_.Concat_with_str(",\n", server_urls);
|
||||
else if (ctx.Match(k, Invk_server_urls_)) server_urls = m.ReadStrAryIgnore("v", ",", "\n");
|
||||
else if (ctx.Match(k, Invk_custom_cmds)) return String_.Concat_with_str(",", custom_cmds);
|
||||
else if (ctx.Match(k, Invk_custom_cmds_)) custom_cmds = String_.Ary_filter(m.ReadStrAry("v", ","), Xoi_cmd_mgr.Wiki_cmds_valid);
|
||||
else if (ctx.Match(k, Invk_data_storage_format)) return Io_stream_.Obsolete_to_str(data_storage_format);
|
||||
else if (ctx.Match(k, Invk_data_storage_format_)) data_storage_format = Io_stream_.Obsolete_to_tid(m.ReadStr("v"));
|
||||
else if (ctx.Match(k, Invk_data_storage_format_list)) return Options_data_storage_format_list;
|
||||
else if (ctx.Match(k, Invk_db_text_max)) return db_text_max / Io_mgr.Len_mb;
|
||||
else if (ctx.Match(k, Invk_db_text_max_)) db_text_max = m.ReadLong("v") * Io_mgr.Len_mb;
|
||||
else if (ctx.Match(k, Invk_db_categorylinks_max)) return db_categorylinks_max / Io_mgr.Len_mb;
|
||||
else if (ctx.Match(k, Invk_db_categorylinks_max_)) db_categorylinks_max = m.ReadLong("v") * Io_mgr.Len_mb;
|
||||
else if (ctx.Match(k, Invk_db_wikidata_max)) return db_wikidata_max / Io_mgr.Len_mb;
|
||||
else if (ctx.Match(k, Invk_db_wikidata_max_)) db_wikidata_max = m.ReadLong("v") * Io_mgr.Len_mb;
|
||||
else if (ctx.Match(k, Invk_db_ns_map)) return db_ns_map;
|
||||
else if (ctx.Match(k, Invk_db_ns_map_)) db_ns_map = m.ReadStr("v");
|
||||
else if (ctx.Match(k, Invk_wiki_storage_type)) return Wiki_storage_type_str(wiki_storage_type);
|
||||
else if (ctx.Match(k, Invk_wiki_storage_type_)) wiki_storage_type = Wiki_storage_type_parse(m.ReadStr("v"));
|
||||
else if (ctx.Match(k, Invk_wiki_storage_type_list)) return Options_storage_type_list;
|
||||
else if (ctx.Match(k, Invk_css_wiki_update)) return Yn.Xto_str(css_wiki_update);
|
||||
else if (ctx.Match(k, Invk_css_wiki_update_)) css_wiki_update = m.ReadYn("v");
|
||||
else if (ctx.Match(k, Invk_css_commons_download)) return Yn.Xto_str(css_commons_download);
|
||||
else if (ctx.Match(k, Invk_css_commons_download_)) css_commons_download = m.ReadYn("v");
|
||||
else if (ctx.Match(k, Invk_delete_xml_file)) return Yn.Xto_str(delete_xml_file);
|
||||
else if (ctx.Match(k, Invk_delete_xml_file_)) delete_xml_file = m.ReadYn("v");
|
||||
else if (ctx.Match(k, Invk_search_version)) return Options_search_version_str(search_version);
|
||||
else if (ctx.Match(k, Invk_search_version_)) search_version = Options_search_version_parse(m.ReadStr("v"));
|
||||
else if (ctx.Match(k, Invk_search_version_list)) return Options_search_version_list;
|
||||
else if (ctx.Match(k, Invk_import_bz2_by_stdout)) return Yn.Xto_str(import_bz2_by_stdout);
|
||||
else if (ctx.Match(k, Invk_import_bz2_by_stdout_)) import_bz2_by_stdout = m.ReadYn("v");
|
||||
else return GfoInvkAble_.Rv_unhandled;
|
||||
return this;
|
||||
}
|
||||
private static final String Invk_server_urls = "server_urls", Invk_server_urls_ = "server_urls_", Invk_custom_cmds = "custom_cmds", Invk_custom_cmds_ = "custom_cmds_"
|
||||
, Invk_data_storage_format = "data_storage_format", Invk_data_storage_format_ = "data_storage_format_", Invk_data_storage_format_list = "data_storage_format_list"
|
||||
, Invk_db_text_max = "db_text_max", Invk_db_text_max_ = "db_text_max_", Invk_db_categorylinks_max = "db_categorylinks_max", Invk_db_categorylinks_max_ = "db_categorylinks_max_", Invk_db_wikidata_max = "db_wikidata_max", Invk_db_wikidata_max_ = "db_wikidata_max_"
|
||||
, Invk_db_ns_map = "db_ns_map", Invk_db_ns_map_ = "db_ns_map_"
|
||||
, Invk_wiki_storage_type = "wiki_storage_type", Invk_wiki_storage_type_ = "wiki_storage_type_", Invk_wiki_storage_type_list = "wiki_storage_type_list"
|
||||
, Invk_css_wiki_update = "css_wiki_update", Invk_css_wiki_update_ = "css_wiki_update_"
|
||||
, Invk_css_commons_download = "css_commons_download", Invk_css_commons_download_ = "css_commons_download_"
|
||||
, Invk_delete_xml_file = "delete_xml_file", Invk_delete_xml_file_ = "delete_xml_file_"
|
||||
, Invk_search_version = "search_version", Invk_search_version_ = "search_version_", Invk_search_version_list = "search_version_list"
|
||||
, Invk_import_bz2_by_stdout = "import_bz2_by_stdout", Invk_import_bz2_by_stdout_ = "import_bz2_by_stdout_"
|
||||
;
|
||||
private static KeyVal[] Options_data_storage_format_list = KeyVal_.Ary(KeyVal_.new_(".xdat", "text"), KeyVal_.new_(".gz", "gzip"), KeyVal_.new_(".bz2", "bzip2")); // removed .zip; DATE:2014-05-13; updated aliases; DATE:2014-06-20
|
||||
static final byte Wiki_storage_type_xdat = 1, Wiki_storage_type_sqlite = 2;
|
||||
private static final KeyVal[] Options_storage_type_list = KeyVal_.Ary(KeyVal_.new_("sqlite"), KeyVal_.new_("xdat")); // DEPRECATED: KeyVal_.new_("xdat"); DATE:2015-03-30
|
||||
public static String Wiki_storage_type_str(byte v) {
|
||||
switch (v) {
|
||||
case Xoi_dump_mgr.Wiki_storage_type_xdat : return "xdat";
|
||||
case Xoi_dump_mgr.Wiki_storage_type_sqlite : return "sqlite";
|
||||
default : throw Err_.new_unhandled(v);
|
||||
}
|
||||
}
|
||||
public static byte Wiki_storage_type_parse(String v) {
|
||||
if (String_.Eq(v, "xdat")) return Xoi_dump_mgr.Wiki_storage_type_xdat;
|
||||
else if (String_.Eq(v, "sqlite")) return Xoi_dump_mgr.Wiki_storage_type_sqlite;
|
||||
else throw Err_.new_unhandled(v);
|
||||
}
|
||||
private static final KeyVal[] Options_search_version_list = KeyVal_.Ary(KeyVal_.new_("1"), KeyVal_.new_("2"));
|
||||
public static String Options_search_version_str(byte v) {return Byte_.To_str(v);}
|
||||
public static byte Options_search_version_parse(String v) {return Byte_.parse(v);}
|
||||
}
|
||||
47
400_xowa/src/gplx/xowa/bldrs/installs/Xoi_mirror_parser.java
Normal file
47
400_xowa/src/gplx/xowa/bldrs/installs/Xoi_mirror_parser.java
Normal file
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
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.bldrs.installs; import gplx.*; import gplx.xowa.*; import gplx.xowa.bldrs.*;
|
||||
public class Xoi_mirror_parser {
|
||||
public String[] Parse(String raw_str) {
|
||||
if (String_.Len_eq_0(raw_str)) return String_.Ary_empty;
|
||||
byte[] raw = Bry_.new_u8(raw_str);
|
||||
List_adp rv = List_adp_.new_();
|
||||
int pos = 0;
|
||||
while (true) {
|
||||
int bgn = Bry_finder.Find_fwd(raw, CONST_href_bgn, pos); if (bgn == Bry_.NotFound) break;
|
||||
bgn += CONST_href_bgn.length;
|
||||
int end = Bry_finder.Find_fwd(raw, CONST_href_end, bgn); if (end == Bry_.NotFound) return String_.Ary_empty;
|
||||
byte[] date = Bry_.Mid(raw, bgn, end);
|
||||
pos = end + CONST_href_end.length;
|
||||
if (Bry_.Match(date, CONST_date_parent_dir)) continue;
|
||||
int date_pos_last = date.length - 1;
|
||||
if (date_pos_last == -1) return String_.Ary_empty;
|
||||
if (date[date_pos_last] == Byte_ascii.Slash) date = Bry_.Mid(date, 0, date_pos_last); // trim trailing /; EX: "20130101/" -> "20130101"
|
||||
rv.Add(String_.new_u8(date));
|
||||
}
|
||||
return rv.To_str_ary();
|
||||
} static final byte[] CONST_href_bgn = Bry_.new_a7("<a href=\""), CONST_href_end = Bry_.new_a7("\""), CONST_date_parent_dir = Bry_.new_a7("../");
|
||||
public static String Find_last_lte(String[] ary, String comp) { // assuming sorted ary, find last entry that is lte comp
|
||||
int len = ary.length;
|
||||
for (int i = len - 1; i > -1; i--) {
|
||||
String itm = ary[i];
|
||||
if (CompareAble_.Is_lessOrSame(itm, comp)) return itm;
|
||||
}
|
||||
return "";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
/*
|
||||
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.bldrs.installs; import gplx.*; import gplx.xowa.*; import gplx.xowa.bldrs.*;
|
||||
import org.junit.*;
|
||||
public class Xoi_mirror_parser_tst {
|
||||
@Test public void Basic() {
|
||||
Tst_parse(String_.Concat_lines_nl
|
||||
( "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
|
||||
, "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.1//EN\" \"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd\">"
|
||||
, "<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"en\">"
|
||||
, "<head>"
|
||||
, "<title>Index of /simplewiki/</title>"
|
||||
, "<link rel=\"stylesheet\" type=\"text/css\" href=\"/pub/misc/lighttpd-white-dir.css\" />"
|
||||
, "</head>"
|
||||
, "<body>"
|
||||
, "<h2>Index of /simplewiki/</h2>"
|
||||
, "<div class=\"list\">"
|
||||
, "<table summary=\"Directory Listing\" cellpadding=\"0\" cellspacing=\"0\">"
|
||||
, "<thead><tr><th class=\"n\">Name</th><th class=\"m\">Last Modified</th><th class=\"s\">Size</th><th class=\"t\">Type</th></tr></thead>"
|
||||
, "<tbody>"
|
||||
, "<tr><td class=\"n\"><a href=\"../\">Parent Directory</a>/</td><td class=\"m\"> </td><td class=\"s\">- </td><td class=\"t\">Directory</td></tr>"
|
||||
, "<tr><td class=\"n\"><a href=\"20120516/\">20120516</a>/</td><td class=\"m\">2012-May-17 01:04:39</td><td class=\"s\">- </td><td class=\"t\">Directory</td></tr>"
|
||||
, "<tr><td class=\"n\"><a href=\"20121220/\">20121220</a>/</td><td class=\"m\">2012-Dec-20 20:15:55</td><td class=\"s\">- </td><td class=\"t\">Directory</td></tr>"
|
||||
, "<tr><td class=\"n\"><a href=\"20130214/\">20130214</a>/</td><td class=\"m\">2013-Feb-14 06:28:41</td><td class=\"s\">- </td><td class=\"t\">Directory</td></tr>"
|
||||
, "<tr><td class=\"n\"><a href=\"latest/\">latest</a>/</td><td class=\"m\">2013-Feb-14 06:28:41</td><td class=\"s\">- </td><td class=\"t\">Directory</td></tr>"
|
||||
, "</tbody>"
|
||||
, "</table>"
|
||||
, "</div>"
|
||||
, "<div class=\"foot\">lighttpd</div>"
|
||||
, "</body>"
|
||||
, "</html>"
|
||||
), String_.Ary("20120516", "20121220", "20130214", "latest"));
|
||||
}
|
||||
@Test public void Find_last_lte() {
|
||||
Tst_find_last_lte(String_.Ary("20120516", "20121220", "20130214", "latest"), "20130101", "20121220");
|
||||
Tst_find_last_lte(String_.Ary("20120516", "20121220", "20130214", "latest"), "20120101", "");
|
||||
}
|
||||
private void Tst_parse(String raw, String[] expd) {
|
||||
Xoi_mirror_parser parser = new Xoi_mirror_parser();
|
||||
Tfds.Eq_ary_str(expd, parser.Parse(raw));
|
||||
}
|
||||
private void Tst_find_last_lte(String[] ary, String comp, String expd) {
|
||||
Tfds.Eq(expd, Xoi_mirror_parser.Find_last_lte(ary, comp));
|
||||
}
|
||||
}
|
||||
44
400_xowa/src/gplx/xowa/bldrs/installs/Xoi_setup_mgr.java
Normal file
44
400_xowa/src/gplx/xowa/bldrs/installs/Xoi_setup_mgr.java
Normal file
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
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.bldrs.installs; import gplx.*; import gplx.xowa.*; import gplx.xowa.bldrs.*;
|
||||
import gplx.gfui.*; import gplx.xowa.setup.addons.*;
|
||||
import gplx.xowa.setup.maints.*;
|
||||
public class Xoi_setup_mgr implements GfoInvkAble {
|
||||
public Xoi_setup_mgr(Xoae_app app) {
|
||||
this.app = app;
|
||||
cmd_mgr = new Xoi_cmd_mgr(this);
|
||||
maint_mgr = new Xoa_maint_mgr(app);
|
||||
}
|
||||
public void Init_by_app(Xoae_app app) {
|
||||
addon_mgr.Init_by_app(app);
|
||||
}
|
||||
public Xoae_app App() {return app;} private Xoae_app app;
|
||||
public Xoi_cmd_mgr Cmd_mgr() {return cmd_mgr;} private Xoi_cmd_mgr cmd_mgr;
|
||||
public Xoi_dump_mgr Dump_mgr() {return dump_mgr;} private Xoi_dump_mgr dump_mgr = new Xoi_dump_mgr();
|
||||
public Xoi_addon_mgr Addon_mgr() {return addon_mgr;} private Xoi_addon_mgr addon_mgr = new Xoi_addon_mgr();
|
||||
public Xoa_maint_mgr Maint_mgr() {return maint_mgr;} private Xoa_maint_mgr maint_mgr;
|
||||
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
|
||||
if (ctx.Match(k, Invk_cmds)) return cmd_mgr;
|
||||
else if (ctx.Match(k, Invk_dumps)) return dump_mgr;
|
||||
else if (ctx.Match(k, Invk_addons)) return addon_mgr;
|
||||
else if (ctx.Match(k, Invk_maint)) return maint_mgr;
|
||||
else return GfoInvkAble_.Rv_unhandled;
|
||||
}
|
||||
static final String Invk_cmds = "cmds", Invk_dumps = "dumps", Invk_addons = "addons", Invk_maint = "maint";
|
||||
static final String GRP_KEY = "xowa.setup";
|
||||
}
|
||||
86
400_xowa/src/gplx/xowa/bldrs/installs/Xow_cfg_wiki_core.java
Normal file
86
400_xowa/src/gplx/xowa/bldrs/installs/Xow_cfg_wiki_core.java
Normal file
@@ -0,0 +1,86 @@
|
||||
/*
|
||||
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.bldrs.installs; import gplx.*; import gplx.xowa.*; import gplx.xowa.bldrs.*;
|
||||
public class Xow_cfg_wiki_core {
|
||||
public Xow_cfg_wiki_core(Xowe_wiki wiki) {this.wiki = wiki;} private Xowe_wiki wiki;
|
||||
public void Save() {
|
||||
}
|
||||
public byte[] Build_gfs() {
|
||||
Gfs_bldr wtr = new Gfs_bldr();
|
||||
Xow_wiki_props props = wiki.Props();
|
||||
wtr.Add_proc_init_many(Xowe_wiki.Invk_props).Add_nl();
|
||||
wtr.Add_proc_cont_one(Xow_wiki_props.Invk_bldr_version_).Add_parens_str(props.Bldr_version()).Add_nl();
|
||||
wtr.Add_proc_cont_one(Xow_wiki_props.Invk_main_page_).Add_parens_str(props.Main_page()).Add_nl();
|
||||
wtr.Add_proc_cont_one(Xow_wiki_props.Invk_siteinfo_misc_).Add_parens_str(props.Siteinfo_misc()).Add_nl();
|
||||
wtr.Add_proc_cont_one(Xow_wiki_props.Invk_siteinfo_mainpage_).Add_parens_str(props.Siteinfo_mainpage()).Add_nl();
|
||||
wtr.Add_term_nl();
|
||||
wtr.Add_proc_init_many(Xowe_wiki.Invk_ns_mgr).Add_nl();
|
||||
wtr.Add_proc_cont_one(Xow_ns_mgr.Invk_clear).Add_nl();
|
||||
wtr.Add_proc_cont_one(Xow_ns_mgr.Invk_load).Add_paren_bgn().Add_nl();
|
||||
wtr.Add_quote_xtn_bgn();
|
||||
Xol_csv_parser csv_parser = Xol_csv_parser._;
|
||||
int nms_len = wiki.Ns_mgr().Count();
|
||||
for (int i = 0; i < nms_len; i++) {
|
||||
Xow_ns ns = wiki.Ns_mgr().Ords_get_at(i);
|
||||
wtr.Bfr().Add_int_variable(ns.Id()).Add_byte_pipe().Add_int_fixed(ns.Case_match(), 1).Add_byte_pipe();
|
||||
csv_parser.Save(wtr.Bfr(), ns.Name_txt());
|
||||
wtr.Add_nl();
|
||||
}
|
||||
wtr.Add_quote_xtn_end();
|
||||
wtr.Add_paren_end().Add_term_nl();
|
||||
return wtr.Xto_bry();
|
||||
}
|
||||
public void Load(String raw) {
|
||||
wiki.Appe().Gfs_mgr().Run_str_for(wiki, raw);
|
||||
}
|
||||
public static void Load_ns_(Xow_ns_mgr ns_mgr, byte[] src) {// 10|1|Template
|
||||
int len = src.length; int pos = 0, fld_bgn = 0, fld_idx = 0, row_bgn = 0;
|
||||
int cur_id = Int_.Min_value; byte cur_case_match = Byte_.Max_value_127; byte[] cur_name = Bry_.Empty;
|
||||
Xol_csv_parser csv_parser = Xol_csv_parser._;
|
||||
while (true) {
|
||||
boolean last = pos == len;
|
||||
byte b = last ? Byte_ascii.Nl : src[pos];
|
||||
switch (b) {
|
||||
case Byte_ascii.Pipe:
|
||||
switch (fld_idx) {
|
||||
case 0: cur_id = Bry_.To_int_or(src, fld_bgn, pos, Int_.Min_value); if (cur_id == Int_.Min_value) throw Err_.new_wo_type("failed to load id", "id", String_.new_u8(src, fld_bgn, pos)); break;
|
||||
case 1: cur_case_match = Bry_.To_int_as_byte(src, fld_bgn, pos, Byte_.Max_value_127); if (cur_id == Byte_.Max_value_127) throw Err_.new_wo_type("failed to load match", "id", String_.new_u8(src, fld_bgn, pos)); break;
|
||||
default: throw Err_.new_unhandled(fld_idx);
|
||||
}
|
||||
fld_bgn = pos + 1;
|
||||
++fld_idx;
|
||||
break;
|
||||
case Byte_ascii.Nl:
|
||||
if (pos > row_bgn) { // guard against blank lines
|
||||
cur_name = csv_parser.Load(src, fld_bgn, pos);
|
||||
ns_mgr.Add_new(cur_id, cur_name, cur_case_match, false);
|
||||
}
|
||||
cur_id = Int_.Min_value; cur_case_match = Byte_.Max_value_127;
|
||||
fld_bgn = pos + 1;
|
||||
fld_idx = 0;
|
||||
row_bgn = fld_bgn;
|
||||
break;
|
||||
}
|
||||
if (last) break;
|
||||
++pos;
|
||||
}
|
||||
ns_mgr.Init_w_defaults();
|
||||
}
|
||||
static final String Url_wiki_core_gfs = "wiki_core.gfs";
|
||||
static final String GRP_KEY = "xowa.wiki.cfg.wiki_core";
|
||||
}
|
||||
111
400_xowa/src/gplx/xowa/bldrs/installs/Xow_cfg_wiki_core_tst.java
Normal file
111
400_xowa/src/gplx/xowa/bldrs/installs/Xow_cfg_wiki_core_tst.java
Normal file
@@ -0,0 +1,111 @@
|
||||
/*
|
||||
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.bldrs.installs; import gplx.*; import gplx.xowa.*; import gplx.xowa.bldrs.*;
|
||||
import org.junit.*;
|
||||
public class Xow_cfg_wiki_core_tst {
|
||||
Xow_cfg_wiki_core_fxt fxt = new Xow_cfg_wiki_core_fxt();
|
||||
@Before public void init() {fxt.Clear();}
|
||||
@Test public void Save() {
|
||||
fxt.Save_tst(Xoa_app_.Version, "Main_Page", "Wikipedia|MediaWiki 1.21wmf5|first-letter|", 0, "User test", Const_wiki_core_cfg);
|
||||
}
|
||||
@Test public void Load_and_save() {
|
||||
fxt.Load_and_save_tst(Const_wiki_core_cfg);
|
||||
}
|
||||
@Test public void Load() {
|
||||
fxt.Load_tst(String_.Concat_lines_nl
|
||||
( "ns_mgr.clear.load("
|
||||
, "<:['"
|
||||
, "0|0|" // DEFECT: test that 0 sets case_match to case-sensitive; empty name was causing it to "default" to 1; DATE:2013-01-30
|
||||
, "" // test to make sure blank line doesn't fail
|
||||
, "4|1|Wikipedia" // test to make sure that values are updated after blank line
|
||||
, ""
|
||||
, "']:>"
|
||||
, ");"
|
||||
)
|
||||
, fxt.ns_(Xow_ns_.Id_main , true, "")
|
||||
, fxt.ns_(Xow_ns_.Id_project , false, "Wikipedia")
|
||||
);
|
||||
}
|
||||
public static final String Const_wiki_core_cfg = String_.Concat_lines_nl
|
||||
( "props"
|
||||
, ".bldr_version_('" + Xoa_app_.Version + "')"
|
||||
, ".main_page_('Main_Page')"
|
||||
, ".siteinfo_misc_('Wikipedia|MediaWiki 1.21wmf5|first-letter|')"
|
||||
, ".siteinfo_mainpage_('')"
|
||||
, ";"
|
||||
, "ns_mgr"
|
||||
, ".clear"
|
||||
, ".load("
|
||||
, "<:['"
|
||||
, "-2|1|Media"
|
||||
, "-1|1|Special"
|
||||
, "0|1|"
|
||||
, "1|1|Talk"
|
||||
, "2|0|User test" // NOTE: intentionally changing this to "0|User test" to differ from existing
|
||||
, "3|1|User talk"
|
||||
, "4|1|Wikipedia"
|
||||
, "5|1|Wikipedia talk"
|
||||
, "6|1|File"
|
||||
, "7|1|File talk"
|
||||
, "8|1|MediaWiki"
|
||||
, "9|1|MediaWiki talk"
|
||||
, "10|1|Template"
|
||||
, "11|1|Template talk"
|
||||
, "12|1|Help"
|
||||
, "13|1|Help talk"
|
||||
, "14|1|Category"
|
||||
, "15|1|Category talk"
|
||||
, "100|1|Portal"
|
||||
, "101|1|Portal talk"
|
||||
, "108|1|Book"
|
||||
, "109|1|Book talk"
|
||||
, "828|1|Module"
|
||||
, "829|1|Module talk"
|
||||
, "']:>"
|
||||
, ");"
|
||||
);
|
||||
}
|
||||
class Xow_cfg_wiki_core_fxt {
|
||||
Xoae_app app; Xowe_wiki wiki;
|
||||
public Xowe_wiki Wiki() {return wiki;}
|
||||
public void Clear() {
|
||||
app = Xoa_app_fxt.app_();
|
||||
wiki = Xoa_app_fxt.wiki_tst_(app);
|
||||
}
|
||||
public void Save_tst(String bldr_version, String main_page, String siteinfo_misc, int ns_user_case_match, String ns_user_name, String expd) {
|
||||
wiki.Props().Bldr_version_(Bry_.new_a7(bldr_version)).Main_page_(Bry_.new_a7(main_page)).Siteinfo_misc_(Bry_.new_a7(siteinfo_misc));
|
||||
Xow_ns ns_user = wiki.Ns_mgr().Ids_get_or_null(Xow_ns_.Id_user);
|
||||
ns_user.Case_match_((byte)ns_user_case_match); ns_user.Name_bry_(Bry_.new_a7(ns_user_name));
|
||||
Tfds.Eq_str_lines(expd, String_.new_a7(wiki.Cfg_wiki_core().Build_gfs()));
|
||||
}
|
||||
public void Load_and_save_tst(String raw) {
|
||||
wiki.Cfg_wiki_core().Load(raw);
|
||||
Tfds.Eq_str_lines(raw, String_.new_a7(wiki.Cfg_wiki_core().Build_gfs()));
|
||||
}
|
||||
public Xow_ns ns_(int id, boolean case_match, String name) {return new Xow_ns(id, case_match ? Xow_ns_case_.Id_all : Xow_ns_case_.Id_1st, Bry_.new_u8(name), false);}
|
||||
public void Load_tst(String raw, Xow_ns... expd_ary) {
|
||||
wiki.Cfg_wiki_core().Load(raw);
|
||||
int expd_len = expd_ary.length;
|
||||
for (int i = 0; i < expd_len; i++) {
|
||||
Xow_ns expd = expd_ary[i];
|
||||
Xow_ns actl = wiki.Ns_mgr().Ids_get_or_null(expd.Id());
|
||||
Tfds.Eq(expd.Case_match(), actl.Case_match(), Int_.Xto_str(expd.Id()));
|
||||
Tfds.Eq(expd.Name_str(), actl.Name_str(), Int_.Xto_str(expd.Id()));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -16,7 +16,8 @@ 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.bldrs.langs; import gplx.*; import gplx.xowa.*; import gplx.xowa.bldrs.*;
|
||||
import gplx.xowa.apps.fsys.*; import gplx.xowa.langs.*;
|
||||
import gplx.xowa.apps.fsys.*; import gplx.xowa.apps.langs.*;
|
||||
import gplx.xowa.langs.*;
|
||||
public class Xobc_utl_make_lang implements GfoInvkAble {
|
||||
private final Xoa_lang_mgr lang_mgr; private final Xoa_fsys_mgr fsys_mgr; Xol_mw_lang_parser lang_parser;
|
||||
public Xobc_utl_make_lang(Xoa_lang_mgr lang_mgr, Xoa_fsys_mgr fsys_mgr, Gfo_msg_log msg_log) {
|
||||
|
||||
@@ -16,7 +16,7 @@ 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.bldrs.langs; import gplx.*; import gplx.xowa.*; import gplx.xowa.bldrs.*;
|
||||
import gplx.xowa.langs.*;
|
||||
import gplx.xowa.langs.*; import gplx.xowa.apps.langs.*;
|
||||
public class Xobc_utl_make_lang_kwds implements GfoInvkAble, Xol_lang_transform {
|
||||
private final Xoa_lang_mgr lang_mgr;
|
||||
public Xobc_utl_make_lang_kwds(Xoa_lang_mgr lang_mgr) {this.lang_mgr = lang_mgr;}
|
||||
|
||||
@@ -17,7 +17,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.bldrs.langs; import gplx.*; import gplx.xowa.*; import gplx.xowa.bldrs.*;
|
||||
import org.junit.*;
|
||||
import gplx.intl.*;
|
||||
import gplx.intl.*; import gplx.xowa.parsers.lnkis.*;
|
||||
public class Xol_mw_lang_parser_tst {
|
||||
@Before public void init() {fxt.Clear();} private Xol_mw_lang_parser_fxt fxt = new Xol_mw_lang_parser_fxt();
|
||||
@Test public void Core_keywords() {
|
||||
|
||||
162
400_xowa/src/gplx/xowa/bldrs/sqls/Sql_file_parser.java
Normal file
162
400_xowa/src/gplx/xowa/bldrs/sqls/Sql_file_parser.java
Normal file
@@ -0,0 +1,162 @@
|
||||
/*
|
||||
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.bldrs.sqls; import gplx.*; import gplx.xowa.*; import gplx.xowa.bldrs.*;
|
||||
import gplx.core.flds.*; import gplx.ios.*;
|
||||
public class Sql_file_parser {
|
||||
public Io_url Src_fil() {return src_fil;} public Sql_file_parser Src_fil_(Io_url v) {src_fil = v; return this;} Io_url src_fil;
|
||||
public int Src_len() {return src_len;} public Sql_file_parser Src_len_(int v) {src_len = v; return this;} private int src_len = 8 * Io_mgr.Len_mb;
|
||||
public Io_url_gen Trg_fil_gen() {return trg_fil_gen;} public Sql_file_parser Trg_fil_gen_(Io_url_gen v) {trg_fil_gen = v; return this;} Io_url_gen trg_fil_gen;
|
||||
public int Trg_len() {return trg_len;} public Sql_file_parser Trg_len_(int v) {trg_len = v; return this;} private int trg_len = 4 * Io_mgr.Len_mb;
|
||||
private Sql_fld_itm[] flds_all; private int flds_all_len;
|
||||
Gfo_fld_rdr sql_parser = Gfo_fld_rdr.sql_(); Gfo_fld_wtr fld_wtr = Gfo_fld_wtr.xowa_();
|
||||
static final byte Mode_sql_bgn = 0, Mode_row_bgn = 1, Mode_row_end = 2, Mode_fld = 3, Mode_quote = 4, Mode_escape = 5;
|
||||
public Sql_file_parser Fld_cmd_(Sql_file_parser_cmd v) {this.fld_cmd = v; return this;} Sql_file_parser_cmd fld_cmd;
|
||||
public Sql_file_parser Flds_req_(byte[]... v) {flds_req = v; return this;} private byte[][] flds_req;
|
||||
public Sql_file_parser Flds_req_idx_(int flds_all_len, int... idxs) {
|
||||
new_flds_all(flds_all_len);
|
||||
int len = idxs.length;
|
||||
for (int i = 0; i < len; i++) {
|
||||
int idx = idxs[i];
|
||||
Sql_fld_itm itm = new Sql_fld_itm(idx, Bry_.Empty);
|
||||
flds_all[idx] = itm;
|
||||
}
|
||||
return this;
|
||||
}
|
||||
private void Identify_flds(byte[] raw) {
|
||||
Sql_fld_mgr fld_mgr = new Sql_fld_mgr().Parse(raw);
|
||||
new_flds_all(fld_mgr.Count());
|
||||
int len = flds_req.length;
|
||||
for (int i = 0; i < len; i++) {
|
||||
byte[] fld = flds_req[i];
|
||||
Sql_fld_itm itm = fld_mgr.Get_by_key(fld); if (itm == null) throw Err_.new_wo_type("could not find field", "fld", fld);
|
||||
flds_all[itm.Idx()] = itm;
|
||||
}
|
||||
}
|
||||
private void new_flds_all(int len) {
|
||||
this.flds_all_len = len; // NOTE: must set flds_all_len, else Commit_fld will not be correct;
|
||||
this.flds_all = new Sql_fld_itm[len];
|
||||
}
|
||||
public void Parse(Gfo_usr_dlg usr_dlg) {
|
||||
Io_buffer_rdr rdr = Io_buffer_rdr.Null;
|
||||
try {
|
||||
rdr = Io_buffer_rdr.new_(gplx.ios.Io_stream_rdr_.new_by_url_(src_fil), src_len);
|
||||
Bry_bfr fil_bfr = Bry_bfr.new_(), val_bfr = Bry_bfr.new_();
|
||||
byte[] bfr = rdr.Bfr(); int bfr_len = rdr.Bfr_len(), fld_idx = 0, cur_pos = 0;
|
||||
if (flds_req != null) Identify_flds(bfr);
|
||||
byte mode = Mode_sql_bgn; byte[] decode_regy = sql_parser.Escape_decode();
|
||||
boolean reading_file = true; byte mode_prv = Mode_sql_bgn;
|
||||
Sql_file_parser_data data = new Sql_file_parser_data();
|
||||
while (reading_file) {
|
||||
if (cur_pos + 256 > bfr_len && rdr.Fil_pos() != rdr.Fil_len()) { // buffer 256 characters; can be 0, but erring on side of simplicity
|
||||
rdr.Bfr_load_from(cur_pos);
|
||||
cur_pos = 0;
|
||||
bfr = rdr.Bfr();
|
||||
bfr_len = rdr.Bfr_len();
|
||||
}
|
||||
if (cur_pos == bfr_len) break;
|
||||
byte b = bfr[cur_pos];
|
||||
switch (mode) {
|
||||
case Mode_sql_bgn:
|
||||
cur_pos = Bry_finder.Find_fwd(bfr, Bry_insert_into, cur_pos);
|
||||
if (cur_pos == Bry_.NotFound || cur_pos > bfr_len) {reading_file = false; continue;}
|
||||
cur_pos = Bry_finder.Find_fwd(bfr, Bry_values, cur_pos);
|
||||
if (cur_pos == Bry_.NotFound || cur_pos > bfr_len) throw Err_.new_wo_type("VALUES not found"); // something went wrong;
|
||||
mode = Mode_fld;
|
||||
cur_pos += Bry_values.length;
|
||||
break;
|
||||
case Mode_row_bgn:
|
||||
switch (b) {
|
||||
case Byte_ascii.Paren_bgn: mode = Mode_fld; break;
|
||||
default: throw Err_.new_unhandled(mode);
|
||||
}
|
||||
++cur_pos;
|
||||
break;
|
||||
case Mode_row_end:
|
||||
switch (b) {
|
||||
case Byte_ascii.Nl: break; // ignore \n
|
||||
case Byte_ascii.Comma: mode = Mode_row_bgn; break;
|
||||
case Byte_ascii.Semic: mode = Mode_sql_bgn; break;
|
||||
default: throw Err_.new_unhandled(mode);
|
||||
}
|
||||
++cur_pos;
|
||||
break;
|
||||
case Mode_fld:
|
||||
switch (b) {
|
||||
case Byte_ascii.Apos: mode = Mode_quote; break; // NOTE: never escape apos by doubling; will fail for empty fields; EX: ", '', ''"; DATE:2013-07-06
|
||||
case Byte_ascii.Backslash: mode_prv = mode; mode = Mode_escape; break;
|
||||
default: val_bfr.Add_byte(b); break;
|
||||
case Byte_ascii.Space: case Byte_ascii.Nl: break;
|
||||
case Byte_ascii.Comma:
|
||||
Commit_fld(fld_idx++, val_bfr, fil_bfr, data);
|
||||
break;
|
||||
case Byte_ascii.Paren_end:
|
||||
Commit_fld(fld_idx++, val_bfr, fil_bfr, data);
|
||||
if (!data.Cancel_row())
|
||||
Commit_row(usr_dlg, fil_bfr);
|
||||
fld_idx = 0;
|
||||
mode = Mode_row_end;
|
||||
break;
|
||||
}
|
||||
++cur_pos;
|
||||
break;
|
||||
case Mode_quote:
|
||||
switch (b) {
|
||||
case Byte_ascii.Apos: mode = Mode_fld; break;
|
||||
case Byte_ascii.Backslash: mode_prv = mode; mode = Mode_escape; break;
|
||||
default: val_bfr.Add_byte(b); break;
|
||||
}
|
||||
++cur_pos;
|
||||
break;
|
||||
case Mode_escape:
|
||||
byte escape_val = decode_regy[b];
|
||||
if (escape_val == Byte_ascii.Null) {val_bfr.Add_byte(Byte_ascii.Backslash).Add_byte(b);}
|
||||
else val_bfr.Add_byte(escape_val);
|
||||
mode = mode_prv;
|
||||
++cur_pos;
|
||||
break;
|
||||
default: throw Err_.new_unhandled(mode);
|
||||
}
|
||||
}
|
||||
Io_mgr.I.AppendFilByt(trg_fil_gen.Nxt_url(), fil_bfr.Xto_bry_and_clear());
|
||||
}
|
||||
finally {rdr.Rls();}
|
||||
}
|
||||
private void Commit_row(Gfo_usr_dlg usr_dlg, Bry_bfr fil_bfr) {
|
||||
fil_bfr.Add_byte(Byte_ascii.Nl);
|
||||
if (fil_bfr.Len() > trg_len) {
|
||||
Io_url trg_fil = trg_fil_gen.Nxt_url();
|
||||
usr_dlg.Prog_one(GRP_KEY, "make", "making ~{0}", trg_fil.NameAndExt());
|
||||
Io_mgr.I.AppendFilByt(trg_fil, fil_bfr.Xto_bry_and_clear());
|
||||
}
|
||||
}
|
||||
private void Commit_fld(int fld_idx, Bry_bfr val_bfr, Bry_bfr fil_bfr, Sql_file_parser_data data) {
|
||||
Sql_fld_itm fld = fld_idx < flds_all_len ? flds_all[fld_idx] : null; // handle new flds added by MW, but not supported by XO; EX:hiddencat and pp_sortkey; DATE:2014-04-28
|
||||
if (fld != null) {
|
||||
data.Cancel_row_n_();
|
||||
if (fld_cmd == null) { // no custom cmd; assume append;
|
||||
fld_wtr.Bfr_(fil_bfr);
|
||||
fld_wtr.Write_bry_escape_fld(val_bfr.Bfr(), 0, val_bfr.Len());
|
||||
}
|
||||
else
|
||||
fld_cmd.Exec(val_bfr.Bfr(), fld.Key(), fld_idx, 0, val_bfr.Len(), fil_bfr, data);
|
||||
}
|
||||
val_bfr.Clear();
|
||||
}
|
||||
private static final byte[] Bry_insert_into = Bry_.new_a7("INSERT INTO "), Bry_values = Bry_.new_a7(" VALUES (");
|
||||
private static final String GRP_KEY = "xowa.bldr.sql";
|
||||
}
|
||||
43
400_xowa/src/gplx/xowa/bldrs/sqls/Sql_file_parser_cmd.java
Normal file
43
400_xowa/src/gplx/xowa/bldrs/sqls/Sql_file_parser_cmd.java
Normal file
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
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.bldrs.sqls; import gplx.*; import gplx.xowa.*; import gplx.xowa.bldrs.*;
|
||||
import gplx.core.strings.*;
|
||||
public interface Sql_file_parser_cmd {
|
||||
void Exec(byte[] src, byte[] fld_key, int fld_idx, int fld_bgn, int fld_end, Bry_bfr file_bfr, Sql_file_parser_data data);
|
||||
}
|
||||
class Sql_file_parser_cmd_max_len implements Sql_file_parser_cmd {
|
||||
public void Log_len_(int v) {log_len = v;} private int log_len = 141;
|
||||
public void Log_print(Io_url url) {
|
||||
String_bldr sb = String_bldr_.new_();
|
||||
for (int i = 0; i < log.Count(); i++) {
|
||||
String itm = (String)log.Get_at(i);
|
||||
sb.Add(String_.Len(itm) + "|" + itm + "\n");
|
||||
}
|
||||
Io_mgr.I.SaveFilStr(url, sb.To_str());
|
||||
}
|
||||
public int Max_len() {return max_len;} private int max_len;
|
||||
public void Exec(byte[] src, byte[] fld_key, int fld_idx, int fld_bgn, int fld_end, Bry_bfr file_bfr, Sql_file_parser_data data) {
|
||||
int fld_len = fld_end - fld_bgn;
|
||||
if (fld_len > max_len) max_len = fld_len;
|
||||
if (fld_len > log_len) {
|
||||
log.Add(String_.new_u8(src, fld_bgn, fld_end));
|
||||
}
|
||||
file_bfr.Add_mid(src, fld_bgn, fld_end).Add_byte(Byte_ascii.Pipe);
|
||||
}
|
||||
List_adp log = List_adp_.new_();
|
||||
}
|
||||
23
400_xowa/src/gplx/xowa/bldrs/sqls/Sql_file_parser_data.java
Normal file
23
400_xowa/src/gplx/xowa/bldrs/sqls/Sql_file_parser_data.java
Normal file
@@ -0,0 +1,23 @@
|
||||
/*
|
||||
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.bldrs.sqls; import gplx.*; import gplx.xowa.*; import gplx.xowa.bldrs.*;
|
||||
public class Sql_file_parser_data {
|
||||
public boolean Cancel_row() {return cancel_row;}
|
||||
public Sql_file_parser_data Cancel_row_n_() {cancel_row = false; return this;}
|
||||
public Sql_file_parser_data Cancel_row_y_() {cancel_row = true; return this;} private boolean cancel_row;
|
||||
}
|
||||
73
400_xowa/src/gplx/xowa/bldrs/sqls/Sql_file_parser_tst.java
Normal file
73
400_xowa/src/gplx/xowa/bldrs/sqls/Sql_file_parser_tst.java
Normal file
@@ -0,0 +1,73 @@
|
||||
/*
|
||||
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.bldrs.sqls; import gplx.*; import gplx.xowa.*; import gplx.xowa.bldrs.*;
|
||||
import org.junit.*; import gplx.ios.*;
|
||||
public class Sql_file_parser_tst {
|
||||
Sql_file_parser_fxt fxt = new Sql_file_parser_fxt();
|
||||
@Before public void init() {fxt.Clear();}
|
||||
@Test public void One() {
|
||||
fxt.Init_flds_req_idx_(2, 1).Test_parse("INSERT INTO 'tbl_1' VALUES (1,2);", "2|\n");
|
||||
}
|
||||
@Test public void Many() {
|
||||
fxt.Init_flds_req_idx_(2, 1).Test_parse("INSERT INTO 'tbl_1' VALUES (1,2),(3,4),(5,6);", "2|\n4|\n6|\n");
|
||||
}
|
||||
@Test public void Quote_basic() {
|
||||
fxt.Init_flds_req_idx_(3, 1, 2).Test_parse("INSERT INTO 'tbl_1' VALUES (1,'a','b');", "a|b|\n");
|
||||
}
|
||||
@Test public void Escape_pipe() {
|
||||
fxt.Init_flds_req_idx_(3, 1, 2).Test_parse("INSERT INTO 'tbl_1' VALUES (1,'a|b','c');", "a~pb|c|\n");
|
||||
}
|
||||
@Test public void Escape_nl() {
|
||||
fxt.Init_flds_req_idx_(3, 1, 2).Test_parse("INSERT INTO 'tbl_1' VALUES (1,'a\\nb','c');", "a~nb|c|\n");
|
||||
}
|
||||
@Test public void Escape_tab() {
|
||||
fxt.Init_flds_req_idx_(3, 1, 2).Test_parse("INSERT INTO 'tbl_1' VALUES (1,'a\\tb','c');", "a~tb|c|\n");
|
||||
}
|
||||
@Test public void Escape_backslash() {
|
||||
fxt.Init_flds_req_idx_(3, 1, 2).Test_parse("INSERT INTO 'tbl_1' VALUES (1,'a\\\\b','c');", "a\\b|c|\n");
|
||||
}
|
||||
@Test public void Escape_quote() {
|
||||
fxt.Init_flds_req_idx_(3, 1, 2).Test_parse("INSERT INTO 'tbl_1' VALUES (1,'a\"b','c');", "a\"b|c|\n");
|
||||
}
|
||||
@Test public void Fld_paren_end() {
|
||||
fxt.Init_flds_req_idx_(3, 1, 2).Test_parse("INSERT INTO 'tbl_1' VALUES (1,'Психостимуляторы_(лекарственные_средства)','c');", "Психостимуляторы_(лекарственные_средства)|c|\n");
|
||||
}
|
||||
@Test public void Insert_multiple() {
|
||||
fxt.Init_flds_req_idx_(2, 1).Test_parse("INSERT INTO 'tbl_1' VALUES (1,2);INSERT INTO 'tbl_1' VALUES (3,4)", "2|\n4|\n");
|
||||
}
|
||||
@Test public void Cmds() {
|
||||
Sql_file_parser_cmd_max_len cmd = new Sql_file_parser_cmd_max_len();
|
||||
fxt.Init_flds_req_idx_(2, 1).Init_cmd_(cmd).Test_parse("INSERT INTO 'tbl_1' VALUES (1,'a'),(3,'abc');", "a|\nabc|\n");
|
||||
Tfds.Eq(3, cmd.Max_len());
|
||||
}
|
||||
}
|
||||
class Sql_file_parser_fxt {
|
||||
Sql_file_parser parser = new Sql_file_parser().Src_len_(Io_mgr.Len_kb).Trg_len_(Io_mgr.Len_kb);
|
||||
public Sql_file_parser_fxt Clear() {Io_mgr.I.InitEngine_mem(); return this;}
|
||||
public Sql_file_parser_fxt Init_flds_req_idx_(int flds_all_len, int... idxs) {parser.Flds_req_idx_(flds_all_len, idxs); return this;}
|
||||
public Sql_file_parser_fxt Init_cmd_(Sql_file_parser_cmd cmd) {parser.Fld_cmd_(cmd); return this;}
|
||||
public void Test_parse(String raw_str, String expd) {
|
||||
Io_url src_fil = Io_url_.new_fil_("mem/test.sql");
|
||||
Io_mgr.I.SaveFilBry(src_fil, Bry_.new_u8(raw_str));
|
||||
Io_url trg_fil = Io_url_.new_fil_("mem/test.csv");
|
||||
parser.Src_fil_(src_fil).Trg_fil_gen_(Io_url_gen_.fil_(trg_fil));
|
||||
parser.Parse(Gfo_usr_dlg_.Test());
|
||||
byte[] actl = Io_mgr.I.LoadFilBry(trg_fil);
|
||||
Tfds.Eq(expd, String_.new_u8(actl));
|
||||
}
|
||||
}
|
||||
60
400_xowa/src/gplx/xowa/bldrs/sqls/Sql_fld_mgr.java
Normal file
60
400_xowa/src/gplx/xowa/bldrs/sqls/Sql_fld_mgr.java
Normal file
@@ -0,0 +1,60 @@
|
||||
/*
|
||||
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.bldrs.sqls; import gplx.*; import gplx.xowa.*; import gplx.xowa.bldrs.*;
|
||||
import gplx.ios.*;
|
||||
class Sql_fld_mgr {
|
||||
public int Count() {return hash.Count();}
|
||||
public Sql_fld_itm Get_by_key(String fld) {return Get_by_key(Bry_.new_u8(fld));}
|
||||
public Sql_fld_itm Get_by_key(byte[] fld) {
|
||||
return (Sql_fld_itm)hash.Get_by(fld);
|
||||
} private Ordered_hash hash = Ordered_hash_.new_bry_();
|
||||
public Sql_fld_mgr Parse(byte[] raw) {
|
||||
hash.Clear();
|
||||
int bgn = Bry_finder.Find_fwd(raw, Tkn_create_table); if (bgn == Bry_.NotFound) throw Err_.new_wo_type("could not find 'CREATE TABLE'");
|
||||
bgn = Bry_finder.Find_fwd(raw, Byte_ascii.Nl, bgn); if (bgn == Bry_.NotFound) throw Err_.new_wo_type("could not find new line after 'CREATE TABLE'");
|
||||
bgn += Int_.Const_position_after_char;
|
||||
int end = Bry_finder.Find_fwd(raw, Tkn_unique_index); if (end == Bry_.NotFound) throw Err_.new_wo_type("could not find 'UNIQUE KEY'");
|
||||
end = Bry_finder.Find_bwd(raw, Byte_ascii.Nl, end); if (bgn == Bry_.NotFound) throw Err_.new_wo_type("could not find new line before 'UNIQUE KEY'");
|
||||
Parse_lines(Bry_.Mid(raw, bgn, end));
|
||||
return this;
|
||||
}
|
||||
private void Parse_lines(byte[] raw) {
|
||||
byte[][] lines = Bry_.Split(raw, Byte_ascii.Nl);
|
||||
int lines_len = lines.length;
|
||||
int fld_idx = 0;
|
||||
for (int i = 0; i < lines_len; i++) {
|
||||
byte[] line = lines[i];
|
||||
int bgn = Bry_finder.Find_fwd(line, Byte_ascii.Tick); if (bgn == Bry_.NotFound) continue; // skip blank lines
|
||||
bgn += Int_.Const_position_after_char;
|
||||
int end = Bry_finder.Find_fwd(line, Byte_ascii.Tick, bgn); if (end == Bry_.NotFound) continue; // skip blank lines
|
||||
byte[] key = Bry_.Mid(line, bgn, end);
|
||||
Sql_fld_itm fld = new Sql_fld_itm(fld_idx++, key);
|
||||
hash.Add(fld.Key(), fld);
|
||||
}
|
||||
}
|
||||
private static final byte[]
|
||||
Tkn_create_table = Bry_.new_a7("CREATE TABLE")
|
||||
, Tkn_unique_index = Bry_.new_a7("UNIQUE KEY")
|
||||
;
|
||||
public static final int Not_found = -1;
|
||||
}
|
||||
class Sql_fld_itm {
|
||||
public Sql_fld_itm(int idx, byte[] key) {this.idx = idx; this.key = key;}
|
||||
public int Idx() {return idx;} private int idx;
|
||||
public byte[] Key() {return key;} private byte[] key;
|
||||
}
|
||||
47
400_xowa/src/gplx/xowa/bldrs/sqls/Sql_fld_mgr_tst.java
Normal file
47
400_xowa/src/gplx/xowa/bldrs/sqls/Sql_fld_mgr_tst.java
Normal file
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
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.bldrs.sqls; import gplx.*; import gplx.xowa.*; import gplx.xowa.bldrs.*;
|
||||
import org.junit.*;
|
||||
public class Sql_fld_mgr_tst {
|
||||
Sql_fld_mgr_fxt fxt = new Sql_fld_mgr_fxt();
|
||||
@Test public void Basic() {
|
||||
fxt.Exec_parse(String_.Concat_lines_nl
|
||||
( "ignore"
|
||||
, "CREATE TABLE tbl_0 ("
|
||||
, " `fld_2` int,"
|
||||
, " `fld_1` int,"
|
||||
, " `fld_0` int,"
|
||||
, " UNIQUE KEY idx_0 (fld_2)"
|
||||
, ");"
|
||||
));
|
||||
fxt.Test_count(3);
|
||||
fxt.Exec_get("fld_0", 2);
|
||||
fxt.Exec_get("fld_1", 1);
|
||||
fxt.Exec_get("fld_2", 0);
|
||||
fxt.Exec_get("fld_3", -1);
|
||||
}
|
||||
}
|
||||
class Sql_fld_mgr_fxt {
|
||||
Sql_fld_mgr fld_mgr = new Sql_fld_mgr();
|
||||
public void Exec_parse(String v) {fld_mgr.Parse(Bry_.new_a7(v));}
|
||||
public void Exec_get(String key, int expd) {
|
||||
Sql_fld_itm actl_itm = fld_mgr.Get_by_key(key);
|
||||
Tfds.Eq(expd, actl_itm == null ? Sql_fld_mgr.Not_found : actl_itm.Idx());
|
||||
}
|
||||
public void Test_count(int expd) {Tfds.Eq(expd, fld_mgr.Count());}
|
||||
}
|
||||
@@ -16,7 +16,9 @@ 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.dbs; import gplx.*; import gplx.xowa.*;
|
||||
import gplx.core.primitives.*; import gplx.core.brys.*; import gplx.core.flds.*; import gplx.xowa.bldrs.cmds.ctgs.*; import gplx.xowa.ctgs.*; import gplx.xowa.wikis.data.tbls.*; import gplx.xowa.specials.search.*; import gplx.xowa.tdbs.*;
|
||||
import gplx.core.primitives.*; import gplx.core.brys.*; import gplx.core.flds.*; import gplx.xowa.bldrs.cmds.ctgs.*; import gplx.xowa.ctgs.*; import gplx.xowa.specials.search.*;
|
||||
import gplx.xowa.wikis.data.*; import gplx.xowa.wikis.data.tbls.*;
|
||||
import gplx.xowa.tdbs.*; import gplx.xowa.tdbs.hives.*;
|
||||
public class Xodb_load_mgr_txt implements Xodb_load_mgr {
|
||||
private final Xob_xdat_file tmp_xdat_file = new Xob_xdat_file(); private final Xob_xdat_itm tmp_xdat_itm = new Xob_xdat_itm();
|
||||
private final Xowd_page_itm tmp_page = new Xowd_page_itm();
|
||||
|
||||
@@ -16,8 +16,9 @@ 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.dbs; import gplx.*; import gplx.xowa.*;
|
||||
import gplx.ios.*; import gplx.xowa.tdbs.*;
|
||||
import gplx.ios.*;
|
||||
import gplx.xowa.wikis.data.tbls.*;
|
||||
import gplx.xowa.tdbs.*; import gplx.xowa.tdbs.hives.*;
|
||||
public class Xodb_page_rdr__tdb implements Xodb_page_rdr {
|
||||
private final Xow_ns_mgr ns_mgr; private final Xotdb_fsys_mgr fsys_mgr;
|
||||
private int cur_ns_ord = -1; private Xow_ns cur_ns; private Io_url[] cur_file_ary; private Io_url cur_file; private int cur_file_idx = -1;
|
||||
|
||||
@@ -16,7 +16,9 @@ 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.dbs; import gplx.*; import gplx.xowa.*;
|
||||
import gplx.xowa.wikis.domains.*; import gplx.xowa.tdbs.*; import gplx.xowa.wikis.data.tbls.*;
|
||||
import gplx.xowa.wikis.domains.*; import gplx.xowa.wikis.data.tbls.*;
|
||||
import gplx.xowa.parsers.utils.*;
|
||||
import gplx.xowa.tdbs.*; import gplx.xowa.tdbs.hives.*;
|
||||
public class Xodb_save_mgr_txt implements Xodb_save_mgr {
|
||||
public Xodb_save_mgr_txt(Xowe_wiki wiki, Xodb_load_mgr_txt load_mgr) {
|
||||
this.wiki = wiki;
|
||||
@@ -108,3 +110,12 @@ public class Xodb_save_mgr_txt implements Xodb_save_mgr {
|
||||
private Xowd_page_itm tmp_page = new Xowd_page_itm();
|
||||
public static final int File_idx_unknown = -1;
|
||||
}
|
||||
class Bry_comparer_fld_last implements gplx.lists.ComparerAble {
|
||||
public int compare(Object lhsObj, Object rhsObj) {
|
||||
byte[] lhs = (byte[])lhsObj, rhs = (byte[])rhsObj;
|
||||
int lhs_bgn = Bry_finder.Find_bwd(lhs, Byte_ascii.Pipe); if (lhs_bgn == Bry_.NotFound) lhs_bgn = -1;
|
||||
int rhs_bgn = Bry_finder.Find_bwd(rhs, Byte_ascii.Pipe); if (rhs_bgn == Bry_.NotFound) rhs_bgn = -1;
|
||||
return Bry_.Compare(lhs, lhs_bgn + 1, lhs.length, rhs, rhs_bgn + 1, rhs.length);
|
||||
}
|
||||
public static final Bry_comparer_fld_last _ = new Bry_comparer_fld_last();
|
||||
}
|
||||
|
||||
67
400_xowa/src/gplx/xowa/files/Xoa_repo_mgr.java
Normal file
67
400_xowa/src/gplx/xowa/files/Xoa_repo_mgr.java
Normal file
@@ -0,0 +1,67 @@
|
||||
/*
|
||||
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.files; import gplx.*; import gplx.xowa.*;
|
||||
import gplx.xowa.apps.fsys.*; import gplx.xowa.files.exts.*; import gplx.xowa.files.repos.*;
|
||||
public class Xoa_repo_mgr implements GfoInvkAble {
|
||||
private final Xoa_fsys_mgr app_fsys; private final Xof_rule_mgr ext_rule_mgr;
|
||||
public Xoa_repo_mgr(Xoa_fsys_mgr app_fsys, Xof_rule_mgr ext_rule_mgr) {this.app_fsys = app_fsys; this.ext_rule_mgr = ext_rule_mgr;}
|
||||
public int Count() {return hash.Count();}
|
||||
public Xof_repo_itm Get_at(int i) {return (Xof_repo_itm)hash.Get_at(i);}
|
||||
public Xof_repo_itm Get_by(byte[] key) {return (Xof_repo_itm)hash.Get_by(key);}
|
||||
public Xof_repo_itm Get_by_primary(byte[] key) {
|
||||
int len = hash.Count();
|
||||
for (int i = 0; i < len; i++) {
|
||||
Xof_repo_itm repo = (Xof_repo_itm)hash.Get_at(i);
|
||||
if (Bry_.Eq(key, repo.Wiki_domain()) && repo.Primary()) return repo;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
public Xof_repo_itm Get_by_wmf_fsys(byte[] key) {
|
||||
int len = hash.Count();
|
||||
for (int i = 0; i < len; i++) {
|
||||
Xof_repo_itm repo = (Xof_repo_itm)hash.Get_at(i);
|
||||
if (Bry_.Eq(key, repo.Wiki_domain()) && repo.Wmf_fsys()) return repo;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
public Xof_repo_itm Get_by_wiki_key(byte[] key) {
|
||||
int len = hash.Count();
|
||||
for (int i = 0; i < len; i++) {
|
||||
Xof_repo_itm repo = (Xof_repo_itm)hash.Get_at(i);
|
||||
if (Bry_.Eq(key, repo.Wiki_domain())) return repo;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
public Xof_repo_itm Add(Xof_repo_itm itm) {hash.Add(itm.Key(), itm); return itm;} private Ordered_hash hash = Ordered_hash_.new_bry_();
|
||||
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
|
||||
if (ctx.Match(k, Invk_set)) return Set(m.ReadStr("key"), m.ReadStr("url"), m.ReadStr("wiki"));
|
||||
else return GfoInvkAble_.Rv_unhandled;
|
||||
} private static final String Invk_set = "set";
|
||||
public Xof_repo_itm Set(String key, String url_str, String wiki) {
|
||||
byte[] key_bry = Bry_.new_u8(key);
|
||||
Xof_repo_itm itm = (Xof_repo_itm)hash.Get_by(key_bry);
|
||||
byte[] wiki_domain = Bry_.new_u8(wiki);
|
||||
if (itm == null) {
|
||||
itm = new Xof_repo_itm(key_bry, app_fsys, ext_rule_mgr, wiki_domain);
|
||||
this.Add(itm);
|
||||
}
|
||||
itm.Root_str_(url_str);
|
||||
itm.Wiki_domain_(wiki_domain);
|
||||
return itm;
|
||||
}
|
||||
}
|
||||
50
400_xowa/src/gplx/xowa/files/Xof_cfg_download.java
Normal file
50
400_xowa/src/gplx/xowa/files/Xof_cfg_download.java
Normal file
@@ -0,0 +1,50 @@
|
||||
/*
|
||||
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.files; import gplx.*; import gplx.xowa.*;
|
||||
public class Xof_cfg_download implements GfoInvkAble {
|
||||
public Xof_cfg_download() {
|
||||
this.enabled = true; // CFG: set to false b/c some tests only do parsing [[File:A.png]] and repos are not set up
|
||||
this.redownload = Redownload_none; // CFG: set to none to be as conservative as possible
|
||||
}
|
||||
public boolean Enabled() {return enabled;} public Xof_cfg_download Enabled_(boolean v) {enabled = v; return this;} private boolean enabled;
|
||||
public byte Redownload() {return redownload;} public Xof_cfg_download Redownload_(byte v) {redownload = v; return this;} private byte redownload;
|
||||
|
||||
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
|
||||
if (ctx.Match(k, Invk_enabled_)) enabled = m.ReadYn("v");
|
||||
else if (ctx.Match(k, Invk_redownload)) return Redownload_to_str_(redownload);
|
||||
else if (ctx.Match(k, Invk_redownload_)) redownload = Redownload_parse_(m.ReadStr("v"));
|
||||
else if (ctx.Match(k, Invk_redownload_toggle)) redownload = redownload == Redownload_none ? Redownload_missing : Redownload_none;
|
||||
else return GfoInvkAble_.Rv_unhandled;
|
||||
return this;
|
||||
} private static final String Invk_enabled_ = "enabled_", Invk_redownload = "redownload", Invk_redownload_ = "redownload_", Invk_redownload_toggle = "redownload_toggle";
|
||||
byte Redownload_parse_(String s) {
|
||||
if (String_.Eq(s, "none")) return Redownload_none;
|
||||
else if (String_.Eq(s, "missing")) return Redownload_missing;
|
||||
else if (String_.Eq(s, "all")) return Redownload_all;
|
||||
else throw Err_.new_unhandled(s);
|
||||
}
|
||||
public static final byte Redownload_none = 0, Redownload_missing = 1, Redownload_all = 2;
|
||||
String Redownload_to_str_(byte v) {
|
||||
switch (v) {
|
||||
case Redownload_none: return "none";
|
||||
case Redownload_missing: return "missing";
|
||||
case Redownload_all: return "all";
|
||||
default: throw Err_.new_unhandled(v);
|
||||
}
|
||||
}
|
||||
}
|
||||
45
400_xowa/src/gplx/xowa/files/Xof_file_mgr.java
Normal file
45
400_xowa/src/gplx/xowa/files/Xof_file_mgr.java
Normal file
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
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.files; import gplx.*; import gplx.xowa.*;
|
||||
import gplx.dbs.*; import gplx.xowa2.files.commons.*; import gplx.xowa.xtns.math.*;
|
||||
import gplx.xowa.wmfs.*; import gplx.xowa.files.exts.*; import gplx.xowa.files.caches.*; import gplx.xowa.files.imgs.*;
|
||||
public class Xof_file_mgr implements GfoInvkAble {
|
||||
public Xoa_repo_mgr Repo_mgr() {return repo_mgr;} private Xoa_repo_mgr repo_mgr;
|
||||
public Xof_img_mgr Img_mgr() {return img_mgr;} private final Xof_img_mgr img_mgr = new Xof_img_mgr();
|
||||
public Xof_cache_mgr Cache_mgr() {return cache_mgr;} private Xof_cache_mgr cache_mgr;
|
||||
public Xof_math_mgr Math_mgr() {return math_mgr;} private final Xof_math_mgr math_mgr = new Xof_math_mgr();
|
||||
public Xof_rule_mgr Ext_rules() {return ext_rules;} private final Xof_rule_mgr ext_rules = new Xof_rule_mgr();
|
||||
public Xoa_wmf_mgr Wmf_mgr() {return wmf_mgr;} private Xoa_wmf_mgr wmf_mgr;
|
||||
public void Ctor_by_app(Xoae_app app) {
|
||||
Gfo_usr_dlg usr_dlg = app.Usr_dlg();
|
||||
this.cache_mgr = new Xof_cache_mgr(usr_dlg, app.Wiki_mgr(), repo_mgr);
|
||||
this.repo_mgr = new Xoa_repo_mgr(app.Fsys_mgr(), ext_rules);
|
||||
this.wmf_mgr = new Xoa_wmf_mgr(usr_dlg, app.Wiki_mgr());
|
||||
img_mgr.Init_by_app(app.Wmf_mgr(), app.Prog_mgr());
|
||||
math_mgr.Init_by_app(app);
|
||||
}
|
||||
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
|
||||
if (ctx.Match(k, Invk_repos)) return repo_mgr;
|
||||
else if (ctx.Match(k, Invk_img_mgr)) return img_mgr;
|
||||
else if (ctx.Match(k, Invk_ext_rules)) return ext_rules;
|
||||
else if (ctx.Match(k, Invk_math)) return math_mgr;
|
||||
else if (ctx.Match(k, Invk_download)) return wmf_mgr; // NOTE: do not rename "download" to wmf_mgr
|
||||
else if (ctx.Match(k, Invk_cache_mgr)) return cache_mgr;
|
||||
else return GfoInvkAble_.Rv_unhandled;
|
||||
} private static final String Invk_repos = "repos", Invk_img_mgr= "img_mgr", Invk_ext_rules = "ext_rules", Invk_math = "math", Invk_download = "download", Invk_cache_mgr = "cache_mgr";
|
||||
}
|
||||
@@ -18,6 +18,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
package gplx.xowa.files; import gplx.*; import gplx.xowa.*;
|
||||
import gplx.ios.*;
|
||||
import gplx.xowa.files.gui.*; import gplx.xowa.files.repos.*;
|
||||
import gplx.xowa.parsers.lnkis.*;
|
||||
public class Xof_fsdb_itm implements Xof_file_itm {
|
||||
private int lnki_upright_patch;
|
||||
public byte[] Lnki_wiki_abrv() {return lnki_wiki_abrv;} private byte[] lnki_wiki_abrv;
|
||||
|
||||
@@ -18,6 +18,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
package gplx.xowa.files; import gplx.*; import gplx.xowa.*;
|
||||
import gplx.xowa.wikis.domains.*;
|
||||
import gplx.xowa.files.repos.*;
|
||||
import gplx.xowa.parsers.lnkis.*;
|
||||
public class Xof_fsdb_itm_fxt {
|
||||
private byte[] wiki_abrv;
|
||||
private byte[] lnki_ttl;
|
||||
|
||||
@@ -16,6 +16,7 @@ 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.files; import gplx.*; import gplx.xowa.*;
|
||||
import gplx.xowa.parsers.lnkis.*;
|
||||
public class Xof_img_size {
|
||||
public int Html_w() {return html_w;} private int html_w;
|
||||
public int Html_h() {return html_h;} private int html_h;
|
||||
|
||||
@@ -16,7 +16,7 @@ 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.files; import gplx.*; import gplx.xowa.*;
|
||||
import org.junit.*; import gplx.xowa.files.*;
|
||||
import org.junit.*; import gplx.xowa.files.*; import gplx.xowa.parsers.lnkis.*;
|
||||
public class Xof_img_size_tst {
|
||||
private final Xof_img_size_fxt fxt = new Xof_img_size_fxt();
|
||||
@Before public void init() {
|
||||
|
||||
@@ -16,7 +16,10 @@ 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.files; import gplx.*; import gplx.xowa.*;
|
||||
import gplx.core.primitives.*;
|
||||
import gplx.xowa.files.gui.*; import gplx.xowa.files.repos.*;
|
||||
import gplx.xowa.tdbs.metas.*;
|
||||
import gplx.xowa.parsers.utils.*;
|
||||
public class Xof_xfer_itm implements Xof_file_itm {
|
||||
public Xof_xfer_itm() {
|
||||
lnki_type = orig_repo_id = Byte_.Max_value_127;
|
||||
|
||||
@@ -16,7 +16,8 @@ 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.files; import gplx.*; import gplx.xowa.*;
|
||||
import gplx.gfui.*;
|
||||
import gplx.core.primitives.*;
|
||||
import gplx.gfui.*; import gplx.xowa.parsers.lnkis.*;
|
||||
public class Xof_xfer_itm_ {
|
||||
public static void Calc_xfer_size(Int_2_ref rv, byte lnki_type, int thumb_default_w, int file_w, int file_h, int lnki_w, int lnki_h, boolean lnki_thumb, double lnki_upright, Xof_ext ext, int exec_tid) {
|
||||
boolean ext_is_svg = ext.Id_is_svg();
|
||||
|
||||
@@ -16,8 +16,7 @@ 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.files; import gplx.*; import gplx.xowa.*;
|
||||
import org.junit.*;
|
||||
import gplx.gfui.*; import gplx.xowa.files.*;
|
||||
import org.junit.*; import gplx.core.primitives.*; import gplx.gfui.*; import gplx.xowa.files.*; import gplx.xowa.parsers.lnkis.*;
|
||||
public class Xof_xfer_itm_tst {
|
||||
@Before public void init() {fxt.ini();} Xof_xfer_itm_fxt fxt = new Xof_xfer_itm_fxt();
|
||||
@Test public void Box() {tst_Calc_view("40,50" , "40,40" , "40,40");} // EX:[[File:Crystal Clear app kedit.svg|50x40px]]
|
||||
|
||||
@@ -19,6 +19,7 @@ package gplx.xowa.files; import gplx.*; import gplx.xowa.*;
|
||||
import gplx.dbs.*; import gplx.dbs.cfgs.*;
|
||||
import gplx.xowa.files.repos.*; import gplx.xowa.files.origs.*;
|
||||
import gplx.fsdb.*; import gplx.fsdb.meta.*; import gplx.xowa.files.fsdb.*;
|
||||
import gplx.xowa.tdbs.metas.*;
|
||||
public class Xow_file_mgr implements GfoInvkAble {
|
||||
private Xof_wkr_mgr wkr_mgr;
|
||||
public Xow_file_mgr(Xowe_wiki wiki) {
|
||||
|
||||
@@ -16,7 +16,7 @@ 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.files.fsdb.tsts; import gplx.*; import gplx.xowa.*; import gplx.xowa.files.*; import gplx.xowa.files.fsdb.*;
|
||||
import org.junit.*;
|
||||
import org.junit.*; import gplx.xowa.parsers.lnkis.*;
|
||||
public class Xof_file_ext__png_tst {
|
||||
@Before public void init() {fxt.Reset();} private final Xof_file_fxt fxt = new Xof_file_fxt();
|
||||
@After public void term() {fxt.Rls();}
|
||||
|
||||
@@ -19,6 +19,7 @@ package gplx.xowa.files.fsdb.tsts; import gplx.*; import gplx.xowa.*; import gpl
|
||||
import gplx.fsdb.*; import gplx.fsdb.meta.*; import gplx.dbs.*; import gplx.xowa.files.origs.*; import gplx.xowa.files.bins.*; import gplx.xowa.files.cnvs.*; import gplx.xowa.files.exts.*; import gplx.xowa.files.gui.*;
|
||||
import gplx.xowa.wikis.domains.*; import gplx.xowa.files.repos.*; import gplx.xowa.wikis.data.*;
|
||||
import gplx.fsdb.data.*;
|
||||
import gplx.xowa.parsers.lnkis.*;
|
||||
class Xof_file_fxt {
|
||||
private Xoae_app app; private Xof_fsdb_mgr__sql fsdb_mgr; private Xowe_wiki wiki; private Xof_orig_mgr orig_mgr;
|
||||
private final Fsd_thm_itm tmp_thm = Fsd_thm_itm.new_(); private final Fsd_img_itm tmp_img = new Fsd_img_itm();
|
||||
|
||||
@@ -18,6 +18,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
package gplx.xowa.files.gui; import gplx.*; import gplx.xowa.*; import gplx.xowa.files.*;
|
||||
import gplx.xowa.xtns.gallery.*;
|
||||
import gplx.xowa.files.fsdb.*; import gplx.xowa.gui.views.*;
|
||||
import gplx.xowa.parsers.lnkis.*;
|
||||
public class Js_img_mgr {
|
||||
public static void Update_img(Xoa_page page, Xog_js_wkr js_wkr, Xof_file_itm itm) {
|
||||
Js_img_mgr.Update_img(page, js_wkr, itm.Html_img_wkr(), itm.Html_uid(), itm.Lnki_type(), itm.Html_elem_tid(), itm.Html_w(), itm.Html_h(), itm.Html_view_url(), itm.Orig_w(), itm.Orig_h(), itm.Html_orig_url(), itm.Orig_ttl(), itm.Html_gallery_mgr_h());
|
||||
|
||||
@@ -19,6 +19,7 @@ package gplx.xowa.files.origs; import gplx.*; import gplx.xowa.*; import gplx.xo
|
||||
import org.junit.*;
|
||||
import gplx.dbs.*; import gplx.xowa.*;
|
||||
import gplx.xowa.files.*; import gplx.xowa.files.fsdb.*;
|
||||
import gplx.xowa.parsers.lnkis.*;
|
||||
public class Xof_orig_tbl_tst {
|
||||
@Before public void init() {fxt.Clear();} private Xof_orig_tbl_fxt fxt = new Xof_orig_tbl_fxt();
|
||||
@Test public void Select_in() {
|
||||
|
||||
@@ -18,6 +18,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
package gplx.xowa.files.origs; import gplx.*; import gplx.xowa.*; import gplx.xowa.files.*;
|
||||
import gplx.core.flds.*;
|
||||
import gplx.dbs.*; import gplx.xowa.files.fsdb.*;
|
||||
import gplx.xowa.tdbs.metas.*;
|
||||
public class Xof_orig_wkr__xo_meta implements Xof_orig_wkr {
|
||||
private final Io_url wiki_meta_dir; private final byte dir_spr_byte; private final Bry_bfr url_bfr = Bry_bfr.new_(255);
|
||||
private final Gfo_fld_rdr meta_rdr = Gfo_fld_rdr.xowa_(); private final Xof_meta_thumb_parser parser = new Xof_meta_thumb_parser();
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
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.files.repos; import gplx.*; import gplx.xowa.*; import gplx.xowa.files.*;
|
||||
import gplx.xowa.parsers.utils.*;
|
||||
public class Xofw_file_finder_rslt {
|
||||
public byte[] Ttl() {return ttl;} private byte[] ttl;
|
||||
public byte[] Redirect() {return redirect;} private byte[] redirect;
|
||||
public int Repo_idx() {return repo_idx;} private int repo_idx;
|
||||
public byte[] Repo_wiki_key() {return repo_wiki_key;} private byte[] repo_wiki_key;
|
||||
public void Init(byte[] ttl) {
|
||||
this.ttl = ttl; redirect = Xop_redirect_mgr.Redirect_null_bry; repo_wiki_key = null; repo_idx = Byte_.Max_value_127;
|
||||
}
|
||||
public void Done(int repo_idx, byte[] repo_wiki_key, byte[] redirect) {
|
||||
this.repo_idx = repo_idx; this.repo_wiki_key = repo_wiki_key; this.redirect = redirect;
|
||||
}
|
||||
}
|
||||
23
400_xowa/src/gplx/xowa/files/repos/Xofw_wiki_finder.java
Normal file
23
400_xowa/src/gplx/xowa/files/repos/Xofw_wiki_finder.java
Normal file
@@ -0,0 +1,23 @@
|
||||
/*
|
||||
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.files.repos; import gplx.*; import gplx.xowa.*; import gplx.xowa.files.*;
|
||||
import gplx.xowa.wikis.*; import gplx.xowa.files.*; import gplx.xowa.files.repos.*;
|
||||
public interface Xofw_wiki_finder {
|
||||
void Find(List_adp repo_pairs, Xof_xfer_itm file);
|
||||
boolean Locate(Xofw_file_finder_rslt rv, List_adp repo_pairs, byte[] ttl_bry);
|
||||
}
|
||||
73
400_xowa/src/gplx/xowa/files/repos/Xofw_wiki_wkr_base.java
Normal file
73
400_xowa/src/gplx/xowa/files/repos/Xofw_wiki_wkr_base.java
Normal file
@@ -0,0 +1,73 @@
|
||||
/*
|
||||
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.files.repos; import gplx.*; import gplx.xowa.*; import gplx.xowa.files.*;
|
||||
import gplx.xowa.wikis.*; import gplx.xowa.files.*; import gplx.xowa.files.repos.*; import gplx.xowa.wikis.data.tbls.*;
|
||||
import gplx.xowa.parsers.utils.*;
|
||||
public class Xofw_wiki_wkr_base implements Xofw_wiki_finder {
|
||||
public Xofw_wiki_wkr_base(Xowe_wiki wiki, Xoae_wiki_mgr wiki_mgr) {this.wiki = wiki; this.wiki_mgr = wiki_mgr;} private Xowe_wiki wiki; Xoae_wiki_mgr wiki_mgr;
|
||||
public void Find(List_adp repo_pairs, Xof_xfer_itm file) {
|
||||
byte[] ttl_bry = file.Lnki_ttl();
|
||||
int repo_pairs_len = repo_pairs.Count();
|
||||
for (int i = 0; i < repo_pairs_len; i++) {
|
||||
Xof_repo_pair repo_pair = (Xof_repo_pair)repo_pairs.Get_at(i);
|
||||
byte[] wiki_key = repo_pair.Src().Wiki_domain();
|
||||
if (repo_pair.Src().Wmf_api()) continue;
|
||||
Xowe_wiki repo_wiki = wiki_mgr.Get_by_key_or_null(wiki_key);
|
||||
if (repo_wiki == null) {continue;}
|
||||
Xoa_ttl ttl = Xoa_ttl.parse(repo_wiki, ttl_bry);
|
||||
Xow_ns file_ns = repo_wiki.Ns_mgr().Ns_file();
|
||||
boolean found = repo_wiki.Db_mgr().Load_mgr().Load_by_ttl(tmp_db_page, file_ns, ttl.Page_db());
|
||||
if (!found) {continue;}
|
||||
byte[] redirect = Get_redirect(repo_wiki, file_ns, tmp_db_page);
|
||||
file.Orig_ttl_and_redirect_(ttl.Page_txt(), redirect);
|
||||
file.Orig_repo_id_(i);
|
||||
return;
|
||||
}
|
||||
file.Orig_repo_id_(-1);
|
||||
}
|
||||
public boolean Locate(Xofw_file_finder_rslt rv, List_adp repo_pairs, byte[] ttl_bry) {
|
||||
Xoa_ttl ttl = Xoa_ttl.parse(wiki, ttl_bry); // NOTE: parse(ttl_bry) should be the same across all wikis; i.e.: there should be no aliases/namespaces
|
||||
Xow_ns file_ns = wiki.Ns_mgr().Ns_file(); // NOTE: file_ns should also be the same across all wikis; being used for data_mgr.Parse below
|
||||
byte[] ttl_db_key = ttl.Page_db();
|
||||
rv.Init(ttl_db_key);
|
||||
int repo_pairs_len = repo_pairs.Count();
|
||||
for (int i = 0; i < repo_pairs_len; i++) {
|
||||
Xof_repo_pair repo_pair = (Xof_repo_pair)repo_pairs.Get_at(i);
|
||||
byte[] src_wiki_key = repo_pair.Src().Wiki_domain();
|
||||
Xowe_wiki src_wiki = wiki_mgr.Get_by_key_or_null(src_wiki_key);
|
||||
if (src_wiki == null) continue; // src_wiki defined as repo_pair in cfg, but it has not been downloaded; continue; EX: commons set up but not downloaded
|
||||
boolean found = src_wiki.Db_mgr().Load_mgr().Load_by_ttl(tmp_db_page, file_ns, ttl_db_key);
|
||||
if (!found) continue; // ttl does not exist in src_wiki; continue; EX: file does not exist in commons, but exists in en_wiki
|
||||
byte[] redirect = Get_redirect(src_wiki, file_ns, tmp_db_page);
|
||||
rv.Done(i, src_wiki_key, redirect);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
private byte[] Get_redirect(Xowe_wiki wiki, Xow_ns file_ns, Xowd_page_itm db_page) {
|
||||
if (db_page.Redirected()) {
|
||||
wiki.Db_mgr().Load_mgr().Load_page(db_page, file_ns, false);
|
||||
byte[] src = db_page.Text();
|
||||
Xoa_ttl redirect_ttl = wiki.Redirect_mgr().Extract_redirect(src, src.length);
|
||||
return redirect_ttl == Xop_redirect_mgr.Redirect_null_ttl ? Xop_redirect_mgr.Redirect_null_bry : redirect_ttl.Page_db();
|
||||
}
|
||||
else
|
||||
return Xop_redirect_mgr.Redirect_null_bry;
|
||||
}
|
||||
private static final Xowd_page_itm tmp_db_page = Xowd_page_itm.new_tmp();
|
||||
}
|
||||
43
400_xowa/src/gplx/xowa/files/repos/Xofw_wiki_wkr_mock.java
Normal file
43
400_xowa/src/gplx/xowa/files/repos/Xofw_wiki_wkr_mock.java
Normal file
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
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.files.repos; import gplx.*; import gplx.xowa.*; import gplx.xowa.files.*;
|
||||
import gplx.xowa.files.*; import gplx.xowa.tdbs.metas.*;
|
||||
public class Xofw_wiki_wkr_mock implements Xofw_wiki_finder {
|
||||
int repo_idx; byte[] repo_wiki_key;
|
||||
public Xofw_wiki_wkr_mock Clear_en_wiki() {return Clear(1, Bry_en_wiki);}
|
||||
public Xofw_wiki_wkr_mock Clear_commons() {return Clear(0, Bry_commons);}
|
||||
Xofw_wiki_wkr_mock Clear(int repo_idx, byte[] repo_wiki_key) {
|
||||
this.repo_idx = repo_idx; this.repo_wiki_key = repo_wiki_key;
|
||||
if_ttl = then_redirect = Bry_.Empty;
|
||||
return this;
|
||||
}
|
||||
private static final byte[] Bry_commons = Bry_.new_a7("commons.wikimedia.org"), Bry_en_wiki = Bry_.new_a7("en.wikipedia.org");
|
||||
public Xofw_wiki_wkr_mock Repo_idx_(int v) {this.repo_idx = v; return this;}
|
||||
public Xofw_wiki_wkr_mock Redirect_(String if_ttl_str, String then_redirect_str) {this.if_ttl = Bry_.new_u8(if_ttl_str); this.then_redirect = Bry_.new_u8(then_redirect_str); return this;} private byte[] if_ttl, then_redirect;
|
||||
public void Find(List_adp repo_pairs, Xof_xfer_itm file) {
|
||||
byte[] ttl = file.Lnki_ttl();
|
||||
if (Bry_.Eq(ttl, if_ttl) && repo_idx != -1) {file.Orig_ttl_and_redirect_(ttl, then_redirect); file.Orig_repo_id_(repo_idx);}
|
||||
else {file.Orig_ttl_and_redirect_(ttl, Bry_.Empty) ; file.Orig_repo_id_(Xof_meta_itm.Repo_unknown);} // FUTURE: this should be missing, but haven't implemented unknown yet
|
||||
}
|
||||
public boolean Locate(Xofw_file_finder_rslt rv, List_adp repo_pairs, byte[] ttl) {
|
||||
rv.Init(ttl);
|
||||
byte[] redirect = Bry_.Eq(ttl, if_ttl) ? then_redirect : null;
|
||||
rv.Done(repo_idx, repo_wiki_key, redirect);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -18,6 +18,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
package gplx.xowa.files.repos; import gplx.*; import gplx.xowa.*; import gplx.xowa.files.*;
|
||||
import gplx.xowa.files.xfers.*;
|
||||
import gplx.xowa.wikis.domains.*;
|
||||
import gplx.xowa.parsers.utils.*;
|
||||
import gplx.xowa.tdbs.metas.*;
|
||||
public class Xowe_repo_mgr implements Xow_repo_mgr, GfoInvkAble {
|
||||
private Xowe_wiki wiki; private final List_adp repos = List_adp_.new_();
|
||||
public Xowe_repo_mgr(Xowe_wiki wiki) {
|
||||
|
||||
@@ -19,6 +19,7 @@ package gplx.xowa.files.xfers; import gplx.*; import gplx.xowa.*; import gplx.xo
|
||||
import gplx.core.primitives.*; import gplx.gfui.*;
|
||||
import gplx.xowa.files.*; import gplx.xowa.files.repos.*; import gplx.xowa.files.exts.*; import gplx.xowa.files.downloads.*;
|
||||
import gplx.xowa.wmfs.*; import gplx.xowa.wmfs.apis.*;
|
||||
import gplx.xowa.tdbs.metas.*;
|
||||
public class Xof_xfer_mgr {
|
||||
public Xof_xfer_mgr(Xof_file_mgr file_mgr, Xowmf_mgr wmf_mgr) {this.file_mgr = file_mgr; this.wmf_mgr = wmf_mgr;} private final Xof_file_mgr file_mgr; private final Xowmf_mgr wmf_mgr;
|
||||
public Xof_xfer_rslt Rslt() {return rslt;} private Xof_xfer_rslt rslt = new Xof_xfer_rslt();
|
||||
|
||||
@@ -19,6 +19,7 @@ package gplx.xowa.files.xfers; import gplx.*; import gplx.xowa.*; import gplx.xo
|
||||
import gplx.core.primitives.*;
|
||||
import gplx.xowa.files.*; import gplx.xowa.files.fsdb.*; import gplx.xowa.files.bins.*; import gplx.xowa.files.origs.*;
|
||||
import gplx.xowa.files.gui.*;
|
||||
import gplx.xowa.tdbs.metas.*;
|
||||
public class Xof_xfer_queue {
|
||||
private final List_adp xfer_list = List_adp_.new_(); private final Ordered_hash dirty_meta_mgrs = Ordered_hash_.new_bry_();
|
||||
public Int_obj_ref Html_uid() {return html_uid;} private Int_obj_ref html_uid = Int_obj_ref.neg1_();
|
||||
|
||||
@@ -18,6 +18,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
package gplx.xowa.files.xfers; import gplx.*; import gplx.xowa.*; import gplx.xowa.files.*;
|
||||
import gplx.core.primitives.*; import gplx.dbs.*;
|
||||
import gplx.ios.*; import gplx.xowa.wikis.domains.*; import gplx.xowa.files.*;
|
||||
import gplx.xowa.parsers.lnkis.*;
|
||||
public class Xof_xfer_queue_html_fxt extends Xof_xfer_queue_base_fxt {
|
||||
private final Xof_xfer_queue queue = new Xof_xfer_queue();
|
||||
@Override public void Clear(boolean src_repo_is_wmf) {
|
||||
|
||||
@@ -16,8 +16,7 @@ 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.files.xfers; import gplx.*; import gplx.xowa.*; import gplx.xowa.files.*;
|
||||
import org.junit.*;
|
||||
import gplx.xowa.files.*;
|
||||
import org.junit.*; import gplx.xowa.files.*; import gplx.xowa.parsers.lnkis.*;
|
||||
public class Xof_xfer_queue_html_offline_tst {
|
||||
Xof_xfer_queue_html_fxt fxt = new Xof_xfer_queue_html_fxt();
|
||||
@Before public void init() {fxt.Clear(true); fxt.Src_commons_repo().Tarball_(true); fxt.Src_en_wiki_repo().Tarball_(true);}
|
||||
|
||||
@@ -16,7 +16,7 @@ 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.files.xfers; import gplx.*; import gplx.xowa.*; import gplx.xowa.files.*;
|
||||
import org.junit.*;
|
||||
import org.junit.*; import gplx.xowa.parsers.lnkis.*;
|
||||
public class Xof_xfer_queue_html_wmf_api_tst {
|
||||
private final Xof_xfer_queue_html_fxt fxt = new Xof_xfer_queue_html_fxt();
|
||||
@Before public void init() {fxt.Clear(true); fxt.Src_commons_repo().Wmf_api_(true); fxt.Src_en_wiki_repo().Wmf_api_(true);}
|
||||
|
||||
@@ -17,6 +17,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.gui.urls; import gplx.*; import gplx.xowa.*; import gplx.xowa.gui.*;
|
||||
import gplx.xowa.files.*; import gplx.xowa.files.repos.*; import gplx.xowa.files.origs.*;
|
||||
import gplx.xowa.parsers.lnkis.*;
|
||||
public class Xof_orig_file_downloader {
|
||||
public static Xof_fsdb_itm Make_fsdb(Xowe_wiki wiki, byte[] lnki_ttl, Xof_img_size img_size, Xof_url_bldr url_bldr) {
|
||||
Xof_fsdb_itm fsdb = new Xof_fsdb_itm();
|
||||
|
||||
@@ -18,7 +18,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
package gplx.xowa.gui.urls; import gplx.*; import gplx.xowa.*; import gplx.xowa.gui.*;
|
||||
import gplx.core.net.*;
|
||||
import gplx.xowa.files.*; import gplx.xowa.files.repos.*; import gplx.xowa.files.origs.*;
|
||||
import gplx.xowa.html.hrefs.*;
|
||||
import gplx.xowa.html.hrefs.*; import gplx.xowa.html.doms.*;
|
||||
import gplx.xowa.gui.views.*;
|
||||
public class Xog_url_wkr {
|
||||
private final Xoa_url tmp_url = Xoa_url.blank();
|
||||
|
||||
@@ -38,7 +38,7 @@ public class Load_page_wkr implements Gfo_thread_wkr {
|
||||
Xoae_app app = wiki.Appe();
|
||||
app.Usr_dlg().Log_many("", "", "page.load: url=~{0}", url.To_str());
|
||||
if (Env_.System_memory_free() < app.Sys_cfg().Free_mem_when()) // check if low in memory
|
||||
app.Free_mem(false); // clear caches (which will clear bry_bfr_mkr)
|
||||
Xow_wiki_.Rls_mem(wiki, false); // clear caches (which will clear bry_bfr_mkr)
|
||||
else // not low in memory
|
||||
app.Utl__bfr_mkr().Clear(); // clear bry_bfr_mkr only; NOTE: call before page parse, not when page is first added, else threading errors; DATE:2014-05-30
|
||||
this.page = wiki.Load_page_by_ttl(url, ttl, wiki.Lang(), tab, false);
|
||||
|
||||
@@ -17,6 +17,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.gui.views; import gplx.*; import gplx.xowa.*; import gplx.xowa.gui.*;
|
||||
import gplx.gfui.*; import gplx.xowa.html.*; import gplx.xowa.pages.*;
|
||||
import gplx.xowa.parsers.*; import gplx.xowa.parsers.tmpls.*;
|
||||
public class Xog_tab_itm_edit_mgr {
|
||||
public static void Save(Xog_tab_itm tab, boolean quick_save) {
|
||||
if (tab.View_mode() != Xopg_view_mode.Tid_edit) return; // exit if not edit; handles ctrl+s being pressed in read/html modes
|
||||
|
||||
@@ -17,6 +17,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.html; import gplx.*; import gplx.xowa.*;
|
||||
import gplx.xowa.html.tidy.*; import gplx.xowa.html.utils.*; import gplx.xowa.html.skins.*;
|
||||
import gplx.xowa.parsers.xndes.*;
|
||||
public class Xoh_html_mgr implements GfoInvkAble {
|
||||
public Xoh_html_mgr(Xoae_app app) {
|
||||
js_cleaner = new Xoh_js_cleaner(app);
|
||||
|
||||
@@ -19,7 +19,7 @@ package gplx.xowa.html; import gplx.*; import gplx.xowa.*;
|
||||
import gplx.core.primitives.*; import gplx.core.net.*;
|
||||
import gplx.core.btries.*; import gplx.html.*;
|
||||
import gplx.xowa.wikis.domains.*;
|
||||
import gplx.xowa.parsers.apos.*; import gplx.xowa.parsers.amps.*; import gplx.xowa.parsers.lnkes.*; import gplx.xowa.parsers.hdrs.*; import gplx.xowa.parsers.lists.*; import gplx.xowa.html.lnkis.*; import gplx.xowa.parsers.tblws.*; import gplx.xowa.parsers.paras.*;
|
||||
import gplx.xowa.parsers.*; import gplx.xowa.parsers.apos.*; import gplx.xowa.parsers.amps.*; import gplx.xowa.parsers.lnkes.*; import gplx.xowa.parsers.hdrs.*; import gplx.xowa.parsers.lists.*; import gplx.xowa.html.lnkis.*; import gplx.xowa.parsers.tblws.*; import gplx.xowa.parsers.paras.*; import gplx.xowa.parsers.xndes.*; import gplx.xowa.parsers.lnkis.*; import gplx.xowa.parsers.miscs.*;
|
||||
import gplx.xowa.xtns.*; import gplx.xowa.xtns.dynamicPageList.*; import gplx.xowa.xtns.math.*; import gplx.xowa.langs.vnts.*; import gplx.xowa.xtns.cite.*; import gplx.xowa.html.hzips.*;
|
||||
public class Xoh_html_wtr {
|
||||
private Xowe_wiki wiki; private Xoae_app app; private Xoae_page page; private Xop_xatr_whitelist_mgr whitelist_mgr;
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user