mirror of
https://github.com/gnosygnu/xowa.git
synced 2026-03-02 03:49:30 +00:00
Source: Restore broken commit
This commit is contained in:
67
400_xowa/src/gplx/xowa/drds/Xod_app.java
Normal file
67
400_xowa/src/gplx/xowa/drds/Xod_app.java
Normal file
@@ -0,0 +1,67 @@
|
||||
/*
|
||||
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.drds; import gplx.*; import gplx.xowa.*;
|
||||
import gplx.xowa.drds.pages.*; import gplx.xowa.drds.files.*;
|
||||
import gplx.xowa.apps.*; import gplx.xowa.wikis.data.tbls.*;
|
||||
import gplx.xowa.wikis.domains.*; import gplx.xowa.wikis.nss.*; import gplx.xowa.guis.cbks.js.*;
|
||||
import gplx.xowa.addons.wikis.searchs.searchers.rslts.*;
|
||||
import gplx.langs.htmls.encoders.*; import gplx.xowa.htmls.hrefs.*;
|
||||
import gplx.xowa.addons.wikis.searchs.*; import gplx.xowa.addons.wikis.searchs.searchers.*;
|
||||
import gplx.xowa.langs.cases.*;
|
||||
public class Xod_app {
|
||||
private final Xoav_app app;
|
||||
private final Xod_page_mgr page_mgr = new Xod_page_mgr();
|
||||
private final Xod_file_mgr file_mgr = new Xod_file_mgr();
|
||||
private final Srch_ns_mgr ns_mgr = new Srch_ns_mgr();
|
||||
public Xod_app(Xoav_app app) {
|
||||
this.app = app;
|
||||
ns_mgr.Add_main_if_empty();
|
||||
}
|
||||
public Xow_wiki Wikis__get_by_domain(String wiki_domain) {
|
||||
Xow_wiki rv = app.Wiki_mgri().Get_by_or_make_init_y(Bry_.new_u8(wiki_domain));
|
||||
if (rv != null && rv.Data__core_mgr() == null) rv.Init_by_wiki();
|
||||
return rv;
|
||||
}
|
||||
public Xod_page_itm Wiki__get_by_url(Xow_wiki wiki, Xoa_url page_url) {
|
||||
return page_mgr.Get_page(wiki, page_url);
|
||||
}
|
||||
public Xod_page_itm Wiki__get_random(Xow_wiki wiki, Xow_ns ns) {
|
||||
byte[] random_ttl_bry = wiki.Data__core_mgr().Tbl__page().Select_random(ns);
|
||||
Xoa_url url = wiki.Utl__url_parser().Parse(random_ttl_bry);
|
||||
return Wiki__get_by_url(wiki, url);
|
||||
}
|
||||
public void Wiki__search(Cancelable cxl, Srch_rslt_cbk cbk, Xow_wiki wiki, String search, int bgn, int end) {
|
||||
Srch_search_addon addon = Get_addon(wiki);
|
||||
Srch_search_qry qry = Srch_search_qry.New__drd(wiki, ns_mgr, Bry_.new_u8(search), bgn, end);
|
||||
addon.Search(qry, cbk);
|
||||
}
|
||||
public void Page__on_load_end(Xow_wiki wiki, Xod_page_itm pg, Xog_js_wkr js_wkr) {
|
||||
file_mgr.Load_files(wiki, pg, js_wkr);
|
||||
app.User().User_db_mgr().Cache_mgr().Db_save();
|
||||
gplx.xowa.wikis.pages.lnkis.Xopg_redlink_mgr.Run_async(pg.Hpg(), js_wkr);
|
||||
}
|
||||
public static byte[] To_page_url(Xow_wiki wiki, String canonical_str) {// NOTE: need canonical_url to handle "A:B" where "A:" is not a ns, even though PageTitle treats "A:" as a namespace
|
||||
byte[] canonical_bry = Bry_.new_u8(canonical_str);
|
||||
int page_bgn = Bry_find_.Move_fwd(canonical_bry, Xoh_href_.Bry__wiki, 0); if (page_bgn == Bry_find_.Not_found) throw Err_.new_("drd", "uknown url format: no '/wiki/'", "url", canonical_bry);
|
||||
byte[] page_bry = Bry_.Mid(canonical_bry, page_bgn, canonical_bry.length); // get bry; EX: https://en.wikipedia.org/wiki/A -> A
|
||||
page_bry = Gfo_url_encoder_.Http_url.Decode(page_bry); // decode %-encoding; convert + to space
|
||||
page_bry = Xoa_ttl.Replace_spaces(page_bry); // convert spaces to unders; canonical-url has spaces
|
||||
return page_bry;
|
||||
}
|
||||
private Srch_search_addon Get_addon(Xow_wiki wiki) {return Srch_search_addon.Get(wiki);}
|
||||
}
|
||||
73
400_xowa/src/gplx/xowa/drds/Xod_app_tst.java
Normal file
73
400_xowa/src/gplx/xowa/drds/Xod_app_tst.java
Normal file
@@ -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.drds; import gplx.*; import gplx.xowa.*;
|
||||
import org.junit.*; import gplx.xowa.drds.pages.*; import gplx.xowa.wikis.*; import gplx.xowa.htmls.sections.*;
|
||||
public class Xod_app_tst {
|
||||
private final Xod_app_tstr tstr = new Xod_app_tstr();
|
||||
@Before public void init() {tstr.Init_mem();}
|
||||
// COMMENTED: broke from changes to auto-init wiki; DATE:2016-06-16
|
||||
// @Test public void Get() {
|
||||
// tstr.Data_mgr().Page__insert(1, "A", "2015-10-19 00:01:02");
|
||||
// tstr.Data_mgr().Html__insert(1, "abc");
|
||||
// tstr.Test__get("A", tstr.Make_page(1, "A", "2015-10-19T00:01:02Z", tstr.Make_section(0, 2, "", "", "abc")));
|
||||
// }
|
||||
@Test public void To_page_db() {
|
||||
tstr.Test__to_page_url("http://en.wikipedia.org/wiki/A" , "A");
|
||||
tstr.Test__to_page_url("http://en.wikipedia.org/wiki/A:B" , "A:B");
|
||||
tstr.Test__to_page_url("http://en.wikipedia.org/wiki/Help:A" , "Help:A");
|
||||
tstr.Test__to_page_url("http://en.wikipedia.org/wiki/A B" , "A_B"); // NOTE:canonical url has spaces;
|
||||
tstr.Test__to_page_url("http://en.wikipedia.org/wiki/A%27B" , "A'B"); // NOTE:canonical url has percent-encoding;
|
||||
tstr.Test__to_page_url("http://en.wikipedia.org/wiki/A+B" , "A_B"); // NOTE:canonical url sometimes has "+" for space
|
||||
}
|
||||
}
|
||||
class Xod_app_tstr {
|
||||
private final gplx.xowa.apps.Xoav_app app; private final Xowv_wiki wiki;
|
||||
private final Xod_app drd_provider;
|
||||
public Xod_app_tstr() {
|
||||
this.app = Xoa_app_fxt.Make__app__view();
|
||||
this.wiki = Xoa_app_fxt.Make__wiki__view(app);
|
||||
data_mgr.Wiki_(wiki);
|
||||
Xoa_test_.Init__db__view(wiki);
|
||||
drd_provider = new Xod_app(app);
|
||||
}
|
||||
public Xowd_data_tstr Data_mgr() {return data_mgr;} private final Xowd_data_tstr data_mgr = new Xowd_data_tstr();
|
||||
public void Init_mem() {
|
||||
Io_mgr.Instance.InitEngine_mem();
|
||||
}
|
||||
public void Test__get(String ttl, Xod_page_itm expd) {
|
||||
Xow_wiki wiki = drd_provider.Wikis__get_by_domain("en.wikipedia.org");
|
||||
Xoa_url page_url = wiki.Utl__url_parser().Parse(Bry_.new_u8(ttl));
|
||||
Xod_page_itm itm = drd_provider.Wiki__get_by_url(wiki, page_url);
|
||||
Tfds.Eq(expd.To_str(), itm.To_str());
|
||||
}
|
||||
public void Test__to_page_url(String raw, String expd) {
|
||||
// // canonical url has spaces as well as %-encoding; PAGE:en.w:List_of_Fire_Emblem:Shadow_Dragon_characters
|
||||
Tfds.Eq_bry(Bry_.new_u8(expd), Xod_app.To_page_url(wiki, raw));
|
||||
}
|
||||
public Xod_page_itm Make_page(int page_id, String ttl, String modified_on, Xoh_section_itm... section_ary) {
|
||||
Xod_page_itm rv = new Xod_page_itm();
|
||||
rv.Init(page_id, page_id, ttl, ttl, null, null, modified_on, Bool_.N, Bool_.N, Bool_.N, 1, null, null, null);
|
||||
int len = section_ary.length;
|
||||
for (int i = 0; i < len; ++i) {
|
||||
Xoh_section_itm itm = section_ary[i];
|
||||
rv.Section_list().Add(itm);
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
public Xoh_section_itm Make_section(int id, int level, String anchor, String heading, String content) {return new Xoh_section_itm(id, level, Bry_.new_u8(anchor), Bry_.new_u8(heading)).Content_(Bry_.new_u8(content));}
|
||||
}
|
||||
52
400_xowa/src/gplx/xowa/drds/Xowd_data_tstr.java
Normal file
52
400_xowa/src/gplx/xowa/drds/Xowd_data_tstr.java
Normal file
@@ -0,0 +1,52 @@
|
||||
/*
|
||||
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.drds; import gplx.*; import gplx.xowa.*;
|
||||
import gplx.xowa.wikis.data.*;
|
||||
import gplx.xowa.htmls.*; import gplx.xowa.wikis.data.tbls.*;
|
||||
public class Xowd_data_tstr {
|
||||
public void Wiki_(Xow_wiki wiki) {this.wiki = wiki;} private Xow_wiki wiki;
|
||||
public void Page__insert(int page_id, String ttl_str, String modified_on) {Page__insert(page_id, ttl_str, modified_on, Bool_.N, 0, page_id, 0, 0);}
|
||||
public void Page__insert(int page_id, String ttl_str, String modified_on, boolean page_is_redirect, int page_len, int random_int, int text_db_id, int html_db_id) {
|
||||
Xoa_ttl ttl = wiki.Ttl_parse(Bry_.new_u8(ttl_str));
|
||||
wiki.Data__core_mgr().Tbl__page().Insert(page_id, ttl.Ns().Id(), ttl.Page_db(), page_is_redirect, DateAdp_.parse_iso8561(modified_on), page_len, page_id, text_db_id, html_db_id);
|
||||
}
|
||||
public void Html__insert(int page_id, String html) {
|
||||
Xow_db_file html_db = wiki.Data__core_mgr().Db__html();
|
||||
if (html_db == null) {
|
||||
html_db = wiki.Data__core_mgr().Db__core();
|
||||
html_db.Tbl__html().Create_tbl();
|
||||
}
|
||||
byte[] html_bry = Bry_.new_u8(html);
|
||||
Xoh_page hpg = new Xoh_page();
|
||||
hpg.Db().Html().Html_bry_(html_bry);
|
||||
byte[] data = html_bry;
|
||||
html_db.Tbl__html().Insert(page_id, 0, gplx.core.ios.streams.Io_stream_tid_.Tid__raw, gplx.xowa.htmls.core.hzips.Xoh_hzip_dict_.Hzip__none, Bry_.Empty, Bry_.Empty, Bry_.Empty, data);
|
||||
}
|
||||
public void Text__insert(int page_id, String text) {
|
||||
Xow_db_file db = wiki.Data__core_mgr().Db__text();
|
||||
if (db == null) {
|
||||
db = wiki.Data__core_mgr().Db__core();
|
||||
db.Tbl__text().Create_tbl();
|
||||
}
|
||||
db.Tbl__text().Create_tbl();
|
||||
byte[] text_bry = Bry_.new_u8(text);
|
||||
db.Tbl__text().Insert_bgn();
|
||||
db.Tbl__text().Insert_cmd_by_batch(page_id, text_bry);
|
||||
db.Tbl__text().Insert_end();
|
||||
}
|
||||
}
|
||||
23
400_xowa/src/gplx/xowa/drds/files/Xod_activity_adp.java
Normal file
23
400_xowa/src/gplx/xowa/drds/files/Xod_activity_adp.java
Normal file
@@ -0,0 +1,23 @@
|
||||
/*
|
||||
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.drds.files; import gplx.*; import gplx.xowa.*; import gplx.xowa.drds.*;
|
||||
public interface Xod_activity_adp {
|
||||
String Fsys__files_dir();
|
||||
String Fsys__cache_dir();
|
||||
String Fsys__sdcard_rw_or_null();
|
||||
}
|
||||
39
400_xowa/src/gplx/xowa/drds/files/Xod_file_mgr.java
Normal file
39
400_xowa/src/gplx/xowa/drds/files/Xod_file_mgr.java
Normal file
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
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.drds.files; import gplx.*; import gplx.xowa.*; import gplx.xowa.drds.*;
|
||||
import gplx.core.threads.*;
|
||||
import gplx.xowa.drds.pages.*;
|
||||
import gplx.xowa.files.*; import gplx.xowa.guis.cbks.js.*;
|
||||
import gplx.xowa.htmls.*;
|
||||
public class Xod_file_mgr {
|
||||
private final Gfo_thread_pool thread_pool = new Gfo_thread_pool();
|
||||
public void Load_files(Xow_wiki wiki, Xod_page_itm pg, Xog_js_wkr js_wkr) {
|
||||
Xoh_page hpg = pg.Hpg();
|
||||
List_adp img_list = To_img_list(hpg.Img_mgr());
|
||||
Xof_file_wkr img_wkr = new Xof_file_wkr(wiki.File__orig_mgr(), wiki.File__bin_mgr(), wiki.File__mnt_mgr(), wiki.App().User().User_db_mgr().Cache_mgr(), wiki.File__repo_mgr(), js_wkr, hpg, img_list);
|
||||
thread_pool.Add_at_end(img_wkr);
|
||||
thread_pool.Run();
|
||||
}
|
||||
private static List_adp To_img_list(Xoh_img_mgr img_mgr) {
|
||||
List_adp rv = List_adp_.New();
|
||||
int len = img_mgr.Len();
|
||||
for (int i = 0; i < len; ++i)
|
||||
rv.Add(img_mgr.Get_at(i));
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
35
400_xowa/src/gplx/xowa/drds/files/Xod_fsys_mgr.java
Normal file
35
400_xowa/src/gplx/xowa/drds/files/Xod_fsys_mgr.java
Normal file
@@ -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.xowa.drds.files; import gplx.*; import gplx.xowa.*; import gplx.xowa.drds.*;
|
||||
public class Xod_fsys_mgr {
|
||||
public Xod_fsys_mgr(Gfo_log log, Xod_activity_adp activity) {
|
||||
this.usr_data_dir = Io_url_.lnx_dir_(activity.Fsys__files_dir() + "/");
|
||||
// this.usr_temp_dir = Io_url_.lnx_dir_(activity.Fsys__cache_dir() + "/");
|
||||
this.usr_data_fil = usr_data_dir.GenSubFil_nest("usr-anonymous.sqlite3"); // should go to /xowa/usr/usr-anonymous.sqlite3
|
||||
this.app_root_dir = usr_data_dir.GenSubDir_nest("files", "xowa");
|
||||
String sdcard_rw = activity.Fsys__sdcard_rw_or_null();
|
||||
if (sdcard_rw != null) {
|
||||
app_root_dir = Io_url_.lnx_dir_(sdcard_rw + "files/xowa/");
|
||||
}
|
||||
log.Info("fsys_mgr:root_dir", "root", app_root_dir.Xto_api());
|
||||
}
|
||||
public Io_url Usr_data_dir() {return usr_data_dir;} private Io_url usr_data_dir; // cleared by "Clear data"; maps to both @gplx.Internal protected and external storage
|
||||
// private Io_url Usr_temp_dir() {return usr_temp_dir;} private Io_url usr_temp_dir; // cleared by "Clear cache"
|
||||
public Io_url Usr_data_fil() {return usr_data_fil;} private Io_url usr_data_fil;
|
||||
public Io_url App_root_dir() {return app_root_dir;} private Io_url app_root_dir;
|
||||
}
|
||||
21
400_xowa/src/gplx/xowa/drds/ios/assets/Xod_asset_mgr.java
Normal file
21
400_xowa/src/gplx/xowa/drds/ios/assets/Xod_asset_mgr.java
Normal file
@@ -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.drds.ios.assets; import gplx.*; import gplx.xowa.*; import gplx.xowa.drds.*; import gplx.xowa.drds.ios.*;
|
||||
public interface Xod_asset_mgr extends gplx.core.ios.loaders.Io_loader {
|
||||
String[] List_as_str_ary (Io_url dir);
|
||||
}
|
||||
@@ -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.drds.ios.media_scanners; import gplx.*; import gplx.xowa.*; import gplx.xowa.drds.*; import gplx.xowa.drds.ios.*;
|
||||
public interface Xod_media_scanner extends Gfo_evt_itm {
|
||||
Xod_media_scanner Add(Io_url url);
|
||||
void Scan();
|
||||
}
|
||||
@@ -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.drds.ios.media_scanners; import gplx.*; import gplx.xowa.*; import gplx.xowa.drds.*; import gplx.xowa.drds.ios.*;
|
||||
public abstract class Xod_media_scanner__base implements Xod_media_scanner {
|
||||
private final List_adp list = List_adp_.New();
|
||||
public Xod_media_scanner__base() {
|
||||
this.evt_mgr = new Gfo_evt_mgr(this);
|
||||
Gfo_evt_mgr_.Sub_same(Io_mgr.Instance, Io_mgr.Evt__fil_created, this);
|
||||
}
|
||||
public Gfo_evt_mgr Evt_mgr() {return evt_mgr;} private final Gfo_evt_mgr evt_mgr;
|
||||
public Xod_media_scanner Add(Io_url url) {list.Add(url.Xto_api()); return this;}
|
||||
public void Scan() {
|
||||
String[] urls = list.To_str_ary_and_clear();
|
||||
Gfo_log_.Instance.Info("xo.io:media scan", "urls", String_.Concat_with_str(":", urls));
|
||||
this.Scan__hook(urls);
|
||||
}
|
||||
protected abstract void Scan__hook(String[] urls);
|
||||
private void On_fil_created(Io_url[] ary) {
|
||||
for (Io_url itm : ary)
|
||||
this.Add(itm);
|
||||
this.Scan();
|
||||
}
|
||||
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
|
||||
if (ctx.Match(k, Io_mgr.Evt__fil_created)) On_fil_created((Io_url[])m.ReadObj("v"));
|
||||
else return Gfo_invk_.Rv_unhandled;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
96
400_xowa/src/gplx/xowa/drds/pages/Xod_page_itm.java
Normal file
96
400_xowa/src/gplx/xowa/drds/pages/Xod_page_itm.java
Normal file
@@ -0,0 +1,96 @@
|
||||
/*
|
||||
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.drds.pages; import gplx.*; import gplx.xowa.*; import gplx.xowa.drds.*;
|
||||
import gplx.xowa.htmls.*; import gplx.xowa.htmls.sections.*;
|
||||
import gplx.xowa.wikis.data.tbls.*;
|
||||
import gplx.xowa.wikis.pages.*; import gplx.xowa.wikis.pages.tags.*;
|
||||
public class Xod_page_itm {
|
||||
public int Page_id() {return page_id;} private int page_id;
|
||||
public long Rev_id() {return rev_id;} private long rev_id;
|
||||
public String Ttl_text() {return ttl_text;} private String ttl_text;
|
||||
public String Ttl_db() {return ttl_db;} private String ttl_db;
|
||||
public String Ttl_special() {return ttl_special;} public void Ttl_special_(String v) {ttl_special = v;} private String ttl_special;
|
||||
public String Redirected() {return redirected;} private String redirected;
|
||||
public String Description() {return description;} private String description;
|
||||
public String Modified_on() {return modified_on;} private String modified_on;
|
||||
public boolean Is_editable() {return is_editable;} private boolean is_editable;
|
||||
public boolean Is_main_page() {return is_main_page;} private boolean is_main_page;
|
||||
public boolean Is_disambiguation() {return is_disambiguation;} private boolean is_disambiguation;
|
||||
public int Lang_count() {return lang_count;} private int lang_count;
|
||||
public String Head_url() {return head_url;} private String head_url;
|
||||
public String Head_name() {return head_ttl;} private String head_ttl;
|
||||
public String First_allowed_editor_role() {return first_allowed_editor_role;} private String first_allowed_editor_role;
|
||||
public List_adp Section_list() {return section_list;} private List_adp section_list = List_adp_.New();
|
||||
public Xoh_page Hpg() {return hpg;} private Xoh_page hpg;
|
||||
public Xopg_tag_mgr Head_tags() {return head_tags;} private final Xopg_tag_mgr head_tags = new Xopg_tag_mgr(Bool_.Y);
|
||||
public Xopg_tag_mgr Tail_tags() {return tail_tags;} private final Xopg_tag_mgr tail_tags = new Xopg_tag_mgr(Bool_.N);
|
||||
public void Init(int page_id, int rev_id
|
||||
, String ttl_text, String ttl_db, String redirected, String description, String modified_on
|
||||
, boolean is_editable, boolean is_main_page, boolean is_disambiguation, int lang_count
|
||||
, String head_url, String head_ttl
|
||||
, String first_allowed_editor_role
|
||||
) {
|
||||
this.page_id = page_id; this.rev_id = rev_id;
|
||||
this.ttl_text = ttl_text; this.ttl_db = ttl_db; this.redirected = redirected; this.description = description; this.modified_on = modified_on;
|
||||
this.is_editable = is_editable; this.is_main_page = is_main_page; this.is_disambiguation = is_disambiguation; this.lang_count = lang_count;
|
||||
this.head_url = head_url; this.head_ttl= head_ttl; this.first_allowed_editor_role = first_allowed_editor_role;
|
||||
}
|
||||
public void Init_by_dbpg(Xoa_ttl ttl, Xowd_page_itm db_page) {
|
||||
this.page_id = db_page.Id();
|
||||
this.rev_id = page_id;
|
||||
this.ttl_text = String_.new_u8(ttl.Page_txt());
|
||||
this.ttl_db = ttl.Page_db_as_str();
|
||||
this.modified_on = db_page.Modified_on().XtoStr_fmt_iso_8561_w_tz();
|
||||
this.lang_count = 1;
|
||||
this.redirected = null;
|
||||
this.description = null;
|
||||
this.is_editable = false;
|
||||
this.is_main_page = false;
|
||||
this.is_disambiguation = false;
|
||||
this.head_url = null;
|
||||
this.head_ttl = null;
|
||||
this.first_allowed_editor_role = null;
|
||||
}
|
||||
public void Init_by_hpg(Xoh_page hpg) {
|
||||
this.hpg = hpg;
|
||||
}
|
||||
public String To_str() {
|
||||
Bry_bfr bfr = Bry_bfr_.New();
|
||||
bfr .Add_int_variable(page_id).Add_byte_pipe()
|
||||
.Add_long_variable(rev_id).Add_byte_pipe()
|
||||
.Add_str_u8(ttl_text).Add_byte_pipe()
|
||||
.Add_str_u8(ttl_db).Add_byte_pipe()
|
||||
.Add_str_a7_null(modified_on).Add_byte_pipe()
|
||||
.Add_int_variable(lang_count).Add_byte_pipe()
|
||||
.Add_str_a7_null(redirected).Add_byte_pipe()
|
||||
.Add_str_a7_null(description).Add_byte_pipe()
|
||||
.Add_yn(is_editable).Add_byte_pipe()
|
||||
.Add_yn(is_main_page).Add_byte_pipe()
|
||||
.Add_yn(is_disambiguation).Add_byte_pipe()
|
||||
.Add_str_a7_null(head_url).Add_byte_pipe()
|
||||
.Add_str_a7_null(head_ttl).Add_byte_pipe()
|
||||
.Add_str_a7_null(first_allowed_editor_role).Add_byte_nl()
|
||||
;
|
||||
int len = section_list.Count();
|
||||
for (int i = 0; i < len; ++i) {
|
||||
Xoh_section_itm section = (Xoh_section_itm)section_list.Get_at(i);
|
||||
section.To_bfr(bfr);
|
||||
}
|
||||
return bfr.To_str_and_clear();
|
||||
}
|
||||
}
|
||||
79
400_xowa/src/gplx/xowa/drds/pages/Xod_page_mgr.java
Normal file
79
400_xowa/src/gplx/xowa/drds/pages/Xod_page_mgr.java
Normal file
@@ -0,0 +1,79 @@
|
||||
/*
|
||||
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.drds.pages; import gplx.*; import gplx.xowa.*; import gplx.xowa.drds.*;
|
||||
import gplx.core.net.*; import gplx.xowa.addons.wikis.imports.*;
|
||||
import gplx.xowa.wikis.data.tbls.*;
|
||||
import gplx.xowa.htmls.*; import gplx.xowa.htmls.sections.*;
|
||||
import gplx.xowa.wikis.pages.redirects.*;
|
||||
public class Xod_page_mgr {
|
||||
public Xod_page_itm Get_page(Xow_wiki wiki, Xoa_url page_url) {
|
||||
Xod_page_itm rv = new Xod_page_itm();
|
||||
|
||||
// load meta info like page_id, modified, etc
|
||||
Xoa_ttl ttl = wiki.Ttl_parse(page_url.Page_bry());
|
||||
if (ttl.Ns().Id_is_special()) return Load_special(rv, wiki, page_url, ttl);
|
||||
Xowd_page_itm dbpg = new Xowd_page_itm();
|
||||
try {wiki.Data__core_mgr().Tbl__page().Select_by_ttl(dbpg, ttl.Ns(), ttl.Page_db());}
|
||||
catch (Exception e) {// throw detailed exception to track down page_score exception
|
||||
throw Err_.new_("", "failed to retrieve page", "wiki", wiki.Domain_str(), "page_url", page_url.Page_bry(), "err", Err_.Message_lang(e));
|
||||
}
|
||||
rv.Init_by_dbpg(ttl, dbpg);
|
||||
|
||||
// load page data
|
||||
Xoh_page hpg = new Xoh_page();
|
||||
hpg.Ctor_by_hview(wiki, Xoa_url.New(wiki, ttl), ttl, 1);
|
||||
rv.Init_by_hpg(hpg);
|
||||
wiki.Html__hdump_mgr().Load_mgr().Load_by_xowh(hpg, ttl, Bool_.Y);
|
||||
Load_sections(rv, hpg);
|
||||
return rv;
|
||||
}
|
||||
private void Load_sections(Xod_page_itm rv, Xoh_page hpg) {
|
||||
Xoh_section_mgr section_mgr = hpg.Section_mgr();
|
||||
int len = section_mgr.Len();
|
||||
for (int i = 0; i < len; ++i) {
|
||||
Xoh_section_itm itm = section_mgr.Get_at(i);
|
||||
rv.Section_list().Add(itm);
|
||||
}
|
||||
}
|
||||
private Xod_page_itm Load_special(Xod_page_itm rv, Xow_wiki wiki, Xoa_url url, Xoa_ttl ttl) {
|
||||
// get prototype
|
||||
gplx.xowa.specials.Xow_special_page proto = wiki.App().Special_regy().Get_by_or_null(ttl.Page_txt_wo_qargs());
|
||||
if (proto == null) return rv; // invalid url
|
||||
|
||||
// generate special
|
||||
Xoh_page page = new Xoh_page();
|
||||
page.Ctor_by_hview(wiki, Xoa_url.New(wiki, ttl), ttl, 1); // NOTE: init page to set url, ttl; DATE:2016-06-23
|
||||
try {proto.Special__clone().Special__gen(wiki, page, url, ttl);}
|
||||
catch (Exception e) {Gfo_log_.Instance.Warn("failed to generate special page", "url", url.To_str(), "err", Err_.Message_gplx_log(e)); return rv;}
|
||||
|
||||
// handle redirects; EX: Special:XowaWikiInfo
|
||||
Xopg_redirect_itm redirect_itm = page.Redirect_trail().Itms__get_at_nth_or_null();
|
||||
if (redirect_itm != null)
|
||||
return Get_page(wiki, redirect_itm.Url());
|
||||
|
||||
rv.Init(-1, -1, String_.new_u8(ttl.Page_txt()), String_.new_u8(ttl.Page_db()), null, null, Datetime_now.Get().XtoStr_fmt_iso_8561(), false, false, false, 0, "", "", "");
|
||||
rv.Init_by_hpg(page);
|
||||
Xoh_section_itm section = new Xoh_section_itm(1, 1, Bry_.Empty, Bry_.Empty);
|
||||
section.Content_(page.Html_data().Custom_body());
|
||||
rv.Section_list().Add(section);
|
||||
rv.Ttl_special_(String_.new_u8(page.Html_data().Display_ttl()));
|
||||
rv.Head_tags().Copy(page.Html_data().Custom_head_tags());
|
||||
rv.Tail_tags().Copy(page.Html_data().Custom_tail_tags());
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
22
400_xowa/src/gplx/xowa/drds/powers/Xod_power_mgr.java
Normal file
22
400_xowa/src/gplx/xowa/drds/powers/Xod_power_mgr.java
Normal file
@@ -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.drds.powers; import gplx.*; import gplx.xowa.*; import gplx.xowa.drds.*;
|
||||
public interface Xod_power_mgr {
|
||||
void Wake_lock__get(String name);
|
||||
void Wake_lock__rls(String name);
|
||||
}
|
||||
32
400_xowa/src/gplx/xowa/drds/powers/Xod_power_mgr_.java
Normal file
32
400_xowa/src/gplx/xowa/drds/powers/Xod_power_mgr_.java
Normal file
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.drds.powers; import gplx.*; import gplx.xowa.*; import gplx.xowa.drds.*;
|
||||
public class Xod_power_mgr_ {
|
||||
public static Xod_power_mgr Instance = new Xod_power_mgr__shim();
|
||||
}
|
||||
class Xod_power_mgr__shim implements Xod_power_mgr {
|
||||
// private final Ordered_hash hash = Ordered_hash_.New();
|
||||
public void Wake_lock__get(String name) {
|
||||
// if (hash.Has(name)) {hash.Clear(); throw Err_.new_("itm exists", "name", name);}
|
||||
// hash.Add(name, name);
|
||||
}
|
||||
public void Wake_lock__rls(String name) {
|
||||
// if (!hash.Has(name)) throw Err_.new_("itm missing", "name", name);
|
||||
// hash.Del(name);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user