mirror of
https://github.com/gnosygnu/xowa.git
synced 2026-03-02 03:49:30 +00:00
v1.8.2.1
This commit is contained in:
54
400_xowa/src/gplx/xowa/dbs/hdumps/Bry_rdr.java
Normal file
54
400_xowa/src/gplx/xowa/dbs/hdumps/Bry_rdr.java
Normal file
@@ -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.xowa.dbs.hdumps; import gplx.*; import gplx.xowa.*; import gplx.xowa.dbs.*;
|
||||
public class Bry_rdr {
|
||||
private byte[] src; private int src_len;
|
||||
public Bry_rdr Src_(byte[] src, int src_len) {this.src = src; this.src_len = src_len; pos = 0; return this;} public Bry_rdr Src_(byte[] src) {return Src_(src, src.length);}
|
||||
public int Pos() {return pos;} public Bry_rdr Pos_(int v) {this.pos = v; return this;} private int pos;
|
||||
public int Or_int() {return or_int;} public void Or_int_(int v) {or_int = v;} private int or_int = Int_.MinValue;
|
||||
public byte[] Or_bry() {return or_bry;} public void Or_bry_(byte[] v) {or_bry = v;} private byte[] or_bry;
|
||||
public int Read_int_to_pipe() {return Read_int_to(Byte_ascii.Pipe);}
|
||||
public int Read_int_to(byte to_char) {
|
||||
int bgn = pos;
|
||||
int rv = 0;
|
||||
while (pos < src_len) {
|
||||
byte b = src[pos++];
|
||||
switch (b) {
|
||||
case Byte_ascii.Num_0: case Byte_ascii.Num_1: case Byte_ascii.Num_2: case Byte_ascii.Num_3: case Byte_ascii.Num_4:
|
||||
case Byte_ascii.Num_5: case Byte_ascii.Num_6: case Byte_ascii.Num_7: case Byte_ascii.Num_8: case Byte_ascii.Num_9:
|
||||
rv = (rv * 10) + (b - Byte_ascii.Num_0);
|
||||
break;
|
||||
default:
|
||||
return b == to_char ? rv : or_int;
|
||||
}
|
||||
}
|
||||
return bgn == pos ? or_int : rv;
|
||||
}
|
||||
public byte[] Read_bry_to_pipe() {return Read_bry_to(Byte_ascii.Pipe);}
|
||||
public byte[] Read_bry_to(byte to_char) {
|
||||
int bgn = pos;
|
||||
while (pos < src_len) {
|
||||
byte b = src[pos];
|
||||
if (b == to_char)
|
||||
return Bry_.Mid(src, bgn, pos++);
|
||||
else
|
||||
++pos;
|
||||
}
|
||||
return bgn == pos ? or_bry : Bry_.Mid(src, bgn, src_len);
|
||||
}
|
||||
}
|
||||
51
400_xowa/src/gplx/xowa/dbs/hdumps/Bry_rdr_tst.java
Normal file
51
400_xowa/src/gplx/xowa/dbs/hdumps/Bry_rdr_tst.java
Normal file
@@ -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.xowa.dbs.hdumps; import gplx.*; import gplx.xowa.*; import gplx.xowa.dbs.*;
|
||||
import org.junit.*;
|
||||
public class Bry_rdr_tst {
|
||||
@Before public void init() {fxt.Clear();} private Bry_rdr_fxt fxt = new Bry_rdr_fxt();
|
||||
@Test public void Int() {
|
||||
fxt.Init_src("12|3456|789");
|
||||
fxt.Test_read_int(12);
|
||||
fxt.Test_read_int(3456);
|
||||
fxt.Test_read_int(789);
|
||||
fxt.Test_read_int(Int_.MinValue);
|
||||
}
|
||||
@Test public void Bry() {
|
||||
fxt.Init_src("abc|d||ef");
|
||||
fxt.Test_read_bry("abc");
|
||||
fxt.Test_read_bry("d");
|
||||
fxt.Test_read_bry("");
|
||||
fxt.Test_read_bry("ef");
|
||||
fxt.Test_read_bry(null);
|
||||
}
|
||||
}
|
||||
class Bry_rdr_fxt {
|
||||
private Bry_rdr rdr;
|
||||
public void Clear() {rdr = new Bry_rdr();}
|
||||
public Bry_rdr_fxt Init_src(String v) {rdr.Src_(Bry_.new_utf8_(v)); return this;}
|
||||
public Bry_rdr_fxt Init_pos(int v) {rdr.Pos_(v); return this;}
|
||||
public void Test_read_int(int expd_val) {
|
||||
Tfds.Eq(expd_val, rdr.Read_int_to_pipe());
|
||||
}
|
||||
public void Test_read_bry(String expd_str) {
|
||||
byte[] actl_bry = rdr.Read_bry_to_pipe();
|
||||
String actl_str = actl_bry == null ? null : String_.new_utf8_(actl_bry);
|
||||
Tfds.Eq(expd_str, actl_str);
|
||||
}
|
||||
}
|
||||
@@ -1,101 +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.dbs.hdumps; import gplx.*; import gplx.xowa.*; import gplx.xowa.dbs.*;
|
||||
class Hdump_data_mgr {
|
||||
// private Xow_wiki wiki;
|
||||
// public void Init_by_wiki(Xow_wiki wiki) {this.wiki = wiki;}
|
||||
public void Select(int ns_id, Hdump_page_row page, int page_id) {
|
||||
Hdump_db db = Get_db(ns_id, page_id);
|
||||
// int reg =
|
||||
db.Page_tbl().Select(null, page, page_id);
|
||||
// db.Frag_tbl().Select(list, 1);
|
||||
// page.Frags_(list.XtoAry());
|
||||
}
|
||||
public void Insert(int ns_id, Hdump_page_row page) {
|
||||
byte[] page_html = page.Page_html();
|
||||
int page_html_len = page_html.length;
|
||||
Hdump_db db = Get_db(ns_id, page_html_len);
|
||||
Hdump_frag_row[] frags = page.Frags();
|
||||
int frags_len = frags.length;
|
||||
db.Page_tbl().Insert(page.Page_id(), page.Page_html(), frags_len, 1);
|
||||
Hdump_frag_tbl frag_tbl = db.Frag_tbl();
|
||||
for (int i = 0; i < frags_len; ++i) {
|
||||
Hdump_frag_row frag = frags[i];
|
||||
frag_tbl.Insert(null, frag.Frag_id(), page.Page_id(), frag.Frag_tid(), frag.Frag_key(), frag.Frag_text());
|
||||
}
|
||||
}
|
||||
public void Update() {
|
||||
}
|
||||
private Hdump_db Get_db(int ns_id, int len) {return null;}
|
||||
}
|
||||
class Hdump_db {
|
||||
public Io_url Db_url() {return db_url;} private Io_url db_url = Io_url_.Null;
|
||||
public void Txn_bgn() {}
|
||||
public void Txn_end() {}
|
||||
public void Rls() {}
|
||||
public Hdump_page_tbl Page_tbl() {return page_tbl;} private Hdump_page_tbl page_tbl = new Hdump_page_tbl();
|
||||
public Hdump_frag_tbl Frag_tbl() {return frag_tbl;} private Hdump_frag_tbl frag_tbl = new Hdump_frag_tbl();
|
||||
}
|
||||
class Hdump_bldr {
|
||||
public byte[] Do_this() {
|
||||
// SELECT * FROM page_id
|
||||
return null;
|
||||
}
|
||||
}
|
||||
class Hdump_rdr {
|
||||
public void Read(Hdump_page page, Hdump_text_itm[] itms) {
|
||||
int len = itms.length;
|
||||
for (int i = 0; i < len; ++i) {
|
||||
Hdump_text_itm itm = itms[i];
|
||||
switch (itm.Tid()) {
|
||||
case Hdump_text_tid.Tid_page: Read_page(page, itm); break;
|
||||
case Hdump_text_tid.Tid_file: break;
|
||||
}
|
||||
}
|
||||
}
|
||||
public void Read_page(Hdump_page page, Hdump_text_itm itm) {
|
||||
page.Version_id_(Bry_.Xto_int(itm.Args()));
|
||||
page.Html_(itm.Text());
|
||||
}
|
||||
public void Read_file(Hdump_page page, Hdump_text_itm file) {
|
||||
//byte[][] args = null;
|
||||
}
|
||||
}
|
||||
class Hdump_page {
|
||||
public int Version_id() {return version_id;} public void Version_id_(int v) {version_id = v;} private int version_id;
|
||||
public byte[] Html() {return html;} public void Html_(byte[] v) {html = v;} private byte[] html;
|
||||
public void Generate() {
|
||||
// swap in each file
|
||||
// add skin
|
||||
// swap in display title, content_sub, menu
|
||||
}
|
||||
}
|
||||
class Hdump_itm_file {
|
||||
public byte[] Ttl() {return ttl;} private byte[] ttl;
|
||||
public void Init(byte[][] ary) {
|
||||
ttl = ary[0];
|
||||
}
|
||||
}
|
||||
class Hdump_text_itm {
|
||||
public int Tid() {return tid;} public void Tid_(int v) {tid = v;} private int tid;
|
||||
public byte[] Args() {return args;} public void Args_(byte[] v) {args = v;} private byte[] args;
|
||||
public byte[] Text() {return text;} public void Text_(byte[] v) {text = v;} private byte[] text;
|
||||
}
|
||||
class Hdump_text_tid {
|
||||
public static final int Tid_page = 0, Tid_file = 1, Tid_display = 2, Tid_content_sub = 3, Tid_sidebar = 4;
|
||||
}
|
||||
@@ -16,13 +16,10 @@ 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.dbs.hdumps; import gplx.*; import gplx.xowa.*; import gplx.xowa.dbs.*;
|
||||
import gplx.ios.*;
|
||||
public class Hdump_skin_row {
|
||||
public int Skin_id() {return skin_id;} private int skin_id;
|
||||
public byte[] Skin_html() {return skin_html;} private byte[] skin_html;
|
||||
public Hdump_skin_row Ctor(int skin_id, byte[] skin_html) {
|
||||
this.skin_id = skin_id;
|
||||
this.skin_html = skin_html;
|
||||
return this;
|
||||
import gplx.dbs.*;
|
||||
public class Hdump_db_mgr {
|
||||
public Db_provider Db_provider_by_page(int page_id) {
|
||||
return null;
|
||||
}
|
||||
public int Next_insert_id() {return 0;}
|
||||
}
|
||||
60
400_xowa/src/gplx/xowa/dbs/hdumps/Hdump_file_itm.java
Normal file
60
400_xowa/src/gplx/xowa/dbs/hdumps/Hdump_file_itm.java
Normal file
@@ -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.xowa.dbs.hdumps; import gplx.*; import gplx.xowa.*; import gplx.xowa.dbs.*;
|
||||
class Hdump_file_itm {
|
||||
// lnki_ttl|lnki_ext|lnki_type|lnki_w|lnki_h|lnki_align_x|lnki_align_y|lnki_border|lnki_upright|lnki_time|lnki_page|lnki_media_icon|lnki_alt|lnki_caption
|
||||
public byte[] Lnki_ttl() {return lnki_ttl;} private byte[] lnki_ttl;
|
||||
public byte Lnki_tid() {return lnki_tid;} private byte lnki_tid;
|
||||
public int Lnki_w() {return lnki_w;} private int lnki_w;
|
||||
public int Lnki_h() {return lnki_h;} private int lnki_h;
|
||||
public byte Lnki_align_x() {return lnki_align_x;} private byte lnki_align_x;
|
||||
public byte Lnki_align_y() {return lnki_align_y;} private byte lnki_align_y;
|
||||
public byte Lnki_border() {return lnki_border;} private byte lnki_border;
|
||||
public double Lnki_upright() {return lnki_upright;} private double lnki_upright;
|
||||
public double Lnki_time() {return lnki_time;} private double lnki_time;
|
||||
public int Lnki_page() {return lnki_page;} private int lnki_page;
|
||||
public boolean Lnki_media_icon() {return lnki_media_icon;} private boolean lnki_media_icon;
|
||||
public byte[] Lnki_alt() {return lnki_alt;} private byte[] lnki_alt;
|
||||
public byte[] Lnki_caption() {return lnki_caption;} private byte[] lnki_caption;
|
||||
public void Parse(byte[] src) {
|
||||
int len = src.length;
|
||||
int pos = 0;
|
||||
int fld_idx = 0, fld_bgn = 0;
|
||||
while (pos < len) {
|
||||
byte b = src[pos];
|
||||
if (b == Byte_ascii.Pipe) {
|
||||
switch (fld_idx) {
|
||||
case 0: lnki_ttl = Bry_.Mid(src, fld_bgn, pos); break;
|
||||
case 2: lnki_tid = Bry_.Xto_byte_by_int(src, fld_bgn, pos, Byte_.MaxValue_127); break;
|
||||
case 3: lnki_w = Bry_.Xto_int_or(src, fld_bgn, pos, -1); break;
|
||||
case 4: lnki_h = Bry_.Xto_int_or(src, fld_bgn, pos, -1); break;
|
||||
case 5: lnki_align_x = Bry_.Xto_byte_by_int(src, fld_bgn, pos, Byte_.MaxValue_127); break;
|
||||
case 6: lnki_align_y = Bry_.Xto_byte_by_int(src, fld_bgn, pos, Byte_.MaxValue_127); break;
|
||||
case 7: lnki_border = Bry_.Xto_byte_by_int(src, fld_bgn, pos, Byte_.MaxValue_127); break;
|
||||
case 8: lnki_upright = Bry_.XtoDoubleByPos(src, fld_bgn, pos); break;
|
||||
case 9: lnki_time = Bry_.XtoDoubleByPos(src, fld_bgn, pos); break;
|
||||
case 10: lnki_page = Bry_.Xto_int_or(src, fld_bgn, pos, -1); break;
|
||||
case 11: lnki_media_icon = src[pos] == Byte_ascii.Ltr_y; break;
|
||||
case 12: lnki_alt = Bry_.Mid(src, fld_bgn, pos); break;
|
||||
case 13: lnki_caption = Bry_.Mid(src, fld_bgn, pos); break;
|
||||
}
|
||||
++fld_idx;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,52 +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.dbs.hdumps; import gplx.*; import gplx.xowa.*; import gplx.xowa.dbs.*;
|
||||
import gplx.ios.*;
|
||||
public class Hdump_frag_row {
|
||||
public int Frag_id() {return frag_id;} private int frag_id;
|
||||
public int Page_id() {return page_id;} private int page_id;
|
||||
public int Frag_tid() {return frag_tid;} private int frag_tid;
|
||||
public byte[] Frag_key() {return frag_key;} private byte[] frag_key;
|
||||
public byte[] Frag_text() {return frag_text;} private byte[] frag_text;
|
||||
public Hdump_frag_row Ctor(int frag_id, int page_id, int frag_tid, byte[] frag_key, byte[] frag_text) {
|
||||
this.frag_id = frag_id;
|
||||
this.page_id = page_id;
|
||||
this.frag_tid = frag_tid;
|
||||
this.frag_key = frag_key;
|
||||
this.frag_text = frag_text;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
class Hdump_frag_tid {
|
||||
public static final int Tid_file = 1, Tid_title = 2, Tid_sidebar = 3;
|
||||
public static final String Key_file = "file", Key_title = "title", Key_sidebar = "sidebar";
|
||||
public static String Xto_key(int v) {
|
||||
switch (v) {
|
||||
case Tid_file : return Key_file;
|
||||
case Tid_title : return Key_title;
|
||||
case Tid_sidebar : return Key_sidebar;
|
||||
default : throw Err_.unhandled(v);
|
||||
}
|
||||
}
|
||||
public static byte Xto_tid(String v) {
|
||||
if (String_.Eq(v, Key_file)) return Tid_file;
|
||||
else if (String_.Eq(v, Key_title)) return Tid_title;
|
||||
else if (String_.Eq(v, Key_sidebar)) return Tid_sidebar;
|
||||
else throw Err_.unhandled("v");
|
||||
}
|
||||
}
|
||||
@@ -1,93 +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.dbs.hdumps; import gplx.*; import gplx.xowa.*; import gplx.xowa.dbs.*;
|
||||
import gplx.dbs.*; import gplx.ios.*;
|
||||
public class Hdump_frag_tbl {
|
||||
private Db_stmt stmt_select, stmt_insert, stmt_update, stmt_delete;
|
||||
@gplx.Virtual public void Insert(Db_provider provider, int frag_id, int page_id, int frag_tid, byte[] frag_key, byte[] frag_text) {
|
||||
if (stmt_insert == null) stmt_insert = Db_stmt_.new_insert_(provider, Tbl_name, Flds_all);
|
||||
try {
|
||||
stmt_insert.Val_int_(frag_id).Val_int_(page_id).Val_int_(frag_tid).Val_str_by_bry_(frag_key).Val_str_by_bry_(frag_text).Exec_insert();
|
||||
} finally {stmt_insert.Rls();}
|
||||
}
|
||||
@gplx.Virtual public void Update(Db_provider provider, int frag_id, int page_id, int frag_tid, byte[] frag_key, byte[] frag_text) {
|
||||
if (stmt_update == null) stmt_update = Db_stmt_.new_update_(provider, Tbl_name, Flds_all);
|
||||
try {
|
||||
stmt_update.Val_int_(frag_id).Val_int_(page_id).Val_int_(frag_tid).Val_str_by_bry_(frag_key).Val_str_by_bry_(frag_text).Exec_update();
|
||||
} finally {stmt_update.Rls();}
|
||||
}
|
||||
@gplx.Virtual public void Select(Db_provider provider, Hdump_frag_row rv, int frag_id) {
|
||||
if (stmt_select == null) stmt_select = Db_stmt_.new_select_(provider, Tbl_name, String_.Ary(Fld_frag_id), Flds_all);
|
||||
try {
|
||||
DataRdr rdr = stmt_select.Val_int_(frag_id).Exec_select();
|
||||
rv.Ctor
|
||||
( rdr.ReadInt(Fld_frag_id)
|
||||
, rdr.ReadInt(Fld_page_id)
|
||||
, rdr.ReadInt(Fld_frag_tid)
|
||||
, rdr.ReadBryByStr(Fld_frag_key)
|
||||
, rdr.ReadBryByStr(Fld_frag_text)
|
||||
);
|
||||
rdr.Rls();
|
||||
} finally {stmt_select.Rls();}
|
||||
}
|
||||
@gplx.Virtual public void Delete(Db_provider provider, int frag_id) {
|
||||
if (stmt_delete == null) stmt_delete = Db_stmt_.new_delete_(provider, Tbl_name, Fld_frag_id);
|
||||
try {
|
||||
stmt_delete.Val_int_(frag_id).Exec_delete();
|
||||
} finally {stmt_delete.Rls();}
|
||||
}
|
||||
@gplx.Virtual public void Delete_all(Db_provider provider) {
|
||||
Db_qry_.delete_tbl_(Tbl_name).Exec_qry(provider);
|
||||
}
|
||||
public void Rls() {
|
||||
stmt_select = stmt_insert = stmt_update = stmt_delete = null;
|
||||
}
|
||||
public static final String Tbl_name = "html_frag"
|
||||
, Fld_frag_id = "frag_id", Fld_page_id = "page_id", Fld_frag_tid = "frag_tid"
|
||||
, Fld_frag_key = "frag_key", Fld_frag_text = "frag_text";
|
||||
private static final String[] Flds_all = new String[] {Fld_frag_id, Fld_page_id, Fld_frag_tid, Fld_frag_key, Fld_frag_text};
|
||||
public static final String Tbl_sql = String_.Concat_lines_nl
|
||||
( "CREATE TABLE IF NOT EXISTS html_frag"
|
||||
, "( frag_id integer NOT NULL PRIMARY KEY"
|
||||
, ", page_id integer NOT NULL"
|
||||
, ", frag_tid integer NOT NULL"
|
||||
, ", frag_key varchar(255) NOT NULL"
|
||||
, ", frag_text mediumblob NOT NULL"
|
||||
, ");"
|
||||
);
|
||||
}
|
||||
class Hdump_frag_tbl_mem extends Hdump_frag_tbl { private OrderedHash hash = OrderedHash_.new_();
|
||||
@Override public void Insert(Db_provider provider, int frag_id, int page_id, int frag_tid, byte[] frag_key, byte[] frag_text) {
|
||||
Hdump_frag_row row = new Hdump_frag_row().Ctor(frag_id, page_id, frag_tid, frag_key, frag_text);
|
||||
hash.Add(frag_id, row);
|
||||
}
|
||||
@Override public void Update(Db_provider provider, int frag_id, int page_id, int frag_tid, byte[] frag_key, byte[] frag_text) {
|
||||
Hdump_frag_row row = (Hdump_frag_row)hash.Fetch(frag_id);
|
||||
row.Ctor(frag_id, page_id, frag_tid, frag_key, frag_text);
|
||||
}
|
||||
@Override public void Select(Db_provider provider, Hdump_frag_row rv, int frag_id) {
|
||||
Hdump_frag_row row = (Hdump_frag_row)hash.Fetch(frag_id);
|
||||
rv.Ctor(row.Frag_id(), row.Page_id(), row.Frag_tid(), row.Frag_key(), row.Frag_text());
|
||||
}
|
||||
@Override public void Delete(Db_provider provider, int frag_id) {
|
||||
hash.Del(frag_id);
|
||||
}
|
||||
@Override public void Delete_all(Db_provider provider) {
|
||||
hash.Clear();
|
||||
}
|
||||
}
|
||||
@@ -16,18 +16,18 @@ 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.dbs.hdumps; import gplx.*; import gplx.xowa.*; import gplx.xowa.dbs.*;
|
||||
import gplx.ios.*;
|
||||
public class Hdump_page_row {
|
||||
public int Page_id() {return page_id;} private int page_id;
|
||||
public byte[] Page_html() {return page_html;} private byte[] page_html;
|
||||
public int Frags_len() {return frags_len;} private int frags_len;
|
||||
public int Make_id() {return make_id;} private int make_id;
|
||||
public Hdump_frag_row[] Frags() {return frags;} public void Frags_(Hdump_frag_row[] frags) {this.frags = frags;} private Hdump_frag_row[] frags;
|
||||
public Hdump_page_row Ctor(int page_id, byte[] page_html, int frags_len, int make_id) {
|
||||
this.page_id = page_id;
|
||||
this.page_html = page_html;
|
||||
this.frags_len = frags_len;
|
||||
this.make_id = make_id;
|
||||
return this;
|
||||
public class Hdump_img_itm {
|
||||
public Hdump_img_itm(int img_id, byte[] img_src, int img_w, int img_h) {
|
||||
this.img_id = img_id;
|
||||
this.img_src = img_src;
|
||||
this.img_w = img_w;
|
||||
this.img_h = img_h;
|
||||
}
|
||||
public int Img_id() {return img_id;} private int img_id;
|
||||
public byte[] Img_src() {return img_src;} private byte[] img_src;
|
||||
public int Img_w() {return img_w;} private int img_w;
|
||||
public int Img_h() {return img_h;} private int img_h;
|
||||
public void Write_html(Bry_bfr bfr) {
|
||||
fmtr.Bld_bfr_many(bfr, img_src, img_w, img_h);
|
||||
} private static final Bry_fmtr fmtr = Bry_fmtr.new_(" src='~{src}' width='~{w}' height='~{h}'", "src", "w", "h");
|
||||
}
|
||||
72
400_xowa/src/gplx/xowa/dbs/hdumps/Hdump_load_mgr.java
Normal file
72
400_xowa/src/gplx/xowa/dbs/hdumps/Hdump_load_mgr.java
Normal file
@@ -0,0 +1,72 @@
|
||||
/*
|
||||
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.dbs.hdumps; import gplx.*; import gplx.xowa.*; import gplx.xowa.dbs.*;
|
||||
import gplx.dbs.*; import gplx.ios.*;
|
||||
import gplx.core.btries.*; import gplx.xowa.pages.*;
|
||||
class Hdump_load_mgr {
|
||||
private Hdump_db_mgr db_mgr;
|
||||
private Io_stream_zip_mgr zip_mgr = new Io_stream_zip_mgr();
|
||||
private int page_version;
|
||||
private byte[] page_text, display_ttl, content_sub;
|
||||
private ListAdp sidebar_divs = ListAdp_.new_(), img_itms = ListAdp_.new_();
|
||||
private Hdump_text_tbl text_tbl = new Hdump_text_tbl(); private ListAdp tmp_text_itms = ListAdp_.new_();
|
||||
private Bry_rdr bry_rdr = new Bry_rdr();
|
||||
public Hdump_load_mgr(Hdump_db_mgr db_mgr) {this.db_mgr = db_mgr;}
|
||||
public void Clear() {
|
||||
page_version = -1;
|
||||
page_text = display_ttl = content_sub = null;
|
||||
sidebar_divs.Clear();
|
||||
img_itms.Clear();
|
||||
}
|
||||
public void Load(Hdump_page_itm page, int page_id, byte[] page_url) {
|
||||
Db_provider provider = db_mgr.Db_provider_by_page(page_id);
|
||||
text_tbl.Select_by_page(tmp_text_itms, provider, page_id);
|
||||
Load_itm(page, page_id, page_url, tmp_text_itms);
|
||||
}
|
||||
public void Load_itm(Hdump_page_itm page, int page_id, byte[] page_url, ListAdp itms) {
|
||||
this.Clear();
|
||||
int len = itms.Count();
|
||||
for (int i = 0; i < len; ++i) {
|
||||
Hdump_text_row itm = (Hdump_text_row)itms.FetchAt(i);
|
||||
switch (itm.Tid()) {
|
||||
case Hdump_text_row_tid.Tid_body: Load_itm_body(itm); break;
|
||||
case Hdump_text_row_tid.Tid_img: Load_itm_img(itm); break;
|
||||
case Hdump_text_row_tid.Tid_sidebar_div: sidebar_divs.Add(zip_mgr.Unzip(Io_stream_.Tid_gzip, itm.Data())); break;
|
||||
case Hdump_text_row_tid.Tid_display_ttl: display_ttl = zip_mgr.Unzip(Io_stream_.Tid_gzip, itm.Data()); break;
|
||||
case Hdump_text_row_tid.Tid_content_sub: content_sub = zip_mgr.Unzip(Io_stream_.Tid_gzip, itm.Data()); break;
|
||||
}
|
||||
}
|
||||
page.Init(page_id, page_url, page_version, display_ttl, content_sub, page_text
|
||||
, (byte[][])sidebar_divs.XtoAryAndClear(byte[].class)
|
||||
, (Hdump_img_itm[])img_itms.XtoAryAndClear(Hdump_img_itm.class)
|
||||
);
|
||||
}
|
||||
public void Load_itm_body(Hdump_text_row itm) {
|
||||
page_version = Bry_.Xto_int(itm.Meta());
|
||||
page_text = zip_mgr.Unzip(Io_stream_.Tid_gzip, itm.Data());
|
||||
}
|
||||
public void Load_itm_img(Hdump_text_row itm) {
|
||||
bry_rdr.Src_(itm.Meta());
|
||||
int img_id = itm.Sub_id();
|
||||
byte[] img_src = bry_rdr.Read_bry_to_pipe();
|
||||
int img_w = bry_rdr.Read_int_to_pipe();
|
||||
int img_h = bry_rdr.Read_int_to_pipe();
|
||||
Hdump_img_itm img_itm = new Hdump_img_itm(img_id, img_src, img_w, img_h);
|
||||
img_itms.Add(img_itm);
|
||||
}
|
||||
}
|
||||
38
400_xowa/src/gplx/xowa/dbs/hdumps/Hdump_page_itm.java
Normal file
38
400_xowa/src/gplx/xowa/dbs/hdumps/Hdump_page_itm.java
Normal file
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.dbs.hdumps; import gplx.*; import gplx.xowa.*; import gplx.xowa.dbs.*;
|
||||
public class Hdump_page_itm {
|
||||
public int Page_id() {return page_id;} private int page_id;
|
||||
public byte[] Page_url() {return page_url;} private byte[] page_url;
|
||||
public int Version_id() {return version_id;} public void Version_id_(int v) {version_id = v;} private int version_id;
|
||||
public byte[] Page_body() {return page_body;} private byte[] page_body;
|
||||
public byte[] Display_ttl() {return display_ttl;} private byte[] display_ttl;
|
||||
public byte[] Content_sub() {return content_sub;} private byte[] content_sub;
|
||||
public byte[][] Sidebar_divs() {return sidebar_divs;} private byte[][] sidebar_divs;
|
||||
public Hdump_img_itm[] Img_itms() {return img_itms;} private Hdump_img_itm[] img_itms;
|
||||
public void Init(int page_id, byte[] page_url, int version_id, byte[] display_ttl, byte[] content_sub, byte[] page_body, byte[][] sidebar_divs, Hdump_img_itm[] img_itms) {
|
||||
this.page_id = page_id;
|
||||
this.page_url = page_url;
|
||||
this.version_id = version_id;
|
||||
this.display_ttl = display_ttl;
|
||||
this.content_sub = content_sub;
|
||||
this.page_body = page_body;
|
||||
this.sidebar_divs = sidebar_divs;
|
||||
this.img_itms = img_itms;
|
||||
}
|
||||
}
|
||||
47
400_xowa/src/gplx/xowa/dbs/hdumps/Hdump_page_itm_save.java
Normal file
47
400_xowa/src/gplx/xowa/dbs/hdumps/Hdump_page_itm_save.java
Normal file
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
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.dbs.hdumps; import gplx.*; import gplx.xowa.*; import gplx.xowa.dbs.*;
|
||||
import gplx.dbs.*; import gplx.xowa.pages.*; import gplx.xowa.pages.skins.*;
|
||||
class Hdump_page_itm_save {
|
||||
private Bry_bfr tmp_bfr = Bry_bfr.reset_(10 * Io_mgr.Len_mb);
|
||||
private Hdump_text_tbl text_tbl = new Hdump_text_tbl();
|
||||
private Hdump_db_mgr text_db_mgr = new Hdump_db_mgr();
|
||||
public void Insert(Db_provider provider, Xoa_page page) {
|
||||
int page_id = page.Revision_data().Id();
|
||||
Xopg_html_data html_data = page.Html_data();
|
||||
text_tbl.Insert(provider, text_db_mgr.Next_insert_id(), page_id, Hdump_text_row_tid.Tid_body, Version_id, Bry_.Empty, Bry_.Empty);
|
||||
Insert_if_exists(provider, page_id, Hdump_text_row_tid.Tid_display_ttl, html_data.Display_ttl());
|
||||
Insert_if_exists(provider, page_id, Hdump_text_row_tid.Tid_content_sub, html_data.Content_sub());
|
||||
Insert_sidebars(provider, page_id, page, html_data.Xtn_skin_mgr());
|
||||
}
|
||||
private void Insert_if_exists(Db_provider provider, int page_id, int tid, byte[] val) {
|
||||
if (Bry_.Len_gt_0(val))
|
||||
text_tbl.Insert(provider, text_db_mgr.Next_insert_id(), page_id, tid, Version_id, Bry_.Empty, val);
|
||||
}
|
||||
private void Insert_sidebars(Db_provider provider, int page_id, Xoa_page page, Xopg_xtn_skin_mgr xtn_skin_mgr) {
|
||||
int len = xtn_skin_mgr.Count();
|
||||
for (int i = 0; i < len; ++i) {
|
||||
Xopg_xtn_skin_itm itm = xtn_skin_mgr.Get_at(i);
|
||||
if (itm.Tid() == Xopg_xtn_skin_itm_tid.Tid_sidebar) {
|
||||
itm.Write(tmp_bfr, page);
|
||||
text_tbl.Insert(provider, text_db_mgr.Next_insert_id(), page_id, Hdump_text_row_tid.Tid_sidebar_div, Version_id, Bry_.Empty, tmp_bfr.XtoAryAndClear());
|
||||
}
|
||||
}
|
||||
}
|
||||
private static final int Version_id = 0;
|
||||
}
|
||||
@@ -1,104 +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.dbs.hdumps; import gplx.*; import gplx.xowa.*; import gplx.xowa.dbs.*;
|
||||
import gplx.dbs.*; import gplx.ios.*;
|
||||
public class Hdump_page_tbl {
|
||||
private Db_provider provider;
|
||||
private Db_stmt stmt_select, stmt_insert, stmt_update, stmt_delete;
|
||||
private Io_stream_zip_mgr zip_mgr; private byte zip_tid;
|
||||
public void Ctor(Io_stream_zip_mgr zip_mgr, byte zip_tid) {this.zip_mgr = zip_mgr; this.zip_tid = zip_tid;}
|
||||
public void Ctor(Db_provider provider, Io_stream_zip_mgr zip_mgr, byte zip_tid) {this.provider = provider; this.zip_mgr = zip_mgr; this.zip_tid = zip_tid;}
|
||||
@gplx.Virtual public void Insert(int page_id, byte[] page_html, int frags_len, int make_id) {
|
||||
if (stmt_insert == null) stmt_insert = Db_stmt_.new_insert_(provider, Tbl_name, Flds_all);
|
||||
try {
|
||||
page_html = zip_mgr.Zip(zip_tid, page_html);
|
||||
stmt_insert.Val_int_(page_id).Val_str_by_bry_(page_html).Val_int_(frags_len).Val_int_(make_id).Exec_insert();
|
||||
} finally {stmt_insert.Rls();}
|
||||
}
|
||||
@gplx.Virtual public void Insert(Db_provider provider, int page_id, byte[] page_html, int frags_len, int make_id) {
|
||||
if (stmt_insert == null) stmt_insert = Db_stmt_.new_insert_(provider, Tbl_name, Flds_all);
|
||||
try {
|
||||
page_html = zip_mgr.Zip(zip_tid, page_html);
|
||||
stmt_insert.Val_int_(page_id).Val_str_by_bry_(page_html).Val_int_(frags_len).Val_int_(make_id).Exec_insert();
|
||||
} finally {stmt_insert.Rls();}
|
||||
}
|
||||
@gplx.Virtual public void Update(Db_provider provider, int page_id, byte[] page_html, int frags_len, int make_id) {
|
||||
if (stmt_update == null) stmt_update = Db_stmt_.new_update_(provider, Tbl_name, Flds_all);
|
||||
try {
|
||||
page_html = zip_mgr.Zip(zip_tid, page_html);
|
||||
stmt_update.Val_int_(page_id).Val_str_by_bry_(page_html).Val_int_(frags_len).Val_int_(make_id).Exec_update();
|
||||
} finally {stmt_update.Rls();}
|
||||
}
|
||||
@gplx.Virtual public void Select(Db_provider provider, Hdump_page_row rv, int page_id) {
|
||||
if (stmt_select == null) stmt_select = Db_stmt_.new_select_(provider, Tbl_name, String_.Ary(Fld_page_id), Flds_all);
|
||||
try {
|
||||
DataRdr rdr = stmt_select.Val_int_(page_id).Exec_select();
|
||||
rv.Ctor
|
||||
( rdr.ReadInt(Fld_page_id)
|
||||
, zip_mgr.Unzip(zip_tid, rdr.ReadBry(Fld_page_html))
|
||||
, rdr.ReadInt(Fld_frags_len)
|
||||
, rdr.ReadInt(Fld_make_id)
|
||||
);
|
||||
rdr.Rls();
|
||||
} finally {stmt_select.Rls();}
|
||||
}
|
||||
@gplx.Virtual public void Delete(Db_provider provider, int page_id) {
|
||||
if (stmt_delete == null) stmt_delete = Db_stmt_.new_delete_(provider, Tbl_name, Fld_page_id);
|
||||
try {
|
||||
stmt_delete.Val_int_(page_id).Exec_delete();
|
||||
} finally {stmt_delete.Rls();}
|
||||
}
|
||||
@gplx.Virtual public void Delete_all(Db_provider provider) {
|
||||
Db_qry_.delete_tbl_(Tbl_name).Exec_qry(provider);
|
||||
}
|
||||
public void Rls() {
|
||||
stmt_select = stmt_insert = stmt_update = stmt_delete = null;
|
||||
zip_mgr = null;
|
||||
}
|
||||
public static final String Tbl_name = "html_page"
|
||||
, Fld_page_id = "page_id", Fld_page_html = "page_html", Fld_frags_len = "frags_len", Fld_make_id= "make_id";
|
||||
private static final String[] Flds_all = new String[] {Fld_page_id, Fld_page_html, Fld_frags_len, Fld_make_id};
|
||||
public static final String Tbl_sql = String_.Concat_lines_nl
|
||||
( "CREATE TABLE IF NOT EXISTS html_page"
|
||||
, "( page_id integer NOT NULL PRIMARY KEY"
|
||||
, ", page_html mediumblob NOT NULL"
|
||||
, ", frags_len integer NOT NULL"
|
||||
, ", make_id integer NOT NULL"
|
||||
, ");"
|
||||
);
|
||||
}
|
||||
class Hdump_page_tbl_mem extends Hdump_page_tbl { private OrderedHash hash = OrderedHash_.new_();
|
||||
@Override public void Insert(Db_provider provider, int page_id, byte[] page_html, int frags_len, int make_id) {
|
||||
Hdump_page_row row = new Hdump_page_row().Ctor(page_id, page_html, frags_len, make_id);
|
||||
hash.Add(page_id, row);
|
||||
}
|
||||
@Override public void Update(Db_provider provider, int page_id, byte[] page_html, int frags_len, int make_id) {
|
||||
Hdump_page_row row = (Hdump_page_row)hash.Fetch(page_id);
|
||||
row.Ctor(page_id, page_html, frags_len, make_id);
|
||||
}
|
||||
@Override public void Select(Db_provider provider, Hdump_page_row rv, int page_id) {
|
||||
Hdump_page_row row = (Hdump_page_row)hash.Fetch(page_id);
|
||||
rv.Ctor(row.Page_id(), row.Page_html(), row.Frags_len(), row.Make_id());
|
||||
}
|
||||
@Override public void Delete(Db_provider provider, int page_id) {
|
||||
hash.Del(page_id);
|
||||
}
|
||||
@Override public void Delete_all(Db_provider provider) {
|
||||
hash.Clear();
|
||||
}
|
||||
}
|
||||
@@ -1,86 +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.dbs.hdumps; import gplx.*; import gplx.xowa.*; import gplx.xowa.dbs.*;
|
||||
import gplx.dbs.*; import gplx.ios.*;
|
||||
public class Hdump_skin_tbl {
|
||||
private Db_stmt stmt_select, stmt_insert, stmt_update, stmt_delete;
|
||||
@gplx.Virtual public void Insert(Db_provider provider, int skin_id, byte[] skin_text) {
|
||||
if (stmt_insert == null) stmt_insert = Db_stmt_.new_insert_(provider, Tbl_name, Flds_all);
|
||||
try {
|
||||
stmt_insert.Val_int_(skin_id).Val_str_by_bry_(skin_text).Exec_insert();
|
||||
} finally {stmt_insert.Rls();}
|
||||
}
|
||||
@gplx.Virtual public void Update(Db_provider provider, int skin_id, byte[] skin_text) {
|
||||
if (stmt_update == null) stmt_update = Db_stmt_.new_update_(provider, Tbl_name, Flds_all);
|
||||
try {
|
||||
stmt_update.Val_int_(skin_id).Val_str_by_bry_(skin_text).Exec_update();
|
||||
} finally {stmt_update.Rls();}
|
||||
}
|
||||
@gplx.Virtual public void Select(Db_provider provider, Hdump_skin_row rv, int skin_id) {
|
||||
if (stmt_select == null) stmt_select = Db_stmt_.new_select_(provider, Tbl_name, String_.Ary(Fld_skin_id), Flds_all);
|
||||
try {
|
||||
DataRdr rdr = stmt_select.Val_int_(skin_id).Exec_select();
|
||||
rv.Ctor
|
||||
( rdr.ReadInt(Fld_skin_id)
|
||||
, rdr.ReadBryByStr(Fld_skin_text)
|
||||
);
|
||||
rdr.Rls();
|
||||
} finally {stmt_select.Rls();}
|
||||
}
|
||||
@gplx.Virtual public void Delete(Db_provider provider, int skin_id) {
|
||||
if (stmt_delete == null) stmt_delete = Db_stmt_.new_delete_(provider, Tbl_name, Fld_skin_id);
|
||||
try {
|
||||
stmt_delete.Val_int_(skin_id).Exec_delete();
|
||||
} finally {stmt_delete.Rls();}
|
||||
}
|
||||
@gplx.Virtual public void Delete_all(Db_provider provider) {
|
||||
Db_qry_.delete_tbl_(Tbl_name).Exec_qry(provider);
|
||||
}
|
||||
public void Rls() {
|
||||
stmt_select = stmt_insert = stmt_update = stmt_delete = null;
|
||||
}
|
||||
public static final String Tbl_name = "html_skin"
|
||||
, Fld_skin_id = "skin_id", Fld_skin_text = "skin_text";
|
||||
private static final String[] Flds_all = new String[] {Fld_skin_id, Fld_skin_text};
|
||||
public static final String Tbl_sql = String_.Concat_lines_nl
|
||||
( "CREATE TABLE IF NOT EXISTS html_skin"
|
||||
, "( skin_id integer NOT NULL PRIMARY KEY"
|
||||
, ", skin_text mediumblob NOT NULL"
|
||||
, ");"
|
||||
);
|
||||
}
|
||||
class Hdump_skin_tbl_mem extends Hdump_skin_tbl { private OrderedHash hash = OrderedHash_.new_();
|
||||
@Override public void Insert(Db_provider provider, int skin_id, byte[] skin_text) {
|
||||
Hdump_skin_row row = new Hdump_skin_row().Ctor(skin_id, skin_text);
|
||||
hash.Add(skin_id, row);
|
||||
}
|
||||
@Override public void Update(Db_provider provider, int skin_id, byte[] skin_text) {
|
||||
Hdump_skin_row row = (Hdump_skin_row)hash.Fetch(skin_id);
|
||||
row.Ctor(skin_id, skin_text);
|
||||
}
|
||||
@Override public void Select(Db_provider provider, Hdump_skin_row rv, int skin_id) {
|
||||
Hdump_skin_row row = (Hdump_skin_row)hash.Fetch(skin_id);
|
||||
rv.Ctor(row.Skin_id(), row.Skin_html());
|
||||
}
|
||||
@Override public void Delete(Db_provider provider, int skin_id) {
|
||||
hash.Del(skin_id);
|
||||
}
|
||||
@Override public void Delete_all(Db_provider provider) {
|
||||
hash.Clear();
|
||||
}
|
||||
}
|
||||
34
400_xowa/src/gplx/xowa/dbs/hdumps/Hdump_text_row.java
Normal file
34
400_xowa/src/gplx/xowa/dbs/hdumps/Hdump_text_row.java
Normal file
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
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.dbs.hdumps; import gplx.*; import gplx.xowa.*; import gplx.xowa.dbs.*;
|
||||
class Hdump_text_row {
|
||||
public int Id() {return id;} private int id;
|
||||
public int Page_id() {return page_id;} private int page_id;
|
||||
public int Tid() {return tid;} private int tid;
|
||||
public int Version() {return version;} private int version;
|
||||
public byte[] Meta() {return meta;} private byte[] meta;
|
||||
public byte[] Data() {return data;} private byte[] data;
|
||||
public int Sub_id() {return sub_id;} public void Sub_id_(int v) {sub_id = v;} private int sub_id;
|
||||
public Hdump_text_row Init(int id, int page_id, int tid, int version, byte[] meta, byte[] data) {
|
||||
this.id = id; this.page_id = page_id; this.tid = tid; this.version = version; this.meta = meta; this.data = data;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
class Hdump_text_row_tid {
|
||||
public static final int Tid_body = 0, Tid_img = 1, Tid_display_ttl = 2, Tid_content_sub = 3, Tid_sidebar_div = 4;
|
||||
}
|
||||
81
400_xowa/src/gplx/xowa/dbs/hdumps/Hdump_text_tbl.java
Normal file
81
400_xowa/src/gplx/xowa/dbs/hdumps/Hdump_text_tbl.java
Normal file
@@ -0,0 +1,81 @@
|
||||
/*
|
||||
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.dbs.hdumps; import gplx.*; import gplx.xowa.*; import gplx.xowa.dbs.*;
|
||||
import gplx.dbs.*;
|
||||
class Hdump_text_tbl {
|
||||
private Db_stmt stmt_select, stmt_insert;//, stmt_update, stmt_delete;
|
||||
@gplx.Virtual public void Insert(Db_provider provider, int id, int page_id, int tid, int version, byte[] meta, byte[] data) {
|
||||
if (stmt_insert == null) stmt_insert = Db_stmt_.new_insert_(provider, Tbl_name, Flds_all);
|
||||
stmt_insert.Val_int_(id).Val_int_(page_id).Val_int_(tid).Val_int_(version).Val_str_by_bry_(meta).Val_str_by_bry_(data).Exec_insert();
|
||||
}
|
||||
@gplx.Virtual public void Select_by_page(ListAdp rv, Db_provider provider, int page_id) {
|
||||
if (stmt_select == null) stmt_select = Db_stmt_.new_select_(provider, Tbl_name, String_.Ary(Fld_page_id), Flds_all);
|
||||
try {
|
||||
DataRdr rdr = stmt_select.Val_int_(page_id).Exec_select();
|
||||
while(rdr.MoveNextPeer()) {
|
||||
Hdump_text_row row = new Hdump_text_row().Init
|
||||
( rdr.ReadInt(Fld_text_id)
|
||||
, rdr.ReadInt(Fld_page_id)
|
||||
, rdr.ReadInt(Fld_text_tid)
|
||||
, rdr.ReadInt(Fld_text_version)
|
||||
, rdr.ReadBryByStr(Fld_text_meta)
|
||||
, rdr.ReadBryByStr(Fld_text_data)
|
||||
);
|
||||
rv.Add(row);
|
||||
}
|
||||
rdr.Rls();
|
||||
} finally {stmt_select.Rls();}
|
||||
}
|
||||
public static final String Tbl_name = "html_text"
|
||||
, Fld_text_id = "text_id", Fld_page_id = "page_id", Fld_text_tid = "text_tid", Fld_text_version = "text_version"
|
||||
, Fld_text_meta = "text_meta", Fld_text_data = "text_data";
|
||||
private static final String[] Flds_all = new String[] {Fld_text_id, Fld_page_id, Fld_text_tid, Fld_text_version, Fld_text_meta, Fld_text_data};
|
||||
public static final String Tbl_sql = String_.Concat_lines_nl
|
||||
( "CREATE TABLE IF NOT EXISTS html_text"
|
||||
, "( text_id integer NOT NULL PRIMARY KEY"
|
||||
, ", page_id integer NOT NULL"
|
||||
, ", text_tid integer NOT NULL"
|
||||
, ", text_version integer NOT NULL"
|
||||
, ", text_meta varchar(4000) NOT NULL"
|
||||
, ", text_data mediumblob NOT NULL"
|
||||
, ");"
|
||||
);
|
||||
}
|
||||
class Hdump_text_tbl_mem extends Hdump_text_tbl { private HashAdp pages = HashAdp_.new_();
|
||||
@Override public void Insert(Db_provider provider, int id, int page_id, int tid, int version, byte[] meta, byte[] data) {
|
||||
Hdump_text_row row = new Hdump_text_row().Init(id, page_id, tid, version, meta, data);
|
||||
ListAdp rows = Get_or_new(pages, page_id);
|
||||
rows.Add(row);
|
||||
}
|
||||
@Override public void Select_by_page(ListAdp rv, Db_provider provider, int page_id) {
|
||||
ListAdp rows = Get_or_new(pages, page_id);
|
||||
int len = rows.Count();
|
||||
for (int i = 0; i < len; ++i) {
|
||||
Hdump_text_row row = (Hdump_text_row)rows.FetchAt(i);
|
||||
rv.Add(row);
|
||||
}
|
||||
}
|
||||
private static ListAdp Get_or_new(HashAdp pages, int page_id) {
|
||||
ListAdp rv = (ListAdp)pages.Fetch(page_id);
|
||||
if (rv == null) {
|
||||
rv = ListAdp_.new_();
|
||||
pages.Add(page_id, rv);
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
/*
|
||||
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.dbs.hdumps.html; import gplx.*; import gplx.xowa.*; import gplx.xowa.dbs.*; import gplx.xowa.dbs.hdumps.*;
|
||||
import gplx.core.btries.*;
|
||||
class Hdump_html_fmtr__body implements Bry_fmtr_arg {
|
||||
private Bry_rdr bry_rdr = new Bry_rdr();
|
||||
private Hdump_page_itm page;
|
||||
private Gfo_usr_dlg usr_dlg; private byte[] app_dir = Bry_.Empty;
|
||||
public void Init_by_app(Gfo_usr_dlg usr_dlg, byte[] app_dir) {this.usr_dlg = usr_dlg; this.app_dir = app_dir;}
|
||||
public void Init_by_page(Hdump_page_itm page) {this.page = page;}
|
||||
public void XferAry(Bry_bfr bfr, int idx) {
|
||||
byte[] src = page.Page_body(); int len = src.length;
|
||||
Hdump_img_itm[] imgs = page.Img_itms(); int imgs_len = page.Img_itms().length;
|
||||
bry_rdr.Src_(src);
|
||||
int pos = 0; int rng_bgn = -1;
|
||||
while (pos < len) {
|
||||
byte b = src[pos];
|
||||
Object o = trie.Match_bgn_w_byte(b, src, pos, len);
|
||||
if (o == null) {
|
||||
if (rng_bgn == -1) rng_bgn = pos;
|
||||
}
|
||||
else {
|
||||
if (rng_bgn != -1) {
|
||||
bfr.Add_mid(src, rng_bgn, pos);
|
||||
rng_bgn = -1;
|
||||
}
|
||||
byte tid = ((Byte_obj_val)o).Val();
|
||||
pos = trie.Match_pos(); // position after match; EX: "~{xo.img." positions after "."
|
||||
switch (tid) {
|
||||
case Tid_app_dir: bfr.Add(app_dir); break;
|
||||
case Tid_img: pos = Write_img(bfr, page, src, imgs, imgs_len, pos); break;
|
||||
}
|
||||
++pos; // + 1 to skip trailing }
|
||||
}
|
||||
}
|
||||
if (rng_bgn != -1) bfr.Add_mid(src, rng_bgn, len);
|
||||
}
|
||||
private int Write_img(Bry_bfr bfr, Hdump_page_itm page, byte[] src, Hdump_img_itm[] imgs, int imgs_len, int idx_bgn) {
|
||||
int idx_val = bry_rdr.Read_int_to(Byte_ascii.Curly_end);
|
||||
int idx_end = bry_rdr.Pos();
|
||||
if (idx_val == bry_rdr.Or_int()) {usr_dlg.Warn_many("", "", "index is not a valid int; page=~{0} text=~{1}", page.Page_url(), Bry_.Mid(src, idx_bgn, idx_end)); return idx_end;}
|
||||
if (!Int_.Between(idx_val, 0, imgs_len)) {usr_dlg.Warn_many("", "", "index is out of range; page=~{0} idx=~{1} len=~{2}", page.Page_url(), idx_val, imgs_len); return idx_end;}
|
||||
imgs[idx_val].Write_html(bfr);
|
||||
return idx_end;
|
||||
}
|
||||
private static final byte Tid_app_dir = 0, Tid_img = 1;
|
||||
private Btrie_slim_mgr trie = Btrie_slim_mgr.cs_()
|
||||
.Add_str_byte("~{xo.dir" , Tid_app_dir)
|
||||
.Add_str_byte("~{xo.img." , Tid_img)
|
||||
;
|
||||
}
|
||||
@@ -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.dbs.hdumps.html; import gplx.*; import gplx.xowa.*; import gplx.xowa.dbs.*; import gplx.xowa.dbs.hdumps.*;
|
||||
class Hdump_html_fmtr__sidebars implements Bry_fmtr_arg {
|
||||
private Hdump_page_itm page;
|
||||
public void Init_by_page(Hdump_page_itm page) {this.page = page;}
|
||||
public void XferAry(Bry_bfr bfr, int idx) {
|
||||
byte[][] sidebar_divs = page.Sidebar_divs();
|
||||
int sidebar_divs_len = sidebar_divs.length;
|
||||
for (int i = 0; i < sidebar_divs_len; ++i) {
|
||||
byte[] sidebar_div = sidebar_divs[i];
|
||||
bfr.Add(sidebar_div);
|
||||
}
|
||||
}
|
||||
}
|
||||
28
400_xowa/src/gplx/xowa/dbs/hdumps/html/Hdump_html_mgr.java
Normal file
28
400_xowa/src/gplx/xowa/dbs/hdumps/html/Hdump_html_mgr.java
Normal file
@@ -0,0 +1,28 @@
|
||||
/*
|
||||
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.dbs.hdumps.html; import gplx.*; import gplx.xowa.*; import gplx.xowa.dbs.*; import gplx.xowa.dbs.hdumps.*;
|
||||
class Hdump_html_mgr {
|
||||
private Hdump_html_fmtr__sidebars sidebars_fmtr = new Hdump_html_fmtr__sidebars();
|
||||
private Hdump_html_fmtr__body body_fmtr = new Hdump_html_fmtr__body();
|
||||
public void Init_by_app(Gfo_usr_dlg usr_dlg, byte[] app_dir) {body_fmtr.Init_by_app(usr_dlg, app_dir);}
|
||||
public void Write(Bry_bfr bfr, Bry_fmtr skin_fmtr, Hdump_page_itm page) {
|
||||
body_fmtr.Init_by_page(page);
|
||||
sidebars_fmtr.Init_by_page(page);
|
||||
skin_fmtr.Bld_bfr_many(bfr, page.Display_ttl(), page.Content_sub(), sidebars_fmtr, body_fmtr);
|
||||
}
|
||||
}
|
||||
@@ -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.xowa.dbs.hdumps.html; import gplx.*; import gplx.xowa.*; import gplx.xowa.dbs.*; import gplx.xowa.dbs.hdumps.*;
|
||||
import org.junit.*;
|
||||
public class Hdump_html_mgr_tst {
|
||||
@Before public void init() {fxt.Clear();} private Hdump_html_mgr_fxt fxt = new Hdump_html_mgr_fxt();
|
||||
@Test public void Basic() {
|
||||
// fxt.Test_save("A b c", fxt.itm_text_("A b c"));
|
||||
}
|
||||
}
|
||||
class Hdump_html_mgr_fxt {
|
||||
public void Clear() {
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user