2021-12-19 21:19:19 +00:00
/ *
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.types.basics.utls.ClassUtl ;
import gplx.types.errs.ErrUtl ;
import gplx.types.basics.utls.StringUtl ;
2017-10-24 00:50:50 +00:00
class GfmlPragmaLxrFrm implements GfmlPragma {
public String KeyOfPragma ( ) { return " _lxr_frame " ; }
public void Exec ( GfmlBldr bldr , GfmlNde pragmaNde ) {
Compile ( bldr , pragmaNde ) ;
}
2021-12-19 21:19:19 +00:00
public static GfmlLxr Compile ( GfmlBldr bldr , GfmlNde ownerNde ) {
2017-10-24 00:50:50 +00:00
String key = ownerNde . SubKeys ( ) . FetchDataOrFail ( " key " ) ;
String type = ownerNde . SubKeys ( ) . FetchDataOrNull ( " type " ) ;
String bgn = ownerNde . SubKeys ( ) . FetchDataOrFail ( " bgn " ) ;
String end = ownerNde . SubKeys ( ) . FetchDataOrFail ( " end " ) ;
2021-12-19 21:19:19 +00:00
GfmlFrame frame = StringUtl . Eq ( type , " comment " ) ? GfmlFrame_ . comment_ ( ) : GfmlFrame_ . quote_ ( ) ;
2017-10-24 00:50:50 +00:00
GfmlLxr lxr = bldr . Doc ( ) . LxrRegy ( ) . Get_by ( key ) ;
if ( lxr = = null ) {
lxr = GfmlLxr_ . frame_ ( key , frame , bgn , end ) ;
bldr . Doc ( ) . LxrRegy ( ) . Add ( lxr ) ;
bldr . Doc ( ) . RootLxr ( ) . SubLxr_Add ( lxr ) ; // FIXME: always add to cur lxr; should be outside if block; also, auto_add=n to skip adding to rootLxr
}
else {
2021-12-19 21:19:19 +00:00
GfmlLxr_frame frameLxr = GfmlLxr_frame . as_ ( lxr ) ; if ( frameLxr = = null ) throw ErrUtl . NewArgs ( " lxr is not GfmlLxr_frame " , " key " , key , " type " , ClassUtl . NameByObj ( lxr ) ) ;
2017-10-24 00:50:50 +00:00
if ( type ! = null ) {
// frame = frameLxr.Frame.MakeNew(frameLxr);
}
if ( bgn ! = null ) {
frameLxr . BgnRaw_set ( bgn ) ;
}
if ( end ! = null ) {
frameLxr . EndRaw_set ( end ) ;
// end = frameLxr.EndLxr.CmdTkn.Raw;
}
}
for ( int i = 0 ; i < ownerNde . SubHnds ( ) . Count ( ) ; i + + ) {
GfmlNde subNde = ( GfmlNde ) ownerNde . SubHnds ( ) . Get_at ( i ) ;
GfmlLxr subLxr = null ;
2021-12-19 21:19:19 +00:00
if ( StringUtl . Eq ( subNde . Hnd ( ) , " sym " ) )
2017-10-24 00:50:50 +00:00
subLxr = GfmlPragmaLxrSym . Compile ( bldr , subNde ) ;
lxr . SubLxr_Add ( subLxr ) ;
}
return lxr ;
}
public GfmlType [ ] MakePragmaTypes ( GfmlTypeMakr makr ) {
makr . MakeRootType ( " _lxr_frame " , " _lxr_frame " , " key " , " type " , " bgn " , " end " ) ;
return makr . Xto_bry ( ) ;
}
public static GfmlPragmaLxrFrm new_ ( ) { return new GfmlPragmaLxrFrm ( ) ; } GfmlPragmaLxrFrm ( ) { }
}