mirror of
https://github.com/gnosygnu/xowa.git
synced 2024-10-27 20:34:16 +00:00
HTML Databases: Allow Hzip_none for saving / loading images [#320]
This commit is contained in:
parent
739d302850
commit
4c47bb8793
@ -41,7 +41,7 @@ public class Xow_hdump_mgr {
|
||||
load_mgr.Init_by_wiki(wiki);
|
||||
}
|
||||
public void Init_by_db(byte dflt_zip_tid, boolean dflt_hzip_enable, boolean mode_is_b256) {
|
||||
int dflt_hzip_tid = dflt_hzip_enable ? Xoh_hzip_dict_.Hzip__v1 : Xoh_hzip_dict_.Hzip__plain;
|
||||
int dflt_hzip_tid = dflt_hzip_enable ? Xoh_hzip_dict_.Hzip__v1 : Xoh_hzip_dict_.Hzip__none;
|
||||
save_mgr.Init_by_db(dflt_zip_tid, dflt_hzip_tid, Bool_.N);
|
||||
}
|
||||
}
|
||||
|
@ -81,13 +81,12 @@ public class Xow_hdump_mgr__load implements Gfo_invk {
|
||||
src = zip_mgr.Unzip((byte)zip_tid, src);
|
||||
switch (hzip_tid) {
|
||||
case Xoh_hzip_dict_.Hzip__none:
|
||||
case Xoh_hzip_dict_.Hzip__plain:
|
||||
src = make_mgr.Parse(src, hpg, hpg.Wiki());
|
||||
break;
|
||||
// case Xoh_hzip_dict_.Hzip__plain:
|
||||
// gplx.xowa.addons.wikis.pages.syncs.core.loaders.Xosync_page_loader page_loader = new gplx.xowa.addons.wikis.pages.syncs.core.loaders.Xosync_page_loader();
|
||||
// src = page_loader.Parse(wiki, hpg, src);
|
||||
// break;
|
||||
case Xoh_hzip_dict_.Hzip__plain:
|
||||
gplx.xowa.addons.wikis.pages.syncs.core.loaders.Xosync_page_loader page_loader = new gplx.xowa.addons.wikis.pages.syncs.core.loaders.Xosync_page_loader();
|
||||
src = page_loader.Parse(wiki, hpg, src);
|
||||
break;
|
||||
case Xoh_hzip_dict_.Hzip__v1:
|
||||
if (override_mgr__html != null) // null when Parse is called directly
|
||||
src = override_mgr__html.Get_or_same(hpg.Ttl().Page_db(), src);
|
||||
|
@ -44,8 +44,9 @@ public class Xow_hdump_mgr__save {
|
||||
return db_body.length;
|
||||
}
|
||||
public void Bld_hdump(Xoae_page page) {
|
||||
page.File_queue().Clear(); // need to reset uid to 0, else xowa_file_# will keep incrementing upwards
|
||||
wiki.Html__wtr_mgr().Wkr(Xopg_page_.Tid_read).Write_body(tmp_bfr, page.Wikie().Parser_mgr().Ctx(), Xoh_wtr_ctx.Hdump, page); // save as hdump_fmt
|
||||
page.File_queue().Clear(); // need to reset uid to 0, else xowa_file_# will keep incrementing upwards
|
||||
Xoh_wtr_ctx hctx = Xoh_wtr_ctx.Hdump_by_hzip_tid(dflt_hzip_tid);
|
||||
wiki.Html__wtr_mgr().Wkr(Xopg_page_.Tid_read).Write_body(tmp_bfr, page.Wikie().Parser_mgr().Ctx(), hctx, page); // save as hdump_fmt
|
||||
page.Db().Html().Html_bry_(tmp_bfr.To_bry_and_clear());
|
||||
}
|
||||
private byte[] Write(Xoh_hzip_bfr bfr, Xow_wiki wiki, Xoae_page page, Xoh_page hpg, Xoh_hzip_mgr hzip_mgr, Io_stream_zip_mgr zip_mgr, int zip_tid, int hzip_tid, byte[] src) {
|
||||
|
@ -14,28 +14,39 @@ 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.core.htmls; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*;
|
||||
import gplx.xowa.htmls.core.hzips.*;
|
||||
import gplx.xowa.htmls.hrefs.*;
|
||||
public class Xoh_wtr_ctx {
|
||||
Xoh_wtr_ctx(int mode, byte[] anch__href__bgn, byte[] anch__href__end) {
|
||||
this.mode = mode; this.anch__href__bgn = anch__href__bgn; this.anch__href__end = anch__href__end;
|
||||
Xoh_wtr_ctx(int mode, int hzip_tid, byte[] anch__href__bgn, byte[] anch__href__end) {
|
||||
this.mode = mode;
|
||||
this.hzip_tid = hzip_tid;
|
||||
this.anch__href__bgn = anch__href__bgn;
|
||||
this.anch__href__end = anch__href__end;
|
||||
}
|
||||
public int Mode() {return mode;} private final int mode;
|
||||
public boolean Mode_is_alt() {return mode == Mode_alt;}
|
||||
public boolean Mode_is_display_title() {return mode == Mode_display_title;}
|
||||
public boolean Mode_is_popup() {return mode == Mode_popup;}
|
||||
public boolean Mode_is_hdump() {return mode == Mode_hdump;}
|
||||
public byte[] Anch__href__bgn() {return anch__href__bgn;} private final byte[] anch__href__bgn;
|
||||
public byte[] Anch__href__end() {return anch__href__end;} private final byte[] anch__href__end;
|
||||
public int Mode() {return mode;} private final int mode;
|
||||
public int Hzip_tid() {return hzip_tid;} private final int hzip_tid;
|
||||
public byte[] Anch__href__bgn() {return anch__href__bgn;} private final byte[] anch__href__bgn;
|
||||
public byte[] Anch__href__end() {return anch__href__end;} private final byte[] anch__href__end;
|
||||
public boolean Mode_is_hdump() {return mode == Mode_hdump;}
|
||||
public boolean Mode_is_file_dump() {return mode == Mode_hdump;}
|
||||
public boolean Mode_is_alt() {return mode == Mode_alt;}
|
||||
public boolean Mode_is_display_title() {return mode == Mode_display_title;}
|
||||
public boolean Mode_is_popup() {return mode == Mode_popup;}
|
||||
|
||||
public static final int Mode_basic = 0, Mode_alt = 1, Mode_display_title = 2, Mode_popup = 3, Mode_hdump = 4, Mode_file_dump = 5;
|
||||
|
||||
public static final Xoh_wtr_ctx
|
||||
Basic = new Xoh_wtr_ctx(Mode_basic , gplx.xowa.htmls.hrefs.Xoh_href_.Bry__wiki, null)
|
||||
, Alt = new Xoh_wtr_ctx(Mode_alt , gplx.xowa.htmls.hrefs.Xoh_href_.Bry__wiki, null)
|
||||
, Display_title = new Xoh_wtr_ctx(Mode_display_title , gplx.xowa.htmls.hrefs.Xoh_href_.Bry__wiki, null)
|
||||
, Popup = new Xoh_wtr_ctx(Mode_popup , gplx.xowa.htmls.hrefs.Xoh_href_.Bry__wiki, null)
|
||||
, Hdump = new Xoh_wtr_ctx(Mode_hdump , gplx.xowa.htmls.hrefs.Xoh_href_.Bry__wiki, null)
|
||||
Basic = new Xoh_wtr_ctx(Mode_basic , Xoh_hzip_dict_.Hzip__none, Xoh_href_.Bry__wiki, null)
|
||||
, Hdump = new Xoh_wtr_ctx(Mode_hdump , Xoh_hzip_dict_.Hzip__v1 , Xoh_href_.Bry__wiki, null)
|
||||
, Alt = new Xoh_wtr_ctx(Mode_alt , Xoh_hzip_dict_.Hzip__none, Xoh_href_.Bry__wiki, null)
|
||||
, Display_title = new Xoh_wtr_ctx(Mode_display_title , Xoh_hzip_dict_.Hzip__none, Xoh_href_.Bry__wiki, null)
|
||||
, Popup = new Xoh_wtr_ctx(Mode_popup , Xoh_hzip_dict_.Hzip__none, Xoh_href_.Bry__wiki, null)
|
||||
;
|
||||
|
||||
public static Xoh_wtr_ctx File_dump(byte[] anch__href__bgn, byte[] anch__href__end) {
|
||||
return new Xoh_wtr_ctx(Mode_file_dump, anch__href__bgn, anch__href__end);
|
||||
return new Xoh_wtr_ctx(Mode_file_dump, Xoh_hzip_dict_.Hzip__none, anch__href__bgn, anch__href__end);
|
||||
}
|
||||
public static Xoh_wtr_ctx Hdump_by_hzip_tid(int hzip_tid) {
|
||||
return new Xoh_wtr_ctx(Mode_hdump, hzip_tid, Xoh_href_.Bry__wiki, null);
|
||||
}
|
||||
}
|
||||
|
@ -25,7 +25,7 @@ public class Xoh_lnke_html {
|
||||
public void Write_html(Bry_bfr bfr, Xow_html_mgr html_mgr, Xoh_html_wtr html_wtr, Xoh_wtr_ctx hctx, Xop_ctx ctx, byte[] src, Xop_lnke_tkn lnke) {
|
||||
int href_bgn = lnke.Lnke_href_bgn(), href_end = lnke.Lnke_href_end(); boolean proto_is_xowa = lnke.Proto_tid() == Gfo_protocol_itm.Tid_xowa;
|
||||
byte lnke_type = Calc_type(lnke);
|
||||
if (proto_is_xowa && hctx.Mode() == Xoh_wtr_ctx.Mode_file_dump) { // if protocol and file-dump, then don't write link; DATE:2016-04-12
|
||||
if (proto_is_xowa && hctx.Mode_is_file_dump()) { // if protocol and file-dump, then don't write link; DATE:2016-04-12
|
||||
bfr.Add(Gfh_tag_.Div_lhs);
|
||||
Write_caption(bfr, html_wtr, hctx, ctx, src, lnke, href_bgn, href_end, proto_is_xowa);
|
||||
bfr.Add(Gfh_entity_.Nbsp_num_bry).Add(Disabled_button);
|
||||
@ -49,7 +49,7 @@ public class Xoh_lnke_html {
|
||||
byte[] lnke_xwiki_wiki = lnke.Lnke_xwiki_wiki();
|
||||
if ( lnke_xwiki_wiki == null
|
||||
|| hctx.Mode_is_hdump() // if hdump, never write xwiki format (/site/); always write in url format (https:); note that xwiki is set when wiki is installed locally
|
||||
|| hctx.Mode() == Xoh_wtr_ctx.Mode_file_dump
|
||||
|| hctx.Mode_is_file_dump()
|
||||
) {
|
||||
if (lnke.Lnke_relative()) { // relative; EX: //a.org
|
||||
bfr.Add(ctx.Wiki().Utl__url_parser().Url_parser().Relative_url_protocol_bry()).Add_mid(src, href_bgn, href_end);
|
||||
|
@ -16,7 +16,7 @@ Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
package gplx.xowa.htmls.core.wkrs.lnkes; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*; import gplx.xowa.htmls.core.wkrs.*;
|
||||
import org.junit.*;
|
||||
public class Xoh_lnke_html__basic__tst {
|
||||
@After public void term() {fxt.Init_para_n_(); fxt.Reset();} private final Xop_fxt fxt = new Xop_fxt();
|
||||
@After public void term() {fxt.Init_para_n_(); fxt.Reset();} private final Xop_fxt fxt = new Xop_fxt();
|
||||
@Test public void Auto__one() {fxt.Test_parse_page_wiki_str("[https://a]" , "<a href=\"https://a\" rel=\"nofollow\" class=\"external autonumber\">[1]</a>");}
|
||||
@Test public void Auto__many() {fxt.Test_parse_page_wiki_str("[https://a] [https://b]" , "<a href=\"https://a\" rel=\"nofollow\" class=\"external autonumber\">[1]</a> <a href=\"https://b\" rel=\"nofollow\" class=\"external autonumber\">[2]</a>");}
|
||||
@Test public void Text__basic() {fxt.Test_parse_page_wiki_str("[https://a b]" , "<a href=\"https://a\" rel=\"nofollow\" class=\"external text\">b</a>");}
|
||||
|
@ -27,8 +27,8 @@ public class Xoh_file_fmtr__hdump extends Xoh_file_fmtr__basic { private final
|
||||
byte[] data_xowa_title = Gfh_atr_.Make(tmp_bfr, Xoh_img_xoimg_data.Bry__data_xowa_title, a_xowa_title);
|
||||
byte[] data_xowa_image = Bld_xowa_image_data(tmp_bfr, xfer_itm.Lnki_type(), xfer_itm.Lnki_w(), xfer_itm.Lnki_h(), xfer_itm.Lnki_upright(), xfer_itm.Lnki_time(), xfer_itm.Lnki_page());
|
||||
|
||||
// only write src="..." width="..." height="..." if orig is present
|
||||
if (!xfer_itm.Orig_exists()) {
|
||||
// only write src="..." width="..." height="..." if orig is present or if Hzip__none (Hzip__none should always write title and image)
|
||||
if (!xfer_itm.Orig_exists() || hctx.Hzip_tid() == gplx.xowa.htmls.core.hzips.Xoh_hzip_dict_.Hzip__none) {
|
||||
img_w = img_h = 0;
|
||||
img_src = Bry_.Empty;
|
||||
}
|
||||
|
@ -0,0 +1,54 @@
|
||||
/*
|
||||
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.core.wkrs.lnkis.htmls; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*; import gplx.xowa.htmls.core.wkrs.*; import gplx.xowa.htmls.core.wkrs.lnkis.*;
|
||||
import org.junit.*; import gplx.xowa.files.*;
|
||||
import gplx.xowa.htmls.core.htmls.*; import gplx.xowa.htmls.core.hzips.*;
|
||||
public class Xoh_file_wtr__hdump__tst {
|
||||
private final Xoh_file_wtr__hdump__fxt fxt = new Xoh_file_wtr__hdump__fxt();
|
||||
|
||||
@Test public void Plain() {
|
||||
fxt.Init__hctx__hzip__none();
|
||||
fxt.Test__parse
|
||||
( "[[File:A.png]]"
|
||||
, String_.Concat_lines_nl_skip_last
|
||||
( "<a href=\"/wiki/File:A.png\" class=\"image\" xowa_title=\"A.png\">"
|
||||
+ "<img data-xowa-title=\"A.png\" data-xoimg=\"0|-1|-1|-1|-1|-1\" src=\"\" width=\"0\" height=\"0\" alt=\"\"/></a>"
|
||||
));
|
||||
}
|
||||
}
|
||||
class Xoh_file_wtr__hdump__fxt {
|
||||
private final Xop_fxt fxt = new Xop_fxt();
|
||||
private final Xof_file_fxt file_fxt;
|
||||
public Xoh_file_wtr__hdump__fxt() {
|
||||
fxt.Reset();
|
||||
|
||||
// default to hzip
|
||||
fxt.Hctx_(Xoh_wtr_ctx.Hdump_by_hzip_tid(Xoh_hzip_dict_.Hzip__v1));
|
||||
|
||||
// create file_fx
|
||||
this.file_fxt = Xof_file_fxt.new_all(fxt.Wiki());
|
||||
fxt.Wiki().File__fsdb_mode().Tid__v2__mp__y_();
|
||||
this.Init__orig__add("A.png", 400, 300);
|
||||
}
|
||||
public void Init__hctx__hzip__none() {fxt.Hctx_(Xoh_wtr_ctx.Hdump_by_hzip_tid(Xoh_hzip_dict_.Hzip__none));}
|
||||
public void Init__hctx__hzip__v1() {fxt.Hctx_(Xoh_wtr_ctx.Hdump_by_hzip_tid(Xoh_hzip_dict_.Hzip__plain));}
|
||||
public void Init__orig__add(String orig_ttl, int orig_w, int orig_h) {
|
||||
file_fxt.Exec_orig_add(Bool_.Y, orig_ttl, Xof_ext_.new_by_ttl_(Bry_.new_u8(orig_ttl)).Id(), orig_w, orig_h, "");
|
||||
}
|
||||
public void Test__parse(String raw, String expd) {
|
||||
fxt.Test_parse_page_wiki_str(raw, expd);
|
||||
}
|
||||
}
|
@ -45,7 +45,7 @@ public class Xoh_href_wtr { // TS:do not move to app-level
|
||||
break;
|
||||
}
|
||||
case Xoh_wtr_ctx.Mode_file_dump: {
|
||||
bfr.Add(hctx.Anch__href__bgn());
|
||||
bfr.Add(hctx.Anch__href__bgn()); // add "/wiki/"; EX: /wiki/Page; can be "/home/wiki/Page" for Html__dump_to_fsys
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
@ -84,7 +84,7 @@ public class Xoh_href_wtr { // TS:do not move to app-level
|
||||
int anch_bgn = Bry_find_.Find_fwd(ttl_full, Byte_ascii.Hash); // NOTE: cannot use Anch_bgn b/c Anch_bgn has bug with whitespace
|
||||
if (anch_bgn == Bry_find_.Not_found){ // no anchor; just add page
|
||||
encoder.Encode(encoder_bfr, ttl_full, page_bgn, ttl_full.length);
|
||||
if (hctx.Mode() == Xoh_wtr_ctx.Mode_file_dump) {
|
||||
if (hctx.Mode_is_file_dump()) {
|
||||
byte[] href_end = hctx.Anch__href__end();
|
||||
if (href_end != null) encoder_bfr.Add(href_end);
|
||||
}
|
||||
@ -93,7 +93,7 @@ public class Xoh_href_wtr { // TS:do not move to app-level
|
||||
int page_end = Bry_find_.Find_bwd_last_ws(ttl_full, anch_bgn); // first 1st ws before #; handles multiple ws
|
||||
page_end = page_end == Bry_find_.Not_found ? anch_bgn : page_end; // if ws not found, use # pos; else use 1st ws pos
|
||||
encoder.Encode(encoder_bfr, ttl_full, page_bgn, page_end); // add page
|
||||
if (hctx.Mode() == Xoh_wtr_ctx.Mode_file_dump) {
|
||||
if (hctx.Mode_is_file_dump()) {
|
||||
byte[] href_end = hctx.Anch__href__end();
|
||||
if ( href_end != null
|
||||
&& page_end - page_bgn > 0) // handle [[#A]] which will have no page; else will dump "home/page/.html#A"; DATE:2016-04-12
|
||||
|
Loading…
Reference in New Issue
Block a user