1
0
mirror of https://github.com/gnosygnu/xowa.git synced 2026-03-02 03:49:30 +00:00
This commit is contained in:
gnosygnu
2015-06-21 23:25:42 -04:00
parent fe0ce6340d
commit bf44bcf3c6
191 changed files with 1347 additions and 430 deletions

View File

@@ -1,90 +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.core.brys; import gplx.*; import gplx.core.*;
public class Bry_rdr {
private byte[] src; private int src_len;
public Bry_rdr Src_(byte[] src, int src_len) {this.src = src; this.src_len = src_len; pos = 0; return this;} public Bry_rdr Src_(byte[] src) {return Src_(src, src.length);}
public int Pos() {return pos;} public Bry_rdr Pos_(int v) {this.pos = v; return this;} private int pos;
public boolean Pos_is_eos() {return pos == src_len;}
public void Pos_add_one() {++pos;}
public int Or_int() {return or_int;} public void Or_int_(int v) {or_int = v;} private int or_int = Int_.MinValue;
public byte[] Or_bry() {return or_bry;} public void Or_bry_(byte[] v) {or_bry = v;} private byte[] or_bry;
public int Find_fwd__pos_at_lhs(byte[] find_bry) {return Find_fwd__pos_at(find_bry, Bool_.N);}
public int Find_fwd__pos_at_rhs(byte[] find_bry) {return Find_fwd__pos_at(find_bry, Bool_.Y);}
public int Find_fwd__pos_at(byte[] find_bry, boolean pos_at_rhs) {
int find_pos = Bry_finder.Find_fwd(src, find_bry, pos, src_len);
if (pos_at_rhs) find_pos += find_bry.length;
if (find_pos != Bry_finder.Not_found) pos = find_pos;
return find_pos;
}
public int Read_int_to_semic() {return Read_int_to(Byte_ascii.Semic);}
public int Read_int_to_comma() {return Read_int_to(Byte_ascii.Comma);}
public int Read_int_to_pipe() {return Read_int_to(Byte_ascii.Pipe);}
public int Read_int_to_nl() {return Read_int_to(Byte_ascii.NewLine);}
public int Read_int_to_quote() {return Read_int_to(Byte_ascii.Quote);}
public int Read_int_to(byte to_char) {
int bgn = pos;
int rv = 0;
int negative = 1;
while (pos < src_len) {
byte b = src[pos++];
switch (b) {
case Byte_ascii.Num_0: case Byte_ascii.Num_1: case Byte_ascii.Num_2: case Byte_ascii.Num_3: case Byte_ascii.Num_4:
case Byte_ascii.Num_5: case Byte_ascii.Num_6: case Byte_ascii.Num_7: case Byte_ascii.Num_8: case Byte_ascii.Num_9:
rv = (rv * 10) + (b - Byte_ascii.Num_0);
break;
case Byte_ascii.Dash:
if (negative == -1) // 2nd negative
return or_int; // return or_int
else // 1st negative
negative = -1; // flag negative
break;
default:
return b == to_char ? rv * negative : or_int;
}
}
return bgn == pos ? or_int : rv * negative;
}
public byte[] Read_bry_to_nl() {return Read_bry_to(Byte_ascii.NewLine);}
public byte[] Read_bry_to_semic() {return Read_bry_to(Byte_ascii.Semic);}
public byte[] Read_bry_to_pipe() {return Read_bry_to(Byte_ascii.Pipe);}
public byte[] Read_bry_to_quote() {return Read_bry_to(Byte_ascii.Quote);}
public byte[] Read_bry_to_apos() {return Read_bry_to(Byte_ascii.Apos);}
public byte[] Read_bry_to(byte to_char) {
int bgn = pos;
while (pos < src_len) {
byte b = src[pos];
if (b == to_char)
return Bry_.Mid(src, bgn, pos++);
else
++pos;
}
return bgn == pos ? or_bry : Bry_.Mid(src, bgn, src_len);
}
public boolean Read_yn_to_pipe() {return Read_byte_to_pipe() == Byte_ascii.Ltr_y;}
public byte Read_byte_to_pipe() {
byte rv = src[pos];
pos += 2; // 1 for byte; 1 for pipe;
return rv;
}
public double Read_double_to_pipe() {return Read_double_to(Byte_ascii.Pipe);}
public double Read_double_to(byte to_char) {
byte[] double_bry = Read_bry_to(to_char);
return Double_.parse_(String_.new_a7(double_bry)); // double will never have utf8
}
}

View File

