mirror of
https://github.com/gnosygnu/xowa.git
synced 2026-03-02 03:49:30 +00:00
v1.6.5.1
This commit is contained in:
64
400_xowa/src_160_file/gplx/xowa/Xoa_repo_mgr.java
Normal file
64
400_xowa/src_160_file/gplx/xowa/Xoa_repo_mgr.java
Normal file
@@ -0,0 +1,64 @@
|
||||
/*
|
||||
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_repo_mgr implements GfoInvkAble {
|
||||
public Xoa_repo_mgr(Xoa_app app) {this.app = app;}
|
||||
public Xoa_app App() {return app;} private Xoa_app app;
|
||||
public int Count() {return hash.Count();}
|
||||
public Xof_repo_itm Get_at(int i) {return (Xof_repo_itm)hash.FetchAt(i);}
|
||||
public Xof_repo_itm Get_by(byte[] key) {return (Xof_repo_itm)hash.Fetch(key);}
|
||||
public Xof_repo_itm Get_primary(byte[] key) {
|
||||
int len = hash.Count();
|
||||
for (int i = 0; i < len; i++) {
|
||||
Xof_repo_itm repo = (Xof_repo_itm)hash.FetchAt(i);
|
||||
if (Bry_.Eq(key, repo.Wiki_key()) && repo.Primary()) return repo;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
public Xof_repo_itm Get_by_wmf(byte[] key) {
|
||||
int len = hash.Count();
|
||||
for (int i = 0; i < len; i++) {
|
||||
Xof_repo_itm repo = (Xof_repo_itm)hash.FetchAt(i);
|
||||
if (Bry_.Eq(key, repo.Wiki_key()) && repo.Wmf_fsys()) return repo;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
public Xof_repo_itm Get_by_wiki_key(byte[] key) {
|
||||
int len = hash.Count();
|
||||
for (int i = 0; i < len; i++) {
|
||||
Xof_repo_itm repo = (Xof_repo_itm)hash.FetchAt(i);
|
||||
if (Bry_.Eq(key, repo.Wiki_key())) return repo;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
public Xof_repo_itm Add(Xof_repo_itm itm) {hash.Add(itm.Key(), itm); return itm;} private OrderedHash hash = OrderedHash_.new_bry_();
|
||||
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
|
||||
if (ctx.Match(k, Invk_set)) return Set(m.ReadStr("key"), m.ReadStr("url"), m.ReadStr("wiki"));
|
||||
else return GfoInvkAble_.Rv_unhandled;
|
||||
} private static final String Invk_set = "set";
|
||||
public Xof_repo_itm Set(String key, String url_str, String wiki) {
|
||||
byte[] key_bry = Bry_.new_utf8_(key);
|
||||
Xof_repo_itm itm = (Xof_repo_itm)hash.Fetch(key_bry);
|
||||
if (itm == null) {
|
||||
itm = new Xof_repo_itm(this, key_bry);
|
||||
this.Add(itm);
|
||||
}
|
||||
itm.Root_str_(url_str).Wiki_key_(Bry_.new_utf8_(wiki));
|
||||
return itm;
|
||||
}
|
||||
}
|
||||
46
400_xowa/src_160_file/gplx/xowa/Xoaf_download_mgr.java
Normal file
46
400_xowa/src_160_file/gplx/xowa/Xoaf_download_mgr.java
Normal file
@@ -0,0 +1,46 @@
|
||||
/*
|
||||
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 Xoaf_download_mgr implements GfoInvkAble {
|
||||
public Xoaf_download_mgr(Xoa_app app) {
|
||||
this.app = app;
|
||||
download_wkr = new Xof_download_wkr_io(app);
|
||||
download_wkr.Download_xrg().User_agent_(Xoa_app_.User_agent).Prog_dlg_(app.Usr_dlg());
|
||||
} private Xoa_app app;
|
||||
public boolean Enabled() {return enabled;}
|
||||
public Xoaf_download_mgr Enabled_(boolean v) {
|
||||
enabled = v;
|
||||
File_download_enable(app, v);
|
||||
return this;
|
||||
} private boolean enabled;
|
||||
public Xof_download_wkr Download_wkr() {return download_wkr;} public Xoaf_download_mgr Download_wkr_(Xof_download_wkr v) {download_wkr = v; return this;} private Xof_download_wkr download_wkr;
|
||||
public Xof_img_wkr_api_size_base Api_size_wkr() {return api_size_wkr;} public Xoaf_download_mgr Api_size_wkr_(Xof_img_wkr_api_size_base v) {api_size_wkr = v; return this;} private Xof_img_wkr_api_size_base api_size_wkr = new Xof_img_wkr_api_size_base_wmf();
|
||||
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
|
||||
if (ctx.Match(k, Invk_enabled)) return Yn.X_to_str(enabled);
|
||||
else if (ctx.Match(k, Invk_enabled_)) Enabled_(m.ReadYn("v"));
|
||||
else return GfoInvkAble_.Rv_unhandled;
|
||||
return this;
|
||||
} private static final String Invk_enabled = "enabled", Invk_enabled_ = "enabled_";
|
||||
public static void File_download_enable(Xoa_app app, boolean v) {
|
||||
int len = app.Wiki_mgr().Count();
|
||||
for (int i = 0; i < len; i++) {
|
||||
Xow_wiki wiki = app.Wiki_mgr().Get_at(i);
|
||||
wiki.File_mgr().Cfg_download().Enabled_(v);
|
||||
}
|
||||
}
|
||||
}
|
||||
50
400_xowa/src_160_file/gplx/xowa/Xof_cfg_download.java
Normal file
50
400_xowa/src_160_file/gplx/xowa/Xof_cfg_download.java
Normal file
@@ -0,0 +1,50 @@
|
||||
/*
|
||||
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 Xof_cfg_download implements GfoInvkAble {
|
||||
public Xof_cfg_download() {
|
||||
this.enabled = true; // CFG: set to false b/c some tests only do parsing [[File:A.png]] and repos are not set up
|
||||
this.redownload = Redownload_none; // CFG: set to none to be as conservative as possible
|
||||
}
|
||||
public boolean Enabled() {return enabled;} public Xof_cfg_download Enabled_(boolean v) {enabled = v; return this;} private boolean enabled;
|
||||
public byte Redownload() {return redownload;} public Xof_cfg_download Redownload_(byte v) {redownload = v; return this;} private byte redownload;
|
||||
|
||||
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
|
||||
if (ctx.Match(k, Invk_enabled_)) enabled = m.ReadYn("v");
|
||||
else if (ctx.Match(k, Invk_redownload)) return Redownload_to_str_(redownload);
|
||||
else if (ctx.Match(k, Invk_redownload_)) redownload = Redownload_parse_(m.ReadStr("v"));
|
||||
else if (ctx.Match(k, Invk_redownload_toggle)) redownload = redownload == Redownload_none ? Redownload_missing : Redownload_none;
|
||||
else return GfoInvkAble_.Rv_unhandled;
|
||||
return this;
|
||||
} private static final String Invk_enabled_ = "enabled_", Invk_redownload = "redownload", Invk_redownload_ = "redownload_", Invk_redownload_toggle = "redownload_toggle";
|
||||
byte Redownload_parse_(String s) {
|
||||
if (String_.Eq(s, "none")) return Redownload_none;
|
||||
else if (String_.Eq(s, "missing")) return Redownload_missing;
|
||||
else if (String_.Eq(s, "all")) return Redownload_all;
|
||||
else throw Err_.unhandled(s);
|
||||
}
|
||||
public static final byte Redownload_none = 0, Redownload_missing = 1, Redownload_all = 2;
|
||||
String Redownload_to_str_(byte v) {
|
||||
switch (v) {
|
||||
case Redownload_none: return "none";
|
||||
case Redownload_missing: return "missing";
|
||||
case Redownload_all: return "all";
|
||||
default: throw Err_.unhandled(v);
|
||||
}
|
||||
}
|
||||
}
|
||||
57
400_xowa/src_160_file/gplx/xowa/Xof_download_wkr.java
Normal file
57
400_xowa/src_160_file/gplx/xowa/Xof_download_wkr.java
Normal file
@@ -0,0 +1,57 @@
|
||||
/*
|
||||
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.ios.*;
|
||||
import gplx.gfui.*;
|
||||
public interface Xof_download_wkr {
|
||||
byte Download(boolean src_is_web, String src, Io_url trg, String prog_fmt_hdr);
|
||||
IoEngine_xrg_downloadFil Download_xrg();
|
||||
}
|
||||
class Xof_download_wkr_test implements Xof_download_wkr {
|
||||
public IoEngine_xrg_downloadFil Download_xrg() {return IoEngine_xrg_downloadFil.new_("", Io_url_.Null).Trg_engine_key_(IoEngine_.MemKey);}
|
||||
public byte Download(boolean src_is_web, String src_str, Io_url trg_url, String prog_fmt_hdr) {
|
||||
Io_mgr._.CreateDirIfAbsent(trg_url.OwnerDir());
|
||||
Io_url src_url = Io_url_.new_fil_(src_str);
|
||||
if (!Io_mgr._.ExistsFil(src_url)) return IoEngine_xrg_downloadFil.Rslt_fail_file_not_found;
|
||||
try {Io_mgr._.CopyFil(src_url, trg_url, true);}
|
||||
catch (Exception exc) {Err_.Noop(exc); return IoEngine_xrg_downloadFil.Rslt_fail_unknown;}
|
||||
return IoEngine_xrg_downloadFil.Rslt_pass;
|
||||
}
|
||||
}
|
||||
class Xof_download_wkr_io implements Xof_download_wkr {
|
||||
IoEngine_xrg_downloadFil xrg = Io_mgr._.DownloadFil_args("", Io_url_.Null);
|
||||
public Xof_download_wkr_io(Xoa_app app) {}
|
||||
public IoEngine_xrg_downloadFil Download_xrg() {return xrg;}
|
||||
public String Download_err() {return download_err;} private String download_err = "";
|
||||
public byte Download(boolean src_is_web, String src_str, Io_url trg_url, String prog_fmt_hdr) {
|
||||
download_err = "";
|
||||
if (src_is_web) {
|
||||
xrg.Prog_fmt_hdr_(prog_fmt_hdr);
|
||||
xrg.Init(src_str, trg_url);
|
||||
xrg.Exec();
|
||||
return xrg.Rslt();
|
||||
}
|
||||
else {
|
||||
Io_url src_url = Io_url_.new_fil_(src_str);
|
||||
if (!Io_mgr._.ExistsFil(src_url)) return IoEngine_xrg_downloadFil.Rslt_fail_file_not_found;
|
||||
try {Io_mgr._.CopyFil(src_url, trg_url, true);}
|
||||
catch (Exception exc) {Err_.Noop(exc); return IoEngine_xrg_downloadFil.Rslt_fail_unknown;}
|
||||
return IoEngine_xrg_downloadFil.Rslt_pass;
|
||||
}
|
||||
}
|
||||
}
|
||||
41
400_xowa/src_160_file/gplx/xowa/Xof_ext.java
Normal file
41
400_xowa/src_160_file/gplx/xowa/Xof_ext.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.*;
|
||||
public class Xof_ext {
|
||||
public Xof_ext(int id, byte[] ext) {this.id = id; this.ext = ext;}
|
||||
public int Id() {return id;} private int id;
|
||||
public byte[] Ext() {return ext;} private byte[] ext;
|
||||
public byte[] Ext_view() {return Xof_ext_.Bry__ary[Id_view()];}
|
||||
public byte[] Mime_type() {return Xof_ext_.Mime_type__ary[id];}
|
||||
public boolean Id_is_unknown() {return id == Xof_ext_.Id_unknown;}
|
||||
public boolean Id_is_svg() {return id == Xof_ext_.Id_svg;}
|
||||
public boolean Id_is_ogg() {return id == Xof_ext_.Id_ogg;}
|
||||
public boolean Id_is_oga() {return id == Xof_ext_.Id_oga;}
|
||||
public boolean Id_is_ogv() {return id == Xof_ext_.Id_ogv;}
|
||||
public boolean Id_is_djvu() {return id == Xof_ext_.Id_djvu;}
|
||||
public boolean Id_is_pdf() {return id == Xof_ext_.Id_pdf;}
|
||||
public boolean Id_is_image() {return Xof_ext_.Id_is_image(id);}
|
||||
public boolean Id_is_media() {return Xof_ext_.Id_is_media(id);}
|
||||
public boolean Id_is_audio() {return Xof_ext_.Id_is_audio(id);}
|
||||
public boolean Id_is_audio_strict() {return Xof_ext_.Id_is_audio_strict(id);}
|
||||
public boolean Id_is_video() {return Xof_ext_.Id_is_video(id);}
|
||||
public boolean Id_is_thumbable_img() {return Xof_ext_.Id_is_thumbable_img(id);}
|
||||
public boolean Id_supports_page() {return Xof_ext_.Id_supports_page(id);}
|
||||
public boolean Id_needs_convert() {return Xof_ext_.Id_needs_convert(id);}
|
||||
public int Id_view() {return Xof_ext_.Id_view(id);}
|
||||
}
|
||||
184
400_xowa/src_160_file/gplx/xowa/Xof_ext_.java
Normal file
184
400_xowa/src_160_file/gplx/xowa/Xof_ext_.java
Normal file
@@ -0,0 +1,184 @@
|
||||
/*
|
||||
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 Xof_ext_ {
|
||||
// NOTE: do not change ids; ids are saved to image databases;
|
||||
public static final int Id_unknown = 0
|
||||
, Id_png = 1, Id_jpg = 2, Id_jpeg = 3, Id_gif = 4, Id_tif = 5, Id_tiff = 6
|
||||
, Id_svg = 7, Id_djvu = 8, Id_pdf = 9
|
||||
, Id_mid = 10, Id_ogg = 11, Id_oga = 12, Id_ogv = 13, Id_webm = 14
|
||||
, Id_flac = 15, Id_bmp = 16, Id_xcf = 17;
|
||||
public static final int Id__max = 18;
|
||||
public static final byte[]
|
||||
Bry_png = Bry_.new_ascii_("png"), Bry_jpg = Bry_.new_ascii_("jpg"), Bry_jpeg = Bry_.new_ascii_("jpeg")
|
||||
, Bry_gif = Bry_.new_ascii_("gif"), Bry_tif = Bry_.new_ascii_("tif"), Bry_tiff = Bry_.new_ascii_("tiff")
|
||||
, Bry_svg = Bry_.new_ascii_("svg"), Bry_djvu = Bry_.new_ascii_("djvu"), Bry_pdf = Bry_.new_ascii_("pdf")
|
||||
, Bry_mid = Bry_.new_ascii_("mid"), Bry_ogg = Bry_.new_ascii_("ogg"), Bry_oga = Bry_.new_ascii_("oga")
|
||||
, Bry_ogv = Bry_.new_ascii_("ogv"), Bry_webm = Bry_.new_ascii_("webm")
|
||||
, Bry_flac = Bry_.new_ascii_("flac"), Bry_bmp = Bry_.new_ascii_("bmp"), Bry_xcf = Bry_.new_ascii_("xcf")
|
||||
;
|
||||
public static final byte[][] Bry__ary = new byte[][]
|
||||
{ Bry_.Empty, Bry_png, Bry_jpg, Bry_jpeg, Bry_gif, Bry_tif, Bry_tiff
|
||||
, Bry_svg, Bry_djvu, Bry_pdf, Bry_mid, Bry_ogg, Bry_oga, Bry_ogv, Bry_webm
|
||||
, Bry_flac, Bry_bmp, Bry_xcf
|
||||
};
|
||||
public static final byte[][] Mime_type__ary = new byte[][]
|
||||
{ Bry_.new_ascii_("application/octet-stream")
|
||||
, Bry_.new_ascii_("image/png"), Bry_.new_ascii_("image/jpg"), Bry_.new_ascii_("image/jpeg")
|
||||
, Bry_.new_ascii_("image/gif"), Bry_.new_ascii_("image/tiff"), Bry_.new_ascii_("image/tiff")
|
||||
, Bry_.new_ascii_("image/svg+xml"), Bry_.new_ascii_("image/x.djvu"), Bry_.new_ascii_("application/pdf")
|
||||
, Bry_.new_ascii_("application/x-midi"), Bry_.new_ascii_("video/ogg"), Bry_.new_ascii_("audio/oga")
|
||||
, Bry_.new_ascii_("video/ogg"), Bry_.new_ascii_("video/webm")
|
||||
, Bry_.new_ascii_("audio/flac"), Bry_.new_ascii_("image/bmp"), Bry_.new_ascii_("image/xcf")
|
||||
};
|
||||
private static final HashAdp id_hash = id_hash_new_();
|
||||
private static HashAdp id_hash_new_() {
|
||||
HashAdp rv = HashAdp_.new_bry_();
|
||||
id_hash_new_(rv, Bry_png, Id_png);
|
||||
id_hash_new_(rv, Bry_jpg, Id_jpg);
|
||||
id_hash_new_(rv, Bry_jpeg, Id_jpeg);
|
||||
id_hash_new_(rv, Bry_gif, Id_gif);
|
||||
id_hash_new_(rv, Bry_tif, Id_tif);
|
||||
id_hash_new_(rv, Bry_tiff, Id_tiff);
|
||||
id_hash_new_(rv, Bry_svg, Id_svg);
|
||||
id_hash_new_(rv, Bry_djvu, Id_djvu);
|
||||
id_hash_new_(rv, Bry_pdf, Id_pdf);
|
||||
id_hash_new_(rv, Bry_mid, Id_mid);
|
||||
id_hash_new_(rv, Bry_ogg, Id_ogg);
|
||||
id_hash_new_(rv, Bry_oga, Id_oga);
|
||||
id_hash_new_(rv, Bry_ogv, Id_ogv);
|
||||
id_hash_new_(rv, Bry_webm, Id_webm);
|
||||
id_hash_new_(rv, Bry_flac, Id_flac);
|
||||
id_hash_new_(rv, Bry_bmp, Id_bmp);
|
||||
id_hash_new_(rv, Bry_xcf, Id_xcf);
|
||||
return rv;
|
||||
}
|
||||
private static void id_hash_new_(HashAdp hash, byte[] key, int val) {hash.Add(key, Int_obj_val.new_(val));}
|
||||
|
||||
private static final Hash_adp_bry ext_hash = Hash_adp_bry.ci_().Add_bry_bry(Bry_png).Add_bry_bry(Bry_jpg).Add_bry_bry(Bry_jpeg).Add_bry_bry(Bry_gif).Add_bry_bry(Bry_tif).Add_bry_bry(Bry_tiff).Add_bry_bry(Bry_svg).Add_bry_bry(Bry_djvu).Add_bry_bry(Bry_pdf).Add_bry_bry(Bry_mid).Add_bry_bry(Bry_ogg).Add_bry_bry(Bry_oga).Add_bry_bry(Bry_ogv).Add_bry_bry(Bry_webm);
|
||||
private static final Xof_ext[] Ary = new Xof_ext[Id__max];
|
||||
|
||||
public static byte[] Get_ext_by_id_(int id) {
|
||||
if (id < 0 || id >= Id__max) throw Err_.new_fmt_("index out of bounds; {id}", id);
|
||||
return Bry__ary[id];
|
||||
}
|
||||
public static int Get_id_by_ext_(byte[] ext_bry) {
|
||||
Object o = id_hash.Fetch(ext_bry);
|
||||
return o == null ? Id_unknown : ((Int_obj_val)o).Val();
|
||||
}
|
||||
public static Xof_ext new_by_ttl_(byte[] ttl) {
|
||||
int ttl_len = ttl.length;
|
||||
int dot_pos = Bry_finder.Find_bwd(ttl, Byte_ascii.Dot);
|
||||
byte[] ext = (dot_pos == Bry_.NotFound || dot_pos == ttl_len) ? Bry_.Empty : Bry_.Xto_str_lower(ttl, dot_pos + 1, ttl_len); // +1 to bgn after .
|
||||
return new_(Get_id_by_ext_(ext), ext);
|
||||
}
|
||||
public static Xof_ext new_by_ext_(byte[] ext) {return new_(Get_id_by_ext_(ext), ext);}
|
||||
public static Xof_ext new_by_id_(int id) {return new_(id, Get_ext_by_id_(id));}
|
||||
public static Xof_ext new_(int id, byte[] ext) {
|
||||
Xof_ext rv = Ary[id];
|
||||
if (rv == null) {
|
||||
rv = new Xof_ext(id, ext);
|
||||
Ary[id] = rv;
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
public static byte[] Lower_ext(byte[] ttl) {
|
||||
int dot_pos = Bry_finder.Find_bwd(ttl, Byte_ascii.Dot);
|
||||
int ttl_len = ttl.length;
|
||||
if (dot_pos == Bry_.NotFound || dot_pos == ttl_len - 1) return ttl;
|
||||
Object o = ext_hash.Get_by_mid(ttl, dot_pos + 1, ttl_len);
|
||||
if (o == null) return ttl;
|
||||
byte[] ext = (byte[])o;
|
||||
boolean match = Bry_.Match(ttl, dot_pos, ttl_len, ext);
|
||||
if (match) return ttl;
|
||||
int ext_len = ext.length;
|
||||
for (int i = 0; i < ext_len; i++)
|
||||
ttl[i + dot_pos + 1] = ext[i];
|
||||
return ttl;
|
||||
}
|
||||
public static boolean Orig_file_is_img(int v) { // identifies if orig_file can be used for <img src>; EX: png is valid, but svg, ogv, pdf is not
|
||||
switch (v) {
|
||||
case Id_png: case Id_jpg: case Id_jpeg:
|
||||
case Id_gif: case Id_tif: case Id_tiff: return true;
|
||||
default: return false;
|
||||
}
|
||||
}
|
||||
public static boolean Id_supports_page(int v) { // identifies if tid supports page in lnki; EX: [[File:A.pdf|page=1]]; REF: https://en.wikipedia.org/wiki/Wikipedia:Picture_tutorial; DATE:2014-01-18
|
||||
switch (v) {
|
||||
case Id_pdf: case Id_djvu: return true;
|
||||
default: return false;
|
||||
}
|
||||
}
|
||||
public static boolean Id_supports_thumbtime(int v) { // identifies if tid supports thumbtime in lnki; EX: [[File:A.ogv|thumbtime=1]];
|
||||
switch (v) {
|
||||
case Id_ogg: case Id_ogv: case Id_webm: return true;
|
||||
default: return false;
|
||||
}
|
||||
}
|
||||
public static boolean Id_is_image(int id) {
|
||||
switch (id) {
|
||||
case Xof_ext_.Id_png: case Xof_ext_.Id_jpg: case Xof_ext_.Id_jpeg:
|
||||
case Xof_ext_.Id_gif: case Xof_ext_.Id_tif: case Xof_ext_.Id_tiff:
|
||||
case Xof_ext_.Id_svg:
|
||||
case Xof_ext_.Id_bmp: case Xof_ext_.Id_xcf:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
public static boolean Id_is_thumbable_img(int id) {
|
||||
switch (id) {
|
||||
case Xof_ext_.Id_png: case Xof_ext_.Id_jpg: case Xof_ext_.Id_jpeg:
|
||||
case Xof_ext_.Id_gif: case Xof_ext_.Id_tif: case Xof_ext_.Id_tiff:
|
||||
case Xof_ext_.Id_svg: case Xof_ext_.Id_djvu: case Xof_ext_.Id_pdf:
|
||||
case Xof_ext_.Id_bmp: case Xof_ext_.Id_xcf:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
public static boolean Id_is_audio(int id) {
|
||||
switch (id) {
|
||||
case Xof_ext_.Id_mid: case Xof_ext_.Id_oga: case Xof_ext_.Id_flac: case Xof_ext_.Id_ogg: return true;
|
||||
default: return false;
|
||||
}
|
||||
}
|
||||
public static boolean Id_is_video(int id) {return id == Xof_ext_.Id_ogv || id == Xof_ext_.Id_ogg || id == Xof_ext_.Id_webm;} // NOTE: ogg can be vid; EX.WP: Comet; Encke_tail_rip_off.ogg
|
||||
public static boolean Id_is_video_strict(int id) {return id == Xof_ext_.Id_ogv || id == Xof_ext_.Id_webm;} // NOTE: ogg can be aud / vid; EX.WP: Comet; Encke_tail_rip_off.ogg
|
||||
public static boolean Id_is_audio_strict(int id) { // same as above, but deliberately exclude ambiguous ogg
|
||||
switch (id) {
|
||||
case Xof_ext_.Id_mid: case Xof_ext_.Id_oga: case Xof_ext_.Id_flac: return true;
|
||||
default: return false;
|
||||
}
|
||||
}
|
||||
public static boolean Id_is_media(int id) {return Id_is_audio(id) || Id_is_video(id);}
|
||||
public static boolean Id_needs_convert(int id) {
|
||||
switch (id) {
|
||||
case Xof_ext_.Id_svg: case Xof_ext_.Id_djvu: case Xof_ext_.Id_pdf: return true;
|
||||
default: return false;
|
||||
}
|
||||
}
|
||||
public static int Id_view(int id) {
|
||||
switch (id) {
|
||||
case Xof_ext_.Id_svg: case Xof_ext_.Id_bmp: case Xof_ext_.Id_xcf: return Xof_ext_.Id_png;
|
||||
case Xof_ext_.Id_tif: case Xof_ext_.Id_tiff: case Xof_ext_.Id_djvu: case Xof_ext_.Id_pdf:
|
||||
case Xof_ext_.Id_ogg: case Xof_ext_.Id_ogv: case Xof_ext_.Id_webm: return Xof_ext_.Id_jpg;
|
||||
default: return id;
|
||||
}
|
||||
}
|
||||
}
|
||||
50
400_xowa/src_160_file/gplx/xowa/Xof_file_mgr.java
Normal file
50
400_xowa/src_160_file/gplx/xowa/Xof_file_mgr.java
Normal file
@@ -0,0 +1,50 @@
|
||||
/*
|
||||
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.xtns.math.*;
|
||||
import gplx.xowa.files.fsdb.caches.*;
|
||||
public class Xof_file_mgr implements GfoInvkAble {
|
||||
public void Init_app(Xoa_app app, Gfo_usr_dlg usr_dlg) {
|
||||
this.app = app;
|
||||
img_mgr.Init_app(app); repo_mgr = new Xoa_repo_mgr(app);
|
||||
math_mgr = new Xof_math_mgr(app);
|
||||
math_mgr.Init(app);
|
||||
download_mgr = new Xoaf_download_mgr(app);
|
||||
cache_mgr = new Cache_mgr(app);
|
||||
}
|
||||
public Xoa_app App() {return app;} private Xoa_app app;
|
||||
public Xoa_repo_mgr Repo_mgr() {return repo_mgr;} private Xoa_repo_mgr repo_mgr;
|
||||
public Xof_img_mgr Img_mgr() {return img_mgr;} private Xof_img_mgr img_mgr = new Xof_img_mgr();
|
||||
public Xof_math_mgr Math_mgr() {return math_mgr;} private Xof_math_mgr math_mgr;
|
||||
public Xoft_rule_mgr Ext_rules() {return ext_rules;} private Xoft_rule_mgr ext_rules = new Xoft_rule_mgr();
|
||||
public Xoaf_download_mgr Download_mgr() {return download_mgr;} private Xoaf_download_mgr download_mgr;
|
||||
public Cache_mgr Cache_mgr() {return cache_mgr;} private Cache_mgr cache_mgr;
|
||||
public void Init_by_app() {
|
||||
if (!Env_.Mode_testing())
|
||||
cache_mgr.Db_init(app.User().Db_mgr());
|
||||
}
|
||||
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
|
||||
if (ctx.Match(k, Invk_repos)) return repo_mgr;
|
||||
else if (ctx.Match(k, Invk_img_mgr)) return img_mgr;
|
||||
else if (ctx.Match(k, Invk_ext_rules)) return ext_rules;
|
||||
else if (ctx.Match(k, Invk_math)) return math_mgr;
|
||||
else if (ctx.Match(k, Invk_download)) return download_mgr;
|
||||
else if (ctx.Match(k, Invk_cache_mgr)) return cache_mgr;
|
||||
else return GfoInvkAble_.Rv_unhandled;
|
||||
} private static final String Invk_repos = "repos", Invk_img_mgr= "img_mgr", Invk_ext_rules = "ext_rules", Invk_math = "math", Invk_download = "download", Invk_cache_mgr = "cache_mgr";
|
||||
}
|
||||
32
400_xowa/src_160_file/gplx/xowa/Xof_img_mgr.java
Normal file
32
400_xowa/src_160_file/gplx/xowa/Xof_img_mgr.java
Normal file
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
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.apps.fsys.*; import gplx.xowa.files.cnvs.*; import gplx.xowa.files.*;
|
||||
public class Xof_img_mgr {
|
||||
public Xof_img_wkr_query_img_size Wkr_query_img_size() {return wkr_query_img_size;} public Xof_img_mgr Wkr_query_img_size_(Xof_img_wkr_query_img_size v) {wkr_query_img_size = v; return this;} private Xof_img_wkr_query_img_size wkr_query_img_size;
|
||||
public Xof_img_wkr_resize_img Wkr_resize_img() {return wkr_resize_img;} public Xof_img_mgr Wkr_resize_img_(Xof_img_wkr_resize_img v) {wkr_resize_img = v; return this;} private Xof_img_wkr_resize_img wkr_resize_img;
|
||||
public Xof_img_wkr_convert_djvu_to_tiff Wkr_convert_djvu_to_tiff() {return wkr_convert_djvu_to_tiff;} public Xof_img_mgr Wkr_convert_djvu_to_tiff_(Xof_img_wkr_convert_djvu_to_tiff v) {wkr_convert_djvu_to_tiff = v; return this;} private Xof_img_wkr_convert_djvu_to_tiff wkr_convert_djvu_to_tiff;
|
||||
public int Thumb_w_img() {return thumb_w_img;} private int thumb_w_img = Xof_img_size.Thumb_width_img;
|
||||
public int Thumb_w_ogv() {return thumb_w_ogv;} private int thumb_w_ogv = Xof_img_size.Thumb_width_ogv;
|
||||
public void Init_app(Xoa_app app) {
|
||||
Launcher_app_mgr app_mgr = app.Fsys_mgr().App_mgr();
|
||||
wkr_query_img_size = new Xof_img_wkr_query_img_size_imageMagick(app, app_mgr.App_query_img_size());
|
||||
wkr_resize_img = new Xof_img_wkr_resize_img_imageMagick(app, app_mgr.App_resize_img(), app_mgr.App_convert_svg_to_png());
|
||||
wkr_convert_djvu_to_tiff = new Xof_img_wkr_convert_djvu_to_tiff_app(app_mgr.App_convert_djvu_to_tiff());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
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 Xof_img_wkr_convert_djvu_to_tiff {
|
||||
boolean Exec(Io_url src, Io_url trg);
|
||||
}
|
||||
class Xof_img_wkr_convert_djvu_to_tiff_app implements Xof_img_wkr_convert_djvu_to_tiff {
|
||||
public Xof_img_wkr_convert_djvu_to_tiff_app(ProcessAdp process) {this.process = process;} ProcessAdp process;
|
||||
public boolean Exec(Io_url src, Io_url trg) {
|
||||
process.Run(src, trg);
|
||||
return process.Exit_code_pass();
|
||||
}
|
||||
}
|
||||
class Xof_img_wkr_convert_djvu_to_tiff_mok implements Xof_img_wkr_convert_djvu_to_tiff {
|
||||
public Xof_img_wkr_convert_djvu_to_tiff_mok(int w, int h) {this.w = w; this.h = h;} private int w, h;
|
||||
public boolean Exec(Io_url src, Io_url trg) {
|
||||
Io_mgr._.SaveFilStr(trg, gplx.gfui.SizeAdp_.new_(w, h).XtoStr());
|
||||
return true;
|
||||
}
|
||||
}
|
||||
30
400_xowa/src_160_file/gplx/xowa/Xof_media_type.java
Normal file
30
400_xowa/src_160_file/gplx/xowa/Xof_media_type.java
Normal file
@@ -0,0 +1,30 @@
|
||||
/*
|
||||
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 Xof_media_type {
|
||||
public static final byte Tid_null = 0, Tid_audio = 1, Tid_bitmap = 2, Tid_drawing = 2, Tid_office = 3, Tid_video = 4;
|
||||
public static final String Name_null = "", Name_audio = "AUDIO", Name_bitmap = "BITMAP", Name_drawing = "DRAWING", Name_office = "OFFICE", Name_video = "VIDEO";
|
||||
public static byte Xto_byte(String v) {
|
||||
if (String_.Eq(v, Name_audio)) return Tid_audio;
|
||||
else if (String_.Eq(v, Name_bitmap)) return Tid_bitmap;
|
||||
else if (String_.Eq(v, Name_drawing)) return Tid_drawing;
|
||||
else if (String_.Eq(v, Name_office)) return Tid_office;
|
||||
else if (String_.Eq(v, Name_video)) return Tid_video;
|
||||
else return Tid_null;
|
||||
}
|
||||
}
|
||||
53
400_xowa/src_160_file/gplx/xowa/Xof_mime_minor_.java
Normal file
53
400_xowa/src_160_file/gplx/xowa/Xof_mime_minor_.java
Normal file
@@ -0,0 +1,53 @@
|
||||
/*
|
||||
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 Xof_mime_minor_ {
|
||||
public static Xof_ext ext_(byte[] minor_mime) {
|
||||
Int_obj_val id_obj = (Int_obj_val)mime_hash.Fetch(minor_mime);
|
||||
int id = id_obj == null ? Xof_ext_.Id_unknown : id_obj.Val();
|
||||
return Xof_ext_.new_by_id_(id);
|
||||
}
|
||||
private static final byte[]
|
||||
Mime_svg = Bry_.new_ascii_("svg+xml"), Mime_djvu = Bry_.new_ascii_("vnd.djvu"), Mime_midi = Bry_.new_ascii_("midi")
|
||||
, Mime_xcf = Bry_.new_ascii_("x-xcf"), Mime_flac = Bry_.new_ascii_("x-flac")
|
||||
, Mime_bmp = Bry_.new_ascii_("x-bmp"), Mime_bmp_2 = Bry_.new_ascii_("x-ms-bmp");
|
||||
private static final HashAdp mime_hash = mime_hash_();
|
||||
private static HashAdp mime_hash_() {
|
||||
HashAdp rv = HashAdp_.new_bry_();
|
||||
mime_hash_itm_(rv, Xof_ext_.Bry_png, Xof_ext_.Id_png);
|
||||
mime_hash_itm_(rv, Xof_ext_.Bry_jpg, Xof_ext_.Id_jpg);
|
||||
mime_hash_itm_(rv, Xof_ext_.Bry_jpeg, Xof_ext_.Id_jpeg);
|
||||
mime_hash_itm_(rv, Xof_ext_.Bry_gif, Xof_ext_.Id_gif);
|
||||
mime_hash_itm_(rv, Xof_ext_.Bry_tif, Xof_ext_.Id_tif);
|
||||
mime_hash_itm_(rv, Xof_ext_.Bry_tiff, Xof_ext_.Id_tiff);
|
||||
mime_hash_itm_(rv, Mime_svg, Xof_ext_.Id_svg);
|
||||
mime_hash_itm_(rv, Mime_djvu, Xof_ext_.Id_djvu);
|
||||
mime_hash_itm_(rv, Xof_ext_.Bry_pdf, Xof_ext_.Id_pdf);
|
||||
mime_hash_itm_(rv, Mime_midi, Xof_ext_.Id_mid);
|
||||
mime_hash_itm_(rv, Xof_ext_.Bry_ogg, Xof_ext_.Id_ogg);
|
||||
mime_hash_itm_(rv, Xof_ext_.Bry_oga, Xof_ext_.Id_oga);
|
||||
mime_hash_itm_(rv, Xof_ext_.Bry_ogv, Xof_ext_.Id_ogv);
|
||||
mime_hash_itm_(rv, Xof_ext_.Bry_webm, Xof_ext_.Id_webm);
|
||||
mime_hash_itm_(rv, Mime_flac, Xof_ext_.Id_flac);
|
||||
mime_hash_itm_(rv, Mime_bmp, Xof_ext_.Id_bmp);
|
||||
mime_hash_itm_(rv, Mime_bmp_2, Xof_ext_.Id_bmp);
|
||||
mime_hash_itm_(rv, Mime_xcf, Xof_ext_.Id_xcf);
|
||||
return rv;
|
||||
}
|
||||
private static void mime_hash_itm_(HashAdp hash, byte[] key, int val) {hash.Add(key, Int_obj_val.new_(val));}
|
||||
}
|
||||
128
400_xowa/src_160_file/gplx/xowa/Xof_repo_itm.java
Normal file
128
400_xowa/src_160_file/gplx/xowa/Xof_repo_itm.java
Normal file
@@ -0,0 +1,128 @@
|
||||
/*
|
||||
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 Xof_repo_itm implements GfoInvkAble {
|
||||
public Xof_repo_itm(Xoa_repo_mgr mgr, byte[] key) {this.mgr = mgr; this.key = key;} private Xoa_repo_mgr mgr;
|
||||
public byte[] Key() {return key;} private byte[] key;
|
||||
public boolean Wmf_fsys() {return wmf_fsys;} public Xof_repo_itm Wmf_fsys_(boolean v) {wmf_fsys = v; return this;} private boolean wmf_fsys;
|
||||
public boolean Wmf_api() {return wmf_api;} public Xof_repo_itm Wmf_api_(boolean v) {wmf_api = v; return this;} private boolean wmf_api;
|
||||
public boolean Tarball() {return tarball;} public Xof_repo_itm Tarball_(boolean v) {tarball = v; return this;} private boolean tarball;
|
||||
public byte Dir_spr() {return dir_spr;} private byte dir_spr;
|
||||
public byte[] Root() {return root;} private byte[] root;
|
||||
public String Root_str() {return root_str;} private String root_str;
|
||||
public Io_url Root_url() {return root_url;} Io_url root_url;
|
||||
public boolean Fsys_is_wnt() {return fsys_is_wnt;} public Xof_repo_itm Fsys_is_wnt_(boolean v) {fsys_is_wnt = v; return this;} private boolean fsys_is_wnt;
|
||||
public byte[] Root_http() {return root_http;} private byte[] root_http = Bry_.Empty;
|
||||
public byte[] Wiki_key() {return wiki_key;} public Xof_repo_itm Wiki_key_(byte[] v) {wiki_key = v; return this;} private byte[] wiki_key;
|
||||
public int Ttl_max() {return ttl_max;} public Xof_repo_itm Ttl_max_(int v) {ttl_max = v; return this;} private int ttl_max = 180;
|
||||
public byte[][] Mode_names() {return mode_names;} private byte[][] mode_names = new byte[][] {Mode_names_key[0], Mode_names_key[1]};
|
||||
public static final byte[][] Mode_names_key = new byte[][] {Bry_.new_utf8_("orig"), Bry_.new_utf8_("thumb")};
|
||||
public Xoft_rule_grp Ext_rules() {return ext_rules;} public Xof_repo_itm Ext_rules_(Xoft_rule_grp v) {ext_rules = v; return this;} private Xoft_rule_grp ext_rules;
|
||||
public int Dir_depth() {return dir_depth;} public Xof_repo_itm Dir_depth_(int v) {dir_depth = v; return this;} private int dir_depth = 4;
|
||||
public boolean Primary() {return primary;} public Xof_repo_itm Primary_(boolean v) {primary = v; return this;} private boolean primary;
|
||||
public Xof_repo_itm Root_str_(String v) {
|
||||
this.root_str = v;
|
||||
root = Bry_.new_utf8_(root_str);
|
||||
wmf_fsys = String_.HasAtBgn(root_str, "http") || String_.HasAtBgn(root_str, "ftp");
|
||||
if (wmf_fsys) {
|
||||
root_url = Io_url_.Null;
|
||||
dir_spr = Byte_ascii.Slash;
|
||||
wmf_api = true;
|
||||
}
|
||||
else {
|
||||
root_url = App_cmd_arg.Val_as_url_rel_url_or(root_str, mgr.App().Fsys_mgr().File_dir(), Io_url_.new_dir_(root_str), true);
|
||||
root = root_url.RawBry();
|
||||
dir_spr = root_url.Info().DirSpr_byte();
|
||||
root_http = mgr.App().Url_converter_fsys().Encode_http(root_url);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
public static byte[] Ttl_invalid_fsys_chars(byte[] ttl) {
|
||||
int ttl_len = ttl.length;
|
||||
for (int i = 0; i < ttl_len; i++) {
|
||||
byte b = ttl[i];
|
||||
Object o = wnt_trie.Match(b, ttl, i, ttl_len);
|
||||
if (o == null) wnt_tmp_bfr.Add_byte(b); // regular char; add orig byte
|
||||
else wnt_tmp_bfr.Add((byte[])o); // invalid char; add swap byte(s)
|
||||
}
|
||||
return wnt_tmp_bfr.XtoAryAndClear();
|
||||
} private static final Bry_bfr wnt_tmp_bfr = Bry_bfr.reset_(255); private static final ByteTrieMgr_slim wnt_trie = trie_make();
|
||||
public static byte[] Ttl_shorten_ttl(int ttl_max, byte[] ttl, byte[] md5, Xof_ext ext) {
|
||||
byte[] rv = ttl;
|
||||
int exceed_len = rv.length - ttl_max;
|
||||
if (exceed_len > 0) {
|
||||
wnt_tmp_bfr.Add_mid(rv, 0, ttl_max - 33); // add truncated title; 33=_.length + md5.length
|
||||
wnt_tmp_bfr.Add_byte(Byte_ascii.Underline); // add underline; EX: "_"
|
||||
wnt_tmp_bfr.Add(md5); // add md5; EX: "abcdefghijklmnopqrstuvwxyz0123456"
|
||||
wnt_tmp_bfr.Add_byte(Byte_ascii.Dot); // add dot; EX: "."
|
||||
wnt_tmp_bfr.Add(ext.Ext()); // add ext; EX: ".png"
|
||||
rv = wnt_tmp_bfr.XtoAryAndClear();
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
public byte[] Gen_name_src(byte[] name) {
|
||||
if (!fsys_is_wnt || wmf_fsys) return name;
|
||||
int name_len = name.length;
|
||||
for (int i = 0; i < name_len; i++) {
|
||||
byte b = name[i];
|
||||
Object o = trie.Match(b, name, i, name_len);
|
||||
if (o == null) tmp_bfr.Add_byte(b);
|
||||
else tmp_bfr.Add((byte[])o);
|
||||
}
|
||||
byte[] rv = tmp_bfr.XtoAryAndReset(300);
|
||||
return rv;
|
||||
} private Bry_bfr tmp_bfr = Bry_bfr.new_(); ByteTrieMgr_slim trie = trie_make();
|
||||
private static ByteTrieMgr_slim trie_make() {
|
||||
ByteTrieMgr_slim rv = ByteTrieMgr_slim.cs_();
|
||||
byte[] invalid = Op_sys.Wnt.Fsys_invalid_chars();
|
||||
byte[] underline = new byte[] {Byte_ascii.Underline};
|
||||
int len = invalid.length;
|
||||
for (int i = 0; i < len; i++)
|
||||
rv.Add(new byte[] {invalid[i]}, underline);
|
||||
return rv;
|
||||
}
|
||||
public byte[] Gen_name_trg(byte[] bry, byte[] md5, Xof_ext ext) {
|
||||
byte[] rv = Gen_name_src(bry);
|
||||
byte[] ext_bry = ext.Ext();
|
||||
int exceed_len = rv.length - ttl_max;
|
||||
if (exceed_len > 0) {
|
||||
tmp_bfr.Add_mid(rv, 0, ttl_max - 33); // add truncated title; 33=_.length + md5.length
|
||||
tmp_bfr.Add_byte(Byte_ascii.Underline); // add underline; EX: "_"
|
||||
tmp_bfr.Add(md5); // add md5; EX: "abcdefghijklmnopqrstuvwxyz0123456"
|
||||
tmp_bfr.Add_byte(Byte_ascii.Dot);
|
||||
tmp_bfr.Add(ext_bry);
|
||||
rv = tmp_bfr.XtoAryAndReset(300);
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
|
||||
if (ctx.Match(k, Invk_owner)) return mgr;
|
||||
else if (ctx.Match(k, Invk_fsys_)) fsys_is_wnt = String_.Eq(m.ReadStr("v"), "wnt");
|
||||
else if (ctx.Match(k, Invk_primary_)) primary = m.ReadYn("v");
|
||||
else if (ctx.Match(k, Invk_ext_rules_)) Ext_rules_(m.ReadBry("v"));
|
||||
else if (ctx.Match(k, Invk_wmf_api_)) wmf_api = m.ReadYn("v");
|
||||
else if (ctx.Match(k, Invk_tarball_)) tarball = m.ReadYn("v");
|
||||
else return GfoInvkAble_.Rv_unhandled;
|
||||
return this;
|
||||
} private static final String Invk_owner = "owner", Invk_fsys_ = "fsys_", Invk_ext_rules_ = "ext_rules_", Invk_primary_ = "primary_", Invk_wmf_api_ = "wmf_api_", Invk_tarball_ = "tarball_";
|
||||
public Xof_repo_itm Ext_rules_(byte[] ext_rules_key) {ext_rules = mgr.App().File_mgr().Ext_rules().Get_or_new(ext_rules_key); return this;}
|
||||
public static final int Thumb_default_null = -1;
|
||||
public static final byte Mode_orig = 0, Mode_thumb = 1, Mode_nil = Byte_.MaxValue_127;
|
||||
public static final byte Repo_remote = 0, Repo_local = 1, Repo_unknown = 126, Repo_null = Byte_.MaxValue_127;
|
||||
public static final int Dir_depth_null = -1, Dir_depth_wmf = 2, Dir_depth_xowa = 4;
|
||||
}
|
||||
193
400_xowa/src_160_file/gplx/xowa/Xof_url_bldr.java
Normal file
193
400_xowa/src_160_file/gplx/xowa/Xof_url_bldr.java
Normal file
@@ -0,0 +1,193 @@
|
||||
/*
|
||||
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.gfui.*;
|
||||
import gplx.xowa.files.*;
|
||||
public class Xof_url_bldr {
|
||||
private Bry_bfr bfr = Bry_bfr.reset_(400);
|
||||
private byte[] area; private boolean wmf_protocol_is_file;
|
||||
public byte Dir_spr() {return dir_spr;} public Xof_url_bldr Dir_spr_(byte v) {dir_spr = v; return this;} private byte dir_spr;
|
||||
public byte[] Root() {return root;} public Xof_url_bldr Root_(byte[] v) {root = v; return this;} private byte[] root;
|
||||
public byte[] Ttl() {return ttl;} public Xof_url_bldr Ttl_(byte[] v) {ttl = v; return this;} private byte[] ttl;
|
||||
public byte[] Md5() {return md5;} public Xof_url_bldr Md5_(byte[] v) {md5 = v; return this;} private byte[] md5;
|
||||
public Xof_ext Ext() {return ext;} public Xof_url_bldr Ext_(Xof_ext v) {ext = v; return this;} private Xof_ext ext;
|
||||
public int Width() {return width;} public Xof_url_bldr Width_(int v) {width = v; return this;} private int width;
|
||||
public Xof_url_bldr Thumbtime_(double v) {thumbtime = v; return this;} private double thumbtime = Xof_doc_thumb.Null;
|
||||
public Xof_url_bldr Page_(int v) {page = v; return this;} private int page = Xof_doc_page.Null;
|
||||
public Xof_url_bldr Wmf_dir_hive_(boolean v) {wmf_dir_hive = v; return this;} private boolean wmf_dir_hive;
|
||||
public boolean Thumb() {return thumb;} public Xof_url_bldr Thumb_(boolean v) {thumb = v; return this;} private boolean thumb;
|
||||
public byte Thumbtime_dlm() {return thumbtime_dlm;} private byte thumbtime_dlm = Byte_ascii.At;
|
||||
public Xof_url_bldr Thumbtime_dlm_dash_() {thumbtime_dlm = Byte_ascii.Dash; return this;}
|
||||
public Xof_url_bldr Set_trg_html_(byte mode, Xof_repo_itm repo, byte[] ttl, byte[] md5, Xof_ext ext, int width, double thumbtime, int page) {
|
||||
this.wmf_dir_hive = false; this.thumb = mode == Xof_repo_itm.Mode_thumb;
|
||||
this.dir_spr = Byte_ascii.Slash; this.root = repo.Root_http(); this.ttl = repo.Gen_name_trg(ttl, md5, ext); this.area = repo.Mode_names()[mode];
|
||||
this.md5 = md5; this.ext = ext; this.width = width; this.thumbtime = thumbtime; this.page = page;
|
||||
this.repo_dir_depth = repo.Dir_depth();
|
||||
return this;
|
||||
} private int repo_dir_depth;
|
||||
public Xof_url_bldr Set_src_file_(byte mode, Xof_repo_itm repo, byte[] ttl, byte[] md5, Xof_ext ext, int width, double thumbtime, int page) {
|
||||
this.wmf_dir_hive = true; this.thumb = mode == Xof_repo_itm.Mode_thumb;
|
||||
this.dir_spr = repo.Dir_spr(); this.root = repo.Root(); this.ttl = repo.Gen_name_src(ttl); this.area = repo.Mode_names()[mode];
|
||||
this.md5 = md5; this.ext = ext; this.width = width; this.thumbtime = thumbtime; this.page = page;
|
||||
this.wmf_protocol_is_file = repo.Tarball();
|
||||
return this;
|
||||
}
|
||||
public Xof_url_bldr Set_trg_file_(byte mode, Xof_repo_itm repo, byte[] ttl, byte[] md5, Xof_ext ext, int width, double thumbtime, int page) {
|
||||
this.wmf_dir_hive = false; this.thumb = mode == Xof_repo_itm.Mode_thumb;
|
||||
this.dir_spr = repo.Dir_spr(); this.root = repo.Root(); this.ttl = repo.Gen_name_trg(ttl, md5, ext); this.area = repo.Mode_names()[mode];
|
||||
this.md5 = md5; this.ext = ext; this.width = width; this.thumbtime = thumbtime; this.page = page;
|
||||
this.repo_dir_depth = repo.Dir_depth();
|
||||
return this;
|
||||
}
|
||||
public Xof_url_bldr Init_by_root(byte[] root, byte dir_spr, boolean wmf_dir_hive, boolean wmf_protocol_is_file, int repo_dir_depth) {
|
||||
this.root = root; this.dir_spr = dir_spr; this.wmf_dir_hive = wmf_dir_hive; this.wmf_protocol_is_file = wmf_protocol_is_file; this.repo_dir_depth = repo_dir_depth;
|
||||
this.fsys_tid_is_wnt = Op_sys.Cur().Tid_is_wnt();
|
||||
return this;
|
||||
} private boolean fsys_tid_is_wnt;
|
||||
public Xof_url_bldr Init_by_itm(byte mode, byte[] ttl, byte[] md5, Xof_ext ext, int width, double thumbtime) {
|
||||
this.thumb = mode == Xof_repo_itm.Mode_thumb;
|
||||
this.area = Xof_repo_itm.Mode_names_key[mode];
|
||||
this.ttl = ttl;
|
||||
if (wmf_protocol_is_file && fsys_tid_is_wnt)
|
||||
this.ttl = Xof_repo_itm.Ttl_invalid_fsys_chars(ttl);
|
||||
this.md5 = md5; // NOTE: the md5 is the orig ttl, even if ttl gets changed b/c of invalid_chars or exceeds_len
|
||||
this.ext = ext; this.width = width; this.thumbtime = thumbtime;
|
||||
return this;
|
||||
}
|
||||
public byte[] Xto_bry() {Bld(); byte[] rv = bfr.XtoAryAndClear(); Clear(); return rv;}
|
||||
public String Xto_str() {Bld(); String rv = bfr.XtoStr(); Clear(); return rv;}
|
||||
public Io_url Xto_url() {Bld(); Io_url rv = Io_url_.new_fil_(bfr.XtoStr()); Clear(); return rv;}
|
||||
private void Bld() {
|
||||
Add_core();
|
||||
if (thumb) {
|
||||
if (wmf_dir_hive) Add_thumb_wmf();
|
||||
else Add_thumb_xowa();
|
||||
}
|
||||
}
|
||||
private Xof_url_bldr Add_core() {
|
||||
bfr.Add(root); // add root; EX: "C:\xowa\file\"; assume trailing dir_spr
|
||||
if (area != null && !(wmf_dir_hive && !thumb)) // !(wmf_dir_hive && !thumb) means never add if wmf_dir_hive and orig
|
||||
bfr.Add(area).Add_byte(dir_spr); // add area; EX: "thumb\"
|
||||
byte b0 = md5[0];
|
||||
if (wmf_dir_hive) {
|
||||
bfr.Add_byte(b0).Add_byte(dir_spr); // add md5_0 EX: "0/"
|
||||
bfr.Add_byte(b0).Add_byte(md5[1]).Add_byte(dir_spr); // add md5_01 EX: "01/"
|
||||
}
|
||||
else {
|
||||
for (int i = 0; i < repo_dir_depth; i++)
|
||||
bfr.Add_byte(md5[i]).Add_byte(dir_spr); // add md5_0123 EX: "0/1/2/3"
|
||||
}
|
||||
if (wmf_dir_hive) {
|
||||
if (wmf_protocol_is_file) // sitting on local file system (as opposed to http)
|
||||
bfr.Add(ttl); // NOTE: file_names are not url-encoded; this includes symbols (') and foreign characters (ö)
|
||||
else // wmf_http
|
||||
bfr.Add(encoder_src_http.Encode(ttl)); // NOTE: file_names must be url-encoded; JAVA will default to native charset which on Windows will be 1252; foreign character urls will fail due to conversion mismatch (1252 on windows; UTF-8 on WMF); EX.WP:Möbius strip
|
||||
}
|
||||
else
|
||||
bfr.Add(ttl); // add title; EX: "A.png"
|
||||
return this;
|
||||
}
|
||||
private Xof_url_bldr Add_thumb_xowa() {
|
||||
bfr.Add_byte(dir_spr); // add dir_spr; EX: "\"
|
||||
bfr.Add_int_variable(width).Add(Bry_px); // add width; EX: "220px"
|
||||
if (Xof_doc_thumb.Null_n(thumbtime))
|
||||
bfr.Add_byte(thumbtime_dlm).Add_str(Xof_doc_thumb.X_str(thumbtime)); // add thumbtime EX: "@5"
|
||||
else if (page != Xof_doc_page.Null)
|
||||
bfr.Add_byte(Byte_ascii.Dash).Add_int_variable(page); // add page EX: "-5"
|
||||
bfr.Add_byte(Byte_ascii.Dot); // add . EX: "."
|
||||
if (thumb)
|
||||
bfr.Add(ext.Ext_view()); // add view_ext EX: ".png"
|
||||
else
|
||||
bfr.Add(ext.Ext()); // add orig_ext EX: ".svg"
|
||||
return this;
|
||||
}
|
||||
private Xof_url_bldr Add_thumb_wmf() {
|
||||
bfr.Add_byte(dir_spr); // add dir_spr; EX: "\"
|
||||
int file_ext_id = ext.Id();
|
||||
switch (file_ext_id) {
|
||||
case Xof_ext_.Id_ogg:
|
||||
case Xof_ext_.Id_ogv:
|
||||
case Xof_ext_.Id_webm:
|
||||
if (Xof_doc_thumb.Null_n(thumbtime))
|
||||
bfr.Add(Bry_seek).Add_str(Xof_doc_thumb.X_str(thumbtime)).Add_byte(Byte_ascii.Dash);// add seek; EX: "seek%3D5-"
|
||||
else
|
||||
bfr.Add(Bry_mid); // add mid; EX: "mid-"
|
||||
break;
|
||||
case Xof_ext_.Id_tif:
|
||||
case Xof_ext_.Id_tiff:
|
||||
Add_thumb_wmf_page(Bry_lossy_page1, Bry_lossy_page);
|
||||
bfr.Add_int_variable(width); // add file_w; EX: "220"
|
||||
bfr.Add(Bry_px_dash); // add px; EX: "px-"
|
||||
break;
|
||||
case Xof_ext_.Id_pdf:
|
||||
case Xof_ext_.Id_djvu:
|
||||
Add_thumb_wmf_page(Bry_page1, Bry_page);
|
||||
bfr.Add_int_variable(width); // add file_w; EX: "220"
|
||||
bfr.Add(Bry_px_dash); // add px; EX: "px-"
|
||||
break;
|
||||
default:
|
||||
bfr.Add_int_variable(width); // add file_w; EX: "220"
|
||||
bfr.Add(Bry_px_dash); // add px; EX: "px-"
|
||||
break;
|
||||
}
|
||||
bfr.Add(encoder_src_http.Encode(ttl)); // add ttl again; EX: "A.png"
|
||||
switch (file_ext_id) {
|
||||
case Xof_ext_.Id_svg:
|
||||
case Xof_ext_.Id_bmp:
|
||||
case Xof_ext_.Id_xcf:
|
||||
bfr.Add_byte(Byte_ascii.Dot).Add(Xof_ext_.Bry_png); // add .png; EX: "A.svg" -> "A.svg.png" NOTE: MediaWiki always adds as lowercase
|
||||
break;
|
||||
case Xof_ext_.Id_pdf:
|
||||
case Xof_ext_.Id_tif: // add .jpg EX: "A.tif" -> "A.tif.jpg" NOTE: MediaWiki always adds as lowercase
|
||||
case Xof_ext_.Id_tiff:
|
||||
case Xof_ext_.Id_ogg:
|
||||
case Xof_ext_.Id_ogv:
|
||||
case Xof_ext_.Id_djvu:
|
||||
case Xof_ext_.Id_webm:
|
||||
bfr.Add_byte(Byte_ascii.Dot).Add(Xof_ext_.Bry_jpg);
|
||||
break;
|
||||
}
|
||||
return this;
|
||||
}
|
||||
private void Add_thumb_wmf_page(byte[] bry_page_1, byte[] bry_page) {
|
||||
if (Xof_doc_thumb.Null_y(page))
|
||||
bfr.Add(bry_page_1); // add "lossy-page1-" EX: "lossy-page1-"
|
||||
else {
|
||||
bfr.Add(bry_page); // add "lossy-page" EX: "lossy-page"
|
||||
bfr.Add_int_variable(page); // add page EX: 123
|
||||
bfr.Add_byte(Byte_ascii.Dash); // add - EX: "-"
|
||||
}
|
||||
}
|
||||
private Xof_url_bldr Clear() {
|
||||
root = area = ttl = md5 = null;
|
||||
width = 0; thumbtime = Xof_doc_thumb.Null;
|
||||
ext = null;
|
||||
bfr.Clear();
|
||||
return this;
|
||||
}
|
||||
public static final byte[] Bry_reg = Bry_.new_ascii_("reg.csv")
|
||||
, Bry_px = Bry_.new_ascii_("px"), Bry_px_dash = Bry_.new_ascii_("px-")
|
||||
, Bry_thumb = Bry_.new_ascii_("thumb"), Bry_mid = Bry_.new_ascii_("mid-")
|
||||
;
|
||||
private static final byte[]
|
||||
Bry_lossy_page = Bry_.new_ascii_("lossy-page"), Bry_page = Bry_.new_ascii_("page")
|
||||
, Bry_lossy_page1 = Bry_.new_ascii_("lossy-page1-"), Bry_page1 = Bry_.new_ascii_("page1-"), Bry_seek = Bry_.new_ascii_("seek%3D");
|
||||
public static final Xof_url_bldr Temp = new Xof_url_bldr();
|
||||
private static final Url_encoder encoder_src_http = Url_encoder.new_http_url_(); // NOTE: changed from new_html_href_mw_ to new_url_ on 2012-11-19; issues with A%2Cb becoming A%252Cb
|
||||
public static Xof_url_bldr new_v2_() {return new Xof_url_bldr().Thumbtime_dlm_dash_();}
|
||||
}
|
||||
54
400_xowa/src_160_file/gplx/xowa/Xof_url_bldr_tst.java
Normal file
54
400_xowa/src_160_file/gplx/xowa/Xof_url_bldr_tst.java
Normal file
@@ -0,0 +1,54 @@
|
||||
/*
|
||||
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.gfui.*;
|
||||
import gplx.xowa.files.*;
|
||||
public class Xof_url_bldr_tst {
|
||||
Xof_url_bldr_fxt fxt = new Xof_url_bldr_fxt();
|
||||
@Before public void init() {fxt.ini();}
|
||||
@Test public void Ogv() {fxt.Dir_spr_http_().Root_("http://test/").Md5_("d0").Ttl_("A.ogv").Expd_src_("http://test/d/d0/A.ogv/mid-A.ogv.jpg").tst();}
|
||||
@Test public void Ogv_seek() {fxt.Dir_spr_http_().Root_("http://test/").Md5_("d0").Ttl_("A.ogv").Expd_src_("http://test/d/d0/A.ogv/seek%3D5-A.ogv.jpg").Seek_(5).tst();}
|
||||
@Test public void Xcf() {fxt.Dir_spr_http_().Root_("http://test/").Md5_("44").Ttl_("A.xcf").Expd_src_("http://test/4/44/A.xcf/0px-A.xcf.png").tst();}
|
||||
@Test public void Bmp() {fxt.Dir_spr_http_().Root_("http://test/").Md5_("70").Ttl_("A.bmp").Expd_src_("http://test/7/70/A.bmp/0px-A.bmp.png").tst();}
|
||||
@Test public void Pdf_none() {fxt.Dir_spr_http_().Root_("http://test/").Md5_("ef").Ttl_("A.pdf").Expd_src_("http://test/e/ef/A.pdf/page1-0px-A.pdf.jpg").tst();}
|
||||
@Test public void Pdf_page_2() {fxt.Dir_spr_http_().Root_("http://test/").Md5_("ef").Ttl_("A.pdf").Page_(2).Expd_src_("http://test/e/ef/A.pdf/page2-0px-A.pdf.jpg").tst();}
|
||||
}
|
||||
class Xof_url_bldr_fxt {
|
||||
public Xof_url_bldr_fxt ini() {this.Clear(); return this;}
|
||||
public Xof_url_bldr_fxt Dir_spr_http_() {return Dir_spr_(Byte_ascii.Slash);}
|
||||
public Xof_url_bldr_fxt Dir_spr_fsys_wnt_() {return Dir_spr_(Byte_ascii.Backslash);}
|
||||
public Xof_url_bldr_fxt Dir_spr_(byte v) {dir_spr = v; return this;} private byte dir_spr;
|
||||
public Xof_url_bldr_fxt Root_(String v) {root = v; return this;} private String root;
|
||||
public Xof_url_bldr_fxt Md5_(String v) {md5 = v; return this;} private String md5;
|
||||
public Xof_url_bldr_fxt Ttl_(String v) {ttl = v; ext = Xof_ext_.new_by_ttl_(Bry_.new_utf8_(v)); return this;} private String ttl; Xof_ext ext;
|
||||
public Xof_url_bldr_fxt Page_(int v) {page = v; return this;} private int page = Xof_doc_page.Null;
|
||||
public Xof_url_bldr_fxt Seek_(int v) {seek = v; return this;} private double seek = Xof_doc_thumb.Null;
|
||||
public Xof_url_bldr_fxt Expd_src_(String v) {expd_src = v; return this;} private String expd_src;
|
||||
Xof_url_bldr url_bldr = new Xof_url_bldr();
|
||||
private void Clear() {
|
||||
dir_spr = Byte_.Zero; ext = null; root = md5 = ttl = expd_src = null;
|
||||
seek = Xof_doc_thumb.Null;
|
||||
page = Xof_doc_page.Null;
|
||||
}
|
||||
public Xof_url_bldr_fxt tst() {
|
||||
url_bldr.Wmf_dir_hive_(true).Thumb_(true).Dir_spr_(dir_spr).Root_(Bry_.new_utf8_(root)).Md5_(Bry_.new_utf8_(md5)).Ttl_(Bry_.new_utf8_(ttl)).Ext_(ext).Thumbtime_(seek).Page_(page);
|
||||
Tfds.Eq(expd_src, url_bldr.Xto_str());
|
||||
return this;
|
||||
}
|
||||
}
|
||||
109
400_xowa/src_160_file/gplx/xowa/Xofo_file.java
Normal file
109
400_xowa/src_160_file/gplx/xowa/Xofo_file.java
Normal file
@@ -0,0 +1,109 @@
|
||||
/*
|
||||
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.ios.*; import gplx.gfui.*;
|
||||
class Xofo_file {
|
||||
public byte[] Name() {return name;} public Xofo_file Name_(byte[] v) {name = v; return this;} byte[] name = Bry_.Empty;
|
||||
public byte[] Redirect() {return redirect;} private byte[] redirect = Bry_.Empty; public boolean Redirect_exists() {return redirect.length > 0;}
|
||||
public int Orig_w() {return orig_w;} private int orig_w;
|
||||
public int Orig_h() {return orig_h;} private int orig_h;
|
||||
public int Orig_size() {return orig_size;} private int orig_size;
|
||||
public int Bits() {return bits;} private int bits;
|
||||
public int Repo_id() {return repo_id;} public Xofo_file Repo_id_(int v) {this.repo_id = v; return this;} private int repo_id = -1;
|
||||
public byte[] Status_msg() {return status_msg;} public Xofo_file Status_msg_(byte[] v) {status_msg = v; return this;} private byte[] status_msg = Bry_.Empty;
|
||||
public int[] Thumbs() {return (int[])thumbs.XtoAry(int.class);} private OrderedHash thumbs = OrderedHash_.new_();
|
||||
public Xofo_lnki[] Links() {return lnkis;} private Xofo_lnki[] lnkis = Xofo_lnki.Ary_empty; int links_len;
|
||||
public void Links_(ListAdp list) {
|
||||
lnkis = (Xofo_lnki[])list.XtoAry(Xofo_lnki.class);
|
||||
links_len = lnkis.length;
|
||||
list.Clear();
|
||||
}
|
||||
public void Write(boolean reverse, Gfo_fld_wtr wtr) {
|
||||
Write_main(reverse, wtr);
|
||||
wtr.Write_dlm_row();
|
||||
}
|
||||
public void Write_bldr(Gfo_fld_wtr wtr) {
|
||||
Write_main(false, wtr);
|
||||
wtr.Write_int_variable_fld(repo_id);
|
||||
wtr.Write_bry_escape_fld(status_msg);
|
||||
Xofo_lnki[] lnkis = this.Links();
|
||||
int links_len = lnkis.length;
|
||||
Bry_bfr bfr = wtr.Bfr();
|
||||
for (int i = 0; i < links_len; i++) {
|
||||
if (i != 0) bfr.Add_byte(Byte_ascii.Semic);
|
||||
Xofo_lnki lnki = lnkis[i];
|
||||
bfr .Add_int_variable(lnki.Lnki_type()) .Add_byte(Byte_ascii.Comma)
|
||||
.Add_int_variable(lnki.Lnki_w()) .Add_byte(Byte_ascii.Comma)
|
||||
.Add_int_variable(lnki.Lnki_h());
|
||||
if (lnki.Lnki_upright() != Xop_lnki_tkn.Upright_null)
|
||||
bfr.Add_byte(Byte_ascii.Comma).Add(Xop_lnki_arg_parser.Bry_upright).Add_byte(Byte_ascii.Eq).Add_double(lnki.Lnki_upright());
|
||||
}
|
||||
wtr.Write_dlm_row();
|
||||
}
|
||||
private void Write_main(boolean reverse, Gfo_fld_wtr wtr) {
|
||||
if (reverse) {
|
||||
wtr.Write_bry_escape_fld(redirect);
|
||||
wtr.Write_bry_escape_fld(name);
|
||||
}
|
||||
else {
|
||||
wtr.Write_bry_escape_fld(name);
|
||||
wtr.Write_bry_escape_fld(redirect);
|
||||
}
|
||||
wtr.Write_bry_escape_fld(name_ext);
|
||||
wtr.Write_int_variable_fld(orig_size);
|
||||
wtr.Write_int_variable_fld(orig_w);
|
||||
wtr.Write_int_variable_fld(orig_h);
|
||||
wtr.Write_int_variable_fld(bits);
|
||||
}
|
||||
public Xofo_file Load_by_xfer_rdr(Gfo_fld_rdr fld_parser, Xofo_lnki_parser lnki_parser, Io_line_rdr rdr, ListAdp link_list) {
|
||||
byte[] bfr = rdr.Bfr();
|
||||
fld_parser.Ini(bfr, rdr.Itm_pos_bgn());
|
||||
Load_ttl_atrs(fld_parser);
|
||||
Load_sql_atrs(fld_parser);
|
||||
repo_id = fld_parser.Read_int();
|
||||
status_msg = fld_parser.Read_bry_escape();
|
||||
lnkis = lnki_parser.Parse_ary(fld_parser.Data(), fld_parser.Pos(), rdr.Itm_pos_end() - 1); // -1 to ignore closing \n
|
||||
return this;
|
||||
}
|
||||
public void Load_by_name_rdr(Gfo_fld_rdr fld_parser, Io_line_rdr rdr) {
|
||||
fld_parser.Ini(rdr.Bfr(), rdr.Itm_pos_bgn());
|
||||
Load_ttl_atrs(fld_parser);
|
||||
}
|
||||
public void Load_by_size_rdr(Gfo_fld_rdr fld_parser, Io_line_rdr rdr) {
|
||||
fld_parser.Ini(rdr.Bfr(), rdr.Itm_pos_bgn());
|
||||
fld_parser.Move_next_escaped();
|
||||
Load_sql_atrs(fld_parser);
|
||||
}
|
||||
public Xofo_file Load_by_merge_rdr(Gfo_fld_rdr fld_parser, Io_line_rdr rdr) {
|
||||
fld_parser.Ini(rdr.Bfr(), rdr.Itm_pos_bgn());
|
||||
Load_ttl_atrs(fld_parser);
|
||||
Load_sql_atrs(fld_parser);
|
||||
return this;
|
||||
}
|
||||
private void Load_ttl_atrs(Gfo_fld_rdr fld_parser) {
|
||||
name = fld_parser.Read_bry_escape();
|
||||
redirect = fld_parser.Read_bry_escape();
|
||||
}
|
||||
private void Load_sql_atrs(Gfo_fld_rdr fld_parser) {
|
||||
name_ext = fld_parser.Read_bry_escape();
|
||||
orig_size = fld_parser.Read_int();
|
||||
orig_w = fld_parser.Read_int();
|
||||
orig_h = fld_parser.Read_int();
|
||||
bits = fld_parser.Read_int();
|
||||
} byte[] name_ext = Bry_.Empty;
|
||||
}
|
||||
62
400_xowa/src_160_file/gplx/xowa/Xofo_lnki.java
Normal file
62
400_xowa/src_160_file/gplx/xowa/Xofo_lnki.java
Normal file
@@ -0,0 +1,62 @@
|
||||
/*
|
||||
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.ios.*;
|
||||
import gplx.xowa.parsers.lnkis.*;
|
||||
import gplx.xowa.files.*;
|
||||
class Xofo_lnki {
|
||||
public byte[] Name() {return name;} private byte[] name;
|
||||
public byte Lnki_type() {return lnki_type;} public Xofo_lnki Lnki_type_(byte v) {lnki_type = v; return this;} private byte lnki_type;
|
||||
public int Lnki_w() {return lnki_w;} public Xofo_lnki Lnki_w_(int v) {lnki_w = v; return this;} private int lnki_w;
|
||||
public int Lnki_h() {return lnki_h;} public Xofo_lnki Lnki_h_(int v) {lnki_h = v; return this;} private int lnki_h;
|
||||
public double Lnki_upright() {return lnki_upright;} public Xofo_lnki Lnki_upright_(double v) {lnki_upright = v; return this;} double lnki_upright = Xop_lnki_tkn.Upright_null;
|
||||
public double Lnki_thumbtime() {return lnki_thumbtime;} public Xofo_lnki Lnki_thumbtime_(double v) {lnki_thumbtime = v; return this;} private double lnki_thumbtime = Xof_doc_thumb.Null;
|
||||
public byte Xfer_status() {return xfer_status;} public Xofo_lnki Xfer_status_(byte v) {xfer_status = v; return this;} private byte xfer_status; public static final byte Xfer_status_none = 0, Xfer_status_xfer_pass = 1, Xfer_status_xfer_fail = 2, Xfer_status_convert_pass = 3, Xfer_status_convert_fail = 4;
|
||||
public Xofo_lnki Xfer_status_(boolean v) {return Xfer_status_(v ? Xfer_status_xfer_pass : Xfer_status_xfer_fail);}
|
||||
public boolean Orig() {return !thumb;}
|
||||
public boolean Thumb() {return thumb;} public Xofo_lnki Thumb_(boolean v) {thumb = v; return this;} private boolean thumb;
|
||||
public int File_w() {return file_w;} public Xofo_lnki File_w_(int v) {file_w = v; return this;} private int file_w;
|
||||
public int File_h() {return file_h;} public Xofo_lnki File_h_(int v) {file_h = v; return this;} private int file_h;
|
||||
public void Calc_size_(int w, int h) {file_w = w; file_h = h;}
|
||||
public void Load_by_html_wtr(byte typ, int w, int h, double lnki_upright) {this.lnki_type = typ; this.lnki_w = w; this.lnki_h = h; this.lnki_upright = lnki_upright;}
|
||||
public Xofo_lnki Load_link_rdr(Gfo_fld_rdr fld_rdr, Io_line_rdr rdr, Xofo_lnki_parser lnki_parser) {
|
||||
fld_rdr.Ini(rdr.Bfr(), rdr.Itm_pos_bgn());
|
||||
name = fld_rdr.Read_bry_escape();
|
||||
Xofo_lnki tmp = lnki_parser.Parse_ary(rdr.Bfr(), fld_rdr.Pos(), rdr.Itm_pos_end())[0];
|
||||
lnki_type = tmp.Lnki_type();
|
||||
lnki_w = tmp.Lnki_w();
|
||||
lnki_h = tmp.Lnki_h();
|
||||
lnki_upright = tmp.Lnki_upright();
|
||||
return this;
|
||||
}
|
||||
public static void Write(Gfo_fld_wtr wtr, byte[] ttl, Xop_lnki_tkn lnki) {
|
||||
wtr.Write_bry_escape_fld(ttl);
|
||||
wtr.Bfr()
|
||||
.Add_int_variable(lnki.Lnki_type()).Add_byte(Byte_ascii.Comma)
|
||||
.Add_int_variable(lnki.Lnki_w()).Add_byte(Byte_ascii.Comma)
|
||||
.Add_int_variable(lnki.Lnki_h())
|
||||
;
|
||||
boolean upright_exists = lnki.Upright() != Xop_lnki_tkn.Upright_null;
|
||||
if (upright_exists) {
|
||||
wtr.Bfr().Add_byte(Byte_ascii.Comma)
|
||||
.Add(Xop_lnki_arg_parser.Bry_upright).Add_byte(Byte_ascii.Eq).Add_double(lnki.Upright());
|
||||
}
|
||||
wtr.Write_dlm_row();
|
||||
}
|
||||
public static final Xofo_lnki[] Ary_empty = new Xofo_lnki[0];
|
||||
}
|
||||
75
400_xowa/src_160_file/gplx/xowa/Xofo_lnki_parser.java
Normal file
75
400_xowa/src_160_file/gplx/xowa/Xofo_lnki_parser.java
Normal file
@@ -0,0 +1,75 @@
|
||||
/*
|
||||
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.files.*;
|
||||
class Xofo_lnki_parser extends Obj_ary_parser_base {
|
||||
NumberParser parser = new NumberParser(); Xofo_lnki[] ary; int ary_idx;
|
||||
public Xofo_lnki[] Parse_ary(byte[] bry, int bgn, int end) {
|
||||
Parse_core(bry, bgn, end, Byte_ascii.Semic, Byte_ascii.NewLine);
|
||||
return ary;
|
||||
}
|
||||
@Override protected void Ary_len_(int v) {
|
||||
if (v == 0)
|
||||
ary = Xofo_lnki.Ary_empty;
|
||||
else {
|
||||
ary = new Xofo_lnki[v]; // NOTE: always create new array; never reuse;
|
||||
ary_idx = 0;
|
||||
}
|
||||
}
|
||||
@Override protected void Parse_itm(byte[] bry, int bgn, int end) {// 1,2,3,lnki_upright=12
|
||||
Xofo_lnki lnki = new Xofo_lnki();
|
||||
ary[ary_idx++] = lnki;
|
||||
int fld_bgn = bgn, fld_idx = 0, eq_pos = -1;
|
||||
for (int i = bgn; i < end; i++) {
|
||||
byte b = bry[i];
|
||||
switch (b) {
|
||||
case Byte_ascii.Eq: eq_pos = i; break;
|
||||
case Byte_ascii.Comma:
|
||||
Exec_val(lnki, fld_idx, eq_pos, bry, fld_bgn, i);
|
||||
++fld_idx;
|
||||
fld_bgn = i + 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
Exec_val(lnki, fld_idx, eq_pos, bry, fld_bgn, end);
|
||||
}
|
||||
private void Exec_val(Xofo_lnki lnki, int fld_idx, int eq_pos, byte[] bry, int fld_bgn, int i) {
|
||||
int fld_val = -1;
|
||||
if (fld_idx < 3) {
|
||||
fld_val = Bry_.X_to_int_or(bry, fld_bgn, i, Int_.MinValue);
|
||||
if (fld_val == Int_.MinValue) throw Err_.new_fmt_("invalid int: {0}", String_.new_utf8_(bry, fld_bgn, i));
|
||||
switch (fld_idx) {
|
||||
case 0: lnki.Lnki_type_((byte)fld_val); break;
|
||||
case 1: lnki.Lnki_w_(fld_val); break;
|
||||
case 2: lnki.Lnki_h_(fld_val); break;
|
||||
default: throw Err_.unhandled(fld_idx);
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (Bry_.Match(bry, fld_bgn, eq_pos, Xop_lnki_arg_parser.Bry_upright)) {
|
||||
double upright = Bry_.XtoDoubleByPos(bry, eq_pos + 1, i); // +1 to position after eq
|
||||
lnki.Lnki_upright_(upright);
|
||||
}
|
||||
else if (Bry_.Match(bry, fld_bgn, eq_pos, Xop_lnki_arg_parser.Bry_thumbtime)) {
|
||||
fld_val = Bry_.X_to_int_or(bry, eq_pos + 1, i, Int_.MinValue); // +1 to position after eq
|
||||
if (fld_val == Int_.MinValue) throw Err_.new_fmt_("invalid int: {0}", String_.new_utf8_(bry, eq_pos + 1, i));
|
||||
lnki.Lnki_thumbtime_(Xof_doc_thumb.X_int(fld_val));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
68
400_xowa/src_160_file/gplx/xowa/Xofo_lnki_parser_tst.java
Normal file
68
400_xowa/src_160_file/gplx/xowa/Xofo_lnki_parser_tst.java
Normal file
@@ -0,0 +1,68 @@
|
||||
/*
|
||||
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.files.*;
|
||||
public class Xofo_lnki_parser_tst {
|
||||
Xofo_lnki_parser_fxt fxt = new Xofo_lnki_parser_fxt();
|
||||
@Before public void init() {fxt.Reset();}
|
||||
@Test public void Basic() {
|
||||
fxt.Raw_("8,90,80").Expd_(fxt.lnki_(8, 90, 80)).tst();
|
||||
}
|
||||
@Test public void Upright() {
|
||||
fxt.Raw_("8,90,80,upright=.8").Expd_(fxt.lnki_(8, 90, 80).Lnki_upright_(.8d)).tst();
|
||||
}
|
||||
@Test public void Thumbtime() {
|
||||
fxt.Raw_("8,90,80,thumbtime=8").Expd_(fxt.lnki_(8, 90, 80).Lnki_thumbtime_(8)).tst();
|
||||
}
|
||||
@Test public void Many() {
|
||||
fxt.Raw_("8,20,30;8,90,80,upright=.8,thumbtime=8;8,30,40").Expd_(fxt.lnki_(8, 20, 30), fxt.lnki_(8, 90, 80).Lnki_upright_(.8d).Lnki_thumbtime_(8), fxt.lnki_(8, 30, 40)).tst();
|
||||
}
|
||||
}
|
||||
class Xofo_lnki_parser_fxt {
|
||||
Tst_mgr tst_mgr = new Tst_mgr();
|
||||
Xofo_lnki_parser parser = new Xofo_lnki_parser();
|
||||
public void Reset() {raw = null; expd = null;}
|
||||
public Xofo_lnki_chkr lnki_(int t, int w, int h) {return new Xofo_lnki_chkr().Lnki_type_((byte)t).Lnki_w_(w).Lnki_h_(h);}
|
||||
public Xofo_lnki_parser_fxt Raw_(String v) {raw = v; return this;} private String raw;
|
||||
public Xofo_lnki_parser_fxt Expd_(Xofo_lnki_chkr... v) {expd = v; return this;} private Xofo_lnki_chkr[] expd;
|
||||
public Xofo_lnki_parser_fxt tst() {
|
||||
byte[] bry = Bry_.new_utf8_(raw);
|
||||
Xofo_lnki[] actl = parser.Parse_ary(bry, 0, bry.length);
|
||||
tst_mgr.Tst_ary("", expd, actl);
|
||||
return this;
|
||||
}
|
||||
}
|
||||
class Xofo_lnki_chkr implements Tst_chkr {
|
||||
public Class<?> TypeOf() {return Xofo_lnki.class;}
|
||||
public Xofo_lnki_chkr Lnki_type_(byte v) {lnki_type = v; return this;} private byte lnki_type = Byte_.MaxValue_127;
|
||||
public Xofo_lnki_chkr Lnki_w_(int v) {lnki_w = v; return this;} private int lnki_w = -1;
|
||||
public Xofo_lnki_chkr Lnki_h_(int v) {lnki_h = v; return this;} private int lnki_h = -1;
|
||||
public Xofo_lnki_chkr Lnki_upright_(double v) {lnki_upright = v; return this;} double lnki_upright = -1;
|
||||
public Xofo_lnki_chkr Lnki_thumbtime_(int v) {lnki_thumbtime = v; return this;} private int lnki_thumbtime = -1;
|
||||
public int Chk(Tst_mgr mgr, String path, Object actl_obj) {
|
||||
Xofo_lnki actl = (Xofo_lnki)actl_obj;
|
||||
int rv = 0;
|
||||
rv += mgr.Tst_val(lnki_type == Byte_.MaxValue_127, path, "lnki_type", lnki_type, actl.Lnki_type());
|
||||
rv += mgr.Tst_val(lnki_w == -1, path, "lnki_w", lnki_w, actl.Lnki_w());
|
||||
rv += mgr.Tst_val(lnki_h == -1, path, "lnki_h", lnki_h, actl.Lnki_h());
|
||||
rv += mgr.Tst_val(lnki_upright == -1, path, "lnki_upright", lnki_upright, actl.Lnki_upright());
|
||||
rv += mgr.Tst_val(lnki_thumbtime == -1, path, "lnki_thumbtime", lnki_thumbtime, Xof_doc_thumb.X_int(actl.Lnki_thumbtime()));
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
40
400_xowa/src_160_file/gplx/xowa/Xoft_rule_grp.java
Normal file
40
400_xowa/src_160_file/gplx/xowa/Xoft_rule_grp.java
Normal file
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
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 Xoft_rule_grp implements GfoInvkAble {
|
||||
public Xoft_rule_grp(Xoft_rule_mgr owner, byte[] key) {this.owner = owner; this.key = key;}
|
||||
public Xoft_rule_mgr Owner() {return owner;} private Xoft_rule_mgr owner;
|
||||
public byte[] Key() {return key;} private byte[] key;
|
||||
public Xoft_rule_itm Get_or_null(byte[] key) {return (Xoft_rule_itm)hash.Fetch(hash_ref.Val_(key));}
|
||||
public Xoft_rule_itm Get_or_new(byte[] key) {
|
||||
Xoft_rule_itm rv = Get_or_null(key);
|
||||
if (rv == null) {
|
||||
Xof_ext file_type = Xof_ext_.new_by_ext_(key);
|
||||
rv = new Xoft_rule_itm(this, file_type);
|
||||
hash.Add(Bry_obj_ref.new_(key), rv);
|
||||
}
|
||||
return rv;
|
||||
} HashAdp hash = HashAdp_.new_(); Bry_obj_ref hash_ref = Bry_obj_ref.null_();
|
||||
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
|
||||
if (ctx.Match(k, Invk_owner)) return owner;
|
||||
else if (ctx.Match(k, Invk_set)) return Get_or_new(Bry_.new_utf8_(m.ReadStr("v")));
|
||||
else return GfoInvkAble_.Rv_unhandled;
|
||||
} private static final String Invk_owner = "owner", Invk_set = "set";
|
||||
public static final String Grp_app_default_str = "app_default";
|
||||
public static byte[] Grp_app_default = Bry_.new_utf8_(Grp_app_default_str);
|
||||
}
|
||||
35
400_xowa/src_160_file/gplx/xowa/Xoft_rule_itm.java
Normal file
35
400_xowa/src_160_file/gplx/xowa/Xoft_rule_itm.java
Normal file
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
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.apps.*;
|
||||
public class Xoft_rule_itm implements GfoInvkAble {
|
||||
public Xoft_rule_itm(Xoft_rule_grp owner, Xof_ext file_type) {this.owner = owner; this.file_type = file_type;}
|
||||
public Xoft_rule_grp Owner() {return owner;} private Xoft_rule_grp owner;
|
||||
public Xof_ext File_type() {return file_type;} private Xof_ext file_type;
|
||||
public long Make_max() {return make_max;} public Xoft_rule_itm Make_max_(long v) {make_max = v; return this;} long make_max = Max_wildcard;
|
||||
public long View_max() {return view_max;} public Xoft_rule_itm View_max_(long v) {view_max = v; return this;} long view_max = Max_wildcard;
|
||||
|
||||
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
|
||||
if (ctx.Match(k, Invk_owner)) return owner;
|
||||
else if (ctx.Match(k, Invk_make_max_)) make_max = gplx.ios.Io_size_.Load_int_(m);
|
||||
else if (ctx.Match(k, Invk_view_max_)) view_max = gplx.ios.Io_size_.Load_int_(m);
|
||||
else return GfoInvkAble_.Rv_unhandled;
|
||||
return this;
|
||||
} private static final String Invk_owner = "owner", Invk_make_max_ = "make_max_", Invk_view_max_ = "view_max_";
|
||||
public static final long Max_wildcard = -1;
|
||||
}
|
||||
44
400_xowa/src_160_file/gplx/xowa/Xoft_rule_mgr.java
Normal file
44
400_xowa/src_160_file/gplx/xowa/Xoft_rule_mgr.java
Normal file
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
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.apps.*;
|
||||
public class Xoft_rule_mgr implements GfoInvkAble {
|
||||
public Xoft_rule_mgr() {
|
||||
Xoft_rule_grp app_default = new Xoft_rule_grp(this, Xoft_rule_grp.Grp_app_default);
|
||||
App_default_set(app_default, Io_mgr.Len_gb, Xof_ext_.Bry__ary);
|
||||
hash.Add(Xoft_rule_grp.Grp_app_default, app_default);
|
||||
}
|
||||
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
|
||||
if (ctx.Match(k, Invk_set)) return Get_or_new(Bry_.new_utf8_(m.ReadStr("v")));
|
||||
else return GfoInvkAble_.Rv_unhandled;
|
||||
} private static final String Invk_set = "set";
|
||||
Xoft_rule_grp Get_or_null(byte[] key) {return (Xoft_rule_grp)hash.Fetch(key);}
|
||||
public Xoft_rule_grp Get_or_new(byte[] key) {
|
||||
Xoft_rule_grp rv = Get_or_null(key);
|
||||
if (rv == null) {
|
||||
rv = new Xoft_rule_grp(this, key);
|
||||
hash.Add(key, rv);
|
||||
}
|
||||
return rv;
|
||||
} HashAdp hash = HashAdp_.new_bry_();
|
||||
private void App_default_set(Xoft_rule_grp app_default, long make_max, byte[][] keys) {
|
||||
int keys_len = keys.length;
|
||||
for (int i = 0; i < keys_len; i++)
|
||||
app_default.Get_or_new(keys[i]).Make_max_(make_max);
|
||||
}
|
||||
}
|
||||
30
400_xowa/src_160_file/gplx/xowa/Xofw_file_finder_rslt.java
Normal file
30
400_xowa/src_160_file/gplx/xowa/Xofw_file_finder_rslt.java
Normal file
@@ -0,0 +1,30 @@
|
||||
/*
|
||||
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 Xofw_file_finder_rslt {
|
||||
public byte[] Ttl() {return ttl;} private byte[] ttl;
|
||||
public byte[] Redirect() {return redirect;} private byte[] redirect;
|
||||
public int Repo_idx() {return repo_idx;} private int repo_idx;
|
||||
public byte[] Repo_wiki_key() {return repo_wiki_key;} private byte[] repo_wiki_key;
|
||||
public void Init(byte[] ttl) {
|
||||
this.ttl = ttl; redirect = Xop_redirect_mgr.Redirect_null_bry; repo_wiki_key = null; repo_idx = Byte_.MaxValue_127;
|
||||
}
|
||||
public void Done(int repo_idx, byte[] repo_wiki_key, byte[] redirect) {
|
||||
this.repo_idx = repo_idx; this.repo_wiki_key = repo_wiki_key; this.redirect = redirect;
|
||||
}
|
||||
}
|
||||
98
400_xowa/src_160_file/gplx/xowa/Xofw_wiki_finder.java
Normal file
98
400_xowa/src_160_file/gplx/xowa/Xofw_wiki_finder.java
Normal file
@@ -0,0 +1,98 @@
|
||||
/*
|
||||
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.wikis.*; import gplx.xowa.files.*;
|
||||
public interface Xofw_wiki_finder {
|
||||
void Find(ListAdp repo_pairs, Xof_xfer_itm file);
|
||||
boolean Locate(Xofw_file_finder_rslt rv, ListAdp repo_pairs, byte[] ttl_bry);
|
||||
}
|
||||
class Xofw_wiki_wkr_mock implements Xofw_wiki_finder {
|
||||
int repo_idx; byte[] repo_wiki_key;
|
||||
public Xofw_wiki_wkr_mock Clear_en_wiki() {return Clear(1, Bry_en_wiki);}
|
||||
public Xofw_wiki_wkr_mock Clear_commons() {return Clear(0, Bry_commons);}
|
||||
Xofw_wiki_wkr_mock Clear(int repo_idx, byte[] repo_wiki_key) {
|
||||
this.repo_idx = repo_idx; this.repo_wiki_key = repo_wiki_key;
|
||||
if_ttl = then_redirect = Bry_.Empty;
|
||||
return this;
|
||||
} static final byte[] Bry_commons = Bry_.new_ascii_("commons.wikimedia.org"), Bry_en_wiki = Bry_.new_ascii_("en.wikipedia.org");
|
||||
public Xofw_wiki_wkr_mock Repo_idx_(int v) {this.repo_idx = v; return this;}
|
||||
public Xofw_wiki_wkr_mock Redirect_(String if_ttl_str, String then_redirect_str) {this.if_ttl = Bry_.new_utf8_(if_ttl_str); this.then_redirect = Bry_.new_utf8_(then_redirect_str); return this;} private byte[] if_ttl, then_redirect;
|
||||
public void Find(ListAdp repo_pairs, Xof_xfer_itm file) {
|
||||
byte[] ttl = file.Lnki_ttl();
|
||||
if (Bry_.Eq(ttl, if_ttl) && repo_idx != -1) {file.Atrs_by_ttl(ttl, then_redirect); file.Trg_repo_idx_(repo_idx);}
|
||||
else {file.Atrs_by_ttl(ttl, Bry_.Empty); file.Trg_repo_idx_(Xof_meta_itm.Repo_unknown);} // FUTURE: this should be missing, but haven't implemented unknown yet
|
||||
}
|
||||
public boolean Locate(Xofw_file_finder_rslt rv, ListAdp repo_pairs, byte[] ttl) {
|
||||
rv.Init(ttl);
|
||||
byte[] redirect = Bry_.Eq(ttl, if_ttl) ? then_redirect : null;
|
||||
rv.Done(repo_idx, repo_wiki_key, redirect);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
class Xofw_wiki_wkr_base implements Xofw_wiki_finder {
|
||||
public Xofw_wiki_wkr_base(Xow_wiki wiki, Xoa_wiki_mgr wiki_mgr) {this.wiki = wiki; this.wiki_mgr = wiki_mgr;} private Xow_wiki wiki; Xoa_wiki_mgr wiki_mgr;
|
||||
public void Find(ListAdp repo_pairs, Xof_xfer_itm file) {
|
||||
byte[] ttl_bry = file.Lnki_ttl();
|
||||
int repo_pairs_len = repo_pairs.Count();
|
||||
for (int i = 0; i < repo_pairs_len; i++) {
|
||||
Xof_repo_pair repo_pair = (Xof_repo_pair)repo_pairs.FetchAt(i);
|
||||
byte[] wiki_key = repo_pair.Src().Wiki_key();
|
||||
if (repo_pair.Src().Wmf_api()) continue;
|
||||
Xow_wiki repo_wiki = wiki_mgr.Get_by_key_or_null(wiki_key);
|
||||
if (repo_wiki == null) {continue;}
|
||||
Xoa_ttl ttl = Xoa_ttl.parse_(repo_wiki, ttl_bry);
|
||||
Xow_ns file_ns = repo_wiki.Ns_mgr().Ns_file();
|
||||
boolean found = repo_wiki.Db_mgr().Load_mgr().Load_by_ttl(tmp_db_page, file_ns, ttl.Page_db());
|
||||
if (!found) {continue;}
|
||||
byte[] redirect = Get_redirect(repo_wiki, file_ns, tmp_db_page);
|
||||
file.Atrs_by_ttl(ttl.Page_txt(), redirect);
|
||||
file.Trg_repo_idx_(i);
|
||||
return;
|
||||
}
|
||||
file.Trg_repo_idx_(-1);
|
||||
}
|
||||
public boolean Locate(Xofw_file_finder_rslt rv, ListAdp repo_pairs, byte[] ttl_bry) {
|
||||
Xoa_ttl ttl = Xoa_ttl.parse_(wiki, ttl_bry); // NOTE: parse_(ttl_bry) should be the same across all wikis; i.e.: there should be no aliases/namespaces
|
||||
Xow_ns file_ns = wiki.Ns_mgr().Ns_file(); // NOTE: file_ns should also be the same across all wikis; being used for data_mgr.Parse below
|
||||
byte[] ttl_db_key = ttl.Page_db();
|
||||
rv.Init(ttl_db_key);
|
||||
int repo_pairs_len = repo_pairs.Count();
|
||||
for (int i = 0; i < repo_pairs_len; i++) {
|
||||
Xof_repo_pair repo_pair = (Xof_repo_pair)repo_pairs.FetchAt(i);
|
||||
byte[] src_wiki_key = repo_pair.Src().Wiki_key();
|
||||
Xow_wiki src_wiki = wiki_mgr.Get_by_key_or_null(src_wiki_key);
|
||||
if (src_wiki == null) continue; // src_wiki defined as repo_pair in cfg, but it has not been downloaded; continue; EX: commons set up but not downloaded
|
||||
boolean found = src_wiki.Db_mgr().Load_mgr().Load_by_ttl(tmp_db_page, file_ns, ttl_db_key);
|
||||
if (!found) continue; // ttl does not exist in src_wiki; continue; EX: file does not exist in commons, but exists in en_wiki
|
||||
byte[] redirect = Get_redirect(src_wiki, file_ns, tmp_db_page);
|
||||
rv.Done(i, src_wiki_key, redirect);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
} static final Xodb_page tmp_db_page = Xodb_page.tmp_();
|
||||
byte[] Get_redirect(Xow_wiki wiki, Xow_ns file_ns, Xodb_page db_page) {
|
||||
if (db_page.Type_redirect()) {
|
||||
wiki.Db_mgr().Load_mgr().Load_page(db_page, file_ns, false);
|
||||
byte[] src = db_page.Text();
|
||||
Xoa_ttl redirect_ttl = wiki.Redirect_mgr().Extract_redirect(src, src.length);
|
||||
return redirect_ttl == Xop_redirect_mgr.Redirect_null_ttl ? Xop_redirect_mgr.Redirect_null_bry : redirect_ttl.Page_db();
|
||||
}
|
||||
else
|
||||
return Xop_redirect_mgr.Redirect_null_bry;
|
||||
}
|
||||
}
|
||||
54
400_xowa/src_160_file/gplx/xowa/Xoo_mgr.java
Normal file
54
400_xowa/src_160_file/gplx/xowa/Xoo_mgr.java
Normal file
@@ -0,0 +1,54 @@
|
||||
/*
|
||||
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.*;
|
||||
class Xoo_mgr implements GfoInvkAble {
|
||||
public Xoo_mgr(Xoa_app app) {this.app = app;} private Xoa_app app;
|
||||
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
|
||||
if (ctx.Match(k, Invk_owner)) return app;
|
||||
else return GfoInvkAble_.Rv_unhandled;
|
||||
} private static final String Invk_owner = "owner";
|
||||
}
|
||||
class Xoo_grp implements GfoInvkAble {
|
||||
public Xoo_grp(Xoo_mgr mgr, String key) {this.mgr = mgr; this.key = key;} private Xoo_mgr mgr;
|
||||
public String Key() {return key;} private String key;
|
||||
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
|
||||
if (ctx.Match(k, Invk_owner)) return mgr;
|
||||
else return GfoInvkAble_.Rv_unhandled;
|
||||
} private static final String Invk_owner = "owner";
|
||||
}
|
||||
class Xoo_itm_html {
|
||||
public Xoo_itm_html(Xoo_grp grp) {this.grp = grp;} private Xoo_grp grp;
|
||||
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
|
||||
if (ctx.Match(k, Invk_owner)) return grp;
|
||||
else return GfoInvkAble_.Rv_unhandled;
|
||||
} private static final String Invk_owner = "owner";
|
||||
}
|
||||
class Xoo_itm_file {
|
||||
public Xoo_itm_file(Xoo_grp grp) {this.grp = grp;} private Xoo_grp grp;
|
||||
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
|
||||
if (ctx.Match(k, Invk_owner)) return grp;
|
||||
else return GfoInvkAble_.Rv_unhandled;
|
||||
} private static final String Invk_owner = "owner";
|
||||
}
|
||||
class Xoo_itm_interwiki {
|
||||
public Xoo_itm_interwiki(Xoo_grp grp) {this.grp = grp;} private Xoo_grp grp;
|
||||
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
|
||||
if (ctx.Match(k, Invk_owner)) return grp;
|
||||
else return GfoInvkAble_.Rv_unhandled;
|
||||
} private static final String Invk_owner = "owner";
|
||||
}
|
||||
Reference in New Issue
Block a user