mirror of
https://github.com/gnosygnu/xowa.git
synced 2024-10-27 20:34:16 +00:00
Hdump: Serialize / deserialize top-icon [#721]
This commit is contained in:
parent
dc66b926d3
commit
0cdfa0992c
@ -1,18 +1,18 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.core.texts; import gplx.*; import gplx.core.*;
|
||||
public class Base64Converter {
|
||||
private final static char[] ALPHABET = String_.XtoCharAry("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/");
|
||||
@ -22,6 +22,11 @@ public class Base64Converter {
|
||||
for(int i=0; i< ALPHABET.length; i++){
|
||||
toInt[ALPHABET[i]]= i;
|
||||
}
|
||||
}
|
||||
public static char GetIndexChar(int i) {return ALPHABET[i];}
|
||||
public static int GetIndexInt(char c) {
|
||||
if (toInt == null) Init();
|
||||
return toInt[c];
|
||||
}
|
||||
public static String EncodeString(String orig) {return Encode(Bry_.new_u8(orig));}
|
||||
public static String Encode(byte[] buf){
|
||||
|
46
400_xowa/src/gplx/core/serials/binarys/BinaryLoadMgr.java
Normal file
46
400_xowa/src/gplx/core/serials/binarys/BinaryLoadMgr.java
Normal file
@ -0,0 +1,46 @@
|
||||
package gplx.core.serials.binarys;
|
||||
|
||||
import gplx.Bry_;
|
||||
import gplx.core.serials.core.SerialLoadMgr;
|
||||
import gplx.core.serials.core.SerialLoadWkr;
|
||||
import gplx.core.texts.Base64Converter;
|
||||
|
||||
public class BinaryLoadMgr implements SerialLoadMgr {
|
||||
public static final int CORE_VERSION = 0;
|
||||
private byte[] data;
|
||||
private int headerEnd;
|
||||
private int dataVersion;
|
||||
|
||||
@Override
|
||||
public int CoreVersion() {
|
||||
return CORE_VERSION;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int DataVersion() {return dataVersion;}
|
||||
|
||||
@Override
|
||||
public void ReadHeader(byte[] data) {
|
||||
this.data = data;
|
||||
this.dataVersion = Base64Converter.GetIndexInt((char)data[1]);
|
||||
this.headerEnd = 3; // 1=coreVersion; 2=dataVersion; 3=\n
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] Data() {
|
||||
return data;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int HeaderEnd() {
|
||||
return headerEnd;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SerialLoadWkr NewLoadWkr() {
|
||||
return new BinaryLoadWkr().Ctor(this);
|
||||
}
|
||||
|
||||
public byte[] FldDlm() {return fldDlm;} private final byte[] fldDlm = Bry_.new_a7("|");
|
||||
public byte[] RowDlm() {return rowDlm;} private final byte[] rowDlm = Bry_.new_a7("\n");
|
||||
}
|
75
400_xowa/src/gplx/core/serials/binarys/BinaryLoadWkr.java
Normal file
75
400_xowa/src/gplx/core/serials/binarys/BinaryLoadWkr.java
Normal file
@ -0,0 +1,75 @@
|
||||
package gplx.core.serials.binarys;
|
||||
|
||||
import gplx.Bry_;
|
||||
import gplx.Bry_find_;
|
||||
import gplx.Err_;
|
||||
import gplx.String_;
|
||||
import gplx.core.serials.core.SerialLoadMgr;
|
||||
import gplx.core.serials.core.SerialLoadWkr;
|
||||
|
||||
public class BinaryLoadWkr implements SerialLoadWkr {
|
||||
private BinaryLoadMgr mgr;
|
||||
private byte[] fldDlm;
|
||||
private byte[] rowDlm;
|
||||
private byte[] src;
|
||||
private int srcLen;
|
||||
private int cur;
|
||||
|
||||
@Override
|
||||
public SerialLoadWkr Ctor(SerialLoadMgr mgrObj) {
|
||||
this.mgr = (BinaryLoadMgr)mgrObj;
|
||||
this.fldDlm = mgr.FldDlm();
|
||||
this.rowDlm = mgr.RowDlm();
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void Init(byte[] src, int cur) {
|
||||
this.src = src;
|
||||
this.srcLen = src.length;
|
||||
this.cur = cur;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String LoadStr() {
|
||||
return String_.new_u8(LoadBry());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int LoadInt() {
|
||||
return LoadInt(rowDlm);
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] LoadBry() {
|
||||
int bryLen = LoadInt(fldDlm);
|
||||
|
||||
// extract bry
|
||||
int bryBgn = cur;
|
||||
int bryEnd = bryBgn + bryLen;
|
||||
if (bryEnd > srcLen) {
|
||||
throw Err_.new_wo_type(String_.Format("End position is out of bounds; src={0} currentPosition={1} byteArrayLength={2} remainder={3}", src, cur, bryLen, Bry_.Mid(src, bryBgn, bryEnd)));
|
||||
}
|
||||
cur = bryEnd + rowDlm.length;
|
||||
|
||||
return Bry_.Mid(src, bryBgn, bryEnd);
|
||||
}
|
||||
|
||||
private int LoadInt(byte[] dlm) {
|
||||
int bgn = cur;
|
||||
|
||||
// find position of delimiter
|
||||
int end = Bry_find_.Find_fwd(src, dlm, cur, srcLen);
|
||||
if (end == Bry_find_.Not_found) {
|
||||
throw Err_.new_wo_type(String_.Format("Failed to find delimiter for integer's end position; src={0} currentPosition={1} delimiter={2}", src, cur, fldDlm));
|
||||
}
|
||||
cur = end + dlm.length;
|
||||
|
||||
// parse int
|
||||
int val = Bry_.To_int_or(src, bgn, end, -1);
|
||||
if (val == -1) {
|
||||
throw Err_.new_wo_type(String_.Format("Failed to parse integer; src={0} currentPosition={1} string={2}", src, cur, Bry_.Mid(src, bgn, end)));
|
||||
}
|
||||
return val;
|
||||
}
|
||||
}
|
16
400_xowa/src/gplx/core/serials/binarys/BinarySaveMgr.java
Normal file
16
400_xowa/src/gplx/core/serials/binarys/BinarySaveMgr.java
Normal file
@ -0,0 +1,16 @@
|
||||
package gplx.core.serials.binarys;
|
||||
|
||||
import gplx.Bry_;
|
||||
import gplx.core.serials.core.SerialSaveMgr;
|
||||
import gplx.core.serials.core.SerialSaveWkr;
|
||||
|
||||
public class BinarySaveMgr implements SerialSaveMgr {
|
||||
public int CoreVersion() {return BinaryLoadMgr.CORE_VERSION;}
|
||||
public byte[] FldDlm() {return fldDlm;} private final byte[] fldDlm = Bry_.new_a7("|");
|
||||
public byte[] RowDlm() {return rowDlm;} private final byte[] rowDlm = Bry_.new_a7("\n");
|
||||
|
||||
@Override
|
||||
public SerialSaveWkr NewSaveWkr() {
|
||||
return new BinarySaveWkr().Ctor(this);
|
||||
}
|
||||
}
|
60
400_xowa/src/gplx/core/serials/binarys/BinarySaveWkr.java
Normal file
60
400_xowa/src/gplx/core/serials/binarys/BinarySaveWkr.java
Normal file
@ -0,0 +1,60 @@
|
||||
package gplx.core.serials.binarys;
|
||||
|
||||
import gplx.Bry_;
|
||||
import gplx.Bry_bfr;
|
||||
import gplx.Bry_bfr_;
|
||||
import gplx.core.serials.core.SerialSaveMgr;
|
||||
import gplx.core.serials.core.SerialSaveWkr;
|
||||
import gplx.core.texts.Base64Converter;
|
||||
|
||||
public class BinarySaveWkr implements SerialSaveWkr {
|
||||
private byte[] fldDlm;
|
||||
private byte[] rowDlm;
|
||||
private BinarySaveMgr mgr;
|
||||
private final Bry_bfr bfr = Bry_bfr_.New();
|
||||
|
||||
@Override
|
||||
public SerialSaveWkr Ctor(SerialSaveMgr mgrObj) {
|
||||
this.mgr = (BinarySaveMgr)mgrObj;
|
||||
this.fldDlm = mgr.FldDlm();
|
||||
this.rowDlm = mgr.RowDlm();
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void Init() {
|
||||
bfr.Clear();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void SaveHdr(int dataVersion) {
|
||||
// EX: AA -> SerialCoreMgrID+DataVersionID
|
||||
bfr.Add_byte((byte)Base64Converter.GetIndexChar(mgr.CoreVersion()));
|
||||
bfr.Add_byte((byte)Base64Converter.GetIndexChar(dataVersion)).Add(rowDlm);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void SaveInt(int val) {
|
||||
SaveInt(val, rowDlm);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void SaveStr(String val) {
|
||||
this.SaveBry(Bry_.new_u8(val));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void SaveBry(byte[] val) {
|
||||
SaveInt(val.length, fldDlm);
|
||||
bfr.Add(val).Add(rowDlm);
|
||||
}
|
||||
|
||||
private void SaveInt(int val, byte[] dlm) {
|
||||
bfr.Add_int_variable(val).Add(dlm);
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] ToBry() {
|
||||
return bfr.To_bry();
|
||||
}
|
||||
}
|
24
400_xowa/src/gplx/core/serials/core/SerialCoreFactory.java
Normal file
24
400_xowa/src/gplx/core/serials/core/SerialCoreFactory.java
Normal file
@ -0,0 +1,24 @@
|
||||
package gplx.core.serials.core;
|
||||
|
||||
import gplx.Err_;
|
||||
import gplx.core.serials.binarys.BinaryLoadMgr;
|
||||
import gplx.core.serials.binarys.BinarySaveMgr;
|
||||
import gplx.core.texts.Base64Converter;
|
||||
|
||||
public class SerialCoreFactory {
|
||||
public static SerialSaveMgr NewSaveMgr(int coreVersion) {
|
||||
if (coreVersion == BinaryLoadMgr.CORE_VERSION) {
|
||||
return new BinarySaveMgr();
|
||||
}
|
||||
throw Err_.new_unhandled_default(coreVersion);
|
||||
}
|
||||
public static SerialLoadMgr NewLoadMgr(byte[] data) {
|
||||
int coreVersion = Base64Converter.GetIndexInt((char)data[0]);
|
||||
if (coreVersion == BinaryLoadMgr.CORE_VERSION) {
|
||||
BinaryLoadMgr loadMgr = new BinaryLoadMgr();
|
||||
loadMgr.ReadHeader(data);
|
||||
return loadMgr;
|
||||
}
|
||||
throw Err_.new_unhandled_default(coreVersion);
|
||||
}
|
||||
}
|
10
400_xowa/src/gplx/core/serials/core/SerialLoadMgr.java
Normal file
10
400_xowa/src/gplx/core/serials/core/SerialLoadMgr.java
Normal file
@ -0,0 +1,10 @@
|
||||
package gplx.core.serials.core;
|
||||
|
||||
public interface SerialLoadMgr {
|
||||
int CoreVersion();
|
||||
int DataVersion();
|
||||
SerialLoadWkr NewLoadWkr();
|
||||
void ReadHeader(byte[] data);
|
||||
byte[] Data();
|
||||
int HeaderEnd();
|
||||
}
|
9
400_xowa/src/gplx/core/serials/core/SerialLoadWkr.java
Normal file
9
400_xowa/src/gplx/core/serials/core/SerialLoadWkr.java
Normal file
@ -0,0 +1,9 @@
|
||||
package gplx.core.serials.core;
|
||||
|
||||
public interface SerialLoadWkr {
|
||||
SerialLoadWkr Ctor(SerialLoadMgr mgr);
|
||||
void Init(byte[] src, int cur);
|
||||
int LoadInt();
|
||||
byte[] LoadBry();
|
||||
String LoadStr();
|
||||
}
|
6
400_xowa/src/gplx/core/serials/core/SerialSaveMgr.java
Normal file
6
400_xowa/src/gplx/core/serials/core/SerialSaveMgr.java
Normal file
@ -0,0 +1,6 @@
|
||||
package gplx.core.serials.core;
|
||||
|
||||
public interface SerialSaveMgr {
|
||||
int CoreVersion();
|
||||
SerialSaveWkr NewSaveWkr();
|
||||
}
|
11
400_xowa/src/gplx/core/serials/core/SerialSaveWkr.java
Normal file
11
400_xowa/src/gplx/core/serials/core/SerialSaveWkr.java
Normal file
@ -0,0 +1,11 @@
|
||||
package gplx.core.serials.core;
|
||||
|
||||
public interface SerialSaveWkr {
|
||||
SerialSaveWkr Ctor(SerialSaveMgr mgr);
|
||||
void Init();
|
||||
void SaveHdr(int dataVersion);
|
||||
void SaveInt(int val);
|
||||
void SaveStr(String val);
|
||||
void SaveBry(byte[] val);
|
||||
byte[] ToBry();
|
||||
}
|
@ -1,20 +1,32 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.addons; import gplx.*; import gplx.xowa.*;
|
||||
import gplx.xowa.addons.wikis.searchs.gui.urlbars.*; import gplx.xowa.addons.wikis.searchs.gui.htmlbars.*; import gplx.xowa.addons.wikis.searchs.specials.*;
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2020 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.addons;
|
||||
|
||||
import gplx.List_adp;
|
||||
import gplx.List_adp_;
|
||||
import gplx.Ordered_hash;
|
||||
import gplx.Ordered_hash_;
|
||||
import gplx.Type_;
|
||||
import gplx.xowa.Xoa_app;
|
||||
import gplx.xowa.Xoae_app;
|
||||
import gplx.xowa.Xow_wiki;
|
||||
import gplx.xowa.addons.wikis.searchs.gui.htmlbars.Srch_htmlbar_mgr;
|
||||
import gplx.xowa.addons.wikis.searchs.gui.urlbars.Srch_urlbar_mgr;
|
||||
import gplx.xowa.addons.wikis.searchs.specials.Srch_special_cfg;
|
||||
|
||||
public class Xoax_addon_mgr {
|
||||
private final Ordered_hash hash = Ordered_hash_.New(); // LOCK: must synchronized else two search tabs will fail on startup
|
||||
public Xoax_addon_itm Itms__get_or_null(String key) {synchronized (hash) {return (Xoax_addon_itm)hash.Get_by(key);}}
|
||||
@ -63,6 +75,7 @@ public class Xoax_addon_mgr {
|
||||
, new gplx.xowa.xtns.hieros .Hiero_addon()
|
||||
, new gplx.xowa.xtns.imaps .Imap_addon()
|
||||
, new gplx.xowa.xtns.graphs .Graph_addon()
|
||||
, new gplx.xowa.xtns.indicators .Indicator_addon()
|
||||
|
||||
// specials
|
||||
, new gplx.xowa.addons.wikis.registrys .Wiki_registry_addon()
|
||||
|
@ -1,24 +1,44 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.htmls; import gplx.*; import gplx.xowa.*;
|
||||
import gplx.xowa.wikis.pages.*; import gplx.xowa.wikis.pages.skins.*; import gplx.xowa.wikis.pages.lnkis.*; import gplx.xowa.wikis.pages.redirects.*;
|
||||
import gplx.xowa.files.*;
|
||||
import gplx.xowa.langs.*;
|
||||
import gplx.xowa.htmls.heads.*; import gplx.xowa.htmls.sections.*; import gplx.xowa.addons.htmls.tocs.*;
|
||||
import gplx.xowa.wikis.pages.dbs.*; import gplx.xowa.wikis.pages.hdumps.*; import gplx.xowa.wikis.pages.htmls.*; import gplx.xowa.wikis.pages.wtxts.*;
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2020 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.htmls;
|
||||
|
||||
import gplx.Bry_;
|
||||
import gplx.Bry_bfr;
|
||||
import gplx.Guid_adp;
|
||||
import gplx.Guid_adp_;
|
||||
import gplx.Hash_adp;
|
||||
import gplx.Hash_adp_;
|
||||
import gplx.xowa.Xoa_page;
|
||||
import gplx.xowa.Xoa_page_;
|
||||
import gplx.xowa.Xoa_ttl;
|
||||
import gplx.xowa.Xoa_url;
|
||||
import gplx.xowa.Xoae_page;
|
||||
import gplx.xowa.Xow_wiki;
|
||||
import gplx.xowa.files.Xof_exec_tid;
|
||||
import gplx.xowa.htmls.heads.Xoh_head_mgr;
|
||||
import gplx.xowa.htmls.sections.Xoh_section_mgr;
|
||||
import gplx.xowa.langs.Xol_lang_itm;
|
||||
import gplx.xowa.wikis.pages.Xoa_page__commons_mgr;
|
||||
import gplx.xowa.wikis.pages.Xopg_module_mgr;
|
||||
import gplx.xowa.wikis.pages.dbs.Xopg_db_data;
|
||||
import gplx.xowa.wikis.pages.hdumps.Xopg_hdump_data;
|
||||
import gplx.xowa.wikis.pages.htmls.Xopg_html_data;
|
||||
import gplx.xowa.wikis.pages.redirects.Xopg_redirect_mgr;
|
||||
import gplx.xowa.wikis.pages.wtxts.Xopg_wtxt_data;
|
||||
|
||||
public class Xoh_page implements Xoa_page {
|
||||
// core
|
||||
public Xow_wiki Wiki() {return wiki;} private Xow_wiki wiki;
|
||||
@ -49,6 +69,7 @@ public class Xoh_page implements Xoa_page {
|
||||
public Xoh_section_mgr Section_mgr() {return section_mgr;} private final Xoh_section_mgr section_mgr = new Xoh_section_mgr();
|
||||
public Xoh_img_mgr Img_mgr() {return img_mgr;} private Xoh_img_mgr img_mgr = new Xoh_img_mgr();
|
||||
public Xopg_module_mgr Head_mgr() {return head_mgr;} private Xopg_module_mgr head_mgr = new Xopg_module_mgr();
|
||||
public Hash_adp Props() {return props;} private final Hash_adp props = Hash_adp_.New();
|
||||
|
||||
// util
|
||||
public Xoa_page__commons_mgr Commons_mgr() {return commons_mgr;} private final Xoa_page__commons_mgr commons_mgr = new Xoa_page__commons_mgr();
|
||||
@ -95,6 +116,7 @@ public class Xoh_page implements Xoa_page {
|
||||
display_ttl = content_sub = sidebar_div = Bry_.Empty;
|
||||
head_mgr.Clear(); commons_mgr.Clear();
|
||||
section_mgr.Clear(); img_mgr.Clear();
|
||||
props.Clear();
|
||||
}
|
||||
public static Xoh_page New_missing() {
|
||||
Xoh_page rv = new Xoh_page();
|
||||
|
@ -33,6 +33,8 @@ import gplx.xowa.apps.gfs.Gfs_php_converter;
|
||||
import gplx.xowa.htmls.core.Xow_hdump_mode;
|
||||
import gplx.xowa.htmls.core.htmls.Xoh_html_wtr_escaper;
|
||||
import gplx.xowa.htmls.core.htmls.Xoh_wtr_ctx;
|
||||
import gplx.xowa.htmls.hxtns.blobs.Hxtn_blob_tbl;
|
||||
import gplx.xowa.htmls.hxtns.pages.Hxtn_page_mgr;
|
||||
import gplx.xowa.htmls.portal.Xoh_page_body_cls;
|
||||
import gplx.xowa.htmls.portal.Xow_portal_mgr;
|
||||
import gplx.xowa.langs.vnts.Xol_vnt_mgr;
|
||||
@ -166,6 +168,12 @@ public class Xoh_page_wtr_wkr {
|
||||
if (wpg.Html_data().Xtn_pgbnr() != null) {
|
||||
ctx.Wiki().Xtn_mgr().Xtn_pgbnr().Write_html(wpg, ctx, hctx).Bfr_arg__add(bfr); // if pgbnr exists, write to top of html
|
||||
}
|
||||
|
||||
int page_id = wpg.Db().Page().Id();
|
||||
Hxtn_page_mgr html_data_mgr = wpg.Wikie().Hxtn_mgr();
|
||||
|
||||
wpg.Html_data().Indicators().HxtnSave(wpg.Wikie(), html_data_mgr, wpg, page_id);
|
||||
|
||||
this.Write_body(bfr, ctx, hctx, wpg);
|
||||
}
|
||||
public void Write_body(Bry_bfr bfr, Xop_ctx ctx, Xoh_wtr_ctx hctx, Xoae_page page) {
|
||||
|
@ -42,6 +42,7 @@ import gplx.xowa.wikis.pages.Xopg_module_mgr;
|
||||
import gplx.xowa.wikis.pages.htmls.Xopg_html_data;
|
||||
import gplx.xowa.wikis.pages.lnkis.Xopg_lnki_list;
|
||||
import gplx.xowa.wikis.pages.skins.Xopg_xtn_skin_itm_stub;
|
||||
import gplx.xowa.xtns.indicators.Indicator_hxtn_page_wkr;
|
||||
|
||||
public class Xow_hdump_mgr__load implements Gfo_invk {
|
||||
private final Xow_wiki wiki; private final Xoh_hzip_mgr hzip_mgr; private final Io_stream_zip_mgr zip_mgr;
|
||||
@ -123,10 +124,12 @@ public class Xow_hdump_mgr__load implements Gfo_invk {
|
||||
}
|
||||
public void Fill_page(Xoae_page wpg, Xoh_page hpg) {
|
||||
Xopg_html_data html_data = wpg.Html_data();
|
||||
|
||||
html_data.Display_ttl_(tmp_hpg.Display_ttl());
|
||||
html_data.Content_sub_(tmp_hpg.Content_sub());
|
||||
html_data.Xtn_skin_mgr().Add(new Xopg_xtn_skin_itm_stub(tmp_hpg.Sidebar_div()));
|
||||
html_data.Custom_head_tags().Add(hpg.Html_data().Custom_head_tags().To_ary());
|
||||
html_data.Indicators().Deserialise(wiki, hpg, (byte[])tmp_hpg.Props().Get_by(Indicator_hxtn_page_wkr.KEY));
|
||||
|
||||
Xoh_head_mgr wpg_head = html_data.Head_mgr();
|
||||
Xopg_module_mgr hpg_head = hpg.Head_mgr();
|
||||
|
@ -1,23 +1,36 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.htmls.hxtns.pages; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.hxtns.*;
|
||||
import gplx.dbs.*;
|
||||
import gplx.core.lists.*; import gplx.core.lists.hashs.*;
|
||||
import gplx.xowa.htmls.hxtns.pages.*; import gplx.xowa.htmls.hxtns.blobs.*; import gplx.xowa.htmls.hxtns.wkrs.*; import gplx.xowa.htmls.hxtns.wikis.*;
|
||||
import gplx.xowa.wikis.*;
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2020 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.htmls.hxtns.pages;
|
||||
|
||||
import gplx.Bry_bfr;
|
||||
import gplx.Bry_bfr_;
|
||||
import gplx.Gfo_usr_dlg_;
|
||||
import gplx.Hash_adp_bry;
|
||||
import gplx.Io_mgr;
|
||||
import gplx.Io_url;
|
||||
import gplx.List_adp;
|
||||
import gplx.core.lists.hashs.Hash_adp__int;
|
||||
import gplx.dbs.Db_conn;
|
||||
import gplx.dbs.Db_conn_bldr;
|
||||
import gplx.xowa.Xoa_ttl;
|
||||
import gplx.xowa.Xow_wiki;
|
||||
import gplx.xowa.htmls.Xoh_page;
|
||||
import gplx.xowa.htmls.hxtns.blobs.Hxtn_blob_tbl;
|
||||
import gplx.xowa.htmls.hxtns.wikis.Hxtn_wiki_mgr;
|
||||
import gplx.xowa.htmls.hxtns.wkrs.Hxtn_wkr_mgr;
|
||||
public class Hxtn_page_mgr {
|
||||
private Hxtn_page_tbl page_tbl;
|
||||
private Hxtn_blob_tbl blob_tbl;
|
||||
@ -102,5 +115,8 @@ public class Hxtn_page_mgr {
|
||||
}
|
||||
}
|
||||
private static Io_url Make_url(Xow_wiki wiki, String file_name) {return wiki.Fsys_mgr().Root_dir().GenSubFil(wiki.Domain_str() + file_name);}
|
||||
public static final int Id__template_styles = 0;
|
||||
public static final int
|
||||
Id__template_styles = 0
|
||||
, Id__indicators = 2
|
||||
;
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
Copyright (C) 2012-2020 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
@ -13,29 +13,36 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.parsers; import gplx.*; import gplx.xowa.*;
|
||||
import gplx.xowa.htmls.core.htmls.*;
|
||||
import gplx.xowa.langs.vnts.*;
|
||||
public class Xop_parser_ {
|
||||
public static final int Doc_bgn_bos = -1, Doc_bgn_char_0 = 0;
|
||||
public static byte[] Parse_text_to_html(Xowe_wiki wiki, Xop_ctx owner_ctx, Xoae_page page, byte[] src, boolean para_enabled) { // NOTE: must pass in same page instance; do not do Xoa_page_.new_(), else img_idx will get reset to 0; DATE:2015-02-08
|
||||
// init
|
||||
Xop_ctx ctx = Xop_ctx.New__sub(wiki, owner_ctx, page);
|
||||
Xop_tkn_mkr tkn_mkr = ctx.Tkn_mkr();
|
||||
Xop_root_tkn root = tkn_mkr.Root(src);
|
||||
Xop_parser parser = wiki.Parser_mgr().Main();
|
||||
|
||||
// expand template; EX: {{A}} -> wikitext
|
||||
byte[] wtxt = parser.Expand_tmpl(root, ctx, tkn_mkr, src);
|
||||
|
||||
// parse wikitext
|
||||
root.Reset();
|
||||
ctx.Para().Enabled_(para_enabled);
|
||||
parser.Parse_wtxt_to_wdom(root, ctx, ctx.Tkn_mkr(), wtxt, Xop_parser_.Doc_bgn_bos);
|
||||
|
||||
// write html
|
||||
Bry_bfr bfr = wiki.Utl__bfr_mkr().Get_b512();
|
||||
wiki.Html_mgr().Html_wtr().Write_doc(bfr, ctx, Xoh_wtr_ctx.Basic, wtxt, root);
|
||||
return bfr.To_bry_and_rls();
|
||||
}
|
||||
}
|
||||
package gplx.xowa.parsers;
|
||||
|
||||
import gplx.Bry_bfr;
|
||||
import gplx.xowa.Xoae_page;
|
||||
import gplx.xowa.Xowe_wiki;
|
||||
import gplx.xowa.htmls.core.htmls.Xoh_wtr_ctx;
|
||||
|
||||
public class Xop_parser_ {
|
||||
public static final int Doc_bgn_bos = -1, Doc_bgn_char_0 = 0;
|
||||
public static byte[] Parse_text_to_html(Xowe_wiki wiki, Xop_ctx owner_ctx, Xoae_page page, byte[] src, boolean para_enabled) {
|
||||
return Parse_text_to_html(wiki, owner_ctx, Xoh_wtr_ctx.Basic, page, src, para_enabled);
|
||||
}
|
||||
public static byte[] Parse_text_to_html(Xowe_wiki wiki, Xop_ctx owner_ctx, Xoh_wtr_ctx hctx, Xoae_page page, byte[] src, boolean para_enabled) { // NOTE: must pass in same page instance; do not do Xoa_page_.new_(), else img_idx will get reset to 0; DATE:2015-02-08
|
||||
// init
|
||||
Xop_ctx ctx = Xop_ctx.New__sub(wiki, owner_ctx, page);
|
||||
Xop_tkn_mkr tkn_mkr = ctx.Tkn_mkr();
|
||||
Xop_root_tkn root = tkn_mkr.Root(src);
|
||||
Xop_parser parser = wiki.Parser_mgr().Main();
|
||||
|
||||
// expand template; EX: {{A}} -> wikitext
|
||||
byte[] wtxt = parser.Expand_tmpl(root, ctx, tkn_mkr, src);
|
||||
|
||||
// parse wikitext
|
||||
root.Reset();
|
||||
ctx.Para().Enabled_(para_enabled);
|
||||
parser.Parse_wtxt_to_wdom(root, ctx, ctx.Tkn_mkr(), wtxt, Xop_parser_.Doc_bgn_bos);
|
||||
|
||||
// write html
|
||||
Bry_bfr bfr = wiki.Utl__bfr_mkr().Get_b512();
|
||||
wiki.Html_mgr().Html_wtr().Write_doc(bfr, ctx, hctx, wtxt, root);
|
||||
return bfr.To_bry_and_rls();
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,53 @@
|
||||
package gplx.xowa.xtns.indicators;
|
||||
|
||||
import gplx.Ordered_hash;
|
||||
import gplx.Ordered_hash_;
|
||||
import gplx.core.serials.binarys.BinaryLoadMgr;
|
||||
import gplx.core.serials.core.SerialCoreFactory;
|
||||
import gplx.core.serials.core.SerialLoadMgr;
|
||||
import gplx.core.serials.core.SerialLoadWkr;
|
||||
import gplx.core.serials.core.SerialSaveMgr;
|
||||
import gplx.core.serials.core.SerialSaveWkr;
|
||||
|
||||
public class IndicatorSerialCore {
|
||||
private static final int DATA_VERSION = 0;
|
||||
|
||||
public static byte[] Save(Ordered_hash list) {
|
||||
// get wkr
|
||||
SerialSaveMgr mgr = SerialCoreFactory.NewSaveMgr(BinaryLoadMgr.CORE_VERSION);
|
||||
SerialSaveWkr wkr = mgr.NewSaveWkr();
|
||||
|
||||
// save header
|
||||
wkr.SaveHdr(DATA_VERSION);
|
||||
|
||||
// save items
|
||||
int len = list.Len();
|
||||
wkr.SaveInt(len);
|
||||
for (int i = 0; i < len; i++) {
|
||||
Indicator_xnde xnde = (Indicator_xnde)list.Get_at(i);
|
||||
wkr.SaveStr(xnde.Name());
|
||||
wkr.SaveBry(xnde.Html());
|
||||
}
|
||||
return wkr.ToBry();
|
||||
}
|
||||
|
||||
public static Ordered_hash Load(byte[] data) {
|
||||
// get wkr
|
||||
SerialLoadMgr mgr = SerialCoreFactory.NewLoadMgr(data);
|
||||
SerialLoadWkr wkr = mgr.NewLoadWkr();
|
||||
|
||||
// init
|
||||
wkr.Init(mgr.Data(), mgr.HeaderEnd());
|
||||
|
||||
// load items
|
||||
int len = wkr.LoadInt();
|
||||
Ordered_hash list = Ordered_hash_.New();
|
||||
for (int i = 0; i < len; i++) {
|
||||
Indicator_xnde xnde = new Indicator_xnde();
|
||||
xnde.Name_(wkr.LoadStr());
|
||||
xnde.Html_(wkr.LoadBry());
|
||||
list.Add_if_dupe_use_nth(xnde.Name(), xnde);
|
||||
}
|
||||
return list;
|
||||
}
|
||||
}
|
30
400_xowa/src/gplx/xowa/xtns/indicators/Indicator_addon.java
Normal file
30
400_xowa/src/gplx/xowa/xtns/indicators/Indicator_addon.java
Normal file
@ -0,0 +1,30 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2020 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.xtns.indicators;
|
||||
|
||||
import gplx.xowa.Xoa_app;
|
||||
import gplx.xowa.Xow_wiki;
|
||||
import gplx.xowa.addons.Xoax_addon_itm;
|
||||
import gplx.xowa.addons.Xoax_addon_itm__init;
|
||||
|
||||
public class Indicator_addon implements Xoax_addon_itm, Xoax_addon_itm__init {
|
||||
public void Init_addon_by_app(Xoa_app app) {}
|
||||
public void Init_addon_by_wiki(Xow_wiki wiki) {
|
||||
wiki.Hxtn_mgr().Reg_wkr(new Indicator_hxtn_page_wkr(wiki.Hxtn_mgr().Blob_tbl()));
|
||||
}
|
||||
|
||||
public String Addon__key() {return "xowa.indicators";}
|
||||
}
|
@ -1,20 +1,38 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.xtns.indicators; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
|
||||
import gplx.core.brys.fmtrs.*;
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2020 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.xtns.indicators;
|
||||
|
||||
import gplx.Bool_;
|
||||
import gplx.Bry_;
|
||||
import gplx.Bry_bfr;
|
||||
import gplx.Bry_bfr_;
|
||||
import gplx.Int_;
|
||||
import gplx.Ordered_hash;
|
||||
import gplx.Ordered_hash_;
|
||||
import gplx.String_;
|
||||
import gplx.core.brys.fmtrs.Bry_fmtr;
|
||||
import gplx.xowa.Xoae_page;
|
||||
import gplx.xowa.Xow_wiki;
|
||||
import gplx.xowa.Xowe_wiki;
|
||||
import gplx.xowa.htmls.Xoh_page;
|
||||
import gplx.xowa.htmls.core.htmls.Xoh_wtr_ctx;
|
||||
import gplx.xowa.htmls.hxtns.blobs.Hxtn_blob_tbl;
|
||||
import gplx.xowa.htmls.hxtns.pages.Hxtn_page_mgr;
|
||||
import gplx.xowa.parsers.Xop_parser_;
|
||||
|
||||
public class Indicator_html_bldr implements gplx.core.brys.Bfr_arg {
|
||||
private Indicator_html_bldr_itm bldr_itm = new Indicator_html_bldr_itm();
|
||||
private Ordered_hash list = Ordered_hash_.New();
|
||||
@ -41,6 +59,40 @@ public class Indicator_html_bldr implements gplx.core.brys.Bfr_arg {
|
||||
, " </div>"
|
||||
), "itms")
|
||||
;
|
||||
|
||||
public void HxtnSave(Xowe_wiki wiki, Hxtn_page_mgr hxtnPageMgr, Xoae_page page, int pageId) {
|
||||
// exit if empty
|
||||
int len = list.Count();
|
||||
if (len == 0) return;
|
||||
|
||||
// reparse html to generate xoimg attribute b/c indicators are parsed differently due to location above the "mw-content-text" div
|
||||
for (int i = 0; i < len; i++) {
|
||||
Indicator_xnde xnde = (Indicator_xnde)list.Get_at(i);
|
||||
byte[] html = Xop_parser_.Parse_text_to_html(wiki, wiki.Parser_mgr().Ctx(), Xoh_wtr_ctx.Hdump, page, xnde.GetHdumpSrc(), true);
|
||||
xnde.Html_(html);
|
||||
}
|
||||
|
||||
// serialize and save to db
|
||||
byte[] indicators = IndicatorSerialCore.Save(list);
|
||||
hxtnPageMgr.Page_tbl__insert(pageId, Hxtn_page_mgr.Id__indicators, pageId);
|
||||
hxtnPageMgr.Blob_tbl__insert(Hxtn_blob_tbl.Blob_tid__wtxt, Hxtn_page_mgr.Id__indicators, pageId, indicators);
|
||||
}
|
||||
|
||||
public void Deserialise(Xow_wiki wiki, Xoh_page hpg, byte[] data) {
|
||||
// exit if empty
|
||||
if (Bry_.Len_eq_0(data)) return;
|
||||
|
||||
// deserialize data
|
||||
this.list = IndicatorSerialCore.Load(data);
|
||||
|
||||
// reparse html to convert xoimg attribute to file
|
||||
int len = list.Count();
|
||||
for (int i = 0; i < len; i++) {
|
||||
Indicator_xnde xnde = (Indicator_xnde)list.Get_at(i);
|
||||
byte[] html = wiki.Html__hdump_mgr().Load_mgr().Make_mgr().Parse(xnde.Html(), wiki, hpg);
|
||||
xnde.Html_(html);
|
||||
}
|
||||
}
|
||||
}
|
||||
class Indicator_html_bldr_itm implements gplx.core.brys.Bfr_arg {
|
||||
private Ordered_hash list;
|
||||
@ -52,8 +104,7 @@ class Indicator_html_bldr_itm implements gplx.core.brys.Bfr_arg {
|
||||
fmtr_itm.Bld_bfr_many(bfr, xnde.Name(), xnde.Html());
|
||||
}
|
||||
}
|
||||
private static final Bry_fmtr
|
||||
fmtr_itm = Bry_fmtr.new_(String_.Concat_lines_nl_skip_last
|
||||
private static final Bry_fmtr fmtr_itm = Bry_fmtr.new_(String_.Concat_lines_nl_skip_last
|
||||
( ""
|
||||
, " <div id='mw-indicator-~{name}' class='mw-indicator'>~{html}</div>"
|
||||
), "name", "html")
|
||||
|
@ -0,0 +1,36 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2020 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.xtns.indicators;
|
||||
|
||||
import gplx.xowa.Xoa_ttl;
|
||||
import gplx.xowa.htmls.Xoh_page;
|
||||
import gplx.xowa.htmls.hxtns.blobs.Hxtn_blob_tbl;
|
||||
import gplx.xowa.htmls.hxtns.pages.Hxtn_page_mgr;
|
||||
import gplx.xowa.htmls.hxtns.pages.Hxtn_page_wkr;
|
||||
|
||||
public class Indicator_hxtn_page_wkr implements Hxtn_page_wkr {
|
||||
private final Hxtn_blob_tbl page_text_tbl;
|
||||
public int Id() {return Hxtn_page_mgr.Id__indicators;}
|
||||
public String Key() {return KEY;}
|
||||
public Indicator_hxtn_page_wkr(Hxtn_blob_tbl page_text_tbl) {
|
||||
this.page_text_tbl = page_text_tbl;
|
||||
}
|
||||
public void Load_by_page(Xoh_page hpg, Xoa_ttl ttl, int page_id) {
|
||||
byte[] data = page_text_tbl.Select_text(Hxtn_blob_tbl.Blob_tid__wtxt, Hxtn_page_mgr.Id__indicators, page_id);
|
||||
hpg.Props().Add(KEY, data);
|
||||
}
|
||||
public static final String KEY = "xowa.xtns.indicators";
|
||||
}
|
@ -1,25 +1,46 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.xtns.indicators; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
|
||||
import gplx.core.primitives.*; import gplx.xowa.htmls.core.htmls.*; import gplx.xowa.wikis.pages.skins.*;
|
||||
import gplx.xowa.parsers.*; import gplx.xowa.parsers.xndes.*; import gplx.xowa.parsers.htmls.*;
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2020 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.xtns.indicators;
|
||||
|
||||
import gplx.Bry_;
|
||||
import gplx.Bry_bfr;
|
||||
import gplx.Hash_adp_bry;
|
||||
import gplx.core.primitives.Byte_obj_val;
|
||||
import gplx.xowa.Xoae_app;
|
||||
import gplx.xowa.Xoae_page;
|
||||
import gplx.xowa.Xowe_wiki;
|
||||
import gplx.xowa.htmls.core.htmls.Xoh_html_wtr;
|
||||
import gplx.xowa.htmls.core.htmls.Xoh_wtr_ctx;
|
||||
import gplx.xowa.parsers.Xop_ctx;
|
||||
import gplx.xowa.parsers.Xop_parser_;
|
||||
import gplx.xowa.parsers.Xop_root_tkn;
|
||||
import gplx.xowa.parsers.htmls.Mwh_atr_itm;
|
||||
import gplx.xowa.parsers.htmls.Mwh_atr_itm_owner1;
|
||||
import gplx.xowa.parsers.xndes.Xop_xnde_tkn;
|
||||
import gplx.xowa.xtns.Xox_xnde;
|
||||
import gplx.xowa.xtns.Xox_xnde_;
|
||||
public class Indicator_xnde implements Xox_xnde, Mwh_atr_itm_owner1 {
|
||||
public String Name() {return name;} private String name;
|
||||
public byte[] Html() {return html;} private byte[] html;
|
||||
private byte[] src;
|
||||
private Xop_xnde_tkn xnde;
|
||||
public String Name() {return name;} public void Name_(String v) {this.name = v;} private String name;
|
||||
public byte[] Html() {return html;} public void Html_(byte[] v) {this.html = v;} private byte[] html;
|
||||
public void Init_for_test(String name, byte[] html) {this.name = name; this.html = html;} // TEST
|
||||
public byte[] GetHdumpSrc() {
|
||||
return Bry_.Mid(src, xnde.Tag_open_end(), xnde.Tag_close_bgn());
|
||||
}
|
||||
public void Xatr__set(Xowe_wiki wiki, byte[] src, Mwh_atr_itm xatr, Object xatr_id_obj) {
|
||||
if (xatr_id_obj == null) return;
|
||||
Byte_obj_val xatr_id = (Byte_obj_val)xatr_id_obj;
|
||||
@ -28,13 +49,15 @@ public class Indicator_xnde implements Xox_xnde, Mwh_atr_itm_owner1 {
|
||||
}
|
||||
}
|
||||
public void Xtn_parse(Xowe_wiki wiki, Xop_ctx ctx, Xop_root_tkn root, byte[] src, Xop_xnde_tkn xnde) {
|
||||
this.xnde = xnde;
|
||||
this.src = src;
|
||||
Xox_xnde_.Xatr__set(wiki, this, xatrs_hash, src, xnde);
|
||||
this.html = Xop_parser_.Parse_text_to_html(wiki, ctx, ctx.Page(), Bry_.Mid(src, xnde.Tag_open_end(), xnde.Tag_close_bgn()), false);
|
||||
Indicator_html_bldr html_bldr = ctx.Page().Html_data().Indicators();
|
||||
if (this.name != null) html_bldr.Add(this); // NOTE: must do null-check b/c Add will use Name as key for hashtable
|
||||
}
|
||||
public void Xtn_write(Bry_bfr bfr, Xoae_app app, Xop_ctx ctx, Xoh_html_wtr html_wtr, Xoh_wtr_ctx hctx, Xoae_page wpg, Xop_xnde_tkn xnde, byte[] src) {
|
||||
if (this.name == null) bfr.Add_str_a7("Error: Page status indicators' name attribute must not be empty.");
|
||||
if (this.name == null) bfr.Add_str_a7("Error: Page status indicators' name attribute must not be empty.");
|
||||
}
|
||||
private static final byte Xatr_name = 0;
|
||||
private static final Hash_adp_bry xatrs_hash = Hash_adp_bry.ci_a7()
|
||||
|
@ -0,0 +1,56 @@
|
||||
package gplx.xowa.xtns.indicators;
|
||||
|
||||
import gplx.Bry_;
|
||||
import gplx.Ordered_hash;
|
||||
import gplx.Ordered_hash_;
|
||||
import gplx.String_;
|
||||
import gplx.core.tests.Gftest;
|
||||
import org.junit.Test;
|
||||
|
||||
public class IndicatorSerialCoreTest {
|
||||
private IndicatorSerialCoreTstr tstr = new IndicatorSerialCoreTstr();
|
||||
|
||||
@Test
|
||||
public void Save() {
|
||||
tstr.TestBoth(String_.Concat_lines_nl
|
||||
( "AA"
|
||||
, "2"
|
||||
, "5|name0"
|
||||
, "5|html0"
|
||||
, "5|name1"
|
||||
, "5|html1"
|
||||
), tstr.NewXnde("name0", "html0"), tstr.NewXnde("name1", "html1"));
|
||||
}
|
||||
}
|
||||
class IndicatorSerialCoreTstr {
|
||||
public Indicator_xnde NewXnde(String name, String html) {
|
||||
Indicator_xnde xnde = new Indicator_xnde();
|
||||
xnde.Name_(name);
|
||||
xnde.Html_(Bry_.new_u8(html));
|
||||
return xnde;
|
||||
}
|
||||
|
||||
public void TestBoth(String data, Indicator_xnde... xndes) {
|
||||
byte[] save = TestSave(data, xndes);
|
||||
TestLoad(String_.new_u8(save), xndes);
|
||||
}
|
||||
public byte[] TestSave(String expd, Indicator_xnde... xndes) {
|
||||
byte[] actl = IndicatorSerialCore.Save(ToList(xndes));
|
||||
Gftest.Eq__str(expd, actl);
|
||||
return actl;
|
||||
}
|
||||
public Ordered_hash TestLoad(String data, Indicator_xnde... expd) {
|
||||
Ordered_hash list = IndicatorSerialCore.Load(Bry_.new_u8(data));
|
||||
|
||||
Gftest.Eq__bry(IndicatorSerialCore.Save(ToList(expd)), IndicatorSerialCore.Save(list)); // should probably compare items, but easier to compare seiarlization
|
||||
|
||||
return list;
|
||||
}
|
||||
private Ordered_hash ToList(Indicator_xnde[] xndes) {
|
||||
Ordered_hash list = Ordered_hash_.New();
|
||||
for (Indicator_xnde xnde : xndes) {
|
||||
list.Add_if_dupe_use_nth(xnde.Name(), xnde);
|
||||
}
|
||||
return list;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user