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

Wiki: Support renamed folders (fix)

This commit is contained in:
gnosygnu
2017-02-06 22:12:56 -05:00
parent 6f9e92afff
commit 938beac9f9
4379 changed files with 0 additions and 327818 deletions

View File

@@ -1,22 +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.langs.dsvs; import gplx.*; import gplx.langs.*;
public interface Dsv_fld_parser {
void Init(byte fld_dlm, byte row_dlm);
int Parse(Dsv_tbl_parser tbl_parser, Dsv_wkr_base mgr, byte[] src, int pos, int src_len, int fld_idx, int fld_bgn);
}

View File

@@ -1,114 +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.langs.dsvs; import gplx.*; import gplx.langs.*;
public class Dsv_fld_parser_ {
public static final Dsv_fld_parser Bry_parser = Dsv_fld_parser_bry.Instance;
public static final Dsv_fld_parser Int_parser = Dsv_fld_parser_int.Instance;
public static final Dsv_fld_parser Line_parser__comment_is_pipe = new Dsv_fld_parser_line(Byte_ascii.Pipe);
public static Err err_fld_unhandled(Dsv_fld_parser parser, Dsv_wkr_base wkr, int fld_idx, byte[] src, int bgn, int end) {
throw Err_.new_wo_type("fld unhandled", "parser", Type_adp_.NameOf_obj(parser), "wkr", Type_adp_.NameOf_obj(wkr), "fld_idx", fld_idx, "val", String_.new_u8(src, bgn, end)).Trace_ignore_add_1_();
}
}
class Dsv_fld_parser_line implements Dsv_fld_parser {
private byte row_dlm = Byte_ascii.Nl; private final byte comment_dlm;
public Dsv_fld_parser_line(byte comment_dlm) {this.comment_dlm = comment_dlm;}
public void Init(byte fld_dlm, byte row_dlm) {
this.row_dlm = row_dlm;
}
public int Parse(Dsv_tbl_parser parser, Dsv_wkr_base wkr, byte[] src, int pos, int src_len, int fld_idx, int fld_bgn) {
while (true) {
boolean pos_is_last = pos == src_len;
byte b = pos_is_last ? row_dlm : src[pos];
if (b == comment_dlm) {
pos = Bry_find_.Find_fwd_until(src, pos, src_len, row_dlm);
if (pos == Bry_find_.Not_found)
pos = src_len;
}
else if (b == row_dlm) {
boolean pass = wkr.Write_bry(parser, fld_idx, src, fld_bgn, pos);
if (!pass) throw Dsv_fld_parser_.err_fld_unhandled(this, wkr, fld_idx, src, fld_bgn, pos);
wkr.Commit_itm(parser, pos);
int rv = pos + 1; // row_dlm is always 1 byte
parser.Update_by_row(rv);
return rv;
}
else
++pos;
}
}
}
class Dsv_fld_parser_bry implements Dsv_fld_parser {
private byte fld_dlm = Byte_ascii.Pipe, row_dlm = Byte_ascii.Nl;
public void Init(byte fld_dlm, byte row_dlm) {
this.fld_dlm = fld_dlm; this.row_dlm = row_dlm;
}
public int Parse(Dsv_tbl_parser parser, Dsv_wkr_base wkr, byte[] src, int pos, int src_len, int fld_idx, int fld_bgn) {
while (true) {
boolean pos_is_last = pos == src_len;
byte b = pos_is_last ? row_dlm : src[pos];
if (b == fld_dlm) {
boolean pass = wkr.Write_bry(parser, fld_idx, src, fld_bgn, pos);
if (!pass) throw Dsv_fld_parser_.err_fld_unhandled(this, wkr, fld_idx, src, fld_bgn, pos);
int rv = pos + 1; // fld_dlm is always 1 byte
parser.Update_by_fld(rv);
return rv;
}
else if (b == row_dlm) {
boolean pass = wkr.Write_bry(parser, fld_idx, src, fld_bgn, pos);
if (!pass) throw Dsv_fld_parser_.err_fld_unhandled(this, wkr, fld_idx, src, fld_bgn, pos);
wkr.Commit_itm(parser, pos);
int rv = pos + 1; // row_dlm is always 1 byte
parser.Update_by_row(rv);
return rv;
}
else
++pos;
}
}
public static final Dsv_fld_parser_bry Instance = new Dsv_fld_parser_bry(); Dsv_fld_parser_bry() {}
}
class Dsv_fld_parser_int implements Dsv_fld_parser {
private byte fld_dlm = Byte_ascii.Pipe, row_dlm = Byte_ascii.Nl;
public void Init(byte fld_dlm, byte row_dlm) {
this.fld_dlm = fld_dlm; this.row_dlm = row_dlm;
}
public int Parse(Dsv_tbl_parser parser, Dsv_wkr_base wkr, byte[] src, int pos, int src_len, int fld_idx, int fld_bgn) {
while (true) {
boolean pos_is_last = pos == src_len;
byte b = pos_is_last ? row_dlm : src[pos];
if (b == fld_dlm) {
boolean pass = wkr.Write_int(parser, fld_idx, pos, Bry_.To_int_or(src, fld_bgn, pos, -1));
if (!pass) throw Dsv_fld_parser_.err_fld_unhandled(this, wkr, fld_idx, src, fld_bgn, pos);
int rv = pos + 1; // fld_dlm is always 1 byte
parser.Update_by_fld(rv);
return rv;
}
else if (b == row_dlm) {
boolean pass = wkr.Write_int(parser, fld_idx, pos, Bry_.To_int_or(src, fld_bgn, pos, -1));
if (!pass) throw Dsv_fld_parser_.err_fld_unhandled(this, wkr, fld_idx, src, fld_bgn, pos);
wkr.Commit_itm(parser, pos);
int rv = pos + 1; // row_dlm is always 1 byte
parser.Update_by_row(rv);
return rv;
}
else
++pos;
}
}
public static final Dsv_fld_parser_int Instance = new Dsv_fld_parser_int(); Dsv_fld_parser_int() {}
}

