mirror of https://github.com/gnosygnu/xowa
parent
e3b393650d
commit
3fc2e0741f
@ -1,55 +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.core.ios.streams; import gplx.*; import gplx.core.*; import gplx.core.ios.*;
|
||||
public class Io_stream_ { // SERIALIZED
|
||||
public static final byte Tid_null = 0, Tid_raw = 1, Tid_zip = 2, Tid_gzip = 3, Tid_bzip2 = 4;
|
||||
public static final String Ext_zip = ".zip", Ext_gz = ".gz", Ext_bz2 = ".bz2";
|
||||
|
||||
public static String Obsolete_to_str(byte v) {
|
||||
switch (v) {
|
||||
case Io_stream_.Tid_raw : return ".xdat";
|
||||
case Io_stream_.Tid_zip : return ".zip";
|
||||
case Io_stream_.Tid_gzip : return ".gz";
|
||||
case Io_stream_.Tid_bzip2 : return ".bz2";
|
||||
default : throw Err_.new_unhandled(v);
|
||||
}
|
||||
}
|
||||
public static byte Obsolete_to_tid(String v) {
|
||||
if (String_.Eq(v, ".xdat")) return Io_stream_.Tid_raw;
|
||||
else if (String_.Eq(v, ".zip")) return Io_stream_.Tid_zip;
|
||||
else if (String_.Eq(v, ".gz")) return Io_stream_.Tid_gzip;
|
||||
else if (String_.Eq(v, ".bz2")) return Io_stream_.Tid_bzip2;
|
||||
else throw Err_.new_unhandled(v);
|
||||
}
|
||||
public static String To_str(byte v) {
|
||||
switch (v) {
|
||||
case Io_stream_.Tid_raw : return "raw";
|
||||
case Io_stream_.Tid_zip : return "zip";
|
||||
case Io_stream_.Tid_gzip : return "gzip";
|
||||
case Io_stream_.Tid_bzip2 : return "bzip2";
|
||||
default : throw Err_.new_unhandled(v);
|
||||
}
|
||||
}
|
||||
public static byte To_tid(String v) {
|
||||
if (String_.Eq(v, "raw")) return Io_stream_.Tid_raw;
|
||||
else if (String_.Eq(v, "zip")) return Io_stream_.Tid_zip;
|
||||
else if (String_.Eq(v, "gzip")) return Io_stream_.Tid_gzip;
|
||||
else if (String_.Eq(v, "bzip2")) return Io_stream_.Tid_bzip2;
|
||||
else throw Err_.new_unhandled(v);
|
||||
}
|
||||
}
|
@ -0,0 +1,58 @@
|
||||
/*
|
||||
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.core.ios.streams; import gplx.*; import gplx.core.*; import gplx.core.ios.*;
|
||||
public class Io_stream_tid_ {
|
||||
public static final byte Tid__null = 0, Tid__raw = 1, Tid__zip = 2, Tid__gzip = 3, Tid__bzip2 = 4, Tid__xz = 5; // SERIALIZED:xo.text_db;xo.html_db
|
||||
public static final String Ext__zip = ".zip", Ext__gz = ".gz", Ext__bz2 = ".bz2", Ext__xz = ".xz";
|
||||
private static final String Key__raw = "raw", Key__zip = "zip", Key__gzip = "gzip", Key__bzip2 = "bzip2", Key__xz = "xz";
|
||||
|
||||
public static String To_key(byte v) {
|
||||
switch (v) {
|
||||
case Io_stream_tid_.Tid__raw : return Key__raw;
|
||||
case Io_stream_tid_.Tid__zip : return Key__zip;
|
||||
case Io_stream_tid_.Tid__gzip : return Key__gzip;
|
||||
case Io_stream_tid_.Tid__bzip2 : return Key__bzip2;
|
||||
case Io_stream_tid_.Tid__xz : return Key__xz;
|
||||
default : throw Err_.new_unhandled_default(v);
|
||||
}
|
||||
}
|
||||
public static byte To_tid(String v) {
|
||||
if (String_.Eq(v, Key__raw)) return Io_stream_tid_.Tid__raw;
|
||||
else if (String_.Eq(v, Key__zip)) return Io_stream_tid_.Tid__zip;
|
||||
else if (String_.Eq(v, Key__gzip)) return Io_stream_tid_.Tid__gzip;
|
||||
else if (String_.Eq(v, Key__bzip2)) return Io_stream_tid_.Tid__bzip2;
|
||||
else if (String_.Eq(v, Key__xz)) return Io_stream_tid_.Tid__xz;
|
||||
else throw Err_.new_unhandled_default(v);
|
||||
}
|
||||
public static String Obsolete_to_str(byte v) {
|
||||
switch (v) {
|
||||
case Io_stream_tid_.Tid__raw : return ".xdat";
|
||||
case Io_stream_tid_.Tid__zip : return ".zip";
|
||||
case Io_stream_tid_.Tid__gzip : return ".gz";
|
||||
case Io_stream_tid_.Tid__bzip2 : return ".bz2";
|
||||
default : throw Err_.new_unhandled_default(v);
|
||||
}
|
||||
}
|
||||
public static byte Obsolete_to_tid(String v) {
|
||||
if (String_.Eq(v, ".xdat")) return Io_stream_tid_.Tid__raw;
|
||||
else if (String_.Eq(v, ".zip")) return Io_stream_tid_.Tid__zip;
|
||||
else if (String_.Eq(v, ".gz")) return Io_stream_tid_.Tid__gzip;
|
||||
else if (String_.Eq(v, ".bz2")) return Io_stream_tid_.Tid__bzip2;
|
||||
else throw Err_.new_unhandled_default(v);
|
||||
}
|
||||
}
|
@ -0,0 +1,41 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.core.ios.streams.rdrs; import gplx.*; import gplx.core.*; import gplx.core.ios.*; import gplx.core.ios.streams.*;
|
||||
public class Io_stream_rdr__adp implements Io_stream_rdr {
|
||||
private java.io.InputStream strm;
|
||||
public Io_stream_rdr__adp(java.io.InputStream strm) {this.strm = strm;}
|
||||
public Object Under() {return strm;}
|
||||
public byte Tid() {return Io_stream_tid_.Tid__raw;}
|
||||
public boolean Exists() {return len > 0;}
|
||||
public Io_url Url() {return url;} public Io_stream_rdr Url_(Io_url v) {this.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 = Io_mgr.Len_null;
|
||||
public void Open_mem(byte[] v) {}
|
||||
public Io_stream_rdr Open() {return this;}
|
||||
public int Read(byte[] bry, int bgn, int len) {
|
||||
try {return strm.read(bry, bgn, len);}
|
||||
catch (Exception e) {throw Err_.new_exc(e, "io", "read failed", "bgn", bgn, "len", len);}
|
||||
}
|
||||
public long Skip(long len) {
|
||||
try {return strm.skip(len);}
|
||||
catch (Exception e) {throw Err_.new_exc(e, "io", "skip failed", "len", len);}
|
||||
}
|
||||
public void Rls() {
|
||||
try {strm.close();}
|
||||
catch (Exception e) {throw Err_.new_exc(e, "io", "close failed", "url", url.Xto_api());}
|
||||
}
|
||||
}
|
@ -0,0 +1,48 @@
|
||||
/*
|
||||
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.core.ios.streams.rdrs; import gplx.*; import gplx.core.*; import gplx.core.ios.*; import gplx.core.ios.streams.*;
|
||||
public abstract class Io_stream_rdr__base implements Io_stream_rdr {
|
||||
public abstract byte Tid();
|
||||
public Io_url Url() {return url;} protected Io_url url;
|
||||
public long Len() {return len;} private long len = Io_mgr.Len_null;
|
||||
public boolean Exists() {return this.Len() > 0;}
|
||||
public Io_stream_rdr Url_(Io_url v) {this.url = v; return this;}
|
||||
public Io_stream_rdr Len_(long v) {len = v; return this;}
|
||||
public Object Under() {return stream;} public Io_stream_rdr Under_(java.io.InputStream v) {this.stream = v; return this;} protected java.io.InputStream stream;
|
||||
public void Open_mem(byte[] v) {
|
||||
stream = Wrap_stream(new java.io.ByteArrayInputStream(v));
|
||||
}
|
||||
public Io_stream_rdr Open() {
|
||||
try {stream = Wrap_stream(new java.io.FileInputStream(url.Xto_api()));}
|
||||
catch (Exception e) {throw Err_.new_exc(e, "io", "open failed", "url", url.Xto_api());}
|
||||
return this;
|
||||
}
|
||||
public int Read(byte[] bry, int bgn, int len) {
|
||||
try {return stream.read(bry, bgn, len);}
|
||||
catch (Exception e) {throw Err_.new_exc(e, "io", "read failed", "bgn", bgn, "len", len);}
|
||||
}
|
||||
public long Skip(long len) {
|
||||
try {return stream.skip(len);}
|
||||
catch (Exception e) {throw Err_.new_exc(e, "io", "skip failed", "len", len);}
|
||||
}
|
||||
public void Rls() {
|
||||
try {stream.close();}
|
||||
catch (Exception e) {throw Err_.new_exc(e, "io", "close failed", "url", url.Xto_api());}
|
||||
}
|
||||
public abstract java.io.InputStream Wrap_stream(java.io.InputStream stream);
|
||||
}
|
@ -0,0 +1,29 @@
|
||||
/*
|
||||
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.core.ios.streams.rdrs; import gplx.*; import gplx.core.*; import gplx.core.ios.*; import gplx.core.ios.streams.*;
|
||||
public class Io_stream_rdr__bzip2 extends Io_stream_rdr__base {
|
||||
@Override public byte Tid() {return Io_stream_tid_.Tid__bzip2;}
|
||||
@Override public int Read(byte[] bry, int bgn, int len) {
|
||||
return Io_stream_rdr_.Read_by_parts(stream, Read_len, bry, bgn, len);
|
||||
}
|
||||
@Override public java.io.InputStream Wrap_stream(java.io.InputStream stream) {
|
||||
try {return new org.apache.commons.compress.compressors.bzip2.BZip2CompressorInputStream(stream, true);}
|
||||
catch (Exception exc) {throw Err_.new_wo_type("failed to open bzip2 stream");}
|
||||
}
|
||||
private static final int Read_len = Io_mgr.Len_mb * 128;
|
||||
}
|
@ -0,0 +1,44 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.core.ios.streams.rdrs; import gplx.*; import gplx.core.*; import gplx.core.ios.*; import gplx.core.ios.streams.*;
|
||||
public class Io_stream_rdr__gzip extends Io_stream_rdr__base {
|
||||
@Override public byte Tid() {return Io_stream_tid_.Tid__gzip;}
|
||||
@Override public int Read(byte[] bry, int bgn, int len) {
|
||||
synchronized (this) {
|
||||
try {
|
||||
int total_read = 0;
|
||||
while (true) { // NOTE: the gz stream reads partially; (request 100; only get back 10); keep reading until entire bfr is full or -1
|
||||
int read = stream.read(bry, bgn, len);
|
||||
if (read == Io_stream_rdr_.Read_done) break;
|
||||
total_read += read;
|
||||
if (total_read >= len) break; // entire bfr full; stop
|
||||
bgn += read; // increase bgn by amount read
|
||||
len -= read; // decrease len by amount read
|
||||
}
|
||||
return total_read == 0 ? Io_stream_rdr_.Read_done : total_read; // gzip seems to allow 0 bytes read (bz2 and zip return -1 instead); normalize return to -1;
|
||||
}
|
||||
catch (Exception e) {
|
||||
throw Err_.new_exc(e, "io", "read failed", "bgn", bgn, "len", len);
|
||||
}
|
||||
}
|
||||
}
|
||||
@Override public java.io.InputStream Wrap_stream(java.io.InputStream stream) {
|
||||
try {return new java.util.zip.GZIPInputStream(stream);}
|
||||
catch (Exception exc) {throw Err_.new_wo_type("failed to open gz stream");}
|
||||
}
|
||||
}
|
@ -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.core.ios.streams.rdrs; import gplx.*; import gplx.core.*; import gplx.core.ios.*; import gplx.core.ios.streams.*;
|
||||
public class Io_stream_rdr__noop implements Io_stream_rdr {
|
||||
public Object Under() {return null;}
|
||||
public byte Tid() {return Io_stream_tid_.Tid__null;}
|
||||
public boolean Exists() {return false;}
|
||||
public Io_url Url() {return Io_url_.Empty;} public Io_stream_rdr Url_(Io_url v) {return this;}
|
||||
public long Len() {return Io_mgr.Len_null;} public Io_stream_rdr Len_(long v) {return this;}
|
||||
public void Open_mem(byte[] v) {}
|
||||
public Io_stream_rdr Open() {return this;}
|
||||
public int Read(byte[] bry, int bgn, int len) {return Io_stream_rdr_.Read_done;}
|
||||
public long Skip(long len) {return Io_stream_rdr_.Read_done;}
|
||||
public void Rls() {}
|
||||
}
|
@ -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.core.ios.streams.rdrs; import gplx.*; import gplx.core.*; import gplx.core.ios.*; import gplx.core.ios.streams.*;
|
||||
public class Io_stream_rdr__raw extends Io_stream_rdr__base {
|
||||
public byte Tid() {return Io_stream_tid_.Tid__raw;}
|
||||
public Io_stream_rdr Open() {
|
||||
Io_url url = this.Url();
|
||||
try {
|
||||
if (!Io_mgr.Instance.Exists(url))
|
||||
stream = Wrap_stream(new java.io.ByteArrayInputStream(Bry_.Empty));
|
||||
else {
|
||||
if (url.Info().EngineKey() == IoEngine_.MemKey)
|
||||
stream = Wrap_stream(new java.io.ByteArrayInputStream(Io_mgr.Instance.LoadFilBry(url.Xto_api())));
|
||||
else
|
||||
stream = Wrap_stream(new java.io.FileInputStream(url.Xto_api()));
|
||||
}
|
||||
}
|
||||
catch (Exception e) {throw Err_.new_exc(e, "io", "open failed", "url", url.Xto_api());}
|
||||
return this;
|
||||
}
|
||||
@Override public java.io.InputStream Wrap_stream(java.io.InputStream stream) {return stream;}
|
||||
}
|
@ -0,0 +1,25 @@
|
||||
/*
|
||||
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.core.ios.streams.rdrs; import gplx.*; import gplx.core.*; import gplx.core.ios.*; import gplx.core.ios.streams.*;
|
||||
public class Io_stream_rdr__xz extends Io_stream_rdr__base {
|
||||
@Override public byte Tid() {return Io_stream_tid_.Tid__xz;}
|
||||
@Override public java.io.InputStream Wrap_stream(java.io.InputStream stream) {
|
||||
try {return new org.tukaani.xz.XZInputStream(stream);}
|
||||
catch (Exception exc) {throw Err_.new_wo_type("failed to open xz stream");}
|
||||
}
|
||||
}
|
@ -0,0 +1,54 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.core.ios.streams.rdrs; import gplx.*; import gplx.core.*; import gplx.core.ios.*; import gplx.core.ios.streams.*;
|
||||
public class Io_stream_rdr__zip extends Io_stream_rdr__base {
|
||||
@Override public byte Tid() {return Io_stream_tid_.Tid__gzip;}
|
||||
public Object Under() {return zip_stream;} private java.util.zip.ZipInputStream zip_stream;
|
||||
public void Src_bfr_(Bry_bfr v) {this.src_bfr = v;} Bry_bfr src_bfr;
|
||||
public void Open_mem(byte[] v) {
|
||||
this.zip_stream = (java.util.zip.ZipInputStream)Wrap_stream(new java.io.ByteArrayInputStream(v));
|
||||
}
|
||||
public Io_stream_rdr Open() {
|
||||
try {this.zip_stream = (java.util.zip.ZipInputStream)Wrap_stream(new java.io.FileInputStream(url.Xto_api()));}
|
||||
catch (Exception e) {throw Err_.new_exc(e, "io", "open failed", "url", url.Xto_api());}
|
||||
return this;
|
||||
}
|
||||
public int Read(byte[] bry, int bgn, int len) {
|
||||
try {
|
||||
while (true){
|
||||
int read = zip_stream.read(bry, bgn, len);
|
||||
if (read == Io_stream_rdr_.Read_done) {
|
||||
if (zip_stream.getNextEntry() == null)
|
||||
return Io_stream_rdr_.Read_done;
|
||||
}
|
||||
else
|
||||
return read;
|
||||
}
|
||||
}
|
||||
catch (Exception e) {throw Err_.new_exc(e, "io", "read failed", "bgn", bgn, "len", len);}
|
||||
}
|
||||
public long Skip(long len) {
|
||||
try {return zip_stream.skip(len);}
|
||||
catch (Exception e) {throw Err_.new_exc(e, "io", "skip failed", "len", len);}
|
||||
}
|
||||
public void Rls() {
|
||||
try {zip_stream.close();}
|
||||
catch (Exception e) {throw Err_.new_exc(e, "io", "close failed", "url", url.Xto_api());}
|
||||
}
|
||||
@Override public java.io.InputStream Wrap_stream(java.io.InputStream input_stream) {return new java.util.zip.ZipInputStream(input_stream);}
|
||||
}
|
@ -0,0 +1,60 @@
|
||||
/*
|
||||
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.core.ios.streams.wtrs; import gplx.*; import gplx.core.*; import gplx.core.ios.*; import gplx.core.ios.streams.*;
|
||||
public abstract class Io_stream_wtr__base implements Io_stream_wtr {
|
||||
public abstract byte Tid();
|
||||
public Io_url Url() {return url;} private Io_url url;
|
||||
public Io_stream_wtr Url_(Io_url v) {url = v; return this;}
|
||||
public void Trg_bfr_(Bry_bfr v) {this.trg_bfr = v;} private Bry_bfr trg_bfr;
|
||||
public byte[] To_ary_and_clear() {return trg_bfr.To_bry_and_clear();}
|
||||
|
||||
private java.io.OutputStream zip_stream;
|
||||
private java.io.ByteArrayOutputStream mem_stream;
|
||||
@Virtual public Io_stream_wtr Open() {
|
||||
java.io.OutputStream bry_stream = null;
|
||||
if (trg_bfr == null) {
|
||||
if (!Io_mgr.Instance.ExistsFil(url)) Io_mgr.Instance.SaveFilStr(url, "");
|
||||
try {bry_stream = new java.io.FileOutputStream(url.Raw());}
|
||||
catch (Exception e) {throw Err_.new_exc(e, "io", "open failed", "url", url.Raw());}
|
||||
}
|
||||
else {
|
||||
mem_stream = new java.io.ByteArrayOutputStream();
|
||||
bry_stream = mem_stream;
|
||||
}
|
||||
zip_stream = Wrap_stream(bry_stream);
|
||||
return this;
|
||||
}
|
||||
public void Write(byte[] bry, int bgn, int len) {
|
||||
try {zip_stream.write(bry, bgn, len);}
|
||||
catch (Exception e) {Err_.new_exc(e, "io", "write failed", "bgn", bgn, "len", len);}
|
||||
}
|
||||
public void Flush() {
|
||||
if (trg_bfr != null) {
|
||||
try {zip_stream.close();} catch (Exception e) {throw Err_.new_exc(e, "io", "flush failed");} // must close zip_stream to flush all bytes
|
||||
trg_bfr.Add(mem_stream.toByteArray());
|
||||
}
|
||||
}
|
||||
public void Rls() {
|
||||
try {
|
||||
if (zip_stream != null) zip_stream.close();
|
||||
if (mem_stream != null) mem_stream.close();
|
||||
}
|
||||
catch (Exception e) {throw Err_.new_exc(e, "io", "close failed", "url", url.Raw());}
|
||||
}
|
||||
@Virtual protected java.io.OutputStream Wrap_stream(java.io.OutputStream stream) {throw Err_.new_unimplemented();}
|
||||
}
|
@ -0,0 +1,25 @@
|
||||
/*
|
||||
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.core.ios.streams.wtrs; import gplx.*; import gplx.core.*; import gplx.core.ios.*; import gplx.core.ios.streams.*;
|
||||
public class Io_stream_wtr__bzip2 extends Io_stream_wtr__base {
|
||||
@Override public byte Tid() {return Io_stream_tid_.Tid__bzip2;}
|
||||
@Override public java.io.OutputStream Wrap_stream(java.io.OutputStream stream) {
|
||||
try {return new org.apache.commons.compress.compressors.bzip2.BZip2CompressorOutputStream(stream);}
|
||||
catch (Exception e) {throw Err_.new_exc(e, "io", "failed to open bzip2 stream");}
|
||||
}
|
||||
}
|
@ -0,0 +1,25 @@
|
||||
/*
|
||||
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.core.ios.streams.wtrs; import gplx.*; import gplx.core.*; import gplx.core.ios.*; import gplx.core.ios.streams.*;
|
||||
public class Io_stream_wtr__gzip extends Io_stream_wtr__base {
|
||||
@Override public byte Tid() {return Io_stream_tid_.Tid__gzip;}
|
||||
@Override public java.io.OutputStream Wrap_stream(java.io.OutputStream stream) {
|
||||
try {return new java.util.zip.GZIPOutputStream(stream);}
|
||||
catch (Exception e) {throw Err_.new_exc(e, "io", "failed to open gz stream");}
|
||||
}
|
||||
}
|
@ -0,0 +1,55 @@
|
||||
/*
|
||||
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.core.ios.streams.wtrs; import gplx.*; import gplx.core.*; import gplx.core.ios.*; import gplx.core.ios.streams.*;
|
||||
public class Io_stream_wtr__raw implements Io_stream_wtr {
|
||||
public byte Tid() {return Io_stream_tid_.Tid__raw;}
|
||||
public Io_url Url() {return url;} public Io_stream_wtr Url_(Io_url v) {url = v; return this;} private Io_url url;
|
||||
public void Trg_bfr_(Bry_bfr v) {trg_bfr = v;} private Bry_bfr trg_bfr;
|
||||
|
||||
private IoStream bry_stream;
|
||||
@Override public Io_stream_wtr Open() {
|
||||
try {
|
||||
if (trg_bfr == null)
|
||||
bry_stream = Io_mgr.Instance.OpenStreamWrite(url);
|
||||
}
|
||||
catch (Exception e) {throw Err_.new_exc(e, "io", "open failed", "url", url.Raw());}
|
||||
return this;
|
||||
}
|
||||
public void Write(byte[] bry, int bgn, int len) {
|
||||
if (trg_bfr == null) {
|
||||
try {bry_stream.Write(bry, bgn, len);}
|
||||
catch (Exception e) {throw Err_.new_exc(e, "io", "write failed", "url", url.Raw(), "bgn", bgn, "len", len);}
|
||||
}
|
||||
else
|
||||
trg_bfr.Add_mid(bry, bgn, bgn + len);
|
||||
}
|
||||
public byte[] To_ary_and_clear() {
|
||||
return trg_bfr == null ? Io_mgr.Instance.LoadFilBry(url) : trg_bfr.To_bry_and_clear();
|
||||
}
|
||||
public void Flush() {
|
||||
if (trg_bfr == null)
|
||||
bry_stream.Flush();
|
||||
}
|
||||
public void Rls() {
|
||||
try {
|
||||
if (trg_bfr == null)
|
||||
bry_stream.Rls();
|
||||
}
|
||||
catch (Exception e) {throw Err_.new_exc(e, "io", "close failed", "url", url.Raw());}
|
||||
}
|
||||
}
|
@ -0,0 +1,25 @@
|
||||
/*
|
||||
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.core.ios.streams.wtrs; import gplx.*; import gplx.core.*; import gplx.core.ios.*; import gplx.core.ios.streams.*;
|
||||
public class Io_stream_wtr__xz extends Io_stream_wtr__base {
|
||||
@Override public byte Tid() {return Io_stream_tid_.Tid__xz;}
|
||||
@Override public java.io.OutputStream Wrap_stream(java.io.OutputStream stream) {
|
||||
try {return new org.tukaani.xz.XZOutputStream(stream, new org.tukaani.xz.LZMA2Options(org.tukaani.xz.LZMA2Options.PRESET_DEFAULT));}
|
||||
catch (Exception e) {throw Err_.new_exc(e, "io", "failed to open xz stream");}
|
||||
}
|
||||
}
|
@ -0,0 +1,68 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.core.ios.streams.wtrs; import gplx.*; import gplx.core.*; import gplx.core.ios.*; import gplx.core.ios.streams.*;
|
||||
public class Io_stream_wtr__zip extends Io_stream_wtr__base {
|
||||
@Override public byte Tid() {return Io_stream_tid_.Tid__zip;}
|
||||
private java.util.zip.ZipOutputStream zip_stream;
|
||||
public Io_url Url() {return url;} public Io_stream_wtr Url_(Io_url v) {url = v; trg_bfr = null; return this;} private Io_url url = Io_url_.Empty;
|
||||
public void Trg_bfr_(Bry_bfr v) {trg_bfr = v;} private Bry_bfr trg_bfr; private java.io.ByteArrayOutputStream mem_stream;
|
||||
// rely on zip_stream to close bry_stream
|
||||
@Override public Io_stream_wtr Open() {
|
||||
java.io.OutputStream bry_stream;
|
||||
if (trg_bfr == null) {
|
||||
if (!Io_mgr.Instance.ExistsFil(url)) Io_mgr.Instance.SaveFilStr(url, ""); // create file if it doesn't exist
|
||||
try {bry_stream = new java.io.FileOutputStream(url.Xto_api());}
|
||||
catch (Exception e) {throw Err_.new_exc(e, "io", "open failed", "url", url.Raw());}
|
||||
}
|
||||
else {
|
||||
mem_stream = new java.io.ByteArrayOutputStream();
|
||||
bry_stream = mem_stream;
|
||||
}
|
||||
zip_stream = new java.util.zip.ZipOutputStream(bry_stream);
|
||||
java.util.zip.ZipEntry entry = new java.util.zip.ZipEntry("file");
|
||||
try {zip_stream.putNextEntry(entry);}
|
||||
catch (Exception e) {throw Err_.new_exc(e, "io", "open failed", "url", url.Raw());}
|
||||
return this;
|
||||
}
|
||||
public void Write(byte[] bry, int bgn, int len) {
|
||||
try {zip_stream.write(bry, bgn, len);}
|
||||
catch (Exception e) {throw Err_.new_exc(e, "io", "write failed", "url", url.Raw(), "bgn", bgn, "len", len);}
|
||||
}
|
||||
public void Flush() {// fixed as of DATE:2014-04-15
|
||||
try {
|
||||
zip_stream.closeEntry();
|
||||
zip_stream.close();
|
||||
if (trg_bfr != null)
|
||||
trg_bfr.Add(mem_stream.toByteArray());
|
||||
zip_stream.flush();
|
||||
}
|
||||
catch (Exception e) {throw Err_.new_exc(e, "io", "flush failed", "url", url.Raw());}
|
||||
}
|
||||
public void Rls() {
|
||||
try {
|
||||
if (zip_stream != null) zip_stream.close();
|
||||
if (mem_stream != null) mem_stream.close();
|
||||
}
|
||||
catch (Exception e) {throw Err_.new_exc(e, "io", "close failed", "url", url.Raw());}
|
||||
}
|
||||
public byte[] To_ary_and_clear() {
|
||||
byte[] rv = trg_bfr.To_bry_and_clear();
|
||||
this.Rls();
|
||||
return rv;
|
||||
}
|
||||
}
|
@ -0,0 +1,53 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.dbs; import gplx.*;
|
||||
public class Db_sql_ {
|
||||
public static String Make_by_fmt(String[] lines, Object... args) {
|
||||
Bry_bfr bfr = Bry_bfr_.New();
|
||||
int len = lines.length;
|
||||
for (int i = 0; i < len; ++i) {
|
||||
if (i != 0) bfr.Add_byte_nl();
|
||||
bfr.Add_str_u8(lines[i]);
|
||||
}
|
||||
String fmt = bfr.To_str_and_clear();
|
||||
return String_.Format(fmt, args);
|
||||
}
|
||||
public static byte[] Escape_arg(byte[] raw) {
|
||||
int len = raw.length;
|
||||
Bry_bfr bfr = null;
|
||||
boolean dirty = false;
|
||||
|
||||
for (int i = 0; i < len; ++i) {
|
||||
byte b = raw[i];
|
||||
if (b == Byte_ascii.Apos) {
|
||||
if (bfr == null) {
|
||||
dirty = true;
|
||||
bfr = Bry_bfr_.New();
|
||||
bfr.Add_mid(raw, 0, i);
|
||||
}
|
||||
bfr.Add_byte_apos().Add_byte_apos();
|
||||
}
|
||||
else {
|
||||
if (dirty) {
|
||||
bfr.Add_byte(b);
|
||||
}
|
||||
}
|
||||
}
|
||||
return dirty ? bfr.To_bry_and_clear() : raw;
|
||||
}
|
||||
}
|
@ -0,0 +1,22 @@
|
||||
/*
|
||||
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.core.intls.ucas; import gplx.*; import gplx.core.*; import gplx.core.intls.*;
|
||||
public interface Uca_collator {
|
||||
void Init(String locale, boolean numeric_ordering);
|
||||
byte[] Get_sortkey(String s);
|
||||
}
|
@ -0,0 +1,25 @@
|
||||
/*
|
||||
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.core.intls.ucas; import gplx.*; import gplx.core.*; import gplx.core.intls.*;
|
||||
public class Uca_collator_ {
|
||||
public static Uca_collator New(String locale, boolean numeric_ordering) {
|
||||
Uca_collator rv = new Uca_collator__icu__4_8();
|
||||
rv.Init(locale, numeric_ordering);
|
||||
return rv;
|
||||
}
|
||||
}
|
@ -0,0 +1,49 @@
|
||||
/*
|
||||
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.core.intls.ucas; import gplx.*; import gplx.core.*; import gplx.core.intls.*;
|
||||
import java.util.Locale;
|
||||
import com.ibm.icu.text.CollationKey;
|
||||
import com.ibm.icu.text.Collator;
|
||||
import com.ibm.icu.text.RuleBasedCollator;
|
||||
class Uca_collator__icu__4_8 implements Uca_collator {
|
||||
private Collator collator;
|
||||
public void Init(String locale, boolean numeric_ordering) {
|
||||
try {
|
||||
this.collator = Collator.getInstance(Locale.forLanguageTag(locale));
|
||||
if (numeric_ordering) {
|
||||
RuleBasedCollator rbc = (RuleBasedCollator)collator;
|
||||
rbc.setNumericCollation(true);
|
||||
}
|
||||
} catch (Exception e) {throw Err_.new_wo_type("collator init failed", "err", Err_.Message_lang(e));}
|
||||
}
|
||||
public byte[] Get_sortkey(String s) {
|
||||
CollationKey key = collator.getCollationKey(s);
|
||||
byte[] src = key.toByteArray();
|
||||
int src_len = src.length;
|
||||
byte[] rv = src;
|
||||
|
||||
// remove last byte if it is 0 (which it often is)
|
||||
if (src_len > 0 && src[src_len - 1] == 0) {
|
||||
int rv_len = src_len - 1;
|
||||
rv = new byte[rv_len];
|
||||
for (int i = 0; i < rv_len; ++i)
|
||||
rv[i] = src[i];
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
}
|
@ -0,0 +1,51 @@
|
||||
/*
|
||||
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.core.intls.ucas; import gplx.*; import gplx.core.*; import gplx.core.intls.*;
|
||||
public class Uca_ltr_extractor {
|
||||
private final boolean numeric;
|
||||
private final byte[] numeric_heading;
|
||||
private final Hash_adp_bry numeric_hash;
|
||||
public Uca_ltr_extractor(boolean numeric) {
|
||||
this.numeric = numeric;
|
||||
if (numeric) {
|
||||
numeric_heading = Bry_.new_a7("0-9");
|
||||
|
||||
// create hash of "0", "1", "2", ...
|
||||
numeric_hash = Hash_adp_bry.cs();
|
||||
for (int i = 0; i < 10; ++i) {
|
||||
byte[] digit_bry = Bry_.new_by_int(Byte_ascii.Num_0 + i);
|
||||
numeric_hash.Add(digit_bry, digit_bry);
|
||||
}
|
||||
}
|
||||
else {
|
||||
numeric_heading = null;
|
||||
numeric_hash = null;
|
||||
}
|
||||
}
|
||||
public byte[] Get_1st_ltr(byte[] bry) {
|
||||
// NOTE: this is simplified and only does numeric logic; MW code loads up all ICU chars via first-letters-root.ser, adds custom chars, sorts them, and then does a binary search to find it; REF:IcuCollation.php!getFirstLetter
|
||||
int bry_len = bry.length;
|
||||
if (bry_len == 0) return Bry_.Empty;
|
||||
byte[] rv = gplx.core.intls.Utf8_.Get_char_at_pos_as_bry(bry, 0);
|
||||
if (numeric) {
|
||||
if (numeric_hash.Has(rv))
|
||||
rv = numeric_heading;
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
}
|
@ -0,0 +1,31 @@
|
||||
/*
|
||||
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.addons.bldrs.app_cfgs.wm_server_cfgs; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.bldrs.*; import gplx.xowa.addons.bldrs.app_cfgs.*;
|
||||
import gplx.xowa.bldrs.*; import gplx.xowa.bldrs.wkrs.*;
|
||||
public class Xowm_server_cfg_cmd extends Xob_cmd__base {
|
||||
public Xowm_server_cfg_cmd(Xob_bldr bldr, Xowe_wiki wiki) {super(bldr, wiki);}
|
||||
@Override public void Cmd_run() {
|
||||
// wiki.Init_assert();
|
||||
// mgr.Exec(wiki);
|
||||
}
|
||||
|
||||
public static final String BLDR_CMD_KEY = "cfg.wikis.wm_server_cfg";
|
||||
@Override public String Cmd_key() {return BLDR_CMD_KEY;}
|
||||
public static final Xob_cmd Prototype = new Xowm_server_cfg_cmd(null, null);
|
||||
@Override public Xob_cmd Cmd_clone(Xob_bldr bldr, Xowe_wiki wiki) {return new Xowm_server_cfg_cmd(bldr, wiki);}
|
||||
}
|
@ -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.addons.bldrs.app_cfgs.wm_server_cfgs; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.bldrs.*; import gplx.xowa.addons.bldrs.app_cfgs.*;
|
||||
import gplx.xowa.bldrs.*; import gplx.xowa.bldrs.wkrs.*;
|
||||
public class Xowm_server_cfg_mgr {
|
||||
public void Exec() {
|
||||
byte[] src = Load_or_download();
|
||||
Parse_cat_collation(src);
|
||||
}
|
||||
private byte[] Load_or_download() {
|
||||
// Io_mgr.Instance.DownloadFil_args("", Io_url_.NullPtr).Exec_as_bry("https://noc.wikimedia.org/conf/InitialiseSettings.php.txt");
|
||||
return null;
|
||||
}
|
||||
private void Parse_cat_collation(byte[] src) {
|
||||
int bgn_pos = Bry_find_.Find_fwd(src, Bry_.new_a7("wgCategoryCollation"));
|
||||
if (bgn_pos == Bry_find_.Not_found) throw Err_.new_wo_type("could not find wgCategoryCollation bgn");
|
||||
int end_pos = Bry_find_.Find_fwd(src, Bry_.new_a7("],"));
|
||||
if (end_pos == Bry_find_.Not_found) throw Err_.new_wo_type("could not find wgCategoryCollation end");
|
||||
Tfds.Write(src, bgn_pos, end_pos);
|
||||
}
|
||||
}
|
@ -0,0 +1,32 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.addons.bldrs.centrals.dbs.datas; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.bldrs.*; import gplx.xowa.addons.bldrs.centrals.*; import gplx.xowa.addons.bldrs.centrals.dbs.*;
|
||||
public class Xobc_task_regy_itm {
|
||||
public Xobc_task_regy_itm(int id, int seqn, byte[] key, byte[] name, int step_count) {
|
||||
this.id = id;
|
||||
this.seqn = seqn;
|
||||
this.key = key;
|
||||
this.name = name;
|
||||
this.step_count = step_count;
|
||||
}
|
||||
public int Id() {return id;} private final int id;
|
||||
public int Seqn() {return seqn;} private final int seqn;
|
||||
public byte[] Key() {return key;} private final byte[] key;
|
||||
public byte[] Name() {return name;} private final byte[] name;
|
||||
public int Step_count() {return step_count;} private final int step_count;
|
||||
}
|
@ -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.addons.bldrs.files.cksums; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.bldrs.*; import gplx.xowa.addons.bldrs.files.*;
|
||||
import gplx.xowa.bldrs.*; import gplx.xowa.bldrs.wkrs.*;
|
||||
public class Xocksum_calc_cmd extends Xob_cmd__base {
|
||||
public Xocksum_calc_cmd(Xob_bldr bldr, Xowe_wiki wiki) {super(bldr, wiki);}
|
||||
@Override public void Cmd_run() {
|
||||
wiki.Init_assert();
|
||||
new Xocksum_calc_mgr().Exec(wiki);
|
||||
}
|
||||
|
||||
@Override public String Cmd_key() {return BLDR_CMD_KEY;} private static final String BLDR_CMD_KEY = "fsdb.cksums.calc";
|
||||
public static final Xob_cmd Prototype = new Xocksum_calc_cmd(null, null);
|
||||
@Override public Xob_cmd Cmd_clone(Xob_bldr bldr, Xowe_wiki wiki) {return new Xocksum_calc_cmd(bldr, wiki);}
|
||||
}
|
@ -0,0 +1,79 @@
|
||||
/*
|
||||
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.addons.bldrs.files.cksums; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.bldrs.*; import gplx.xowa.addons.bldrs.files.*;
|
||||
import gplx.core.ios.streams.*; import gplx.core.security.*;
|
||||
import gplx.dbs.*; import gplx.xowa.addons.bldrs.files.cksums.dbs.*;
|
||||
import gplx.xowa.files.*; import gplx.fsdb.*; import gplx.fsdb.data.*;
|
||||
public class Xocksum_calc_mgr {
|
||||
public void Exec(Xowe_wiki wiki) {
|
||||
// get conn variables
|
||||
Xocksum_cksum_db db = Xocksum_cksum_db.Get(wiki);
|
||||
Db_conn conn = db.Conn();
|
||||
Xocksum_cksum_tbl tbl = db.Tbl__cksum();
|
||||
conn.Meta_tbl_assert(tbl);
|
||||
|
||||
// insert missing items
|
||||
tbl.Insert_missing();
|
||||
tbl.Create_idx();
|
||||
|
||||
// get updates
|
||||
int count = 0;
|
||||
Hash_algo md5_algo = Hash_algo_.New__md5();
|
||||
List_adp updates = List_adp_.New();
|
||||
String cur_date = Datetime_now.Get().XtoStr_gplx();
|
||||
Db_stmt select_stmt = tbl.Select_samples_stmt(10000);
|
||||
while (true) {
|
||||
// get cksum_rows
|
||||
Xocksum_cksum_row[] rows = tbl.Select_samples(select_stmt);
|
||||
|
||||
// loop cksum_rows and (a) get bin_data; (b) if md5 diff, then add to updates
|
||||
int len = rows.length; if (len == 0) break;
|
||||
for (int i = 0; i < len; ++i) {
|
||||
Xocksum_cksum_row row = rows[i];
|
||||
byte[] bin_bry = Get_bin(wiki, row);
|
||||
if (bin_bry == null) {
|
||||
Gfo_usr_dlg_.Instance.Prog_many("", "", "null; fil_id=~{0} thm_id=~{1}", row.Fil_id(), row.Thm_id());
|
||||
bin_bry = Bry_.Empty;
|
||||
}
|
||||
row.Bin_size_(bin_bry.length);
|
||||
byte[] md5 = md5_algo.Hash_bry_as_bry(bin_bry);
|
||||
if (!Bry_.Eq(md5, row.Cksum_val())) {
|
||||
row.Cksum_val_(md5);
|
||||
updates.Add(row);
|
||||
}
|
||||
}
|
||||
|
||||
// run updates
|
||||
conn.Txn_bgn("cksum_update");
|
||||
len = updates.Len();
|
||||
for (int i = 0; i < len; ++i) {
|
||||
Xocksum_cksum_row row = (Xocksum_cksum_row)updates.Get_at(i);
|
||||
tbl.Update(row.Fil_id(), row.Thm_id(), row.Bin_db_id(), row.Bin_size(), row.Cksum_tid(), 0, row.Cksum_val(), cur_date);
|
||||
if (++count % 2000 == 0) Gfo_usr_dlg_.Instance.Prog_many("", "", "updating; rows=~{0}", count);
|
||||
}
|
||||
updates.Clear();
|
||||
conn.Txn_end();
|
||||
}
|
||||
select_stmt.Rls();
|
||||
}
|
||||
private byte[] Get_bin(Xowe_wiki wiki, Xocksum_cksum_row row) {
|
||||
int bin_id = row.Thm_id() == -1 ? row.Fil_id() : row.Thm_id();
|
||||
Fsd_bin_itm bin_itm = wiki.File__mnt_mgr().Mnts__get_main().Bin_mgr().Dbs__get_at(row.Bin_db_id()).Select_as_itm(bin_id);
|
||||
return bin_itm.Bin_data();
|
||||
}
|
||||
}
|
@ -0,0 +1,31 @@
|
||||
/*
|
||||
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.addons.bldrs.files.cksums.dbs; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.bldrs.*; import gplx.xowa.addons.bldrs.files.*; import gplx.xowa.addons.bldrs.files.cksums.*;
|
||||
import gplx.dbs.*; import gplx.fsdb.meta.*;
|
||||
public class Xocksum_cksum_db {
|
||||
public Xocksum_cksum_db(Db_conn conn) {
|
||||
this.conn = conn;
|
||||
this.tbl__cksum = new Xocksum_cksum_tbl(conn);
|
||||
}
|
||||
public Db_conn Conn() {return conn;} private final Db_conn conn;
|
||||
public Xocksum_cksum_tbl Tbl__cksum() {return tbl__cksum;} private final Xocksum_cksum_tbl tbl__cksum;
|
||||
|
||||
public static Xocksum_cksum_db Get(Xowe_wiki wiki) {
|
||||
return new Xocksum_cksum_db(wiki.File__fsdb_core().File__abc_file__at(Fsm_mnt_mgr.Mnt_idx_main).Conn());
|
||||
}
|
||||
}
|
@ -0,0 +1,41 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.addons.bldrs.files.cksums.dbs; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.bldrs.*; import gplx.xowa.addons.bldrs.files.*; import gplx.xowa.addons.bldrs.files.cksums.*;
|
||||
public class Xocksum_cksum_row {
|
||||
public Xocksum_cksum_row(int fil_id, int thm_id, int bin_db_id, long bin_size, byte cksum_tid, int cksum_count, byte[] cksum_val, String cksum_date) {
|
||||
this.fil_id = fil_id;
|
||||
this.thm_id = thm_id;
|
||||
this.bin_db_id = bin_db_id;
|
||||
this.bin_size = bin_size;
|
||||
this.cksum_tid = cksum_tid;
|
||||
this.cksum_count = cksum_count;
|
||||
this.cksum_val = cksum_val;
|
||||
this.cksum_date = cksum_date;
|
||||
}
|
||||
public int Fil_id() {return fil_id;} private final int fil_id;
|
||||
public int Thm_id() {return thm_id;} private final int thm_id;
|
||||
public int Bin_db_id() {return bin_db_id;} private final int bin_db_id;
|
||||
public long Bin_size() {return bin_size;} private long bin_size;
|
||||
public byte Cksum_tid() {return cksum_tid;} private final byte cksum_tid;
|
||||
public int Cksum_count() {return cksum_count;} private final int cksum_count;
|
||||
public byte[] Cksum_val() {return cksum_val;} private byte[] cksum_val;
|
||||
public String Cksum_date() {return cksum_date;} private final String cksum_date;
|
||||
|
||||
public void Bin_size_(long v) {this.bin_size = v;}
|
||||
public void Cksum_val_(byte[] v) {this.cksum_val = v;}
|
||||
}
|
@ -0,0 +1,107 @@
|
||||
/*
|
||||
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.addons.bldrs.files.cksums.dbs; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.bldrs.*; import gplx.xowa.addons.bldrs.files.*; import gplx.xowa.addons.bldrs.files.cksums.*;
|
||||
import gplx.dbs.*; import gplx.dbs.qrys.*; import gplx.xowa.addons.wikis.ctgs.*;
|
||||
public class Xocksum_cksum_tbl implements Db_tbl {
|
||||
private final Dbmeta_fld_list flds = new Dbmeta_fld_list();
|
||||
private final String fld__fil_id, fld__thm_id, fld__bin_db_id, fld__bin_len, fld__cksum_tid, fld__cksum_count, fld__cksum_val, fld__cksum_date;
|
||||
private Db_stmt stmt__update;
|
||||
public Xocksum_cksum_tbl(Db_conn conn) {
|
||||
this.conn = conn;
|
||||
this.tbl_name = "fsdb_cksum";
|
||||
this.fld__fil_id = flds.Add_int("fil_id");
|
||||
this.fld__thm_id = flds.Add_int("thm_id");
|
||||
this.fld__bin_db_id = flds.Add_int("bin_db_id");
|
||||
this.fld__bin_len = flds.Add_long("bin_size");
|
||||
this.fld__cksum_tid = flds.Add_byte("cksum_tid");
|
||||
this.fld__cksum_count = flds.Add_int("cksum_count");
|
||||
this.fld__cksum_val = flds.Add_str("cksum_val", 255);
|
||||
this.fld__cksum_date = flds.Add_str("cksum_date", 16);
|
||||
conn.Rls_reg(this);
|
||||
}
|
||||
public Db_conn Conn() {return conn;} private final Db_conn conn;
|
||||
public String Tbl_name() {return tbl_name;} private final String tbl_name;
|
||||
public void Create_tbl() {conn.Meta_tbl_create(Dbmeta_tbl_itm.New(tbl_name, flds));}
|
||||
public void Create_idx() {
|
||||
conn.Meta_idx_create(Dbmeta_idx_itm.new_normal_by_tbl(tbl_name, "fil_id__thm_id", fld__fil_id, fld__thm_id));
|
||||
conn.Meta_idx_create(Dbmeta_idx_itm.new_normal_by_tbl(tbl_name, fld__cksum_val, fld__cksum_val));
|
||||
}
|
||||
public void Insert_missing() {
|
||||
// insert from fsdb_fil
|
||||
conn.Exec_sql(Db_sql_.Make_by_fmt(String_.Ary
|
||||
( "INSERT INTO fsdb_cksum (fil_id, thm_id, bin_db_id, bin_size, cksum_tid, cksum_count, cksum_val, cksum_date)"
|
||||
, "SELECT f.fil_id, -1, f.fil_bin_db_id, f.fil_size, {0}, 0, '', ''"
|
||||
, "FROM fsdb_fil f"
|
||||
, " LEFT JOIN fsdb_cksum c ON c.fil_id = f.fil_id AND c.thm_id = -1"
|
||||
, "WHERE c.fil_id IS NULL"
|
||||
, "AND f.fil_bin_db_id != -1"
|
||||
), Cksum_tid__md5));
|
||||
|
||||
// insert from fsdb_fil
|
||||
conn.Exec_sql(Db_sql_.Make_by_fmt(String_.Ary
|
||||
( "INSERT INTO fsdb_cksum (fil_id, thm_id, bin_db_id, bin_size, cksum_tid, cksum_count, cksum_val, cksum_date)"
|
||||
, "SELECT t.thm_owner_id, t.thm_id, t.thm_bin_db_id, t.thm_size, {0}, 0, '', ''"
|
||||
, "FROM fsdb_thm t"
|
||||
, " LEFT JOIN fsdb_cksum c ON c.fil_id = t.thm_owner_id AND c.thm_id = t.thm_id"
|
||||
, "WHERE c.fil_id IS NULL"
|
||||
), Cksum_tid__md5));
|
||||
}
|
||||
public Db_stmt Select_samples_stmt(int count) {
|
||||
return conn.Stmt_sql(Db_sql_.Make_by_fmt(String_.Ary
|
||||
( "SELECT *"
|
||||
, "FROM fsdb_cksum"
|
||||
, "WHERE cksum_val = ''"
|
||||
// , "ORDER BY cksum_count, cksum_date"
|
||||
, "LIMIT {0}"
|
||||
), count));
|
||||
}
|
||||
public Xocksum_cksum_row[] Select_samples(Db_stmt stmt) {
|
||||
List_adp rv = List_adp_.New();
|
||||
|
||||
Db_rdr rdr = stmt.Exec_select__rls_manual();
|
||||
try {
|
||||
while (rdr.Move_next()) {
|
||||
rv.Add(new Xocksum_cksum_row
|
||||
( rdr.Read_int("fil_id")
|
||||
, rdr.Read_int("thm_id")
|
||||
, rdr.Read_int("bin_db_id")
|
||||
, rdr.Read_long("bin_size")
|
||||
, rdr.Read_byte("cksum_tid")
|
||||
, rdr.Read_int("cksum_count")
|
||||
, rdr.Read_bry_by_str("cksum_val")
|
||||
, rdr.Read_str("cksum_date")
|
||||
));
|
||||
}
|
||||
} finally {rdr.Rls();}
|
||||
|
||||
return (Xocksum_cksum_row[])rv.To_ary_and_clear(Xocksum_cksum_row.class);
|
||||
}
|
||||
public void Update(int fil_id, int thm_id, int bin_db_id, long bin_size, byte cksum_tid, int cksum_count, byte[] cksum_val, String cksum_date) {
|
||||
if (stmt__update == null) stmt__update = conn.Stmt_update_exclude(tbl_name, flds, fld__fil_id, fld__thm_id);
|
||||
stmt__update.Clear()
|
||||
.Val_int(fld__bin_db_id, bin_db_id).Val_long(fld__bin_len, bin_size)
|
||||
.Val_byte(fld__cksum_tid, cksum_tid).Val_int(fld__cksum_count, cksum_count)
|
||||
.Val_bry_as_str(fld__cksum_val, cksum_val).Val_str(fld__cksum_date, cksum_date)
|
||||
.Crt_int(fld__fil_id, fil_id).Crt_int(fld__thm_id, thm_id)
|
||||
.Exec_update();
|
||||
}
|
||||
public void Rls() {
|
||||
this.stmt__update = Db_stmt_.Rls(stmt__update);
|
||||
}
|
||||
public static final byte Cksum_tid__md5 = 1;
|
||||
}
|
@ -0,0 +1,59 @@
|
||||
/*
|
||||
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.addons.htmls.includes; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.htmls.*;
|
||||
import java.io.FileReader;
|
||||
|
||||
import javax.script.Invocable;
|
||||
import javax.script.ScriptEngine;
|
||||
import javax.script.ScriptEngineManager;
|
||||
class Script_engine__java implements Script_engine {
|
||||
private final ScriptEngine engine;
|
||||
private final Invocable invk;
|
||||
public Script_engine__java() {
|
||||
ScriptEngineManager manager = new ScriptEngineManager();
|
||||
this.engine = manager.getEngineByName("JavaScript");
|
||||
this.invk = (Invocable)engine;
|
||||
}
|
||||
public void Load_script(Io_url url) {
|
||||
try {
|
||||
engine.eval(new FileReader(url.Xto_api()));
|
||||
// return engine.eval(script);
|
||||
} catch (Exception e) {
|
||||
System.out.println(e);
|
||||
}
|
||||
}
|
||||
public void Put_object(String key, Object val) {
|
||||
engine.put(key, val);
|
||||
}
|
||||
public Object Get_object(String obj_name) {
|
||||
try {
|
||||
return engine.get(obj_name);
|
||||
} catch (Exception e) {
|
||||
System.out.println(e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
public Object Invoke_method(Object obj, String func, Object... args) {
|
||||
try {
|
||||
return invk.invokeMethod(obj, func, args);
|
||||
} catch (Exception e) {
|
||||
System.out.println(e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
@ -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.addons.htmls.includes; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.htmls.*;
|
||||
interface Script_engine {
|
||||
void Load_script(Io_url url);
|
||||
Object Get_object(String obj_name);
|
||||
void Put_object(String name, Object obj);
|
||||
Object Invoke_method(Object obj, String func, Object... args);
|
||||
}
|
||||
class Script_engine__noop implements Script_engine {
|
||||
public void Load_script(Io_url url) {}
|
||||
public Object Get_object(String obj_name) {return null;}
|
||||
public void Put_object(String name, Object obj) {}
|
||||
public Object Invoke_method(Object obj, String func, Object... args) {return null;}
|
||||
}
|
@ -0,0 +1,57 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.addons.htmls.includes; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.htmls.*;
|
||||
import gplx.xowa.wikis.pages.tags.*;
|
||||
public class Xoh_include_mgr {
|
||||
private Io_url[] main_urls; private int main_urls_len;
|
||||
public void Init(Xow_wiki wiki) {
|
||||
// check bin dir
|
||||
Io_url include_dir = wiki.Fsys_mgr().Root_dir().GenSubDir_nest("bin", "html", "include");
|
||||
if (!Io_mgr.Instance.ExistsDir(include_dir)) return;
|
||||
|
||||
this.main_urls = Io_mgr.Instance.QueryDir_args(include_dir).FilPath_("*.js").ExecAsUrlAry();
|
||||
this.main_urls_len = main_urls.length;
|
||||
if (main_urls_len == 0) {
|
||||
Gfo_usr_dlg_.Instance.Warn_many("", "", "no '.js' files found; dir=~{0}", include_dir.Raw());
|
||||
return;
|
||||
}
|
||||
}
|
||||
public void Write(Xow_wiki wiki, Xoa_page page) {
|
||||
this.Init(wiki);
|
||||
if (main_urls_len == 0) return;
|
||||
|
||||
// create engine and load scripts
|
||||
Script_engine engine = new Script_engine__java();
|
||||
for (int i = 0; i < main_urls_len; ++i) {
|
||||
engine.Load_script(main_urls[i]);
|
||||
}
|
||||
// engine.Put_object("page", new Xoscript_page())
|
||||
Xoscript_page xos_pg = new Xoscript_page();
|
||||
|
||||
Object xowa_script = engine.Get_object("xowa_script");
|
||||
// engine.Invoke_method(xowa_script, "main", page.Url().To_str());
|
||||
engine.Invoke_method(xowa_script, "main", xos_pg);
|
||||
// if (String_.Has(rv, "yes")) {
|
||||
// Io_url js_url = null;
|
||||
// page.Html_data().Custom_head_tags().Add(Xopg_tag_itm.New_js_file(js_url));
|
||||
// }
|
||||
}
|
||||
// public static Xoh_include_mgr Get_or_new(Xow_wiki wiki) {
|
||||
// wiki.Addon_mgr().Itms__get_or_null();
|
||||
// }
|
||||
}
|
@ -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.addons.htmls.includes; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.htmls.*;
|
||||
public class Xoscript_page {
|
||||
private Xoscript_page_doc doc = new Xoscript_page_doc();
|
||||
public Xoscript_page_doc Doc() {
|
||||
return doc;
|
||||
}
|
||||
}
|
@ -0,0 +1,23 @@
|
||||
/*
|
||||
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.addons.htmls.includes; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.htmls.*;
|
||||
public class Xoscript_page_doc {
|
||||
public void Test() {
|
||||
Tfds.Write("hi");
|
||||
}
|
||||
}
|
File diff suppressed because it is too large
Load Diff
@ -1,45 +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.addons.wikis.ctgs.bldrs.ucas; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.wikis.*; import gplx.xowa.addons.wikis.ctgs.*; import gplx.xowa.addons.wikis.ctgs.bldrs.*;
|
||||
import org.junit.*; import gplx.xowa.bldrs.*;
|
||||
public class Uca_trie_tst {
|
||||
@Before public void init() {fxt.Clear();} private Xob_base_fxt fxt = new Xob_base_fxt();
|
||||
@Test public void Basic() {
|
||||
Uca_trie_fxt fxt = new Uca_trie_fxt();
|
||||
fxt.Clear();
|
||||
fxt.Init_trie_itm("a", Bry_.New_by_ints(10, 11));
|
||||
fxt.Init_trie_itm("b", Bry_.New_by_ints(20, 21));
|
||||
fxt.Init_trie_itm("c", Bry_.New_by_ints(30, 31));
|
||||
fxt.Test_decode(Bry_.New_by_ints(10, 11), "a");
|
||||
fxt.Test_decode(Bry_.New_by_ints(10, 11, 20, 21, 30, 31), "abc");
|
||||
}
|
||||
}
|
||||
class Uca_trie_fxt {
|
||||
public void Clear() {
|
||||
if (trie == null) {
|
||||
trie = new Uca_trie();
|
||||
bfr = Bry_bfr_.New();
|
||||
}
|
||||
trie.Clear();
|
||||
} Uca_trie trie; Bry_bfr bfr;
|
||||
public void Init_trie_itm(String charAsStr, byte[] uca) {trie.Init_itm(gplx.core.intls.Utf16_.Decode_to_int(Bry_.new_u8(charAsStr), 0), uca);}
|
||||
public void Test_decode(byte[] bry, String expd) {
|
||||
trie.Decode(bfr, bry, 0, bry.length);
|
||||
Tfds.Eq(expd, bfr.To_str_and_clear());
|
||||
}
|
||||
}
|
@ -0,0 +1,182 @@
|
||||
/*
|
||||
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.addons.wikis.ctgs.htmls.catpages.dbs; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.wikis.*; import gplx.xowa.addons.wikis.ctgs.*; import gplx.xowa.addons.wikis.ctgs.htmls.*; import gplx.xowa.addons.wikis.ctgs.htmls.catpages.*;
|
||||
import gplx.dbs.*; import gplx.xowa.wikis.data.*; import gplx.xowa.wikis.data.tbls.*;
|
||||
import gplx.xowa.addons.wikis.ctgs.htmls.catpages.doms.*; import gplx.xowa.addons.wikis.ctgs.htmls.catpages.langs.*;
|
||||
class Xoctg_catlink_loader {
|
||||
private byte version;
|
||||
private int link_dbs_len;
|
||||
private Db_attach_mgr attach_mgr;
|
||||
private final Bry_bfr sortkey_val_bfr = Bry_bfr_.New();
|
||||
public void Run(Xoctg_catpage_ctg rv, Xow_wiki wiki, Xoctg_catpage_mgr catpage_mgr, Xowd_page_tbl page_tbl, int cat_id, byte grp_tid, boolean url_is_from, byte[] url_sortkey, int limit) {
|
||||
String sql = Bld_sql(catpage_mgr, cat_id, grp_tid, url_is_from, url_sortkey, limit);
|
||||
Load_catlinks(rv, wiki, page_tbl, rv.Grp_by_tid(grp_tid), sql, url_is_from, limit);
|
||||
}
|
||||
public void Make_attach_mgr__v2(Xow_db_mgr db_mgr, int cat_link_db_idx) {
|
||||
this.version = 2;
|
||||
this.link_dbs_len = 1;
|
||||
Xow_db_file cat_link_db = db_mgr.Dbs__get_by_id_or_fail(cat_link_db_idx);
|
||||
this.attach_mgr = new Db_attach_mgr(cat_link_db.Conn(), new Db_attach_itm("link_db_1", cat_link_db.Conn()));
|
||||
}
|
||||
public void Make_attach_mgr__v3_v4(Xow_db_mgr db_mgr, Db_conn cat_core_conn) {
|
||||
// init db vars
|
||||
List_adp db_list = List_adp_.New();
|
||||
Db_conn db_1st = null;
|
||||
int db_idx = 0;
|
||||
|
||||
// fill db_list by looping over each db unless (a) cat_link_db or (b) core_db (if all or few)
|
||||
int len = db_mgr.Dbs__len();
|
||||
for (int i = 0; i < len; ++i) {
|
||||
Xow_db_file cl_db = db_mgr.Dbs__get_at(i);
|
||||
switch (cl_db.Tid()) {
|
||||
case Xow_db_file_.Tid__cat_link: // always use cat_link db
|
||||
break;
|
||||
case Xow_db_file_.Tid__core: // only use core if all or few
|
||||
if (db_mgr.Props().Layout_text().Tid_is_lot())
|
||||
continue;
|
||||
else
|
||||
break;
|
||||
default: // skip all other files
|
||||
continue;
|
||||
}
|
||||
|
||||
// add to db_list
|
||||
if (db_1st == null) db_1st = cl_db.Conn();
|
||||
db_list.Add(new Db_attach_itm("link_db_" + ++db_idx, cl_db.Conn()));
|
||||
}
|
||||
|
||||
// make attach_mgr
|
||||
this.version = 4;
|
||||
this.link_dbs_len = db_list.Len();
|
||||
if (cat_core_conn.Meta_tbl_exists("cat_sort")) {
|
||||
version = 3;
|
||||
db_1st = cat_core_conn;
|
||||
}
|
||||
this.attach_mgr = new Db_attach_mgr(db_1st, (Db_attach_itm[])db_list.To_ary_and_clear(Db_attach_itm.class));
|
||||
}
|
||||
private String Bld_sql (Xoctg_catpage_mgr catpage_mgr, int cat_id, byte grp_tid, boolean url_is_from, byte[] url_sortkey, int limit) {
|
||||
Bry_bfr bfr = Bry_bfr_.New();
|
||||
for (int i = 0; i < link_dbs_len; ++i)
|
||||
Bld_sql_by_db(catpage_mgr, cat_id, grp_tid, url_is_from, url_sortkey, i + List_adp_.Base1, bfr);
|
||||
bfr.Add_str_u8_fmt
|
||||
( "\nORDER BY cl_to_id, cl_type_id, cl_sortkey {0}"
|
||||
+ "\nLIMIT {1}"
|
||||
, url_is_from ? "ASC" : "DESC", limit + 1);
|
||||
return bfr.To_str_and_clear();
|
||||
}
|
||||
private void Bld_sql_by_db (Xoctg_catpage_mgr catpage_mgr, int cat_id, byte grp_tid, boolean url_is_from, byte[] url_sortkey, int link_db_id, Bry_bfr bfr) {
|
||||
if (link_db_id != List_adp_.Base1) bfr.Add_str_a7("\nUNION\n");
|
||||
|
||||
// change sortkey vars per version; note that v3 differs from v2 and v4 b/c of cat_sort tbl
|
||||
String sortkey_col = "cl_sortkey";
|
||||
String sortkey_join = "";
|
||||
if (version == 3) { // NOTE: version 3 takes sortkey from cat_sort
|
||||
sortkey_col = "cs.cs_key";
|
||||
sortkey_join = "\n JOIN cat_sort cs ON cl.cl_sortkey_id = cs.cs_id";
|
||||
}
|
||||
|
||||
// sortkey_val
|
||||
byte[] sortkey_val = null;
|
||||
String sortkey_prefix_fld = version == 4 ? "cl_sortkey_prefix" : "''";
|
||||
sortkey_val = Build_sortkey_val(sortkey_val_bfr, version, catpage_mgr.Collation_mgr(), url_sortkey);
|
||||
|
||||
// bld sql; NOTE: building sql with args embedded b/c (a) UNION requires multiple Crt_arg for each ?; (EX: 4 unions, 3 ? require 12 .Crt_arg); (b) easier to debug
|
||||
String sql = Db_sql_.Make_by_fmt(String_.Ary
|
||||
( "SELECT cl_to_id"
|
||||
, ", cl_from"
|
||||
, ", cl_type_id"
|
||||
, ", {3} AS cl_sortkey"
|
||||
, ", {7} AS cl_sortkey_prefix"
|
||||
, "FROM <link_db_{0}>cat_link cl{6}"
|
||||
, "WHERE cl_to_id = {1}"
|
||||
, "AND cl_type_id = {2}"
|
||||
, "AND {3} {4} {5}"
|
||||
), link_db_id, cat_id, grp_tid, sortkey_col, url_is_from ? ">=" : "<", sortkey_val, sortkey_join, sortkey_prefix_fld);
|
||||
bfr.Add_str_u8(sql);
|
||||
}
|
||||
private void Load_catlinks(Xoctg_catpage_ctg rv, Xow_wiki wiki, Xowd_page_tbl page_tbl, Xoctg_catpage_grp grp, String sql, boolean url_is_from, int limit) {
|
||||
// init; prep sql
|
||||
Xoctg_page_loader catlink_loader = new Xoctg_page_loader(wiki);
|
||||
Ordered_hash hash = catlink_loader.Hash();
|
||||
sql = attach_mgr.Resolve_sql(sql);
|
||||
|
||||
// run sql and create itms based on cat_link
|
||||
Xoctg_catpage_itm itm_zth = null;
|
||||
Db_rdr rdr = Db_rdr_.Empty;
|
||||
int row_idx = 0;
|
||||
try {
|
||||
attach_mgr.Attach();
|
||||
rdr = attach_mgr.Conn_main().Stmt_sql(sql).Exec_select__rls_auto();
|
||||
while (rdr.Move_next()) {
|
||||
Xoctg_catpage_itm itm = Xoctg_catpage_itm.New_by_rdr(rdr, version);
|
||||
if (row_idx++ < limit) // row_idx >= limit for last row; EX: 200 < 200
|
||||
hash.Add(itm.Page_id(), itm);
|
||||
else { // last row; EX: 201
|
||||
if (url_is_from) // from=some_key; 201st row is sort_key for "(Next 200)"
|
||||
itm_zth = itm;
|
||||
else // until=some_key; 201st row means that 200th row is not 1st row; show prev link
|
||||
grp.Prev_disable_(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
finally {
|
||||
rdr.Rls();
|
||||
attach_mgr.Detach();
|
||||
}
|
||||
|
||||
// load ns / ttl from page
|
||||
page_tbl.Select_in__id(catlink_loader);
|
||||
grp.Itms_((Xoctg_catpage_itm[])hash.To_ary_and_clear(Xoctg_catpage_itm.class));
|
||||
|
||||
// set data for Next 200 / Previous 200
|
||||
if (itm_zth != null) {
|
||||
if (version == 4) {
|
||||
Xowd_page_itm tmp_pg = new Xowd_page_itm();
|
||||
page_tbl.Select_by_id(tmp_pg, itm_zth.Page_id());
|
||||
Xoa_ttl zth_ttl = wiki.Ttl_parse(tmp_pg.Ns_id(), tmp_pg.Ttl_page_db());
|
||||
itm_zth.Page_ttl_(zth_ttl);
|
||||
itm_zth.Sortkey_handle_make(Bry_bfr_.New(), grp.Itms__get_at(grp.Itms__len() - 1).Sortkey_handle());
|
||||
grp.Next_sortkey_(itm_zth.Sortkey_handle());
|
||||
}
|
||||
else
|
||||
grp.Next_sortkey_(itm_zth.Sortkey_handle());
|
||||
}
|
||||
}
|
||||
public static byte[] Build_sortkey_val(Bry_bfr sortkey_val_bfr, byte version, Xoctg_collation_mgr collation_mgr, byte[] url_sortkey) {
|
||||
// find \n and ignore everything after it; needed else "< 'A\nA'" will pull up "A"; NOTE: can't find logic in MediaWiki CategoryViewer.php; DATE:2016-10-11
|
||||
// ALSO: needed for v2 else SQL will literally have WHERE cl_sortkey = 'A\nA';
|
||||
byte[] tmp_sortkey = url_sortkey;
|
||||
int nl_pos = Bry_find_.Find_fwd(tmp_sortkey, Byte_ascii.Nl);
|
||||
if (nl_pos != Bry_find_.Not_found)
|
||||
tmp_sortkey = Bry_.Mid(tmp_sortkey, 0, nl_pos);
|
||||
|
||||
if (version == 4) {
|
||||
if (Bry_.Len_gt_0(url_sortkey)) {
|
||||
// make sortkey_val
|
||||
sortkey_val_bfr.Add_byte(Byte_ascii.Ltr_x).Add_byte_apos();
|
||||
gplx.core.encoders.Hex_utl_.Encode_bfr(sortkey_val_bfr, collation_mgr.Get_sortkey(tmp_sortkey));
|
||||
sortkey_val_bfr.Add_byte_apos();
|
||||
}
|
||||
else
|
||||
sortkey_val_bfr.Add_byte_apos().Add_byte_apos();
|
||||
}
|
||||
else
|
||||
sortkey_val_bfr.Add_byte_apos().Add(Db_sql_.Escape_arg(tmp_sortkey)).Add_byte_apos();
|
||||
return sortkey_val_bfr.To_bry_and_clear();
|
||||
}
|
||||
}
|
@ -0,0 +1,39 @@
|
||||
/*
|
||||
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.addons.wikis.ctgs.htmls.catpages.dbs; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.wikis.*; import gplx.xowa.addons.wikis.ctgs.*; import gplx.xowa.addons.wikis.ctgs.htmls.*; import gplx.xowa.addons.wikis.ctgs.htmls.catpages.*;
|
||||
import org.junit.*; import gplx.core.tests.*; import gplx.xowa.apps.urls.*;
|
||||
import gplx.xowa.langs.*; import gplx.xowa.addons.wikis.ctgs.htmls.catpages.langs.*;
|
||||
public class Xoctg_catlink_loader__tst {
|
||||
private final Xoctg_catlink_loader__fxt fxt = new Xoctg_catlink_loader__fxt();
|
||||
@Test public void Build_sortkey_val__v4() { // PURPOSE: remove "\n" and afterwards else will omit 1 record
|
||||
fxt.Test__build_sortkey_sql(4, "A\nA", "x'41'"); // fails if "x'410a41'"
|
||||
}
|
||||
@Test public void Build_sortkey_val__v2() { // PURPOSE: remove "\n" and afterwards else SQL will be malformed
|
||||
fxt.Test__build_sortkey_sql(2, "A\nA", "'A'"); // fails if "'A\nA'"
|
||||
}
|
||||
}
|
||||
class Xoctg_catlink_loader__fxt {
|
||||
public void Test__build_sortkey_sql(int version, String sortkey, String expd) {
|
||||
Xoae_app app = Xoa_app_fxt.Make__app__edit();
|
||||
Xowe_wiki wiki = Xoa_app_fxt.Make__wiki__edit(app, "de.wikipedia.org"); // use "de.wikipedia.org" for simple "uppercase" collation
|
||||
Xoctg_collation_mgr collation_mgr = new Xoctg_collation_mgr(wiki);
|
||||
|
||||
Bry_bfr bfr = Bry_bfr_.New();
|
||||
Gftest.Eq__str(expd, Xoctg_catlink_loader.Build_sortkey_val(bfr, Byte_.By_int(version), collation_mgr, Bry_.new_u8(sortkey)));
|
||||
}
|
||||
}
|
@ -0,0 +1,71 @@
|
||||
/*
|
||||
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.addons.wikis.ctgs.htmls.catpages.dbs; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.wikis.*; import gplx.xowa.addons.wikis.ctgs.*; import gplx.xowa.addons.wikis.ctgs.htmls.*; import gplx.xowa.addons.wikis.ctgs.htmls.catpages.*;
|
||||
import gplx.dbs.*; import gplx.xowa.wikis.data.*; import gplx.xowa.wikis.data.tbls.*; import gplx.xowa.addons.wikis.ctgs.dbs.*;
|
||||
import gplx.xowa.addons.wikis.ctgs.htmls.catpages.doms.*; import gplx.xowa.addons.wikis.ctgs.htmls.catpages.urls.*; import gplx.xowa.addons.wikis.ctgs.htmls.catpages.dbs.*;
|
||||
public class Xoctg_catpage_loader {
|
||||
public Xoctg_catpage_ctg Load_ctg_or_null(Xow_wiki wiki, Xoctg_catpage_mgr catpage_mgr, Xoctg_catpage_url cat_url, Xoa_ttl cat_ttl, int limit) {
|
||||
// get cat_id from page_tbl
|
||||
Xow_db_mgr db_mgr = wiki.Data__core_mgr();
|
||||
Xowd_page_tbl page_tbl = db_mgr.Db__core().Tbl__page();
|
||||
Xowd_page_itm page_itm = page_tbl.Select_by_ttl_as_itm_or_null(cat_ttl);
|
||||
if (page_itm == null) {
|
||||
Gfo_usr_dlg_.Instance.Warn_many("", "", "category does not exist in page table; ttl=~{0}", cat_ttl.Full_db());
|
||||
return null;
|
||||
}
|
||||
int cat_id = page_itm.Id();
|
||||
|
||||
// get cat_core_itm from cat_core_tbl
|
||||
Xowd_cat_core_tbl cat_core_tbl = Xodb_cat_db_.Get_cat_core_or_fail(db_mgr);
|
||||
Xowd_category_itm cat_core_itm = cat_core_tbl.Select(cat_id);
|
||||
if (cat_core_itm == Xowd_category_itm.Null) {
|
||||
Gfo_usr_dlg_.Instance.Log_many("", "", "category does not exist in cat_core table; ttl=~{0}", cat_ttl.Full_db()); // NOTE: this is not rare as Category pages can be created as deliberately empty, or as redirects; fr.w:Catégorie:Utilisateur_hess-4; DATE:2016-09-12
|
||||
return null;
|
||||
}
|
||||
|
||||
// load itms from cat_link_db for each grp_tid
|
||||
Xoctg_catpage_ctg rv = new Xoctg_catpage_ctg(cat_id, cat_ttl.Page_txt());
|
||||
for (byte grp_tid = Xoa_ctg_mgr.Tid__subc; grp_tid < Xoa_ctg_mgr.Tid___max; ++grp_tid) {
|
||||
Xoctg_catpage_grp grp = rv.Grp_by_tid(grp_tid);
|
||||
grp.Count_all_(cat_core_itm.Count_by_tid(grp_tid)); // set total counts per grp based on cat_core_itm;
|
||||
|
||||
// init url_vars
|
||||
boolean url_is_from = cat_url.Grp_fwds()[grp_tid]; // EX: "pagefrom=A"; "pageuntil=B"
|
||||
byte[] url_sortkey = cat_url.Grp_keys()[grp_tid];
|
||||
|
||||
// set prev / next props to dflt values
|
||||
if (url_is_from) { // url is from; EX: from=A
|
||||
if (Bry_.Len_eq_0(url_sortkey)) // no sortkey specified for group, so group always starts with 1st itm -> disable previous link
|
||||
grp.Prev_disable_(true);
|
||||
}
|
||||
else { // url is until; EX: until=A
|
||||
grp.Prev_disable_(true); // default prev link to disabled; loader will load 201 items and set to false if 201st found
|
||||
grp.Next_sortkey_(url_sortkey); // next sortkey is always sortkey of until url arg;
|
||||
}
|
||||
|
||||
// load links
|
||||
Xoctg_catlink_loader loader = new Xoctg_catlink_loader();
|
||||
if (cat_core_itm.File_idx() == -1) // v3 or v4: loop over all cat_link dbs {
|
||||
loader.Make_attach_mgr__v3_v4 (db_mgr, cat_core_tbl.Conn());
|
||||
else // v2: use cat_link_db
|
||||
loader.Make_attach_mgr__v2 (db_mgr, cat_core_itm.File_idx());
|
||||
loader.Run(rv, wiki, catpage_mgr, page_tbl, cat_id, grp_tid, url_is_from, url_sortkey, limit);
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
}
|
@ -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.addons.wikis.ctgs.htmls.catpages.dbs; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.wikis.*; import gplx.xowa.addons.wikis.ctgs.*; import gplx.xowa.addons.wikis.ctgs.htmls.*; import gplx.xowa.addons.wikis.ctgs.htmls.catpages.*;
|
||||
import gplx.dbs.*; import gplx.xowa.wikis.data.tbls.*;
|
||||
import gplx.xowa.addons.wikis.ctgs.htmls.catpages.doms.*;
|
||||
public class Xoctg_page_loader implements Select_in_cbk {
|
||||
private final Xow_wiki wiki;
|
||||
private final Ordered_hash hash = Ordered_hash_.New();
|
||||
public Xoctg_page_loader(Xow_wiki wiki) {this.wiki = wiki;}
|
||||
public Ordered_hash Hash() {return hash;}
|
||||
public int Hash_max() {return hash.Len();}
|
||||
public void Write_sql(Bry_bfr bfr, int idx) {
|
||||
Xoctg_catpage_itm itm = (Xoctg_catpage_itm)hash.Get_at(idx);
|
||||
bfr.Add_int_variable(itm.Page_id());
|
||||
}
|
||||
public void Read_data(Db_rdr rdr) {
|
||||
// read values from page_tbl
|
||||
int page_id = rdr.Read_int("page_id");
|
||||
int page_ns = rdr.Read_int("page_namespace");
|
||||
byte[] page_ttl = rdr.Read_bry_by_str("page_title");
|
||||
|
||||
// get itm and set data
|
||||
Xoctg_catpage_itm itm = (Xoctg_catpage_itm)hash.Get_by(page_id);
|
||||
if (itm == null) return; // NOTE: itms can exist in cat_links_tbl, but not in page_tbl; EX:User:Any_page
|
||||
itm.Page_ttl_(wiki.Ttl_parse(page_ns, page_ttl));
|
||||
}
|
||||
}
|
@ -0,0 +1,41 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.addons.wikis.ctgs.htmls.catpages.langs; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.wikis.*; import gplx.xowa.addons.wikis.ctgs.*; import gplx.xowa.addons.wikis.ctgs.htmls.*; import gplx.xowa.addons.wikis.ctgs.htmls.catpages.*;
|
||||
import gplx.core.intls.ucas.*;
|
||||
public class Xoctg_collation_mgr {
|
||||
private final Xow_wiki wiki;
|
||||
private Uca_collator collator;
|
||||
private String collation_name = "uppercase"; // REF:https://noc.wikimedia.org/conf/InitialiseSettings.php.txt|wgCategoryCollation|default
|
||||
public Xoctg_collation_mgr(Xow_wiki wiki) {
|
||||
this.wiki = wiki;
|
||||
if (String_.Eq(wiki.Domain_str(), "en.wikipedia.org"))
|
||||
collation_name = "uca-default-kn";
|
||||
}
|
||||
public void Collation_name_(String v) {
|
||||
this.collation_name = v;
|
||||
}
|
||||
public byte[] Get_sortkey(byte[] src) {
|
||||
if (String_.Eq(collation_name, "uppercase")) {
|
||||
return wiki.Lang().Case_mgr().Case_build_upper(src);
|
||||
}
|
||||
else {
|
||||
if (collator == null) collator = Uca_collator_.New(collation_name, true);
|
||||
return collator.Get_sortkey(String_.new_u8(src));
|
||||
}
|
||||
}
|
||||
}
|
@ -1,62 +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.addons.wikis.ctgs.htmls.catpages.utls; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.wikis.*; import gplx.xowa.addons.wikis.ctgs.*; import gplx.xowa.addons.wikis.ctgs.htmls.*; import gplx.xowa.addons.wikis.ctgs.htmls.catpages.*;
|
||||
import gplx.core.lists.binary_searches.*;
|
||||
import gplx.xowa.addons.wikis.ctgs.htmls.catpages.doms.*; import gplx.xowa.addons.wikis.ctgs.htmls.catpages.urls.*;
|
||||
public class Xoctg_catpage_filter {
|
||||
public static void Filter(int limit, Xoctg_catpage_url cat_url, Xoctg_catpage_ctg ctg) {
|
||||
int len = Xoa_ctg_mgr.Tid___max;
|
||||
for (byte i = 0; i < len; ++i) {
|
||||
Filter_by_grp(limit, cat_url, ctg.Grp_by_tid(i));
|
||||
}
|
||||
}
|
||||
private static void Filter_by_grp(int grp_len, Xoctg_catpage_url cat_url, Xoctg_catpage_grp grp) {
|
||||
byte grp_tid = grp.Tid();
|
||||
byte[] grp_key = cat_url.Grp_keys()[grp_tid];
|
||||
|
||||
// dflt to bos; EX: grp_bgn=0 grp_end=200
|
||||
int grp_bgn = 0;
|
||||
int grp_end = grp_bgn + grp_len;
|
||||
|
||||
// key specified; calc new grp_bgn, grp_end
|
||||
if (grp_key != null) {
|
||||
// get idx of key
|
||||
int key_idx = Binary_search_.Search(grp.Itms(), Xoctg_catpage_itm_sorter__sort_key.Sorter, grp_key);
|
||||
|
||||
// if fwd, set grp_bgn to key_idx, and add grp_len
|
||||
if (cat_url.Grp_fwds()[grp_tid]) {
|
||||
grp_bgn = key_idx;
|
||||
grp_end = grp_bgn + grp_len;
|
||||
}
|
||||
// if bwd, set grp_end to key_idx, and subtract grp_len
|
||||
else {
|
||||
grp_end = key_idx;
|
||||
grp_bgn = grp_end - grp_len;
|
||||
|
||||
// assert new grp_bgn is not negative
|
||||
if (grp_bgn < 0) grp_bgn = 0;
|
||||
}
|
||||
}
|
||||
|
||||
// assert new grp_end is not > grp_max; note that this needs to be specified for when grp_key is null and not null
|
||||
int grp_max = grp.Itms__len();
|
||||
if (grp_end > grp_max)
|
||||
grp_end = grp_max;
|
||||
grp.Rng_(grp_bgn, grp_end);
|
||||
}
|
||||
}
|
@ -1,107 +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.addons.wikis.ctgs.htmls.catpages.utls; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.wikis.*; import gplx.xowa.addons.wikis.ctgs.*; import gplx.xowa.addons.wikis.ctgs.htmls.*; import gplx.xowa.addons.wikis.ctgs.htmls.catpages.*;
|
||||
import org.junit.*; import gplx.core.tests.*;
|
||||
import gplx.xowa.apps.urls.*;
|
||||
import gplx.xowa.addons.wikis.ctgs.htmls.catpages.doms.*; import gplx.xowa.addons.wikis.ctgs.htmls.catpages.urls.*;
|
||||
public class Xoctg_catpage_filter__tst {
|
||||
private final Xoctg_catpage_filter__fxt fxt = new Xoctg_catpage_filter__fxt();
|
||||
private Xoctg_catpage_ctg ctg;
|
||||
@Before public void init() {
|
||||
this.ctg = fxt.Make__ctg(25, 25, 25);
|
||||
}
|
||||
@Test public void Initial() {
|
||||
fxt.Exec__filter(5, "A", ctg);
|
||||
fxt.Test__cat_grp(ctg, Xoa_ctg_mgr.Tid__subc, 0, 5);
|
||||
fxt.Test__cat_grp(ctg, Xoa_ctg_mgr.Tid__page, 0, 5);
|
||||
fxt.Test__cat_grp(ctg, Xoa_ctg_mgr.Tid__file, 0, 5);
|
||||
}
|
||||
@Test public void Fwd__page__05() {
|
||||
fxt.Exec__filter(5, "A?pagefrom=05", ctg);
|
||||
fxt.Test__cat_grp(ctg, Xoa_ctg_mgr.Tid__page, 5, 10);
|
||||
fxt.Test__cat_grp(ctg, Xoa_ctg_mgr.Tid__subc, 0, 5);
|
||||
fxt.Test__cat_grp(ctg, Xoa_ctg_mgr.Tid__file, 0, 5);
|
||||
}
|
||||
@Test public void Fwd__page__10() {
|
||||
fxt.Exec__filter(5, "A?pagefrom=10", ctg);
|
||||
fxt.Test__cat_grp(ctg, Xoa_ctg_mgr.Tid__page, 10, 15);
|
||||
fxt.Test__cat_grp(ctg, Xoa_ctg_mgr.Tid__subc, 0, 5);
|
||||
fxt.Test__cat_grp(ctg, Xoa_ctg_mgr.Tid__file, 0, 5);
|
||||
}
|
||||
@Test public void Fwd__page__23() {
|
||||
fxt.Exec__filter(5, "A?pagefrom=23", ctg);
|
||||
fxt.Test__cat_grp(ctg, Xoa_ctg_mgr.Tid__page, 23, 25);
|
||||
fxt.Test__cat_grp(ctg, Xoa_ctg_mgr.Tid__subc, 0, 5);
|
||||
fxt.Test__cat_grp(ctg, Xoa_ctg_mgr.Tid__file, 0, 5);
|
||||
}
|
||||
@Test public void Fwd__full__06() {
|
||||
fxt.Exec__filter(5, "A?from=06", ctg);
|
||||
fxt.Test__cat_grp(ctg, Xoa_ctg_mgr.Tid__page, 6, 11);
|
||||
fxt.Test__cat_grp(ctg, Xoa_ctg_mgr.Tid__subc, 6, 11);
|
||||
fxt.Test__cat_grp(ctg, Xoa_ctg_mgr.Tid__file, 6, 11);
|
||||
}
|
||||
@Test public void Bwd__page__20() {
|
||||
fxt.Exec__filter(5, "A?pageuntil=20", ctg);
|
||||
fxt.Test__cat_grp(ctg, Xoa_ctg_mgr.Tid__page, 15, 20);
|
||||
fxt.Test__cat_grp(ctg, Xoa_ctg_mgr.Tid__subc, 0, 5);
|
||||
fxt.Test__cat_grp(ctg, Xoa_ctg_mgr.Tid__file, 0, 5);
|
||||
}
|
||||
@Test public void Bwd__page__2() {
|
||||
fxt.Exec__filter(5, "A?pageuntil=01", ctg);
|
||||
fxt.Test__cat_grp(ctg, Xoa_ctg_mgr.Tid__page, 0, 1);
|
||||
fxt.Test__cat_grp(ctg, Xoa_ctg_mgr.Tid__subc, 0, 5);
|
||||
fxt.Test__cat_grp(ctg, Xoa_ctg_mgr.Tid__file, 0, 5);
|
||||
}
|
||||
@Test public void Bwd__full__11() {
|
||||
fxt.Exec__filter(5, "A?until=11", ctg);
|
||||
fxt.Test__cat_grp(ctg, Xoa_ctg_mgr.Tid__page, 6, 11);
|
||||
fxt.Test__cat_grp(ctg, Xoa_ctg_mgr.Tid__subc, 6, 11);
|
||||
fxt.Test__cat_grp(ctg, Xoa_ctg_mgr.Tid__file, 6, 11);
|
||||
}
|
||||
}
|
||||
class Xoctg_catpage_filter__fxt {
|
||||
private Xow_url_parser url_parser;
|
||||
public Xoctg_catpage_filter__fxt() {
|
||||
Xoa_app app = Xoa_app_fxt.Make__app__edit();
|
||||
this.url_parser = app.User().Wikii().Utl__url_parser();
|
||||
}
|
||||
public Xoctg_catpage_ctg Make__ctg(int subc, int page, int file) {
|
||||
Xoctg_catpage_ctg ctg = new Xoctg_catpage_ctg(Bry_.new_a7("A"));
|
||||
Make__ctg_grp(ctg, Xoa_ctg_mgr.Tid__subc, subc);
|
||||
Make__ctg_grp(ctg, Xoa_ctg_mgr.Tid__page, page);
|
||||
Make__ctg_grp(ctg, Xoa_ctg_mgr.Tid__file, file);
|
||||
return ctg;
|
||||
}
|
||||
private void Make__ctg_grp(Xoctg_catpage_ctg ctg, byte tid, int count) {
|
||||
Xoctg_catpage_grp grp = ctg.Grp_by_tid(tid);
|
||||
for (int i = 0; i < count; ++i) {
|
||||
Xoctg_catpage_itm itm = new Xoctg_catpage_itm(i * tid, Xoa_ttl.Null, Bry_.new_a7(Int_.To_str_pad_bgn_zero(i, 2)));
|
||||
grp.Itms__add(itm);
|
||||
}
|
||||
grp.Itms__make();
|
||||
}
|
||||
public void Exec__filter(int limit, String cat_url_str, Xoctg_catpage_ctg ctg) {
|
||||
Xoctg_catpage_url cat_url = Xoctg_catpage_url_parser.Parse(url_parser.Parse(Bry_.new_a7(cat_url_str)));
|
||||
Xoctg_catpage_filter.Filter(limit, cat_url, ctg);
|
||||
}
|
||||
public void Test__cat_grp(Xoctg_catpage_ctg ctg, byte tid, int expd_bgn, int expd_end) {
|
||||
Xoctg_catpage_grp grp = ctg.Grp_by_tid(tid);
|
||||
Gftest.Eq__int(expd_bgn, grp.Bgn(), "bgn failed; tid={0}", tid);
|
||||
Gftest.Eq__int(expd_end, grp.End(), "end failed; tid={0}", tid);
|
||||
}
|
||||
}
|
@ -1,120 +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.addons.wikis.ctgs.htmls.catpages.utls; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.wikis.*; import gplx.xowa.addons.wikis.ctgs.*; import gplx.xowa.addons.wikis.ctgs.htmls.*; import gplx.xowa.addons.wikis.ctgs.htmls.catpages.*;
|
||||
import gplx.dbs.*; import gplx.xowa.wikis.data.*; import gplx.xowa.wikis.data.tbls.*; import gplx.xowa.addons.wikis.ctgs.dbs.*;
|
||||
import gplx.xowa.addons.wikis.ctgs.htmls.catpages.doms.*;
|
||||
public class Xoctg_catpage_loader {
|
||||
private static final Object thread_lock = new Object();
|
||||
public Xoctg_catpage_ctg Load_by_ttl_or_null(Xow_wiki wiki, Xoa_ttl cat_ttl) {
|
||||
// get cat_id for cat_ttl from page_tbl
|
||||
Xow_db_mgr db_mgr = wiki.Data__core_mgr();
|
||||
Xowd_page_tbl page_tbl = db_mgr.Db__core().Tbl__page();
|
||||
Xowd_page_itm page_itm = page_tbl.Select_by_ttl_as_itm_or_null(cat_ttl);
|
||||
if (page_itm == null) {
|
||||
Gfo_usr_dlg_.Instance.Warn_many("", "", "category does not exist in page table; ttl=~{0}", cat_ttl.Full_db());
|
||||
return null;
|
||||
}
|
||||
|
||||
// get cat_link db from cat_core_tbl
|
||||
Xowd_cat_core_tbl cat_core_tbl = Xodb_cat_db_.Get_cat_core_or_fail(db_mgr);
|
||||
int cat_id = page_itm.Id();
|
||||
Xowd_category_itm cat_core_itm = cat_core_tbl.Select(cat_id);
|
||||
if (cat_core_itm == Xowd_category_itm.Null) {
|
||||
Gfo_usr_dlg_.Instance.Log_many("", "", "category does not exist in cat_core table; ttl=~{0}", cat_ttl.Full_db()); // NOTE: this is not rare as Category pages can be created as deliberately empty, or as redirects; fr.w:Catégorie:Utilisateur_hess-4; DATE:2016-09-12
|
||||
return null;
|
||||
}
|
||||
|
||||
// load itms from cat_link_db
|
||||
Xoctg_catpage_ctg rv = new Xoctg_catpage_ctg(cat_ttl.Page_txt());
|
||||
if (cat_core_itm.File_idx() == -1) // new v3: loop over all cat_link dbs
|
||||
Search_cat_core_tbls_for_cat_id(rv, wiki, db_mgr, page_tbl.Conn(), cat_core_tbl.Conn(), cat_id);
|
||||
else { // old v2: use cat_link_db
|
||||
Xow_db_file cat_link_db = db_mgr.Dbs__get_by_id_or_fail(cat_core_itm.File_idx());
|
||||
Select_by_cat_id(rv, wiki, page_tbl.Conn(), cat_core_tbl.Conn(), cat_link_db.Conn(), cat_id, Sql_for_v2(cat_id));
|
||||
}
|
||||
rv.Make_itms();
|
||||
return rv;
|
||||
}
|
||||
private static void Search_cat_core_tbls_for_cat_id(Xoctg_catpage_ctg rv, Xow_wiki wiki, Xow_db_mgr db_mgr, Db_conn page_conn, Db_conn cat_core_conn, int cat_id) {
|
||||
// loop over each db unless (a) cat_link_db; (b) core_db (if all or few)
|
||||
int len = db_mgr.Dbs__len();
|
||||
for (int i = 0; i < len; ++i) {
|
||||
Xow_db_file db_file = db_mgr.Dbs__get_at(i);
|
||||
switch (db_file.Tid()) {
|
||||
case Xow_db_file_.Tid__cat_link: // always use cat_link db
|
||||
break;
|
||||
case Xow_db_file_.Tid__core: // only use core if all or few
|
||||
if (db_mgr.Props().Layout_text().Tid_is_lot())
|
||||
continue;
|
||||
else
|
||||
break;
|
||||
default: // else ignore all other files
|
||||
continue;
|
||||
}
|
||||
Select_by_cat_id(rv, wiki, page_conn, cat_core_conn, db_file.Conn(), cat_id, Sql_for_v3(cat_id));
|
||||
}
|
||||
}
|
||||
private static void Select_by_cat_id(Xoctg_catpage_ctg rv, Xow_wiki wiki, Db_conn page_conn, Db_conn cat_core_conn, Db_conn cat_link_conn, int cat_id, String sql) {
|
||||
// prep sql
|
||||
Db_attach_mgr attach_mgr = new Db_attach_mgr(cat_link_conn, new Db_attach_itm("page_db", page_conn), new Db_attach_itm("cat_core_db", cat_core_conn));
|
||||
sql = attach_mgr.Resolve_sql(sql);
|
||||
|
||||
// run sql and create itms based on cat_link
|
||||
Db_rdr rdr = Db_rdr_.Empty;
|
||||
synchronized (thread_lock) { // LOCK:used by multiple wrks; DATE:2016-09-12
|
||||
try {
|
||||
attach_mgr.Attach();
|
||||
rdr = cat_link_conn.Stmt_sql(sql).Exec_select__rls_auto();
|
||||
while (rdr.Move_next()) {
|
||||
Xoa_ttl page_ttl = wiki.Ttl_parse(rdr.Read_int("page_namespace"), rdr.Read_bry_by_str("page_title"));
|
||||
Xoctg_catpage_itm itm = new Xoctg_catpage_itm(rdr.Read_int("cl_from"), page_ttl, Bry_.new_u8(rdr.Read_str("cl_sortkey")));
|
||||
rv.Grp_by_tid(rdr.Read_byte("cl_type_id")).Itms__add(itm);
|
||||
}
|
||||
}
|
||||
finally {
|
||||
rdr.Rls();
|
||||
attach_mgr.Detach();
|
||||
}
|
||||
}
|
||||
}
|
||||
private static String Sql_for_v3(int cat_id) {
|
||||
return String_.Concat_lines_nl_skip_last // ANSI.Y
|
||||
( "SELECT cl.cl_from"
|
||||
, ", cl.cl_type_id"
|
||||
, ", p.page_namespace"
|
||||
, ", p.page_title"
|
||||
, ", cs.cs_key AS cl_sortkey"
|
||||
, "FROM cat_link cl"
|
||||
, " JOIN <page_db>page p ON cl.cl_from = p.page_id"
|
||||
, " JOIN <cat_core_db>cat_sort cs ON cl.cl_sortkey_id = cs.cs_id"
|
||||
, "WHERE cl.cl_to_id = " + Int_.To_str(cat_id)
|
||||
);
|
||||
}
|
||||
private static String Sql_for_v2(int cat_id) { // NOTE: main difference is cl_sortkey is on cat_link, not in cat_sort
|
||||
return String_.Concat_lines_nl_skip_last // ANSI.Y
|
||||
( "SELECT cl.cl_from"
|
||||
, ", cl.cl_type_id"
|
||||
, ", p.page_namespace"
|
||||
, ", p.page_title"
|
||||
, ", cl.cl_sortkey"
|
||||
, "FROM cat_link cl"
|
||||
, " JOIN <page_db>page p ON cl.cl_from = p.page_id"
|
||||
, "WHERE cl.cl_to_id = " + Int_.To_str(cat_id)
|
||||
);
|
||||
}
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue