1
0
mirror of https://github.com/gnosygnu/xowa.git synced 2026-03-02 03:49:30 +00:00
This commit is contained in:
gnosygnu
2015-09-20 23:43:51 -04:00
parent 5fe27b5b3b
commit fa70c05354
1056 changed files with 8375 additions and 7095 deletions

View File

@@ -0,0 +1,25 @@
/*
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.urls; import gplx.*; import gplx.xowa.*; import gplx.xowa.apps.*;
public class Xoav_url {
public byte[] Wiki_bry() {return wiki_bry;} public void Wiki_bry_(byte[] v) {wiki_bry = v;} private byte[] wiki_bry;
public byte[] Page_bry() {return page_bry;} public void Page_bry_(byte[] v) {page_bry = v;} private byte[] page_bry;
public byte[] Anch_bry() {return anch_bry;} public void Anch_bry_(byte[] v) {anch_bry = v;} private byte[] anch_bry;
public byte[] Qarg_bry() {return qarg_bry;} public void Qarg_bry_(byte[] v) {qarg_bry = v;} private byte[] qarg_bry;
public void Clear() {wiki_bry = page_bry = null;}
}

View File

@@ -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.apps.urls; import gplx.*; import gplx.xowa.*; import gplx.xowa.apps.*;
public class Xoav_url_parser {
private static final byte[] Bry_site = Bry_.new_a7("/site/"), Bry_wiki = Bry_.new_a7("/wiki/"), Bry_http = Bry_.new_a7("http:");
public void Parse_xo_href(Xoav_url rv, byte[] src, byte[] cur_wiki_bry) {
rv.Clear();
int pos = Bry_.Has_at_bgn(src, Bry_http) ? Bry_http.length : 0; // DRD: DRD:2.2 adds "http:" to all links
int src_len = src.length;
if (Bry_.Has_at_bgn(src, Bry_site, pos, src_len))
pos = Parse_wiki(rv, src, src_len, pos);
else
rv.Wiki_bry_(cur_wiki_bry);
if (Bry_.Has_at_bgn(src, Bry_wiki, pos, src_len)) pos = Parse_page(rv, src, src_len, pos);
}
private int Parse_wiki(Xoav_url rv, byte[] src, int src_len, int pos) {
int wiki_bgn = pos + Bry_site.length;
int wiki_end = Bry_find_.Find_fwd(src, Byte_ascii.Slash, wiki_bgn, src_len); if (wiki_end == Bry_.NotFound) throw Err_.new_wo_type("could not find wiki_end", "src", String_.new_u8(src));
rv.Wiki_bry_(Bry_.Mid(src, wiki_bgn, wiki_end));
return wiki_end;
}
private int Parse_page(Xoav_url rv, byte[] src, int src_len, int pos) {
int page_bgn = pos + Bry_wiki.length;
int page_end = src_len;
rv.Page_bry_(Bry_.Mid(src, page_bgn, page_end));
return page_end;
}
}

View File

@@ -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.apps.urls; import gplx.*; import gplx.xowa.*; import gplx.xowa.apps.*;
import org.junit.*;
public class Xoav_url_parser_tst {
@Before public void init() {fxt.Clear();} private final Xoav_url_parser_fxt fxt = new Xoav_url_parser_fxt();
@Test public void Page() {
fxt.Exec_parse_xo_href("http:/wiki/Earth").Test_wiki("en.wikipedia.org").Test_page("Earth");
}
@Test public void Site() {
fxt.Exec_parse_xo_href("http:/site/en.wikipedia.org/wiki/Earth").Test_wiki("en.wikipedia.org").Test_page("Earth");
}
}
class Xoav_url_parser_fxt {
private Xoav_url_parser url_parser = new Xoav_url_parser(); private Xoav_url url = new Xoav_url();
public void Clear() {
cur_wiki = Bry_.new_a7("en.wikipedia.org");
url.Clear();
}
public Xoav_url_parser_fxt Init_cur_wiki(String v) {cur_wiki = Bry_.new_u8(v); return this;} private byte[] cur_wiki;
public Xoav_url_parser_fxt Test_wiki(String v) {Tfds.Eq_bry(Bry_.new_u8(v), url.Wiki_bry()); return this;}
public Xoav_url_parser_fxt Test_page(String v) {Tfds.Eq_bry(Bry_.new_u8(v), url.Page_bry()); return this;}
public Xoav_url_parser_fxt Exec_parse_xo_href(String src_str) {
byte[] src_bry = Bry_.new_u8(src_str);
url_parser.Parse_xo_href(url, src_bry, cur_wiki);
return this;
}
}