View File

@@ -1,83 +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.langs.dsvs; import gplx.*; import gplx.langs.*;
public class Dsv_tbl_parser implements Gfo_invk, Rls_able {
private Dsv_wkr_base mgr;
private Dsv_fld_parser[] fld_parsers = new Dsv_fld_parser[2]; private int fld_parsers_len = 2;
public byte[] Src() {return src;} private byte[] src;
public int Fld_bgn() {return fld_bgn;} private int fld_bgn = 0;
public int Fld_idx() {return fld_idx;} private int fld_idx = 0;
public int Row_bgn() {return row_bgn;} private int row_bgn = 0;
public int Row_idx() {return row_idx;} private int row_idx = 0;
public boolean Skip_blank_lines() {return skip_blank_lines;} public Dsv_tbl_parser Skip_blank_lines_(boolean v) {skip_blank_lines = v; return this;} private boolean skip_blank_lines = true;
public byte Fld_dlm() {return fld_dlm;} public Dsv_tbl_parser Fld_dlm_(byte v) {fld_dlm = v; return this;} private byte fld_dlm = Byte_ascii.Pipe;
public byte Row_dlm() {return row_dlm;} public Dsv_tbl_parser Row_dlm_(byte v) {row_dlm = v; return this;} private byte row_dlm = Byte_ascii.Nl;
public void Init(Dsv_wkr_base mgr, Dsv_fld_parser... fld_parsers) {
this.mgr = mgr;
this.fld_parsers = fld_parsers;
this.fld_parsers_len = fld_parsers.length;
for (int i = 0; i < fld_parsers_len; i++)
fld_parsers[i].Init(fld_dlm, row_dlm);
}
public void Clear() {
fld_bgn = fld_idx = row_bgn = row_idx = 0;
}
public Err Err_row_bgn(String fmt, int pos) {
return Err_.new_wo_type(fmt, "line", String_.new_u8(src, row_bgn, pos)).Trace_ignore_add_1_();
}
public void Update_by_fld(int pos) {
fld_bgn = pos;
++fld_idx;
}
public void Update_by_row(int pos) {
row_bgn = fld_bgn = pos;
++row_idx;
fld_idx = 0;
}
public void Parse(byte[] src) {
int src_len = src.length; if (src_len == 0) return; // NOTE: do not process if empty; note that loop below will process once for empty row
this.src = src;
int pos = 0;
while (true) {
if (fld_idx == 0 && skip_blank_lines) { // row committed; skip blank lines
while (pos < src_len) {
if (src[pos] == row_dlm) {
++pos;
row_bgn = fld_bgn = pos;
}
else
break;
}
}
if (fld_idx == fld_parsers_len) break;
Dsv_fld_parser fld_parser = fld_parsers[fld_idx];
pos = fld_parser.Parse(this, mgr, src, pos, src_len, fld_idx, fld_bgn);
if ( pos > src_len // pos is now fully past src_len; exit
|| pos == src_len && fld_idx == 0 // last pos but fld_idx > 0; do one more iteration which will "commit row; EX: 2 fields and src of "a|"; EOS should close out row
) break;
}
}
public void Rls() {
src = null; fld_parsers = null; mgr = null; fld_parsers_len = 0;
}
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk_load_by_str)) Parse(m.ReadBry("v"));
else return Gfo_invk_.Rv_unhandled;
return this;
} private static final String Invk_load_by_str = "load_by_str";
}

