mirror of
https://github.com/gnosygnu/xowa.git
synced 2026-03-02 03:49:30 +00:00
v2.7.2.1
This commit is contained in:
25
400_xowa/src_300_html/gplx/xowa/Xoa_app_eval.java
Normal file
25
400_xowa/src_300_html/gplx/xowa/Xoa_app_eval.java
Normal 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; import gplx.*;
|
||||
public class Xoa_app_eval implements Bry_fmtr_eval_mgr {
|
||||
public boolean Enabled() {return enabled;} public void Enabled_(boolean v) {enabled = v;} private boolean enabled = true;
|
||||
public byte[] Eval(byte[] cmd) {
|
||||
Object rslt = GfsCore._.Exec_bry(cmd);
|
||||
return Bry_.new_u8(Object_.Xto_str_strict_or_null_mark(rslt));
|
||||
}
|
||||
}
|
||||
41
400_xowa/src_300_html/gplx/xowa/Xoa_app_eval_tst.java
Normal file
41
400_xowa/src_300_html/gplx/xowa/Xoa_app_eval_tst.java
Normal file
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
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 org.junit.*;
|
||||
import gplx.xowa.apps.*;
|
||||
public class Xoa_app_eval_tst {
|
||||
Xoa_app_eval_fxt fxt = new Xoa_app_eval_fxt();
|
||||
@Before public void init() {fxt.Clear();}
|
||||
@Test public void Basic() {
|
||||
fxt.Eval_test("[~{<>app.sys_cfg.version;<>}]", "[" + Xoa_app_.Version + "]");
|
||||
}
|
||||
}
|
||||
class Xoa_app_eval_fxt {
|
||||
public void Clear() {
|
||||
if (app == null) {
|
||||
app = Xoa_app_fxt.app_();
|
||||
fmtr = Bry_fmtr.new_();
|
||||
eval = new Xoa_app_eval();
|
||||
fmtr.Eval_mgr_(eval);
|
||||
Xoa_gfs_mgr.Msg_parser_init();
|
||||
}
|
||||
} private Xoae_app app; Bry_fmtr fmtr; Xoa_app_eval eval;
|
||||
public void Eval_test(String raw, String expd) {
|
||||
Tfds.Eq(fmtr.Fmt_(raw).Bld_str_many(), expd);
|
||||
}
|
||||
}
|
||||
27
400_xowa/src_300_html/gplx/xowa/Xoa_page.java
Normal file
27
400_xowa/src_300_html/gplx/xowa/Xoa_page.java
Normal file
@@ -0,0 +1,27 @@
|
||||
/*
|
||||
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 interface Xoa_page {
|
||||
Xow_wiki Wiki();
|
||||
Xoa_url Url();
|
||||
byte[] Url_bry_safe();
|
||||
Xoa_ttl Ttl();
|
||||
void Xtn_gallery_packed_exists_y_();
|
||||
boolean Exists();
|
||||
Xoa_page__commons_mgr Commons_mgr();
|
||||
}
|
||||
24
400_xowa/src_300_html/gplx/xowa/Xoa_page_.java
Normal file
24
400_xowa/src_300_html/gplx/xowa/Xoa_page_.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; import gplx.*;
|
||||
public class Xoa_page_ {
|
||||
public static final byte Edit_mode_create = 1, Edit_mode_update = 2;
|
||||
public static final byte[] Main_page_bry = Bry_.new_a7("Main_Page"); // OBSOLETE; may not work for non-english wikis
|
||||
public static final byte[] Main_page_bry_empty = Bry_.Empty;
|
||||
public static final int Page_len_max = 2048 * Io_mgr.Len_kb; // REF.MW: DefaultSettings.php; $wgMaxArticleSize = 2048;
|
||||
}
|
||||
27
400_xowa/src_300_html/gplx/xowa/Xoa_page__commons_mgr.java
Normal file
27
400_xowa/src_300_html/gplx/xowa/Xoa_page__commons_mgr.java
Normal file
@@ -0,0 +1,27 @@
|
||||
/*
|
||||
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_page__commons_mgr {
|
||||
public boolean Xowa_mockup() {return xowa_mockup;} public void Xowa_mockup_(boolean v) {xowa_mockup = v;} private boolean xowa_mockup;
|
||||
public Xow_wiki Source_wiki() {return source_wiki;} public void Source_wiki_(Xow_wiki v) {source_wiki = v;} private Xow_wiki source_wiki;
|
||||
public Xow_wiki Source_wiki_or(Xow_wiki or) {return source_wiki == null ? or : source_wiki;}
|
||||
public void Clear() {
|
||||
this.xowa_mockup = false;
|
||||
this.source_wiki = null;
|
||||
}
|
||||
}
|
||||
110
400_xowa/src_300_html/gplx/xowa/Xoae_page.java
Normal file
110
400_xowa/src_300_html/gplx/xowa/Xoae_page.java
Normal file
@@ -0,0 +1,110 @@
|
||||
/*
|
||||
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.xowa.gui.*; import gplx.xowa.gui.views.*; import gplx.xowa.html.*; import gplx.xowa.pages.*;
|
||||
import gplx.xowa.files.*; import gplx.xowa.files.xfers.*; import gplx.xowa.xtns.cite.*; import gplx.xowa.xtns.wdatas.*; import gplx.xowa.parsers.lnkis.redlinks.*; import gplx.xowa.html.tocs.*;
|
||||
import gplx.xowa.html.modules.popups.*; import gplx.xowa.html.hdumps.pages.*; import gplx.xowa.xtns.wdatas.pfuncs.*;
|
||||
public class Xoae_page implements Xoa_page {
|
||||
Xoae_page(Xowe_wiki wiki, Xoa_ttl ttl) {
|
||||
this.wiki = wiki; this.ttl = ttl;
|
||||
this.lang = wiki.Lang(); // default to wiki.lang; can be override later by wikitext
|
||||
hdr_mgr = new Xow_hdr_mgr(this, Xoa_app_.Utl__encoder_mgr());
|
||||
redlink_lnki_list = new Xopg_redlink_lnki_list(ttl.Ns().Id_module());
|
||||
Ttl_(ttl);
|
||||
} Xoae_page() {} // called by Null
|
||||
public Xow_wiki Wiki() {return wiki;}
|
||||
public Xoa_ttl Ttl() {return ttl;} public Xoae_page Ttl_(Xoa_ttl v) {ttl = v; url.Wiki_bry_(wiki.Domain_bry()).Page_bry_(v.Full_url()); return this;} private Xoa_ttl ttl;
|
||||
public Xoa_url Url() {return url;} public Xoae_page Url_(Xoa_url v) {url = v; return this;} private Xoa_url url = Xoa_url.blank_();
|
||||
public byte[] Url_bry_safe() {return url == null ? Bry_.Empty : url.Raw();}
|
||||
public void Xtn_gallery_packed_exists_y_() {html_data.Xtn_gallery_packed_exists_y_();}
|
||||
public boolean Exists() {return !Missing();}
|
||||
|
||||
public Xoa_page__commons_mgr Commons_mgr() {return commons_mgr;} private final Xoa_page__commons_mgr commons_mgr = new Xoa_page__commons_mgr();
|
||||
public Xopg_revision_data Revision_data() {return revision_data;} private Xopg_revision_data revision_data = new Xopg_revision_data();
|
||||
public Xowe_wiki Wikie() {return wiki;} private Xowe_wiki wiki;
|
||||
public Xopg_redlink_lnki_list Redlink_lnki_list() {return redlink_lnki_list;} private Xopg_redlink_lnki_list redlink_lnki_list;
|
||||
public Xol_lang Lang() {return lang;} public Xoae_page Lang_(Xol_lang v) {lang = v; return this;} private Xol_lang lang;
|
||||
public Xopg_html_data Html_data() {return html_data;} private Xopg_html_data html_data = new Xopg_html_data();
|
||||
public Xopg_tab_data Tab_data() {return tab_data;} private final Xopg_tab_data tab_data = new Xopg_tab_data();
|
||||
public Xopg_hdump_data Hdump_data() {return hdump_data;} private final Xopg_hdump_data hdump_data = new Xopg_hdump_data();
|
||||
public boolean Missing() {return missing;} public Xoae_page Missing_() {return Missing_(true);} public Xoae_page Missing_(boolean v) {missing = v; return this;} private boolean missing;
|
||||
public boolean Redirected() {return redirected;} public Xoae_page Redirected_(boolean v) {redirected = v; return this;} private boolean redirected;
|
||||
public List_adp Redirected_ttls() {return redirected_ttls;} private List_adp redirected_ttls = List_adp_.new_();
|
||||
public byte[] Redirected_ttls__itm_0() {return (byte[])redirected_ttls.Get_at(0);}
|
||||
public byte[] Redirected_src() {return redirected_src;} public void Redirected_src_(byte[] v) {this.redirected_src = v;} private byte[] redirected_src;
|
||||
public byte Edit_mode() {return edit_mode;} private byte edit_mode; public void Edit_mode_update_() {edit_mode = Xoa_page_.Edit_mode_update;}
|
||||
public Xop_root_tkn Root() {return root;} public Xoae_page Root_(Xop_root_tkn v) {root = v; return this;} private Xop_root_tkn root;
|
||||
public byte[] Data_raw() {return data_raw;} public Xoae_page Data_raw_(byte[] v) {data_raw = v; return this;} private byte[] data_raw = Bry_.Empty;
|
||||
public Xow_hdr_mgr Hdr_mgr() {return hdr_mgr;} private Xow_hdr_mgr hdr_mgr;
|
||||
public Xoh_cmd_mgr Html_cmd_mgr() {return html_cmd_mgr;} private Xoh_cmd_mgr html_cmd_mgr = new Xoh_cmd_mgr();
|
||||
public byte[][] Category_list() {return category_list;} public Xoae_page Category_list_(byte[][] v) {category_list = v; return this;} private byte[][] category_list = new byte[0][];
|
||||
public List_adp Lnki_list() {return lnki_list;} public void Lnki_list_(List_adp v) {this.lnki_list = v;} private List_adp lnki_list = List_adp_.new_();
|
||||
public Xof_xfer_queue File_queue() {return file_queue;} private Xof_xfer_queue file_queue = new Xof_xfer_queue();
|
||||
public List_adp File_math() {return file_math;} private List_adp file_math = List_adp_.new_();
|
||||
public Ref_itm_mgr Ref_mgr() {return ref_mgr;} private Ref_itm_mgr ref_mgr = new Ref_itm_mgr();
|
||||
public Xopg_popup_mgr Popup_mgr() {return popup_mgr;} private Xopg_popup_mgr popup_mgr = new Xopg_popup_mgr();
|
||||
public List_adp Slink_list() {return slink_list;} private List_adp slink_list = List_adp_.new_();
|
||||
public Wdata_external_lang_links_data Wdata_external_lang_links() {return wdata_external_lang_links;} private Wdata_external_lang_links_data wdata_external_lang_links = new Wdata_external_lang_links_data();
|
||||
public boolean Pages_recursed() {return pages_recursed;} public void Pages_recursed_(boolean v) {pages_recursed = v; } private boolean pages_recursed;
|
||||
public int Bldr__ns_ord() {return bldr__ns_ord;} public void Bldr__ns_ord_(int v) {bldr__ns_ord = v;} private int bldr__ns_ord;
|
||||
public Xopg_tmpl_prepend_mgr Tmpl_prepend_mgr() {return tmpl_prepend_mgr;} private Xopg_tmpl_prepend_mgr tmpl_prepend_mgr = new Xopg_tmpl_prepend_mgr();
|
||||
public void Tmpl_stack_del() {--tmpl_stack_ary_len;}
|
||||
public boolean Tmpl_stack_add(byte[] key) {
|
||||
for (int i = 0; i < tmpl_stack_ary_len; i++) {
|
||||
if (Bry_.Match(key, tmpl_stack_ary[i])) return false;
|
||||
}
|
||||
int new_len = tmpl_stack_ary_len + 1;
|
||||
if (new_len > tmpl_stack_ary_max) {
|
||||
tmpl_stack_ary_max = new_len * 2;
|
||||
tmpl_stack_ary = (byte[][])Array_.Resize(tmpl_stack_ary, tmpl_stack_ary_max);
|
||||
}
|
||||
tmpl_stack_ary[tmpl_stack_ary_len] = key;
|
||||
tmpl_stack_ary_len = new_len;
|
||||
return true;
|
||||
} private byte[][] tmpl_stack_ary = Bry_.Ary_empty; private int tmpl_stack_ary_len = 0, tmpl_stack_ary_max = 0;
|
||||
public void Clear() { // NOTE: this is called post-fetch but pre-parse; do not clear items set by post-fetch, such as id, ttl, redirected_ttls, data_raw
|
||||
hdr_mgr.Clear();
|
||||
lnki_list.Clear();
|
||||
file_math.Clear();
|
||||
file_queue.Clear();
|
||||
ref_mgr.Grps_clear();
|
||||
html_cmd_mgr.Clear();
|
||||
hdump_data.Clear();
|
||||
wdata_external_lang_links.Reset();
|
||||
gplx.xowa.xtns.scribunto.Scrib_core.Core_page_changed(this);
|
||||
slink_list.Clear();
|
||||
html_data.Clear();
|
||||
tab_data.Clear();
|
||||
pages_recursed = false;
|
||||
tmpl_stack_ary = Bry_.Ary_empty;
|
||||
tmpl_stack_ary_len = tmpl_stack_ary_max = 0;
|
||||
popup_mgr.Clear();
|
||||
revision_data.Clear();
|
||||
tmpl_prepend_mgr.Clear();
|
||||
commons_mgr.Clear();
|
||||
}
|
||||
public static final Xoae_page Null = null;
|
||||
public static final Xoae_page Empty = new Xoae_page().Missing_();
|
||||
public static Xoae_page test_(Xowe_wiki wiki, Xoa_ttl ttl) {return new Xoae_page(wiki, ttl);}
|
||||
public static Xoae_page new_(Xowe_wiki wiki, Xoa_ttl ttl) {return new Xoae_page(wiki, ttl);}
|
||||
public static Xoae_page create_(Xowe_wiki wiki, Xoa_ttl ttl) {
|
||||
Xoae_page rv = new Xoae_page(wiki, ttl);
|
||||
rv.edit_mode = Xoa_page_.Edit_mode_create;
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
26
400_xowa/src_300_html/gplx/xowa/Xoh_cfg_gallery.java
Normal file
26
400_xowa/src_300_html/gplx/xowa/Xoh_cfg_gallery.java
Normal file
@@ -0,0 +1,26 @@
|
||||
/*
|
||||
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 Xoh_cfg_gallery implements GfoInvkAble {
|
||||
public int Imgs_per_row() {return imgs_per_row;} public Xoh_cfg_gallery Imgs_per_row_(int v) {imgs_per_row = v; return this;} private int imgs_per_row = 8; // changed from 4 to 8; DATE:2014-02-04
|
||||
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
|
||||
if (ctx.Match(k, Invk_imgs_per_row_)) imgs_per_row = m.ReadInt("v");
|
||||
else return GfoInvkAble_.Rv_unhandled;
|
||||
return this;
|
||||
} private static final String Invk_imgs_per_row_ = "imgs_per_row_";
|
||||
}
|
||||
71
400_xowa/src_300_html/gplx/xowa/Xoh_dom_.java
Normal file
71
400_xowa/src_300_html/gplx/xowa/Xoh_dom_.java
Normal file
@@ -0,0 +1,71 @@
|
||||
/*
|
||||
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.html.*;
|
||||
public class Xoh_dom_ {
|
||||
private static final byte[] Lt_bry = Bry_.new_a7("<"), Space_bry = Bry_.new_a7(" ");
|
||||
public static byte[] Query_val_by_where(Xoh_find rv, byte[] src, byte[] where_nde, byte[] where_key, byte[] where_val, byte[] query_key, int bgn) {
|
||||
int src_len = src.length;
|
||||
where_nde = Bry_.Add(Lt_bry, where_nde, Space_bry);
|
||||
while (true) {
|
||||
boolean where_val_found = Select_tag(rv, src, where_nde, where_key, bgn, src_len);
|
||||
if (where_val_found) {
|
||||
int tag_bgn = rv.Tag_bgn();
|
||||
int tag_end = rv.Tag_end();
|
||||
boolean where_val_match = Bry_.Match(src, rv.Val_bgn(), rv.Val_end(), where_val);
|
||||
if (where_val_match) {
|
||||
boolean query_val_found = Find_atr_val_in_tag(rv, src, query_key, tag_bgn, tag_end);
|
||||
if (query_val_found) {
|
||||
return Bry_.Mid(src, rv.Val_bgn(), rv.Val_end());
|
||||
}
|
||||
else
|
||||
return null;
|
||||
}
|
||||
else
|
||||
bgn = tag_end + 1;
|
||||
}
|
||||
else
|
||||
break;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
public static boolean Select_tag(Xoh_find rv, byte[] src, byte[] nde, byte[] key, int rng_bgn, int rng_end) {
|
||||
int tag_bgn = Bry_finder.Find_fwd(src, nde, rng_bgn, rng_end); if (tag_bgn == Bry_.NotFound) return false;
|
||||
int tag_end = Bry_finder.Find_fwd(src, Byte_ascii.Gt, tag_bgn, rng_end); if (tag_end == Bry_.NotFound) return false;
|
||||
int key_bgn = Bry_finder.Find_fwd(src, key, tag_bgn, tag_end); if (key_bgn == Bry_.NotFound) return false;
|
||||
int key_end = key_bgn + key.length;
|
||||
int val_bgn = Bry_finder.Find_fwd(src, Byte_ascii.Quote, key_end, tag_end); if (val_bgn == Bry_.NotFound) return false;
|
||||
++val_bgn;
|
||||
int val_end = Bry_finder.Find_fwd(src, Byte_ascii.Quote, val_bgn, tag_end); if (val_end == Bry_.NotFound) return false;
|
||||
rv.Set_all(tag_bgn, tag_end, key_bgn, key_end, val_bgn, val_end);
|
||||
return true;
|
||||
}
|
||||
public static boolean Find_atr_val_in_tag(Xoh_find rv, byte[] src, byte[] key, int tag_bgn, int tag_end) {
|
||||
int key_bgn = Bry_finder.Find_fwd(src, key, tag_bgn, tag_end); if (key_bgn == Bry_.NotFound) return false;
|
||||
int key_end = key_bgn + key.length;
|
||||
int val_bgn = Bry_finder.Find_fwd(src, Byte_ascii.Quote, key_end, tag_end); if (val_bgn == Bry_.NotFound) return false;
|
||||
++val_bgn;
|
||||
int val_end = Bry_finder.Find_fwd(src, Byte_ascii.Quote, val_bgn, tag_end); if (val_end == Bry_.NotFound) return false;
|
||||
rv.Set_all(tag_bgn, tag_end, key_bgn, key_end, val_bgn, val_end);
|
||||
return true;
|
||||
}
|
||||
public static String Title_by_href(byte[] href, byte[] html_src) {
|
||||
byte[] xowa_title = Xoh_dom_.Query_val_by_where(dom_find, html_src, Html_tag_.A_name_bry, Html_atr_.Href_bry, href, gplx.xowa.html.Xoh_consts.Atr_xowa_title_bry, 0);
|
||||
return String_.new_u8(xowa_title);
|
||||
} private static final Xoh_find dom_find = new Xoh_find();
|
||||
}
|
||||
45
400_xowa/src_300_html/gplx/xowa/Xoh_dom_tst.java
Normal file
45
400_xowa/src_300_html/gplx/xowa/Xoh_dom_tst.java
Normal file
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
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 org.junit.*;
|
||||
public class Xoh_dom_tst {
|
||||
@Test public void Find_atr() {
|
||||
String src = "a <nde0 atr0=\"val0\" atr1=\"val1\"/> b <nde1 atr0=\"val3\" atr1=\"val4\"/> c";
|
||||
tst_Find(src, "nde0", "atr0", "val0", "atr1", "val1"); // match nde0
|
||||
tst_Find(src, "nde1", "atr0", "val3", "atr1", "val4"); // match nde1
|
||||
tst_Find(src, "nde0", "atr0", "val5", "atr1", null); // wrong val
|
||||
tst_Find(src, "nde0", "atr2", "val0", "atr1", null); // wrong key
|
||||
tst_Find(src, "nde2", "atr0", "val0", "atr1", null); // wrong nde
|
||||
}
|
||||
@Test public void Title_by_href() {// PURPOSE: handle content-editable=n and finding file directly for download
|
||||
Title_by_href_tst
|
||||
( "/wiki/File:Bazille,_Fr%C3%A9d%C3%A9ric_%7E_Le_Petit_Jardinier_%28The_Little_Gardener%29,_c1866-67_oil_on_canvas_Museum_of_Fine_Arts,_Houston.jpg"
|
||||
, "<a href=\"lure\" xowa_title=\"wrong\"></a><a href=\"/wiki/File:Bazille,_Fr%C3%A9d%C3%A9ric_%7E_Le_Petit_Jardinier_%28The_Little_Gardener%29,_c1866-67_oil_on_canvas_Museum_of_Fine_Arts,_Houston.jpg\" xowa_title=\"find_me\"></a>"
|
||||
, "find_me"
|
||||
);
|
||||
}
|
||||
private void tst_Find(String src, String where_nde, String where_key, String where_val, String select_key, String expd) {
|
||||
Xoh_find rv = new Xoh_find();
|
||||
byte[] actl = Xoh_dom_.Query_val_by_where(rv, Bry_.new_u8(src), Bry_.new_u8(where_nde), Bry_.new_u8(where_key), Bry_.new_u8(where_val), Bry_.new_u8(select_key), 0);
|
||||
Tfds.Eq(expd, String_.new_u8(actl));
|
||||
}
|
||||
private void Title_by_href_tst(String href, String html_src, String expd) {
|
||||
String actl = Xoh_dom_.Title_by_href(Bry_.new_u8(href), Bry_.new_u8(html_src));
|
||||
Tfds.Eq(expd, actl);
|
||||
}
|
||||
}
|
||||
29
400_xowa/src_300_html/gplx/xowa/Xoh_find.java
Normal file
29
400_xowa/src_300_html/gplx/xowa/Xoh_find.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; import gplx.*;
|
||||
public class Xoh_find {
|
||||
public int Tag_bgn() {return tag_bgn;} public Xoh_find Tag_bgn_(int v) {tag_bgn = v; return this;} private int tag_bgn;
|
||||
public int Tag_end() {return tag_end;} public Xoh_find Tag_end_(int v) {tag_end = v; return this;} private int tag_end;
|
||||
public int Key_bgn() {return key_bgn;} public Xoh_find Key_bgn_(int v) {key_bgn = v; return this;} private int key_bgn;
|
||||
public int Key_end() {return key_end;} public Xoh_find Key_end_(int v) {key_end = v; return this;} private int key_end;
|
||||
public int Val_bgn() {return val_bgn;} public Xoh_find Val_bgn_(int v) {val_bgn = v; return this;} private int val_bgn;
|
||||
public int Val_end() {return val_end;} public Xoh_find Val_end_(int v) {val_end = v; return this;} private int val_end;
|
||||
public void Set_all(int tag_bgn, int tag_end, int key_bgn, int key_end, int val_bgn, int val_end) {
|
||||
this.tag_bgn = tag_bgn; this.tag_end = tag_end; this.key_bgn = key_bgn; this.key_end = key_end; this.val_bgn = val_bgn; this.val_end = val_end;
|
||||
}
|
||||
}
|
||||
90
400_xowa/src_300_html/gplx/xowa/Xop_link_parser.java
Normal file
90
400_xowa/src_300_html/gplx/xowa/Xop_link_parser.java
Normal file
@@ -0,0 +1,90 @@
|
||||
/*
|
||||
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.xowa.net.*; import gplx.xowa.wikis.xwikis.*;
|
||||
import gplx.xowa.html.*; import gplx.xowa.html.lnkis.*; import gplx.xowa.html.hrefs.*;
|
||||
public class Xop_link_parser {
|
||||
public byte[] Html_xowa_ttl() {return html_xowa_ttl;} private byte[] html_xowa_ttl;
|
||||
public byte Html_anchor_cls() {return html_anchor_cls;} private byte html_anchor_cls;
|
||||
public byte Html_anchor_rel() {return html_anchor_rel;} private byte html_anchor_rel;
|
||||
public byte[] Parse(Bry_bfr tmp_bfr, Xoa_url tmp_url, Xowe_wiki wiki, byte[] raw, byte[] or) {
|
||||
html_xowa_ttl = null; html_anchor_cls = Xoh_lnki_consts.Tid_a_cls_image; html_anchor_rel = Xoh_lnki_consts.Tid_a_rel_none; // default member variables for html
|
||||
Xoae_app app = wiki.Appe(); int raw_len = raw.length;
|
||||
app.Utl__url_parser().Parse(tmp_url, raw);
|
||||
switch (tmp_url.Protocol_tid()) {
|
||||
case Xoo_protocol_itm.Tid_http: case Xoo_protocol_itm.Tid_https: // "http:" or "https:"; check if to offline wiki and redirect
|
||||
byte[] wiki_bry = tmp_url.Wiki_bry(), page_bry = tmp_url.Page_bry();
|
||||
if (Bry_.Eq(wiki_bry, wiki.Domain_bry()) // link is to this wiki; check if alias
|
||||
|| app.Xwiki_mgr__exists(wiki_bry)) { // link is to an xwiki
|
||||
page_bry = tmp_url.Page_for_lnki();
|
||||
Parse__ttl(tmp_bfr, wiki, wiki_bry, page_bry);
|
||||
}
|
||||
else { // http is to an unknown site
|
||||
if (tmp_url.Protocol_is_relative()) // relative protocol; EX:"//www.a.org";
|
||||
tmp_bfr.Add(tmp_url.Protocol_bry()).Add(raw); // prepend protocol b/c mozilla cannot launch "//www.a.org", but can launch "http://www.a.org"
|
||||
else // regular url
|
||||
tmp_bfr.Add(raw); // dump everything
|
||||
}
|
||||
raw = tmp_bfr.Xto_bry_and_clear();
|
||||
html_anchor_cls = Xoh_lnki_consts.Tid_a_cls_none;
|
||||
html_anchor_rel = Xoh_lnki_consts.Tid_a_rel_nofollow;
|
||||
break;
|
||||
case Xoo_protocol_itm.Tid_file: // "file:///" or "File:A.png"
|
||||
int proto_len = tmp_url.Protocol_bry().length;
|
||||
if (proto_len + 1 < raw_len && raw[proto_len + 1] == Byte_ascii.Slash) { // next char is slash, assume xfer_itm refers to protocol; EX: file:///C/A.png
|
||||
int slash_pos = Bry_finder.Find_bwd(raw, Byte_ascii.Slash);
|
||||
if (slash_pos != Bry_.NotFound) // set xowa_title to file_name; TODO: call Xoa_url.build; note that this will fail sometimes when (a) xfer_itm is very long (File:ReallyLongName will be shortened to 128 chars) or (b) xfer_itm has invalid windows characters (EX:File:a"b"c.jpg)
|
||||
html_xowa_ttl = Bry_.Mid(raw, slash_pos + Int_.Const_dlm_len, raw.length);
|
||||
}
|
||||
else // next char is not slash; assume xfer_itm refers to ns; EX:File:A.png
|
||||
raw = tmp_bfr.Add(Xoh_href_parser.Href_wiki_bry).Add(raw).Xto_bry_and_clear();
|
||||
break;
|
||||
default: // is page only; EX: Abc
|
||||
if (Bry_.Len_eq_0(raw)) // NOTE: handle blank link; EX: [[File:Loudspeaker.svg|11px|link=|alt=play]]
|
||||
raw = or;
|
||||
else {
|
||||
if (raw[0] == Byte_ascii.Colon) raw = Bry_.Mid(raw, 1, raw.length); // ignore initial colon; EX: [[:commons:A.png]]
|
||||
if (!Parse__ttl(tmp_bfr, wiki, wiki.Domain_bry(), raw)) {
|
||||
tmp_bfr.Clear();
|
||||
return null;
|
||||
}
|
||||
raw = tmp_bfr.Xto_bry_and_clear();
|
||||
}
|
||||
break;
|
||||
}
|
||||
return raw;
|
||||
}
|
||||
private static boolean Parse__ttl(Bry_bfr tmp_bfr, Xowe_wiki wiki, byte[] wiki_bry, byte[] page_bry) {
|
||||
Xoa_ttl page_ttl = Xoa_ttl.parse_(wiki, page_bry);
|
||||
boolean page_ttl_is_valid = page_ttl != null;
|
||||
if (page_ttl_is_valid) {
|
||||
Xow_xwiki_itm xwiki_itm = page_ttl.Wik_itm();
|
||||
if (xwiki_itm != null) { // is alias; set wiki, page
|
||||
wiki_bry = xwiki_itm.Domain_bry();
|
||||
page_bry = Bry_.Mid(page_bry, xwiki_itm.Key_bry().length + 1, page_bry.length); // +1 for ":"
|
||||
}
|
||||
else // is regular page; use ttl.Full_db() to normalize; EX: -> _
|
||||
page_bry = page_ttl.Full_db();
|
||||
}
|
||||
if (Bry_.Eq(wiki_bry, wiki.Domain_bry())) // NOTE: check against wiki.Key_bry() again; EX: in en_wiki, and http://commons.wikimedia.org/wiki/w:A
|
||||
tmp_bfr.Add(Xoh_href_parser.Href_wiki_bry).Add(page_bry);
|
||||
else
|
||||
tmp_bfr.Add(Xoh_href_parser.Href_site_bry).Add(wiki_bry).Add(Xoh_href_parser.Href_wiki_bry).Add(page_bry);
|
||||
return page_ttl_is_valid;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user