mirror of
https://github.com/gnosygnu/xowa.git
synced 2026-03-02 03:49:30 +00:00
v2.3.1.1
This commit is contained in:
@@ -1,41 +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; 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);}
|
||||
}
|
||||
@@ -1,182 +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; import gplx.*;
|
||||
import gplx.core.primitives.*;
|
||||
public class Xof_ext_ {
|
||||
public static final int Id_unknown = 0 // SERIALIZED; ids are saved to fsdb;
|
||||
, 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, Id_wav = 18;
|
||||
public static final int Id__max = 19;
|
||||
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"), Bry_wav = Bry_.new_ascii_("wav")
|
||||
;
|
||||
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, Bry_wav
|
||||
};
|
||||
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"), Bry_.new_ascii_("audio/x-wav")
|
||||
};
|
||||
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); id_hash_new_(rv, Bry_wav, Id_wav);
|
||||
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_ascii_()
|
||||
.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).Add_bry_bry(Bry_flac)
|
||||
.Add_bry_bry(Bry_bmp).Add_bry_bry(Bry_xcf).Add_bry_bry(Bry_wav)
|
||||
;
|
||||
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: case Xof_ext_.Id_wav: 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; PAGE:en.w: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; PAGE:en.w: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: case Xof_ext_.Id_wav: 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -36,8 +36,8 @@ public class Xof_file_mgr implements GfoInvkAble {
|
||||
public void Init_by_app(Xoae_app app) {
|
||||
Io_url db_url = app.User().Fsys_mgr().Root_dir().OwnerDir().GenSubFil_ary("xowa.user.", app.User().Key_str(), ".sqlite3");
|
||||
Db_conn_bldr_data conn_data = Db_conn_bldr.I.Get_or_new("xowa.user_db", db_url);
|
||||
boolean version_is_1 = Bool_.Y;
|
||||
cache_mgr.Init_for_db(conn_data.Conn(), conn_data.Created(), version_is_1);
|
||||
boolean schema_is_1 = Bool_.Y;
|
||||
cache_mgr.Init_for_db(conn_data.Conn(), conn_data.Created(), schema_is_1);
|
||||
}
|
||||
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
|
||||
if (ctx.Match(k, Invk_repos)) return repo_mgr;
|
||||
|
||||
@@ -1,30 +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; 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;
|
||||
}
|
||||
}
|
||||
@@ -1,54 +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; import gplx.*;
|
||||
import gplx.core.primitives.*;
|
||||
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));}
|
||||
}
|
||||
Reference in New Issue
Block a user