View File

@@ -1,64 +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.langs.dsvs; import gplx.*; import gplx.langs.*;
import org.junit.*;
public class Dsv_tbl_parser_int_tst {
private Dsv_mok_fxt fxt = new Dsv_mok_fxt();
@Test public void Basic() {
fxt .Test_load(String_.Concat_lines_nl_skip_last
( "a|1|3"
, "b|2|4"
)
, fxt.mgr_int_()
, fxt.itm_int_("a", 1, 3)
, fxt.itm_int_("b", 2, 4)
);
}
}
class Mok_int_itm implements To_str_able {
private String fld_0;
private int fld_1, fld_2;
public Mok_int_itm(String fld_0, int fld_1, int fld_2) {this.fld_0 = fld_0; this.fld_1 = fld_1; this.fld_2 = fld_2;}
public String To_str() {return String_.Concat_with_str("|", fld_0, Int_.To_str(fld_1), Int_.To_str(fld_2));}
}
class Mok_int_mgr extends Mok_mgr_base {
public void Clear() {itms.Clear();}
@Override public To_str_able[] Itms() {return (To_str_able[])itms.To_ary(To_str_able.class);} private List_adp itms = List_adp_.New();
private String fld_0;
private int fld_1, fld_2;
@Override public Dsv_fld_parser[] Fld_parsers() {
return new Dsv_fld_parser[] {Dsv_fld_parser_bry.Instance, Dsv_fld_parser_int.Instance, Dsv_fld_parser_int.Instance};
}
@Override public boolean Write_bry(Dsv_tbl_parser parser, int fld_idx, byte[] src, int bgn, int end) {
switch (fld_idx) {
case 0: fld_0 = String_.new_u8(src, bgn, end); return true;
default: return false;
}
}
@Override public boolean Write_int(Dsv_tbl_parser parser, int fld_idx, int pos, int val_int) {
switch (fld_idx) {
case 1: fld_1 = val_int; return true;
case 2: fld_2 = val_int; return true;
default: return false;
}
}
@Override public void Commit_itm(Dsv_tbl_parser parser, int pos) {
Mok_int_itm itm = new Mok_int_itm(fld_0, fld_1, fld_2);
itms.Add(itm);
}
}

View File

