mirror of
https://github.com/gnosygnu/xowa.git
synced 2026-03-02 03:49:30 +00:00
v3.1.1.1
This commit is contained in:
92
400_xowa/src/gplx/core/brys/Bit_heap_rdr.java
Normal file
92
400_xowa/src/gplx/core/brys/Bit_heap_rdr.java
Normal file
@@ -0,0 +1,92 @@
|
||||
/*
|
||||
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.*;
|
||||
import gplx.xowa.htmls.core.hzips.*;
|
||||
public class Bit_heap_rdr {
|
||||
private final byte[] hzip_int_bry = new byte[5];
|
||||
public int Cur_val() {return cur_val;} private int cur_val;
|
||||
public int Cur_bits() {return cur_bits;} private int cur_bits;
|
||||
public int Cur_pos() {return cur_pos;} private int cur_pos;
|
||||
public byte[] Src() {return src;} private byte[] src;
|
||||
public int Src_end() {return src_end;} private int src_end;
|
||||
public void Load(byte[] src, int src_bgn, int src_end) {
|
||||
this.src = src; this.cur_pos = src_bgn; this.src_end = src_end;
|
||||
this.cur_val = 0; this.cur_bits = 0;
|
||||
}
|
||||
public boolean Get_bool() {
|
||||
Get_bgn(cur_bits);
|
||||
int old_val = cur_val;
|
||||
this.cur_val = cur_val >> 1;
|
||||
int comp_val = cur_val << 1;
|
||||
boolean rv = (old_val - comp_val) == 1;
|
||||
Get_end(1);
|
||||
return rv;
|
||||
}
|
||||
public byte Get_byte(int bits) {
|
||||
int old_bits = bits;
|
||||
int new_bits = cur_bits + bits;
|
||||
boolean again = false;
|
||||
if (new_bits > 7 && cur_bits > 0) {
|
||||
old_bits = 8 - cur_bits;
|
||||
again = true;
|
||||
new_bits -= 8;
|
||||
}
|
||||
int rv = Get_byte_private(old_bits, cur_bits);
|
||||
if (again) {
|
||||
Get_end(old_bits);
|
||||
int new_val = Get_byte_private(new_bits, 0);
|
||||
rv += new_val << old_bits;
|
||||
}
|
||||
Get_end(new_bits);
|
||||
return (byte)rv;
|
||||
}
|
||||
public int Get_int_hzip(int reqd_len) {
|
||||
int full_len = reqd_len; int bgn_idx = 0;
|
||||
byte b0 = Get_byte(8);
|
||||
switch (b0) {
|
||||
case Xoh_hzip_int.prefix__b256__2: full_len = 2; bgn_idx = 1; break;
|
||||
case Xoh_hzip_int.prefix__b256__3: full_len = 3; bgn_idx = 1; break;
|
||||
case Xoh_hzip_int.prefix__b256__4: full_len = 4; bgn_idx = 1; break;
|
||||
case Xoh_hzip_int.prefix__b256__5: full_len = 5; bgn_idx = 1; break;
|
||||
}
|
||||
hzip_int_bry[0] = b0;
|
||||
for (int i = 1; i < full_len; ++i)
|
||||
hzip_int_bry[i] = Get_byte(8);
|
||||
return Xoh_hzip_int.To_int_by_bry(hzip_int_bry, bgn_idx, full_len, Byte_.Zero, 256);
|
||||
}
|
||||
private byte Get_byte_private(int bits, int chk_bits) {
|
||||
Get_bgn(chk_bits);
|
||||
int old_val = cur_val;
|
||||
this.cur_val = cur_val >> bits;
|
||||
int comp_val = cur_val << bits;
|
||||
byte rv = (byte)(old_val - comp_val);
|
||||
return rv;
|
||||
}
|
||||
private void Get_bgn(int chk_bits) {
|
||||
if (chk_bits == 0) cur_val = src[cur_pos] & 0xFF; // PATCH.JAVA:need to convert to unsigned byte
|
||||
}
|
||||
private void Get_end(int bits) {
|
||||
int new_bits = cur_bits + bits;
|
||||
if (new_bits == 8) {
|
||||
cur_bits = 0;
|
||||
cur_pos += 1;
|
||||
}
|
||||
else
|
||||
cur_bits = new_bits;
|
||||
}
|
||||
}
|
||||
84
400_xowa/src/gplx/core/brys/Bit_heap_rdr_tst.java
Normal file
84
400_xowa/src/gplx/core/brys/Bit_heap_rdr_tst.java
Normal file
@@ -0,0 +1,84 @@
|
||||
/*
|
||||
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.*;
|
||||
import org.junit.*;
|
||||
public class Bit_heap_rdr_tst {
|
||||
private final Bit_heap_rdr_fxt fxt = new Bit_heap_rdr_fxt();
|
||||
@Test public void Get_bool() {
|
||||
fxt.Load(255);
|
||||
fxt.Test__get_bool(Bool_.Y).Test__cur(127, 1, 0);
|
||||
fxt.Test__get_bool(Bool_.Y).Test__cur( 63, 2, 0);
|
||||
fxt.Test__get_bool(Bool_.Y).Test__cur( 31, 3, 0);
|
||||
fxt.Test__get_bool(Bool_.Y).Test__cur( 15, 4, 0);
|
||||
fxt.Test__get_bool(Bool_.Y).Test__cur( 7, 5, 0);
|
||||
fxt.Test__get_bool(Bool_.Y).Test__cur( 3, 6, 0);
|
||||
fxt.Test__get_bool(Bool_.Y).Test__cur( 1, 7, 0);
|
||||
fxt.Test__get_bool(Bool_.Y).Test__cur( 0, 0, 1);
|
||||
|
||||
fxt.Load(0);
|
||||
fxt.Test__get_bool(Bool_.N).Test__cur( 0, 1, 0);
|
||||
|
||||
fxt.Load(6);
|
||||
fxt.Test__get_bool(Bool_.N).Test__cur( 3, 1, 0);
|
||||
fxt.Test__get_bool(Bool_.Y).Test__cur( 1, 2, 0);
|
||||
fxt.Test__get_bool(Bool_.Y).Test__cur( 0, 3, 0);
|
||||
}
|
||||
@Test public void Get_byte() {
|
||||
fxt.Load(255).Test__get_byte(2, 3).Test__cur(63, 2, 0);
|
||||
|
||||
fxt.Load(255, 3);
|
||||
fxt.Test__get_byte(7, 127);
|
||||
fxt.Test__get_byte(3, 7);
|
||||
|
||||
fxt.Load(10);
|
||||
fxt.Test__get_bool(false);
|
||||
fxt.Test__get_byte(3, 5);
|
||||
}
|
||||
@Test public void Get_int_hzip() {
|
||||
fxt.Load(100).Test__get_int_hzip(1, 100).Test__cur(0, 0, 1);
|
||||
fxt.Load(253, 1, 44).Test__get_int_hzip(1, 300).Test__cur(0, 0, 3);
|
||||
fxt.Load(0, 100).Test__get_int_hzip(2, 100).Test__cur(0, 0, 2);
|
||||
fxt.Load(250, 3, 88, 0).Test__get_bool(Bool_.N).Test__get_int_hzip(1, 300).Test__cur(0, 1, 3);
|
||||
}
|
||||
}
|
||||
class Bit_heap_rdr_fxt {
|
||||
private final Bit_heap_rdr heap = new Bit_heap_rdr();
|
||||
public Bit_heap_rdr_fxt Load(int... src) {
|
||||
byte[] bry = Bry_.New_by_ints(src);
|
||||
heap.Load(bry, 0, bry.length);
|
||||
return this;
|
||||
}
|
||||
public Bit_heap_rdr_fxt Test__get_bool(boolean expd) {
|
||||
Tfds.Eq_bool(expd, heap.Get_bool());
|
||||
return this;
|
||||
}
|
||||
public Bit_heap_rdr_fxt Test__get_byte(int bits, int expd) {
|
||||
Tfds.Eq_byte((byte)expd, heap.Get_byte(bits));
|
||||
return this;
|
||||
}
|
||||
public Bit_heap_rdr_fxt Test__get_int_hzip(int reqd, int expd) {
|
||||
Tfds.Eq_int(expd, heap.Get_int_hzip(reqd));
|
||||
return this;
|
||||
}
|
||||
public Bit_heap_rdr_fxt Test__cur(int cur_val, int cur_bits, int cur_pos) {
|
||||
Tfds.Eq_int(cur_val, heap.Cur_val(), "val");
|
||||
Tfds.Eq_int(cur_bits, heap.Cur_bits(), "bits");
|
||||
Tfds.Eq_int(cur_pos, heap.Cur_pos(), "pos");
|
||||
return this;
|
||||
}
|
||||
}
|
||||
71
400_xowa/src/gplx/core/brys/Bit_heap_wtr.java
Normal file
71
400_xowa/src/gplx/core/brys/Bit_heap_wtr.java
Normal 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.core.brys; import gplx.*; import gplx.core.*;
|
||||
public class Bit_heap_wtr {
|
||||
private final gplx.xowa.htmls.core.hzips.Xoh_hzip_int hzip_int = new gplx.xowa.htmls.core.hzips.Xoh_hzip_int().Mode_is_b256_(true);
|
||||
private final Bry_bfr hzip_int_bfr = Bry_bfr.reset_(5);
|
||||
public int Cur() {return cur;} private int cur;
|
||||
public int Cur_bits() {return cur_bits;} private int cur_bits;
|
||||
public Bry_bfr Heap() {return heap;} private final Bry_bfr heap = Bry_bfr.new_();
|
||||
public void Clear() {heap.Clear(); cur = 0; cur_bits = 0;}
|
||||
public void Add_bool(boolean v) {
|
||||
if (v)
|
||||
cur += Pow_ary[cur_bits];
|
||||
if (cur_bits == 7) {
|
||||
heap.Add_byte((byte)cur);
|
||||
cur = 0;
|
||||
cur_bits = 0;
|
||||
}
|
||||
else
|
||||
++cur_bits;
|
||||
}
|
||||
public void Add_byte(byte val_byte) {
|
||||
int val_int = val_byte & 0xFF; // PATCH.JAVA:need to convert to unsigned byte
|
||||
if (cur_bits == 0)
|
||||
heap.Add_byte(val_byte);
|
||||
else {
|
||||
heap.Add_byte((byte)(cur + (val_int << cur_bits)));
|
||||
this.cur = val_int >> cur_bits;
|
||||
}
|
||||
}
|
||||
public void Add_byte(int val_bits, int val) {
|
||||
int total_bits = cur_bits + val_bits;
|
||||
int new_val = cur + (val << cur_bits);
|
||||
if (total_bits < 8) {
|
||||
this.cur_bits = total_bits;
|
||||
this.cur = new_val;
|
||||
}
|
||||
else {
|
||||
heap.Add_byte((byte)new_val);
|
||||
this.cur = val >> (8 - cur_bits);
|
||||
this.cur_bits = total_bits - 8;
|
||||
}
|
||||
}
|
||||
public void Add_int_hzip(int reqd_len, int val) {
|
||||
hzip_int.Encode(reqd_len, hzip_int_bfr, val);
|
||||
int len = hzip_int_bfr.Len();
|
||||
byte[] hzip_bry = hzip_int_bfr.Bfr();
|
||||
for (int i = 0; i < len; ++i) {
|
||||
byte b = hzip_bry[i];
|
||||
Add_byte(8, b & 0xFF); // PATCH.JAVA:need to convert to unsigned byte
|
||||
}
|
||||
hzip_int_bfr.Clear();
|
||||
}
|
||||
public void Save(Bry_bfr bfr) {}
|
||||
public static final int[] Pow_ary = new int[] {1, 2, 4, 8, 16, 32, 64, 128, 256};
|
||||
}
|
||||
88
400_xowa/src/gplx/core/brys/Bit_heap_wtr_tst.java
Normal file
88
400_xowa/src/gplx/core/brys/Bit_heap_wtr_tst.java
Normal file
@@ -0,0 +1,88 @@
|
||||
/*
|
||||
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.*;
|
||||
import org.junit.*;
|
||||
public class Bit_heap_wtr_tst {
|
||||
private final Bit_heap_wtr_fxt fxt = new Bit_heap_wtr_fxt();
|
||||
@Test public void Add_bool() {
|
||||
fxt.Clear().Add_bool(Bool_.Y).Test__vals(1, 1);
|
||||
fxt.Clear().Add_bool(Bool_.N).Test__vals(1, 0);
|
||||
fxt.Clear().Add_bool(Bool_.Y, Bool_.Y, Bool_.Y, Bool_.Y).Test__vals(4, 15);
|
||||
fxt.Clear().Add_bool(Bool_.Y, Bool_.N, Bool_.N, Bool_.Y).Test__vals(4, 9);
|
||||
fxt.Clear().Add_bool(8, Bool_.Y).Test__vals(0, 0, 255);
|
||||
}
|
||||
@Test public void Add_byte() {
|
||||
fxt.Clear().Add_byte(255).Test__vals(0, 0, 255);
|
||||
}
|
||||
@Test public void Add_bool_byte() {
|
||||
fxt.Clear().Add_bool(Bool_.N).Add_byte(255).Test__vals(1, 127, 254);
|
||||
fxt.Clear().Add_bool(Bool_.Y).Add_byte(255).Test__vals(1, 127, 255);
|
||||
fxt.Clear().Add_bool(Bool_.Y, Bool_.Y, Bool_.Y, Bool_.Y).Add_byte(255).Test__vals(4, 15, 255);
|
||||
}
|
||||
@Test public void Add_byte_digits() {
|
||||
fxt.Clear().Add_byte(4, 15).Test__vals(4, 15);
|
||||
fxt.Clear().Add_byte(7, 127).Add_byte(2, 3).Test__vals(1, 1, 255);
|
||||
|
||||
fxt.Clear().Add_byte(3, 7).Add_byte(3, 7).Test__vals(6, 63);
|
||||
fxt.Clear().Add_byte(6, 63).Add_byte(3, 7).Test__vals(1, 1, 255);
|
||||
|
||||
fxt.Clear().Add_byte(3, 6).Add_byte(3, 6).Test__vals(6, 54);
|
||||
}
|
||||
@Test public void Add_int_hzip() {
|
||||
fxt.Clear().Add_int_hzip(1, 100).Test__vals(0, 0, 100);
|
||||
fxt.Clear().Add_int_hzip(1, 300).Test__vals(0, 0, 253, 1, 44);
|
||||
fxt.Clear().Add_int_hzip(2, 100).Test__vals(0, 0, 0, 100);
|
||||
fxt.Clear().Add_bool(Bool_.N).Add_int_hzip(1, 300).Test__vals(1, 0, 250, 3, 88);
|
||||
}
|
||||
}
|
||||
class Bit_heap_wtr_fxt {
|
||||
private final Bit_heap_wtr heap = new Bit_heap_wtr();
|
||||
public Bit_heap_wtr_fxt Clear() {heap.Clear(); return this;}
|
||||
public Bit_heap_wtr_fxt Add_bool(int len, boolean v) {
|
||||
boolean[] ary = new boolean[len];
|
||||
for (int i = 0; i < len; ++i)
|
||||
ary[i] = v;
|
||||
Add_bool(ary);
|
||||
return this;
|
||||
}
|
||||
public Bit_heap_wtr_fxt Add_bool(boolean... v) {
|
||||
int len = v.length;
|
||||
for (int i = 0; i < len; ++i)
|
||||
heap.Add_bool(v[i]);
|
||||
return this;
|
||||
}
|
||||
public Bit_heap_wtr_fxt Add_byte(int... v) {
|
||||
int len = v.length;
|
||||
for (int i = 0; i < len; ++i)
|
||||
heap.Add_byte((byte)v[i]);
|
||||
return this;
|
||||
}
|
||||
public Bit_heap_wtr_fxt Add_byte(int bits, int val) {
|
||||
heap.Add_byte(bits, (byte)val);
|
||||
return this;
|
||||
}
|
||||
public Bit_heap_wtr_fxt Add_int_hzip(int reqd, int val) {
|
||||
heap.Add_int_hzip(reqd, val);
|
||||
return this;
|
||||
}
|
||||
public void Test__vals(int expd_cur_bits, int expd_cur, int... expd_ary) {
|
||||
Tfds.Eq_int (expd_cur_bits , heap.Cur_bits() , "cur_bits");
|
||||
Tfds.Eq_int (expd_cur , heap.Cur() , "cur");
|
||||
Tfds.Eq_ary (Bry_.New_by_ints(expd_ary) , heap.Heap().To_bry() , "heap");
|
||||
}
|
||||
}
|
||||
@@ -20,8 +20,8 @@ import gplx.core.errs.*;
|
||||
public class Bry_rdr {
|
||||
private final gplx.core.primitives.Int_obj_ref pos_ref = gplx.core.primitives.Int_obj_ref.neg1_();
|
||||
public byte[] Src() {return src;} private byte[] src;
|
||||
public int Pos() {return pos;} private int pos;
|
||||
public int Src_end() {return src_end;} private int src_end;
|
||||
public int Pos() {return pos;} private int pos;
|
||||
public Bry_rdr Dflt_dlm_(byte b) {this.dflt_dlm = b; return this;} private byte dflt_dlm;
|
||||
public Bry_rdr Fail_throws_err_(boolean v) {err_wkr.Fail_throws_err_(v); return this;}
|
||||
public Bry_rdr Init_by_page(byte[] page, byte[] src, int src_len) {err_wkr.Init_by_page(String_.new_u8(page), src); this.pos = 0; this.src = src; this.src_end = src_len; return this;}
|
||||
@@ -109,12 +109,7 @@ public class Bry_rdr {
|
||||
if (bgn == pos) {err_wkr.Fail("int is empty"); return Int_.Min_value;}
|
||||
return rv * negative;
|
||||
}
|
||||
public byte Read_byte_as_a7_int() {
|
||||
byte rv = Byte_ascii.To_a7_int(src[pos]);
|
||||
++pos;
|
||||
return rv;
|
||||
}
|
||||
public int Read_int_by_base85(int reqd) {
|
||||
public int Read_hzip_int(int reqd) {
|
||||
int rv = gplx.xowa.htmls.core.hzips.Xoh_hzip_int_.Decode(reqd, src, src_end, pos, pos_ref);
|
||||
pos = pos_ref.Val();
|
||||
return rv;
|
||||
|
||||
@@ -45,9 +45,9 @@ public class Btrie_u8_mgr_tst {
|
||||
}
|
||||
@Test public void Uft8_asymmetric() {
|
||||
fxt.Init_add(Bry_.new_u8("İ") , "1");
|
||||
fxt.Test_match("İ" , "1"); // exact=y; İ = Bry_.new_ints(196,176)
|
||||
fxt.Test_match("i" , "1"); // lower=y; i = Bry_.new_ints(105)
|
||||
fxt.Test_match("I" , null); // upper=n; I = Bry_.new_ints( 73); see Btrie_u8_itm and rv.asymmetric_bry
|
||||
fxt.Test_match("İ" , "1"); // exact=y; İ = Bry_.New_by_ints(196,176)
|
||||
fxt.Test_match("i" , "1"); // lower=y; i = Bry_.New_by_ints(105)
|
||||
fxt.Test_match("I" , null); // upper=n; I = Bry_.New_by_ints( 73); see Btrie_u8_itm and rv.asymmetric_bry
|
||||
|
||||
fxt.Clear();
|
||||
fxt.Init_add(Bry_.new_u8("i") , "1");
|
||||
|
||||
@@ -88,9 +88,6 @@ public class Io_line_rdr {
|
||||
}
|
||||
while (true) {
|
||||
int compare = Bry_.Compare(ttl, 0, ttl.length, bfr, key_pos_bgn, key_pos_end);
|
||||
// if (String_.new_u8(bfr, key_pos_bgn, key_pos_end) == "US Naval Jack.svg") {
|
||||
// Tfds.Write();
|
||||
// }
|
||||
if (compare == CompareAble_.Same) { // eq; return true and move fwd; EX: "BA" and "BA"
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ package gplx.core.ios; import gplx.*; import gplx.core.*;
|
||||
public class Io_sort_split_itm_sorter implements gplx.core.lists.ComparerAble {
|
||||
public int compare(Object lhsObj, Object rhsObj) {
|
||||
Io_sort_split_itm lhs = (Io_sort_split_itm)lhsObj, rhs = (Io_sort_split_itm)rhsObj;
|
||||
// Tfds.Write(String_.new_u8(lhs.Bfr(), lhs.Key_bgn(), lhs.Key_end()), String_.new_u8(rhs.Bfr(), rhs.Key_bgn(), rhs.Key_end()));
|
||||
// Tfds.Dbg(String_.new_u8(lhs.Bfr(), lhs.Key_bgn(), lhs.Key_end()), String_.new_u8(rhs.Bfr(), rhs.Key_bgn(), rhs.Key_end()));
|
||||
return Bry_.Compare(lhs.Bfr(), lhs.Key_bgn(), lhs.Key_end(), rhs.Bfr(), rhs.Key_bgn(), rhs.Key_end());
|
||||
}
|
||||
public static final Io_sort_split_itm_sorter Instance = new Io_sort_split_itm_sorter(); Io_sort_split_itm_sorter() {}
|
||||
|
||||
@@ -106,6 +106,7 @@ public class Gfo_protocol_itm {
|
||||
;
|
||||
public static final String Str_file = "file:", Str_xcmd = "xowa-cmd:";
|
||||
public static final byte[] Bry_file = Bry_.new_a7(Str_file), Bry_xcmd = Bry_.new_a7(Str_xcmd);
|
||||
public static final byte[] Bry_file_with_slashes = Bry_.new_a7("file:///");
|
||||
public static final int Len_xcmd = Bry_xcmd.length;
|
||||
public static final byte[] Bry_relative = Bry_.new_a7("//");
|
||||
public static Gfo_protocol_itm Get_or(byte tid, Gfo_protocol_itm or) {
|
||||
|
||||
@@ -97,7 +97,7 @@ public class Gfo_url_parser {
|
||||
case Byte_ascii.Question: pos = Parse_qarg_key_1st(pos, b); break;
|
||||
case Byte_ascii.Amp: pos = Parse_qarg_key_nth(pos, b); break;
|
||||
case Byte_ascii.Eq: pos = Parse_qarg_val(pos, b); break;
|
||||
case Byte_ascii.Hash: pos = Parse_anch(pos, b); break;
|
||||
case Byte_ascii.Hash: if (anch_bgn == -1) pos = Parse_anch(pos, b); else ++pos; break; // anchor begins at 1st #, not last #; EX:A#B#C has anchor of "B#C" not "C" PAGE:en.w:Grand_Central_Terminal; DATE:2015-12-31
|
||||
case Byte_ascii.Percent: encoded = true; ++pos; break;
|
||||
default:
|
||||
++pos;
|
||||
|
||||
@@ -89,16 +89,16 @@ public class Gfo_url_parser_tst {
|
||||
tstr.Run_parse("https://site/A#B").Chk_page("A").Chk_anch("B");
|
||||
}
|
||||
@Test public void Anch__repeat__2() {
|
||||
tstr.Run_parse("https://site/A#B#C").Chk_page("A#B").Chk_anch("C");
|
||||
tstr.Run_parse("https://site/A#B#C").Chk_page("A").Chk_anch("B#C");
|
||||
}
|
||||
@Test public void Anch__repeat__3() {
|
||||
tstr.Run_parse("https://site/A#B#C#D").Chk_page("A#B#C").Chk_anch("D");
|
||||
tstr.Run_parse("https://site/A#B#C#D").Chk_page("A").Chk_anch("B#C#D");
|
||||
}
|
||||
@Test public void Anch__missing() {
|
||||
tstr.Run_parse("https://site/A#").Chk_page("A#").Chk_anch(null);
|
||||
}
|
||||
@Test public void Anch__missing__eos() {
|
||||
tstr.Run_parse("https://site/A#B#").Chk_page("A#B#").Chk_anch(null);
|
||||
tstr.Run_parse("https://site/A#B#").Chk_page("A").Chk_anch("B#");
|
||||
}
|
||||
@Test public void Anch__qargs__basic() {
|
||||
tstr.Run_parse("https://site/A?B=C&D=E#F").Chk_page("A").Chk_qargs("B", "C", "D", "E").Chk_anch("F");
|
||||
|
||||
@@ -15,10 +15,10 @@ 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.drds; import gplx.*; import gplx.xowa.*;
|
||||
public interface Xod_img_loader {
|
||||
void Show_img(int html_uid);
|
||||
package gplx.dbs.diffs; import gplx.*; import gplx.dbs.*;
|
||||
public class Gfdb_diff_db {
|
||||
public Gfdb_diff_db(Db_conn conn) {
|
||||
this.conn = conn;
|
||||
}
|
||||
public Db_conn Conn() {return conn;} private final Db_conn conn;
|
||||
}
|
||||
/*
|
||||
int uid
|
||||
*/
|
||||
34
400_xowa/src/gplx/dbs/diffs/Gfdb_diff_db_.java
Normal file
34
400_xowa/src/gplx/dbs/diffs/Gfdb_diff_db_.java
Normal file
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
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.dbs.diffs; import gplx.*; import gplx.dbs.*;
|
||||
public class Gfdb_diff_db_ {
|
||||
public static final String
|
||||
Fld__diff_site = "diff_site" // -1 for single-site merge; 0+ for multiple-site merges where 0+ is defined in a registry
|
||||
, Fld__diff_time = "diff_time" // -1 for single-time merge; 0+ for multiple-time merges where 0+ is defined in a registry
|
||||
, Fld__diff_db_trg = "diff_db_trg" // -1 for single-db tables; 0+ for multiple-db tables
|
||||
, Fld__diff_db_src = "diff_db_src" // -1 for I,U,D; 0+ for M
|
||||
, Fld__diff_type = "diff_type" // I,U,D,M
|
||||
, Fld__diff_uid = "diff_uid" // 0+
|
||||
;
|
||||
public static final byte
|
||||
Tid__insert = 0
|
||||
, Tid__update = 1
|
||||
, Tid__delete = 2
|
||||
, Tid__move = 3
|
||||
;
|
||||
}
|
||||
34
400_xowa/src/gplx/dbs/diffs/Gfdb_diff_tbl.java
Normal file
34
400_xowa/src/gplx/dbs/diffs/Gfdb_diff_tbl.java
Normal file
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
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.dbs.diffs; import gplx.*; import gplx.dbs.*;
|
||||
public class Gfdb_diff_tbl {
|
||||
public Gfdb_diff_tbl(String name, Db_meta_fld[] keys, Db_meta_fld[] vals, Db_rdr rdr) {
|
||||
this.name = name; this.keys = keys; this.vals = vals; this.rdr = rdr;
|
||||
int keys_len = keys.length; int vals_len = vals.length;
|
||||
this.flds = new Db_meta_fld[keys_len + vals_len];
|
||||
for (int i = 0; i < keys_len; ++i)
|
||||
flds[i] = keys[i];
|
||||
for (int i = 0; i < vals_len; ++i)
|
||||
flds[i + keys_len] = vals[i];
|
||||
}
|
||||
public String Name() {return name;} private final String name;
|
||||
public Db_meta_fld[] Flds() {return flds;} private final Db_meta_fld[] flds;
|
||||
public Db_meta_fld[] Keys() {return keys;} private final Db_meta_fld[] keys;
|
||||
public Db_meta_fld[] Vals() {return vals;} private final Db_meta_fld[] vals;
|
||||
public Db_rdr Rdr() {return rdr;} private final Db_rdr rdr;
|
||||
}
|
||||
56
400_xowa/src/gplx/dbs/diffs/Gfdb_rdr_utl_.java
Normal file
56
400_xowa/src/gplx/dbs/diffs/Gfdb_rdr_utl_.java
Normal file
@@ -0,0 +1,56 @@
|
||||
/*
|
||||
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.dbs.diffs; import gplx.*; import gplx.dbs.*;
|
||||
public class Gfdb_rdr_utl_ {
|
||||
public static int Compare(Db_meta_fld[] flds, int len, Db_rdr lhs_rdr, Db_rdr rhs_rdr) {
|
||||
int comp = CompareAble_.Same;
|
||||
for (int i = 0; i < len; ++i) {
|
||||
Db_meta_fld fld = flds[i];
|
||||
String fld_name = fld.Name();
|
||||
switch (fld.Tid()) {
|
||||
case Db_meta_fld.Tid_bool: comp = Bool_.Compare (lhs_rdr.Read_bool_by_byte(fld_name), rhs_rdr.Read_bool_by_byte(fld_name)); break;
|
||||
case Db_meta_fld.Tid_int: comp = Int_.Compare (lhs_rdr.Read_int(fld_name) , rhs_rdr.Read_int(fld_name)); break;
|
||||
case Db_meta_fld.Tid_long: comp = Long_.Compare (lhs_rdr.Read_long(fld_name) , rhs_rdr.Read_long(fld_name)); break;
|
||||
case Db_meta_fld.Tid_float: comp = Float_.Compare (lhs_rdr.Read_float(fld_name) , rhs_rdr.Read_float(fld_name)); break;
|
||||
case Db_meta_fld.Tid_double: comp = Double_.Compare (lhs_rdr.Read_double(fld_name) , rhs_rdr.Read_double(fld_name)); break;
|
||||
case Db_meta_fld.Tid_str: comp = String_.Compare (lhs_rdr.Read_str(fld_name) , rhs_rdr.Read_str(fld_name)); break;
|
||||
case Db_meta_fld.Tid_bry: comp = Bry_.Compare (lhs_rdr.Read_bry(fld_name) , rhs_rdr.Read_bry(fld_name)); break;
|
||||
default: throw Err_.new_unhandled(fld.Tid());
|
||||
}
|
||||
if (comp != CompareAble_.Same) return comp;
|
||||
}
|
||||
return CompareAble_.Same;
|
||||
}
|
||||
public static void Stmt_args(Db_stmt stmt, Db_meta_fld[] flds, int len, Db_rdr rdr) {
|
||||
for (int i = 0; i < len; ++i) {
|
||||
Db_meta_fld fld = flds[i];
|
||||
String fld_name = fld.Name();
|
||||
switch (fld.Tid()) {
|
||||
case Db_meta_fld.Tid_bool: stmt.Val_bool_as_byte (fld_name, rdr.Read_bool_by_byte(fld_name)); break;
|
||||
case Db_meta_fld.Tid_byte: stmt.Val_byte (fld_name, rdr.Read_byte(fld_name)); break;
|
||||
case Db_meta_fld.Tid_int: stmt.Val_int (fld_name, rdr.Read_int(fld_name)); break;
|
||||
case Db_meta_fld.Tid_long: stmt.Val_long (fld_name, rdr.Read_long(fld_name)); break;
|
||||
case Db_meta_fld.Tid_float: stmt.Val_float (fld_name, rdr.Read_float(fld_name)); break;
|
||||
case Db_meta_fld.Tid_double: stmt.Val_double (fld_name, rdr.Read_double(fld_name)); break;
|
||||
case Db_meta_fld.Tid_str: stmt.Val_str (fld_name, rdr.Read_str(fld_name)); break;
|
||||
case Db_meta_fld.Tid_bry: stmt.Val_bry (fld_name, rdr.Read_bry(fld_name)); break;
|
||||
default: throw Err_.new_unhandled(fld.Tid());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
38
400_xowa/src/gplx/dbs/diffs/builds/Gfdb_diff_bldr.java
Normal file
38
400_xowa/src/gplx/dbs/diffs/builds/Gfdb_diff_bldr.java
Normal file
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
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.dbs.diffs.builds; import gplx.*; import gplx.dbs.*; import gplx.dbs.diffs.*;
|
||||
import gplx.dbs.*;
|
||||
public class Gfdb_diff_bldr {
|
||||
private Gfdb_diff_rdr_comparer rdr_comparer = new Gfdb_diff_rdr_comparer();
|
||||
private Gfdb_diff_wkr diff_wkr;
|
||||
public void Init(Gfdb_diff_wkr diff_wkr) {this.diff_wkr = diff_wkr;}
|
||||
public void Compare(Gfdb_diff_tbl lhs_tbl, Gfdb_diff_tbl rhs_tbl) {
|
||||
rdr_comparer.Init(lhs_tbl, rhs_tbl);
|
||||
diff_wkr.Init_tbls(lhs_tbl, rhs_tbl);
|
||||
boolean loop = true;
|
||||
while (loop) {
|
||||
int rslt = rdr_comparer.Compare();
|
||||
switch (rslt) {
|
||||
case Gfdb_diff_rdr_comparer.Rslt__same: diff_wkr.Handle_same(); break;
|
||||
case Gfdb_diff_rdr_comparer.Rslt__lhs_missing: diff_wkr.Handle_lhs_missing(); break;
|
||||
case Gfdb_diff_rdr_comparer.Rslt__rhs_missing: diff_wkr.Handle_rhs_missing(); break;
|
||||
case Gfdb_diff_rdr_comparer.Rslt__done: loop = false; break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
123
400_xowa/src/gplx/dbs/diffs/builds/Gfdb_diff_bldr_tst.java
Normal file
123
400_xowa/src/gplx/dbs/diffs/builds/Gfdb_diff_bldr_tst.java
Normal file
@@ -0,0 +1,123 @@
|
||||
/*
|
||||
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.dbs.diffs.builds; import gplx.*; import gplx.dbs.*; import gplx.dbs.diffs.*;
|
||||
import org.junit.*;
|
||||
import gplx.dbs.*; import gplx.dbs.engines.mems.*;
|
||||
public class Gfdb_diff_bldr_tst {
|
||||
private final Gfdb_diff_bldr_fxt fxt = new Gfdb_diff_bldr_fxt();
|
||||
@Test public void Same() {
|
||||
fxt.Init__tbl__lhs(Object_.Ary(1, "A") , Object_.Ary(2, "B"));
|
||||
fxt.Init__tbl__rhs(Object_.Ary(1, "A") , Object_.Ary(2, "B"));
|
||||
fxt.Test__bld();
|
||||
}
|
||||
@Test public void Update() {
|
||||
fxt.Init__tbl__lhs(Object_.Ary(1, "A") , Object_.Ary(2, "B"));
|
||||
fxt.Init__tbl__rhs(Object_.Ary(1, "A1") , Object_.Ary(2, "B1"));
|
||||
fxt.Test__bld("U|1|A1", "U|2|B1");
|
||||
}
|
||||
@Test public void Insert() {
|
||||
fxt.Init__tbl__lhs(Object_.Ary(1, "A"));
|
||||
fxt.Init__tbl__rhs(Object_.Ary(1, "A") , Object_.Ary(2, "B"));
|
||||
fxt.Test__bld("I|2|B");
|
||||
}
|
||||
@Test public void Delete() {
|
||||
fxt.Init__tbl__lhs(Object_.Ary(1, "A") , Object_.Ary(2, "B"));
|
||||
fxt.Init__tbl__rhs(Object_.Ary(1, "A"));
|
||||
fxt.Test__bld("D|2");
|
||||
}
|
||||
@Test public void Basic() {
|
||||
fxt.Init__tbl__lhs
|
||||
( Object_.Ary(1, "A")
|
||||
, Object_.Ary(2, "B")
|
||||
, Object_.Ary(3, "C")
|
||||
);
|
||||
fxt.Init__tbl__rhs
|
||||
( Object_.Ary(1, "A")
|
||||
, Object_.Ary(2, "B1")
|
||||
, Object_.Ary(4, "D")
|
||||
);
|
||||
fxt.Test__bld("U|2|B1", "D|3", "I|4|D");
|
||||
}
|
||||
}
|
||||
class Gfdb_diff_bldr_fxt {
|
||||
private final Gfdb_diff_bldr bldr = new Gfdb_diff_bldr();
|
||||
private final Gfdb_diff_wkr__test wkr = new Gfdb_diff_wkr__test();
|
||||
private final Db_meta_fld[] key_flds, val_flds;
|
||||
private Gfdb_diff_tbl lhs_tbl, rhs_tbl;
|
||||
public Gfdb_diff_bldr_fxt() {
|
||||
Db_meta_fld_list fld_list = new Db_meta_fld_list();
|
||||
fld_list.Add_int("id");
|
||||
key_flds = fld_list.To_fld_ary();
|
||||
fld_list.Clear();
|
||||
fld_list.Add_str("val", 255);
|
||||
val_flds = fld_list.To_fld_ary();
|
||||
bldr.Init(wkr);
|
||||
}
|
||||
public void Init__tbl__lhs(Object[]... rows) {this.lhs_tbl = Make__tbl(key_flds, val_flds, rows);}
|
||||
public void Init__tbl__rhs(Object[]... rows) {this.rhs_tbl = Make__tbl(key_flds, val_flds, rows);}
|
||||
public void Test__bld(String... expd) {
|
||||
bldr.Compare(lhs_tbl, rhs_tbl);
|
||||
Tfds.Eq_ary_str(expd, wkr.To_str_ary());
|
||||
}
|
||||
private static Gfdb_diff_tbl Make__tbl(Db_meta_fld[] keys, Db_meta_fld[] vals, Object[][] rows) {
|
||||
int keys_len = keys.length; int vals_len = vals.length;
|
||||
int cols_len = keys_len + vals_len;
|
||||
String[] cols = new String[cols_len];
|
||||
for (int i = 0; i < keys_len; ++i)
|
||||
cols[i] = keys[i].Name();
|
||||
for (int i = 0; i < vals_len; ++i)
|
||||
cols[i + keys_len] = vals[i].Name();
|
||||
|
||||
int rows_len = rows.length;
|
||||
Mem_row[] mem_rows = new Mem_row[rows_len];
|
||||
for (int i = 0; i < rows_len; ++i) {
|
||||
Object[] row = rows[i];
|
||||
Mem_row mem_row = new Mem_row();
|
||||
mem_rows[i] = mem_row;
|
||||
for (int j = 0; j < cols_len; ++j) {
|
||||
Object cell = row[j];
|
||||
mem_row.Add(cols[j], cell);
|
||||
}
|
||||
}
|
||||
Db_rdr rdr = new Db_rdr__mem(cols, mem_rows);
|
||||
return new Gfdb_diff_tbl("tbl1", keys, vals, rdr);
|
||||
}
|
||||
}
|
||||
class Gfdb_diff_wkr__test implements Gfdb_diff_wkr {
|
||||
private final List_adp list = List_adp_.new_();
|
||||
private final Bry_bfr bfr = Bry_bfr.new_();
|
||||
private Db_rdr lhs_rdr, rhs_rdr;
|
||||
public void Init_tbls(Gfdb_diff_tbl lhs_tbl, Gfdb_diff_tbl rhs_tbl) {
|
||||
this.lhs_rdr = lhs_tbl.Rdr(); this.rhs_rdr = rhs_tbl.Rdr();
|
||||
}
|
||||
public void Term_tbls() {}
|
||||
public void Handle_same() {
|
||||
String lhs_val = lhs_rdr.Read_str("val");
|
||||
String rhs_val = rhs_rdr.Read_str("val");
|
||||
if (!String_.Eq(lhs_val, rhs_val))
|
||||
list.Add(bfr.Add_str_a7("U").Add_byte_pipe().Add_obj(lhs_rdr.Read_obj("id")).Add_byte_pipe().Add_str_a7(rhs_val).To_str_and_clear());
|
||||
}
|
||||
public void Handle_lhs_missing() {
|
||||
String rhs_val = rhs_rdr.Read_str("val");
|
||||
list.Add(bfr.Add_str_a7("I").Add_byte_pipe().Add_obj(rhs_rdr.Read_obj("id")).Add_byte_pipe().Add_str_a7(rhs_val).To_str_and_clear());
|
||||
}
|
||||
public void Handle_rhs_missing() {
|
||||
list.Add(bfr.Add_str_a7("D").Add_byte_pipe().Add_obj(lhs_rdr.Read_obj("id")).To_str_and_clear());
|
||||
}
|
||||
public String[] To_str_ary() {return list.To_str_ary_and_clear();}
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
/*
|
||||
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.dbs.diffs.builds; import gplx.*; import gplx.dbs.*; import gplx.dbs.diffs.*;
|
||||
class Gfdb_diff_rdr_comparer {
|
||||
private Db_rdr lhs_rdr, rhs_rdr;
|
||||
private boolean lhs_rdr_move, rhs_rdr_move;
|
||||
private boolean lhs_rdr_done, rhs_rdr_done;
|
||||
private Db_meta_fld[] key_flds; private int key_flds_len;
|
||||
public void Init(Gfdb_diff_tbl lhs_tbl, Gfdb_diff_tbl rhs_tbl) {
|
||||
this.lhs_rdr = lhs_tbl.Rdr(); this.rhs_rdr = rhs_tbl.Rdr();
|
||||
this.lhs_rdr_move = rhs_rdr_move = Bool_.Y;
|
||||
this.lhs_rdr_done = rhs_rdr_done = Bool_.N;
|
||||
this.key_flds = rhs_tbl.Keys(); key_flds_len = key_flds.length;
|
||||
}
|
||||
public int Compare() {
|
||||
if (lhs_rdr_move) {
|
||||
lhs_rdr_move = lhs_rdr.Move_next();
|
||||
if (!lhs_rdr_move) lhs_rdr_done = true;
|
||||
}
|
||||
if (rhs_rdr_move) {
|
||||
rhs_rdr_move = rhs_rdr.Move_next();
|
||||
if (!rhs_rdr_move) rhs_rdr_done = true;
|
||||
}
|
||||
if (lhs_rdr_done && rhs_rdr_done) return Gfdb_diff_rdr_comparer.Rslt__done;
|
||||
else if (lhs_rdr_done) {rhs_rdr_move = true; return Gfdb_diff_rdr_comparer.Rslt__lhs_missing;}
|
||||
else if (rhs_rdr_done) {lhs_rdr_move = true; return Gfdb_diff_rdr_comparer.Rslt__rhs_missing;}
|
||||
else {
|
||||
int comp = Gfdb_rdr_utl_.Compare(key_flds, key_flds_len, lhs_rdr, rhs_rdr);
|
||||
switch (comp) {
|
||||
case CompareAble_.Same: // lhs == rhs; move both
|
||||
lhs_rdr_move = rhs_rdr_move = true;
|
||||
return Gfdb_diff_rdr_comparer.Rslt__same;
|
||||
case CompareAble_.Less: // lhs < rhs; EX: lhs == 2; rhs == 3
|
||||
lhs_rdr_move = true;
|
||||
rhs_rdr_move = false;
|
||||
return Gfdb_diff_rdr_comparer.Rslt__rhs_missing;
|
||||
case CompareAble_.More: // lhs > rhs; EX: lhs == 4; rhs == 3
|
||||
lhs_rdr_move = false;
|
||||
rhs_rdr_move = true;
|
||||
return Gfdb_diff_rdr_comparer.Rslt__lhs_missing;
|
||||
default: throw Err_.new_unhandled(comp);
|
||||
}
|
||||
}
|
||||
}
|
||||
public static final int
|
||||
Rslt__same = 0
|
||||
, Rslt__lhs_missing = 1
|
||||
, Rslt__rhs_missing = 2
|
||||
, Rslt__done = 3
|
||||
;
|
||||
}
|
||||
25
400_xowa/src/gplx/dbs/diffs/builds/Gfdb_diff_wkr.java
Normal file
25
400_xowa/src/gplx/dbs/diffs/builds/Gfdb_diff_wkr.java
Normal file
@@ -0,0 +1,25 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.dbs.diffs.builds; import gplx.*; import gplx.dbs.*; import gplx.dbs.diffs.*;
|
||||
public interface Gfdb_diff_wkr {
|
||||
void Init_tbls(Gfdb_diff_tbl lhs, Gfdb_diff_tbl rhs);
|
||||
void Term_tbls();
|
||||
void Handle_same();
|
||||
void Handle_lhs_missing();
|
||||
void Handle_rhs_missing();
|
||||
}
|
||||
82
400_xowa/src/gplx/dbs/diffs/builds/Gfdb_diff_wkr__db.java
Normal file
82
400_xowa/src/gplx/dbs/diffs/builds/Gfdb_diff_wkr__db.java
Normal file
@@ -0,0 +1,82 @@
|
||||
/*
|
||||
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.dbs.diffs.builds; import gplx.*; import gplx.dbs.*; import gplx.dbs.diffs.*;
|
||||
class Gfdb_diff_wkr__db implements Gfdb_diff_wkr {
|
||||
private Gfdb_diff_tbl lhs_tbl, rhs_tbl;
|
||||
private Db_meta_fld[] val_flds; private int val_flds_len;
|
||||
private Db_conn diff_conn; private Db_stmt stmt;
|
||||
private int uid__upsert, uid__delete; private int prog_interval, prog_count;
|
||||
public void Init_conn(Gfdb_diff_db diff_db, int prog_interval) {this.diff_conn = diff_db.Conn(); this.prog_interval = prog_interval;}
|
||||
public void Init_tbls(Gfdb_diff_tbl lhs_tbl, Gfdb_diff_tbl rhs_tbl) {
|
||||
this.lhs_tbl = lhs_tbl; this.rhs_tbl = rhs_tbl;
|
||||
this.val_flds = lhs_tbl.Vals(); val_flds_len = val_flds.length;
|
||||
this.uid__upsert = 0; uid__delete = 0; this.prog_count = 0;
|
||||
String tbl_name = rhs_tbl.Name();
|
||||
Db_meta_fld[] diff_flds = Gfdb_diff_wkr__db_.New_diff_flds(rhs_tbl.Flds());
|
||||
if (!diff_conn.Meta_tbl_exists(tbl_name)) diff_conn.Ddl_create_tbl(Db_meta_tbl.new_(tbl_name, diff_flds));
|
||||
this.stmt = diff_conn.Stmt_insert(tbl_name, Gfdb_diff_wkr__db_.To_str_ary(diff_flds));
|
||||
diff_conn.Txn_bgn("diff_db");
|
||||
}
|
||||
public void Term_tbls() {
|
||||
diff_conn.Txn_end();
|
||||
}
|
||||
public void Handle_same() {
|
||||
if (Gfdb_rdr_utl_.Compare(val_flds, val_flds_len, lhs_tbl.Rdr(), rhs_tbl.Rdr()) != CompareAble_.Same)
|
||||
Insert(Gfdb_diff_db_.Tid__update, uid__upsert++, rhs_tbl.Flds(), rhs_tbl.Rdr());
|
||||
}
|
||||
public void Handle_lhs_missing() {Insert(Gfdb_diff_db_.Tid__insert, uid__upsert++, rhs_tbl.Flds(), rhs_tbl.Rdr());}
|
||||
public void Handle_rhs_missing() {Insert(Gfdb_diff_db_.Tid__delete, uid__delete++, lhs_tbl.Keys(), lhs_tbl.Rdr());}
|
||||
private void Insert(byte diff_type, int uid, Db_meta_fld[] flds, Db_rdr rdr) {
|
||||
stmt.Val_int (Gfdb_diff_db_.Fld__diff_site , -1)
|
||||
.Val_int (Gfdb_diff_db_.Fld__diff_time , -1)
|
||||
.Val_int (Gfdb_diff_db_.Fld__diff_db_trg , -1)
|
||||
.Val_int (Gfdb_diff_db_.Fld__diff_db_src , -1)
|
||||
.Val_byte (Gfdb_diff_db_.Fld__diff_type , diff_type)
|
||||
.Val_int (Gfdb_diff_db_.Fld__diff_type , uid)
|
||||
;
|
||||
Gfdb_rdr_utl_.Stmt_args(stmt, flds, flds.length, rdr);
|
||||
stmt.Exec_insert();
|
||||
if ((++prog_count % prog_interval) == 0) diff_conn.Txn_sav();
|
||||
}
|
||||
}
|
||||
class Gfdb_diff_wkr__db_ {
|
||||
public static Db_meta_fld[] New_diff_flds(Db_meta_fld[] all_flds) {
|
||||
int len = all_flds.length;
|
||||
int system_flds = 6;
|
||||
Db_meta_fld[] rv = new Db_meta_fld[len + system_flds];
|
||||
rv[0] = Db_meta_fld.new_int (Gfdb_diff_db_.Fld__diff_site);
|
||||
rv[1] = Db_meta_fld.new_int (Gfdb_diff_db_.Fld__diff_time);
|
||||
rv[2] = Db_meta_fld.new_int (Gfdb_diff_db_.Fld__diff_db_trg);
|
||||
rv[3] = Db_meta_fld.new_int (Gfdb_diff_db_.Fld__diff_db_src);
|
||||
rv[4] = Db_meta_fld.new_byte(Gfdb_diff_db_.Fld__diff_type);
|
||||
rv[5] = Db_meta_fld.new_int (Gfdb_diff_db_.Fld__diff_uid);
|
||||
for (int i = 0; i < len; ++i) {
|
||||
Db_meta_fld orig_fld = all_flds[i];
|
||||
Db_meta_fld diff_fld = new Db_meta_fld(orig_fld.Name(), orig_fld.Tid(), orig_fld.Len()).Nullable_y_(); // keep same name and type, but make nullable
|
||||
all_flds[i + system_flds] = diff_fld;
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
public static String[] To_str_ary(Db_meta_fld[] ary) {
|
||||
int len = ary.length;
|
||||
String[] rv = new String[len];
|
||||
for (int i = 0; i < len; ++i)
|
||||
rv[i] = ary[i].Name();
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
123
400_xowa/src/gplx/dbs/diffs/merges/Gfdb_diff_cmd.java
Normal file
123
400_xowa/src/gplx/dbs/diffs/merges/Gfdb_diff_cmd.java
Normal file
@@ -0,0 +1,123 @@
|
||||
/*
|
||||
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.dbs.diffs.merges; import gplx.*; import gplx.dbs.*; import gplx.dbs.diffs.*;
|
||||
import gplx.core.brys.fmtrs.*;
|
||||
interface Gfdb_diff_cmd {
|
||||
void Merge_undo();
|
||||
void Merge_exec();
|
||||
}
|
||||
class Gfdb_diff_cmd__insert {
|
||||
// else if I
|
||||
// // txn_bgn
|
||||
// // audit
|
||||
// INSERT INTO db_temp.page (diff_type, diff, *)
|
||||
// SELECT 'D', d.page_id, *
|
||||
// FROM db_diff.page d
|
||||
// JOIN db_main.page m ON d.page_id = m.page_id
|
||||
// WHERE d.diff_type = 0
|
||||
// AND d.diff_idx BETWEEN lo and hi
|
||||
//
|
||||
// // update
|
||||
// INSERT INTO db_main.page
|
||||
// SELECT d.page_title
|
||||
// FROM db_diff.page d
|
||||
// JOIN db_main.page m
|
||||
// // txn_end
|
||||
private Db_conn conn;
|
||||
private String exec_sql;
|
||||
public void Init(Db_conn main_conn, Db_conn diff_conn, Db_conn temp_conn, Gfdb_diff_tbl tbl) {
|
||||
this.conn = temp_conn;
|
||||
this.exec_sql = "";
|
||||
// this.exec_sql = String_.Format(String_.Concat_lines_nl_skip_last
|
||||
// ( "INSERT INTO db_curr.{tbl}"
|
||||
// ), Gfdb_diff_cmd_ctx.Alias__curr);
|
||||
}
|
||||
public void Merge_exec() {
|
||||
conn.Exec_sql(exec_sql);
|
||||
}
|
||||
}
|
||||
class Gfdb_diff_cmd_sql_bldr {
|
||||
private final Bry_fmtr fmtr = Bry_fmtr.new_();
|
||||
private final Bry_bfr tmp_bfr = Bry_bfr.new_();
|
||||
public void Bld_insert(Bry_bfr bfr, String tbl_name, String[] keys, String[] vals, int rng_bgn, int rng_end) {
|
||||
fmtr.Fmt_(Insert__fmt).Keys_(Insert__keys);
|
||||
fmtr.Bld_bfr_many(bfr, tbl_name, Bld_flds(tmp_bfr, ", ", "d.", keys, vals), Bld_join(keys), rng_bgn, rng_end);
|
||||
}
|
||||
public void Bld_update(Bry_bfr bfr, String tbl_name, String[] keys, String[] vals, int rng_bgn, int rng_end) {
|
||||
fmtr.Fmt_(Update__fmt).Keys_(Update__keys);
|
||||
fmtr.Bld_bfr_many(bfr, tbl_name, Bld_flds(tmp_bfr, ", ", "d.", keys, vals), Bld_join(keys), rng_bgn, rng_end);
|
||||
}
|
||||
public void Bld_delete(Bry_bfr bfr, String tbl_name, String[] keys, int rng_bgn, int rng_end) {
|
||||
fmtr.Fmt_(Delete__fmt).Keys_(Delete__keys);
|
||||
fmtr.Bld_bfr_many(bfr, tbl_name, Bld_flds(tmp_bfr, " || '|' || ", "", keys, String_.Ary_empty), Bld_flds(tmp_bfr, " || '|' || ", "k.", keys, String_.Ary_empty), Bld_join(keys), rng_bgn, rng_end);
|
||||
}
|
||||
private static String Bld_flds(Bry_bfr tmp_bfr, String dlm, String alias, String[] keys, String[] vals) {
|
||||
int keys_len = keys.length;
|
||||
for (int i = 0; i < keys_len; ++i) {
|
||||
String key = keys[i];
|
||||
if (i != 0) tmp_bfr.Add_str_a7(dlm);
|
||||
tmp_bfr.Add_str_a7(alias).Add_str_a7(key);
|
||||
}
|
||||
int flds_len = vals.length;
|
||||
for (int i = 0; i < flds_len; ++i) {
|
||||
String val = vals[i];
|
||||
tmp_bfr.Add_str_a7(dlm);
|
||||
tmp_bfr.Add_str_a7(alias).Add_str_a7(val);
|
||||
}
|
||||
return tmp_bfr.To_str_and_clear();
|
||||
}
|
||||
private String Bld_join(String[] keys) {
|
||||
int len = keys.length;
|
||||
for (int i = 0; i < len; ++i) {
|
||||
String key = keys[i];
|
||||
tmp_bfr.Add_str_a7(i == 0 ? " ON " : " AND ");
|
||||
tmp_bfr.Add_str_a7("k.").Add_str_a7(key).Add_str_a7(" = ");
|
||||
tmp_bfr.Add_str_a7("d.").Add_str_a7(key);
|
||||
}
|
||||
return tmp_bfr.To_str_and_clear();
|
||||
}
|
||||
private static final String[] Insert__keys = String_.Ary("tbl", "flds", "join", "rng_bgn", "rng_end");
|
||||
private static final String Insert__fmt = String_.Concat_lines_nl_skip_last
|
||||
( "INSERT INTO db_curr.~{tbl}"
|
||||
, "SELECT ~{flds}"
|
||||
, "FROM db_temp.~{tbl}_pkey k"
|
||||
, " JOIN db_diff.~{tbl} d~{join}"
|
||||
, "WHERE k.diff_type = 1"
|
||||
, "AND k.diff_uid BETWEEN ~{rng_bgn} AND ~{rng_end};"
|
||||
);
|
||||
private static final String[] Update__keys = String_.Ary("tbl", "flds", "join", "rng_bgn", "rng_end");
|
||||
private static final String Update__fmt = String_.Concat_lines_nl_skip_last
|
||||
( "REPLACE INTO db_curr.~{tbl}"
|
||||
, "SELECT ~{flds}"
|
||||
, "FROM db_temp.~{tbl}_pkey k"
|
||||
, " JOIN db_diff.~{tbl} d~{join}"
|
||||
, "WHERE k.diff_type = 2"
|
||||
, "AND k.diff_uid BETWEEN ~{rng_bgn} AND ~{rng_end};"
|
||||
);
|
||||
private static final String[] Delete__keys = String_.Ary("tbl", "pkey_where", "pkey_select", "join", "rng_bgn", "rng_end");
|
||||
private static final String Delete__fmt = String_.Concat_lines_nl_skip_last
|
||||
( "DELETE db_curr.~{tbl}"
|
||||
, "WHERE ~{pkey_where} IN"
|
||||
, "( SELECT ~{pkey_select}"
|
||||
, " FROM db_temp.~{tbl}_pkey k"
|
||||
, " JOIN db_diff.~{tbl} d~{join}"
|
||||
, " WHERE k.diff_type = 0"
|
||||
, " AND k.diff_uid BETWEEN ~{rng_bgn} AND ~{rng_end}"
|
||||
, ");"
|
||||
);
|
||||
}
|
||||
@@ -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.dbs.diffs.merges; import gplx.*; import gplx.dbs.*; import gplx.dbs.diffs.*;
|
||||
import org.junit.*;
|
||||
import gplx.dbs.*; import gplx.dbs.engines.mems.*;
|
||||
public class Gfdb_diff_cmd_sql_bldr_tst {
|
||||
private final Gfdb_diff_cmd_sql_bldr_fxt fxt = new Gfdb_diff_cmd_sql_bldr_fxt();
|
||||
@Test public void Insert() {
|
||||
fxt.Test__insert("tbl1", String_.Ary("key1", "key2"), String_.Ary("fld1", "fld2"), 0, 99, String_.Concat_lines_nl_skip_last
|
||||
( "INSERT INTO db_curr.tbl1"
|
||||
, "SELECT d.key1, d.key2, d.fld1, d.fld2"
|
||||
, "FROM db_temp.tbl1_pkey k"
|
||||
, " JOIN db_diff.tbl1 d ON k.key1 = d.key1 AND k.key2 = d.key2"
|
||||
, "WHERE k.diff_type = 1"
|
||||
, "AND k.diff_uid BETWEEN 0 AND 99;"
|
||||
));
|
||||
}
|
||||
@Test public void Update() {
|
||||
fxt.Test__update("tbl1", String_.Ary("key1", "key2"), String_.Ary("fld1", "fld2"), 0, 99, String_.Concat_lines_nl_skip_last
|
||||
( "REPLACE INTO db_curr.tbl1"
|
||||
, "SELECT d.key1, d.key2, d.fld1, d.fld2"
|
||||
, "FROM db_temp.tbl1_pkey k"
|
||||
, " JOIN db_diff.tbl1 d ON k.key1 = d.key1 AND k.key2 = d.key2"
|
||||
, "WHERE k.diff_type = 2"
|
||||
, "AND k.diff_uid BETWEEN 0 AND 99;"
|
||||
));
|
||||
}
|
||||
@Test public void Delete() {
|
||||
fxt.Test__delete("tbl1", String_.Ary("key1", "key2"), 0, 99, String_.Concat_lines_nl_skip_last
|
||||
( "DELETE db_curr.tbl1"
|
||||
, "WHERE key1 || '|' || key2 IN"
|
||||
, "( SELECT k.key1 || '|' || k.key2"
|
||||
, " FROM db_temp.tbl1_pkey k"
|
||||
, " JOIN db_diff.tbl1 d ON k.key1 = d.key1 AND k.key2 = d.key2"
|
||||
, " WHERE k.diff_type = 0"
|
||||
, " AND k.diff_uid BETWEEN 0 AND 99"
|
||||
, ");"
|
||||
));
|
||||
}
|
||||
}
|
||||
class Gfdb_diff_cmd_sql_bldr_fxt {
|
||||
private Gfdb_diff_cmd_sql_bldr bldr = new Gfdb_diff_cmd_sql_bldr();
|
||||
private final Bry_bfr bfr = Bry_bfr.new_();
|
||||
public void Test__insert(String tbl_name, String[] keys, String[] flds, int rng_bgn, int rng_end, String expd) {
|
||||
bldr.Bld_insert(bfr, tbl_name, keys, flds, 0, 99);
|
||||
Tfds.Eq_str_lines(expd, bfr.To_str_and_clear());
|
||||
}
|
||||
public void Test__update(String tbl_name, String[] keys, String[] flds, int rng_bgn, int rng_end, String expd) {
|
||||
bldr.Bld_update(bfr, tbl_name, keys, flds, 0, 99);
|
||||
Tfds.Eq_str_lines(expd, bfr.To_str_and_clear());
|
||||
}
|
||||
public void Test__delete(String tbl_name, String[] keys, int rng_bgn, int rng_end, String expd) {
|
||||
bldr.Bld_delete(bfr, tbl_name, keys, 0, 99);
|
||||
Tfds.Eq_str_lines(expd, bfr.To_str_and_clear());
|
||||
}
|
||||
}
|
||||
57
400_xowa/src/gplx/langs/htmls/Gfh_atr_.java
Normal file
57
400_xowa/src/gplx/langs/htmls/Gfh_atr_.java
Normal 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.langs.htmls; import gplx.*; import gplx.langs.*;
|
||||
public class Gfh_atr_ {
|
||||
public static final byte[]
|
||||
// "coreattrs"
|
||||
Bry__id = Bry_.new_a7("id")
|
||||
, Bry__class = Bry_.new_a7("class")
|
||||
, Bry__style = Bry_.new_a7("style")
|
||||
, Bry__title = Bry_.new_a7("title")
|
||||
// "i18n"
|
||||
, Bry__lang = Bry_.new_a7("lang")
|
||||
, Bry__dir = Bry_.new_a7("dir")
|
||||
// <a>
|
||||
, Bry__href = Bry_.new_a7("href")
|
||||
, Bry__rel = Bry_.new_a7("rel")
|
||||
// <img>
|
||||
, Bry__alt = Bry_.new_a7("alt")
|
||||
, Bry__src = Bry_.new_a7("src")
|
||||
, Bry__width = Bry_.new_a7("width")
|
||||
, Bry__height = Bry_.new_a7("height")
|
||||
// <table>
|
||||
//, Bry__width = Bry_.new_a7("width")
|
||||
, Bry__cellpadding = Bry_.new_a7("cellpadding")
|
||||
, Bry__cellspacing = Bry_.new_a7("cellspacing")
|
||||
, Bry__summary = Bry_.new_a7("summary") // HTML.ua
|
||||
// <table>.borders_and_rules
|
||||
, Bry__border = Bry_.new_a7("border")
|
||||
, Bry__frames = Bry_.new_a7("frames")
|
||||
, Bry__rules = Bry_.new_a7("rules")
|
||||
// <th>,<td>
|
||||
, Bry__scope = Bry_.new_a7("scope")
|
||||
, Bry__rowspan = Bry_.new_a7("rowspan")
|
||||
, Bry__colspan = Bry_.new_a7("colspan")
|
||||
, Bry__align = Bry_.new_a7("align") // HTML.v4
|
||||
, Bry__bgcolor = Bry_.new_a7("bgcolor") // HTML.v4
|
||||
, Bry__abbr = Bry_.new_a7("abbr") // HTML.ua
|
||||
;
|
||||
public static byte[] Make(Bry_bfr bfr, byte[] key, byte[] val) {
|
||||
return bfr.Add_byte_space().Add(key).Add_byte_eq().Add_byte_quote().Add(val).Add_byte_quote().To_bry_and_clear();
|
||||
}
|
||||
}
|
||||
@@ -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.langs.htmls; import gplx.*; import gplx.langs.*;
|
||||
public class Html_bldr_ {
|
||||
public class Gfh_bldr_ {
|
||||
public static final byte[]
|
||||
Bry__a_lhs_bgn = Bry_.new_a7("<a")
|
||||
, Bry__a_rhs = Bry_.new_a7("</a>")
|
||||
@@ -34,6 +34,7 @@ public class Html_bldr_ {
|
||||
, Bry__src__nth = Bry_.new_a7("\" src=\"")
|
||||
, Bry__width__nth = Bry_.new_a7("\" width=\"")
|
||||
, Bry__height__nth = Bry_.new_a7("\" height=\"")
|
||||
, Bry__lhs_end_head = Bry_.new_a7(">")
|
||||
, Bry__lhs_end_head_w_quote = Bry_.new_a7("\">")
|
||||
, Bry__lhs_end_inline = Bry_.new_a7("/>")
|
||||
, Bry__lhs_end_inline_w_quote = Bry_.new_a7("\"/>")
|
||||
@@ -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.langs.htmls; import gplx.*; import gplx.langs.*;
|
||||
public class Html_entity_ {
|
||||
public class Gfh_entity_ {
|
||||
public static final String
|
||||
Nl_str = " "
|
||||
;
|
||||
@@ -16,8 +16,8 @@ You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.langs.htmls; import gplx.*; import gplx.langs.*;
|
||||
public class Html_nde {
|
||||
public Html_nde(byte[] src, boolean tag_tid_is_inline, int tag_lhs_bgn, int tag_lhs_end, int tag_rhs_bgn, int tag_rhs_end, int name_bgn, int name_end, int[] cur_atrs, int atrs_idx) {
|
||||
public class Gfh_nde {
|
||||
public Gfh_nde(byte[] src, boolean tag_tid_is_inline, int tag_lhs_bgn, int tag_lhs_end, int tag_rhs_bgn, int tag_rhs_end, int name_bgn, int name_end, int[] cur_atrs, int atrs_idx) {
|
||||
this.src = src;
|
||||
this.tag_tid_is_inline = tag_tid_is_inline;
|
||||
this.tag_lhs_bgn = tag_lhs_bgn; this.tag_lhs_end = tag_lhs_end; this.tag_rhs_bgn = tag_rhs_bgn; this.tag_rhs_end = tag_rhs_end; this.name_bgn = name_bgn; this.name_end = name_end;
|
||||
@@ -32,12 +32,12 @@ public class Html_nde {
|
||||
public int[] Atrs() {return atrs;} private int[] atrs = Int_.Ary_empty;
|
||||
public int Atrs_len() {return atrs_len;} private int atrs_len;
|
||||
public boolean Tag_tid_is_inline() {return tag_tid_is_inline;} private boolean tag_tid_is_inline;
|
||||
public int Tag_lhs_bgn() {return tag_lhs_bgn;} public Html_nde Tag_lhs_bgn_(int v) {tag_lhs_bgn = v; return this;} private int tag_lhs_bgn;
|
||||
public int Tag_lhs_end() {return tag_lhs_end;} public Html_nde Tag_lhs_end_(int v) {tag_lhs_end = v; return this;} private int tag_lhs_end;
|
||||
public int Tag_rhs_bgn() {return tag_rhs_bgn;} public Html_nde Tag_rhs_bgn_(int v) {tag_rhs_bgn = v; return this;} private int tag_rhs_bgn;
|
||||
public int Tag_rhs_end() {return tag_rhs_end;} public Html_nde Tag_rhs_end_(int v) {tag_rhs_end = v; return this;} private int tag_rhs_end;
|
||||
public int Name_bgn() {return name_bgn;} public Html_nde Name_bgn_(int v) {name_bgn = v; return this;} private int name_bgn;
|
||||
public int Name_end() {return name_end;} public Html_nde Name_end_(int v) {name_end = v; return this;} private int name_end;
|
||||
public int Tag_lhs_bgn() {return tag_lhs_bgn;} public Gfh_nde Tag_lhs_bgn_(int v) {tag_lhs_bgn = v; return this;} private int tag_lhs_bgn;
|
||||
public int Tag_lhs_end() {return tag_lhs_end;} public Gfh_nde Tag_lhs_end_(int v) {tag_lhs_end = v; return this;} private int tag_lhs_end;
|
||||
public int Tag_rhs_bgn() {return tag_rhs_bgn;} public Gfh_nde Tag_rhs_bgn_(int v) {tag_rhs_bgn = v; return this;} private int tag_rhs_bgn;
|
||||
public int Tag_rhs_end() {return tag_rhs_end;} public Gfh_nde Tag_rhs_end_(int v) {tag_rhs_end = v; return this;} private int tag_rhs_end;
|
||||
public int Name_bgn() {return name_bgn;} public Gfh_nde Name_bgn_(int v) {name_bgn = v; return this;} private int name_bgn;
|
||||
public int Name_end() {return name_end;} public Gfh_nde Name_end_(int v) {name_end = v; return this;} private int name_end;
|
||||
public void Clear() {tag_lhs_bgn = tag_rhs_bgn = -1;}
|
||||
public String Atrs_val_by_key_str(String find_key_str) {return String_.new_u8(Atrs_val_by_key_bry(Bry_.new_u8(find_key_str)));}
|
||||
public byte[] Atrs_val_by_key_bry(byte[] find_key_bry) {
|
||||
@@ -17,17 +17,17 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.langs.htmls; import gplx.*; import gplx.langs.*;
|
||||
import gplx.core.brys.*;
|
||||
public class Html_parser {
|
||||
public Html_parser() {
|
||||
public class Gfh_parser {
|
||||
public Gfh_parser() {
|
||||
Bry_bldr bry_bldr = new Bry_bldr();
|
||||
bry_xnde_name = bry_bldr.New_256().Set_rng_xml_identifier(Scan_valid).Set_rng_ws(Scan_stop).Val();
|
||||
bry_atr_key = bry_bldr.New_256().Set_rng_xml_identifier(Scan_valid).Set_rng_ws(Scan_stop).Set_many(Scan_stop, Byte_ascii.Eq).Val();
|
||||
}
|
||||
byte[] src; int pos, end; byte[] bry_xnde_name, bry_atr_key;
|
||||
int cur_atrs_idx = 0; int[] cur_atrs = new int[250];// define max of 50 atrs;
|
||||
public Html_nde[] Parse_as_ary(byte[] src) {return Parse_as_ary(src, 0, src.length, Wildcard, Wildcard);}
|
||||
public Html_nde[] Parse_as_ary(byte[] src, int bgn, int end) {return Parse_as_ary(src, bgn, end, Wildcard, Wildcard);}
|
||||
public Html_nde[] Parse_as_ary(byte[] src, int bgn, int end, byte[] find_key, byte[] find_val) { // flattens html into a list of hndes; only used for Options
|
||||
public Gfh_nde[] Parse_as_ary(byte[] src) {return Parse_as_ary(src, 0, src.length, Wildcard, Wildcard);}
|
||||
public Gfh_nde[] Parse_as_ary(byte[] src, int bgn, int end) {return Parse_as_ary(src, bgn, end, Wildcard, Wildcard);}
|
||||
public Gfh_nde[] Parse_as_ary(byte[] src, int bgn, int end, byte[] find_key, byte[] find_val) { // flattens html into a list of hndes; only used for Options
|
||||
this.src = src; pos = bgn; this.end = end;
|
||||
List_adp rv = List_adp_.new_();
|
||||
while (pos < end) {
|
||||
@@ -37,14 +37,14 @@ public class Html_parser {
|
||||
if (xnde_init) {
|
||||
if (Parse_xnde_lhs()) {
|
||||
if (tag_tid_is_inline)
|
||||
rv.Add(new Html_nde(src, tag_tid_is_inline, cur_lhs_bgn, cur_lhs_end, cur_rhs_bgn, pos, cur_name_bgn, cur_name_end, cur_atrs, cur_atrs_idx));
|
||||
rv.Add(new Gfh_nde(src, tag_tid_is_inline, cur_lhs_bgn, cur_lhs_end, cur_rhs_bgn, pos, cur_name_bgn, cur_name_end, cur_atrs, cur_atrs_idx));
|
||||
else
|
||||
xnde_init = false;
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (Parse_xnde_rhs()) {
|
||||
rv.Add(new Html_nde(src, tag_tid_is_inline, cur_lhs_bgn, cur_lhs_end, cur_rhs_bgn, pos, cur_name_bgn, cur_name_end, cur_atrs, cur_atrs_idx));
|
||||
rv.Add(new Gfh_nde(src, tag_tid_is_inline, cur_lhs_bgn, cur_lhs_end, cur_rhs_bgn, pos, cur_name_bgn, cur_name_end, cur_atrs, cur_atrs_idx));
|
||||
}
|
||||
xnde_init = true;
|
||||
}
|
||||
@@ -53,7 +53,7 @@ public class Html_parser {
|
||||
break;
|
||||
}
|
||||
}
|
||||
return (Html_nde[])rv.To_ary(Html_nde.class);
|
||||
return (Gfh_nde[])rv.To_ary(Gfh_nde.class);
|
||||
}
|
||||
int cur_lhs_bgn, cur_lhs_end, cur_name_bgn, cur_name_end, cur_rhs_bgn; boolean xnde_init = true, tag_tid_is_inline = false;
|
||||
private boolean Parse_xnde_rhs() {
|
||||
@@ -17,8 +17,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.langs.htmls; import gplx.*; import gplx.langs.*;
|
||||
import org.junit.*;
|
||||
public class Html_parser_tst {
|
||||
@Before public void init() {fxt.Clear();} private Html_parser_fxt fxt = new Html_parser_fxt();
|
||||
public class Gfh_parser_tst {
|
||||
@Before public void init() {fxt.Clear();} private Gfh_parser_fxt fxt = new Gfh_parser_fxt();
|
||||
@Test public void One() {fxt.Test_parse_find_all("<a id='id0'></a>", "id0");}
|
||||
@Test public void Many() {fxt.Test_parse_find_all("<a id='id0'></a><a id='id1'></a><a id='id2'></a>", "id0", "id1", "id2");}
|
||||
@Test public void Inline() {fxt.Test_parse_find_all("<a id='id0'/>", "id0");}
|
||||
@@ -26,25 +26,25 @@ public class Html_parser_tst {
|
||||
@Test public void Quote_double() {fxt.Test_parse_find_all("<a id='id''0'/>", "id'0");}
|
||||
@Test public void Quote_escape() {fxt.Test_parse_find_all("<a id='id\\'0'/>", "id'0");}
|
||||
}
|
||||
class Html_parser_fxt {
|
||||
class Gfh_parser_fxt {
|
||||
public void Clear() {
|
||||
if (parser == null) {
|
||||
parser = new Html_parser();
|
||||
parser = new Gfh_parser();
|
||||
}
|
||||
} private Html_parser parser;
|
||||
public Html_parser_fxt Test_parse_find_all(String raw_str, String... expd) {return Test_parse_find(raw_str, Html_parser.Wildcard_str, Html_parser.Wildcard_str, expd);}
|
||||
public Html_parser_fxt Test_parse_find(String raw_str, String find_key, String find_val, String... expd) {
|
||||
} private Gfh_parser parser;
|
||||
public Gfh_parser_fxt Test_parse_find_all(String raw_str, String... expd) {return Test_parse_find(raw_str, Gfh_parser.Wildcard_str, Gfh_parser.Wildcard_str, expd);}
|
||||
public Gfh_parser_fxt Test_parse_find(String raw_str, String find_key, String find_val, String... expd) {
|
||||
byte[] raw = Bry_.new_a7(raw_str);
|
||||
Html_nde[] actl_ndes = parser.Parse_as_ary(raw, 0, raw.length, Bry_.new_a7(find_key), Bry_.new_a7(find_val));
|
||||
Gfh_nde[] actl_ndes = parser.Parse_as_ary(raw, 0, raw.length, Bry_.new_a7(find_key), Bry_.new_a7(find_val));
|
||||
String[] actl = Xto_ids(raw, actl_ndes);
|
||||
Tfds.Eq_ary_str(expd, actl);
|
||||
return this;
|
||||
}
|
||||
private String[] Xto_ids(byte[] src, Html_nde[] ary) {
|
||||
private String[] Xto_ids(byte[] src, Gfh_nde[] ary) {
|
||||
int len = ary.length;
|
||||
String[] rv = new String[len];
|
||||
for (int i = 0; i < len; i++) {
|
||||
Html_nde itm = ary[i];
|
||||
Gfh_nde itm = ary[i];
|
||||
String atr_val = itm.Atrs_val_by_key_str("id");
|
||||
rv[i] = atr_val;
|
||||
}
|
||||
@@ -16,12 +16,12 @@ 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.langs.htmls; import gplx.*; import gplx.langs.*;
|
||||
public class Html_selecter {
|
||||
public static Html_nde[] Select(byte[] src, Html_nde[] ary, Hash_adp_bry hash) {
|
||||
public class Gfh_selecter {
|
||||
public static Gfh_nde[] Select(byte[] src, Gfh_nde[] ary, Hash_adp_bry hash) {
|
||||
List_adp list = List_adp_.new_();
|
||||
int xndes_len = ary.length;
|
||||
for (int i = 0; i < xndes_len; i++) {
|
||||
Html_nde hnde = ary[i];
|
||||
Gfh_nde hnde = ary[i];
|
||||
int[] atrs = hnde.Atrs();
|
||||
int atrs_len = atrs.length;
|
||||
for (int j = 0; j < atrs_len; j += 5) {
|
||||
@@ -33,7 +33,7 @@ public class Html_selecter {
|
||||
}
|
||||
}
|
||||
}
|
||||
Html_nde[] rv = (Html_nde[])list.To_ary(Html_nde.class);
|
||||
Gfh_nde[] rv = (Gfh_nde[])list.To_ary(Gfh_nde.class);
|
||||
list.Clear();
|
||||
return rv;
|
||||
}
|
||||
@@ -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.langs.htmls; import gplx.*; import gplx.langs.*;
|
||||
public class Html_tag_ {
|
||||
public class Gfh_tag_ {
|
||||
public static final int
|
||||
Id__eos = -2
|
||||
, Id__any = -1
|
||||
@@ -34,11 +34,15 @@ public class Html_tag_ {
|
||||
, Id__ul = 11
|
||||
, Id__li = 12
|
||||
, Id__p = 13
|
||||
, Id__hr = 14
|
||||
, Id__br = 14
|
||||
, Id__hr = 15
|
||||
, Id__td = 16
|
||||
;
|
||||
public static final byte[]
|
||||
Bry__a = Bry_.new_a7("a")
|
||||
, Bry__ul = Bry_.new_a7("ul")
|
||||
, Bry__td = Bry_.new_a7("td")
|
||||
, Bry__th = Bry_.new_a7("th")
|
||||
;
|
||||
public static final Hash_adp_bry Hash = Hash_adp_bry.ci_a7()
|
||||
.Add_bry_int(Bry__a , Id__a)
|
||||
@@ -50,8 +54,12 @@ public class Html_tag_ {
|
||||
.Add_str_int("span" , Id__span)
|
||||
.Add_str_int("div" , Id__div)
|
||||
.Add_str_int("img" , Id__img)
|
||||
.Add_str_int("br" , Id__br)
|
||||
.Add_str_int("hr" , Id__hr)
|
||||
.Add_str_int("ul" , Id__ul)
|
||||
.Add_str_int("li" , Id__li)
|
||||
.Add_str_int("td" , Id__td)
|
||||
.Add_str_int("p" , Id__p)
|
||||
;
|
||||
public static String To_str(int tid) {
|
||||
switch (tid) {
|
||||
@@ -68,12 +76,18 @@ public class Html_tag_ {
|
||||
case Id__span: return "span";
|
||||
case Id__div: return "div";
|
||||
case Id__img: return "img";
|
||||
case Id__p: return "p";
|
||||
case Id__br: return "br";
|
||||
case Id__hr: return "hr";
|
||||
case Id__td: return "td";
|
||||
case Id__ul: return "ul";
|
||||
case Id__li: return "li";
|
||||
default: throw Err_.new_unhandled(tid);
|
||||
}
|
||||
}
|
||||
public static final byte[]
|
||||
Br_inl = Bry_.new_a7("<br/>")
|
||||
, Br_lhs = Bry_.new_a7("<br>")
|
||||
, Hr_inl = Bry_.new_a7("<hr/>")
|
||||
, Body_lhs = Bry_.new_a7("<body>") , Body_rhs = Bry_.new_a7("</body>")
|
||||
, B_lhs = Bry_.new_a7("<b>") , B_rhs = Bry_.new_a7("</b>")
|
||||
@@ -17,7 +17,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.langs.htmls; import gplx.*; import gplx.langs.*;
|
||||
import gplx.core.primitives.*; import gplx.core.btries.*; import gplx.langs.htmls.encoders.*;
|
||||
public class Html_utl {
|
||||
public class Gfh_utl {
|
||||
private static final Gfo_url_encoder encoder_id = Gfo_url_encoder_.Id; private static final Bry_bfr tmp_bfr = Bry_bfr.reset_(255);
|
||||
public static String Encode_id_as_str(byte[] key) {return String_.new_u8(Encode_id_as_bry(key));}
|
||||
public static byte[] Encode_id_as_bry(byte[] key) {
|
||||
@@ -44,8 +44,8 @@ public class Html_utl {
|
||||
dirty = true;
|
||||
}
|
||||
switch (quote_byte) {
|
||||
case Byte_ascii.Apos: bfr.Add(Html_entity_.Apos_num_bry); break;
|
||||
case Byte_ascii.Quote: bfr.Add(Html_entity_.Quote_bry); break;
|
||||
case Byte_ascii.Apos: bfr.Add(Gfh_entity_.Apos_num_bry); break;
|
||||
case Byte_ascii.Quote: bfr.Add(Gfh_entity_.Quote_bry); break;
|
||||
default: throw Err_.new_unhandled(quote_byte);
|
||||
}
|
||||
}
|
||||
@@ -73,11 +73,11 @@ public class Html_utl {
|
||||
for (int i = bgn; i < end; i++) {
|
||||
byte b = bry[i];
|
||||
switch (b) {
|
||||
case Byte_ascii.Lt: if (escape_lt) escaped = Html_entity_.Lt_bry; break;
|
||||
case Byte_ascii.Gt: if (escape_gt) escaped = Html_entity_.Gt_bry; break;
|
||||
case Byte_ascii.Amp: if (escape_amp) escaped = Html_entity_.Amp_bry; break;
|
||||
case Byte_ascii.Quote: if (escape_quote) escaped = Html_entity_.Quote_bry; break;
|
||||
case Byte_ascii.Apos: if (escape_apos) escaped = Html_entity_.Apos_num_bry; break;
|
||||
case Byte_ascii.Lt: if (escape_lt) escaped = Gfh_entity_.Lt_bry; break;
|
||||
case Byte_ascii.Gt: if (escape_gt) escaped = Gfh_entity_.Gt_bry; break;
|
||||
case Byte_ascii.Amp: if (escape_amp) escaped = Gfh_entity_.Amp_bry; break;
|
||||
case Byte_ascii.Quote: if (escape_quote) escaped = Gfh_entity_.Quote_bry; break;
|
||||
case Byte_ascii.Apos: if (escape_apos) escaped = Gfh_entity_.Apos_num_bry; break;
|
||||
default:
|
||||
if (dirty || write_to_bfr)
|
||||
bfr.Add_byte(b);
|
||||
@@ -104,11 +104,11 @@ public class Html_utl {
|
||||
}
|
||||
|
||||
private static final Btrie_slim_mgr unescape_trie = Btrie_slim_mgr.ci_a7()
|
||||
.Add_bry_byte(Html_entity_.Lt_bry , Byte_ascii.Lt)
|
||||
.Add_bry_byte(Html_entity_.Gt_bry , Byte_ascii.Gt)
|
||||
.Add_bry_byte(Html_entity_.Amp_bry , Byte_ascii.Amp)
|
||||
.Add_bry_byte(Html_entity_.Quote_bry , Byte_ascii.Quote)
|
||||
.Add_bry_byte(Html_entity_.Apos_num_bry , Byte_ascii.Apos)
|
||||
.Add_bry_byte(Gfh_entity_.Lt_bry , Byte_ascii.Lt)
|
||||
.Add_bry_byte(Gfh_entity_.Gt_bry , Byte_ascii.Gt)
|
||||
.Add_bry_byte(Gfh_entity_.Amp_bry , Byte_ascii.Amp)
|
||||
.Add_bry_byte(Gfh_entity_.Quote_bry , Byte_ascii.Quote)
|
||||
.Add_bry_byte(Gfh_entity_.Apos_num_bry , Byte_ascii.Apos)
|
||||
;
|
||||
public static String Unescape_as_str(String src) {
|
||||
Bry_bfr bfr = Bry_bfr.reset_(255);
|
||||
@@ -162,18 +162,18 @@ public class Html_utl {
|
||||
public static byte[] Del_comments(Bry_bfr bfr, byte[] src, int pos, int end) {
|
||||
while (true) {
|
||||
if (pos >= end) break;
|
||||
int comm_bgn = Bry_find_.Find_fwd(src, Html_tag_.Comm_bgn, pos); // look for <!--
|
||||
int comm_bgn = Bry_find_.Find_fwd(src, Gfh_tag_.Comm_bgn, pos); // look for <!--
|
||||
if (comm_bgn == Bry_find_.Not_found) { // not found; consume rest
|
||||
bfr.Add_mid(src, pos, end);
|
||||
break;
|
||||
}
|
||||
int comm_end = Bry_find_.Find_fwd(src, Html_tag_.Comm_end, comm_bgn + Html_tag_.Comm_bgn_len); // look for -->
|
||||
int comm_end = Bry_find_.Find_fwd(src, Gfh_tag_.Comm_end, comm_bgn + Gfh_tag_.Comm_bgn_len); // look for -->
|
||||
if (comm_end == Bry_find_.Not_found) { // not found; consume rest
|
||||
bfr.Add_mid(src, pos, end);
|
||||
break;
|
||||
}
|
||||
bfr.Add_mid(src, pos, comm_bgn); // add everything between pos and comm_bgn
|
||||
pos = comm_end + Html_tag_.Comm_end_len; // reposition pos after comm_end
|
||||
pos = comm_end + Gfh_tag_.Comm_end_len; // reposition pos after comm_end
|
||||
}
|
||||
return bfr.To_bry_and_clear();
|
||||
}
|
||||
@@ -17,8 +17,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.langs.htmls; import gplx.*; import gplx.langs.*;
|
||||
import org.junit.*;
|
||||
public class Html_utl_tst {
|
||||
@Before public void init() {fxt.Clear();} private Html_atr_class_fxt fxt = new Html_atr_class_fxt();
|
||||
public class Gfh_utl_tst {
|
||||
@Before public void init() {fxt.Clear();} private Gfh_class_fxt fxt = new Gfh_class_fxt();
|
||||
@Test public void Basic() {fxt.Test_del_comments("a<!-- b -->c" , "ac");}
|
||||
@Test public void Bgn_missing() {fxt.Test_del_comments("a b c" , "a b c");}
|
||||
@Test public void End_missing() {fxt.Test_del_comments("a<!-- b c" , "a<!-- b c");}
|
||||
@@ -37,26 +37,26 @@ public class Html_utl_tst {
|
||||
fxt.Test_unescape_html(Bool_.Y, Bool_.Y, Bool_.Y, Bool_.Y, Bool_.Y, "a<>'&"b" , "a<>'&\"b"); // basic
|
||||
}
|
||||
}
|
||||
class Html_atr_class_fxt {
|
||||
class Gfh_class_fxt {
|
||||
private Bry_bfr tmp_bfr = Bry_bfr.reset_(255);
|
||||
public void Clear() {
|
||||
tmp_bfr.Clear();
|
||||
}
|
||||
public void Test_del_comments(String src, String expd) {
|
||||
byte[] actl = Html_utl.Del_comments(tmp_bfr, Bry_.new_u8(src));
|
||||
byte[] actl = Gfh_utl.Del_comments(tmp_bfr, Bry_.new_u8(src));
|
||||
Tfds.Eq(expd, String_.new_a7(actl));
|
||||
}
|
||||
public void Test_escape_html(boolean lt, boolean gt, boolean amp, boolean quote, boolean apos, String src, String expd) {
|
||||
byte[] actl = Html_utl.Escape_html_as_bry(Bry_.new_a7(src), lt, gt, amp, quote, apos);
|
||||
byte[] actl = Gfh_utl.Escape_html_as_bry(Bry_.new_a7(src), lt, gt, amp, quote, apos);
|
||||
Tfds.Eq(expd, String_.new_a7(actl));
|
||||
}
|
||||
public void Test_escape_for_atr(String src, boolean quote_is_apos, String expd) {
|
||||
byte[] actl = Html_utl.Escape_for_atr_val_as_bry(tmp_bfr, quote_is_apos ? Byte_ascii.Apos : Byte_ascii.Quote, src);
|
||||
byte[] actl = Gfh_utl.Escape_for_atr_val_as_bry(tmp_bfr, quote_is_apos ? Byte_ascii.Apos : Byte_ascii.Quote, src);
|
||||
Tfds.Eq(expd, String_.new_u8(actl));
|
||||
}
|
||||
public void Test_unescape_html(boolean lt, boolean gt, boolean amp, boolean quote, boolean apos, String src, String expd) {
|
||||
byte[] bry = Bry_.new_u8(src);
|
||||
byte[] actl = Html_utl.Unescape(false, tmp_bfr, bry, 0, bry.length, lt, gt, amp, quote, apos);
|
||||
byte[] actl = Gfh_utl.Unescape(false, tmp_bfr, bry, 0, bry.length, lt, gt, amp, quote, apos);
|
||||
Tfds.Eq(expd, String_.new_a7(actl));
|
||||
}
|
||||
}
|
||||
@@ -16,11 +16,11 @@ 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.langs.htmls; import gplx.*; import gplx.langs.*;
|
||||
public class Html_wtr {
|
||||
public class Gfh_wtr {
|
||||
private Bry_bfr bfr = Bry_bfr.reset_(255);
|
||||
private List_adp nde_stack = List_adp_.new_();
|
||||
public byte Atr_quote() {return atr_quote;} public Html_wtr Atr_quote_(byte v) {atr_quote = v; return this;} private byte atr_quote = Byte_ascii.Quote;
|
||||
public Html_wtr Nde_full_atrs(byte[] tag, byte[] text, boolean text_escape, byte[]... atrs) {
|
||||
public byte Atr_quote() {return atr_quote;} public Gfh_wtr Atr_quote_(byte v) {atr_quote = v; return this;} private byte atr_quote = Byte_ascii.Quote;
|
||||
public Gfh_wtr Nde_full_atrs(byte[] tag, byte[] text, boolean text_escape, byte[]... atrs) {
|
||||
Nde_bgn(tag);
|
||||
int atrs_len = atrs.length;
|
||||
for (int i = 0; i < atrs_len; i += 2) {
|
||||
@@ -36,46 +36,46 @@ public class Html_wtr {
|
||||
Nde_end();
|
||||
return this;
|
||||
}
|
||||
public Html_wtr Nde_full(byte[] tag, byte[] text) {
|
||||
public Gfh_wtr Nde_full(byte[] tag, byte[] text) {
|
||||
Nde_bgn_hdr(tag);
|
||||
Txt(text);
|
||||
Nde_end();
|
||||
return this;
|
||||
}
|
||||
public Html_wtr Txt_mid(byte[] src, int bgn, int end) {bfr.Add_mid(src, bgn, end); return this;}
|
||||
public Html_wtr Txt_byte(byte v) {bfr.Add_byte(v); return this;}
|
||||
public Html_wtr Txt_raw(byte[] v) {bfr.Add(v); return this;}
|
||||
public Html_wtr Txt(byte[] v) {
|
||||
public Gfh_wtr Txt_mid(byte[] src, int bgn, int end) {bfr.Add_mid(src, bgn, end); return this;}
|
||||
public Gfh_wtr Txt_byte(byte v) {bfr.Add_byte(v); return this;}
|
||||
public Gfh_wtr Txt_raw(byte[] v) {bfr.Add(v); return this;}
|
||||
public Gfh_wtr Txt(byte[] v) {
|
||||
if (v != null) {
|
||||
bfr.Add(Html_utl.Escape_html_as_bry(v));
|
||||
bfr.Add(Gfh_utl.Escape_html_as_bry(v));
|
||||
}
|
||||
return this;
|
||||
}
|
||||
public Html_wtr Nde_bgn_hdr(byte[] name) {
|
||||
public Gfh_wtr Nde_bgn_hdr(byte[] name) {
|
||||
this.Nde_bgn(name);
|
||||
this.Nde_end_hdr();
|
||||
return this;
|
||||
}
|
||||
public Html_wtr Nde_bgn(byte[] name) {
|
||||
public Gfh_wtr Nde_bgn(byte[] name) {
|
||||
bfr.Add_byte(Byte_ascii.Lt);
|
||||
bfr.Add(name);
|
||||
nde_stack.Add(name);
|
||||
return this;
|
||||
}
|
||||
public Html_wtr Atr(byte[] key, byte[] val) {
|
||||
public Gfh_wtr Atr(byte[] key, byte[] val) {
|
||||
Write_atr_bry(bfr, Bool_.Y, atr_quote, key, val);
|
||||
return this;
|
||||
}
|
||||
public Html_wtr Nde_end_inline() {
|
||||
public Gfh_wtr Nde_end_inline() {
|
||||
bfr.Add_byte(Byte_ascii.Slash).Add_byte(Byte_ascii.Gt);
|
||||
List_adp_.Pop_last(nde_stack);
|
||||
return this;
|
||||
}
|
||||
public Html_wtr Nde_end_hdr() {
|
||||
public Gfh_wtr Nde_end_hdr() {
|
||||
bfr.Add_byte(Byte_ascii.Gt);
|
||||
return this;
|
||||
}
|
||||
public Html_wtr Nde_end() {
|
||||
public Gfh_wtr Nde_end() {
|
||||
byte[] name = (byte[])List_adp_.Pop_last(nde_stack);
|
||||
bfr.Add_byte(Byte_ascii.Lt).Add_byte(Byte_ascii.Slash);
|
||||
bfr.Add(name);
|
||||
@@ -92,7 +92,7 @@ public class Html_wtr {
|
||||
bfr.Add(key);
|
||||
bfr.Add_byte(Byte_ascii.Eq);
|
||||
bfr.Add_byte(atr_quote);
|
||||
Html_utl.Escape_html_to_bfr(bfr, val, 0, val.length, false, false, false, true, true);
|
||||
Gfh_utl.Escape_html_to_bfr(bfr, val, 0, val.length, false, false, false, true, true);
|
||||
bfr.Add_byte(atr_quote);
|
||||
}
|
||||
public static void Write_atr_int(Bry_bfr bfr, byte[] key, int val) {Write_atr_int(bfr, Bool_.Y, Byte_ascii.Quote, key, val);}
|
||||
@@ -15,8 +15,8 @@ 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.langs.htmls.parsers.clses; import gplx.*; import gplx.langs.*; import gplx.langs.htmls.*; import gplx.langs.htmls.parsers.*;
|
||||
public class Html_atr_class_ {
|
||||
package gplx.langs.htmls.clses; import gplx.*; import gplx.langs.*; import gplx.langs.htmls.*;
|
||||
public class Gfh_class_ {
|
||||
public static boolean Has(byte[] src, int src_bgn, int src_end, byte[] cls) {
|
||||
int cls_bgn = src_bgn;
|
||||
int pos = src_bgn;
|
||||
@@ -15,10 +15,10 @@ 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.langs.htmls.parsers.clses; import gplx.*; import gplx.langs.*; import gplx.langs.htmls.*; import gplx.langs.htmls.parsers.*;
|
||||
package gplx.langs.htmls.clses; import gplx.*; import gplx.langs.*; import gplx.langs.htmls.*;
|
||||
import org.junit.*;
|
||||
public class Html_atr_class__tst {
|
||||
private final Html_atr_class__fxt fxt = new Html_atr_class__fxt();
|
||||
public class Gfh_class__tst {
|
||||
private final Gfh_class__fxt fxt = new Gfh_class__fxt();
|
||||
@Test public void Has() {
|
||||
fxt.Test__has__y("a b c", "a", "b", "c");
|
||||
fxt.Test__has__n("a b c", "d");
|
||||
@@ -34,14 +34,14 @@ public class Html_atr_class__tst {
|
||||
fxt.Test__find_1st(hash, Byte_.Max_value_127, "xyz");
|
||||
}
|
||||
}
|
||||
class Html_atr_class__fxt {
|
||||
class Gfh_class__fxt {
|
||||
public void Test__has__y(String src, String... ary) {Test__has(Bool_.Y, src, ary);}
|
||||
public void Test__has__n(String src, String... ary) {Test__has(Bool_.N, src, ary);}
|
||||
public void Test__has(boolean expd, String src, String... ary) {
|
||||
byte[] src_bry = Bry_.new_u8(src);
|
||||
for (String itm : ary) {
|
||||
byte[] itm_bry = Bry_.new_u8(itm);
|
||||
Tfds.Eq_bool(expd, Html_atr_class_.Has(src_bry, 0, src_bry.length, itm_bry), itm);
|
||||
Tfds.Eq_bool(expd, Gfh_class_.Has(src_bry, 0, src_bry.length, itm_bry), itm);
|
||||
}
|
||||
}
|
||||
public Hash_adp_bry Make_hash(String... ary) {
|
||||
@@ -53,6 +53,6 @@ class Html_atr_class__fxt {
|
||||
}
|
||||
public void Test__find_1st(Hash_adp_bry hash, int expd, String src) {
|
||||
byte[] src_bry = Bry_.new_u8(src);
|
||||
Tfds.Eq_byte((byte)expd, Html_atr_class_.Find_1st(src_bry, 0, src_bry.length, hash), src);
|
||||
Tfds.Eq_byte((byte)expd, Gfh_class_.Find_1st(src_bry, 0, src_bry.length, hash), src);
|
||||
}
|
||||
}
|
||||
@@ -15,15 +15,16 @@ 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.langs.htmls.parsers.clses; import gplx.*; import gplx.langs.*; import gplx.langs.htmls.*; import gplx.langs.htmls.parsers.*;
|
||||
public class Html_atr_class_parser_ {
|
||||
public static void Parse(Html_tag tag, Html_atr_class_wkr wkr) {
|
||||
Html_atr atr = tag.Atrs__get_by_or_empty(Html_atr_.Bry__class);
|
||||
package gplx.langs.htmls.clses; import gplx.*; import gplx.langs.*; import gplx.langs.htmls.*;
|
||||
import gplx.langs.htmls.docs.*;
|
||||
public class Gfh_class_parser_ {
|
||||
public static void Parse(Gfh_tag tag, Gfh_class_parser_wkr wkr) {
|
||||
Gfh_atr atr = tag.Atrs__get_by_or_empty(Gfh_atr_.Bry__class);
|
||||
if (atr.Val_dat_exists())
|
||||
Parse(tag.Src(), atr.Val_bgn(), atr.Val_end(), wkr);
|
||||
}
|
||||
public static void Parse(byte[] src, int src_bgn, int src_end, Html_atr_class_wkr wkr) {
|
||||
int atr_idx = 0, atr_bgn = -1, atr_end = -1, tmp_bgn = -1, tmp_end = -1;
|
||||
public static void Parse(byte[] src, int src_bgn, int src_end, Gfh_class_parser_wkr wkr) {
|
||||
int atr_idx = 0, tmp_bgn = -1, tmp_end = -1;
|
||||
int pos = src_bgn;
|
||||
while (true) {
|
||||
boolean pos_is_last = pos == src_end;
|
||||
@@ -31,10 +32,10 @@ public class Html_atr_class_parser_ {
|
||||
switch (b) {
|
||||
case Byte_ascii.Tab: case Byte_ascii.Nl: case Byte_ascii.Cr: case Byte_ascii.Space:
|
||||
if (tmp_bgn != -1) { // ignore empty atrs
|
||||
if (!wkr.On_cls(src, atr_idx, atr_bgn, atr_end, tmp_bgn, tmp_end))
|
||||
if (!wkr.On_cls(src, atr_idx, src_bgn, src_end, tmp_bgn, tmp_end))
|
||||
pos_is_last = true;
|
||||
}
|
||||
++atr_idx; atr_bgn = -1; atr_end = -1; tmp_bgn = -1; tmp_end = -1;
|
||||
++atr_idx; tmp_bgn = -1; tmp_end = -1;
|
||||
break;
|
||||
default:
|
||||
if (tmp_bgn == -1) tmp_bgn = pos;
|
||||
@@ -15,22 +15,22 @@ 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.langs.htmls.parsers.clses; import gplx.*; import gplx.langs.*; import gplx.langs.htmls.*; import gplx.langs.htmls.parsers.*;
|
||||
package gplx.langs.htmls.clses; import gplx.*; import gplx.langs.*; import gplx.langs.htmls.*;
|
||||
import org.junit.*;
|
||||
public class Html_atr_class_parser__tst {
|
||||
private final Html_atr_class_parser__fxt fxt = new Html_atr_class_parser__fxt();
|
||||
public class Gfh_class_parser__tst {
|
||||
private final Gfh_class_parser__fxt fxt = new Gfh_class_parser__fxt();
|
||||
@Test public void Basic() {fxt.Test__parse("v1" , "v1");}
|
||||
@Test public void Many() {fxt.Test__parse("v1 v2" , "v1", "v2");}
|
||||
}
|
||||
class Html_atr_class_parser__fxt {
|
||||
private final Html_atr_class_wkr__list wkr = new Html_atr_class_wkr__list();
|
||||
class Gfh_class_parser__fxt {
|
||||
private final Gfh_class_wkr__list wkr = new Gfh_class_wkr__list();
|
||||
public void Test__parse(String src_str, String... expd) {
|
||||
byte[] src_bry = Bry_.new_u8(src_str);
|
||||
String[] actl = wkr.Parse(src_bry, 0, src_bry.length);
|
||||
Tfds.Eq_ary_str(expd, actl);
|
||||
}
|
||||
}
|
||||
class Html_atr_class_wkr__list implements Html_atr_class_wkr {
|
||||
class Gfh_class_wkr__list implements Gfh_class_parser_wkr {
|
||||
private final List_adp list = List_adp_.new_();
|
||||
public boolean On_cls(byte[] src, int atr_idx, int atr_bgn, int atr_end, int val_bgn, int val_end) {
|
||||
String s = String_.new_u8(src, val_bgn, val_end);
|
||||
@@ -38,7 +38,7 @@ class Html_atr_class_wkr__list implements Html_atr_class_wkr {
|
||||
return true;
|
||||
}
|
||||
public String[] Parse(byte[] src, int src_bgn, int src_end) {
|
||||
Html_atr_class_parser_.Parse(src, src_bgn, src_end, this);
|
||||
Gfh_class_parser_.Parse(src, src_bgn, src_end, this);
|
||||
return (String[])list.To_ary_and_clear(String.class);
|
||||
}
|
||||
}
|
||||
@@ -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.langs.htmls.parsers.clses; import gplx.*; import gplx.langs.*; import gplx.langs.htmls.*; import gplx.langs.htmls.parsers.*;
|
||||
public interface Html_atr_class_wkr {
|
||||
package gplx.langs.htmls.clses; import gplx.*; import gplx.langs.*; import gplx.langs.htmls.*;
|
||||
public interface Gfh_class_parser_wkr {
|
||||
boolean On_cls(byte[] src, int atr_idx, int atr_bgn, int atr_end, int val_bgn, int val_end);
|
||||
}
|
||||
@@ -15,14 +15,16 @@ 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.langs.htmls.parsers; import gplx.*; import gplx.langs.*; import gplx.langs.htmls.*;
|
||||
public class Html_atr extends gplx.core.brys.Bfr_arg_base {
|
||||
public Html_atr(int idx, byte[] key, byte[] val, byte[] src, int val_bgn, int val_end) {
|
||||
this.idx = idx; this.key = key; this.val = val;
|
||||
package gplx.langs.htmls.docs; import gplx.*; import gplx.langs.*; import gplx.langs.htmls.*;
|
||||
public class Gfh_atr implements gplx.core.brys.Bfr_arg {
|
||||
public Gfh_atr(int idx, int atr_bgn, int atr_end, byte[] key, byte[] val, byte[] src, int val_bgn, int val_end) {
|
||||
this.idx = idx; this.atr_bgn = atr_bgn; this.atr_end = atr_end; this.key = key; this.val = val;
|
||||
this.src = src; this.val_bgn = val_bgn; this.val_end = val_end;
|
||||
}
|
||||
public byte[] Src() {return src;} private final byte[] src;
|
||||
public int Idx() {return idx;} private final int idx;
|
||||
public int Atr_bgn() {return atr_bgn;} private final int atr_bgn;
|
||||
public int Atr_end() {return atr_end;} private final int atr_end;
|
||||
public byte[] Key() {return key;} private final byte[] key;
|
||||
public int Val_bgn() {return val_bgn;} private final int val_bgn;
|
||||
public int Val_end() {return val_end;} private final int val_end;
|
||||
@@ -37,10 +39,9 @@ public class Html_atr extends gplx.core.brys.Bfr_arg_base {
|
||||
if (val_end > val_bgn)
|
||||
bfr.Add_mid(src, val_bgn, val_end);
|
||||
}
|
||||
@Override public boolean Bfr_arg__exists() {return this.Val_dat_exists();}
|
||||
@Override public void Bfr_arg__add(Bry_bfr bfr) {
|
||||
public void Bfr_arg__add(Bry_bfr bfr) {
|
||||
if (Val_dat_exists())
|
||||
bfr.Add_mid(src, val_bgn, val_end);
|
||||
}
|
||||
public static final Html_atr Noop = new Html_atr(-1, Bry_.Empty, Bry_.Empty, Bry_.Empty, -1, -1);
|
||||
public static final Gfh_atr Noop = new Gfh_atr(-1, -1, -1, Bry_.Empty, Bry_.Empty, Bry_.Empty, -1, -1);
|
||||
}
|
||||
@@ -15,14 +15,14 @@ GNU Affero General Public License for more details.
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.langs.htmls.parsers; import gplx.*; import gplx.langs.*; import gplx.langs.htmls.*;
|
||||
package gplx.langs.htmls.docs; import gplx.*; import gplx.langs.*; import gplx.langs.htmls.*;
|
||||
import gplx.core.btries.*;
|
||||
public class Html_doc_parser {
|
||||
public class Gfh_doc_parser {
|
||||
private final Btrie_slim_mgr trie = Btrie_slim_mgr.cs();
|
||||
private final Html_txt_wkr txt_wkr;
|
||||
public Html_doc_parser(Html_txt_wkr txt_wkr, Html_doc_wkr... wkr_ary) {
|
||||
private final Gfh_txt_wkr txt_wkr;
|
||||
public Gfh_doc_parser(Gfh_txt_wkr txt_wkr, Gfh_doc_wkr... wkr_ary) {
|
||||
this.txt_wkr = txt_wkr;
|
||||
for (Html_doc_wkr wkr : wkr_ary)
|
||||
for (Gfh_doc_wkr wkr : wkr_ary)
|
||||
trie.Add_obj(wkr.Hook(), wkr);
|
||||
}
|
||||
public void Parse(byte[] page_url, byte[] src, int src_bgn, int src_end) {
|
||||
@@ -39,10 +39,10 @@ public class Html_doc_parser {
|
||||
txt_wkr.Parse(txt_bgn, pos);
|
||||
txt_bgn = -1;
|
||||
}
|
||||
Html_doc_wkr wkr = (Html_doc_wkr)o;
|
||||
Gfh_doc_wkr wkr = (Gfh_doc_wkr)o;
|
||||
try {pos = wkr.Parse(src, src_bgn, src_end, pos);}
|
||||
catch (Exception e) {
|
||||
Html_utl.Log(e, "html parse failed", page_url, src, pos);
|
||||
Gfh_utl.Log(e, "html parse failed", page_url, src, pos);
|
||||
txt_bgn = pos; // set txt_bgn to hook_bgn which is "pos"; i.e.: txt resumes from start of failed hook
|
||||
pos = trie.Match_pos(); // set pos to hook_end
|
||||
}
|
||||
@@ -15,8 +15,8 @@ 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.langs.htmls.parsers; import gplx.*; import gplx.langs.*; import gplx.langs.htmls.*;
|
||||
public interface Html_doc_wkr {
|
||||
package gplx.langs.htmls.docs; import gplx.*; import gplx.langs.*; import gplx.langs.htmls.*;
|
||||
public interface Gfh_doc_wkr {
|
||||
byte[] Hook();
|
||||
int Parse(byte[] src, int src_bgn, int src_end, int pos);
|
||||
}
|
||||
@@ -15,67 +15,79 @@ 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.langs.htmls.parsers; import gplx.*; import gplx.langs.*; import gplx.langs.htmls.*;
|
||||
import gplx.xowa.parsers.htmls.*; import gplx.langs.htmls.parsers.styles.*; import gplx.langs.htmls.parsers.clses.*;
|
||||
public class Html_tag implements Mwh_atr_wkr {
|
||||
private Html_tag_rdr tag_rdr;
|
||||
package gplx.langs.htmls.docs; import gplx.*; import gplx.langs.*; import gplx.langs.htmls.*;
|
||||
import gplx.xowa.parsers.htmls.*; import gplx.langs.htmls.styles.*; import gplx.langs.htmls.clses.*;
|
||||
public class Gfh_tag implements Mwh_atr_wkr {
|
||||
private Gfh_tag_rdr tag_rdr;
|
||||
private Ordered_hash atrs_hash; private boolean atrs_null; private int atrs_bgn, atrs_end;
|
||||
public Html_tag Init(Html_tag_rdr tag_rdr, byte[] src, boolean tag_is_tail, boolean tag_is_inline, int src_bgn, int src_end, int atrs_bgn, int atrs_end, int name_id) {
|
||||
public Gfh_tag Init(Gfh_tag_rdr tag_rdr, byte[] src, boolean tag_is_tail, boolean tag_is_inline, int src_bgn, int src_end, int atrs_bgn, int atrs_end, int name_id, byte[] name_bry) {
|
||||
this.tag_rdr = tag_rdr; this.src = src; this.atrs_null = true;
|
||||
this.tag_is_tail = tag_is_tail; this.tag_is_inline = tag_is_inline;
|
||||
this.atrs_bgn = atrs_bgn; this.atrs_end = atrs_end;
|
||||
this.name_id = name_id; this.src_bgn = src_bgn; this.src_end = src_end;
|
||||
this.name_id = name_id; this.name_bry = name_bry; this.src_bgn = src_bgn; this.src_end = src_end;
|
||||
return this;
|
||||
}
|
||||
public Html_tag Copy() {
|
||||
Html_tag rv = new Html_tag().Init(tag_rdr, src, tag_is_tail, tag_is_inline, src_bgn, src_end, atrs_bgn, atrs_end, name_id);
|
||||
public Gfh_tag Copy() {
|
||||
Gfh_tag rv = new Gfh_tag().Init(tag_rdr, src, tag_is_tail, tag_is_inline, src_bgn, src_end, atrs_bgn, atrs_end, name_id, name_bry);
|
||||
rv.atrs_null = false;
|
||||
rv.atrs_hash = Copy(atrs_hash);
|
||||
return rv;
|
||||
}
|
||||
public int Name_id() {return name_id;} private int name_id;
|
||||
public Html_tag Chk_id(int chk) {
|
||||
if ( chk == name_id
|
||||
|| (name_id != Html_tag_.Id__eos && Int_.In(chk, Html_tag_.Id__any, Html_tag_.Id__comment))) {
|
||||
}
|
||||
else
|
||||
tag_rdr.Err_wkr().Fail("name_id chk failed", "expecting", Html_tag_.To_str(chk));
|
||||
public byte[] Name_bry() {return name_bry;} private byte[] name_bry;
|
||||
public Gfh_tag Chk_name_or_fail(int chk) {
|
||||
if (!Chk_name(chk)) tag_rdr.Err_wkr().Fail("name_id chk failed", "expecting", Gfh_tag_.To_str(chk));
|
||||
return this;
|
||||
}
|
||||
public boolean Chk_name(int chk) {
|
||||
return ( chk == name_id
|
||||
|| (name_id != Gfh_tag_.Id__eos && Int_.In(chk, Gfh_tag_.Id__any, Gfh_tag_.Id__comment)));
|
||||
}
|
||||
public boolean Chk(int chk_name, byte[] chk_cls) {return name_id == chk_name && Atrs__cls_has(chk_cls);}
|
||||
public byte[] Src() {return src;} private byte[] src;
|
||||
public int Src_bgn() {return src_bgn;} private int src_bgn;
|
||||
public int Src_end() {return src_end;} private int src_end;
|
||||
public boolean Src_exists() {return src_end > src_bgn;} // NOTE: only true if EOS where src_end == src_bgn == src_len
|
||||
public boolean Tag_is_tail() {return tag_is_tail;} private boolean tag_is_tail;
|
||||
public boolean Tag_is_inline() {return tag_is_inline;} private boolean tag_is_inline;
|
||||
public Ordered_hash Atrs__hash() {if (atrs_null) Atrs__make(); return atrs_hash;}
|
||||
public int Atrs__len() {if (atrs_null) Atrs__make(); return atrs_hash.Count();}
|
||||
public boolean Atrs__match_pair(byte[] key, byte[] val) {
|
||||
if (atrs_null) Atrs__make();
|
||||
Html_atr rv = (Html_atr)atrs_hash.Get_by(key);
|
||||
Gfh_atr rv = (Gfh_atr)atrs_hash.Get_by(key);
|
||||
return rv == null ? false : Bry_.Eq(val, rv.Val());
|
||||
}
|
||||
public boolean Atrs__cls_has(byte[] val) {
|
||||
if (atrs_null) Atrs__make();
|
||||
Html_atr rv = (Html_atr)atrs_hash.Get_by(Html_atr_.Bry__class); if (rv == null) return false;
|
||||
Gfh_atr rv = (Gfh_atr)atrs_hash.Get_by(Gfh_atr_.Bry__class); if (rv == null) return false;
|
||||
byte[] rv_val = rv.Val();
|
||||
return Html_atr_class_.Has(rv_val, 0, rv_val.length, val);
|
||||
return Gfh_class_.Has(rv_val, 0, rv_val.length, val);
|
||||
}
|
||||
public boolean Atrs__cls_eq(byte[] val) {
|
||||
if (atrs_null) Atrs__make();
|
||||
Gfh_atr rv = (Gfh_atr)atrs_hash.Get_by(Gfh_atr_.Bry__class); if (rv == null) return false;
|
||||
return Bry_.Eq(val, rv.Val());
|
||||
}
|
||||
public byte Atrs__cls_find_or_fail(Hash_adp_bry hash) {
|
||||
if (atrs_null) Atrs__make();
|
||||
Html_atr cls_atr = (Html_atr)atrs_hash.Get_by(Html_atr_.Bry__class); if (cls_atr == null) tag_rdr.Err_wkr().Fail("cls missing");
|
||||
byte rv = Html_atr_class_.Find_1st(src, cls_atr.Val_bgn(), cls_atr.Val_end(), hash); if (rv == Byte_.Max_value_127) tag_rdr.Err_wkr().Fail("cls val missing");
|
||||
byte rv = Atrs__cls_find_or(hash, Byte_.Max_value_127); if (rv == Byte_.Max_value_127) tag_rdr.Err_wkr().Fail("cls missing");
|
||||
return rv;
|
||||
}
|
||||
private static final Html_atr_style_wkr__get_val_as_int style_wkr = new Html_atr_style_wkr__get_val_as_int();
|
||||
public byte Atrs__cls_find_or(Hash_adp_bry hash, byte or) {
|
||||
if (atrs_null) Atrs__make();
|
||||
Gfh_atr cls_atr = (Gfh_atr)atrs_hash.Get_by(Gfh_atr_.Bry__class); if (cls_atr == null) return or;
|
||||
byte rv = Gfh_class_.Find_1st(src, cls_atr.Val_bgn(), cls_atr.Val_end(), hash); if (rv == Byte_.Max_value_127) return or;
|
||||
return rv;
|
||||
}
|
||||
private static final Gfh_style_wkr__val_as_int style_wkr = new Gfh_style_wkr__val_as_int();
|
||||
public int Atrs__style_get_as_int(byte[] key) {
|
||||
if (atrs_null) Atrs__make();
|
||||
Html_atr rv = (Html_atr)atrs_hash.Get_by(Html_atr_.Bry__style); if (rv == null) return -1;
|
||||
Gfh_atr rv = (Gfh_atr)atrs_hash.Get_by(Gfh_atr_.Bry__style); if (rv == null) return -1;
|
||||
byte[] rv_val = rv.Val();
|
||||
return style_wkr.Parse(rv_val, 0, rv_val.length, key);
|
||||
}
|
||||
public byte[] Atrs__get_as_bry(byte[] key) {
|
||||
if (atrs_null) Atrs__make();
|
||||
Html_atr rv = (Html_atr)atrs_hash.Get_by(key);
|
||||
Gfh_atr rv = (Gfh_atr)atrs_hash.Get_by(key);
|
||||
return rv == null ? Bry_.Empty : rv.Val();
|
||||
}
|
||||
public int Atrs__get_as_int(byte[] key) {
|
||||
@@ -84,18 +96,18 @@ public class Html_tag implements Mwh_atr_wkr {
|
||||
}
|
||||
public int Atrs__get_as_int_or(byte[] key, int or) {
|
||||
if (atrs_null) Atrs__make();
|
||||
Html_atr rv = (Html_atr)atrs_hash.Get_by(key); if (rv == null) return or;
|
||||
Gfh_atr rv = (Gfh_atr)atrs_hash.Get_by(key); if (rv == null) return or;
|
||||
return Bry_.To_int_or(src, rv.Val_bgn(), rv.Val_end(), or);
|
||||
}
|
||||
public Html_atr Atrs__get_at(int i) {return (Html_atr)atrs_hash.Get_at(i);}
|
||||
public Html_atr Atrs__get_by_or_fail(byte[] key) {return Atrs__get_by_or_fail(key, Bool_.Y);}
|
||||
public Html_atr Atrs__get_by_or_empty(byte[] key) {return Atrs__get_by_or_fail(key, Bool_.N);}
|
||||
public Html_atr Atrs__get_by_or_fail(byte[] key, boolean fail_if_null) {
|
||||
public Gfh_atr Atrs__get_at(int i) {return (Gfh_atr)atrs_hash.Get_at(i);}
|
||||
public Gfh_atr Atrs__get_by_or_fail(byte[] key) {return Atrs__get_by_or_fail(key, Bool_.Y);}
|
||||
public Gfh_atr Atrs__get_by_or_empty(byte[] key) {return Atrs__get_by_or_fail(key, Bool_.N);}
|
||||
public Gfh_atr Atrs__get_by_or_fail(byte[] key, boolean fail_if_null) {
|
||||
if (atrs_null) Atrs__make();
|
||||
Html_atr rv = (Html_atr)atrs_hash.Get_by(key);
|
||||
Gfh_atr rv = (Gfh_atr)atrs_hash.Get_by(key);
|
||||
if (rv == null) {
|
||||
if (fail_if_null) tag_rdr.Err_wkr().Fail("atr missing", "key", key);
|
||||
else return Html_atr.Noop;
|
||||
else return Gfh_atr.Noop;
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
@@ -104,7 +116,7 @@ public class Html_tag implements Mwh_atr_wkr {
|
||||
Bry_bfr bfr = Bry_bfr.new_();
|
||||
int len = atrs_hash.Count();
|
||||
for (int i = 0; i < len; ++i) {
|
||||
Html_atr atr = (Html_atr)atrs_hash.Get_at(i);
|
||||
Gfh_atr atr = (Gfh_atr)atrs_hash.Get_at(i);
|
||||
bfr.Add(atr.Key()).Add_byte_eq().Add(atr.Val()).Add_byte_nl();
|
||||
}
|
||||
return bfr.To_str();
|
||||
@@ -119,20 +131,22 @@ public class Html_tag implements Mwh_atr_wkr {
|
||||
if (!valid) return;
|
||||
byte[] val_bry = val_bry_manual;
|
||||
int val_bgn = -1, val_end = -1;
|
||||
int atr_bgn = itm_ary[itm_idx + Mwh_atr_mgr.Idx_atr_bgn];
|
||||
int atr_end = itm_ary[itm_idx + Mwh_atr_mgr.Idx_atr_end];
|
||||
if (key_exists) {
|
||||
val_bgn = itm_ary[itm_idx + Mwh_atr_mgr.Idx_val_bgn];
|
||||
val_end = itm_ary[itm_idx + Mwh_atr_mgr.Idx_val_end];
|
||||
}
|
||||
else
|
||||
val_bry = key_bry;
|
||||
Html_atr atr = new Html_atr(atrs_hash.Count(), key_bry, val_bry, src, val_bgn, val_end);
|
||||
Gfh_atr atr = new Gfh_atr(atrs_hash.Count(), atr_bgn, atr_end, key_bry, val_bry, src, val_bgn, val_end);
|
||||
atrs_hash.Add(key_bry, atr);
|
||||
}
|
||||
private static Ordered_hash Copy(Ordered_hash src) {
|
||||
Ordered_hash rv = Ordered_hash_.New();
|
||||
int len = src.Count();
|
||||
for (int i = 0; i < len; ++i) {
|
||||
Html_atr atr = (Html_atr)src.Get_at(i);
|
||||
Gfh_atr atr = (Gfh_atr)src.Get_at(i);
|
||||
rv.Add(atr.Key(), atr);
|
||||
}
|
||||
return rv;
|
||||
@@ -15,35 +15,35 @@ 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.langs.htmls.parsers; import gplx.*; import gplx.langs.*; import gplx.langs.htmls.*;
|
||||
package gplx.langs.htmls.docs; import gplx.*; import gplx.langs.*; import gplx.langs.htmls.*;
|
||||
import gplx.core.primitives.*; import gplx.core.brys.*; import gplx.core.btries.*;
|
||||
import gplx.xowa.parsers.htmls.*;
|
||||
public class Html_tag_rdr {
|
||||
private final Hash_adp_bry name_hash = Html_tag_.Hash;
|
||||
public class Gfh_tag_rdr {
|
||||
private final Hash_adp_bry name_hash = Gfh_tag_.Hash;
|
||||
private final Mwh_atr_parser atr_parser = new Mwh_atr_parser();
|
||||
private final Html_tag tag__tmp__move = new Html_tag(), tag__tmp__peek = new Html_tag(), tag__eos = new Html_tag(), tag__comment = new Html_tag();
|
||||
private final Gfh_tag tag__tmp__move = new Gfh_tag(), tag__tmp__peek = new Gfh_tag(), tag__eos = new Gfh_tag(), tag__comment = new Gfh_tag();
|
||||
private final Int_obj_ref tmp_depth = Int_obj_ref.zero_();
|
||||
public byte[] Src() {return src;} private byte[] src;
|
||||
public int Src_end() {return src_end;} private int src_end;
|
||||
public Bry_err_wkr Err_wkr() {return err_wkr;} private final Bry_err_wkr err_wkr = new Bry_err_wkr();
|
||||
public void Init(byte[] ctx, byte[] src, int src_bgn, int src_end) {
|
||||
this.src = src; this.pos = src_bgn; this.src_end = src_end;
|
||||
tag__eos.Init(this, src, Bool_.N, Bool_.N, src_end, src_end, src_end, src_end, Html_tag_.Id__eos);
|
||||
tag__eos.Init(this, src, Bool_.N, Bool_.N, src_end, src_end, src_end, src_end, Gfh_tag_.Id__eos, Bry_.Empty);
|
||||
err_wkr.Init_by_page(String_.new_u8(ctx), src);
|
||||
}
|
||||
public int Pos() {return pos;} private int pos;
|
||||
public void Pos_(int v) {this.pos = v;}
|
||||
public void Atrs__make(Mwh_atr_wkr atr_wkr, int head_bgn, int head_end) {atr_parser.Parse(atr_wkr, -1, -1, src, head_bgn, head_end);}
|
||||
public Html_tag Tag__move_fwd_head() {return Tag__find(Bool_.Y, Bool_.N, Bool_.N, pos, src_end, Html_tag_.Id__any);}
|
||||
public Html_tag Tag__move_fwd_head(int match_name_id) {return Tag__find(Bool_.Y, Bool_.N, Bool_.N, pos, src_end, match_name_id);}
|
||||
public Html_tag Tag__move_fwd_tail(int match_name_id) {return Tag__find(Bool_.Y, Bool_.N, Bool_.Y, pos, src_end, match_name_id);}
|
||||
public Html_tag Tag__peek_fwd_head() {return Tag__find(Bool_.N, Bool_.N, Bool_.N, pos, src_end, Html_tag_.Id__any);}
|
||||
public Html_tag Tag__peek_fwd_head(int match_name_id) {return Tag__find(Bool_.N, Bool_.N, Bool_.N, pos, src_end, match_name_id);}
|
||||
public Html_tag Tag__peek_fwd_tail(int match_name_id) {return Tag__find(Bool_.N, Bool_.N, Bool_.Y, pos, src_end, match_name_id);}
|
||||
public Html_tag Tag__peek_bwd_tail(int match_name_id) {return Tag__find(Bool_.N, Bool_.Y, Bool_.Y, pos, src_end, match_name_id);}
|
||||
public Html_tag Tag__peek_bwd_head() {return Tag__find(Bool_.N, Bool_.Y, Bool_.Y, pos, src_end, Html_tag_.Id__any);}
|
||||
public Html_tag Tag__find_fwd_head(int bgn, int end, int match_name_id) {return Tag__find(Bool_.N, Bool_.N, Bool_.N, bgn, end, match_name_id);}
|
||||
private Html_tag Tag__find(boolean move, boolean bwd, boolean tail, int rng_bgn, int rng_end, int match_name_id) {
|
||||
public Gfh_tag Tag__move_fwd_head() {return Tag__find(Bool_.Y, Bool_.N, Bool_.N, pos, src_end, Gfh_tag_.Id__any);}
|
||||
public Gfh_tag Tag__move_fwd_head(int match_name_id) {return Tag__find(Bool_.Y, Bool_.N, Bool_.N, pos, src_end, match_name_id);}
|
||||
public Gfh_tag Tag__move_fwd_tail(int match_name_id) {return Tag__find(Bool_.Y, Bool_.N, Bool_.Y, pos, src_end, match_name_id);}
|
||||
public Gfh_tag Tag__peek_fwd_head() {return Tag__find(Bool_.N, Bool_.N, Bool_.N, pos, src_end, Gfh_tag_.Id__any);}
|
||||
public Gfh_tag Tag__peek_fwd_head(int match_name_id) {return Tag__find(Bool_.N, Bool_.N, Bool_.N, pos, src_end, match_name_id);}
|
||||
public Gfh_tag Tag__peek_fwd_tail(int match_name_id) {return Tag__find(Bool_.N, Bool_.N, Bool_.Y, pos, src_end, match_name_id);}
|
||||
public Gfh_tag Tag__peek_bwd_tail(int match_name_id) {return Tag__find(Bool_.N, Bool_.Y, Bool_.Y, pos, src_end, match_name_id);}
|
||||
public Gfh_tag Tag__peek_bwd_head() {return Tag__find(Bool_.N, Bool_.Y, Bool_.Y, pos, src_end, Gfh_tag_.Id__any);}
|
||||
public Gfh_tag Tag__find_fwd_head(int bgn, int end, int match_name_id) {return Tag__find(Bool_.N, Bool_.N, Bool_.N, bgn, end, match_name_id);}
|
||||
private Gfh_tag Tag__find(boolean move, boolean bwd, boolean tail, int rng_bgn, int rng_end, int match_name_id) {
|
||||
int tmp = rng_bgn;
|
||||
int stop_pos = rng_end; int adj = 1;
|
||||
if (bwd) {
|
||||
@@ -52,7 +52,7 @@ public class Html_tag_rdr {
|
||||
--tmp; // subtract 1 from tmp; needed when pos is at src_len, else array error below
|
||||
}
|
||||
tmp_depth.Val_zero_();
|
||||
Html_tag rv = null;
|
||||
Gfh_tag rv = null;
|
||||
while (tmp != stop_pos) {
|
||||
if (src[tmp] == Byte_ascii.Angle_bgn) {
|
||||
rv = Tag__extract(move, tail, match_name_id, tmp);
|
||||
@@ -68,20 +68,20 @@ public class Html_tag_rdr {
|
||||
}
|
||||
if (rv == null) {
|
||||
if (move && tail && !bwd)
|
||||
err_wkr.Fail("move failed", "tag_name", Html_tag_.To_str(match_name_id));
|
||||
err_wkr.Fail("move failed", "tag_name", Gfh_tag_.To_str(match_name_id));
|
||||
else
|
||||
return Tag__eos(rng_bgn);
|
||||
}
|
||||
if (move) pos = rv.Src_end();
|
||||
return rv;
|
||||
}
|
||||
private boolean Tag__match(boolean move, boolean bwd, boolean tail, int match_name_id, Int_obj_ref depth_obj, Html_tag tag) {
|
||||
private boolean Tag__match(boolean move, boolean bwd, boolean tail, int match_name_id, Int_obj_ref depth_obj, Gfh_tag tag) {
|
||||
int tag_name_id = tag.Name_id();
|
||||
if ( tag_name_id != match_name_id // tag doesn't match requested
|
||||
&& match_name_id != Html_tag_.Id__any // requested is not wildcard
|
||||
&& match_name_id != Gfh_tag_.Id__any // requested is not wildcard
|
||||
) return false;
|
||||
if (tag_name_id == Html_tag_.Id__comment) {
|
||||
if (match_name_id == Html_tag_.Id__comment)
|
||||
if (tag_name_id == Gfh_tag_.Id__comment) {
|
||||
if (match_name_id == Gfh_tag_.Id__comment)
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
@@ -108,7 +108,7 @@ public class Html_tag_rdr {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
public Html_tag Tag__extract(boolean move, boolean tail, int match_name_id, int tag_bgn) {
|
||||
public Gfh_tag Tag__extract(boolean move, boolean tail, int match_name_id, int tag_bgn) {
|
||||
int name_bgn = tag_bgn + 1; if (name_bgn == src_end) return Tag__eos(tag_bgn); // EX: "<EOS"
|
||||
byte name_0 = src[name_bgn];
|
||||
boolean cur_is_tail = false;
|
||||
@@ -166,8 +166,8 @@ public class Html_tag_rdr {
|
||||
atrs_end = tag_end;
|
||||
++tag_end; // position after ">"
|
||||
}
|
||||
Html_tag tmp = move ? tag__tmp__move : tag__tmp__peek;
|
||||
return tmp.Init(this, src, cur_is_tail, inline, tag_bgn, tag_end, name_end, atrs_end, name_hash.Get_as_int_or(src, name_bgn, name_end, -1));
|
||||
Gfh_tag tmp = move ? tag__tmp__move : tag__tmp__peek;
|
||||
return tmp.Init(this, src, cur_is_tail, inline, tag_bgn, tag_end, name_end, atrs_end, name_hash.Get_as_int_or(src, name_bgn, name_end, -1), Bry_.Mid(src, name_bgn, name_end));
|
||||
}
|
||||
public boolean Read_and_move(byte match) {
|
||||
byte b = src[pos];
|
||||
@@ -211,13 +211,13 @@ public class Html_tag_rdr {
|
||||
}
|
||||
return bgn == pos ? or_int : rv * negative;
|
||||
}
|
||||
private Html_tag Tag__comment(int tag_bgn) {
|
||||
int tag_end = Bry_find_.Move_fwd(src, gplx.langs.htmls.Html_tag_.Comm_end, tag_bgn, src_end); if (tag_end == Bry_find_.Not_found) tag_end = src_end;
|
||||
return tag__comment.Init(this, src, Bool_.N, Bool_.N, tag_bgn, tag_end, tag_end, tag_end, Html_tag_.Id__comment);
|
||||
private Gfh_tag Tag__comment(int tag_bgn) {
|
||||
int tag_end = Bry_find_.Move_fwd(src, gplx.langs.htmls.Gfh_tag_.Comm_end, tag_bgn, src_end); if (tag_end == Bry_find_.Not_found) tag_end = src_end;
|
||||
return tag__comment.Init(this, src, Bool_.N, Bool_.N, tag_bgn, tag_end, tag_end, tag_end, Gfh_tag_.Id__comment, Bry_.Empty);
|
||||
}
|
||||
private Html_tag Tag__eos(int tag_bgn) {
|
||||
private Gfh_tag Tag__eos(int tag_bgn) {
|
||||
int tag_end = tag_bgn + 255; if (tag_end > src_end) tag_end = src_end;
|
||||
return tag__comment.Init(this, src, Bool_.N, Bool_.N, tag_bgn, tag_end, tag_end, tag_end, Html_tag_.Id__eos);
|
||||
return tag__comment.Init(this, src, Bool_.N, Bool_.N, tag_bgn, tag_end, tag_end, tag_end, Gfh_tag_.Id__eos, Bry_.Empty);
|
||||
}
|
||||
private static final byte[] Bry__comment__mid = Bry_.new_a7("--");
|
||||
}
|
||||
@@ -15,10 +15,10 @@ 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.langs.htmls.parsers; import gplx.*; import gplx.langs.*; import gplx.langs.htmls.*;
|
||||
package gplx.langs.htmls.docs; import gplx.*; import gplx.langs.*; import gplx.langs.htmls.*;
|
||||
import org.junit.*;
|
||||
public class Html_tag_rdr_tst {
|
||||
private final Html_tag_rdr_fxt fxt = new Html_tag_rdr_fxt();
|
||||
public class Gfh_tag_rdr_tst {
|
||||
private final Gfh_tag_rdr_fxt fxt = new Gfh_tag_rdr_fxt();
|
||||
@Test public void Basic() {
|
||||
fxt.Init("1<div id='1'>2</div>3<div id='2'>4</div>5<div id='3'>6</div>7");
|
||||
fxt.Test__move_fwd_head("<div id='1'>"); fxt.Test__pos("2");
|
||||
@@ -28,46 +28,46 @@ public class Html_tag_rdr_tst {
|
||||
}
|
||||
@Test public void Comment() {
|
||||
fxt.Init("1<!--2-->3<!--4-->5<div id='1'>6</div>");
|
||||
fxt.Test__move_fwd_head(Html_tag_.Id__comment , "<!--2-->") ; fxt.Test__pos("3");
|
||||
fxt.Test__move_fwd_head(Html_tag_.Id__any , "<div id='1'>") ; fxt.Test__pos("6");
|
||||
fxt.Test__move_fwd_head(Gfh_tag_.Id__comment , "<!--2-->") ; fxt.Test__pos("3");
|
||||
fxt.Test__move_fwd_head(Gfh_tag_.Id__any , "<div id='1'>") ; fxt.Test__pos("6");
|
||||
}
|
||||
@Test public void Meta() {
|
||||
fxt.Init("<!DOCTYPE html>1<div id='1'>2</div>3");
|
||||
fxt.Test__move_fwd_head(Html_tag_.Id__div , "<div id='1'>") ; fxt.Test__pos("2");
|
||||
fxt.Test__move_fwd_head(Gfh_tag_.Id__div , "<div id='1'>") ; fxt.Test__pos("2");
|
||||
}
|
||||
@Test public void Recursive__same_tags() {
|
||||
fxt.Init("1<a>2<a>3</a>4</a>5");
|
||||
fxt.Test__move_fwd_head(Html_tag_.Id__a , "<a>") ; fxt.Test__pos("2");
|
||||
fxt.Test__move_fwd_tail(Html_tag_.Id__a , "</a>") ; fxt.Test__pos("5");
|
||||
fxt.Test__move_fwd_head(Gfh_tag_.Id__a , "<a>") ; fxt.Test__pos("2");
|
||||
fxt.Test__move_fwd_tail(Gfh_tag_.Id__a , "</a>") ; fxt.Test__pos("5");
|
||||
}
|
||||
@Test public void Recursive__diff_tags() {
|
||||
fxt.Init("1<div>2<a>3<img/>4</a>5</div>6");
|
||||
fxt.Test__move_fwd_head(Html_tag_.Id__div , "<div>") ; fxt.Test__pos("2");
|
||||
fxt.Test__move_fwd_tail(Html_tag_.Id__div , "</div>") ; fxt.Test__pos("6");
|
||||
fxt.Test__move_fwd_head(Gfh_tag_.Id__div , "<div>") ; fxt.Test__pos("2");
|
||||
fxt.Test__move_fwd_tail(Gfh_tag_.Id__div , "</div>") ; fxt.Test__pos("6");
|
||||
}
|
||||
}
|
||||
class Html_tag_rdr_fxt {
|
||||
private final Html_tag_rdr rdr = new Html_tag_rdr();
|
||||
class Gfh_tag_rdr_fxt {
|
||||
private final Gfh_tag_rdr rdr = new Gfh_tag_rdr();
|
||||
public void Init(String src_str) {
|
||||
byte[] src_bry = Bry_.new_u8(src_str);
|
||||
rdr.Init(Bry_.Empty, src_bry, 0, src_bry.length);
|
||||
}
|
||||
public void Test__move_fwd_head(String expd) {Test__move_fwd_head(Html_tag_.Id__any, expd);}
|
||||
public void Test__move_fwd_head(String expd) {Test__move_fwd_head(Gfh_tag_.Id__any, expd);}
|
||||
public void Test__move_fwd_head(int match_name_id, String expd) {
|
||||
Html_tag actl_tag = rdr.Tag__move_fwd_head(match_name_id).Chk_id(match_name_id);
|
||||
Gfh_tag actl_tag = rdr.Tag__move_fwd_head(match_name_id).Chk_name_or_fail(match_name_id);
|
||||
Tfds.Eq_str(expd, String_.new_u8(rdr.Src(), actl_tag.Src_bgn(), actl_tag.Src_end()));
|
||||
}
|
||||
public void Test__move_fwd_tail(int match_name_id, String expd) {
|
||||
Html_tag actl_tag = rdr.Tag__move_fwd_tail(match_name_id);
|
||||
Gfh_tag actl_tag = rdr.Tag__move_fwd_tail(match_name_id);
|
||||
Tfds.Eq_str(expd, String_.new_u8(rdr.Src(), actl_tag.Src_bgn(), actl_tag.Src_end()));
|
||||
}
|
||||
public void Test__peek_fwd_head(String expd) {
|
||||
Html_tag actl_tag = rdr.Tag__peek_fwd_head();
|
||||
Gfh_tag actl_tag = rdr.Tag__peek_fwd_head();
|
||||
Tfds.Eq_str(expd, String_.new_u8(rdr.Src(), actl_tag.Src_bgn(), actl_tag.Src_end()));
|
||||
}
|
||||
public void Test__peek_bwd_tail(String expd_str) {
|
||||
byte[] expd_bry = Bry_.new_u8(expd_str);
|
||||
Html_tag actl_tag = rdr.Tag__peek_bwd_tail(-1);
|
||||
Gfh_tag actl_tag = rdr.Tag__peek_bwd_tail(-1);
|
||||
Tfds.Eq_bry(expd_bry, Bry_.Mid(rdr.Src(), actl_tag.Src_bgn(), actl_tag.Src_bgn() + expd_bry.length));
|
||||
}
|
||||
public void Test__pos(String expd_str) {
|
||||
@@ -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.langs.htmls.parsers; import gplx.*; import gplx.langs.*; import gplx.langs.htmls.*;
|
||||
public interface Html_txt_wkr {
|
||||
package gplx.langs.htmls.docs; import gplx.*; import gplx.langs.*; import gplx.langs.htmls.*;
|
||||
public interface Gfh_txt_wkr {
|
||||
void Parse(int rng_bgn, int rng_end);
|
||||
}
|
||||
@@ -1,38 +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/>.
|
||||
*/
|
||||
//namespace gplx.langs.htmls.parsers {
|
||||
// public class Html_doc_log {
|
||||
// private byte[] src; private byte[] page_url; private String wkr_name; private int src_bgn; private int src_end;
|
||||
// public Html_doc_log Init_by_page(byte[] src, byte[] page_url) {
|
||||
// this.src = src; this.page_url = page_url;
|
||||
// return this;
|
||||
// }
|
||||
// public Html_doc_log Init_by_wkr(String wkr_name, int src_bgn, int src_end) {
|
||||
// this.wkr_name = wkr_name; this.src_bgn = src_bgn; this.src_end = src_end;
|
||||
// return this;
|
||||
// }
|
||||
// public Err Fail_w_args(String fail_msg, params Object[] custom_args) {return Fail_w_excerpt(fail_msg, src_bgn, src_end + 255, custom_args);}
|
||||
// public Err Fail_w_excerpt(String fail_msg, int excerpt_bgn, int excerpt_end, params Object[] custom_args) {
|
||||
// Object[] dflt_args = Object_.Ary("page", page_url, "wkr", wkr_name, "excerpt", Bry_.Mid_safe(src, excerpt_bgn, excerpt_end));
|
||||
// Object[] fail_args = Object_.Ary_add(custom_args, dflt_args);
|
||||
// String msg = Err_msg.To_str(fail_msg, fail_args);
|
||||
// Gfo_usr_dlg_.Instance.Warn_many("", "", msg);
|
||||
// return Err_.new_("Xoh_hdoc_err", msg);
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
25
400_xowa/src/gplx/langs/htmls/styles/Gfh_style_itm.java
Normal file
25
400_xowa/src/gplx/langs/htmls/styles/Gfh_style_itm.java
Normal file
@@ -0,0 +1,25 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.langs.htmls.styles; import gplx.*; import gplx.langs.*; import gplx.langs.htmls.*;
|
||||
public class Gfh_style_itm implements To_str_able {
|
||||
public Gfh_style_itm(int idx, byte[] key, byte[] val) {this.idx = idx; this.key = key; this.val = val;}
|
||||
public int Idx() {return idx;} private final int idx;
|
||||
public byte[] Key() {return key;} private final byte[] key;
|
||||
public byte[] Val() {return val;} private final byte[] val;
|
||||
public String To_str() {return String_.new_u8(Bry_.Add(key, Byte_ascii.Colon_bry, val, Byte_ascii.Semic_bry));}
|
||||
}
|
||||
@@ -15,9 +15,10 @@ 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.langs.htmls.parsers.styles; import gplx.*; import gplx.langs.*; import gplx.langs.htmls.*; import gplx.langs.htmls.parsers.*;
|
||||
public class Html_atr_style_ {
|
||||
package gplx.langs.htmls.styles; import gplx.*; import gplx.langs.*; import gplx.langs.htmls.*;
|
||||
public class Gfh_style_key_ {
|
||||
public static final byte[]
|
||||
Bry__width = Bry_.new_a7("width")
|
||||
Bry__width = Bry_.new_a7("width")
|
||||
, Bry__margin = Bry_.new_a7("margin")
|
||||
;
|
||||
}
|
||||
@@ -15,15 +15,16 @@ 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.langs.htmls.parsers.styles; import gplx.*; import gplx.langs.*; import gplx.langs.htmls.*; import gplx.langs.htmls.parsers.*;
|
||||
public class Html_atr_style_parser_ {
|
||||
public static void Parse(Html_tag tag, Html_atr_style_wkr wkr) {
|
||||
Html_atr atr = tag.Atrs__get_by_or_empty(Html_atr_.Bry__style);
|
||||
package gplx.langs.htmls.styles; import gplx.*; import gplx.langs.*; import gplx.langs.htmls.*;
|
||||
import gplx.langs.htmls.docs.*;
|
||||
public class Gfh_style_parser_ {
|
||||
public static void Parse(Gfh_tag tag, Gfh_style_wkr wkr) {
|
||||
Gfh_atr atr = tag.Atrs__get_by_or_empty(Gfh_atr_.Bry__style);
|
||||
if (atr.Val_dat_exists())
|
||||
Parse(tag.Src(), atr.Val_bgn(), atr.Val_end(), wkr);
|
||||
}
|
||||
public static void Parse(byte[] src, int src_bgn, int src_end, Html_atr_style_wkr wkr) {
|
||||
int atr_idx = 0, atr_bgn = -1, atr_end = -1, key_bgn = -1, key_end = -1, tmp_bgn = -1, tmp_end = -1;
|
||||
public static void Parse(byte[] src, int src_bgn, int src_end, Gfh_style_wkr wkr) {
|
||||
int atr_idx = 0, key_bgn = -1, key_end = -1, tmp_bgn = -1, tmp_end = -1;
|
||||
int pos = src_bgn;
|
||||
while (true) {
|
||||
boolean pos_is_last = pos == src_end;
|
||||
@@ -31,10 +32,10 @@ public class Html_atr_style_parser_ {
|
||||
switch (b) {
|
||||
case Byte_ascii.Semic:
|
||||
if (key_bgn != -1) { // ignore empty atrs
|
||||
if (!wkr.On_atr(src, atr_idx, atr_bgn, atr_end, key_bgn, key_end, tmp_bgn, tmp_end))
|
||||
if (!wkr.On_atr(src, atr_idx, src_bgn, src_end, key_bgn, key_end, tmp_bgn, tmp_end))
|
||||
pos_is_last = true;
|
||||
}
|
||||
++atr_idx; atr_bgn = -1; atr_end = -1; key_bgn = -1; key_end = -1; tmp_bgn = -1; tmp_end = -1;
|
||||
++atr_idx; key_bgn = -1; key_end = -1; tmp_bgn = -1; tmp_end = -1;
|
||||
break;
|
||||
case Byte_ascii.Colon:
|
||||
key_bgn = tmp_bgn;
|
||||
@@ -15,10 +15,10 @@ 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.langs.htmls.parsers.styles; import gplx.*; import gplx.langs.*; import gplx.langs.htmls.*; import gplx.langs.htmls.parsers.*;
|
||||
package gplx.langs.htmls.styles; import gplx.*; import gplx.langs.*; import gplx.langs.htmls.*;
|
||||
import org.junit.*;
|
||||
public class Html_atr_style_parser__tst {
|
||||
private final Html_atr_style_parser__fxt fxt = new Html_atr_style_parser__fxt();
|
||||
public class Gfh_style_parser__tst {
|
||||
private final Gfh_style_parser__fxt fxt = new Gfh_style_parser__fxt();
|
||||
@Test public void Basic() {
|
||||
fxt.Test__parse("k_0:v_0" , fxt.Make("k_0", "v_0"));
|
||||
fxt.Test__parse("k_0:v_0;" , fxt.Make("k_0", "v_0"));
|
||||
@@ -29,25 +29,17 @@ public class Html_atr_style_parser__tst {
|
||||
fxt.Test__parse(" k_0 : v_0 ; k_1 : v_1 " , fxt.Make("k_0", "v_0"), fxt.Make("k_1", "v_1"));
|
||||
fxt.Test__parse(" k_0 : v 0 ;" , fxt.Make("k_0", "v 0"));
|
||||
}
|
||||
@Test public void Empty() {
|
||||
fxt.Test__parse("k_0:v_0;;" , fxt.Make("k_0", "v_0"));
|
||||
fxt.Test__parse("k_0:v_0; ; " , fxt.Make("k_0", "v_0"));
|
||||
}
|
||||
}
|
||||
class Html_atr_style_parser__fxt {
|
||||
private final Html_atr_style_wkr__kv_list wkr = new Html_atr_style_wkr__kv_list();
|
||||
public KeyVal Make(String k, String v) {return KeyVal_.new_(k, v);}
|
||||
public void Test__parse(String src_str, KeyVal... expd) {
|
||||
class Gfh_style_parser__fxt {
|
||||
private final Gfh_style_wkr__ary wkr = Gfh_style_wkr__ary.Instance;
|
||||
public Gfh_style_itm Make(String k, String v) {return new Gfh_style_itm(-1, Bry_.new_u8(k), Bry_.new_u8(v));}
|
||||
public void Test__parse(String src_str, Gfh_style_itm... expd) {
|
||||
byte[] src_bry = Bry_.new_u8(src_str);
|
||||
KeyVal[] actl = wkr.Parse(src_bry, 0, src_bry.length);
|
||||
Gfh_style_itm[] actl = wkr.Parse(src_bry, 0, src_bry.length);
|
||||
Tfds.Eq_ary_str(expd, actl);
|
||||
}
|
||||
}
|
||||
class Html_atr_style_wkr__kv_list implements Html_atr_style_wkr {
|
||||
private final List_adp list = List_adp_.new_();
|
||||
public boolean On_atr(byte[] src, int atr_idx, int atr_bgn, int atr_end, int key_bgn, int key_end, int val_bgn, int val_end) {
|
||||
KeyVal kv = KeyVal_.new_(String_.new_u8(src, key_bgn, key_end), String_.new_u8(src, val_bgn, val_end));
|
||||
list.Add(kv);
|
||||
return true;
|
||||
}
|
||||
public KeyVal[] Parse(byte[] src, int src_bgn, int src_end) {
|
||||
Html_atr_style_parser_.Parse(src, src_bgn, src_end, this);
|
||||
return (KeyVal[])list.To_ary_and_clear(KeyVal.class);
|
||||
}
|
||||
}
|
||||
@@ -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.langs.htmls.parsers.styles; import gplx.*; import gplx.langs.*; import gplx.langs.htmls.*; import gplx.langs.htmls.parsers.*;
|
||||
public interface Html_atr_style_wkr {
|
||||
package gplx.langs.htmls.styles; import gplx.*; import gplx.langs.*; import gplx.langs.htmls.*;
|
||||
public interface Gfh_style_wkr {
|
||||
boolean On_atr(byte[] src, int atr_idx, int atr_bgn, int atr_end, int key_bgn, int key_end, int val_bgn, int val_end);
|
||||
}
|
||||
32
400_xowa/src/gplx/langs/htmls/styles/Gfh_style_wkr__ary.java
Normal file
32
400_xowa/src/gplx/langs/htmls/styles/Gfh_style_wkr__ary.java
Normal file
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
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.langs.htmls.styles; import gplx.*; import gplx.langs.*; import gplx.langs.htmls.*;
|
||||
public class Gfh_style_wkr__ary implements Gfh_style_wkr {
|
||||
private final List_adp list = List_adp_.new_();
|
||||
public boolean On_atr(byte[] src, int atr_idx, int atr_bgn, int atr_end, int key_bgn, int key_end, int val_bgn, int val_end) {
|
||||
byte[] key = Bry_.Mid(src, key_bgn, key_end);
|
||||
byte[] val = Bry_.Mid(src, val_bgn, val_end);
|
||||
list.Add(new Gfh_style_itm(list.Count(), key, val));
|
||||
return true;
|
||||
}
|
||||
public Gfh_style_itm[] Parse(byte[] src, int src_bgn, int src_end) {
|
||||
Gfh_style_parser_.Parse(src, src_bgn, src_end, this);
|
||||
return (Gfh_style_itm[])list.To_ary_and_clear(Gfh_style_itm.class);
|
||||
}
|
||||
public static final Gfh_style_wkr__ary Instance = new Gfh_style_wkr__ary(); Gfh_style_wkr__ary() {}
|
||||
}
|
||||
@@ -15,8 +15,8 @@ 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.langs.htmls.parsers.styles; import gplx.*; import gplx.langs.*; import gplx.langs.htmls.*; import gplx.langs.htmls.parsers.*;
|
||||
public class Html_atr_style_wkr__get_val_as_int implements Html_atr_style_wkr {
|
||||
package gplx.langs.htmls.styles; import gplx.*; import gplx.langs.*; import gplx.langs.htmls.*;
|
||||
public class Gfh_style_wkr__val_as_int implements Gfh_style_wkr {
|
||||
private byte[] find_key;
|
||||
private int val_bgn, val_end;
|
||||
public boolean On_atr(byte[] src, int atr_idx, int atr_bgn, int atr_end, int key_bgn, int key_end, int val_bgn, int val_end) {
|
||||
@@ -29,7 +29,7 @@ public class Html_atr_style_wkr__get_val_as_int implements Html_atr_style_wkr {
|
||||
}
|
||||
public int Parse(byte[] src, int src_bgn, int src_end, byte[] find_key) {
|
||||
this.find_key = find_key;
|
||||
Html_atr_style_parser_.Parse(src, src_bgn, src_end, this);
|
||||
Gfh_style_parser_.Parse(src, src_bgn, src_end, this);
|
||||
return Bry_.To_int_or__lax(src, val_bgn, val_end, -1);
|
||||
}
|
||||
}
|
||||
@@ -23,7 +23,7 @@ class Json_itm_str extends Json_itm_base {
|
||||
@Override public byte Tid() {return Json_itm_.Tid__str;}
|
||||
@Override public void Print_as_json(Bry_bfr bfr, int depth) {
|
||||
bfr.Add_byte(Byte_ascii.Quote);
|
||||
gplx.langs.htmls.Html_utl.Escape_html_to_bfr(bfr, doc.Src(), this.Src_bgn(), this.Src_end(), true, true, true, true, false); // false to apos for backwards compatibility
|
||||
gplx.langs.htmls.Gfh_utl.Escape_html_to_bfr(bfr, doc.Src(), this.Src_bgn(), this.Src_end(), true, true, true, true, false); // false to apos for backwards compatibility
|
||||
bfr.Add_byte(Byte_ascii.Quote);
|
||||
}
|
||||
@Override public Object Data() {
|
||||
|
||||
@@ -34,7 +34,7 @@ public class Xoa_app_ {
|
||||
}
|
||||
}
|
||||
public static final String Name = "xowa";
|
||||
public static final String Version = "2.12.1.1";
|
||||
public static final String Version = "3.1.1.1";
|
||||
public static String Build_date = "2012-12-30 00:00:00";
|
||||
public static String Op_sys_str;
|
||||
public static String User_agent = "";
|
||||
|
||||
@@ -39,6 +39,8 @@ public class Xoa_app_fxt {
|
||||
Io_url user_dir = root_dir.GenSubDir_nest("user", "test_user");
|
||||
Gfo_usr_dlg__log_base.Instance.Log_dir_(user_dir.GenSubDir_nest("tmp", "current"));
|
||||
Xoav_app rv = new Xoav_app(Gfo_usr_dlg_.Test(), Xoa_app_mode.Itm_gui, op_sys, root_dir, root_dir.GenSubDir("file"), root_dir.GenSubDir("css"));
|
||||
rv.Init_by_app(user_dir);
|
||||
rv.Wiki_mgr().Add(new Xowv_wiki(rv, Xow_domain_itm_.Bry__home, user_dir));
|
||||
return rv;
|
||||
}
|
||||
public static Xoae_app app_(String op_sys, Io_url root_dir) {
|
||||
|
||||
@@ -103,7 +103,7 @@ public class Xoa_ttl { // PAGE:en.w:http://en.wikipedia.org/wiki/Help:Link; REF.
|
||||
// $dbkey = preg_replace( '/[ _\xA0\x{1680}\x{180E}\x{2000}-\x{200A}\x{2028}\x{2029}\x{202F}\x{205F}\x{3000}]+/u', '_', $dbkey );
|
||||
private static final int Char__bidi = 1, Char__ws = 2;
|
||||
private static final Btrie_slim_mgr char_trie = Btrie_slim_mgr.cs()
|
||||
.Add_many_int(Char__bidi , Bry_.new_ints(0xE2, 0x80, 0x8E), Bry_.new_ints(0xE2, 0x80, 0x8F), Bry_.new_ints(0xE2, 0x80, 0xAA), Bry_.new_ints(0xE2, 0x80, 0xAB), Bry_.new_ints(0xE2, 0x80, 0xAC), Bry_.new_ints(0xE2, 0x80, 0xAD), Bry_.new_ints(0xE2, 0x80, 0xAE))
|
||||
.Add_many_int(Char__bidi , Bry_.New_by_ints(0xE2, 0x80, 0x8E), Bry_.New_by_ints(0xE2, 0x80, 0x8F), Bry_.New_by_ints(0xE2, 0x80, 0xAA), Bry_.New_by_ints(0xE2, 0x80, 0xAB), Bry_.New_by_ints(0xE2, 0x80, 0xAC), Bry_.New_by_ints(0xE2, 0x80, 0xAD), Bry_.New_by_ints(0xE2, 0x80, 0xAE))
|
||||
.Add_many_int(Char__ws , "\u00A0", "\u1680", "\u180E", "\u2000", "\u2001", "\u2002", "\u2003", "\u2004", "\u2005", "\u2006", "\u2007", "\u2008", "\u2009", "\u200A", "\u2028", "\u2029", "\u202F", "\u205F", "\u3000")
|
||||
;
|
||||
public static Xoa_ttl new_(Xowe_wiki wiki, Gfo_msg_log msg_log, byte[] src, int bgn, int end) {
|
||||
@@ -196,7 +196,10 @@ public class Xoa_ttl { // PAGE:en.w:http://en.wikipedia.org/wiki/Help:Link; REF.
|
||||
colon_count++; // increment colon count
|
||||
break;
|
||||
}
|
||||
case Byte_ascii.Hash: anch_bgn = (txt_bb_len) + 1; break; // flag last anch_bgn
|
||||
case Byte_ascii.Hash:
|
||||
if (anch_bgn == -1) // anchor begins at 1st #, not last #; EX:A#B#C has anchor of "B#C" not "C" PAGE:en.w:Grand_Central_Terminal; DATE:2015-12-31
|
||||
anch_bgn = (txt_bb_len) + 1;
|
||||
break;
|
||||
case Byte_ascii.Slash:
|
||||
if (root_bgn == -1)
|
||||
root_bgn = (txt_bb_len) + 1;
|
||||
|
||||
@@ -19,7 +19,7 @@ package gplx.xowa; import gplx.*;
|
||||
import gplx.xowa.langs.*; import gplx.xowa.wikis.pages.*;
|
||||
import gplx.xowa.guis.*; import gplx.xowa.guis.views.*;
|
||||
import gplx.xowa.files.*; import gplx.xowa.files.xfers.*;
|
||||
import gplx.xowa.parsers.*; import gplx.xowa.parsers.lnkis.redlinks.*; import gplx.xowa.xtns.cite.*; import gplx.xowa.xtns.wdatas.*; import gplx.xowa.xtns.wdatas.pfuncs.*;
|
||||
import gplx.xowa.parsers.*; import gplx.xowa.parsers.lnkis.redlinks.*; import gplx.xowa.xtns.cites.*; import gplx.xowa.xtns.wdatas.*; import gplx.xowa.xtns.wdatas.pfuncs.*;
|
||||
import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.htmls.*; import gplx.xowa.htmls.tocs.*; import gplx.xowa.htmls.modules.popups.*;
|
||||
public class Xoae_page implements Xoa_page {
|
||||
Xoae_page(Xowe_wiki wiki, Xoa_ttl ttl) {
|
||||
|
||||
@@ -64,6 +64,7 @@ public class Xop_fxt {
|
||||
ctx.Clear_all();
|
||||
ctx.App().Free_mem(false);
|
||||
ctx.Cur_page().Clear_all();
|
||||
wiki.File_mgr().Clear_for_tests();
|
||||
wiki.Db_mgr().Load_mgr().Clear();
|
||||
app.Wiki_mgr().Clear();
|
||||
Io_mgr.Instance.InitEngine_mem(); // clear created pages
|
||||
@@ -221,6 +222,8 @@ public class Xop_fxt {
|
||||
public byte[] Test_parse_tmpl_str_rv(String raw) {
|
||||
byte[] raw_bry = Bry_.new_u8(raw);
|
||||
Xop_root_tkn root = tkn_mkr.Root(raw_bry);
|
||||
ctx.Cur_page().Root_(root);
|
||||
ctx.Cur_page().Data_raw_(raw_bry);
|
||||
return parser.Parse_text_to_wtxt(root, ctx, tkn_mkr, raw_bry);
|
||||
}
|
||||
public Xot_defn_tmpl run_Parse_tmpl(byte[] name, byte[] raw) {return parser.Parse_text_to_defn_obj(ctx, ctx.Tkn_mkr(), wiki.Ns_mgr().Ns_template(), name, raw);}
|
||||
@@ -358,7 +361,7 @@ public class Xop_fxt {
|
||||
wiki.Appe().Usere().Wiki().Xwiki_mgr().Add_by_atrs(domain_bry, domain_bry);
|
||||
}
|
||||
public static String html_img_none(String trg, String alt, String src, String ttl) {
|
||||
return String_.Format(String_.Concat_lines_nl_skip_last("<a href=\"/wiki/{0}\" class=\"image\" xowa_title=\"{3}\"><img id=\"xowa_file_img_0\" alt=\"{1}\" src=\"{2}\" width=\"9\" height=\"8\" /></a>"), trg, alt, src, ttl);
|
||||
return String_.Format(String_.Concat_lines_nl_skip_last("<a href=\"/wiki/{0}\" class=\"image\" xowa_title=\"{3}\"><img id=\"xoimg_0\" alt=\"{1}\" src=\"{2}\" width=\"9\" height=\"8\" /></a>"), trg, alt, src, ttl);
|
||||
}
|
||||
private String Exec_html_full(String raw) {return this.Exec_parse_page_all_as_str(raw);}
|
||||
private String Exec_html_wiki(String raw) {return this.Exec_parse_page_wiki_as_str(raw);}
|
||||
@@ -369,7 +372,7 @@ public class Xop_fxt {
|
||||
public void Test_html_full_frag_n(String raw, String... expd_frags) {Test_str_part_n(Exec_html_full(raw), expd_frags);}
|
||||
public void Test__parse__wtxt_to_html(String raw, String expd) {
|
||||
String actl = Exec_html_wiki(raw);
|
||||
Tfds.Eq_str_lines(gplx.langs.htmls.Html_utl.Replace_apos(expd), actl, raw);
|
||||
Tfds.Eq_str_lines(gplx.langs.htmls.Gfh_utl.Replace_apos(expd), actl, raw);
|
||||
}
|
||||
|
||||
public void Test_str_full(String raw, String expd, String actl) {Tfds.Eq_str_lines(expd, actl, raw);}
|
||||
@@ -436,6 +439,7 @@ public class Xop_fxt {
|
||||
html_wtr.Cfg().Toc__show_(Bool_.Y); // needed for hdr to show <span class='mw-headline' id='A'>
|
||||
ctx.Cur_page().Redlink_lnki_list().Clear();
|
||||
html_wtr.Write_all(tmp_bfr, ctx, hctx, src_bry, root);
|
||||
// Tfds.Dbg(tmp_bfr.To_str());
|
||||
return tmp_bfr.To_str_and_clear();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,18 +26,18 @@ public class Xoa_fsys_eval implements Bry_fmtr_eval_mgr {
|
||||
Object o = hash.Get_by_bry(cmd); if (o == null) return null;
|
||||
byte val = ((Byte_obj_val)o).Val();
|
||||
switch (val) {
|
||||
case Tid_xowa_root_dir: return app_fsys_mgr.Root_dir().RawBry();
|
||||
case Tid_bin_plat_dir: return app_fsys_mgr.Bin_plat_dir().RawBry();
|
||||
case Tid_user_temp_dir: return usr_fsys_mgr.App_temp_dir().RawBry();
|
||||
case Tid_user_cfg_dir: return usr_fsys_mgr.App_data_cfg_dir().RawBry();
|
||||
case Tid__xowa_root_dir: return app_fsys_mgr.Root_dir().RawBry();
|
||||
case Tid__bin_plat_dir: return app_fsys_mgr.Bin_plat_dir().RawBry();
|
||||
case Tid__user_temp_dir: return usr_fsys_mgr.App_temp_dir().RawBry();
|
||||
case Tid__user_cfg_dir: return usr_fsys_mgr.App_data_cfg_dir().RawBry();
|
||||
default: throw Err_.new_unhandled(val);
|
||||
}
|
||||
}
|
||||
private static final byte Tid_bin_plat_dir = 0, Tid_user_temp_dir = 1, Tid_xowa_root_dir = 2, Tid_user_cfg_dir = 3;
|
||||
private static final byte Tid__bin_plat_dir = 0, Tid__user_temp_dir = 1, Tid__xowa_root_dir = 2, Tid__user_cfg_dir = 3;
|
||||
private static final Hash_adp_bry hash = Hash_adp_bry.ci_a7()
|
||||
.Add_str_byte("bin_plat_dir" , Tid_bin_plat_dir)
|
||||
.Add_str_byte("user_temp_dir" , Tid_user_temp_dir)
|
||||
.Add_str_byte("xowa_root_dir" , Tid_xowa_root_dir)
|
||||
.Add_str_byte("user_cfg_dir" , Tid_user_cfg_dir)
|
||||
.Add_str_byte("bin_plat_dir" , Tid__bin_plat_dir)
|
||||
.Add_str_byte("user_temp_dir" , Tid__user_temp_dir)
|
||||
.Add_str_byte("xowa_root_dir" , Tid__xowa_root_dir)
|
||||
.Add_str_byte("user_cfg_dir" , Tid__user_cfg_dir)
|
||||
;
|
||||
}
|
||||
|
||||
@@ -25,17 +25,17 @@ public class Xoa_prog_mgr implements GfoInvkAble {
|
||||
Process_adp.ini_(this, usr_dlg, app_convert_svg_to_png , cmd_eval, Process_adp.Run_mode_sync_timeout , 10 * 60, "~{<>bin_plat_dir<>}inkscape\\inkscape", "-z -w ~{width} -f \"~{source}\" -e \"~{target}\"", "source", "target", "width").Thread_kill_name_("inkscape.exe"); // // -z=without-gui; -w=width; -f=file -e=export-png
|
||||
Process_adp.ini_(this, usr_dlg, app_convert_tex_to_dvi , cmd_eval, Process_adp.Run_mode_sync_timeout , 2 * 60, "~{<>bin_plat_dir<>}miktex\\miktex\\bin\\latex", "-quiet -output-directory=~{temp_dir} -job-name=xowa_temp ~{tex_file}", "tex_file", "temp_dir");
|
||||
Process_adp.ini_(this, usr_dlg, app_convert_dvi_to_png , cmd_eval, Process_adp.Run_mode_sync_timeout , 2 * 60, "~{<>bin_plat_dir<>}miktex\\miktex\\bin\\dvipng", "~{dvi_file} -o ~{png_file} -q* -T tight -bg Transparent", "dvi_file", "png_file", "temp_dir");
|
||||
Process_adp.ini_(this, usr_dlg, app_convert_djvu_to_tiff , cmd_eval, Process_adp.Run_mode_sync_timeout , 1 * 60, "~{<>bin_plat_dir<>}djvulibre\\ddjvu", "-format=tiff -page=1 \"~{source}\" \"~{target}\"", "source", "target");
|
||||
Process_adp.ini_(this, usr_dlg, app_convert_djvu_to_tiff , cmd_eval, Process_adp.Run_mode_sync_timeout , 1 * 60, "~{<>bin_plat_dir<>}djvulibre\\ddjvu", "-format=tiff -page=1 \"~{source}\" \"~{target}\"", "source", "target");
|
||||
Process_adp.ini_(this, usr_dlg, app_decompress_bz2 , cmd_eval, Process_adp.Run_mode_sync_timeout , 0 , "~{<>bin_plat_dir<>}7-zip\\7za", "x -y \"~{src}\" -o\"~{trg_dir}\"", "src", "trg", "trg_dir"); // x=extract; -y=yes on all queries; -o=output_dir
|
||||
Process_adp.ini_(this, usr_dlg, app_decompress_bz2_by_stdout , cmd_eval, Process_adp.Run_mode_sync_timeout , 0 , "~{<>bin_plat_dir<>}7-zip\\7za", "x -so \"~{src}\"", "src"); // x=extract; -so=stdout
|
||||
Process_adp.ini_(this, usr_dlg, app_decompress_bz2_by_stdout, cmd_eval, Process_adp.Run_mode_sync_timeout , 0 , "~{<>bin_plat_dir<>}7-zip\\7za", "x -so \"~{src}\"", "src"); // x=extract; -so=stdout
|
||||
Process_adp.ini_(this, usr_dlg, app_decompress_zip , cmd_eval, Process_adp.Run_mode_sync_timeout , 0 , "~{<>bin_plat_dir<>}7-zip\\7za", "x -y \"~{src}\" -o\"~{trg_dir}\"", "src", "trg", "trg_dir"); // x=extract; -y=yes on all queries; -o=output_dir
|
||||
Process_adp.ini_(this, usr_dlg, app_decompress_gz , cmd_eval, Process_adp.Run_mode_sync_timeout , 0 , "~{<>bin_plat_dir<>}7-zip\\7za", "x -y \"~{src}\" -o\"~{trg_dir}\"", "src", "trg", "trg_dir"); // x=extract; -y=yes on all queries; -o=output_dir
|
||||
Process_adp.ini_(this, usr_dlg, app_lua , cmd_eval, Process_adp.Run_mode_async , 0 , "~{<>bin_plat_dir<>}lua\\lua", "", "");
|
||||
Process_adp.ini_(this, usr_dlg, app_lilypond , cmd_eval, Process_adp.Run_mode_sync_timeout , 1 * 60, "~{<>bin_plat_dir<>}lilypond\\usr\\bin\\lilypond.exe", "\"-dsafe=#t\" -dbackend=ps --png --header=texidoc -dmidi-extension=midi \"~{file}\"", "file");
|
||||
Process_adp.ini_(this, usr_dlg, app_lilypond , cmd_eval, Process_adp.Run_mode_sync_timeout , 1 * 60, "~{<>bin_plat_dir<>}lilypond\\usr\\bin\\lilypond.exe", "\"-dsafe=#t\" -dbackend=ps --png --header=texidoc -dmidi-extension=midi \"~{file}\"", "file");
|
||||
Process_adp.ini_(this, usr_dlg, app_abc2ly , cmd_eval, Process_adp.Run_mode_sync_timeout , 1 * 60, "~{<>bin_plat_dir<>}lilypond\\usr\\bin\\python.exe", "abc2ly.py -s \"--output=~{target}\" \"~{source}\"", "source", "target");
|
||||
Process_adp.ini_(this, usr_dlg, app_trim_img , cmd_eval, Process_adp.Run_mode_sync_timeout , 1 * 60, "~{<>bin_plat_dir<>}imagemagick\\convert", "-trim \"~{source}\" \"~{target}\"", "source", "target");
|
||||
Process_adp.ini_(this, usr_dlg, app_trim_img , cmd_eval, Process_adp.Run_mode_sync_timeout , 1 * 60, "~{<>bin_plat_dir<>}imagemagick\\convert", "-trim \"~{source}\" \"~{target}\"", "source", "target");
|
||||
Process_adp.ini_(this, usr_dlg, app_convert_midi_to_ogg , cmd_eval, Process_adp.Run_mode_sync_timeout , 1 * 60, "~{<>bin_plat_dir<>}timidity\\timidity", "-Ov \"--output-file=~{target}\" \"~{source}\"", "source", "target");
|
||||
Process_adp.ini_(this, usr_dlg, app_view_web , cmd_eval, Process_adp.Run_mode_async , 0 , "cmd", "/c start \"~{url}\"", "url");
|
||||
Process_adp.ini_(this, usr_dlg, app_view_web , cmd_eval, Process_adp.Run_mode_async , 0 , "cmd", "/c start \"~{url}\"", "url");
|
||||
Process_adp.ini_(this, usr_dlg, app_view_text , cmd_eval, Process_adp.Run_mode_async , 0 , "cmd", "/c start \"~{url}\"", "url");
|
||||
int cmds_view_file_by_ext_len = cmds_view_file_by_ext.length;
|
||||
for (int i= 0; i < cmds_view_file_by_ext_len; i++) {
|
||||
@@ -56,11 +56,11 @@ public class Xoa_prog_mgr implements GfoInvkAble {
|
||||
public Process_adp App_decompress_zip() {return app_decompress_zip;} private Process_adp app_decompress_zip = new Process_adp();
|
||||
public Process_adp App_decompress_gz() {return app_decompress_gz;} private Process_adp app_decompress_gz = new Process_adp();
|
||||
public Process_adp App_decompress_bz2_by_stdout() {return app_decompress_bz2_by_stdout;} private Process_adp app_decompress_bz2_by_stdout = new Process_adp();
|
||||
public Process_adp App_lua() {return app_lua;} private Process_adp app_lua = new Process_adp();
|
||||
public Process_adp App_lua() {return app_lua;} private Process_adp app_lua = new Process_adp();
|
||||
public Process_adp App_lilypond() {return app_lilypond;} private Process_adp app_lilypond = new Process_adp();
|
||||
public Process_adp App_abc2ly() {return app_abc2ly;} private Process_adp app_abc2ly = new Process_adp();
|
||||
public Process_adp App_trim_img() {return app_trim_img;} private Process_adp app_trim_img = new Process_adp();
|
||||
public Process_adp App_convert_midi_to_ogg() {return app_convert_midi_to_ogg;} private Process_adp app_convert_midi_to_ogg = new Process_adp();
|
||||
public Process_adp App_convert_midi_to_ogg() {return app_convert_midi_to_ogg;} private Process_adp app_convert_midi_to_ogg = new Process_adp();
|
||||
public Process_adp App_by_ext(String ext) {return App_by_ext_key(String_.Mid(ext, 1));} // ignore 1st . in ext; EX: ".png" -> "png"
|
||||
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
|
||||
if (ctx.Match(k, Invk_query_img_size)) return app_query_img_size;
|
||||
|
||||
@@ -63,7 +63,7 @@ public class Xoa_site_cfg_mgr_tst {
|
||||
}
|
||||
// @Test public void Print() {
|
||||
// String s = fxt.Make_api(fxt.Make_api_interwikimap("k1", "v1", "k2", "v2"), fxt.Make_api_extensiontags2("k3", "v3", "k4", "v4"));
|
||||
// Tfds.Write(s);
|
||||
// Tfds.Dbg(s);
|
||||
// }
|
||||
}
|
||||
class Xoa_site_cfg_mgr_fxt {
|
||||
|
||||
@@ -54,6 +54,9 @@ public class Xob_cmd_keys {
|
||||
, Key_wbase_pid = "wbase.pid" // "text.wdata.pid"
|
||||
, Key_wbase_db = "wbase.db" // "wiki.wdata_db"
|
||||
, Key_site_meta = "util.site_meta"
|
||||
, Key_diff_build = "diff.build"
|
||||
, Key_diff_merge = "diff.merge"
|
||||
|
||||
, Key_tdb_text_init = "tdb.text.init" // "core.init"
|
||||
, Key_tdb_make_page = "tdb.text.page" // "core.make_page"
|
||||
, Key_tdb_make_id = "core.make_id"
|
||||
|
||||
@@ -89,7 +89,7 @@ public class Xob_wiki_cfg_bldr_tst {
|
||||
// String[] terms = String_.Split(line, '|');
|
||||
// sb.Add(lang_code).Add("|").Add(String_.Trim(terms[0])).Add("|").Add(String_.Trim(terms[1])).Add("\n");
|
||||
// }
|
||||
// Tfds.Write(sb.To_str_and_clear());
|
||||
// Tfds.Dbg(sb.To_str_and_clear());
|
||||
// }
|
||||
@Test public void Ns_aliases() {
|
||||
Io_mgr.Instance.InitEngine_mem();
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -22,11 +22,11 @@ public class Uca_trie_tst {
|
||||
@Test public void Basic() {
|
||||
Uca_trie_fxt fxt = new Uca_trie_fxt();
|
||||
fxt.Clear();
|
||||
fxt.Init_trie_itm("a", Bry_.new_ints(10, 11));
|
||||
fxt.Init_trie_itm("b", Bry_.new_ints(20, 21));
|
||||
fxt.Init_trie_itm("c", Bry_.new_ints(30, 31));
|
||||
fxt.Test_decode(Bry_.new_ints(10, 11), "a");
|
||||
fxt.Test_decode(Bry_.new_ints(10, 11, 20, 21, 30, 31), "abc");
|
||||
fxt.Init_trie_itm("a", Bry_.New_by_ints(10, 11));
|
||||
fxt.Init_trie_itm("b", Bry_.New_by_ints(20, 21));
|
||||
fxt.Init_trie_itm("c", Bry_.New_by_ints(30, 31));
|
||||
fxt.Test_decode(Bry_.New_by_ints(10, 11), "a");
|
||||
fxt.Test_decode(Bry_.New_by_ints(10, 11, 20, 21, 30, 31), "abc");
|
||||
}
|
||||
}
|
||||
class Uca_trie_fxt {
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
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.diffs; import gplx.*; import gplx.xowa.*; import gplx.xowa.bldrs.*; import gplx.xowa.bldrs.cmds.*;
|
||||
public class Xob_diff_build_cmd implements Xob_cmd {
|
||||
private final Xob_bldr bldr; private final Xowe_wiki wiki;
|
||||
private String prev_url, curr_url, diff_url; private int commit_interval;
|
||||
public Xob_diff_build_cmd(Xob_bldr bldr, Xowe_wiki wiki) {this.bldr = bldr; this.wiki = wiki;}
|
||||
public String Cmd_key() {return Xob_cmd_keys.Key_diff_build;}
|
||||
public void Cmd_run() {
|
||||
new Xob_diff_build_wkr(bldr, wiki, prev_url, curr_url, diff_url, commit_interval).Exec();
|
||||
}
|
||||
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
|
||||
if (ctx.Match(k, Invk__prev_url_)) prev_url = m.ReadStr("v");
|
||||
else if (ctx.Match(k, Invk__curr_url_)) curr_url = m.ReadStr("v");
|
||||
else if (ctx.Match(k, Invk__diff_url_)) diff_url = m.ReadStr("v");
|
||||
else if (ctx.Match(k, Invk__commit_interval_)) commit_interval = m.ReadInt("v");
|
||||
else return GfoInvkAble_.Rv_unhandled;
|
||||
return this;
|
||||
}
|
||||
public void Cmd_init(Xob_bldr bldr) {}
|
||||
public void Cmd_bgn(Xob_bldr bldr) {}
|
||||
public void Cmd_end() {}
|
||||
public void Cmd_term() {}
|
||||
private static final String Invk__prev_url_ = "prev_url_", Invk__curr_url_ = "curr_url_", Invk__diff_url_ = "diff_url_", Invk__commit_interval_ = "commit_interval_";
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
/*
|
||||
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.diffs; import gplx.*; import gplx.xowa.*; import gplx.xowa.bldrs.*; import gplx.xowa.bldrs.cmds.*;
|
||||
import gplx.core.brys.*; import gplx.core.brys.fmtrs.*;
|
||||
import gplx.dbs.*; import gplx.dbs.diffs.*; import gplx.dbs.diffs.builds.*;
|
||||
class Xob_diff_build_wkr {
|
||||
private final Gfdb_diff_bldr diff_bldr = new Gfdb_diff_bldr();
|
||||
private Db_conn prev_conn, curr_conn, diff_conn;
|
||||
public Xob_diff_build_wkr(Xob_bldr bldr, Xowe_wiki wiki, String prev_url, String curr_url, String diff_url, int commit_interval) {
|
||||
Bry_fmt url_fmt = Bry_fmt.New("").Args_(New_url_args(wiki));
|
||||
Bry_bfr tmp_bfr = Bry_bfr.new_();
|
||||
prev_conn = New_conn(wiki, url_fmt, prev_url, tmp_bfr);
|
||||
curr_conn = New_conn(wiki, url_fmt, curr_url, tmp_bfr);
|
||||
diff_conn = New_conn(wiki, url_fmt, diff_url, tmp_bfr);
|
||||
// get Gfdb_diff_tbl; format urls
|
||||
Tfds.Write(prev_conn, curr_conn, diff_conn);
|
||||
}
|
||||
public void Exec() {
|
||||
diff_bldr.Init(null); // diff_db_wkr
|
||||
diff_bldr.Compare(null, null); // lhs_tbl, rhs_tbl
|
||||
}
|
||||
public static Db_conn New_conn(Xow_wiki wiki, Bry_fmt fmtr, String url_fmt, Bry_bfr tmp_bfr) {
|
||||
fmtr.Fmt_(url_fmt).Bld_bfr_many(tmp_bfr);
|
||||
Db_conn conn = Db_conn_pool.Instance.Get_or_new(tmp_bfr.To_str_and_clear());
|
||||
return conn;
|
||||
}
|
||||
private static Bfr_fmt_arg[] New_url_args(Xow_wiki wiki) {
|
||||
return null;
|
||||
}
|
||||
//prev_url='~{.dump_dir}-prev/~{.dump_core}';
|
||||
//curr_url='~{.dump_dir}/~{.dump_core}';
|
||||
//diff_url='~{.dump_dir}/~{.dump_domain}-diff.xowa';
|
||||
}
|
||||
// class Bfr_arg__dump_dir : Bfr_arg {
|
||||
// public void Bfr_arg__add(Bry_bfr bfr) {
|
||||
// // dump_dir = bfr.Add("C:\xowa\wiki\en.wikipedia.org");
|
||||
// // dump_core = en.wikipedia.org-core.xowa
|
||||
// // dump_domain = en.wikipedia.org
|
||||
// }
|
||||
// }
|
||||
@@ -35,8 +35,8 @@ public class Xob_diff_regy_make_cmd extends Xob_itm_basic_base implements Xob_cm
|
||||
}
|
||||
private void Make_join_indexes(Db_conn make_db_provider) {
|
||||
try {
|
||||
Sqlite_engine_.Idx_create(make_db_provider, Xob_diff_regy_tbl.Idx_fsdb_regy__join);
|
||||
Sqlite_engine_.Idx_create(make_db_provider, Xob_diff_regy_tbl.Idx_xfer_regy__join);
|
||||
make_db_provider.Ddl_create_idx(Db_meta_idx.new_normal_by_name("fsdb_regy", "fsdb_regy__join", "fsdb_name", "fsdb_is_orig", "fsdb_repo", "fsdb_w", "fsdb_time", "fsdb_page"));
|
||||
make_db_provider.Ddl_create_idx(Db_meta_idx.new_normal_by_name("xfer_regy", "xfer_regy__join", "lnki_ttl", "file_is_orig", "orig_repo", "file_w", "lnki_time", "lnki_page"));
|
||||
}
|
||||
catch (Exception exc) {
|
||||
app.Usr_dlg().Warn_many("", "", "error while making indexes: err=~{0}", Err_.Message_gplx_full(exc));
|
||||
@@ -110,8 +110,8 @@ class Xob_diff_regy_tbl {
|
||||
, ", diff_size bigint NOT NULL"
|
||||
, ");"
|
||||
);
|
||||
public static final Db_idx_itm Idx_fsdb_regy__join = Db_idx_itm.sql_("CREATE INDEX fsdb_regy__join ON fsdb_regy (fsdb_name, fsdb_is_orig, fsdb_repo, fsdb_w, fsdb_time, fsdb_page);");
|
||||
public static final Db_idx_itm Idx_xfer_regy__join = Db_idx_itm.sql_("CREATE INDEX xfer_regy__join ON xfer_regy (lnki_ttl , file_is_orig, orig_repo, file_w, lnki_time, lnki_page);");
|
||||
// public static final Db_idx_itm Idx_fsdb_regy__join = Db_idx_itm.sql_("CREATE INDEX fsdb_regy__join ON fsdb_regy (fsdb_name, fsdb_is_orig, fsdb_repo, fsdb_w, fsdb_time, fsdb_page);");
|
||||
// public static final Db_idx_itm Idx_xfer_regy__join = Db_idx_itm.sql_("CREATE INDEX xfer_regy__join ON xfer_regy (lnki_ttl , file_is_orig, orig_repo, file_w, lnki_time, lnki_page);");
|
||||
public static final Db_idx_itm Idx_diff_regy__load = Db_idx_itm.sql_("CREATE INDEX diff_regy__load ON diff_regy (diff_status, diff_db_id, diff_is_orig, diff_fil_id, diff_thm_id);");
|
||||
public static final String
|
||||
Make_diff_regy = String_.Concat_lines_nl
|
||||
|
||||
@@ -65,7 +65,7 @@ public class Xob_lnki_temp_wkr extends Xob_dump_mgr_base implements Xopg_redlink
|
||||
property_wkr = this.Property_wkr(); // set member reference
|
||||
property_wkr = log_mgr.Make_wkr_property();
|
||||
wiki.Appe().Wiki_mgr().Wdata_mgr().Enabled_(wdata_enabled);
|
||||
if (!xtn_ref_enabled) gplx.xowa.xtns.cite.References_nde.Enabled = false;
|
||||
if (!xtn_ref_enabled) gplx.xowa.xtns.cites.References_nde.Enabled = false;
|
||||
gplx.xowa.xtns.gallery.Gallery_xnde.Log_wkr = log_mgr.Make_wkr().Save_src_str_(Bool_.Y);
|
||||
gplx.xowa.xtns.imaps.Imap_xnde.Log_wkr = log_mgr.Make_wkr();
|
||||
gplx.xowa.parsers.xndes.Xop_xnde_wkr.Timeline_log_wkr = log_mgr.Make_wkr();
|
||||
|
||||
@@ -39,7 +39,7 @@ public class Xob_search_sql_wkr extends Xob_search_base implements Io_make_cmd {
|
||||
byte[] bry = rdr.Bfr();
|
||||
byte[] cur_word = Bry_.Mid(bry, rdr.Key_pos_bgn(), rdr.Key_pos_end());
|
||||
if (!Bry_.Eq(cur_word, prv_word)) {
|
||||
search_word_tbl.Insert_cmd_by_batch(++search_id, cur_word, page_count);
|
||||
search_word_tbl.Insert_cmd_by_batch(++search_id, prv_word, page_count);
|
||||
prv_word = cur_word;
|
||||
page_count = 0;
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ public class Xob_redirect_cmd extends Xob_dump_mgr_base {
|
||||
public Xob_redirect_cmd(Xob_bldr bldr, Xowe_wiki wiki) {this.Cmd_ctor(bldr, wiki); this.Reset_db_y_();}
|
||||
@Override public String Cmd_key() {return Xob_cmd_keys.Key_wiki_redirect;}
|
||||
@Override public int[] Init_ns_ary() {return Int_.Ary(Xow_ns_.Tid__file);} // restrict to file ns
|
||||
@Override public byte Init_redirect() {return Bool_.Y_byte;} // restrict to redirects
|
||||
@Override public byte Init_redirect() {return Bool_.Y_byte;} // restrict to redirects
|
||||
@Override protected void Init_reset(Db_conn conn) {
|
||||
Db_cfg_tbl cfg_tbl = new Db_cfg_tbl(conn, "xowa_cfg");
|
||||
cfg_tbl.Delete_all();
|
||||
|
||||
@@ -46,10 +46,10 @@ public class Xoi_cmd_wiki_tst {
|
||||
for (int j = 0; j < 5; ++j) {
|
||||
latest_html = Io_mgr.Instance.DownloadFil_args("", Io_url_.Empty).Exec_as_bry(url);
|
||||
if (latest_html != null) break;
|
||||
Tfds.Write("fail|" + url);
|
||||
Tfds.Dbg("fail|" + url);
|
||||
if (j == 4) return;
|
||||
}
|
||||
Tfds.Write("pass|" + url);
|
||||
Tfds.Dbg("pass|" + url);
|
||||
parser.Parse(latest_html);
|
||||
Xowm_dump_file dump_file = new Xowm_dump_file(domain_str, "latest", Xowm_dump_type_.Str__pages_articles);
|
||||
dump_file.Server_url_(Xowm_dump_file_.Server_wmf_https);
|
||||
|
||||
@@ -28,7 +28,7 @@ public class Wmf_latest_parser_tst {
|
||||
// @Test public void Smoke() {
|
||||
// Wmf_latest_parser parser = new Wmf_latest_parser();
|
||||
// parser.Parse(Io_mgr.Instance.LoadFilBry("C:\\wmf_latest.html"));
|
||||
// Tfds.Write(String_.Concat_lines_nl(Wmf_latest_parser_fxt.Xto_str_ary(parser.To_ary())));
|
||||
// Tfds.Dbg(String_.Concat_lines_nl(Wmf_latest_parser_fxt.Xto_str_ary(parser.To_ary())));
|
||||
// }
|
||||
}
|
||||
class Wmf_latest_parser_fxt {
|
||||
|
||||
@@ -19,6 +19,7 @@ package gplx.xowa.drds; import gplx.*; import gplx.xowa.*;
|
||||
import gplx.xowa.drds.pages.*; import gplx.xowa.drds.files.*;
|
||||
import gplx.xowa.apps.*; import gplx.xowa.wikis.data.tbls.*;
|
||||
import gplx.xowa.files.gui.*;
|
||||
import gplx.xowa.specials.search.*;
|
||||
public class Xod_app {
|
||||
private final Xoav_app app;
|
||||
private final Xod_page_mgr page_mgr = new Xod_page_mgr();
|
||||
@@ -26,13 +27,29 @@ public class Xod_app {
|
||||
public Xod_app(Xoav_app app) {
|
||||
this.app = app;
|
||||
}
|
||||
public Xow_wiki Get_wiki(String wiki_domain) {
|
||||
return app.Wiki_mgri().Get_by_key_or_make_init_y(Bry_.new_u8(wiki_domain));
|
||||
public int Get_wiki_count() {
|
||||
int rv = app.Wiki_mgri().Count();
|
||||
return rv - 1; // ignore home wiki
|
||||
}
|
||||
public Xod_page_itm Get_page(Xow_wiki wiki, String page_ttl) {
|
||||
return page_mgr.Get_page(wiki, page_ttl);
|
||||
public Xow_wiki Get_wiki(String wiki_domain) {
|
||||
Xow_wiki rv = app.Wiki_mgri().Get_by_key_or_make_init_y(Bry_.new_u8(wiki_domain));
|
||||
if (rv.Data__core_mgr() == null) rv.Init_by_wiki();
|
||||
return rv;
|
||||
}
|
||||
public Xod_page_itm Get_page(Xow_wiki wiki, Xoa_url page_url) {
|
||||
return page_mgr.Get_page(wiki, page_url);
|
||||
}
|
||||
public void Load_files(Xow_wiki wiki, Xod_page_itm pg, Xog_js_wkr js_wkr) {
|
||||
file_mgr.Load_files(wiki, pg, js_wkr);
|
||||
}
|
||||
public String[] Search_titles(Cancelable cancelable, Xow_wiki wiki, Xows_ui_async ui_async, String search) {
|
||||
Xows_db_wkr search_wkr = new Xows_db_wkr();
|
||||
Xows_db_row[] rows = search_wkr.Search_by_drd(cancelable, wiki, ui_async, Bry_.new_u8(search), 50);
|
||||
int len = rows.length;
|
||||
String[] rv = new String[len];
|
||||
for (int i = 0; i < len; ++i) {
|
||||
rv[i] = String_.new_u8(rows[i].Page_ttl().Page_txt());
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,7 +23,7 @@ public class Xod_app_tst {
|
||||
@Test public void Get() {
|
||||
tstr.Data_mgr().Page__insert(1, "A", "2015-10-19 00:01:02");
|
||||
tstr.Data_mgr().Html__insert(1, "abc");
|
||||
tstr.Test__get("A", tstr.Make_page(1, "A", "2015-10-19 00:01:02", tstr.Make_section(0, 2, "", "", "abc")));
|
||||
tstr.Test__get("A", tstr.Make_page(1, "A", "2015-10-19T00:01:02Z", tstr.Make_section(0, 2, "", "", "abc")));
|
||||
}
|
||||
}
|
||||
class Xod_app_tstr {
|
||||
@@ -42,7 +42,8 @@ class Xod_app_tstr {
|
||||
}
|
||||
public void Test__get(String ttl, Xod_page_itm expd) {
|
||||
Xow_wiki wiki = drd_provider.Get_wiki("en.wikipedia.org");
|
||||
Xod_page_itm itm = drd_provider.Get_page(wiki, ttl);
|
||||
Xoa_url page_url = wiki.Utl__url_parser().Parse(Bry_.new_u8(ttl));
|
||||
Xod_page_itm itm = drd_provider.Get_page(wiki, page_url);
|
||||
Tfds.Eq(expd.To_str(), itm.To_str());
|
||||
}
|
||||
public Xod_page_itm Make_page(int page_id, String ttl, String modified_on, Xoh_section_itm... section_ary) {
|
||||
|
||||
@@ -51,7 +51,7 @@ public class Xod_page_itm {
|
||||
this.rev_id = page_id;
|
||||
this.ttl_text = String_.new_u8(ttl.Page_txt());
|
||||
this.ttl_db = ttl.Page_db_as_str();
|
||||
this.modified_on = db_page.Modified_on().XtoStr_fmt_iso_8561();
|
||||
this.modified_on = db_page.Modified_on().XtoStr_fmt_iso_8561_w_tz();
|
||||
this.lang_count = 1;
|
||||
this.redirected = null;
|
||||
this.description = null;
|
||||
|
||||
@@ -18,12 +18,14 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
package gplx.xowa.drds.pages; import gplx.*; import gplx.xowa.*; import gplx.xowa.drds.*;
|
||||
import gplx.xowa.wikis.data.tbls.*;
|
||||
import gplx.xowa.htmls.*; import gplx.xowa.htmls.sections.*;
|
||||
import gplx.core.net.*; import gplx.xowa.specials.xowa.file_browsers.*;
|
||||
public class Xod_page_mgr {
|
||||
public Xod_page_itm Get_page(Xow_wiki wiki, String page_ttl) {
|
||||
public Xod_page_itm Get_page(Xow_wiki wiki, Xoa_url page_url) {
|
||||
Xod_page_itm rv = new Xod_page_itm();
|
||||
|
||||
// load meta info like page_id, modified, etc
|
||||
Xoa_ttl ttl = wiki.Ttl_parse(Bry_.new_u8(page_ttl));
|
||||
Xoa_ttl ttl = wiki.Ttl_parse(page_url.Page_bry());
|
||||
if (ttl.Ns().Id_is_special()) return Load_special(rv, wiki, ttl, page_url.Qargs_ary());
|
||||
Xowd_page_itm dbpg = new Xowd_page_itm();
|
||||
wiki.Data__core_mgr().Tbl__page().Select_by_ttl(dbpg, ttl.Ns(), ttl.Page_db());
|
||||
rv.Init_by_dbpg(ttl, dbpg);
|
||||
@@ -44,4 +46,13 @@ public class Xod_page_mgr {
|
||||
rv.Section_list().Add(itm);
|
||||
}
|
||||
}
|
||||
private Xod_page_itm Load_special(Xod_page_itm rv, Xow_wiki wiki, Xoa_ttl ttl, Gfo_qarg_itm[] qargs) {
|
||||
Xosp_fbrow_rslt rslt = Xosp_fbrow_special.Gen(qargs, wiki.App().Wiki_mgri());
|
||||
rv.Init(-1, -1, String_.new_u8(ttl.Page_txt()), String_.new_u8(ttl.Page_db()), null, null, DateAdp_.Now().XtoStr_fmt_iso_8561(), false, false, false, 0, "", "", "");
|
||||
rv.Init_by_hpg(new Xoh_page());
|
||||
Xoh_section_itm section = new Xoh_section_itm(1, 1, Bry_.Empty, Bry_.Empty);
|
||||
section.Content_(rslt.Html_body());
|
||||
rv.Section_list().Add(section);
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,6 +33,12 @@ public class Xof_file_wkr implements Gfo_thread_wkr {
|
||||
public String Name() {return "xowa.load_imgs";}
|
||||
public boolean Resume() {return true;}
|
||||
public void Exec() {
|
||||
int len = imgs.Count();
|
||||
for (int i = 0; i < len; ++i)
|
||||
Exec_by_fsdb((Xof_fsdb_itm)imgs.Get_at(i));
|
||||
Xoa_app_.Usr_dlg().Prog_none("", "", "");
|
||||
}
|
||||
public void Exec_old() {
|
||||
int len = imgs.Count();
|
||||
for (int i = 0; i < len; ++i)
|
||||
Ctor_by_hdump(hpg, (Xohd_img_itm__base)imgs.Get_at(i));
|
||||
@@ -42,6 +48,9 @@ public class Xof_file_wkr implements Gfo_thread_wkr {
|
||||
Xof_fsdb_itm fsdb = new Xof_fsdb_itm();
|
||||
fsdb.Init_at_lnki(Xof_exec_tid.Tid_wiki_page, hpg.Wiki().Domain_itm().Abrv_xo(), hdump.Lnki_ttl(), hdump.Lnki_type(), hdump.Lnki_upright(), hdump.Lnki_w(), hdump.Lnki_h(), hdump.Lnki_time(), hdump.Lnki_page(), Xof_patch_upright_tid_.Tid_all);
|
||||
fsdb.Init_at_hdoc(hdump.Html_uid(), hdump.Html_elem_tid());
|
||||
Exec_by_fsdb(fsdb);
|
||||
}
|
||||
private void Exec_by_fsdb(Xof_fsdb_itm fsdb) {
|
||||
fsdb.Orig_exists_n_();
|
||||
Xof_orig_itm orig = orig_mgr.Find_by_ttl_or_null(fsdb.Lnki_ttl()); if (orig == Xof_orig_itm.Null) return;
|
||||
Eval_orig(orig, fsdb, url_bldr, repo_mgr, img_size);
|
||||
|
||||
@@ -89,6 +89,10 @@ public class Xow_file_mgr implements GfoInvkAble {
|
||||
return fsdb_mgr.Mnt_mgr().Mnts__get_main().Cfg_mgr().Grps_get_or_load(grp);
|
||||
}
|
||||
public Xof_fsdb_mgr Fsdb_mgr() {return fsdb_mgr;} private Xof_fsdb_mgr fsdb_mgr = new Xof_fsdb_mgr__sql();
|
||||
public void Clear_for_tests() { // NOTE: must clear else fsdb_mode will be cached for multiple runs; will generally be v1, but some tests will set to v2; DATE:2015-12-22
|
||||
version = Bool_.__byte;
|
||||
fsdb_mode = null;
|
||||
}
|
||||
public boolean Find_meta(Xof_xfer_itm xfer_itm) {
|
||||
xfer_itm.Orig_repo_id_(Xof_meta_itm.Repo_unknown);
|
||||
byte[] xfer_itm_ttl = xfer_itm.Lnki_ttl();
|
||||
|
||||
@@ -53,5 +53,5 @@ public class Js_img_mgr {
|
||||
break;
|
||||
}
|
||||
}
|
||||
public static String To_doc_uid(int html_uid) {return "xowa_file_img_" + Int_.To_str(html_uid);}
|
||||
public static String To_doc_uid(int html_uid) {return gplx.xowa.htmls.Xoh_img_mgr.Str__html_uid + Int_.To_str(html_uid);}
|
||||
}
|
||||
|
||||
@@ -123,7 +123,7 @@ public class Xog_win_itm implements GfoInvkAble, GfoEvObj {
|
||||
}
|
||||
private void Win__link_clicked(String anchor_raw) {
|
||||
String url = url_box.Text();
|
||||
int pos = String_.FindFwd(url, gplx.langs.htmls.Html_tag_.Anchor_str);
|
||||
int pos = String_.FindFwd(url, gplx.langs.htmls.Gfh_tag_.Anchor_str);
|
||||
if (pos != Bry_find_.Not_found) url = String_.Mid(url, 0, pos);
|
||||
String anchor_str = Parse_evt_location_changing(anchor_raw);
|
||||
byte[] anchor_bry = Bry_.new_u8(anchor_str);
|
||||
@@ -145,7 +145,7 @@ public class Xog_win_itm implements GfoInvkAble, GfoEvObj {
|
||||
app.Gfs_mgr().Run_str(snippet);
|
||||
}
|
||||
private static String Parse_evt_location_changing(String v) { // EX: about:blank#anchor -> anchor
|
||||
int pos = String_.FindFwd(v, gplx.langs.htmls.Html_tag_.Anchor_str);
|
||||
int pos = String_.FindFwd(v, gplx.langs.htmls.Gfh_tag_.Anchor_str);
|
||||
return pos == Bry_find_.Not_found
|
||||
? null
|
||||
: String_.Mid(v, pos + 1);
|
||||
|
||||
@@ -29,11 +29,8 @@ public class Xoh_consts {
|
||||
, __inline_quote = Bry_.new_a7("\"/>")
|
||||
, Space_2 = Bry_.new_a7(" ")
|
||||
|
||||
, A_bgn = Bry_.new_a7("<a href=\""), A_bgn_lnki_0 = Bry_.new_a7("\" title=\""), A_mid_xowa_title = Bry_.new_a7("\" xowa_title=\"")
|
||||
, A_mid_id = Bry_.new_a7("\" id=\"xolnki_")
|
||||
, A_end = Bry_.new_a7("</a>")
|
||||
, Div_bgn_open = Bry_.new_a7("<div ")
|
||||
, Div_end = Bry_.new_a7("</div>")
|
||||
|
||||
, Img_bgn = Bry_.new_a7("<img src=\"")
|
||||
, Span_bgn_open = Bry_.new_a7("<span")
|
||||
@@ -47,7 +44,6 @@ public class Xoh_consts {
|
||||
, Code_bgn_closed = Bry_.new_a7("<code>")
|
||||
, Code_bgn_open = Bry_.new_a7("<code")
|
||||
, Code_end = Bry_.new_a7("</code>")
|
||||
, Title_atr = Bry_.new_a7("\" title=\"")
|
||||
, Id_atr = Bry_.new_a7(" id=\"")
|
||||
, Style_atr = Bry_.new_a7(" style=\"")
|
||||
, Atr_xowa_title_bry = Bry_.new_a7(Atr_xowa_title_str)
|
||||
|
||||
@@ -39,5 +39,6 @@ public class Xoh_img_mgr {
|
||||
itm.To_bfr(bfr);
|
||||
}
|
||||
}
|
||||
public static final byte[] Bry__html_uid = Bry_.new_a7("xoimg_");
|
||||
public static final String Str__html_uid = "xoimg_";
|
||||
public static final byte[] Bry__html_uid = Bry_.new_a7(Str__html_uid);
|
||||
}
|
||||
|
||||
@@ -46,13 +46,13 @@ public class Xoh_page_wtr_wkr {
|
||||
Bry_bfr page_bfr = Xoa_app_.Utl__bfr_mkr().Get_m001(); // NOTE: get separate page bfr to output page; do not reuse tmp_bfr b/c it will be used inside Fmt_do
|
||||
if (page_mode == Xopg_page_.Tid_html && wiki.App().Api_root().Html().Page().View_html_generates_hdump()) {
|
||||
Write_body(page_bfr, Xoh_wtr_ctx.Hdump, page);
|
||||
Write_page_by_tid(page_mode, bfr, mgr.Page_html_fmtr(), Html_utl.Escape_html_as_bry(page_bfr.To_bry_and_clear()));
|
||||
Write_page_by_tid(page_mode, bfr, mgr.Page_html_fmtr(), Gfh_utl.Escape_html_as_bry(page_bfr.To_bry_and_clear()));
|
||||
}
|
||||
else {
|
||||
Write_body(page_bfr, Xoh_wtr_ctx.Basic, page);
|
||||
Write_page_by_tid(view_mode, bfr, fmtr, page_bfr.To_bry_and_rls());
|
||||
if (page_mode == Xopg_page_.Tid_html) // if html, write page again, but wrap it in html skin this time
|
||||
Write_page_by_tid(page_mode, bfr, mgr.Page_html_fmtr(), Html_utl.Escape_html_as_bry(bfr.To_bry_and_clear()));
|
||||
Write_page_by_tid(page_mode, bfr, mgr.Page_html_fmtr(), Gfh_utl.Escape_html_as_bry(bfr.To_bry_and_clear()));
|
||||
wdata_lang_wtr.Page_(null);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,7 +23,7 @@ public class Xoh_page_wtr_wkr_ {
|
||||
public static byte[] Bld_page_content_sub(Xoae_app app, Xowe_wiki wiki, Xoae_page page, Bry_bfr tmp_bfr) {
|
||||
byte[] subpages = app.Html_mgr().Page_mgr().Subpages_bldr().Bld(wiki.Ns_mgr(), page.Ttl());
|
||||
byte[] page_content_sub = page.Html_data().Content_sub(); // contentSub exists; SEE: {{#isin}}
|
||||
byte[] redirect_msg = Xop_redirect_mgr.Bld_redirect_msg(app, wiki, page);
|
||||
byte[] redirect_msg = Xop_redirect_mgr.Bld_redirect_msg(app, wiki, page.Redirected_ttls());
|
||||
return Bry_.Add(subpages, page_content_sub, redirect_msg);
|
||||
}
|
||||
public static byte[] Bld_page_name(Bry_bfr tmp_bfr, Xoa_ttl ttl, byte[] display_ttl) {
|
||||
@@ -38,7 +38,7 @@ public class Xoh_page_wtr_wkr_ {
|
||||
public static void Bld_head_end(Bry_bfr html_bfr, Xoae_page page) {
|
||||
byte[] head_end = page.Html_data().Custom_head_end();
|
||||
if (head_end == null) return;
|
||||
int insert_pos = Bry_find_.Find_fwd(html_bfr.Bfr(), Html_tag_.Head_rhs);
|
||||
int insert_pos = Bry_find_.Find_fwd(html_bfr.Bfr(), Gfh_tag_.Head_rhs);
|
||||
if (insert_pos == Bry_find_.Not_found) {
|
||||
Gfo_usr_dlg_.Instance.Warn_many("", "", "could not find </head>");
|
||||
return;
|
||||
@@ -48,7 +48,7 @@ public class Xoh_page_wtr_wkr_ {
|
||||
public static void Bld_html_end(Bry_bfr html_bfr, Xoae_page page) {
|
||||
byte[] html_end = page.Html_data().Custom_html_end();
|
||||
if (html_end == null) return;
|
||||
int insert_pos = Bry_find_.Find_bwd(html_bfr.Bfr(), Html_tag_.Html_rhs, html_bfr.Len());
|
||||
int insert_pos = Bry_find_.Find_bwd(html_bfr.Bfr(), Gfh_tag_.Html_rhs, html_bfr.Len());
|
||||
if (insert_pos == Bry_find_.Not_found) {
|
||||
Gfo_usr_dlg_.Instance.Warn_many("", "", "could not find </html>");
|
||||
return;
|
||||
|
||||
@@ -43,9 +43,9 @@ public class Xohp_ctg_grp_mgr {
|
||||
grp_fmtr.Bld_bfr_many(bfr, categories_lbl, itm_mgr);
|
||||
}
|
||||
}
|
||||
class Xoh_ctg_itm_fmtr extends gplx.core.brys.Bfr_arg_base {
|
||||
class Xoh_ctg_itm_fmtr implements gplx.core.brys.Bfr_arg {
|
||||
public void Set(Xoae_page page, Bry_fmtr itm_fmtr) {this.page = page; this.itm_fmtr = itm_fmtr;} private Xoae_page page; Bry_fmtr itm_fmtr;
|
||||
@Override public void Bfr_arg__add(Bry_bfr bfr) {
|
||||
public void Bfr_arg__add(Bry_bfr bfr) {
|
||||
int ctgs_len = page.Category_list().length;
|
||||
Bry_bfr tmp_bfr = Xoa_app_.Utl__bfr_mkr().Get_b128();
|
||||
Bry_bfr tmp_href = Xoa_app_.Utl__bfr_mkr().Get_b128();
|
||||
|
||||
@@ -18,7 +18,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
package gplx.xowa.htmls.bridges.dbuis.fmtrs; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.bridges.*; import gplx.xowa.htmls.bridges.dbuis.*;
|
||||
import gplx.core.brys.fmtrs.*;
|
||||
import gplx.xowa.htmls.bridges.dbuis.tbls.*;
|
||||
public class Dbui_cells_fmtr extends gplx.core.brys.Bfr_arg_base {
|
||||
public class Dbui_cells_fmtr implements gplx.core.brys.Bfr_arg {
|
||||
private final Dbui_cell_fmtr cell_fmtr = new Dbui_cell_fmtr();
|
||||
private final Dbui_btn_fmtr btn_fmtr = new Dbui_btn_fmtr();
|
||||
private Dbui_btn_itm[] btns;
|
||||
@@ -30,7 +30,7 @@ public class Dbui_cells_fmtr extends gplx.core.brys.Bfr_arg_base {
|
||||
this.row_key = row_key; this.row_itm = row_itm;
|
||||
return this;
|
||||
}
|
||||
@Override public void Bfr_arg__add(Bry_bfr bfr) {
|
||||
public void Bfr_arg__add(Bry_bfr bfr) {
|
||||
fmtr.Bld_bfr_many(bfr, cell_fmtr.Init(row_key, row_itm), btn_fmtr.Init(row_key, btns));
|
||||
}
|
||||
private static final Bry_fmtr fmtr = Bry_fmtr.new_(String_.Concat_lines_nl_skip_last
|
||||
@@ -40,12 +40,12 @@ public class Dbui_cells_fmtr extends gplx.core.brys.Bfr_arg_base {
|
||||
, " </div>"
|
||||
), "vals", "btns");
|
||||
}
|
||||
class Dbui_cell_fmtr extends gplx.core.brys.Bfr_arg_base {
|
||||
class Dbui_cell_fmtr implements gplx.core.brys.Bfr_arg {
|
||||
private byte[] row_key; private Dbui_row_itm row_itm;
|
||||
private Dbui_val_fmtr val_fmtr;
|
||||
public void Ctor(Dbui_val_fmtr val_fmtr) {this.val_fmtr = val_fmtr;}
|
||||
public Dbui_cell_fmtr Init(byte[] row_key, Dbui_row_itm row_itm) {this.row_key = row_key; this.row_itm = row_itm; return this;}
|
||||
@Override public void Bfr_arg__add(Bry_bfr bfr) {
|
||||
public void Bfr_arg__add(Bry_bfr bfr) {
|
||||
Dbui_col_itm[] cols = row_itm.Tbl().Cols();
|
||||
Dbui_val_itm[] vals = row_itm.Vals(); int len = vals.length;
|
||||
for (int i = 0; i < len; ++i) {
|
||||
@@ -58,12 +58,12 @@ class Dbui_cell_fmtr extends gplx.core.brys.Bfr_arg_base {
|
||||
, " <div class='xo_cell'>~{html}</div>"
|
||||
), "row_key", "val_idx", "html");
|
||||
}
|
||||
class Dbui_btn_fmtr extends gplx.core.brys.Bfr_arg_base {
|
||||
class Dbui_btn_fmtr implements gplx.core.brys.Bfr_arg {
|
||||
private byte[] row_key; private Dbui_btn_itm[] btns;
|
||||
public Dbui_btn_fmtr Init(byte[] row_key, Dbui_btn_itm[] btns) {
|
||||
this.row_key = row_key; this.btns = btns; return this;
|
||||
}
|
||||
@Override public void Bfr_arg__add(Bry_bfr bfr) {
|
||||
public void Bfr_arg__add(Bry_bfr bfr) {
|
||||
int len = btns.length;
|
||||
Io_url img_dir = gplx.xowa.htmls.heads.Xoh_head_itm__dbui.Img_dir();
|
||||
for (int i = 0; i < len; ++i) {
|
||||
|
||||
@@ -33,10 +33,10 @@ public class Dbui_tbl_fmtr {
|
||||
, "</div>"
|
||||
), "tbl_key", "width", "origin", "delete_confirm_msg", "head_cells", "data_rows");
|
||||
}
|
||||
class Dbui_head_cell_fmtr extends gplx.core.brys.Bfr_arg_base {
|
||||
class Dbui_head_cell_fmtr implements gplx.core.brys.Bfr_arg {
|
||||
private Dbui_tbl_itm tbl;
|
||||
public Dbui_head_cell_fmtr Init(Dbui_tbl_itm tbl) {this.tbl = tbl; return this;}
|
||||
@Override public void Bfr_arg__add(Bry_bfr bfr) {
|
||||
public void Bfr_arg__add(Bry_bfr bfr) {
|
||||
Dbui_col_itm[] cols = tbl.Cols(); int len = cols.length;
|
||||
for (int i = 0; i < len; ++i) {
|
||||
Dbui_col_itm col = cols[i];
|
||||
@@ -49,13 +49,13 @@ class Dbui_head_cell_fmtr extends gplx.core.brys.Bfr_arg_base {
|
||||
, " <div class='xo_head xo_resizable_col' style='width:~{width}px;'>~{display}</div>"
|
||||
), "width", "display");
|
||||
}
|
||||
class Dbui_row_fmtr extends gplx.core.brys.Bfr_arg_base {
|
||||
class Dbui_row_fmtr implements gplx.core.brys.Bfr_arg {
|
||||
private final Dbui_cells_fmtr cells_fmtr = new Dbui_cells_fmtr();
|
||||
private final Dbui_val_fmtr val_fmtr = Dbui_val_fmtr_.new_view();
|
||||
private final Bry_bfr row_key_bfr = Bry_bfr.new_(255);
|
||||
private Dbui_tbl_itm tbl; private Dbui_row_itm[] rows;
|
||||
public Dbui_row_fmtr Init(Dbui_tbl_itm tbl, Dbui_row_itm[] rows) {this.tbl = tbl; this.rows = rows; return this;}
|
||||
@Override public void Bfr_arg__add(Bry_bfr bfr) {
|
||||
public void Bfr_arg__add(Bry_bfr bfr) {
|
||||
byte[] tbl_key = tbl.Key();
|
||||
int len = rows.length;
|
||||
cells_fmtr.Ctor(val_fmtr, tbl.View_btns());
|
||||
|
||||
@@ -21,17 +21,17 @@ import gplx.xowa.htmls.bridges.dbuis.tbls.*;
|
||||
public interface Dbui_val_fmtr {
|
||||
Dbui_val_fmtr Init(Dbui_col_itm col, byte[] row_id, Dbui_val_itm val);
|
||||
}
|
||||
class Dbui_val_fmtr__view extends gplx.core.brys.Bfr_arg_base implements Dbui_val_fmtr {
|
||||
class Dbui_val_fmtr__view implements gplx.core.brys.Bfr_arg, Dbui_val_fmtr {
|
||||
private Dbui_val_itm val;
|
||||
public Dbui_val_fmtr Init(Dbui_col_itm col, byte[] row_id, Dbui_val_itm val) {this.val = val; return this;}
|
||||
@Override public void Bfr_arg__add(Bry_bfr bfr) {
|
||||
public void Bfr_arg__add(Bry_bfr bfr) {
|
||||
bfr.Add(val.Html());
|
||||
}
|
||||
}
|
||||
class Dbui_val_fmtr__edit extends gplx.core.brys.Bfr_arg_base implements Dbui_val_fmtr {
|
||||
class Dbui_val_fmtr__edit implements gplx.core.brys.Bfr_arg, Dbui_val_fmtr {
|
||||
private Dbui_col_itm col; private byte[] row_id; private Dbui_val_itm val;
|
||||
public Dbui_val_fmtr Init(Dbui_col_itm col, byte[] row_id, Dbui_val_itm val) {this.col = col; this.row_id = row_id; this.val = val; return this;}
|
||||
@Override public void Bfr_arg__add(Bry_bfr bfr) {
|
||||
public void Bfr_arg__add(Bry_bfr bfr) {
|
||||
switch (col.Type()) {
|
||||
case Dbui_col_itm.Type_id_str: input_fmtr_str.Bld_bfr_many(bfr, col.Key(), col.Width(), val.Data(), row_id); break;
|
||||
case Dbui_col_itm.Type_id_text: textarea_fmtr_str.Bld_bfr_many(bfr, col.Key(), col.Width(), val.Data(), row_id); break;
|
||||
|
||||
@@ -23,6 +23,7 @@ import gplx.xowa.wikis.pages.*; import gplx.xowa.wikis.pages.skins.*;
|
||||
public class Xow_hdump_mgr__load {
|
||||
private final Xow_wiki wiki; private final Xoh_hzip_mgr hzip_mgr; private final Io_stream_zip_mgr zip_mgr;
|
||||
private final Xoh_page tmp_hpg; private final Bry_bfr tmp_bfr; private final Xowd_page_itm tmp_dbpg = new Xowd_page_itm();
|
||||
private Hash_adp_bry page_overrides;
|
||||
public Xow_hdump_mgr__load(Xow_wiki wiki, Xoh_hzip_mgr hzip_mgr, Io_stream_zip_mgr zip_mgr, Xoh_page tmp_hpg, Bry_bfr tmp_bfr) {
|
||||
this.wiki = wiki; this.hzip_mgr = hzip_mgr; this.zip_mgr = zip_mgr; this.tmp_hpg = tmp_hpg; this.tmp_bfr = tmp_bfr;
|
||||
this.make_mgr = new Xoh_make_mgr(wiki.App().Usr_dlg(), wiki.App().Fsys_mgr(), gplx.langs.htmls.encoders.Gfo_url_encoder_.Fsys_lnx, wiki.Domain_bry());
|
||||
@@ -36,12 +37,13 @@ public class Xow_hdump_mgr__load {
|
||||
}
|
||||
public boolean Load(Xoh_page hpg, Xoa_ttl ttl) {
|
||||
synchronized (tmp_dbpg) {
|
||||
if (page_overrides == null) page_overrides = Init_page_overrides(wiki);
|
||||
if (!Load__dbpg(wiki, tmp_dbpg.Clear(), hpg, ttl)) return Load__fail(hpg); // nothing in "page" table
|
||||
Xowd_db_file html_db = wiki.Data__core_mgr().Dbs__get_at(tmp_dbpg.Html_db_id());
|
||||
hpg.Init(hpg.Wiki(), hpg.Url(), ttl, tmp_dbpg.Id());
|
||||
if (!html_db.Tbl__html().Select_by_page(hpg)) return Load__fail(hpg); // nothing in "html_page" table
|
||||
if (!html_db.Tbl__html().Select_by_page(hpg)) return Load__fail(hpg); // nothing in "html_page" table
|
||||
byte[] src = Parse(hpg, hpg.Body_zip_tid(), hpg.Body_hzip_tid(), hpg.Body());
|
||||
hpg.Body_(make_mgr.Parse(src, hpg, hpg.Wiki()));
|
||||
hpg.Body_(src);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -49,8 +51,15 @@ public class Xow_hdump_mgr__load {
|
||||
private byte[] Parse(Xoh_page hpg, int zip_tid, int hzip_tid, byte[] src) {
|
||||
if (zip_tid > gplx.core.ios.Io_stream_.Tid_raw)
|
||||
src = zip_mgr.Unzip((byte)zip_tid, src);
|
||||
if (hzip_tid == Xoh_hzip_dict_.Hzip__v1)
|
||||
if (hzip_tid == Xoh_hzip_dict_.Hzip__v1) {
|
||||
byte[] page_override_src = (byte[])page_overrides.Get_by_bry(hpg.Ttl().Page_db());
|
||||
if (page_override_src != null) src = page_override_src;
|
||||
hpg.Section_mgr().Add(0, 2, Bry_.Empty, Bry_.Empty).Content_bgn_(0); // +1 to skip \n
|
||||
src = Decode_as_bry(tmp_bfr.Clear(), hpg, src, Bool_.N);
|
||||
hpg.Section_mgr().Set_content(hpg.Section_mgr().Len() - 1, src, src.length);
|
||||
}
|
||||
else
|
||||
src = make_mgr.Parse(src, hpg, hpg.Wiki());
|
||||
return src;
|
||||
}
|
||||
private void Fill_page(Xoae_page wpg, Xoh_page hpg) {
|
||||
@@ -79,4 +88,19 @@ public class Xow_hdump_mgr__load {
|
||||
if (redirect_id == -1) break;
|
||||
}
|
||||
}
|
||||
private static Hash_adp_bry Init_page_overrides(Xow_wiki wiki) {
|
||||
Hash_adp_bry rv = Hash_adp_bry.cs();
|
||||
Io_url[] page_urls = Io_mgr.Instance.QueryDir_fils(wiki.Fsys_mgr().Root_dir().GenSubDir_nest("data", "page"));
|
||||
int page_urls_len = page_urls.length;
|
||||
for (int i = 0; i < page_urls_len; ++i) {
|
||||
Io_url page_url = page_urls[i];
|
||||
byte[] page_raw = Io_mgr.Instance.LoadFilBry(page_url);
|
||||
int page_raw_len = page_raw.length;
|
||||
int page_nl = Bry_find_.Find_fwd(page_raw, Byte_ascii.Nl, 0, page_raw_len); if (page_nl == Bry_find_.Not_found) continue;
|
||||
byte[] page_ttl_bry = Bry_.Mid(page_raw, 0, page_nl);
|
||||
byte[] page_src_bry = Bry_.Mid(page_raw, page_nl + 1, page_raw_len);
|
||||
rv.Add_bry_obj(page_ttl_bry, page_src_bry);
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -35,7 +35,7 @@ public class Xow_hdump_mgr__load_tst {
|
||||
// ( "[[File:A.png|thumb|test_caption]]", String_.Concat_lines_nl_skip_last
|
||||
// ( "<div class=\"thumb tright\">"
|
||||
// , " <div id=\"xowa_file_div_0\" class=\"thumbinner\" xowa_img_style='0'>"
|
||||
// , " <a href=\"/wiki/File:A.png\" class=\"image\" xowa_title=\"A.png\"><img id=\"xowa_file_img_0\" alt=\"\" xowa_img='0' /></a>"
|
||||
// , " <a href=\"/wiki/File:A.png\" class=\"image\" xowa_title=\"A.png\"><img id=\"xoimg_0\" alt=\"\" xowa_img='0' /></a>"
|
||||
// , " <div class=\"thumbcaption\"><xowa_mgnf id='0'/>"
|
||||
// , " test_caption"
|
||||
// , " </div>"
|
||||
@@ -49,7 +49,7 @@ public class Xow_hdump_mgr__load_tst {
|
||||
// ( "[[File:A.oga|thumb|test_caption]]", String_.Concat_lines_nl_skip_last
|
||||
// ( "<div class=\"thumb tright\">"
|
||||
// , " <div id=\"xowa_file_div_0\" class=\"thumbinner\" xowa_img_style='0'>"
|
||||
// , " <div id=\"xowa_media_div\"><xowa_play id='0'/><xowa_info id='0'/>"
|
||||
// , " <div class=\"xowa_media_div\"><xowa_play id='0'/><xowa_info id='0'/>"
|
||||
// , " </div>"
|
||||
// , " <div class=\"thumbcaption\"><xowa_mgnf id='0'/>"
|
||||
// , " test_caption"
|
||||
@@ -64,10 +64,10 @@ public class Xow_hdump_mgr__load_tst {
|
||||
// ( "[[File:A.ogv|thumb|test_caption]]", String_.Concat_lines_nl_skip_last
|
||||
// ( "<div class=\"thumb tright\">"
|
||||
// , " <div id=\"xowa_file_div_0\" class=\"thumbinner\" xowa_img_style='0'>"
|
||||
// , " <div id=\"xowa_media_div\">"
|
||||
// , " <div class=\"xowa_media_div\">"
|
||||
// , " <div>"
|
||||
// , " <a href=\"/wiki/File:A.ogv\" class=\"image\" title=\"A.ogv\">"
|
||||
// , " <img id=\"xowa_file_img_0\" xowa_img='0' alt=\"\" />"
|
||||
// , " <img id=\"xoimg_0\" xowa_img='0' alt=\"\" />"
|
||||
// , " </a>"
|
||||
// , " </div><xowa_play id='0'/>"
|
||||
// , " </div>"
|
||||
@@ -93,7 +93,7 @@ public class Xow_hdump_mgr__load_tst {
|
||||
// , " <div xowa_gly_box_w='0'>"
|
||||
// , " <div class=\"thumb\" style=\"width: 150px;\">"
|
||||
// , " <div xowa_gly_img_pad='0'>"
|
||||
// , " <a href=\"/wiki/File:A.png\" class=\"image\" xowa_title=\"A.png\"><img id=\"xowa_file_img_0\" alt=\"\" xowa_img='0' /></a>"
|
||||
// , " <a href=\"/wiki/File:A.png\" class=\"image\" xowa_title=\"A.png\"><img id=\"xoimg_0\" alt=\"\" xowa_img='0' /></a>"
|
||||
// , " </div>"
|
||||
// , " </div>"
|
||||
// , " <div class=\"gallerytext\"><p>A1"
|
||||
|
||||
@@ -50,7 +50,7 @@ public class Xob_link_dump_cmd {
|
||||
tbl.Create_idx_2();
|
||||
conn.Env_vacuum();
|
||||
} catch (Exception e) {
|
||||
Tfds.Write(Err_.Message_gplx_full(e));
|
||||
Tfds.Dbg(Err_.Message_gplx_full(e));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@ import gplx.core.primitives.*; import gplx.core.net.*; import gplx.core.btries.*
|
||||
import gplx.langs.htmls.*; import gplx.xowa.langs.*; import gplx.xowa.langs.kwds.*;
|
||||
import gplx.xowa.wikis.domains.*;
|
||||
import gplx.xowa.parsers.*; import gplx.xowa.parsers.apos.*; import gplx.xowa.parsers.amps.*; import gplx.xowa.parsers.lnkes.*; import gplx.xowa.parsers.lists.*; import gplx.xowa.htmls.core.wkrs.lnkis.htmls.*; import gplx.xowa.parsers.tblws.*; import gplx.xowa.parsers.paras.*; import gplx.xowa.parsers.xndes.*; import gplx.xowa.parsers.lnkis.*; import gplx.xowa.parsers.miscs.*; import gplx.xowa.parsers.vnts.*; import gplx.xowa.parsers.htmls.*;
|
||||
import gplx.xowa.xtns.*; import gplx.xowa.xtns.dynamicPageList.*; import gplx.xowa.xtns.math.*; import gplx.xowa.xtns.cite.*; import gplx.xowa.htmls.core.hzips.*; import gplx.xowa.parsers.hdrs.*;
|
||||
import gplx.xowa.xtns.*; import gplx.xowa.xtns.dynamicPageList.*; import gplx.xowa.xtns.math.*; import gplx.xowa.xtns.cites.*; import gplx.xowa.htmls.core.hzips.*; import gplx.xowa.parsers.hdrs.*;
|
||||
import gplx.xowa.htmls.core.*;
|
||||
import gplx.xowa.htmls.core.wkrs.hdrs.*; import gplx.xowa.htmls.core.wkrs.lnkes.*;
|
||||
public class Xoh_html_wtr {
|
||||
@@ -114,18 +114,18 @@ public class Xoh_html_wtr {
|
||||
if (literal_apos > 0)
|
||||
bfr.Add_byte_repeat(Byte_ascii.Apos, literal_apos);
|
||||
switch (apos.Apos_cmd()) {
|
||||
case Xop_apos_tkn_.Cmd_b_bgn: bfr.Add(Html_tag_.B_lhs); break;
|
||||
case Xop_apos_tkn_.Cmd_b_end: bfr.Add(Html_tag_.B_rhs); break;
|
||||
case Xop_apos_tkn_.Cmd_i_bgn: bfr.Add(Html_tag_.I_lhs); break;
|
||||
case Xop_apos_tkn_.Cmd_i_end: bfr.Add(Html_tag_.I_rhs); break;
|
||||
case Xop_apos_tkn_.Cmd_bi_bgn: bfr.Add(Html_tag_.B_lhs).Add(Html_tag_.I_lhs); break;
|
||||
case Xop_apos_tkn_.Cmd_ib_end: bfr.Add(Html_tag_.I_rhs).Add(Html_tag_.B_rhs); break;
|
||||
case Xop_apos_tkn_.Cmd_ib_bgn: bfr.Add(Html_tag_.I_lhs).Add(Html_tag_.B_lhs); break;
|
||||
case Xop_apos_tkn_.Cmd_bi_end: bfr.Add(Html_tag_.B_rhs).Add(Html_tag_.I_rhs);; break;
|
||||
case Xop_apos_tkn_.Cmd_bi_end__b_bgn: bfr.Add(Html_tag_.B_rhs).Add(Html_tag_.I_rhs).Add(Html_tag_.B_lhs); break;
|
||||
case Xop_apos_tkn_.Cmd_ib_end__i_bgn: bfr.Add(Html_tag_.I_rhs).Add(Html_tag_.B_rhs).Add(Html_tag_.I_lhs); break;
|
||||
case Xop_apos_tkn_.Cmd_b_end__i_bgn: bfr.Add(Html_tag_.B_rhs).Add(Html_tag_.I_lhs); break;
|
||||
case Xop_apos_tkn_.Cmd_i_end__b_bgn: bfr.Add(Html_tag_.I_rhs).Add(Html_tag_.B_lhs); break;
|
||||
case Xop_apos_tkn_.Cmd_b_bgn: bfr.Add(Gfh_tag_.B_lhs); break;
|
||||
case Xop_apos_tkn_.Cmd_b_end: bfr.Add(Gfh_tag_.B_rhs); break;
|
||||
case Xop_apos_tkn_.Cmd_i_bgn: bfr.Add(Gfh_tag_.I_lhs); break;
|
||||
case Xop_apos_tkn_.Cmd_i_end: bfr.Add(Gfh_tag_.I_rhs); break;
|
||||
case Xop_apos_tkn_.Cmd_bi_bgn: bfr.Add(Gfh_tag_.B_lhs).Add(Gfh_tag_.I_lhs); break;
|
||||
case Xop_apos_tkn_.Cmd_ib_end: bfr.Add(Gfh_tag_.I_rhs).Add(Gfh_tag_.B_rhs); break;
|
||||
case Xop_apos_tkn_.Cmd_ib_bgn: bfr.Add(Gfh_tag_.I_lhs).Add(Gfh_tag_.B_lhs); break;
|
||||
case Xop_apos_tkn_.Cmd_bi_end: bfr.Add(Gfh_tag_.B_rhs).Add(Gfh_tag_.I_rhs);; break;
|
||||
case Xop_apos_tkn_.Cmd_bi_end__b_bgn: bfr.Add(Gfh_tag_.B_rhs).Add(Gfh_tag_.I_rhs).Add(Gfh_tag_.B_lhs); break;
|
||||
case Xop_apos_tkn_.Cmd_ib_end__i_bgn: bfr.Add(Gfh_tag_.I_rhs).Add(Gfh_tag_.B_rhs).Add(Gfh_tag_.I_lhs); break;
|
||||
case Xop_apos_tkn_.Cmd_b_end__i_bgn: bfr.Add(Gfh_tag_.B_rhs).Add(Gfh_tag_.I_lhs); break;
|
||||
case Xop_apos_tkn_.Cmd_i_end__b_bgn: bfr.Add(Gfh_tag_.I_rhs).Add(Gfh_tag_.B_lhs); break;
|
||||
case Xop_apos_tkn_.Cmd_nil: break;
|
||||
default: throw Err_.new_unhandled(apos.Apos_cmd());
|
||||
}
|
||||
@@ -466,9 +466,9 @@ public class Xoh_html_wtr {
|
||||
break;
|
||||
default:
|
||||
byte[] tag_name = sub_xnde.Tag().Name_bry();
|
||||
bfr.Add(Html_entity_.Lt_bry).Add(tag_name);
|
||||
bfr.Add(Gfh_entity_.Lt_bry).Add(tag_name);
|
||||
if (xnde.Atrs_bgn() > Xop_tblw_wkr.Atrs_ignore_check) Xnde_atrs(sub_xnde.Tag().Id(), hctx, src, sub_xnde.Atrs_bgn(), sub_xnde.Atrs_end(), xnde.Atrs_ary(), bfr);
|
||||
bfr.Add(Html_entity_.Gt_bry);
|
||||
bfr.Add(Gfh_entity_.Gt_bry);
|
||||
break;
|
||||
}
|
||||
Xnde_subs_escape(ctx, hctx, bfr, src, sub_xnde, amp_enable, false);
|
||||
|
||||
@@ -40,17 +40,17 @@ public class Xoh_html_wtr_escaper {
|
||||
}
|
||||
}
|
||||
}
|
||||
bfr.Add(Html_entity_.Lt_bry);
|
||||
bfr.Add(Gfh_entity_.Lt_bry);
|
||||
break;
|
||||
case Byte_ascii.Gt:
|
||||
bfr.Add(Html_entity_.Gt_bry);
|
||||
bfr.Add(Gfh_entity_.Gt_bry);
|
||||
break;
|
||||
case Byte_ascii.Amp:
|
||||
if (interpret_amp) {
|
||||
int text_bgn = i + 1; // i is &; i + 1 is first char after amp
|
||||
Object o = (text_bgn < end) ? amp_trie.Match_bgn(src, text_bgn, end) : null; // check if this is a valid &; note must check that text_bgn < end or else arrayIndex error; occurs when src is just "&"; DATE:2013-12-19
|
||||
if (o == null) // invalid; EX: "a&b"; "&bad;"; "&#letters;";
|
||||
bfr.Add(Html_entity_.Amp_bry); // escape & and continue
|
||||
bfr.Add(Gfh_entity_.Amp_bry); // escape & and continue
|
||||
else { // is either (1) a name or (2) an ncr (hex/dec)
|
||||
Xop_amp_trie_itm itm = (Xop_amp_trie_itm)o;
|
||||
int match_pos = amp_trie.Match_pos();
|
||||
@@ -70,17 +70,17 @@ public class Xoh_html_wtr_escaper {
|
||||
i = end_pos - 1;
|
||||
}
|
||||
else // parse failed; escape and continue
|
||||
bfr.Add(Html_entity_.Amp_bry);
|
||||
bfr.Add(Gfh_entity_.Amp_bry);
|
||||
break;
|
||||
default: throw Err_.new_unhandled(itm_tid);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
bfr.Add(Html_entity_.Amp_bry);
|
||||
bfr.Add(Gfh_entity_.Amp_bry);
|
||||
break;
|
||||
case Byte_ascii.Quote:
|
||||
bfr.Add(Html_entity_.Quote_bry);
|
||||
bfr.Add(Gfh_entity_.Quote_bry);
|
||||
break;
|
||||
default:
|
||||
bfr.Add_byte(b);
|
||||
@@ -103,7 +103,7 @@ public class Xoh_html_wtr_escaper {
|
||||
if ( tag_is_bgn // <nowiki < found
|
||||
|| (i + nowiki_name_len + 2 > end) // not enough chars for "/nowiki>"
|
||||
|| src[i + 1] != Byte_ascii.Slash // /
|
||||
|| !Bry_.Eq(src, i + 2, i + 2 + nowiki_name_len, nowiki_name) // nowiki
|
||||
|| !Bry_.Eq(src, i + 2, i + 2 + nowiki_name_len, nowiki_name) // nowiki
|
||||
|| src[i + 2 + nowiki_name_len] != Byte_ascii.Gt // >
|
||||
) return Bry_find_.Not_found;
|
||||
end_lt = i;
|
||||
|
||||
@@ -18,7 +18,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
package gplx.xowa.htmls.core.htmls; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*;
|
||||
import org.junit.*;
|
||||
public class Xoh_html_wtr_tst {
|
||||
private Xop_fxt fxt = new Xop_fxt();
|
||||
private final Xop_fxt fxt = new Xop_fxt();
|
||||
@After public void term() {fxt.Init_para_n_(); fxt.Reset();}
|
||||
@Test public void Hr_basic() {fxt.Test_parse_page_wiki_str("----" , "<hr/>");}
|
||||
@Test public void Hr_extended() {fxt.Test_parse_page_wiki_str("--------" , "<hr/>");}
|
||||
|
||||
@@ -65,9 +65,9 @@ public class Xoh_tidy_mgr implements GfoInvkAble {
|
||||
}
|
||||
public static boolean Tidy_unwrap(Bry_bfr bfr) {
|
||||
byte[] bfr_bry = bfr.Bfr();
|
||||
int find = Bry_find_.Find_fwd(bfr_bry, Html_tag_.Body_lhs); if (find == Bry_find_.Not_found) return false;
|
||||
bfr.Delete_rng_to_bgn(find + Html_tag_.Body_lhs.length);
|
||||
find = Bry_find_.Find_bwd(bfr_bry, Html_tag_.Body_rhs, bfr.Len()); if (find == Bry_find_.Not_found) return false;
|
||||
int find = Bry_find_.Find_fwd(bfr_bry, Gfh_tag_.Body_lhs); if (find == Bry_find_.Not_found) return false;
|
||||
bfr.Delete_rng_to_bgn(find + Gfh_tag_.Body_lhs.length);
|
||||
find = Bry_find_.Find_bwd(bfr_bry, Gfh_tag_.Body_rhs, bfr.Len()); if (find == Bry_find_.Not_found) return false;
|
||||
bfr.Delete_rng_to_end(find);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -38,7 +38,7 @@ public class Xoh_anchor_kv_bldr {
|
||||
tmp_bfr.Add_byte(has_qarg ? Byte_ascii.Amp : Byte_ascii.Question);
|
||||
tmp_bfr.Add(key);
|
||||
tmp_bfr.Add_byte(Byte_ascii.Eq);
|
||||
tmp_bfr.Add(Html_utl.Escape_for_atr_val_as_bry(apos_bfr, Byte_ascii.Apos, bry));
|
||||
tmp_bfr.Add(Gfh_utl.Escape_for_atr_val_as_bry(apos_bfr, Byte_ascii.Apos, bry));
|
||||
return this;
|
||||
}
|
||||
public byte[] Bld_to_bry() {
|
||||
|
||||
@@ -32,7 +32,7 @@ public class Xoh_lnki_bldr {
|
||||
img_pos_is_left = true;
|
||||
return this;
|
||||
}
|
||||
public Xoh_lnki_bldr Id_(byte[] v) {this.id = Html_utl.Escape_for_atr_val_as_bry(tmp_bfr, Byte_ascii.Apos, v); return this;}
|
||||
public Xoh_lnki_bldr Id_(byte[] v) {this.id = Gfh_utl.Escape_for_atr_val_as_bry(tmp_bfr, Byte_ascii.Apos, v); return this;}
|
||||
public Xoh_lnki_bldr Href_(Xow_wiki wiki, byte[] bry) {return Href_(wiki.Domain_bry(), wiki.Ttl_parse(bry));}
|
||||
public Xoh_lnki_bldr Href_(byte[] domain_bry, Xoa_ttl ttl) {
|
||||
href_wtr.Build_to_bfr(tmp_bfr, app, Xoh_wtr_ctx.Mode_popup, domain_bry, ttl);
|
||||
@@ -40,7 +40,7 @@ public class Xoh_lnki_bldr {
|
||||
return this;
|
||||
}
|
||||
public Xoh_lnki_bldr Title_(byte[] title) {
|
||||
this.title = Html_utl.Escape_for_atr_val_as_bry(tmp_bfr, Byte_ascii.Apos, title);
|
||||
this.title = Gfh_utl.Escape_for_atr_val_as_bry(tmp_bfr, Byte_ascii.Apos, title);
|
||||
return this;
|
||||
}
|
||||
public Xoh_lnki_bldr Img_pos_is_left_(boolean v) {this.img_pos_is_left = v; return this;}
|
||||
@@ -52,7 +52,7 @@ public class Xoh_lnki_bldr {
|
||||
return this;
|
||||
}
|
||||
public Xoh_lnki_bldr Caption_(byte[] text) {
|
||||
this.caption = Html_utl.Escape_html_as_bry(tmp_bfr, text, Bool_.Y, Bool_.Y, Bool_.Y, Bool_.Y, Bool_.Y);
|
||||
this.caption = Gfh_utl.Escape_html_as_bry(tmp_bfr, text, Bool_.Y, Bool_.Y, Bool_.Y, Bool_.Y, Bool_.Y);
|
||||
return this;
|
||||
}
|
||||
public byte[] Bld_to_bry() {
|
||||
|
||||
@@ -29,6 +29,6 @@ public class Xoh_lnki_wtr_utl {
|
||||
return tmp_bfr.To_bry_and_clear();
|
||||
}
|
||||
public byte[] Bld_title(byte[] text) {
|
||||
return gplx.langs.htmls.Html_utl.Escape_html_as_bry(tmp_bfr, text, Bool_.N, Bool_.N, Bool_.N, Bool_.Y, Bool_.Y);
|
||||
return gplx.langs.htmls.Gfh_utl.Escape_html_as_bry(tmp_bfr, text, Bool_.N, Bool_.N, Bool_.N, Bool_.Y, Bool_.Y);
|
||||
}
|
||||
}
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user