mirror of
https://github.com/gnosygnu/xowa.git
synced 2026-03-02 03:49:30 +00:00
v2.5.4.1
This commit is contained in:
@@ -17,10 +17,11 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa; import gplx.*;
|
||||
import gplx.core.flds.*;
|
||||
public class Xof_meta_fil {
|
||||
public class Xof_meta_fil {
|
||||
private final Ordered_hash itms = Ordered_hash_.new_bry_();
|
||||
public Xof_meta_fil(Xof_meta_mgr meta_mgr, byte[] md5) {this.meta_mgr = meta_mgr; this.md5 = md5;}
|
||||
public Xof_meta_mgr Owner_mgr() {return meta_mgr;} Xof_meta_mgr meta_mgr;
|
||||
public byte[] Md5() {return md5;} private byte[] md5;
|
||||
public Xof_meta_mgr Owner_mgr() {return meta_mgr;} private final Xof_meta_mgr meta_mgr;
|
||||
public byte[] Md5() {return md5;} private final byte[] md5;
|
||||
public void Dirty_() {meta_mgr.Dirty_(this);}
|
||||
public Xof_meta_itm Get_or_new(byte[] ttl) {
|
||||
Xof_meta_itm rv = Get_or_null(ttl);
|
||||
@@ -29,12 +30,12 @@ public class Xof_meta_fil {
|
||||
itms.Add(ttl, rv);
|
||||
}
|
||||
return rv;
|
||||
} private OrderedHash itms = OrderedHash_.new_bry_();
|
||||
public Xof_meta_itm Get_or_null(byte[] ttl) {return (Xof_meta_itm)itms.Fetch(ttl);}
|
||||
}
|
||||
public Xof_meta_itm Get_or_null(byte[] ttl) {return (Xof_meta_itm)itms.Get_by(ttl);}
|
||||
public void Save(Gfo_fld_wtr wtr) {
|
||||
int itms_len = itms.Count();
|
||||
for (int i = 0; i < itms_len; i++) {
|
||||
Xof_meta_itm itm = (Xof_meta_itm)itms.FetchAt(i);
|
||||
Xof_meta_itm itm = (Xof_meta_itm)itms.Get_at(i);
|
||||
itm.Save(wtr);
|
||||
}
|
||||
}
|
||||
@@ -56,5 +57,5 @@ public class Xof_meta_fil {
|
||||
Bld_url_bfr.Add_byte(md5[i]);
|
||||
Bld_url_bfr.Add(Bry_url_ext);
|
||||
return Io_url_.new_fil_(Bld_url_bfr.Xto_str_and_clear());
|
||||
} static final byte[] Bry_url_ext = Bry_.new_ascii_(".csv"); static Bry_bfr Bld_url_bfr = Bry_bfr.new_(260); // 260 is max path of url
|
||||
} static final byte[] Bry_url_ext = Bry_.new_a7(".csv"); static Bry_bfr Bld_url_bfr = Bry_bfr.new_(260); // 260 is max path of url
|
||||
}
|
||||
|
||||
@@ -23,7 +23,7 @@ public class Xof_meta_fil_tst {
|
||||
@Test public void Bld_url() {fxt.Bld_url("mem/root/", "abcdef", 3, "mem/root/a/b/abc.csv");}
|
||||
}
|
||||
class Xof_meta_fil_fxt {
|
||||
byte[] md5_(byte[] name) {return Xof_xfer_itm_.Md5_(name);}
|
||||
byte[] md5_(byte[] name) {return Xof_file_wkr_.Md5_(name);}
|
||||
public void Ini() {}
|
||||
public void Bld_url(String root, String md5, int depth, String expd) {Tfds.Eq(expd, Xof_meta_fil.Bld_url(Io_url_.new_dir_(root), Bry_.new_ascii_(md5), depth).Raw());}
|
||||
public void Bld_url(String root, String md5, int depth, String expd) {Tfds.Eq(expd, Xof_meta_fil.Bld_url(Io_url_.new_dir_(root), Bry_.new_a7(md5), depth).Raw());}
|
||||
}
|
||||
|
||||
@@ -18,7 +18,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
package gplx.xowa; import gplx.*;
|
||||
import gplx.core.flds.*;
|
||||
public class Xof_meta_mgr implements GfoInvkAble {
|
||||
Object[] root = new Object[16]; OrderedHash dirty_fils = OrderedHash_.new_bry_();
|
||||
private Object[] root = new Object[16]; private final Ordered_hash dirty_fils = Ordered_hash_.new_bry_();
|
||||
private final Gfo_fld_rdr rdr = Gfo_fld_rdr.xowa_(); private final Xof_meta_thumb_parser parser = new Xof_meta_thumb_parser();
|
||||
public Xof_meta_mgr(Xowe_wiki wiki) {this.wiki = wiki; this.root_dir = wiki.Appe().Fsys_mgr().File_dir().GenSubDir_nest("#meta", wiki.Domain_str());}
|
||||
public Xowe_wiki Wiki() {return wiki;} private Xowe_wiki wiki;
|
||||
public Io_url Root_dir() {return root_dir;} Io_url root_dir;
|
||||
@@ -36,7 +37,7 @@ public class Xof_meta_mgr implements GfoInvkAble {
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
public Xof_meta_itm Get_itm_or_new(byte[] ttl) {return Get_itm_or_new(ttl, gplx.xowa.files.Xof_xfer_itm_.Md5_(ttl));}
|
||||
public Xof_meta_itm Get_itm_or_new(byte[] ttl) {return Get_itm_or_new(ttl, gplx.xowa.files.Xof_file_wkr_.Md5_(ttl));}
|
||||
public Xof_meta_itm Get_itm_or_new(byte[] ttl, byte[] md5) {
|
||||
Xof_meta_fil fil = this.Get_fil_or_new(md5);
|
||||
return fil.Get_or_new(ttl);
|
||||
@@ -53,25 +54,25 @@ public class Xof_meta_mgr implements GfoInvkAble {
|
||||
Bry_bfr tmp_bfr = Bry_bfr.new_();
|
||||
wtr.Bfr_(tmp_bfr);
|
||||
for (int i = 0; i < dirty_len; i++) {
|
||||
Xof_meta_fil fil = (Xof_meta_fil)dirty_fils.FetchAt(i);
|
||||
Xof_meta_fil fil = (Xof_meta_fil)dirty_fils.Get_at(i);
|
||||
Io_url fil_url = Xof_meta_fil.Bld_url(root_dir, fil.Md5(), depth);
|
||||
fil.Save(wtr);
|
||||
if (append_only)
|
||||
Io_mgr._.AppendFilBfr(fil_url, tmp_bfr);
|
||||
Io_mgr.I.AppendFilBfr(fil_url, tmp_bfr);
|
||||
else
|
||||
Io_mgr._.SaveFilBfr(fil_url, tmp_bfr);
|
||||
Io_mgr.I.SaveFilBfr(fil_url, tmp_bfr);
|
||||
}
|
||||
dirty_fils.Clear();
|
||||
if (clear) this.Clear();
|
||||
} Gfo_fld_wtr wtr = Gfo_fld_wtr.xowa_();
|
||||
Xof_meta_fil Load(byte[] md5) {
|
||||
Io_url fil_url = Xof_meta_fil.Bld_url(root_dir, md5, depth);
|
||||
byte[] bry = Io_mgr._.LoadFilBry(fil_url); if (bry == Bry_.Empty) return null;
|
||||
byte[] bry = Io_mgr.I.LoadFilBry(fil_url); if (bry == Bry_.Empty) return null;
|
||||
rdr.Ini(bry, 0);
|
||||
Xof_meta_fil rv = Bld_new(root, depth - 1, this, md5, 0); // NOTE: need to register file before loading it; defect wherein 2 files with same hash prefix would skip one b/c Loaded file was not registered; EX.WS: en.wikiquote.org/The Hitchhiker's Guide to the Galaxy; NMMP_dolphin_with_locator.jpeg, da6f95736ed249f371f30bf5f1205fbd; Hoags_object.jpg, daed4a54e48e4266bd2f2763b7c4018c
|
||||
rv.Load(rdr, parser);
|
||||
return rv;
|
||||
} Gfo_fld_rdr rdr = Gfo_fld_rdr.xowa_(); Xof_meta_thumb_parser parser = new Xof_meta_thumb_parser();
|
||||
}
|
||||
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
|
||||
if (ctx.Match(k, Invk_regy_depth_)) depth = m.ReadInt("v");
|
||||
else return GfoInvkAble_.Rv_unhandled;
|
||||
@@ -80,7 +81,7 @@ public class Xof_meta_mgr implements GfoInvkAble {
|
||||
static final String GRP_KEY = "xowa.file_regy.";
|
||||
private static Xof_meta_fil Get_fil_or_null_recur(Object[] ary, int depth_max, byte[] md5, int md5_idx) {
|
||||
int ary_idx = Int_.Xto_int_hex(md5[md5_idx]);
|
||||
if (ary_idx < 0 || ary_idx > 15) throw Err_mgr._.fmt_auto_(GRP_KEY, "md5_not_valid", String_.new_utf8_(md5), md5_idx);
|
||||
if (ary_idx < 0 || ary_idx > 15) throw Err_mgr._.fmt_auto_(GRP_KEY, "md5_not_valid", String_.new_u8(md5), md5_idx);
|
||||
Object o = ary[ary_idx];
|
||||
if (o == null) return null;
|
||||
if (md5_idx == depth_max) { // leaf; return fil
|
||||
@@ -91,7 +92,7 @@ public class Xof_meta_mgr implements GfoInvkAble {
|
||||
}
|
||||
private static Xof_meta_fil Bld_new(Object[] ary, int depth_max, Xof_meta_mgr regy_mgr, byte[] md5, int md5_idx) {
|
||||
int ary_idx = Int_.Xto_int_hex(md5[md5_idx]);
|
||||
if (ary_idx < 0 || ary_idx > 15) throw Err_mgr._.fmt_auto_(GRP_KEY, "md5_not_valid", String_.new_utf8_(md5), md5_idx);
|
||||
if (ary_idx < 0 || ary_idx > 15) throw Err_mgr._.fmt_auto_(GRP_KEY, "md5_not_valid", String_.new_u8(md5), md5_idx);
|
||||
Object o = ary[ary_idx];
|
||||
if (md5_idx == depth_max) { // leaf; create itm
|
||||
Xof_meta_fil rv = null;
|
||||
|
||||
@@ -59,25 +59,25 @@ public class Xof_meta_mgr_tst {
|
||||
}
|
||||
class Xof_file_regy_fxt {
|
||||
Xof_meta_mgr regy_mgr;
|
||||
byte[] md5_(byte[] name) {return Xof_xfer_itm_.Md5_(name);}
|
||||
byte[] md5_(byte[] name) {return Xof_file_wkr_.Md5_(name);}
|
||||
public void Ini() {
|
||||
Io_mgr._.InitEngine_mem();
|
||||
Io_mgr.I.InitEngine_mem();
|
||||
Xoae_app app = Xoa_app_fxt.app_();
|
||||
Xowe_wiki wiki = Xoa_app_fxt.wiki_tst_(app);
|
||||
regy_mgr = new Xof_meta_mgr(wiki);
|
||||
regy_mgr.Clear();
|
||||
regy_mgr.Depth_(2);
|
||||
}
|
||||
public Xof_file_regy_fxt Save_fil(String url, String... data) {Io_mgr._.SaveFilStr(Io_url_.mem_fil_(url), String_.Concat_lines_nl(data)); return this;}
|
||||
public Xof_file_regy_fxt Save_fil(String url, String... data) {Io_mgr.I.SaveFilStr(Io_url_.mem_fil_(url), String_.Concat_lines_nl(data)); return this;}
|
||||
public Xof_file_regy_fxt Set(String name_str, int w, int h, boolean orig_exists, String... thumbs) {
|
||||
byte[] name = Bry_.new_utf8_(name_str);
|
||||
byte[] name = Bry_.new_u8(name_str);
|
||||
byte[] md5 = md5_(name);
|
||||
Xof_meta_itm itm = regy_mgr.Get_itm_or_new(name, md5);
|
||||
itm.Vrtl_repo_(Xof_meta_itm.Repo_same); // all tests above assume this is main
|
||||
itm.Update_all(Bry_.Empty, w, h, orig_exists ? Xof_meta_itm.Exists_y : Xof_meta_itm.Exists_unknown, Xto_ary(thumbs));
|
||||
itm.Update_all(Bry_.Empty, w, h, orig_exists ? Xof_meta_itm.Exists_y : Xof_meta_itm.Exists_unknown, To_ary(thumbs));
|
||||
return this;
|
||||
}
|
||||
Xof_meta_thumb[] Xto_ary(String[] ary) {
|
||||
Xof_meta_thumb[] To_ary(String[] ary) {
|
||||
int len = ary.length;
|
||||
Xof_meta_thumb[] rv = new Xof_meta_thumb[len];
|
||||
for (int i = 0; i < len; i++) {
|
||||
@@ -88,7 +88,7 @@ class Xof_file_regy_fxt {
|
||||
}
|
||||
public Xof_file_regy_fxt tst_Save(String url_str, String... expd_ary) {
|
||||
regy_mgr.Save();
|
||||
Tfds.Eq_ary_str(expd_ary, Io_mgr._.LoadFilStr_args(Io_url_.new_fil_(url_str)).ExecAsStrAryLnx());
|
||||
Tfds.Eq_ary_str(expd_ary, Io_mgr.I.LoadFilStr_args(Io_url_.new_fil_(url_str)).ExecAsStrAryLnx());
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,16 +33,16 @@ public class Xof_meta_thumb_parser extends Obj_ary_parser_base {
|
||||
}
|
||||
@Override protected void Parse_itm(byte[] bry, int bgn, int end) { // EX: "1:45,40"; "1:45,40:3,4"
|
||||
Xof_meta_thumb itm = new Xof_meta_thumb(); boolean height_found = false;
|
||||
if (end - 2 < bgn) throw Err_mgr._.fmt_(GRP_KEY, "invalid_itm", "itm must be at least 2 bytes long: itm=~{0}", String_.new_utf8_(bry, bgn, end)); // EX: 4,6
|
||||
if (end - 2 < bgn) throw Err_mgr._.fmt_(GRP_KEY, "invalid_itm", "itm must be at least 2 bytes long: itm=~{0}", String_.new_u8(bry, bgn, end)); // EX: 4,6
|
||||
int pos = bgn;
|
||||
byte exists_byte = bry[pos];
|
||||
switch (exists_byte) {
|
||||
case Byte_ascii.Num_0: itm.Exists_(Xof_meta_itm.Exists_n); break;
|
||||
case Byte_ascii.Num_1: itm.Exists_(Xof_meta_itm.Exists_y); break;
|
||||
case Byte_ascii.Num_2: itm.Exists_(Xof_meta_itm.Exists_unknown); break;
|
||||
default: throw Err_mgr._.fmt_(GRP_KEY, "invalid_exists_val", "exists must be 0,1,2: exists=~{0} itm=~{1}", exists_byte, String_.new_utf8_(bry, bgn, end));
|
||||
default: throw Err_mgr._.fmt_(GRP_KEY, "invalid_exists_val", "exists must be 0,1,2: exists=~{0} itm=~{1}", exists_byte, String_.new_u8(bry, bgn, end));
|
||||
}
|
||||
if (bry[pos + 1] != Dlm_exists) throw Err_mgr._.fmt_(GRP_KEY, "invalid_exists_spr", "question must follow exists: bad_char=~{0} itm=~{1}", bry[pos + 1], String_.new_utf8_(bry, bgn, end));
|
||||
if (bry[pos + 1] != Dlm_exists) throw Err_mgr._.fmt_(GRP_KEY, "invalid_exists_spr", "question must follow exists: bad_char=~{0} itm=~{1}", bry[pos + 1], String_.new_u8(bry, bgn, end));
|
||||
pos += 2;
|
||||
int num_bgn = pos;
|
||||
while (pos < end) {
|
||||
|
||||
@@ -24,7 +24,7 @@ public class Xof_meta_thumb_parser_tst {
|
||||
@Test public void Many() {Tst_parse("1?45,40;0?90,80", itm_y_(45, 40), itm_n_(90, 80));}
|
||||
@Test public void Seek() {Tst_parse("1?45,40@2,3,4", itm_y_(45, 40, 2, 3, 4));}
|
||||
private void Tst_parse(String raw_str, Xof_meta_thumb... expd) {
|
||||
byte[] raw = Bry_.new_ascii_(raw_str);
|
||||
byte[] raw = Bry_.new_a7(raw_str);
|
||||
parser.Parse_ary(raw, 0, raw.length);
|
||||
Tfds.Eq_str_lines(Xto_str(expd, 0, expd.length), Xto_str(parser.Ary(), 0, parser.Len()));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user