@@ -43,7 +43,7 @@ public class Bry_rdr_tst {
class Bry_rdr_fxt {
private Bry_rdr rdr;
public void Clear() {rdr = new Bry_rdr();}
public Bry_rdr_fxt Init_src(String v) {rdr.Src_(Bry_.new_u8(v)); return this;}
public Bry_rdr_fxt Init_src(String v) {rdr.Init(Bry_.new_u8(v)); return this;}
public Bry_rdr_fxt Init_pos(int v) {rdr.Pos_(v); return this;}
public void Test_read_int(int expd_val) {
Tfds.Eq(expd_val, rdr.Read_int_to_pipe());

View File

@@ -1,88 +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.core.btries; import gplx.*; import gplx.core.*;
import gplx.core.primitives.*;
public class Btrie_bwd_mgr {
public int Match_pos() {return match_pos;} private int match_pos;
public Object Match_exact(byte[] src, int bgn_pos, int end_pos) {
Object rv = Match(src[bgn_pos], src, bgn_pos, end_pos);
return rv == null ? null : match_pos - bgn_pos == end_pos - bgn_pos ? rv : null;
}
public Object Match_bgn(byte[] src, int bgn_pos, int end_pos) {return Match(src[bgn_pos], src, bgn_pos, end_pos);}
public Object Match(byte b, byte[] src, int bgn_pos, int end_pos) {
// NOTE: bgn, end follows same semantics as fwd where bgn >= & end < except reversed: bgn <= & end >; EX: "abcde" should pass 5, -1
Object rv = null; int cur_pos = match_pos = bgn_pos;
Btrie_slim_itm cur = root;
while (true) {
Btrie_slim_itm nxt = cur.Ary_find(b); if (nxt == null) return rv; // nxt does not hav b; return rv;
--cur_pos;
if (nxt.Ary_is_empty()) {match_pos = cur_pos; return nxt.Val();} // nxt is leaf; return nxt.Val() (which should be non-null)
Object nxt_val = nxt.Val();
if (nxt_val != null) {match_pos = cur_pos; rv = nxt_val;} // nxt is node; cache rv (in case of false match)
if (cur_pos == end_pos) return rv; // increment cur_pos and exit if src_len
b = src[cur_pos];
cur = nxt;
}
}
public Btrie_bwd_mgr Add_str_byte(String key, byte val) {return Add(Bry_.new_u8(key), Byte_obj_val.new_(val));}
public Btrie_bwd_mgr Add_byteVal_strAry(byte val, String... ary) {
int ary_len = ary.length;
Byte_obj_val byteVal = Byte_obj_val.new_(val);
for (int i = 0; i < ary_len; i++) {
String itm = ary[i];
Add(Bry_.new_u8(itm), byteVal);
}
return this;
}
public Btrie_bwd_mgr Add(String key, Object val) {return Add(Bry_.new_u8(key), val);}
public Btrie_bwd_mgr Add(byte[] key, Object val) {
if (val == null) throw Err_.new_("null objects cannot be registered").Add("key", String_.new_u8(key));
int key_len = key.length;
Btrie_slim_itm cur = root;
for (int i = key_len - 1; i > -1; i--) {
byte b = key[i];
if (root.Case_any() && (b > 64 && b < 91)) b += 32;
Btrie_slim_itm nxt = cur.Ary_find(b);
if (nxt == null)
nxt = cur.Ary_add(b, null);
if (i == 0)
nxt.Val_set(val);
cur = nxt;
}
count++; // FUTURE: do not increment if replacing value
return this;
}
public int Count() {return count;} private int count;
public void Del(byte[] key) {
int key_len = key.length;
Btrie_slim_itm cur = root;
for (int i = 0; i < key_len; i++) {
byte b = key[i];
cur = cur.Ary_find(b);
if (cur == null) break;
cur.Ary_del(b);
}
count--; // FUTURE: do not decrement if not found
}
public void Clear() {root.Clear(); count = 0;}
public static Btrie_bwd_mgr cs_() {return new Btrie_bwd_mgr(false);}
public static Btrie_bwd_mgr ci_() {return new Btrie_bwd_mgr(true);}
public Btrie_bwd_mgr(boolean caseAny) {
root = new Btrie_slim_itm(Byte_.Zero, null, caseAny);
} private Btrie_slim_itm root;
}

View File

@@ -1,87 +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.core.btries; import gplx.*; import gplx.core.*;
import org.junit.*;
public class Btrie_bwd_mgr_tst {
@Before public void init() {} private Btrie_bwd_mgr trie;
private void ini_setup1() {
trie = new Btrie_bwd_mgr(false);
run_Add("c" , 1);
run_Add("abc" , 123);
}
@Test public void Get_by() {
ini_setup1();
tst_MatchAtCur("c" , 1);
tst_MatchAtCur("abc" , 123);
tst_MatchAtCur("bc" , 1);
tst_MatchAtCur("yzabc" , 123);
tst_MatchAtCur("ab" , null);
}
@Test public void Fetch_intl() {
trie = new Btrie_bwd_mgr(false);
run_Add("a<EFBFBD>", 1);
tst_MatchAtCur("a<EFBFBD>" , 1);
tst_MatchAtCur("<EFBFBD>" , null);
}
@Test public void Eos() {
ini_setup1();
tst_Match("ab", Byte_ascii.Ltr_c, 2, 123);
}
@Test public void Match_exact() {
ini_setup1();
tst_MatchAtCurExact("c", 1);
tst_MatchAtCurExact("bc", null);
tst_MatchAtCurExact("abc", 123);
}
private void ini_setup2() {
trie = new Btrie_bwd_mgr(false);
run_Add("a" , 1);
run_Add("b" , 2);
}
@Test public void Match_2() {
ini_setup2();
tst_MatchAtCur("a", 1);
tst_MatchAtCur("b", 2);
}
private void ini_setup_caseAny() {
trie = Btrie_bwd_mgr.ci_();
run_Add("a" , 1);
run_Add("b" , 2);
}
@Test public void CaseAny() {
ini_setup_caseAny();
tst_MatchAtCur("a", 1);
tst_MatchAtCur("A", 1);
}
private void run_Add(String k, int val) {trie.Add(Bry_.new_u8(k), val);}
private void tst_Match(String srcStr, byte b, int bgn_pos, int expd) {
byte[] src = Bry_.new_u8(srcStr);
Object actl = trie.Match(b, src, bgn_pos, -1);
Tfds.Eq(expd, actl);
}
private void tst_MatchAtCur(String srcStr, Object expd) {
byte[] src = Bry_.new_u8(srcStr);
Object actl = trie.Match(src[src.length - 1], src, src.length - 1, -1);
Tfds.Eq(expd, actl);
}
private void tst_MatchAtCurExact(String srcStr, Object expd) {
byte[] src = Bry_.new_u8(srcStr);
Object actl = trie.Match_exact(src, src.length - 1, -1);
Tfds.Eq(expd, actl);
}
}

View File

@@ -1,156 +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.core.btries; import gplx.*; import gplx.core.*;
import gplx.core.primitives.*;
public class Btrie_fast_mgr {
private ByteTrieItm_fast root;
public boolean CaseAny() {return root.CaseAny();} public Btrie_fast_mgr CaseAny_(boolean v) {root.CaseAny_(v); return this;}
public int Match_pos() {return match_pos;} private int match_pos;
public Object Match_exact(byte[] src, int bgn_pos, int end_pos) {
Object rv = Match_bgn_w_byte(src[bgn_pos], src, bgn_pos, end_pos);
return rv == null ? null : match_pos - bgn_pos == end_pos - bgn_pos ? rv : null;
}
public Object Match_bgn(byte[] src, int bgn_pos, int end_pos) {return Match_bgn_w_byte(src[bgn_pos], src, bgn_pos, end_pos);}
public Object Match_bgn_w_byte(byte b, byte[] src, int bgn_pos, int src_len) {
match_pos = bgn_pos;
ByteTrieItm_fast nxt = root.Ary_find(b); if (nxt == null) return null; // nxt does not have b; return rv;
Object rv = null; int cur_pos = bgn_pos + 1;
ByteTrieItm_fast cur = root;
while (true) {
if (nxt.Ary_is_empty()) {match_pos = cur_pos; return nxt.Val();} // nxt is leaf; return nxt.Val() (which should be non-null)
Object nxt_val = nxt.Val();
if (nxt_val != null) {match_pos = cur_pos; rv = nxt_val;} // nxt is node; cache rv (in case of false match)
if (cur_pos == src_len) return rv; // eos; exit
b = src[cur_pos];
cur = nxt;
nxt = cur.Ary_find(b); if (nxt == null) return rv;
++cur_pos;
}
}
public Btrie_fast_mgr Add_bry_bval(byte key, byte val) {return Add(new byte[] {key}, Byte_obj_val.new_(val));}
public Btrie_fast_mgr Add_bry_bval(byte[] key, byte val) {return Add(key, Byte_obj_val.new_(val));}
public Btrie_fast_mgr Add_str_byte(String key, byte val) {return Add(Bry_.new_u8(key), Byte_obj_val.new_(val));}
public Btrie_fast_mgr Add(byte key, Object val) {return Add(new byte[] {key}, val);}
public Btrie_fast_mgr Add(String key, Object val) {return Add(Bry_.new_u8(key), val);}
public Btrie_fast_mgr Add(byte[] key, Object val) {
if (val == null) throw Err_.new_("null objects cannot be registered").Add("key", String_.new_u8(key));
int key_len = key.length; int key_end = key_len - 1;
ByteTrieItm_fast cur = root;
for (int i = 0; i < key_len; i++) {
byte b = key[i];
ByteTrieItm_fast nxt = cur.Ary_find(b);
if (nxt == null)
nxt = cur.Ary_add(b, null);
if (i == key_end)
nxt.Val_set(val);
cur = nxt;
}
return this;
}
public Btrie_fast_mgr Add_stub(byte tid, String s) {
byte[] bry = Bry_.new_u8(s);
Btrie_itm_stub stub = new Btrie_itm_stub(tid, bry);
return Add(bry, stub);
}
public void Del(byte[] key) {
int key_len = key.length;
ByteTrieItm_fast cur = root;
for (int i = 0; i < key_len; i++) {
byte b = key[i];
Object itm_obj = cur.Ary_find(b);
if (itm_obj == null) break; // b not found; no match; exit;
ByteTrieItm_fast itm = (ByteTrieItm_fast)itm_obj;
if (i == key_len - 1) { // last char
if (itm.Val() == null) break; // itm does not have val; EX: trie with "abc", and "ab" deleted
if (itm.Ary_is_empty())
cur.Ary_del(b);
else
itm.Val_set(null);
}
else { // mid char; set itm as cur and continue
cur = itm;
}
}
}
public void Clear() {root.Clear();}
public byte[] Replace(Bry_bfr tmp_bfr, byte[] src, int bgn, int end) {
int pos = bgn;
boolean dirty = false;
while (pos < end) {
byte b = src[pos];
Object o = this.Match_bgn_w_byte(b, src, pos, end);
if (o == null) {
if (dirty)
tmp_bfr.Add_byte(b);
pos++;
}
else {
if (!dirty) {
tmp_bfr.Add_mid(src, bgn, pos);
dirty = true;
}
tmp_bfr.Add((byte[])o);
pos = match_pos;
}
}
return dirty ? tmp_bfr.Xto_bry_and_clear() : src;
}
public static Btrie_fast_mgr cs_() {return new Btrie_fast_mgr(false);}
public static Btrie_fast_mgr ci_ascii_() {return new Btrie_fast_mgr(true);}
public static Btrie_fast_mgr new_(boolean case_any) {return new Btrie_fast_mgr(case_any);}
Btrie_fast_mgr(boolean caseAny) {
root = new ByteTrieItm_fast(Byte_.Zero, null, caseAny);
}
}
class ByteTrieItm_fast {
private ByteTrieItm_fast[] ary = new ByteTrieItm_fast[256];
public byte Key_byte() {return key_byte;} private byte key_byte;
public Object Val() {return val;} public void Val_set(Object val) {this.val = val;} Object val;
public boolean Ary_is_empty() {return ary_is_empty;} private boolean ary_is_empty;
public boolean CaseAny() {return caseAny;} public ByteTrieItm_fast CaseAny_(boolean v) {caseAny = v; return this;} private boolean caseAny;
public void Clear() {
val = null;
for (int i = 0; i < 256; i++) {
if (ary[i] != null) {
ary[i].Clear();
ary[i] = null;
}
}
ary_len = 0;
ary_is_empty = true;
}
public ByteTrieItm_fast Ary_find(byte b) {
int key_byte = (caseAny && (b > 64 && b < 91) ? b + 32 : b) & 0xff;// PATCH.JAVA:need to convert to unsigned byte
return ary[key_byte];
}
public ByteTrieItm_fast Ary_add(byte b, Object val) {
int key_byte = (caseAny && (b > 64 && b < 91) ? b + 32 : b) & 0xff;// PATCH.JAVA:need to convert to unsigned byte
ByteTrieItm_fast rv = new ByteTrieItm_fast(b, val, caseAny);
ary[key_byte] = rv;
++ary_len;
ary_is_empty = false;
return rv;
}
public void Ary_del(byte b) {
int key_byte = (caseAny && (b > 64 && b < 91) ? b + 32 : b) & 0xff;// PATCH.JAVA:need to convert to unsigned byte
ary[key_byte] = null;
--ary_len;
ary_is_empty = ary_len == 0;
} int ary_len = 0;
public ByteTrieItm_fast(byte key_byte, Object val, boolean caseAny) {this.key_byte = key_byte; this.val = val; this.caseAny = caseAny;}
}

View File

@@ -1,85 +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.core.btries; import gplx.*; import gplx.core.*;
import org.junit.*;
public class Btrie_fast_mgr_tst {
private Btrie_fast_mgr_fxt fxt = new Btrie_fast_mgr_fxt();
@Before public void init() {fxt.Clear();}
@Test public void Get_by() {
fxt.Test_matchAtCur("a" , 1);
fxt.Test_matchAtCur("abc" , 123);
fxt.Test_matchAtCur("ab" , 1);
fxt.Test_matchAtCur("abcde" , 123);
fxt.Test_matchAtCur(" a" , null);
}
@Test public void Bos() {
fxt.Test_match("bc", Byte_ascii.Ltr_a, -1, 123);
}
@Test public void Match_exact() {
fxt.Test_matchAtCurExact("a", 1);
fxt.Test_matchAtCurExact("ab", null);
fxt.Test_matchAtCurExact("abc", 123);
}
@Test public void Del_noop__no_match() {
fxt.Exec_del("d");
fxt.Test_matchAtCurExact("a" , 1);
fxt.Test_matchAtCurExact("abc" , 123);
}
@Test public void Del_noop__partial_match() {
fxt.Exec_del("ab");
fxt.Test_matchAtCurExact("a" , 1);
fxt.Test_matchAtCurExact("abc" , 123);
}
@Test public void Del_match__long() {
fxt.Exec_del("abc");
fxt.Test_matchAtCurExact("a" , 1);
fxt.Test_matchAtCurExact("abc" , null);
}
@Test public void Del_match__short() {
fxt.Exec_del("a");
fxt.Test_matchAtCurExact("a" , null);
fxt.Test_matchAtCurExact("abc" , 123);
}
}
class Btrie_fast_mgr_fxt {
private Btrie_fast_mgr trie;
public void Clear() {
trie = Btrie_fast_mgr.cs_();
Init_add( 1 , Byte_ascii.Ltr_a);
Init_add(123 , Byte_ascii.Ltr_a, Byte_ascii.Ltr_b, Byte_ascii.Ltr_c);
}
public void Init_add(int val, byte... ary) {trie.Add(ary, val);}
public void Test_match(String src_str, byte b, int bgn_pos, int expd) {
byte[] src = Bry_.new_a7(src_str);
Object actl = trie.Match_bgn_w_byte(b, src, bgn_pos, src.length);
Tfds.Eq(expd, actl);
}
public void Test_matchAtCur(String src_str, Object expd) {
byte[] src = Bry_.new_a7(src_str);
Object actl = trie.Match_bgn(src, 0, src.length);
Tfds.Eq(expd, actl);
}
public void Test_matchAtCurExact(String src_str, Object expd) {
byte[] src = Bry_.new_a7(src_str);
Object actl = trie.Match_exact(src, 0, src.length);
Tfds.Eq(expd, actl);
}
public void Exec_del(String src_str) {
trie.Del(Bry_.new_u8(src_str));
}
}

View File

@@ -1,23 +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.core.btries; import gplx.*; import gplx.core.*;
public class Btrie_itm_stub {
public Btrie_itm_stub(byte tid, byte[] val) {this.tid = tid; this.val = val;}
public byte Tid() {return tid;} private byte tid;
public byte[] Val() {return val;} private byte[] val;
}

View File

@@ -1,24 +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.core.btries; import gplx.*; import gplx.core.*;
public interface Btrie_mgr {
int Match_pos();
Object Match_bgn(byte[] src, int bgn_pos, int end_pos);
Btrie_mgr Add_obj(String key, Object val);
Btrie_mgr Add_obj(byte[] key, Object val);
}

View File

@@ -1,130 +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.core.btries; import gplx.*; import gplx.core.*;
public class Btrie_slim_itm {
private Btrie_slim_itm[] ary = Btrie_slim_itm.Ary_empty;
public Btrie_slim_itm(byte key_byte, Object val, boolean case_any) {this.key_byte = key_byte; this.val = val; this.case_any = case_any;}
public byte Key_byte() {return key_byte;} private byte key_byte;
public Object Val() {return val;} public void Val_set(Object val) {this.val = val;} private Object val;
public boolean Case_any() {return case_any;} private boolean case_any;
public boolean Ary_is_empty() {return ary == Btrie_slim_itm.Ary_empty;}
public void Clear() {
val = null;
for (int i = 0; i < ary_len; i++)
ary[i].Clear();
ary = Btrie_slim_itm.Ary_empty;
ary_len = ary_max = 0;
}
public Btrie_slim_itm Ary_find(byte b) {
int find_val = (case_any && (b > 64 && b < 91) ? b + 32 : b) & 0xff;// PATCH.JAVA:need to convert to unsigned byte
int key_val = 0;
switch (ary_len) {
case 0: return null;
case 1:
Btrie_slim_itm rv = ary[0];
key_val = rv.Key_byte() & 0xff;// PATCH.JAVA:need to convert to unsigned byte;
key_val = (case_any && (key_val > 64 && key_val < 91) ? key_val + 32 : key_val);
return key_val == find_val ? rv : null;
default:
int adj = 1;
int prv_pos = 0;
int prv_len = ary_len;
int cur_len = 0;
int cur_idx = 0;
Btrie_slim_itm itm = null;
while (true) {
cur_len = prv_len / 2;
if (prv_len % 2 == 1) ++cur_len;
cur_idx = prv_pos + (cur_len * adj);
if (cur_idx < 0) cur_idx = 0;
else if (cur_idx >= ary_len) cur_idx = ary_len - 1;
itm = ary[cur_idx];
key_val = itm.Key_byte() & 0xff; // PATCH.JAVA:need to convert to unsigned byte;
key_val = (case_any && (key_val > 64 && key_val < 91) ? key_val + 32 : key_val);
if (find_val < key_val) adj = -1;
else if (find_val > key_val) adj = 1;
else /*(find_val == cur_val)*/ return itm;
if (cur_len == 1) {
cur_idx += adj;
if (cur_idx < 0 || cur_idx >= ary_len) return null;
itm = ary[cur_idx];
return (itm.Key_byte() & 0xff) == find_val ? itm : null; // PATCH.JAVA:need to convert to unsigned byte;
}
prv_len = cur_len;
prv_pos = cur_idx;
}
}
}
public Btrie_slim_itm Ary_add(byte b, Object val) {
int new_len = ary_len + 1;
if (new_len > ary_max) {
ary_max += 4;
ary = (Btrie_slim_itm[])Array_.Resize(ary, ary_max);
}
Btrie_slim_itm rv = new Btrie_slim_itm(b, val, case_any);
ary[ary_len] = rv;
ary_len = new_len;
ByteHashItm_sorter._.Sort(ary, ary_len);
return rv;
}
public void Ary_del(byte b) {
boolean found = false;
for (int i = 0; i < ary_len; i++) {
if (found) {
if (i < ary_len - 1)
ary[i] = ary[i + 1];
}
else {
if (b == ary[i].Key_byte()) found = true;
}
}
if (found) --ary_len;
}
public static final Btrie_slim_itm[] Ary_empty = new Btrie_slim_itm[0]; int ary_len = 0, ary_max = 0;
}
class ByteHashItm_sorter {// quicksort
Btrie_slim_itm[] ary; int ary_len;
public void Sort(Btrie_slim_itm[] ary, int ary_len) {
if (ary == null || ary_len < 2) return;
this.ary = ary;
this.ary_len = ary_len;
Sort_recurse(0, ary_len - 1);
}
private void Sort_recurse(int lo, int hi) {
int i = lo, j = hi;
int mid = ary[lo + (hi-lo)/2].Key_byte()& 0xFF; // get mid itm
while (i <= j) { // divide into two lists
while ((ary[i].Key_byte() & 0xFF) < mid) // if lhs.cur < mid, then get next from lhs
i++;
while ((ary[j].Key_byte() & 0xFF) > mid) // if rhs.cur > mid, then get next from rhs
j--;
// lhs.cur > mid && rhs.cur < mid; switch lhs.cur and rhs.cur; increase i and j
if (i <= j) {
Btrie_slim_itm tmp = ary[i];
ary[i] = ary[j];
ary[j] = tmp;
i++;
j--;
}
}
if (lo < j) Sort_recurse(lo, j);
if (i < hi) Sort_recurse(i, hi);
}
public static final ByteHashItm_sorter _ = new ByteHashItm_sorter(); ByteHashItm_sorter() {}
}

View File

@@ -1,49 +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.core.btries; import gplx.*; import gplx.core.*;
import org.junit.*;
public class Btrie_slim_itm_tst {
private Btrie_slim_itm itm = new Btrie_slim_itm(Byte_.Zero, null, false);
@Before public void init() {itm.Clear();}
@Test public void Find_nil() {
tst_Find(Byte_ascii.Ltr_a, null);
}
@Test public void Add_one() {
run_Add(Byte_ascii.Ltr_a);
tst_Find(Byte_ascii.Ltr_a, "a");
}
@Test public void Add_many() {
run_Add(Byte_ascii.Bang, Byte_ascii.Num_0, Byte_ascii.Ltr_a, Byte_ascii.Ltr_B);
tst_Find(Byte_ascii.Ltr_a, "a");
}
@Test public void Del() {
run_Add(Byte_ascii.Bang, Byte_ascii.Num_0, Byte_ascii.Ltr_a, Byte_ascii.Ltr_B);
tst_Find(Byte_ascii.Ltr_a, "a");
run_Del(Byte_ascii.Ltr_a);
tst_Find(Byte_ascii.Ltr_a, null);
tst_Find(Byte_ascii.Num_0, "0");
tst_Find(Byte_ascii.Ltr_B, "B");
}
private void tst_Find(byte b, String expd) {
Btrie_slim_itm actl_itm = itm.Ary_find(b);
Object actl = actl_itm == null ? null : actl_itm.Val();
Tfds.Eq(expd, actl);
}
private void run_Add(byte... ary) {for (byte b : ary) itm.Ary_add(b, Char_.XtoStr((char)b));}
private void run_Del(byte... ary) {for (byte b : ary) itm.Ary_del(b);}
}

View File

@@ -1,128 +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.core.btries; import gplx.*; import gplx.core.*;
import gplx.core.primitives.*;
public class Btrie_slim_mgr implements Btrie_mgr {
Btrie_slim_mgr(boolean case_match) {root = new Btrie_slim_itm(Byte_.Zero, null, !case_match);} private Btrie_slim_itm root;
public int Count() {return count;} private int count;
public int Match_pos() {return match_pos;} private int match_pos;
public Object Match_exact(byte[] src, int bgn_pos, int end_pos) {
Object rv = Match_bgn_w_byte(src[bgn_pos], src, bgn_pos, end_pos);
return rv == null ? null : match_pos - bgn_pos == end_pos - bgn_pos ? rv : null;
}
public Object Match_bgn(byte[] src, int bgn_pos, int end_pos) {return Match_bgn_w_byte(src[bgn_pos], src, bgn_pos, end_pos);}
public Object Match_bgn_w_byte(byte b, byte[] src, int bgn_pos, int src_len) {
Object rv = null; int cur_pos = match_pos = bgn_pos;
Btrie_slim_itm cur = root;
while (true) {
Btrie_slim_itm nxt = cur.Ary_find(b); if (nxt == null) return rv; // nxt does not hav b; return rv;
++cur_pos;
if (nxt.Ary_is_empty()) {match_pos = cur_pos; return nxt.Val();} // nxt is leaf; return nxt.Val() (which should be non-null)
Object nxt_val = nxt.Val();
if (nxt_val != null) {match_pos = cur_pos; rv = nxt_val;} // nxt is node; cache rv (in case of false match)
if (cur_pos == src_len) return rv; // increment cur_pos and exit if src_len
b = src[cur_pos];
cur = nxt;
}
}
public Btrie_slim_mgr Add_bry_tid(byte[] bry, byte tid) {return (Btrie_slim_mgr)Add_obj(bry, Byte_obj_val.new_(tid));}
public Btrie_slim_mgr Add_str_byte(String key, byte val) {return (Btrie_slim_mgr)Add_obj(Bry_.new_u8(key), Byte_obj_val.new_(val));}
public Btrie_slim_mgr Add_str_int(String key, int val) {return (Btrie_slim_mgr)Add_obj(Bry_.new_u8(key), Int_obj_val.new_(val));}
public Btrie_slim_mgr Add_bry(String key, String val) {return (Btrie_slim_mgr)Add_obj(Bry_.new_u8(key), Bry_.new_u8(val));}
public Btrie_slim_mgr Add_bry(String key, byte[] val) {return (Btrie_slim_mgr)Add_obj(Bry_.new_u8(key), val);}
public Btrie_slim_mgr Add_bry(byte[] v) {return (Btrie_slim_mgr)Add_obj(v, v);}
public Btrie_slim_mgr Add_bry_bval(byte b, byte val) {return (Btrie_slim_mgr)Add_obj(new byte[] {b}, Byte_obj_val.new_(val));}
public Btrie_slim_mgr Add_bry_bval(byte[] bry, byte val) {return (Btrie_slim_mgr)Add_obj(bry, Byte_obj_val.new_(val));}
public Btrie_slim_mgr Add_str_byte__many(byte val, String... ary) {
int ary_len = ary.length;
Byte_obj_val bval = Byte_obj_val.new_(val);
for (int i = 0; i < ary_len; i++)
Add_obj(Bry_.new_u8(ary[i]), bval);
return this;
}
public Btrie_slim_mgr Add_stub(String key, byte val) {byte[] bry = Bry_.new_u8(key); return (Btrie_slim_mgr)Add_obj(bry, new Btrie_itm_stub(val, bry));}
public Btrie_slim_mgr Add_stubs(byte[][] ary) {return Add_stubs(ary, ary.length);}
public Btrie_slim_mgr Add_stubs(byte[][] ary, int ary_len) {
for (byte i = 0; i < ary_len; i++) {
byte[] bry = ary[i];
Add_obj(bry, new Btrie_itm_stub(i, bry));
}
return this;
}
public Btrie_mgr Add_obj(String key, Object val) {return Add_obj(Bry_.new_u8(key), val);}
public Btrie_mgr Add_obj(byte[] key, Object val) {
if (val == null) throw Err_.new_("null objects cannot be registered").Add("key", String_.new_u8(key));
int key_len = key.length; int key_end = key_len - 1;
Btrie_slim_itm cur = root;
for (int i = 0; i < key_len; i++) {
byte b = key[i];
if (root.Case_any() && (b > 64 && b < 91)) b += 32;
Btrie_slim_itm nxt = cur.Ary_find(b);
if (nxt == null)
nxt = cur.Ary_add(b, null);
if (i == key_end)
nxt.Val_set(val);
cur = nxt;
}
count++; // FUTURE: do not increment if replacing value
return this;
}
public void Del(byte[] key) {
int key_len = key.length;
Btrie_slim_itm cur = root;
for (int i = 0; i < key_len; i++) {
byte b = key[i];
Btrie_slim_itm nxt = cur.Ary_find(b);
if (nxt == null) break;
Object nxt_val = nxt.Val();
if (nxt_val == null) // cur is end of chain; remove entry; EX: Abc and at c
cur.Ary_del(b);
else // cur is mid of chain; null out entry
nxt.Val_set(null);
cur = nxt;
}
count--; // FUTURE: do not decrement if not found
}
public byte[] Replace(Bry_bfr tmp_bfr, byte[] src, int bgn, int end) {
int pos = bgn;
boolean dirty = false;
while (pos < end) {
byte b = src[pos];
Object o = this.Match_bgn_w_byte(b, src, pos, end);
if (o == null) {
if (dirty)
tmp_bfr.Add_byte(b);
pos++;
}
else {
if (!dirty) {
tmp_bfr.Add_mid(src, bgn, pos);
dirty = true;
}
tmp_bfr.Add((byte[])o);
pos = match_pos;
}
}
return dirty ? tmp_bfr.Xto_bry_and_clear() : src;
}
public void Clear() {root.Clear(); count = 0;}
public static Btrie_slim_mgr cs_() {return new Btrie_slim_mgr(true);}
public static Btrie_slim_mgr ci_ascii_() {return new Btrie_slim_mgr(false);}
public static Btrie_slim_mgr ci_utf_8_() {return new Btrie_slim_mgr(false);}
public static Btrie_slim_mgr new_(boolean v) {return new Btrie_slim_mgr(v);}
}

View File

@@ -1,92 +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.core.btries; import gplx.*; import gplx.core.*;
import org.junit.*;
public class Btrie_slim_mgr_tst {
@Before public void init() {
} private Btrie_slim_mgr trie;
private void ini_setup1() {
trie = Btrie_slim_mgr.cs_();
run_Add("a" , 1);
run_Add("abc" , 123);
}
@Test public void Get_by() {
ini_setup1();
tst_MatchAtCur("a" , 1);
tst_MatchAtCur("abc" , 123);
tst_MatchAtCur("ab" , 1);
tst_MatchAtCur("abcde" , 123);
tst_MatchAtCur(" a" , null);
}
@Test public void Bos() {
ini_setup1();
tst_Match("bc", Byte_ascii.Ltr_a, -1, 123);
}
@Test public void Match_exact() {
ini_setup1();
tst_MatchAtCurExact("a", 1);
tst_MatchAtCurExact("ab", null);
tst_MatchAtCurExact("abc", 123);
}
private void ini_setup2() {
trie = Btrie_slim_mgr.cs_();
run_Add("a" , 1);
run_Add("b" , 2);
}
@Test public void Match_2() {
ini_setup2();
tst_MatchAtCur("a", 1);
tst_MatchAtCur("b", 2);
}
private void ini_setup_caseAny() {
trie = Btrie_slim_mgr.ci_ascii_(); // NOTE:ci.ascii:test
run_Add("a" , 1);
run_Add("b" , 2);
}
@Test public void CaseAny() {
ini_setup_caseAny();
tst_MatchAtCur("a", 1);
tst_MatchAtCur("A", 1);
}
@Test public void Del() {
ini_setup1();
trie.Del(Bry_.new_a7("a")); // delete "a"; "abc" still remains;
tst_MatchAtCur("a" , null);
tst_MatchAtCur("abc" , 123);
trie.Del(Bry_.new_a7("abc"));
tst_MatchAtCur("abc" , null);
}
private void run_Add(String k, int val) {trie.Add_obj(Bry_.new_a7(k), val);}
private void tst_Match(String srcStr, byte b, int bgn_pos, int expd) {
byte[] src = Bry_.new_a7(srcStr);
Object actl = trie.Match_bgn_w_byte(b, src, bgn_pos, src.length);
Tfds.Eq(expd, actl);
}
private void tst_MatchAtCur(String srcStr, Object expd) {
byte[] src = Bry_.new_a7(srcStr);
Object actl = trie.Match_bgn_w_byte(src[0], src, 0, src.length);
Tfds.Eq(expd, actl);
}
private void tst_MatchAtCurExact(String srcStr, Object expd) {
byte[] src = Bry_.new_a7(srcStr);
Object actl = trie.Match_exact(src, 0, src.length);
Tfds.Eq(expd, actl);
}
}

View File

@@ -1,68 +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.core.btries; import gplx.*; import gplx.core.*;
import gplx.intl.*;
class Btrie_utf8_itm {
private Hash_adp_bry nxts;
private byte[] asymmetric_bry;
public Btrie_utf8_itm(byte[] key, Object val) {this.key = key; this.val = val;}
public byte[] Key() {return key;} private byte[] key;
public Object Val() {return val;} public void Val_set(Object val) {this.val = val;} private Object val;
public boolean Nxts_is_empty() {return nxts == null;}
public void Clear() {
val = null;
nxts.Clear();
nxts = null;
}
public Btrie_utf8_itm Nxts_find(byte[] src, int c_bgn, int c_end, boolean called_by_match) {
if (nxts == null) return null;
Object rv_obj = nxts.Get_by_mid(src, c_bgn, c_end);
if (rv_obj == null) return null;
Btrie_utf8_itm rv = (Btrie_utf8_itm)rv_obj;
byte[] asymmetric_bry = rv.asymmetric_bry;
if (asymmetric_bry == null) // itm doesn't have asymmetric_bry; note that this is the case for most items
return rv;
else { // itm has asymmetric_bry; EX: "İ" was added to trie, must match "İ" and "i";
if (called_by_match) { // called by mgr.Match
return
( Bry_.Eq(rv.key, src, c_bgn, c_end) // key matches src; EX: "aİ"
|| Bry_.Eq(rv.asymmetric_bry, src, c_bgn, c_end) // asymmetric_bry matches src; EX: "ai"; note that "aI" won't match
)
? rv : null;
}
else { // called by mgr.Add; this means that an asymmetric_itm was already added; happens when "İ" added first and then "I" added next
rv.asymmetric_bry = null; // always null out asymmetric_bry; note that this noops non-asymmetric itms, while making an asymmetric_itm case-insenstivie (matches İ,i,I); see tests
return rv;
}
}
}
public Btrie_utf8_itm Nxts_add(Gfo_case_mgr case_mgr, byte[] key, Object val) {
Btrie_utf8_itm rv = new Btrie_utf8_itm(key, val);
if (nxts == null) nxts = Hash_adp_bry.ci_utf8_(case_mgr);
nxts.Add_bry_obj(key, rv);
Gfo_case_itm case_itm = case_mgr.Get_or_null(key[0], key, 0, key.length); // get case_item
if (case_itm != null) { // note that case_itm may be null; EX: "__TOC__" and "_"
byte[] asymmetric_bry = case_itm.Asymmetric_bry();
if (asymmetric_bry != null) { // case_itm has asymmetry_bry; only itms in Xol_case_itm_ that are created with Tid_upper and Tid_lower will be non-null
rv.asymmetric_bry = asymmetric_bry; // set itm to asymmetric_bry; EX: for İ, asymmetric_bry = i
nxts.Add_bry_obj(asymmetric_bry, rv); // add the asymmetric_bry to the hash; in above example, this allows "i" to match "İ"
}
}
return rv;
}
}

View File

@@ -1,68 +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.core.btries; import gplx.*; import gplx.core.*;
import gplx.intl.*;
public class Btrie_utf8_mgr implements Btrie_mgr {
private Btrie_utf8_itm root; private Gfo_case_mgr case_mgr;
Btrie_utf8_mgr(Gfo_case_mgr case_mgr) {
this.case_mgr = case_mgr;
this.root = new Btrie_utf8_itm(Bry_.Empty, null);
}
public int Count() {return count;} private int count;
public int Match_pos() {return match_pos;} private int match_pos;
public Object Match_bgn(byte[] src, int bgn_pos, int end_pos) {return Match_bgn_w_byte(src[bgn_pos], src, bgn_pos, end_pos);}
public Object Match_bgn_w_byte(byte b, byte[] src, int bgn_pos, int end_pos) {
Object rv = null; int cur_pos = match_pos = bgn_pos;
Btrie_utf8_itm cur = root;
while (true) {
int c_len = Utf8_.Len_of_char_by_1st_byte(b);
int c_end = cur_pos + c_len;
Btrie_utf8_itm nxt = cur.Nxts_find(src, cur_pos, c_end, true); if (nxt == null) return rv; // nxts does not have key; return rv;
cur_pos = c_end;
if (nxt.Nxts_is_empty()) {match_pos = cur_pos; return nxt.Val();} // nxt is leaf; return nxt.Val() (which should be non-null)
Object nxt_val = nxt.Val();
if (nxt_val != null) {match_pos = cur_pos; rv = nxt_val;} // nxt is node; cache rv (in case of false match)
if (cur_pos == end_pos) return rv; // increment cur_pos and exit if end
b = src[cur_pos];
cur = nxt;
}
}
public void Clear() {root.Clear(); count = 0;}
public Btrie_mgr Add_obj(String key, Object val) {return Add_obj(Bry_.new_u8(key), val);}
public Btrie_mgr Add_obj(byte[] key, Object val) {
if (val == null) throw Err_.new_("null objects cannot be registered").Add("key", String_.new_u8(key));
int key_len = key.length;
Btrie_utf8_itm cur = root;
int c_bgn = 0;
while (c_bgn < key_len) {
byte c = key[c_bgn];
int c_len = Utf8_.Len_of_char_by_1st_byte(c);
int c_end = c_bgn + c_len;
Btrie_utf8_itm nxt = cur.Nxts_find(key, c_bgn, c_end, false);
if (nxt == null)
nxt = cur.Nxts_add(case_mgr, Bry_.Mid(key, c_bgn, c_end), null);
c_bgn = c_end;
if (c_bgn == key_len)
nxt.Val_set(val);
cur = nxt;
}
++count;
return this;
}
public static Btrie_utf8_mgr new_(Gfo_case_mgr case_mgr) {return new Btrie_utf8_mgr(case_mgr);}
}

View File

@@ -66,7 +66,7 @@ public class Gfo_thread_cmd_unzip implements Gfo_thread_cmd {
Io_url zip_dir = Io_url_.Empty;
for (int i = 0; i < dirs_len; i++) {
Io_url dir = dirs[i];
if (String_.HasAtBgn(String_.Lower(dir.NameOnly()), String_.Lower(trg.NameOnly()))) { // HACK: check that directory starts with archive name; DATE:2013-12-22
if (String_.Has_at_bgn(String_.Lower(dir.NameOnly()), String_.Lower(trg.NameOnly()))) { // HACK: check that directory starts with archive name; DATE:2013-12-22
zip_dir = dir;
break;
}

View File

@@ -15,12 +15,12 @@ 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.dbs.schemas; import gplx.*; import gplx.dbs.*;
import gplx.dbs.schemas.updates.*;
package gplx.dbs.metas; import gplx.*; import gplx.dbs.*;
import gplx.dbs.metas.updates.*;
public class Schema_db_mgr {
public Schema_loader_mgr Loader() {return loader;} public void Loader_(Schema_loader_mgr v) {loader = v;} private Schema_loader_mgr loader;
public Schema_update_mgr Updater() {return updater;} private final Schema_update_mgr updater = new Schema_update_mgr();
public Schema_tbl_mgr Tbl_mgr() {return tbl_mgr;} private final Schema_tbl_mgr tbl_mgr = new Schema_tbl_mgr();
public Meta_tbl_mgr Tbl_mgr() {return tbl_mgr;} private final Meta_tbl_mgr tbl_mgr = new Meta_tbl_mgr();
public void Init(Db_conn conn) {
loader.Load(this, conn);
updater.Update(this, conn);

View File

@@ -15,7 +15,7 @@ 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.dbs.schemas; import gplx.*; import gplx.dbs.*;
package gplx.dbs.metas; import gplx.*; import gplx.dbs.*;
public interface Schema_loader_mgr {
void Load(Schema_db_mgr db_mgr, Db_conn conn);
}

View File

@@ -15,7 +15,7 @@ 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.dbs.schemas; import gplx.*; import gplx.dbs.*;
package gplx.dbs.metas; import gplx.*; import gplx.dbs.*;
import gplx.dbs.qrys.*;
public class Schema_loader_mgr_ {
public static final Schema_loader_mgr Null = new Schema_loader_mgr__null();
@@ -27,19 +27,22 @@ class Schema_loader_mgr__null implements Schema_loader_mgr {
class Schema_loader_mgr__sqlite implements Schema_loader_mgr {
public void Load(Schema_db_mgr db_mgr, Db_conn conn) {
Gfo_usr_dlg_.I.Log_many("", "", "db.schema.load.bgn: conn=~{0}", conn.Conn_info().Xto_api());
Schema_tbl_mgr tbl_mgr = db_mgr.Tbl_mgr();
Meta_tbl_mgr tbl_mgr = db_mgr.Tbl_mgr();
Db_qry__select_in_tbl qry = Db_qry__select_in_tbl.new_("sqlite_master", String_.Ary_empty, String_.Ary("type", "name", "sql"), Db_qry__select_in_tbl.Order_by_null);
Db_rdr rdr = conn.Stmt_new(qry).Exec_select__rls_auto();
try {
while (rdr.Move_next()) {
int type = Schema_itm_tid.Xto_int(rdr.Read_str(0));
switch (type) {
case Schema_itm_tid.Tid_table:
Schema_tbl_itm tbl_itm = new Schema_tbl_itm(rdr.Read_str(1), rdr.Read_str(2));
String type_str = rdr.Read_str("type");
String name = rdr.Read_str("name");
String sql = rdr.Read_str("sql");
int type_int = Meta_itm_tid.Xto_int(type_str);
switch (type_int) {
case Meta_itm_tid.Tid_table:
Meta_tbl_itm tbl_itm = new Meta_tbl_itm(name, sql);
tbl_mgr.Add(tbl_itm);
break;
case Schema_itm_tid.Tid_index: break; // noop for now
default: throw Err_.unhandled(type);
case Meta_itm_tid.Tid_index: break; // noop for now
default: throw Err_.unhandled(type_str);
}
}
} finally {rdr.Rls();}

View File

@@ -15,7 +15,7 @@ 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.dbs.schemas.updates; import gplx.*; import gplx.dbs.*; import gplx.dbs.schemas.*;
package gplx.dbs.metas.updates; import gplx.*; import gplx.dbs.*; import gplx.dbs.metas.*;
public interface Schema_update_cmd {
String Name();
boolean Exec_is_done();

View File

@@ -15,7 +15,7 @@ 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.dbs.schemas.updates; import gplx.*; import gplx.dbs.*; import gplx.dbs.schemas.*;
package gplx.dbs.metas.updates; import gplx.*; import gplx.dbs.*; import gplx.dbs.metas.*;
import gplx.dbs.engines.sqlite.*;
public class Schema_update_cmd_ {
public static Schema_update_cmd Make_tbl_create(String tbl_name, String tbl_sql, Db_idx_itm... tbl_idxs) {return new Schema_update_cmd__tbl_create(tbl_name, tbl_sql, tbl_idxs);}

View File

@@ -15,7 +15,7 @@ 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.dbs.schemas.updates; import gplx.*; import gplx.dbs.*; import gplx.dbs.schemas.*;
package gplx.dbs.metas.updates; import gplx.*; import gplx.dbs.*; import gplx.dbs.metas.*;
public class Schema_update_mgr {
private List_adp cmds = List_adp_.new_();
public void Add(Schema_update_cmd cmd) {cmds.Add(cmd);}

View File

@@ -15,7 +15,7 @@ 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.dbs.schemas.updates; import gplx.*; import gplx.dbs.*; import gplx.dbs.schemas.*;
package gplx.dbs.metas.updates; import gplx.*; import gplx.dbs.*; import gplx.dbs.metas.*;
import org.junit.*; import gplx.dbs.*;
public class Schema_update_mgr_tst {
@Before public void init() {fxt.Clear();} private Schema_update_mgr_fxt fxt = new Schema_update_mgr_fxt();
@@ -23,7 +23,7 @@ public class Schema_update_mgr_tst {
fxt.Test_exec_y(new Schema_update_cmd__mock());
}
@Test public void Delete() {
fxt.Init_itm(Schema_itm_tid.Tid_table, Schema_update_cmd__mock.Tbl_name);
fxt.Init_itm(Meta_itm_tid.Tid_table, Schema_update_cmd__mock.Tbl_name);
fxt.Test_exec_n(new Schema_update_cmd__mock());
}
}
@@ -34,7 +34,7 @@ class Schema_update_mgr_fxt {
db_mgr = new Schema_db_mgr();
}
public void Init_itm(int tid, String name) {
db_mgr.Tbl_mgr().Add(new Schema_tbl_itm(name, "sql"));
db_mgr.Tbl_mgr().Add(new Meta_tbl_itm(name, "sql"));
}
public void Test_exec_y(Schema_update_cmd cmd) {Test_exec(cmd, Bool_.Y);}
public void Test_exec_n(Schema_update_cmd cmd) {Test_exec(cmd, Bool_.N);}

View File

@@ -46,7 +46,13 @@ public class Fsdb_db_mgr__v1 implements Fsdb_db_mgr {
Io_url url = file_dir.GenSubFil_nest(mnt_name, bin_name); // EX: /xowa/enwiki/fsdb.main/fsdb.bin.0000.sqlite3
return new Fsdb_db_file(url, Db_conn_bldr.I.Get(url));
}
public Fsdb_db_file File__bin_file__new(int mnt_id, String file_name) {throw Err_.not_implemented_();}
public Fsdb_db_file File__bin_file__new(int mnt_id, String file_name) {
String mnt_name = mnt_id == Fsm_mnt_mgr.Mnt_idx_main ? Fsm_mnt_tbl.Mnt_name_main : Fsm_mnt_tbl.Mnt_name_user;
Io_url url = file_dir.GenSubFil_nest(mnt_name, file_name); // EX: /xowa/enwiki/fsdb.main/fsdb.bin.0000.sqlite3
Db_conn conn = Db_conn_bldr.I.New(url);
Fsd_bin_tbl bin_tbl = new Fsd_bin_tbl(conn, Bool_.Y); bin_tbl.Create_tbl();
return new Fsdb_db_file(url, conn);
}
public static final String Orig_name = "wiki.orig#00.sqlite3", Mnt_name = "wiki.mnt.sqlite3", Abc_name = "fsdb.abc.sqlite3", Atr_name= "fsdb.atr.00.sqlite3";
private static Fsdb_db_file get_db(Io_url file) {
Db_conn conn = Db_conn_bldr.I.Get(file);

View File

@@ -20,7 +20,7 @@ import gplx.dbs.*; import gplx.dbs.cfgs.*; import gplx.fsdb.meta.*; import gplx.
import gplx.xowa.*; import gplx.xowa.wikis.data.*; import gplx.xowa.bldrs.infos.*;
public class Fsdb_db_mgr__v2_bldr {
public Fsdb_db_mgr__v2 Get_or_make(Xow_wiki wiki, boolean delete_if_exists) { // NOTE: must check if file exists else imports with existing v2 dbs will fail; DATE:2015-05-23
Xowd_db_layout layout = wiki.Data_mgr__core_mgr().Props().Layout_file();
Xowd_db_layout layout = wiki.Data__core_mgr().Props().Layout_file();
String domain_str = wiki.Domain_str();
Io_url wiki_dir = wiki.Fsys_mgr().Root_dir();
String main_core_name = Main_core_name(layout, domain_str);
@@ -99,7 +99,7 @@ public class Fsdb_db_mgr__v2_bldr {
}
public static void Make_cfg_data(Xow_wiki wiki, String file_core_name, Fsdb_db_file file, byte file_tid, int part_id) {
Db_cfg_tbl cfg_tbl = file.Tbl__cfg();
Xowd_db_file core_db = wiki.Data_mgr__core_mgr().Db__core();
Xowd_db_file core_db = wiki.Data__core_mgr().Db__core();
core_db.Info_session().Save(cfg_tbl);
Xob_info_file info_file = new Xob_info_file(-1, Xowd_db_file_.To_key(file_tid), Xob_info_file.Ns_ids_empty, part_id, Guid_adp_.new_(), 2, file_core_name, file.Url().NameAndExt());
info_file.Save(cfg_tbl);

View File

@@ -68,7 +68,13 @@ public class Fsd_bin_tbl implements RlsAble {
Db_rdr rdr = stmt_select.Clear().Crt_int(fld_owner_id, owner_id).Exec_select__rls_manual();
try {
if (rdr.Move_next()) {
byte[] rv = rdr.Read_bry(fld_data);
byte[] rv = null;
try {rv = rdr.Read_bry(fld_data);}
catch (Exception e) {
if (Op_sys.Cur().Tid_is_drd() && String_.Has(Err_.Message_lang(e), "get field slot from row")) { // get field slot from row 0 col 0 failed
rv = rdr.Read_bry_in_parts(tbl_name, fld_data, fld_owner_id, owner_id);
}
}
return rv == null ? Bry_.Empty : rv; // NOTE: bug in v0.10.1 where .ogg would save as null; return Bry_.Empty instead, else java.io.ByteArrayInputStream would fail on null
}
else

View File

@@ -20,13 +20,14 @@ import gplx.ios.*; import gplx.dbs.*;
import gplx.fsdb.data.*;
public class Fsm_bin_fil {
private final Fsd_bin_tbl tbl;
public Fsm_bin_fil(int id, String url_rel, long bin_len, Db_conn conn, boolean schema_is_1) {
this.id = id; this.url_rel = url_rel; this.bin_len = bin_len; this.conn = conn;
public Fsm_bin_fil(boolean schema_is_1, int id, Io_url url, String url_rel, Db_conn conn, long bin_len) {
this.id = id; this.url = url; this.url_rel = url_rel; this.conn = conn; this.bin_len = bin_len;
this.tbl = new Fsd_bin_tbl(conn, schema_is_1);
}
public int Id() {return id;} private final int id;
public Io_url Url() {return url;} private Io_url url;
public String Url_rel() {return url_rel;} private final String url_rel;
public long Bin_len() {return bin_len;} private void Bin_len_(long v) {bin_len = v;} private long bin_len;
public long Bin_len() {return bin_len;} public void Bin_len_(long v) {bin_len = v;} private long bin_len;
public Db_conn Conn() {return conn;} private final Db_conn conn;
public boolean Select_to_url(int id, Io_url url) {return tbl.Select_to_url(id, url);}
public Io_stream_rdr Select_as_rdr(int id) {return tbl.Select_as_rdr(id);}

View File

@@ -29,11 +29,12 @@ public class Fsm_bin_mgr {
this.dbs__ary_len = dbs__ary.length;
if (dbs__ary_len > 0) this.nth_db = dbs__ary[dbs__ary_len - 1];
}
public int Dbs__len() {return dbs__ary_len;}
public Fsm_bin_fil Dbs__get_nth() {return nth_db;}
public Fsm_bin_fil Dbs__get_at(int i) {return dbs__ary[i];}
public Fsm_bin_fil Dbs__make(String file_name) {
Fsdb_db_file db = core_mgr.File__bin_file__new(mnt_id, file_name);
Fsm_bin_fil rv = new Fsm_bin_fil(dbs__ary_len, db.Url().NameAndExt(), Fsm_bin_fil.Bin_len_null, db.Conn(), core_mgr.File__schema_is_1());
Fsm_bin_fil rv = new Fsm_bin_fil(core_mgr.File__schema_is_1(), dbs__ary_len, db.Url(), db.Url().NameAndExt(), db.Conn(), Fsm_bin_fil.Bin_len_null);
tbl.Insert(rv.Id(), rv.Url_rel());
Dbs__add(rv);
return rv;

View File

@@ -19,19 +19,27 @@ package gplx.fsdb.meta; import gplx.*; import gplx.fsdb.*;
import gplx.dbs.*; import gplx.dbs.qrys.*;
public class Fsm_bin_tbl {
private final String tbl_name; private final Db_meta_fld_list flds = Db_meta_fld_list.new_();
private final String fld_uid, fld_url;
private final String fld_uid, fld_url, fld_bin_len, fld_bin_max;
private final Db_conn conn; private int mnt_id;
public Fsm_bin_tbl(Db_conn conn, boolean schema_is_1, int mnt_id) {
this.conn = conn; this.mnt_id = mnt_id;
String fld_prefix = "";
if (schema_is_1) {tbl_name = "fsdb_db_bin";}
else {tbl_name = "fsdb_dbb"; fld_prefix = "dbb_";}
if (schema_is_1) {tbl_name = "fsdb_db_bin";}
else {tbl_name = "fsdb_dbb"; fld_prefix = "dbb_";}
fld_uid = flds.Add_int_pkey (fld_prefix + "uid");
fld_url = flds.Add_str (fld_prefix + "url", 255);
if (schema_is_1) {
fld_bin_len = flds.Add_long("bin_len");
fld_bin_max = flds.Add_long("bin_max");
}
else {
fld_bin_len = Db_meta_fld.Key_null;
fld_bin_max = Db_meta_fld.Key_null;
}
}
public void Create_tbl() {conn.Ddl_create_tbl(Db_meta_tbl.new_(tbl_name, flds));}
public void Insert(int id, String url_rel) {
conn.Stmt_insert(tbl_name, flds).Crt_int(fld_uid, id).Val_str(fld_url, url_rel).Exec_insert();
conn.Stmt_insert(tbl_name, flds).Crt_int(fld_uid, id).Val_str(fld_url, url_rel).Val_long(fld_bin_len, 0).Val_long(fld_bin_max, 0).Exec_insert();
}
public Fsm_bin_fil[] Select_all(Fsdb_db_mgr db_conn_mgr) {
List_adp rv = List_adp_.new_();
@@ -41,7 +49,7 @@ public class Fsm_bin_tbl {
int bin_id = rdr.Read_int(fld_uid);
String bin_url = rdr.Read_str(fld_url);
Fsdb_db_file bin_db = db_conn_mgr.File__bin_file__at(mnt_id, bin_id, bin_url);
Fsm_bin_fil itm = new Fsm_bin_fil(bin_id, bin_url, Fsm_bin_fil.Bin_len_null, bin_db.Conn(), db_conn_mgr.File__schema_is_1());
Fsm_bin_fil itm = new Fsm_bin_fil(db_conn_mgr.File__schema_is_1(), bin_id, bin_db.Url(), bin_url, bin_db.Conn(), Fsm_bin_fil.Bin_len_null);
rv.Add(itm);
}
} finally {rdr.Rls();}

View File

@@ -147,7 +147,7 @@ class Gfs_parser_fxt {
catch (Exception e) {
String actl_err = Err_.Message_gplx_brief(e);
actl_err = String_.GetStrBefore(actl_err, ":");
boolean match = String_.HasAtBgn(actl_err, expd_err);
boolean match = String_.Has_at_bgn(actl_err, expd_err);
if (!match) Tfds.Fail("expecting '" + expd_err + "' got '" + actl_err + "'");
return;
}

View File

@@ -26,7 +26,7 @@ public class Xoa_app_ {
boot_mgr.Run(args);
}
public static final String Name = "xowa";
public static final String Version = "2.6.3.1";
public static final String Version = "2.6.4.1";
public static String Build_date = "2012-12-30 00:00:00";
public static String Op_sys;
public static String User_agent = "";

View File

@@ -42,7 +42,7 @@ public class Xoapi_url implements GfoInvkAble {
else {
for (int i = 0; i < urls_len; i++) {
String url = urls[i];
if (String_.HasAtBgn(url, "\"") && String_.HasAtBgn(url, "\""))
if (String_.Has_at_bgn(url, "\"") && String_.Has_at_bgn(url, "\""))
url = String_.Mid(url, 1, String_.Len(url) - 1);
app.Gui_mgr().Browser_win().Tab_mgr().Tabs_new_link(url, false);
}

View File

@@ -71,11 +71,11 @@ public class Xob_wiki_cfg_bldr_tst {
// line = String_.Replace(line, "/** ", "");
// int pos = String_.FindBwd(line, " (");
// if (pos == String_.Find_none) continue; // en; en_rtl have no "language" line
// if ( String_.HasAtBgn(lang_code, "be_")
// || String_.HasAtBgn(lang_code, "crh_")
// || String_.HasAtBgn(lang_code, "kk_")
// || String_.HasAtBgn(lang_code, "ku_")
// || String_.HasAtBgn(lang_code, "sr_")
// if ( String_.Has_at_bgn(lang_code, "be_")
// || String_.Has_at_bgn(lang_code, "crh_")
// || String_.Has_at_bgn(lang_code, "kk_")
// || String_.Has_at_bgn(lang_code, "ku_")
// || String_.Has_at_bgn(lang_code, "sr_")
// || String_.In(lang_code, "de_formal", "nb", "nl_informal", "nn", "no")
// ) {
// int new_pos = String_.FindBwd(line, " (", pos - 1);

View File

@@ -29,7 +29,7 @@ public abstract class Xob_categorylinks_base extends Xob_sql_dump_base implement
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) {
if (Bry_.Eq(fld_key, Fld_cl_from)) cur_id = Bry_.Xto_int_or(src, fld_bgn, fld_end, -1);
else if (Bry_.Eq(fld_key, Fld_cl_to)) cur_ctg = Bry_.Mid(src, fld_bgn, fld_end);
else if (Bry_.Eq(fld_key, Fld_cl_collation)) cur_collation_is_uca = Bry_.HasAtBgn(src, Collation_uca, fld_bgn, fld_end);
else if (Bry_.Eq(fld_key, Fld_cl_collation)) cur_collation_is_uca = Bry_.Has_at_bgn(src, Collation_uca, fld_bgn, fld_end);
else if (Bry_.Eq(fld_key, Fld_cl_timestamp)) {
date_parser.Parse_iso8651_like(cur_modified_on, src, fld_bgn, fld_end);
cur_date = fld_end - fld_bgn == 0 // ignore null dates added by ctg_v1

View File

@@ -0,0 +1,57 @@
/*
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.cmds.files; import gplx.*; import gplx.xowa.*; import gplx.xowa.bldrs.*; import gplx.xowa.bldrs.cmds.*;
import gplx.fsdb.meta.*;
class Xob_bin_db_itm {
public Xob_bin_db_itm(int id, Io_url db_url, int ns_id, int pt_id) {this.id = id; this.db_url = db_url; this.ns_id = ns_id; this.pt_id = pt_id;}
public int Id() {return id;} private int id;
public int Ns_id() {return ns_id;} private final int ns_id;
public int Pt_id() {return pt_id;} private int pt_id;
public long Db_len() {return db_len;} public void Db_len_(long v) {this.db_len = v;} private long db_len;
public Io_url Db_url() {return db_url;} public void Db_url_(Io_url v) {db_url = v;} private Io_url db_url;
public void Set(int id, int pt_id, Io_url db_url) {
this.id = id; this.pt_id = pt_id; this.db_url = db_url;
}
public static String Gen_name_v1(int pt_id) {
return String_.Format("fsdb.bin.{0}.sqlite3", Int_.Xto_str_pad_bgn_zero(pt_id, 4));
}
public static String Gen_name_v2(String domain_str, int ns_id, int pt_id) {
String ns_id_str = Int_.Xto_str_pad_bgn_zero(ns_id, 3);
String pt_id_str = Int_.Xto_str_pad_bgn_zero(pt_id, 3);
return String_.Format("{0}-file-ns.{1}-db.{2}.xowa", domain_str, ns_id_str, pt_id_str);
}
public static Xob_bin_db_itm new_v1(Fsm_bin_fil fil) {
byte[] name = Bry_.new_u8(fil.Url_rel()); // EX: "fsdb.bin.0000.sqlite3"
int ns_id = 0; // assume v1 dbs are all in main ns
int pt_id = Bry_.Xto_int_or(name, 9 , 13, Int_.MinValue); if (pt_id == Int_.MinValue) throw Err_.new_("bin_db_itm.parse: invalid pt_id; name={0} conn={1}", fil.Url_rel(), fil.Conn().Conn_info().Xto_raw());
return new Xob_bin_db_itm(fil.Id(), fil.Url(), ns_id, pt_id);
}
public static Xob_bin_db_itm new_v2(Fsm_bin_fil fil) {
byte[] ns_bgn_tkn = Bry_.new_a7("file-ns."), ns_end_tkn = Bry_.new_a7("-db."), pt_end_tkn = Bry_.new_a7(".xowa");
int ns_bgn_tkn_len = ns_bgn_tkn.length, ns_end_tkn_len = ns_end_tkn.length;
byte[] name = Bry_.new_u8(fil.Url_rel()); // EX: en.wikipedia.org-file-ns.000-db.001.xowa
int ns_bgn = Bry_finder.Find_fwd(name, ns_bgn_tkn, 0); if (ns_bgn == Bry_finder.Not_found) throw Err_.new_("bin_db_itm.parse: invalid ns_bgn; name={0} conn={1}", fil.Url_rel(), fil.Conn().Conn_info().Xto_raw());
ns_bgn += ns_bgn_tkn_len;
int ns_end = Bry_finder.Find_fwd(name, ns_end_tkn, ns_bgn); if (ns_end == Bry_finder.Not_found) throw Err_.new_("bin_db_itm.parse: invalid ns_end; name={0} conn={1}", fil.Url_rel(), fil.Conn().Conn_info().Xto_raw());
int pt_bgn = ns_end + ns_end_tkn_len;
int pt_end = Bry_finder.Find_fwd(name, pt_end_tkn, pt_bgn); if (pt_end == Bry_finder.Not_found) throw Err_.new_("bin_db_itm.parse: invalid pt_end; name={0} conn={1}", fil.Url_rel(), fil.Conn().Conn_info().Xto_raw());
int ns_id = Bry_.Xto_int_or(name, ns_bgn, ns_end, Int_.MinValue); if (ns_id == Int_.MinValue) throw Err_.new_("bin_db_itm.parse: invalid ns_id; name={0} conn={1}", fil.Url_rel(), fil.Conn().Conn_info().Xto_raw());
int pt_id = Bry_.Xto_int_or(name, pt_bgn, pt_end, Int_.MinValue); if (pt_id == Int_.MinValue) throw Err_.new_("bin_db_itm.parse: invalid pt_id; name={0} conn={1}", fil.Url_rel(), fil.Conn().Conn_info().Xto_raw());
return new Xob_bin_db_itm(fil.Id(), fil.Url(), ns_id, pt_id);
}
}

View File

@@ -0,0 +1,71 @@
/*
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.cmds.files; import gplx.*; import gplx.xowa.*; import gplx.xowa.bldrs.*; import gplx.xowa.bldrs.cmds.*;
import gplx.core.primitives.*; import gplx.ios.*;
import gplx.fsdb.meta.*;
class Xob_bin_db_mgr {
private final int[] ns_ids; private final int ns_ids_len;
private final Ordered_hash nth_hash = Ordered_hash_.new_(); private final Int_obj_ref tier_key = Int_obj_ref.neg1_();
public Xob_bin_db_mgr(int[] ns_ids) {
this.ns_ids = ns_ids; this.ns_ids_len = ns_ids.length;
}
public boolean Schema_is_1() {return schema_is_1;} private boolean schema_is_1;
public void Init_by_mnt_mgr(Fsm_mnt_mgr trg_mnt_mgr) {
Fsm_mnt_itm trg_mnt_itm = trg_mnt_mgr.Mnts__get_main();
this.schema_is_1 = trg_mnt_itm.Db_mgr().File__schema_is_1();
Fsm_bin_mgr bin_db_mgr = trg_mnt_itm.Bin_mgr();
int len = ns_ids_len;
for (int i = 0; i < len; ++i) { // iterate ns_ids and add default nth
int ns_id = ns_ids[i];
Xob_bin_db_itm nth = new Xob_bin_db_itm(-1, null, ns_id, 0);
nth_hash.Add(Int_obj_ref.new_(ns_ids[i]), nth);
}
len = bin_db_mgr.Dbs__len();
for (int i = 0; i < len; ++i) { // iterate bin_dbs to find max pt_id for each ns
Fsm_bin_fil fil = bin_db_mgr.Dbs__get_at(i);
Xob_bin_db_itm itm = schema_is_1 ? Xob_bin_db_itm.new_v1(fil) : Xob_bin_db_itm.new_v2(fil);
int ns_id = itm.Ns_id();
Xob_bin_db_itm nth = (Xob_bin_db_itm)nth_hash.Get_by(tier_key.Val_(ns_id));
if (itm.Pt_id() > nth.Pt_id()) // update max pt_id
nth.Set(itm.Id(), itm.Pt_id(), itm.Db_url()); // note that ns_id is same
}
len = nth_hash.Count();
for (int i = 0; i < len; ++i) { // iterated tiers to calculate max_size
Xob_bin_db_itm nth = (Xob_bin_db_itm)nth_hash.Get_at(i);
if (nth.Id() == -1) continue; // ignore default nth
IoItmFil nth_itm = Io_mgr.I.QueryFil(nth.Db_url());
nth.Db_len_(nth_itm.Size());
}
}
public boolean Tier_id_is_last(int tier_id) {return tier_id >= ns_ids_len;} // assumes tier_id is 0 based; EX: 0,1,2 for
public int Get_ns_id(int tier_id) {return ns_ids[tier_id];}
public int Increment_pt_id(Xob_bin_db_itm itm) {
itm.Set(-1, itm.Pt_id() + 1, null);
itm.Db_len_(0);
return itm.Pt_id();
}
public String Gen_name(String domain_str, int ns_id, int pt_id) {
return schema_is_1 ? Xob_bin_db_itm.Gen_name_v1(pt_id) : Xob_bin_db_itm.Gen_name_v2(domain_str, ns_id, pt_id);
}
public Xob_bin_db_itm Get_nth_by_tier(int tier_id) {
if (schema_is_1) return (Xob_bin_db_itm)nth_hash.Get_by(tier_key.Val_(0)); // v1 is always in ns_0
if (tier_id >= ns_ids_len) throw Err_.new_("tier out of range: tier_id={0} len={1}", tier_id, ns_ids_len);
int ns_id = ns_ids[tier_id];
return (Xob_bin_db_itm)nth_hash.Get_by(tier_key.Val_(ns_id));
}
}

View File

@@ -24,7 +24,7 @@ public class Xob_fsdb_make_cmd extends Xob_itm_basic_base implements Xob_cmd {
private Db_conn bldr_conn; private Db_cfg_tbl bldr_cfg_tbl;
private Xof_bin_mgr src_bin_mgr; private Xof_bin_wkr__fsdb_sql src_fsdb_wkr; private boolean src_bin_mgr__cache_enabled = Bool_.N; private String src_bin_mgr__fsdb_version; private String[] src_bin_mgr__fsdb_skip_wkrs; private boolean src_bin_mgr__wmf_enabled;
private Fsm_mnt_itm trg_mnt_itm; private Fsm_cfg_mgr trg_cfg_mgr; private Fsm_atr_fil trg_atr_fil; private Fsm_bin_fil trg_bin_fil; private long trg_bin_db_max;
private final Xof_bin_updater trg_bin_updater = new Xof_bin_updater(); private Xob_tier_namer tier_namer; private int[] ns_ids; private int prv_lnki_tier_id = -1;
private final Xof_bin_updater trg_bin_updater = new Xof_bin_updater(); private Xob_bin_db_mgr bin_db_mgr; private int[] ns_ids; private int prv_lnki_tier_id = -1;
private long download_size_max = Io_mgr.Len_mb_long * 5; private int[] download_keep_tier_ids = Int_.Ary(0);
private Xobu_poll_mgr poll_mgr; private int poll_interval; private long time_bgn;
private int select_interval = 2500, progress_interval = 1, commit_interval = 1, delete_interval = 5000;
@@ -41,7 +41,7 @@ public class Xob_fsdb_make_cmd extends Xob_itm_basic_base implements Xob_cmd {
public void Cmd_bgn(Xob_bldr bldr) {
wiki.Init_assert();
this.poll_interval = poll_mgr.Poll_interval();
this.tier_namer = new Xob_tier_namer(wiki.Domain_str(), ns_ids);
this.bin_db_mgr = new Xob_bin_db_mgr(ns_ids);
// src_bin_mgr
if (src_bin_mgr__fsdb_version != null) {
this.src_fsdb_wkr = Xof_bin_wkr__fsdb_sql.new_(wiki.File__mnt_mgr());
@@ -72,7 +72,9 @@ public class Xob_fsdb_make_cmd extends Xob_itm_basic_base implements Xob_cmd {
Fsm_mnt_mgr.Patch(trg_mnt_itm.Cfg_mgr().Tbl()); // NOTE: always patch again; fsdb_make may be run separately without lnki_temp; DATE:2014-04-26
this.trg_atr_fil = trg_mnt_itm.Atr_mgr().Db__core();
this.trg_cfg_mgr = trg_mnt_itm.Cfg_mgr();
bin_db_mgr.Init_by_mnt_mgr(trg_mnt_mgr);
trg_atr_fil.Conn().Txn_bgn();
trg_cfg_mgr.Tbl().Conn().Txn_bgn();
// bldr_db
Xob_db_file bldr_db = Xob_db_file.new__file_make(wiki.Fsys_mgr().Root_dir());
this.bldr_conn = bldr_db.Conn();
@@ -91,7 +93,7 @@ public class Xob_fsdb_make_cmd extends Xob_itm_basic_base implements Xob_cmd {
byte rslt = Select_fsdb_itms(list);
switch (rslt) {
case Select_rv_stop:
if (tier_namer.Is_last(tier_id_val))
if (bin_db_mgr.Tier_id_is_last(tier_id_val))
loop = false;
else {
++tier_id_val;
@@ -126,6 +128,7 @@ public class Xob_fsdb_make_cmd extends Xob_itm_basic_base implements Xob_cmd {
src_fsdb_wkr.Mnt_mgr().Mnts__get_main().Txn_end(); // NOTE: src_fsdb_wkr will be null if no src db defined
}
trg_atr_fil.Conn().Txn_end(); trg_atr_fil.Conn().Rls_conn();
trg_cfg_mgr.Tbl().Conn().Txn_end(); trg_cfg_mgr.Tbl().Conn().Rls_conn();
if (!trg_mnt_itm.Db_mgr().File__solo_file()) {
trg_bin_fil.Conn().Txn_end(); trg_bin_fil.Conn().Rls_conn();
}
@@ -222,13 +225,14 @@ public class Xob_fsdb_make_cmd extends Xob_itm_basic_base implements Xob_cmd {
usr_dlg.Warn_many("", "", "skipped; ttl=~{0} w=~{1} size=~{2} tier=~{3}", fsdb.Orig_ttl(), fsdb.Lnki_w(), src_rdr_len, lnki_tier_id);
return;
}
if (trg_bin_fil == null) // no trg_bin_fil
Make_trg_bin_file(fsdb);
else if (trg_bin_fil.Bin_len() + src_rdr_len > trg_bin_db_max) // or trg_bin_fil is out of space
Make_trg_bin_file(fsdb);
else if (prv_lnki_tier_id != lnki_tier_id) {
if (prv_lnki_tier_id != -1)
Make_trg_bin_file(fsdb);
if (trg_bin_fil == null) // no trg_bin_fil
Make_trg_bin_file(Bool_.Y, fsdb, src_rdr_len);
else if (trg_bin_fil.Bin_len() + src_rdr_len > trg_bin_db_max) // or trg_bin_fil is out of space
Make_trg_bin_file(Bool_.N, fsdb, src_rdr_len);
else if (prv_lnki_tier_id != lnki_tier_id) { // or tier has changed
if ( prv_lnki_tier_id != -1
&& !bin_db_mgr.Schema_is_1()) // do not increment dbs for v1
Make_trg_bin_file(Bool_.Y, fsdb, src_rdr_len);
prv_lnki_tier_id = lnki_tier_id;
}
trg_bin_updater.Save_bin(trg_mnt_itm, trg_atr_fil, trg_bin_fil, fsdb, src_rdr, src_rdr_len);
@@ -236,17 +240,34 @@ public class Xob_fsdb_make_cmd extends Xob_itm_basic_base implements Xob_cmd {
}
finally {src_rdr.Rls();}
}
private void Make_trg_bin_file(Xodb_tbl_oimg_xfer_itm fsdb) {
private void Make_trg_bin_file(boolean try_nth, Xodb_tbl_oimg_xfer_itm fsdb, long src_rdr_len) {
if ( trg_bin_fil != null // null-check needed for 1st call
&& !trg_mnt_itm.Db_mgr().File__solo_file()) // don't close if one file
trg_bin_fil.Conn().Txn_end(); // close txn
String trg_bin_fil_name = tier_namer.Gen_name_and_add(fsdb.Lnki_tier_id()); // gen name
this.trg_bin_fil = trg_mnt_itm.Bin_mgr().Dbs__make(trg_bin_fil_name); // create trg_bin_fil
if (!trg_mnt_itm.Db_mgr().File__solo_file()) {
Fsdb_db_file trg_bin_db = trg_mnt_itm.Db_mgr().File__bin_file__at(trg_mnt_itm.Id(), trg_bin_fil.Id(), trg_bin_fil_name);
Fsdb_db_mgr__v2_bldr.Make_cfg_data(wiki, trg_atr_fil.Url_rel(), trg_bin_db, Xowd_db_file_.Tid_file_data, trg_bin_fil.Id() + List_adp_.Base1);
trg_bin_fil.Conn().Txn_bgn();
boolean make = true;
int tier_id = fsdb.Lnki_tier_id();
Xob_bin_db_itm nth_bin_db = bin_db_mgr.Get_nth_by_tier(tier_id);
if (try_nth) { // try_nth is true; occurs for new runs or changed tier
if ( nth_bin_db.Id() != -1 // nth exists;
&& nth_bin_db.Db_len() + src_rdr_len < trg_bin_db_max) // if src_rdr_len exceeds
make = false; // do not make; use existing
}
if (make) { // no nth; make it;
int ns_id = bin_db_mgr.Get_ns_id(tier_id);
int pt_id = bin_db_mgr.Increment_pt_id(nth_bin_db);
String new_bin_db_name = bin_db_mgr.Gen_name(wiki.Domain_str(), ns_id, pt_id);
this.trg_bin_fil = trg_mnt_itm.Bin_mgr().Dbs__make(new_bin_db_name);
if (!trg_mnt_itm.Db_mgr().File__solo_file()) {
Fsdb_db_file trg_bin_db = trg_mnt_itm.Db_mgr().File__bin_file__at(trg_mnt_itm.Id(), trg_bin_fil.Id(), new_bin_db_name);
if (!bin_db_mgr.Schema_is_1())
Fsdb_db_mgr__v2_bldr.Make_cfg_data(wiki, trg_atr_fil.Url_rel(), trg_bin_db, Xowd_db_file_.Tid_file_data, trg_bin_fil.Id() + List_adp_.Base1);
}
}
else { // nth available; use it
this.trg_bin_fil = trg_mnt_itm.Bin_mgr().Dbs__get_at(nth_bin_db.Id());
trg_bin_fil.Bin_len_(nth_bin_db.Db_len());
}
trg_bin_fil.Conn().Txn_bgn();
}
private void Txn_sav() {
usr_dlg.Prog_many("", "", "committing data: count=~{0} failed=~{1}", exec_count, exec_fail);
@@ -255,6 +276,7 @@ public class Xob_fsdb_make_cmd extends Xob_itm_basic_base implements Xob_cmd {
bldr_cfg_tbl.Conn().Txn_sav();
trg_cfg_mgr.Next_id_commit();
trg_atr_fil.Conn().Txn_sav();
trg_cfg_mgr.Tbl().Conn().Txn_sav();
if (src_bin_mgr__fsdb_version != null && src_bin_mgr__fsdb_skip_wkrs != null) {
src_fsdb_wkr.Skip_mgr().Skip_term(src_fsdb_wkr.Mnt_mgr().Mnts__get_main().Cfg_mgr());
}
@@ -303,7 +325,7 @@ public class Xob_fsdb_make_cmd extends Xob_itm_basic_base implements Xob_cmd {
, Invk_src_bin_mgr__cache_enabled_ = "src_bin_mgr__cache_enabled_", Invk_ns_ids_ = "ns_ids_"
, Invk_download_size_max = "download_size_max", Invk_download_keep_tier_ids = "download_keep_tier_ids"
;
private static Fsdb_db_mgr new_src_bin_db_mgr(Xow_wiki wiki, String version) {
public static Fsdb_db_mgr new_src_bin_db_mgr(Xow_wiki wiki, String version) {
String domain_str = wiki.Domain_str();
Fsdb_db_mgr rv = null; Io_url url = null;
if (String_.Eq(version, "v1")) {
@@ -345,22 +367,3 @@ class Xodb_tbl_oimg_xfer_itm extends Xof_fsdb_itm { public int Lnki_id() {re
return rv;
}
}
class Xob_tier_namer {
private final String domain_str; private final int[] ns_ids;
private final int[] db_ids;
public Xob_tier_namer(String domain_str, int[] ns_ids) {
this.domain_str = domain_str;
this.ns_ids = ns_ids;
this.db_ids = new int[ns_ids.length];
}
public boolean Is_last(int v) {return v >= ns_ids.length;}
public int Db_id(int tier_id) {return db_ids[tier_id];}
public String Gen_name_and_add(int tier_id) {// en.wikipedia.org-file-ns.000-db.0001.xowa
if (tier_id >= ns_ids.length) throw Err_.new_("unknown grp: tier_id={0} len={1}", tier_id, ns_ids.length);
String ns_id = Int_.Xto_str_pad_bgn_zero(ns_ids[tier_id], 3);
int db_id_int = db_ids[tier_id];
db_ids[tier_id] = db_id_int + 1;
String db_id = Int_.Xto_str_pad_bgn_zero(db_id_int + List_adp_.Base1, 3);
return String_.Format("{0}-file-ns.{1}-db.{2}.xowa", domain_str, ns_id, db_id);
}
}

View File

@@ -38,8 +38,9 @@ public class Xob_xfer_regy_update_cmd extends Xob_itm_basic_base implements Xob_
Sqlite_engine_.Tbl_create_and_delete(make_db_provider, Xob_fsdb_regy_tbl.Tbl_name, Xob_fsdb_regy_tbl.Tbl_sql);
Sqlite_engine_.Db_attach(make_db_provider, "fsdb_db", fsdb_atr_url.Raw());
make_db_provider.Txn_bgn();
make_db_provider.Exec_sql(Xob_fsdb_regy_tbl.Update_regy_nil);
make_db_provider.Exec_sql(Xob_fsdb_regy_tbl.Insert_fsdb_fil);
String fsdb_thm_tbl = "fsdb_thm";
String fsdb_thm_tbl = fsdb_abc_mgr.Db_mgr().File__schema_is_1() ? "fsdb_xtn_thm" : "fsdb_thm";
String insert_sql_fsdb_thm = wiki.File_mgr().Fsdb_mgr().Mnt_mgr().Mnts__get_main().Cfg_mgr().Schema_thm_page() // Cfg_get(Fsm_cfg_mgr.Grp_core).Get_yn_or_n(Fsm_cfg_mgr.Key_schema_thm_page)
? String_.Format(Xob_fsdb_regy_tbl.Insert_fsdb_thm, fsdb_thm_tbl)
: Xob_fsdb_regy_tbl.Insert_fsdb_thm_v0
@@ -133,6 +134,7 @@ class Xob_fsdb_regy_tbl {
, " JOIN fsdb_db.fsdb_dir d ON f.fil_owner_id = d.dir_id"
, ";"
)
, Update_regy_nil = "UPDATE xfer_regy SET xfer_status = 0;"
, Update_regy_fil = String_.Concat_lines_nl
( "REPLACE INTO xfer_regy "
, "( lnki_id, lnki_tier_id, lnki_page_id, orig_page_id, orig_repo, lnki_ttl, orig_redirect_src, lnki_ext, orig_media_type"

View File

@@ -79,7 +79,7 @@ public class Xob_page_cmd extends Xob_itm_basic_base implements Xobd_wkr, GfoInv
Xowd_db_file db_core = db_mgr.Db__core();
db_core.Tbl__site_stats().Update(page_count_main, page_count_all, ns_mgr.Ns_file().Count()); // save page stats
db_core.Tbl__ns().Insert(ns_mgr); // save ns
db_mgr.Tbl__cfg().Insert_str(Xow_cfg_consts.Grp_wiki_init, "props.modified_latest", modified_latest.XtoStr_fmt(DateAdp_.Fmt_iso8561_date_time));
db_mgr.Tbl__cfg().Insert_str(Xow_cfg_consts.Grp__wiki_init, "props.modified_latest", modified_latest.XtoStr_fmt(DateAdp_.Fmt_iso8561_date_time));
if (idx_mode.Tid_is_end()) page_core_tbl.Create_index();
if (redirect_id_enabled) {
redirect_tbl.Conn().Txn_end();

View File

@@ -22,12 +22,12 @@ public class Xob_term_cmd extends Xob_term_base {
@Override public String Cmd_key() {return KEY;} public static final String KEY = "text.term";
@Override public void Cmd_end_hook() {
Io_mgr.I.DeleteDirDeep(wiki.Fsys_mgr().Tmp_dir());
Db_cfg_tbl cfg_tbl = wiki.Data_mgr__core_mgr().Tbl__cfg();
cfg_tbl.Insert_bry(Xow_cfg_consts.Grp_wiki_init, "props.bldr_version", wiki.Props().Bldr_version());
cfg_tbl.Insert_bry(Xow_cfg_consts.Grp_wiki_init, "props.main_page", wiki.Props().Main_page());
cfg_tbl.Insert_bry(Xow_cfg_consts.Grp_wiki_init, "props.siteinfo_misc", wiki.Props().Siteinfo_misc());
cfg_tbl.Insert_bry(Xow_cfg_consts.Grp_wiki_init, "props.siteinfo_mainpage", wiki.Props().Siteinfo_mainpage());
Db_cfg_tbl cfg_tbl = wiki.Data__core_mgr().Tbl__cfg();
cfg_tbl.Insert_bry(Xow_cfg_consts.Grp__wiki_init, "props.bldr_version", wiki.Props().Bldr_version());
cfg_tbl.Insert_bry(Xow_cfg_consts.Grp__wiki_init, Xow_cfg_consts.Key__init__main_page, wiki.Props().Main_page());
cfg_tbl.Insert_bry(Xow_cfg_consts.Grp__wiki_init, "props.siteinfo_misc", wiki.Props().Siteinfo_misc());
cfg_tbl.Insert_bry(Xow_cfg_consts.Grp__wiki_init, "props.siteinfo_mainpage", wiki.Props().Siteinfo_mainpage());
gplx.fsdb.Fsdb_db_mgr__v2_bldr.I.Get_or_make(wiki, false);// always build file.user db; DATE:2015-05-12
wiki.Data_mgr__core_mgr().Rls();
wiki.Data__core_mgr().Rls();
}
}

View File

@@ -119,8 +119,8 @@ public class Xob_cleanup_cmd extends Xob_itm_basic_base implements Xob_cmd {
if ( !String_.Eq(url.Ext(), ".xowa")
&& !String_.Eq(url.Ext(), ".sqlite3"))
continue;
if ( String_.HasAtBgn(url.NameAndExt(), file_prefix)
|| String_.HasAtBgn(url.NameAndExt(), html_prefix)
if ( String_.Has_at_bgn(url.NameAndExt(), file_prefix)
|| String_.Has_at_bgn(url.NameAndExt(), html_prefix)
) continue; // skip
Io_mgr.I.DeleteFil(url);
deleted++;

View File

@@ -22,7 +22,7 @@ public class Xob_page_dump_cmd_drop extends Xob_itm_basic_base implements Xob_cm
public String Cmd_key() {return Xob_cmd_keys.Key_wiki_page_dump_drop;}
public void Cmd_run() {
wiki.Init_assert();
Xowd_db_mgr db_mgr = wiki.Data_mgr__core_mgr();
Xowd_db_mgr db_mgr = wiki.Data__core_mgr();
int len = db_mgr.Dbs__len();
for (int i = 0; i < len; i++) {
Xowd_db_file db_file = db_mgr.Dbs__get_at(i);

View File

@@ -22,7 +22,7 @@ public class Xob_page_dump_cmd_make extends Xob_itm_basic_base implements Xob_cm
public String Cmd_key() {return Xob_cmd_keys.Key_wiki_page_dump_make;}
public void Cmd_run() {
wiki.Init_assert();
Xowd_db_mgr db_mgr = wiki.Data_mgr__core_mgr();
Xowd_db_mgr db_mgr = wiki.Data__core_mgr();
Io_url page_db_url = db_mgr.Db__core().Url();
int len = db_mgr.Dbs__len();
for (int i = 0; i < len; i++) {

View File

@@ -57,7 +57,7 @@ public class Xoa_css_extractor {
this.Install_by_wmf((Xowe_wiki)wiki, wiki_html_dir);
}
catch (Exception e) { // if error, failover; paranoia catch for outliers like bad network connectivity fail, or MediaWiki: message not existing; DATE:2013-11-21
wiki.App().Usr_dlg().Warn_many("", "", "failed while trying to generate css; failing over; wiki='~{0}' err=~{1}", wiki.Domain_str(), Err_.Message_gplx(e));
wiki.App().Usr_dlg().Warn_many("", "", "failed to get css; failing over; wiki='~{0}' err=~{1}", wiki.Domain_str(), Err_.Message_gplx(e));
Css_common_failover(); // only failover xowa_common.css; xowa_wiki.css comes from MediaWiki:Common.css / Vector.css
}
}
@@ -77,7 +77,7 @@ public class Xoa_css_extractor {
Logo_setup();
}
private boolean Install_by_db(Xow_wiki wiki, Io_url wiki_html_dir, String css_key) {
Xowd_db_mgr core_db_mgr = wiki.Data_mgr__core_mgr();
Xowd_db_mgr core_db_mgr = wiki.Data__core_mgr();
if ( core_db_mgr == null
|| core_db_mgr.Props() == null
|| core_db_mgr.Props().Schema_is_1()

View File

@@ -70,7 +70,7 @@ public class Xoa_css_img_downloader {
continue;
}
byte[] img_raw = Bry_.Mid(src, bgn_pos, end_pos); int img_raw_len = img_raw.length;
if (Bry_.HasAtBgn(img_raw, Bry_data_image, 0, img_raw_len)) { // base64
if (Bry_.Has_at_bgn(img_raw, Bry_data_image, 0, img_raw_len)) { // base64
bfr.Add_mid(src, prv_pos, end_pos); // nothing to download; just add entire String
prv_pos = end_pos;
continue;
@@ -104,7 +104,7 @@ public class Xoa_css_img_downloader {
}
}
public static byte[] Import_url_build(byte[] stylesheet_prefix, byte[] rel_url_prefix, byte[] css_url) {
return Bry_.HasAtBgn(css_url, Bry_http_protocol) // css_url already starts with "http"; return self; PAGE:tr.n:Main_Page; DATE:2014-06-04
return Bry_.Has_at_bgn(css_url, Bry_http_protocol) // css_url already starts with "http"; return self; PAGE:tr.n:Main_Page; DATE:2014-06-04
? css_url
: Bry_.Add(stylesheet_prefix, css_url)
;
@@ -141,8 +141,8 @@ public class Xoa_css_img_downloader {
;
public byte[] Clean_img_url(byte[] raw, int raw_len) {
int pos_bgn = 0;
if (Bry_.HasAtBgn(raw, Bry_fwd_slashes, 0, raw_len)) pos_bgn = Bry_fwd_slashes.length;
if (Bry_.HasAtBgn(raw, Bry_http, 0, raw_len)) pos_bgn = Bry_http.length;
if (Bry_.Has_at_bgn(raw, Bry_fwd_slashes, 0, raw_len)) pos_bgn = Bry_fwd_slashes.length;
if (Bry_.Has_at_bgn(raw, Bry_http, 0, raw_len)) pos_bgn = Bry_http.length;
int pos_slash = Bry_finder.Find_fwd(raw, Byte_ascii.Slash, pos_bgn, raw_len);
if (pos_slash == Bry_.NotFound) return null; // first segment is site_name; at least one slash must be present for image name; EX: site.org/img_name.jpg
if (pos_slash == raw_len - 1) return null; // "site.org/" is invalid

View File

@@ -24,7 +24,7 @@ class Xob_css_parser__import {
public Xob_css_tkn__base Parse(byte[] src, int src_len, int tkn_bgn, int tkn_end) { // " @import"
int bgn_pos = Bry_finder.Find_fwd_while_ws(src, tkn_end, src_len); // skip any ws after " @import"
if (bgn_pos == src_len) return Xob_css_tkn__warn.new_(tkn_bgn, tkn_end, "mirror.parser.import:EOS after import; bgn=~{0}", tkn_bgn);
if (!Bry_.HasAtBgn(src, Tkn_url_bry, bgn_pos, src_len)) return Xob_css_tkn__warn.new_(tkn_bgn, tkn_end, "mirror.parser.import:url missing; bgn=~{0}", tkn_bgn);
if (!Bry_.Has_at_bgn(src, Tkn_url_bry, bgn_pos, src_len)) return Xob_css_tkn__warn.new_(tkn_bgn, tkn_end, "mirror.parser.import:url missing; bgn=~{0}", tkn_bgn);
tkn_end = bgn_pos + Tkn_url_bry.length;
Xob_css_tkn__base frag = url_parser.Parse(src, src_len, bgn_pos, tkn_end);
if (frag.Tid() != Xob_css_tkn__url.Tid_url) return Xob_css_tkn__warn.new_(tkn_bgn, frag.Pos_end(), "mirror.parser.import:url invalid; bgn=~{0}", tkn_bgn);

View File

@@ -47,7 +47,7 @@ class Xob_css_parser__url {
else
return Xob_css_tkn__warn.new_(tkn_bgn, end_pos, "mirror.parser.url:base64 dangling; bgn=~{0} excerpt=~{1}", bgn_pos, String_.new_u8(url_orig));
}
if (Bry_.HasAtBgn(url_orig, Bry_data_image)) // base64
if (Bry_.Has_at_bgn(url_orig, Bry_data_image)) // base64
return Xob_css_tkn__base64.new_(tkn_bgn, end_pos);
byte[] src_url = Xob_url_fixer.Fix(site, url_orig, url_orig_len);
if (src_url == null) // could not convert

View File

@@ -47,7 +47,7 @@ abstract class Xoctg_fmtr_itm_base implements Xoctg_fmtr_itm {
Xoa_ttl ttl = itm.Ttl();
byte[] itm_sortkey = itm.Sortkey();
byte[] ttl_bry = ttl.Page_txt();
if (!Bry_.HasAtBgn(itm_sortkey, ttl_char_0, 0, itm_sortkey.length)) {
if (!Bry_.Has_at_bgn(itm_sortkey, ttl_char_0, 0, itm_sortkey.length)) {
grp_end_idx = i;
grp_end_at_col = i == col_end;
return;

View File

@@ -31,13 +31,13 @@ public class Xodb_load_mgr_sql implements Xodb_load_mgr {
}
public void Load_init(Xowe_wiki wiki) {
Load_init_cfg(wiki);
Xowd_db_file db_core = wiki.Data_mgr__core_mgr().Db__core();
Xowd_db_file db_core = wiki.Data__core_mgr().Db__core();
db_core.Tbl__site_stats().Select(wiki.Stats());
db_core.Tbl__ns().Select_all(wiki.Ns_mgr());
}
private void Load_init_cfg(Xowe_wiki wiki) {
String version_key = Xoa_gfs_mgr.Build_code(Xowe_wiki.Invk_props, Xow_wiki_props.Invk_bldr_version);
Db_cfg_hash cfg_hash = db_mgr.Core_data_mgr().Tbl__cfg().Select_as_hash(Xow_cfg_consts.Grp_wiki_init);
Db_cfg_hash cfg_hash = db_mgr.Core_data_mgr().Tbl__cfg().Select_as_hash(Xow_cfg_consts.Grp__wiki_init);
String version_val = cfg_hash.Get(version_key).To_str_or("");
Xodb_upgrade_mgr.Upgrade(db_mgr, cfg_hash, version_key, version_val);
Bry_bfr bfr = wiki.Utl__bfr_mkr().Get_k004();

View File

@@ -39,7 +39,7 @@ public class Xodb_mgr_sql implements Xodb_mgr, GfoInvkAble {
return Io_mgr.I.QueryFil(url).ModifiedTime();
}
public void Category_version_update(boolean version_is_1) {
String grp = Xow_cfg_consts.Grp_wiki_init;
String grp = Xow_cfg_consts.Grp__wiki_init;
String key = Xoa_gfs_mgr.Build_code(Xowe_wiki.Invk_db_mgr, Xodb_mgr_sql.Invk_category_version);
core_data_mgr.Tbl__cfg().Delete_val(grp, key);// always delete ctg version
category_version = version_is_1 ? Xoa_ctg_mgr.Version_1 : Xoa_ctg_mgr.Version_2;

View File

@@ -22,7 +22,7 @@ class Xodb_page_rdr__sql implements Xodb_page_rdr {
private final Xowd_db_mgr db_mgr;
private final Xowd_page_tbl page_tbl; private final Db_rdr rdr;
public Xodb_page_rdr__sql(Xowe_wiki wiki) {
this.db_mgr = wiki.Data_mgr__core_mgr();
this.db_mgr = wiki.Data__core_mgr();
this.page_tbl = db_mgr.Tbl__page();
this.rdr = page_tbl.Select_all();
}

View File

@@ -25,7 +25,7 @@ class Xodb_upgrade_mgr {
// version_new = "0.6.2.1";
// }
// if (version_new != null) {
// db_mgr.Tbl_xowa_cfg().Update(Xodb_mgr_sql.Grp_wiki_init, version_key, version_new);
// db_mgr.Tbl_xowa_cfg().Update(Xodb_mgr_sql.Grp__wiki_init, version_key, version_new);
// }
}
}
@@ -45,7 +45,7 @@ class Xodb_upgrade_mgr {
// byte data_storage_format_byte = Byte_.parse_(kv.Val_to_str_or_empty());
// String data_storage_format_name = Xoi_dump_mgr.Wtr_tid_to_str(data_storage_format_byte);
// kv.Val_(data_storage_format_name); // update memory
// db_mgr.Tbl_xowa_cfg().Update(Xodb_mgr_sql.Grp_wiki_init, gfs_data_storage_format, data_storage_format_name); // update_database
// db_mgr.Tbl_xowa_cfg().Update(Xodb_mgr_sql.Grp__wiki_init, gfs_data_storage_format, data_storage_format_name); // update_database
// break;
// }
// }

View File

@@ -23,6 +23,5 @@ public class Xof_lnki_page {
public static boolean Null_n(int v) {return v != Null;}
public static int Db_load_int(DataRdr rdr, String fld) {return rdr.ReadInt(fld);}
public static int Db_load_int(Db_rdr rdr, String fld) {return rdr.Read_int(fld);}
public static int Db_load_int(Db_rdr rdr, int ord) {return rdr.Read_int(ord);}
public static int Db_save_int(int v) {return v;}
}

View File

@@ -24,7 +24,6 @@ public class Xof_lnki_time {
public static int Db_save_int(double v) {return (int)v;}
public static double Db_load_int(DataRdr rdr, String fld) {return rdr.ReadInt(fld);}
public static double Db_load_int(Db_rdr rdr, String fld) {return rdr.Read_int(fld);}
public static double Db_load_int(Db_rdr rdr, int ord) {return rdr.Read_int(ord);}
public static int X_int(double v) {return (int)v;}
public static String X_str(double v) {return Double_.Xto_str(v);}
public static final double Null = -1;

View File

@@ -118,8 +118,9 @@ public class Xow_file_mgr implements GfoInvkAble {
if (db_core != null) return; // already init'd
this.db_core = Fsdb_db_mgr_.new_detect(wiki, wiki.Fsys_mgr().Root_dir(), wiki.Fsys_mgr().File_dir());
// if (db_core == null) return; // no fsdb_core found; exit
if (db_core == null)
if (db_core == null) {
db_core = Fsdb_db_mgr__v2_bldr.I.Get_or_make(wiki, false);
}
this.version = Version_2;
this.fsdb_mode = Xof_fsdb_mode.new_v2_gui();
orig_mgr.Init_by_wiki(wiki, fsdb_mode, db_core.File__orig_tbl_ary(), Xof_url_bldr.new_v2());

View File

@@ -88,6 +88,7 @@ public class Xof_bin_mgr {
fsdb.File_exists_y_();
return rv;
}
if (fsdb.Orig_ext().Id_is_video()) continue; // item is video; don't download orig as imageMagick can't thumbnail it; DATE:2015-06-16
rv = wkr.Get_as_rdr(fsdb, Bool_.N, fsdb.Orig_w()); // thumb missing; get orig;
if (rv == Io_stream_rdr_.Noop) {
usr_dlg.Log_direct(String_.Format("bin_mgr:thumb not found; wkr={0} ttl={1} w={2}", wkr.Key(), fsdb.Orig_ttl(), fsdb.Lnki_w()));
@@ -108,7 +109,7 @@ public class Xof_bin_mgr {
}
private boolean Resize(int exec_tid, Xof_fsdb_itm itm, boolean file_is_orig, Io_url src, Io_url trg) {
tmp_size.Html_size_calc(exec_tid, itm.Lnki_w(), itm.Lnki_h(), itm.Lnki_type(), mnt_mgr.Patch_upright(), itm.Lnki_upright(), itm.Orig_ext().Id(), itm.Orig_w(), itm.Orig_h(), Xof_img_size.Thumb_width_img);
boolean rv = resizer.Exec(src, trg, tmp_size.Html_w(), tmp_size.Html_h(), itm.Orig_ext().Id(), resize_warning);
boolean rv = resizer.Resize_exec(src, trg, tmp_size.Html_w(), tmp_size.Html_h(), itm.Orig_ext().Id(), resize_warning);
itm.File_resized_y_();
return rv;
}

View File

@@ -18,5 +18,5 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
package gplx.xowa.files.cnvs; import gplx.*; import gplx.xowa.*; import gplx.xowa.files.*;
import gplx.core.primitives.*;
public interface Xof_img_wkr_resize_img {
boolean Exec(Io_url src, Io_url trg, int trg_w, int trg_h, int ext_id, String_obj_ref rslt_val);
boolean Resize_exec(Io_url src, Io_url trg, int trg_w, int trg_h, int ext_id, String_obj_ref rslt_val);
}

View File

@@ -23,7 +23,7 @@ public class Xof_img_wkr_resize_img_imageMagick implements Xof_img_wkr_resize_im
public Xof_img_wkr_resize_img_imageMagick(Xowmf_mgr wmf_mgr, ProcessAdp cmd_convert, ProcessAdp cmd_convert_svg_to_png) {
this.wmf_mgr = wmf_mgr; this.cmd_convert = cmd_convert; this.cmd_convert_svg_to_png = cmd_convert_svg_to_png;
}
public boolean Exec(Io_url src, Io_url trg, int trg_w, int trg_h, int ext_id, String_obj_ref rslt_val) {
public boolean Resize_exec(Io_url src, Io_url trg, int trg_w, int trg_h, int ext_id, String_obj_ref rslt_val) {
if (!Io_mgr.I.ExistsFil(src)) return false;
Io_mgr.I.CreateDirIfAbsent(trg.OwnerDir());
if (init_needed) {
@@ -38,6 +38,6 @@ public class Xof_img_wkr_resize_img_imageMagick implements Xof_img_wkr_resize_im
rslt_val.Val_(cmd.Rslt_out());
boolean rv = cmd.Exit_code_pass();
if (!rv) Xoa_app_.Usr_dlg().Log_many("", "process_warning", "process completed with warnings: ~{0}", cmd.Rslt_out());
return true;
return rv; // NOTE: was true (?); DATE:2015-06-16
}
}

View File

@@ -18,7 +18,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
package gplx.xowa.files.cnvs; import gplx.*; import gplx.xowa.*; import gplx.xowa.files.*;
import gplx.core.primitives.*; import gplx.gfui.*; import gplx.xowa.files.cnvs.*;
public class Xof_img_wkr_resize_img_mok implements Xof_img_wkr_resize_img {
public boolean Exec(Io_url src, Io_url trg, int trg_w, int trg_h, int ext_id, String_obj_ref rslt_val) {
public boolean Resize_exec(Io_url src, Io_url trg, int trg_w, int trg_h, int ext_id, String_obj_ref rslt_val) {
SizeAdp src_size = ImageAdp_.txt_fil_(src).Size();
int src_w = src_size.Width(), src_h = src_size.Height();
if (trg_w < 1) throw Err_.new_fmt_("trg_w must be > 0: {0}", trg_w);

View File

@@ -44,7 +44,7 @@ public class Fs_root_wkr_fsdb {
String thumb_name = Int_.Xto_str(html_w) + orig_url.Ext();
Io_url thumb_url = thumb_dir.GenSubFil_ary(thumb_rel + orig_url.Info().DirSpr(), thumb_name);
if (!Io_mgr.I.ExistsFil(thumb_url)) {
if (!wiki.Appe().File_mgr().Img_mgr().Wkr_resize_img().Exec(orig_url, thumb_url, html_w, html_h, fsdb_itm.Orig_ext().Id(), tmp_resize_result))
if (!wiki.Appe().File_mgr().Img_mgr().Wkr_resize_img().Resize_exec(orig_url, thumb_url, html_w, html_h, fsdb_itm.Orig_ext().Id(), tmp_resize_result))
return false;
}
fsdb_itm.Html_size_(html_w, html_h);

View File

@@ -34,7 +34,7 @@ class Xof_file_fxt {
this.orig_mgr = wiki.File__orig_mgr();
Xof_repo_fxt.Repos_init(app.File_mgr(), true, wiki);
Xowe_wiki_bldr.Create(wiki, 1, "dump.xml");
Xowd_db_file text_db = wiki.Data_mgr__core_mgr().Dbs__make_by_tid(Xowd_db_file_.Tid_text); text_db.Tbl__text().Create_tbl();
Xowd_db_file text_db = wiki.Data__core_mgr().Dbs__make_by_tid(Xowd_db_file_.Tid_text); text_db.Tbl__text().Create_tbl();
Fsdb_db_mgr__v2 fsdb_core = Fsdb_db_mgr__v2_bldr.I.Get_or_make(wiki, Bool_.Y);
fsdb_mgr.Mnt_mgr().Ctor_by_load(fsdb_core);
fsdb_mgr.Mnt_mgr().Mnts__get_main().Bin_mgr().Dbs__make("temp.xowa");

View File

@@ -18,7 +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.dbs.*; import gplx.dbs.engines.sqlite.*; import gplx.xowa.bldrs.*; import gplx.fsdb.*;
public class Xob_orig_tbl_bldr extends Xob_itm_basic_base implements Xob_cmd {
private Db_conn conn;
private Db_conn conn; private boolean schema_1;
public Xob_orig_tbl_bldr(Xob_bldr bldr, Xowe_wiki wiki) {this.Cmd_ctor(bldr, wiki);}
public String Cmd_key() {return Xob_cmd_keys.Key_file_orig_reg;}
public void Cmd_init(Xob_bldr bldr) {}
@@ -27,6 +27,7 @@ public class Xob_orig_tbl_bldr extends Xob_itm_basic_base implements Xob_cmd {
fsdb_mode.Tid_v2_bld_y_();
wiki.Init_assert();
Fsdb_db_mgr db_core_mgr = Fsdb_db_mgr_.new_detect(wiki, wiki.Fsys_mgr().Root_dir(), wiki.Fsys_mgr().File_dir());
this.schema_1 = db_core_mgr.File__schema_is_1();
conn = db_core_mgr.File__orig_tbl_ary()[gplx.fsdb.meta.Fsm_mnt_mgr.Mnt_idx_main].Conn();
Io_url make_db_url = Xob_db_file.new__file_make(wiki.Fsys_mgr().Root_dir()).Url();
Sqlite_engine_.Db_attach(conn, "make_db", make_db_url.Raw());
@@ -35,17 +36,22 @@ public class Xob_orig_tbl_bldr extends Xob_itm_basic_base implements Xob_cmd {
public void Cmd_end() {}
public void Cmd_term() {}
private void Exec() {
conn.Exec_sql_plog_txn("orig_wkr.deleting orig_reg" , Sql_delete_wiki_orig); // always delete orig_reg, else will not pick up changed sizes / moved repos; DATE:2014-07-21
conn.Exec_sql_plog_txn("orig_wkr.inserting xfer direct" , Sql_create_xfer_direct);
conn.Exec_sql_plog_txn("orig_wkr.inserting xfer redirect" , Sql_create_xfer_redirect);
conn.Exec_sql_plog_txn("orig_wkr.inserting orig direct" , Sql_create_orig_direct);
conn.Exec_sql_plog_txn("orig_wkr.inserting orig redirect" , Sql_create_orig_redirect);
String tbl_name = "orig_reg", fld_status = "orig_status";
if (schema_1) {
tbl_name = "wiki_orig";
fld_status = "status";
}
conn.Exec_sql_plog_txn("orig_wkr.deleting orig_reg" , String_.Format(Sql_delete_wiki_orig, tbl_name)); // always delete orig_reg, else will not pick up changed sizes / moved repos; DATE:2014-07-21
conn.Exec_sql_plog_txn("orig_wkr.inserting xfer direct" , String_.Format(Sql_create_xfer_direct, tbl_name, fld_status));
conn.Exec_sql_plog_txn("orig_wkr.inserting xfer redirect" , String_.Format(Sql_create_xfer_redirect, tbl_name, fld_status));
conn.Exec_sql_plog_txn("orig_wkr.inserting orig direct" , String_.Format(Sql_create_orig_direct, tbl_name, fld_status));
conn.Exec_sql_plog_txn("orig_wkr.inserting orig redirect" , String_.Format(Sql_create_orig_redirect, tbl_name, fld_status));
}
public static final String
Sql_delete_wiki_orig = "DELETE FROM orig_reg;"
private static final String
Sql_delete_wiki_orig = "DELETE FROM {0};"
, Sql_create_xfer_direct = String_.Concat_lines_nl
( "INSERT INTO orig_reg "
, "(orig_ttl, orig_status, orig_repo, orig_ext, orig_w, orig_h, orig_redirect)"
( "INSERT INTO {0} "
, "(orig_ttl, {1}, orig_repo, orig_ext, orig_w, orig_h, orig_redirect)"
, "SELECT DISTINCT"
, " xfer.lnki_ttl"
, ", 1 --pass"
@@ -55,12 +61,12 @@ public class Xob_orig_tbl_bldr extends Xob_itm_basic_base implements Xob_cmd {
, ", xfer.orig_h"
, ", ''"
, "FROM make_db.xfer_regy xfer"
, " LEFT JOIN orig_reg cur ON xfer.lnki_ttl = cur.orig_ttl"
, " LEFT JOIN {0} cur ON xfer.lnki_ttl = cur.orig_ttl"
, "WHERE cur.orig_ttl IS NULL"
)
, Sql_create_xfer_redirect = String_.Concat_lines_nl
( "INSERT INTO orig_reg "
, "(orig_ttl, orig_status, orig_repo, orig_ext, orig_w, orig_h, orig_redirect)"
( "INSERT INTO {0} "
, "(orig_ttl, {1}, orig_repo, orig_ext, orig_w, orig_h, orig_redirect)"
, "SELECT DISTINCT"
, " xfer.orig_redirect_src"
, ", 1 --pass"
@@ -70,13 +76,13 @@ public class Xob_orig_tbl_bldr extends Xob_itm_basic_base implements Xob_cmd {
, ", xfer.orig_h"
, ", xfer.lnki_ttl"
, "FROM make_db.xfer_regy xfer"
, " LEFT JOIN orig_reg cur ON xfer.orig_redirect_src = cur.orig_ttl"
, " LEFT JOIN {0} cur ON xfer.orig_redirect_src = cur.orig_ttl"
, "WHERE cur.orig_ttl IS NULL"
, "AND Coalesce(xfer.orig_redirect_src, '') != ''"
)
, Sql_create_orig_direct = String_.Concat_lines_nl
( "INSERT INTO orig_reg "
, "(orig_ttl, orig_status, orig_repo, orig_ext, orig_w, orig_h, orig_redirect)"
( "INSERT INTO {0} "
, "(orig_ttl, {1}, orig_repo, orig_ext, orig_w, orig_h, orig_redirect)"
, "SELECT DISTINCT"
, " orig.lnki_ttl"
, ", 0 --unknown"
@@ -86,15 +92,15 @@ public class Xob_orig_tbl_bldr extends Xob_itm_basic_base implements Xob_cmd {
, ", orig.orig_h"
, ", ''"
, "FROM make_db.orig_regy orig"
, " LEFT JOIN orig_reg cur ON orig.lnki_ttl = cur.orig_ttl"
, " LEFT JOIN {0} cur ON orig.lnki_ttl = cur.orig_ttl"
, "WHERE cur.orig_ttl IS NULL" // not already in orig_reg
, "AND orig.orig_repo IS NOT NULL" // not found in oimg_image.sqlite3
, "AND Coalesce(orig.orig_w , -1) != -1" // ignore entries that are either ext_id = 0 ("File:1") or don't have any width / height info (makes it useless); need to try to get again from wmf_api
, "AND Coalesce(orig.orig_redirect_ttl, '') == ''" // direct
)
, Sql_create_orig_redirect = String_.Concat_lines_nl
( "INSERT INTO orig_reg "
, "(orig_ttl, orig_status, orig_repo, orig_ext, orig_w, orig_h, orig_redirect)"
( "INSERT INTO {0} "
, "(orig_ttl, {1}, orig_repo, orig_ext, orig_w, orig_h, orig_redirect)"
, "SELECT DISTINCT"
, " orig.orig_redirect_ttl"
, ", 0 --unknown"
@@ -104,7 +110,7 @@ public class Xob_orig_tbl_bldr extends Xob_itm_basic_base implements Xob_cmd {
, ", orig.orig_h"
, ", ''"
, "FROM make_db.orig_regy orig"
, " LEFT JOIN orig_reg cur ON orig.orig_redirect_ttl = cur.orig_ttl"
, " LEFT JOIN {0} cur ON orig.orig_redirect_ttl = cur.orig_ttl"
, "WHERE cur.orig_ttl IS NULL" // not already in orig_reg
, "AND orig.orig_repo IS NOT NULL" // not found in oimg_image.sqlite3
, "AND Coalesce(orig.orig_w, -1) != -1" // ignore entries that are either ext_id = 0 ("File:1") or don't have any width / height info (makes it useless); need to try to get again from wmf_api

View File

@@ -26,6 +26,7 @@ public class Xof_orig_wkr__wmf_api implements Xof_orig_wkr {
public byte Tid() {return Xof_orig_wkr_.Tid_wmf_api;}
public void Find_by_list(Ordered_hash rv, List_adp itms) {Xof_orig_wkr_.Find_by_list(this, rv, itms);}
public Xof_orig_itm Find_as_itm(byte[] ttl, int list_idx, int list_len) {
if (!gplx.ios.IoEngine_system.Web_access_enabled) return Xof_orig_itm.Null; // don't check api if download disabled, else prog messages; DATE:2015-06-17
Xoa_app_.Usr_dlg().Prog_none("", "", Prog_msg(list_idx, list_len, ttl));
boolean found = orig_api.Api_query_size(api_rv, download_wkr, repo_mgr, ttl, Xof_img_size.Null, Xof_img_size.Null); // pass in null size to look for orig; DATE:2015-02-10
if (!found) return Xof_orig_itm.Null; // ttl not found by api; return

View File

@@ -50,7 +50,7 @@ public class Xof_repo_itm implements GfoInvkAble {
this.wiki_abrv_xo = Xow_domain_abrv_xo_.To_bry(v, domain_itm.Lang_itm(), domain_itm.Domain_type());
}
public Xof_repo_itm Root_str_(String root_str) {
this.wmf_fsys = String_.HasAtBgn(root_str, "http") || String_.HasAtBgn(root_str, "ftp");
this.wmf_fsys = String_.Has_at_bgn(root_str, "http") || String_.Has_at_bgn(root_str, "ftp");
if (wmf_fsys) {
this.root_bry = Bry_.new_u8(root_str);
this.dir_spr = Byte_ascii.Slash;

View File

@@ -291,7 +291,7 @@ public class Xof_xfer_mgr {
private boolean Img_convert(Io_url src_url, Io_url trg_url) {
rslt.Atrs_src_trg_(src_url.Xto_api(), trg_url); // NOTE: must be set at start; Img_rename_by_size may overwrite trg
if (Io_mgr.I.ExistsFil(trg_url)) return true; // NOTE: already converted; occurs when same image used twice on same page (EX: flags)
if (!file_mgr.Img_mgr().Wkr_resize_img().Exec(src_url, trg_url, lnki_w, lnki_h, orig_ext.Id(), img_convert_rslt)) {
if (!file_mgr.Img_mgr().Wkr_resize_img().Resize_exec(src_url, trg_url, lnki_w, lnki_h, orig_ext.Id(), img_convert_rslt)) {
return rslt.Fail("convert failed|" + src_url.Raw() + "|" + img_convert_rslt.Val());
}
if (lnki_w < 1 || lnki_h < 1) { // lnki_w or lnki_h is invalid >>> get real size for thumb

View File

@@ -228,7 +228,7 @@ class Xog_html_itm__href_extractor {
default: throw Err_.unhandled(text_tid);
}
int href_bgn = 2; // 2 for length of "2|"
if (Bry_.HasAtBgn(text_bry, File_protocol_bry, 2, text_len)) {
if (Bry_.Has_at_bgn(text_bry, File_protocol_bry, 2, text_len)) {
href_bgn += File_protocol_len; // skip "file://"
}
Byte_obj_val href_tid = (Byte_obj_val)href_trie.Match_bgn(text_bry, href_bgn, text_len);

View File

@@ -100,7 +100,6 @@ public class Xog_tab_itm implements GfoInvkAble {
public void Show_url_bgn(Xoa_url url) {
this.tab_is_loading = true;
Xoae_app app = win.App(); Gfo_usr_dlg usr_dlg = app.Usr_dlg();
// Xoae_page page = Xoae_page.Empty;
if ( url.Anchor_str() != null // url has anchor
&& url.Eq_page(page.Url()) // url has same page_name as existing page
&& url.Args().length == 0) { // url has no args; needed for Category:A?from=b#mw-pages

View File

@@ -47,7 +47,7 @@ public class Xob_css_status {
rv.Fs_exists_(exists, css_dir);
}
private static void Chk_db(Xob_css_status rv, Xow_wiki wiki, Io_url css_dir) {
Xowd_db_mgr core_db_mgr = wiki.Data_mgr__core_mgr();
Xowd_db_mgr core_db_mgr = wiki.Data__core_mgr();
if ( core_db_mgr == null
|| core_db_mgr.Props() != null
|| !core_db_mgr.Props().Schema_is_1()

View File

@@ -21,7 +21,7 @@ public class Xohd_abrv_ {
public static final byte
Tid_dir = 1, Tid_img = 2, Tid_img_style = 3, Tid_file_play = 4, Tid_file_info = 5, Tid_file_mgnf = 6
, Tid_hiero_dir = 7, Tid_gallery_box_max = 8, Tid_gallery_box_w = 9, Tid_gallery_img_w = 10, Tid_gallery_img_pad = 11
, Tid_redlink = 12, Tid_toc = 13
, Tid_redlink = 12, Tid_toc = 13, Tid_hdr_bgn = 14, Tid_hdr_end = 15
;
public static final byte[]
Key_dir = Bry_.new_a7("~{xowa_dir}")
@@ -37,6 +37,8 @@ public class Xohd_abrv_ {
, Key_gallery_img_pad = Bry_.new_a7("xowa_gly_img_pad='")
, Key_redlink = Bry_.new_a7("xowa_redlink='")
, Key_toc = Bry_.new_a7("~{xowa_toc}")
, Key_hdr_bgn = Bry_.new_a7("<h")
, Key_hdr_end = Bry_.new_a7("</h")
;
public static final byte[]
A_href_bgn = Bry_.new_a7("/wiki/File:")
@@ -60,6 +62,8 @@ public class Xohd_abrv_ {
trie_itm(rv, Tid_gallery_img_pad , Byte_ascii.Apos , Key_gallery_img_pad);
trie_itm(rv, Tid_redlink , Byte_ascii.Apos , Key_redlink);
trie_itm(rv, Tid_toc , Byte_ascii.Nil , Key_toc);
// trie_itm(rv, Tid_hdr_bgn , Byte_ascii.Nil , Key_hdr_bgn);
// trie_itm(rv, Tid_hdr_end , Byte_ascii.Nil , Key_hdr_end);
return rv;
}
private static void trie_itm(Btrie_slim_mgr trie, byte tid, byte subst_end_byte, byte[] key_bry) {

View File

@@ -26,6 +26,7 @@ public class Xohd_abrv_mgr {
private Xoh_cfg_file cfg_file; private Xof_url_bldr url_bldr = Xof_url_bldr.new_v2(); private Xoh_file_html_fmtr__base html_fmtr;
private byte[] root_dir, file_dir, file_dir_comm, file_dir_wiki, hiero_img_dir;
private byte[] wiki_domain;
private final Xohd_abrv_wkr__hdr wkr__hdr = new Xohd_abrv_wkr__hdr();
public Xohd_abrv_mgr(Gfo_usr_dlg usr_dlg, Xoa_fsys_mgr fsys_mgr, Url_encoder fsys_encoder, byte[] wiki_domain) {
this.usr_dlg = usr_dlg;
this.root_dir = fsys_mgr.Root_dir().To_http_file_bry();
@@ -43,17 +44,17 @@ public class Xohd_abrv_mgr {
this.Init();
byte[] src = hpg.Page_body(); int len = src.length;
Xohd_data_itm__base[] imgs = hpg.Img_itms(); int imgs_len = hpg.Img_itms().length;
bry_rdr.Src_(src);
bry_rdr.Init(src);
int pos = 0; int rng_bgn = -1;
while (pos < len) {
byte b = src[pos];
Object o = trie.Match_bgn_w_byte(b, src, pos, len);
if (o == null) {
if (o == null) { // regular char; set bgn and move to next char
if (rng_bgn == -1) rng_bgn = pos;
++pos;
}
else {
if (rng_bgn != -1) {
else { // special tkn
if (rng_bgn != -1) { // pending rng exists; add it
rv.Add_mid(src, rng_bgn, pos);
rng_bgn = -1;
}
@@ -75,6 +76,8 @@ public class Xohd_abrv_mgr {
case Xohd_abrv_.Tid_dir: bfr.Add(root_dir); return rv;
case Xohd_abrv_.Tid_hiero_dir: bfr.Add(hiero_img_dir); return rv;
case Xohd_abrv_.Tid_redlink: return Write_redlink(bfr, hpg, uid, rv);
case Xohd_abrv_.Tid_hdr_bgn: return wkr__hdr.Write_bgn(bfr, hpg, uid, rv);
case Xohd_abrv_.Tid_hdr_end: return wkr__hdr.Write_end(bfr, hpg, uid, rv);
}
if (itm.Elem_is_xnde()) rv += 2; // if xnde, skip "/>"
if (uid == bry_rdr.Or_int()) {usr_dlg.Warn_many("", "", "index is not a valid int; hpg=~{0} text=~{1}", hpg.Url().Xto_full_str_safe(), Bry_.Mid_safe(src, uid_bgn, uid_end)); return uid_end;}
@@ -149,3 +152,11 @@ class Hdump_html_fmtr_itm {
public boolean Elem_is_xnde() {return elem_is_xnde;} private final boolean elem_is_xnde;
public byte Subst_end_byte() {return subst_end_byte;} private final byte subst_end_byte;
}
class Xohd_abrv_wkr__hdr {
public int Write_bgn(Bry_bfr bfr, Xog_page hpg, int uid, int rv) {
return rv;
}
public int Write_end(Bry_bfr bfr, Xog_page hpg, int uid, int rv) {
return rv;
}
}

View File

@@ -35,7 +35,7 @@ class Xob_hdump_img_cmd extends Xob_itm_basic_base implements Xob_cmd {
html_tbl = new Xowd_html_tbl(conn, wiki.Db_mgr_as_sql().Core_data_mgr().Props().Zip_tid_text());
int cur_page_id = -1;
while (rdr.Move_next()) {
int lnki_page_id = rdr.Read_int(0);
int lnki_page_id = rdr.Read_int("lnki_page_id");
if (lnki_page_id != cur_page_id) {
Save(cur_page_id, bfr.Xto_bry_and_clear());
cur_page_id = lnki_page_id;

View File

@@ -20,7 +20,7 @@ import gplx.core.brys.*; import gplx.dbs.*;
public class Xob_link_dump_cmd {
private Xob_link_dump_tbl tbl; private int src_page_id; private Io_url page_db_url;
public void Init_by_wiki(Xowe_wiki wiki) {
this.page_db_url = wiki.Data_mgr__core_mgr().Db__core().Url();
this.page_db_url = wiki.Data__core_mgr().Db__core().Url();
this.tbl = Xob_link_dump_tbl.Get_or_new(wiki);
tbl.Insert_bgn();
}

View File

@@ -26,7 +26,7 @@ public class Xob_redlink_mkr_cmd extends Xob_itm_basic_base implements Xob_cmd {
private void Read_data() {
Bry_bfr bfr = Bry_bfr.reset_(255);
wiki.Init_assert();
Xowd_db_file core_db = wiki.Data_mgr__core_mgr().Db__core();
Xowd_db_file core_db = wiki.Data__core_mgr().Db__core();
Xob_db_file link_dump_db = Xob_db_file.new__redlink(wiki.Fsys_mgr().Root_dir());
Db_attach_rdr attach_rdr = new Db_attach_rdr(link_dump_db.Conn(), "page_db", core_db.Url());
attach_rdr.Attach();
@@ -39,7 +39,7 @@ public class Xob_redlink_mkr_cmd extends Xob_itm_basic_base implements Xob_cmd {
int html_db_id = rdr.Read_int(page_tbl.Fld_html_db_id().Name());
if (html_db_id != cur_html_db_id) {
if (html_dump_tbl != null) html_dump_tbl.Conn().Txn_end();
html_dump_tbl = wiki.Data_mgr__core_mgr().Dbs__get_at(html_db_id).Tbl__html();
html_dump_tbl = wiki.Data__core_mgr().Dbs__get_at(html_db_id).Tbl__html();
html_dump_tbl.Conn().Txn_bgn();
cur_html_db_id = html_db_id;
}

View File

@@ -43,7 +43,7 @@ public class Xohd_page_html_mgr__load {
rows.Clear();
}
private void Parse_data(Xog_page hpg, Xowd_html_row row) {
rdr.Src_(row.Data());
rdr.Init(row.Data());
while (!rdr.Pos_is_eos()) {
int tid = rdr.Read_int_to_pipe();
switch (tid) {

View File

@@ -44,7 +44,7 @@ public class Xow_hzip_itm__anchor {
private int Save_img_full(Bry_bfr bfr, Xodump_stats_itm stats, byte[] src, int src_len, int bgn, int pos) {
bfr.Add(Xow_hzip_dict.Bry_img_full);
int xatrs_bgn = Bry_finder.Move_fwd(src, Find_img_xatrs, pos, src_len); if (xatrs_bgn == Bry_finder.Not_found) return hzip_mgr.Warn_by_pos_add_dflt("a.img_xatrs_missing", bgn, pos);
bry_rdr.Src_(src).Pos_(xatrs_bgn);
bry_rdr.Init(src, xatrs_bgn);
int a_cls = bry_rdr.Read_int_to_pipe();
int a_rel = bry_rdr.Read_int_to_pipe();
int img_rel = bry_rdr.Read_int_to_pipe();

View File

@@ -24,15 +24,15 @@ public class Xow_hzip_itm__header_tst {
// fxt.Test_save(brys, "<h2><span class='mw-headline' id='A'>A<!--xo_hdr_end--></span></h2>");
// fxt.Test_load(brys, "<h2><span class='mw-headline' id='A'>A</span></h2>");
}
@Test public void Html_basic() {
// @Test public void Html_basic() {
// fxt.Test_html("==A==", "<h2><span class='mw-headline' id='A'>A<!--xo_hdr_end--></span></h2>\n");
}
@Test public void Srl_anchor() {
// }
// @Test public void Srl_anchor() {
// byte[][] brys = Bry_.Ary(Xow_hzip_dict.Bry_hdr_lhs, Bry_.ints_(2), Bry_.new_a7("A <a xtid='a_lnki_text_n' href=\"/wiki/B\" xowa_redlink='1'>b</a> c"), Xow_hzip_dict.Escape_bry);
// fxt.Test_save(brys, "<h2><span class='mw-headline' id='A_b_c'>A <a xtid='a_lnki_text_n' href=\"/wiki/B\" xowa_redlink='1'>b</a> c<!--xo_hdr_end--></span></h2>");
//// fxt.Test_load(brys, "<h2><span class='mw-headline' id='A_b_c'>A <a xtid='a_lnki_text_n' href=\"/wiki/B\" xowa_redlink='1'>b</a> c<!--xo_hdr_end--></span></h2>");
}
@Test public void Html_anchor() {
// }
// @Test public void Html_anchor() {
// fxt.Test_html("==A [[b]] c==", "<h2><span class='mw-headline' id='A_b_c'>A <a xtid='a_lnki_text_n' href=\"/wiki/B\" xowa_redlink='1'>b</a> c<!--xo_hdr_end--></span></h2>\n");
}
// }
}

View File

@@ -82,7 +82,7 @@ public class Xow_popup_mgr implements GfoInvkAble, GfoEvObj {
Show_popup_html(Cbk_xowa_popups_show_update, Mode_show_all, popup_itm);
}
public String Get_async_bgn(byte[] js_cbk, byte[] href) {
if (Bry_.HasAtBgn(href, gplx.xowa.parsers.lnkes.Xop_lnke_wkr.Bry_xowa_protocol)) return null; // ignore xowa-cmd
if (Bry_.Has_at_bgn(href, gplx.xowa.parsers.lnkes.Xop_lnke_wkr.Bry_xowa_protocol)) return null; // ignore xowa-cmd
synchronized (thread_lock) {
if (async_itm != null) async_itm.Cancel();
async_itm = new Xow_popup_itm(++async_id_next, href, Bry_.Empty, show_init_word_count);

View File

@@ -55,7 +55,7 @@ public class Xow_popup_parser {
tmpl_keeplist = new Xop_keeplist_wiki(wiki);
tmpl_ctx.Tmpl_keeplist_(tmpl_keeplist);
}
if (!Bry_.HasAtEnd(raw, Byte_ascii.NewLine_bry)) raw = Bry_.Add(raw, Byte_ascii.NewLine_bry);
if (!Bry_.Has_at_end(raw, Byte_ascii.NewLine_bry)) raw = Bry_.Add(raw, Byte_ascii.NewLine_bry);
tmpl_keeplist.Srl().Load_by_bry(raw);
}
private boolean Canceled(Xow_popup_itm popup_itm, Xog_tab_itm cur_tab) {return popup_itm.Canceled() || cur_tab != null && cur_tab.Tab_is_loading();}

View File

@@ -53,7 +53,7 @@ public class Xol_grammar_fi implements Xol_grammar {
byte[] lower = lang.Case_mgr().Case_build_lower(word, 0, word_len);
boolean aou = Vowel_harmony(lower, word_len);
// PHP: if ( preg_match( '/wiki$/i', $word ) ) $aou = false;
if (aou && Bry_.HasAtEnd(lower, Xoa_url_parser.Bry_wiki_name))
if (aou && Bry_.Has_at_end(lower, Xoa_url_parser.Bry_wiki_name))
aou = false;
// PHP: if ( preg_match( '/[bcdfghjklmnpqrstvwxz]$/i', $word ) ) $word .= 'i';
switch (lower[word_len - 1]) {

View File

@@ -76,7 +76,7 @@ public class Xol_num_fmtr_base implements GfoInvkAble {
wkr.Fmt(src, num_bgn, i, tmp);
num_bgn = dec_pos = -1; // reset vars
if (b == Byte_ascii.Dot // current char is "."; NOTE: all languages treat "." as decimal separator for parse; EX: for de, "1.23" is "1,23" DATE:2013-10-21
//|| Bry_.HasAtBgn(src, dec_dlm, i, src_len)
//|| Bry_.Has_at_bgn(src, dec_dlm, i, src_len)
) { // current char is languages's decimal delimiter; note this can be "," or any other multi-byte separator
dec_pos = i;
// i += dec_dlm.length - 1;

View File

@@ -220,7 +220,7 @@ class HttpRequest implements Runnable{
if(!req.contains("%file%")){
if(req.equals("/")) { // no page; EX:"localhost:8080" vs "localhost:8080/en.wikipedia.org/wiki/Earth"
String home_url = app.Http_server().Home();;
if (String_.HasAtBgn(home_url, "file://")) {
if (String_.Has_at_bgn(home_url, "file://")) {
Io_url file_url = Io_url_.http_any_(home_url, Op_sys.Cur().Tid_is_wnt());
String page_html = Io_mgr.I.LoadFilStr(file_url);
Write_page(dos, page_html, app_root_dir, wiki_domain);

View File

@@ -21,8 +21,8 @@ class Http_server_wkr_ {
public static String Assert_main_page(Xoae_app app, String req) {
int mode = -1;
String[] req_array = String_.Split(req, "/");
if (String_.HasAtEnd(req, "wiki/")) mode = 0;
else if (String_.HasAtEnd(req, "wiki")) mode = 1;
if (String_.Has_at_end(req, "wiki/")) mode = 0;
else if (String_.Has_at_end(req, "wiki")) mode = 1;
else if (req_array.length == 3) mode = 2;
if (mode == -1) return req; // not a link to a Main Page; EX:localhost:8080/en.wikipedia.org/wiki/Earth
if (req_array.length < 3) return req; // shouldn't happen; EX: "localhost:8080wiki"

View File

@@ -55,7 +55,7 @@ class Xosrv_msg_rdr_fxt {
msg_rdr_stream.Data_bry_(raw_bry).Read_limit_(raw_bry.length);
Xosrv_msg msg = msg_rdr.Read();
String msg_text = String_.new_a7(msg.Msg_text());
Tfds.Eq_true(String_.HasAtBgn(msg_text, expd_err), msg_text);
Tfds.Eq_true(String_.Has_at_bgn(msg_text, expd_err), msg_text);
}
public void Test_print(Xosrv_msg msg, String expd) {
Bry_bfr bfr = Bry_bfr.new_();

View File

@@ -72,7 +72,7 @@ class Xog_search_suggest_cmd implements GfoInvkAble, Cancelable {
for (int i = 0; i < page_ary_len; i++) {
Xowd_page_itm page = page_ary[i];
if (page != null) {
if (!Bry_.HasAtBgn(page.Ttl_page_db(), search_ttl_bry)) continue; // look-ahead may return other titles that don't begin with search; ignore
if (!Bry_.Has_at_bgn(page.Ttl_page_db(), search_ttl_bry)) continue; // look-ahead may return other titles that don't begin with search; ignore
if (page.Text_len() > all_pages_min) {
rslts_2.Add(page);
idx++;

View File

@@ -50,9 +50,9 @@ class Xosrh_qry_itm {
byte wiki_db_tid = wiki.Db_mgr().Tid();
if (wiki_db_tid == Xodb_mgr_sql.Tid_sql
&& wiki.Appe().Gui_mgr().Search_suggest_mgr().Auto_wildcard()) { // HACK: auto-asterisk words for sqlite; DATE:2013-09-05
if (!Bry_.HasAtEnd(search_word, new byte[] {Byte_ascii.Asterisk}))
if (!Bry_.Has_at_end(search_word, new byte[] {Byte_ascii.Asterisk}))
search_word = Bry_.Add(search_word, Byte_ascii.Asterisk);
if (!Bry_.HasAtBgn(search_word, new byte[] {Byte_ascii.Asterisk}))
if (!Bry_.Has_at_bgn(search_word, new byte[] {Byte_ascii.Asterisk}))
search_word = Bry_.Add(Byte_ascii.Asterisk, search_word);
}
wiki.Db_mgr().Load_mgr().Load_search(cancelable, found, search_word, results_max);

View File

@@ -52,7 +52,7 @@ class Xows_arg_mgr {
}
}
else {
if (Bry_.HasAtBgn(key, Ns_bry)) // check for ns*; EX: &ns0=1&ns8=1; NOTE: lowercase only
if (Bry_.Has_at_bgn(key, Ns_bry)) // check for ns*; EX: &ns0=1&ns8=1; NOTE: lowercase only
ns_mgr.Add_by_parse(key, arg.Val_bry());
}
}

View File

@@ -66,7 +66,7 @@ class Xows_core {
cmd_hash.Del(cmd.Key());
}
private void Assert_page_count(Xowe_wiki wiki) {
Xowd_db_file search_db = wiki.Data_mgr__core_mgr().Db__search();
Xowd_db_file search_db = wiki.Data__core_mgr().Db__search();
if (ask_for_upgrade
&& wiki.App().App_type().Uid_is_gui()
&& !search_db.Tbl__search_word().Ddl__page_count()

View File

@@ -22,7 +22,7 @@ import gplx.gfui.*;
class Xows_db_wkr {
public void Search(Xows_ui_cmd cmd, Xows_ui_qry qry, Xows_ui_rslt rslt, Xows_db_cache cache, Xow_wiki wiki) {
// assert matcher
Xowd_db_file search_db = wiki.Data_mgr__core_mgr().Db__search();
Xowd_db_file search_db = wiki.Data__core_mgr().Db__search();
Xoa_app_.Usr_dlg().Prog_many("", "", "search started (please wait)");
Xows_db_matcher matcher = cache.Matcher();
if (matcher == null) {
@@ -35,7 +35,7 @@ class Xows_db_wkr {
}
// init
int rslts_wanted = qry.Itms_end() - qry.Itms_bgn();
Xowd_db_file core_db = wiki.Data_mgr__core_mgr().Db__core();
Xowd_db_file core_db = wiki.Data__core_mgr().Db__core();
Xowd_page_tbl page_tbl = core_db.Tbl__page();
Xowd_search_link_tbl link_tbl = search_db.Tbl__search_link();
Xows_db_word[] word_ary = cache.Words(); int word_ary_len = word_ary.length;

View File

@@ -21,7 +21,7 @@ class Xows_paging_parser {
private final List_adp itm_list = List_adp_.new_();
private final Bry_rdr rdr = new Bry_rdr();
public Xows_paging_itm[] Parse(byte[] raw) { // EX: en.wikipedia.org|41|60;en.wiktionary.org|21|40;
rdr.Src_(raw);
rdr.Init(raw);
while (!rdr.Pos_is_eos()) {
byte[] wiki = rdr.Read_bry_to_pipe();
int bgn = rdr.Read_int_to_pipe();

View File

@@ -86,7 +86,7 @@ abstract class Xosp_fbrow_cmd__base implements Xosp_fbrow_cmd {
, " <td>"
, " <table width='100%'>"
, " <tr>"
, " <td align='right'><a href='javascript:get_selected_chk(\"/wiki/Special:XowaFileBrowser?cmd=~{cmd_src}&amp;path=~{url_enc}&amp;selected=\", \"chk_\");'>~{cmd_gui}</a>"
, " <td align='left'><a href='javascript:get_selected_chk(\"/wiki/Special:XowaFileBrowser?cmd=~{cmd_src}&amp;path=~{url_enc}&amp;selected=\", \"chk_\");'>~{cmd_gui}</a>"
, " </td>"
, " </tr>"
, " </table>"
@@ -183,7 +183,7 @@ class Xosp_fbrow_cmd__wiki_add extends Xosp_fbrow_cmd__base {
@Override public Xosp_fbrow_cmd Make_new() {return new Xosp_fbrow_cmd__wiki_add();}
@Override protected void Process_itm(Xosp_fbrow_data_sub itm) {
byte[] url_bry = itm.Url().RawBry();
if (!Bry_.HasAtEnd(url_bry, Ext_xowa)) itm.Selectable_(false);
if (!Bry_.Has_at_end(url_bry, Ext_xowa)) itm.Selectable_(false);
}
@Override protected Xosp_fbrow_rslt Write_html_selected(Xoa_url_arg_mgr arg_mgr, String selected, GfoInvkAble select_invkable) {
String[] wikis = String_.Split(selected, ";");

View File

@@ -35,7 +35,7 @@ class Xosp_fbrow_data_dir {
for (int i = 0; i < len; ++i) {
IoItm_base src = (IoItm_base)itms.Get_at(i);
Io_url src_url = src.Url();
if (String_.HasAtBgn(src_url.NameAndExt(), ".")) continue; // ignore hidden "." files; NameAndExt() b/c ".ext" has NameOnly of ""; EX: "/dir/.hidden"
if (String_.Has_at_bgn(src_url.NameAndExt(), ".")) continue; // ignore hidden "." files; NameAndExt() b/c ".ext" has NameOnly of ""; EX: "/dir/.hidden"
Xosp_fbrow_data_sub trg = null;
if (dir)
trg = new Xosp_fbrow_data_sub(src_url, -1, null);

View File

@@ -27,7 +27,7 @@ public class Xosp_fbrow_special_tst {
, " <td>"
, " <table width='100%'>"
, " <tr>"
, " <td align='right'><a href='javascript:get_selected_chk(\"/wiki/Special:XowaFileBrowser?cmd=xowa.wiki.add&amp;path=mem/root/dir/&amp;selected=\", \"chk_\");'>import</a>"
, " <td align='left'><a href='javascript:get_selected_chk(\"/wiki/Special:XowaFileBrowser?cmd=xowa.wiki.add&amp;path=mem/root/dir/&amp;selected=\", \"chk_\");'>import</a>"
, " </td>"
, " </tr>"
, " </table>"

View File

@@ -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.users.data; import gplx.*; import gplx.xowa.*; import gplx.xowa.users.*;
import gplx.dbs.*; import gplx.dbs.cfgs.*; import gplx.dbs.schemas.*;
import gplx.dbs.*; import gplx.dbs.cfgs.*; import gplx.dbs.metas.*;
import gplx.xowa.files.caches.*;
public class Xou_db_file {
private final Db_conn conn;
@@ -34,11 +34,11 @@ public class Xou_db_file {
public Xou_cache_tbl Tbl__cache() {return tbl__cache;} private final Xou_cache_tbl tbl__cache;
public Xoud_bmk_tbl Tbl__bmk() {return tbl__bmk;} private final Xoud_bmk_tbl tbl__bmk;
public void Init_assert() {
if (!conn.Schema_tbl_exists(tbl__cache.Tbl_name())) {
if (!conn.Meta_tbl_exists(tbl__cache.Tbl_name())) {
tbl__cfg.Create_tbl();
tbl__cache.Create_tbl();
}
// if (!conn.Schema_tbl_exists(tbl__bmk.Tbl_name())) {
// if (!conn.Meta_tbl_exists(tbl__bmk.Tbl_name())) {
// tbl__bmk.Create_tbl();
// }
}

View File

@@ -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.users.data; import gplx.*; import gplx.xowa.*; import gplx.xowa.users.*;
import gplx.core.threads.*; import gplx.dbs.*; import gplx.dbs.schemas.updates.*; import gplx.dbs.schemas.*;
import gplx.core.threads.*; import gplx.dbs.*; import gplx.dbs.metas.updates.*; import gplx.dbs.metas.*;
import gplx.xowa.files.caches.*;
public class Xou_db_mgr {
private final Xoa_app app;

View File

@@ -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.users.data; import gplx.*; import gplx.xowa.*; import gplx.xowa.users.*;
import gplx.dbs.*; import gplx.dbs.qrys.*; import gplx.dbs.schemas.*; import gplx.dbs.schemas.updates.*;
import gplx.dbs.*; import gplx.dbs.qrys.*; import gplx.dbs.metas.*; import gplx.dbs.metas.updates.*;
public class Xoud_history_tbl implements RlsAble {
private final String tbl_name = "user_history"; private final Db_meta_fld_list flds = Db_meta_fld_list.new_();
private final String fld_wiki, fld_page, fld_qarg, fld_time, fld_count;

View File

@@ -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.users.data; import gplx.*; import gplx.xowa.*; import gplx.xowa.users.*;
import gplx.dbs.*; import gplx.dbs.qrys.*; import gplx.dbs.schemas.*; import gplx.dbs.schemas.updates.*;
import gplx.dbs.*; import gplx.dbs.qrys.*; import gplx.dbs.metas.*; import gplx.dbs.metas.updates.*;
public class Xoud_regy_tbl {
public static final String Tbl_name = "user_regy", Fld_regy_grp = "regy_grp", Fld_regy_key = "regy_key", Fld_regy_val = "regy_val";
private static final String[] Flds__all = new String[] {Fld_regy_grp, Fld_regy_key, Fld_regy_val};
@@ -68,10 +68,10 @@ public class Xoud_regy_tbl {
@gplx.Virtual public String Select_val(String grp, String key) {
if (stmt_select_key == null) stmt_select_key = Db_stmt_.new_select_as_rdr(conn, Db_qry__select_in_tbl.new_(Tbl_name, String_.Ary(Fld_regy_grp, Fld_regy_key), Flds__all, Db_qry__select_in_tbl.Order_by_null));
try {
Db_rdr rdr = stmt_select_key.Clear().Val_str(grp).Val_str(key).Exec_select__rls_manual();
Db_rdr rdr = stmt_select_key.Clear().Val_str(Fld_regy_grp, grp).Val_str(Fld_regy_key, key).Exec_select__rls_manual();
String rv = null;
if (rdr.Move_next())
rv = rdr.Read_str(2);
rv = rdr.Read_str(Fld_regy_val);
rdr.Rls();
return rv;
}
@@ -79,9 +79,9 @@ public class Xoud_regy_tbl {
}
private Xoud_regy_row Make_row(Db_rdr rdr) {
return new Xoud_regy_row
( rdr.Read_str(0)
, rdr.Read_str(1)
, rdr.Read_str(2)
( rdr.Read_str(Fld_regy_grp)
, rdr.Read_str(Fld_regy_key)
, rdr.Read_str(Fld_regy_val)
);
}
public void Rls_all() {

View File

@@ -133,7 +133,7 @@ public class Prefs_mgr implements GfoInvkAble {
return // if tidy_enabled and text_area and ends with \n, then remove \n; DATE:2014-06-21
( tidy_enabled
&& elem_tid == Elem_tid_textarea
&& String_.HasAtEnd(val, "\n")
&& String_.Has_at_end(val, "\n")
)
? String_.MidByLen(val, 0, String_.Len(val) - 1)
: val

View File

@@ -35,7 +35,7 @@ class Xofs_url_itm_parser {
public void Parse(Xofs_url_itm itm, String raw_str) {
itm.Raw_(raw_str);
byte[] raw = Bry_.new_u8(raw_str);
if (!Bry_.HasAtBgn(raw, Xowa_fs_protocol)) { // raw does not start with "xowa-fs://"; mark as custom str and exit
if (!Bry_.Has_at_bgn(raw, Xowa_fs_protocol)) { // raw does not start with "xowa-fs://"; mark as custom str and exit
itm.Tid_is_xowa_(false);
itm.Url_(raw_str);
return;

View File

@@ -17,5 +17,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.wikis; import gplx.*; import gplx.xowa.*;
public interface Xoa_wiki_mgr {
Xow_wiki Get_by_key_or_make_2(byte[] key);
Xow_wiki Get_by_key_or_make_2(byte[] key);
Xow_wiki Get_by_key_or_make_3(byte[] key);
}

View File

@@ -24,8 +24,8 @@ public class Xoa_wiki_regy {
public boolean Has(byte[] domain) {if (init_needed) Init(); return hash.Has(domain);}
public boolean Url_is_invalid_domain(Xoa_url url) {
if (!Bry_.Eq(url.Page_bry(), Xoa_page_.Main_page_bry)) return false; // page is not "Main_Page"; assume not an invalid domain str; EX: "uk/wiki/Main_Page"
if ( Bry_.Eq(Xow_domain_type_.Key_bry_home, url.Wiki_bry()) // wiki is "home"
&& !Bry_.Eq(Xow_domain_type_.Key_bry_home, url.Raw())) // raw is "home"; should be "home/wiki/Main_Page"; DATE:2014-02-09
if ( Bry_.Eq(Xow_domain_type_.Key_bry_home, url.Wiki_bry()) // wiki is "home"
&& !Bry_.Eq(Xow_domain_type_.Key_bry_home, url.Raw())) // raw is "home"; should be "home/wiki/Main_Page"; DATE:2014-02-09
return false; // special case to handle "home" which should mean "home" in any wiki, but "home/wiki/Main_Page" in home wiki
return !this.Has(url.Wiki_bry());
}

View File

@@ -43,6 +43,7 @@ public class Xoae_wiki_mgr implements Xoa_wiki_mgr, GfoInvkAble {
rv.Init_assert();
return rv;
}
public Xow_wiki Get_by_key_or_make_3(byte[] key) {return Get_by_key_or_make(key);}
public Xowe_wiki Get_by_key_or_make(byte[] key) {
Xowe_wiki rv = this.Get_by_key_or_null(key);
if (rv == null) rv = New_wiki(key);

Some files were not shown because too many files have changed in this diff Show More