mirror of
https://github.com/gnosygnu/xowa.git
synced 2026-03-02 03:49:30 +00:00
v2.8.1.1
This commit is contained in:
@@ -17,7 +17,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa; import gplx.*;
|
||||
import gplx.ios.*;
|
||||
import gplx.xowa.apps.*; import gplx.xowa.apps.fsys.*; import gplx.xowa.apis.*;
|
||||
import gplx.xowa.apps.*; import gplx.xowa.apps.fsys.*; import gplx.xowa.apps.metas.*; import gplx.xowa.apis.*;
|
||||
import gplx.xowa.bldrs.css.*;
|
||||
import gplx.xowa.files.caches.*; import gplx.xowa.files.imgs.*;
|
||||
import gplx.xowa.urls.encoders.*;
|
||||
@@ -34,9 +34,11 @@ public interface Xoa_app {
|
||||
Xof_img_mgr File__img_mgr();
|
||||
Io_download_fmt File__download_fmt();
|
||||
Xoh_href_parser Html__href_parser();
|
||||
Xoh_href_wtr Html__href_wtr();
|
||||
Xoh_lnki_bldr Html__lnki_bldr();
|
||||
Xoa_css_extractor Html__css_installer();
|
||||
Xoh_bridge_mgr Html__bridge_mgr();
|
||||
Xoa_meta_mgr Meta_mgr();
|
||||
Xou_user User();
|
||||
Xowmf_mgr Wmf_mgr();
|
||||
boolean Xwiki_mgr__missing(byte[] domain);
|
||||
@@ -44,5 +46,4 @@ public interface Xoa_app {
|
||||
Gfo_usr_dlg Usr_dlg();
|
||||
Bry_bfr_mkr Utl__bfr_mkr();
|
||||
Url_encoder_mgr Utl__encoder_mgr();
|
||||
Xoa_url_parser Utl__url_parser();
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ public class Xoa_app_ {
|
||||
boot_mgr.Run(args);
|
||||
}
|
||||
public static final String Name = "xowa";
|
||||
public static final String Version = "2.7.3.3";
|
||||
public static final String Version = "2.8.1.1";
|
||||
public static String Build_date = "2012-12-30 00:00:00";
|
||||
public static String Op_sys;
|
||||
public static String User_agent = "";
|
||||
|
||||
118
400_xowa/src/gplx/xowa/Xoa_url.java
Normal file
118
400_xowa/src/gplx/xowa/Xoa_url.java
Normal file
@@ -0,0 +1,118 @@
|
||||
/*
|
||||
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; import gplx.*;
|
||||
import gplx.core.net.*; import gplx.xowa.urls.*;
|
||||
import gplx.xowa.html.hrefs.*;
|
||||
public class Xoa_url {
|
||||
public int Tid() {return tid;} private int tid;
|
||||
public byte[] Raw() {return raw;} private byte[] raw = Bry_.Empty;
|
||||
public byte[] Wiki_bry() {return wiki_bry;} public Xoa_url Wiki_bry_(byte[] v) {wiki_bry = v; return this;} private byte[] wiki_bry;
|
||||
public byte[] Page_bry() {return page_bry;} public Xoa_url Page_bry_(byte[] v) {page_bry = v; return this;} private byte[] page_bry;
|
||||
public byte[] Anch_bry() {return anch_bry;} public Xoa_url Anch_bry_(byte[] v) {anch_bry = v; return this;} private byte[] anch_bry;
|
||||
public String Anch_str() {return anch_bry == null ? null : String_.new_u8(anch_bry);}
|
||||
public byte[][] Segs_ary() {return segs_ary;} private byte[][] segs_ary;
|
||||
public Gfo_qarg_itm[] Qargs_ary() {return qargs_ary;} public Xoa_url Qargs_ary_(Gfo_qarg_itm[] v) {qargs_ary = v; return this;} private Gfo_qarg_itm[] qargs_ary = Gfo_qarg_itm.Ary_empty;
|
||||
public Gfo_qarg_mgr Qargs_mgr() {if (qargs_mgr == null) qargs_mgr = new Gfo_qarg_mgr().Load(qargs_ary); return qargs_mgr;} private Gfo_qarg_mgr qargs_mgr;
|
||||
public byte Protocol_tid() {return protocol_tid;} private byte protocol_tid;
|
||||
public byte[] Protocol_bry() {return protocol_bry;} private byte[] protocol_bry;
|
||||
public boolean Protocol_is_relative() {return protocol_is_relative;} private boolean protocol_is_relative;
|
||||
public byte[] Vnt_bry() {return vnt_bry;} private byte[] vnt_bry;
|
||||
public boolean Wiki_is_missing() {return wiki_is_missing;} private boolean wiki_is_missing;
|
||||
public boolean Wiki_is_same() {return wiki_is_same;} private boolean wiki_is_same;
|
||||
public boolean Page_is_main() {return page_is_main;} private boolean page_is_main;
|
||||
public Xoa_url Ctor(int tid, byte[] raw, byte protocol_tid, byte[] protocol_bry, boolean protocol_is_relative
|
||||
, byte[] wiki, byte[] page, Gfo_qarg_itm[] qargs, byte[] anch
|
||||
, byte[][] segs_ary, byte[] vnt_bry, boolean wiki_is_missing, boolean wiki_is_same, boolean page_is_main) {
|
||||
this.tid = tid; this.raw = raw;
|
||||
this.protocol_tid = protocol_tid; this.protocol_bry = protocol_bry; this.protocol_is_relative = protocol_is_relative;
|
||||
this.wiki_bry = wiki; this.page_bry = page; this.qargs_ary = qargs; this.anch_bry = anch;
|
||||
this.segs_ary = segs_ary; this.vnt_bry = vnt_bry;
|
||||
this.wiki_is_missing = wiki_is_missing; this.wiki_is_same = wiki_is_same; this.page_is_main = page_is_main;
|
||||
return this;
|
||||
}
|
||||
public byte[] Page_for_lnki() {
|
||||
int raw_len = raw.length;
|
||||
int page_bgn = Page_bgn(raw_len);
|
||||
if (page_bgn == Bry_.NotFound) // no /wiki/ found; return page
|
||||
return page_bry == null ? Bry_.Empty : page_bry; // guard against null ref
|
||||
else
|
||||
return Bry_.Mid(raw, page_bgn, raw_len);// else take everything after "/wiki/";
|
||||
}
|
||||
private int Page_bgn(int raw_len) {
|
||||
int wiki_pos = Bry_finder.Find_fwd(raw, Xoh_href_.Bry__wiki, 0, raw_len); // look for /wiki/
|
||||
return wiki_pos == Bry_.NotFound ? Bry_.NotFound : wiki_pos + Xoh_href_.Bry__wiki.length;
|
||||
}
|
||||
public boolean Eq_page(Xoa_url comp) {return Bry_.Eq(wiki_bry, comp.wiki_bry) && Bry_.Eq(page_bry, comp.page_bry) && this.Qargs_mgr().Match(Xoa_url_.Qarg__redirect, Xoa_url_.Qarg__redirect__yes) == comp.Qargs_mgr().Match(Xoa_url_.Qarg__redirect, Xoa_url_.Qarg__redirect__yes);}
|
||||
public String To_str() {return String_.new_u8(To_bry(Bool_.Y, Bool_.Y));}
|
||||
public byte[] To_bry_page_w_anch() {
|
||||
byte[] page = page_bry, anch = anch_bry;
|
||||
byte[] anch_spr = anch == null ? null : Byte_ascii.Hash_bry;
|
||||
return Bry_.Add(page, anch_spr, anch);
|
||||
}
|
||||
public byte[] To_bry_full_wo_qargs() {return To_bry(Bool_.Y, Bool_.N);}
|
||||
public byte[] To_bry(boolean full, boolean show_qargs) { // currently used for status bar; not embedded in any html
|
||||
switch (tid) {
|
||||
case Xoa_url_.Tid_unknown: // unknown; should not occur?
|
||||
return Bry_.Len_eq_0(raw) ? Bry_.Add(wiki_bry, Byte_ascii.Slash_bry, page_bry) : raw; // raw is empty when using new_();
|
||||
case Xoa_url_.Tid_inet: // protocol; embed all; EX: "http://a.org/A"; "file:///C/dir/file.txt"
|
||||
case Xoa_url_.Tid_file: // file; EX: "file:///C:/A/B.jpg"
|
||||
return raw;
|
||||
case Xoa_url_.Tid_xcmd: // xcmd; embed page only; EX: "xowa.usr.bookmarks.add"
|
||||
return page_bry;
|
||||
default:
|
||||
throw Err_.new_unhandled(tid);
|
||||
case Xoa_url_.Tid_anch:
|
||||
case Xoa_url_.Tid_page:
|
||||
break;
|
||||
}
|
||||
byte[] wiki = wiki_bry, page = page_bry, anch = anch_bry;
|
||||
byte[] wiki_spr = vnt_bry == null ? Xoh_href_.Bry__wiki : Bry_.Add(Byte_ascii.Slash_bry, vnt_bry, Byte_ascii.Slash_bry);
|
||||
byte[] anch_spr = anch == null ? null : Byte_ascii.Hash_bry;
|
||||
if (!full) {
|
||||
boolean tid_is_anch = tid == Xoa_url_.Tid_anch;
|
||||
if ( wiki_is_same // same wiki; don't show wiki; EX: "/wiki/A" -> "A" x> "en.wikipedia.org/wiki/A"
|
||||
|| tid_is_anch) { // anch never shows wiki; EX: #A
|
||||
wiki = wiki_spr = null; // don't show wiki;
|
||||
}
|
||||
if (tid_is_anch)
|
||||
page = null;
|
||||
}
|
||||
byte[] rv = Bry_.Add
|
||||
( wiki, wiki_spr // add wiki_key; EX: "en.wikipedia.org", "/wiki/"
|
||||
, page // add page; EX: "A"
|
||||
, anch_spr, anch // add anch EX: "#", "B"
|
||||
);
|
||||
if (show_qargs || qargs_ary.length > 0) {
|
||||
Bry_bfr bfr = Xoa_app_.Utl__bfr_mkr().Get_b128();
|
||||
bfr.Add(rv);
|
||||
Gfo_qarg_mgr.Concat_bfr(bfr, Xoa_app_.Utl__encoder_mgr().Href(), qargs_ary);
|
||||
return bfr.To_bry_and_rls();
|
||||
}
|
||||
else
|
||||
return rv;
|
||||
}
|
||||
public static final Xoa_url Null = null;
|
||||
public static Xoa_url blank() {return new Xoa_url();}
|
||||
public static Xoa_url new_(byte[] wiki, byte[] page) {
|
||||
Xoa_url rv = new Xoa_url();
|
||||
rv.Wiki_bry_(wiki);
|
||||
rv.Page_bry_(page);
|
||||
rv.tid = Xoa_url_.Tid_page;
|
||||
return rv;
|
||||
} Xoa_url() {}
|
||||
}
|
||||
33
400_xowa/src/gplx/xowa/Xoa_url_.java
Normal file
33
400_xowa/src/gplx/xowa/Xoa_url_.java
Normal file
@@ -0,0 +1,33 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa; import gplx.*;
|
||||
public class Xoa_url_ {
|
||||
public static final int Tid_unknown = 0, Tid_page = 1, Tid_anch = 2, Tid_inet = 3, Tid_file = 4, Tid_xcmd = 5;
|
||||
public static boolean Tid_is_pagelike(int tid) {
|
||||
switch (tid) {
|
||||
case Tid_page: case Tid_anch: return true;
|
||||
default: return false;
|
||||
}
|
||||
}
|
||||
public static final byte[]
|
||||
Qarg__redirect = Bry_.new_a7("redirect")
|
||||
, Qarg__redirect__yes = Bry_.new_a7("yes")
|
||||
, Qarg__action = Bry_.new_a7("action")
|
||||
, Qarg__action__edit = Bry_.new_a7("edit")
|
||||
;
|
||||
}
|
||||
@@ -17,7 +17,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa; import gplx.*;
|
||||
import gplx.core.btries.*; import gplx.core.flds.*; import gplx.ios.*; import gplx.core.threads.*;
|
||||
import gplx.xowa.apps.*; import gplx.xowa.apps.caches.*; import gplx.xowa.apps.fsys.*; import gplx.xowa.apis.*; import gplx.xowa.urls.encoders.*; import gplx.xowa.apps.progs.*;
|
||||
import gplx.xowa.apps.*; import gplx.xowa.apps.caches.*; import gplx.xowa.apps.fsys.*; import gplx.xowa.apis.*; import gplx.xowa.apps.metas.*; import gplx.xowa.urls.encoders.*; import gplx.xowa.apps.progs.*;
|
||||
import gplx.xowa.langs.*; import gplx.xowa.specials.*; import gplx.xowa.cfgs2.*;
|
||||
import gplx.xowa.bldrs.css.*;
|
||||
import gplx.xowa.files.caches.*; import gplx.xowa.files.imgs.*;
|
||||
@@ -37,6 +37,7 @@ public class Xoae_app implements Xoa_app, GfoInvkAble {
|
||||
cfg_mgr = new Xoa_cfg_mgr(this);
|
||||
api_root = new Xoapi_root(this);
|
||||
user = new Xoue_user(this, user_dir);
|
||||
this.meta_mgr = new Xoa_meta_mgr(this);
|
||||
url_cmd_eval = new Xoa_fsys_eval(fsys_mgr, user.Fsys_mgr());
|
||||
fsys_mgr.Init_by_app(prog_mgr);
|
||||
log_wtr.Log_dir_(user.Fsys_mgr().App_temp_dir().GenSubDir("log"));
|
||||
@@ -45,7 +46,6 @@ public class Xoae_app implements Xoa_app, GfoInvkAble {
|
||||
gui_mgr = new Xoa_gui_mgr(this);
|
||||
bldr = new Xob_bldr(this);
|
||||
file_mgr.Ctor_by_app(this);
|
||||
href_parser = new Xoh_href_parser(Xoa_app_.Utl__encoder_mgr().Href(), utl_url_parser.Url_parser());
|
||||
sanitizer = new Xop_sanitizer(parser_amp_mgr, msg_log);
|
||||
user_mgr = new Xou_user_mgr(this, user);
|
||||
sys_cfg = new Xoa_sys_cfg(this);
|
||||
@@ -61,21 +61,22 @@ public class Xoae_app implements Xoa_app, GfoInvkAble {
|
||||
http_server = new Http_server_mgr(this);
|
||||
cfg_regy = new Xocfg_regy(this);
|
||||
html_mgr = new Xoh_html_mgr(this);
|
||||
this.html__lnki_bldr = new Xoh_lnki_bldr(this, href_parser);
|
||||
this.html__lnki_bldr = new Xoh_lnki_bldr(this, html__href_wtr);
|
||||
}
|
||||
public Xoa_app_type App_type() {return app_type;} private final Xoa_app_type app_type;
|
||||
public Xoa_fsys_mgr Fsys_mgr() {return fsys_mgr;} private final Xoa_fsys_mgr fsys_mgr;
|
||||
public Xof_cache_mgr File__cache_mgr() {return file_mgr.Cache_mgr();}
|
||||
public Xof_img_mgr File__img_mgr() {return file_mgr.Img_mgr();}
|
||||
public Io_download_fmt File__download_fmt() {return wmf_mgr.Download_wkr().Download_xrg().Download_fmt();}
|
||||
public Xoh_href_parser Html__href_parser() {return href_parser;} private Xoh_href_parser href_parser;
|
||||
public Xoh_href_parser Html__href_parser() {return html__href_parser;} private final Xoh_href_parser html__href_parser = new Xoh_href_parser();
|
||||
public Xoh_href_wtr Html__href_wtr() {return html__href_wtr;} private final Xoh_href_wtr html__href_wtr = new Xoh_href_wtr();
|
||||
public Xoh_lnki_bldr Html__lnki_bldr() {return html__lnki_bldr;} private final Xoh_lnki_bldr html__lnki_bldr;
|
||||
public Xoa_css_extractor Html__css_installer() {return html__css_installer;} private final Xoa_css_extractor html__css_installer = new Xoa_css_extractor();
|
||||
public Xoh_bridge_mgr Html__bridge_mgr() {return html__bridge_mgr;} private final Xoh_bridge_mgr html__bridge_mgr = new Xoh_bridge_mgr();
|
||||
public Xowmf_mgr Wmf_mgr() {return wmf_mgr;} private final Xowmf_mgr wmf_mgr = new Xowmf_mgr();
|
||||
public Bry_bfr_mkr Utl__bfr_mkr() {return Xoa_app_.Utl__bfr_mkr();}
|
||||
public Url_encoder_mgr Utl__encoder_mgr() {return Xoa_app_.Utl__encoder_mgr();}
|
||||
public Xoa_url_parser Utl__url_parser() {return utl_url_parser;} private final Xoa_url_parser utl_url_parser = new Xoa_url_parser();
|
||||
public Xoa_meta_mgr Meta_mgr() {return meta_mgr;} private final Xoa_meta_mgr meta_mgr;
|
||||
public boolean Bldr__running() {return bldr__running;} public void Bldr__running_(boolean v) {this.bldr__running = v;} private boolean bldr__running;
|
||||
|
||||
public Xoae_wiki_mgr Wiki_mgr() {return wiki_mgr;} private Xoae_wiki_mgr wiki_mgr;
|
||||
@@ -99,7 +100,6 @@ public class Xoae_app implements Xoa_app, GfoInvkAble {
|
||||
public Xoa_shell Shell() {return shell;} private Xoa_shell shell;
|
||||
public Xoa_thread_mgr Thread_mgr() {return thread_mgr;} private Xoa_thread_mgr thread_mgr = new Xoa_thread_mgr();
|
||||
public Xoa_hive_mgr Hive_mgr() {return hive_mgr;} private Xoa_hive_mgr hive_mgr;
|
||||
public Xoh_href_parser Href_parser() {return href_parser;}
|
||||
public Xop_sanitizer Sanitizer() {return sanitizer;} private Xop_sanitizer sanitizer;
|
||||
public Xop_xatr_parser Xatr_parser() {return xatr_parser;} private Xop_xatr_parser xatr_parser = new Xop_xatr_parser();
|
||||
public Xop_xnde_tag_regy Xnde_tag_regy() {return xnde_tag_regy;} private Xop_xnde_tag_regy xnde_tag_regy = new Xop_xnde_tag_regy();
|
||||
@@ -129,7 +129,7 @@ public class Xoae_app implements Xoa_app, GfoInvkAble {
|
||||
|
||||
public Xosrv_server Tcp_server() {return tcp_server;} private Xosrv_server tcp_server = new Xosrv_server();
|
||||
public Http_server_mgr Http_server() {return http_server;} private Http_server_mgr http_server;
|
||||
public Xop_amp_mgr Parser_amp_mgr() {return parser_amp_mgr;} private Xop_amp_mgr parser_amp_mgr = new Xop_amp_mgr();
|
||||
public Xop_amp_mgr Parser_amp_mgr() {return parser_amp_mgr;} private Xop_amp_mgr parser_amp_mgr = Xop_amp_mgr.I;
|
||||
|
||||
private Xoa_fmtr_mgr fmtr_mgr;
|
||||
public Number_parser Utl_num_parser() {return utl_num_parser;} private Number_parser utl_num_parser = new Number_parser();
|
||||
|
||||
@@ -48,6 +48,7 @@ public class Xoapi_root implements GfoInvkAble {
|
||||
public Xoapi_usr Usr() {return usr_api;} private final Xoapi_usr usr_api = new Xoapi_usr();
|
||||
public Xoapi_special Special() {return special_api;} private final Xoapi_special special_api = new Xoapi_special();
|
||||
public Xoapi_xtns Xtns() {return xtns_api;} private final Xoapi_xtns xtns_api = new Xoapi_xtns();
|
||||
public Xoapi_app_wikis Wikis() {return app_wikis;} private final Xoapi_app_wikis app_wikis = new Xoapi_app_wikis();
|
||||
public String Test_str() {return test_str;} public void Test_str_(String v) {test_str = v;} private String test_str; // TEST
|
||||
private void Exec(String key) {
|
||||
Xog_cmd_itm cmd_itm = app.Gui_mgr().Cmd_mgr().Get_or_null(key);
|
||||
@@ -65,6 +66,7 @@ public class Xoapi_root implements GfoInvkAble {
|
||||
else if (ctx.Match(k, Invk_special)) return special_api;
|
||||
else if (ctx.Match(k, Invk_xtns)) return xtns_api;
|
||||
else if (ctx.Match(k, Invk_exec)) Exec(m.ReadStr("v"));
|
||||
else if (ctx.Match(k, Invk_wikis)) return app_wikis;
|
||||
else if (ctx.Match(k, Invk_test_str)) return test_str;
|
||||
else if (ctx.Match(k, Invk_test_str_)) test_str = m.ReadStr("v");
|
||||
return this;
|
||||
@@ -73,5 +75,6 @@ public class Xoapi_root implements GfoInvkAble {
|
||||
Invk_exec = "exec"
|
||||
, Invk_app = "app", Invk_bldr = "bldr", Invk_nav = "nav", Invk_gui = "gui", Invk_html = "html", Invk_net = "net", Invk_usr = "usr", Invk_special = "special", Invk_xtns = "xtns"
|
||||
, Invk_test_str = "test_str", Invk_test_str_ = "test_str_"
|
||||
, Invk_wikis = "wikis"
|
||||
;
|
||||
}
|
||||
|
||||
29
400_xowa/src/gplx/xowa/apis/xowa/Xoapi_app_wiki.java
Normal file
29
400_xowa/src/gplx/xowa/apis/xowa/Xoapi_app_wiki.java
Normal file
@@ -0,0 +1,29 @@
|
||||
/*
|
||||
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.apis.xowa; import gplx.*; import gplx.xowa.*; import gplx.xowa.apis.*;
|
||||
import gplx.xowa.apis.xowa.wikis.*;
|
||||
public class Xoapi_app_wiki implements GfoInvkAble {
|
||||
public Xoapi_wiki_lang Lang() {return lang;} private final Xoapi_wiki_lang lang = new Xoapi_wiki_lang();
|
||||
public void Subscribe(GfoEvObj sub) {lang.Subscribe(sub);}
|
||||
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
|
||||
if (ctx.Match(k, Invk_lang)) return lang;
|
||||
else return GfoInvkAble_.Rv_unhandled;
|
||||
}
|
||||
private static final String Invk_lang = "lang";
|
||||
public static final Xoapi_app_wiki Dflt = new Xoapi_app_wiki();
|
||||
}
|
||||
34
400_xowa/src/gplx/xowa/apis/xowa/Xoapi_app_wikis.java
Normal file
34
400_xowa/src/gplx/xowa/apis/xowa/Xoapi_app_wikis.java
Normal file
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.apis.xowa; import gplx.*; import gplx.xowa.*; import gplx.xowa.apis.*;
|
||||
public class Xoapi_app_wikis implements GfoInvkAble {
|
||||
private final Ordered_hash hash = Ordered_hash_.new_bry_();
|
||||
public Xoapi_app_wiki Get(byte[] domain) {
|
||||
Xoapi_app_wiki rv = (Xoapi_app_wiki)hash.Get_by(domain);
|
||||
if (rv == null) {
|
||||
rv = new Xoapi_app_wiki();
|
||||
hash.Add(domain, rv);
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
|
||||
if (ctx.Match(k, Invk_get)) return Get(m.ReadBry("v"));
|
||||
else return GfoInvkAble_.Rv_unhandled;
|
||||
}
|
||||
private static final String Invk_get = "get";
|
||||
}
|
||||
@@ -26,7 +26,7 @@ public class Xoapi_url implements GfoInvkAble {
|
||||
public void Exec_new_tab_by_paste() {Exec_wkr(Bool_.Y, ClipboardAdp_.GetText());}
|
||||
public void Restore() {
|
||||
Xog_tab_itm tab = app.Gui_mgr().Browser_win().Active_tab(); if (tab == Xog_tab_itm_.Null) return;
|
||||
this.Url_box().Text_(tab.Page().Url().Xto_full_str());
|
||||
this.Url_box().Text_(tab.Page().Url().To_str());
|
||||
}
|
||||
private void Exec_wkr(boolean new_tab, String urls_text) {
|
||||
if (Op_sys.Cur().Tid_is_wnt())
|
||||
|
||||
@@ -30,7 +30,7 @@ public class Xoapi_selection implements GfoInvkAble {
|
||||
if (this.Active_tab_is_null()) return;
|
||||
Xog_html_itm html_itm = win.Tab_mgr().Active_tab().Html_itm();
|
||||
String src = html_itm.Html_selected_get_src_or_empty();
|
||||
if (String_.Len_eq_0(src)) {app.Usr_dlg().Prog_many("", "", "no file selected: tab=~{0}", html_itm.Owner_tab().Page().Url().Xto_full_str()); return;}
|
||||
if (String_.Len_eq_0(src)) {app.Usr_dlg().Prog_many("", "", "no file selected: tab=~{0}", html_itm.Owner_tab().Page().Url().To_str()); return;}
|
||||
Io_url src_url = Io_url_.http_any_(src, Op_sys.Cur().Tid_is_wnt());
|
||||
String trg_name = src_url.NameAndExt();
|
||||
if (String_.Has(src, "/thumb/")) trg_name = src_url.OwnerDir().NameOnly();
|
||||
|
||||
@@ -27,7 +27,7 @@ public class Xoapi_wiki implements GfoInvkAble {
|
||||
public void Sandbox() {win.Page__navigate_by_url_bar("Project:Sandbox");}
|
||||
public void Main_page() {
|
||||
win.Tab_mgr().Active_tab_assert(); // force an active tab in case all tabs are closed; needed for win.Active_page() below; DATE:2014-09-17
|
||||
win.Page__navigate_by_url_bar(win.Active_tab().Wiki().Domain_str() + Xoh_href_parser.Href_wiki_str); // NOTE: add "/wiki/" to generate non-page like url; EX: "home" -> "home/wiki/" which will be interpreted as a url, as opposed to "home" which will be intrepretted as page; DATE:2014-04-14
|
||||
win.Page__navigate_by_url_bar(win.Active_tab().Wiki().Domain_str() + Xoh_href_.Str__wiki); // NOTE: add "/wiki/" to generate non-page like url; EX: "home" -> "home/wiki/" which will be interpreted as a url, as opposed to "home" which will be intrepretted as page; DATE:2014-04-14
|
||||
}
|
||||
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
|
||||
if (ctx.Match(k, Invk_main_page)) this.Main_page();
|
||||
|
||||
@@ -18,6 +18,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
package gplx.xowa.apis.xowa.usrs; import gplx.*; import gplx.xowa.*; import gplx.xowa.apis.*; import gplx.xowa.apis.xowa.*;
|
||||
import gplx.xowa.gui.history.*; import gplx.xowa.gui.views.*;
|
||||
import gplx.xowa.users.bmks.*;
|
||||
import gplx.xowa.wikis.*;
|
||||
public class Xoapi_bookmarks implements GfoInvkAble {
|
||||
private Xoae_app app; private Xog_win_itm win;
|
||||
public void Ctor_by_app(Xoae_app app) {this.app = app;}
|
||||
@@ -30,20 +31,11 @@ public class Xoapi_bookmarks implements GfoInvkAble {
|
||||
if (!enabled) return app.Html__bridge_mgr().Msg_bldr().To_json_str__empty();
|
||||
Xoa_url url = null;
|
||||
if (url_str == null) {
|
||||
Xog_tab_itm tab = win.Active_tab(); if (tab == Xog_tab_itm_.Null) return app.Html__bridge_mgr().Msg_bldr().Clear().Notify_pass_("bookmark added").To_json_str();
|
||||
Xog_tab_itm tab = win.Active_tab(); if (tab == Xog_tab_itm_.Null) return app.Html__bridge_mgr().Msg_bldr().Clear().Notify_pass_("bookmark added").To_json_str(); // called by http_server; return success
|
||||
url = tab.Page().Url();
|
||||
if (url.Wiki_bry() == null) {
|
||||
url_str = "home/wiki/" + String_.new_u8(url.Page_bry());
|
||||
}
|
||||
else if (url.Page_bry() == null) {
|
||||
url_str = tab.Wiki().Domain_str() + "/wiki/" + String_.new_u8(url.Wiki_bry());
|
||||
}
|
||||
else
|
||||
url_str = String_.new_u8(url.Raw());
|
||||
url = app.Utl__url_parser().Parse(Bry_.new_u8(url_str));
|
||||
}
|
||||
else
|
||||
url = app.Utl__url_parser().Parse(Bry_.new_u8(url_str));
|
||||
url = app.User().Wikii().Utl__url_parser().Parse(Bry_.new_u8(url_str));
|
||||
app.User().User_db_mgr().Bmk_mgr().Itms__add(Xoud_bmk_mgr.Owner_root, url);
|
||||
String msg = "bookmark added: " + String_.new_u8(url.Page_bry());
|
||||
String rv = app.Html__bridge_mgr().Msg_bldr().Clear().Notify_pass_(msg).To_json_str();
|
||||
|
||||
28
400_xowa/src/gplx/xowa/apis/xowa/wikis/Xoapi_wiki_lang.java
Normal file
28
400_xowa/src/gplx/xowa/apis/xowa/wikis/Xoapi_wiki_lang.java
Normal file
@@ -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.apis.xowa.wikis; import gplx.*; import gplx.xowa.*; import gplx.xowa.apis.*; import gplx.xowa.apis.xowa.*;
|
||||
import gplx.xowa.apis.xowa.wikis.langs.*;
|
||||
public class Xoapi_wiki_lang implements GfoInvkAble {
|
||||
public Xoap_lang_variants Variants() {return variants;} private final Xoap_lang_variants variants = new Xoap_lang_variants();
|
||||
public void Subscribe(GfoEvObj sub) {variants.Subscribe(sub);}
|
||||
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
|
||||
if (ctx.Match(k, Invk_variants)) return variants;
|
||||
else return GfoInvkAble_.Rv_unhandled;
|
||||
}
|
||||
private static final String Invk_variants = "variants";
|
||||
}
|
||||
@@ -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.apis.xowa.wikis.langs; import gplx.*; import gplx.xowa.*; import gplx.xowa.apis.*; import gplx.xowa.apis.xowa.*; import gplx.xowa.apis.xowa.wikis.*;
|
||||
public class Xoap_lang_variants implements GfoInvkAble, GfoEvMgrOwner {
|
||||
public Xoap_lang_variants() {
|
||||
this.ev_mgr = GfoEvMgr.new_(this);
|
||||
}
|
||||
public GfoEvMgr EvMgr() {return ev_mgr;} private final GfoEvMgr ev_mgr;
|
||||
public byte[] Current() {return current;} private byte[] current;
|
||||
public void Current_(byte[] v) {
|
||||
this.current = v;
|
||||
GfoEvMgr_.PubVal(this, Evt_current_changed, v);
|
||||
}
|
||||
public void Subscribe(GfoEvObj sub) {
|
||||
GfoEvMgr_.SubSame(this, Evt_current_changed, sub);
|
||||
if (current != null) GfoInvkAble_.InvkCmd_val(sub, Evt_current_changed, current);
|
||||
}
|
||||
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
|
||||
if (ctx.Match(k, Invk_current)) return String_.new_u8(current);
|
||||
else if (ctx.Match(k, Invk_current_)) Current_(m.ReadBry("v"));
|
||||
else return GfoInvkAble_.Rv_unhandled;
|
||||
return this;
|
||||
}
|
||||
private static final String Invk_current = "current", Invk_current_ = "current_";
|
||||
public static final String
|
||||
Evt_current_changed = "current_changed"
|
||||
;
|
||||
}
|
||||
@@ -35,7 +35,7 @@ public class Xoa_app_type {
|
||||
}
|
||||
private static final int Uid_cmd = 1, Uid_gui = 2, Uid_tcp = 3, Uid_http = 4, Uid_file = 5;
|
||||
private static final byte[] Key_cmd = Bry_.new_a7("cmd"), Key_gui = Bry_.new_a7("gui"), Key_tcp = Bry_.new_a7("server"), Key_http = Bry_.new_a7("http_server"), Key_file = Bry_.new_a7("file");
|
||||
private static final Hash_adp_bry type_hash = Hash_adp_bry.cs_()
|
||||
private static final Hash_adp_bry type_hash = Hash_adp_bry.cs()
|
||||
.Add_bry_int(Key_cmd , Uid_cmd)
|
||||
.Add_bry_int(Key_gui , Uid_gui)
|
||||
.Add_bry_int(Key_http , Uid_http)
|
||||
|
||||
@@ -74,7 +74,7 @@ public class Xoa_gfs_php_mgr {
|
||||
)
|
||||
throw Err_.new_wo_type("invalid gfs; num_end not found", "src", String_.new_u8(src));
|
||||
bfr.Add_byte(Byte_ascii.Dollar);
|
||||
int arg_idx = Bry_.Xto_int_or(src, num_bgn, num_end, -1);
|
||||
int arg_idx = Bry_.To_int_or(src, num_bgn, num_end, -1);
|
||||
if (arg_idx == -1) {
|
||||
throw Err_.new_wo_type("invalid int");
|
||||
}
|
||||
@@ -103,7 +103,7 @@ public class Xoa_gfs_php_mgr {
|
||||
break;
|
||||
case Byte_ascii.Dollar:
|
||||
int end_pos = Php_text_itm_parser.Find_fwd_non_int(raw, i + 1, raw_len);
|
||||
int int_val = Bry_.Xto_int_or(raw, i + 1, end_pos, -1);
|
||||
int int_val = Bry_.To_int_or(raw, i + 1, end_pos, -1);
|
||||
bfr.Add_byte(Bry_fmtr.char_escape).Add_byte(Bry_fmtr.char_arg_bgn).Add_int_variable(int_val - 1).Add_byte(Bry_fmtr.char_arg_end);
|
||||
i = end_pos - 1;
|
||||
break;
|
||||
|
||||
@@ -18,7 +18,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
package gplx.xowa.apps.caches; import gplx.*; import gplx.xowa.*; import gplx.xowa.apps.*;
|
||||
import gplx.xowa.xtns.wdatas.*;
|
||||
public class Wdata_doc_cache {
|
||||
private Hash_adp_bry hash = Hash_adp_bry.cs_();
|
||||
private Hash_adp_bry hash = Hash_adp_bry.cs();
|
||||
public void Add(byte[] qid, Wdata_doc doc) {hash.Add(qid, doc);}
|
||||
public Wdata_doc Get_or_null(byte[] qid) {return (Wdata_doc)hash.Get_by_bry(qid);}
|
||||
public void Free_mem_all() {this.Clear();}
|
||||
|
||||
@@ -33,7 +33,7 @@ public class Xoa_fsys_eval implements Bry_fmtr_eval_mgr {
|
||||
}
|
||||
}
|
||||
private static final byte Tid_bin_plat_dir = 0, Tid_user_temp_dir = 1, Tid_xowa_root_dir = 2, Tid_user_cfg_dir = 3;
|
||||
private static final Hash_adp_bry hash = Hash_adp_bry.ci_ascii_()
|
||||
private static final Hash_adp_bry hash = Hash_adp_bry.ci_a7()
|
||||
.Add_str_byte("bin_plat_dir" , Tid_bin_plat_dir)
|
||||
.Add_str_byte("user_temp_dir" , Tid_user_temp_dir)
|
||||
.Add_str_byte("xowa_root_dir" , Tid_xowa_root_dir)
|
||||
|
||||
24
400_xowa/src/gplx/xowa/apps/metas/Xoa_meta_mgr.java
Normal file
24
400_xowa/src/gplx/xowa/apps/metas/Xoa_meta_mgr.java
Normal file
@@ -0,0 +1,24 @@
|
||||
/*
|
||||
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.metas; import gplx.*; import gplx.xowa.*; import gplx.xowa.apps.*;
|
||||
public class Xoa_meta_mgr {
|
||||
public Xoa_meta_mgr(Xoa_app app) {
|
||||
this.ns_mgr = new Xoa_ns_mgr(app);
|
||||
}
|
||||
public Xoa_ns_mgr Ns_mgr() {return ns_mgr;} private final Xoa_ns_mgr ns_mgr;
|
||||
}
|
||||
49
400_xowa/src/gplx/xowa/apps/metas/Xoa_ns_mgr.java
Normal file
49
400_xowa/src/gplx/xowa/apps/metas/Xoa_ns_mgr.java
Normal file
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
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.metas; import gplx.*; import gplx.xowa.*; import gplx.xowa.apps.*;
|
||||
import gplx.dbs.*;
|
||||
import gplx.xowa.langs.cases.*;
|
||||
import gplx.xowa.wmfs.data.*;
|
||||
public class Xoa_ns_mgr {
|
||||
private final Xoa_app app;
|
||||
private final Hash_adp_bry hash = Hash_adp_bry.cs();
|
||||
private Xowmf_site_tbl wmf_site_tbl; private Xowmf_ns_tbl wmf_ns_tbl;
|
||||
public Xoa_ns_mgr(Xoa_app app) {
|
||||
this.app = app;
|
||||
}
|
||||
public void Add(byte[] wiki_domain, Xow_ns_mgr ns_mgr) {hash.Add(wiki_domain, ns_mgr);} // TEST:
|
||||
public Xow_ns_mgr Get_or_load(byte[] wiki_domain) {
|
||||
Xow_ns_mgr rv = (Xow_ns_mgr)hash.Get_by_bry(wiki_domain);
|
||||
if (rv == null) {
|
||||
rv = Load(wiki_domain);
|
||||
Add(wiki_domain, rv);
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
private Xow_ns_mgr Load(byte[] wiki_domain) {
|
||||
Xow_ns_mgr rv = new Xow_ns_mgr(Xol_case_mgr_.U8());
|
||||
if (wmf_site_tbl == null) {
|
||||
Db_conn conn = Xowmf_site_tbl.Get_conn_or_new(app.Fsys_mgr().Root_dir());
|
||||
wmf_site_tbl = new Xowmf_site_tbl(conn);
|
||||
wmf_ns_tbl = new Xowmf_ns_tbl(conn);
|
||||
}
|
||||
int site_id = wmf_site_tbl.Select_id(String_.new_u8(wiki_domain));
|
||||
wmf_ns_tbl.Select_all(rv, site_id);
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
@@ -173,7 +173,7 @@ public abstract class Xob_dump_mgr_base extends Xob_itm_basic_base implements Xo
|
||||
Exec_commit(-1, -1, -1, Bry_.Empty);
|
||||
Exec_end_hook();
|
||||
Free();
|
||||
usr_dlg.Note_many("", "", "done: ~{0} ~{1}", exec_count, DecimalAdp_.divide_safe_(exec_count, Env_.TickCount_elapsed_in_sec(time_bgn)).Xto_str("#,###.000"));
|
||||
usr_dlg.Note_many("", "", "done: ~{0} ~{1}", exec_count, Decimal_adp_.divide_safe_(exec_count, Env_.TickCount_elapsed_in_sec(time_bgn)).To_str("#,###.000"));
|
||||
}
|
||||
private void Free() {
|
||||
ctx.App().Free_mem(true);
|
||||
@@ -294,9 +294,9 @@ class Xob_rate_mgr {
|
||||
}
|
||||
private void Save(int count, long bgn, long end) {
|
||||
int dif = (int)(end - bgn) / 1000;
|
||||
DecimalAdp rate = DecimalAdp_.divide_safe_(count, dif);
|
||||
Decimal_adp rate = Decimal_adp_.divide_safe_(count, dif);
|
||||
save_bfr
|
||||
.Add_str(rate.Xto_str("#,##0.000")).Add_byte_pipe()
|
||||
.Add_str(rate.To_str("#,##0.000")).Add_byte_pipe()
|
||||
.Add_int_variable(count).Add_byte_pipe()
|
||||
.Add_int_variable(dif).Add_byte_nl()
|
||||
;
|
||||
|
||||
@@ -18,6 +18,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
package gplx.xowa.bldrs.cmds.ctgs; import gplx.*; import gplx.xowa.*; import gplx.xowa.bldrs.*; import gplx.xowa.bldrs.cmds.*;
|
||||
import gplx.core.btries.*;
|
||||
class Uca_trie {
|
||||
private final Btrie_slim_mgr trie = Btrie_slim_mgr.cs();
|
||||
public void Init() {
|
||||
Init_itm(1, Bry_.ints_(1,1));
|
||||
Init_itm(2, Bry_.ints_(1,1));
|
||||
@@ -1043,7 +1044,7 @@ Init_itm(1021, Bry_.ints_(91,74,1,5,1,143));
|
||||
Init_itm(1022, Bry_.ints_(91,72,1,5,1,143));
|
||||
Init_itm(1023, Bry_.ints_(91,76,1,5,1,143));
|
||||
Init_itm(1024, Bry_.ints_(92,52,1,134,143,1,143,5));
|
||||
} private Btrie_slim_mgr trie = Btrie_slim_mgr.cs_();
|
||||
}
|
||||
public void Clear() {trie.Clear();}
|
||||
public void Decode(Bry_bfr tmp, byte[] src, int bgn, int end) {
|
||||
int i = bgn;
|
||||
|
||||
@@ -27,7 +27,7 @@ public abstract class Xob_categorylinks_base extends Xob_sql_dump_base implement
|
||||
parser.Fld_cmd_(this).Flds_req_(Fld_cl_from, Fld_cl_to, Fld_cl_timestamp, Fld_cl_collation, Fld_cl_sortkey, Fld_cl_type);
|
||||
}
|
||||
public void Exec(byte[] src, byte[] fld_key, int fld_idx, int fld_bgn, int fld_end, Bry_bfr file_bfr, Sql_file_parser_data data) {
|
||||
if (Bry_.Eq(fld_key, Fld_cl_from)) cur_id = Bry_.Xto_int_or(src, fld_bgn, fld_end, -1);
|
||||
if (Bry_.Eq(fld_key, Fld_cl_from)) cur_id = Bry_.To_int_or(src, fld_bgn, fld_end, -1);
|
||||
else if (Bry_.Eq(fld_key, Fld_cl_to)) cur_ctg = Bry_.Mid(src, fld_bgn, fld_end);
|
||||
else if (Bry_.Eq(fld_key, Fld_cl_collation)) cur_collation_is_uca = Bry_.Has_at_bgn(src, Collation_uca, fld_bgn, fld_end);
|
||||
else if (Bry_.Eq(fld_key, Fld_cl_timestamp)) {
|
||||
|
||||
@@ -29,7 +29,7 @@ public abstract class Xoctg_hiddencat_parser_base extends Xob_sql_dump_base impl
|
||||
}
|
||||
public void Exec(byte[] src, byte[] fld_key, int fld_idx, int fld_bgn, int fld_end, Bry_bfr file_bfr, Sql_file_parser_data data) {
|
||||
switch (fld_idx) {
|
||||
case Fld_id: cur_id = Bry_.Xto_int_or(src, fld_bgn, fld_end, -1); break;
|
||||
case Fld_id: cur_id = Bry_.To_int_or(src, fld_bgn, fld_end, -1); break;
|
||||
case Fld_key: cur_is_hiddencat = Bry_.Eq(Key_hiddencat, src, fld_bgn, fld_end); break;
|
||||
case Fld_val:
|
||||
if (!cur_is_hiddencat) {data.Cancel_row_y_(); return;}
|
||||
|
||||
@@ -38,7 +38,7 @@ class Xob_bin_db_itm {
|
||||
public static Xob_bin_db_itm new_v1(Fsm_bin_fil fil) {
|
||||
byte[] name = Bry_.new_u8(fil.Url_rel()); // EX: "fsdb.bin.0000.sqlite3"
|
||||
int ns_id = 0; // assume v1 dbs are all in main ns
|
||||
int pt_id = Bry_.Xto_int_or(name, 9 , 13, Int_.MinValue); if (pt_id == Int_.MinValue) throw Err_.new_wo_type("bin_db_itm.parse: invalid pt_id", "name", fil.Url_rel(), "conn", fil.Conn().Conn_info().Xto_raw());
|
||||
int pt_id = Bry_.To_int_or(name, 9 , 13, Int_.MinValue); if (pt_id == Int_.MinValue) throw Err_.new_wo_type("bin_db_itm.parse: invalid pt_id", "name", fil.Url_rel(), "conn", fil.Conn().Conn_info().Xto_raw());
|
||||
return new Xob_bin_db_itm(fil.Id(), fil.Url(), ns_id, pt_id);
|
||||
}
|
||||
public static Xob_bin_db_itm new_v2(Fsm_bin_fil fil) {
|
||||
@@ -50,8 +50,8 @@ class Xob_bin_db_itm {
|
||||
int ns_end = Bry_finder.Find_fwd(name, ns_end_tkn, ns_bgn); if (ns_end == Bry_finder.Not_found) throw Err_.new_wo_type("bin_db_itm.parse: invalid ns_end", "name", fil.Url_rel(), "conn", fil.Conn().Conn_info().Xto_raw());
|
||||
int pt_bgn = ns_end + ns_end_tkn_len;
|
||||
int pt_end = Bry_finder.Find_fwd(name, pt_end_tkn, pt_bgn); if (pt_end == Bry_finder.Not_found) throw Err_.new_wo_type("bin_db_itm.parse: invalid pt_end", "name", fil.Url_rel(), "conn", fil.Conn().Conn_info().Xto_raw());
|
||||
int ns_id = Bry_.Xto_int_or(name, ns_bgn, ns_end, Int_.MinValue); if (ns_id == Int_.MinValue) throw Err_.new_wo_type("bin_db_itm.parse: invalid ns_id", "name", fil.Url_rel(), "conn", fil.Conn().Conn_info().Xto_raw());
|
||||
int pt_id = Bry_.Xto_int_or(name, pt_bgn, pt_end, Int_.MinValue); if (pt_id == Int_.MinValue) throw Err_.new_wo_type("bin_db_itm.parse: invalid pt_id", "name", fil.Url_rel(), "conn", fil.Conn().Conn_info().Xto_raw());
|
||||
int ns_id = Bry_.To_int_or(name, ns_bgn, ns_end, Int_.MinValue); if (ns_id == Int_.MinValue) throw Err_.new_wo_type("bin_db_itm.parse: invalid ns_id", "name", fil.Url_rel(), "conn", fil.Conn().Conn_info().Xto_raw());
|
||||
int pt_id = Bry_.To_int_or(name, pt_bgn, pt_end, Int_.MinValue); if (pt_id == Int_.MinValue) throw Err_.new_wo_type("bin_db_itm.parse: invalid pt_id", "name", fil.Url_rel(), "conn", fil.Conn().Conn_info().Xto_raw());
|
||||
return new Xob_bin_db_itm(fil.Id(), fil.Url(), ns_id, pt_id);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -276,7 +276,7 @@ public class Xob_fsdb_make_cmd extends Xob_itm_basic_base implements Xob_cmd {
|
||||
if (exit_after_commit) exit_now = true;
|
||||
}
|
||||
public void Cmd_end() {
|
||||
usr_dlg.Note_many("", "", "fsdb_make.done: count=~{0} rate=~{1}", exec_count, DecimalAdp_.divide_safe_(exec_count, Env_.TickCount_elapsed_in_sec(time_bgn)).Xto_str("#,###.000"));
|
||||
usr_dlg.Note_many("", "", "fsdb_make.done: count=~{0} rate=~{1}", exec_count, Decimal_adp_.divide_safe_(exec_count, Env_.TickCount_elapsed_in_sec(time_bgn)).To_str("#,###.000"));
|
||||
if (src_fsdb_wkr != null) {
|
||||
src_fsdb_wkr.Mnt_mgr().Mnts__get_main().Txn_end(); // NOTE: src_fsdb_wkr will be null if no src db defined
|
||||
}
|
||||
|
||||
@@ -50,10 +50,10 @@ public class Xob_image_cmd extends Xob_itm_dump_base implements Xob_cmd, GfoInvk
|
||||
public void Exec(byte[] src, byte[] fld_key, int fld_idx, int fld_bgn, int fld_end, Bry_bfr file_bfr, Sql_file_parser_data data) {
|
||||
switch (fld_idx) {
|
||||
case Fld_img_name: cur_ttl = Bry_.Mid(src, fld_bgn, fld_end); break;
|
||||
case Fld_img_size: cur_size = Bry_.Xto_int_or(src, fld_bgn, fld_end, -1); break;
|
||||
case Fld_img_width: cur_width = Bry_.Xto_int_or(src, fld_bgn, fld_end, -1); break;
|
||||
case Fld_img_height: cur_height = Bry_.Xto_int_or(src, fld_bgn, fld_end, -1); break;
|
||||
case Fld_img_bits: cur_bits = Bry_.Xto_int_or(src, fld_bgn, fld_end, -1); break;
|
||||
case Fld_img_size: cur_size = Bry_.To_int_or(src, fld_bgn, fld_end, -1); break;
|
||||
case Fld_img_width: cur_width = Bry_.To_int_or(src, fld_bgn, fld_end, -1); break;
|
||||
case Fld_img_height: cur_height = Bry_.To_int_or(src, fld_bgn, fld_end, -1); break;
|
||||
case Fld_img_bits: cur_bits = Bry_.To_int_or(src, fld_bgn, fld_end, -1); break;
|
||||
case Fld_img_media_type: cur_media_type = Bry_.Mid(src, fld_bgn, fld_end); break;
|
||||
case Fld_img_minor_mime: cur_minor_mime = Bry_.Mid(src, fld_bgn, fld_end); break;
|
||||
case Fld_img_timestamp: cur_timestamp = Bry_.Mid(src, fld_bgn, fld_end);
|
||||
|
||||
@@ -19,6 +19,7 @@ package gplx.xowa.bldrs.css; import gplx.*; import gplx.xowa.*; import gplx.xowa
|
||||
import gplx.ios.*; import gplx.xowa.html.*;
|
||||
import gplx.xowa.wikis.*; import gplx.xowa.wikis.data.*;
|
||||
import gplx.xowa.files.downloads.*;
|
||||
import gplx.core.net.*;
|
||||
public class Xoa_css_extractor {
|
||||
public IoEngine_xrg_downloadFil Download_xrg() {return download_xrg;} private IoEngine_xrg_downloadFil download_xrg = Io_mgr.I.DownloadFil_args("", Io_url_.Empty);
|
||||
public Xoa_css_extractor Wiki_domain_(byte[] v) {wiki_domain = v; return this;} private byte[] wiki_domain;
|
||||
@@ -33,6 +34,7 @@ public class Xoa_css_extractor {
|
||||
public Xoa_css_extractor Url_encoder_(Url_encoder v) {url_encoder = v; return this;} private Url_encoder url_encoder;
|
||||
public Xoa_css_extractor Wiki_code_(byte[] v) {this.wiki_code = v; return this;} private byte[] wiki_code = null;
|
||||
private byte[] mainpage_html; private boolean lang_is_ltr = true;
|
||||
private final Gfo_url_parser url_parser = new Gfo_url_parser();
|
||||
public void Init_by_app(Xoae_app app) {
|
||||
this.usr_dlg = app.Usr_dlg();
|
||||
Xof_download_wkr download_wkr = app.Wmf_mgr().Download_wkr();
|
||||
@@ -234,6 +236,7 @@ public class Xoa_css_extractor {
|
||||
int prv_pos = 0;
|
||||
int css_find_bgn_len = Css_find_bgn.length;
|
||||
byte[] protocol_prefix_bry = Bry_.new_u8(protocol_prefix);
|
||||
Gfo_url gfo_url = new Gfo_url();
|
||||
while (true) {
|
||||
int url_bgn = Bry_finder.Find_fwd(raw, Css_find_bgn, prv_pos); if (url_bgn == Bry_.NotFound) break; // nothing left; stop
|
||||
url_bgn += css_find_bgn_len;
|
||||
@@ -241,7 +244,10 @@ public class Xoa_css_extractor {
|
||||
byte[] css_url_bry = Bry_.Mid(raw, url_bgn, url_end);
|
||||
css_url_bry = Bry_.Replace(css_url_bry, Css_amp_find, Css_amp_repl); // & -> &
|
||||
css_url_bry = url_encoder.Decode(css_url_bry); // %2C -> %7C -> |
|
||||
css_url_bry = Bry_.Add(protocol_prefix_bry, css_url_bry);
|
||||
url_parser.Parse(gfo_url, css_url_bry, 0, css_url_bry.length);
|
||||
if ( gfo_url.Protocol_tid() == Gfo_protocol_itm.Tid_relative_1 // if rel url, add protocol_prefix DATE:2015-08-01
|
||||
|| (Env_.Mode_testing() && gfo_url.Protocol_tid() == Gfo_protocol_itm.Tid_unknown)) // TEST:
|
||||
css_url_bry = Bry_.Add(protocol_prefix_bry, css_url_bry);
|
||||
rv.Add(String_.new_u8(css_url_bry));
|
||||
prv_pos = url_end;
|
||||
}
|
||||
|
||||
@@ -39,7 +39,7 @@ public class Xoa_css_img_downloader {
|
||||
int src_len = src.length;
|
||||
int prv_pos = 0;
|
||||
Bry_bfr bfr = Bry_bfr.new_(src_len);
|
||||
Hash_adp img_hash = Hash_adp_bry.cs_();
|
||||
Hash_adp img_hash = Hash_adp_bry.cs();
|
||||
while (true) {
|
||||
int url_pos = Bry_finder.Find_fwd(src, Bry_url, prv_pos);
|
||||
if (url_pos == Bry_.NotFound) {bfr.Add_mid(src, prv_pos, src_len); break;} // no more "url("; exit;
|
||||
|
||||
@@ -49,7 +49,7 @@ class Xob_css_parser {
|
||||
}
|
||||
}
|
||||
private static final byte Tkn_import = 1, Tkn_url = 2;
|
||||
private static final Btrie_slim_mgr tkns_trie = Btrie_slim_mgr.ci_ascii_()
|
||||
private static final Btrie_slim_mgr tkns_trie = Btrie_slim_mgr.ci_a7()
|
||||
.Add_str_byte("@import" , Tkn_import)
|
||||
.Add_str_byte(" url(" , Tkn_url)
|
||||
;
|
||||
|
||||
@@ -76,7 +76,7 @@ class Xob_url_fixer_tkn {
|
||||
private static Btrie_slim_mgr bgn_trie;
|
||||
public static Btrie_slim_mgr Bgn_trie() {
|
||||
if (bgn_trie == null) {
|
||||
bgn_trie = Btrie_slim_mgr.ci_ascii_();
|
||||
bgn_trie = Btrie_slim_mgr.ci_a7();
|
||||
trie_add(bgn_trie, Tid_bgn_slash_1 , "/");
|
||||
trie_add(bgn_trie, Tid_bgn_slash_2 , "//");
|
||||
trie_add(bgn_trie, Tid_bgn_http , "http://");
|
||||
@@ -88,7 +88,7 @@ class Xob_url_fixer_tkn {
|
||||
private static Btrie_slim_mgr mid_trie;
|
||||
public static Btrie_slim_mgr Mid_trie() {
|
||||
if (mid_trie == null) {
|
||||
mid_trie = Btrie_slim_mgr.ci_ascii_();
|
||||
mid_trie = Btrie_slim_mgr.ci_a7();
|
||||
trie_add(mid_trie, Tid_mid_rel_1 , "/../");
|
||||
trie_add(mid_trie, Tid_mid_rel_2 , "/./");
|
||||
trie_add(mid_trie, Tid_mid_slash , "/");
|
||||
|
||||
@@ -20,7 +20,7 @@ import gplx.xowa.wikis.ttls.*;
|
||||
public class Xob_ttl_filter_mgr {
|
||||
private boolean exclude_is_empty = true, include_is_empty = true;
|
||||
private final Xob_ttl_filter_mgr_srl srl = new Xob_ttl_filter_mgr_srl();
|
||||
private Hash_adp_bry exclude_hash = Hash_adp_bry.cs_(), include_hash = Hash_adp_bry.cs_();
|
||||
private Hash_adp_bry exclude_hash = Hash_adp_bry.cs(), include_hash = Hash_adp_bry.cs();
|
||||
public void Clear() {
|
||||
exclude_hash.Clear();
|
||||
include_hash.Clear();
|
||||
|
||||
@@ -37,7 +37,7 @@ public class Xob_ttl_filter_mgr_srl_tst {
|
||||
}
|
||||
class Xob_ttl_filter_mgr_srl_fxt {
|
||||
private final Xob_ttl_filter_mgr_srl mgr = new Xob_ttl_filter_mgr_srl();
|
||||
private final Hash_adp_bry hash = Hash_adp_bry.cs_();
|
||||
private final Hash_adp_bry hash = Hash_adp_bry.cs();
|
||||
public void Clear() {
|
||||
hash.Clear();
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@ class Dg_file {
|
||||
public Dg_rule[] Lines() {return lines;} private final Dg_rule[] lines;
|
||||
}
|
||||
class Dg_rule {// EX: < wikipedia ><-30>
|
||||
private final Hash_adp_bry word_idx_hash = Hash_adp_bry.cs_();
|
||||
private final Hash_adp_bry word_idx_hash = Hash_adp_bry.cs();
|
||||
public Dg_rule(int file_id, int id, int idx, int tid, byte[] key, int score, Dg_word[] words) {
|
||||
this.file_id = file_id;
|
||||
this.id = id; this.idx = idx; this.tid = tid; this.key = key; this.score = score; this.words = words;
|
||||
|
||||
@@ -20,7 +20,7 @@ import gplx.core.primitives.*; import gplx.core.btries.*;
|
||||
import gplx.xowa.bldrs.filters.core.*;
|
||||
public class Dg_match_mgr {
|
||||
private int score_init, score_fail; private boolean log_enabled, case_match;
|
||||
private final Btrie_slim_mgr btrie = Btrie_slim_mgr.cs_();
|
||||
private final Btrie_slim_mgr btrie = Btrie_slim_mgr.cs();
|
||||
private final Ordered_hash rules = Ordered_hash_.new_bry_();
|
||||
private final Ordered_hash rule_group_hash = Ordered_hash_.new_bry_(), rule_tally_hash = Ordered_hash_.new_bry_();
|
||||
private final Dg_parser parser = new Dg_parser();
|
||||
|
||||
@@ -71,7 +71,7 @@ class Dg_parser {
|
||||
if (src[brack_bgn] != Byte_ascii.Lt) {Warn("dg.invalid_line.wrong_term_dlm", rel_path, line_idx, src, line_bgn, line_end); break;}
|
||||
brack_end = Bry_finder.Find_fwd(src, Byte_ascii.Gt, brack_bgn);
|
||||
if (brack_end == Bry_finder.Not_found) {Warn("dg.invalid_line.score not found", rel_path, line_idx, src, line_bgn, line_end); break;}
|
||||
int parse_score = Bry_.Xto_int_or(src, brack_bgn + 1, brack_end, Int_.MinValue);
|
||||
int parse_score = Bry_.To_int_or(src, brack_bgn + 1, brack_end, Int_.MinValue);
|
||||
if (parse_score == Int_.MinValue) {Warn("dg.invalid_line.score is invalid", rel_path, line_idx, src, line_bgn, line_end); break;}
|
||||
score = parse_score;
|
||||
break;
|
||||
|
||||
@@ -331,7 +331,7 @@ public class Xol_mw_lang_parser {
|
||||
, Tid_fallback = 5, Tid_rtl = 6
|
||||
, Tid_separatorTransformTable = 7, Tid_digitTransformTable = 8, Tid_digitGroupingPattern = 9
|
||||
;
|
||||
private static Hash_adp_bry Tid_hash = Hash_adp_bry.cs_()
|
||||
private static Hash_adp_bry Tid_hash = Hash_adp_bry.cs()
|
||||
.Add_str_byte("namespaceNames", Tid_namespaceNames).Add_str_byte("namespaceAliases", Tid_namespaceAliases).Add_str_byte("specialPageAliases", Tid_specialPageAliases)
|
||||
.Add_str_byte("messages", Tid_messages).Add_str_byte("magicWords", Tid_magicwords)
|
||||
.Add_str_byte("fallback", Tid_fallback).Add_str_byte("rtl", Tid_rtl)
|
||||
@@ -340,7 +340,7 @@ public class Xol_mw_lang_parser {
|
||||
;
|
||||
public static int Id_by_mw_name(byte[] src) {
|
||||
if (mw_names == null) {
|
||||
mw_names = Btrie_slim_mgr.cs_();
|
||||
mw_names = Btrie_slim_mgr.cs();
|
||||
mw_names.Add_obj("NS_MEDIA", Int_obj_val.new_(Xow_ns_.Id_media));
|
||||
mw_names.Add_obj("NS_SPECIAL", Int_obj_val.new_(Xow_ns_.Id_special));
|
||||
mw_names.Add_obj("NS_MAIN", Int_obj_val.new_(Xow_ns_.Id_main));
|
||||
|
||||
@@ -18,7 +18,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
package gplx.xowa.bldrs.xmls; import gplx.*; import gplx.xowa.*; import gplx.xowa.bldrs.*;
|
||||
import gplx.gfui.*; import gplx.xowa.bldrs.cmds.utils.*;
|
||||
public class Xob_import_marker {
|
||||
private final Hash_adp_bry in_progress_hash = Hash_adp_bry.cs_();
|
||||
private final Hash_adp_bry in_progress_hash = Hash_adp_bry.cs();
|
||||
public void Bgn(Xowe_wiki wiki) {
|
||||
in_progress_hash.Add_as_key_and_val(wiki.Domain_bry());
|
||||
Io_mgr.I.SaveFilStr(url_(wiki), "XOWA has created this file to indicate that an import is in progress. This file will be deleted once the import is completed.");
|
||||
|
||||
@@ -59,7 +59,7 @@ public class Xob_xml_parser {
|
||||
case Xob_xml_parser_.Id_id_bgn: if (page_id_needed) data_bgn = pos; break; // only flag if first <id>; note that 1st <id> always belongs to <page>;
|
||||
case Xob_xml_parser_.Id_id_end:
|
||||
if (page_id_needed) {
|
||||
int page_id = Bry_.Xto_int_or(src, data_bgn, hook_bgn, -1); if (page_id == -1) usr_dlg.Warn_many(GRP_KEY, "page_id_invalid", "page_id_is_invalid: ~{0}", String_.new_u8(src, data_bgn, hook_bgn));
|
||||
int page_id = Bry_.To_int_or(src, data_bgn, hook_bgn, -1); if (page_id == -1) usr_dlg.Warn_many(GRP_KEY, "page_id_invalid", "page_id_is_invalid: ~{0}", String_.new_u8(src, data_bgn, hook_bgn));
|
||||
rv.Id_(page_id);
|
||||
page_id_needed = false; // turn off for other <id> tags (<contributor>; <revision>)
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@ public class Xob_xml_parser_tst {
|
||||
Io_mgr.I.InitEngine_mem();
|
||||
Xoae_app app = Xoa_app_fxt.app_();
|
||||
bldr = new Xob_bldr(app);
|
||||
} private Xow_ns_mgr ns_mgr = Xow_ns_mgr_.default_(gplx.xowa.langs.cases.Xol_case_mgr_.Ascii());
|
||||
} private Xow_ns_mgr ns_mgr = Xow_ns_mgr_.default_(gplx.xowa.langs.cases.Xol_case_mgr_.A7());
|
||||
@Test public void Basic_docs_1() {
|
||||
Xowd_page_itm doc = doc_(1, "a", "a a", Date_1);
|
||||
fil = page_bldr.Add(doc).XtoByteStreamRdr();
|
||||
|
||||
@@ -43,5 +43,5 @@ public class Xoa_cfg_grp_tid {
|
||||
factory.Add(key, rv);
|
||||
}
|
||||
return rv;
|
||||
} static Hash_adp_bry factory = Hash_adp_bry.cs_();
|
||||
} static Hash_adp_bry factory = Hash_adp_bry.cs();
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.ctgs; import gplx.*; import gplx.xowa.*;
|
||||
public class Xoctg_data_cache {
|
||||
private Hash_adp_bry regy = Hash_adp_bry.cs_(); // NOTE: changed to cs from ci; cache is hashing page_ttls by ctg_name which is always ttl.Page_txt(); DATE:2014-07-07
|
||||
private Hash_adp_bry regy = Hash_adp_bry.cs(); // NOTE: changed to cs from ci; cache is hashing page_ttls by ctg_name which is always ttl.Page_txt(); DATE:2014-07-07
|
||||
public Xoctg_data_ctg Get_or_null(byte[] ctg_name) {return (Xoctg_data_ctg)regy.Get_by_bry(ctg_name);}
|
||||
public Xoctg_data_ctg Load_or_null(Xowe_wiki wiki, byte[] ctg_name) {
|
||||
Gfo_usr_dlg usr_dlg = wiki.Appe().Usr_dlg();
|
||||
|
||||
@@ -116,7 +116,7 @@ class Xoctg_fmtr_all {
|
||||
private void Html_nav_bry(Bry_bfr bfr, Xowe_wiki wiki, Xoa_ttl ttl, Xoctg_view_grp view_grp, boolean fill_at_bgn) {
|
||||
Bry_bfr href_bfr = wiki.Utl__bfr_mkr().Get_b512();
|
||||
Xoae_app app = wiki.Appe();
|
||||
app.Href_parser().Build_to_bfr(href_bfr, app, wiki.Domain_bry(), ttl);
|
||||
app.Html__href_wtr().Build_to_bfr(href_bfr, app, wiki.Domain_bry(), ttl);
|
||||
byte[] arg_idx_lbl = null; byte[] arg_sortkey = null;
|
||||
if (fill_at_bgn) {
|
||||
arg_idx_lbl = url_arg_bgn;
|
||||
|
||||
@@ -21,7 +21,7 @@ import gplx.xowa.users.history.*;
|
||||
abstract class Xoctg_fmtr_itm_base implements Xoctg_fmtr_itm {
|
||||
public void Init_from_all(Xowe_wiki wiki, Xol_lang lang, Xoctg_view_ctg ctg, Xoctg_fmtr_all mgr, Xoctg_view_grp itms_list, int itms_list_len) {
|
||||
this.wiki = wiki; this.lang = lang; this.ctg = ctg; this.list = itms_list; this.len = itms_list_len; this.msg_mgr = wiki.Msg_mgr();
|
||||
href_parser = wiki.Appe().Href_parser();
|
||||
href_parser = wiki.Appe().Html__href_parser();
|
||||
html_itm = mgr.Html_itm();
|
||||
html_itm_missing = mgr.Html_itm_missing();
|
||||
history_mgr = wiki.Appe().Usere().History_mgr();
|
||||
@@ -58,7 +58,7 @@ abstract class Xoctg_fmtr_itm_base implements Xoctg_fmtr_itm {
|
||||
grp_end_at_col = true;
|
||||
}
|
||||
@gplx.Virtual public void Bld_html(Bry_bfr bfr, Xowe_wiki wiki, Xoctg_view_itm itm, Xoa_ttl ttl, byte[] ttl_page, Xoh_href_parser href_parser, Bry_fmtr html_itm) {
|
||||
byte[] itm_href = href_parser.Build_to_bry(wiki, ttl);
|
||||
byte[] itm_href = wiki.App().Html__href_wtr().Build_to_bry(wiki, ttl);
|
||||
byte[] itm_full_ttl = ttl.Full_txt();// NOTE: ttl.Full_txt() to get full ns; EX: Template:A instead of just "A"
|
||||
byte[] itm_atr_cls = Xoh_lnki_wtr.Lnki_cls_visited(history_mgr, wiki.Domain_bry(), ttl.Page_txt()); // NOTE: must be ttl.Page_txt() in order to match Xou_history_mgr.Add
|
||||
Bry_fmtr fmtr = itm.Id_missing() ? html_itm_missing : html_itm;
|
||||
@@ -94,7 +94,7 @@ class Xoctg_fmtr_itm_file extends Xoctg_fmtr_itm_base {
|
||||
}
|
||||
class Xoctg_fmtr_itm_subc extends Xoctg_fmtr_itm_base {
|
||||
@Override public void Bld_html(Bry_bfr bfr, Xowe_wiki wiki, Xoctg_view_itm itm, Xoa_ttl ttl, byte[] ttl_page, Xoh_href_parser href_parser, Bry_fmtr html_itm) {
|
||||
byte[] itm_href = href_parser.Build_to_bry(wiki, ttl);
|
||||
byte[] itm_href = wiki.App().Html__href_wtr().Build_to_bry(wiki, ttl);
|
||||
int sub_ctgs = itm.Subs_ctgs();
|
||||
int sub_pages = itm.Subs_pages();
|
||||
int sub_files = itm.Subs_files();
|
||||
|
||||
@@ -19,11 +19,12 @@ package gplx.xowa.ctgs; import gplx.*; import gplx.xowa.*;
|
||||
import gplx.xowa.html.*; import gplx.xowa.html.hrefs.*; import gplx.xowa.html.lnkis.*; import gplx.xowa.wikis.data.tbls.*;
|
||||
import gplx.xowa.users.history.*;
|
||||
public class Xoctg_pagelist_itms implements Bry_fmtr_arg {
|
||||
private Xoh_href_wtr href_wtr; private Xou_history_mgr history_mgr; private Bry_fmtr fmtr_itm;
|
||||
public void Init_app(Xoae_app app, Bry_fmtr fmtr_itm) {
|
||||
this.href_parser = app.Href_parser();
|
||||
this.href_wtr = app.Html__href_wtr();
|
||||
this.history_mgr = app.Usere().History_mgr();
|
||||
this.fmtr_itm = fmtr_itm;
|
||||
} private Xoh_href_parser href_parser; private Xou_history_mgr history_mgr; private Bry_fmtr fmtr_itm;
|
||||
}
|
||||
public void Init_wiki(Xowe_wiki wiki) {this.wiki = wiki;} private Xowe_wiki wiki;
|
||||
public void Itms_clear() {itms.Clear();} private List_adp itms = List_adp_.new_();
|
||||
public void Itms_add(Xowd_page_itm page) {itms.Add(page);}
|
||||
@@ -33,7 +34,7 @@ public class Xoctg_pagelist_itms implements Bry_fmtr_arg {
|
||||
Xowd_page_itm page = (Xowd_page_itm)itms.Get_at(i);
|
||||
Xoa_ttl ttl = Xoa_ttl.parse_(wiki, Xow_ns_.Id_category, page.Ttl_page_db());
|
||||
byte[] lnki_cls = Xoh_lnki_wtr.Lnki_cls_visited(history_mgr, wiki.Domain_bry(), ttl.Page_txt()); // NOTE: must be ttl.Page_txt() in order to match Xou_history_mgr.Add
|
||||
byte[] lnki_href = href_parser.Build_to_bry(wiki, ttl);
|
||||
byte[] lnki_href = href_wtr.Build_to_bry(wiki, ttl);
|
||||
byte[] lnki_ttl = ttl.Full_txt();
|
||||
byte[] lnki_text = ttl.Page_txt();
|
||||
fmtr_itm.Bld_bfr_many(bfr, lnki_cls, lnki_href, lnki_ttl, lnki_text);
|
||||
|
||||
@@ -16,7 +16,7 @@ You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.ctgs; import gplx.*; import gplx.xowa.*;
|
||||
import gplx.core.primitives.*;
|
||||
import gplx.core.primitives.*; import gplx.core.net.*;
|
||||
public class Xoctg_url {
|
||||
public byte[][] Grp_idxs() {return grp_idxs;} private byte[][] grp_idxs = new byte[3][];
|
||||
public byte[] Grp_fwds() {return grp_fwds;} private byte[] grp_fwds = new byte[3];
|
||||
@@ -28,10 +28,10 @@ public class Xoctg_url {
|
||||
}
|
||||
public Xoctg_url Parse(Gfo_usr_dlg usr_dlg, Xoa_url url) {
|
||||
this.Clear();
|
||||
Gfo_url_arg[] args = url.Args();
|
||||
Gfo_qarg_itm[] args = url.Qargs_ary();
|
||||
int len = args.length;
|
||||
for (int i = 0; i < len; i++) {
|
||||
Gfo_url_arg arg = args[i];
|
||||
Gfo_qarg_itm arg = args[i];
|
||||
byte[] arg_key = arg.Key_bry();
|
||||
Object tid_obj = Arg_keys.Get_by_bry(arg_key);
|
||||
if (tid_obj == null) {usr_dlg.Warn_many("", "", "unknown arg_key: ~{0}", String_.new_u8(arg_key)); continue;} // ignore invalid args
|
||||
@@ -59,7 +59,7 @@ public class Xoctg_url {
|
||||
}
|
||||
}
|
||||
public static final byte Tid_all_bgn = 0, Tid_subc_bgn = 1, Tid_subc_end = 2, Tid_file_bgn = 3, Tid_file_end = 4, Tid_page_bgn = 5, Tid_page_end = 6, Tid_all_end = 8;
|
||||
public static final Hash_adp_bry Arg_keys = Hash_adp_bry.ci_ascii_()
|
||||
public static final Hash_adp_bry Arg_keys = Hash_adp_bry.ci_a7()
|
||||
.Add_bry_byte(Xoctg_fmtr_all.Url_arg_from, Tid_all_bgn)
|
||||
.Add_bry_byte(Xoctg_fmtr_all.Url_arg_until, Tid_all_end)
|
||||
.Add_bry_byte(Xoctg_fmtr_all.Url_arg_subc_bgn, Tid_subc_bgn)
|
||||
|
||||
@@ -16,7 +16,7 @@ You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.ctgs; import gplx.*; import gplx.xowa.*;
|
||||
import org.junit.*;
|
||||
import org.junit.*; import gplx.xowa.urls.*;
|
||||
public class Xoctg_url_tst {
|
||||
@Before public void init() {fxt.Clear();} private Xoctg_url_fxt fxt = new Xoctg_url_fxt();
|
||||
@Test public void Basic() {
|
||||
@@ -30,14 +30,15 @@ class Xoctg_url_fxt {
|
||||
public Xoctg_url_chkr url() {return expd.Clear();} private Xoctg_url_chkr expd;
|
||||
public void Clear() {
|
||||
if (parser == null) {
|
||||
parser = new Xoa_url_parser();
|
||||
page_url = Xoa_url.blank_();
|
||||
Xoa_app app = Xoa_app_fxt.app_();
|
||||
parser = app.User().Wikii().Utl__url_parser();
|
||||
page_url = Xoa_url.blank();
|
||||
ctg_url = new Xoctg_url();
|
||||
expd = new Xoctg_url_chkr();
|
||||
}
|
||||
} private Xoa_url_parser parser; Xoa_url page_url; Xoctg_url ctg_url;
|
||||
public void Test_parse(String url_str, Xoctg_url_chkr expd) {
|
||||
parser.Parse(page_url, Bry_.new_u8(url_str));
|
||||
page_url = parser.Parse(Bry_.new_u8(url_str));
|
||||
ctg_url.Parse(Gfo_usr_dlg_.Test(), page_url);
|
||||
expd.Chk(ctg_url);
|
||||
expd.Clear();
|
||||
|
||||
@@ -498,7 +498,7 @@ public class Xodb_load_mgr_txt implements Xodb_load_mgr {
|
||||
if (pids_root == null)
|
||||
pids_root = wiki.Appe().Wiki_mgr().Wdata_mgr().Wdata_wiki().Tdb_fsys_mgr().Site_dir().GenSubDir_nest("data", "pid");
|
||||
Xob_xdat_itm pid_itm = Load_xdat_itm_by_dir(pids_root.GenSubDir(String_.new_u8(lang_key)), pid_name); if (pid_itm == null) return gplx.xowa.xtns.wdatas.Wdata_wiki_mgr.Pid_null;
|
||||
return Bry_.Xto_int_or(pid_itm.Src(), pid_itm.Itm_bgn() + pid_name.length + 1 + 1, pid_itm.Itm_end(), gplx.xowa.xtns.wdatas.Wdata_wiki_mgr.Pid_null); // extract pid; note that all itms have format of "ttl|pid"; +1=skip pipe; +1 skip p
|
||||
return Bry_.To_int_or(pid_itm.Src(), pid_itm.Itm_bgn() + pid_name.length + 1 + 1, pid_itm.Itm_end(), gplx.xowa.xtns.wdatas.Wdata_wiki_mgr.Pid_null); // extract pid; note that all itms have format of "ttl|pid"; +1=skip pipe; +1 skip p
|
||||
} Io_url pids_root;
|
||||
public int Load_ctg_count(byte[] ttl) {return wiki.Db_mgr().Category_version() == Xoa_ctg_mgr.Version_1 ? Load_ctg_count_v1(ttl) : Load_ctg_count_v2(ttl);}
|
||||
int Load_ctg_count_v1(byte[] ttl) {
|
||||
|
||||
@@ -50,7 +50,7 @@ public class Xof_ext_ {
|
||||
};
|
||||
private static final Hash_adp id_hash = id_hash_new_();
|
||||
private static Hash_adp id_hash_new_() {
|
||||
Hash_adp rv = Hash_adp_bry.cs_();
|
||||
Hash_adp rv = Hash_adp_bry.cs();
|
||||
id_hash_new_(rv, Bry_png, Id_png); id_hash_new_(rv, Bry_jpg, Id_jpg); id_hash_new_(rv, Bry_jpeg, Id_jpeg);
|
||||
id_hash_new_(rv, Bry_gif, Id_gif); id_hash_new_(rv, Bry_tif, Id_tif); id_hash_new_(rv, Bry_tiff, Id_tiff);
|
||||
id_hash_new_(rv, Bry_svg, Id_svg); id_hash_new_(rv, Bry_djvu, Id_djvu); id_hash_new_(rv, Bry_pdf, Id_pdf);
|
||||
@@ -61,7 +61,7 @@ public class Xof_ext_ {
|
||||
}
|
||||
private static void id_hash_new_(Hash_adp hash, byte[] key, int val) {hash.Add(key, Int_obj_val.new_(val));}
|
||||
|
||||
private static final Hash_adp_bry ext_hash = Hash_adp_bry.ci_ascii_()
|
||||
private static final Hash_adp_bry ext_hash = Hash_adp_bry.ci_a7()
|
||||
.Add_bry_bry(Bry_png).Add_bry_bry(Bry_jpg).Add_bry_bry(Bry_jpeg)
|
||||
.Add_bry_bry(Bry_gif).Add_bry_bry(Bry_tif).Add_bry_bry(Bry_tiff)
|
||||
.Add_bry_bry(Bry_svg).Add_bry_bry(Bry_djvu).Add_bry_bry(Bry_pdf)
|
||||
@@ -82,7 +82,7 @@ public class Xof_ext_ {
|
||||
public static Xof_ext new_by_ttl_(byte[] ttl) {
|
||||
int ttl_len = ttl.length;
|
||||
int dot_pos = Bry_finder.Find_bwd(ttl, Byte_ascii.Dot);
|
||||
byte[] ext = (dot_pos == Bry_.NotFound || dot_pos == ttl_len) ? Bry_.Empty : Bry_.Xto_str_lower(ttl, dot_pos + 1, ttl_len); // +1 to bgn after .
|
||||
byte[] ext = (dot_pos == Bry_.NotFound || dot_pos == ttl_len) ? Bry_.Empty : Bry_.Lcase__all(ttl, dot_pos + 1, ttl_len); // +1 to bgn after .
|
||||
return new_(Get_id_by_ext_(ext), ext);
|
||||
}
|
||||
public static Xof_ext new_by_ext_(byte[] ext) {return new_(Get_id_by_ext_(ext), ext);}
|
||||
|
||||
@@ -29,7 +29,7 @@ public class Xof_mime_minor_ {
|
||||
, Mime_bmp = Bry_.new_a7("x-bmp"), Mime_bmp_2 = Bry_.new_a7("x-ms-bmp");
|
||||
private static final Hash_adp mime_hash = mime_hash_();
|
||||
private static Hash_adp mime_hash_() {
|
||||
Hash_adp rv = Hash_adp_bry.cs_();
|
||||
Hash_adp rv = Hash_adp_bry.cs();
|
||||
mime_hash_itm_(rv, Xof_ext_.Bry_png , Xof_ext_.Id_png);
|
||||
mime_hash_itm_(rv, Xof_ext_.Bry_jpg , Xof_ext_.Id_jpg);
|
||||
mime_hash_itm_(rv, Xof_ext_.Bry_jpeg , Xof_ext_.Id_jpeg);
|
||||
|
||||
@@ -18,7 +18,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
package gplx.xowa.files.exts; import gplx.*; import gplx.xowa.*; import gplx.xowa.files.*;
|
||||
import gplx.core.primitives.*;
|
||||
public class Xof_rule_grp implements GfoInvkAble {
|
||||
private final Hash_adp_bry hash = Hash_adp_bry.cs_();
|
||||
private final Hash_adp_bry hash = Hash_adp_bry.cs();
|
||||
public Xof_rule_grp(Xof_rule_mgr owner, byte[] key) {this.owner = owner; this.key = key;}
|
||||
public Xof_rule_mgr Owner() {return owner;} private final Xof_rule_mgr owner;
|
||||
public byte[] Key() {return key;} private final byte[] key;
|
||||
|
||||
@@ -18,7 +18,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
package gplx.xowa.files.exts; import gplx.*; import gplx.xowa.*; import gplx.xowa.files.*;
|
||||
import gplx.xowa.apps.*;
|
||||
public class Xof_rule_mgr implements GfoInvkAble {
|
||||
private final Hash_adp_bry hash = Hash_adp_bry.cs_();
|
||||
private final Hash_adp_bry hash = Hash_adp_bry.cs();
|
||||
public Xof_rule_mgr() {
|
||||
Xof_rule_grp app_default = new Xof_rule_grp(this, Xof_rule_grp.Grp_app_default);
|
||||
Set_app_default(app_default, Io_mgr.Len_gb, Xof_ext_.Bry__ary);
|
||||
|
||||
@@ -104,7 +104,7 @@ class Fs_root_dir {
|
||||
public static byte[] Xto_fil_bry(Io_url url) {
|
||||
byte[] rv = Bry_.new_u8(url.NameAndExt());
|
||||
rv = Bry_.Replace(rv, Byte_ascii.Space, Byte_ascii.Underline);
|
||||
rv = Bry_.Upper_1st(rv);
|
||||
rv = Bry_.Ucase__1st(rv);
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,7 +27,7 @@ public class Xog_history_mgr {
|
||||
if (itm == Xog_history_itm.Null) return Xoae_page.Empty;
|
||||
Xoae_page rv = Get_or_fetch(wiki, itm);
|
||||
byte[] anch_key = itm.Anch();
|
||||
rv.Url().Anchor_bry_(anch_key); // must override anchor as it may be different for cached page
|
||||
rv.Url().Anch_bry_(anch_key); // must override anchor as it may be different for cached page
|
||||
rv.Html_data().Bmk_pos_(itm.Bmk_pos());
|
||||
return rv;
|
||||
}
|
||||
@@ -62,14 +62,14 @@ public class Xog_history_mgr {
|
||||
Xoa_ttl ttl = Xoa_ttl.parse_(wiki, itm.Page());
|
||||
return wiki.Data_mgr().Get_page(ttl, false);
|
||||
}
|
||||
private static byte[] Build_page_key(Xoae_page page) {return Build_page_key(page.Wiki().Domain_bry(), page.Ttl().Full_url(), page.Url().Args_all_as_bry());}
|
||||
private static byte[] Build_page_key(Xoae_page page) {return Build_page_key(page.Wiki().Domain_bry(), page.Ttl().Full_url(), page.Url().Qargs_mgr().To_bry());}
|
||||
private static byte[] Build_page_key(byte[] wiki_key, byte[] page_key, byte[] args_key) {return Bry_.Add_w_dlm(Byte_ascii.Pipe, wiki_key, page_key, args_key);}
|
||||
public static Xog_history_itm new_(Xoae_page pg) {
|
||||
byte[] wiki = pg.Wiki().Domain_bry();
|
||||
byte[] page = pg.Ttl().Full_url(); // get page_name only (no anchor; no query args)
|
||||
byte[] anch = pg.Url().Anchor_bry();
|
||||
byte[] qarg = pg.Url().Args_all_as_bry();
|
||||
boolean redirect_force = pg.Url().Redirect_force();
|
||||
byte[] anch = pg.Url().Anch_bry();
|
||||
byte[] qarg = pg.Url().Qargs_mgr().To_bry();
|
||||
boolean redirect_force = pg.Url().Qargs_mgr().Match(Xoa_url_.Qarg__redirect, Xoa_url_.Qarg__redirect__yes);
|
||||
String bmk_pos = pg.Html_data().Bmk_pos();
|
||||
if (bmk_pos == null) bmk_pos = Xog_history_itm.Html_doc_pos_toc; // never allow null doc_pos; set to top
|
||||
return new Xog_history_itm(wiki, page, anch, qarg, redirect_force, bmk_pos);
|
||||
|
||||
@@ -44,10 +44,9 @@ class Xog_history_stack_fxt {
|
||||
if (app == null) {
|
||||
app = Xoa_app_fxt.app_();
|
||||
wiki = Xoa_app_fxt.wiki_tst_(app);
|
||||
url_parser = app.Utl__url_parser();
|
||||
}
|
||||
return this;
|
||||
} private Xoae_app app; private Xowe_wiki wiki; private Xog_history_stack stack = new Xog_history_stack(); private Xoa_url_parser url_parser;
|
||||
} private Xoae_app app; private Xowe_wiki wiki; private Xog_history_stack stack = new Xog_history_stack();
|
||||
public Xog_history_stack_fxt Test_cur(String expd) {
|
||||
Xog_history_itm page = stack.Cur_itm();
|
||||
String actl = page == null ? null : String_.new_u8(page.Page());
|
||||
@@ -75,8 +74,8 @@ class Xog_history_stack_fxt {
|
||||
Xoa_ttl ttl = Xoa_ttl.parse_(wiki, ttl_bry);
|
||||
Xoae_page page = Xoae_page.test_(wiki, ttl);
|
||||
byte[] url_bry = ttl_bry;
|
||||
if (arg_str != null) url_bry = Bry_.Add(url_bry, Bry_.new_u8(arg_str));
|
||||
Xoa_url url = url_parser.Parse(url_bry);
|
||||
if (arg_str != null) url_bry = Bry_.Add(url_bry, Bry_.new_u8(arg_str));
|
||||
Xoa_url url = app.User().Wikii().Utl__url_parser().Parse(url_bry);
|
||||
page.Url_(url); // set url b/c history_mgr.Add uses url
|
||||
stack.Add(Xog_history_mgr.new_(page));
|
||||
return this;
|
||||
|
||||
@@ -16,59 +16,58 @@ 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.gui.urls; import gplx.*; import gplx.xowa.*; import gplx.xowa.gui.*;
|
||||
import gplx.core.net.*;
|
||||
import gplx.xowa.files.*; import gplx.xowa.files.repos.*; import gplx.xowa.files.origs.*;
|
||||
import gplx.xowa.html.hrefs.*;
|
||||
import gplx.xowa.gui.views.*;
|
||||
public class Xog_url_wkr {
|
||||
private Xoh_href href = new Xoh_href();
|
||||
private final Xoa_url tmp_url = Xoa_url.blank();
|
||||
private Xoae_app app; private Xog_win_itm win; private Xowe_wiki wiki; private Xoae_page page;
|
||||
private final Xof_img_size img_size = new Xof_img_size(); private final Xof_url_bldr url_bldr = Xof_url_bldr.new_v2();
|
||||
public byte Href_tid() {return href.Tid();}
|
||||
public Xog_url_wkr Parse(Xog_win_itm win, String href_str) {
|
||||
if (href_str == null) return this; // text is not link; return;
|
||||
byte[] href_bry = Bry_.new_u8(href_str);
|
||||
this.win = win; this.app = win.App();
|
||||
this.page = win.Active_page();
|
||||
this.wiki = win.Active_tab().Wiki();
|
||||
app.Href_parser().Parse(href, href_bry, wiki, page.Ttl().Page_url());
|
||||
app.Html__href_parser().Parse_as_url(tmp_url, href_bry, wiki, page.Ttl().Page_url());
|
||||
return this;
|
||||
}
|
||||
public Xoa_url Exec() {
|
||||
byte[] href_bry = href.Raw();
|
||||
switch (href.Tid()) {
|
||||
case Xoh_href.Tid_null: return Rslt_handled; // url is invalid; return handled (which effectively ignores)
|
||||
case Xoh_href.Tid_xowa: return Exec_url_xowa(app); // xowa:app.version
|
||||
case Xoh_href.Tid_http: return Exec_url_http(app); // http://site.org
|
||||
case Xoh_href.Tid_anchor: return Exec_url_anchor(win); // #anchor
|
||||
case Xoh_href.Tid_xcmd: return Exec_url_xcmd(win); // /xcmd/app.version
|
||||
case Xoh_href.Tid_file: return Exec_url_file(app, wiki, page, win, href_bry); // file:///xowa/A.png
|
||||
default: return Exec_url_page(app, wiki, page, win, href_bry); // Page /wiki/Page
|
||||
switch (tmp_url.Tid()) {
|
||||
case Xoa_url_.Tid_unknown: return Xoa_url.Null; // unknown; return null which will become a noop
|
||||
case Xoa_url_.Tid_inet: return Exec_url_http(app); // http://site.org
|
||||
case Xoa_url_.Tid_anch: return Exec_url_anchor(win); // #anchor
|
||||
case Xoa_url_.Tid_xcmd: return Exec_url_xowa(app); // xowa:app.version or /xcmd/app.version
|
||||
case Xoa_url_.Tid_file: return Exec_url_file(app, wiki, page, win, tmp_url.Raw()); // file:///xowa/A.png
|
||||
case Xoa_url_.Tid_page: return Exec_url_page(app, wiki, page, win, tmp_url.Raw()); // Page /wiki/Page
|
||||
default: throw Err_.new_unhandled(tmp_url.Tid());
|
||||
}
|
||||
}
|
||||
private Xoa_url Exec_url_xowa(Xoae_app app) { // EX: xowa:app.version
|
||||
// NOTE: must catch exception else it will bubble to SWT browser and raise secondary exception of xowa is not a registered protocol
|
||||
try {app.Gfs_mgr().Run_str(String_.new_u8(href.Page()));}
|
||||
try {app.Gfs_mgr().Run_str(String_.new_u8(tmp_url.Page_bry()));}
|
||||
catch (Exception e) {app.Gui_mgr().Kit().Ask_ok("", "", Err_.Message_gplx_full(e));}
|
||||
return Rslt_handled;
|
||||
}
|
||||
private Xoa_url Exec_url_http(Xoae_app app) { // EX: http:a.org
|
||||
app.Prog_mgr().Exec_view_web(href.Raw());
|
||||
// private Xoa_url Exec_url_xcmd(Xog_win_itm win) { // EX: /xcmd/
|
||||
// byte[] xowa_href_bry = tmp_url.Page();
|
||||
// int xowa_href_bry_len = xowa_href_bry.length;
|
||||
// int slash_pos = Bry_finder.Find_fwd(xowa_href_bry, Byte_ascii.Slash); if (slash_pos == Bry_.NotFound) slash_pos = xowa_href_bry_len;
|
||||
// byte[] xowa_cmd_bry = Bry_.Mid(xowa_href_bry, 0, slash_pos);
|
||||
// String xowa_cmd_str = String_.new_u8(xowa_cmd_bry);
|
||||
// GfoMsg m = GfoMsg_.new_cast_(xowa_cmd_str);
|
||||
// if (String_.Eq(xowa_cmd_str, Xog_win_itm.Invk_eval))
|
||||
// m.Add("cmd", String_.new_u8(xowa_href_bry, slash_pos + 1, xowa_href_bry_len));
|
||||
// win.Invk(GfsCtx.new_(), 0, xowa_cmd_str, m);
|
||||
// return Rslt_handled;
|
||||
// }
|
||||
private Xoa_url Exec_url_http(Xoae_app app) { // EX: http://a.org
|
||||
app.Prog_mgr().Exec_view_web(tmp_url.Raw());
|
||||
return Rslt_handled;
|
||||
}
|
||||
private Xoa_url Exec_url_anchor(Xog_win_itm win) { // EX: #anchor
|
||||
win.Active_html_itm().Scroll_page_by_id_gui(String_.new_u8(href.Anchor())); // NOTE: was originally directly; changed to call on thread; DATE:2014-05-03
|
||||
return Rslt_handled;
|
||||
}
|
||||
private Xoa_url Exec_url_xcmd(Xog_win_itm win) { // EX: /xcmd/
|
||||
byte[] xowa_href_bry = href.Page();
|
||||
int xowa_href_bry_len = xowa_href_bry.length;
|
||||
int slash_pos = Bry_finder.Find_fwd(xowa_href_bry, Byte_ascii.Slash); if (slash_pos == Bry_.NotFound) slash_pos = xowa_href_bry_len;
|
||||
byte[] xowa_cmd_bry = Bry_.Mid(xowa_href_bry, 0, slash_pos);
|
||||
String xowa_cmd_str = String_.new_u8(xowa_cmd_bry);
|
||||
GfoMsg m = GfoMsg_.new_cast_(xowa_cmd_str);
|
||||
if (String_.Eq(xowa_cmd_str, Xog_win_itm.Invk_eval))
|
||||
m.Add("cmd", String_.new_u8(xowa_href_bry, slash_pos + 1, xowa_href_bry_len));
|
||||
win.Invk(GfsCtx.new_(), 0, xowa_cmd_str, m);
|
||||
win.Active_html_itm().Scroll_page_by_id_gui(tmp_url.Anch_str()); // NOTE: was originally directly; changed to call on thread; DATE:2014-05-03
|
||||
return Rslt_handled;
|
||||
}
|
||||
private Xoa_url Exec_url_file(Xoae_app app, Xowe_wiki cur_wiki, Xoae_page page, Xog_win_itm win, byte[] href_bry) { // EX: file:///xowa/A.png
|
||||
@@ -97,59 +96,73 @@ public class Xog_url_wkr {
|
||||
return Rslt_handled;
|
||||
}
|
||||
private Xoa_url Exec_url_page(Xoae_app app, Xowe_wiki wiki, Xoae_page page, Xog_win_itm win, byte[] href_bry) { // EX: "Page"; "/wiki/Page"; // rewritten; DATE:2014-01-19
|
||||
Xoa_url rv = app.Utl__url_parser().Parse(href_bry); // needed for query_args
|
||||
byte[] anchor_bry = href.Anchor();
|
||||
byte[] page_bry = rv.Page_bry();
|
||||
byte[][] segs_ary = rv.Segs_ary();
|
||||
int segs_ary_len = segs_ary.length;
|
||||
boolean use_main_page = false;
|
||||
if ( segs_ary_len > 0 // handle "Special:Search/Earth" which creates segs[1] {"Special:Search"} and page="Earth"
|
||||
|| href.Tid() == Xoh_href.Tid_site) { // NOTE: if site, must always (a) zap Segs_ary and (b) force correct page; see tests; DATE:2014-01-21
|
||||
int segs_bgn = 0;
|
||||
boolean segs_iterate = true;
|
||||
if (href.Tid() == Xoh_href.Tid_site) { // site, handle multiple segs; EX: "home/wiki/", "home/wiki/Help:Contents"; DATE:2014-01-21
|
||||
if (segs_ary_len < 2) { // only 0 or 1 seg; usually occurs for logo and other xwiki links to Main_Page; EX: "/site/en.wikipedia.org/wiki/"; "/site/en.wikipedia.org/"
|
||||
page_bry = wiki.Init_assert().Props().Main_page(); // use Main_page; DATE:2014-02-16
|
||||
use_main_page = true;
|
||||
segs_iterate = false;
|
||||
}
|
||||
else
|
||||
segs_bgn = 2; // start from seg_2; seg_0="/en.wikipedia.org/" and seg_1="/wiki/"; note that > 2 segs possible; EX: "/site/en.wikipedia.org/wiki/A/B/C
|
||||
}
|
||||
if (segs_iterate) {
|
||||
Bry_bfr tmp_bfr = wiki.Utl__bfr_mkr().Get_b128();
|
||||
for (int i = segs_bgn; i < segs_ary_len; i++) {
|
||||
tmp_bfr.Add(segs_ary[i]);
|
||||
tmp_bfr.Add_byte(Byte_ascii.Slash);
|
||||
}
|
||||
tmp_bfr.Add(page_bry);
|
||||
page_bry = tmp_bfr.To_bry_and_rls();
|
||||
}
|
||||
rv.Segs_ary_(Bry_.Ary_empty);
|
||||
}
|
||||
Gfo_url_arg[] qargs = rv.Args();
|
||||
Xoa_url rv = wiki.Utl__url_parser().Parse(href_bry);// needed for query_args
|
||||
Gfo_qarg_itm[] qargs = rv.Qargs_ary();
|
||||
int qargs_len = qargs.length;
|
||||
if (qargs_len > 0) { // remove anchors from qargs; EX: "to=B#mw_pages"
|
||||
for (int i = 0; i < qargs_len; i++) {
|
||||
Gfo_url_arg arg = qargs[i];
|
||||
int anchor_pos = Bry_finder.Find_bwd(arg.Val_bry(), Byte_ascii.Hash); // NOTE: must .FindBwd to handle Category args like de.wikipedia.org/wiki/Kategorie:Begriffskl%C3%A4rung?pagefrom=#::12%20PANZERDIVISION#mw-pages; DATE:2013-06-18
|
||||
if (anchor_pos != Bry_.NotFound)
|
||||
arg.Val_bry_(Bry_.Mid(arg.Val_bry(), 0, anchor_pos));
|
||||
Gfo_qarg_itm arg = qargs[i];
|
||||
int anch_pos = Bry_finder.Find_bwd(arg.Val_bry(), Byte_ascii.Hash); // NOTE: must .FindBwd to handle Category args like de.wikipedia.org/wiki/Kategorie:Begriffskl%C3%A4rung?pagefrom=#::12%20PANZERDIVISION#mw-pages; DATE:2013-06-18
|
||||
if (anch_pos != Bry_.NotFound)
|
||||
arg.Val_bry_(Bry_.Mid(arg.Val_bry(), 0, anch_pos));
|
||||
}
|
||||
}
|
||||
if (!Bry_.Eq(page.Wiki().Domain_bry(), href.Wiki())) {// xwiki; EX: "file:///site/en.wiktionary.org/wiki/a"; EX: (1) goto w:Anything; (2) click on "anything" in wikt; "anything" will be parsed by en.wiki's rules, not en.wikt; DATE:2013-01-30
|
||||
wiki = app.Wiki_mgr().Get_by_key_or_make(href.Wiki()).Init_assert(); // get xwiki and set to wiki
|
||||
if (use_main_page)
|
||||
page_bry = wiki.Props().Main_page(); // get Main_page for new wiki; DATE:2014-02-23
|
||||
Xoa_ttl tmp_ttl = Xoa_ttl.parse_(wiki, page_bry); // reparse ttl according to xwiki's case_match rules; NOTE: do not use rv.Page_bry() or else will lose sub_pages (A/B/C); DATE:2014-02-21
|
||||
if (tmp_ttl != null)
|
||||
page_bry = tmp_ttl.Full_db();
|
||||
}
|
||||
rv.Wiki_bry_(wiki.Domain_bry()); // needed b/c url_parser.Parse(href) will result in wiki of "wiki" for "/wiki/Page"
|
||||
rv.Page_bry_(page_bry);
|
||||
rv.Anchor_bry_(anchor_bry);
|
||||
return rv;
|
||||
}
|
||||
// private Xoa_url Exec_url_page(Xoae_app app, Xowe_wiki wiki, Xoae_page page, Xog_win_itm win, byte[] href_bry) { // EX: "Page"; "/wiki/Page"; // rewritten; DATE:2014-01-19
|
||||
// Xoa_url rv = wiki.Utl__url_parser().Parse(href_bry);// needed for query_args
|
||||
// byte[] anchor_bry = href.Anchor();
|
||||
// byte[] page_bry = rv.Page_bry();
|
||||
// byte[][] segs_ary = rv.Mids_ary();
|
||||
// int segs_ary_len = segs_ary.length;
|
||||
// boolean use_main_page = false;
|
||||
// if ( segs_ary_len > 0 // handle "Special:Search/Earth" which creates segs[1] {"Special:Search"} and page="Earth"
|
||||
// || href.Tid() == Xoh_href_.Tid_site) { // NOTE: if site, must always (a) zap Segs_ary and (b) force correct page; see tests; DATE:2014-01-21
|
||||
// int segs_bgn = 0;
|
||||
// boolean segs_iterate = true;
|
||||
// if (href.Tid() == Xoh_href_.Tid_site) { // site, handle multiple segs; EX: "home/wiki/", "home/wiki/Help:Contents"; DATE:2014-01-21
|
||||
// if (segs_ary_len < 2) { // only 0 or 1 seg; usually occurs for logo and other xwiki links to Main_Page; EX: "/site/en.wikipedia.org/wiki/"; "/site/en.wikipedia.org/"
|
||||
// page_bry = wiki.Init_assert().Props().Main_page(); // use Main_page; DATE:2014-02-16
|
||||
// use_main_page = true;
|
||||
// segs_iterate = false;
|
||||
// }
|
||||
// else
|
||||
// segs_bgn = 2; // start from seg_2; seg_0="/en.wikipedia.org/" and seg_1="/wiki/"; note that > 2 segs possible; EX: "/site/en.wikipedia.org/wiki/A/B/C
|
||||
// }
|
||||
// if (segs_iterate) {
|
||||
// Bry_bfr tmp_bfr = wiki.Utl__bfr_mkr().Get_b128();
|
||||
// for (int i = segs_bgn; i < segs_ary_len; i++) {
|
||||
// tmp_bfr.Add(segs_ary[i]);
|
||||
// tmp_bfr.Add_byte(Byte_ascii.Slash);
|
||||
// }
|
||||
// tmp_bfr.Add(page_bry);
|
||||
// page_bry = tmp_bfr.To_bry_and_rls();
|
||||
// }
|
||||
// rv.Mids_ary_(Bry_.Ary_empty);
|
||||
// }
|
||||
// Gfo_qarg_itm[] qargs = rv.Qargs_ary();
|
||||
// int qargs_len = qargs.length;
|
||||
// if (qargs_len > 0) { // remove anchors from qargs; EX: "to=B#mw_pages"
|
||||
// for (int i = 0; i < qargs_len; i++) {
|
||||
// Gfo_qarg_itm arg = qargs[i];
|
||||
// int anch_pos = Bry_finder.Find_bwd(arg.Val_bry(), Byte_ascii.Hash); // NOTE: must .FindBwd to handle Category args like de.wikipedia.org/wiki/Kategorie:Begriffskl%C3%A4rung?pagefrom=#::12%20PANZERDIVISION#mw-pages; DATE:2013-06-18
|
||||
// if (anch_pos != Bry_.NotFound)
|
||||
// arg.Val_bry_(Bry_.Mid(arg.Val_bry(), 0, anch_pos));
|
||||
// }
|
||||
// }
|
||||
// if (!Bry_.Eq(page.Wiki().Domain_bry(), href.Wiki())) {// xwiki; EX: "file:///site/en.wiktionary.org/wiki/a"; EX: (1) goto w:Anything; (2) click on "anything" in wikt; "anything" will be parsed by en.wiki's rules, not en.wikt; DATE:2013-01-30
|
||||
// wiki = app.Wiki_mgr().Get_by_key_or_make(href.Wiki()).Init_assert(); // get xwiki and set to wiki
|
||||
// if (use_main_page)
|
||||
// page_bry = wiki.Props().Main_page(); // get Main_page for new wiki; DATE:2014-02-23
|
||||
// Xoa_ttl tmp_ttl = Xoa_ttl.parse_(wiki, page_bry); // reparse ttl according to xwiki's case_match rules; NOTE: do not use rv.Page_bry() or else will lose sub_pages (A/B/C); DATE:2014-02-21
|
||||
// if (tmp_ttl != null)
|
||||
// page_bry = tmp_ttl.Full_db();
|
||||
// }
|
||||
// rv.Wiki_bry_(wiki.Domain_bry()); // needed b/c url_parser.Parse(href) will result in wiki of "wiki" for "/wiki/Page"
|
||||
// rv.Page_bry_(page_bry);
|
||||
// rv.Anch_bry_(anchor_bry);
|
||||
// return rv;
|
||||
// }
|
||||
public static Xoa_url Rslt_handled = null;
|
||||
public static Xoa_url Exec_url(Xog_win_itm win, String href_str) {
|
||||
Xog_url_wkr url_wkr = new Xog_url_wkr();
|
||||
|
||||
@@ -1,100 +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.gui.urls; import gplx.*; import gplx.xowa.*; import gplx.xowa.gui.*;
|
||||
import org.junit.*; import gplx.xowa.html.hrefs.*; import gplx.xowa.gui.views.*;
|
||||
public class Xog_url_wkr_tst {
|
||||
@Before public void init() {fxt.Clear();} private Xog_url_wkr_fxt fxt = new Xog_url_wkr_fxt();
|
||||
@Test public void term() {fxt.Clear();}
|
||||
@Test public void Basic() {
|
||||
fxt.Init_exec("file:///wiki/A").Expd_tid_(Xoh_href.Tid_wiki).Expd_page_("A").Test();
|
||||
}
|
||||
@Test public void Basic_question() {
|
||||
fxt.Init_exec("file:///wiki/A?").Expd_tid_(Xoh_href.Tid_wiki).Expd_page_("A?").Expd_qargs_("").Test();
|
||||
}
|
||||
@Test public void Basic_question_text() {
|
||||
fxt.Init_exec("file:///wiki/A?B").Expd_tid_(Xoh_href.Tid_wiki).Expd_page_("A?B").Expd_qargs_("").Test();
|
||||
}
|
||||
@Test public void Redirect() {
|
||||
fxt.Init_exec("file:///wiki/A?redirect=no").Expd_tid_(Xoh_href.Tid_wiki).Expd_page_("A").Expd_qargs_("?redirect=no").Test();
|
||||
}
|
||||
@Test public void Search() {
|
||||
fxt.Init_exec("file:///wiki/Special:Search/Moon%3Ffulltext%3Dy%26xowa_page_index%3D1").Expd_tid_(Xoh_href.Tid_wiki).Expd_page_("Special:Search/Moon").Expd_qargs_("?fulltext=y&xowa_page_index=1").Test();
|
||||
}
|
||||
@Test public void Ctg() {
|
||||
fxt.Init_exec("file:///wiki/Category:A?pagefrom=A#mw-pages").Expd_tid_(Xoh_href.Tid_wiki).Expd_page_("Category:A").Expd_qargs_("?pagefrom=A").Expd_anchor_("mw-pages").Test();
|
||||
}
|
||||
@Test public void Xwiki() {
|
||||
Xow_ns_mgr ns_mgr = fxt.App().Wiki_mgr().Get_by_key_or_make(Bry_.new_a7("en.wiktionary.org")).Ns_mgr();
|
||||
|
||||
ns_mgr.Ns_main().Case_match_(Xow_ns_case_.Id_all);
|
||||
fxt.Init_exec("file:///site/en.wiktionary.org/wiki/a").Expd_tid_(Xoh_href.Tid_site).Expd_wiki_("en.wiktionary.org").Expd_page_("a").Test();
|
||||
|
||||
ns_mgr.Ns_category().Case_match_(Xow_ns_case_.Id_all);
|
||||
fxt.Init_exec("file:///site/en.wiktionary.org/wiki/Category:a").Expd_tid_(Xoh_href.Tid_site).Expd_wiki_("en.wiktionary.org").Expd_page_("Category:a").Test();
|
||||
|
||||
fxt.Init_exec("file:///site/en.wiktionary.org/wiki/A/B/C").Expd_tid_(Xoh_href.Tid_site).Expd_page_("A/B/C").Test();
|
||||
}
|
||||
@Test public void Xwiki_site_sidebar() {// PURPOSE: make sure sidebar links don't fail; DATE:2014-01-21
|
||||
fxt.Init_exec("file:///site/en.wikipedia.org/wiki/A").Expd_tid_(Xoh_href.Tid_site).Expd_wiki_("en.wikipedia.org").Expd_page_("A").Test();
|
||||
}
|
||||
@Test public void Xwiki_site_logo() { // DATE:2014-01-21
|
||||
fxt.Init_exec("file:///site/en.wikipedia.org/wiki/").Expd_tid_(Xoh_href.Tid_site).Expd_wiki_("en.wikipedia.org").Expd_page_("Main_Page").Test();
|
||||
fxt.Init_exec("file:///site/en.wikipedia.org/wiki").Expd_tid_(Xoh_href.Tid_site).Expd_wiki_("en.wikipedia.org").Expd_page_("Main_Page").Test();
|
||||
fxt.Init_exec("file:///site/en.wikipedia.org/").Expd_tid_(Xoh_href.Tid_site).Expd_wiki_("en.wikipedia.org").Expd_page_("Main_Page").Test();
|
||||
}
|
||||
@Test public void Main_page() {// PURPOSE: Main_page does not update to use Main_page of xwiki; DATE:2014-02-23
|
||||
fxt.App().Usere().Wiki().Xwiki_mgr().Add_full("zh.wikipedia.org", "zh.wikipedia.org");
|
||||
gplx.xowa.wikis.Xoa_wiki_regy.Make_wiki_dir(fxt.App(), "zh.wikipedia.org");
|
||||
fxt.App().Wiki_mgr().Get_by_key_or_make(Bry_.new_a7("zh.wikipedia.org")).Props().Main_page_(Bry_.new_a7("Zh_Main_Page"));
|
||||
fxt.App().Wiki_mgr().Get_by_key_or_make(Bry_.new_a7("en.wikipedia.org")).Props().Main_page_(Bry_.new_a7("En_Main_Page"));
|
||||
fxt.Init_exec("file:///site/zh.wikipedia.org/").Expd_tid_(Xoh_href.Tid_site).Expd_wiki_("zh.wikipedia.org").Expd_page_("Zh_Main_Page").Test();
|
||||
fxt.Init_exec("file:///site/en.wikipedia.org/").Expd_tid_(Xoh_href.Tid_site).Expd_wiki_("en.wikipedia.org").Expd_page_("En_Main_Page").Test(); // still stuck at Zh
|
||||
}
|
||||
}
|
||||
class Xog_url_wkr_fxt {
|
||||
private Xoae_app app; private Xowe_wiki wiki;
|
||||
private Xog_win_itm win;
|
||||
private Xog_url_wkr url_wkr = new Xog_url_wkr();
|
||||
private String init_raw;
|
||||
public Xoae_app App() {return app;}
|
||||
public Xog_url_wkr_fxt Expd_tid_(byte v) {expd_tid = v; return this;} private byte expd_tid;
|
||||
public Xog_url_wkr_fxt Expd_wiki_(String v) {expd_wiki = v; return this;} private String expd_wiki;
|
||||
public Xog_url_wkr_fxt Expd_page_(String v) {expd_page = v; return this;} private String expd_page;
|
||||
public Xog_url_wkr_fxt Expd_anchor_(String v) {expd_anchor = v; return this;} private String expd_anchor;
|
||||
public Xog_url_wkr_fxt Expd_qargs_(String v) {expd_qargs = v; return this;} private String expd_qargs;
|
||||
public void Clear() {
|
||||
app = Xoa_app_fxt.app_();
|
||||
wiki = Xoa_app_fxt.wiki_tst_(app);
|
||||
Xoa_app_fxt.Init_gui(app, wiki);
|
||||
win = app.Gui_mgr().Browser_win();
|
||||
win.Active_page_(Xoae_page.test_(wiki, Xoa_ttl.parse_(wiki, Bry_.new_a7("test")))); // TODO: remove unnecessary page init
|
||||
expd_wiki = expd_page = expd_qargs = expd_anchor = null;
|
||||
}
|
||||
public Xog_url_wkr_fxt Init_exec(String raw) {
|
||||
this.init_raw = raw;
|
||||
return this;
|
||||
}
|
||||
public void Test() {
|
||||
Xoa_url url = url_wkr.Parse(win, init_raw).Exec();
|
||||
Tfds.Eq(expd_tid, url_wkr.Href_tid());
|
||||
Tfds.Eq(expd_page, String_.new_u8(url.Page_bry()));
|
||||
if (expd_wiki != null) Tfds.Eq(expd_wiki , String_.new_u8(url.Wiki_bry()));
|
||||
if (expd_anchor != null) Tfds.Eq(expd_anchor , String_.new_u8(url.Anchor_bry()));
|
||||
if (expd_qargs != null) Tfds.Eq(expd_qargs , String_.new_u8(url.Args_all_as_bry()));
|
||||
}
|
||||
}
|
||||
@@ -18,7 +18,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
package gplx.xowa.gui.urls.url_macros; import gplx.*; import gplx.xowa.*; import gplx.xowa.gui.*; import gplx.xowa.gui.urls.*;
|
||||
import gplx.core.btries.*;
|
||||
public class Xog_url_macro_grp implements GfoInvkAble {
|
||||
public Btrie_slim_mgr Trie() {return trie;} private Btrie_slim_mgr trie = Btrie_slim_mgr.cs_();
|
||||
public Btrie_slim_mgr Trie() {return trie;} private Btrie_slim_mgr trie = Btrie_slim_mgr.cs();
|
||||
public void Del(byte[] abrv) {trie.Del(abrv);}
|
||||
public void Set(String abrv, String fmt) {Set(Bry_.new_u8(abrv), Bry_.new_u8(fmt));}
|
||||
public void Set(byte[] abrv, byte[] fmt) {trie.Add_obj(abrv, new Xog_url_macro_itm(abrv, fmt));}
|
||||
|
||||
@@ -49,7 +49,7 @@ public class Load_page_wkr implements Gfo_thread_wkr {
|
||||
Thread_adp_.Sleep(10);
|
||||
}
|
||||
Xoae_app app = wiki.Appe();
|
||||
app.Usr_dlg().Log_many("", "", "page.load: url=~{0}", url.Xto_full_str_safe());
|
||||
app.Usr_dlg().Log_many("", "", "page.load: url=~{0}", url.To_str());
|
||||
if (Env_.System_memory_free() < app.Sys_cfg().Free_mem_when()) // check if low in memory
|
||||
app.Free_mem(false); // clear caches (which will clear bry_bfr_mk)
|
||||
else // not low in memory
|
||||
|
||||
@@ -18,7 +18,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
package gplx.xowa.gui.views; import gplx.*; import gplx.xowa.*; import gplx.xowa.gui.*;
|
||||
import gplx.core.primitives.*; import gplx.core.btries.*;
|
||||
import gplx.gfui.*; import gplx.xowa.gui.menus.*; import gplx.xowa.gui.menus.dom.*; import gplx.xowa.files.gui.*;
|
||||
import gplx.html.*; import gplx.xowa.html.js.*; import gplx.xowa.html.heads.*; import gplx.xowa.pages.*;
|
||||
import gplx.html.*; import gplx.xowa.html.hrefs.*; import gplx.xowa.html.js.*; import gplx.xowa.html.heads.*; import gplx.xowa.pages.*;
|
||||
public class Xog_html_itm implements Xog_js_wkr, GfoInvkAble, GfoEvObj {
|
||||
private Xoae_app app; private final Object thread_lock = new Object();
|
||||
private final String_obj_ref scroll_top = String_obj_ref.null_(), node_path = String_obj_ref.null_();
|
||||
@@ -56,7 +56,7 @@ public class Xog_html_itm implements Xog_js_wkr, GfoInvkAble, GfoEvObj {
|
||||
Xoae_page page = owner_tab.Page();
|
||||
String site = owner_tab.Wiki().Domain_str();
|
||||
String ttl = String_.new_u8(page.Ttl().Full_db());
|
||||
return Xog_html_itm__href_extractor.Html_extract_text(site, ttl, v);
|
||||
return Xoh_href_gui_utl.Html_extract_text(site, ttl, v);
|
||||
}
|
||||
public void Show(Xoae_page page) {
|
||||
byte view_mode = owner_tab.View_mode();
|
||||
@@ -71,9 +71,9 @@ public class Xog_html_itm implements Xog_js_wkr, GfoInvkAble, GfoEvObj {
|
||||
String html_str = String_.new_u8(html_bry);
|
||||
if (owner_tab.Tab_mgr().Html_load_tid__url()) {
|
||||
Io_url html_url = app.Usere().Fsys_mgr().App_temp_html_dir().GenSubFil_ary(owner_tab.Tab_key(), ".html");
|
||||
try {html_box.Html_doc_html_load_by_url(html_url.Xto_api(), html_str);}
|
||||
try {html_box.Html_doc_html_load_by_url(html_url, html_str);}
|
||||
catch (Exception e) {
|
||||
app.Usr_dlg().Warn_many("", "", "failed to write html to file; writing directly by memory: page=~{0} file=~{1} err=~{2}", page.Url().Xto_full_str_safe(), html_url.Raw(), Err_.Message_gplx_full(e));
|
||||
app.Usr_dlg().Warn_many("", "", "failed to write html to file; writing directly by memory: page=~{0} file=~{1} err=~{2}", page.Url().To_str(), html_url.Raw(), Err_.Message_gplx_full(e));
|
||||
html_box.Html_doc_html_load_by_mem(html_str);
|
||||
}
|
||||
}
|
||||
@@ -223,39 +223,3 @@ public class Xog_html_itm implements Xog_js_wkr, GfoInvkAble, GfoEvObj {
|
||||
node_path.Val_(node_path_val);
|
||||
}
|
||||
}
|
||||
class Xog_html_itm__href_extractor {
|
||||
private static final byte Text_tid_none = 0, Text_tid_text = 1, Text_tid_href = 2;
|
||||
private static final byte Href_tid_wiki = 1, Href_tid_site = 2, Href_tid_anchor = 3;
|
||||
private static final byte[] File_protocol_bry = Bry_.new_a7("file://");
|
||||
private static final int File_protocol_len = File_protocol_bry.length;
|
||||
private static final Btrie_slim_mgr href_trie = Btrie_slim_mgr.cs_()
|
||||
.Add_str_byte("/site/" , Href_tid_site)
|
||||
.Add_str_byte("/wiki/" , Href_tid_wiki)
|
||||
.Add_str_byte("#" , Href_tid_anchor)
|
||||
;
|
||||
public static String Html_extract_text(String site, String page, String text_str) {
|
||||
byte[] text_bry = Bry_.new_u8(text_str);
|
||||
int text_tid = Byte_ascii.Xto_digit(text_bry[0]);
|
||||
int text_len = text_bry.length;
|
||||
switch (text_tid) {
|
||||
case Text_tid_none: return "";
|
||||
case Text_tid_text: return String_.new_u8(text_bry, 2, text_len); // 2 to skip "1|"
|
||||
case Text_tid_href: break; // fall through to below
|
||||
default: throw Err_.new_unhandled(text_tid);
|
||||
}
|
||||
int href_bgn = 2; // 2 for length of "2|"
|
||||
if (Bry_.Has_at_bgn(text_bry, File_protocol_bry, 2, text_len)) {
|
||||
href_bgn += File_protocol_len; // skip "file://"
|
||||
}
|
||||
Byte_obj_val href_tid = (Byte_obj_val)href_trie.Match_bgn(text_bry, href_bgn, text_len);
|
||||
if (href_tid != null) {
|
||||
switch (href_tid.Val()) {
|
||||
case Href_tid_wiki: return site + String_.new_u8(text_bry, href_bgn, text_len);
|
||||
case Href_tid_site: return String_.new_u8(text_bry, href_bgn + 6, text_len); // +6 to skip "site/"
|
||||
case Href_tid_anchor: return site + "/wiki/" + page + String_.new_u8(text_bry, href_bgn, text_len);
|
||||
}
|
||||
}
|
||||
return String_.new_u8(text_bry, 2, text_len); // 2 to skip "2|"; handles "http://" text as well as any fall-thru from above
|
||||
}
|
||||
public static final Xog_html_itm__href_extractor _ = new Xog_html_itm__href_extractor(); Xog_html_itm__href_extractor() {}
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@ You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.gui.views; import gplx.*; import gplx.xowa.*; import gplx.xowa.gui.*;
|
||||
import gplx.xowa.urls.*;
|
||||
class Xog_launcher_tabs {
|
||||
public void Launch(Xog_win_itm win) {
|
||||
Xoae_app app = win.App(); Gfo_log_bfr log_bfr = app.Log_bfr();
|
||||
@@ -59,8 +60,8 @@ class Xog_launcher_tabs {
|
||||
}
|
||||
private void Launch_tab(Xog_win_itm win, Xowe_wiki home_wiki, String launch_str) {
|
||||
Xoae_app app = win.App();
|
||||
Xoa_url launch_url = Xoa_url_parser.Parse_from_url_bar(app, home_wiki, launch_str);
|
||||
Xowe_wiki launch_wiki = app.Wiki_mgr().Get_by_key_or_null(launch_url.Wiki_bry());
|
||||
Xoa_url launch_url = home_wiki.Utl__url_parser().Parse_by_urlbar(launch_str);
|
||||
Xowe_wiki launch_wiki = (Xowe_wiki)app.Wiki_mgr().Get_by_key_or_make_init_y(launch_url.Wiki_bry());
|
||||
Xoa_ttl launch_ttl = Xoa_ttl.parse_(launch_wiki, launch_url.Page_bry());
|
||||
Xog_tab_itm tab = win.Tab_mgr().Tabs_new_init(launch_wiki, Xoae_page.new_(launch_wiki, launch_ttl)); // WORKAROUND: set the tab to an empty page, else null ref later; DATE:2014-07-23
|
||||
tab.Show_url_bgn(launch_url);
|
||||
|
||||
@@ -18,6 +18,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
package gplx.xowa.gui.views; import gplx.*; import gplx.xowa.*; import gplx.xowa.gui.*;
|
||||
import gplx.core.threads.*; import gplx.gfui.*; import gplx.xowa.gui.history.*; import gplx.xowa.gui.bnds.*;
|
||||
import gplx.xowa.files.*; import gplx.xowa.files.fsdb.*;
|
||||
import gplx.xowa.langs.vnts.*;
|
||||
import gplx.xowa.parsers.*; import gplx.xowa.parsers.lnkis.redlinks.*; import gplx.xowa.cfgs2.*;
|
||||
import gplx.xowa.pages.*; import gplx.xowa.pages.skins.*;
|
||||
public class Xog_tab_itm implements GfoInvkAble {
|
||||
@@ -25,7 +26,7 @@ public class Xog_tab_itm implements GfoInvkAble {
|
||||
public Xog_tab_itm(Xog_tab_mgr tab_mgr, Gfui_tab_itm_data tab_data, Xowe_wiki wiki, Xoae_page page) {
|
||||
this.tab_mgr = tab_mgr; this.tab_data = tab_data; this.wiki = wiki; this.page = page;
|
||||
this.win = tab_mgr.Win(); this.cfg_tab_mgr = win.App().Cfg_regy ().App().Gui_mgr().Tab_mgr();
|
||||
html_itm = new Xog_html_itm(this);
|
||||
this.html_itm = new Xog_html_itm(this);
|
||||
cmd_sync = win.Kit().New_cmd_sync(this);
|
||||
}
|
||||
public Xowe_wiki Wiki() {return wiki;} public void Wiki_(Xowe_wiki v) {this.wiki = v;} private Xowe_wiki wiki;
|
||||
@@ -40,6 +41,7 @@ public class Xog_tab_itm implements GfoInvkAble {
|
||||
if (app.App_type().Uid_is_gui()) { // NOTE: only run for gui; will cause firefox addon to fail; DATE:2014-05-03
|
||||
html_box.Html_doc_html_load_by_mem(""); // NOTE: must set source, else control will be empty, and key events will not be raised; DATE:2014-04-30
|
||||
IptBnd_.ipt_to_(IptCfg_.Null, html_box, this, "popup", IptEventType_.MouseDown, IptMouseBtn_.Right);
|
||||
IptBnd_.cmd_to_(IptCfg_.Null, html_box, win, Xog_win_itm.Invk_exit, IptKey_.add_(IptKey_.Alt, IptKey_.F4)); // WORKAROUND:SWT: xulrunner_v24 no longer sends Alt+F4 to SwtShell; must manually subscribe it to quit; DATE:2015-07-31
|
||||
GfoEvMgr_.SubSame(html_box, GfuiElemKeys.Evt_menu_detected, html_itm);
|
||||
gui_mgr.Bnd_mgr().Bind(Xog_bnd_box_.Tid_browser_html, html_box);
|
||||
if (!Env_.Mode_testing())
|
||||
@@ -81,7 +83,7 @@ public class Xog_tab_itm implements GfoInvkAble {
|
||||
} private Xoae_page page;
|
||||
public void Page_update_ui() {
|
||||
this.Tab_name_();
|
||||
tab_box.Tab_tip_text_(page.Url().Xto_full_str());
|
||||
tab_box.Tab_tip_text_(page.Url().To_str());
|
||||
}
|
||||
public void Tab_name_() {
|
||||
byte[] tab_name = page.Html_data().Custom_name();
|
||||
@@ -100,21 +102,20 @@ public class Xog_tab_itm implements GfoInvkAble {
|
||||
public void Show_url_bgn(Xoa_url url) {
|
||||
this.tab_is_loading = true;
|
||||
Xoae_app app = win.App(); Gfo_usr_dlg usr_dlg = app.Usr_dlg();
|
||||
if ( url.Anchor_str() != null // url has anchor
|
||||
if ( url.Anch_str() != null // url has anchor
|
||||
&& url.Eq_page(page.Url()) // url has same page_name as existing page
|
||||
&& url.Args().length == 0) { // url has no args; needed for Category:A?from=b#mw-pages
|
||||
html_itm.Scroll_page_by_id_gui(url.Anchor_str()); // skip page_load and jump to anchor
|
||||
&& url.Qargs_ary().length == 0) { // url has no args; needed for Category:A?from=b#mw-pages
|
||||
html_itm.Scroll_page_by_id_gui(url.Anch_str()); // skip page_load and jump to anchor
|
||||
return;
|
||||
}
|
||||
if (url.Xowa_vnt() != null)
|
||||
wiki.Lang().Vnt_mgr().Cur_vnt_(url.Xowa_vnt());
|
||||
if (win.Page__async__working(url)) return;
|
||||
app.Gui_mgr().Search_suggest_mgr().Cancel(); // cancel pending search_suggest calls
|
||||
if (page != null) page.Tab_data().Close_mgr().When_close(this, url); // cancel any current search cmds
|
||||
app.Log_wtr().Queue_enabled_(true);
|
||||
usr_dlg.Gui_wkr().Clear();
|
||||
this.wiki = app.Wiki_mgr().Get_by_key_or_null(url.Wiki_bry()); // NOTE: must update wiki
|
||||
wiki.Init_assert(); // NOTE: assert wiki.Init before parsing; needed b/c lang (with lang-specific ns) is only loaded on init, and parse Xoa_ttl.parse_ will fail below; EX:pt.wikipedia.org/wiki/Wikipedia:P<>gina principal
|
||||
this.wiki = (Xowe_wiki)app.Wiki_mgr().Get_by_key_or_make_init_y(url.Wiki_bry()); // NOTE: must update wiki variable; DATE:????-??-??; NOTE: must load wiki; DATE:2015-07-22
|
||||
if (url.Page_is_main()) url.Page_bry_(wiki.Props().Main_page());
|
||||
if (url.Vnt_bry() != null) Cur_vnt_(wiki, url.Vnt_bry());
|
||||
Xoa_ttl ttl = Xoa_ttl.parse_(wiki, url.Page_bry());
|
||||
if (ttl == null) {usr_dlg.Prog_one("", "", "title is invalid: ~{0}", String_.new_u8(url.Raw())); return;}
|
||||
Tab_name_(String_.new_u8(ttl.Full_txt()));
|
||||
@@ -123,6 +124,14 @@ public class Xog_tab_itm implements GfoInvkAble {
|
||||
this.Html_box().Html_js_eval_script("if (window.xowa_popups_hide_all != null) window.xowa_popups_hide_all();"); // should be more configurable; DATE:2014-07-09
|
||||
app.Thread_mgr().Page_load_mgr().Add_at_end(new Load_page_wkr(this, wiki, url, ttl)).Run();
|
||||
}
|
||||
private void Cur_vnt_(Xowe_wiki wiki, byte[] vnt) {
|
||||
Xoae_app app = wiki.Appe();
|
||||
gplx.xowa.apis.xowa.wikis.langs.Xoap_lang_variants vnt_mgr = app.Api_root().Wikis().Get(wiki.Domain_bry()).Lang().Variants();
|
||||
if (Bry_.Eq(vnt, vnt_mgr.Current())) return;
|
||||
vnt_mgr.Current_(vnt);
|
||||
app.Cfg_mgr().Set_by_app(String_.Format("xowa.api.wikis.get('{0}').lang.variants.current", wiki.Domain_str()), String_.new_u8(vnt));
|
||||
app.Cfg_mgr().Db_save_txt();
|
||||
}
|
||||
private void Show_url_loaded(Load_page_wkr wkr) {
|
||||
Xowe_wiki wiki = wkr.Wiki(); Xoae_page page = wkr.Page();
|
||||
Xoa_url url = page.Url(); Xoa_ttl ttl = page.Ttl();
|
||||
@@ -151,7 +160,7 @@ public class Xog_tab_itm implements GfoInvkAble {
|
||||
return;
|
||||
}
|
||||
if (!page.Redirected()) page.Url_(url); // NOTE: handle redirect from commons
|
||||
if (page.Ttl().Anch_bgn() != Bry_.NotFound) page.Url().Anchor_bry_(page.Ttl().Anch_txt()); // NOTE: occurs when page is a redirect to an anchor; EX: w:Duck race -> Rubber duck#Races
|
||||
if (page.Ttl().Anch_bgn() != Bry_.NotFound) page.Url().Anch_bry_(page.Ttl().Anch_txt()); // NOTE: occurs when page is a redirect to an anchor; EX: w:Duck race -> Rubber duck#Races
|
||||
history_mgr.Add(page);
|
||||
Xog_tab_itm_read_mgr.Show_page(this, page, true);
|
||||
if (app.Api_root().Usr().History().Enabled()) {
|
||||
@@ -203,8 +212,8 @@ public class Xog_tab_itm implements GfoInvkAble {
|
||||
public void Async() {
|
||||
if (page == null) return; // TEST: occurs during Xog_win_mgr_tst
|
||||
Xowe_wiki wiki = page.Wikie(); Xoae_app app = wiki.Appe(); Xog_win_itm win_itm = tab_mgr.Win(); Gfo_usr_dlg usr_dlg = win_itm.Usr_dlg();
|
||||
app.Usr_dlg().Log_many("", "", "page.async: url=~{0}", page.Url().Xto_full_str_safe());
|
||||
if (page.Url().Anchor_str() != null) html_itm.Scroll_page_by_id_gui(page.Url().Anchor_str());
|
||||
app.Usr_dlg().Log_many("", "", "page.async: url=~{0}", page.Url().To_str());
|
||||
if (page.Url().Anch_str() != null) html_itm.Scroll_page_by_id_gui(page.Url().Anch_str());
|
||||
if (usr_dlg.Canceled()) {usr_dlg.Prog_none("", "", ""); app.Log_wtr().Queue_enabled_(false); return;}
|
||||
int xfer_len = 0;
|
||||
xfer_len = page.File_queue().Count();
|
||||
@@ -271,7 +280,7 @@ class Load_files_wkr implements Gfo_thread_wkr {
|
||||
public void Exec() {
|
||||
try {tab.Async();}
|
||||
catch (Exception e) {
|
||||
tab.Tab_mgr().Win().App().Usr_dlg().Warn_many("error while running file wkr; page=~{0} err=~{1}", tab.Page().Url().Xto_full_str(), Err_.Message_gplx_full(e));
|
||||
tab.Tab_mgr().Win().App().Usr_dlg().Warn_many("error while running file wkr; page=~{0} err=~{1}", tab.Page().Url().To_str(), Err_.Message_gplx_full(e));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,12 +19,11 @@ package gplx.xowa.gui.views; import gplx.*; import gplx.xowa.*; import gplx.xowa
|
||||
import gplx.gfui.*; import gplx.core.threads.*;
|
||||
import gplx.xowa.parsers.lnkis.redlinks.*; import gplx.xowa.gui.history.*; import gplx.xowa.pages.*;
|
||||
public class Xog_tab_itm_read_mgr {
|
||||
private static final Xoa_url_parser url_parser = new Xoa_url_parser(); // NOTE: separate url_parser to reduce threading issues
|
||||
public static void Async(Xog_tab_itm tab) {tab.Async();}
|
||||
public static void Show_page(Xog_tab_itm tab, Xoae_page new_page, boolean reset_to_read) {Show_page(tab, new_page, reset_to_read, false, false, Xog_history_stack.Nav_fwd);}
|
||||
public static void Show_page(Xog_tab_itm tab, Xoae_page new_page, boolean reset_to_read, boolean new_page_is_same, boolean show_is_err, byte history_nav_type) {
|
||||
if (reset_to_read) tab.View_mode_(Xopg_view_mode.Tid_read);
|
||||
if (new_page.Url().Action_is_edit()) tab.View_mode_(Xopg_view_mode.Tid_edit);
|
||||
if (new_page.Url().Qargs_mgr().Match(Xoa_url_.Qarg__action, Xoa_url_.Qarg__action__edit)) tab.View_mode_(Xopg_view_mode.Tid_edit);
|
||||
Xoae_page cur_page = tab.Page(); Xog_html_itm html_itm = tab.Html_itm(); Gfui_html html_box = html_itm.Html_box();
|
||||
Xog_win_itm win = tab.Tab_mgr().Win();
|
||||
if (cur_page != null && !new_page_is_same) { // if new_page_is_same, don't update DocPos; will "lose" current position
|
||||
@@ -37,7 +36,7 @@ public class Xog_tab_itm_read_mgr {
|
||||
catch (Exception e) {
|
||||
if (String_.Eq(Err_.Message_lang(e), "class org.eclipse.swt.SWTException Widget is disposed")) return; // ignore errors caused by user closing tab early; DATE:2014-07-26
|
||||
if (show_is_err) { // trying to show error page, but failed; don't show again, else recursion until out of memory; TODO:always load error page; no reason it should fail; WHEN:html_skin; DATE:2014-06-08
|
||||
Gfo_usr_dlg_.I.Warn_many("", "", "fatal error trying to load error page; page=~{0} err=~{1}" + new_page.Url().Xto_full_str_safe(), Err_.Message_gplx_full(e));
|
||||
Gfo_usr_dlg_.I.Warn_many("", "", "fatal error trying to load error page; page=~{0} err=~{1}" + new_page.Url().To_str(), Err_.Message_gplx_full(e));
|
||||
return;
|
||||
}
|
||||
else
|
||||
@@ -61,8 +60,8 @@ public class Xog_tab_itm_read_mgr {
|
||||
public static void Update_selected_tab_blank(Xog_win_itm win) {Update_selected_tab(win, null, null);} // called when all tabs are null
|
||||
public static void Update_selected_tab(Xog_win_itm win, Xoa_url url, Xoa_ttl ttl) {
|
||||
String url_str = "", win_str = Win_text_blank;
|
||||
if (url != null && ttl != null) {
|
||||
try {url_str = url_parser.Build_str(url);}
|
||||
if (url != null && ttl != null) { // TODO: remove; no longer needed for new url parser
|
||||
try {url_str = url.To_str();}
|
||||
catch (Exception e) { // HACK: failed pages will have a null wiki; for now, catch and ignore; DATE:2014-06-22
|
||||
Gfo_usr_dlg_.I.Warn_many("", "", "failed to build url: url=~{0}, err=~{1}", String_.new_u8(url.Raw()), Err_.Message_gplx_full(e));
|
||||
url_str = String_.new_u8(ttl.Full_txt());
|
||||
|
||||
@@ -17,6 +17,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.gui.views; import gplx.*; import gplx.xowa.*; import gplx.xowa.gui.*;
|
||||
import gplx.gfui.*; import gplx.xowa.cfgs2.*; import gplx.xowa.apis.xowa.gui.browsers.*; import gplx.xowa.specials.*;
|
||||
import gplx.xowa.urls.*;
|
||||
public class Xog_tab_mgr implements GfoEvObj {
|
||||
private Ordered_hash tab_regy = Ordered_hash_.new_(); private int tab_uid = 0;
|
||||
public Xog_tab_mgr(Xog_win_itm win) {
|
||||
@@ -77,7 +78,7 @@ public class Xog_tab_mgr implements GfoEvObj {
|
||||
boolean active_tab_is_null = this.Active_tab_is_null();
|
||||
Xowe_wiki cur_wiki = active_tab_is_null ? win.App().Usere().Wiki() : active_tab.Wiki();
|
||||
Xoa_ttl ttl = Xoa_ttl.parse_(cur_wiki, Xows_special_meta_.Itm__default_tab.Ttl_bry());
|
||||
Xoa_url url = Xoa_url_parser.Parse_from_url_bar(win.App(), cur_wiki, ttl.Full_db_as_str());
|
||||
Xoa_url url = cur_wiki.Utl__url_parser().Parse_by_urlbar(ttl.Full_db_as_str());
|
||||
Xog_tab_itm rv = Tabs_new(focus, active_tab_is_null, cur_wiki, Xoae_page.new_(cur_wiki, ttl));
|
||||
rv.Page_update_ui();
|
||||
rv.Show_url_bgn(url);
|
||||
@@ -102,7 +103,7 @@ public class Xog_tab_mgr implements GfoEvObj {
|
||||
}
|
||||
public void Tabs_new_dupe(boolean focus) {
|
||||
if (this.Active_tab_is_null()) return;
|
||||
String url = active_tab.Page().Url().Xto_full_str();
|
||||
String url = active_tab.Page().Url().To_str();
|
||||
Tabs_new_dflt(focus);
|
||||
win.Page__navigate_by_url_bar(url);
|
||||
}
|
||||
@@ -161,7 +162,7 @@ public class Xog_tab_mgr implements GfoEvObj {
|
||||
private void Tabs_closed(String key) {
|
||||
Xog_tab_itm itm = Tabs_get_by_key_or_warn(key); if (itm == null) return;
|
||||
itm.Html_box().Html_dispose();
|
||||
closed_undo_list.Add(itm.Page().Url().Xto_full_str());
|
||||
closed_undo_list.Add(itm.Page().Url().To_str());
|
||||
tab_regy.Del(key);
|
||||
if (tab_regy.Count() == 0) {
|
||||
active_tab = Xog_tab_itm_.Null;
|
||||
@@ -218,7 +219,7 @@ public class Xog_tab_mgr implements GfoEvObj {
|
||||
public void Tabs_new_link(String link, boolean focus) {
|
||||
Xowe_wiki wiki = active_tab.Wiki();
|
||||
Xog_tab_itm new_tab = Tabs_new(focus, false, wiki, Xoae_page.new_(wiki, active_tab.Page().Ttl())); // NOTE: do not use ttl from link, else middle-clicking pages with anchors won't work; DATE:2015-05-03
|
||||
Xoa_url url = Xoa_url_parser.Parse_from_url_bar(win.App(), wiki, link); // NOTE: link must be of form domain/wiki/page; DATE:2014-05-27
|
||||
Xoa_url url = wiki.Utl__url_parser().Parse_by_urlbar(link); // NOTE: link must be of form domain/wiki/page; DATE:2014-05-27
|
||||
new_tab.Show_url_bgn(url);
|
||||
if (focus)
|
||||
tab_mgr.Tabs_select_by_idx(new_tab.Tab_idx());
|
||||
|
||||
@@ -18,12 +18,14 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
package gplx.xowa.gui.views; import gplx.*; import gplx.xowa.*; import gplx.xowa.gui.*;
|
||||
import gplx.core.threads.*; import gplx.gfui.*; import gplx.xowa.gui.*; import gplx.xowa.gui.history.*; import gplx.xowa.xtns.math.*; import gplx.xowa.files.*;
|
||||
import gplx.xowa.gui.urls.*; import gplx.xowa.gui.views.*; import gplx.xowa.pages.*;
|
||||
import gplx.xowa.html.hrefs.*;
|
||||
import gplx.xowa.parsers.lnkis.redlinks.*; import gplx.xowa.specials.*;
|
||||
import gplx.xowa.urls.*;
|
||||
public class Xog_win_itm implements GfoInvkAble, GfoEvObj {
|
||||
private GfoInvkAble sync_cmd;
|
||||
public Xog_win_itm(Xoae_app app, Xoa_gui_mgr gui_mgr) {
|
||||
this.app = app; this.gui_mgr = gui_mgr;
|
||||
this.tab_mgr = new Xog_tab_mgr(this);
|
||||
this.tab_mgr = new Xog_tab_mgr(this);
|
||||
}
|
||||
public Gfui_kit Kit() {return kit;} private Gfui_kit kit;
|
||||
public Xoa_gui_mgr Gui_mgr() {return gui_mgr;} private Xoa_gui_mgr gui_mgr;
|
||||
@@ -57,9 +59,9 @@ public class Xog_win_itm implements GfoInvkAble, GfoEvObj {
|
||||
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
|
||||
if (ctx.Match(k, Invk_link_click)) Win__link_click();
|
||||
else if (ctx.Match(k, Invk_link_print)) Xog_win_itm__prog_href_mgr.Print(this);
|
||||
else if (ctx.Match(k, Gfui_html.Evt_link_hover)) Xog_win_itm__prog_href_mgr.Hover(app, this.Active_tab().Wiki(), this.Active_page(), m.ReadStr("v"));
|
||||
else if (ctx.Match(k, Gfui_html.Evt_link_hover)) Xog_win_itm__prog_href_mgr.Hover(app, this.Active_tab().Wiki(), this.Active_page(), Xoh_href_gui_utl.Standardize_xowa_link(m.ReadStr("v")));
|
||||
else if (ctx.Match(k, Gfui_html.Evt_location_changed)) Win__link_clicked(m.ReadStr("v"));
|
||||
else if (ctx.Match(k, Gfui_html.Evt_location_changing)) Page__navigate_by_internal_href(m.ReadStr("v"), tab_mgr.Active_tab());
|
||||
else if (ctx.Match(k, Gfui_html.Evt_location_changing)) Page__navigate_by_href(tab_mgr.Active_tab(), Xoh_href_gui_utl.Standardize_xowa_link(m.ReadStr("v")));
|
||||
else if (ctx.Match(k, Gfui_html.Evt_win_resized)) Refresh_win_size();
|
||||
else if (ctx.Match(k, Invk_page_refresh)) Page__refresh();
|
||||
else if (ctx.Match(k, Invk_page_async_exec)) Xog_tab_itm_read_mgr.Async((Xog_tab_itm)m.ReadObj("v"));
|
||||
@@ -86,6 +88,7 @@ public class Xog_win_itm implements GfoInvkAble, GfoEvObj {
|
||||
else if (ctx.Match(k, Invk_app)) return app;
|
||||
else if (ctx.Match(k, Invk_page)) return this.Active_page();
|
||||
else if (ctx.Match(k, Invk_wiki)) return this.Active_tab().Wiki();
|
||||
else if (ctx.Match(k, Invk_exit)) App__exit();
|
||||
else return GfoInvkAble_.Rv_unhandled;
|
||||
return this;
|
||||
}
|
||||
@@ -105,6 +108,7 @@ public class Xog_win_itm implements GfoInvkAble, GfoEvObj {
|
||||
, Invk_page_edit_save = "page_edit_save", Invk_page_edit_save_draft = "page_edit_save_draft", Invk_page_edit_preview = "page_edit_preview", Invk_page_edit_rename = "page_edit_rename"
|
||||
, Invk_page_dbg_wiki = "page_dbg_wiki", Invk_page_dbg_html = "page_dbg_html"
|
||||
, Invk_eval = "eval"
|
||||
, Invk_exit = "exit"
|
||||
// xowa.gfs: shortcuts
|
||||
, Invk_page_goto = "page_goto", Invk_page_goto_recent = "page_goto_recent"
|
||||
;
|
||||
@@ -113,7 +117,7 @@ public class Xog_win_itm implements GfoInvkAble, GfoEvObj {
|
||||
if (wiki.Gui_mgr().Cfg_browser().Content_editable()) {
|
||||
String href = tab.Html_itm().Html_box().Html_js_eval_proc_as_str(Xog_js_procs.Selection__get_active_for_editable_mode, Gfui_html.Atr_href, null);
|
||||
if (String_.Len_eq_0(href)) return; // NOTE: href can be null for images; EX: [[File:Loudspeaker.svg|11px|link=|alt=play]]; link= basically means don't link to image
|
||||
Page__navigate_by_internal_href(href, tab);
|
||||
Page__navigate_by_href(tab, href);
|
||||
}
|
||||
}
|
||||
private void Win__link_clicked(String anchor_raw) {
|
||||
@@ -127,7 +131,7 @@ public class Xog_win_itm implements GfoInvkAble, GfoEvObj {
|
||||
url_box.Text_(url + "#" + anchor_str); // update url box
|
||||
page.Html_data().Bmk_pos_(Xog_history_itm.Html_doc_pos_toc); // HACK: anchor clicked; set docPos of curentPage to TOC (so back will go back to TOC)
|
||||
tab.History_mgr().Update_html_doc_pos(page, Xog_history_stack.Nav_by_anchor); // HACK: update history_mgr; note that this must occur before setting Anchor (since Anchor will generate a new history itm)
|
||||
page.Url().Anchor_bry_(anchor_bry); // update url
|
||||
page.Url().Anch_bry_(anchor_bry); // update url
|
||||
}
|
||||
tab.History_mgr().Add(page);
|
||||
app.Usere().History_mgr().Add(page.Url(), page.Ttl(), Bry_.Add_w_dlm(Byte_ascii.Hash, page.Url().Page_bry(), anchor_bry));
|
||||
@@ -155,8 +159,8 @@ public class Xog_win_itm implements GfoInvkAble, GfoEvObj {
|
||||
tab.Page_(page);
|
||||
wiki.ParsePage_root(page, true); // NOTE: must reparse page if (a) Edit -> Read; or (b) "Options" save
|
||||
Xoa_url url = page.Url();
|
||||
if (url.Args_exists(Xoa_url_parser.Bry_arg_action, Xoa_url_parser.Bry_arg_action_edit)) // url has ?action=edit
|
||||
app.Utl__url_parser().Parse(url, url.Xto_full_bry()); // remove all query args; handle (1) s.w:Earth?action=edit; (2) click on Read; DATE:2014-03-06
|
||||
if (url.Qargs_mgr().Match(Xoa_url_.Qarg__action, Xoa_url_.Qarg__action__edit)) // url has ?action=edit
|
||||
url = tab.Wiki().Utl__url_parser().Parse(url.To_bry_full_wo_qargs()); // remove all query args; handle (1) s.w:Earth?action=edit; (2) click on Read; DATE:2014-03-06
|
||||
}
|
||||
tab.View_mode_(new_mode_tid);
|
||||
if (page.Missing()) return;
|
||||
@@ -166,10 +170,9 @@ public class Xog_win_itm implements GfoInvkAble, GfoEvObj {
|
||||
public void Page__navigate_by_search() {Page__navigate_by_url_bar(app.Gui_mgr().Win_cfg().Search_box_fmtr().Bld_str_many(search_box.Text()));}
|
||||
public void Page__navigate_by_url_bar(String href) {
|
||||
Xog_tab_itm tab = tab_mgr.Active_tab_assert();
|
||||
Xoa_url url = Xoa_url_parser.Parse_from_url_bar(app, tab.Wiki(), href);
|
||||
tab.Show_url_bgn(url);
|
||||
tab.Show_url_bgn(tab.Wiki().Utl__url_parser().Parse_by_urlbar(href));
|
||||
}
|
||||
private void Page__navigate_by_internal_href(String href, Xog_tab_itm tab) { // NOTE: different from Navigate_by_url_bar in that it handles "file:///" and other @gplx.Internal protected formats; EX: "/site/", "about:blank"; etc..
|
||||
private void Page__navigate_by_href(Xog_tab_itm tab, String href) { // NOTE: different from Navigate_by_url_bar in that it handles "file:///" and other @gplx.Internal protected formats; EX: "/site/", "about:blank"; etc..
|
||||
Xoa_url url = Xog_url_wkr.Exec_url(this, href);
|
||||
if (url != Xog_url_wkr.Rslt_handled)
|
||||
tab.Show_url_bgn(url);
|
||||
@@ -198,10 +201,10 @@ public class Xog_win_itm implements GfoInvkAble, GfoEvObj {
|
||||
Xog_tab_itm tab = tab_mgr.Active_tab(); Xoae_page page = tab.Page(); Xog_html_itm html_itm = tab.Html_itm();
|
||||
page.Html_data().Bmk_pos_(html_itm.Html_box().Html_js_eval_proc_as_str(Xog_js_procs.Win__vpos_get));
|
||||
html_itm.Show(page);
|
||||
if (page.Url().Anchor_str() == null)
|
||||
if (page.Url().Anch_str() == null)
|
||||
html_itm.Scroll_page_by_bmk_gui();
|
||||
else
|
||||
html_itm.Scroll_page_by_id_gui(page.Url().Anchor_str());
|
||||
html_itm.Scroll_page_by_id_gui(page.Url().Anch_str());
|
||||
Page__async__bgn(tab);
|
||||
}
|
||||
public void Page__async__bgn(Xog_tab_itm tab) {
|
||||
@@ -252,8 +255,8 @@ public class Xog_win_itm implements GfoInvkAble, GfoEvObj {
|
||||
Xoae_page new_page = Xoae_page.new_(home_wiki, ttl);
|
||||
gplx.xowa.servers.Gxw_html_server.Assert_tab(app, new_page); // HACK: assert at least 1 tab for Firefox addon; DATE:2015-01-23
|
||||
this.Active_page_(new_page);
|
||||
Xoa_url url = Xoa_url.blank_();
|
||||
url = Xoa_url_parser.Parse_url(url, app, home_wiki, url_bry, 0, url_bry.length, true);
|
||||
Xoa_url url = Xoa_url.blank();
|
||||
url = home_wiki.Utl__url_parser().Parse(url_bry);
|
||||
new_page.Url_(url);
|
||||
return App__retrieve_by_href(url, output_html);
|
||||
}
|
||||
@@ -261,7 +264,7 @@ public class Xog_win_itm implements GfoInvkAble, GfoEvObj {
|
||||
public byte[] App__retrieve_by_href(String href, boolean output_html) {return App__retrieve_by_href(Xog_url_wkr.Exec_url(this, href), output_html);} // NOTE: used by drd
|
||||
private byte[] App__retrieve_by_href(Xoa_url url, boolean output_html) {
|
||||
if (url == null) return Bry_.new_a7("missing");
|
||||
Xowe_wiki wiki = app.Wiki_mgr().Get_by_key_or_null(url.Wiki_bry());
|
||||
Xowe_wiki wiki = (Xowe_wiki)app.Wiki_mgr().Get_by_key_or_make_init_y(url.Wiki_bry());
|
||||
Xoa_ttl ttl = Xoa_ttl.parse_(wiki, url.Page_bry());
|
||||
Xoae_page new_page = wiki.Load_page_by_ttl(url, ttl);
|
||||
if (new_page.Missing()) {return Bry_.Empty;}
|
||||
@@ -299,7 +302,7 @@ public class Xog_win_itm implements GfoInvkAble, GfoEvObj {
|
||||
|
||||
GfoEvMgr_.SubSame_many(this, this, Gfui_html.Evt_location_changed, Gfui_html.Evt_location_changing, Gfui_html.Evt_link_hover);
|
||||
GfoEvMgr_.SubSame(win_box, Gfui_html.Evt_win_resized, this);
|
||||
GfoEvMgr_.Sub(app.Gui_mgr().Win_cfg().Font(), Xol_font_info.Font_changed, this, Invk_window_font_changed);
|
||||
GfoEvMgr_.Sub(app.Gui_mgr().Win_cfg().Font(), Xol_font_info.Font_changed, this, Invk_window_font_changed);
|
||||
|
||||
if ( !Env_.Mode_testing()
|
||||
&& app.App_type().Uid_is_gui()) // only run for gui; do not run for tcp/http server; DATE:2014-05-03
|
||||
|
||||
@@ -18,8 +18,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
package gplx.xowa.gui.views; import gplx.*; import gplx.xowa.*; import gplx.xowa.gui.*;
|
||||
import gplx.gfui.*; import gplx.xowa.html.hrefs.*;
|
||||
public class Xog_win_itm__prog_href_mgr {
|
||||
private static Xoh_href tmp_href = new Xoh_href();
|
||||
private static Bry_bfr tmp_bfr = Bry_bfr.reset_(512);
|
||||
public static void Print(Xog_win_itm win) { // PURPOSE: print href in prog box when in content editable mode
|
||||
String href = win.Active_html_box().Html_js_eval_proc_as_str(Xog_js_procs.Selection__get_active_for_editable_mode, Gfui_html.Atr_href, "");// get selected href from html_box
|
||||
href = Xoa_app_.Utl__encoder_mgr().Href().Decode_str(href); // remove url encodings
|
||||
@@ -33,8 +31,9 @@ public class Xog_win_itm__prog_href_mgr {
|
||||
usr_dlg.Prog_direct(""); // clear out previous entry
|
||||
return;
|
||||
}
|
||||
app.Href_parser().Parse(tmp_href, href, wiki, page.Ttl().Page_url());
|
||||
tmp_href.Print_to_bfr(tmp_bfr, !app.Api_root().Gui().Browser().Prog().Show_short_url());
|
||||
usr_dlg.Prog_direct(tmp_bfr.Xto_str_and_clear());
|
||||
Xoa_url url = Xoa_url.blank();
|
||||
app.Html__href_parser().Parse_as_url(url, Bry_.new_u8(href), wiki, page.Ttl().Page_txt());
|
||||
// Xoa_url url = wiki.Utl__url_parser().Parse(Bry_.new_u8(href));
|
||||
usr_dlg.Prog_direct(String_.new_u8(url.To_bry(!app.Api_root().Gui().Browser().Prog().Show_short_url(), Bool_.Y)));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
package gplx.xowa.html; import gplx.*; import gplx.xowa.*;
|
||||
public class Xoh_consts {
|
||||
public static final String
|
||||
Atr_xowa_title_str = "xowa_title"
|
||||
Atr_xowa_title_str = "xowa_title"
|
||||
, Img_w_str = "width"
|
||||
, Img_h_str = "height"
|
||||
;
|
||||
@@ -31,14 +31,13 @@ public class Xoh_consts {
|
||||
, A_bgn = Bry_.new_a7("<a href=\""), A_bgn_lnki_0 = Bry_.new_a7("\" title=\""), A_mid_xowa_title = Bry_.new_a7("\" xowa_title=\"")
|
||||
, A_mid_id = Bry_.new_a7("\" id=\"xowa_lnki_")
|
||||
, A_end = Bry_.new_a7("</a>")
|
||||
|
||||
, Div_bgn_open = Bry_.new_a7("<div ")
|
||||
, Div_end = Bry_.new_a7("</div>")
|
||||
|
||||
, Img_bgn = Bry_.new_a7("<img src=\"")
|
||||
, Span_bgn_open = Bry_.new_a7("<span")
|
||||
, Span_end = Bry_.new_a7("</span>")
|
||||
, Span_bgn = Bry_.new_a7("<span>")
|
||||
, Img_bgn = Bry_.new_a7("<img src=\"")
|
||||
, Span_bgn_open = Bry_.new_a7("<span")
|
||||
, Span_end = Bry_.new_a7("</span>")
|
||||
, Span_bgn = Bry_.new_a7("<span>")
|
||||
|
||||
, Pre_bgn = Bry_.new_a7("<pre>"), Pre_end = Bry_.new_a7("</pre>")
|
||||
, Pre_bgn_open = Bry_.new_a7("<pre")
|
||||
@@ -53,6 +52,5 @@ public class Xoh_consts {
|
||||
, Style_atr = Bry_.new_a7(" style=\"")
|
||||
, Atr_xowa_title_bry = Bry_.new_a7(Atr_xowa_title_str)
|
||||
;
|
||||
|
||||
public static final int Nbsp_int = 160;
|
||||
}
|
||||
|
||||
@@ -19,17 +19,16 @@ package gplx.xowa.html; import gplx.*; import gplx.xowa.*;
|
||||
import gplx.xowa.html.tidy.*; import gplx.xowa.html.utils.*; import gplx.xowa.html.skins.*;
|
||||
public class Xoh_html_mgr implements GfoInvkAble {
|
||||
public Xoh_html_mgr(Xoae_app app) {
|
||||
page_mgr = new Xoh_page_mgr(app);
|
||||
js_cleaner = new Xoh_js_cleaner(app);
|
||||
}
|
||||
public void Init_by_app(Xoae_app app) {
|
||||
tidy_mgr.Init_by_app(app);
|
||||
}
|
||||
public Xop_xatr_whitelist_mgr Whitelist_mgr() {return whitelist_mgr;} private Xop_xatr_whitelist_mgr whitelist_mgr = new Xop_xatr_whitelist_mgr().Ini();
|
||||
public Xoh_page_mgr Page_mgr() {return page_mgr;} private Xoh_page_mgr page_mgr;
|
||||
public Xoh_tidy_mgr Tidy_mgr() {return tidy_mgr;} private Xoh_tidy_mgr tidy_mgr = new Xoh_tidy_mgr();
|
||||
public Xoh_js_cleaner Js_cleaner() {return js_cleaner;} private Xoh_js_cleaner js_cleaner;
|
||||
public Xoh_skin_mgr Skin_mgr() {return skin_mgr;} private Xoh_skin_mgr skin_mgr = new Xoh_skin_mgr();
|
||||
public Xop_xatr_whitelist_mgr Whitelist_mgr() {return whitelist_mgr;} private final Xop_xatr_whitelist_mgr whitelist_mgr = new Xop_xatr_whitelist_mgr().Ini();
|
||||
public Xoh_page_mgr Page_mgr() {return page_mgr;} private final Xoh_page_mgr page_mgr = new Xoh_page_mgr();
|
||||
public Xoh_tidy_mgr Tidy_mgr() {return tidy_mgr;} private final Xoh_tidy_mgr tidy_mgr = new Xoh_tidy_mgr();
|
||||
public Xoh_js_cleaner Js_cleaner() {return js_cleaner;} private final Xoh_js_cleaner js_cleaner;
|
||||
public Xoh_skin_mgr Skin_mgr() {return skin_mgr;} private final Xoh_skin_mgr skin_mgr = new Xoh_skin_mgr();
|
||||
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
|
||||
if (ctx.Match(k, Invk_page)) return page_mgr;
|
||||
else if (ctx.Match(k, Invk_tidy)) return tidy_mgr;
|
||||
|
||||
@@ -16,8 +16,8 @@ You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.html; import gplx.*; import gplx.xowa.*;
|
||||
import gplx.core.primitives.*;
|
||||
import gplx.core.btries.*; import gplx.html.*; import gplx.xowa.wikis.*; import gplx.xowa.net.*;
|
||||
import gplx.core.primitives.*; import gplx.core.net.*;
|
||||
import gplx.core.btries.*; import gplx.html.*; import gplx.xowa.wikis.*;
|
||||
import gplx.xowa.parsers.apos.*; import gplx.xowa.parsers.amps.*; import gplx.xowa.parsers.lnkes.*; import gplx.xowa.parsers.hdrs.*; import gplx.xowa.parsers.lists.*; import gplx.xowa.html.lnkis.*; import gplx.xowa.parsers.tblws.*; import gplx.xowa.parsers.paras.*;
|
||||
import gplx.xowa.xtns.*; import gplx.xowa.xtns.dynamicPageList.*; import gplx.xowa.xtns.math.*; import gplx.xowa.langs.vnts.*; import gplx.xowa.xtns.cite.*; import gplx.xowa.html.hzips.*;
|
||||
public class Xoh_html_wtr {
|
||||
@@ -633,7 +633,7 @@ class Xoh_display_ttl_wtr {
|
||||
Atr_key_style = Bry_.new_a7("style")
|
||||
, Msg_style_restricted = Bry_.new_a7(" style='/* attempt to bypass $wgRestrictDisplayTitle */'")
|
||||
;
|
||||
private Btrie_slim_mgr style_trie = Btrie_slim_mgr.ci_ascii_()
|
||||
private Btrie_slim_mgr style_trie = Btrie_slim_mgr.ci_a7()
|
||||
.Add_str_byte__many(Byte_.By_int(0), "display", "user-select", "visibility"); // if ( preg_match( '/(display|user-select|visibility)\s*:/i', $decoded['style'] ) ) {
|
||||
public boolean Is_style_restricted(Bry_bfr bfr, Xoh_wtr_ctx hctx, byte[] src, Xop_xatr_itm atr, byte[] atr_key) {
|
||||
if (atr_key != null
|
||||
|
||||
@@ -18,10 +18,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
package gplx.xowa.html; import gplx.*; import gplx.xowa.*;
|
||||
import gplx.xowa.html.portal.*;
|
||||
public class Xoh_page_mgr implements GfoInvkAble {
|
||||
public Xoh_page_mgr(Xoae_app app) {
|
||||
this.subpages_bldr = new Xoh_subpages_bldr(app);
|
||||
}
|
||||
public Xoh_subpages_bldr Subpages_bldr() {return subpages_bldr;} private Xoh_subpages_bldr subpages_bldr;
|
||||
public Xoh_subpages_bldr Subpages_bldr() {return subpages_bldr;} private final Xoh_subpages_bldr subpages_bldr = new Xoh_subpages_bldr();
|
||||
public boolean Font_enabled() {return font_enabled;} private boolean font_enabled = false;
|
||||
public void Font_enabled_(boolean v) {font_enabled = v;}
|
||||
public String Font_name() {return font_name;} private String font_name = "Arial";
|
||||
|
||||
@@ -67,11 +67,17 @@ public class Xoh_page_wtr_wkr implements Bry_fmtr_arg {
|
||||
byte[] page_content_sub = Xoh_page_wtr_wkr_.Bld_page_content_sub(app, wiki, page, tmp_bfr);
|
||||
byte[] js_edit_toolbar_bry = view_tid == Xopg_view_mode.Tid_edit ? wiki.Fragment_mgr().Html_js_edit_toolbar() : Bry_.Empty;
|
||||
Xow_portal_mgr portal_mgr = wiki.Html_mgr().Portal_mgr().Init_assert();
|
||||
byte[] page_name = Xoh_page_wtr_wkr_.Bld_page_name(tmp_bfr, page_ttl, null); // NOTE: page_name does not show display_title (<i>). always pass in null
|
||||
byte[] page_display = Xoh_page_wtr_wkr_.Bld_page_name(tmp_bfr, page_ttl, page.Html_data().Display_ttl());
|
||||
Xol_vnt_mgr vnt_mgr = wiki.Lang().Vnt_mgr();
|
||||
if (vnt_mgr.Enabled()) { // VNT
|
||||
page_name = vnt_mgr.Convert_text(wiki, page_name);
|
||||
page_display = vnt_mgr.Convert_text(wiki, page_display);
|
||||
}
|
||||
fmtr.Bld_bfr_many(html_bfr
|
||||
, root_dir_bry, Xoa_app_.Version, Xoa_app_.Build_date, app.Tcp_server().Running_str()
|
||||
, page.Revision_data().Id()
|
||||
, Xoh_page_wtr_wkr_.Bld_page_name(tmp_bfr, page_ttl, null) // NOTE: page_name does not show display_title (<i>). always pass in null
|
||||
, Xoh_page_wtr_wkr_.Bld_page_name(tmp_bfr, page_ttl, page.Html_data().Display_ttl())
|
||||
, page_name, page_display
|
||||
, page_modified_on_msg
|
||||
, mgr.Css_common_bry(), mgr.Css_wiki_bry(), page.Html_data().Head_mgr().Init(app, wiki, page).Init_dflts()
|
||||
, page.Lang().Dir_ltr_bry(), page.Html_data().Indicators(), page_content_sub, wiki.Html_mgr().Portal_mgr().Div_jump_to(), page_body_class, html_content_editable
|
||||
@@ -123,9 +129,6 @@ public class Xoh_page_wtr_wkr implements Bry_fmtr_arg {
|
||||
boolean tidy_enabled = tidy_mgr.Enabled();
|
||||
Bry_bfr hdom_bfr = tidy_enabled ? app.Utl__bfr_mkr().Get_m001() : bfr; // if tidy, then write to tidy_bfr; note that bfr already has <html> and <head> written to it, so this can't be passed to tidy; DATE:2014-06-11
|
||||
wiki.Html_mgr().Html_wtr().Write_all(hdom_bfr, page.Wikie().Ctx(), hctx, page.Root().Data_mid(), page.Root());
|
||||
// Xol_vnt_mgr vnt_mgr = wiki.Lang().Vnt_mgr();
|
||||
// if (vnt_mgr.Enabled()) // VNT
|
||||
// hdom_bfr.Add(vnt_mgr.Convert_text(wiki, hdom_bfr.Xto_bry_and_clear()));
|
||||
if (tidy_enabled) {
|
||||
tidy_mgr.Run_tidy_html(page, hdom_bfr);
|
||||
bfr.Add_bfr_and_clear(hdom_bfr);
|
||||
@@ -145,6 +148,9 @@ public class Xoh_page_wtr_wkr implements Bry_fmtr_arg {
|
||||
else
|
||||
wiki.Html_mgr().Ctg_mgr().Bld(bfr, page, ctgs_len);
|
||||
}
|
||||
Xol_vnt_mgr vnt_mgr = wiki.Lang().Vnt_mgr();
|
||||
if (vnt_mgr.Enabled()) // VNT
|
||||
bfr.Add(vnt_mgr.Convert_text(wiki, bfr.Xto_bry_and_clear()));
|
||||
}
|
||||
private void Write_body_pre(Bry_bfr bfr, Xoae_app app, Xowe_wiki wiki, byte[] data_raw, Bry_bfr tmp_bfr) {
|
||||
Xoh_html_wtr_escaper.Escape(app.Parser_amp_mgr(), tmp_bfr, data_raw, 0, data_raw.length, false, false);
|
||||
|
||||
@@ -53,7 +53,7 @@ class Xoh_ctg_itm_fmtr implements Bry_fmtr_arg {
|
||||
for (int i = 0; i < ctgs_len; i++) {
|
||||
byte[] page_name = page.Category_list()[i];
|
||||
tmp_bfr.Add(ctg_prefix).Add(page_name);
|
||||
page.Wikie().Appe().Href_parser().Build_to_bfr(tmp_href, app, wiki.Domain_bry(), wiki.Ttl_parse(tmp_bfr.Xto_bry_and_clear()));
|
||||
page.Wikie().Appe().Html__href_wtr().Build_to_bfr(tmp_href, app, wiki.Domain_bry(), wiki.Ttl_parse(tmp_bfr.Xto_bry_and_clear()));
|
||||
itm_fmtr.Bld_bfr(bfr, tmp_href.Xto_bry_and_clear(), page_name, page_name);
|
||||
}
|
||||
tmp_bfr.Mkr_rls();
|
||||
|
||||
@@ -18,7 +18,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
package gplx.xowa.html.bridges; import gplx.*; import gplx.xowa.*; import gplx.xowa.html.*;
|
||||
import gplx.core.json.*;
|
||||
public class Bridge_cmd_mgr {
|
||||
private final Hash_adp_bry cmd_hash = Hash_adp_bry.cs_();
|
||||
private final Hash_adp_bry cmd_hash = Hash_adp_bry.cs();
|
||||
public void Add(Bridge_cmd_itm cmd) {cmd_hash.Add_bry_obj(cmd.Key(), cmd);}
|
||||
public String Exec(GfoMsg m) {
|
||||
if (m.Args_count() == 0) throw Err_.new_("bridge.cmds", "no json specified for json_exec");
|
||||
|
||||
@@ -18,7 +18,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
package gplx.xowa.html.bridges.dbuis; import gplx.*; import gplx.xowa.*; import gplx.xowa.html.*; import gplx.xowa.html.bridges.*;
|
||||
import gplx.core.json.*; import gplx.xowa.html.bridges.dbuis.tbls.*;
|
||||
public class Dbui_cmd_mgr {
|
||||
private final Hash_adp_bry hash = Hash_adp_bry.cs_();
|
||||
private final Hash_adp_bry hash = Hash_adp_bry.cs();
|
||||
private boolean init;
|
||||
public void Init_by_bridge(Bridge_cmd_mgr cmd_mgr) {
|
||||
if (init) return;
|
||||
|
||||
@@ -41,7 +41,7 @@ class Dbui_head_cell_fmtr implements Bry_fmtr_arg {
|
||||
Dbui_col_itm col = cols[i];
|
||||
fmtr.Bld_bfr_many(bfr, col.Width(), col.Display());
|
||||
}
|
||||
bfr.Add_str_a7("\n <div class='xo_head xo_resizable_col' style='width:35px;'> </div>"); // btns headers
|
||||
bfr.Add_str_a7("\n <div class='xo_head xo_resizable_col' style='width:50px;'> </div>"); // btns headers
|
||||
}
|
||||
private static final Bry_fmtr fmtr = Bry_fmtr.new_(String_.Concat_lines_nl_skip_last
|
||||
( ""
|
||||
|
||||
@@ -51,7 +51,7 @@ public class Xohd_hdump_wtr {
|
||||
public void Generate_hdump(Bry_bfr tmp_bfr, Xoae_page page) {
|
||||
page.File_queue().Clear(); // need to reset uid to 0, else xowa_file_# will resume from last
|
||||
page_wtr_mgr.Wkr(Xopg_view_mode.Tid_read).Write_body(tmp_bfr, Xoh_wtr_ctx.Hdump, page);
|
||||
if (!Env_.Mode_testing()) page.Wikie().Html_mgr().Hzip_mgr().Write(tmp_bfr, new Xodump_stats_itm(), page.Url().Xto_full_bry(), tmp_bfr.Xto_bry_and_clear()); // hzip data;
|
||||
if (!Env_.Mode_testing()) page.Wikie().Html_mgr().Hzip_mgr().Write(tmp_bfr, new Xodump_stats_itm(), page.Url().To_bry_full_wo_qargs(), tmp_bfr.Xto_bry_and_clear()); // hzip data;
|
||||
page.Hdump_data().Body_(tmp_bfr.Xto_bry_and_clear()); // write to body bry
|
||||
}
|
||||
}
|
||||
|
||||
@@ -48,7 +48,7 @@ public class Xohd_abrv_ {
|
||||
, Html_redlink_end = Bry_.new_a7("'>")
|
||||
;
|
||||
public static Btrie_slim_mgr new_trie() {
|
||||
Btrie_slim_mgr rv = Btrie_slim_mgr.cs_();
|
||||
Btrie_slim_mgr rv = Btrie_slim_mgr.cs();
|
||||
trie_itm(rv, Tid_dir , Byte_ascii.Null , Key_dir);
|
||||
trie_itm(rv, Tid_img , Byte_ascii.Apos , Key_img);
|
||||
trie_itm(rv, Tid_img_style , Byte_ascii.Apos , Key_img_style);
|
||||
|
||||
@@ -80,8 +80,8 @@ public class Xohd_abrv_mgr {
|
||||
case Xohd_abrv_.Tid_hdr_end: return wkr__hdr.Write_end(bfr, hpg, uid, rv);
|
||||
}
|
||||
if (itm.Elem_is_xnde()) rv += 2; // if xnde, skip "/>"
|
||||
if (uid == bry_rdr.Or_int()) {usr_dlg.Warn_many("", "", "index is not a valid int; hpg=~{0} text=~{1}", hpg.Url().Xto_full_str_safe(), Bry_.Mid_safe(src, uid_bgn, uid_end)); return uid_end;}
|
||||
if (!Int_.Between(uid, 0, imgs_len)) {usr_dlg.Warn_many("", "", "index is out of range; hpg=~{0} idx=~{1} len=~{2}", hpg.Url().Xto_full_str_safe(), uid, imgs_len); return uid_end;}
|
||||
if (uid == bry_rdr.Or_int()) {usr_dlg.Warn_many("", "", "index is not a valid int; hpg=~{0} text=~{1}", hpg.Url().To_str(), Bry_.Mid_safe(src, uid_bgn, uid_end)); return uid_end;}
|
||||
if (!Int_.Between(uid, 0, imgs_len)) {usr_dlg.Warn_many("", "", "index is out of range; hpg=~{0} idx=~{1} len=~{2}", hpg.Url().To_str(), uid, imgs_len); return uid_end;}
|
||||
if (uid >= imgs.length) return rv;
|
||||
Xohd_data_itm__base img = imgs[uid];
|
||||
int img_view_w = img.Html_w();
|
||||
|
||||
@@ -54,10 +54,10 @@ public class Xob_hdump_bldr {
|
||||
private void Hzip_data(Xoae_page page) {
|
||||
Xowe_wiki wiki = page.Wikie();
|
||||
Xow_hzip_mgr hzip_mgr = wiki.Html_mgr().Hzip_mgr();
|
||||
page.File_queue().Clear(); // need to reset uid to 0, else xowa_file_# will resume from last
|
||||
wiki.Html_mgr().Page_wtr_mgr().Wkr(Xopg_view_mode.Tid_read).Write_body(tmp_bfr, Xoh_wtr_ctx.Hdump, page); // write to html again, except in hdump mode
|
||||
if (hzip_enabled) hzip_mgr.Write(tmp_bfr, stats_itm, page.Url().Xto_full_bry(), tmp_bfr.Xto_bry_and_clear()); // hzip data
|
||||
page.Hdump_data().Body_(tmp_bfr.Xto_bry_and_clear()); // write to body bry
|
||||
page.File_queue().Clear(); // need to reset uid to 0, else xowa_file_# will resume from last
|
||||
wiki.Html_mgr().Page_wtr_mgr().Wkr(Xopg_view_mode.Tid_read).Write_body(tmp_bfr, Xoh_wtr_ctx.Hdump, page); // write to html again, except in hdump mode
|
||||
if (hzip_enabled) hzip_mgr.Write(tmp_bfr, stats_itm, page.Url().To_bry_full_wo_qargs(), tmp_bfr.Xto_bry_and_clear()); // hzip data
|
||||
page.Hdump_data().Body_(tmp_bfr.Xto_bry_and_clear()); // write to body bry
|
||||
}
|
||||
}
|
||||
class Xob_ns_to_db_wkr__html implements Xob_ns_to_db_wkr {
|
||||
|
||||
@@ -25,7 +25,7 @@ public class Xohd_page_html_mgr__load {
|
||||
public void Load_page(Xow_wiki wiki, Xog_page hpg, Xowd_html_tbl tbl, int page_id, Xoa_ttl page_ttl) {
|
||||
Xoa_app_.Usr_dlg().Plog_many("", "", "hdump.load.text: ttl=~{0}", page_ttl.Full_db_as_str());
|
||||
tbl.Select_by_page(rows, page_id);
|
||||
Parse_rows(wiki, hpg, page_id, Xoa_url.blank_(), page_ttl, rows);
|
||||
Parse_rows(wiki, hpg, page_id, Xoa_url.blank(), page_ttl, rows);
|
||||
}
|
||||
public void Parse_rows(Xow_wiki wiki, Xog_page hpg, int page_id, Xoa_url page_url, Xoa_ttl page_ttl, List_adp rows) { // TEST:
|
||||
hpg.Init(wiki, page_id, page_url, page_ttl);
|
||||
|
||||
@@ -1,75 +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.html.hrefs; import gplx.*; import gplx.xowa.*; import gplx.xowa.html.*;
|
||||
public class Xoh_href {
|
||||
public byte[] Raw() {return raw;} public Xoh_href Raw_(byte[] v) {raw = v; return this;} private byte[] raw;
|
||||
public byte[] Wiki() {return wiki;} public Xoh_href Wiki_(byte[] v) {wiki = v; return this;} private byte[] wiki;
|
||||
public byte[] Page() {return page;} public Xoh_href Page_(byte[] v) {page = v; return this;} private byte[] page;
|
||||
public byte[] Anchor() {return anchor;} public Xoh_href Anchor_(byte[] v) {anchor = v; return this;} private byte[] anchor;
|
||||
public byte Tid() {return tid;} public Xoh_href Tid_(byte v) {tid = v; return this;} private byte tid;
|
||||
public byte[] Page_and_anchor() {
|
||||
if (Bry_.Len_eq_0(anchor)) return page;
|
||||
else if (Bry_.Len_eq_0(page)) return anchor;
|
||||
else return Bry_.Add_w_dlm(Byte_ascii.Hash, page, anchor);
|
||||
}
|
||||
public byte Protocol_tid() {return protocol_tid;} private byte protocol_tid;
|
||||
public void Init(byte[] raw, byte protocol_tid) {
|
||||
this.raw = raw; this.protocol_tid = protocol_tid;
|
||||
wiki = page = anchor = null;
|
||||
tid = Tid_null;
|
||||
}
|
||||
public void Print_to_bfr(Bry_bfr bfr, boolean full) { // currently used for status bar (not embedded in any html)
|
||||
switch (tid) {
|
||||
case Xoh_href.Tid_http: case Xoh_href.Tid_file: // full protocol; embed all; EX: "http://en.wikipedia.org/wiki/A"; "file:///C/dir/file.txt"
|
||||
bfr.Add(raw);
|
||||
break;
|
||||
case Xoh_href.Tid_xowa:
|
||||
bfr.Add(page);
|
||||
break;
|
||||
default:
|
||||
if (full) { // "full" can be copied and pasted into firefox url bar
|
||||
switch (tid) {
|
||||
case Xoh_href.Tid_wiki: case Xoh_href.Tid_site: case Xoh_href.Tid_anchor:
|
||||
bfr.Add(wiki); // add wiki_key; EX: "en.wikipedia.org"
|
||||
bfr.Add(Xoh_href_parser.Href_wiki_bry); // add wiki_str; EX: "/wiki/"
|
||||
bfr.Add(page); // add page; EX: "A"
|
||||
if (anchor != null)
|
||||
bfr.Add_byte(Byte_ascii.Hash).Add(anchor); // add anchor; EX: "#B"
|
||||
break;
|
||||
}
|
||||
}
|
||||
else {
|
||||
switch (tid) {
|
||||
case Xoh_href.Tid_site:
|
||||
bfr.Add(wiki).Add_byte(Byte_ascii.Slash); // add wiki_key; EX: "en.wikipedia.org/"
|
||||
bfr.Add(page); // add page; EX: "A"
|
||||
break;
|
||||
case Xoh_href.Tid_wiki:
|
||||
bfr.Add(page); // add page; EX: "A"
|
||||
break;
|
||||
case Xoh_href.Tid_anchor: // anchor to be added below
|
||||
break;
|
||||
}
|
||||
if (anchor != null)
|
||||
bfr.Add_byte(Byte_ascii.Hash).Add(anchor); // add anchor; EX: "#B"
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
public static final byte Tid_null = 0, Tid_http = 1, Tid_file = 2, Tid_wiki = 3, Tid_site = 4, Tid_xcmd = 5, Tid_anchor = 6, Tid_xowa = 7;
|
||||
}
|
||||
40
400_xowa/src/gplx/xowa/html/hrefs/Xoh_href_.java
Normal file
40
400_xowa/src/gplx/xowa/html/hrefs/Xoh_href_.java
Normal file
@@ -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.html.hrefs; import gplx.*; import gplx.xowa.*; import gplx.xowa.html.*;
|
||||
public class Xoh_href_ {
|
||||
public static final String
|
||||
Str__file = "file://"
|
||||
, Str__site = "/site/"
|
||||
, Str__wiki = "/wiki/"
|
||||
, Str__anch = "#"
|
||||
;
|
||||
public static final byte[]
|
||||
Bry__file = Bry_.new_a7(Str__file)
|
||||
, Bry__site = Bry_.new_a7(Str__site)
|
||||
, Bry__wiki = Bry_.new_a7(Str__wiki)
|
||||
, Bry__anch = Bry_.new_a7(Str__anch)
|
||||
, Bry__https = Bry_.new_a7("https://") // NOTE: must be "https:" or wmf api won't work; DATE:2015-06-17
|
||||
, Bry__xcmd = Bry_.new_a7("/xcmd/")
|
||||
;
|
||||
public static final int
|
||||
Len__file = Bry__file.length
|
||||
, Len__site = Bry__site.length
|
||||
, Len__wiki = Bry__wiki.length
|
||||
, Len__anch = Bry__anch.length
|
||||
;
|
||||
}
|
||||
94
400_xowa/src/gplx/xowa/html/hrefs/Xoh_href_gui_utl.java
Normal file
94
400_xowa/src/gplx/xowa/html/hrefs/Xoh_href_gui_utl.java
Normal file
@@ -0,0 +1,94 @@
|
||||
/*
|
||||
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.html.hrefs; import gplx.*; import gplx.xowa.*; import gplx.xowa.html.*;
|
||||
import gplx.core.btries.*; import gplx.core.primitives.*;
|
||||
public class Xoh_href_gui_utl {
|
||||
public static String Html_extract_text(String site, String page, String text_str) {
|
||||
byte[] text_bry = Bry_.new_u8(text_str);
|
||||
int text_len = text_bry.length;
|
||||
int text_tid = Byte_ascii.Xto_digit(text_bry[0]);
|
||||
switch (text_tid) {
|
||||
case Text_tid_none: return ""; // "0"
|
||||
case Text_tid_text: return String_.new_u8(text_bry, 2, text_len); // 2 to skip "1|"
|
||||
case Text_tid_href: break; // fall through to below
|
||||
default: throw Err_.new_unhandled(text_tid);
|
||||
}
|
||||
int href_bgn = 2; // 2 to skip "2|"
|
||||
if (Bry_.Has_at_bgn(text_bry, Xoh_href_.Bry__file, href_bgn, text_len))
|
||||
href_bgn += Xoh_href_.Len__file; // skip "file://"
|
||||
Byte_obj_val href_tid = (Byte_obj_val)href_trie.Match_bgn(text_bry, href_bgn, text_len);
|
||||
if (href_tid != null) {
|
||||
switch (href_tid.Val()) {
|
||||
case Href_tid_wiki: return site + String_.new_u8(text_bry, href_bgn, text_len);
|
||||
case Href_tid_site: return String_.new_u8(text_bry, href_bgn + 6, text_len); // +6 to skip "site/"
|
||||
case Href_tid_anch: return site + "/wiki/" + page + String_.new_u8(text_bry, href_bgn, text_len);
|
||||
}
|
||||
}
|
||||
return String_.new_u8(text_bry, 2, text_len); // 2 to skip "2|"; handles "http://" text as well as any fall-thru from above
|
||||
}
|
||||
public static String Standardize_xowa_link(String str) {
|
||||
byte[] bry = Bry_.new_u8(str);
|
||||
int skip = Skip_start_of_xowa_link(bry, bry.length, 0);
|
||||
return skip == 0 ? str : String_.Mid(str, skip);
|
||||
}
|
||||
private static int Skip_start_of_xowa_link(byte[] src, int src_len, int bgn) {
|
||||
if (!Bry_.Has_at_bgn(src, Xoh_href_.Bry__file, bgn, src_len)) return bgn; // does not start with "file://"
|
||||
int pos = bgn + Xoh_href_.Len__file; // skip "file://"
|
||||
Object tid_obj = href_trie.Match_bgn(src, pos, src_len);
|
||||
if (tid_obj == null) {
|
||||
return bgn; // if not a known xowa link, return original bgn;
|
||||
}
|
||||
switch (((Byte_obj_val)tid_obj).Val()) {
|
||||
case Href_tid_site: return pos;
|
||||
case Href_tid_wiki: return pos;
|
||||
case Href_tid_anch: return pos;
|
||||
default: throw Err_.new_unhandled(tid_obj);
|
||||
}
|
||||
}
|
||||
private static final byte Text_tid_none = 0, Text_tid_text = 1, Text_tid_href = 2;
|
||||
private static final byte Href_tid_wiki = 1, Href_tid_site = 2, Href_tid_anch = 3;
|
||||
private static final Btrie_slim_mgr href_trie = Btrie_slim_mgr.cs()
|
||||
.Add_bry_byte(Xoh_href_.Bry__site , Href_tid_site)
|
||||
.Add_bry_byte(Xoh_href_.Bry__wiki , Href_tid_wiki)
|
||||
.Add_bry_byte(Xoh_href_.Bry__anch , Href_tid_anch)
|
||||
;
|
||||
}
|
||||
/*
|
||||
NOTE_1:
|
||||
. swt/mozilla treats text differently in href="{text}" when content_editable=n; occurs in LocationListener.changing
|
||||
http://a.org -> http://a.org does nothing
|
||||
A -> file:///A adds "file:///"
|
||||
/wiki/A -> file:///wiki/A adds "file://"
|
||||
Category:A -> Category:A noops; Category is assumed to be protocol?
|
||||
//en.wiktionary.org/wiki/a -> file:///wiki/a strips out site name and prepends "file://"; no idea why
|
||||
|
||||
. so, to handle the above, the code does the following
|
||||
http://a.org -> http://a.org does nothing; nothing needed
|
||||
A -> /wiki/A always prepend /wiki/
|
||||
Category:A -> /wiki/Category:A always prepend /wiki/
|
||||
//en.wiktionary.org/wiki/A -> /site/en.wiktionary.org/wiki/A always transform relative url to /site/
|
||||
|
||||
. the href will still come here as file:///wiki/A or file:///site/en.wiktionary.org/wiki/A.
|
||||
. however, the file:// can be lopped off and discarded and the rest of the href will fall into one of the following cases
|
||||
.. /wiki/
|
||||
.. /site/
|
||||
.. /xcmd/
|
||||
.. #
|
||||
.. anything else -> assume to be really a file:// url; EX: file://C/dir/fil.txt -> C/dir/fil.txt
|
||||
. the other advantage of this approach is that this proc can be reused outside of swt calls; i.e.: it can parse both "file:///wiki/A" and "/wiki/A"
|
||||
*/
|
||||
@@ -15,11 +15,11 @@ 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.gui.views; import gplx.*; import gplx.xowa.*; import gplx.xowa.gui.*;
|
||||
package gplx.xowa.html.hrefs; import gplx.*; import gplx.xowa.*; import gplx.xowa.html.*;
|
||||
import org.junit.*;
|
||||
import gplx.core.primitives.*;
|
||||
public class Xog_html_itm_tst {
|
||||
@Before public void init() {fxt.Clear();} private Xog_html_itm_fxt fxt = new Xog_html_itm_fxt();
|
||||
import gplx.core.primitives.*; import gplx.xowa.html.hrefs.*; import gplx.xowa.gui.views.*;
|
||||
public class Xoh_href_gui_utl_tst {
|
||||
@Before public void init() {fxt.Clear();} private Xoh_href_gui_utl_fxt fxt = new Xoh_href_gui_utl_fxt();
|
||||
@Test public void Extract_href__text() {
|
||||
fxt.Test_extract_href("0|" , "");
|
||||
fxt.Test_extract_href("1|selected_text" , "selected_text");
|
||||
@@ -30,7 +30,7 @@ public class Xog_html_itm_tst {
|
||||
fxt.Test_extract_href("2|file:///wiki/Page_2" , "en.wikipedia.org/wiki/Page_2");
|
||||
fxt.Test_extract_href("2|file://#anchor" , "en.wikipedia.org/wiki/Page_0#anchor");
|
||||
}
|
||||
@Test public void Extract_href__internal() { //
|
||||
@Test public void Extract_href__internal() {
|
||||
fxt.Test_extract_href("2|/site/en.wiktionary.org/wiki/Page_1" , "en.wiktionary.org/wiki/Page_1");
|
||||
fxt.Test_extract_href("2|/wiki/Page_2" , "en.wikipedia.org/wiki/Page_2");
|
||||
fxt.Test_extract_href("2|#anchor" , "en.wikipedia.org/wiki/Page_0#anchor");
|
||||
@@ -39,16 +39,21 @@ public class Xog_html_itm_tst {
|
||||
fxt.Test_Html_window_vpos_parse("0|0,1,2", "0", "'0','1','2'");
|
||||
fxt.Test_Html_window_vpos_parse("org.eclipse.swt.SWTException: Permission denied for <file://> to get property Selection.rangeCount", null, null); // check that invalid path doesn't fail; DATE:2014-04-05
|
||||
}
|
||||
@Test public void Standardize_xowa_link() {
|
||||
fxt.Test_standardize_xowa_link("file:///site/en.wikipedia.org/wiki/A" , "/site/en.wikipedia.org/wiki/A");
|
||||
fxt.Test_standardize_xowa_link("file:///wiki/A" , "/wiki/A");
|
||||
fxt.Test_standardize_xowa_link("file://#A" , "#A");
|
||||
}
|
||||
}
|
||||
class Xog_html_itm_fxt {
|
||||
class Xoh_href_gui_utl_fxt {
|
||||
public void Clear() {
|
||||
cur_wiki = "en.wikipedia.org";
|
||||
cur_page = "Page_0";
|
||||
}
|
||||
public String Cur_wiki() {return cur_wiki;} public Xog_html_itm_fxt Cur_wiki_(String v) {cur_wiki = v; return this;} private String cur_wiki;
|
||||
public String Cur_page() {return cur_page;} public Xog_html_itm_fxt Cur_page_(String v) {cur_page = v; return this;} private String cur_page;
|
||||
public String Cur_wiki() {return cur_wiki;} public Xoh_href_gui_utl_fxt Cur_wiki_(String v) {cur_wiki = v; return this;} private String cur_wiki;
|
||||
public String Cur_page() {return cur_page;} public Xoh_href_gui_utl_fxt Cur_page_(String v) {cur_page = v; return this;} private String cur_page;
|
||||
public void Test_extract_href(String text_str, String expd) {
|
||||
Tfds.Eq(expd, Xog_html_itm__href_extractor.Html_extract_text(cur_wiki, cur_page, text_str));
|
||||
Tfds.Eq(expd, Xoh_href_gui_utl.Html_extract_text(cur_wiki, cur_page, text_str));
|
||||
}
|
||||
private String_obj_ref scroll_top = String_obj_ref.null_(), node_path = String_obj_ref.null_();
|
||||
public void Test_Html_window_vpos_parse(String raw, String expd_scroll_top, String expd_node_path) {
|
||||
@@ -57,4 +62,7 @@ class Xog_html_itm_fxt {
|
||||
Tfds.Eq(expd_scroll_top, scroll_top.Val(), expd_scroll_top);
|
||||
Tfds.Eq(expd_node_path, node_path.Val(), expd_node_path);
|
||||
}
|
||||
public void Test_standardize_xowa_link(String raw, String expd) {
|
||||
Tfds.Eq_str(expd, Xoh_href_gui_utl.Standardize_xowa_link(raw), "standardize");
|
||||
}
|
||||
}
|
||||
@@ -16,228 +16,64 @@ 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.html.hrefs; import gplx.*; import gplx.xowa.*; import gplx.xowa.html.*;
|
||||
import gplx.core.btries.*; import gplx.xowa.wikis.xwikis.*; import gplx.xowa.net.*; import gplx.xowa.parsers.lnkes.*;
|
||||
import gplx.xowa.wikis.*;
|
||||
import gplx.core.primitives.*; import gplx.core.btries.*; import gplx.core.net.*;
|
||||
import gplx.xowa.langs.vnts.*;
|
||||
public class Xoh_href_parser {
|
||||
private Gfo_url_parser url_parser; private Gfo_url tmp_url = new Gfo_url();
|
||||
private Btrie_slim_mgr segs = Btrie_slim_mgr.ci_ascii_(); // NOTE:ci.ascii:XO_const.en; /wiki/, /site/ etc.
|
||||
private Bry_bfr bfr_encoder = Bry_bfr.reset_(255), tmp_bfr = Bry_bfr.reset_(255);
|
||||
public Xoh_href_parser(Url_encoder encoder, Gfo_url_parser url_parser) {
|
||||
this.encoder = encoder;
|
||||
this.url_parser = url_parser;
|
||||
url_parser.Init_protocol(Protocol_xowa_tid, Xop_lnke_wkr.Str_xowa_protocol);
|
||||
segs.Add_stubs(Seg__ary);
|
||||
}
|
||||
public Url_encoder Encoder() {return encoder;} private Url_encoder encoder;
|
||||
public void Parse(Xoh_href rv, String raw, Xowe_wiki wiki, byte[] cur_page) {Parse(rv, Bry_.new_u8(raw), wiki, cur_page);}
|
||||
public void Parse(Xoh_href rv, byte[] raw, Xowe_wiki wiki, byte[] cur_page) {
|
||||
int bgn = 0, raw_len = raw.length; int file_slash_end = 0;
|
||||
url_parser.Parse(tmp_url, raw, 0, raw_len); // parse as regular tmp_url to get protocol
|
||||
rv.Init(raw, tmp_url.Protocol_tid());
|
||||
switch (tmp_url.Protocol_tid()) {
|
||||
default: // tmp_url is known protocol ("http:", "ftp:", etc); use it and exit; do not do any substitutions EX: http://en.wikipedia.org
|
||||
rv.Tid_(Xoh_href.Tid_http);
|
||||
return;
|
||||
case Xoo_protocol_itm.Tid_null: // unknown protocol ("unknown:A")or protocol-less ("A"); could be wiki-title or file-name; fall through to below
|
||||
public void Parse_as_url(Xoa_url rv, byte[] raw, Xowe_wiki wiki, byte[] cur_page) {
|
||||
int bgn = 0;
|
||||
Object seg_obj = btrie.Match_bgn(raw, bgn, raw.length); // match /wiki/ or /site/ or /xcmd/
|
||||
if (seg_obj == null) {
|
||||
Xol_vnt_mgr vnt_mgr = wiki.Lang().Vnt_mgr();
|
||||
if (vnt_mgr.Enabled() && raw[0] == Byte_ascii.Slash) {
|
||||
int slash_end = Bry_finder.Find_fwd(raw, Byte_ascii.Slash, 1);
|
||||
if (vnt_mgr.Vnt_grp().Has(Bry_.Mid(raw, 1, slash_end))) {
|
||||
raw = Bry_.Add(wiki.Domain_bry(), raw);
|
||||
}
|
||||
}
|
||||
}
|
||||
else { // something matched
|
||||
switch (((Byte_obj_val)seg_obj).Val()) {
|
||||
case Seg_xcmd_tid: // convert "/xcmd/a" to "xowa-cmd:a"
|
||||
raw = Bry_.Add(Gfo_protocol_itm.Bry_xcmd, Bry_.Mid(raw, btrie.Match_pos()));
|
||||
bgn = 0;
|
||||
break;
|
||||
case Seg_wiki_tid: // skip "/wiki/" or "/site/"
|
||||
case Seg_site_tid:
|
||||
bgn = btrie.Match_pos();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
wiki.Utl__url_parser().Parse(rv, raw, bgn, raw.length);
|
||||
switch (rv.Tid()) {
|
||||
case Xoa_url_.Tid_anch:
|
||||
rv.Wiki_bry_(wiki.Domain_bry());
|
||||
rv.Page_bry_(cur_page);
|
||||
break;
|
||||
case Xoo_protocol_itm.Tid_file: // tmp_url is "file:"; remove it; NOTE: swt/mozilla automatically prepends "file://" to any protocol-less links; see NOTE_1 below
|
||||
int file_proto_len = tmp_url.Protocol_bry().length;
|
||||
bgn = file_slash_end = Bry_.While_fwd(raw, Byte_ascii.Slash, file_proto_len, raw_len);
|
||||
if (file_slash_end - file_proto_len > 0) --bgn; // if at least 1 slash, include slash; this ensures that all strings which have "file://" stripped will start with a "/"; EX: file:///wiki -> "/wiki"; file://C -> "/C"
|
||||
case Xoa_url_.Tid_page:
|
||||
Xow_wiki ttl_wiki = wiki.App().Wiki_mgri().Get_by_key_or_make_init_n(rv.Wiki_bry());
|
||||
byte[] tmp_page = rv.Page_bry();
|
||||
if (rv.Page_is_main())
|
||||
tmp_page = ttl_wiki.Props().Main_page();
|
||||
else {
|
||||
if (tmp_page != null) {
|
||||
if (ttl_wiki != null) {
|
||||
Xoa_ttl ttl = ttl_wiki.Ttl_parse(tmp_page);
|
||||
if (ttl == null) // invalid ttl; null out page;
|
||||
tmp_page = Bry_.Empty;
|
||||
else
|
||||
tmp_page = ttl.Full_txt();
|
||||
}
|
||||
}
|
||||
}
|
||||
rv.Page_bry_(tmp_page);
|
||||
break;
|
||||
case Xoo_protocol_itm.Tid_xowa:
|
||||
bgn = file_slash_end = Bry_.While_fwd(raw, Byte_ascii.Slash, tmp_url.Protocol_bry().length, raw_len);
|
||||
rv.Tid_(Xoh_href.Tid_xowa);
|
||||
rv.Wiki_(wiki.Domain_bry()); // wiki is always the current wiki
|
||||
byte[] page = Xoa_app_.Utl__encoder_mgr().Gfs().Decode(Bry_.Mid(raw, bgn, raw_len));
|
||||
rv.Page_(page); // page is everything after "/xcmd/"; individual cmds will do further parsing; note that it should be decoded; EX: %20 -> " "; also note that anchor (#) or query params (?) are not parsed; the entire String will be reparsed later
|
||||
return;
|
||||
}
|
||||
if (file_slash_end < raw_len && raw[file_slash_end] == Byte_ascii.Hash) { // 1st character is anchor; extract and return
|
||||
rv.Tid_(Xoh_href.Tid_anchor);
|
||||
rv.Wiki_(wiki.Domain_bry()); // wiki is always current
|
||||
rv.Page_(cur_page); // page is always current
|
||||
rv.Anchor_(Bry_.Mid(raw, file_slash_end + 1, raw_len)); // +1 to skip #; i.e. Anchor should be "A" not "#A"
|
||||
return;
|
||||
}
|
||||
Object seg_obj = segs.Match_bgn(raw, bgn, raw_len); // match /wiki/ or /site/ or /xcmd/
|
||||
if (seg_obj == null) // nothing matched; assume file; EX: file:///C/dir/fil.txt -> /C/dir/fil.txt
|
||||
rv.Tid_(Xoh_href.Tid_file);
|
||||
else { // something matched;
|
||||
Btrie_itm_stub seg = (Btrie_itm_stub)seg_obj;
|
||||
bgn += seg.Val().length;
|
||||
switch (seg.Tid()) {
|
||||
case Seg_wiki_tid: Parse_wiki(rv, encoder, wiki, raw, bgn, raw_len); break;
|
||||
case Seg_site_tid: Parse_site(rv, encoder, wiki, raw, bgn, raw_len); break;
|
||||
case Seg_xcmd_tid: Parse_xcmd(rv, encoder, wiki, raw, bgn, raw_len); break;
|
||||
}
|
||||
}
|
||||
}
|
||||
public byte[] Build_to_bry(Xow_wiki wiki, Xoa_ttl ttl) {
|
||||
synchronized (tmp_bfr) {
|
||||
Build_to_bfr(tmp_bfr, wiki.App(), wiki.Domain_bry(), ttl, Bool_.N);
|
||||
return tmp_bfr.Xto_bry_and_clear();
|
||||
}
|
||||
}
|
||||
public void Build_to_bfr(Bry_bfr bfr, Xoa_app app, byte[] domain_bry, Xoa_ttl ttl) {Build_to_bfr(bfr, app, domain_bry, ttl, Bool_.N);}
|
||||
public void Build_to_bfr(Bry_bfr bfr, Xoa_app app, byte[] domain_bry, Xoa_ttl ttl, boolean force_site) {
|
||||
byte[] page = ttl.Full_txt_raw();
|
||||
Xow_xwiki_itm xwiki = ttl.Wik_itm();
|
||||
if (xwiki == null) // not an xwiki; EX: [[wikt:Word]]
|
||||
Build_to_bfr_page(ttl, page, 0); // write page only; NOTE: changed to remove leaf logic DATE:2014-09-07
|
||||
else { // xwiki; skip wiki and encode page only;
|
||||
byte[] wik_txt = ttl.Wik_txt();
|
||||
Build_to_bfr_page(ttl, page, wik_txt.length + 1);
|
||||
}
|
||||
if (xwiki == null) { // not an xwiki
|
||||
if (ttl.Anch_bgn() != 1) { // not an anchor-only; EX: "#A"
|
||||
if (force_site) { // popup parser always writes as "/site/"
|
||||
bfr.Add(Href_site_bry); // add "/site/"; EX: /site/
|
||||
bfr.Add(domain_bry); // add xwiki; EX: en_dict
|
||||
bfr.Add(Href_wiki_bry); // add "/wiki/"; EX: /wiki/
|
||||
}
|
||||
else
|
||||
bfr.Add(Href_wiki_bry); // add "/wiki/"; EX: /wiki/Page
|
||||
}
|
||||
else {} // anchor: noop
|
||||
}
|
||||
else { // xwiki
|
||||
if (app.Xwiki_mgr__missing(xwiki.Domain_bry())) { // xwiki is not offline; use http:
|
||||
Bry_fmtr url_fmtr = xwiki.Url_fmtr();
|
||||
if (url_fmtr == null) {
|
||||
bfr.Add(Href_https_bry); // add "https://"; EX: https://
|
||||
bfr.Add(xwiki.Domain_bry()); // add xwiki; EX: en_dict
|
||||
bfr.Add(Href_wiki_bry); // add "/wiki/"; EX: /wiki/
|
||||
}
|
||||
else { // url_fmtr exists; DATE:2015-04-22
|
||||
url_fmtr.Bld_bfr(bfr, bfr_encoder.Xto_bry_and_clear()); // use it and pass bfr_encoder for page_name;
|
||||
return;
|
||||
}
|
||||
}
|
||||
else { // xwiki is avaiable; use /site/
|
||||
bfr.Add(Href_site_bry); // add "/site/"; EX: /site/
|
||||
bfr.Add(xwiki.Domain_bry()); // add xwiki; EX: en_dict
|
||||
bfr.Add(Href_wiki_bry); // add "/wiki/"; EX: /wiki/
|
||||
}
|
||||
}
|
||||
bfr.Add_bfr_and_clear(bfr_encoder);
|
||||
}
|
||||
private void Build_to_bfr_page(Xoa_ttl ttl, byte[] ttl_full, int page_bgn) {
|
||||
int anch_bgn = Bry_finder.Find_fwd(ttl_full, Byte_ascii.Hash); // NOTE: cannot use Anch_bgn b/c Anch_bgn has bug with whitespace
|
||||
if (anch_bgn == Bry_.NotFound) // no anchor; just add page
|
||||
encoder.Encode(bfr_encoder, ttl_full, page_bgn, ttl_full.length);
|
||||
else { // anchor exists; check if anchor is preceded by ws; EX: [[A #b]] -> "/wiki/A#b"
|
||||
int page_end = Bry_finder.Find_bwd_last_ws(ttl_full, anch_bgn); // first 1st ws before #; handles multiple ws
|
||||
page_end = page_end == Bry_.NotFound ? anch_bgn : page_end; // if ws not found, use # pos; else use 1st ws pos
|
||||
encoder.Encode(bfr_encoder, ttl_full, page_bgn, page_end); // add page
|
||||
encoder.Encode(bfr_encoder, ttl_full, anch_bgn, ttl_full.length); // add anchor
|
||||
}
|
||||
}
|
||||
public static final String Href_file_str = "file:///", Href_wiki_str = "/wiki/", Href_site_str = "/site/", Href_xcmd_str = "/xcmd/";
|
||||
public static final byte[]
|
||||
Href_https_bry = Bry_.new_a7("https://") // NOTE: must be "https:" or wmf api won't work; DATE:2015-06-17
|
||||
, Href_file_bry = Bry_.new_a7(Href_file_str), Href_site_bry = Bry_.new_a7(Href_site_str), Href_wiki_bry = Bry_.new_a7(Href_wiki_str);
|
||||
|
||||
private static final int Href_wiki_len = Href_wiki_bry.length;
|
||||
static final byte Seg_null_tid = 0, Seg_wiki_tid = 1, Seg_site_tid = 2, Seg_xcmd_tid = 3;
|
||||
private static final byte[] Seg_null_bry = Bry_.new_a7("/null/"), Seg_wiki_bry = Bry_.new_a7(Href_wiki_str), Seg_site_bry = Bry_.new_a7(Href_site_str), Seg_xcmd_bry = Bry_.new_a7(Href_xcmd_str);
|
||||
private static final byte[][] Seg__ary = new byte[][] {Seg_null_bry, Seg_wiki_bry, Seg_site_bry, Seg_xcmd_bry};
|
||||
private static void Parse_wiki(Xoh_href rv, Url_encoder encoder, Xowe_wiki wiki, byte[] raw, int bgn, int len) {
|
||||
byte[] ttl_raw = Bry_.Mid(raw, bgn, len);
|
||||
Xoa_ttl ttl = wiki.Ttl_parse(ttl_raw);
|
||||
if (ttl == null) {
|
||||
Xoa_app_.Usr_dlg().Warn_many("xowa.href.parser", "invalid_wiki", "wiki href does not have valid title: ~{0}", String_.new_u8(raw, bgn, len));
|
||||
return;
|
||||
}
|
||||
if (ttl.Wik_itm() == null) { // standard href; EX: "/wiki/A"
|
||||
rv.Tid_(Xoh_href.Tid_wiki);
|
||||
rv.Wiki_(wiki.Domain_bry()); // wiki is always the current wiki
|
||||
}
|
||||
else { // embedded xwiki prefix; EX: "/wiki/fr:A"
|
||||
rv.Tid_(Xoh_href.Tid_site);
|
||||
rv.Wiki_(ttl.Wik_itm().Domain_bry()); // wiki is the xwiki prefix; EX: "en.wikpedia.org//wiki/fr:A" -> "fr.wikpedia.org/wiki/A"
|
||||
}
|
||||
byte[] page_bry = encoder.Decode(ttl.Full_txt()); // note that Full is everything except for ns, so it handles "fr:A" ("fr:" being treated as ns, so only "A" will be Full_txt)
|
||||
if (Bry_.Len_eq_0(page_bry)) // handle xwiki hrefs like "fr:"; EX: "/wiki/wikipedia:" on en.wikisource.org/Main Page
|
||||
page_bry = Xoa_page_.Main_page_bry_empty;
|
||||
// if (ttl.Qarg_bgn() != Bry_.NotFound)
|
||||
// rv.Qarg_(ttl.Qarg_txt());
|
||||
rv.Page_(page_bry); // add page; note that it should be decoded; EX: %20 -> " "; also note that anchor (#) or query params (?) are not parsed; the entire String will be reparsed later
|
||||
if (ttl.Anch_bgn() != Bry_.NotFound) rv.Anchor_(ttl.Anch_txt());
|
||||
}
|
||||
private static void Parse_site(Xoh_href rv, Url_encoder encoder, Xowe_wiki wiki, byte[] raw, int bgn, int len) { // /site/; EX: /site/fr.wikipedia.org/wiki/A
|
||||
int slash = Bry_finder.Find_fwd(raw, Byte_ascii.Slash, bgn, len); if (slash == Bry_.NotFound) throw Err_.new_wo_type("site href is missing slash", "snip", String_.new_u8(raw, bgn, len));
|
||||
rv.Tid_(Xoh_href.Tid_site);
|
||||
byte[] wiki_bry = Bry_.Mid(raw, bgn, slash); // wiki is text between "/site/" and next "/"
|
||||
Xow_xwiki_itm xwiki = wiki.Appe().Usere().Wiki().Xwiki_mgr().Get_by_key(wiki_bry); // NOTE: site may refer to alias in user_wiki; ex: /site/wikisource.org which points to en.wikisource.org; this occurs during lnke substitution; EX: [//wikisource.org Wikisource]
|
||||
if (xwiki != null) {
|
||||
wiki_bry = xwiki.Domain_bry();
|
||||
wiki = wiki.Appe().Wiki_mgr().Get_by_key_or_make(wiki_bry); // NOTE: xwiki links should use case_match of xwiki (en.wiktionary.org) not cur_wiki (en.wikipedia.org); EX:w:alphabet
|
||||
}
|
||||
rv.Wiki_(wiki_bry);
|
||||
int page_pos = slash + Href_wiki_len;
|
||||
byte[] page_bry = page_pos < len
|
||||
? Bry_.Mid(raw, page_pos, len) // page is text after next "/" + "/wiki/";
|
||||
: Bry_.Empty;
|
||||
if (Bry_.Len_eq_0(page_bry)) // handle "/site/fr.wikipedia.org/wiki/"; note that these are generated by [[fr:]]
|
||||
page_bry = wiki.Props().Main_page(); // default to Main Page
|
||||
// int qarg_pos = Bry_finder.Find_bwd(page_bry, Byte_ascii.Question);
|
||||
// byte[] qarg_bry = null;
|
||||
// if (qarg_pos != Bry_.NotFound) {
|
||||
// qarg_bry = Bry_.Mid(page_bry, qarg_pos + 1, page_bry.length);
|
||||
// rv.Qarg_(qarg_bry);
|
||||
// page_bry = Bry_.Mid(page_bry, 0, qarg_pos);
|
||||
// }
|
||||
Parse_ttl_and_resolve_xwiki(rv, wiki, encoder, page_bry, raw, bgn, len);
|
||||
}
|
||||
private static void Parse_ttl_and_resolve_xwiki(Xoh_href rv, Xowe_wiki wiki, Url_encoder encoder, byte[] page_bry, byte[] raw, int bgn, int len) {
|
||||
Xoa_ttl ttl = wiki.Ttl_parse(page_bry);
|
||||
if (ttl == null) {
|
||||
Xoa_app_.Usr_dlg().Warn_many("xowa.href.parser", "invalid_wiki", "wiki href does not have valid title: ~{0}", String_.new_u8(raw, bgn, len));
|
||||
rv.Page_(Bry_.Empty);
|
||||
return;
|
||||
}
|
||||
if (ttl.Wik_itm() != null) { // page_bry has xwiki; EX: "wikt:A"; note that since this is called by "/site/", there may be two xwikis; EX: "w:wikt:"; Note that more than 2 is not being handled
|
||||
wiki = wiki.Appe().Wiki_mgr().Get_by_key_or_make(ttl.Wik_itm().Domain_bry());
|
||||
rv.Wiki_(wiki.Domain_bry());
|
||||
if (Bry_.Len_eq_0(ttl.Page_txt())) // page_bry is just alias; EX: "wikt:"
|
||||
page_bry = wiki.Props().Main_page();
|
||||
else
|
||||
page_bry = ttl.Page_txt();
|
||||
ttl = Xoa_ttl.parse_(wiki, page_bry); if (ttl == null) throw Err_.new_wo_type("wiki href does not have valid title", "ttl", String_.new_u8(raw, bgn, len));
|
||||
}
|
||||
rv.Page_(encoder.Decode(ttl.Full_txt())); // add page; note that it should be decoded; EX: %20 -> " "; also note that anchor (#) or query params (?) are not parsed; the entire String will be reparsed later
|
||||
if (ttl.Anch_bgn() != Bry_.NotFound) // add anchor if it exists
|
||||
rv.Anchor_(ttl.Anch_txt());
|
||||
}
|
||||
private static void Parse_xcmd(Xoh_href rv, Url_encoder encoder, Xowe_wiki wiki, byte[] raw, int bgn, int len) { // /xcmd/; note encoder is passed, but don't decode for now; most invk commands have an _ which will get changed to a " ";
|
||||
rv.Tid_(Xoh_href.Tid_xcmd);
|
||||
rv.Wiki_(wiki.Domain_bry()); // wiki is always the current wiki
|
||||
rv.Page_(Bry_.Mid(raw, bgn, len)); // page is everything after "/xcmd/"; individual cmds will do further parsing; note that it should be decoded; EX: %20 -> " "; also note that anchor (#) or query params (?) are not parsed; the entire String will be reparsed later
|
||||
}
|
||||
private static final byte Protocol_xowa_tid = Xoo_protocol_itm.Tid_xowa;
|
||||
private static final byte Seg_wiki_tid = 0, Seg_site_tid = 1, Seg_xcmd_tid = 2;
|
||||
private static final Btrie_slim_mgr btrie = Btrie_slim_mgr.ci_a7() // NOTE:ci.ascii:XO_const.en; /wiki/, /site/ etc.
|
||||
.Add_bry_tid(Xoh_href_.Bry__wiki, Seg_wiki_tid)
|
||||
.Add_bry_tid(Xoh_href_.Bry__site, Seg_site_tid)
|
||||
.Add_bry_tid(Xoh_href_.Bry__xcmd, Seg_xcmd_tid);
|
||||
}
|
||||
/*
|
||||
NOTE_1:
|
||||
. swt/mozilla treats text differently in href="{text}" when content_editable=n; occurs in LocationListener.changing
|
||||
http://a.org -> http://a.org does nothing
|
||||
A -> file:///A adds "file:///"
|
||||
/wiki/A -> file:///wiki/A adds "file://"
|
||||
Category:A -> Category:A noops; Category is assumed to be protocol?
|
||||
//en.wiktionary.org/wiki/a -> file:///wiki/a strips out site name and prepends "file://"; no idea why
|
||||
|
||||
. so, to handle the above, the code does the following
|
||||
http://a.org -> http://a.org does nothing; nothing needed
|
||||
A -> /wiki/A always prepend /wiki/
|
||||
Category:A -> /wiki/Category:A always prepend /wiki/
|
||||
//en.wiktionary.org/wiki/A -> /site/en.wiktionary.org/wiki/A always transform relative url to /site/
|
||||
|
||||
. the href will still come here as file:///wiki/A or file:///site/en.wiktionary.org/wiki/A.
|
||||
. however, the file:// can be lopped off and discarded and the rest of the href will fall into one of the following cases
|
||||
.. /wiki/
|
||||
.. /site/
|
||||
.. /xcmd/
|
||||
.. #
|
||||
.. anything else -> assume to be really a file:// url; EX: file://C/dir/fil.txt -> C/dir/fil.txt
|
||||
. the other advantage of this approach is that this proc can be reused outside of swt calls; i.e.: it can parse both "file:///wiki/A" and "/wiki/A"
|
||||
*/
|
||||
|
||||
@@ -16,234 +16,103 @@ 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.html.hrefs; import gplx.*; import gplx.xowa.*; import gplx.xowa.html.*;
|
||||
import org.junit.*;
|
||||
import gplx.xowa.net.*;
|
||||
public class Xoh_href_parser_tst {
|
||||
@Before public void init() {fxt.Clear();} private Xoh_href_parser_fxt fxt = new Xoh_href_parser_fxt();
|
||||
@Test public void Parse_full_wiki() {
|
||||
fxt .Prep_raw_("file:///wiki/A")
|
||||
.Expd_tid_(Xoh_href.Tid_wiki)
|
||||
.Expd_full_("en.wikipedia.org/wiki/A")
|
||||
.Expd_wiki_("en.wikipedia.org")
|
||||
.Expd_page_("A")
|
||||
.Test_parse();
|
||||
import org.junit.*; import gplx.xowa.urls.*;
|
||||
public class Xoh_href_parser_tst {
|
||||
private final Xoh_href_parser_fxt fxt = new Xoh_href_parser_fxt();
|
||||
@Test public void Wiki__basic() {
|
||||
fxt.Run_parse_by_href("/wiki/A").Chk_tid(Xoa_url_.Tid_page).Chk_to_str("en.wikipedia.org/wiki/A").Chk_wiki("en.wikipedia.org").Chk_page("A");
|
||||
}
|
||||
@Test public void Parse_full_http() {
|
||||
fxt .Prep_raw_("http://a.org/b")
|
||||
.Expd_tid_(Xoh_href.Tid_http)
|
||||
.Expd_full_("http://a.org/b")
|
||||
.Test_parse();
|
||||
@Test public void Wiki__page__w_question() {
|
||||
fxt.Run_parse_by_href("/wiki/%3F").Chk_page("?");
|
||||
}
|
||||
@Test public void Parse_full_file() {
|
||||
fxt .Prep_raw_("file:///C/xowa/file/a.png")
|
||||
.Expd_tid_(Xoh_href.Tid_file)
|
||||
.Expd_full_("file:///C/xowa/file/a.png")
|
||||
.Test_parse();
|
||||
@Test public void Wiki__qarg() {
|
||||
fxt.Run_parse_by_href("/wiki/A?action=edit").Chk_page("A").Chk_qargs("?action=edit").Chk_to_str("en.wikipedia.org/wiki/A?action=edit");
|
||||
}
|
||||
@Test public void Parse_full_anchor_only() {
|
||||
fxt .Prep_raw_("#a")
|
||||
.Expd_tid_(Xoh_href.Tid_anchor)
|
||||
.Expd_full_("en.wikipedia.org/wiki/Page 1#a")
|
||||
.Expd_anch_("a")
|
||||
.Test_parse();
|
||||
@Test public void Wiki__qarg__w_question() {
|
||||
fxt.Run_parse_by_href("/wiki/A%3F?action=edit").Chk_page("A?").Chk_qargs("?action=edit");
|
||||
}
|
||||
@Test public void Parse_full_anchor_w_page() {
|
||||
fxt .Prep_raw_("file:///wiki/A#b")
|
||||
.Expd_tid_(Xoh_href.Tid_wiki)
|
||||
.Expd_full_("en.wikipedia.org/wiki/A#b")
|
||||
.Expd_anch_("b")
|
||||
.Test_parse();
|
||||
@Test public void Wiki__anchor() {
|
||||
fxt.Run_parse_by_href("/wiki/A#b").Chk_to_str("en.wikipedia.org/wiki/A#b").Chk_anch("b");
|
||||
}
|
||||
@Test public void Parse_full_xwiki() {
|
||||
fxt .Prep_raw_("file:///site/en.wikt.org/wiki/Page")
|
||||
.Expd_tid_(Xoh_href.Tid_site)
|
||||
.Expd_full_("en.wikt.org/wiki/Page")
|
||||
.Expd_page_("Page")
|
||||
.Test_parse();
|
||||
@Test public void Wiki__xwiki__only() {
|
||||
fxt.Prep_add_xwiki_to_wiki("wikt", "en.wiktionary.org");
|
||||
fxt.Run_parse_by_href("/wiki/wikt:").Chk_page_is_main_y().Chk_page("Main_Page").Chk_to_str("en.wiktionary.org/wiki/Main_Page");
|
||||
}
|
||||
@Test public void Parse_full_xwiki_domain_only() {
|
||||
fxt .Prep_raw_("/wiki/wikt:")
|
||||
.Init_xwiki_alias("wikt", "en.wiktionary.org")
|
||||
.Expd_full_("en.wiktionary.org/wiki/")
|
||||
.Expd_page_("")
|
||||
.Test_parse();
|
||||
@Test public void Wiki__encoded() {
|
||||
fxt.Run_parse_by_href("/wiki/A%22b%22c").Chk_page("A\"b\"c");
|
||||
}
|
||||
@Test public void Parse_full_wiki_page() {
|
||||
fxt .Prep_raw_("/wiki/A")
|
||||
.Expd_tid_(Xoh_href.Tid_wiki)
|
||||
.Expd_full_("en.wikipedia.org/wiki/A")
|
||||
.Expd_page_("A")
|
||||
.Test_parse();
|
||||
@Test public void Site__basic() {
|
||||
fxt.Run_parse_by_href("/site/en.wikipedia.org/wiki/A").Chk_tid(Xoa_url_.Tid_page).Chk_to_str("en.wikipedia.org/wiki/A").Chk_page("A");
|
||||
}
|
||||
@Test public void Parse_empty_is_main_page() { // PURPOSE: w/ slash; "wiki/"
|
||||
fxt .Prep_raw_("/site/en.wikipedia.org/wiki/")
|
||||
.Expd_tid_(Xoh_href.Tid_site)
|
||||
.Expd_full_("en.wikipedia.org/wiki/Main Page")
|
||||
.Expd_page_("Main Page")
|
||||
.Test_parse();
|
||||
@Test public void Site__ns_case() {
|
||||
fxt.Run_parse_by_href("/site/en.wikipedia.org/wiki/file:A").Chk_page("File:A");
|
||||
}
|
||||
@Test public void Parse_empty_is_main_page_2() { // PURPOSE: wo slash; "wiki"
|
||||
fxt .Prep_raw_("/site/en.wikipedia.org/wiki")
|
||||
.Expd_tid_(Xoh_href.Tid_site)
|
||||
.Expd_full_("en.wikipedia.org/wiki/Main Page")
|
||||
.Expd_page_("Main Page")
|
||||
.Test_parse();
|
||||
@Test public void Site__main_page() {
|
||||
fxt.Run_parse_by_href("/site/en.wikipedia.org/wiki/").Chk_page("Main_Page").Chk_page_is_main_y();
|
||||
}
|
||||
@Test public void Parse_site_page() {
|
||||
fxt .Prep_raw_("/site/en.wikt.org/wiki/A")
|
||||
.Expd_tid_(Xoh_href.Tid_site)
|
||||
.Expd_full_("en.wikt.org/wiki/A")
|
||||
.Expd_page_("A")
|
||||
.Test_parse();
|
||||
@Test public void Site__anch() {
|
||||
fxt.Run_parse_by_href("/site/en.wikipedia.org/wiki/A#b_c").Chk_page("A").Chk_anch("b_c");
|
||||
}
|
||||
@Test public void Parse_site_ns_case() {
|
||||
fxt .Prep_raw_("/site/en.wikt.org/wiki/file:A")
|
||||
.Expd_tid_(Xoh_href.Tid_site)
|
||||
.Expd_full_("en.wikt.org/wiki/File:A")
|
||||
.Expd_page_("File:A")
|
||||
.Test_parse();
|
||||
@Test public void Site__qarg() {
|
||||
fxt.Run_parse_by_href("/site/en.wikipedia.org/wiki/A?action=edit").Chk_page("A").Chk_qargs("?action=edit");
|
||||
}
|
||||
@Test public void Parse_site_page__invalid_ttl_shouldnt_fail() { // PURPOSE: invalid title shouldn't fail; EX: A{{B}} is invalid (b/c of braces);
|
||||
fxt .Prep_raw_("/site/en.wikt.org/wiki/A{{B}}")
|
||||
.Expd_tid_(Xoh_href.Tid_site)
|
||||
.Expd_full_("en.wikt.org/wiki/")
|
||||
.Expd_page_("")
|
||||
.Test_parse();
|
||||
@Test public void Site__invalid_ttl_shouldnt_fail() { // PURPOSE: invalid title shouldn't fail; EX: A{{B}} is invalid (b/c of braces);
|
||||
fxt.Run_parse_by_href("/site/en.wikipedia.org/wiki/A{{B}}").Chk_page("");
|
||||
}
|
||||
@Test public void Parse_xcmd_edit() {
|
||||
fxt .Prep_raw_("/xcmd/page_edit")
|
||||
.Expd_tid_(Xoh_href.Tid_xcmd)
|
||||
.Expd_full_("")
|
||||
.Expd_page_("page_edit")
|
||||
.Test_parse();
|
||||
}
|
||||
@Test public void Parse_xowa() {
|
||||
fxt .Prep_raw_("xowa-cmd:a%22b*c")
|
||||
.Expd_tid_(Xoh_href.Tid_xowa)
|
||||
.Expd_full_("a\"b*c")
|
||||
.Expd_page_("a\"b*c")
|
||||
.Test_parse();
|
||||
}
|
||||
@Test public void Parse_edit_wiki_quote() {
|
||||
fxt .Prep_raw_("/wiki/A%22b%22c")
|
||||
.Expd_tid_(Xoh_href.Tid_wiki)
|
||||
.Expd_full_("en.wikipedia.org/wiki/A\"b\"c")
|
||||
.Expd_page_("A\"b\"c")
|
||||
.Test_parse();
|
||||
}
|
||||
|
||||
@Test public void Hover_string_wiki() {fxt.Init_hover_full_n_().Test_hover_string("file:///wiki/A" , "A");}
|
||||
@Test public void Hover_string_http() {fxt.Init_hover_full_n_().Test_hover_string("http://a.org/b" , "http://a.org/b");}
|
||||
@Test public void Hover_string_file() {fxt.Init_hover_full_n_().Test_hover_string("file:///C/xowa/file/a.png" , "file:///C/xowa/file/a.png");}
|
||||
@Test public void Hover_string_anchor() {fxt.Init_hover_full_n_().Test_hover_string("#a" , "#a");}
|
||||
@Test public void Hover_string_anchor_file() {fxt.Init_hover_full_n_().Test_hover_string("file:///#a" , "#a");}
|
||||
@Test public void Hover_string_xwiki() {fxt.Init_hover_full_n_().Test_hover_string("file:///site/en.wikt.org/wiki/Page" , "en.wikt.org/Page");}
|
||||
@Test public void Hover_string_xwiki_2() {fxt.Init_hover_full_n_().Expd_page_("a").Test_hover_string("/wiki/wikt:a" , "en.wiktionary.org/a");}
|
||||
@Test public void Hover_string_error() {fxt.Init_hover_full_n_().Test_hover_string("file:///wiki/{{{extlink}}}" , "");} // {{{extlink}}} not a valid title; return empty
|
||||
// @Test public void Parse_site_qarg() {fxt.Prep_raw_("/site/en.wikt.org/wiki/A?action=edit").Expd_tid_(Xoh_href.Tid_site).Expd_full_("en.wikt.org/wiki/A").Expd_page_("A").Expd_qarg_("action=edit").Test_parse();}
|
||||
// @Test public void Parse_wiki_qarg() {fxt.Prep_raw_("/wiki/A?action=edit").Expd_tid_(Xoh_href.Tid_wiki).Expd_full_("en.wikipedia.org/wiki/A").Expd_page_("A").Expd_qarg_("action=edit").Test_parse();}
|
||||
//@Test public void Parse_site_anchor() {fxt.Prep_raw_("/site/en.wikt.org/wiki/A#b_c" ).Expd_tid_(Xoh_href.Tid_site).Expd_full_("en.wikt.org/wiki/A#b_c").Expd_page_("A").Expd_anch_("b_c").Test_parse();}
|
||||
@Test public void Build_xwiki_enc() {fxt.Test_build("wikt:abc?d" , "/site/en.wiktionary.org/wiki/abc%3Fd");}
|
||||
@Test public void Build_page_quote() {fxt.Test_build("a\"b\"c" , "/wiki/A%22b%22c");}
|
||||
@Test public void Build_page() {fxt.Test_build("abc" , "/wiki/Abc");}
|
||||
@Test public void Build_page_ns() {fxt.Test_build("Image:A.png" , "/wiki/Image:A.png");}
|
||||
@Test public void Build_anchor() {fxt.Test_build("#abc" , "#abc");}
|
||||
@Test public void Build_page_anchor() {fxt.Test_build("Abc#def" , "/wiki/Abc#def");}
|
||||
@Test public void Build_xwiki() {fxt.Test_build("wikt:abc" , "/site/en.wiktionary.org/wiki/abc");} // NOTE: "abc" not capitalized, b/c other wiki's case sensitivity is not known; this emulates WP's behavior
|
||||
@Test public void Build_xwiki_2() {fxt.Test_build("wikt:Special:Search/a" , "/site/en.wiktionary.org/wiki/Special:Search/a");}
|
||||
@Test public void Build_category() {fxt.Test_build("Category:abc" , "/wiki/Category:Abc");}
|
||||
|
||||
@Test public void Parse_site_user_wiki() {// PURPOSE: outlier for wikisource.org which is alias to en.wikisource.org; alias added in user_wiki; EX: [//wikisource.org a]; in browser, automatically goes to http://wikisource.org; in xowa, should go to /site/en.wikisource.org
|
||||
fxt .Prep_raw_("/site/en_wiki_alias/wiki/")
|
||||
.Init_xwiki_alias("en_wiki_alias", "en.wikipedia.org")
|
||||
.Expd_tid_(Xoh_href.Tid_site)
|
||||
.Expd_full_("en.wikipedia.org/wiki/Main Page")
|
||||
.Expd_page_("Main Page")
|
||||
.Test_parse();
|
||||
}
|
||||
@Test public void Parse_xwiki_cases_correctly() { // PURPOSE: xwiki links should use case_match of xwiki (en.wiktionary.org) not cur_wiki (en.wikipedia.org); EX:w:Alphabet
|
||||
fxt .Prep_raw_("/site/en.wiktionary.org/wiki/alphabet")
|
||||
.Init_xwiki_alias("en.wiktionary.org", "en.wiktionary.org");
|
||||
Xowe_wiki en_wiktionary_org = fxt.App().Wiki_mgr().Get_by_key_or_make(Bry_.new_a7("en.wiktionary.org"));
|
||||
@Test public void Site__xwiki_cases_correctly() { // PURPOSE: xwiki links should use case_match of xwiki (en.wiktionary.org) not cur_wiki (en.wikipedia.org); EX:w:Alphabet
|
||||
Xowe_wiki en_wiktionary_org = fxt.Prep_create_wiki("en.wiktionary.org");
|
||||
en_wiktionary_org.Ns_mgr().Ns_main().Case_match_(Xow_ns_case_.Id_all);
|
||||
fxt .Expd_tid_(Xoh_href.Tid_site)
|
||||
.Expd_full_("en.wiktionary.org/wiki/alphabet")
|
||||
.Expd_page_("alphabet")
|
||||
.Test_parse();
|
||||
fxt.Prep_add_xwiki_to_user("en.wiktionary.org", "en.wiktionary.org");
|
||||
fxt.Run_parse_by_href("/site/en.wiktionary.org/wiki/alphabet");
|
||||
fxt.Chk_to_str("en.wiktionary.org/wiki/alphabet").Chk_page("alphabet");
|
||||
}
|
||||
@Test public void Parse_xwiki_compound() { // PURPOSE: [[[w:wikt:]] not handled; DATE:2013-07-25
|
||||
fxt .Prep_raw_("/site/en.wikipedia.org/wiki/wikt:")
|
||||
.Init_xwiki_alias("wikt:", "en.wiktionary.org")
|
||||
.Expd_tid_(Xoh_href.Tid_site)
|
||||
.Expd_full_("en.wiktionary.org/wiki/Main Page")
|
||||
.Expd_page_("Main Page")
|
||||
.Test_parse();
|
||||
@Test public void Site__xwiki_compound() { // PURPOSE: [[[w:wikt:]] not handled; DATE:2013-07-25
|
||||
fxt.Prep_add_xwiki_to_wiki("wikt", "en.wiktionary.org");
|
||||
fxt.Run_parse_by_href("/site/en.wikipedia.org/wiki/wikt:")
|
||||
.Chk_tid(Xoa_url_.Tid_page)
|
||||
.Chk_page("Main_Page")
|
||||
.Chk_to_str("en.wiktionary.org/wiki/Main_Page")
|
||||
;
|
||||
}
|
||||
@Test public void Parse_protocol() { // PURPOSE: check that urls with form of "ftp://" return back Tid_ftp; DATE:2014-04-25
|
||||
fxt .Test_parse_protocol("ftp://a.org", Xoo_protocol_itm.Tid_ftp);
|
||||
// @Test public void Vnt() {
|
||||
// Xowe_wiki wiki = fxt.Wiki();
|
||||
// fxt.Prep_add_xwiki_to_user("zh.wikipedia.org");
|
||||
// wiki.Lang().Vnt_mgr().Enabled_(true);
|
||||
// wiki.Lang().Vnt_mgr().Vnt_grp().Add(new gplx.xowa.langs.vnts.Vnt_mnu_itm(Bry_.new_a7("zh-hans"), Bry_.new_a7("zh-hant")));
|
||||
// fxt.Run_parse_by_href("/site/zh.wikipedia.org/zh-hant/A").Chk_page("A").Chk_vnt("zh-hant");
|
||||
// }
|
||||
@Test public void Http__basic() {
|
||||
fxt.Run_parse_by_href("http://a.org/b").Chk_tid(Xoa_url_.Tid_inet);
|
||||
}
|
||||
@Test public void Build_xwiki_wikimedia_mail() { // PURPOSE: DATE:2015-04-22
|
||||
fxt .Init_xwiki_by_many("mail|https://lists.wikimedia.org/mailman/listinfo/$1|Wikitech Mailing List");
|
||||
fxt.Test_build("mail:A" , "https://lists.wikimedia.org/mailman/listinfo/A");
|
||||
@Test public void Prot__ftp() { // PURPOSE: check that urls with form of "ftp://" return back Tid_ftp; DATE:2014-04-25
|
||||
fxt.Run_parse_by_href("ftp://a.org").Chk_tid(Xoa_url_.Tid_inet);
|
||||
}
|
||||
// @Test public void Parse_question_ttl() {fxt.Prep_raw_("/wiki/%3F").Expd_tid_(Xoh_href.Tid_wiki).Expd_full_("en.wikipedia.org/wiki/?").Expd_page_("?").Test_parse();}
|
||||
// @Test public void Parse_question_w_arg() {fxt.Prep_raw_("/wiki/A%3F?action=edit").Expd_tid_(Xoh_href.Tid_wiki).Expd_full_("en.wikipedia.org/wiki/A??action=edit").Expd_page_("A??action=edit").Test_parse();}
|
||||
@Test public void File__basic() {
|
||||
fxt.Run_parse_by_href("file:///C/xowa/file/a.png").Chk_tid(Xoa_url_.Tid_file);
|
||||
}
|
||||
@Test public void Anchor__basic() {
|
||||
fxt.Run_parse_by_href("#a").Chk_tid(Xoa_url_.Tid_anch).Chk_to_str("en.wikipedia.org/wiki/Page 1#a").Chk_anch("a");
|
||||
}
|
||||
@Test public void Xcmd__basic() {
|
||||
fxt.Run_parse_by_href("/xcmd/page_edit").Chk_tid(Xoa_url_.Tid_xcmd).Chk_page("page_edit");
|
||||
}
|
||||
@Test public void Xowa__basic() {
|
||||
fxt.Run_parse_by_href("xowa-cmd:a%22b*c").Chk_tid(Xoa_url_.Tid_xcmd).Chk_page("a\"b*c");
|
||||
}
|
||||
// COMMENTED: this seems wrong; [//wikisource.org] should go to https://wikisource.org not https://en.wikisource.org; both sites are different; DATE:2015-08-02
|
||||
// @Test public void Site__user_wiki() {// PURPOSE: outlier for wikisource.org which is alias to en.wikisource.org; alias added in user_wiki; EX: [//wikisource.org a]; in browser, automatically goes to http://wikisource.org; in xowa, should go to /site/en.wikisource.org
|
||||
// fxt.Prep_xwiki(fxt.App().User().Wikii(), "en_wiki_alias", "en.wikipedia.org", null);
|
||||
// fxt.Run_parse_by_href("/site/en_wiki_alias/wiki/")
|
||||
// .Chk_tid(Xoa_url_.Tid_page)
|
||||
// .Chk_page("Main_Page")
|
||||
// .Chk_to_str("en.wikipedia.org/wiki/Main_Page")
|
||||
// ;
|
||||
// }
|
||||
}
|
||||
class Xoh_href_parser_fxt {
|
||||
private Xowe_wiki wiki; private Xoh_href_parser href_parser; private Bry_bfr tmp_bfr = Bry_bfr.reset_(255); private Xoh_href href = new Xoh_href();
|
||||
private static final byte[] Page_1_ttl = Bry_.new_a7("Page 1");
|
||||
public void Clear() {
|
||||
expd_tid = Xoh_href.Tid_null;
|
||||
prep_raw = expd_full = expd_wiki = expd_page = expd_anch = null;
|
||||
if (app != null) return;
|
||||
app = Xoa_app_fxt.app_();
|
||||
wiki = Xoa_app_fxt.wiki_tst_(app);
|
||||
wiki.Xwiki_mgr().Add_bulk(Bry_.new_a7("wikt|en.wiktionary.org"));
|
||||
app.Usere().Wiki().Xwiki_mgr().Add_bulk(Bry_.new_a7("en.wiktionary.org|en.wiktionary.org"));
|
||||
href_parser = new Xoh_href_parser(Xoa_app_.Utl__encoder_mgr().Href(), app.Utl__url_parser().Url_parser());
|
||||
}
|
||||
public Xoae_app App() {return app;} private Xoae_app app;
|
||||
public Xoh_href_parser_fxt Init_xwiki_alias(String alias, String domain) {
|
||||
app.Usere().Wiki().Xwiki_mgr().Add_full(alias, domain);
|
||||
class Xoh_href_parser_fxt extends Xoa_url_parser_fxt { private final Xoh_href_parser href_parser = new Xoh_href_parser();
|
||||
public Xoh_href_parser_fxt Run_parse_by_href(String raw) {
|
||||
href_parser.Parse_as_url(actl_url, Bry_.new_u8(raw), cur_wiki, Bry__page_1);
|
||||
return this;
|
||||
}
|
||||
public Xoh_href_parser_fxt Init_xwiki_by_many(String raw) {
|
||||
wiki.Xwiki_mgr().Add_many(Bry_.new_u8(raw)); // need to add to wiki's xwiki_mgr for ttl_parse
|
||||
return this;
|
||||
}
|
||||
public Xoh_href_parser_fxt Init_hover_full_y_() {return Init_hover_full_(Bool_.Y);}
|
||||
public Xoh_href_parser_fxt Init_hover_full_n_() {return Init_hover_full_(Bool_.N);}
|
||||
public Xoh_href_parser_fxt Init_hover_full_(boolean v) {show_full_hover_string = v; return this;}
|
||||
public Xoh_href_parser_fxt Prep_raw_(String v) {this.prep_raw = v; return this;} private String prep_raw;
|
||||
public Xoh_href_parser_fxt Expd_tid_(byte v) {this.expd_tid = v; return this;} private byte expd_tid;
|
||||
public Xoh_href_parser_fxt Expd_full_(String v) {this.expd_full = v; return this;} private String expd_full;
|
||||
public Xoh_href_parser_fxt Expd_wiki_(String v) {this.expd_wiki = v; return this;} private String expd_wiki;
|
||||
public Xoh_href_parser_fxt Expd_page_(String v) {this.expd_page = v; return this;} private String expd_page;
|
||||
public Xoh_href_parser_fxt Expd_anch_(String v) {this.expd_anch = v; return this;} private String expd_anch;
|
||||
public void Test_parse() {
|
||||
href_parser.Parse(href, prep_raw, wiki, Page_1_ttl);
|
||||
if (expd_tid != Xoh_href.Tid_null) Tfds.Eq(expd_tid, href.Tid());
|
||||
if (expd_wiki != null) Tfds.Eq(expd_wiki, String_.new_u8(href.Wiki()));
|
||||
if (expd_page != null) Tfds.Eq(expd_page, String_.new_u8(href.Page()));
|
||||
if (expd_anch != null) Tfds.Eq(expd_anch, String_.new_u8(href.Anchor()));
|
||||
if (expd_full != null) {
|
||||
href.Print_to_bfr(tmp_bfr, true);
|
||||
Tfds.Eq(expd_full, tmp_bfr.Xto_str_and_clear());
|
||||
}
|
||||
}
|
||||
private boolean show_full_hover_string = false;
|
||||
public void Test_hover_string(String raw, String expd) {
|
||||
href_parser.Parse(href, raw, wiki, Page_1_ttl);
|
||||
href.Print_to_bfr(tmp_bfr, show_full_hover_string);
|
||||
Tfds.Eq(expd, tmp_bfr.Xto_str_and_clear());
|
||||
}
|
||||
public void Test_build(String raw, String expd) {
|
||||
Xoa_ttl ttl = Xoa_ttl.parse_(wiki, Bry_.new_u8(raw));
|
||||
href_parser.Build_to_bfr(tmp_bfr, app, wiki.Domain_bry(), ttl);
|
||||
Tfds.Eq(expd, tmp_bfr.Xto_str_and_clear());
|
||||
}
|
||||
public void Test_parse_protocol(String raw, byte expd_tid) {
|
||||
href_parser.Parse(href, raw, wiki, Page_1_ttl);
|
||||
Tfds.Eq(expd_tid, href.Protocol_tid());
|
||||
}
|
||||
private static final byte[] Bry__page_1 = Bry_.new_a7("Page 1");
|
||||
}
|
||||
|
||||
83
400_xowa/src/gplx/xowa/html/hrefs/Xoh_href_wtr.java
Normal file
83
400_xowa/src/gplx/xowa/html/hrefs/Xoh_href_wtr.java
Normal file
@@ -0,0 +1,83 @@
|
||||
/*
|
||||
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.html.hrefs; import gplx.*; import gplx.xowa.*; import gplx.xowa.html.*;
|
||||
import gplx.xowa.wikis.xwikis.*;
|
||||
public class Xoh_href_wtr {
|
||||
private final Bry_bfr encoder_bfr = Bry_bfr.reset_(255), tmp_bfr = Bry_bfr.reset_(255);
|
||||
private final Url_encoder encoder = Xoa_app_.Utl__encoder_mgr().Href();
|
||||
public byte[] Build_to_bry(Xow_wiki wiki, Xoa_ttl ttl) {
|
||||
synchronized (tmp_bfr) {
|
||||
Build_to_bfr(tmp_bfr, wiki.App(), wiki.Domain_bry(), ttl, Bool_.N);
|
||||
return tmp_bfr.Xto_bry_and_clear();
|
||||
}
|
||||
}
|
||||
public void Build_to_bfr(Bry_bfr bfr, Xoa_app app, byte[] domain_bry, Xoa_ttl ttl) {Build_to_bfr(bfr, app, domain_bry, ttl, Bool_.N);}
|
||||
public void Build_to_bfr(Bry_bfr bfr, Xoa_app app, byte[] domain_bry, Xoa_ttl ttl, boolean force_site) {
|
||||
byte[] page = ttl.Full_txt_raw();
|
||||
Xow_xwiki_itm xwiki = ttl.Wik_itm();
|
||||
if (xwiki == null) // not an xwiki; EX: [[wikt:Word]]
|
||||
Build_to_bfr_page(ttl, page, 0); // write page only; NOTE: changed to remove leaf logic DATE:2014-09-07
|
||||
else { // xwiki; skip wiki and encode page only;
|
||||
byte[] wik_txt = ttl.Wik_txt();
|
||||
Build_to_bfr_page(ttl, page, wik_txt.length + 1);
|
||||
}
|
||||
if (xwiki == null) { // not an xwiki
|
||||
if (ttl.Anch_bgn() != 1) { // not an anchor-only; EX: "#A"
|
||||
if (force_site) { // popup parser always writes as "/site/"
|
||||
bfr.Add(Xoh_href_.Bry__site); // add "/site/"; EX: /site/
|
||||
bfr.Add(domain_bry); // add xwiki; EX: en_dict
|
||||
bfr.Add(Xoh_href_.Bry__wiki); // add "/wiki/"; EX: /wiki/
|
||||
}
|
||||
else
|
||||
bfr.Add(Xoh_href_.Bry__wiki); // add "/wiki/"; EX: /wiki/Page
|
||||
}
|
||||
else {} // anchor: noop
|
||||
}
|
||||
else { // xwiki
|
||||
if (app.Xwiki_mgr__missing(xwiki.Domain_bry())) { // xwiki is not offline; use http:
|
||||
Bry_fmtr url_fmtr = xwiki.Url_fmtr();
|
||||
if (url_fmtr == null) {
|
||||
bfr.Add(Xoh_href_.Bry__https); // add "https://"; EX: https://
|
||||
bfr.Add(xwiki.Domain_bry()); // add xwiki; EX: en_dict
|
||||
bfr.Add(Xoh_href_.Bry__wiki); // add "/wiki/"; EX: /wiki/
|
||||
}
|
||||
else { // url_fmtr exists; DATE:2015-04-22
|
||||
url_fmtr.Bld_bfr(bfr, encoder_bfr.Xto_bry_and_clear()); // use it and pass encoder_bfr for page_name;
|
||||
return;
|
||||
}
|
||||
}
|
||||
else { // xwiki is avaiable; use /site/
|
||||
bfr.Add(Xoh_href_.Bry__site); // add "/site/"; EX: /site/
|
||||
bfr.Add(xwiki.Domain_bry()); // add xwiki; EX: en_dict
|
||||
bfr.Add(Xoh_href_.Bry__wiki); // add "/wiki/"; EX: /wiki/
|
||||
}
|
||||
}
|
||||
bfr.Add_bfr_and_clear(encoder_bfr);
|
||||
}
|
||||
private void Build_to_bfr_page(Xoa_ttl ttl, byte[] ttl_full, int page_bgn) {
|
||||
int anch_bgn = Bry_finder.Find_fwd(ttl_full, Byte_ascii.Hash); // NOTE: cannot use Anch_bgn b/c Anch_bgn has bug with whitespace
|
||||
if (anch_bgn == Bry_.NotFound) // no anchor; just add page
|
||||
encoder.Encode(encoder_bfr, ttl_full, page_bgn, ttl_full.length);
|
||||
else { // anchor exists; check if anchor is preceded by ws; EX: [[A #b]] -> "/wiki/A#b"
|
||||
int page_end = Bry_finder.Find_bwd_last_ws(ttl_full, anch_bgn); // first 1st ws before #; handles multiple ws
|
||||
page_end = page_end == Bry_.NotFound ? anch_bgn : page_end; // if ws not found, use # pos; else use 1st ws pos
|
||||
encoder.Encode(encoder_bfr, ttl_full, page_bgn, page_end); // add page
|
||||
encoder.Encode(encoder_bfr, ttl_full, anch_bgn, ttl_full.length); // add anchor
|
||||
}
|
||||
}
|
||||
}
|
||||
59
400_xowa/src/gplx/xowa/html/hrefs/Xoh_href_wtr_tst.java
Normal file
59
400_xowa/src/gplx/xowa/html/hrefs/Xoh_href_wtr_tst.java
Normal file
@@ -0,0 +1,59 @@
|
||||
/*
|
||||
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.html.hrefs; import gplx.*; import gplx.xowa.*; import gplx.xowa.html.*;
|
||||
import org.junit.*;
|
||||
import gplx.core.net.*;
|
||||
public class Xoh_href_wtr_tst {
|
||||
private final Xoh_href_wtr_fxt fxt = new Xoh_href_wtr_fxt();
|
||||
@Test public void Xwiki_enc() {fxt.Test_build("wikt:abc?d" , "/site/en.wiktionary.org/wiki/abc%3Fd");}
|
||||
@Test public void Page_quote() {fxt.Test_build("a\"b\"c" , "/wiki/A%22b%22c");}
|
||||
@Test public void Page() {fxt.Test_build("abc" , "/wiki/Abc");}
|
||||
@Test public void Page_ns() {fxt.Test_build("Image:A.png" , "/wiki/Image:A.png");}
|
||||
@Test public void Anchor() {fxt.Test_build("#abc" , "#abc");}
|
||||
@Test public void Page_anchor() {fxt.Test_build("Abc#def" , "/wiki/Abc#def");}
|
||||
@Test public void Xwiki() {fxt.Test_build("wikt:abc" , "/site/en.wiktionary.org/wiki/abc");} // NOTE: "abc" not capitalized, b/c other wiki's case sensitivity is not known; this emulates WP's behavior
|
||||
@Test public void Xwiki_2() {fxt.Test_build("wikt:Special:Search/a" , "/site/en.wiktionary.org/wiki/Special:Search/a");}
|
||||
@Test public void Category() {fxt.Test_build("Category:abc" , "/wiki/Category:Abc");}
|
||||
@Test public void Xwiki_wikimedia_mail() { // PURPOSE: DATE:2015-04-22
|
||||
fxt.Prep_xwiki_by_many("mail|https://lists.wikimedia.org/mailman/listinfo/$1|Wikitech Mailing List");
|
||||
fxt.Test_build("mail:A" , "https://lists.wikimedia.org/mailman/listinfo/A");
|
||||
}
|
||||
}
|
||||
class Xoh_href_wtr_fxt {
|
||||
private final Xowe_wiki wiki;
|
||||
private final Bry_bfr tmp_bfr = Bry_bfr.reset_(255);
|
||||
private final Xoh_href_wtr href_wtr = new Xoh_href_wtr();
|
||||
public Xoh_href_wtr_fxt() {
|
||||
this.app = Xoa_app_fxt.app_();
|
||||
this.wiki = Xoa_app_fxt.wiki_tst_(app);
|
||||
wiki.Xwiki_mgr().Add_bulk(Bry_.new_a7("wikt|en.wiktionary.org"));
|
||||
app.Usere().Wiki().Xwiki_mgr().Add_bulk(Bry_.new_a7("en.wiktionary.org|en.wiktionary.org"));
|
||||
}
|
||||
public Xoae_app App() {return app;} private final Xoae_app app;
|
||||
public Xoh_href_wtr_fxt Prep_wiki_cs(String domain) {
|
||||
Xow_wiki wiki = app.Wiki_mgr().Get_by_key_or_make_init_n(Bry_.new_u8(domain));
|
||||
wiki.Ns_mgr().Ns_main().Case_match_(Xow_ns_case_.Id_all);
|
||||
return this;
|
||||
}
|
||||
public Xoh_href_wtr_fxt Prep_xwiki_by_many(String raw) {wiki.Xwiki_mgr().Add_many(Bry_.new_u8(raw)); return this;} // need to add to wiki's xwiki_mgr for ttl_parse
|
||||
public void Test_build(String raw, String expd) {
|
||||
Xoa_ttl ttl = Xoa_ttl.parse_(wiki, Bry_.new_u8(raw));
|
||||
href_wtr.Build_to_bfr(tmp_bfr, app, wiki.Domain_bry(), ttl);
|
||||
Tfds.Eq(expd, tmp_bfr.Xto_str_and_clear());
|
||||
}
|
||||
}
|
||||
@@ -80,7 +80,7 @@ public class Xow_hzip_itm__anchor {
|
||||
if (id_bgn > a_lhs_end) return Xow_hzip_mgr.Unhandled;
|
||||
id_bgn += Find_id_bry.length + gplx.xowa.parsers.lnkis.redlinks.Xopg_redlink_lnki_list.Lnki_id_prefix_len;
|
||||
int id_end = Bry_finder.Find_fwd(src, Byte_ascii.Quote, id_bgn, src_len); if (id_end == Bry_finder.Not_found) return Xow_hzip_mgr.Unhandled;
|
||||
int id = Bry_.Xto_int_or(src, id_bgn, id_end, -1); if (id == Bry_finder.Not_found) return Xow_hzip_mgr.Unhandled;
|
||||
int id = Bry_.To_int_or(src, id_bgn, id_end, -1); if (id == Bry_finder.Not_found) return Xow_hzip_mgr.Unhandled;
|
||||
int a_rhs_bgn = Bry_finder.Find_fwd(src, Find_a_rhs_bgn_bry, a_lhs_end, src_len); if (a_rhs_bgn == Bry_finder.Not_found) return hzip_mgr.Warn_by_pos_add_dflt("a.a_rhs_bgn_missing", bgn, ttl_end);
|
||||
int ttl_len = ttl_end - ttl_bgn;
|
||||
int html_text_len = a_rhs_bgn - a_lhs_end;
|
||||
@@ -132,7 +132,7 @@ public class Xow_hzip_itm__anchor {
|
||||
int a_lhs_end = Bry_finder.Find_fwd(src, Byte_ascii.Gt, href_end, src_len); if (a_lhs_end == Bry_finder.Not_found) return hzip_mgr.Warn_by_pos_add_dflt("a.a_lhs_end_missing", bgn, href_end);
|
||||
int num_bgn = a_lhs_end + 2; // skip >[
|
||||
int num_end = Bry_finder.Find_fwd(src, Byte_ascii.Brack_end, num_bgn, src_len); if (num_end == Bry_finder.Not_found) return hzip_mgr.Warn_by_pos_add_dflt("a.num_end_missing", bgn, href_end);
|
||||
int num = Bry_.Xto_int_or(src, num_bgn, num_end, -1); if (num == -1) return hzip_mgr.Warn_by_pos_add_dflt("a.num_invalid", num_bgn, num_end);
|
||||
int num = Bry_.To_int_or(src, num_bgn, num_end, -1); if (num == -1) return hzip_mgr.Warn_by_pos_add_dflt("a.num_invalid", num_bgn, num_end);
|
||||
Xow_hzip_int_.Save_bin_int_abrv(bfr, num);
|
||||
int a_rhs_bgn = num_end + 1;
|
||||
int a_rhs_end = a_rhs_bgn + Find_a_rhs_bgn_len;
|
||||
|
||||
@@ -68,17 +68,17 @@ class Xow_hzip_itm__href {
|
||||
, Tid_ext_asp = 6
|
||||
, Tid_ext_aspx = 7
|
||||
;
|
||||
// private static final Btrie_slim_mgr proto_trie = Btrie_slim_mgr.ci_ascii_()
|
||||
// private static final Btrie_slim_mgr proto_trie = Btrie_slim_mgr.ci_a7()
|
||||
// .Add_str_byte("http", Tid_proto_http)
|
||||
// .Add_str_byte("https", Tid_proto_http)
|
||||
// ;
|
||||
// private static final Btrie_slim_mgr tld_trie = Btrie_slim_mgr.ci_ascii_()
|
||||
// private static final Btrie_slim_mgr tld_trie = Btrie_slim_mgr.ci_a7()
|
||||
// .Add_str_byte("com", Tid_tld_com)
|
||||
// .Add_str_byte("org", Tid_tld_org)
|
||||
// .Add_str_byte("net", Tid_tld_net)
|
||||
// .Add_str_byte("gov", Tid_tld_gov)
|
||||
// ;
|
||||
// private static final Btrie_slim_mgr ext_trie = Btrie_slim_mgr.ci_ascii_()
|
||||
// private static final Btrie_slim_mgr ext_trie = Btrie_slim_mgr.ci_a7()
|
||||
// .Add_str_byte("htm", Tid_ext_htm)
|
||||
// .Add_str_byte("html", Tid_ext_html)
|
||||
// .Add_str_byte("php", Tid_ext_php)
|
||||
|
||||
@@ -101,7 +101,7 @@ public class Xow_hzip_mgr {
|
||||
, Tid_a_rhs = 1
|
||||
, Tid_h_lhs = 2
|
||||
;
|
||||
private Btrie_slim_mgr btrie = Btrie_slim_mgr.cs_()
|
||||
private Btrie_slim_mgr btrie = Btrie_slim_mgr.cs()
|
||||
.Add_str_byte("<a " , Tid_a_lhs)
|
||||
.Add_str_byte("</a>" , Tid_a_rhs)
|
||||
// .Add_str_byte("<h" , Tid_h_lhs)
|
||||
|
||||
@@ -40,7 +40,7 @@ class Xow_hzip_xtid {
|
||||
, Bry_img_full = Bry_.new_a7("a_img_full")
|
||||
, Bry_hdr = Bry_.new_a7("hdr")
|
||||
;
|
||||
private static final Hash_adp_bry Xtids = Hash_adp_bry.cs_()
|
||||
private static final Hash_adp_bry Xtids = Hash_adp_bry.cs()
|
||||
.Add_bry_byte(Bry_lnki_text_n , Xow_hzip_dict.Tid_lnki_text_n)
|
||||
.Add_bry_byte(Bry_lnki_text_y , Xow_hzip_dict.Tid_lnki_text_y)
|
||||
.Add_bry_byte(Bry_lnke_txt , Xow_hzip_dict.Tid_lnke_txt)
|
||||
|
||||
@@ -149,7 +149,7 @@ public class Xoh_js_cbk implements GfoInvkAble {
|
||||
if (Bry_.Eq(lang_key, Wikidata_get_label_xowa_title))
|
||||
val_bry = ttl_bry;
|
||||
else {
|
||||
val_bry = page.Label_list_get(lang_key);
|
||||
val_bry = page.Label_list__get(lang_key);
|
||||
}
|
||||
if (val_bry == null) continue;
|
||||
rv[i - 1] = String_.new_u8(val_bry);
|
||||
|
||||
@@ -20,7 +20,7 @@ import gplx.html.*; import gplx.xowa.files.*; import gplx.xowa.html.hdumps.core.
|
||||
public class Xoh_file_wtr__basic {
|
||||
private final Xowe_wiki wiki; private final Xow_html_mgr html_mgr; private final Xoh_html_wtr html_wtr; private final Bry_bfr_mkr bfr_mkr; private final Bry_bfr scratch_bfr = Bry_bfr.reset_(Io_mgr.Len_kb);
|
||||
private final Xoh_lnki_text_fmtr media_alt_fmtr, caption_fmtr;
|
||||
private final Xop_link_parser tmp_link_parser = new Xop_link_parser(); private Xoa_url tmp_url = Xoa_url.blank_(); private final Xoh_lnki_title_fmtr anchor_title_wkr = new Xoh_lnki_title_fmtr();
|
||||
private final Xop_link_parser tmp_link_parser = new Xop_link_parser(); private Xoa_url tmp_url = Xoa_url.blank(); private final Xoh_lnki_title_fmtr anchor_title_wkr = new Xoh_lnki_title_fmtr();
|
||||
private Xoh_file_html_fmtr__base html_fmtr = Xoh_file_html_fmtr__base.Base;
|
||||
private Xoae_page page; private boolean cfg_alt_defaults_to_caption;
|
||||
public Xoh_file_wtr__basic(Xowe_wiki wiki, Xow_html_mgr html_mgr, Xoh_html_wtr html_wtr) {
|
||||
@@ -45,7 +45,7 @@ public class Xoh_file_wtr__basic {
|
||||
if (lnki_halign == Xop_lnki_align_h.Null)
|
||||
lnki_halign = wiki.Lang().Img_thumb_halign_default(); // if halign is not supplied, then default to align for language
|
||||
byte[] lnki_halign_bry = Xop_lnki_align_h.Html_names[lnki_halign];
|
||||
byte[] lnki_href = wiki.Appe().Href_parser().Build_to_bry(wiki, lnki.Ttl());
|
||||
byte[] lnki_href = wiki.Appe().Html__href_wtr().Build_to_bry(wiki, lnki.Ttl());
|
||||
byte[] img_view_src = xfer_itm.Html_view_url().To_http_file_bry();
|
||||
byte[] img_orig_src = xfer_itm.Html_orig_url().To_http_file_bry();
|
||||
byte[] lnki_ttl = lnki.Ttl().Page_txt();
|
||||
|
||||
@@ -42,7 +42,7 @@ public class Xoh_lnki_wtr {
|
||||
public void Write(Bry_bfr bfr, Xoh_wtr_ctx hctx, byte[] src, Xop_lnki_tkn lnki) {
|
||||
Xoa_ttl lnki_ttl = lnki.Ttl();
|
||||
if (lnki_ttl == null) {// NOTE: parser failed to properly invalidate lnki; escape tkn now and warn; DATE:2014-06-06
|
||||
app.Usr_dlg().Warn_many("", "", "invalid lnki evaded parser; page=~{0} ex=~{1}", ctx.Cur_page().Url().Xto_full_str(), String_.new_u8(src, lnki.Src_bgn(), lnki.Src_end()));
|
||||
app.Usr_dlg().Warn_many("", "", "invalid lnki evaded parser; page=~{0} ex=~{1}", ctx.Cur_page().Url().To_str(), String_.new_u8(src, lnki.Src_bgn(), lnki.Src_end()));
|
||||
Xoh_html_wtr_escaper.Escape(app.Parser_amp_mgr(), bfr, src, lnki.Src_bgn(), lnki.Src_end(), true, false);
|
||||
return;
|
||||
}
|
||||
@@ -100,7 +100,7 @@ public class Xoh_lnki_wtr {
|
||||
wiki.Html_mgr().Hzip_mgr().Itm__anchor().Html_plain(bfr, lnki);
|
||||
else
|
||||
bfr.Add(Xoh_consts.A_bgn); // '<a href="'
|
||||
app.Href_parser().Build_to_bfr(bfr, app, wiki.Domain_bry(), lnki_ttl, hctx.Mode_is_popup()); // '/wiki/A'
|
||||
app.Html__href_wtr().Build_to_bfr(bfr, app, wiki.Domain_bry(), lnki_ttl, hctx.Mode_is_popup()); // '/wiki/A'
|
||||
if (cfg.Lnki__id()) {
|
||||
int lnki_html_id = lnki.Html_uid();
|
||||
if (lnki_html_id > Lnki_id_ignore) // html_id=0 for skipped lnkis; EX:anchors and interwiki
|
||||
|
||||
@@ -25,7 +25,7 @@ import gplx.xowa.apis.xowa.html.modules.*;
|
||||
public class Xow_popup_mgr implements GfoInvkAble, GfoEvObj {
|
||||
private Xoae_app app; private Xowe_wiki wiki; private Js_wtr js_wtr = new Js_wtr();
|
||||
private int show_init_word_count = Xoapi_popups.Dflt_show_init_word_count, show_more_word_count = Xoapi_popups.Dflt_show_more_word_count;
|
||||
private Xoh_href temp_href = new Xoh_href();
|
||||
private Xoa_url tmp_url = Xoa_url.blank();
|
||||
private static final Object thread_lock = new Object(); private Xow_popup_itm async_itm; private GfoInvkAble async_cmd_show; private int async_id_next = 1;
|
||||
public Xow_popup_mgr(Xowe_wiki wiki) {
|
||||
this.wiki = wiki; this.app = wiki.Appe();
|
||||
@@ -117,11 +117,11 @@ public class Xow_popup_mgr implements GfoInvkAble, GfoEvObj {
|
||||
Running_(true);
|
||||
if (itm.Canceled()) return null;
|
||||
cur_page.Popup_mgr().Itms().Add_if_dupe_use_nth(itm.Popup_id(), itm);
|
||||
app.Href_parser().Parse(temp_href, itm.Page_href(), wiki, cur_page.Ttl().Full_url()); // NOTE: use Full_url, not Page_url, else anchors won't work for non-main ns; PAGE:en.w:Project:Sandbox; DATE:2014-08-07
|
||||
if (temp_href.Protocol_tid() == gplx.xowa.net.Xoo_protocol_itm.Tid_file) return Bry_.Empty; // NOTE: do not get popups for "file:///"; DATE:2015-04-05
|
||||
Xowe_wiki popup_wiki = app.Wiki_mgr().Get_by_key_or_null(temp_href.Wiki());
|
||||
app.Html__href_parser().Parse_as_url(tmp_url, itm.Page_href(), wiki, cur_page.Ttl().Full_url()); // NOTE: use Full_url, not Page_url, else anchors won't work for non-main ns; PAGE:en.w:Project:Sandbox; DATE:2014-08-07
|
||||
if (!Xoa_url_.Tid_is_pagelike(tmp_url.Tid())) return Bry_.Empty; // NOTE: do not get popups for "file:///"; DATE:2015-04-05
|
||||
Xowe_wiki popup_wiki = app.Wiki_mgr().Get_by_key_or_null(tmp_url.Wiki_bry());
|
||||
popup_wiki.Init_assert();
|
||||
Xoa_ttl popup_ttl = Xoa_ttl.parse_(popup_wiki, temp_href.Page_and_anchor());
|
||||
Xoa_ttl popup_ttl = Xoa_ttl.parse_(popup_wiki, tmp_url.To_bry_page_w_anch());
|
||||
switch (popup_ttl.Ns().Id()) {
|
||||
case Xow_ns_.Id_media:
|
||||
case Xow_ns_.Id_file:
|
||||
@@ -255,11 +255,11 @@ class Xow_popup_mgr_ {
|
||||
}
|
||||
}
|
||||
class Load_popup_wkr implements Gfo_thread_wkr {
|
||||
private Xow_popup_itm itm; private Xoae_page cur_page; private Xoh_href temp_href;
|
||||
private Xow_popup_itm itm; private Xoae_page cur_page; private Xoa_url tmp_url;
|
||||
private Hash_adp ns_allowed_regy;
|
||||
private Int_obj_ref ns_allowed_regy_key = Int_obj_ref.zero_();
|
||||
public Load_popup_wkr(Xowe_wiki wiki, Xoae_page cur_page, Xow_popup_itm itm, Xoh_href temp_href, Hash_adp ns_allowed_regy, Int_obj_ref ns_allowed_regy_key) {
|
||||
this.wiki = wiki; this.cur_page = cur_page; this.itm = itm; this.temp_href = temp_href; this.ns_allowed_regy = ns_allowed_regy; this.ns_allowed_regy_key = ns_allowed_regy_key;
|
||||
public Load_popup_wkr(Xowe_wiki wiki, Xoae_page cur_page, Xow_popup_itm itm, Xoa_url tmp_url, Hash_adp ns_allowed_regy, Int_obj_ref ns_allowed_regy_key) {
|
||||
this.wiki = wiki; this.cur_page = cur_page; this.itm = itm; this.tmp_url = tmp_url; this.ns_allowed_regy = ns_allowed_regy; this.ns_allowed_regy_key = ns_allowed_regy_key;
|
||||
}
|
||||
public String Name() {return "xowa.load_popup_wkr";}
|
||||
public boolean Resume() {return false;}
|
||||
@@ -272,11 +272,11 @@ class Load_popup_wkr implements Gfo_thread_wkr {
|
||||
try {
|
||||
if (itm.Canceled()) return;
|
||||
cur_page.Popup_mgr().Itms().Add_if_dupe_use_nth(itm.Popup_id(), itm);
|
||||
app.Href_parser().Parse(temp_href, itm.Page_href(), wiki, cur_page.Ttl().Full_url()); // NOTE: use Full_url, not Page_url, else anchors won't work for non-main ns; PAGE:en.w:Project:Sandbox; DATE:2014-08-07
|
||||
if (temp_href.Protocol_tid() == gplx.xowa.net.Xoo_protocol_itm.Tid_file) return; // NOTE: do not get popups for "file:///"; DATE:2015-04-05
|
||||
Xowe_wiki popup_wiki = app.Wiki_mgr().Get_by_key_or_null(temp_href.Wiki());
|
||||
app.Html__href_parser().Parse_as_url(tmp_url, itm.Page_href(), wiki, cur_page.Ttl().Full_url()); // NOTE: use Full_url, not Page_url, else anchors won't work for non-main ns; PAGE:en.w:Project:Sandbox; DATE:2014-08-07
|
||||
if (!Xoa_url_.Tid_is_pagelike(tmp_url.Tid())) return; // NOTE: do not get popups for "file:///"; DATE:2015-04-05
|
||||
Xowe_wiki popup_wiki = app.Wiki_mgr().Get_by_key_or_null(tmp_url.Wiki_bry());
|
||||
popup_wiki.Init_assert();
|
||||
Xoa_ttl popup_ttl = Xoa_ttl.parse_(popup_wiki, temp_href.Page_and_anchor());
|
||||
Xoa_ttl popup_ttl = Xoa_ttl.parse_(popup_wiki, tmp_url.To_bry_page_w_anch());
|
||||
switch (popup_ttl.Ns().Id()) {
|
||||
case Xow_ns_.Id_media:
|
||||
case Xow_ns_.Id_file:
|
||||
|
||||
@@ -21,7 +21,7 @@ import gplx.xowa.parsers.lnkes.*;
|
||||
public class Xow_popup_wrdx_mkr {
|
||||
private boolean skip_space;
|
||||
private Xop_tkn_itm prv_tkn_seen, prv_tkn_added;
|
||||
public Hash_adp_bry Xnde_id_ignore_list() {return xnde_id_ignore_list;} private Hash_adp_bry xnde_id_ignore_list = Hash_adp_bry.ci_ascii_();
|
||||
public Hash_adp_bry Xnde_id_ignore_list() {return xnde_id_ignore_list;} private Hash_adp_bry xnde_id_ignore_list = Hash_adp_bry.ci_a7();
|
||||
public void Init() {
|
||||
skip_space = false;
|
||||
prv_tkn_seen = prv_tkn_added = null;
|
||||
|
||||
@@ -108,7 +108,7 @@ class Xoh_ns_file_page_mgr_fxt {
|
||||
// file.Orig_ttl_and_redirect_(ttl_bry, Bry_.Empty);
|
||||
file.Init_at_orig(Byte_.Zero, wiki.Domain_bry(), ttl_bry, Xof_ext_.new_by_ttl_(ttl_bry), 0, 0, Bry_.Empty);
|
||||
file.Init_at_hdoc(0, Xof_html_elem.Tid_img);
|
||||
wkr.Bld_html(wiki, bfr, file, ttl, opt, Bry_.XtoStrBytesByInt(html_file_size, 0), play_btn_icon); // TEST: must pass in elem_val b/c test only uses 2nd Bld_html while app uses 1st
|
||||
wkr.Bld_html(wiki, bfr, file, ttl, opt, Bry_.To_a7_bry(html_file_size, 0), play_btn_icon); // TEST: must pass in elem_val b/c test only uses 2nd Bld_html while app uses 1st
|
||||
Tfds.Eq_str_lines(expd, bfr.Xto_str_and_clear());
|
||||
} static final byte[] play_btn_icon = Bry_.new_a7("file:///mem/xowa/user/test_user/app/img/file/play.png");
|
||||
public static final String Hdr = String_.Concat_lines_nl_skip_last
|
||||
|
||||
@@ -18,10 +18,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
package gplx.xowa.html.portal; import gplx.*; import gplx.xowa.*; import gplx.xowa.html.*;
|
||||
import gplx.xowa.html.hrefs.*;
|
||||
public class Xoh_subpages_bldr implements Bry_fmtr_arg {
|
||||
private Xoae_app app;
|
||||
private Bry_bfr tmp_bfr = Bry_bfr.reset_(255), ttl_bfr = Bry_bfr.reset_(255);
|
||||
private byte[][] segs;
|
||||
public Xoh_subpages_bldr(Xoae_app app) {this.app = app;}
|
||||
public byte[] Bld(Xow_ns_mgr ns_mgr, Xoa_ttl ttl) {
|
||||
Xow_ns ns = ttl.Ns();
|
||||
if (! ( ns.Subpages_enabled() // ns has subpages
|
||||
@@ -47,8 +45,8 @@ public class Xoh_subpages_bldr implements Bry_fmtr_arg {
|
||||
byte[] seg = segs[i];
|
||||
ttl_bfr.Add(seg);
|
||||
byte[] seg_ttl = ttl_bfr.Xto_bry();
|
||||
byte[] seg_ttl_enc = app.Href_parser().Encoder().Encode(ttl_bfr.Xto_bry());
|
||||
byte[] href = Bry_.Add(Xoh_href_parser.Href_wiki_bry, seg_ttl_enc); // EX: /wiki/Help:A
|
||||
byte[] seg_ttl_enc = Xoa_app_.Utl__encoder_mgr().Href().Encode(ttl_bfr.Xto_bry());
|
||||
byte[] href = Bry_.Add(Xoh_href_.Bry__wiki, seg_ttl_enc); // EX: /wiki/Help:A
|
||||
fmtr_itm.Bld_bfr(bfr, dlm, href, seg_ttl, seg);
|
||||
}
|
||||
ttl_bfr.Clear();
|
||||
|
||||
@@ -35,13 +35,12 @@ public class Xoh_subpages_bldr_tst {
|
||||
}
|
||||
class Xoh_subpages_bldr_fxt {
|
||||
private Xoae_app app;
|
||||
private Xoh_subpages_bldr subpages_bldr;
|
||||
private Xoh_subpages_bldr subpages_bldr = new Xoh_subpages_bldr();
|
||||
public Xowe_wiki Wiki() {return wiki;} private Xowe_wiki wiki;
|
||||
public void Init() {
|
||||
this.app = Xoa_app_fxt.app_();
|
||||
this.wiki = Xoa_app_fxt.wiki_tst_(app);
|
||||
wiki.Ns_mgr().Ids_get_or_null(Xow_ns_.Id_help).Subpages_enabled_(true);
|
||||
this.subpages_bldr = new Xoh_subpages_bldr(app);
|
||||
}
|
||||
public void Test_bld(String ttl_str, String expd) {
|
||||
byte[] actl = subpages_bldr.Bld(wiki.Ns_mgr(), Xoa_ttl.parse_(wiki, Bry_.new_u8(ttl_str)));
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user