v3.3.4 v2.11.2.1
gnosygnu 9 years ago
parent b990ec409f
commit d9f45cec19

@ -212,10 +212,17 @@ class TfdsMsgBldr {
}
for (int i = 0; i < list.Count(); i++) {
TfdsEqAryItm itm = (TfdsEqAryItm)list.Get_at(i);
String eq_str = itm.Eq() ? "==" : "";
if (!itm.Eq()) {
// if (lhsLenMax < 8 )
// eq_str = "!=";
// else
eq_str = "\n!= ";
}
sb.Add_fmt_line("{0}: {1} {2} {3}"
, Int_.To_str_pad_bgn_zero(itm.Idx(), 4)
, String_.PadBgn(itm.Lhs(), lhsLenMax, " ")
, itm.Eq() ? "==" : "!="
, eq_str
, String_.PadBgn(itm.Rhs(), rhsLenMax, " ")
);
}

@ -16,7 +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;
import java.math.BigDecimal; import java.math.MathContext; import java.math.RoundingMode; public class Decimal_adp_ {
import java.math.BigDecimal; import java.math.MathContext; import java.math.RoundingMode; import java.text.DecimalFormat;
import java.text.NumberFormat;
import java.text.ParseException;
import java.util.Locale;
public class Decimal_adp_ {
public static final Class<?> Cls_ref_type = Decimal_adp.class;
public static Decimal_adp as_(Object obj) {return obj instanceof Decimal_adp ? (Decimal_adp)obj : null;}
public static final Decimal_adp Zero = new Decimal_adp(0);
@ -53,5 +57,14 @@ import java.math.BigDecimal; import java.math.MathContext; import java.math.Roun
public static Decimal_adp divide_(long lhs, long rhs) { return new Decimal_adp(new BigDecimal(lhs).divide(new BigDecimal(rhs), Gplx_rounding_context)); } public static Decimal_adp int_(int v) {return new Decimal_adp(new BigDecimal(v));} public static Decimal_adp long_(long v) {return new Decimal_adp(new BigDecimal(v));}
public static Decimal_adp float_(float v) {return new Decimal_adp(new BigDecimal(v));} public static Decimal_adp double_(double v) {return new Decimal_adp(new BigDecimal(v));}
public static Decimal_adp double_thru_str_(double v) {return new Decimal_adp(BigDecimal.valueOf(v));}
public static Decimal_adp db_(Object v) {return new Decimal_adp((BigDecimal)v);} public static Decimal_adp parse(String raw) {return new Decimal_adp(new BigDecimal(raw));} public static Decimal_adp pow_10_(int v) {return new Decimal_adp(new BigDecimal(1).scaleByPowerOfTen(v));}
public static Decimal_adp db_(Object v) {return new Decimal_adp((BigDecimal)v);} public static Decimal_adp parse(String raw) {
try {
DecimalFormat nf = (DecimalFormat)NumberFormat.getInstance(Locale.getDefault());
nf.setParseBigDecimal(true);
BigDecimal bd = (BigDecimal)nf.parse(raw);
return new Decimal_adp(bd);
} catch (ParseException e) {
throw Err_.new_("Decimal_adp_", "parse to decimal failed", "raw", raw);
}
} public static Decimal_adp pow_10_(int v) {return new Decimal_adp(new BigDecimal(1).scaleByPowerOfTen(v));}
public static final MathContext RoundDownContext = new MathContext(0, RoundingMode.DOWN); public static final MathContext Gplx_rounding_context = new MathContext(14, RoundingMode.HALF_UP); // changed from 28 to 14; DATE:2015-07-31 }

@ -20,6 +20,18 @@ public class Object_ {
public static final String Cls_val_name = "Object";
public static final Object[] Ary_empty = new Object[0];
public static Object[] Ary(Object... ary) {return ary;}
public static Object[] Ary_add(Object[] lhs, Object[] rhs) {
int lhs_len = lhs.length, rhs_len = rhs.length;
if (lhs_len == 0) return rhs;
else if (rhs_len == 0) return lhs;
int rv_len = lhs_len + rhs_len;
Object[] rv = new Object[rv_len];
for (int i = 0; i < lhs_len; ++i)
rv[i] = lhs[i];
for (int i = lhs_len; i < rv_len; ++i)
rv[i] = rhs[i - lhs_len];
return rv;
}
public static boolean Eq(Object lhs, Object rhs) {
if (lhs == null && rhs == null) return true;
else if (lhs == null || rhs == null) return false;

@ -41,7 +41,7 @@ public class String_ implements GfoInvkAble {
? null
: new String(v, bgn, end - bgn, "UTF-8");
}
catch (Exception e) {throw Err_.new_exc(e, "core", "unsupported encoding");}
catch (Exception e) {Err_.Noop(e); throw Err_.new_("core", "unsupported encoding", "bgn", bgn, "end", end);}
}
public static String new_u8__by_len(byte[] v, int bgn, int len) {
int v_len = v.length;
@ -115,7 +115,7 @@ public class String_ implements GfoInvkAble {
return false;
}
public static boolean EqNot(String lhs, String rhs) {return !Object_.Eq(lhs, rhs);}
public static boolean EqEmpty(String lhs, String rhs) {return lhs.equals("");}
public static boolean EqEmpty(String lhs) {return lhs.equals("");}
public static String IfNullOrEmpty(String s, String or) {return s == null || s.length() == 0 ? or : s;}
public static int Compare(String lhs, String rhs) {return lhs.compareTo(rhs);} // NOTE: Compare instead of compareTo b/c javafy lowercases compareTo
public static int Compare_ignoreCase(String lhs, String rhs) {

@ -286,8 +286,13 @@ public class Bry_ {
return String_.new_u8(ary);
}
public static byte[] Mid_safe(byte[] src, int bgn, int end) {
try {return Mid(src, bgn, end);}
catch (Exception e) {Err_.Noop(e); return Bry_.Add_w_dlm(Byte_ascii.Space, Bry_.new_by_int(bgn), Bry_.new_by_int(end));}
if (src == null) return null;
int src_len = src.length;
if (bgn < 0) bgn = 0;
if (end >= src_len) end = src_len;
if (bgn > end) bgn = end;
else if (end < bgn) end = bgn;
return Mid(src, bgn, end);
}
public static byte[] Mid(byte[] src, int bgn) {return Mid(src, bgn, src.length);}
public static byte[] Mid_or(byte[] src, int bgn, int end, byte[] or) {

@ -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;
public class Bry_rdr {
public class Bry_rdr_old {
private byte[] scope = Bry_.Empty;
public byte[] Src() {return src;} protected byte[] src;
public int Src_len() {return src_len;} protected int src_len;
@ -26,7 +26,7 @@ public class Bry_rdr {
this.src = src; this.src_len = src.length; this.pos = pos;
this.scope = scope;
}
public int Pos() {return pos;} public Bry_rdr Pos_(int v) {this.pos = v; return this;} protected int pos;
public int Pos() {return pos;} public Bry_rdr_old Pos_(int v) {this.pos = v; return this;} protected int pos;
public void Pos_add(int v) {pos += v;}
public boolean Pos_is_eos() {return pos == src_len;}
public boolean Pos_is_reading() {return pos < src_len;}
@ -106,7 +106,7 @@ public class Bry_rdr {
byte[] double_bry = Read_bry_to(to_char);
return Double_.parse(String_.new_a7(double_bry)); // double will never have utf8
}
@gplx.Virtual public Bry_rdr Skip_ws() {
@gplx.Virtual public Bry_rdr_old Skip_ws() {
while (pos < src_len) {
switch (src[pos]) {
case Byte_ascii.Tab: case Byte_ascii.Nl: case Byte_ascii.Cr: case Byte_ascii.Space:
@ -118,7 +118,7 @@ public class Bry_rdr {
}
return this;
}
public Bry_rdr Skip_alpha_num_under() {
public Bry_rdr_old Skip_alpha_num_under() {
while (pos < src_len) {
switch (src[pos]) {
case Byte_ascii.Num_0: case Byte_ascii.Num_1: case Byte_ascii.Num_2: case Byte_ascii.Num_3: case Byte_ascii.Num_4:

@ -17,13 +17,34 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx;
public class Gfo_usr_dlg_ {
private static Gfo_usr_dlg_base test__list, test__show;
public static Gfo_usr_dlg Instance = Gfo_usr_dlg_noop.Instance; // NOTE: global instance which can be reassigned
public static final Gfo_usr_dlg Noop = Gfo_usr_dlg_noop.Instance;
public static Gfo_usr_dlg__gui Test__list__init() {
if (test__list == null)
test__list = new Gfo_usr_dlg_base(Gfo_usr_dlg__log_.Noop, Gfo_usr_dlg__gui_.Test);
Gfo_usr_dlg__gui_.Test.Clear();
Instance = test__list;
return Gfo_usr_dlg__gui_.Test;
}
public static String Test__list__term__get_1st() {
Instance = Noop;
String[] rv = ((Gfo_usr_dlg__gui_test)test__list.Gui_wkr()).Warns().To_str_ary_and_clear();
return rv.length == 0 ? "" : rv[0];
}
public static void Test__show__init() {
if (test__show == null)
test__show = new Gfo_usr_dlg_base(Gfo_usr_dlg__log_.Noop, Gfo_usr_dlg__gui_.Console);
Instance = test__show;
}
public static void Test__show__term() {
Instance = Noop;
}
public static Gfo_usr_dlg Test() {
if (test == null)
test = new Gfo_usr_dlg_base(Gfo_usr_dlg__log_.Noop, Gfo_usr_dlg__gui_.Test);
return test;
} private static Gfo_usr_dlg_base test;
if (test__list == null)
test__list = new Gfo_usr_dlg_base(Gfo_usr_dlg__log_.Noop, Gfo_usr_dlg__gui_.Test);
return test__list;
}
public static Gfo_usr_dlg Test_console() {
if (test_console == null)
test_console = new Gfo_usr_dlg_base(Gfo_usr_dlg__log_.Noop, Gfo_usr_dlg__gui_.Console);

@ -18,13 +18,12 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
package gplx;
import gplx.core.strings.*;
public class Gfo_usr_dlg__gui_test implements Gfo_usr_dlg__gui {
public String[] Xto_str_ary() {return msgs.To_str_ary();}
public String[] Xto_str_ary_and_clear() {String[] rv = msgs.To_str_ary(); this.Clear(); return rv;}
public List_adp Warns() {return warns;}
public String_ring Prog_msgs() {return ring;} String_ring ring = new String_ring().Max_(0);
public List_adp Warns() {return warns;} private final List_adp warns = List_adp_.new_();
public List_adp Msgs() {return msgs;} private final List_adp msgs = List_adp_.new_();
public String_ring Prog_msgs() {return ring;} private final String_ring ring = new String_ring().Max_(0);
public void Clear() {msgs.Clear(); warns.Clear();}
public void Write_prog(String text) {msgs.Add(text);} List_adp msgs = List_adp_.new_();
public void Write_prog(String text) {msgs.Add(text);}
public void Write_note(String text) {msgs.Add(text);}
public void Write_warn(String text) {warns.Add(text);} List_adp warns = List_adp_.new_();
public void Write_warn(String text) {warns.Add(text);}
public void Write_stop(String text) {msgs.Add(text);}
}

@ -29,7 +29,7 @@ abstract class Meta_fld_wkr__base {
public void Reg(Btrie_slim_mgr trie) {
trie.Add_obj(hook, this);
}
@gplx.Virtual public void Match(Bry_rdr rdr, Meta_fld_itm fld) {
@gplx.Virtual public void Match(Bry_rdr_old rdr, Meta_fld_itm fld) {
for (int i = 0; i < words_len; ++i) {
rdr.Skip_ws();
byte[] word = words_ary[i];
@ -88,7 +88,7 @@ class Meta_fld_wkr__autonumber extends Meta_fld_wkr__base {
}
class Meta_fld_wkr__default extends Meta_fld_wkr__base {
public Meta_fld_wkr__default() {this.Ctor(Hook);}
@Override public void Match(Bry_rdr rdr, Meta_fld_itm fld) {
@Override public void Match(Bry_rdr_old rdr, Meta_fld_itm fld) {
Object default_val = null;
rdr.Skip_ws();
byte[] src = rdr.Src();

@ -18,7 +18,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
package gplx.dbs.metas.parsers; import gplx.*; import gplx.dbs.*; import gplx.dbs.metas.*;
import gplx.core.brys.*; import gplx.core.btries.*;
public class Meta_parser__fld {
public Meta_type_itm Parse_type(Bry_rdr rdr) {
public Meta_type_itm Parse_type(Bry_rdr_old rdr) {
rdr.Skip_ws();
Object type_obj = type_trie.Match_bgn(rdr.Src(), rdr.Pos(), rdr.Src_len());
if (type_obj == null) throw Err_.new_wo_type("invalid fld type", "snip", rdr.Mid_by_len_safe(40));

@ -17,7 +17,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.dbs.metas.parsers; import gplx.*; import gplx.dbs.*; import gplx.dbs.metas.*;
import gplx.core.brys.*;
public class Sql_bry_rdr extends Bry_rdr { public byte[] Read_sql_identifier() {
public class Sql_bry_rdr extends Bry_rdr_old { public byte[] Read_sql_identifier() {
this.Skip_ws();
int bgn = pos, end = -1;
if (pos == src_len) return null;
@ -33,7 +33,7 @@ public class Sql_bry_rdr extends Bry_rdr { public byte[] Read_sql_identifier()
}
return Bry_.Mid(src, bgn, end);
}
@Override public Bry_rdr Skip_ws() {
@Override public Bry_rdr_old Skip_ws() {
byte b_0 = pos < src_len ? src[pos] : Byte_ascii.Null;
byte bgn_1 = Byte_ascii.Null;
byte[] end_bry = null;

@ -17,7 +17,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.core.brys; import gplx.*; import gplx.core.*;
public class Bit_ {
public static String XtoBitStr(int val) {
public static String ToBitStr(int val) {
boolean[] bits = new boolean[8];
int idx = 7;
while (val > 0) {
@ -30,56 +30,7 @@ public class Bit_ {
rv[i] = bits[i] ? Byte_ascii.Num_1 : Byte_ascii.Num_0;
return String_.new_a7(rv);
}
public static int Get_flag(int i) {return Base2_ary[i];}
public static int[] Bld_pow_ary(int... seg_ary) {
int seg_ary_len = seg_ary.length;
int pow = 0;
int[] rv = new int[seg_ary_len];
for (int i = seg_ary_len - 1; i > -1; i--) {
rv[i] = Base2_ary[pow];
pow += seg_ary[i];
}
return rv;
}
public static int Xto_int(int[] pow_ary, int[] val_ary) {
int pow_ary_last = pow_ary.length - 1;
int val = 0;
for (int i = pow_ary_last; i > -1; i--)
val += pow_ary[i] * val_ary[i];
return val;
}
public static int[] Xto_intAry(int[] pow_ary, int v) {
int[] rv = new int[pow_ary.length];
Xto_intAry(rv, pow_ary, v);
return rv;
}
public static void Xto_intAry(int[] rv, int[] pow_ary, int v) {
int pow_ary_len = pow_ary.length;
int rv_len = rv.length;
for (int i = 0; i < pow_ary_len; i++) {
if (i >= rv_len) break;
rv[i] = v / pow_ary[i];
int factor = pow_ary[i] * rv[i];
v = factor == 0 ? v : (v % factor); // NOTE: if 0, do not do modulus or else div by zero
}
}
public static byte Xto_byte(byte[] pow_ary, byte... val_ary) {
int pow_ary_last = pow_ary.length - 1;
int val = 0;
for (int i = pow_ary_last; i > -1; --i)
val += pow_ary[i] * val_ary[i];
return (byte)val;
}
public static void Xto_bry(byte[] rv, byte[] pow_ary, byte val) {
int pow_ary_len = pow_ary.length;
int rv_len = rv.length;
for (int i = 0; i < pow_ary_len; i++) {
if (i >= rv_len) break;
rv[i] = (byte)(val / pow_ary[i]);
int factor = pow_ary[i] * rv[i];
val = (byte)(factor == 0 ? val : (val % factor)); // NOTE: if 0, do not do modulus or else div by zero
}
}
public static int Get_flag(int i) {return Int_flag_bldr_.Base2_ary[i];}
public static int Shift_lhs(int val, int shift) {return val << shift;}
public static int Shift_rhs(int val, int shift) {return val >> shift;}
public static int Shift_lhs_to_int(int[] shift_ary, int... val_ary) {
@ -101,24 +52,4 @@ public class Bit_ {
val -= (itm << shift);
}
}
public static int Xto_int_date_short(int[] val_ary) {
val_ary[0] -= 1900;
return Xto_int(Pow_ary_date_short, val_ary);
}
public static void Xto_date_short_int_ary(int[] rv, int v) {
Xto_intAry(rv, Pow_ary_date_short, v);
rv[0] += 1900;
}
public static DateAdp Xto_date_short(int v) {
int[] rv = new int[Pow_ary_date_short.length];
Xto_date_short_int_ary(rv, v);
return DateAdp_.seg_(rv);
}
private static final int[] Pow_ary_date_short = new int[] {1048576, 65536, 2048, 64, 1}; // yndhm -> 12,4,5,5,6
private static final int[] Base2_ary = new int[]
{ 1, 2, 4, 8, 16, 32, 64, 128
, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768
, 65536, 131072, 262144, 524288, 1048576, 2097152, 4194304, 8388608
, 16777216, 33554432, 67108864, 134217728, 268435456, 536870912, 1073741824, 0
};
}

@ -25,48 +25,7 @@ public class Bit__tst {
tst_XtoBitStr( 2, "00000010");
tst_XtoBitStr( 3, "00000011");
tst_XtoBitStr(255, "11111111");
} void tst_XtoBitStr(int val, String expd) {Tfds.Eq(expd, Bit_.XtoBitStr(val));}
@Test public void Bld_pow_ary() {
tst_Bld_pow_ary(ary_(1, 1, 1, 1), ary_(8, 4, 2, 1));
tst_Bld_pow_ary(ary_(3, 2) , ary_(4, 1));
} void tst_Bld_pow_ary(int[] seg_ary, int[] expd) {Tfds.Eq_ary_str(expd, Bit_.Bld_pow_ary(seg_ary));}
@Test public void Xto_int() {
tst_Xto_int(ary_(1, 1, 1, 1) , ary_(1, 1, 1, 1), 15);
tst_Xto_int(ary_(1, 1, 1, 1) , ary_(0, 0, 0, 0), 0);
tst_Xto_int(ary_(1, 1, 1, 1) , ary_(1, 0, 0, 1), 9);
tst_Xto_int(ary_(1, 1, 1, 1) , ary_(0, 1, 1, 0), 6);
tst_Xto_int(ary_(3, 2) , ary_(7, 3) , 31);
tst_Xto_int(ary_(3, 2, 1) , ary_(7, 3, 1) , 63);
tst_Xto_int(ary_(11, 4, 5, 5, 6), ary_(2012, 6, 3, 23, 17), 2110135761);
tst_Xto_int(ary_(11, 4, 5, 5, 6), ary_(2012, 6, 3, 23, 18), 2110135762);
}
private void tst_Xto_int(int[] seg_ary, int[] val_ary, int expd) {
int[] pow_ary = Bit_.Bld_pow_ary(seg_ary);
Tfds.Eq(expd, Bit_.Xto_int(pow_ary, val_ary));
}
@Test public void Xto_intAry() {
tst_Xto_intAry(ary_(1, 1, 1, 1) , 15, ary_(1, 1, 1, 1));
tst_Xto_intAry(ary_(3, 2) , 31, ary_(7, 3));
tst_Xto_intAry(ary_(3, 2, 1) , 63, ary_(7, 3, 1));
tst_Xto_intAry(ary_(12, 4, 5, 5, 6), 2110135761, ary_(2012, 6, 3, 23, 17));
tst_Xto_intAry(ary_(12, 4, 5, 5, 6), 2110135762, ary_(2012, 6, 3, 23, 18));
}
private void tst_Xto_intAry(int[] seg_ary, int val, int[] expd) {
int[] pow_ary = Bit_.Bld_pow_ary(seg_ary);
Tfds.Eq_ary_str(expd, Bit_.Xto_intAry(pow_ary, val));
}
int[] ary_(int... v) {return v;}
@Test public void Xto_int_date_short() {
tst_Xto_int_date_short("20120604 2359", 117843451);
tst_Xto_int_date_short("20120604 2358", 117843450);
tst_Xto_int_date_short("20120605 0000", 117843968);
}
private void tst_Xto_int_date_short(String date_str, int expd) {
DateAdp date = DateAdp_.parse_fmt(date_str, "yyyyMMdd HHmm");
int date_int = Bit_.Xto_int_date_short(date.XtoSegAry());
Tfds.Eq(expd, date_int);
Tfds.Eq(date_str, Bit_.Xto_date_short(date_int).XtoStr_fmt("yyyyMMdd HHmm"));
}
} void tst_XtoBitStr(int val, String expd) {Tfds.Eq(expd, Bit_.ToBitStr(val));}
@Test public void Shift_lhs() {// simple: shift 1 bit
fxt.Test_shift_lhs(1, 1, 2);
fxt.Test_shift_lhs(2, 1, 4);

@ -1,130 +0,0 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.core.brys; import gplx.*; import gplx.core.*;
public class Bry_parser {
private final gplx.core.primitives.Int_obj_ref pos_ref = gplx.core.primitives.Int_obj_ref.neg1_();
private byte[] page; private String wkr_name; private int hook_bgn;
public byte[] Src() {return src;} private byte[] src;
public int Src_len() {return src_len;} private int src_len;
public int Pos() {return pos;} private int pos;
public void Init_src(byte[] page, byte[] src, int src_len, int pos) {
this.page = page; this.src = src; this.src_len = src_len; this.pos = pos;
}
public void Init_hook(String wkr_name, int hook_bgn, int hook_end) {
this.wkr_name = wkr_name; this.hook_bgn = hook_bgn; this.pos = hook_end;
}
public int Pos_(int v) {this.pos = v; return pos;}
public int Pos_add_one() {return Pos_add(1);}
public int Pos_add(int adj) {
this.pos += adj;
return pos;
}
public byte Read_byte() {
byte rv = src[pos];
++pos;
return rv;
}
public int Read_int_to(byte to_char) {
int bgn = pos;
int rv = 0;
int negative = 1;
while (pos < src_len) {
byte b = src[pos++];
switch (b) {
case Byte_ascii.Num_0: case Byte_ascii.Num_1: case Byte_ascii.Num_2: case Byte_ascii.Num_3: case Byte_ascii.Num_4:
case Byte_ascii.Num_5: case Byte_ascii.Num_6: case Byte_ascii.Num_7: case Byte_ascii.Num_8: case Byte_ascii.Num_9:
rv = (rv * 10) + (b - Byte_ascii.Num_0);
break;
case Byte_ascii.Dash:
if (negative == -1) // 2nd negative
throw Fail("invalid int", String_.new_u8(src, bgn, pos));
else // 1st negative
negative = -1; // flag negative
break;
default: {
boolean match = b == to_char;
if (to_char == Byte_ascii.Null) {// hack for Read_int_to_non_num
--pos;
match = true;
}
if (!match) throw Fail("invalid int", String_.new_u8(src, bgn, pos));
return rv * negative;
}
}
}
if (bgn == pos) throw Fail("int is empty", String_.Empty);
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) {
int rv = gplx.xowa.htmls.core.hzips.Xoh_hzip_int_.Decode(reqd, src, src_len, pos, pos_ref);
pos = pos_ref.Val();
return rv;
}
public boolean Is(byte find) {
boolean rv = src[pos] == find;
if (rv) ++pos; // only advance if match;
return rv;
}
public int Chk(byte[] find) {
int find_end = pos + find.length;
if (!Bry_.Match(src, pos, find_end, find)) throw Fail("failed check", String_.new_u8(find));
pos = find_end;
return pos;
}
public int Chk(byte find) {
if (src[pos] != find) throw Fail("failed check", Byte_ascii.To_str(find));
++pos;
return pos;
}
public int Fwd_bgn(byte[] find) {
int find_pos = Bry_find_.Find_fwd(src, find, pos, src_len);
if (find_pos == Bry_find_.Not_found) throw Fail("missing", String_.new_u8(find));
pos = find_pos + find.length;
return find_pos;
}
public int Fwd_bgn(byte find) {
int find_pos = Bry_find_.Find_fwd(src, find, pos, src_len);
if (find_pos == Bry_find_.Not_found) throw Fail("missing", Byte_ascii.To_str(find));
pos = find_pos + 1;
return find_pos;
}
public int Fwd_end(byte[] find) {
int find_pos = Bry_find_.Find_fwd(src, find, pos, src_len);
if (find_pos == Bry_find_.Not_found) throw Fail("missing", String_.new_u8(find));
pos = find_pos + find.length;
return pos;
}
public int Fwd_end(byte find) {
int find_pos = Bry_find_.Find_fwd(src, find, pos, src_len);
if (find_pos == Bry_find_.Not_found) throw Fail("missing", Byte_ascii.To_str(find));
pos = find_pos + 1;
return pos;
}
public int Fwd_while(byte find) {
this.pos = Bry_find_.Find_fwd_while(src, pos, src_len, find);
return pos;
}
public Err Fail(String msg, String arg) {
return Err_.new_("Bry_parser", msg, "arg", arg, "page", page, "wkr", wkr_name, "excerpt", Bry_.Mid_by_len_safe(src, hook_bgn, 255));
}
}

@ -0,0 +1,171 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.core.brys; import gplx.*; import gplx.core.*;
public class Bry_rdr {
private final gplx.core.primitives.Int_obj_ref pos_ref = gplx.core.primitives.Int_obj_ref.neg1_();
private String ctx; private String wkr; private int err_bgn;
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 Bry_rdr Dflt_dlm_(byte b) {this.dflt_dlm = b; return this;} private byte dflt_dlm;
public Bry_rdr Fail_throws_err_(boolean v) {this.fail_throws_err = v; return this;} private boolean fail_throws_err = true;
public Bry_rdr Ctor_by_page(byte[] ctx, byte[] src, int src_len) {this.ctx = Quote(String_.new_u8(ctx)); this.src = src; this.src_end = src_len; this.pos = 0; return this;}
public Bry_rdr Init_by_hook(String wkr, int err_bgn, int pos) {this.wkr = Quote(wkr); this.err_bgn = err_bgn; this.pos = pos; return this;}
public Bry_rdr Init_by_sub(Bry_rdr rdr, String wkr, int pos, int src_end) {
this.src = rdr.src; this.ctx = rdr.ctx; this.wkr = Quote(wkr); this.err_bgn = pos; this.pos = pos; this.src_end = src_end;
this.dflt_dlm = Byte_ascii.Null;
return this;
}
public int Move_to(int v) {this.pos = v; return pos;}
public int Move_by_one() {return Move_by(1);}
public int Move_by(int v) {this.pos += v; return pos;}
public int Find_fwd_lr() {return Find_fwd(dflt_dlm , Bool_.Y, Bool_.N);}
public int Find_fwd_lr(byte find) {return Find_fwd(find , Bool_.Y, Bool_.N);}
public int Find_fwd_lr(byte[] find) {return Find_fwd(find , Bool_.Y, Bool_.N);}
public int Find_fwd_rr() {return Find_fwd(dflt_dlm , Bool_.N, Bool_.N);}
public int Find_fwd_rr(byte find) {return Find_fwd(find , Bool_.N, Bool_.N);}
public int Find_fwd_rr(byte[] find) {return Find_fwd(find , Bool_.N, Bool_.N);}
private int Find_fwd(byte find, boolean ret_lhs, boolean pos_lhs) {
int find_pos = Bry_find_.Find_fwd(src, find, pos, src_end); if (find_pos == Bry_find_.Not_found) {Fail("find failed", "find", Byte_ascii.To_str(find)); return Bry_find_.Not_found;}
pos = find_pos + (pos_lhs ? 0 : 1);
return ret_lhs ? find_pos : pos;
}
private int Find_fwd(byte[] find, boolean ret_lhs, boolean pos_lhs) {
int find_pos = Bry_find_.Find_fwd(src, find, pos, src_end); if (find_pos == Bry_find_.Not_found) {Fail("find failed", "find", String_.new_u8(find)); return Bry_find_.Not_found;}
pos = find_pos + (pos_lhs ? 0 : find.length);
return ret_lhs ? find_pos : pos;
}
public byte Read_byte() {
byte rv = src[pos];
++pos;
return rv;
}
public byte Read_byte_to() {return Read_byte_to(dflt_dlm);}
public byte Read_byte_to(byte to_char) {
byte rv = src[pos];
++pos;
if (pos < src_end) {
if (src[pos] != to_char) {Fail("read byte to failed", "to", Byte_ascii.To_str(to_char)); return Byte_.Max_value_127;}
++pos;
}
return rv;
}
public double Read_double_to() {return Read_double_to(dflt_dlm);}
public double Read_double_to(byte to_char) {
byte[] bry = Read_bry_to(to_char);
return Double_.parse(String_.new_a7(bry));
}
public int Read_int_to() {return Read_int_to(dflt_dlm);}
public int Read_int_to(byte to_char) {
int bgn = pos;
int rv = 0;
int negative = 1;
while (pos < src_end) {
byte b = src[pos++];
switch (b) {
case Byte_ascii.Num_0: case Byte_ascii.Num_1: case Byte_ascii.Num_2: case Byte_ascii.Num_3: case Byte_ascii.Num_4:
case Byte_ascii.Num_5: case Byte_ascii.Num_6: case Byte_ascii.Num_7: case Byte_ascii.Num_8: case Byte_ascii.Num_9:
rv = (rv * 10) + (b - Byte_ascii.Num_0);
break;
case Byte_ascii.Dash:
if (negative == -1) { // 2nd negative
Fail("invalid int", "mid", String_.new_u8(src, bgn, pos));
return Int_.Min_value;
}
else // 1st negative
negative = -1; // flag negative
break;
default: {
boolean match = b == to_char;
if (to_char == Byte_ascii.Null) {// hack for Read_int_to_non_num
--pos;
match = true;
}
if (!match) {
Fail("invalid int", "mid", String_.new_u8(src, bgn, pos));
return Int_.Min_value;
}
return rv * negative;
}
}
}
if (bgn == pos) {Fail("int is empty", String_.Empty, String_.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) {
int rv = gplx.xowa.htmls.core.hzips.Xoh_hzip_int_.Decode(reqd, src, src_end, pos, pos_ref);
pos = pos_ref.Val();
return rv;
}
public byte[] Read_bry_to() {return Read_bry_to(dflt_dlm);}
public byte[] Read_bry_to(byte b) {
int bgn = pos;
return Bry_.Mid(src, bgn, Find_fwd_lr(b));
}
public boolean Is(byte find) {
boolean rv = src[pos] == find;
if (rv) ++pos; // only advance if match;
return rv;
}
public boolean Is(byte[] find) {
int find_len = find.length;
int find_end = pos + find_len;
boolean rv = Bry_.Match(src, pos, find_end, find, 0, find_len);
if (rv) pos = find_end; // only advance if match;
return rv;
}
public int Chk(byte find) {
if (src[pos] != find) {Fail("failed check", "chk", Byte_.To_str(find)); return Bry_find_.Not_found;}
++pos;
return pos;
}
public int Chk(byte[] find) {
int find_end = pos + find.length;
if (!Bry_.Match(src, pos, find_end, find)) {Fail("failed check", "chk", String_.new_u8(find)); return Bry_find_.Not_found;}
pos = find_end;
return pos;
}
public byte Chk(gplx.core.btries.Btrie_slim_mgr trie) {return Chk(trie, pos, src_end);}
public byte Chk(gplx.core.btries.Btrie_slim_mgr trie, int itm_bgn, int itm_end) {
Object rv_obj = trie.Match_bgn(src, itm_bgn, itm_end);
if (rv_obj == null) {Fail("failed trie check", "mid", String_.new_u8(Bry_.Mid_by_len_safe(src, pos, 16))); return Byte_.Max_value_127;}
pos = trie.Match_pos();
return ((gplx.core.primitives.Byte_obj_val)rv_obj).Val();
}
public int Fail(String msg, String arg_key, Object arg_val) {return Fail(msg, arg_key, arg_val, err_bgn, err_bgn + 255);}
public int Fail(String msg, String arg_key, Object arg_val, int excerpt_bgn, int excerpt_end) {
arg_val = Quote(Object_.Xto_str_strict_or_null_mark(arg_val));
String err_msg = Msg_make(msg, arg_key, arg_val, excerpt_bgn, excerpt_end);
Gfo_usr_dlg_.Instance.Warn_many("", "", err_msg);
if (fail_throws_err) throw Err_.new_("Bry_rdr", err_msg);
return Bry_find_.Not_found;
}
public Err Err_make(String msg, String arg_key, Object arg_val, int excerpt_bgn, int excerpt_end) {return Err_.new_("Bry_rdr", Msg_make(msg, arg_key, arg_val, excerpt_bgn, excerpt_end));}
private String Msg_make(String msg, String arg_key, Object arg_val, int excerpt_bgn, int excerpt_end) {
if (String_.EqEmpty(arg_key))
return Err_msg.To_str(msg, "ctx", ctx, "wkr", wkr, "excerpt", Bry_.Mid_safe(src, excerpt_bgn, excerpt_end));
else
return Err_msg.To_str(msg, arg_key, arg_val, "ctx", ctx, "wkr", wkr, "excerpt", Quote(String_.new_u8(Bry_.Mid_by_len_safe(src, excerpt_bgn, excerpt_end))));
}
private static String Quote(String v) {return "'" + v + "'";}
}

@ -41,8 +41,8 @@ public class Bry_rdr_tst {
}
}
class Bry_rdr_fxt {
private Bry_rdr rdr;
public void Clear() {rdr = new Bry_rdr();}
private Bry_rdr_old rdr;
public void Clear() {rdr = new Bry_rdr_old();}
public Bry_rdr_fxt Init_src(String v) {rdr.Init(Bry_.new_u8(v)); return this;}
public Bry_rdr_fxt Init_pos(int v) {rdr.Pos_(v); return this;}
public void Test_read_int(int expd_val) {

@ -15,12 +15,15 @@ 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.htmls.core.wkrs.lnkes; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*; import gplx.xowa.htmls.core.wkrs.*;
import org.junit.*; import gplx.xowa.htmls.core.parsers.*;
public class Xoh_lnke_parse_tst {
private final Xoh_parser_fxt fxt = new Xoh_parser_fxt();
@Test public void Free() {
fxt.Init__lnke(0, 96, Xoh_lnke_dict_.Type__free, 0, "http://a.org");
fxt.Test__parse(Xoh_lnke_html__hdump__tst.Html__free);
package gplx.core.brys; import gplx.*; import gplx.core.*;
public class Int_flag_bldr {
private int[] pow_ary;
public int[] Val_ary() {return val_ary;} private int[] val_ary;
public Int_flag_bldr Pow_ary_bld_(int... ary) {
this.pow_ary = Int_flag_bldr_.Bld_pow_ary(ary);
this.val_ary = new int[pow_ary.length];
return this;
}
public int Encode() {return Int_flag_bldr_.To_int(pow_ary, val_ary);}
public void Decode(int v) {Int_flag_bldr_.To_int_ary(val_ary, pow_ary, v);}
}

@ -0,0 +1,89 @@
/*
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 Int_flag_bldr_ {
public static int[] Bld_pow_ary(int... ary) {
int len = ary.length;
int[] rv = new int[len];
int pow = 0;
for (int i = len - 1; i > -1; --i) {
rv[i] = Int_flag_bldr_.Base2_ary[pow];
pow += ary[i];
}
return rv;
}
public static int To_int(int[] pow_ary, int[] val_ary) {
int pow_ary_last = pow_ary.length - 1;
int val = 0;
for (int i = pow_ary_last; i > -1; i--)
val += pow_ary[i] * val_ary[i];
return val;
}
public static int[] To_int_ary(int[] pow_ary, int v) {
int[] rv = new int[pow_ary.length];
To_int_ary(rv, pow_ary, v);
return rv;
}
public static void To_int_ary(int[] rv, int[] pow_ary, int v) {
int pow_ary_len = pow_ary.length;
int rv_len = rv.length;
for (int i = 0; i < pow_ary_len; i++) {
if (i >= rv_len) break;
rv[i] = v / pow_ary[i];
int factor = pow_ary[i] * rv[i];
v = factor == 0 ? v : (v % factor); // NOTE: if 0, do not do modulus or else div by zero
}
}
public static byte To_byte(byte[] pow_ary, byte... val_ary) {
int pow_ary_last = pow_ary.length - 1;
int val = 0;
for (int i = pow_ary_last; i > -1; --i)
val += pow_ary[i] * val_ary[i];
return (byte)val;
}
public static void To_bry(byte[] rv, byte[] pow_ary, byte val) {
int pow_ary_len = pow_ary.length;
int rv_len = rv.length;
for (int i = 0; i < pow_ary_len; i++) {
if (i >= rv_len) break;
rv[i] = (byte)(val / pow_ary[i]);
int factor = pow_ary[i] * rv[i];
val = (byte)(factor == 0 ? val : (val % factor)); // NOTE: if 0, do not do modulus or else div by zero
}
}
public static int To_int_date_short(int[] val_ary) {
val_ary[0] -= 1900;
return Int_flag_bldr_.To_int(Pow_ary_date_short, val_ary);
}
public static void To_date_short_int_ary(int[] rv, int v) {
Int_flag_bldr_.To_int_ary(rv, Pow_ary_date_short, v);
rv[0] += 1900;
}
public static DateAdp To_date_short(int v) {
int[] rv = new int[Pow_ary_date_short.length];
To_date_short_int_ary(rv, v);
return DateAdp_.seg_(rv);
}
private static final int[] Pow_ary_date_short = new int[] {1048576, 65536, 2048, 64, 1}; // yndhm -> 12,4,5,5,6
public static final int[] Base2_ary = new int[]
{ 1, 2, 4, 8, 16, 32, 64, 128
, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768
, 65536, 131072, 262144, 524288, 1048576, 2097152, 4194304, 8388608
, 16777216, 33554432, 67108864, 134217728, 268435456, 536870912, 1073741824, 0
};
}

@ -0,0 +1,72 @@
/*
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 Int_flag_bldr__tst {
private final Int_flag_bldr__fxt fxt = new Int_flag_bldr__fxt();
@Test public void Bld_pow_ary() {
fxt.Test__bld_pow_ary(fxt.Make__ary(1, 1, 1, 1), fxt.Make__ary(8, 4, 2, 1));
fxt.Test__bld_pow_ary(fxt.Make__ary(3, 2) , fxt.Make__ary(4, 1));
}
@Test public void To_int__1_1_1() {
int[] seg_ary = fxt.Make__ary(1, 1, 1);
fxt.Test__to_int(seg_ary , fxt.Make__ary(0, 0, 0), 0);
fxt.Test__to_int(seg_ary , fxt.Make__ary(1, 1, 1), 7);
fxt.Test__to_int(seg_ary , fxt.Make__ary(1, 0, 0), 4);
fxt.Test__to_int(seg_ary , fxt.Make__ary(1, 1, 0), 6);
fxt.Test__to_int(seg_ary , fxt.Make__ary(0, 1, 1), 3);
}
@Test public void To_int__2_3() {
fxt.Test__to_int(fxt.Make__ary(2, 3) , fxt.Make__ary(3, 7) , 31);
fxt.Test__to_int(fxt.Make__ary(1, 2, 3) , fxt.Make__ary(1, 3, 7) , 63);
}
@Test public void To_int__11_4_5_5_6() {
fxt.Test__to_int(fxt.Make__ary(11, 4, 5, 5, 6), fxt.Make__ary(2012, 6, 3, 23, 17), 2110135761);
fxt.Test__to_int(fxt.Make__ary(11, 4, 5, 5, 6), fxt.Make__ary(2012, 6, 3, 23, 18), 2110135762);
}
@Test public void To_int_ary() {
fxt.Test__to_int_ary(fxt.Make__ary(1, 1, 1, 1) , 15, fxt.Make__ary(1, 1, 1, 1));
fxt.Test__to_int_ary(fxt.Make__ary(3, 2) , 31, fxt.Make__ary(7, 3));
fxt.Test__to_int_ary(fxt.Make__ary(3, 2, 1) , 63, fxt.Make__ary(7, 3, 1));
fxt.Test__to_int_ary(fxt.Make__ary(12, 4, 5, 5, 6), 2110135761, fxt.Make__ary(2012, 6, 3, 23, 17));
fxt.Test__to_int_ary(fxt.Make__ary(12, 4, 5, 5, 6), 2110135762, fxt.Make__ary(2012, 6, 3, 23, 18));
}
@Test public void To_int_date_short() {
fxt.Test__to_int_date_short("20120604 2359", 117843451);
fxt.Test__to_int_date_short("20120604 2358", 117843450);
fxt.Test__to_int_date_short("20120605 0000", 117843968);
}
}
class Int_flag_bldr__fxt {
public int[] Make__ary(int... v) {return v;}
public void Test__bld_pow_ary(int[] seg_ary, int[] expd) {Tfds.Eq_ary_str(expd, Int_flag_bldr_.Bld_pow_ary(seg_ary));}
public void Test__to_int(int[] seg_ary, int[] val_ary, int expd) {
int[] pow_ary = Int_flag_bldr_.Bld_pow_ary(seg_ary);
Tfds.Eq(expd, Int_flag_bldr_.To_int(pow_ary, val_ary));
}
public void Test__to_int_ary(int[] seg_ary, int val, int[] expd) {
int[] pow_ary = Int_flag_bldr_.Bld_pow_ary(seg_ary);
Tfds.Eq_ary_str(expd, Int_flag_bldr_.To_int_ary(pow_ary, val));
}
public void Test__to_int_date_short(String date_str, int expd) {
DateAdp date = DateAdp_.parse_fmt(date_str, "yyyyMMdd HHmm");
int date_int = Int_flag_bldr_.To_int_date_short(date.XtoSegAry());
Tfds.Eq(expd, date_int);
Tfds.Eq(date_str, Int_flag_bldr_.To_date_short(date_int).XtoStr_fmt("yyyyMMdd HHmm"));
}
}

@ -102,7 +102,7 @@ class Gfo_cmd_arg_mgr_fxt {
return this;
}
public Gfo_cmd_arg_mgr_fxt Test_write(String... expd) {
Tfds.Eq_ary_str(expd, ((Gfo_usr_dlg__gui_test)usr_dlg.Gui_wkr()).Xto_str_ary_and_clear());
Tfds.Eq_ary_str(expd, ((Gfo_usr_dlg__gui_test)usr_dlg.Gui_wkr()).Msgs().To_str_ary_and_clear());
return this;
}
public void Test_val_as_url_rel_dir_or(String root_dir, String dir_spr, String val, String expd) {

@ -20,9 +20,15 @@ public class Html_atr_ {
public static final byte[]
Bry__id = Bry_.new_a7("id")
, Bry__class = Bry_.new_a7("class")
, Bry__rel = Bry_.new_a7("rel")
, Bry__href = Bry_.new_a7("href")
, Bry__title = Bry_.new_a7("title")
, Bry__style = Bry_.new_a7("style")
// <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")
;
}

@ -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.langs.htmls; import gplx.*; import gplx.langs.*;
public class Html_bldr_ {
public static final byte[]
Bry__a_lhs_bgn = Bry_.new_a7("<a")
, Bry__a_rhs = Bry_.new_a7("</a>")
, Bry__a_lhs_w_href = Bry_.new_a7("<a href=\"")
, Bry__img_lhs_w_alt = Bry_.new_a7("<img alt=\"")
, Bry__img_lhs = Bry_.new_a7("<img")
, Bry__id__1st = Bry_.new_a7(" id=\"")
, Bry__id__nth = Bry_.new_a7("\" id=\"")
, Bry__cls__nth = Bry_.new_a7("\" class=\"")
, Bry__title__nth = Bry_.new_a7("\" title=\"")
, Bry__alt__nth = Bry_.new_a7("\" alt=\"")
, 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_w_quote = Bry_.new_a7("\">")
, Bry__lhs_end_inline = Bry_.new_a7("/>")
, Bry__lhs_end_inline_w_quote = Bry_.new_a7("\"/>")
;
}

@ -17,20 +17,40 @@ 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 static final int
Id__eos = -2
, Id__any = -1
, Id__unknown = 0
, Id__comment = 1
, Id__h2 = 2
, Id__h3 = 3
, Id__h4 = 4
, Id__h5 = 5
, Id__h6 = 6
, Id__a = 7
, Id__span = 8
, Id__div = 9
, Id__img = 10
;
public static final byte[]
Ul_name_bry = Bry_.new_a7("ul")
, A_name_bry = Bry_.new_a7("a")
, Code_name_bry = Bry_.new_a7("code")
, Tr_name_bry = Bry_.new_a7("tr")
, Td_name_bry = Bry_.new_a7("td")
, Table_name_bry = Bry_.new_a7("table")
Bry__a = Bry_.new_a7("a")
, Bry__ul = Bry_.new_a7("ul")
;
public static final Hash_adp_bry Hash = Hash_adp_bry.ci_a7()
.Add_bry_int(Bry__a , Id__a)
.Add_str_int("h2" , Id__h2)
.Add_str_int("h3" , Id__h3)
.Add_str_int("h4" , Id__h4)
.Add_str_int("h5" , Id__h5)
.Add_str_int("h6" , Id__h6)
.Add_str_int("span" , Id__span)
.Add_str_int("div" , Id__div)
.Add_str_int("img" , Id__img)
;
public static final byte[]
Br_inl = Bry_.new_a7("<br/>")
, Hr_inl = Bry_.new_a7("<hr/>")
, Body_lhs = Bry_.new_a7("<body>") , Body_rhs = Bry_.new_a7("</body>")
, A_lhs_bgn = Bry_.new_a7("<a")
, A_rhs = Bry_.new_a7("</a>")
, B_lhs = Bry_.new_a7("<b>") , B_rhs = Bry_.new_a7("</b>")
, I_lhs = Bry_.new_a7("<i>") , I_rhs = Bry_.new_a7("</i>")
, P_lhs = Bry_.new_a7("<p>") , P_rhs = Bry_.new_a7("</p>")
@ -60,28 +80,4 @@ public class Html_tag_ {
Comm_bgn_len = Comm_bgn.length
, Comm_end_len = Comm_end.length
;
public static final int
Id__eos = -2
, Id__any = -1
, Id__unknown = 0
, Id__a = 1
, Id__h2 = 2
, Id__h3 = 3
, Id__h4 = 4
, Id__h5 = 5
, Id__h6 = 6
, Id__span = 7
, Id__div = 8
, Id__comment = 9
;
public static final Hash_adp_bry Hash = Hash_adp_bry.ci_a7()
.Add_str_int("a" , Id__a)
.Add_str_int("h2" , Id__h2)
.Add_str_int("h3" , Id__h3)
.Add_str_int("h4" , Id__h4)
.Add_str_int("h5" , Id__h5)
.Add_str_int("h6" , Id__h6)
.Add_str_int("span" , Id__span)
.Add_str_int("div" , Id__div)
;
}

@ -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_utl_fxt fxt = new Html_utl_fxt();
public class Html_utl_tst {
@Before public void init() {fxt.Clear();} private Html_atr_cls_fxt fxt = new Html_atr_cls_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,7 +37,7 @@ public class Html_utl_tst {
fxt.Test_unescape_html(Bool_.Y, Bool_.Y, Bool_.Y, Bool_.Y, Bool_.Y, "a&lt;&gt;&#39;&amp;&quot;b" , "a<>'&\"b"); // basic
}
}
class Html_utl_fxt {
class Html_atr_cls_fxt {
private Bry_bfr tmp_bfr = Bry_bfr.reset_(255);
public void Clear() {
tmp_bfr.Clear();

@ -26,10 +26,15 @@ public class Html_atr {
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;
public boolean Val_exists() {return val_end > val_bgn;}
public byte[] Val() {
if (val == null)
val = Bry_.Mid(src, val_bgn, val_end);
return val;
} private byte[] val;
public static final Html_atr Noop = new Html_atr(-1, Bry_.Empty, Bry_.Empty, Bry_.Empty, 0, 0);
}
public void Html__add(Bry_bfr bfr) {
if (val_end > val_bgn)
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);
}

@ -0,0 +1,61 @@
/*
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.parsers; import gplx.*; import gplx.langs.*; import gplx.langs.htmls.*;
public class Html_atr_cls_ {
public static boolean Has(byte[] src, int src_bgn, int src_end, byte[] cls) {
int cls_bgn = src_bgn;
int pos = src_bgn;
while (true) {
boolean pos_is_last = pos == src_end;
byte b = pos_is_last ? Byte_ascii.Space : src[pos];
if (b == Byte_ascii.Space) {
if (cls_bgn != -1) {
if (Bry_.Match(src, cls_bgn, pos, cls))return true;
cls_bgn = -1;
}
}
else {
if (cls_bgn == -1) cls_bgn = pos;
}
if (pos_is_last) break;
++pos;
}
return false;
}
public static byte Find_1st(byte[] src, int src_bgn, int src_end, Hash_adp_bry hash) {
int cls_bgn = src_bgn;
int pos = src_bgn;
while (true) {
boolean pos_is_last = pos == src_end;
byte b = pos_is_last ? Byte_ascii.Space : src[pos];
if (b == Byte_ascii.Space) {
if (cls_bgn != -1) {
byte rv = hash.Get_as_byte_or(src, cls_bgn, pos, Byte_.Max_value_127);
if (rv != Byte_.Max_value_127) return rv;
cls_bgn = -1;
}
}
else {
if (cls_bgn == -1) cls_bgn = pos;
}
if (pos_is_last) break;
++pos;
}
return Byte_.Max_value_127;
}
}

@ -0,0 +1,58 @@
/*
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.parsers; import gplx.*; import gplx.langs.*; import gplx.langs.htmls.*;
import org.junit.*;
public class Html_atr_cls__tst {
private final Html_atr_cls__fxt fxt = new Html_atr_cls__fxt();
@Test public void Has() {
fxt.Test__has__y("a b c", "a", "b", "c");
fxt.Test__has__n("a b c", "d");
fxt.Test__has__n("ab", "a");
}
@Test public void Cls__has__hash() {
Hash_adp_bry hash = fxt.Make_hash("x", "y", "z");
fxt.Test__find_1st(hash, 0, "x");
fxt.Test__find_1st(hash, 2, "z");
fxt.Test__find_1st(hash, 0, "a x b");
fxt.Test__find_1st(hash, 0, "a b x");
fxt.Test__find_1st(hash, Byte_.Max_value_127, "a");
fxt.Test__find_1st(hash, Byte_.Max_value_127, "xyz");
}
}
class Html_atr_cls__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_cls_.Has(src_bry, 0, src_bry.length, itm_bry), itm);
}
}
public Hash_adp_bry Make_hash(String... ary) {
Hash_adp_bry rv = Hash_adp_bry.ci_a7();
int len = ary.length;
for (int i = 0; i < len; ++i)
rv.Add_bry_byte(Bry_.new_u8(ary[i]), (byte)i);
return rv;
}
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_cls_.Find_1st(src_bry, 0, src_bry.length, hash), src);
}
}

@ -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/>.
*/
//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,11 +25,12 @@ public class Html_doc_parser {
this.txt_wkr = txt_wkr;
return this;
}
public void Reg(Html_doc_wkr... wkr_ary) {
public Html_doc_parser Reg_wkrs(Html_doc_wkr... wkr_ary) {
for (Html_doc_wkr wkr : wkr_ary) {
trie.Add_obj(wkr.Hook(), wkr);
list.Add(wkr);
}
return this;
}
public void Parse(byte[] src, int src_bgn, int src_end) {
txt_wkr.Init(src, src_bgn, src_end);
@ -52,7 +53,9 @@ public class Html_doc_parser {
txt_bgn = -1;
}
Html_doc_wkr wkr = (Html_doc_wkr)o;
pos = wkr.Parse(pos);
int hook_end = trie.Match_pos();
try {pos = wkr.Parse(pos);}
catch (Exception e) {Err_.Noop(e); txt_bgn = pos; pos = hook_end;}
}
}
if (txt_bgn != -1) txt_wkr.Parse(txt_bgn, src_end);

@ -16,19 +16,19 @@ 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.xowa.parsers.htmls.*; import gplx.langs.htmls.parsers.styles.*;
public class Html_tag implements Mwh_atr_wkr {
private Html_tag_rdr rdr;
private Html_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 rdr, boolean tag_is_tail, boolean tag_is_inline, int src_bgn, int src_end, int atrs_bgn, int atrs_end, int name_id) {
this.rdr = rdr; this.atrs_null = true;
public Html_tag Init(Html_tag_rdr tag_rdr, boolean tag_is_tail, boolean tag_is_inline, int src_bgn, int src_end, int atrs_bgn, int atrs_end, int name_id) {
this.tag_rdr = tag_rdr; 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;
return this;
}
public Html_tag Copy() {
Html_tag rv = new Html_tag().Init(rdr, tag_is_tail, tag_is_inline, src_bgn, src_end, atrs_bgn, atrs_end, name_id);
Html_tag rv = new Html_tag().Init(tag_rdr, tag_is_tail, tag_is_inline, src_bgn, src_end, atrs_bgn, atrs_end, name_id);
rv.atrs_null = false;
rv.atrs_hash = Copy(atrs_hash);
return rv;
@ -43,15 +43,49 @@ public class Html_tag implements Mwh_atr_wkr {
Html_atr rv = (Html_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;
byte[] rv_val = rv.Val();
return Html_atr_cls_.Has(rv_val, 0, rv_val.length, val);
}
public byte Atrs__cls_find_1st(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.Rdr().Fail("cls missing", String_.Empty, String_.Empty);
byte rv = Html_atr_cls_.Find_1st(tag_rdr.Src(), cls_atr.Val_bgn(), cls_atr.Val_end(), hash); if (rv == Byte_.Max_value_127) tag_rdr.Rdr().Fail("cls val missing", String_.Empty, String_.Empty);
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 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;
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);
return rv == null ? Bry_.Empty : rv.Val();
}
public Html_atr Atrs__get_by(byte[] key) {
public int Atrs__get_as_int(byte[] key) {
int rv = Atrs__get_as_int_or(key, Int_.Min_value); if (rv == Int_.Min_value) tag_rdr.Rdr().Fail("atr missing", "key", key);
return rv;
}
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;
return Bry_.To_int_or(tag_rdr.Src(), rv.Val_bgn(), rv.Val_end(), or);
}
public Html_atr Atrs__get_by(byte[] key) {return Atrs__get_by(key, Bool_.Y);}
public Html_atr Atrs__get_by_or_empty(byte[] key) {return Atrs__get_by(key, Bool_.N);}
public Html_atr Atrs__get_by(byte[] key, boolean fail_if_null) {
if (atrs_null) Atrs__make();
Html_atr rv = (Html_atr)atrs_hash.Get_by(key);
return rv == null ? Html_atr.Noop : rv;
if (rv == null) {
if (fail_if_null) tag_rdr.Rdr().Fail("atr missing", "key", key);
else return Html_atr.Noop;
}
return rv;
}
public String Atrs__print() {
if (atrs_null) Atrs__make();
@ -67,21 +101,19 @@ public class Html_tag implements Mwh_atr_wkr {
atrs_null = false;
if (atrs_hash == null) atrs_hash = Ordered_hash_.New_bry();
else atrs_hash.Clear();
rdr.Atrs__make(this, atrs_bgn, atrs_end);
tag_rdr.Atrs__make(this, atrs_bgn, atrs_end);
}
public void On_atr_each (Mwh_atr_parser mgr, byte[] src, int nde_tid, boolean valid, boolean repeated, boolean key_exists, byte[] key_bry, byte[] val_bry_manual, int[] itm_ary, int itm_idx) {
if (!valid) return;
byte[] val_bry = val_bry_manual;
int val_bgn = -1, val_end = -1;
if (key_exists) {
if (val_bry == null) {
val_bgn = itm_ary[itm_idx + Mwh_atr_mgr.Idx_val_bgn];
val_end = itm_ary[itm_idx + Mwh_atr_mgr.Idx_val_end];
}
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_manual = key_bry;
Html_atr atr = new Html_atr(atrs_hash.Count(), key_bry, val_bry_manual, src, val_bgn, val_end);
val_bry = key_bry;
Html_atr atr = new Html_atr(atrs_hash.Count(), key_bry, val_bry, src, val_bgn, val_end);
atrs_hash.Add(key_bry, atr);
}
private static Ordered_hash Copy(Ordered_hash src) {

@ -16,22 +16,25 @@ 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.core.primitives.*; import gplx.core.btries.*;
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;
private final Mwh_atr_parser atr_parser = new Mwh_atr_parser();
private final Html_tag tag__tmp = new Html_tag(), tag__eos = new Html_tag(), tag__comment = new Html_tag();
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 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_rdr Rdr() {return rdr;} private final Bry_rdr rdr = new Bry_rdr();
public void Init(byte[] src, int src_bgn, int src_end) {
this.src = src; this.pos = src_bgn; this.src_end = src_end;
tag__eos.Init(this, Bool_.N, Bool_.N, src_end, src_end, src_end, src_end, Html_tag_.Id__eos);
rdr.Ctor_by_page(Bry_.Empty, src, src_end);
}
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 void Fail(String msg, Html_tag tag) {rdr.Fail(msg, String_.Empty, String_.Empty, tag.Src_bgn(), tag.Src_end());}
public Html_tag Tag__move_fwd_head() {return Tag__find(Bool_.Y, Bool_.N, Bool_.N, Html_tag_.Id__any);}
public Html_tag Tag__move_fwd_head(int match_name_id) {return Tag__find(Bool_.Y, Bool_.N, Bool_.N, match_name_id);}
public Html_tag Tag__move_fwd_tail(int match_name_id) {return Tag__find(Bool_.Y, Bool_.N, Bool_.Y, match_name_id);}
@ -40,6 +43,11 @@ public class Html_tag_rdr {
public Html_tag Tag__peek_fwd_tail(int match_name_id) {return Tag__find(Bool_.N, Bool_.N, Bool_.Y, match_name_id);}
public Html_tag Tag__peek_bwd_tail(int match_name_id) {return Tag__find(Bool_.N, Bool_.Y, Bool_.Y, match_name_id);}
public Html_tag Tag__peek_bwd_head() {return Tag__find(Bool_.N, Bool_.Y, Bool_.Y, Html_tag_.Id__any);}
public Html_tag Tag__move_fwd_head(byte[] cls) {
Html_tag rv = Tag__find(Bool_.Y, Bool_.N, Bool_.N, Html_tag_.Id__any);
if (!rv.Atrs__cls_has(cls)) rdr.Fail("missing cls", "cls", cls);
return rv;
}
private Html_tag Tag__find(boolean move, boolean bwd, boolean tail, int match_name_id) {
int tmp = pos;
int stop_pos = src_end; int adj = 1;
@ -52,8 +60,8 @@ public class Html_tag_rdr {
Html_tag rv = null;
while (tmp != stop_pos) {
if (src[tmp] == Byte_ascii.Angle_bgn) {
rv = Tag__extract(tail, match_name_id, tmp);
if (Tag__match(bwd, tail, match_name_id, tmp_depth, rv))
rv = Tag__extract(move, tail, match_name_id, tmp);
if (Tag__match(move, bwd, tail, match_name_id, tmp_depth, rv))
break;
else {
tmp = bwd ? rv.Src_bgn() - 1 : rv.Src_end();
@ -63,11 +71,16 @@ public class Html_tag_rdr {
else
tmp += adj;
}
if (rv == null) rv = tag__eos;
if (rv == null) {
if (move)
rdr.Fail("missing tag", "name_id", match_name_id);
else
return tag__eos;
}
if (move) pos = rv.Src_end();
return rv;
}
private boolean Tag__match(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, Html_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
@ -98,19 +111,21 @@ public class Html_tag_rdr {
return false;
}
}
private Html_tag Tag__extract(boolean tail, int match_name_id, int tag_bgn) {
public Html_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; // EX: "<EOS"
byte name_0 = src[name_bgn];
boolean cur_is_tail = false;
switch (name_0) {
case Byte_ascii.Bang: return Tag__comment(tag_bgn); // skip comment; EX: "<!"
case Byte_ascii.Bang:
if (Bry_.Match(src, name_bgn + 1, name_bgn + 3, Bry__comment__mid)) // skip comment; EX: "<!"
return Tag__comment(tag_bgn);
break;
case Byte_ascii.Slash:
++name_bgn; if (name_bgn == src_end) return tag__eos; // EX: "</EOS"
++name_bgn; if (name_bgn == src_end) return tag__eos; // EX: "</EOS"
name_0 = src[name_bgn];
cur_is_tail = true;
break;
}
if (name_0 == Byte_ascii.Bang) return Tag__comment(tag_bgn); // skip comment; EX: "<!"
int name_end = -1, atrs_end = -1, tag_end = -1, name_pos = name_bgn;
byte name_byte = name_0; boolean inline = false;
boolean loop = true;
@ -145,10 +160,17 @@ public class Html_tag_rdr {
if (tag_end == -1) {
tag_end = Bry_find_.Find_fwd(src, Byte_ascii.Angle_end, name_end, src_end);
if (tag_end == Bry_find_.Not_found) return tag__eos;
atrs_end = tag_end;
int prv_pos = tag_end - 1;
if (src[prv_pos] == Byte_ascii.Slash) {
atrs_end = prv_pos;
inline = true;
}
else
atrs_end = tag_end;
++tag_end; // position after ">"
}
return tag__tmp.Init(this, cur_is_tail, inline, tag_bgn, tag_end, name_end, atrs_end, name_hash.Get_as_int_or(src, name_bgn, name_end, -1));
Html_tag tmp = move ? tag__tmp__move : tag__tmp__peek;
return tmp.Init(this, cur_is_tail, inline, tag_bgn, tag_end, name_end, atrs_end, name_hash.Get_as_int_or(src, name_bgn, name_end, -1));
}
public boolean Read_and_move(byte match) {
byte b = src[pos];
@ -159,6 +181,10 @@ public class Html_tag_rdr {
else
return false;
}
public int Read_int_to(byte to_char) {
int rv = Read_int_to(to_char, Int_.Max_value); if (rv == Int_.Max_value) rdr.Fail("invalid int", "pos", pos);
return rv;
}
public int Read_int_to(byte to_char, int or_int) {
int bgn = pos;
int rv = 0;
@ -192,4 +218,5 @@ public class Html_tag_rdr {
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, Bool_.N, Bool_.N, tag_bgn, tag_end, tag_end, tag_end, Html_tag_.Id__comment);
}
private static final byte[] Bry__comment__mid = Bry_.new_a7("--");
}

@ -31,6 +31,10 @@ public class Html_tag_rdr_tst {
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");
}
@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");
}
@Test public void Recursive() {
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");
@ -39,6 +43,7 @@ public class Html_tag_rdr_tst {
}
class Html_tag_rdr_fxt {
private final Html_tag_rdr rdr = new Html_tag_rdr();
// private final Html_doc_log log = new Html_doc_log();
public void Init(String src_str) {
byte[] src_bry = Bry_.new_u8(src_str);
rdr.Init(src_bry, 0, src_bry.length);

@ -15,14 +15,9 @@ 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.htmls.core; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*;
public class Xoh_html_dict_ {
public static final byte[]
Type__hdr = Bry_.new_a7(" data-xotype='hdr_bgn'")
, Hook__space = Bry_.new_a7(" ")
, Hook__lnke = Bry_.new_a7("<a data-xotype='lnke")
, Hook__lnki = Bry_.new_a7("<a data-xotype='lnki")
, Hdr__end = Bry_.new_a7("<!--xo.hdr-->")
, Rng__bgn = Bry_.new_a7("<!--xo.rng.")
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_ {
public static final byte[]
Bry__width = Bry_.new_a7("width")
;
}

@ -0,0 +1,50 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.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(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;
int pos = src_bgn;
while (true) {
boolean pos_is_last = pos == src_end;
byte b = pos_is_last ? Byte_ascii.Semic : src[pos];
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))
pos_is_last = true;
}
++atr_idx; atr_bgn = -1; atr_end = -1; key_bgn = -1; key_end = -1; tmp_bgn = -1; tmp_end = -1;
break;
case Byte_ascii.Colon:
key_bgn = tmp_bgn;
key_end = tmp_end;
tmp_bgn = -1; tmp_end = -1;
break;
case Byte_ascii.Tab: case Byte_ascii.Nl: case Byte_ascii.Cr: case Byte_ascii.Space:
break;
default:
if (tmp_bgn == -1) tmp_bgn = pos;
tmp_end = pos + 1;
break;
}
if (pos_is_last) break;
++pos;
}
}
}

@ -0,0 +1,41 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.langs.htmls.parsers.styles; import gplx.*; import gplx.langs.*; import gplx.langs.htmls.*; import gplx.langs.htmls.parsers.*;
import org.junit.*;
public class Html_atr_style_parser_tst {
private final Html_atr_style_parser_fxt fxt = new Html_atr_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"));
fxt.Test__parse("k_0:v_0;k_1:v_1" , fxt.Make("k_0", "v_0"), fxt.Make("k_1", "v_1"));
}
@Test public void Ws() {
fxt.Test__parse(" k_0 : v_0 ;" , fxt.Make("k_0", "v_0"));
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"));
}
}
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) {
byte[] src_bry = Bry_.new_u8(src_str);
KeyVal[] actl = wkr.Parse(src_bry, 0, src_bry.length);
Tfds.Eq_ary_str(expd, actl);
}
}

@ -0,0 +1,33 @@
/*
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.parsers.styles; import gplx.*; import gplx.langs.*; import gplx.langs.htmls.*; import gplx.langs.htmls.parsers.*;
public interface Html_atr_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);
}
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);
}
}

@ -0,0 +1,35 @@
/*
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.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 {
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) {
boolean rv = Bry_.Match(src, key_bgn, key_end, find_key);
if (rv) {
this.val_bgn = val_bgn;
this.val_end = val_end;
}
return rv;
}
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);
return Bry_.To_int_or__lax(src, val_bgn, val_end, -1);
}
}

@ -34,7 +34,7 @@ public class Xoa_app_ {
}
}
public static final String Name = "xowa";
public static final String Version = "2.11.1.1";
public static final String Version = "2.11.2.1";
public static String Build_date = "2012-12-30 00:00:00";
public static String Op_sys_str;
public static String User_agent = "";

@ -57,10 +57,6 @@ public class Xoa_app_fxt {
((Xoav_wiki_mgr)app.Wiki_mgri()).Add(rv);
return rv;
}
// public static Xow_wiki Make__wiki__view(Xoa_app app, String domain_str) {
// byte[] domain_bry = Bry_.new_u8(domain_str);
// return app.Wiki_mgri().Get_by_key_or_make_init_y(domain_bry);
// }
public static Xowe_wiki wiki_nonwmf(Xoae_app app, String key) {
Xol_lang_itm lang = new Xol_lang_itm(app.Lang_mgr(), Xol_lang_itm_.Key_en).Kwd_mgr__strx_(true);
Xol_lang_itm_.Lang_init(lang);
@ -73,7 +69,7 @@ public class Xoa_app_fxt {
Xowe_wiki rv = new Xowe_wiki(app, lang, Xow_ns_mgr_.default_(lang.Case_mgr()), Xow_domain_itm_.parse(Bry_.new_u8(key)), wiki_dir);
rv.File_mgr().Meta_mgr().Depth_(2); // TEST: written for 2 depth
rv.Props().Main_page_(Xoa_page_.Main_page_bry); // TEST: default to Main Page (nothing tests loading Main Page from wiki.gfs)
rv.Ns_mgr().Ids_get_or_null(Xow_ns_.Id_main).Subpages_enabled_(true);
rv.Ns_mgr().Ids_get_or_null(Xow_ns_.Tid__main).Subpages_enabled_(true);
app.Wiki_mgr().Add(rv);
return rv;
}
@ -86,11 +82,11 @@ public class Xoa_app_fxt {
wiki.File_mgr().Repo_mgr().Add_repo(Bry_.new_a7("src:c"), Bry_.new_a7("trg:c"));
}
public static void repo2_(Xoae_app app, Xowe_wiki wiki) {
app.File_mgr().Repo_mgr().Set("src:wiki", "mem/http/en.wikipedia.org/" , wiki.Domain_str()).Ext_rules_(Xof_rule_grp.Grp_app_default).Dir_depth_(2);
app.File_mgr().Repo_mgr().Set("trg:wiki", "mem/file/en.wikipedia.org/" , wiki.Domain_str()).Ext_rules_(Xof_rule_grp.Grp_app_default).Dir_depth_(2).Primary_(true);
app.File_mgr().Repo_mgr().Set("src:wiki", "mem/http/en.wikipedia.org/" , wiki.Domain_str()).Ext_rules_(Xof_rule_grp.Grp_app_default).Dir_depth_(2);
app.File_mgr().Repo_mgr().Set("trg:wiki", "mem/xowa/file/en.wikipedia.org/" , wiki.Domain_str()).Ext_rules_(Xof_rule_grp.Grp_app_default).Dir_depth_(2).Primary_(true);
wiki.File_mgr().Repo_mgr().Add_repo(Bry_.new_a7("src:wiki"), Bry_.new_a7("trg:wiki"));
app.File_mgr().Repo_mgr().Set("src:comm", "mem/http/commons.wikimedia.org/" , "commons.wikimedia.org").Ext_rules_(Xof_rule_grp.Grp_app_default).Dir_depth_(2);
app.File_mgr().Repo_mgr().Set("trg:comm", "mem/file/commons.wikimedia.org/" , "commons.wikimedia.org").Ext_rules_(Xof_rule_grp.Grp_app_default).Dir_depth_(2).Primary_(true);
app.File_mgr().Repo_mgr().Set("src:comm", "mem/http/commons.wikimedia.org/" , "commons.wikimedia.org").Ext_rules_(Xof_rule_grp.Grp_app_default).Dir_depth_(2);
app.File_mgr().Repo_mgr().Set("trg:comm", "mem/xowa/file/commons.wikimedia.org/" , "commons.wikimedia.org").Ext_rules_(Xof_rule_grp.Grp_app_default).Dir_depth_(2).Primary_(true);
wiki.File_mgr().Repo_mgr().Add_repo(Bry_.new_a7("src:comm"), Bry_.new_a7("trg:comm"));
}
public static void Init_gui(Xoae_app app, Xowe_wiki wiki) {

@ -50,8 +50,8 @@ public class Xoa_ttl { // PAGE:en.w:http://en.wikipedia.org/wiki/Help:Link; REF.
public int Wik_bgn() {return wik_bgn;}
public int Anch_bgn() {return anch_bgn;} // NOTE: anch_bgn is not correct when page has trailing ws; EX: [[A #b]] should have anch_bgn of 3 (1st char after #), but instead it is 2
public byte[] Anch_txt() {return anch_bgn == -1 ? Bry_.Empty : Bry_.Mid(full_txt, anch_bgn, full_txt.length);}
public byte[] Talk_txt() {return ns.Id_talk() ? Full_txt() : Bry_.Add(tors_txt, Page_txt());}
public byte[] Subj_txt() {return ns.Id_subj() ? Full_txt() : Bry_.Add(tors_txt, Page_txt());}
public byte[] Talk_txt() {return ns.Id_is_talk() ? Full_txt() : Bry_.Add(tors_txt, Page_txt());}
public byte[] Subj_txt() {return ns.Id_is_subj() ? Full_txt() : Bry_.Add(tors_txt, Page_txt());}
public byte[] Full_url() {return Xoa_url_encoder.Instance.Encode(full_txt);}
public String Full_db_as_str() {return String_.new_u8(Full_db());}
public byte[] Full_db() {return ns.Gen_ttl(this.Page_db());}
@ -176,7 +176,7 @@ public class Xoa_ttl { // PAGE:en.w:http://en.wikipedia.org/wiki/Help:Link; REF.
}
else {
ns = (Xow_ns)o;
byte[] ns_name = ns.Name_txt();
byte[] ns_name = ns.Name_ui();
int ns_name_len = ns_name.length;
int tmp_bfr_end = bfr.Len();
if (!Bry_.Eq(bfr.Bfr(), ltr_bgn, tmp_bfr_end, ns_name) && ns_name_len == tmp_bfr_end - ltr_bgn) { // if (a) ns_name != bfr_txt (b) both are same length; note that (b) should not happen, but want to safeguard against mismatched arrays
@ -362,8 +362,8 @@ public class Xoa_ttl { // PAGE:en.w:http://en.wikipedia.org/wiki/Help:Link; REF.
else
full_txt = case_mgr.Case_reuse_upper(full_txt, page_bgn, page_end);
}
Xow_ns tors_ns = ns.Id_talk() ? ns_mgr.Ords_get_at(ns.Ord_subj_id()) : ns_mgr.Ords_get_at(ns.Ord_talk_id());
tors_txt = tors_ns.Name_txt_w_colon();
Xow_ns tors_ns = ns.Id_is_talk() ? ns_mgr.Ords_get_at(ns.Ord_subj_id()) : ns_mgr.Ords_get_at(ns.Ord_talk_id());
tors_txt = tors_ns.Name_ui_w_colon();
return true;
}
public static byte[] Replace_spaces(byte[] raw) {return Bry_.Replace(raw, Byte_ascii.Space, Byte_ascii.Underline);}

@ -57,7 +57,7 @@ public class Xoa_url {
int wiki_pos = Bry_find_.Find_fwd(raw, Xoh_href_.Bry__wiki, 0, raw_len); // look for /wiki/
return wiki_pos == Bry_find_.Not_found ? Bry_find_.Not_found : wiki_pos + Xoh_href_.Bry__wiki.length;
}
public boolean Eq_page(Xoa_url comp) {return Bry_.Eq(wiki_bry, comp.wiki_bry) && Bry_.Eq(page_bry, comp.page_bry) && this.Qargs_mgr().Match(Xoa_url_.Qarg__redirect, Xoa_url_.Qarg__redirect__yes) == comp.Qargs_mgr().Match(Xoa_url_.Qarg__redirect, Xoa_url_.Qarg__redirect__yes);}
public boolean Eq_page(Xoa_url comp) {return Bry_.Eq(wiki_bry, comp.wiki_bry) && Bry_.Eq(page_bry, comp.page_bry) && this.Qargs_mgr().Match(Xoa_url_.Qarg__redirect, Xoa_url_.Qarg__redirect__no) == comp.Qargs_mgr().Match(Xoa_url_.Qarg__redirect, Xoa_url_.Qarg__redirect__no);}
public String To_str() {return String_.new_u8(To_bry(Bool_.Y, Bool_.Y));}
public byte[] To_bry_page_w_anch() {
byte[] page = page_bry, anch = anch_bry;

@ -28,7 +28,7 @@ public class Xoa_url_ {
public static String Main_page__home_str = gplx.xowa.wikis.domains.Xow_domain_itm_.Str__home + gplx.xowa.htmls.hrefs.Xoh_href_.Str__wiki + gplx.xowa.Xoa_page_.Main_page_str; // EX:home/wiki/Main_Page
public static final byte[]
Qarg__redirect = Bry_.new_a7("redirect")
, Qarg__redirect__yes = Bry_.new_a7("yes")
, Qarg__redirect__no = Bry_.new_a7("no")
, Qarg__action = Bry_.new_a7("action")
, Qarg__action__edit = Bry_.new_a7("edit")
;

@ -26,7 +26,7 @@ public class Xoae_page implements Xoa_page {
this.wiki = wiki; this.ttl = ttl;
this.lang = wiki.Lang(); // default to wiki.lang; can be override later by wikitext
hdr_mgr = new Xow_hdr_mgr(this, Xoa_app_.Utl__encoder_mgr());
redlink_lnki_list = new Xopg_redlink_lnki_list(ttl.Ns().Id_module());
redlink_lnki_list = new Xopg_redlink_lnki_list(ttl.Ns().Id_is_module());
Ttl_(ttl);
} Xoae_page() {} // called by Null
public Xow_wiki Wiki() {return wiki;}

@ -265,6 +265,7 @@ public class Xop_fxt {
Parse_chk(raw_bry, root, expd_ary);
}
public void Data_create(String ttl_str, String text_str) {Init_page_create(wiki, ttl_str, text_str);}
public void Test_parse_page_all_str__esc(String raw, String expd) {Test_parse_page_all_str(raw, Xoh_consts.Escape_apos(expd));}
public void Test_parse_page_all_str(String raw, String expd) {
String actl = Exec_parse_page_all_as_str(raw);
Tfds.Eq_ary_str(String_.SplitLines_nl(expd), String_.SplitLines_nl(actl), raw);
@ -302,6 +303,7 @@ public class Xop_fxt {
tst_mgr.Tst_ary("tkns:", expd_ary, actl_ary);
tst_Log_check();
}
public Xop_fxt Test_parse_page_wiki_str__esc(String raw, String expd) {return Test_parse_page_wiki_str(raw, Xoh_consts.Escape_apos(expd));}
public Xop_fxt Test_parse_page_wiki_str(String raw, String expd) {
Tfds.Eq_str_lines(expd, Exec_parse_page_wiki_as_str(raw), raw);
return this;

@ -184,7 +184,7 @@ public class Xowe_wiki implements Xow_wiki, GfoInvkAble, GfoEvObj {
// init ns_mgr
if (lang.Init_by_load()) {
if (domain_tid == Xow_domain_tid_.Int__wikipedia) // NOTE: if type is wikipedia, add "Wikipedia" as an alias; PAGE:en.w:pt.wikipedia.org/wiki/Página principal which redirects to Wikipedia:Página principal
ns_mgr.Aliases_add(Xow_ns_.Id_project, Xow_ns_.Ns_name_wikipedia);
ns_mgr.Aliases_add(Xow_ns_.Tid__project, Xow_ns_.Alias__wikipedia);
}
app.Gfs_mgr().Run_url_for(this, app.Fsys_mgr().Cfg_wiki_core_dir().GenSubFil(domain_str + ".gfs")); // NOTE: must be run after lang.Init_by_load b/c lang will reload ns_mgr; DATE:2015-04-17run cfg for wiki by user ; EX: /xowa/user/anonymous/wiki/en.wikipedia.org/cfg/user_wiki.gfs
cfg_parser.Xtns().Itm_pages().Init(ns_mgr); // init ns_mgr for Page / Index ns just before rebuild; usually set by #cfg file

@ -60,7 +60,7 @@ public class Xowc_xtn_pages implements GfoInvkAble {
private int Set_canonical(Xow_ns_mgr ns_mgr, int aliases_added, int id, byte[] name) {
Xow_ns ns = ns_mgr.Ids_get_or_null(id);
if ( ns == null // ns doesn't exist; should throw error;
|| !Bry_.Eq(ns.Name_bry(), name) // ns exists, but name doesn't match canonical
|| !Bry_.Eq(ns.Name_db(), name) // ns exists, but name doesn't match canonical
) {
ns_mgr.Aliases_add(id, String_.new_a7(name));
++aliases_added;

@ -67,13 +67,13 @@ public class Xoa_url_parser__xwiki_tst {
@Test public void Xwiki__to_enwiki() { // PURPOSE: handle alias of "wikipedia" and sv.wikipedia.org/wiki/Wikipedia:Main_Page; DATE:2015-07-31
Xowe_wiki xwiki = tstr.Prep_create_wiki("sv.wikipedia.org");
tstr.Prep_xwiki(xwiki, "wikipedia", "en.wikipedia.org", null);
tstr.Prep_get_ns_mgr_from_meta("sv.wikipedia.org").Add_new(Xow_ns_.Id_project, "Wikipedia");
tstr.Prep_get_ns_mgr_from_meta("sv.wikipedia.org").Add_new(Xow_ns_.Tid__project, "Wikipedia");
tstr.Run_parse(xwiki, "sv.wikipedia.org/wiki/wikipedia:X").Chk_wiki("sv.wikipedia.org").Chk_page("wikipedia:X");
tstr.Run_parse(xwiki, "sv.wikipedia.org/wiki/Wikipedia:X").Chk_wiki("sv.wikipedia.org").Chk_page("Wikipedia:X");
}
@Test public void Xwiki__to_ns() { // PURPOSE: handle alias of "wikipedia" in current, but no "Wikipedia" ns in other wiki; PAGE:pt.w:Wikipedia:P<>gina_de_testes DATE:2015-09-17
tstr.Prep_create_wiki("pt.wikipedia.org");
tstr.Prep_get_ns_mgr_from_meta("pt.wikipedia.org").Add_new(Xow_ns_.Id_project, "Project"); // clear ns_mgr and add only "Project" ns, not "Wikipedia" ns
tstr.Prep_get_ns_mgr_from_meta("pt.wikipedia.org").Add_new(Xow_ns_.Tid__project, "Project"); // clear ns_mgr and add only "Project" ns, not "Wikipedia" ns
tstr.Prep_xwiki(tstr.Wiki(), "wikipedia", "en.wikipedia.org", null); // add alias of "wikipedia" in current wiki
tstr.Run_parse(tstr.Wiki(), "pt.wikipedia.org/wiki/Wikipedia:X").Chk_wiki("pt.wikipedia.org").Chk_page("Wikipedia:X"); // should get "pt.wikipedia.org", not "en.wikipedia.org" (through alias)
}

@ -226,7 +226,7 @@ class Xob_dump_mgr_base_ {
int load_count = 0;
usr_dlg.Note_many("", "", "tmpl_load init");
while (true) {
page_src.Get_pages(pages, 0, Xow_ns_.Id_template, cur_page_id); // 0 is always template db
page_src.Get_pages(pages, 0, Xow_ns_.Tid__template, cur_page_id); // 0 is always template db
int page_count = pages.Count();
if (page_count == 0) break; // no more pages in db;
Xowd_page_itm page = null;

@ -33,7 +33,7 @@ public class Xob_category_registry_sql implements Xob_cmd {
wiki.Init_db_mgr();
Xowd_page_tbl page_core_tbl = wiki.Db_mgr_as_sql().Core_data_mgr().Tbl__page();
Db_rdr rdr = page_core_tbl.Conn().Stmt_select_order(page_core_tbl.Tbl_name(), String_.Ary(page_core_tbl.Fld_page_title(), page_core_tbl.Fld_page_id()), String_.Ary(page_core_tbl.Fld_page_ns()), page_core_tbl.Fld_page_title())
.Crt_int(page_core_tbl.Fld_page_ns(), Xow_ns_.Id_category)
.Crt_int(page_core_tbl.Fld_page_ns(), Xow_ns_.Tid__category)
.Exec_select__rls_auto();
try {
while (rdr.Move_next()) {

@ -39,7 +39,7 @@ class Xob_category_registry_sql_fxt {
}
public void Rls() {fxt.Rls();}
public void Init_page_insert(String[] ttls) {
fxt.Init_page_insert(page_id_next, Xow_ns_.Id_category, ttls);
fxt.Init_page_insert(page_id_next, Xow_ns_.Tid__category, ttls);
}
public void Exec_category_registry_cmd() {
app.Bldr().Cmd_mgr().Add_cmd(wiki, Xob_cmd_keys.Key_text_cat_core);

@ -34,7 +34,7 @@ public abstract class Xob_categorylinks_base extends Xob_sql_dump_base implement
else if (Bry_.Eq(fld_key, Fld_cl_timestamp)) {
date_parser.Parse_iso8651_like(cur_modified_on, src, fld_bgn, fld_end);
cur_date = fld_end - fld_bgn == 0 // ignore null dates added by ctg_v1
? 0 : Bit_.Xto_int_date_short(cur_modified_on);
? 0 : Int_flag_bldr_.To_int_date_short(cur_modified_on);
}
else if (Bry_.Eq(fld_key, Fld_cl_sortkey)) {
int nl_pos = Bry_find_.Find_fwd(src, Byte_ascii.Nl, fld_bgn, fld_end);

@ -23,7 +23,7 @@ public class Xob_categorylinks_sql_tst {
@Test public void Basic() {
if (Xoa_test_.Db_skip()) return;
fxt.Init_db_sqlite();
fxt.Init_page_insert(Int_obj_ref.new_(1), Xow_ns_.Id_category, String_.Ary("Ctg_1", "Ctg_2"));
fxt.Init_page_insert(Int_obj_ref.new_(1), Xow_ns_.Tid__category, String_.Ary("Ctg_1", "Ctg_2"));
fxt.Init_fil(Xoa_test_.Url_wiki_enwiki().GenSubFil("xowa_categorylinks.sql"), String_.Concat
( Xob_categorylinks_sql.Sql_categorylinks
, "INSERT INTO `categorylinks` VALUES"

@ -33,7 +33,7 @@ public abstract class Xob_ctg_v1_base extends Xob_itm_dump_base implements Xobd_
Xol_lang_itm lang = wiki.Lang();
wkr_hooks_add(tmp_bfr, lang.Ns_names());
wkr_hooks_add(tmp_bfr, lang.Ns_aliases());
wkr_hooks_add(tmp_bfr, Xow_ns_.Canonical);
wkr_hooks_add(tmp_bfr, Xow_ns_canonical_.Ary);
tmp_bfr.Mkr_rls();
fld_wtr.Bfr_(dump_bfr);
}
@ -125,14 +125,14 @@ public abstract class Xob_ctg_v1_base extends Xob_itm_dump_base implements Xobd_
int len = ary.length;
for (int i = 0; i < len; i++) {
Xow_ns ns = ary[i];
if (ns.Id_ctg()) wkr_hooks_add(tmp_bfr, ns.Name_bry());
if (ns.Id_is_ctg()) wkr_hooks_add(tmp_bfr, ns.Name_db());
}
}
private void wkr_hooks_add(Bry_bfr tmp_bfr, Xol_ns_grp ns_grp) {
int len = ns_grp.Len();
for (int i = 0; i < len; i++) {
Xow_ns ns = ns_grp.Get_at(i);
if (ns.Id_ctg()) wkr_hooks_add(tmp_bfr, ns.Name_bry());
if (ns.Id_is_ctg()) wkr_hooks_add(tmp_bfr, ns.Name_db());
}
}
private void wkr_hooks_add(Bry_bfr tmp_bfr, byte[] word) {

@ -33,7 +33,7 @@ public class Xob_lnki_temp_wkr extends Xob_dump_mgr_base implements Xopg_redlink
public Xob_lnki_temp_wkr(Xob_bldr bldr, Xowe_wiki wiki) {this.Cmd_ctor(bldr, wiki);}
@Override public String Cmd_key() {return Xob_cmd_keys.Key_file_lnki_temp;}
@Override public byte Init_redirect() {return Bool_.N_byte;} // lnki_temp does not look at redirect pages
@Override public int[] Init_ns_ary() {return ns_ids;} private int[] ns_ids = Int_.Ary(Xow_ns_.Id_main);
@Override public int[] Init_ns_ary() {return ns_ids;} private int[] ns_ids = Int_.Ary(Xow_ns_.Tid__main);
@Override protected void Init_reset(Db_conn conn) {
Db_cfg_tbl cfg_tbl = new Db_cfg_tbl(conn, "xowa_cfg");
cfg_tbl.Delete_all();
@ -103,7 +103,7 @@ public class Xob_lnki_temp_wkr extends Xob_dump_mgr_base implements Xopg_redlink
page.Bldr__ns_ord_(ns_ord);
page.Ttl_(ttl).Revision_data().Id_(db_page.Id());
page.Redlink_lnki_list().Clear();
if (ns.Id_tmpl())
if (ns.Id_is_tmpl())
parser.Parse_text_to_defn_obj(ctx, ctx.Tkn_mkr(), wiki.Ns_mgr().Ns_template(), ttl_bry, page_src);
else {
parser.Parse_page_all_clear(root, ctx, ctx.Tkn_mkr(), page_src);
@ -156,7 +156,7 @@ public class Xob_lnki_temp_wkr extends Xob_dump_mgr_base implements Xopg_redlink
if ( Xof_lnki_page.Null_n(lnki_page) // page set
&& Xof_lnki_time.Null_n(lnki_time)) // thumbtime set
usr_dlg.Warn_many("", "", "page and thumbtime both set; this may be an issue with fsdb: page=~{0} ttl=~{1}", ctx.Cur_page().Ttl().Page_db_as_str(), String_.new_u8(ttl));
if (lnki.Ns_id() == Xow_ns_.Id_media)
if (lnki.Ns_id() == Xow_ns_.Tid__media)
lnki_src_tid = Xob_lnki_src_tid.Tid_media;
tbl.Insert_cmd_by_batch(ctx.Cur_page().Bldr__ns_ord(), ctx.Cur_page().Revision_data().Id(), ttl, ttl_commons, Byte_.By_int(ext.Id()), lnki.Lnki_type(), lnki_src_tid, lnki.W(), lnki.H(), lnki.Upright(), lnki_time, lnki_page);
}
@ -188,7 +188,7 @@ public class Xob_lnki_temp_wkr extends Xob_dump_mgr_base implements Xopg_redlink
}
public static byte[] Xto_commons(boolean ns_file_is_case_match_all, Xowe_wiki commons_wiki, byte[] ttl_bry) {
if (!ns_file_is_case_match_all) return null; // return "" if wiki matches common
Xoa_ttl ttl = Xoa_ttl.parse(commons_wiki, Xow_ns_.Id_file, ttl_bry);
Xoa_ttl ttl = Xoa_ttl.parse(commons_wiki, Xow_ns_.Tid__file, ttl_bry);
byte[] rv = ttl.Page_db();
return Bry_.Eq(rv, ttl_bry) ? null : rv;
}

@ -35,7 +35,7 @@ class Xob_lnki_temp_wkr_ {
int len = aliases.length;
for (int i = 0; i < len; i++) {
String alias = aliases[i];
if (String_.Eq(alias, Xow_ns_.Key_main))
if (String_.Eq(alias, Xow_ns_.Key__main))
list.Add(ns_mgr.Ns_main());
else {
Xow_ns ns = ns_mgr.Names_get_or_null(Bry_.new_u8(alias));

@ -36,7 +36,7 @@ public abstract class Xob_search_base extends Xob_itm_dump_base implements Xobd_
ns_main = wiki.Ns_mgr().Ns_main();
} private Xob_tmp_wtr_mgr tmp_wtr_mgr; private Xow_ns ns_main;
public void Wkr_run(Xowd_page_itm page) {
// if (page.Ns_id() != Xow_ns_.Id_main) return; // limit to main ns for now
// if (page.Ns_id() != Xow_ns_.Tid__main) return; // limit to main ns for now
try {
byte[] ttl = page.Ttl_page_db();
byte[][] words = Split_ttl_into_words(lang, list, dump_bfr, ttl);

@ -69,7 +69,7 @@ public class Xob_page_cmd extends Xob_itm_basic_base implements Xobd_wkr, GfoInv
if (redirect && redirect_id_enabled)
redirect_tbl.Insert(id, page.Ttl_page_db(), redirect_ttl);
++page_count_all;
if (ns.Id_main() && !page.Redirected()) ++page_count_main;
if (ns.Id_is_main() && !page.Redirected()) ++page_count_main;
if (page_count_all % commit_interval == 0) {
page_core_tbl.Conn().Txn_sav(); text_db.Conn().Txn_sav();
if (redirect_id_enabled) redirect_tbl.Conn().Txn_sav();

@ -30,8 +30,8 @@ public class Xob_page_cmd_tst {
)
.Exec_run(new Xob_page_cmd(fxt.Bldr(), fxt.Wiki()))
;
fxt.Test_load_ttl(Xow_ns_.Id_main, "A", fxt.page_(2, "2013-06-03 01:23", false, 6));
fxt.Test_load_page(Xow_ns_.Id_main, 2, "text_a");
fxt.Test_load_ttl(Xow_ns_.Id_main, "B", fxt.page_(1, "2013-06-03 12:34", true, 15));
fxt.Test_load_ttl(Xow_ns_.Tid__main, "A", fxt.page_(2, "2013-06-03 01:23", false, 6));
fxt.Test_load_page(Xow_ns_.Tid__main, 2, "text_a");
fxt.Test_load_ttl(Xow_ns_.Tid__main, "B", fxt.page_(1, "2013-06-03 12:34", true, 15));
}
}

@ -76,7 +76,7 @@ public class Xob_page_txt extends Xob_itm_dump_base implements Xobd_wkr, GfoInvk
Xob_xdat_file_wtr wtr = regy[i];
if (wtr != null) {
Xow_ns ns_itm = wiki.Ns_mgr().Ords_get_at(wtr.Ns_ord_idx());
Xob_stat_itm datRptItm = data_rpt_typ.GetOrNew(ns_itm.Name_str());
Xob_stat_itm datRptItm = data_rpt_typ.GetOrNew(ns_itm.Name_db_str());
datRptItm.Tally(wtr.Fil_len(), wtr.Fil_idx());
wtr.Flush(bldr.Usr_dlg());
wtr.Rls();

@ -27,7 +27,7 @@ public class Xob_parse_dump_templates_cmd extends Xob_itm_dump_base implements X
Init_dump(KEY);
}
public void Wkr_run(Xowd_page_itm page) {
if (page.Ns_id() != Xow_ns_.Id_template) return;
if (page.Ns_id() != Xow_ns_.Tid__template) return;
int id = page.Id(); byte[] title = page.Ttl_page_db(), text = page.Text(); int title_len = title.length, text_len = text.length;
if (FixedLen_page + title_len + text_len + dump_bfr.Len() > dump_fil_len) super.Flush_dump();
Xotdb_page_itm_.Txt_page_save(dump_bfr, id, page.Modified_on(), title, text, true);

@ -32,13 +32,13 @@ public class Xob_search_base_tst {
( fxt.doc_wo_date_(2, "A b", "text")
, fxt.doc_wo_date_(3, "B a", "text")
)
.Fil_expd(fxt.fil_ns_sttl(Xow_ns_.Id_main, 0)
.Fil_expd(fxt.fil_ns_sttl(Xow_ns_.Tid__main, 0)
, "!!!!;|!!!!;|"
, "a|!!!!#;!!!!%|!!!!$;!!!!%"
, "b|!!!!#;!!!!%|!!!!$;!!!!%"
, ""
)
.Fil_expd(fxt.fil_reg(Xow_ns_.Id_main, Xotdb_dir_info_.Tid_search_ttl)
.Fil_expd(fxt.fil_reg(Xow_ns_.Tid__main, Xotdb_dir_info_.Tid_search_ttl)
, "0|a|b|2"
, ""
)

@ -27,7 +27,7 @@ public class Xob_tst {
( fxt.doc_(3, "2012-01-02 13:15", "Title 2a", "text2a\ny")
, fxt.doc_(2, "2012-01-02 13:14", "Title 1", "text1\nz")
)
.Fil_expd(fxt.fil_ns_page(Xow_ns_.Id_main, 0)
.Fil_expd(fxt.fil_ns_page(Xow_ns_.Tid__main, 0)
, "!!!!@|!!!!>|"
, "!!!!$\t#6>K6\tTitle 2a\ttext2a"
, "y\t"
@ -35,13 +35,13 @@ public class Xob_tst {
, "z\t"
, ""
)
.Fil_expd(fxt.fil_ns_title(Xow_ns_.Id_main, 0)
.Fil_expd(fxt.fil_ns_title(Xow_ns_.Tid__main, 0)
, "!!!!C|!!!!D|"
, "!!!!#|!!!!!|!!!!\"|0|!!!!(|Title 1"
, "!!!!$|!!!!!|!!!!!|0|!!!!)|Title 2a"
, ""
)
.Fil_expd(fxt.fil_reg(Xow_ns_.Id_main, Xotdb_dir_info_.Tid_ttl)
.Fil_expd(fxt.fil_reg(Xow_ns_.Tid__main, Xotdb_dir_info_.Tid_ttl)
, "0|Title 1|Title 2a|2"
, ""
)
@ -53,19 +53,19 @@ public class Xob_tst {
( fxt.doc_(3, "2012-01-02 13:15", "↑", "t2")
, fxt.doc_(2, "2012-01-02 13:14", "!", "t1")
)
.Fil_expd(fxt.fil_ns_page(Xow_ns_.Id_main, 0)
.Fil_expd(fxt.fil_ns_page(Xow_ns_.Tid__main, 0)
, "!!!!5|!!!!3|"
, "!!!!$\t#6>K6\t↑\tt2\t"
, "!!!!#\t#6>K5\t!\tt1\t"
, ""
)
.Fil_expd(fxt.fil_ns_title(Xow_ns_.Id_main, 0)
.Fil_expd(fxt.fil_ns_title(Xow_ns_.Tid__main, 0)
, "!!!!=|!!!!?|"
, "!!!!#|!!!!!|!!!!\"|0|!!!!#|!"
, "!!!!$|!!!!!|!!!!!|0|!!!!#|↑"
, ""
)
.Fil_expd(fxt.fil_reg(Xow_ns_.Id_main, Xotdb_dir_info_.Tid_ttl)
.Fil_expd(fxt.fil_reg(Xow_ns_.Tid__main, Xotdb_dir_info_.Tid_ttl)
, "0|!|↑|2"
, ""
)
@ -76,17 +76,17 @@ public class Xob_tst {
fxt.doc_ary_
( fxt.doc_(2, "2012-01-02 13:14", "Template:A", "test a")
)
.Fil_expd(fxt.fil_ns_page(Xow_ns_.Id_template, 0)
.Fil_expd(fxt.fil_ns_page(Xow_ns_.Tid__template, 0)
, "!!!!7|"
, "!!!!#\t#6>K5\tA\ttest a\t"
, ""
)
.Fil_expd(fxt.fil_ns_title(Xow_ns_.Id_template, 0)
.Fil_expd(fxt.fil_ns_title(Xow_ns_.Tid__template, 0)
, "!!!!=|"
, "!!!!#|!!!!!|!!!!!|0|!!!!'|A"
, ""
)
.Fil_expd(fxt.fil_reg(Xow_ns_.Id_template, Xotdb_dir_info_.Tid_ttl)
.Fil_expd(fxt.fil_reg(Xow_ns_.Tid__template, Xotdb_dir_info_.Tid_ttl)
, "0|A|A|1"
, ""
)
@ -175,7 +175,7 @@ public class Xob_tst {
Io_mgr.Instance.SaveFilStr(url, raw);
Xotdb_page_raw_parser parser = new Xotdb_page_raw_parser();
Xowe_wiki wiki = Xoa_app_fxt.wiki_tst_(app);
parser.Load(Gfo_usr_dlg_.Test(), wiki, new Xow_ns(Xow_ns_.Id_template, Xow_ns_case_.Tid__1st, Bry_.new_a7("Template"), false), new Io_url[] {url}, 1 * Io_mgr.Len_kb);
parser.Load(Gfo_usr_dlg_.Test(), wiki, new Xow_ns(Xow_ns_.Tid__template, Xow_ns_case_.Tid__1st, Bry_.new_a7("Template"), false), new Io_url[] {url}, 1 * Io_mgr.Len_kb);
List_adp actl = List_adp_.new_();
Xowd_page_itm page = new Xowd_page_itm();
while (parser.Read(page)) {

@ -43,7 +43,7 @@ public class Xob_siteinfo_nde {
Xow_ns ns = ns_mgr.Ords_get_at(i);
bfr.Add_int_variable(ns.Id()).Add_byte_pipe();
bfr.Add_str_u8(Xow_ns_case_.To_str(ns.Case_match())).Add_byte_pipe();
bfr.Add(ns.Name_txt()).Add_byte_nl();
bfr.Add(ns.Name_ui()).Add_byte_nl();
}
}
}

@ -38,7 +38,7 @@ public class Xob_deploy_zip_cmd extends Xob_itm_basic_base implements Xob_cmd {
Log("zipping dir: ~{0}", ns_dir.Raw());
String ns_num = ns_dir.NameOnly();
Xow_ns ns_itm = wiki.Ns_mgr().Ids_get_or_null(Int_.parse(ns_num));
Zip_ns(bldr, ns_dir, type_name, ns_itm.Name_str());
Zip_ns(bldr, ns_dir, type_name, ns_itm.Name_db_str());
}
}
private void Zip_ns(Xob_bldr bldr, Io_url root_dir, String type_name, String ns_name) {

@ -25,7 +25,7 @@ public class Xob_redirect_cmd extends Xob_dump_mgr_base {
private Xodb_mgr_sql db_mgr; private Xop_redirect_mgr redirect_mgr; private Url_encoder encoder;
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_.Id_file);} // restrict to file ns
@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 protected void Init_reset(Db_conn conn) {
Db_cfg_tbl cfg_tbl = new Db_cfg_tbl(conn, "xowa_cfg");
@ -43,7 +43,7 @@ public class Xob_redirect_cmd extends Xob_dump_mgr_base {
}
@Override protected void Cmd_bgn_end() {}
@Override public void Exec_pg_itm_hook(int ns_ord, Xow_ns ns, Xowd_page_itm page, byte[] page_src) {
Xoa_ttl redirect_ttl = redirect_mgr.Extract_redirect(page_src, page_src.length);
Xoa_ttl redirect_ttl = redirect_mgr.Extract_redirect(page_src);
byte[] redirect_ttl_bry = Xoa_ttl.Replace_spaces(redirect_ttl.Page_db()); // NOTE: spaces can still exist b/c redirect is scraped from #REDIRECT which sometimes has a mix; EX: "A_b c"
redirect_ttl_bry = encoder.Decode(redirect_ttl_bry);
redirect_tbl.Insert(page.Id(), Xoa_ttl.Replace_spaces(page.Ttl_page_db()), -1, redirect_ttl.Ns().Id(), redirect_ttl_bry, redirect_ttl.Anch_txt(), 1);

@ -142,7 +142,7 @@ public class Xoa_css_extractor {
return true;
} private static final byte[] Ttl_common_css = Bry_.new_a7("Common.css"), Ttl_vector_css = Bry_.new_a7("Vector.css");
private boolean Css_wiki_generate_section(Bry_bfr bfr, byte[] ttl) {
byte[] page = page_fetcher.Get_by(Xow_ns_.Id_mediawiki, ttl);
byte[] page = page_fetcher.Get_by(Xow_ns_.Tid__mediawiki, ttl);
if (page == null) return false;
if (bfr.Len() != 0) bfr.Add_byte_nl().Add_byte_nl(); // add "\n\n" between sections; !=0 checks against first
Css_wiki_section_hdr.Bld_bfr_many(bfr, ttl); // add "/*XOWA:MediaWiki:Common.css*/\n"

@ -20,8 +20,8 @@ import org.junit.*; import gplx.core.ios.*; import gplx.xowa.wikis.nss.*;
public class Xoa_css_extractor_wiki_tst {
@Before public void init() {fxt.Clear();} private Xoa_css_extractor_fxt fxt = new Xoa_css_extractor_fxt();
@Test public void Css_wiki_generate() {
fxt.Init_page(Xow_ns_.Id_mediawiki, "Common.css" , "css_0");
fxt.Init_page(Xow_ns_.Id_mediawiki, "Vector.css" , "css_1");
fxt.Init_page(Xow_ns_.Tid__mediawiki, "Common.css" , "css_0");
fxt.Init_page(Xow_ns_.Tid__mediawiki, "Vector.css" , "css_1");
fxt.Exec_css_wiki_setup();
fxt.Test_fil("mem/xowa/user/anonymous/wiki/en.wikipedia.org/html/xowa_wiki.css", String_.Concat_lines_nl
( "/*XOWA:MediaWiki:Common.css*/"
@ -36,7 +36,7 @@ public class Xoa_css_extractor_wiki_tst {
fxt.Test_fil("mem/xowa/user/anonymous/wiki/en.wikipedia.org/html/xowa_wiki.css", "");
}
@Test public void Css_wiki_tab() { // PURPOSE: swap out &#09; for xdat files
fxt.Init_page(Xow_ns_.Id_mediawiki, "Common.css" , "a&#09;b");
fxt.Init_page(Xow_ns_.Tid__mediawiki, "Common.css" , "a&#09;b");
fxt.Exec_css_wiki_setup();
fxt.Test_fil("mem/xowa/user/anonymous/wiki/en.wikipedia.org/html/xowa_wiki.css", String_.Concat_lines_nl
( "/*XOWA:MediaWiki:Common.css*/"

@ -42,7 +42,7 @@ public class Xow_cfg_wiki_core {
for (int i = 0; i < nms_len; i++) {
Xow_ns ns = wiki.Ns_mgr().Ords_get_at(i);
wtr.Bfr().Add_int_variable(ns.Id()).Add_byte_pipe().Add_int_fixed(ns.Case_match(), 1).Add_byte_pipe();
csv_parser.Save(wtr.Bfr(), ns.Name_txt());
csv_parser.Save(wtr.Bfr(), ns.Name_ui());
wtr.Add_nl();
}
wtr.Add_quote_xtn_end();

@ -37,8 +37,8 @@ public class Xow_cfg_wiki_core_tst {
, "']:>"
, ");"
)
, fxt.ns_(Xow_ns_.Id_main , true, "")
, fxt.ns_(Xow_ns_.Id_project , false, "Wikipedia")
, fxt.ns_(Xow_ns_.Tid__main , true, "")
, fxt.ns_(Xow_ns_.Tid__project , false, "Wikipedia")
);
}
public static final String Const_wiki_core_cfg = String_.Concat_lines_nl
@ -89,7 +89,7 @@ class Xow_cfg_wiki_core_fxt {
}
public void Save_tst(String bldr_version, String main_page, String siteinfo_misc, int ns_user_case_match, String ns_user_name, String expd) {
wiki.Props().Bldr_version_(Bry_.new_a7(bldr_version)).Main_page_(Bry_.new_a7(main_page)).Siteinfo_misc_(Bry_.new_a7(siteinfo_misc));
Xow_ns ns_user = wiki.Ns_mgr().Ids_get_or_null(Xow_ns_.Id_user);
Xow_ns ns_user = wiki.Ns_mgr().Ids_get_or_null(Xow_ns_.Tid__user);
ns_user.Case_match_((byte)ns_user_case_match); ns_user.Name_bry_(Bry_.new_a7(ns_user_name));
Tfds.Eq_str_lines(expd, String_.new_a7(wiki.Cfg_wiki_core().Build_gfs()));
}
@ -105,7 +105,7 @@ class Xow_cfg_wiki_core_fxt {
Xow_ns expd = expd_ary[i];
Xow_ns actl = wiki.Ns_mgr().Ids_get_or_null(expd.Id());
Tfds.Eq(expd.Case_match(), actl.Case_match(), Int_.To_str(expd.Id()));
Tfds.Eq(expd.Name_str(), actl.Name_str(), Int_.To_str(expd.Id()));
Tfds.Eq(expd.Name_db_str(), actl.Name_db_str(), Int_.To_str(expd.Id()));
}
}
}

@ -24,8 +24,8 @@ public class Xowm_rev_wkr__meta__wm_tst {
@After public void term() {Gfo_usr_dlg_.Instance = Gfo_usr_dlg_.Noop;}
@Test public void Basic() {
Wmapi_itm__pge[] expd = fxt.Make_pge_ary
( fxt.Make_pge(Xow_ns_.Id_main, "A", 1, 11, 100, "2015-01-01T01:01:01Z", "user1", "note1")
, fxt.Make_pge(Xow_ns_.Id_main, "B", 2, 22, 200, "2015-02-02T02:02:02Z", "user2", "note2")
( fxt.Make_pge(Xow_ns_.Tid__main, "A", 1, 11, 100, "2015-01-01T01:01:01Z", "user1", "note1")
, fxt.Make_pge(Xow_ns_.Tid__main, "B", 2, 22, 200, "2015-02-02T02:02:02Z", "user2", "note2")
);
fxt.Init_inet_upload(expd);
fxt.Test_fetch(String_.Ary("A", "B"), expd); // test get both
@ -77,7 +77,7 @@ class Xowm_rev_wkr__meta__wm_fxt {
for (int i = 0; i < len; ++i) {
String ttl_str = ttl_ary[i];
byte[] ttl_bry = Bry_.new_u8(ttl_str);
rev_hash.Add(ttl_bry, new Wmapi_itm__pge().Init_ttl(Xow_ns_.Id_main, ttl_bry));
rev_hash.Add(ttl_bry, new Wmapi_itm__pge().Init_ttl(Xow_ns_.Tid__main, ttl_bry));
}
}
}

@ -59,7 +59,7 @@ public class Xob_xml_dumper {
wtr.Atr_kv_int("key" , ns.Id());
wtr.Atr_kv_str_a7("case" , Xow_ns_case_.To_str(ns.Case_match()));
wtr.Nde_lhs_end();
wtr.Txt_bry(ns.Name_bry());
wtr.Txt_bry(ns.Name_db());
wtr.Nde_rhs();
}
public void Write_page(Xowd_page_itm page) {

@ -21,7 +21,7 @@ public class Xob_xml_dumper_tst {
private final Xob_xml_dumper_fxt fxt = new Xob_xml_dumper_fxt();
@Before public void init() {fxt.Clear();}
@Test public void Basic() {
fxt.Test_page(fxt.Make_ary(fxt.Make_page(1, Xow_ns_.Id_main, "A", "A_text")), String_.Concat_lines_nl_skip_last
fxt.Test_page(fxt.Make_ary(fxt.Make_page(1, Xow_ns_.Tid__main, "A", "A_text")), String_.Concat_lines_nl_skip_last
( "<mediawiki xmlns='http://www.mediawiki.org/xml/export-0.10/' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xsi:schemaLocation='http://www.mediawiki.org/xml/export-0.10/ http://www.mediawiki.org/xml/export-0.10.xsd' version='0.10' xml:lang='en'>"
, " <siteinfo>"
, " <sitename>other</sitename>"

@ -85,17 +85,17 @@ public class Xob_xml_parser_tst {
}
@Test public void Ns_file() {
Xowd_page_itm doc = doc_(1, "File:a", "a", Date_1);
Tfds.Eq(Xow_ns_.Id_file, doc.Ns_id());
Tfds.Eq(Xow_ns_.Tid__file, doc.Ns_id());
Tfds.Eq("a", String_.new_u8(doc.Ttl_page_db()));
}
@Test public void Ns_main() {
Xowd_page_itm doc = doc_(1, "a", "a", Date_1);
Tfds.Eq(Xow_ns_.Id_main, doc.Ns_id());
Tfds.Eq(Xow_ns_.Tid__main, doc.Ns_id());
Tfds.Eq("a", String_.new_u8(doc.Ttl_page_db()));
}
@Test public void Ns_main_book() {
Xowd_page_itm doc = doc_(1, "Book", "a", Date_1);
Tfds.Eq(Xow_ns_.Id_main, doc.Ns_id());
Tfds.Eq(Xow_ns_.Tid__main, doc.Ns_id());
Tfds.Eq("Book", String_.new_u8(doc.Ttl_page_db()));
}
@Test public void XmlEntities() {

@ -15,12 +15,14 @@ GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.htmls.core.wkrs.spaces; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*; import gplx.xowa.htmls.core.wkrs.*;
import org.junit.*; import gplx.xowa.htmls.core.parsers.*;
public class Xoh_space_parse_tst {
private final Xoh_parser_fxt fxt = new Xoh_parser_fxt();
@Test public void Basic() {
fxt.Init__space(0, 6);
fxt.Test__parse(" ");
package gplx.xowa.files; import gplx.*; import gplx.xowa.*;
public class Xoa_file_mgr {
private final List_adp list = List_adp_.new_();
public void Clear() {list.Clear();}
public boolean Check_cache(Xof_fsdb_itm itm) {
return false;
}
public void Queue_for_viewing(Xof_fsdb_itm itm) {
list.Add(itm);
}
}

@ -148,4 +148,17 @@ public class Xof_fsdb_itm implements Xof_file_itm {
file_is_orig = img_size.File_is_orig();
}
}
public void To_bfr(Bry_bfr bfr) {
bfr .Add_int_variable(html_uid);
bfr.Add_byte_pipe().Add_int_variable(lnki_exec_tid);
bfr.Add_byte_pipe().Add(lnki_wiki_abrv);
bfr.Add_byte_pipe().Add_int_variable(lnki_type);
bfr.Add_byte_pipe().Add_double(lnki_upright);
bfr.Add_byte_pipe().Add_int_variable(lnki_upright_patch);
bfr.Add_byte_pipe().Add_int_variable(lnki_w);
bfr.Add_byte_pipe().Add_int_variable(lnki_h);
bfr.Add_byte_pipe().Add_double(lnki_time);
bfr.Add_byte_pipe().Add_int_variable(lnki_page);
bfr.Add_byte_nl();
}
}

@ -68,7 +68,7 @@ class Xof_file_fxt {
itm.Init_at_lnki(arg.Exec_tid(), wiki.Domain_itm().Abrv_xo(), ttl_bry, arg.Lnki_type(), arg.Lnki_upright(), arg.Lnki_w(), arg.Lnki_h(), arg.Lnki_time(), Xof_lnki_page.Null, Xof_patch_upright_tid_.Tid_all);
List_adp itms_list = List_adp_.new_(); itms_list.Add(itm);
orig_mgr.Find_by_list(Ordered_hash_.New_bry(), itms_list, Xof_exec_tid.Tid_wiki_page);
Xoa_ttl ttl = Xoa_ttl.parse(wiki, Xow_ns_.Id_main, ttl_bry);
Xoa_ttl ttl = Xoa_ttl.parse(wiki, Xow_ns_.Tid__main, ttl_bry);
Xoae_page page = Xoae_page.new_(wiki, ttl);
fsdb_mgr.Fsdb_search_by_list(itms_list, wiki, page, Xog_js_wkr_.Noop);
if (arg.Rslt_orig_exists() != Bool_.__byte) Tfds.Eq(arg.Rslt_orig_exists() == Bool_.Y_byte, itm.Orig_exists(), "orig_exists");

@ -36,7 +36,7 @@ public class Js_img_mgr {
String html_id = To_doc_uid(uid);
js_wkr.Html_img_update(html_id, html_view_url.To_http_file_str(), html_w, html_h);
if (Xop_lnki_type.Id_is_thumbable(lnki_type)) { // thumb needs to set cls and width
js_wkr.Html_atr_set(html_id, "class", gplx.xowa.htmls.core.wkrs.lnkis.htmls.Xoh_lnki_consts.Str_img_cls_thumbimage);
js_wkr.Html_atr_set(html_id, "class", gplx.xowa.htmls.core.wkrs.imgs.atrs.Xoh_img_cls_.Str__thumbimage);
js_wkr.Html_atr_set("xowa_file_div_" + uid, "style", "width:" + html_w + "px;");
}
switch (elem_tid) {

@ -64,7 +64,7 @@ public class Xofw_wiki_wkr_base implements Xofw_wiki_finder {
if (db_page.Redirected()) {
wiki.Db_mgr().Load_mgr().Load_page(db_page, file_ns, false);
byte[] src = db_page.Text();
Xoa_ttl redirect_ttl = wiki.Redirect_mgr().Extract_redirect(src, src.length);
Xoa_ttl redirect_ttl = wiki.Redirect_mgr().Extract_redirect(src);
return redirect_ttl == Xop_redirect_mgr.Redirect_null_ttl ? Xop_redirect_mgr.Redirect_null_bry : redirect_ttl.Page_db();
}
else

@ -69,7 +69,7 @@ public class Xog_history_mgr {
byte[] page = pg.Ttl().Full_url(); // get page_name only (no anchor; no query args)
byte[] anch = pg.Url().Anch_bry();
byte[] qarg = pg.Url().Qargs_mgr().To_bry();
boolean redirect_force = pg.Url().Qargs_mgr().Match(Xoa_url_.Qarg__redirect, Xoa_url_.Qarg__redirect__yes);
boolean redirect_force = pg.Url().Qargs_mgr().Match(Xoa_url_.Qarg__redirect, Xoa_url_.Qarg__redirect__no);
String bmk_pos = pg.Html_data().Bmk_pos();
if (bmk_pos == null) bmk_pos = Xog_history_itm.Html_doc_pos_toc; // never allow null doc_pos; set to top
return new Xog_history_itm(wiki, page, anch, qarg, redirect_force, bmk_pos);

@ -151,7 +151,7 @@ public class Xog_tab_itm implements GfoInvkAble {
if (page.Redirected_ttls().Count() > 0)
usr_dlg.Prog_many("", "", "could not find: ~{0} (redirected from ~{1})", String_.new_u8(page.Url().Page_bry()), String_.new_u8((byte[])page.Redirected_ttls().Get_at(0)));
else {
if (ttl.Ns().Id_file())
if (ttl.Ns().Id_is_file())
usr_dlg.Prog_one("", "", "commons.wikimedia.org must be installed in order to view the file. See [[Help:Wikis/Commons]]: ~{0}", String_.new_u8(url.Raw()));
else
usr_dlg.Prog_one("", "", "could not find: ~{0}", String_.new_u8(url.Raw()));

@ -82,7 +82,7 @@ public class Xog_tab_itm_edit_mgr {
new_text = Xoa_ttl.Replace_spaces(new_text); // ttls cannot have spaces; only underscores
Xoa_ttl new_ttl = Xoa_ttl.parse(wiki, new_text);
int new_ns_id = new_ttl.Ns().Id();
if (new_ns_id != Xow_ns_.Id_main) {
if (new_ns_id != Xow_ns_.Tid__main) {
win_itm.Usr_dlg().Warn_many("", "", "The new page name must remain in the same namespace");
return;
}

@ -185,7 +185,7 @@ public class Xog_win_itm implements GfoInvkAble, GfoEvObj {
Xoae_page cur_page = tab.Page(); Xowe_wiki cur_wiki = tab.Wiki();
Xoae_page new_page = tab.History_mgr().Go_by_dir(cur_wiki, fwd);
if (new_page.Missing()) return;
if (new_page.Ttl().Ns().Id_special()) // if Special, reload page; needed for Special:Search (DATE:2015-04-19; async loading) and Special:XowaBookmarks DATE:2015-10-05
if (new_page.Ttl().Ns().Id_is_special()) // if Special, reload page; needed for Special:Search (DATE:2015-04-19; async loading) and Special:XowaBookmarks DATE:2015-10-05
new_page = new_page.Wikie().Data_mgr().Load_page_by_ttl(new_page.Url(), new_page.Ttl()); // NOTE: must reparse page if (a) Edit -> Read; or (b) "Options" save
byte history_nav_type = fwd ? Xog_history_stack.Nav_fwd : Xog_history_stack.Nav_bwd;
boolean new_page_is_same = Bry_.Eq(cur_page.Ttl().Full_txt(), new_page.Ttl().Full_txt());

@ -53,4 +53,5 @@ public class Xoh_consts {
, Atr_xowa_title_bry = Bry_.new_a7(Atr_xowa_title_str)
;
public static final int Nbsp_int = 160;
public static String Escape_apos(String s) {return String_.Replace(s, "'", "\"");}
}

@ -0,0 +1,43 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.htmls; import gplx.*; import gplx.xowa.*;
import gplx.xowa.files.*;
public class Xoh_img_mgr {
private final List_adp list = List_adp_.new_();
private int uid_nxt = -1;
public void Clear() {
this.uid_nxt = -1;
list.Clear();
}
public int Len() {return list.Count();}
public Xof_fsdb_itm Get_at(int i) {return (Xof_fsdb_itm)list.Get_at(i);}
public Xof_fsdb_itm Make_img() {
Xof_fsdb_itm itm = new Xof_fsdb_itm();
itm.Init_at_hdoc(++uid_nxt, Xof_html_elem.Tid_img);
list.Add(itm);
return itm;
}
public void To_bfr(Bry_bfr bfr) {
int len = this.Len();
for (int i = 0; i < len; ++i) {
Xof_fsdb_itm itm = this.Get_at(i);
itm.To_bfr(bfr);
}
}
public static final byte[] Bry__html_uid = Bry_.new_a7("xoimg_");
}

@ -28,12 +28,13 @@ public class Xoh_page implements Xoa_page {
public int Page_id() {return page_id;} private int page_id;
public byte[] Body() {return body;} public void Body_(byte[] v) {this.body = v;} private byte[] body;
public byte Body_flag() {return body_flag;} private byte body_flag = Byte_.Max_value_127;
public Xoh_section_mgr Section_mgr() {return section_mgr;} private final Xoh_section_mgr section_mgr = new Xoh_section_mgr();
public byte[] Display_ttl() {return display_ttl;} private byte[] display_ttl;
public byte[] Content_sub() {return content_sub;} private byte[] content_sub;
public byte[] Sidebar_div() {return sidebar_div;} private byte[] sidebar_div;
public Xoh_section_mgr Section_mgr() {return section_mgr;} private final Xoh_section_mgr section_mgr = new Xoh_section_mgr();
public Xoh_img_mgr Img_mgr() {return img_mgr;} private Xoh_img_mgr img_mgr = new Xoh_img_mgr();
public Ordered_hash Redlink_uids() {return redlink_uids;} private final Ordered_hash redlink_uids = Ordered_hash_.New();
public int Img_count() {return img_count;} public void Img_count_(int v) {img_count = v;} private int img_count;
public Xohd_img_itm__base[] Img_itms() {return img_itms;} public void Img_itms_(Xohd_img_itm__base[] v) {this.img_itms = v;} private Xohd_img_itm__base[] img_itms = Xohd_img_itm__base.Ary_empty;
public Ordered_hash Gallery_itms() {return gallery_itms;} private Ordered_hash gallery_itms = Ordered_hash_.New();
public Xopg_module_mgr Head_mgr() {return head_mgr;} private Xopg_module_mgr head_mgr = new Xopg_module_mgr();
@ -66,5 +67,6 @@ public class Xoh_page implements Xoa_page {
display_ttl = content_sub = sidebar_div = Bry_.Empty;
img_itms = Xohd_img_itm__base.Ary_empty;
head_mgr.Clear(); gallery_itms.Clear(); redlink_uids.Clear(); commons_mgr.Clear();
section_mgr.Clear(); img_mgr.Clear();
}
}

@ -131,13 +131,13 @@ public class Xoh_page_wtr_wkr implements Bry_fmtr_arg {
}
// dump and exit if MediaWiki message;
if (ns_id == Xow_ns_.Id_mediawiki) { // if MediaWiki and wikitext, must be a message; convert args back to php; DATE:2014-06-13
if (ns_id == Xow_ns_.Tid__mediawiki) { // if MediaWiki and wikitext, must be a message; convert args back to php; DATE:2014-06-13
bfr.Add(Xoa_gfs_php_mgr.Xto_php(tmp_bfr, Bool_.N, data_raw));
return;
}
// if [[File]], add boilerplate header; note that html is XOWA-generated so does not need to be tidied
if (ns_id == Xow_ns_.Id_file) app.Ns_file_page_mgr().Bld_html(wiki, ctx, page, bfr, page.Ttl(), wiki.Cfg_file_page(), page.File_queue());
if (ns_id == Xow_ns_.Tid__file) app.Ns_file_page_mgr().Bld_html(wiki, ctx, page, bfr, page.Ttl(), wiki.Cfg_file_page(), page.File_queue());
// get separate bfr; note that bfr already has <html> and <head> written to it, so this can't be passed to tidy; DATE:2014-06-11
Bry_bfr tidy_bfr = app.Utl__bfr_mkr().Get_m001();
@ -147,7 +147,7 @@ public class Xoh_page_wtr_wkr implements Bry_fmtr_arg {
wiki.Html_mgr().Html_wtr().Write_all(tidy_bfr, page.Wikie().Parser_mgr().Ctx(), hctx, page.Root().Data_mid(), page.Root());
// if [[Category]], render rest of html (Subcategories; Pages; Files); note that a category may have other html which requires wikitext processing
if (ns_id == Xow_ns_.Id_category) wiki.Html_mgr().Ns_ctg().Bld_html(wiki, page, tidy_bfr);
if (ns_id == Xow_ns_.Tid__category) wiki.Html_mgr().Ns_ctg().Bld_html(wiki, page, tidy_bfr);
// tidy html
gplx.xowa.htmls.core.htmls.tidy.Xoh_tidy_mgr tidy_mgr = app.Html_mgr().Tidy_mgr();
@ -180,7 +180,7 @@ public class Xoh_page_wtr_wkr implements Bry_fmtr_arg {
tmp_bfr.Clear();
}
private void Write_body_edit(Bry_bfr bfr, byte[] data_raw, int ns_id, byte page_tid) {
if ( ns_id == Xow_ns_.Id_mediawiki // if MediaWiki and wikitext, must be a message; convert args back to php; DATE:2014-06-13
if ( ns_id == Xow_ns_.Tid__mediawiki // if MediaWiki and wikitext, must be a message; convert args back to php; DATE:2014-06-13
&& page_tid == Xow_page_tid.Tid_wikitext
)
data_raw = Xoa_gfs_php_mgr.Xto_php(tmp_bfr, Bool_.N, data_raw);

@ -28,8 +28,8 @@ public class Xoh_page_wtr_wkr_ {
}
public static byte[] Bld_page_name(Bry_bfr tmp_bfr, Xoa_ttl ttl, byte[] display_ttl) {
if (display_ttl != null) return display_ttl; // display_ttl explicitly set; use it
if (ttl.Ns().Id() == Xow_ns_.Id_special) { // special: omit query args, else excessively long titles: EX:"Special:Search/earth?fulltext=y&xowa page index=1"
tmp_bfr.Add(ttl.Ns().Name_txt_w_colon()).Add(ttl.Page_txt_wo_qargs());
if (ttl.Ns().Id() == Xow_ns_.Tid__special) { // special: omit query args, else excessively long titles: EX:"Special:Search/earth?fulltext=y&xowa page index=1"
tmp_bfr.Add(ttl.Ns().Name_ui_w_colon()).Add(ttl.Page_txt_wo_qargs());
return tmp_bfr.To_bry_and_clear();
}
else

@ -42,7 +42,7 @@ public class Xow_hdump_mgr__load {
hpg.Init(hpg.Wiki(), hpg.Url(), ttl, tmp_dbpg.Id());
if (!html_db.Tbl__html_page().Select_by_page(hpg)) return Load__fail(hpg); // nothing in "html_page" table
byte[] src = hzip_mgr.Parse(hpg.Url_bry_safe(), hpg.Body_flag(), hpg.Body());
hpg.Body_(make_mgr.Parse(hpg, src));
hpg.Body_(make_mgr.Parse(src, hpg, hpg.Wiki()));
return true;
}
}

@ -21,6 +21,7 @@ import gplx.xowa.htmls.core.*; import gplx.xowa.htmls.core.makes.imgs.*; import
import gplx.xowa.parsers.*;
public class Xow_hdump_mgr__load_tst {
@Before public void init() {fxt.Clear();} private Xohd_hdump_wtr_fxt fxt = new Xohd_hdump_wtr_fxt();
@Test public void Stub() {}
// @Test public void Image_full() {
// fxt.Expd_itms_xfers(fxt.Make_xfer("A.png", 0, 0, 0, Bool_.Y, Xof_ext_.Id_png));
// fxt.Test_write_all
@ -42,68 +43,68 @@ public class Xow_hdump_mgr__load_tst {
// , "</div>"
// ));
// }
@Test public void Audio_thumb() {
fxt.Expd_itms_xfers(fxt.Make_xfer("A.oga", 0, 220, -1, Bool_.N, Xof_ext_.Id_oga));
fxt.Test_write_all
( "[[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>"
, " <div class=\"thumbcaption\"><xowa_mgnf id='0'/>"
, " test_caption"
, " </div>"
, " </div>"
, "</div>"
));
}
@Test public void Video_thumb() {
fxt.Expd_itms_xfers(fxt.Make_xfer("A.ogv", 0, 0, 0, Bool_.N, Xof_ext_.Id_ogv));
fxt.Test_write_all
( "[[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>"
, " <a href=\"/wiki/File:A.ogv\" class=\"image\" title=\"A.ogv\">"
, " <img id=\"xowa_file_img_0\" xowa_img='0' alt=\"\" />"
, " </a>"
, " </div><xowa_play id='0'/>"
, " </div>"
, " <div class=\"thumbcaption\"><xowa_mgnf id='0'/>"
, " test_caption"
, " </div>"
, " </div>"
, "</div>"
));
}
@Test public void Hiero() {
Hiero_html_mgr_fxt hiero_fxt = new Hiero_html_mgr_fxt(fxt.Fxt());
hiero_fxt.Reset();
hiero_fxt.Init_hiero_A1_B1();
fxt.Test_write_frag("<hiero>A1</hiero>", "src='~{xowa_hiero_dir}hiero_A1.png'");
}
@Test public void Gallery() {
Gallery_mgr_base.File_found_mode = Bool_.__byte;
fxt.Test_write_all
( "<gallery>File:A.png|A1</gallery>", String_.Concat_lines_nl_skip_last
( "<ul id=\"xowa_gallery_ul_0\" class=\"gallery mw-gallery-traditional\" xowa_gly_box_max='0'>"
, " <li id=\"xowa_gallery_li_0\" class=\"gallerybox\" xowa_gly_box_w='0'>"
, " <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>"
, " </div>"
, " </div>"
, " <div class=\"gallerytext\"><p>A1"
, "</p>"
, ""
, " </div>"
, " </div>"
, " </li>"
, "</ul>"
));
}
// @Test public void Audio_thumb() {
// fxt.Expd_itms_xfers(fxt.Make_xfer("A.oga", 0, 220, -1, Bool_.N, Xof_ext_.Id_oga));
// fxt.Test_write_all
// ( "[[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>"
// , " <div class=\"thumbcaption\"><xowa_mgnf id='0'/>"
// , " test_caption"
// , " </div>"
// , " </div>"
// , "</div>"
// ));
// }
// @Test public void Video_thumb() {
// fxt.Expd_itms_xfers(fxt.Make_xfer("A.ogv", 0, 0, 0, Bool_.N, Xof_ext_.Id_ogv));
// fxt.Test_write_all
// ( "[[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>"
// , " <a href=\"/wiki/File:A.ogv\" class=\"image\" title=\"A.ogv\">"
// , " <img id=\"xowa_file_img_0\" xowa_img='0' alt=\"\" />"
// , " </a>"
// , " </div><xowa_play id='0'/>"
// , " </div>"
// , " <div class=\"thumbcaption\"><xowa_mgnf id='0'/>"
// , " test_caption"
// , " </div>"
// , " </div>"
// , "</div>"
// ));
// }
// @Test public void Hiero() {
// Hiero_html_mgr_fxt hiero_fxt = new Hiero_html_mgr_fxt(fxt.Fxt());
// hiero_fxt.Reset();
// hiero_fxt.Init_hiero_A1_B1();
// fxt.Test_write_frag("<hiero>A1</hiero>", "src='~{xowa_hiero_dir}hiero_A1.png'");
// }
// @Test public void Gallery() {
// Gallery_mgr_base.File_found_mode = Bool_.__byte;
// fxt.Test_write_all
// ( "<gallery>File:A.png|A1</gallery>", String_.Concat_lines_nl_skip_last
// ( "<ul id=\"xowa_gallery_ul_0\" class=\"gallery mw-gallery-traditional\" xowa_gly_box_max='0'>"
// , " <li id=\"xowa_gallery_li_0\" class=\"gallerybox\" xowa_gly_box_w='0'>"
// , " <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>"
// , " </div>"
// , " </div>"
// , " <div class=\"gallerytext\"><p>A1"
// , "</p>"
// , ""
// , " </div>"
// , " </div>"
// , " </li>"
// , "</ul>"
// ));
// }
}
class Xodb_hdump_mgr__base_fxt {
protected Bry_bfr bfr = Bry_bfr.reset_(255);

@ -81,36 +81,36 @@ interface Page_async_cmd {
void Prep();
void Exec();
}
class Page_async_cmd__img implements Page_async_cmd {
private Xoh_page hpg;
private List_adp missing = List_adp_.new_();
public Page_async_cmd__img(Xoh_page hpg) {this.hpg = hpg;}
public void Prep() {
int len = hpg.Img_count();
Xohd_img_itm__base[] ary = hpg.Img_itms();
missing.Clear();
for (int i = 0; i < len; ++i) {
Xohd_img_itm__base itm = ary[i];
boolean exists = Io_mgr.Instance.ExistsFil(itm.Html_view_url());
if (!exists) missing.Add(itm);
}
}
public void Exec() {
int len = missing.Count();
for (int i = 0; i < len; ++i) {
// Xohd_img_itm__base itm = (Xohd_img_itm__base)missing.Get_at(i);
// byte[] bytes = null; //fsdb.Db_get()ttl, file_w,....):
// Write file(bytes);
}
}
}
/*
CREATE TABLE xtn_gallery
( src_page_id integer NOT NULL
, html_uid integer NOT NULL
, box_max integer NOT NULL
, box_w integer NOT NULL
, img_w integer NOT NULL
, img_pad integer NOT NULL
);
*/
// class Page_async_cmd__img : Page_async_cmd {
// private Xoh_page hpg;
// private List_adp missing = List_adp_.new_();
// public Page_async_cmd__img(Xoh_page hpg) {this.hpg = hpg;}
// public void Prep() {
//// int len = hpg.Img_count();
//// Xohd_img_itm__base[] ary = hpg.Img_itms();
//// missing.Clear();
//// for (int i = 0; i < len; ++i) {
//// Xohd_img_itm__base itm = ary[i];
//// boolean exists = Io_mgr.Instance.ExistsFil(itm.Html_view_url());
//// if (!exists) missing.Add(itm);
//// }
// }
// public void Exec() {
// int len = missing.Count();
// for (int i = 0; i < len; ++i) {
//// Xohd_img_itm__base itm = (Xohd_img_itm__base)missing.Get_at(i);
//// byte[] bytes = null; //fsdb.Db_get()ttl, file_w,....):
//// Write file(bytes);
// }
// }
// }
// /*
// CREATE TABLE xtn_gallery
// ( src_page_id integer NOT NULL
// , html_uid integer NOT NULL
// , box_max integer NOT NULL
// , box_w integer NOT NULL
// , img_w integer NOT NULL
// , img_pad integer NOT NULL
// );
// */

@ -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.xowa.htmls.core.hzips; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*;
import gplx.xowa.files.*; import gplx.xowa.apps.fsys.*; import gplx.xowa.wikis.domains.*; import gplx.xowa.wikis.ttls.*;
public class Xoh_decode_ctx {
private byte[] dir__file;
public Xof_url_bldr Url_bldr() {return url_bldr;} private Xof_url_bldr url_bldr = new Xof_url_bldr();
public byte[] Dir__root() {return dir__root;} private byte[] dir__root;
public byte[] Dir__file__comm() {return dir__file__comm;} private byte[] dir__file__comm;
public byte[] Dir__file__wiki() {return dir__file__wiki;} private byte[] dir__file__wiki;
public Xow_ttl_parser Ttl_parser() {return ttl_parser;} private Xow_ttl_parser ttl_parser;
public void Init_by_app(Xoa_app app) {
Xoa_fsys_mgr fsys_mgr = app.Fsys_mgr();
this.dir__root = fsys_mgr.Root_dir().To_http_file_bry();
this.dir__file = fsys_mgr.File_dir().To_http_file_bry();
this.dir__file__comm = Bry_.Add(dir__file, Xow_domain_itm_.Bry__commons, Byte_ascii.Slash_bry);
}
public void Init_by_page(Xow_wiki wiki) {
if (dir__root == null) Init_by_app(wiki.App()); // LAZY INIT
this.ttl_parser = wiki;
this.dir__file__wiki = Bry_.Add(dir__file, wiki.Domain_bry(), Byte_ascii.Slash_bry);
}
}

@ -18,6 +18,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
package gplx.xowa.htmls.core.hzips; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*;
import gplx.core.primitives.*; import gplx.core.btries.*;
import gplx.xowa.htmls.core.wkrs.spaces.*; import gplx.xowa.htmls.core.wkrs.hdrs.*; import gplx.xowa.htmls.core.wkrs.lnkes.*; import gplx.xowa.htmls.core.wkrs.lnkis.*; import gplx.xowa.htmls.core.wkrs.escapes.*;
import gplx.xowa.htmls.core.wkrs.imgs.*;
public class Xoh_hzip_dict_ {
public static final byte Escape = Byte_.By_int(27); // SERIALIZED: 27=escape byte
public static final byte[] Escape_bry = Bry_.new_ints(27); // SERIALIZED
@ -27,44 +28,40 @@ public class Xoh_hzip_dict_ {
, Tid__hdr = 1 + Base85_ascii
, Tid__lnke = 2 + Base85_ascii
, Tid__lnki = 3 + Base85_ascii
, Tid__img = 4 + Base85_ascii
, Tid__escape = 84 + Base85_ascii
;
public static final byte[]
Bry__space = Bry_.new_ints(Escape, Tid__space)
Bry__escape = Bry_.new_ints(Escape, Tid__escape)
, Bry__space = Bry_.new_ints(Escape, Tid__space)
, Bry__hdr = Bry_.new_ints(Escape, Tid__hdr)
, Bry__lnke = Bry_.new_ints(Escape, Tid__lnke)
, Bry__lnki = Bry_.new_ints(Escape, Tid__lnki)
, Bry__escape = Bry_.new_ints(Escape, Tid__escape)
, Bry__img = Bry_.new_ints(Escape, Tid__img)
;
public static final String
Key__space = "space"
Key__escape = "escape"
, Key__space = "space"
, Key__hdr = "hdr"
, Key__lnke = "lnke"
, Key__lnki = "lnki"
, Key__escape = "escape"
, Key__img = "img"
;
public static Xoh_hzip_wkr To_wkr(byte tid) {
switch (tid) {
case Tid__escape: return Wkr__escape;
case Tid__space: return Wkr__space;
case Tid__hdr: return Wkr__hdr;
case Tid__lnke: return Wkr__lnke;
case Tid__lnki: return Wkr__lnki;
case Tid__escape: return Wkr__escape;
case Tid__img: return Wkr__img;
default: throw Err_.new_unhandled(tid);
}
}
public static final Btrie_slim_mgr Trie = Btrie_slim_mgr.cs()
.Add_bry_byte(Xoh_html_dict_.Hook__space , Xoh_hzip_dict_.Tid__space) // 4 spaces b/c escape code will be 3 bytes
.Add_bry_byte(Xoh_html_dict_.Type__hdr , Xoh_hzip_dict_.Tid__hdr)
.Add_bry_byte(Xoh_html_dict_.Hook__lnke , Xoh_hzip_dict_.Tid__lnke)
.Add_bry_byte(Xoh_html_dict_.Hook__lnki , Xoh_hzip_dict_.Tid__lnki)
.Add_bry_byte(Escape_bry , Xoh_hzip_dict_.Tid__escape)
;
public static final Xoh_hzip_wkr
Wkr__space = new Xoh_space_hzip()
, Wkr__hdr = new Xoh_hdr_hzip()
, Wkr__lnke = new Xoh_lnke_hzip()
, Wkr__lnki = new Xoh_lnki_hzip()
, Wkr__escape = new Xoh_escape_hzip()
;
public static final Xoh_escape_hzip Wkr__escape = new Xoh_escape_hzip();
public static final Xoh_space_hzip Wkr__space = new Xoh_space_hzip();
public static final Xoh_hdr_hzip Wkr__hdr = new Xoh_hdr_hzip();
public static final Xoh_lnke_hzip Wkr__lnke = new Xoh_lnke_hzip();
public static final Xoh_lnki_hzip Wkr__lnki = new Xoh_lnki_hzip();
public static final Xoh_img_hzip Wkr__img = new Xoh_img_hzip();
}

@ -18,6 +18,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
package gplx.xowa.htmls.core.hzips; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*;
import gplx.core.primitives.*; import gplx.core.encoders.*;
public class Xoh_hzip_int_ {
public static final int Neg_1_adj = 1;
public static void Encode(int reqd, Bry_bfr bfr, int val) {
int bfr_len = bfr.Len();
int len_in_base85 = Base85_.Bry_len(val);

@ -18,48 +18,29 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
package gplx.xowa.htmls.core.hzips; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*;
import gplx.core.primitives.*; import gplx.core.brys.*; import gplx.core.btries.*; import gplx.xowa.wikis.ttls.*;
import gplx.xowa.htmls.core.hzips.stats.*;
import gplx.xowa.htmls.core.wkrs.hdrs.*; import gplx.xowa.htmls.core.wkrs.lnkes.*; import gplx.xowa.htmls.core.wkrs.lnkis.*; import gplx.xowa.htmls.core.wkrs.spaces.*; import gplx.xowa.htmls.core.wkrs.escapes.*;
import gplx.xowa.htmls.core.wkrs.*; import gplx.langs.htmls.parsers.*;
public class Xoh_hzip_mgr {
private final Btrie_slim_mgr trie = Xoh_hzip_dict_.Trie;
private final Bry_parser parser = new Bry_parser();
public void Encode(Bry_bfr bfr, Xow_ttl_parser ttl_parser, byte[] page_url, byte[] src, Hzip_stat_itm stat_itm) {
bfr.Clear(); stat_itm.Clear();
((Xoh_lnki_hzip)Xoh_hzip_dict_.To_wkr(Xoh_hzip_dict_.Tid__lnki)).Ttl_parser_(ttl_parser);
int pos = 0, add_bgn = -1; int src_len = src.length;
parser.Init_src(page_url, src, src_len, 0);
while (pos < src_len) {
Object o = trie.Match_bgn_w_byte(src[pos], src, pos, src_len);
if (o == null) {
if (add_bgn == -1) add_bgn = pos;
++pos;
}
else {
if (add_bgn != -1) {bfr.Add_mid(src, add_bgn, pos); add_bgn = -1;}
try {
Xoh_hzip_wkr wkr = Xoh_hzip_dict_.To_wkr(((Byte_obj_val)o).Val());
parser.Init_hook(wkr.Key(), pos, trie.Match_pos());
wkr.Encode(bfr, stat_itm, parser, src, pos);
pos = parser.Pos();
} catch (Exception e) {
Gfo_usr_dlg_.Instance.Warn_many("", "", Err_.Message_gplx_log(e));
pos = trie.Match_pos();
}
}
}
if (add_bgn != -1) bfr.Add_mid(src, add_bgn, src_len);
private final Bry_rdr rdr = new Bry_rdr().Dflt_dlm_(Xoh_hzip_dict_.Escape);
private final Xoh_hdoc_wkr__base hdoc_parser = new Xoh_hdoc_wkr__base(new Xoh_hdoc_wkr__hzip());
private final Xoh_decode_ctx decode_ctx = new Xoh_decode_ctx();
public void Init_by_app(Xoa_app app) {decode_ctx.Init_by_app(app);}
public void Encode(Bry_bfr bfr, Xow_wiki wiki, byte[] page_url, byte[] src, Hzip_stat_itm stat_itm) {
hdoc_parser.Parse(bfr, wiki, null, page_url, src);
}
public byte[] Decode(Bry_bfr bfr, Xow_ttl_parser ttl_parser, byte[] page_url, byte[] src) {
public byte[] Decode(Bry_bfr bfr, Xow_wiki wiki, byte[] page_url, byte[] src) {
bfr.Clear();
((gplx.xowa.htmls.core.wkrs.lnkis.Xoh_lnki_hzip)Xoh_hzip_dict_.To_wkr(Xoh_hzip_dict_.Tid__lnki)).Ttl_parser_(wiki);
int pos = 0, add_bgn = -1; int src_len = src.length;
parser.Init_src(page_url, src, src_len, 0);
rdr.Ctor_by_page(page_url, src, src_len);
decode_ctx.Init_by_page(wiki);
while (pos < src_len) {
if (src[pos] == Xoh_hzip_dict_.Escape) {
if (add_bgn != -1) {bfr.Add_mid(src, add_bgn, pos); add_bgn = -1;}
try {
Xoh_hzip_wkr wkr = Xoh_hzip_dict_.To_wkr(src[pos + 1]);
parser.Init_hook(wkr.Key(), pos, pos + 2);
wkr.Decode(bfr, parser, src, pos);
pos = parser.Pos();
rdr.Init_by_hook(wkr.Key(), pos, pos + 2);
wkr.Decode(bfr, decode_ctx, rdr, src, pos);
pos = rdr.Pos();
} catch (Exception e) {
Gfo_usr_dlg_.Instance.Warn_many("", "", Err_.Message_gplx_log(e));
pos += 2;

@ -1,71 +0,0 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.htmls.core.hzips; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*;
import gplx.xowa.parsers.*;
import gplx.xowa.htmls.core.htmls.*; import gplx.xowa.htmls.core.hzips.stats.*;
public class Xoh_hzip_mgr_fxt {
private final Bry_bfr bfr = Bry_bfr.reset_(Io_mgr.Len_mb); private Xoh_hzip_mgr hzip_mgr; private Xowe_wiki wiki;
private Hzip_stat_itm stat_itm = new Hzip_stat_itm();
public void Clear() {
if (hzip_mgr == null) {
Xoae_app app = Xoa_app_fxt.app_();
wiki = Xoa_app_fxt.wiki_tst_(app);
hzip_mgr = wiki.Html__hdump_mgr().Hzip_mgr().Hzip_mgr();
wiki.Init_by_wiki();
}
}
public void Init_xwiki(String alias, String domain) {
wiki.Appe().Wiki_mgr().Get_by_key_or_make(Bry_.new_u8(domain));
wiki.Xwiki_mgr().Add_by_atrs(alias, domain);
wiki.Appe().Usere().Wiki().Xwiki_mgr().Add_by_atrs(domain, domain);
}
public void Test_save(byte[][] expd_brys, String html) {Test_save(html, expd_brys);}
public void Test_save(String html, byte[]... expd_brys) {
byte[] expd = Bry_.Add(expd_brys);
hzip_mgr.Encode(bfr, wiki, Bry_.Empty, Bry_.new_u8(html), stat_itm);
Tfds.Eq_ary(expd, bfr.To_bry_and_clear());
}
private final Xoh_page hpg = new Xoh_page();
public void Test_swap(String src, String expd) {
Gfo_usr_dlg_.Instance = Gfo_usr_dlg_.Test_console();
byte[] actl = wiki.Html__hdump_mgr().Load_mgr().Make_mgr().Parse(hpg, Bry_.new_u8(src));
Gfo_usr_dlg_.Instance = Gfo_usr_dlg_.Noop;
Tfds.Eq_str_lines(expd, String_.new_u8(actl));
}
public void Test_load(byte[][] src_brys, String expd) {Test_load(Bry_.Add(src_brys), expd);}
public void Test_load(String src, String expd) {Test_load(Bry_.new_u8(src), expd);}
public void Test_load(byte[] src, String expd) {
byte[] actl = hzip_mgr.Decode(bfr, wiki, Bry_.Empty, src);
Tfds.Eq(expd, String_.new_u8(actl));
}
public void Test_html(String wtxt, String expd) {
Xop_ctx ctx = wiki.Parser_mgr().Ctx(); Xop_parser parser = wiki.Parser_mgr().Main(); Xop_tkn_mkr tkn_mkr = ctx.Tkn_mkr();
ctx.Para().Enabled_n_();
ctx.Cur_page().Redlink_lnki_list().Clear();
byte[] html_bry = Bry_.new_u8(wtxt);
Xop_root_tkn root = ctx.Tkn_mkr().Root(html_bry);
parser.Parse_page_all_clear(root, ctx, tkn_mkr, html_bry);
Xoh_wtr_ctx hctx = Xoh_wtr_ctx.Hdump;
Xoh_html_wtr html_wtr = wiki.Html_mgr().Html_wtr();
html_wtr.Cfg().Toc__show_(Bool_.Y); // needed for hdr to show <span class='mw-headline' id='A'>
html_wtr.Cfg().Lnki__title_(Bool_.N);
html_wtr.Cfg().Lnki__id_(Bool_.N);
html_wtr.Write_all(bfr, ctx, hctx, html_bry, root);
Tfds.Eq_str_lines(expd, bfr.To_str_and_clear());
}
}

@ -17,9 +17,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.htmls.core.hzips; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*;
import gplx.core.brys.*;
import gplx.xowa.htmls.core.hzips.stats.*;
public interface Xoh_hzip_wkr {
String Key();
void Encode(Bry_bfr bfr, Hzip_stat_itm stat_itm, Bry_parser parser, byte[] src, int hook_bgn);
int Decode(Bry_bfr bfr, Bry_parser parser, byte[] src, int hook_bgn);
int Decode(Bry_bfr bfr, Xoh_decode_ctx ctx, Bry_rdr parser, byte[] src, int hook_bgn);
}

@ -39,14 +39,14 @@ public class Hzip_stat_itm {
public int Hdr_6() {return hdr_6;} private int hdr_6;
public int Space() {return space;} public void Space_add(int v) {space += v;} private int space;
public int Escape() {return escape;} public void Escape_add_one() {++escape;} private int escape;
public void Hdr_add(byte hdr_num) {
public void Hdr_add(int hdr_num) {
switch (hdr_num) {
case 1: ++hdr_1; break;
case 2: ++hdr_2; break;
case 3: ++hdr_3; break;
case 4: ++hdr_4; break;
case 5: ++hdr_5; break;
case 6: ++hdr_6; break;
case 1: ++hdr_1; break;
case 2: ++hdr_2; break;
case 3: ++hdr_3; break;
case 4: ++hdr_4; break;
case 5: ++hdr_5; break;
case 6: ++hdr_6; break;
default: throw Err_.new_unhandled(hdr_num);
}
}

@ -22,26 +22,40 @@ public class Xoh_hzip_fxt {
private final Xoh_hzip_mgr hzip_mgr;
private final Hzip_stat_itm stat_itm = new Hzip_stat_itm();
public Xoh_hzip_fxt() {
Xoa_app_fxt.repo2_(parser_fxt.App(), parser_fxt.Wiki()); // needed else will be old "mem/wiki/repo/trg/thumb/" instead of standard "mem/file/en.wikipedia.org/thumb/"
parser_fxt.Wiki().Html__hdump_mgr().Init_by_db(parser_fxt.Wiki());
this.hzip_mgr = parser_fxt.Wiki().Html__hdump_mgr().Hzip_mgr().Hzip_mgr();
}
public Xop_fxt Parser_fxt() {return parser_fxt;} private final Xop_fxt parser_fxt = new Xop_fxt();
public Xoh_hzip_mgr Hzip_mgr() {return hzip_mgr;}
public void Test__bicode(String hzip, String html) {
hzip = String_.Replace(Xoh_hzip_fxt.Escape(hzip), "'", "\""); html = String_.Replace(html, "'", "\"");
Test__encode__raw(hzip, html);
Test__decode__raw(hzip, html);
}
public void Test__encode(String hzip, String html) {
Gfo_usr_dlg_.Instance = Gfo_usr_dlg_.Test_console();
hzip = String_.Replace(Xoh_hzip_fxt.Escape(hzip), "'", "\""); html = String_.Replace(html, "'", "\"");
Test__encode__raw(hzip, html);
}
public void Test__decode(String hzip, String html) {
hzip = String_.Replace(Xoh_hzip_fxt.Escape(hzip), "'", "\""); html = String_.Replace(html, "'", "\"");
Test__decode__raw(hzip, html);
}
public void Test__encode__fail(String expd, String html) {
hzip_mgr.Encode(bfr, parser_fxt.Wiki(), Bry_.Empty, Bry_.new_u8(html), stat_itm);
Gfo_usr_dlg_.Instance = Gfo_usr_dlg_.Noop;
Tfds.Eq_str_lines(expd, bfr.To_str_and_clear());
}
private void Test__encode__raw(String hzip, String html) {
Gfo_usr_dlg_.Test__show__init();
hzip_mgr.Encode(bfr, parser_fxt.Wiki(), Bry_.Empty, Bry_.new_u8(html), stat_itm);
Gfo_usr_dlg_.Test__show__term();
Tfds.Eq_str_lines(hzip, bfr.To_str_and_clear());
}
public void Test__decode(String hzip, String html) {
Gfo_usr_dlg_.Instance = Gfo_usr_dlg_.Test_console();
private void Test__decode__raw(String hzip, String html) {
Gfo_usr_dlg_.Test__show__init();
byte[] actl = hzip_mgr.Decode(bfr, parser_fxt.Wiki(), Bry_.Empty, Bry_.new_u8(hzip));
Gfo_usr_dlg_.Instance = Gfo_usr_dlg_.Noop;
Gfo_usr_dlg_.Test__show__term();
Tfds.Eq_str_lines(html, String_.new_u8(actl));
}
public void Test__bicode(String hzip, String html) {
hzip = Xoh_hzip_fxt.Escape(hzip);
Test__encode(hzip, html);
Test__decode(hzip, html);
}
public static String Escape(String v) {return String_.Replace(v, "~", "");}
}

@ -19,14 +19,14 @@ package gplx.xowa.htmls.core.makes; import gplx.*; import gplx.xowa.*; import gp
import gplx.core.primitives.*; import gplx.core.brys.*; import gplx.core.btries.*; import gplx.langs.htmls.encoders.*;
import gplx.langs.htmls.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.makes.imgs.*; import gplx.xowa.htmls.core.wkrs.lnkis.htmls.*;
import gplx.xowa.files.*; import gplx.xowa.files.repos.*; import gplx.xowa.xtns.gallery.*;
import gplx.xowa.wikis.domains.*; import gplx.xowa.apps.fsys.*;
import gplx.xowa.htmls.core.wkrs.hdrs.*;
import gplx.xowa.wikis.domains.*; import gplx.xowa.wikis.ttls.*; import gplx.xowa.apps.fsys.*;
import gplx.xowa.htmls.core.wkrs.*;
public class Xoh_make_mgr {
private final Bry_bfr bfr = Bry_bfr.reset_(255), tmp_bfr = Bry_bfr.reset_(255); private final Bry_rdr bry_rdr = new Bry_rdr(); private Gfo_usr_dlg usr_dlg = Gfo_usr_dlg_.Instance;
private final Bry_bfr bfr = Bry_bfr.reset_(255), tmp_bfr = Bry_bfr.reset_(255); private final Bry_rdr_old bry_rdr = new Bry_rdr_old(); private Gfo_usr_dlg usr_dlg = Gfo_usr_dlg_.Instance;
private Xoh_cfg_file cfg_file; private final Xof_url_bldr url_bldr = Xof_url_bldr.new_v2(); private Xoh_file_html_fmtr__base html_fmtr;
private final byte[] root_dir, file_dir; private byte[] file_dir_comm, file_dir_wiki, hiero_img_dir; private final byte[] wiki_domain;
private final Xoh_hdr_make wkr__hdr = new Xoh_hdr_make();
private final Bry_parser parser = new Bry_parser();
private final Bry_rdr parser = new Bry_rdr();
private final Xoh_hdoc_wkr__base hdoc_parser = new Xoh_hdoc_wkr__base(new Xoh_hdoc_wkr__make());
public Xoh_make_mgr(Gfo_usr_dlg usr_dlg, Xoa_fsys_mgr fsys_mgr, Url_encoder fsys_encoder, byte[] wiki_domain) {
this.usr_dlg = usr_dlg;
this.root_dir = fsys_mgr.Root_dir().To_http_file_bry();
@ -36,7 +36,13 @@ public class Xoh_make_mgr {
this.html_fmtr = Xoh_file_html_fmtr__hdump.Base;
this.wiki_domain = wiki_domain;
}
public byte[] Parse(Xoh_page hpg, byte[] src) {
public byte[] Parse(byte[] src, Xoh_page hpg, Xow_wiki wiki) {
hpg.Section_mgr().Add(0, 2, Bry_.Empty, Bry_.Empty).Content_bgn_(0); // +1 to skip \n
hdoc_parser.Parse(bfr, wiki, hpg, hpg.Url_bry_safe(), src);
hpg.Section_mgr().Set_content(hpg.Section_mgr().Len() - 1, src, src.length);
return bfr.To_bry_and_clear();
}
public byte[] Parse_old(Xoh_page hpg, byte[] src) {
this.file_dir_comm = tmp_bfr.Add(file_dir).Add(Xow_domain_itm_.Bry__commons).Add_byte_slash().To_bry_and_clear();
this.file_dir_wiki = tmp_bfr.Add(file_dir).Add(wiki_domain).Add_byte_slash().To_bry_and_clear();
int src_len = src.length;
@ -44,7 +50,7 @@ public class Xoh_make_mgr {
hpg.Section_mgr().Add(0, 2, Bry_.Empty, Bry_.Empty).Content_bgn_(0); // +1 to skip \n
Xohd_img_itm__base[] imgs = hpg.Img_itms(); int imgs_len = hpg.Img_itms().length;
int pos = 0; int rng_bgn = -1;
parser.Init_src(hpg.Url_bry_safe(), src, src_len, 0);
parser.Ctor_by_page(hpg.Url_bry_safe(), src, src_len);
while (pos < src_len) {
byte b = src[pos];
Object o = trie.Match_bgn_w_byte(b, src, pos, src_len);
@ -73,7 +79,6 @@ public class Xoh_make_mgr {
switch (tid) {
case Xoh_make_trie_.Tid__dir: bfr.Add(root_dir); return rv;
case Xoh_make_trie_.Tid__hiero_dir: bfr.Add(hiero_img_dir); return rv;
case Xoh_make_trie_.Tid__hdr: return wkr__hdr.Make(bfr, hpg, parser, src, hook_bgn);
}
if (itm.Elem_is_xnde()) rv += 2; // if xnde, skip "/>"
if (uid == bry_rdr.Or_int()) {usr_dlg.Warn_many("", "", "index is not a valid int; hpg=~{0} text=~{1}", hpg.Url().To_str(), Bry_.Mid_safe(src, hook_end, uid_end)); return uid_end;}

@ -15,76 +15,77 @@ 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.htmls.core.makes; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*;
import org.junit.*;
public class Xoh_make_mgr__file__tst {
private final Xoh_make_mgr_fxt fxt = new Xoh_make_mgr_fxt();
@Before public void init() {
fxt.Clear();
fxt.Init_data_img_basic("A.png", 0, 220, 110);
}
@Test public void Img() {
fxt .Init_body("<img xowa_img='0' />")
.Test_html("<img src='file:///mem/xowa/file/commons.wikimedia.org/thumb/7/0/A.png/220px.png' width='220' height='110' />");
}
@Test public void Img_style() {
fxt .Init_body("<div xowa_img_style='0'>")
.Test_html("<div style='width:220px;'>");
}
@Test public void File_info() {
fxt .Init_body("<xowa_info id='0'/>")
.Test_html(String_.Concat_lines_nl_skip_last
( ""
, " <div>"
, " <a href=\"/wiki/File:A.png\" class=\"image\" title=\"About this file\">"
, " <img src=\"file:///mem/xowa/bin/any/xowa/file/mediawiki.file/info.png\" width=\"22\" height=\"22\" />"
, " </a>"
, " </div>"
));
}
@Test public void File_mgnf() {
fxt .Init_body("<xowa_mgnf id='0'/>")
.Test_html(String_.Concat_lines_nl_skip_last
( ""
, " <div class=\"magnify\">"
, " <a href=\"/wiki/File:A.png\" class=\"internal\" title=\"A.png\">"
, " <img src=\"file:///mem/xowa/bin/any/xowa/file/mediawiki.file/magnify-clip.png\" width=\"15\" height=\"11\" alt=\"\" />"
, " </a>"
, " </div>"
));
}
@Test public void File_play() {
fxt .Init_body("<xowa_play id='0'/>")
.Test_html(String_.Concat_lines_nl_skip_last
( ""
, " <div>"
, " <a id=\"xowa_file_play_0\" href=\"/wiki/File:A.png\" xowa_title=\"A.png\" class=\"xowa_anchor_button\" style=\"width:220px;max-width:1024px;\">"
, " <img src=\"file:///mem/xowa/bin/any/xowa/file/mediawiki.file/play.png\" width=\"22\" height=\"22\" alt=\"Play sound\" />"
, " </a>"
, " </div>"
));
}
@Test public void Hiero_dir() {
fxt .Init_body("<img src='~{xowa_hiero_dir}hiero_a&A1.png' />")
.Test_html("<img src='file:///mem/xowa/bin/any/xowa/xtns/Wikihiero/img/hiero_a&A1.png' />");
}
@Test public void Gallery() {
fxt.Clear_imgs();
fxt .Init_data_gly(0, 800);
fxt .Init_data_img_gly("A.png", 0, 220, 110, 155, 150, 15);
fxt .Init_body(String_.Concat_lines_nl_skip_last
( "<ul xowa_gly_box_max='0'>"
, " <li class='gallerybox' xowa_gly_box_w='0'>"
, " <div xowa_gly_box_w='0'>"
, " <div class='thumb' xowa_gly_img_w='0'>"
, " <div xowa_gly_img_pad='0'>"
))
.Test_html(String_.Concat_lines_nl_skip_last
( "<ul style=\"max-width:800px;_width:800px;\">"
, " <li class='gallerybox' style=\"width:155px;\">"
, " <div style=\"width:155px;\">"
, " <div class='thumb' style=\"width:150px;\">"
, " <div style=\"margin:15px auto;\">"
));
}
}
//namespace gplx.xowa.htmls.core.makes {
// import org.junit.*;
// public class Xoh_make_mgr__file__tst {
// private final Xoh_make_mgr_fxt fxt = new Xoh_make_mgr_fxt();
// @Before public void init() {
// fxt.Clear();
// fxt.Init_data_img_basic("A.png", 0, 220, 110);
// }
// @Test public void Img() {
// fxt .Init_body("<img xowa_img='0' />")
// .Test_html("<img src='file:///mem/xowa/file/commons.wikimedia.org/thumb/7/0/A.png/220px.png' width='220' height='110' />");
// }
// @Test public void Img_style() {
// fxt .Init_body("<div xowa_img_style='0'>")
// .Test_html("<div style='width:220px;'>");
// }
// @Test public void File_info() {
// fxt .Init_body("<xowa_info id='0'/>")
// .Test_html(String_.Concat_lines_nl_skip_last
// ( ""
// , " <div>"
// , " <a href=\"/wiki/File:A.png\" class=\"image\" title=\"About this file\">"
// , " <img src=\"file:///mem/xowa/bin/any/xowa/file/mediawiki.file/info.png\" width=\"22\" height=\"22\" />"
// , " </a>"
// , " </div>"
// ));
// }
// @Test public void File_mgnf() {
// fxt .Init_body("<xowa_mgnf id='0'/>")
// .Test_html(String_.Concat_lines_nl_skip_last
// ( ""
// , " <div class=\"magnify\">"
// , " <a href=\"/wiki/File:A.png\" class=\"internal\" title=\"A.png\">"
// , " <img src=\"file:///mem/xowa/bin/any/xowa/file/mediawiki.file/magnify-clip.png\" width=\"15\" height=\"11\" alt=\"\" />"
// , " </a>"
// , " </div>"
// ));
// }
// @Test public void File_play() {
// fxt .Init_body("<xowa_play id='0'/>")
// .Test_html(String_.Concat_lines_nl_skip_last
// ( ""
// , " <div>"
// , " <a id=\"xowa_file_play_0\" href=\"/wiki/File:A.png\" xowa_title=\"A.png\" class=\"xowa_anchor_button\" style=\"width:220px;max-width:1024px;\">"
// , " <img src=\"file:///mem/xowa/bin/any/xowa/file/mediawiki.file/play.png\" width=\"22\" height=\"22\" alt=\"Play sound\" />"
// , " </a>"
// , " </div>"
// ));
// }
// @Test public void Hiero_dir() {
// fxt .Init_body("<img src='~{xowa_hiero_dir}hiero_a&A1.png' />")
// .Test_html("<img src='file:///mem/xowa/bin/any/xowa/xtns/Wikihiero/img/hiero_a&A1.png' />");
// }
// @Test public void Gallery() {
// fxt.Clear_imgs();
// fxt .Init_data_gly(0, 800);
// fxt .Init_data_img_gly("A.png", 0, 220, 110, 155, 150, 15);
// fxt .Init_body(String_.Concat_lines_nl_skip_last
// ( "<ul xowa_gly_box_max='0'>"
// , " <li class='gallerybox' xowa_gly_box_w='0'>"
// , " <div xowa_gly_box_w='0'>"
// , " <div class='thumb' xowa_gly_img_w='0'>"
// , " <div xowa_gly_img_pad='0'>"
// ))
// .Test_html(String_.Concat_lines_nl_skip_last
// ( "<ul style=\"max-width:800px;_width:800px;\">"
// , " <li class='gallerybox' style=\"width:155px;\">"
// , " <div style=\"width:155px;\">"
// , " <div class='thumb' style=\"width:150px;\">"
// , " <div style=\"margin:15px auto;\">"
// ));
// }
// }
//}

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

Loading…
Cancel
Save