mirror of
https://github.com/gnosygnu/xowa.git
synced 2026-03-02 03:49:30 +00:00
v2.2.4.1
This commit is contained in:
@@ -20,6 +20,7 @@ public class Bool_obj_ref {
|
||||
public boolean Val() {return val;} private boolean val;
|
||||
public boolean Val_y() {return val;}
|
||||
public boolean Val_n() {return !val;}
|
||||
public String Val_as_str_yn() {return Yn.Xto_str(val);}
|
||||
public Bool_obj_ref Val_y_() {val = true; return this;}
|
||||
public Bool_obj_ref Val_n_() {val = false; return this;}
|
||||
public Bool_obj_ref Val_(boolean v) {val = v; return this;}
|
||||
|
||||
@@ -23,6 +23,7 @@ public class Int_obj_ref {
|
||||
public int Val_add(int v) {val += v; return val;}
|
||||
public Int_obj_ref Val_zero_() {val = 0; return this;}
|
||||
public Int_obj_ref Val_neg1_() {val = -1; return this;}
|
||||
public String Val_as_str() {return Int_.Xto_str(val);}
|
||||
@Override public String toString() {return Int_.Xto_str(val);}
|
||||
@Override public int hashCode() {return val;}
|
||||
@Override public boolean equals(Object obj) {return val == ((Int_obj_ref)obj).Val();}
|
||||
|
||||
@@ -40,6 +40,7 @@ public class Err_ { //_20110415
|
||||
public static Err find_failed_(String find) {return Err.hdr_("find failed").Add("find", find);}
|
||||
|
||||
public static Err null_(String obj) {return Err.hdr_("null obj").Add("obj", obj);}
|
||||
public static Err deprecated(String s) {return Err.hdr_("deprecated:" + s);}
|
||||
public static Err not_implemented_() {return not_implemented_msg_("method not implemented");}
|
||||
public static Err not_implemented_msg_(String hdr) {return Err.hdr_(hdr);}
|
||||
public static Err type_mismatch_exc_(Exception e, Class<?> t, Object o) {return type_mismatch_(t, o);} // NOTE: e passed to "soak" up variable for IDE
|
||||
|
||||
@@ -131,6 +131,7 @@ public class Bry_bfr {
|
||||
public Bry_bfr Add_byte_quote() {return Add_byte(Byte_ascii.Quote);}
|
||||
public Bry_bfr Add_byte_space() {return Add_byte(Byte_ascii.Space);}
|
||||
public Bry_bfr Add_byte_nl() {return Add_byte(Byte_ascii.NewLine);}
|
||||
public Bry_bfr Add_byte_dot() {return Add_byte(Byte_ascii.Dot);}
|
||||
public Bry_bfr Add_byte(byte val) {
|
||||
int newPos = bfr_len + 1;
|
||||
if (newPos > bfr_max) Resize(bfr_len * 2);
|
||||
|
||||
@@ -329,6 +329,16 @@ public class String_ implements GfoInvkAble {
|
||||
}
|
||||
|
||||
public static String[] Ary(String... ary) {return ary;}
|
||||
public static String[] Ary_wo_null(String... ary) {
|
||||
ListAdp list = ListAdp_.new_();
|
||||
int len = ary.length;
|
||||
for (int i = 0; i < len; ++i) {
|
||||
String itm = ary[i];
|
||||
if (itm == null) continue;
|
||||
list.Add(itm);
|
||||
}
|
||||
return list.XtoStrAry();
|
||||
}
|
||||
public static String AryXtoStr(String... ary) {
|
||||
String_bldr sb = String_bldr_.new_();
|
||||
for (String s : ary)
|
||||
|
||||
@@ -30,6 +30,7 @@ public class Hash_adp_bry extends gplx.lists.HashAdp_base implements HashAdp {
|
||||
public Object Get_by_bry(byte[] src) {return super.Fetch_base(key_ref.Init(src));}
|
||||
public Object Get_by_mid(byte[] src, int bgn, int end) {return super.Fetch_base(key_ref.Init(src, bgn, end));}
|
||||
public Hash_adp_bry Add_bry_byte(byte[] key, byte val) {this.Add_base(key, Byte_obj_val.new_(val)); return this;}
|
||||
public Hash_adp_bry Add_bry_int(byte[] key, int val) {this.Add_base(key, Int_obj_val.new_(val)); return this;}
|
||||
public Hash_adp_bry Add_bry_bry(byte[] key) {this.Add_base(key, key); return this;}
|
||||
public Hash_adp_bry Add_str_byte(String key, byte val) {this.Add_base(Bry_.new_utf8_(key), Byte_obj_val.new_(val)); return this;}
|
||||
public Hash_adp_bry Add_str_obj(String key, Object val) {this.Add_base(Bry_.new_utf8_(key), val); return this;}
|
||||
|
||||
@@ -22,9 +22,9 @@ public class OrderedHash_ {
|
||||
public static OrderedHash new_bry_() {return new OrderedHash_bry();}
|
||||
}
|
||||
class OrderedHash_bry extends OrderedHash_base {
|
||||
private Bry_obj_ref lkp = Bry_obj_ref.null_();
|
||||
private final Bry_obj_ref tmp_ref = Bry_obj_ref.null_();
|
||||
@Override protected void Add_base(Object key, Object val) {super.Add_base(Bry_obj_ref.new_((byte[])key), val);}
|
||||
@Override protected void Del_base(Object key) {super.Del_base(lkp.Val_((byte[])key));}
|
||||
@Override protected boolean Has_base(Object key) {return super.Has_base(lkp.Val_((byte[])key));}
|
||||
@Override protected Object Fetch_base(Object key) {return super.Fetch_base(lkp.Val_((byte[])key));}
|
||||
@Override protected void Del_base(Object key) {synchronized (tmp_ref) {super.Del_base(tmp_ref.Val_((byte[])key));}}
|
||||
@Override protected boolean Has_base(Object key) {synchronized (tmp_ref) {return super.Has_base(tmp_ref.Val_((byte[])key));}}
|
||||
@Override protected Object Fetch_base(Object key) {synchronized (tmp_ref) {return super.Fetch_base(tmp_ref.Val_((byte[])key));}}
|
||||
}
|
||||
|
||||
@@ -94,6 +94,13 @@ public class Io_mgr { // exists primarily to gather all cmds under gplx namespac
|
||||
catch (Exception e) {throw Err_.new_("failed to load file").Add("url", url.Xto_api()).Add("e", Err_.Message_lang(e));}
|
||||
finally {stream.Rls();}
|
||||
}
|
||||
public byte[] LoadFilBry_loose(Io_url url) {return Bry_.new_utf8_(LoadFilStr_loose(url));}
|
||||
public String LoadFilStr_loose(Io_url url) {
|
||||
String rv = LoadFilStr_args(url).BomUtf8Convert_(Bool_.Y).MissingIgnored_(Bool_.Y).Exec();
|
||||
if (String_.Has(rv, "\r\n"))
|
||||
rv = String_.Replace(rv, "\r\n", "\n");
|
||||
return rv;
|
||||
}
|
||||
public void AppendFilBfr(Io_url url, Bry_bfr bfr) {AppendFilByt(url, bfr.Bfr(), 0, bfr.Len()); bfr.ClearAndReset();}
|
||||
public void AppendFilByt(Io_url url, byte[] val) {AppendFilByt(url, val, 0, val.length);}
|
||||
public void AppendFilByt(Io_url url, byte[] val, int len) {AppendFilByt(url, val, 0, len);}
|
||||
|
||||
@@ -155,7 +155,7 @@ public class IoEngine_system extends IoEngine_base {
|
||||
}
|
||||
IoItmFil QueryMkr_fil(IoUrlInfo urlInfo, File apiFil) {
|
||||
Io_url filUrl = Io_url_.new_inf_(apiFil.getPath(), urlInfo); // NOTE: may throw PathTooLongException when url is > 248 (exception messages states 260)
|
||||
long fil_len = apiFil.exists() ? apiFil.length() : IoItmFil.Size_Invalid; // NOTE: if file doesn't exist, set len to -1; needed for "boolean Exists() {return size != Size_Invalid;}"; DATE:2014-06-21
|
||||
long fil_len = apiFil.exists() ? apiFil.length() : IoItmFil.Size_invalid; // NOTE: if file doesn't exist, set len to -1; needed for "boolean Exists() {return size != Size_Invalid;}"; DATE:2014-06-21
|
||||
IoItmFil rv = IoItmFil_.new_(filUrl, fil_len, DateAdp_.MinValue, DateAdp_.unixtime_lcl_ms_(apiFil.lastModified()));
|
||||
rv.ReadOnly_(!apiFil.canWrite());
|
||||
return rv;
|
||||
@@ -404,7 +404,7 @@ public class IoEngine_system extends IoEngine_base {
|
||||
src_conn = (HttpURLConnection)src_url.openConnection();
|
||||
// src_conn.setReadTimeout(5000); // do not set; if file does not exist, will wait 5 seconds before timing out; want to fail immediately
|
||||
String user_agent = xrg.User_agent(); if (user_agent != null) src_conn.setRequestProperty("User-Agent", user_agent);
|
||||
long content_length = Long_.parse_or_(src_conn.getHeaderField("Content-Length"), IoItmFil.Size_Invalid_int);
|
||||
long content_length = Long_.parse_or_(src_conn.getHeaderField("Content-Length"), IoItmFil.Size_invalid_int);
|
||||
xrg.Src_content_length_(content_length);
|
||||
if (xrg.Src_last_modified_query()) // NOTE: only files will have last modified (api calls will not); if no last_modified, then src_conn will throw get nullRef; avoid nullRef
|
||||
xrg.Src_last_modified_(DateAdp_.unixtime_lcl_ms_(src_conn.getLastModified()));
|
||||
@@ -535,7 +535,7 @@ class Io_stream_rdr_http implements Io_stream_rdr {
|
||||
} private IoEngine_xrg_downloadFil xrg;
|
||||
public byte Tid() {return Io_stream_.Tid_file;}
|
||||
public Io_url Url() {return url;} public Io_stream_rdr Url_(Io_url v) {url = v; return this;} private Io_url url;
|
||||
public long Len() {return len;} public Io_stream_rdr Len_(long v) {len = v; return this;} private long len = IoItmFil.Size_Invalid; // NOTE: must default size to -1; DATE:2014-06-21
|
||||
public long Len() {return len;} public Io_stream_rdr Len_(long v) {len = v; return this;} private long len = IoItmFil.Size_invalid; // NOTE: must default size to -1; DATE:2014-06-21
|
||||
private String src_str; private HttpURLConnection src_conn; private java.io.BufferedInputStream src_stream;
|
||||
private Io_download_fmt xfer_fmt; private Gfo_usr_dlg prog_dlg;
|
||||
private boolean read_done = true, read_failed = false;
|
||||
@@ -555,7 +555,7 @@ class Io_stream_rdr_http implements Io_stream_rdr {
|
||||
if (user_agent != null)
|
||||
src_conn.setRequestProperty("User-Agent", user_agent);
|
||||
// src_conn.setReadTimeout(5000); // do not set; if file does not exist, will wait 5 seconds before timing out; want to fail immediately
|
||||
long content_length = Long_.parse_or_(src_conn.getHeaderField("Content-Length"), IoItmFil.Size_Invalid_int);
|
||||
long content_length = Long_.parse_or_(src_conn.getHeaderField("Content-Length"), IoItmFil.Size_invalid_int);
|
||||
xrg.Src_content_length_(content_length);
|
||||
this.len = content_length;
|
||||
if (xrg.Src_last_modified_query()) // NOTE: only files will have last modified (api calls will not); if no last_modified, then src_conn will throw get nullRef; avoid nullRef
|
||||
|
||||
@@ -18,7 +18,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
package gplx.ios; import gplx.*;
|
||||
public class IoItmFil extends IoItm_base {
|
||||
@Override public int TypeId() {return IoItmFil.Type_Fil;} @Override public boolean Type_dir() {return false;} @Override public boolean Type_fil() {return true;} public static final int Type_Fil = 2;
|
||||
public boolean Exists() {return size != Size_Invalid;} // NOTE: questionable logic, but preserved for historical reasons; requires that length be set to -1 if !.exists
|
||||
public boolean Exists() {return size != Size_invalid;} // NOTE: questionable logic, but preserved for historical reasons; requires that length be set to -1 if !.exists
|
||||
public DateAdp ModifiedTime() {return modifiedTime;}
|
||||
public IoItmFil ModifiedTime_(DateAdp val) {modifiedTime = val; return this;} DateAdp modifiedTime;
|
||||
public IoItmFil ModifiedTime_(String val) {return ModifiedTime_(DateAdp_.parse_gplx(val));}
|
||||
@@ -37,6 +37,6 @@ public class IoItmFil extends IoItm_base {
|
||||
else return super.Invk(ctx, ikey, k, m);
|
||||
}
|
||||
@gplx.Internal protected IoItmFil() {}
|
||||
public static final long Size_Invalid = -1;
|
||||
public static final int Size_Invalid_int = -1;
|
||||
public static final long Size_invalid = -1;
|
||||
public static final int Size_invalid_int = -1;
|
||||
}
|
||||
|
||||
30
100_core/src_200_io/gplx/ios/Io_url_obj_ref.java
Normal file
30
100_core/src_200_io/gplx/ios/Io_url_obj_ref.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.ios; import gplx.*;
|
||||
public class Io_url_obj_ref {
|
||||
public Io_url Val() {return val;} public Io_url_obj_ref Val_(Io_url v) {val = v; return this;} private Io_url val;
|
||||
public String Val_as_str() {return val.Raw();}
|
||||
@Override public String toString() {return val.Raw();}
|
||||
@Override public int hashCode() {return val.hashCode();}
|
||||
@Override public boolean equals(Object obj) {return String_.Eq(val.Raw(), ((Io_url_obj_ref)obj).val.Raw());}
|
||||
public static Io_url_obj_ref new_(Io_url val) {
|
||||
Io_url_obj_ref rv = new Io_url_obj_ref();
|
||||
rv.val = val;
|
||||
return rv;
|
||||
} Io_url_obj_ref() {}
|
||||
}
|
||||
@@ -93,14 +93,14 @@ public class ProcessAdp implements GfoInvkAble, RlsAble {
|
||||
}
|
||||
static final String Invk_cmd = "cmd", Invk_cmd_ = "cmd_", Invk_args = "args", Invk_args_ = "args_", Invk_cmd_args_ = "cmd_args_", Invk_enabled = "enabled", Invk_enabled_ = "enabled_", Invk_mode_ = "mode_", Invk_timeout_ = "timeout_", Invk_tmp_dir_ = "tmp_dir_", Invk_owner = "owner";
|
||||
Bry_fmtr_eval_mgr cmd_url_eval;
|
||||
public static ProcessAdp ini_(GfoInvkAble owner, Gfo_usr_dlg gui_wtr, ProcessAdp process, Bry_fmtr_eval_mgr cmd_url_eval, byte run_mode, int timeout, String cmd_url_fmt, String args_fmt, String... args_keys) {
|
||||
public static ProcessAdp ini_(GfoInvkAble owner, Gfo_usr_dlg usr_dlg, ProcessAdp process, Bry_fmtr_eval_mgr cmd_url_eval, byte run_mode, int timeout, String cmd_url_fmt, String args_fmt, String... args_keys) {
|
||||
process.Run_mode_(run_mode).Thread_timeout_seconds_(timeout);
|
||||
process.cmd_url_eval = cmd_url_eval;
|
||||
Io_url cmd_url = Bry_fmtr_eval_mgr_.Eval_url(cmd_url_eval, Bry_.new_utf8_(cmd_url_fmt));
|
||||
process.Exe_url_(cmd_url).Tmp_dir_(cmd_url.OwnerDir());
|
||||
process.Args_fmtr().Fmt_(args_fmt).Keys_(args_keys);
|
||||
process.owner = owner;
|
||||
process.Prog_dlg_(gui_wtr);
|
||||
process.Prog_dlg_(usr_dlg);
|
||||
return process; // return process for chaining
|
||||
}
|
||||
public static String Escape_ampersands_if_process_is_cmd(boolean os_is_wnt, String exe_url, String exe_args) {
|
||||
|
||||
Reference in New Issue
Block a user