diff --git a/400_xowa/src/gplx/xowa/Xoa_app_.java b/400_xowa/src/gplx/xowa/Xoa_app_.java index 6efe26a6f..22a7e9598 100644 --- a/400_xowa/src/gplx/xowa/Xoa_app_.java +++ b/400_xowa/src/gplx/xowa/Xoa_app_.java @@ -30,8 +30,8 @@ public class Xoa_app_ { } } public static final String Name = "xowa"; - public static final int Version_id = 521; - public static final String Version = "4.5.0.1703"; + public static final int Version_id = 520; + public static final String Version = "4.4.2.1703"; public static String Build_date = "2012-12-30 00:00:00"; public static String Build_date_fmt = "yyyy-MM-dd HH:mm:ss"; public static String Op_sys_str; diff --git a/400_xowa/src/gplx/xowa/guis/views/Xog_tab_itm_read_mgr.java b/400_xowa/src/gplx/xowa/guis/views/Xog_tab_itm_read_mgr.java index 572abe0b3..971a0ffcc 100644 --- a/400_xowa/src/gplx/xowa/guis/views/Xog_tab_itm_read_mgr.java +++ b/400_xowa/src/gplx/xowa/guis/views/Xog_tab_itm_read_mgr.java @@ -17,6 +17,7 @@ package gplx.xowa.guis.views; import gplx.*; import gplx.xowa.*; import gplx.xow import gplx.core.threads.*; import gplx.gfui.*; import gplx.gfui.controls.standards.*; import gplx.xowa.guis.langs.*; import gplx.xowa.guis.history.*; import gplx.xowa.wikis.pages.lnkis.*; import gplx.xowa.wikis.pages.*; +import gplx.xowa.guis.views.url_box_fmts.*; public class Xog_tab_itm_read_mgr { 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) { @@ -64,6 +65,12 @@ public class Xog_tab_itm_read_mgr { if (url != null && ttl != null) { url_str = url.To_str(); win_str = String_.new_u8(Bry_.Add(ttl.Full_txt_w_ttl_case(), Win_text_suffix_page)); + + // fmt to url if set + Xog_urlfmtr_mgr url_box_fmtr = win.Url_box_fmtr(); + if (url_box_fmtr.Exists()) { + url_str = url_box_fmtr.Gen(url); + } } win.Url_box().Text_(url_str); win.Win_box().Text_(win_str); diff --git a/400_xowa/src/gplx/xowa/guis/views/Xog_win_itm.java b/400_xowa/src/gplx/xowa/guis/views/Xog_win_itm.java index 165fb4d4b..96149fe96 100644 --- a/400_xowa/src/gplx/xowa/guis/views/Xog_win_itm.java +++ b/400_xowa/src/gplx/xowa/guis/views/Xog_win_itm.java @@ -22,6 +22,7 @@ import gplx.xowa.langs.*; import gplx.xowa.langs.msgs.*; import gplx.xowa.wikis.pages.*; import gplx.xowa.apps.urls.*; import gplx.xowa.files.*; import gplx.xowa.htmls.hrefs.*; import gplx.xowa.wikis.pages.lnkis.*; import gplx.xowa.specials.*; import gplx.xowa.xtns.math.*; +import gplx.xowa.guis.views.url_box_fmts.*; public class Xog_win_itm implements Gfo_invk, Gfo_evt_itm { private Gfo_invk sync_cmd; private Xog_url_box__selection_changed url_box__selection_changed; @@ -59,6 +60,7 @@ public class Xog_win_itm implements Gfo_invk, Gfo_evt_itm { public Xog_html_itm Active_html_itm() {return tab_mgr.Active_tab().Html_itm();} public Gfui_html Active_html_box() {return tab_mgr.Active_tab().Html_itm().Html_box();} public Gfo_usr_dlg Usr_dlg() {return app.Usr_dlg();} + public Xog_urlfmtr_mgr Url_box_fmtr() {return url_box_fmtr;} private final Xog_urlfmtr_mgr url_box_fmtr = new Xog_urlfmtr_mgr(); public Xog_win_itm_cfg Cfg() {return cfg;} private final Xog_win_itm_cfg cfg = new Xog_win_itm_cfg(); public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) { if (ctx.Match(k, Invk_link_click)) Win__link_click(); @@ -383,6 +385,8 @@ public class Xog_win_itm implements Gfo_invk, Gfo_evt_itm { && app.Mode().Tid_is_gui()) // only run for gui; do not run for tcp/http server; DATE:2014-05-03 app.Usr_dlg().Gui_wkr_(new Gfo_usr_dlg__gui__swt(app, kit, prog_box, info_box, info_box)); cfg.Init_by_app(app); + + url_box_fmtr.Init_by_app(app); } public static String Remove_redirect_if_exists(String text) { // remove redirect target; EX: "A -> B" -> "A" diff --git a/400_xowa/src/gplx/xowa/guis/views/url_box_fmts/Xog_urlfmtr_mgr.java b/400_xowa/src/gplx/xowa/guis/views/url_box_fmts/Xog_urlfmtr_mgr.java new file mode 100644 index 000000000..3daf8faba --- /dev/null +++ b/400_xowa/src/gplx/xowa/guis/views/url_box_fmts/Xog_urlfmtr_mgr.java @@ -0,0 +1,74 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.xowa.guis.views.url_box_fmts; import gplx.*; import gplx.xowa.*; import gplx.xowa.guis.*; import gplx.xowa.guis.views.*; +public class Xog_urlfmtr_mgr implements Gfo_invk { + private Xog_urlfmtr_itm wildcard = new Xog_urlfmtr_itm(Byte_ascii.Star_bry, Bry_.new_a7("~{wiki_domain}/wiki/~{page_title}")); + private final Bry_bfr bfr = Bry_bfr_.New(); + private final Hash_adp_bry hash = Hash_adp_bry.cs(); + public boolean Exists() {return exists;} private boolean exists = false; + public void Init_by_app(Xoa_app app) { + app.Cfg().Bind_many_app(this, Cfg__url_format); + } + public void Parse(byte[] src) { + // clear + exists = false; + wildcard = new Xog_urlfmtr_itm(Byte_ascii.Star_bry, Bry_.new_a7("~{wiki_domain}/wiki/~{page_title}")); + hash.Clear(); + + // exit if blank + if (Bry_.Len_eq_0(src)) return; + + // parse lines + exists = true; + byte[][] lines = Bry_split_.Split_lines(src); + for (byte[] line : lines) { + byte[][] parts = Bry_split_.Split(line, Byte_ascii.Pipe); + if (parts.length != 2) { + Gfo_usr_dlg_.Instance.Warn_many("", "", "xog_urlfmtr:invalid_line; line=~{0}", line); + continue; + } + byte[] domain = parts[0]; + Xog_urlfmtr_itm itm = new Xog_urlfmtr_itm(domain, parts[1]); + if (Bry_.Eq(domain, Byte_ascii.Star_bry)) { + wildcard = itm; + } + else { + hash.Add_if_dupe_use_nth(domain, itm); + } + } + } + public String Gen(Xoa_url url) { + Xog_urlfmtr_itm itm = (Xog_urlfmtr_itm)hash.Get_by(url.Wiki_bry()); + if (itm == null) { + itm = wildcard; + } + return itm.Gen(bfr, url); + } + public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) { + if (ctx.Match(k, Cfg__url_format)) {Parse(m.ReadBry("v"));} + else return Gfo_invk_.Rv_unhandled; + return this; + } private static final String Cfg__url_format = "xowa.gui.url_bar.url_format"; +} +class Xog_urlfmtr_itm { + private final Bry_fmt fmt; + public Xog_urlfmtr_itm(byte[] wiki_domain, byte[] fmt_str) { + this.fmt = Bry_fmt.New(fmt_str, "wiki_domain", "page_title", "page_title_spaces"); + } + public String Gen(Bry_bfr bfr, Xoa_url url) { + return fmt.Bld_many_to_str(bfr, url.Wiki_bry(), url.Page_bry(), Bry_.Replace(url.Page_bry(), Byte_ascii.Underline, Byte_ascii.Space)); + } +} diff --git a/400_xowa/src/gplx/xowa/guis/views/url_box_fmts/Xog_urlfmtr_mgr_tst.java b/400_xowa/src/gplx/xowa/guis/views/url_box_fmts/Xog_urlfmtr_mgr_tst.java new file mode 100644 index 000000000..cf27e0de5 --- /dev/null +++ b/400_xowa/src/gplx/xowa/guis/views/url_box_fmts/Xog_urlfmtr_mgr_tst.java @@ -0,0 +1,62 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.xowa.guis.views.url_box_fmts; import gplx.*; import gplx.xowa.*; import gplx.xowa.guis.*; import gplx.xowa.guis.views.*; +import org.junit.*; import gplx.core.tests.*; +import gplx.xowa.apps.urls.*; +public class Xog_urlfmtr_mgr_tst { + private Xog_urlfmtr_mgr_fxt fxt = new Xog_urlfmtr_mgr_fxt(); + @Test public void Basic() { + String fmt_suffix = "domain:~{wiki_domain}; page_unders:~{page_title_unders}; page_spaces:~{page_title_spaces}"; + fxt.Init__init_by_parse + ( "*|wild -- " + fmt_suffix + , "en.wikipedia.org|en.w -- " + fmt_suffix + , "de.wikibooks.org|de.b -- " + fmt_suffix + ); + fxt.Test__gen_or_null("en.wikipedia.org/wiki/Page_1", "en.w -- domain:en.wikipedia.org; page_unders:Page_1; page_spaces:Page 1"); + fxt.Test__gen_or_null("de.wikibooks.org/wiki/Page_1", "de.b -- domain:de.wikibooks.org; page_unders:Page_1; page_spaces:Page 1"); + fxt.Test__gen_or_null("fr.wikibooks.org/wiki/Page_1", "wild -- domain:fr.wikibooks.org; page_unders:Page_1; page_spaces:Page 1"); + } + @Test public void Wildcard_default() { + String fmt_suffix = "domain:~{wiki_domain}; page_unders:~{page_title_unders}; page_spaces:~{page_title_spaces}"; + fxt.Init__init_by_parse + ( "en.wikipedia.org|en.w -- " + fmt_suffix + , "de.wikibooks.org|de.b -- " + fmt_suffix + ); + fxt.Test__gen_or_null("en.wikipedia.org/wiki/Page_1", "en.w -- domain:en.wikipedia.org; page_unders:Page_1; page_spaces:Page 1"); + fxt.Test__gen_or_null("fr.wikibooks.org/wiki/Page_1", "fr.wikibooks.org/wiki/Page_1"); + } +} +class Xog_urlfmtr_mgr_fxt { + private final Xog_urlfmtr_mgr mgr = new Xog_urlfmtr_mgr(); + private final Xow_url_parser url_parser; + public Xog_urlfmtr_mgr_fxt() { + // create url parser + Xoae_app app = Xoa_app_fxt.Make__app__edit(); + Xow_wiki wiki = Xoa_app_fxt.Make__wiki__edit(app); + this.url_parser = new Xow_url_parser(wiki); + + // reg xwikis + wiki.App().User().Wikii().Xwiki_mgr().Add_by_atrs("de.wikibooks.org", "de.wikibooks.org"); + wiki.App().User().Wikii().Xwiki_mgr().Add_by_atrs("fr.wikibooks.org", "fr.wikibooks.org"); + } + public void Init__init_by_parse(String... lines) { + mgr.Parse(Bry_.new_u8(String_.Concat_lines_nl_skip_last(lines))); + } + public void Test__gen_or_null(String url_str, String expd) { + Xoa_url url = url_parser.Parse(Bry_.new_u8(url_str)); + Gftest.Eq__str(expd, mgr.Gen(url)); + } +}