mirror of
https://github.com/gnosygnu/xowa.git
synced 2026-03-02 03:49:30 +00:00
Refactor: Pull more classes into baselib
This commit is contained in:
@@ -1,20 +1,23 @@
|
||||
/*
|
||||
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.gfml; import gplx.*;
|
||||
/*
|
||||
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.gfml;
|
||||
import gplx.core.stores.*; import gplx.core.gfo_ndes.*;
|
||||
import gplx.frameworks.invks.GfoMsg;
|
||||
import gplx.frameworks.invks.GfoMsg_;
|
||||
import gplx.types.basics.utls.StringUtl;
|
||||
public class GfmlDataNde {
|
||||
public GfmlDoc Doc() {return gdoc;} GfmlDoc gdoc;
|
||||
public DataRdr XtoRdr() {
|
||||
@@ -27,7 +30,7 @@ public class GfmlDataNde {
|
||||
rv.Doc_set(gdoc);
|
||||
return rv;
|
||||
}
|
||||
public static GfmlDataNde new_any_eol_(String raw) {return new_(String_.Replace(raw, String_.CrLf, String_.Lf));}
|
||||
public static GfmlDataNde new_any_eol_(String raw) {return new_(StringUtl.Replace(raw, StringUtl.CrLf, StringUtl.Nl));}
|
||||
public static GfmlDataNde new_(String raw) {
|
||||
GfmlDataNde rv = new GfmlDataNde();
|
||||
GfmlBldr bldr = GfmlBldr_.default_();
|
||||
@@ -49,14 +52,15 @@ public class GfmlDataNde {
|
||||
GfoMsg msg = XtoMsg(gdoc.RootNde());
|
||||
return (GfoMsg)msg.Subs_getAt(0);
|
||||
}
|
||||
private static String StringUtl_Coalesce(String s, String alt) {return StringUtl.IsNullOrEmpty(s) ? alt : s;}
|
||||
static GfoMsg XtoMsg(GfmlNde gnde) {
|
||||
String msgKey = String_.Coalesce(gnde.Key(), gnde.Hnd());
|
||||
String msgKey = StringUtl_Coalesce(gnde.Key(), gnde.Hnd());
|
||||
GfoMsg msg = GfoMsg_.new_parse_(msgKey);
|
||||
for (int i = 0; i < gnde.SubKeys().Count(); i++) {
|
||||
GfmlItm subItm = (GfmlItm)gnde.SubKeys().Get_at(i);
|
||||
if (subItm.ObjType() == GfmlObj_.Type_atr) {
|
||||
GfmlAtr subAtr = (GfmlAtr)subItm;
|
||||
String subAtrKey = String_.Len_eq_0(subAtr.Key()) ? "" : subAtr.Key(); // NOTE: needs to be "" or else will fail in GfoConsole; key will be evaluated against NullKey in GfsCtx
|
||||
String subAtrKey = StringUtl.IsNullOrEmpty(subAtr.Key()) ? "" : subAtr.Key(); // NOTE: needs to be "" or else will fail in GfoConsole; key will be evaluated against NullKey in GfsCtx
|
||||
msg.Add(subAtrKey, subAtr.DatTkn().Val());
|
||||
}
|
||||
else {
|
||||
@@ -93,7 +97,7 @@ class GfmlDataWtr2 extends DataWtr_base implements DataWtr {
|
||||
String To_str(Object obj) {
|
||||
if (obj == null) return "''";
|
||||
String s = obj.toString();
|
||||
return String_.Concat("'", String_.Replace(s, "'", "''"), "'");
|
||||
return StringUtl.Concat("'", StringUtl.Replace(s, "'", "''"), "'");
|
||||
}
|
||||
@Override public SrlMgr SrlMgr_new(Object o) {return new GfmlDataWtr2();}
|
||||
public void Doc_set(GfmlDoc v) {gdoc = v;} GfmlDoc gdoc;
|
||||
|
||||
@@ -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.gfml; import gplx.*;
|
||||
import gplx.core.stores.*;
|
||||
public class GfmlDataRdr extends GfmlDataRdr_base {
|
||||
@@ -36,7 +36,7 @@ public class GfmlDataRdr extends GfmlDataRdr_base {
|
||||
}
|
||||
public static DataRdr wtr_(DataWtr wtr) {return raw_root_(wtr.To_str());}
|
||||
@Override public SrlMgr SrlMgr_new(Object o) {return new GfmlDataRdr();}
|
||||
@gplx.Internal protected GfmlDataRdr() {
|
||||
public GfmlDataRdr() {
|
||||
this.Parse_set(true);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,21 +1,22 @@
|
||||
/*
|
||||
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.gfml; import gplx.*;
|
||||
/*
|
||||
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.gfml;
|
||||
import gplx.core.stores.*; /*DataRdr_base*/
|
||||
public abstract class GfmlDataRdr_base extends DataRdr_base implements DataRdr {
|
||||
import gplx.types.basics.utls.StringUtl;
|
||||
public abstract class GfmlDataRdr_base extends DataRdr_base implements DataRdr {
|
||||
@Override public String NameOfNode() {return curNde.Hnd();}
|
||||
@Override public int FieldCount() {return curNde.SubKeys().Count();}
|
||||
@Override public String KeyAt(int idx) {return curNde.SubKeys().Get_at(idx).KeyTkn().Val();}
|
||||
@@ -46,13 +47,13 @@ public abstract class GfmlDataRdr_base extends DataRdr_base implements DataRdr {
|
||||
if ( sub.Type().IsTypeAny()) // isAnyType b/c match may not be exact; ex: type can be defined as item:key name; but actlNde may be item:key name size;
|
||||
//|| sub.Type().IsTypeNull())
|
||||
typeName = sub.Hnd();
|
||||
if (String_.Eq(typeName, name))
|
||||
if (StringUtl.Eq(typeName, name))
|
||||
rv.list.Add(sub);
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
public void Rls() {}
|
||||
public String To_str() {return curNde.To_str();}
|
||||
@gplx.Internal protected void SetNode(GfmlNde curNde) {this.curNde = curNde; this.list = curNde.SubHnds();}
|
||||
public String To_str() {return curNde.ToStr();}
|
||||
public void SetNode(GfmlNde curNde) {this.curNde = curNde; this.list = curNde.SubHnds();}
|
||||
GfmlNde curNde; GfmlItmHnds list; int pos = -1;
|
||||
}
|
||||
|
||||
@@ -1,23 +1,25 @@
|
||||
/*
|
||||
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.gfml; import gplx.*;
|
||||
/*
|
||||
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.gfml;
|
||||
import gplx.core.lists.*; /*StackAdp*/ import gplx.core.gfo_ndes.*; import gplx.core.stores.*;
|
||||
import gplx.types.basics.utls.ObjectUtl;
|
||||
import gplx.types.basics.utls.StringUtl;
|
||||
public class GfmlDataWtr extends DataWtr_base implements DataWtr {
|
||||
public void InitWtr(String key, Object val) {
|
||||
if (!String_.Eq(key, GfmlDataWtrOpts.Key_const)) return;
|
||||
if (!StringUtl.Eq(key, GfmlDataWtrOpts.Key_const)) return;
|
||||
GfmlDataWtrOpts layout = GfmlDataWtrOpts.cast(val);
|
||||
keyedSpr = layout.KeyedSpr();
|
||||
indentNodes = layout.IndentNodes();
|
||||
@@ -37,14 +39,14 @@ public class GfmlDataWtr extends DataWtr_base implements DataWtr {
|
||||
if (stack.Count() != 1 // not root
|
||||
&& nde.SubHnds().Count() == 0) { // first subNde
|
||||
AddTkn_nullVal("{");
|
||||
if (indentNodes) AddTkn_nullVal(String_.CrLf);
|
||||
if (indentNodes) AddTkn_nullVal(StringUtl.CrLf);
|
||||
}
|
||||
if (indentNodes) AddTkn_nullVal(String_.Repeat("\t", stack.Count() - 1));
|
||||
if (indentNodes) AddTkn_nullVal(StringUtl.Repeat("\t", stack.Count() - 1));
|
||||
GfmlTkn nameTkn = null;
|
||||
if (ignoreNullNames && String_.Eq(nodeName, ""))
|
||||
if (ignoreNullNames && StringUtl.Eq(nodeName, ""))
|
||||
nameTkn = GfmlTkn_.Null;
|
||||
else {
|
||||
nameTkn = AddTkn_raw(String_.Eq(nodeName, "") ? "%" : nodeName);
|
||||
nameTkn = AddTkn_raw(StringUtl.Eq(nodeName, "") ? "%" : nodeName);
|
||||
AddTkn_nullVal(":");
|
||||
}
|
||||
nde = GfmlNde.named_(nameTkn, GfmlType_.new_any_());
|
||||
@@ -54,10 +56,10 @@ public class GfmlDataWtr extends DataWtr_base implements DataWtr {
|
||||
if (nde.SubHnds().Count() == 0)
|
||||
AddTkn_nullVal(";");
|
||||
else {
|
||||
if (indentNodes) AddTkn_nullVal(String_.Repeat("\t", stack.Count() - 1));
|
||||
if (indentNodes) AddTkn_nullVal(StringUtl.Repeat("\t", stack.Count() - 1));
|
||||
AddTkn_nullVal("}");
|
||||
}
|
||||
if (indentNodes) AddTkn_nullVal(String_.CrLf);
|
||||
if (indentNodes) AddTkn_nullVal(StringUtl.CrLf);
|
||||
GfmlNde finishedNde = nde;
|
||||
nde = GfmlNde.as_(stack.Pop());
|
||||
nde.SubObjs_Add(finishedNde);
|
||||
@@ -78,8 +80,8 @@ public class GfmlDataWtr extends DataWtr_base implements DataWtr {
|
||||
}
|
||||
String To_str(Object obj) {
|
||||
if (obj == null) return "''";
|
||||
String s = Object_.Xto_str_strict_or_empty(obj);
|
||||
return String_.Concat("'", String_.Replace(s, "'", "''"), "'");
|
||||
String s = ObjectUtl.ToStrOrEmpty(obj);
|
||||
return StringUtl.Concat("'", StringUtl.Replace(s, "'", "''"), "'");
|
||||
}
|
||||
GfmlTkn AddTkn_raw(String raw) {return AddTkn(raw, raw);}
|
||||
GfmlTkn AddTkn_nullVal(String raw) {return AddTkn(raw, GfmlTkn_.NullVal);}
|
||||
|
||||
@@ -13,13 +13,14 @@ 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.gfml; import gplx.*;
|
||||
package gplx.gfml;
|
||||
import gplx.types.errs.ErrUtl;
|
||||
public class GfmlDataWtrOpts {
|
||||
public static final String Key_const = "GfmlDataWtrOpts";
|
||||
public String KeyedSpr() {return keyedSeparator;} public GfmlDataWtrOpts KeyedSeparator_(String val) {keyedSeparator = val; return this;} private String keyedSeparator = " ";
|
||||
public boolean IndentNodes() {return indentNodes;} public GfmlDataWtrOpts IndentNodesOn_() {indentNodes = true; return this;} private boolean indentNodes;
|
||||
public boolean IgnoreNullNames() {return ignoreNullNames;} public GfmlDataWtrOpts IgnoreNullNamesOn_() {ignoreNullNames = true; return this;} private boolean ignoreNullNames;
|
||||
public static final GfmlDataWtrOpts Instance = new GfmlDataWtrOpts();
|
||||
public static GfmlDataWtrOpts new_() {return new GfmlDataWtrOpts();} GfmlDataWtrOpts() {}
|
||||
public static GfmlDataWtrOpts cast(Object obj) {try {return (GfmlDataWtrOpts)obj;} catch(Exception exc) {throw Err_.new_type_mismatch_w_exc(exc, GfmlDataWtrOpts.class, obj);}}
|
||||
}
|
||||
public static final String Key_const = "GfmlDataWtrOpts";
|
||||
public String KeyedSpr() {return keyedSeparator;} public GfmlDataWtrOpts KeyedSeparator_(String val) {keyedSeparator = val; return this;} private String keyedSeparator = " ";
|
||||
public boolean IndentNodes() {return indentNodes;} public GfmlDataWtrOpts IndentNodesOn_() {indentNodes = true; return this;} private boolean indentNodes;
|
||||
public boolean IgnoreNullNames() {return ignoreNullNames;} public GfmlDataWtrOpts IgnoreNullNamesOn_() {ignoreNullNames = true; return this;} private boolean ignoreNullNames;
|
||||
public static final GfmlDataWtrOpts Instance = new GfmlDataWtrOpts();
|
||||
public static GfmlDataWtrOpts new_() {return new GfmlDataWtrOpts();} GfmlDataWtrOpts() {}
|
||||
public static GfmlDataWtrOpts cast(Object obj) {try {return (GfmlDataWtrOpts)obj;} catch(Exception exc) {throw ErrUtl.NewCast(exc, GfmlDataWtrOpts.class, obj);}}
|
||||
}
|
||||
|
||||
@@ -13,9 +13,10 @@ 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.gfml; import gplx.*;
|
||||
import gplx.core.gfo_regys.*;
|
||||
public class GfoMsgParser_gfml implements GfoMsgParser {
|
||||
public GfoMsg ParseToMsg(String s) {return GfmlDataNde.XtoMsg(s);}
|
||||
public static final GfoMsgParser_gfml Instance = new GfoMsgParser_gfml(); GfoMsgParser_gfml() {}
|
||||
}
|
||||
package gplx.gfml;
|
||||
import gplx.core.gfo_regys.*;
|
||||
import gplx.frameworks.invks.GfoMsg;
|
||||
public class GfoMsgParser_gfml implements GfoMsgParser {
|
||||
public GfoMsg ParseToMsg(String s) {return GfmlDataNde.XtoMsg(s);}
|
||||
public static final GfoMsgParser_gfml Instance = new GfoMsgParser_gfml(); GfoMsgParser_gfml() {}
|
||||
}
|
||||
|
||||
@@ -13,8 +13,10 @@ 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.gfml; import gplx.*;
|
||||
import gplx.core.strings.*;
|
||||
package gplx.gfml;
|
||||
import gplx.types.basics.utls.StringUtl;
|
||||
import gplx.types.commons.String_bldr;
|
||||
import gplx.types.commons.String_bldr_;
|
||||
public class SqlDoc {
|
||||
public static GfmlDoc XtoDoc(String raw) {
|
||||
GfmlBldr bldr = GfmlBldr_.new_();
|
||||
@@ -43,7 +45,7 @@ public class SqlDoc {
|
||||
}
|
||||
static GfmlLxr whitespace_(GfmlLxr lxr) {
|
||||
GfmlTkn tkn = GfmlTkn_.cmd_("key:gfml.whitespace_0", GfmlBldrCmd_.Null);
|
||||
GfmlLxr rv = GfmlLxr_.range_("lxr:gfml.whitespace_0", String_.Ary(" ", String_.Tab, String_.CrLf, String_.Lf), tkn, false);
|
||||
GfmlLxr rv = GfmlLxr_.range_("lxr:gfml.whitespace_0", StringUtl.Ary(" ", StringUtl.Tab, StringUtl.CrLf, StringUtl.Nl), tkn, false);
|
||||
lxr.SubLxr_Add(rv);
|
||||
return rv;
|
||||
}
|
||||
@@ -77,11 +79,11 @@ class SqlCmd_quote_end implements GfmlBldrCmd {
|
||||
String_bldr sb = String_bldr_.new_();
|
||||
GfmlObjList list = bldr.CurFrame().WaitingTkns();
|
||||
for (int i = 0; i < list.Len(); i++) {
|
||||
GfmlTkn pnd = (GfmlTkn)list.Get_at(i);
|
||||
GfmlTkn pnd = (GfmlTkn)list.GetAt(i);
|
||||
sb.Add(pnd.Val());
|
||||
}
|
||||
//Int_.To_str(bldr.CurNdeFrame().Nde().SubTkns().length)
|
||||
GfmlAtr atr = GfmlAtr.new_(GfmlTkn_.raw_("word"), GfmlTkn_.raw_(sb.To_str()), GfmlType_.String);
|
||||
//IntUtl.To_str(bldr.CurNdeFrame().Nde().SubTkns().length)
|
||||
GfmlAtr atr = GfmlAtr.new_(GfmlTkn_.raw_("word"), GfmlTkn_.raw_(sb.ToStr()), GfmlType_.String);
|
||||
bldr.CurNdeFrame().CurNde().SubObjs_Add(atr);
|
||||
bldr.Frames_end();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user