mirror of
https://github.com/gnosygnu/xowa.git
synced 2026-03-02 03:49:30 +00:00
v1.7.2.1
This commit is contained in:
@@ -17,19 +17,15 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa; import gplx.*;
|
||||
public class Xoa_url {
|
||||
public Gfo_url_arg[] Args() {return args;} public Xoa_url Args_(Gfo_url_arg[] v) {args = v; return this;} Gfo_url_arg[] args = Gfo_url_arg.Ary_empty;
|
||||
public byte[] Raw() {return raw;} public Xoa_url Raw_(byte[] v) {raw = v; return this;} private byte[] raw = Bry_.Empty;
|
||||
public boolean Protocol_is_relative() {return protocol_is_relative;} public Xoa_url Protocol_is_relative_(boolean v) {protocol_is_relative = v; return this;} private boolean protocol_is_relative;
|
||||
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 Xow_wiki Wiki() {return wiki;} public Xoa_url Wiki_(Xow_wiki v) {wiki = v; return this;} private Xow_wiki wiki;
|
||||
public Gfo_url_arg[] Args() {return args;} public Xoa_url Args_(Gfo_url_arg[] v) {args = v; return this;} private Gfo_url_arg[] args = Gfo_url_arg.Ary_empty;
|
||||
public byte Protocol_tid() {return protocol_tid;} public Xoa_url Protocol_tid_(byte v) {protocol_tid = v; return this;} private byte protocol_tid;
|
||||
public byte[] Protocol_bry() {return protocol_bry;} public Xoa_url Protocol_bry_(byte[] v) {protocol_bry = v; return this;} private byte[] protocol_bry;
|
||||
public boolean Protocol_is_relative() {return protocol_is_relative;} public Xoa_url Protocol_is_relative_(boolean v) {protocol_is_relative = v; return this;} private boolean protocol_is_relative;
|
||||
public byte[] Lang_bry() {return lang_bry;} public Xoa_url Lang_bry_(byte[] v) {lang_bry = v; return this;} private byte[] lang_bry;
|
||||
public byte[] Wiki_bry() {return wiki_bry;} public Xoa_url Wiki_bry_(byte[] v) {wiki_bry = v; return this;} private byte[] wiki_bry;
|
||||
public Xow_wiki Wiki() {return wiki;} public Xoa_url Wiki_(Xow_wiki v) {wiki = v; return this;} private Xow_wiki wiki;
|
||||
public byte[] Page_bry() {return page_bry;} public Xoa_url Page_bry_(byte[] v) {page_bry = v; return this;} private byte[] page_bry;
|
||||
int Page_bgn(int raw_len) {
|
||||
int wiki_pos = Bry_finder.Find_fwd(raw, Xoh_href_parser.Href_wiki_bry, 0, raw_len); // look for /wiki/
|
||||
return wiki_pos == Bry_.NotFound ? Bry_.NotFound : wiki_pos + Xoh_href_parser.Href_wiki_bry.length;
|
||||
}
|
||||
public byte[] Page_for_lnki() {
|
||||
int raw_len = raw.length;
|
||||
int page_bgn = Page_bgn(raw_len);
|
||||
@@ -38,10 +34,8 @@ public class Xoa_url {
|
||||
else
|
||||
return Bry_.Mid(raw, page_bgn, raw_len);// else take everything after "/wiki/";
|
||||
}
|
||||
public String X_to_full_str() {return String_.new_utf8_(this.X_to_full());}
|
||||
public byte[] X_to_full() {return wiki_bry == null ? page_bry : Bry_.Add(wiki_bry, Xoa_consts.Url_wiki_intermediary, page_bry);}
|
||||
public String X_to_full_str_safe() {try {return X_to_full_str();} catch (Exception e) {return gplx.Err_.Message_gplx_brief(e);}}
|
||||
public byte[] Anchor_bry() {return anchor_bry;} public Xoa_url Anchor_bry_(byte[] v) {anchor_bry = v; return this;} private byte[] anchor_bry = null;
|
||||
public String Anchor_str() {return anchor_bry == null ? null : String_.new_utf8_(anchor_bry);}
|
||||
public byte[] Use_lang() {return use_lang;} public Xoa_url Use_lang_(byte[] v) {use_lang = v; return this;} private byte[] use_lang;
|
||||
public boolean Redirect_force() {return redirect_force;} public Xoa_url Redirect_force_(boolean v) {redirect_force = v; return this;} private boolean redirect_force;
|
||||
public boolean Search_fulltext() {return search_fulltext;} public Xoa_url Search_fulltext_(boolean v) {search_fulltext = v; return this;} private boolean search_fulltext;
|
||||
@@ -94,11 +88,18 @@ public class Xoa_url {
|
||||
}
|
||||
return bfr.XtoAryAndClear();
|
||||
}
|
||||
public String Anchor_str() {return anchor_bry == null ? null : String_.new_utf8_(anchor_bry);}
|
||||
private int Page_bgn(int raw_len) {
|
||||
int wiki_pos = Bry_finder.Find_fwd(raw, Xoh_href_parser.Href_wiki_bry, 0, raw_len); // look for /wiki/
|
||||
return wiki_pos == Bry_.NotFound ? Bry_.NotFound : wiki_pos + Xoh_href_parser.Href_wiki_bry.length;
|
||||
}
|
||||
public byte[] Xto_full_bry() {return wiki_bry == null ? page_bry : Bry_.Add(wiki_bry, Xoa_consts.Url_wiki_intermediary, page_bry);}
|
||||
public String Xto_full_str() {return String_.new_utf8_(this.Xto_full_bry());}
|
||||
public String Xto_full_str_safe() {try {return Xto_full_str();} catch (Exception e) {return gplx.Err_.Message_gplx_brief(e);}}
|
||||
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);
|
||||
return rv;
|
||||
}
|
||||
} Xoa_url() {}
|
||||
}
|
||||
|
||||
@@ -36,7 +36,12 @@ public class Xoa_url_parser {
|
||||
if (url.Anchor_bry() != null)
|
||||
tmp_bfr.Add_byte(Byte_ascii.Hash).Add(url.Anchor_bry()); // add anchor; EX: "#B"
|
||||
return tmp_bfr.XtoStrAndClear();
|
||||
}
|
||||
}
|
||||
public Xoa_url Parse(byte[] src) {
|
||||
Xoa_url rv = Xoa_url.blank_();
|
||||
Parse(rv, src);
|
||||
return rv;
|
||||
}
|
||||
public boolean Parse(Xoa_url url, byte[] src, int bgn, int end) {return Parse(url, Bry_.Mid(src, bgn, end));}
|
||||
public boolean Parse(Xoa_url url, byte[] src) {
|
||||
url.Init(src); // NOTE: need to call init to clear state; Xoa_url is often reused
|
||||
@@ -124,7 +129,11 @@ public class Xoa_url_parser {
|
||||
: ary
|
||||
;
|
||||
}
|
||||
public static Xoa_url Parse_url(Xoa_app app, Xow_wiki cur_wiki, String raw) {Xoa_url rv = new Xoa_url(); byte[] raw_bry = Bry_.new_utf8_(raw); return Parse_url(rv, app, cur_wiki, raw_bry, 0, raw_bry.length, false);}
|
||||
public static Xoa_url Parse_url(Xoa_app app, Xow_wiki cur_wiki, String raw) {
|
||||
byte[] raw_bry = Bry_.new_utf8_(raw);
|
||||
return Parse_url(Xoa_url.blank_(), app, cur_wiki, raw_bry, 0, raw_bry.length, false);
|
||||
}
|
||||
public static Xoa_url Parse_url(Xoa_app app, Xow_wiki cur_wiki, byte[] raw, int bgn, int end, boolean from_url_bar) {return Parse_url(Xoa_url.blank_(), app, cur_wiki, raw, bgn, end, from_url_bar);}
|
||||
public static Xoa_url Parse_url(Xoa_url rv, Xoa_app app, Xow_wiki cur_wiki, byte[] raw, int bgn, int end, boolean from_url_bar) {
|
||||
Xow_wiki wiki = null; Bry_bfr_mkr bfr_mkr = app.Utl_bry_bfr_mkr();
|
||||
byte[] cur_wiki_key = cur_wiki.Domain_bry();
|
||||
@@ -247,8 +256,7 @@ public class Xoa_url_parser {
|
||||
bry = Parse_from_url_bar__strip_mobile(bry);
|
||||
byte[] fmt = app.Gui_mgr().Url_macro_mgr().Fmt_or_null(bry);
|
||||
if (fmt != null) bry = fmt;
|
||||
Xoa_url rv = new Xoa_url();
|
||||
Xoa_url_parser.Parse_url(rv, app, wiki, bry, 0, bry.length, true);
|
||||
Xoa_url rv = Xoa_url_parser.Parse_url(app, wiki, bry, 0, bry.length, true);
|
||||
if (app.Wiki_mgr().Wiki_regy().Url_is_invalid_domain(rv)) { // handle lang_code entered; EX: "war" should redirect to "war" article in current wiki, not war.wikipedia.org; DATE:2014-02-07
|
||||
rv.Page_bry_(rv.Wiki_bry());
|
||||
rv.Wiki_(wiki);
|
||||
@@ -283,6 +291,13 @@ public class Xoa_url_parser {
|
||||
, Bry_arg_action = Bry_.new_ascii_("action")
|
||||
, Bry_arg_action_edit = Bry_.new_ascii_("edit")
|
||||
;
|
||||
private static final Hash_adp_bry qry_args_hash = Hash_adp_bry.ci_().Add_bry_byte(Bry_arg_redirect, Id_arg_redirect).Add_bry_byte(Bry_arg_uselang, Id_arg_uselang).Add_bry_byte(Bry_arg_title, Id_arg_title).Add_bry_byte(Bry_arg_action, Id_arg_action).Add_bry_byte(Bry_arg_fulltext, Id_arg_fulltext);
|
||||
private static final Hash_adp_bry upload_segs_hash = Hash_adp_bry.ci_().Add_bry_bry(Xow_wiki_domain_.Key_commons_bry);//.Add_bry_bry(Xow_wiki_domain_.Key_species_bry).Add_bry_bry(Xow_wiki_domain_.Key_meta_bry);
|
||||
private static final Hash_adp_bry qry_args_hash = Hash_adp_bry.ci_ascii_()
|
||||
.Add_bry_byte(Bry_arg_redirect, Id_arg_redirect)
|
||||
.Add_bry_byte(Bry_arg_uselang, Id_arg_uselang)
|
||||
.Add_bry_byte(Bry_arg_title, Id_arg_title)
|
||||
.Add_bry_byte(Bry_arg_action, Id_arg_action)
|
||||
.Add_bry_byte(Bry_arg_fulltext, Id_arg_fulltext)
|
||||
;
|
||||
private static final Hash_adp_bry upload_segs_hash = Hash_adp_bry.ci_ascii_()
|
||||
.Add_bry_bry(Xow_wiki_domain_.Key_commons_bry);//.Add_bry_bry(Xow_wiki_domain_.Key_species_bry).Add_bry_bry(Xow_wiki_domain_.Key_meta_bry);
|
||||
}
|
||||
|
||||
@@ -94,18 +94,16 @@ public class Xoa_url_parser_basic_tst {
|
||||
fxt.Expd_wiki("en.wikipedia.org").Expd_page("A").Expd_action_is_edit_y().Test_parse_w_wiki("A?action=edit");
|
||||
}
|
||||
@Test public void Assert_state_cleared() { // PURPOSE.fix: action_is_edit (et. al.) was not being cleared on parse even though Xoa_url reused; DATE:20121231
|
||||
Xoa_url url = new Xoa_url();
|
||||
byte[] raw = Bry_.new_ascii_("A?action=edit");
|
||||
Xoa_url_parser.Parse_url(url, fxt.App(), fxt.Wiki(), raw, 0, raw.length, false);
|
||||
Xoa_url url = Xoa_url_parser.Parse_url(fxt.App(), fxt.Wiki(), raw, 0, raw.length, false);
|
||||
Tfds.Eq(true, url.Action_is_edit());
|
||||
raw = Bry_.new_ascii_("B");
|
||||
Xoa_url_parser.Parse_url(url, fxt.App(), fxt.Wiki(), raw, 0, raw.length, false);
|
||||
Tfds.Eq(false, url.Action_is_edit());
|
||||
}
|
||||
@Test public void Query_arg() { // PURPOSE.fix: query args were not printing out
|
||||
Xoa_url url = new Xoa_url();
|
||||
byte[] raw = Bry_.new_ascii_("en.wikipedia.org/wiki/Special:Search/Earth?fulltext=yes");
|
||||
Xoa_url_parser.Parse_url(url, fxt.App(), fxt.Wiki(), raw, 0, raw.length, false);
|
||||
Xoa_url url = Xoa_url_parser.Parse_url(fxt.App(), fxt.Wiki(), raw, 0, raw.length, false);
|
||||
Xoa_url_parser parser = new Xoa_url_parser();
|
||||
Tfds.Eq("en.wikipedia.org/wiki/Special:Search/Earth?fulltext=yes", parser.Build_str(url));
|
||||
}
|
||||
@@ -157,7 +155,7 @@ class Xoa_url_parser_chkr implements Tst_chkr {
|
||||
}
|
||||
public Xoa_url_parser_chkr Test_parse_from_url_bar(String raw, String expd) {
|
||||
Xoa_url actl_url = Xoa_url_parser.Parse_from_url_bar(app, wiki, raw);
|
||||
Tfds.Eq(expd, String_.new_ascii_(actl_url.X_to_full()));
|
||||
Tfds.Eq(expd, actl_url.Xto_full_str());
|
||||
return this;
|
||||
}
|
||||
public void Test_parse_w_wiki(String raw) {Test_parse_w_wiki(wiki, raw);}
|
||||
|
||||
@@ -27,6 +27,6 @@ public class Xoa_url_tst {
|
||||
}
|
||||
class Xoa_url_fxt {
|
||||
public void Clear() {}
|
||||
public Xoa_url url_(String wiki_str, String page_str, boolean redirect_force) {return new Xoa_url().Wiki_bry_(Bry_.new_utf8_(wiki_str)).Page_bry_(Bry_.new_utf8_(page_str)).Redirect_force_(redirect_force);}
|
||||
public Xoa_url url_(String wiki_str, String page_str, boolean redirect_force) {return Xoa_url.blank_().Wiki_bry_(Bry_.new_utf8_(wiki_str)).Page_bry_(Bry_.new_utf8_(page_str)).Redirect_force_(redirect_force);}
|
||||
public void Eq_page_tst(Xoa_url lhs, Xoa_url rhs, boolean expd) {Tfds.Eq(expd, lhs.Eq_page(rhs));}
|
||||
}
|
||||
|
||||
@@ -16,10 +16,10 @@ 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.xowa.net.*; import gplx.xowa.parsers.lnkes.*;
|
||||
import gplx.core.btries.*; import gplx.xowa.net.*; import gplx.xowa.parsers.lnkes.*;
|
||||
public class Xoh_href_parser {
|
||||
private Url_encoder encoder; private Gfo_url_parser url_parser; private Gfo_url tmp_url = new Gfo_url();
|
||||
private ByteTrieMgr_slim segs = ByteTrieMgr_slim.ci_ascii_(); // NOTE:ci.ascii:XO_const.en; /wiki/, /site/ etc.
|
||||
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;
|
||||
@@ -58,11 +58,11 @@ public class Xoh_href_parser {
|
||||
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.MatchAtCur(raw, bgn, raw_len); // match /wiki/ or /site/ or /xcmd/
|
||||
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;
|
||||
ByteTrie_stub seg = (ByteTrie_stub)seg_obj;
|
||||
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;
|
||||
|
||||
Reference in New Issue
Block a user