mirror of
https://github.com/gnosygnu/xowa.git
synced 2026-03-02 03:49:30 +00:00
'v3.9.4.1'
This commit is contained in:
42
400_xowa/src/gplx/xowa/files/repos/Xof_itm_ttl_.java
Normal file
42
400_xowa/src/gplx/xowa/files/repos/Xof_itm_ttl_.java
Normal file
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
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.files.repos; import gplx.*; import gplx.xowa.*; import gplx.xowa.files.*;
|
||||
public class Xof_itm_ttl_ {
|
||||
public static byte[] Remove_invalid(Bry_bfr bfr, byte[] ttl) {
|
||||
int ttl_len = ttl.length;
|
||||
for (int i = 0; i < ttl_len; i++) {
|
||||
byte b = ttl[i];
|
||||
if (gplx.core.envs.Op_sys_.Wnt_invalid_char(b)) b = Byte_ascii.Underline;
|
||||
bfr.Add_byte(b);
|
||||
}
|
||||
return bfr.To_bry_and_clear();
|
||||
}
|
||||
public static byte[] Shorten(Bry_bfr bfr, byte[] ttl, int ttl_max, byte[] md5, byte[] ext_bry) {
|
||||
byte[] rv = ttl;
|
||||
int exceed_len = rv.length - ttl_max;
|
||||
if (exceed_len > 0) {
|
||||
bfr.Add_mid(rv, 0, ttl_max - 33); // add truncated title; 33=_.length + md5.length
|
||||
bfr.Add_byte(Byte_ascii.Underline); // add underline; EX: "_"
|
||||
bfr.Add(md5); // add md5; EX: "abcdefghijklmnopqrstuvwxyz0123456"
|
||||
bfr.Add_byte(Byte_ascii.Dot); // add dot; EX: "."
|
||||
bfr.Add(ext_bry); // add ext; EX: ".png"
|
||||
rv = bfr.To_bry_and_clear();
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
@@ -16,8 +16,8 @@ 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.files.repos; import gplx.*; import gplx.xowa.*; import gplx.xowa.files.*;
|
||||
import gplx.core.btries.*; import gplx.core.consoles.*;
|
||||
import gplx.xowa.apps.fsys.*; import gplx.xowa.files.exts.*;
|
||||
import gplx.core.consoles.*;
|
||||
import gplx.xowa.apps.fsys.*; import gplx.xowa.files.exts.*; import gplx.xowa.files.imgs.*;
|
||||
import gplx.xowa.wikis.domains.*;
|
||||
public class Xof_repo_itm implements Gfo_invk {
|
||||
private final Xoa_fsys_mgr app_fsys; private final Xof_rule_mgr ext_rule_mgr;
|
||||
@@ -25,23 +25,33 @@ public class Xof_repo_itm implements Gfo_invk {
|
||||
this.key = key; this.app_fsys = app_fsys; this.ext_rule_mgr = ext_rule_mgr;
|
||||
Wiki_domain_(wiki_domain);
|
||||
}
|
||||
public byte[] Key() {return key;} private final byte[] key;
|
||||
public byte[] Wiki_domain() {return wiki_domain;} private byte[] wiki_domain;
|
||||
public byte[] Wiki_abrv_xo() {return wiki_abrv_xo;} private byte[] wiki_abrv_xo;
|
||||
public byte[] Root_bry() {return root_bry;} private byte[] root_bry;
|
||||
public byte[] Root_http() {return root_http;} private byte[] root_http = Bry_.Empty;
|
||||
public String Root_str() {return root_str;} private String root_str;
|
||||
public byte Dir_spr() {return dir_spr;} private byte dir_spr;
|
||||
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 boolean Shorten_ttl() {return shorten_ttl;} public Xof_repo_itm Shorten_ttl_(boolean v) {shorten_ttl = v; return this;} private boolean shorten_ttl = true;
|
||||
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[][] Mode_names() {return mode_names;} private byte[][] mode_names = new byte[][] {Xof_repo_itm_.Mode_names_key[0], Xof_repo_itm_.Mode_names_key[1]};
|
||||
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 Xof_rule_grp Ext_rules() {return ext_rules;} private Xof_rule_grp ext_rules;
|
||||
public byte[] Key() {return key;} private final byte[] key; // EX: "src_http_commons"
|
||||
public byte Tid() {return tid;} private byte tid; // EX: Xof_repo_tid_.Tid__remote
|
||||
public byte[] Wiki_domain() {return wiki_domain;} private byte[] wiki_domain; // EX: "commons.wikimedia.org"
|
||||
public byte[] Wiki_abrv_xo() {return wiki_abrv_xo;} private byte[] wiki_abrv_xo; // EX: "c"
|
||||
public byte Dir_spr() {return dir_spr;} private byte dir_spr; // EX: "/"
|
||||
public int Dir_depth() {return dir_depth;} private int dir_depth = 4; // EX: "/1/2/3/4" vs "/1/2"
|
||||
public byte[] Root_bry() {return root_bry;} private byte[] root_bry; // EX:
|
||||
public byte[] Root_http() {return root_http;} private byte[] root_http = Bry_.Empty; // EX:
|
||||
public String Root_str() {return root_str;} private String root_str;
|
||||
public boolean Fsys_is_wnt() {return fsys_is_wnt;} private boolean fsys_is_wnt;
|
||||
public boolean Shorten_ttl() {return shorten_ttl;} private boolean shorten_ttl = true;
|
||||
public boolean Wmf_fsys() {return wmf_fsys;} private boolean wmf_fsys;
|
||||
public boolean Wmf_api() {return wmf_api;} private boolean wmf_api;
|
||||
public boolean Tarball() {return tarball;} private boolean tarball;
|
||||
public byte[][] Mode_names() {return mode_names;} private byte[][] mode_names = new byte[][] {Xof_img_mode_.Names_ary[0], Xof_img_mode_.Names_ary[1]};
|
||||
public Xof_rule_grp Ext_rules() {return ext_rules;} private Xof_rule_grp ext_rules;
|
||||
public boolean Primary() {return primary;} private boolean primary;
|
||||
|
||||
public Xof_repo_itm Fsys_is_wnt_(boolean v) {fsys_is_wnt = v; return this;}
|
||||
public Xof_repo_itm Shorten_ttl_(boolean v) {shorten_ttl = v; return this;}
|
||||
public Xof_repo_itm Wmf_fsys_(boolean v) {wmf_fsys = v; return this;}
|
||||
public Xof_repo_itm Wmf_api_(boolean v) {wmf_api = v; return this;}
|
||||
public Xof_repo_itm Tarball_(boolean v) {tarball = v; return this;}
|
||||
public Xof_repo_itm Ext_rules_(byte[] ext_rules_key) {ext_rules = ext_rule_mgr.Get_or_new(ext_rules_key); return this;}
|
||||
public boolean Primary() {return primary;} public Xof_repo_itm Primary_(boolean v) {primary = v; return this;} private boolean primary;
|
||||
public Xof_repo_itm Dir_depth_(int v) {dir_depth = v; return this;}
|
||||
public Xof_repo_itm Primary_(boolean v) {primary = v; return this;}
|
||||
|
||||
public void Wiki_domain_(byte[] v) {
|
||||
this.wiki_domain = v;
|
||||
Xow_domain_itm domain_itm = Xow_domain_itm_.parse(v);
|
||||
@@ -70,11 +80,11 @@ public class Xof_repo_itm implements Gfo_invk {
|
||||
}
|
||||
public byte[] Gen_name_src(Bry_bfr tmp_bfr, byte[] name) {
|
||||
if (!fsys_is_wnt || wmf_fsys) return name;
|
||||
return Xof_repo_itm_.Ttl_invalid_fsys_chars(tmp_bfr, name);
|
||||
return Xof_itm_ttl_.Remove_invalid(tmp_bfr, name);
|
||||
}
|
||||
public byte[] Gen_name_trg(Bry_bfr tmp_bfr, byte[] bry, byte[] md5, Xof_ext ext) {
|
||||
byte[] rv = Gen_name_src(tmp_bfr, bry);
|
||||
return shorten_ttl ? Xof_repo_itm_.Ttl_shorten_ttl(tmp_bfr, rv, Ttl__max_len, md5, ext.Ext()) : rv;
|
||||
return shorten_ttl ? Xof_itm_ttl_.Shorten(tmp_bfr, rv, Ttl__max_len, md5, ext.Ext()) : rv;
|
||||
}
|
||||
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
|
||||
if (ctx.Match(k, Invk_owner)) throw Err_.new_unimplemented_w_msg("deprecated repo_itm.owner");
|
||||
@@ -83,9 +93,10 @@ public class Xof_repo_itm implements Gfo_invk {
|
||||
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 if (ctx.Match(k, Invk_tid_)) tid = Xof_repo_tid_.By_str(m.ReadStr("v"));
|
||||
else return Gfo_invk_.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_";
|
||||
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_", Invk_tid_ = "tid_";
|
||||
public static final int Ttl__max_len = 180;
|
||||
}
|
||||
|
||||
@@ -1,56 +0,0 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.files.repos; import gplx.*; import gplx.xowa.*; import gplx.xowa.files.*;
|
||||
import gplx.core.btries.*; import gplx.core.envs.*;
|
||||
public class Xof_repo_itm_ {
|
||||
public static final int Dir_depth_null = -1, Dir_depth_wmf = 2, Dir_depth_xowa = 4;
|
||||
public static final byte Mode_orig = 0, Mode_thumb = 1, Mode_nil = Byte_.Max_value_127;
|
||||
public static byte Mode_by_bool(boolean is_thumb) {return is_thumb ? Mode_thumb : Mode_orig;}
|
||||
public static final byte[][] Mode_names_key = new byte[][] {Bry_.new_a7("orig"), Bry_.new_a7("thumb")};
|
||||
public static final byte Repo_remote = 0, Repo_local = 1, Repo_unknown = 126, Repo_null = Byte_.Max_value_127;
|
||||
public static byte Repo_by_bool(boolean is_commons) {return is_commons ? Repo_remote : Repo_local;}
|
||||
public static boolean Repo_is_known(byte repo) {
|
||||
switch (repo) {
|
||||
case Repo_remote:
|
||||
case Repo_local: return true;
|
||||
default: return false;
|
||||
}
|
||||
}
|
||||
public static byte[] Ttl_invalid_fsys_chars(Bry_bfr bfr, byte[] ttl) {
|
||||
int ttl_len = ttl.length;
|
||||
for (int i = 0; i < ttl_len; i++) {
|
||||
byte b = ttl[i];
|
||||
if (Op_sys_.Wnt_invalid_char(b)) b = Byte_ascii.Underline;
|
||||
bfr.Add_byte(b);
|
||||
}
|
||||
return bfr.To_bry_and_clear();
|
||||
}
|
||||
public static byte[] Ttl_shorten_ttl(Bry_bfr bfr, byte[] ttl, int ttl_max, byte[] md5, byte[] ext_bry) {
|
||||
byte[] rv = ttl;
|
||||
int exceed_len = rv.length - ttl_max;
|
||||
if (exceed_len > 0) {
|
||||
bfr.Add_mid(rv, 0, ttl_max - 33); // add truncated title; 33=_.length + md5.length
|
||||
bfr.Add_byte(Byte_ascii.Underline); // add underline; EX: "_"
|
||||
bfr.Add(md5); // add md5; EX: "abcdefghijklmnopqrstuvwxyz0123456"
|
||||
bfr.Add_byte(Byte_ascii.Dot); // add dot; EX: "."
|
||||
bfr.Add(ext_bry); // add ext; EX: ".png"
|
||||
rv = bfr.To_bry_and_clear();
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
@@ -17,15 +17,16 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.files.repos; import gplx.*; import gplx.xowa.*; import gplx.xowa.files.*;
|
||||
public class Xof_repo_pair implements Gfo_invk {
|
||||
public Xof_repo_pair(byte repo_idx, byte[] wiki_domain, Xof_repo_itm src, Xof_repo_itm trg) {
|
||||
this.repo_idx = repo_idx; this.wiki_domain = wiki_domain; this.src = src; this.trg = trg;
|
||||
public Xof_repo_pair(byte id, byte[] wiki_domain, Xof_repo_itm src, Xof_repo_itm trg) {
|
||||
this.id = id; this.wiki_domain = wiki_domain; this.src = src; this.trg = trg;
|
||||
}
|
||||
public byte Repo_idx() {return repo_idx;} private byte repo_idx;
|
||||
public byte[] Wiki_domain() {return wiki_domain;} private final byte[] wiki_domain;
|
||||
public Xof_repo_itm Src() {return src;} private final Xof_repo_itm src;
|
||||
public Xof_repo_itm Trg() {return trg;} private final Xof_repo_itm trg;
|
||||
public byte Id() {return id;} private byte id;
|
||||
public byte[] Wiki_domain() {return wiki_domain;} private final byte[] wiki_domain;
|
||||
public Xof_repo_itm Src() {return src;} private final Xof_repo_itm src;
|
||||
public Xof_repo_itm Trg() {return trg;} private final Xof_repo_itm trg;
|
||||
|
||||
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
|
||||
if (ctx.Match(k, Invk_repo_id_)) repo_idx = m.ReadByte("v");
|
||||
if (ctx.Match(k, Invk_repo_id_)) id = m.ReadByte("v");
|
||||
else return Gfo_invk_.Rv_unhandled;
|
||||
return this;
|
||||
} private static final String Invk_repo_id_ = "repo_id_";
|
||||
|
||||
36
400_xowa/src/gplx/xowa/files/repos/Xof_repo_tid_.java
Normal file
36
400_xowa/src/gplx/xowa/files/repos/Xof_repo_tid_.java
Normal file
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
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.files.repos; import gplx.*; import gplx.xowa.*; import gplx.xowa.files.*;
|
||||
public class Xof_repo_tid_ {
|
||||
public static final byte
|
||||
Tid__remote = 0 // EX: "https://commons.wikimedia.org/wiki/File:A.png"
|
||||
, Tid__local = 1 // EX: "https://en.wikipedia.org/wiki/File:A.png"
|
||||
, Tid__xtns = 2 // EX: "https://en.wikipedia.org/w/extensions/ImageMap/desc-20.png?15600"
|
||||
, Tid__math = 3 // EX: "https://wikimedia.org/api/rest_v1/media/math/render/svg/596f8baf206a81478afd4194b44138715dc1a05c"
|
||||
, Tid__null = Byte_.Max_value_127
|
||||
;
|
||||
public static byte By_str(String v) {
|
||||
if (String_.Eq(v, "self")) return Tid__local;
|
||||
else if (String_.Eq(v, "comm")) return Tid__remote;
|
||||
else if (String_.Eq(v, "math")) return Tid__math;
|
||||
else throw Err_.new_unhandled_default(v);
|
||||
}
|
||||
public static final byte[]
|
||||
Bry__math = Bry_.new_a7("wikimedia.org/math") // EX: https://wikimedia.org/api/rest_v1/media/math/render/svg/596f8baf206a81478afd4194b44138715dc1a05c
|
||||
;
|
||||
}
|
||||
@@ -55,7 +55,7 @@ public class Xowe_repo_mgr implements Xow_repo_mgr, Gfo_invk {
|
||||
int len = repos.Count();
|
||||
for (int i = 0; i < len; i++) {
|
||||
Xof_repo_pair pair = (Xof_repo_pair)repos.Get_at(i);
|
||||
if (pair.Repo_idx() == id) return pair;
|
||||
if (pair.Id() == id) return pair;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user