mirror of https://github.com/gnosygnu/xowa
parent
7a851a41a5
commit
8e91ac0bc4
@ -1,66 +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.caches; import gplx.*; import gplx.core.*;
|
||||
import org.junit.*; import gplx.core.envs.*;
|
||||
public class GfoCacheMgr_tst {
|
||||
@Before public void init() {fxt = new GfoCacheMgr_fxt();} GfoCacheMgr_fxt fxt;
|
||||
@Test public void teardown() {Env_.TickCount_Test = -1;}
|
||||
@Test public void Basic() {fxt.run_Add("a").Expd_curSize_(1).Expd_itms_("a").tst();}
|
||||
// @Test public void Reduce() {fxt.run_Add("a", "b", "c", "d", "e").Expd_curSize_(3).Expd_itms_("c", "d", "e").tst();}
|
||||
// @Test public void Access() {fxt.run_Add("a", "b", "c", "d").run_Get("b", "a").run_Add("e").Expd_curSize_(3).Expd_itms_("b", "a", "e").tst();}
|
||||
// @Test public void Sizes() {fxt.run_Add("abc", "d", "e").Expd_curSize_(2).Expd_itms_("d", "e").tst();}
|
||||
}
|
||||
class GfoCacheMgr_fxt {
|
||||
Gfo_cache_mgr mgr = new Gfo_cache_mgr().Max_size_(4).Reduce_by_(2);
|
||||
public GfoCacheMgr_fxt() {
|
||||
Env_.TickCount_Test = 1;
|
||||
}
|
||||
public GfoCacheMgr_fxt run_Add(String... ary) {
|
||||
for (int i = 0; i < ary.length; i++) {
|
||||
String s = ary[i];
|
||||
mgr.Add(Bry_.new_u8(s), new GfoCacheItm_mock(s), String_.Len(s));
|
||||
Env_.TickCount_Test++;
|
||||
}
|
||||
return this;
|
||||
}
|
||||
public GfoCacheMgr_fxt run_Get(String... ary) {
|
||||
for (int i = 0; i < ary.length; i++) {
|
||||
String s = ary[i];
|
||||
mgr.Get_by_key(Bry_.new_u8(s));
|
||||
Env_.TickCount_Test++;
|
||||
}
|
||||
return this;
|
||||
}
|
||||
public GfoCacheMgr_fxt Expd_curSize_(int v) {expd_curSize = v; return this;} private int expd_curSize = -1;
|
||||
public GfoCacheMgr_fxt Expd_itms_(String... v) {expd_itms = v; return this;} private String[] expd_itms;
|
||||
public GfoCacheMgr_fxt tst() {
|
||||
if (expd_curSize != -1) Tfds.Eq(expd_curSize, mgr.Cur_size(), "curSize");
|
||||
if (expd_itms != null) {
|
||||
String[] actl = new String[mgr.Count()];
|
||||
for (int i = 0; i < actl.length; i++)
|
||||
actl[i] = ((GfoCacheItm_mock)mgr.Get_at(i)).S();
|
||||
Tfds.Eq_ary_str(expd_itms, actl, "itms");
|
||||
}
|
||||
return this;
|
||||
}
|
||||
}
|
||||
class GfoCacheItm_mock implements Rls_able {
|
||||
public void Rls() {}
|
||||
public String S() {return s;} private String s;
|
||||
public GfoCacheItm_mock(String s) {this.s = s;}
|
||||
}
|
@ -0,0 +1,46 @@
|
||||
/*
|
||||
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.caches; import gplx.*; import gplx.core.*;
|
||||
import gplx.core.envs.*;
|
||||
class Gfo_cache_data implements gplx.CompareAble, Rls_able {
|
||||
private int count = 0;
|
||||
public Gfo_cache_data(byte[] key, Rls_able val, int size) {
|
||||
this.key = key; this.val = val;
|
||||
this.size = size;
|
||||
this.count = 1;
|
||||
}
|
||||
public byte[] Key() {return key;} private final byte[] key;
|
||||
public Rls_able Val() {return val;} private Rls_able val;
|
||||
public int Size() {return size;} private int size;
|
||||
|
||||
public Object Val_and_update() {
|
||||
++count;
|
||||
return val;
|
||||
}
|
||||
public void Val_(Rls_able val, int size) {
|
||||
this.val = val;
|
||||
this.size = size;
|
||||
}
|
||||
public int compareTo(Object obj) {
|
||||
Gfo_cache_data comp = (Gfo_cache_data)obj;
|
||||
return -Long_.Compare(count, comp.count); // "-" to sort most-recent first
|
||||
}
|
||||
public void Rls() {
|
||||
val.Rls();
|
||||
}
|
||||
}
|
@ -0,0 +1,73 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.core.caches; import gplx.*; import gplx.core.*;
|
||||
import org.junit.*; import gplx.core.tests.*; import gplx.core.envs.*;
|
||||
public class Gfo_cache_mgr_tst {
|
||||
@Before public void init() {fxt.Clear();} private final Gfo_cache_mgr_fxt fxt = new Gfo_cache_mgr_fxt();
|
||||
@Test public void Basic() {
|
||||
fxt.Exec__add("a");
|
||||
fxt.Test__cur_size(1);
|
||||
fxt.Test__itms("a");
|
||||
}
|
||||
@Test public void Reduce() {
|
||||
fxt.Exec__add("a", "b", "c", "d", "e");
|
||||
fxt.Test__cur_size(2);
|
||||
fxt.Test__itms("a", "b");
|
||||
}
|
||||
@Test public void Reduce_after_get() {
|
||||
fxt.Exec__add("a", "b", "c", "d");
|
||||
fxt.Exec__get("a", "c");
|
||||
fxt.Exec__add("e");
|
||||
fxt.Test__itms("a", "c");
|
||||
}
|
||||
}
|
||||
class Gfo_cache_mgr_fxt {
|
||||
private final Gfo_cache_mgr mgr = new Gfo_cache_mgr().Max_size_(4).Reduce_by_(2);
|
||||
public void Clear() {mgr.Clear();}
|
||||
public Gfo_cache_mgr_fxt Exec__add(String... ary) {
|
||||
int len = ary.length;
|
||||
for (int i = 0; i < len; ++i) {
|
||||
String itm = ary[i];
|
||||
byte[] key = Bry_.new_u8(itm);
|
||||
mgr.Add(key, new Gfo_cache_itm_mock(itm), key.length);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
public Gfo_cache_mgr_fxt Exec__get(String... ary) {
|
||||
int len = ary.length;
|
||||
for (int i = 0; i < len; ++i) {
|
||||
String itm = ary[i];
|
||||
mgr.Get_by_key(Bry_.new_u8(itm));
|
||||
}
|
||||
return this;
|
||||
}
|
||||
public Gfo_cache_mgr_fxt Test__cur_size(int expd) {Gftest.Eq__int(expd, mgr.Cur_size(), "cur_size"); return this;}
|
||||
public Gfo_cache_mgr_fxt Test__itms(String... expd) {
|
||||
int len = mgr.Test__len();
|
||||
String[] actl = new String[len];
|
||||
for (int i = 0; i < len; ++i)
|
||||
actl[i] = ((Gfo_cache_itm_mock)mgr.Test__get_at(i)).Val();
|
||||
Gftest.Eq__ary(expd, actl, "itms");
|
||||
return this;
|
||||
}
|
||||
}
|
||||
class Gfo_cache_itm_mock implements Rls_able {
|
||||
public Gfo_cache_itm_mock(String val) {this.val = val;}
|
||||
public String Val() {return val;} private String val;
|
||||
public void Rls() {}
|
||||
}
|
@ -0,0 +1,26 @@
|
||||
/*
|
||||
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.*;
|
||||
import org.junit.*;
|
||||
public class Gfh_utl__comments__tst {
|
||||
@Before public void init() {fxt.Clear();} private final Gfh_class_fxt fxt = new Gfh_class_fxt();
|
||||
@Test public void Basic() {fxt.Test_del_comments("a<!-- b -->c" , "ac");}
|
||||
@Test public void Bgn_missing() {fxt.Test_del_comments("a b c" , "a b c");}
|
||||
@Test public void End_missing() {fxt.Test_del_comments("a<!-- b c" , "a");}
|
||||
@Test public void Multiple() {fxt.Test_del_comments("a<!--b-->c<!--d-->e" , "ace");}
|
||||
}
|
@ -0,0 +1,37 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.addons.bldrs.exports.packs.files; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.bldrs.*; import gplx.xowa.addons.bldrs.exports.*; import gplx.xowa.addons.bldrs.exports.packs.*;
|
||||
import gplx.xowa.bldrs.*; import gplx.xowa.bldrs.wkrs.*;
|
||||
public class Pack_file_bldr_cfg implements Gfo_invk {
|
||||
public Io_url Deploy_dir() {return deploy_dir;} private Io_url deploy_dir;
|
||||
public boolean Pack_html() {return pack_html;} private boolean pack_html = true;
|
||||
public boolean Pack_file() {return pack_file;} private boolean pack_file = true;
|
||||
public DateAdp Pack_file_cutoff() {return pack_file_cutoff;} private DateAdp pack_file_cutoff = null;
|
||||
|
||||
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
|
||||
if (ctx.Match(k, Invk__deploy_dir_)) deploy_dir = m.ReadIoUrl("v");
|
||||
else if (ctx.Match(k, Invk__pack_html_)) pack_html = m.ReadYn("v");
|
||||
else if (ctx.Match(k, Invk__pack_file_)) pack_file = m.ReadYn("v");
|
||||
else if (ctx.Match(k, Invk__pack_file_cutoff_)) pack_file_cutoff = m.ReadDate("v");
|
||||
else return Gfo_invk_.Rv_unhandled;
|
||||
return this;
|
||||
}
|
||||
private static final String Invk__deploy_dir_ = "deploy_dir_"
|
||||
, Invk__pack_html_ = "pack_html_", Invk__pack_file_ = "pack_file_", Invk__pack_file_cutoff_ = "pack_file_cutoff_"
|
||||
;
|
||||
}
|
@ -0,0 +1,57 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.addons.bldrs.mass_parses.makes; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.bldrs.*; import gplx.xowa.addons.bldrs.mass_parses.*;
|
||||
import gplx.dbs.*;
|
||||
class Xob_lnki_temp_row implements CompareAble {
|
||||
public int Xomp_uid() {return xomp_uid;} private int xomp_uid;
|
||||
public int Make_uid() {return make_uid;} private int make_uid;
|
||||
public int Lnki_tier_id() {return lnki_tier_id;} private int lnki_tier_id;
|
||||
public int Lnki_page_id() {return lnki_page_id;} private int lnki_page_id;
|
||||
public byte[] Lnki_ttl() {return lnki_ttl;} private byte[] lnki_ttl;
|
||||
public byte[] Lnki_commons_ttl() {return lnki_commons_ttl;} private byte[] lnki_commons_ttl;
|
||||
public byte Lnki_ext() {return lnki_ext;} private byte lnki_ext;
|
||||
public byte Lnki_type() {return lnki_type;} private byte lnki_type;
|
||||
public byte Lnki_src_tid() {return lnki_src_tid;} private byte lnki_src_tid;
|
||||
public int Lnki_w() {return lnki_w;} private int lnki_w;
|
||||
public int Lnki_h() {return lnki_h;} private int lnki_h;
|
||||
public double Lnki_upright() {return lnki_upright;} private double lnki_upright;
|
||||
public double Lnki_time() {return lnki_time;} private double lnki_time;
|
||||
public int Lnki_page() {return lnki_page;} private int lnki_page;
|
||||
public void Load(Db_rdr rdr, int xomp_uid) {
|
||||
this.xomp_uid = xomp_uid;
|
||||
this.make_uid = rdr.Read_int("lnki_make_uid");
|
||||
this.lnki_tier_id = rdr.Read_int("lnki_tier_id");
|
||||
this.lnki_page_id = rdr.Read_int("lnki_page_id");
|
||||
this.lnki_ttl = rdr.Read_bry_by_str("lnki_ttl");
|
||||
this.lnki_commons_ttl = rdr.Read_bry_by_str("lnki_commons_ttl");
|
||||
this.lnki_ext = rdr.Read_byte("lnki_ext");
|
||||
this.lnki_type = rdr.Read_byte("lnki_type");
|
||||
this.lnki_src_tid = rdr.Read_byte("lnki_src_tid");
|
||||
this.lnki_w = rdr.Read_int("lnki_w");
|
||||
this.lnki_h = rdr.Read_int("lnki_h");
|
||||
this.lnki_upright = rdr.Read_double("lnki_upright");
|
||||
this.lnki_time = rdr.Read_int("lnki_time");
|
||||
this.lnki_page = rdr.Read_int("lnki_page");
|
||||
}
|
||||
public int compareTo(Object obj) {
|
||||
Xob_lnki_temp_row comp = (Xob_lnki_temp_row)obj;
|
||||
int rv = Int_.Compare(xomp_uid, comp.xomp_uid);
|
||||
if (rv != CompareAble_.Same) return rv;
|
||||
return Int_.Compare(make_uid, comp.make_uid);
|
||||
}
|
||||
}
|
@ -0,0 +1,95 @@
|
||||
/*
|
||||
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.addons.bldrs.mass_parses.makes; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.bldrs.*; import gplx.xowa.addons.bldrs.mass_parses.*;
|
||||
import gplx.core.brys.*;
|
||||
import gplx.dbs.*; import gplx.xowa.htmls.core.dbs.*; import gplx.xowa.addons.bldrs.mass_parses.dbs.*; import gplx.xowa.addons.bldrs.files.dbs.*;
|
||||
import gplx.xowa.bldrs.*;
|
||||
class Xomp_make_lnki {
|
||||
public void Exec(Xowe_wiki wiki, int uid_count) {
|
||||
// init
|
||||
Xomp_db_core xomp_db = Xomp_db_core.New__load(wiki);
|
||||
|
||||
Xob_db_file make_db = Xob_db_file.New__file_make(wiki.Fsys_mgr().Root_dir());
|
||||
Xob_lnki_temp_tbl lnki_temp_tbl = new Xob_lnki_temp_tbl(make_db.Conn());
|
||||
lnki_temp_tbl.Insert_bgn();
|
||||
|
||||
// add index
|
||||
int wkr_count = xomp_db.Wkr_count();
|
||||
for (int i = 0; i < wkr_count; ++i) {
|
||||
Xomp_wkr_db wkr_db = xomp_db.Wkr_db(Bool_.N, i);
|
||||
wkr_db.Conn().Meta_idx_assert("lnki_temp", "lnki_page_id", "lnki_page_id");
|
||||
}
|
||||
|
||||
// loop
|
||||
List_adp rows = List_adp_.New();
|
||||
int uid_bgn = -1;
|
||||
while (true) {
|
||||
int count = 0;
|
||||
for (int i = 0; i < wkr_count; ++i) {
|
||||
Xomp_wkr_db wkr_db = xomp_db.Wkr_db(Bool_.N, i);
|
||||
count += Load_rows(rows, xomp_db, wkr_db, uid_bgn, uid_bgn + uid_count);
|
||||
}
|
||||
if (count == 0) break;
|
||||
Save_rows(rows, lnki_temp_tbl);
|
||||
}
|
||||
|
||||
// term
|
||||
lnki_temp_tbl.Insert_end();
|
||||
xomp_db.Conn().Rls_conn();
|
||||
make_db.Conn().Rls_conn();
|
||||
}
|
||||
private int Load_rows(List_adp rows, Xomp_db_core xomp_db, Xomp_wkr_db wkr_db, int uid_bgn, int uid_end) {
|
||||
// build sql
|
||||
Db_attach_mgr attach_mgr = new Db_attach_mgr(xomp_db.Conn());
|
||||
attach_mgr.Conn_others_(new Db_attach_itm("wkr_db", wkr_db.Conn()));
|
||||
String sql = String_.Format(String_.Concat_lines_nl_skip_last
|
||||
( "SELECT mgr.xomp_uid"
|
||||
, ", wkr.*"
|
||||
, "FROM <wkr_db>lnki_temp wkr"
|
||||
, " JOIN xomp_page mgr ON wkr.lnki_page_id = mgr.page_id"
|
||||
, "WHERE mgr.xomp_uid > {0} AND mgr.xomp_uid <= {1}"
|
||||
)
|
||||
, uid_bgn
|
||||
, uid_end
|
||||
);
|
||||
sql = attach_mgr.Resolve_sql(sql);
|
||||
|
||||
attach_mgr.Attach();
|
||||
Db_rdr rdr = xomp_db.Conn().Stmt_sql(sql).Exec_select__rls_auto(); // ANSI.Y
|
||||
int rv = -1;
|
||||
try {
|
||||
while (rdr.Move_next()) {
|
||||
rv = rdr.Read_int("xomp_uid");
|
||||
Xob_lnki_temp_row row = new Xob_lnki_temp_row();
|
||||
row.Load(rdr, rv);
|
||||
}
|
||||
} finally {rdr.Rls();}
|
||||
attach_mgr.Detach();
|
||||
return rv;
|
||||
}
|
||||
|
||||
private void Save_rows(List_adp rows, Xob_lnki_temp_tbl lnki_temp_tbl) {
|
||||
int len = rows.Len();
|
||||
for (int i = 0; i < len; ++i) {
|
||||
Xob_lnki_temp_row row = (Xob_lnki_temp_row)rows.Get_at(i);
|
||||
lnki_temp_tbl.Insert_cmd_by_batch(row.Lnki_tier_id(), row.Lnki_page_id(), row.Lnki_ttl(), row.Lnki_commons_ttl()
|
||||
, row.Lnki_ext(), row.Lnki_src_tid(), row.Lnki_src_tid(), row.Lnki_w(), row.Lnki_h(), row.Lnki_upright()
|
||||
, row.Lnki_time(), row.Lnki_page());
|
||||
}
|
||||
}
|
||||
}
|
@ -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.xowa.addons.bldrs.mass_parses.parses; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.bldrs.*; import gplx.xowa.addons.bldrs.mass_parses.*;
|
||||
import gplx.dbs.*;
|
||||
import gplx.xowa.parsers.*; import gplx.xowa.parsers.lnkis.*; import gplx.xowa.parsers.lnkis.files.*;
|
||||
import gplx.xowa.files.*; import gplx.xowa.addons.bldrs.files.cmds.*; import gplx.xowa.addons.bldrs.files.dbs.*;
|
||||
import gplx.xowa.wikis.nss.*; import gplx.xowa.wikis.domains.*;
|
||||
public class Xomp_file_logger implements Xop_file_logger {
|
||||
private final Xob_lnki_temp_tbl tbl;
|
||||
private final Xowe_wiki commons_wiki;
|
||||
private boolean ns_file_is_case_match_all = true;
|
||||
public Xomp_file_logger(Xowe_wiki wiki, Db_conn wkr_conn) {
|
||||
this.tbl = new Xob_lnki_temp_tbl(wkr_conn); wkr_conn.Meta_tbl_assert(tbl);
|
||||
this.commons_wiki = wiki.Appe().Wiki_mgr().Get_by_or_make(Xow_domain_itm_.Bry__commons);
|
||||
this.ns_file_is_case_match_all = wiki.Init_assert().Ns_mgr().Ns_file().Case_match() == Xow_ns_case_.Tid__all; // NOTE: wiki must be init'd;
|
||||
}
|
||||
public void Bgn() {
|
||||
tbl.Insert_bgn();
|
||||
}
|
||||
public void Log_file(Xop_ctx ctx, Xop_lnki_tkn lnki, byte caller_tid) {
|
||||
if (lnki.Ttl().ForceLiteralLink()) return; // ignore literal links which create a link to file, but do not show the image; EX: [[:File:A.png|thumb|120px]] creates a link to File:A.png, regardless of other display-oriented args
|
||||
|
||||
// get caller_tid / tttl
|
||||
if (lnki.Ns_id() == Xow_ns_.Tid__media) caller_tid = Xop_file_logger_.Tid__media;
|
||||
|
||||
// get lnki_data
|
||||
byte[] ttl = lnki.Ttl().Page_db();
|
||||
Xof_ext ext = Xof_ext_.new_by_ttl_(ttl);
|
||||
byte[] ttl_commons = Xomp_file_logger.To_commons_ttl(ns_file_is_case_match_all, commons_wiki, ttl);
|
||||
|
||||
// do insert
|
||||
tbl.Insert_cmd_by_batch(ctx.Page().Bldr__ns_ord(), ctx.Page().Db().Page().Id(), ttl, ttl_commons, Byte_.By_int(ext.Id()), lnki.Lnki_type(), caller_tid, lnki.W(), lnki.H(), lnki.Upright(), lnki.Time(), lnki.Page());
|
||||
}
|
||||
public void End() {
|
||||
tbl.Insert_end();
|
||||
}
|
||||
public static byte[] To_commons_ttl(boolean ns_file_is_case_match_all, Xowe_wiki commons_wiki, byte[] ttl_bry) { // handle case-sensitive wikis (en.d) vs case-insensitive commons
|
||||
if (!ns_file_is_case_match_all) return null; // return "" if wiki matches common
|
||||
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;
|
||||
}
|
||||
}
|
@ -0,0 +1,46 @@
|
||||
/*
|
||||
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.addons.bldrs.xodirs; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.bldrs.*;
|
||||
import gplx.xowa.specials.*;
|
||||
import gplx.xowa.addons.wikis.imports.*;
|
||||
public class Xobc_xodir_addon implements Xoax_addon_itm, Xoax_addon_itm__special, Xoax_addon_itm__init {
|
||||
public Xow_special_page[] Special_pages() {
|
||||
return new Xow_special_page[]
|
||||
{ Xobc_xodir_special.Prototype
|
||||
};
|
||||
}
|
||||
public void Init_addon_by_app(Xoa_app app) {
|
||||
}
|
||||
public void Init_addon_by_wiki(Xow_wiki wiki) {
|
||||
Xow_import_addon addon = Xow_import_addon.Addon__get(wiki);
|
||||
addon.Dir_selected_cbks__add(Xow_import_dir_cbk__xodir.Instance);
|
||||
}
|
||||
|
||||
public String Addon__key() {return ADDON__KEY;} private static final String ADDON__KEY = "xowa.bldrs.xodirs";
|
||||
}
|
||||
class Xow_import_dir_cbk__xodir implements Xow_import_dir_cbk {
|
||||
public String Key() {return "xodir";}
|
||||
public void Cbk__dir_selected(Xow_wiki wiki, Xoa_page page, String path) {
|
||||
// save to prefs
|
||||
wiki.App().User().User_db_mgr().Cfg().Set_app_str("xowa.xodir.custom_dir", path);
|
||||
|
||||
// redirect to import_dir
|
||||
page.Redirect().Itms__add__special(wiki, Xobc_xodir_special.Prototype.Special__meta());
|
||||
}
|
||||
public static Xow_import_dir_cbk__xodir Instance = new Xow_import_dir_cbk__xodir(); Xow_import_dir_cbk__xodir() {}
|
||||
}
|
@ -0,0 +1,30 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.addons.bldrs.xodirs; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.bldrs.*;
|
||||
public class Xobc_xodir_cfg {
|
||||
public static final String
|
||||
Key__selected_dir = "xowa.xodir.selected_dir"
|
||||
, Key__custom_dir = "xowa.xodir.custom_dir"
|
||||
;
|
||||
public static void Set_app_str__selected(Xoa_app app, byte[] val_bry) {
|
||||
// if wnt, replace "\"; note that url-encoding while navigating dirs will always convert "\" to "/"
|
||||
if (gplx.core.envs.Op_sys.Cur().Tid_is_wnt()) val_bry = Bry_.Replace(val_bry, Byte_ascii.Slash, Byte_ascii.Backslash);
|
||||
|
||||
app.User().User_db_mgr().Cfg().Set_app_bry(Xobc_xodir_cfg.Key__selected_dir, val_bry);
|
||||
}
|
||||
}
|
@ -0,0 +1,51 @@
|
||||
/*
|
||||
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.addons.bldrs.xodirs; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.bldrs.*;
|
||||
import gplx.langs.mustaches.*;
|
||||
class Xobc_xodir_doc implements Mustache_doc_itm {
|
||||
private final byte[] import_root, app_root_dir;
|
||||
private final Xobc_xodir_dir[] dirs;
|
||||
public Xobc_xodir_doc(Xobc_xodir_dir[] dirs, byte[] import_root, byte[] app_root_dir) {
|
||||
this.dirs = dirs; this.import_root = import_root; this.app_root_dir = app_root_dir;
|
||||
}
|
||||
public boolean Mustache__write(String key, Mustache_bfr bfr) {
|
||||
if (String_.Eq(key, "import_root")) bfr.Add_bry(import_root);
|
||||
else if (String_.Eq(key, "app_root_dir")) bfr.Add_bry(app_root_dir);
|
||||
return false;
|
||||
}
|
||||
public Mustache_doc_itm[] Mustache__subs(String key) {
|
||||
if (String_.Eq(key, "dirs")) return dirs;
|
||||
return Mustache_doc_itm_.Ary__empty;
|
||||
}
|
||||
}
|
||||
public class Xobc_xodir_dir implements Mustache_doc_itm {
|
||||
private final boolean is_selected, is_custom;
|
||||
private final byte[] path;
|
||||
public Xobc_xodir_dir(boolean is_selected, boolean is_custom, byte[] path) {
|
||||
this.is_selected = is_selected; this.is_custom = is_custom; this.path = path;
|
||||
}
|
||||
public boolean Mustache__write(String key, Mustache_bfr bfr) {
|
||||
if (String_.Eq(key, "path")) bfr.Add_bry(path);
|
||||
return false;
|
||||
}
|
||||
public Mustache_doc_itm[] Mustache__subs(String key) {
|
||||
if (String_.Eq(key, "is_selected")) return Mustache_doc_itm_.Ary__bool(is_selected);
|
||||
else if (String_.Eq(key, "is_custom")) return Mustache_doc_itm_.Ary__bool(is_custom);
|
||||
return Mustache_doc_itm_.Ary__empty;
|
||||
}
|
||||
}
|
@ -0,0 +1,40 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.addons.bldrs.xodirs; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.bldrs.*;
|
||||
import gplx.xowa.specials.*; import gplx.langs.mustaches.*; import gplx.xowa.wikis.pages.*; import gplx.xowa.wikis.pages.tags.*;
|
||||
import gplx.xowa.addons.bldrs.centrals.*; import gplx.xowa.addons.bldrs.centrals.dbs.*; import gplx.xowa.addons.bldrs.centrals.dbs.datas.imports.*; import gplx.xowa.addons.bldrs.centrals.hosts.*;
|
||||
import gplx.xowa.wikis.domains.*; import gplx.core.ios.*;
|
||||
class Xobc_xodir_html extends Xow_special_wtr__base {
|
||||
@Override protected Io_url Get_addon_dir(Xoa_app app) {return app.Fsys_mgr().Http_root().GenSubDir_nest("bin", "any", "xowa", "addon", "bldr", "xodir");}
|
||||
@Override protected Io_url Get_mustache_fil(Io_url addon_dir) {return addon_dir.GenSubFil_nest("bin", "xobc_xodir.mustache.html");}
|
||||
@Override protected Mustache_doc_itm Bld_mustache_root(Xoa_app app) {
|
||||
Xobc_task_addon addon = (Xobc_task_addon)app.Addon_mgr().Itms__get_or_null(Xobc_task_addon.ADDON__KEY);
|
||||
return new Xobc_xodir_doc
|
||||
( addon.Xodir_mgr().Get_dirs(app)
|
||||
, gplx.xowa.addons.wikis.imports.Xow_import_special.Get_root_url()
|
||||
, app.Fsys_mgr().Root_dir().RawBry()
|
||||
);
|
||||
}
|
||||
@Override protected void Bld_tags(Xoa_app app, Io_url addon_dir, Xopage_html_data page_data) {
|
||||
Xopg_tag_mgr head_tags = page_data.Head_tags();
|
||||
Xopg_alertify_.Add_tags (head_tags, app.Fsys_mgr().Http_root());
|
||||
Xopg_tag_wtr_.Add__xocss (head_tags, app.Fsys_mgr().Http_root());
|
||||
Xopg_tag_wtr_.Add__xohelp (head_tags, app.Fsys_mgr().Http_root());
|
||||
head_tags.Add(Xopg_tag_itm.New_css_file(addon_dir.GenSubFil_nest("bin", "xobc_xodir.css")));
|
||||
}
|
||||
}
|
@ -0,0 +1,21 @@
|
||||
/*
|
||||
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.addons.bldrs.xodirs; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.bldrs.*;
|
||||
public interface Xobc_xodir_mgr {
|
||||
Xobc_xodir_dir[] Get_dirs(Xoa_app app);
|
||||
}
|
@ -0,0 +1,32 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.addons.bldrs.xodirs; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.bldrs.*;
|
||||
public class Xobc_xodir_mgr__pc implements Xobc_xodir_mgr {
|
||||
public Xobc_xodir_mgr__pc(Xoa_app app) {
|
||||
}
|
||||
public Xobc_xodir_dir[] Get_dirs(Xoa_app app) {
|
||||
int len = 2;
|
||||
String dflt = app.Fsys_mgr().Root_dir().Raw();
|
||||
String selected = app.User().User_db_mgr().Cfg().Get_app_str_or(Xobc_xodir_cfg.Key__selected_dir, dflt);
|
||||
String custom = app.User().User_db_mgr().Cfg().Get_app_str_or(Xobc_xodir_cfg.Key__custom_dir, "(choose your own folder)");
|
||||
Xobc_xodir_dir[] rv = new Xobc_xodir_dir[len];
|
||||
rv[0] = new Xobc_xodir_dir(String_.Eq(selected, dflt), Bool_.N, Bry_.new_u8(dflt));
|
||||
rv[1] = new Xobc_xodir_dir(String_.Eq(selected, custom), Bool_.Y, Bry_.new_u8(custom));
|
||||
return rv;
|
||||
}
|
||||
}
|
@ -0,0 +1,45 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.addons.bldrs.xodirs; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.bldrs.*;
|
||||
import gplx.xowa.specials.*; import gplx.core.net.*; import gplx.core.net.qargs.*; import gplx.xowa.wikis.pages.*;
|
||||
import gplx.xowa.addons.bldrs.centrals.*;
|
||||
import gplx.xowa.addons.wikis.imports.*;
|
||||
public class Xobc_xodir_special implements Xow_special_page {
|
||||
public void Special__gen(Xow_wiki wiki, Xoa_page page, Xoa_url url, Xoa_ttl ttl) {
|
||||
Gfo_qarg_mgr url_args = new Gfo_qarg_mgr().Init(url.Qargs_ary());
|
||||
|
||||
byte[] path = url_args.Read_bry_or(Bry__path, null);
|
||||
if (path != null) { // path selected; set cfg and redirect to Download Central
|
||||
Xobc_xodir_cfg.Set_app_str__selected(wiki.App(), path);
|
||||
// On_path_selected.Invk(null, -1, "", null);
|
||||
// page.Redirect().Itms__add__special(wiki, Xobc_task_special.Prototype.Special__meta());
|
||||
page.Redirect().Itms__add__special(wiki, Prototype.Special__meta());
|
||||
return;
|
||||
}
|
||||
|
||||
new Xobc_xodir_html().Bld_page_by_mustache(wiki.App(), page, this);
|
||||
}
|
||||
private static final byte[] Bry__path = Bry_.new_a7("path");
|
||||
|
||||
Xobc_xodir_special(Xow_special_meta special__meta) {this.special__meta = special__meta;}
|
||||
public Xow_special_meta Special__meta() {return special__meta;} private final Xow_special_meta special__meta;
|
||||
public Xow_special_page Special__clone() {return this;}
|
||||
public static final Xow_special_page Prototype = new Xobc_xodir_special(Xow_special_meta.New_xo("XowaRootDir", "XOWA Folder Selection"));
|
||||
|
||||
public static Gfo_invk On_path_selected = Gfo_invk_.Noop;
|
||||
}
|
@ -0,0 +1,19 @@
|
||||
/*
|
||||
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.addons.bldrs.xodirs; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.bldrs.*;
|
||||
import gplx.xowa.addons.wikis.imports.*;
|
@ -0,0 +1,22 @@
|
||||
/*
|
||||
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.addons.wikis.imports; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.wikis.*;
|
||||
public interface Xow_import_dir_cbk {
|
||||
String Key();
|
||||
void Cbk__dir_selected(Xow_wiki wiki, Xoa_page page, String path);
|
||||
}
|
@ -1,50 +0,0 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.apps.cfgs.dbs; import gplx.*; import gplx.xowa.*; import gplx.xowa.apps.*; import gplx.xowa.apps.cfgs.*;
|
||||
import gplx.dbs.*;
|
||||
public class Xocfg_data_tbl implements Rls_able {
|
||||
private final String tbl_name; public final Dbmeta_fld_list flds = new Dbmeta_fld_list();
|
||||
private final String fld_key, fld_usr, fld_ctx, fld_val;
|
||||
private final Db_conn conn;
|
||||
public Xocfg_data_tbl(Db_conn conn) {
|
||||
this.conn = conn;
|
||||
tbl_name = Tbl_name;
|
||||
fld_key = flds.Add_str_pkey ("cfg_key", 1024); // EX: "xowa.net.web_enabled"
|
||||
fld_usr = flds.Add_str ("cfg_usr", 1024); // EX: "xowa_user"
|
||||
fld_ctx = flds.Add_str ("cfg_ctx", 1024); // EX: "app"
|
||||
fld_val = flds.Add_str ("cfg_val", 4096); // EX: "y"
|
||||
}
|
||||
public void Create_tbl() {conn.Meta_tbl_create(Dbmeta_tbl_itm.New(tbl_name, flds));}
|
||||
public void Insert(String key, String usr, String ctx, String val) {
|
||||
Db_stmt stmt_insert = conn.Stmt_insert(tbl_name, flds);
|
||||
stmt_insert.Clear().Val_str(fld_key, key).Val_str(fld_usr, usr).Val_str(fld_ctx, ctx).Val_str(fld_val, val)
|
||||
.Exec_insert();
|
||||
}
|
||||
public Xocfg_data_itm Select(String key, String usr, String ctx) {
|
||||
Db_stmt stmt_select = conn.Stmt_select(tbl_name, flds, fld_key, fld_usr, fld_ctx);
|
||||
Db_rdr rdr = stmt_select.Clear().Crt_str(fld_key, key).Crt_str(fld_usr, usr).Crt_str(fld_ctx, ctx).Exec_select__rls_auto();
|
||||
try {
|
||||
if (rdr.Move_next())
|
||||
return new Xocfg_data_itm(key, usr, ctx, rdr.Read_str(fld_val));
|
||||
else
|
||||
return null;
|
||||
} finally {rdr.Rls();}
|
||||
}
|
||||
public void Rls() {conn.Rls_conn();}
|
||||
public static final String Tbl_name = "cfg_data";
|
||||
}
|
@ -0,0 +1,60 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.bldrs.wkrs; import gplx.*; import gplx.xowa.*; import gplx.xowa.bldrs.*;
|
||||
public class Xob_io_utl_ {
|
||||
public static void Delete_sql_files(Io_url wiki_dir, String sql_file_name) {
|
||||
Delete_by_wildcard(wiki_dir, sql_file_name + ".sql", ".gz", ".sql");
|
||||
}
|
||||
public static void Delete_by_wildcard(Io_url dir, String name_pattern, String... ext_ary) {
|
||||
List_adp list = Find_by_wildcard(Io_mgr.Instance.QueryDir_args(dir).ExecAsUrlAry(), name_pattern, ext_ary);
|
||||
int len = list.Len();
|
||||
for (int i = 0; i < len; ++i) {
|
||||
Io_url url = (Io_url)list.Get_at(i);
|
||||
Io_mgr.Instance.DeleteFil(url);
|
||||
}
|
||||
}
|
||||
public static Io_url Find_nth_by_wildcard_or_null(Io_url dir, String name_pattern, String... ext_ary) {
|
||||
return Find_nth_by_wildcard_or_null(Io_mgr.Instance.QueryDir_args(dir).ExecAsUrlAry(), name_pattern, ext_ary);
|
||||
}
|
||||
public static Io_url Find_nth_by_wildcard_or_null(Io_url[] fil_ary, String name_pattern, String... ext_ary) {
|
||||
List_adp list = Find_by_wildcard(fil_ary, name_pattern, ext_ary);
|
||||
int list_len = list.Len();
|
||||
return list_len == 0 ? null : (Io_url)list.Get_at(list_len - 1);
|
||||
}
|
||||
public static List_adp Find_by_wildcard(Io_url[] fil_ary, String name_pattern, String... ext_ary) {
|
||||
List_adp rv = List_adp_.New();
|
||||
|
||||
// create ext_hash
|
||||
Ordered_hash ext_hash = Ordered_hash_.New();
|
||||
for (String ext : ext_ary)
|
||||
ext_hash.Add(ext, ext);
|
||||
|
||||
// iterate fil_ary
|
||||
for (Io_url fil : fil_ary) {
|
||||
// file matches pattern
|
||||
if ( name_pattern == Pattern__wilcard // empty String means match anything
|
||||
|| String_.Has(fil.NameAndExt(), name_pattern)) { // name has name_pattern; EX: "enwiki-latest-pages-articles-current.xml" and "pagelinks"
|
||||
if ( ext_hash.Len() == 0 // empty hash means match any ext
|
||||
|| ext_hash.Has(fil.Ext())) // ext exists in hash
|
||||
rv.Add(fil);
|
||||
}
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
public static final String Pattern__wilcard = String_.Empty;
|
||||
}
|
@ -0,0 +1,43 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.bldrs.wkrs; import gplx.*; import gplx.xowa.*; import gplx.xowa.bldrs.*;
|
||||
import org.junit.*; import gplx.core.tests.*;
|
||||
public class Xob_io_utl__tst {
|
||||
private final Xob_io_utl__fxt fxt = new Xob_io_utl__fxt();
|
||||
@Test public void Basic() {
|
||||
fxt.Test__match(String_.Ary("a.txt", "b.txt", "c.txt"), "b", String_.Ary(".txt"), "b.txt");
|
||||
}
|
||||
@Test public void Include__ext() {// PURPOSE: handle calls like "a.sql", ".sql", ".gz"
|
||||
fxt.Test__match(String_.Ary("a.txt", "b.txt", "c.txt"), "b.txt", String_.Ary(".txt"), "b.txt");
|
||||
}
|
||||
@Test public void Dupe__pick_last() {
|
||||
fxt.Test__match(String_.Ary("b0.txt", "b1.txt", "b2.txt"), "b", String_.Ary(".txt"), "b2.txt");
|
||||
}
|
||||
@Test public void Ext() {
|
||||
fxt.Test__match(String_.Ary("b.txt", "b.png", "b.xml"), "b", String_.Ary(".xml", ".bz2"), "b.xml");
|
||||
}
|
||||
@Test public void Ext__dupes() {
|
||||
fxt.Test__match(String_.Ary("b.txt", "b.png", "b.xml"), "b", String_.Ary(".txt", ".xml"), "b.xml");
|
||||
}
|
||||
}
|
||||
class Xob_io_utl__fxt {
|
||||
public void Test__match(String[] path_ary, String name_pattern, String[] ext_ary, String expd) {
|
||||
Io_url actl = Xob_io_utl_.Find_nth_by_wildcard_or_null(Io_url_.Ary(path_ary), name_pattern, ext_ary);
|
||||
Gftest.Eq__str(expd, actl == null ? "<<NULL>>" : actl.Raw());
|
||||
}
|
||||
}
|
@ -0,0 +1,28 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.parsers; import gplx.*; import gplx.xowa.*;
|
||||
import gplx.core.primitives.*;
|
||||
import gplx.xowa.files.*;
|
||||
import gplx.xowa.xtns.pfuncs.exprs.*; import gplx.xowa.xtns.math.*;
|
||||
public class Xop_tmp_mgr {
|
||||
public Xof_math_itm Math_itm() {return math_itm;} private final Xof_math_itm math_itm = new Xof_math_itm();
|
||||
public Xof_xfer_itm Xfer_itm() {return xfer_itm;} private final Xof_xfer_itm xfer_itm = new Xof_xfer_itm();
|
||||
public Number_parser Pfunc_num_parser_0() {return num_parser_0;} private final Number_parser num_parser_0 = new Number_parser().Hex_enabled_(true);
|
||||
public Number_parser Pfunc_num_parser_1() {return num_parser_1;} private final Number_parser num_parser_1 = new Number_parser().Hex_enabled_(true);
|
||||
public Pfunc_expr_shunter Expr_shunter() {return expr_shunter;} private final Pfunc_expr_shunter expr_shunter = new Pfunc_expr_shunter();
|
||||
}
|
@ -0,0 +1,30 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.users.cfgs; import gplx.*; import gplx.xowa.*; import gplx.xowa.users.*;
|
||||
public class Xou_cfg_itm {
|
||||
public Xou_cfg_itm(int usr, String ctx, String key, String val) {
|
||||
this.usr = usr; this.ctx = ctx; this.key = key; this.val = val;
|
||||
this.uid = Xou_cfg_mgr.Bld_uid(usr, ctx, key);
|
||||
}
|
||||
public String Uid() {return uid;} private final String uid;
|
||||
public int Usr() {return usr;} private final int usr;
|
||||
public String Ctx() {return ctx;} private final String ctx;
|
||||
public String Key() {return key;} private final String key;
|
||||
public String Val() {return val;} private String val;
|
||||
public void Val_(String v) {this.val = v;}
|
||||
}
|
@ -0,0 +1,73 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.users.cfgs; import gplx.*; import gplx.xowa.*; import gplx.xowa.users.*;
|
||||
import gplx.dbs.*;
|
||||
public class Xou_cfg_mgr {
|
||||
private Xou_cfg_tbl tbl;
|
||||
private final Hash_adp hash = Hash_adp_.New();
|
||||
private final Bry_bfr tmp_bfr = Bry_bfr_.New();
|
||||
public void Init_by_app(Db_conn conn) {
|
||||
tbl = new Xou_cfg_tbl(conn);
|
||||
tbl.Conn().Meta_tbl_assert(tbl);
|
||||
this.Reg(tbl.Select_by_usr_ctx(Usr__anonymous, Ctx__app));
|
||||
}
|
||||
public String Get_app_str_or(String key, String or) { // NOTE: app-level is always loaded at start; don't check db
|
||||
synchronized (hash) { // LOCK:app-level
|
||||
String uid = Bld_uid(tmp_bfr, Usr__anonymous, Ctx__app, key);
|
||||
Xou_cfg_itm itm = (Xou_cfg_itm)hash.Get_by(uid);
|
||||
return itm == null ? or : itm.Val();
|
||||
}
|
||||
}
|
||||
public void Set_app_bry(String key, byte[] val) {this.Set_app_str(key, String_.new_u8(val));}
|
||||
public void Set_app_str(String key, String val) {
|
||||
synchronized (hash) { // LOCK:app-level
|
||||
// update val in reg
|
||||
String uid = Bld_uid(tmp_bfr, Usr__anonymous, Ctx__app, key);
|
||||
boolean insert = false;
|
||||
Xou_cfg_itm itm = (Xou_cfg_itm)hash.Get_by(uid);
|
||||
if (itm == null) {
|
||||
itm = new Xou_cfg_itm(Usr__anonymous, Ctx__app, key, val);
|
||||
hash.Add(uid, itm);
|
||||
insert = true;
|
||||
}
|
||||
itm.Val_(val);
|
||||
|
||||
// save to db
|
||||
tbl.Upsert(insert, itm.Usr(), itm.Ctx(), itm.Key(), itm.Val());
|
||||
}
|
||||
}
|
||||
|
||||
private void Reg(Xou_cfg_itm[] itms) {
|
||||
synchronized (hash) { // LOCK:app-level
|
||||
for (Xou_cfg_itm itm : itms)
|
||||
hash.Add(itm.Uid(), itm);
|
||||
}
|
||||
}
|
||||
|
||||
private static final int Usr__anonymous = 1;
|
||||
private static final String Ctx__app = "app";
|
||||
public static String Bld_uid(int usr, String ctx, String key) {
|
||||
return String_.Concat(Int_.To_str(usr), "|", ctx, "|", key);
|
||||
}
|
||||
private static String Bld_uid(Bry_bfr tmp_bfr, int usr, String ctx, String key) {
|
||||
tmp_bfr.Add_int_variable(usr).Add_byte_pipe();
|
||||
tmp_bfr.Add_str_a7(ctx).Add_byte_pipe();
|
||||
tmp_bfr.Add_str_u8(key);
|
||||
return tmp_bfr.To_str_and_clear();
|
||||
}
|
||||
}
|
@ -0,0 +1,70 @@
|
||||
/*
|
||||
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.users.cfgs; import gplx.*; import gplx.xowa.*; import gplx.xowa.users.*;
|
||||
import gplx.dbs.*;
|
||||
public class Xou_cfg_tbl implements Db_tbl {
|
||||
public final Dbmeta_fld_list flds = new Dbmeta_fld_list();
|
||||
private final String fld_key, fld_usr, fld_ctx, fld_val;
|
||||
public Xou_cfg_tbl(Db_conn conn) {
|
||||
this.conn = conn;
|
||||
this.fld_usr = flds.Add_int ("cfg_usr"); // EX: 1=anonymous; others will require usr_regy
|
||||
this.fld_ctx = flds.Add_str ("cfg_ctx", 1024); // EX: "app"; "en.w"
|
||||
this.fld_key = flds.Add_str ("cfg_key", 1024); // EX: "xowa.net.web_enabled"
|
||||
this.fld_val = flds.Add_str ("cfg_val", 4096); // EX: "y"
|
||||
conn.Rls_reg(this);
|
||||
}
|
||||
public Db_conn Conn() {return conn;} private final Db_conn conn;
|
||||
public String Tbl_name() {return tbl_name;} private final String tbl_name = "user_cfg";
|
||||
public void Create_tbl() {
|
||||
conn.Meta_tbl_create(Dbmeta_tbl_itm.New(tbl_name, flds
|
||||
, Dbmeta_idx_itm.new_normal_by_tbl(tbl_name, fld_key, fld_key)
|
||||
));
|
||||
}
|
||||
public void Upsert(boolean insert, int usr, String ctx, String key, String val) {
|
||||
if (insert)
|
||||
Insert(usr, ctx, key, val);
|
||||
else
|
||||
Update(usr, ctx, key, val);
|
||||
}
|
||||
private void Insert(int usr, String ctx, String key, String val) {
|
||||
Db_stmt stmt = conn.Stmt_insert(tbl_name, flds);
|
||||
stmt.Clear().Val_int(fld_usr, usr).Val_str(fld_ctx, ctx).Val_str(fld_key, key).Val_str(fld_val, val).Exec_insert();
|
||||
stmt.Rls();
|
||||
}
|
||||
private void Update(int usr, String ctx, String key, String val) {
|
||||
Db_stmt stmt = conn.Stmt_update(tbl_name, String_.Ary(fld_usr, fld_ctx, fld_key), fld_val);
|
||||
stmt.Clear().Val_str(fld_val, val).Crt_int(fld_usr, usr).Crt_str(fld_ctx, ctx).Crt_str(fld_key, key).Exec_update();
|
||||
stmt.Rls();
|
||||
}
|
||||
public Xou_cfg_itm[] Select_by_usr_ctx(int usr, String ctx) {
|
||||
List_adp list = List_adp_.New();
|
||||
Db_stmt stmt_select = conn.Stmt_select(tbl_name, flds, fld_usr, fld_ctx);
|
||||
Db_rdr rdr = stmt_select.Clear().Crt_int(fld_usr, usr).Crt_str(fld_ctx, ctx).Exec_select__rls_auto();
|
||||
try {
|
||||
while (rdr.Move_next()) {
|
||||
list.Add(Make_itm(rdr));
|
||||
}
|
||||
} finally {rdr.Rls();}
|
||||
return (Xou_cfg_itm[])list.To_ary_and_clear(Xou_cfg_itm.class);
|
||||
}
|
||||
public void Rls() {}
|
||||
|
||||
private Xou_cfg_itm Make_itm(Db_rdr rdr) {
|
||||
return new Xou_cfg_itm(rdr.Read_int(fld_usr), rdr.Read_str(fld_ctx), rdr.Read_str(fld_key), rdr.Read_str(fld_val));
|
||||
}
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue