1
0
mirror of https://github.com/gnosygnu/xowa.git synced 2026-03-02 03:49:30 +00:00

Xtns.TemplateStyles: Cache TemplateStyles for HTML databases [#482]

This commit is contained in:
gnosygnu
2019-06-02 12:50:56 -04:00
parent fbe158537e
commit 3d9491e2de
29 changed files with 725 additions and 31 deletions

View File

@@ -0,0 +1,31 @@
/*
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.template_styles; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
import gplx.dbs.*;
import gplx.xowa.htmls.*;
import gplx.xowa.htmls.hxtns.pages.*; import gplx.xowa.htmls.hxtns.blobs.*; import gplx.xowa.htmls.hxtns.wikis.*;
public class Hxtn_page_wkr__template_styles implements Hxtn_page_wkr {
private final Hxtn_blob_tbl page_text_tbl;
public int Id() {return Hxtn_page_mgr.Id__template_styles;}
public String Key() {return "xowa.xtns.template_styles";}
public Hxtn_page_wkr__template_styles(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[] template_bry = page_text_tbl.Select_text(Hxtn_blob_tbl.Blob_tid__wtxt, Hxtn_wiki_itm.Tid__self, page_id);
hpg.Html_data().Custom_head_tags().Add(gplx.xowa.wikis.pages.tags.Xopg_tag_itm.New_css_code(template_bry));
}
}

View File

@@ -0,0 +1,26 @@
/*
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.template_styles; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
import gplx.xowa.addons.*;
import gplx.xowa.bldrs.wkrs.*;
public class Template_styles_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 Hxtn_page_wkr__template_styles(wiki.Hxtn_mgr().Blob_tbl()));
}
public String Addon__key() {return "xowa.template_styles";}
}

View File

@@ -15,15 +15,17 @@ Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.xowa.xtns.template_styles; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
import gplx.core.primitives.*;
import gplx.core.lists.hashs.*;
import gplx.xowa.wikis.caches.*;
import gplx.xowa.htmls.core.htmls.*; import gplx.xowa.parsers.htmls.*; import gplx.xowa.htmls.heads.*;
import gplx.xowa.parsers.*; import gplx.xowa.parsers.xndes.*;
import gplx.xowa.htmls.hxtns.*; import gplx.xowa.htmls.hxtns.pages.*; import gplx.xowa.htmls.hxtns.blobs.*; import gplx.xowa.htmls.hxtns.wikis.*;
import gplx.xowa.wikis.nss.*;
public class Template_styles_nde implements Xox_xnde, Mwh_atr_itm_owner2 {
private byte[] css_ttl_bry;
private byte[] css_src;
private boolean css_ignore;
private Int_obj_val css_page_id;
private int css_page_id;
private Xoa_ttl css_ttl;
public void Xatr__set(Xowe_wiki wiki, byte[] src, Mwh_atr_itm xatr, byte xatr_id) {
switch (xatr_id) {
@@ -50,22 +52,21 @@ public class Template_styles_nde implements Xox_xnde, Mwh_atr_itm_owner2 {
Xow_page_cache_itm page_itm = wiki.Cache_mgr().Page_cache().Get_or_load_as_itm_2(css_ttl);
if (page_itm != null) {
css_src = page_itm.Wtxt__direct();
css_page_id = new Int_obj_val(page_itm.Page_id());
css_page_id = page_itm.Page_id();
// update css_page_ids
Hash_adp css_page_ids = (Hash_adp)ctx.Page().Kv_data().Get_or_make(Template_styles_kv_itm.Instance);
if (css_page_ids.Has(css_page_id)) {
css_ignore = true;
Hash_adp__int css_page_ids = (Hash_adp__int)ctx.Page().Kv_data().Get_or_make(Template_styles_kv_itm.Instance);
if (css_page_ids.Get_by_or_null(css_page_id) == null) {
css_page_ids.Add(css_page_id, "");
}
else {
css_page_ids.Add_as_key_and_val(css_page_id);
css_ignore = true;
}
}
if (css_src == null) {
Gfo_usr_dlg_.Instance.Warn_many("", "", "Template_styles_nde.page_not_found: wiki=~{0} page=~{1} css_ttl=~{2}", wiki.Domain_bry(), ctx.Page().Url_bry_safe(), css_ttl_bry);
}
}
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 (css_ttl == null) {
@@ -80,11 +81,18 @@ public class Template_styles_nde implements Xox_xnde, Mwh_atr_itm_owner2 {
if (!css_ignore) {
Bry_bfr tmp_bfr = ctx.Wiki().Utl__bfr_mkr().Get_b512();
try {
html_head.Bld_many(tmp_bfr, css_page_id.Val(), css_src);
html_head.Bld_many(tmp_bfr, css_page_id, css_src);
Xoh_head_itm__css_dynamic css_dynamic = ctx.Page().Html_data().Head_mgr().Itm__css_dynamic();
css_dynamic.Enabled_y_();
css_dynamic.Add(tmp_bfr.To_bry_and_clear());
} finally {tmp_bfr.Mkr_rls();}
if (hctx.Mode_is_hdump()) {
int page_id = wpg.Db().Page().Id();
Hxtn_page_mgr html_data_mgr = wpg.Wikie().Hxtn_mgr();
html_data_mgr.Page_tbl__insert(page_id, Hxtn_page_mgr.Id__template_styles, css_page_id);
html_data_mgr.Blob_tbl__insert(Hxtn_blob_tbl.Blob_tid__wtxt, Hxtn_wiki_itm.Tid__self, css_page_id, css_src);
}
}
}
private static String formatTagError(String msg) {
@@ -102,6 +110,6 @@ public class Template_styles_nde implements Xox_xnde, Mwh_atr_itm_owner2 {
}
class Template_styles_kv_itm implements gplx.xowa.apps.kvs.Xoa_kv_itm {
public String Kv__key() {return "TemplateStyles";}
public Object Kv__val_make() {return Hash_adp_.New();}
public Object Kv__val_make() {return new Hash_adp__int();}
public static final Template_styles_kv_itm Instance = new Template_styles_kv_itm(); Template_styles_kv_itm() {}
}