mirror of
https://github.com/gnosygnu/xowa.git
synced 2026-03-02 03:49:30 +00:00
v2.7.2.1
This commit is contained in:
35
400_xowa/src/gplx/xowa/apps/Xoa_app_type.java
Normal file
35
400_xowa/src/gplx/xowa/apps/Xoa_app_type.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.apps; import gplx.*; import gplx.xowa.*;
|
||||
public class Xoa_app_type {
|
||||
Xoa_app_type(int uid) {this.uid = uid;}
|
||||
public int Uid() {return uid;} private final int uid;
|
||||
public boolean Uid_is_gui() {return uid == Uid_gui;}
|
||||
public boolean Uid_is_tcp() {return uid == Uid_tcp;}
|
||||
public boolean Uid_is_http() {return uid == Uid_http;}
|
||||
private static final int Uid_cmd = 1, Uid_gui = 2, Uid_tcp = 3, Uid_http = 4;
|
||||
private static final String Key_cmd = "cmd", Key_gui = "gui", Key_tcp = "server", Key_http = "http_server";
|
||||
public static final Xoa_app_type Itm_cmd = new Xoa_app_type(Uid_cmd), Itm_gui = new Xoa_app_type(Uid_gui), Itm_tcp = new Xoa_app_type(Uid_tcp), Itm_http = new Xoa_app_type(Uid_http);
|
||||
public static Xoa_app_type parse(String s) {
|
||||
if (String_.Eq(s, Key_cmd)) return Itm_cmd;
|
||||
else if (String_.Eq(s, Key_gui)) return Itm_gui;
|
||||
else if (String_.Eq(s, Key_tcp)) return Itm_tcp;
|
||||
else if (String_.Eq(s, Key_http)) return Itm_http;
|
||||
else return Itm_cmd; // default to cmd as per early behaviour; handles mistaken "--app_mode wrong"
|
||||
}
|
||||
}
|
||||
126
400_xowa/src/gplx/xowa/apps/Xoa_gfs_mgr.java
Normal file
126
400_xowa/src/gplx/xowa/apps/Xoa_gfs_mgr.java
Normal file
@@ -0,0 +1,126 @@
|
||||
/*
|
||||
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.apps; import gplx.*; import gplx.xowa.*;
|
||||
import gplx.gfs.*;
|
||||
import gplx.xowa.users.*; import gplx.xowa.apps.fsys.*;
|
||||
public class Xoa_gfs_mgr implements GfoInvkAble, GfoInvkRootWkr {
|
||||
private final GfoInvkAble root_invk; private final Xoa_fsys_mgr app_fsys_mgr; private final Xou_fsys_mgr usr_fsys_mgr;
|
||||
public Xoa_gfs_mgr(GfoInvkAble root_invk, Xoa_fsys_mgr app_fsys_mgr, Xou_fsys_mgr usr_fsys_mgr) {
|
||||
this.root_invk = root_invk; this.app_fsys_mgr = app_fsys_mgr; this.usr_fsys_mgr = usr_fsys_mgr;
|
||||
GfsCore._.AddCmd(root_invk, Xoae_app.Invk_app);
|
||||
GfsCore._.AddCmd(root_invk, Xoae_app.Invk_xowa);
|
||||
}
|
||||
public GfoInvkAble Root_invk() {return root_invk;}
|
||||
public Xoa_fsys_mgr App_fsys_mgr() {return app_fsys_mgr;}
|
||||
public Xoa_app_eval Eval_mgr() {return eval_mgr;} private final Xoa_app_eval eval_mgr = new Xoa_app_eval();
|
||||
private void Run_url_by_type(String type) {
|
||||
Io_url app_data_dir = usr_fsys_mgr.App_data_dir();
|
||||
Io_url url = null;
|
||||
if (String_.Eq(type, "user_system_cfg")) url = app_data_dir.GenSubFil_nest("cfg", "user_system_cfg.gfs");
|
||||
else if (String_.Eq(type, "xowa_cfg_custom")) url = usr_fsys_mgr.App_data_cfg_custom_fil();
|
||||
else if (String_.Eq(type, "xowa_cfg_user")) url = usr_fsys_mgr.App_data_cfg_user_fil();
|
||||
else if (String_.Eq(type, "xowa_cfg_os")) {url = app_fsys_mgr.Bin_data_os_cfg_fil(); Xoa_gfs_mgr_.Cfg_os_assert(url);}
|
||||
else if (String_.Eq(type, "xowa_cfg_app")) url = app_fsys_mgr.Root_dir().GenSubFil("xowa.gfs");
|
||||
else throw Exc_.new_("invalid gfs type", "type", type);
|
||||
try {Run_url(url);}
|
||||
catch (Exception e) { // gfs is corrupt; may happen if multiple XOWAs opened, and "Close all" chosen in OS; DATE:2014-07-01
|
||||
if (!String_.Eq(type, "xowa")) // check if user.gfs
|
||||
Io_mgr.I.MoveFil(url, url.GenNewNameOnly(url.NameOnly() + "-" + DateAdp_.Now().XtoStr_fmt_yyyyMMdd_HHmmss())); // move file
|
||||
Gfo_usr_dlg_.I.Warn_many("", "", "invalid gfs; obsoleting: src=~{0} err=~{1}", url.Raw(), Err_.Message_gplx(e));
|
||||
}
|
||||
}
|
||||
public GfoMsg Parse_root_msg(String v) {return gplx.gfs.Gfs_msg_bldr._.ParseToMsg(v);}
|
||||
public Gfs_wtr Wtr() {return wtr;} private Gfs_wtr wtr = new Gfs_wtr();
|
||||
public void Run_url(Io_url url) {
|
||||
Run_url_for(GfsCore._.Root(), url);
|
||||
Gfo_usr_dlg_.I.Log_wkr().Log_to_session_fmt("gfs.done: ~{0}", url.Raw());
|
||||
}
|
||||
public void Run_url_for(GfoInvkAble invk, Io_url url) {
|
||||
String raw = Io_mgr.I.LoadFilStr_args(url).MissingIgnored_().Exec(); if (String_.Len_eq_0(raw)) return;
|
||||
Run_str_for(invk, raw);
|
||||
}
|
||||
public Object Run_str(String raw) {return Run_str_for(GfsCore._.Root(), raw);}
|
||||
public Object Run_str_for(GfoInvkAble invk, String raw) {return Run_str_for(invk, Parse_root_msg(raw));}
|
||||
public Object Run_str_for(GfoInvkAble invk, GfoMsg root_msg) {
|
||||
try {
|
||||
int sub_msgs_len = root_msg.Subs_count();
|
||||
GfsCtx ctx = GfsCtx.new_().Fail_if_unhandled_(Fail_if_unhandled).Usr_dlg_(Gfo_usr_dlg_.I);
|
||||
Object rv = null;
|
||||
for (int i = 0; i < sub_msgs_len; i++) {
|
||||
GfoMsg sub_msg = root_msg.Subs_getAt(i);
|
||||
rv = GfsCore._.ExecOne_to(ctx, invk, sub_msg);
|
||||
}
|
||||
return rv;
|
||||
} catch (Exception e) {
|
||||
Gfo_usr_dlg_.I.Warn_many("", "", "error while executing script: err=~{0}", Err_.Message_gplx(e));
|
||||
return GfoInvkAble_.Rv_error;
|
||||
}
|
||||
}
|
||||
public GfoEvObj Get_owner_as_event_obj(String cmd) {
|
||||
GfoMsg cur_msg = Parse_root_msg(cmd).Subs_getAt(0); // ignore root_msg which is ""
|
||||
GfoInvkAble cur_invk = root_invk;
|
||||
while (true) {
|
||||
if (cur_msg.Subs_count() == 0) return (GfoEvObj)cur_invk; // terminal msg; return cur_invk
|
||||
cur_invk = (GfoInvkAble)GfoInvkAble_.InvkCmd(cur_invk, cur_msg.Key());
|
||||
cur_msg = cur_msg.Subs_getAt(0);
|
||||
}
|
||||
}
|
||||
public byte[] Build_prop_set_to_bry(Bry_bfr bfr, byte[] prop, byte[] val) {Build_prop_set(bfr, prop, val); return bfr.Xto_bry_and_clear();}
|
||||
public void Build_prop_set(Bry_bfr bfr, byte[] prop, byte[] val) {
|
||||
fmtr_eval_set.Bld_bfr_many(bfr, prop, Xoa_gfs_mgr.Cfg_save_escape(val));
|
||||
} private Bry_fmtr fmtr_eval_set = Bry_fmtr.new_("~{prop}_('~{val}');\n", "prop", "val");
|
||||
public byte[] Build_prop_get_to_bry(Bry_bfr bfr, byte[] prop) {Build_prop_get(bfr, prop); return bfr.Xto_bry_and_clear();}
|
||||
public void Build_prop_get(Bry_bfr bfr, byte[] prop) {
|
||||
fmtr_eval_get.Bld_bfr_many(bfr, prop);
|
||||
} private Bry_fmtr fmtr_eval_get = Bry_fmtr.new_("~{prop};\n", "prop");
|
||||
static final String GRP_KEY = "Xoa_gfs_mgr";
|
||||
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
|
||||
if (ctx.Match(k, Invk_run_file_by_type)) Run_url_by_type(m.ReadStr("v"));
|
||||
else if (ctx.Match(k, Invk_fail_if_unhandled_)) {Fail_if_unhandled = m.ReadYn("v"); ctx.Fail_if_unhandled_(Fail_if_unhandled);}
|
||||
else if (ctx.Match(k, Invk_txns)) {return GfoInvkAble_.Null;} // FUTURE: handle version for upgrades
|
||||
else return GfoInvkAble_.Rv_unhandled;
|
||||
return this;
|
||||
} private static final String Invk_run_file_by_type = "run_file_by_type", Invk_fail_if_unhandled_ = "fail_if_unhandled_", Invk_txns = "txns";
|
||||
public static void Msg_parser_init() {
|
||||
GfsCore._.MsgParser_(gplx.gfs.Gfs_msg_bldr._);
|
||||
}
|
||||
public static byte[] Cfg_save_escape(String v) {return Cfg_save_escape(Bry_.new_u8(v));}
|
||||
public static byte[] Cfg_save_escape(byte[] v) {
|
||||
return Bry_finder.Find_fwd(v, Byte_ascii.Apos) == Bry_.NotFound ? v : Bry_.Replace(v, Bry_apos_1, Bry_apos_2);
|
||||
} static final byte[] Bry_apos_1 = Bry_.new_a7("'"), Bry_apos_2 = Bry_.new_a7("''");
|
||||
public static String Build_code(String... ary) {
|
||||
int len = ary.length;
|
||||
for (int i = 0; i < len; i++) {
|
||||
if (i != 0) Build_code_bfr.Add_byte(Byte_ascii.Dot);
|
||||
Build_code_bfr.Add_str(ary[i]);
|
||||
}
|
||||
return Build_code_bfr.Xto_str_and_clear();
|
||||
} static final Bry_bfr Build_code_bfr = Bry_bfr.new_();
|
||||
public static final String Cfg_user_file = "xowa_user_cfg.gfs", Cfg_user_custom_file = "user_custom_cfg.gfs", Cfg_os = "xowa_cfg_os.gfs";
|
||||
public static boolean Fail_if_unhandled = false;
|
||||
}
|
||||
class Xoa_gfs_mgr_ {
|
||||
public static void Cfg_os_assert(Io_url orig_url) {
|
||||
Io_url dflt_url = orig_url.GenNewNameOnly(orig_url.NameOnly() + "_default");
|
||||
if (!Io_mgr.I.ExistsFil(dflt_url)) return; // no dflt
|
||||
if (!Io_mgr.I.ExistsFil(orig_url)) {
|
||||
Io_mgr.I.CopyFil(dflt_url, orig_url, true);
|
||||
Gfo_usr_dlg_.I.Log_many("", "", "xowa_cfg_os generated; url=~{0}", orig_url.Raw());
|
||||
}
|
||||
}
|
||||
}
|
||||
117
400_xowa/src/gplx/xowa/apps/Xoa_gfs_php_mgr.java
Normal file
117
400_xowa/src/gplx/xowa/apps/Xoa_gfs_php_mgr.java
Normal file
@@ -0,0 +1,117 @@
|
||||
/*
|
||||
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.apps; import gplx.*; import gplx.xowa.*;
|
||||
import gplx.php.*;
|
||||
public class Xoa_gfs_php_mgr {
|
||||
public static byte[] Xto_php(Bry_bfr bfr, boolean escape_backslash, byte[] src) {
|
||||
int len = src.length;
|
||||
int pos = 0;
|
||||
boolean dirty = false;
|
||||
while (pos < len) {
|
||||
byte b = src[pos];
|
||||
switch (b) {
|
||||
case Byte_ascii.Tilde:
|
||||
if (!dirty) {
|
||||
bfr.Add_mid(src, 0, pos);
|
||||
dirty = true;
|
||||
}
|
||||
pos = Xto_php_swap(bfr, src, len, pos + 1);
|
||||
break;
|
||||
case Byte_ascii.Backslash: case Byte_ascii.Dollar:
|
||||
case Byte_ascii.Apos: case Byte_ascii.Quote:
|
||||
if (escape_backslash) {
|
||||
if (!dirty) {
|
||||
bfr.Add_mid(src, 0, pos);
|
||||
dirty = true;
|
||||
}
|
||||
bfr.Add_byte(Byte_ascii.Backslash);
|
||||
bfr.Add_byte(b);
|
||||
}
|
||||
else {
|
||||
if (dirty)
|
||||
bfr.Add_byte(b);
|
||||
}
|
||||
++pos;
|
||||
break;
|
||||
default:
|
||||
if (dirty)
|
||||
bfr.Add_byte(b);
|
||||
++pos;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return dirty ? bfr.Xto_bry_and_clear() : src;
|
||||
}
|
||||
private static int Xto_php_swap(Bry_bfr bfr, byte[] src, int len, int pos) {
|
||||
if (pos >= len) throw Exc_.new_("invalid gfs: tilde is last char", "src", String_.new_u8(src));
|
||||
byte b = src[pos];
|
||||
switch (b) {
|
||||
case Byte_ascii.Tilde: { // ~~ -> ~
|
||||
bfr.Add_byte(Byte_ascii.Tilde);
|
||||
return pos + 1;
|
||||
}
|
||||
case Byte_ascii.Curly_bgn: {
|
||||
int num_bgn = pos + 1;
|
||||
int num_end = Bry_finder.Find_fwd_while_num(src, num_bgn, len); // +1 to position after {
|
||||
if ( num_end == Bry_finder.Not_found
|
||||
|| num_end == len
|
||||
|| src[num_end] != Byte_ascii.Curly_end
|
||||
)
|
||||
throw Exc_.new_("invalid gfs; num_end not found", "src", String_.new_u8(src));
|
||||
bfr.Add_byte(Byte_ascii.Dollar);
|
||||
int arg_idx = Bry_.Xto_int_or(src, num_bgn, num_end, -1);
|
||||
if (arg_idx == -1) {
|
||||
throw Exc_.new_("invalid int");
|
||||
}
|
||||
bfr.Add_int_variable(arg_idx + 1);
|
||||
return num_end + 1;
|
||||
}
|
||||
default: {
|
||||
throw Exc_.new_("invalid gfs; next char after tilde must be either tilde or open brace", "src", String_.new_u8(src));
|
||||
}
|
||||
}
|
||||
}
|
||||
public static byte[] Xto_gfs(Bry_bfr bfr, byte[] raw) {
|
||||
int raw_len = raw.length;
|
||||
for (int i = 0; i < raw_len; i++) {
|
||||
byte b = raw[i];
|
||||
switch (b) {
|
||||
case Byte_ascii.Backslash:
|
||||
++i;
|
||||
if (i < raw_len)
|
||||
bfr.Add_byte(raw[i]);
|
||||
else
|
||||
bfr.Add_byte(Byte_ascii.Backslash);
|
||||
break;
|
||||
case Byte_ascii.Tilde:
|
||||
bfr.Add_byte_repeat(Bry_fmtr.char_escape, 2); // escape tilde; EX: ~u -> ~~u; DATE:2013-11-11
|
||||
break;
|
||||
case Byte_ascii.Dollar:
|
||||
int end_pos = Php_text_itm_parser.Find_fwd_non_int(raw, i + 1, raw_len);
|
||||
int int_val = Bry_.Xto_int_or(raw, i + 1, end_pos, -1);
|
||||
bfr.Add_byte(Bry_fmtr.char_escape).Add_byte(Bry_fmtr.char_arg_bgn).Add_int_variable(int_val - 1).Add_byte(Bry_fmtr.char_arg_end);
|
||||
i = end_pos - 1;
|
||||
break;
|
||||
default:
|
||||
bfr.Add_byte(b);
|
||||
break;
|
||||
}
|
||||
}
|
||||
return bfr.Xto_bry_and_clear();
|
||||
}
|
||||
}
|
||||
50
400_xowa/src/gplx/xowa/apps/Xoa_gfs_php_mgr_tst.java
Normal file
50
400_xowa/src/gplx/xowa/apps/Xoa_gfs_php_mgr_tst.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.apps; import gplx.*; import gplx.xowa.*;
|
||||
import org.junit.*;
|
||||
public class Xoa_gfs_php_mgr_tst {
|
||||
@Before public void init() {fxt.Clear();} private Xoa_gfs_php_mgr_fxt fxt = new Xoa_gfs_php_mgr_fxt();
|
||||
@Test public void Xto_gfs() {
|
||||
fxt.Test_Xto_gfs("a\\\\b\\'c\\\"d\\$e" , "a\\b'c\"d$e"); // backslash.escape
|
||||
fxt.Test_Xto_gfs("\\" , "\\"); // backslash.eos; eos, but nothing to escape; render self but dont fail
|
||||
fxt.Test_Xto_gfs("a~b" , "a~~b"); // tilde.escape
|
||||
fxt.Test_Xto_gfs("a$1b" , "a~{0}b"); // dollar
|
||||
}
|
||||
@Test public void Xto_php() {
|
||||
fxt.Test_Xto_php_escape_y("a~{0}b" , "a$1b"); // tilde.arg.one
|
||||
fxt.Test_Xto_php_escape_y("a~{0}b~{1}c~{2}d" , "a$1b$2c$3d"); // tilde.arg.many
|
||||
fxt.Test_Xto_php_escape_y("a~{9}" , "a$10"); // tilde.arg.9 -> 10
|
||||
fxt.Test_Xto_php_escape_y("a~~b" , "a~b"); // tilde.escape
|
||||
fxt.Test_Xto_php_escape_y("a\\b'c\"d$e" , "a\\\\b\\'c\\\"d\\$e"); // backslash.escape_y
|
||||
fxt.Test_Xto_php_escape_n("a\\b'c\"d$e" , "a\\b'c\"d$e"); // backslash.escape_n
|
||||
}
|
||||
}
|
||||
class Xoa_gfs_php_mgr_fxt {
|
||||
private Bry_bfr bfr = Bry_bfr.new_();
|
||||
public void Clear() {}
|
||||
public void Test_Xto_gfs(String raw, String expd) {
|
||||
byte[] actl = Xoa_gfs_php_mgr.Xto_gfs(bfr, Bry_.new_u8(raw));
|
||||
Tfds.Eq(expd, String_.new_u8(actl));
|
||||
}
|
||||
public void Test_Xto_php_escape_y(String raw, String expd) {Test_Xto_php(raw, Bool_.Y, expd);}
|
||||
public void Test_Xto_php_escape_n(String raw, String expd) {Test_Xto_php(raw, Bool_.N, expd);}
|
||||
public void Test_Xto_php(String raw, boolean escape_backslash, String expd) {
|
||||
byte[] actl = Xoa_gfs_php_mgr.Xto_php(bfr, escape_backslash, Bry_.new_u8(raw));
|
||||
Tfds.Eq(expd, String_.new_u8(actl));
|
||||
}
|
||||
}
|
||||
38
400_xowa/src/gplx/xowa/apps/Xoa_shell.java
Normal file
38
400_xowa/src/gplx/xowa/apps/Xoa_shell.java
Normal file
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
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.apps; import gplx.*; import gplx.xowa.*;
|
||||
public class Xoa_shell implements GfoInvkAble {
|
||||
public Xoa_shell(Xoae_app app) {this.app = app;} private Xoae_app app;
|
||||
public boolean Fetch_page_exec_async() {return fetch_page_exec_async;} private boolean fetch_page_exec_async = true;
|
||||
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
|
||||
if (ctx.Match(k, Invk_fetch_page)) return Fetch_page(m);
|
||||
else if (ctx.Match(k, Invk_chars_per_line_max_)) ConsoleAdp._.CharsPerLineMax_set(m.ReadInt("v"));
|
||||
else if (ctx.Match(k, Invk_backspace_by_bytes_)) ConsoleAdp._.Backspace_by_bytes_(m.ReadYn("v"));
|
||||
else return GfoInvkAble_.Rv_unhandled;
|
||||
return this;
|
||||
}
|
||||
private String Fetch_page(GfoMsg m) {
|
||||
String url = m.ReadStr("url");
|
||||
if (String_.Has_at_bgn(url, "//")) url = String_.Replace(url, "//", ""); // NOTE: handle Firefox_addon which sometimes sends urls of the form "//wiki/" when coming from the sidebar; DATE:2015-07-04
|
||||
return String_.new_u8(app.Gui_mgr().Browser_win().App__retrieve_by_url(url, m.ReadStrOr("output_type", "html")));
|
||||
}
|
||||
private static final String Invk_fetch_page = "fetch_page"
|
||||
, Invk_chars_per_line_max_ = "chars_per_line_max_"
|
||||
, Invk_backspace_by_bytes_ = "backspace_by_bytes_"
|
||||
;
|
||||
}
|
||||
30
400_xowa/src/gplx/xowa/apps/Xoa_shell_tst.java
Normal file
30
400_xowa/src/gplx/xowa/apps/Xoa_shell_tst.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.apps; import gplx.*; import gplx.xowa.*;
|
||||
import org.junit.*;
|
||||
public class Xoa_shell_tst {
|
||||
@Test public void Fetch_page() { // PURPOSE.fix: fetch_page failed with nullRef; DATE:2013-04-12
|
||||
Xop_fxt parser_fxt = new Xop_fxt();
|
||||
Xoae_app app = parser_fxt.App(); Xowe_wiki wiki = parser_fxt.Wiki();
|
||||
parser_fxt.Init_page_create("A", "test"); // need to create page in order for html output to gen
|
||||
wiki.Html_mgr().Page_wtr_mgr().Html_capable_(true); // need to set html_capable in order for div_home to load
|
||||
Xoa_gfs_mgr.Msg_parser_init();
|
||||
wiki.Html_mgr().Portal_mgr().Div_home_fmtr().Fmt_("~{<>app.user.msgs.get('mainpage-description');<>}");
|
||||
app.Gfs_mgr().Run_str("app.shell.fetch_page('en.wikipedia.org/wiki/A' 'html');"); // this causes a nullRef error b/c app.user.lang is null
|
||||
}
|
||||
}
|
||||
21
400_xowa/src/gplx/xowa/apps/Xoa_stage_.java
Normal file
21
400_xowa/src/gplx/xowa/apps/Xoa_stage_.java
Normal file
@@ -0,0 +1,21 @@
|
||||
/*
|
||||
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.apps; import gplx.*; import gplx.xowa.*;
|
||||
public class Xoa_stage_ {
|
||||
public static final byte Tid_ctor = 0, Tid_init = 1, Tid_launch = 2;
|
||||
}
|
||||
30
400_xowa/src/gplx/xowa/apps/Xoa_thread_.java
Normal file
30
400_xowa/src/gplx/xowa/apps/Xoa_thread_.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.apps; import gplx.*; import gplx.xowa.*;
|
||||
public class Xoa_thread_ {
|
||||
public static final String
|
||||
Key_page_async = "xowa.page.async"
|
||||
, Key_page_redlink = "xowa.page.redlink"
|
||||
, Key_page_popup = "xowa.page.popup"
|
||||
, Key_http_server_main = "xowa.http_server.main"
|
||||
, Key_bldr_download = "xowa.bldr.download"
|
||||
, Key_special_search_db = "xowa.special.search.db"
|
||||
, Key_special_search_cancel = "xowa.special.search.cancel"
|
||||
, Key_special_suggest = "xowa.special.suggest"
|
||||
;
|
||||
}
|
||||
27
400_xowa/src/gplx/xowa/apps/Xoa_thread_mgr.java
Normal file
27
400_xowa/src/gplx/xowa/apps/Xoa_thread_mgr.java
Normal file
@@ -0,0 +1,27 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.apps; import gplx.*; import gplx.xowa.*;
|
||||
import gplx.core.threads.*;
|
||||
public class Xoa_thread_mgr {
|
||||
public Gfo_thread_pool Page_load_mgr() {return page_load_mgr;} private Gfo_thread_pool page_load_mgr = new Gfo_thread_pool();
|
||||
public Gfo_thread_pool File_load_mgr() {return file_load_mgr;} private Gfo_thread_pool file_load_mgr = new Gfo_thread_pool();
|
||||
public void Usr_dlg_(Gfo_usr_dlg usr_dlg) {
|
||||
page_load_mgr.Usr_dlg_(usr_dlg);
|
||||
file_load_mgr.Usr_dlg_(usr_dlg);
|
||||
}
|
||||
}
|
||||
26
400_xowa/src/gplx/xowa/apps/caches/Wdata_doc_cache.java
Normal file
26
400_xowa/src/gplx/xowa/apps/caches/Wdata_doc_cache.java
Normal file
@@ -0,0 +1,26 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.apps.caches; import gplx.*; import gplx.xowa.*; import gplx.xowa.apps.*;
|
||||
import gplx.xowa.xtns.wdatas.*;
|
||||
public class Wdata_doc_cache {
|
||||
private Hash_adp_bry hash = Hash_adp_bry.cs_();
|
||||
public void Add(byte[] qid, Wdata_doc doc) {hash.Add(qid, doc);}
|
||||
public Wdata_doc Get_or_null(byte[] qid) {return (Wdata_doc)hash.Get_by_bry(qid);}
|
||||
public void Free_mem_all() {this.Clear();}
|
||||
public void Clear() {hash.Clear();}
|
||||
}
|
||||
24
400_xowa/src/gplx/xowa/apps/caches/Xoa_cache_mgr.java
Normal file
24
400_xowa/src/gplx/xowa/apps/caches/Xoa_cache_mgr.java
Normal file
@@ -0,0 +1,24 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.apps.caches; import gplx.*; import gplx.xowa.*; import gplx.xowa.apps.*;
|
||||
public class Xoa_cache_mgr {
|
||||
public Wdata_doc_cache Doc_cache() {return doc_cache;} private Wdata_doc_cache doc_cache = new Wdata_doc_cache();
|
||||
public void Free_mem_all() {
|
||||
doc_cache.Free_mem_all();
|
||||
}
|
||||
}
|
||||
42
400_xowa/src/gplx/xowa/apps/fsys/Xoa_fsys_eval.java
Normal file
42
400_xowa/src/gplx/xowa/apps/fsys/Xoa_fsys_eval.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.apps.fsys; import gplx.*; import gplx.xowa.*; import gplx.xowa.apps.*;
|
||||
import gplx.core.primitives.*; import gplx.xowa.users.*;
|
||||
public class Xoa_fsys_eval implements Bry_fmtr_eval_mgr {
|
||||
private final Xoa_fsys_mgr app_fsys_mgr; private final Xou_fsys_mgr usr_fsys_mgr;
|
||||
public Xoa_fsys_eval(Xoa_fsys_mgr app_fsys_mgr, Xou_fsys_mgr usr_fsys_mgr) {this.app_fsys_mgr = app_fsys_mgr; this.usr_fsys_mgr = usr_fsys_mgr;}
|
||||
public boolean Enabled() {return enabled;} public void Enabled_(boolean v) {enabled = v;} private boolean enabled = true;
|
||||
public byte[] Eval(byte[] cmd) {
|
||||
Object o = hash.Get_by_bry(cmd); if (o == null) return null;
|
||||
byte val = ((Byte_obj_val)o).Val();
|
||||
switch (val) {
|
||||
case Tid_xowa_root_dir: return app_fsys_mgr.Root_dir().RawBry();
|
||||
case Tid_bin_plat_dir: return app_fsys_mgr.Bin_plat_dir().RawBry();
|
||||
case Tid_user_temp_dir: return usr_fsys_mgr.App_temp_dir().RawBry();
|
||||
case Tid_user_cfg_dir: return usr_fsys_mgr.App_data_cfg_dir().RawBry();
|
||||
default: throw Exc_.new_unhandled(val);
|
||||
}
|
||||
}
|
||||
private static final byte Tid_bin_plat_dir = 0, Tid_user_temp_dir = 1, Tid_xowa_root_dir = 2, Tid_user_cfg_dir = 3;
|
||||
private static final Hash_adp_bry hash = Hash_adp_bry.ci_ascii_()
|
||||
.Add_str_byte("bin_plat_dir" , Tid_bin_plat_dir)
|
||||
.Add_str_byte("user_temp_dir" , Tid_user_temp_dir)
|
||||
.Add_str_byte("xowa_root_dir" , Tid_xowa_root_dir)
|
||||
.Add_str_byte("user_cfg_dir" , Tid_user_cfg_dir)
|
||||
;
|
||||
}
|
||||
52
400_xowa/src/gplx/xowa/apps/fsys/Xoa_fsys_mgr.java
Normal file
52
400_xowa/src/gplx/xowa/apps/fsys/Xoa_fsys_mgr.java
Normal file
@@ -0,0 +1,52 @@
|
||||
/*
|
||||
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.apps.fsys; import gplx.*; import gplx.xowa.*; import gplx.xowa.apps.*;
|
||||
public class Xoa_fsys_mgr implements GfoInvkAble {
|
||||
public Xoa_fsys_mgr(String plat_name, Io_url root_dir, Io_url wiki_dir, Io_url file_dir, Io_url css_dir) {
|
||||
this.root_dir = root_dir;
|
||||
this.wiki_dir = wiki_dir;
|
||||
this.file_dir = file_dir;
|
||||
this.css_dir = css_dir;
|
||||
this.bin_plat_dir = root_dir.GenSubDir("bin").GenSubDir(plat_name);
|
||||
this.bin_any_dir = root_dir.GenSubDir("bin").GenSubDir("any");
|
||||
this.bin_xowa_dir = bin_any_dir.GenSubDir("xowa");
|
||||
this.bin_xtns_dir = bin_any_dir.GenSubDir_nest("xowa", "xtns");
|
||||
this.cfg_lang_core_dir = bin_any_dir.GenSubDir_nest("xowa", "cfg", "lang", "core");
|
||||
this.cfg_wiki_core_dir = bin_any_dir.GenSubDir_nest("xowa", "cfg", "wiki", "core");
|
||||
}
|
||||
public Io_url Root_dir() {return root_dir;} private final Io_url root_dir;
|
||||
public Io_url Wiki_dir() {return wiki_dir;} private final Io_url wiki_dir;
|
||||
public Io_url File_dir() {return file_dir;} private final Io_url file_dir;
|
||||
public Io_url Css_dir() {return css_dir;} private final Io_url css_dir;
|
||||
public Io_url Bin_plat_dir() {return bin_plat_dir;} private final Io_url bin_plat_dir;
|
||||
public Io_url Bin_any_dir() {return bin_any_dir;} private final Io_url bin_any_dir;
|
||||
public Io_url Bin_xowa_dir() {return bin_xowa_dir;} private final Io_url bin_xowa_dir;
|
||||
public Io_url Bin_xtns_dir() {return bin_xtns_dir;} private final Io_url bin_xtns_dir;
|
||||
public Io_url Cfg_lang_core_dir() {return cfg_lang_core_dir;} private final Io_url cfg_lang_core_dir;
|
||||
public Io_url Cfg_wiki_core_dir() {return cfg_wiki_core_dir;} private final Io_url cfg_wiki_core_dir;
|
||||
public Io_url Bin_data_os_cfg_fil() {return bin_plat_dir.GenSubFil_nest("xowa", "cfg", Xoa_gfs_mgr.Cfg_os);}
|
||||
public Io_url Wiki_css_dir(String wiki) {return css_dir.GenSubDir_nest(wiki, "html");} // EX: /xowa/temp/simple.wikipedia.org/html/xowa_common.css
|
||||
public Io_url Wiki_file_dir(String wiki) {return file_dir.GenSubDir_nest(wiki);} // EX: /xowa/temp/simple.wikipedia.org/orig/
|
||||
public void Init_by_app(GfoInvkAble app_mgr_invk) {this.app_mgr_invk = app_mgr_invk;} private GfoInvkAble app_mgr_invk; // for gfs and app.launcher
|
||||
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
|
||||
if (ctx.Match(k, Invk_apps)) return app_mgr_invk;
|
||||
else if (ctx.Match(k, Invk_root_dir)) return root_dir;
|
||||
else return GfoInvkAble_.Rv_unhandled;
|
||||
}
|
||||
private static final String Invk_apps = "apps", Invk_root_dir = "root_dir";
|
||||
}
|
||||
128
400_xowa/src/gplx/xowa/apps/progs/Xoa_prog_mgr.java
Normal file
128
400_xowa/src/gplx/xowa/apps/progs/Xoa_prog_mgr.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.apps.progs; import gplx.*; import gplx.xowa.*; import gplx.xowa.apps.*;
|
||||
import gplx.xowa.apps.fsys.*; import gplx.xowa.files.*;
|
||||
public class Xoa_prog_mgr implements GfoInvkAble {
|
||||
public void Init_by_app(Xoa_fsys_eval cmd_eval) {
|
||||
Gfo_usr_dlg usr_dlg = Xoa_app_.Usr_dlg();
|
||||
ProcessAdp.ini_(this, usr_dlg, app_query_img_size , cmd_eval, ProcessAdp.Run_mode_sync_timeout , 10 * 60, "~{<>bin_plat_dir<>}imagemagick\\identify", "-ping -format \"<{%w,%h}>\" \"~{file}\"", "file");
|
||||
ProcessAdp.ini_(this, usr_dlg, app_resize_img , cmd_eval, ProcessAdp.Run_mode_sync_timeout , 10 * 60, "~{<>bin_plat_dir<>}imagemagick\\convert", "\"~{source}\" -coalesce -resize ~{width}x~{height} \"~{target}\"", "source", "target", "width", "height");
|
||||
ProcessAdp.ini_(this, usr_dlg, app_convert_svg_to_png , cmd_eval, ProcessAdp.Run_mode_sync_timeout , 10 * 60, "~{<>bin_plat_dir<>}inkscape\\inkscape", "-z -w ~{width} -f \"~{source}\" -e \"~{target}\"", "source", "target", "width").Thread_kill_name_("inkscape.exe"); // // -z=without-gui; -w=width; -f=file -e=export-png
|
||||
ProcessAdp.ini_(this, usr_dlg, app_convert_tex_to_dvi , cmd_eval, ProcessAdp.Run_mode_sync_timeout , 2 * 60, "~{<>bin_plat_dir<>}miktex\\miktex\\bin\\latex", "-quiet -output-directory=~{temp_dir} -job-name=xowa_temp ~{tex_file}", "tex_file", "temp_dir");
|
||||
ProcessAdp.ini_(this, usr_dlg, app_convert_dvi_to_png , cmd_eval, ProcessAdp.Run_mode_sync_timeout , 2 * 60, "~{<>bin_plat_dir<>}miktex\\miktex\\bin\\dvipng", "~{dvi_file} -o ~{png_file} -q* -T tight -bg Transparent", "dvi_file", "png_file", "temp_dir");
|
||||
ProcessAdp.ini_(this, usr_dlg, app_convert_djvu_to_tiff , cmd_eval, ProcessAdp.Run_mode_sync_timeout , 1 * 60, "~{<>bin_plat_dir<>}djvulibre\\ddjvu", "-format=tiff -page=1 \"~{source}\" \"~{target}\"", "source", "target");
|
||||
ProcessAdp.ini_(this, usr_dlg, app_decompress_bz2 , cmd_eval, ProcessAdp.Run_mode_sync_timeout , 0 , "~{<>bin_plat_dir<>}7-zip\\7za", "x -y \"~{src}\" -o\"~{trg_dir}\"", "src", "trg", "trg_dir"); // x=extract; -y=yes on all queries; -o=output_dir
|
||||
ProcessAdp.ini_(this, usr_dlg, app_decompress_bz2_by_stdout , cmd_eval, ProcessAdp.Run_mode_sync_timeout , 0 , "~{<>bin_plat_dir<>}7-zip\\7za", "x -so \"~{src}\"", "src"); // x=extract; -so=stdout
|
||||
ProcessAdp.ini_(this, usr_dlg, app_decompress_zip , cmd_eval, ProcessAdp.Run_mode_sync_timeout , 0 , "~{<>bin_plat_dir<>}7-zip\\7za", "x -y \"~{src}\" -o\"~{trg_dir}\"", "src", "trg", "trg_dir"); // x=extract; -y=yes on all queries; -o=output_dir
|
||||
ProcessAdp.ini_(this, usr_dlg, app_decompress_gz , cmd_eval, ProcessAdp.Run_mode_sync_timeout , 0 , "~{<>bin_plat_dir<>}7-zip\\7za", "x -y \"~{src}\" -o\"~{trg_dir}\"", "src", "trg", "trg_dir"); // x=extract; -y=yes on all queries; -o=output_dir
|
||||
ProcessAdp.ini_(this, usr_dlg, app_lua , cmd_eval, ProcessAdp.Run_mode_async , 0 , "~{<>bin_plat_dir<>}lua\\lua", "", "");
|
||||
ProcessAdp.ini_(this, usr_dlg, app_lilypond , cmd_eval, ProcessAdp.Run_mode_sync_timeout , 1 * 60, "~{<>bin_plat_dir<>}lilypond\\usr\\bin\\lilypond.exe", "\"-dsafe=#t\" -dbackend=ps --png --header=texidoc -dmidi-extension=midi \"~{file}\"", "file");
|
||||
ProcessAdp.ini_(this, usr_dlg, app_abc2ly , cmd_eval, ProcessAdp.Run_mode_sync_timeout , 1 * 60, "~{<>bin_plat_dir<>}lilypond\\usr\\bin\\python.exe", "abc2ly.py -s \"--output=~{target}\" \"~{source}\"", "source", "target");
|
||||
ProcessAdp.ini_(this, usr_dlg, app_trim_img , cmd_eval, ProcessAdp.Run_mode_sync_timeout , 1 * 60, "~{<>bin_plat_dir<>}imagemagick\\convert", "-trim \"~{source}\" \"~{target}\"", "source", "target");
|
||||
ProcessAdp.ini_(this, usr_dlg, app_convert_midi_to_ogg , cmd_eval, ProcessAdp.Run_mode_sync_timeout , 1 * 60, "~{<>bin_plat_dir<>}timidity\\timidity", "-Ov \"--output-file=~{target}\" \"~{source}\"", "source", "target");
|
||||
ProcessAdp.ini_(this, usr_dlg, app_view_web , cmd_eval, ProcessAdp.Run_mode_async , 0 , "cmd", "/c start \"~{url}\"", "url");
|
||||
ProcessAdp.ini_(this, usr_dlg, app_view_text , cmd_eval, ProcessAdp.Run_mode_async , 0 , "cmd", "/c start \"~{url}\"", "url");
|
||||
int cmds_view_file_by_ext_len = cmds_view_file_by_ext.length;
|
||||
for (int i= 0; i < cmds_view_file_by_ext_len; i++) {
|
||||
ProcessAdp cmd = new ProcessAdp();
|
||||
cmds_view_file_by_ext [i] = cmd;
|
||||
ProcessAdp.ini_(this, usr_dlg, cmd , cmd_eval, ProcessAdp.Run_mode_async , 0 , "cmd", "/c start \"~{file}\"", "file");
|
||||
}
|
||||
}
|
||||
public ProcessAdp App_query_img_size() {return app_query_img_size;} private ProcessAdp app_query_img_size = new ProcessAdp();
|
||||
public ProcessAdp App_resize_img() {return app_resize_img;} private ProcessAdp app_resize_img = new ProcessAdp();
|
||||
public ProcessAdp App_convert_svg_to_png() {return app_convert_svg_to_png;} private ProcessAdp app_convert_svg_to_png = new ProcessAdp();
|
||||
public ProcessAdp App_convert_tex_to_dvi() {return app_convert_tex_to_dvi;} private ProcessAdp app_convert_tex_to_dvi = new ProcessAdp();
|
||||
public ProcessAdp App_convert_dvi_to_png() {return app_convert_dvi_to_png;} private ProcessAdp app_convert_dvi_to_png = new ProcessAdp();
|
||||
public ProcessAdp App_convert_djvu_to_tiff() {return app_convert_djvu_to_tiff;} private ProcessAdp app_convert_djvu_to_tiff = new ProcessAdp();
|
||||
public ProcessAdp App_view_web() {return app_view_web;} private ProcessAdp app_view_web = new ProcessAdp();
|
||||
public ProcessAdp App_view_text() {return app_view_text;} private ProcessAdp app_view_text = new ProcessAdp();
|
||||
public ProcessAdp App_decompress_bz2() {return app_decompress_bz2;} private ProcessAdp app_decompress_bz2 = new ProcessAdp();
|
||||
public ProcessAdp App_decompress_zip() {return app_decompress_zip;} private ProcessAdp app_decompress_zip = new ProcessAdp();
|
||||
public ProcessAdp App_decompress_gz() {return app_decompress_gz;} private ProcessAdp app_decompress_gz = new ProcessAdp();
|
||||
public ProcessAdp App_decompress_bz2_by_stdout() {return app_decompress_bz2_by_stdout;} private ProcessAdp app_decompress_bz2_by_stdout = new ProcessAdp();
|
||||
public ProcessAdp App_lua() {return app_lua;} private ProcessAdp app_lua = new ProcessAdp();
|
||||
public ProcessAdp App_lilypond() {return app_lilypond;} private ProcessAdp app_lilypond = new ProcessAdp();
|
||||
public ProcessAdp App_abc2ly() {return app_abc2ly;} private ProcessAdp app_abc2ly = new ProcessAdp();
|
||||
public ProcessAdp App_trim_img() {return app_trim_img;} private ProcessAdp app_trim_img = new ProcessAdp();
|
||||
public ProcessAdp App_convert_midi_to_ogg() {return app_convert_midi_to_ogg;} private ProcessAdp app_convert_midi_to_ogg = new ProcessAdp();
|
||||
public ProcessAdp App_by_ext(String ext) {return App_by_ext_key(String_.Mid(ext, 1));} // ignore 1st . in ext; EX: ".png" -> "png"
|
||||
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
|
||||
if (ctx.Match(k, Invk_query_img_size)) return app_query_img_size;
|
||||
else if (ctx.Match(k, Invk_resize_img)) return app_resize_img;
|
||||
else if (ctx.Match(k, Invk_convert_svg_to_png)) return app_convert_svg_to_png;
|
||||
else if (ctx.Match(k, Invk_convert_tex_to_dvi)) return app_convert_tex_to_dvi;
|
||||
else if (ctx.Match(k, Invk_convert_dvi_to_png)) return app_convert_dvi_to_png;
|
||||
else if (ctx.Match(k, Invk_convert_djvu_to_tiff)) return app_convert_djvu_to_tiff;
|
||||
else if (ctx.Match(k, Invk_view_web)) return app_view_web;
|
||||
else if (ctx.Match(k, Invk_decompress_bz2)) return app_decompress_bz2;
|
||||
else if (ctx.Match(k, Invk_decompress_zip)) return app_decompress_zip;
|
||||
else if (ctx.Match(k, Invk_decompress_gz)) return app_decompress_gz;
|
||||
else if (ctx.Match(k, Invk_decompress_bz2_by_stdout)) return app_decompress_bz2_by_stdout;
|
||||
else if (ctx.Match(k, Invk_lua)) return app_lua;
|
||||
else if (ctx.Match(k, Invk_lilypond)) return app_lilypond;
|
||||
else if (ctx.Match(k, Invk_abc2ly)) return app_abc2ly;
|
||||
else if (ctx.Match(k, Invk_convert_midi_to_ogg)) return app_convert_midi_to_ogg;
|
||||
else if (ctx.Match(k, Invk_trim_img)) return app_trim_img;
|
||||
else if (ctx.Match(k, Invk_web)) return app_view_web;
|
||||
else if (ctx.Match(k, Invk_text)) return app_view_text;
|
||||
else if (ctx.Match(k, Invk_image)) return Init_by_exts("png", "jpg", "jpeg", "gif", "tif", "tiff", "svg");
|
||||
else if (ctx.Match(k, Invk_media)) return Init_by_exts("mid", "ogg", "oga", "ogv", "webm");
|
||||
else if (ctx.Match(k, Invk_svg)) return Init_by_exts("svg");
|
||||
else if (ctx.Match(k, Invk_pdf)) return Init_by_exts("pdf");
|
||||
else if (ctx.Match(k, Invk_djvu)) return Init_by_exts("djvu");
|
||||
else if (ctx.Match(k, Invk_view_by_ext)) Exec_view_by_ext(m.ReadStr("exts"), m.ReadStr("cmd"), m.ReadStr("args"));
|
||||
else return GfoInvkAble_.Rv_unhandled;
|
||||
return this;
|
||||
}
|
||||
public void Exec_view_web(byte[] url) {
|
||||
url = Bry_.Replace(url, Quote_normal, Quote_escape); // escape quotes; DATE:2013-03-31
|
||||
String url_str = String_.new_u8(url);
|
||||
url_str = ProcessAdp.Escape_ampersands_if_process_is_cmd(Op_sys.Cur().Tid_is_wnt(), app_view_web.Exe_url().Raw(), url_str); // escape ampersands; DATE:2014-05-20
|
||||
app_view_web.Run(url_str);
|
||||
} private static final byte[] Quote_normal = new byte[] {Byte_ascii.Quote}, Quote_escape = new byte[] {Byte_ascii.Quote, Byte_ascii.Quote};
|
||||
private ProcessAdp App_by_ext_key(String ext) {return cmds_view_file_by_ext[Xof_ext_.Get_id_by_ext_(Bry_.new_a7(ext))];}
|
||||
public void Exec_view_by_ext(String exts_raw, String cmd, String args) {
|
||||
String[] exts_ary = String_.Split(exts_raw, '|');
|
||||
int exts_ary_len = exts_ary.length;
|
||||
for (int i = 0; i < exts_ary_len; i++)
|
||||
App_by_ext_key(exts_ary[i]).Cmd_args(cmd, args);
|
||||
} ProcessAdp[] cmds_view_file_by_ext = new ProcessAdp[Xof_ext_.Id__max];
|
||||
private ProcessAdp Init_by_exts(String... exts) {
|
||||
ProcessAdp rv = App_by_ext_key(exts[0]);
|
||||
int len = exts.length;
|
||||
for (int i = 0; i < len; i++) {
|
||||
cmds_view_file_by_ext[Xof_ext_.Get_id_by_ext_(Bry_.new_a7(exts[i]))] = rv;
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
private static final String Invk_query_img_size = "query_img_size", Invk_resize_img = "resize_img", Invk_convert_svg_to_png = "convert_svg_to_png", Invk_convert_tex_to_dvi = "convert_tex_to_dvi", Invk_convert_dvi_to_png = "convert_dvi_to_png"
|
||||
, Invk_convert_djvu_to_tiff = "convert_djvu_to_tiff", Invk_view_web = "view_web"
|
||||
, Invk_decompress_bz2 = "decompress_bz2", Invk_decompress_zip = "decompress_zip", Invk_decompress_gz = "decompress_gz", Invk_decompress_bz2_by_stdout = "decompress_bz2_by_stdout"
|
||||
, Invk_view_by_ext = "view_by_ext"
|
||||
, Invk_lua = "lua", Invk_lilypond = "lilypond", Invk_abc2ly = "abc2ly", Invk_trim_img = "trim_img", Invk_convert_midi_to_ogg = "convert_midi_to_ogg"
|
||||
, Invk_web = "web"
|
||||
, Invk_media = "media"
|
||||
, Invk_image = "image"
|
||||
, Invk_svg = "svg"
|
||||
, Invk_pdf = "pdf"
|
||||
, Invk_djvu = "djvu"
|
||||
, Invk_text = "text"
|
||||
;
|
||||
public static final int Len_dlm_fld = 1, Adj_next_char = 1;
|
||||
}
|
||||
37
400_xowa/src/gplx/xowa/apps/setups/Xoa_setup_mgr.java
Normal file
37
400_xowa/src/gplx/xowa/apps/setups/Xoa_setup_mgr.java
Normal file
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
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.apps.setups; import gplx.*; import gplx.xowa.*; import gplx.xowa.apps.*;
|
||||
import gplx.xowa.apps.versions.*;
|
||||
public class Xoa_setup_mgr {
|
||||
public static void Delete_old_files(Xoae_app app) {
|
||||
String version_previous = app.Api_root().App().Env().Version_previous();
|
||||
Gfo_usr_dlg usr_dlg = app.Usr_dlg();
|
||||
Io_url root_dir = app.Fsys_mgr().Root_dir();
|
||||
Delete_old_dir(usr_dlg, version_previous, "1.8.2.1" , root_dir.GenSubDir_nest("user", "anonymous", "lang"));
|
||||
Delete_old_dir(usr_dlg, version_previous, "1.8.2.1" , root_dir.GenSubDir_nest("user", "anonymous", "wiki", "#cfg"));
|
||||
Delete_old_dir(usr_dlg, version_previous, "1.10.2.1" , root_dir.GenSubDir_nest("bin", "any", "javascript"));
|
||||
Delete_old_dir(usr_dlg, version_previous, "1.10.2.1" , root_dir.GenSubDir_nest("bin", "any", "xowa", "html", "modules"));
|
||||
}
|
||||
@gplx.Internal protected static void Delete_old_dir(Gfo_usr_dlg usr_dlg, String version_prv, String version_del, Io_url dir) {
|
||||
if (Xoa_version_.Compare(version_prv, version_del) != CompareAble_.Less) return;
|
||||
usr_dlg.Log_many("", "", "setup:checking if dir exists: version_prv=~{0} version_del=~{1} dir=~{2}", version_prv, version_del, dir.Raw());
|
||||
if (!Io_mgr.I.ExistsDir(dir)) return;
|
||||
usr_dlg.Log_many("", "", "setup:deleting dir", version_prv, version_del, dir.Raw());
|
||||
Io_mgr.I.DeleteDirDeep(dir);
|
||||
}
|
||||
}
|
||||
36
400_xowa/src/gplx/xowa/apps/setups/Xoa_setup_mgr_tst.java
Normal file
36
400_xowa/src/gplx/xowa/apps/setups/Xoa_setup_mgr_tst.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.apps.setups; import gplx.*; import gplx.xowa.*; import gplx.xowa.apps.*;
|
||||
import org.junit.*;
|
||||
public class Xoa_setup_mgr_tst {
|
||||
@Before public void init() {fxt.Clear();} private Xoa_setup_mgr_fxt fxt = new Xoa_setup_mgr_fxt();
|
||||
@Test public void Compare() {
|
||||
fxt.Test_delete_old_dir("mem/dir/", "1.8.1.1" , "1.8.2.1", Bool_.Y); // version is earlier than checkpoint; delete
|
||||
fxt.Test_delete_old_dir("mem/dir/", "1.8.2.1" , "1.8.2.1", Bool_.N); // version is not earlier than checkpoint; don't delete
|
||||
fxt.Test_delete_old_dir("mem/dir/", "" , "1.8.2.1", Bool_.Y); // version is empty; delete;
|
||||
}
|
||||
}
|
||||
class Xoa_setup_mgr_fxt {
|
||||
public void Clear() {}
|
||||
public void Test_delete_old_dir(String dir_str, String version_prv, String version_del, boolean expd) {
|
||||
Io_url dir = Io_url_.new_fil_(dir_str);
|
||||
Io_mgr.I.CreateDirIfAbsent(dir);
|
||||
Xoa_setup_mgr.Delete_old_dir(Gfo_usr_dlg_.Noop, version_prv, version_del, dir);
|
||||
Tfds.Eq(expd, !Io_mgr.I.ExistsDir(dir), version_prv + "|" + version_del);
|
||||
}
|
||||
}
|
||||
38
400_xowa/src/gplx/xowa/apps/versions/Xoa_version_.java
Normal file
38
400_xowa/src/gplx/xowa/apps/versions/Xoa_version_.java
Normal file
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
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.apps.versions; import gplx.*; import gplx.xowa.*; import gplx.xowa.apps.*;
|
||||
public class Xoa_version_ {
|
||||
public static int Compare(String lhs_str, String rhs_str) {
|
||||
String[] lhs_ary = String_.Split(lhs_str, ".");
|
||||
String[] rhs_ary = String_.Split(rhs_str, ".");
|
||||
return Compare_as_int(lhs_ary, rhs_ary);
|
||||
}
|
||||
private static int Compare_as_int(String[] lhs_ary, String[] rhs_ary) {
|
||||
int lhs_ary_len = lhs_ary.length;
|
||||
int rhs_ary_len = rhs_ary.length;
|
||||
int len_comp = Int_.Compare(lhs_ary_len, rhs_ary_len);
|
||||
if (len_comp != CompareAble_.Same) return len_comp;
|
||||
for (int i = 0; i < lhs_ary_len; ++i) {
|
||||
String lhs_itm = lhs_ary[i];
|
||||
String rhs_itm = rhs_ary[i];
|
||||
int itm_comp = Int_.Compare(Int_.parse_or_(lhs_itm, 0), Int_.parse_or_(rhs_itm, 0));
|
||||
if (itm_comp != CompareAble_.Same) return itm_comp;
|
||||
}
|
||||
return CompareAble_.Same;
|
||||
}
|
||||
}
|
||||
37
400_xowa/src/gplx/xowa/apps/versions/Xoa_version_tst.java
Normal file
37
400_xowa/src/gplx/xowa/apps/versions/Xoa_version_tst.java
Normal file
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
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.apps.versions; import gplx.*; import gplx.xowa.*; import gplx.xowa.apps.*;
|
||||
import org.junit.*;
|
||||
public class Xoa_version_tst {
|
||||
@Before public void init() {fxt.Clear();} private Xoa_version_fxt fxt = new Xoa_version_fxt();
|
||||
@Test public void Compare() {
|
||||
fxt.Test_compare("1.8.1.1", "1.8.2.1" , CompareAble_.Less); // rev:less
|
||||
fxt.Test_compare("1.8.2.1", "1.8.1.1" , CompareAble_.More); // rev:more
|
||||
fxt.Test_compare("1.8.1.1", "1.8.1.1" , CompareAble_.Same); // rev:same
|
||||
fxt.Test_compare("1.7.9.1", "1.8.1.1" , CompareAble_.Less); // min:less
|
||||
fxt.Test_compare("", "1.8.1.1" , CompareAble_.Less); // empty:less
|
||||
fxt.Test_compare("1.8.1.1", "" , CompareAble_.More); // empty:more
|
||||
fxt.Test_compare("", "" , CompareAble_.Same); // empty:more
|
||||
}
|
||||
}
|
||||
class Xoa_version_fxt {
|
||||
public void Clear() {}
|
||||
public void Test_compare(String lhs, String rhs, int expd) {
|
||||
Tfds.Eq(expd, Xoa_version_.Compare(lhs, rhs), lhs + "|" + rhs);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user