1
0
mirror of https://github.com/gnosygnu/xowa.git synced 2026-03-02 03:49:30 +00:00

v2.11.1.1

This commit is contained in:
gnosygnu
2015-11-01 20:50:05 -05:00
parent 4f43f51b18
commit b990ec409f
858 changed files with 6758 additions and 4187 deletions

View File

@@ -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.bldrs.xmls; import gplx.*; import gplx.xowa.*; import gplx.xowa.bldrs.*;
import gplx.ios.*;
import gplx.core.ios.*;
import gplx.xowa.wikis.ctgs.*; import gplx.xowa.wikis.tdbs.*;
public class Xob_import_cfg {
public Xob_import_cfg(Xowe_wiki wiki) {this.wiki = wiki;} private Xowe_wiki wiki; private boolean src_fil_is_bz2 = true;

View File

@@ -1,89 +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.bldrs.xmls; import gplx.*; import gplx.xowa.*; import gplx.xowa.bldrs.*;
import gplx.ios.*; import gplx.xmls.*; // NOTE: gplx.xmls does not support Android; DATE:2013-01-17
import gplx.xowa.wikis.nss.*;
public class Xob_siteinfo_parser {
public static byte[] Siteinfo_extract(gplx.ios.Io_stream_rdr src_rdr) {
Io_buffer_rdr rdr = Io_buffer_rdr.Null;
try {
rdr = Io_buffer_rdr.new_(src_rdr, Io_mgr.Len_mb); // ASSUME: siteInfo is fully contained in the 1st MB of the src_xml
byte[] src = rdr.Bfr();
int bgn = Bry_find_.Find_fwd(src, Bry_siteinfo_bgn, 0) ; if (bgn == Bry_.NotFound) return null;
int end = Bry_find_.Find_fwd(src, Bry_siteinfo_end, bgn); if (end == Bry_.NotFound) return null;
return Bry_.Mid(src, bgn, end + Bry_siteinfo_end.length);
}
catch (Exception e) {Err_.Noop(e); return null;}
finally {rdr.Rls();}
}
public static void Siteinfo_parse(Xowe_wiki wiki, Gfo_usr_dlg usr_dlg, String siteinfo_str) {
XmlDoc xdoc = XmlDoc_.parse(siteinfo_str);
XmlNde root = xdoc.Root();
int root_subs_len = root.SubNdes().Count();
Bry_bfr siteinfo_misc_bfr = Bry_bfr.reset_(512);
for (int i = 0; i < root_subs_len; i++) {
XmlNde sub_nde = root.SubNdes().Get_at(i);
if ( String_.Eq(sub_nde.Name(), "sitename")
|| String_.Eq(sub_nde.Name(), "generator")
|| String_.Eq(sub_nde.Name(), "case")) siteinfo_misc_bfr.Add_str(sub_nde.Text_inner()).Add_byte_pipe();
else if ( String_.Eq(sub_nde.Name(), "base")) {
String mainpage_url = sub_nde.Text_inner();
byte[] mainpage_name = Siteinfo_parse_mainpage(Bry_.new_u8(mainpage_url)); if (mainpage_name == null) throw Err_.new_wo_type("could not extract mainpage", "mainpage", mainpage_url);
wiki.Props().Main_page_(mainpage_name);
}
else if ( String_.Eq(sub_nde.Name(), "namespaces")) {
Siteinfo_parse_ns(wiki, usr_dlg, sub_nde);
}
else if ( String_.Eq(sub_nde.Name(), "#text")) {} // NOTE: JAVA has node names for "#text"
// else throw Err_mgr.Instance.fmt_(GRP_KEY, "siteinfo.root.unknown_sub", "unknown sub for root nde: ~{0}", sub_nde.Name()); // NOTE: do not fail if MW introduces something odd in future (or if JAVA starts picking up other elements)
}
wiki.Props().Siteinfo_misc_(siteinfo_misc_bfr.To_bry_and_clear());
wiki.Props().Bldr_version_(Bry_.new_a7(Xoa_app_.Version));
}
private static byte[] Siteinfo_parse_mainpage(byte[] url) {
byte[] wiki_bry = gplx.xowa.htmls.hrefs.Xoh_href_.Bry__wiki;
int bgn_pos = Bry_find_.Find_fwd(url, wiki_bry, 0);
if (bgn_pos == Bry_.NotFound) { // "/wiki/" not found; EX: http://mywiki/My_main_page
bgn_pos = Bry_find_.Find_bwd(url, Byte_ascii.Slash); // ASSUME last segment is page
if (bgn_pos == Bry_.NotFound) throw Err_.new_wo_type("could not parse main page url", "url", String_.new_u8(url));
++bgn_pos; // add 1 to position after slash
}
else // "/wiki/" found
bgn_pos += wiki_bry.length; // position bgn after "/wiki/"
return Bry_.Mid(url, bgn_pos, url.length);
}
private static void Siteinfo_parse_ns(Xowe_wiki wiki, Gfo_usr_dlg usr_dlg, XmlNde ns_nde) {
int subs_len = ns_nde.SubNdes().Count();
Xow_ns_mgr ns_mgr = wiki.Ns_mgr();
ns_mgr.Clear(); // NOTE: wipe out any preexisting ns; use siteinfo.xml as definitive list
for (int i = 0; i < subs_len; i++) {
XmlNde sub_nde = ns_nde.SubNdes().Get_at(i);
if (sub_nde.Atrs().Count() == 0) continue; // NOTE: JAVA again has unexpected nodes
try {
int ns_id = Int_.parse(sub_nde.Atrs().FetchValOr("key", ""));
byte case_match = Xow_ns_case_.parse(sub_nde.Atrs().FetchValOr("case", ""));
String name = sub_nde.Text_inner();
ns_mgr.Add_new(ns_id, Bry_.new_u8(name), case_match, false);
}
catch (Exception e) {throw Err_.new_exc(e, "xo", "parse failed", "inner", sub_nde.Text_inner());}
}
ns_mgr.Init_w_defaults();
}
private static final byte[] Bry_siteinfo_bgn = Bry_.new_a7("<siteinfo>"), Bry_siteinfo_end = Bry_.new_a7("</siteinfo>");
static final String GRP_KEY = "xowa.bldr.core.init";
}

View File

@@ -16,20 +16,20 @@ 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.bldrs.xmls; import gplx.*; import gplx.xowa.*; import gplx.xowa.bldrs.*;
import gplx.ios.*; import gplx.xowa.wikis.data.tbls.*;
import gplx.core.ios.*; import gplx.xowa.wikis.data.tbls.*;
public class Xob_xml_page_bldr {
public byte[] Xto_bry() {return bfr.To_bry_and_clear();}
public Io_buffer_rdr XtoByteStreamRdr() {return XtoByteStreamRdr(Io_mgr.Len_kb);}
public Io_buffer_rdr XtoByteStreamRdr(int bfr_len) {
Io_url url = Io_url_.mem_fil_("mem/byteStreamRdr.txt");
Io_mgr.Instance.SaveFilBry(url, bfr.To_bry_and_clear());
return Io_buffer_rdr.new_(gplx.ios.Io_stream_rdr_.file_(url), bfr_len);
return Io_buffer_rdr.new_(gplx.core.ios.Io_stream_rdr_.file_(url), bfr_len);
}
public Bry_bfr Bfr() {return bfr;} Bry_bfr bfr = Bry_bfr.new_();
public Xob_xml_page_bldr Upd(String find, String repl) {
String all = bfr.To_str_and_clear();
all = String_.Replace(all, find, repl);
bfr.Add_str(all);
bfr.Add_str_u8(all);
return this;
}
public Xob_xml_page_bldr Add_ary(Xowd_page_itm... ary) {

View File

@@ -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.bldrs.xmls; import gplx.*; import gplx.xowa.*; import gplx.xowa.bldrs.*;
import gplx.core.btries.*; import gplx.ios.*; import gplx.xowa.wikis.data.tbls.*;
import gplx.core.btries.*; import gplx.core.ios.*; import gplx.xowa.wikis.data.tbls.*;
import gplx.xowa.wikis.nss.*;
public class Xob_xml_parser {
Btrie_fast_mgr trie = Xob_xml_parser_.trie_(); Bry_bfr data_bfr = Bry_bfr.new_(); DateAdp_parser date_parser = DateAdp_parser.new_();
@@ -44,7 +44,7 @@ public class Xob_xml_parser {
fil.Bfr_load_from(refill_pos); // refill src from pos;
src_len = fil.Bfr_len();
}
if (pos >= src_len) return Bry_.NotFound; // no more src left; should only happen at end of file
if (pos >= src_len) return Bry_find_.Not_found; // no more src left; should only happen at end of file
byte b = src[pos];
Object o = trie.Match_bgn_w_byte(b, src, pos, src_len);
if (o == null) { // text_data; not an xml_nde (<id>), xml_escape (&lt;), or tab

View File

@@ -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.bldrs.xmls; import gplx.*; import gplx.xowa.*; import gplx.xowa.bldrs.*;
import org.junit.*; import gplx.ios.*; import gplx.xowa.wikis.nss.*; import gplx.xowa.wikis.data.tbls.*;
import org.junit.*; import gplx.core.ios.*; import gplx.xowa.wikis.nss.*; import gplx.xowa.wikis.data.tbls.*;
public class Xob_xml_parser_tst {
@Before public void init() {
Io_mgr.Instance.InitEngine_mem();
@@ -107,9 +107,9 @@ public class Xob_xml_parser_tst {
}
@Test public void Root() {
Xowd_page_itm doc = doc_(1, "a", "a", Date_1);
page_bldr.Bfr().Add_str("<root>\n");
page_bldr.Bfr().Add_str_a7("<root>\n");
page_bldr.Add(doc);
page_bldr.Bfr().Add_str("</root>");
page_bldr.Bfr().Add_str_a7("</root>");
fil = page_bldr.XtoByteStreamRdr();
tst_parse(fil, doc, 0);
}