@@ -1,109 +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.langs.dsvs; import gplx.*; import gplx.langs.*;
import org.junit.*;
public class Dsv_tbl_parser_str_tst {
private Dsv_mok_fxt fxt = new Dsv_mok_fxt();
@Test public void Basic() {
fxt .Test_load(String_.Concat_lines_nl_skip_last
( "a|A"
, "b|B"
)
, fxt.mgr_str_(2)
, fxt.itm_str_("a", "A")
, fxt.itm_str_("b", "B")
);
}
@Test public void Blank_lines() {
fxt .Test_load(String_.Concat_lines_nl_skip_last
( ""
, "a|A"
, ""
, "b|B"
, ""
)
, fxt.mgr_str_(2)
, fxt.itm_str_("a", "A")
, fxt.itm_str_("b", "B")
);
}
@Test public void Incomplete_row() {
fxt .Test_load(String_.Concat_lines_nl_skip_last
( "a"
, "b"
, ""
)
, fxt.mgr_str_(2)
, fxt.itm_str_("a")
, fxt.itm_str_("b")
);
}
@Test public void Incomplete_row_2() { // PURPOSE: handle multiple incomplete cells
fxt .Test_load(String_.Concat_lines_nl_skip_last
( "a|")
, fxt.mgr_str_(3)
, fxt.itm_str_("a", "")
);
}
}
abstract class Mok_mgr_base extends Dsv_wkr_base {
public abstract To_str_able[] Itms();
}
class Dsv_mok_fxt {
private Dsv_tbl_parser tbl_parser = new Dsv_tbl_parser();
public Dsv_mok_fxt Clear() {
tbl_parser.Clear();
return this;
}
public Mok_mgr_base mgr_int_() {return new Mok_int_mgr();}
public Mok_mgr_base mgr_str_(int len) {return new Mok_str_mgr(len);}
public Mok_str_itm itm_str_(String... flds) {return new Mok_str_itm(flds);}
public Mok_int_itm itm_int_(String fld_0, int fld_1, int fld_2) {return new Mok_int_itm(fld_0, fld_1, fld_2);}
public void Test_load(String src, Mok_mgr_base mgr, To_str_able... expd) {
mgr.Load_by_bry(Bry_.new_u8(src));
Tfds.Eq_ary_str(expd, mgr.Itms());
}
}
class Mok_str_itm implements To_str_able {
private String[] flds;
public Mok_str_itm(String[] flds) {this.flds = flds;}
public String To_str() {return String_.Concat_with_str("|", flds);}
}
class Mok_str_mgr extends Mok_mgr_base {
private int flds_len;
public Mok_str_mgr(int flds_len) {
this.flds_len = flds_len;
}
public void Clear() {itms.Clear();}
@Override public To_str_able[] Itms() {return (To_str_able[])itms.To_ary(To_str_able.class);} private List_adp itms = List_adp_.New();
private List_adp flds = List_adp_.New();
@Override public boolean Write_bry(Dsv_tbl_parser parser, int fld_idx, byte[] src, int bgn, int end) {
flds.Add(String_.new_u8(src, bgn, end));
return true;
}
@Override public Dsv_fld_parser[] Fld_parsers() {
Dsv_fld_parser[] rv = new Dsv_fld_parser[flds_len];
for (int i = 0; i < flds_len; i++)
rv[i] = Dsv_fld_parser_.Bry_parser;
return rv;
}
@Override public void Commit_itm(Dsv_tbl_parser parser, int pos) {
Mok_str_itm itm = new Mok_str_itm((String[])flds.To_ary_and_clear(String.class));
itms.Add(itm);
}
}

View File

@@ -1,42 +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.langs.dsvs; import gplx.*; import gplx.langs.*;
public abstract class Dsv_wkr_base implements Gfo_invk {
public abstract Dsv_fld_parser[] Fld_parsers();
public byte[] Src() {return src;} private byte[] src;
public abstract void Commit_itm(Dsv_tbl_parser parser, int pos);
@gplx.Virtual public boolean Write_bry(Dsv_tbl_parser parser, int fld_idx, byte[] src, int bgn, int end) {return false;}
@gplx.Virtual public boolean Write_int(Dsv_tbl_parser parser, int fld_idx, int pos, int val_int) {return false;}
public void Load_by_bry(byte[] src) {
this.src = src;
Dsv_tbl_parser tbl_parser = new Dsv_tbl_parser(); // NOTE: this proc should only be called once, so don't bother caching tbl_parser
tbl_parser.Init(this, this.Fld_parsers());
Load_by_bry_bgn();
tbl_parser.Parse(src);
tbl_parser.Rls();
Load_by_bry_end();
}
@gplx.Virtual public void Load_by_bry_bgn() {}
@gplx.Virtual public void Load_by_bry_end() {}
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk_load_by_str)) Load_by_bry(m.ReadBry("v"));
else return Gfo_invk_.Rv_unhandled;
return this;
}
public static final String Invk_load_by_str = "load_by_str";
}