From d9f45cec19efd371937913c02b951296a2d89cdb Mon Sep 17 00:00:00 2001 From: gnosygnu Date: Sun, 8 Nov 2015 23:48:07 -0500 Subject: [PATCH] v2.11.2.1 --- 100_core/src/gplx/Tfds.java | 9 +- .../gplx/Decimal_adp_.java | 17 +- .../src_101_types_object/gplx/Object_.java | 12 ++ .../src_101_types_object/gplx/String_.java | 4 +- 100_core/src_130_brys/gplx/Bry_.java | 9 +- .../gplx/{Bry_rdr.java => Bry_rdr_old.java} | 8 +- .../src_420_usrMsg/gplx/Gfo_usr_dlg_.java | 29 ++- .../gplx/Gfo_usr_dlg__gui_test.java | 11 +- .../dbs/metas/parsers/Meta_fld_wkr__base.java | 4 +- .../dbs/metas/parsers/Meta_parser__fld.java | 2 +- .../gplx/dbs/metas/parsers/Sql_bry_rdr.java | 4 +- 400_xowa/src/gplx/core/brys/Bit_.java | 73 +------ 400_xowa/src/gplx/core/brys/Bit__tst.java | 43 +---- 400_xowa/src/gplx/core/brys/Bry_parser.java | 130 ------------- 400_xowa/src/gplx/core/brys/Bry_rdr.java | 171 ++++++++++++++++ 400_xowa/src/gplx/core/brys/Bry_rdr_tst.java | 4 +- .../brys/Int_flag_bldr.java} | 17 +- .../src/gplx/core/brys/Int_flag_bldr_.java | 89 +++++++++ .../gplx/core/brys/Int_flag_bldr__tst.java | 72 +++++++ .../core/consoles/Gfo_cmd_arg_mgr_tst.java | 2 +- 400_xowa/src/gplx/langs/htmls/Html_atr_.java | 10 +- 400_xowa/src/gplx/langs/htmls/Html_bldr_.java | 38 ++++ 400_xowa/src/gplx/langs/htmls/Html_tag_.java | 60 +++--- .../src/gplx/langs/htmls/Html_utl_tst.java | 6 +- .../gplx/langs/htmls/parsers/Html_atr.java | 9 +- .../langs/htmls/parsers/Html_atr_cls_.java | 61 ++++++ .../htmls/parsers/Html_atr_cls__tst.java | 58 ++++++ .../langs/htmls/parsers/Html_doc_log.java | 38 ++++ .../langs/htmls/parsers/Html_doc_parser.java | 7 +- .../gplx/langs/htmls/parsers/Html_tag.java | 60 ++++-- .../langs/htmls/parsers/Html_tag_rdr.java | 51 +++-- .../langs/htmls/parsers/Html_tag_rdr_tst.java | 5 + .../parsers/styles/Html_atr_style_.java} | 13 +- .../parsers/styles/Html_atr_style_parser.java | 50 +++++ .../styles/Html_atr_style_parser_tst.java | 41 ++++ .../parsers/styles/Html_atr_style_wkr.java | 33 ++++ .../Html_atr_style_wkr__get_val_as_int.java | 35 ++++ 400_xowa/src/gplx/xowa/Xoa_app_.java | 2 +- 400_xowa/src/gplx/xowa/Xoa_app_fxt.java | 14 +- 400_xowa/src/gplx/xowa/Xoa_ttl.java | 10 +- 400_xowa/src/gplx/xowa/Xoa_url.java | 2 +- 400_xowa/src/gplx/xowa/Xoa_url_.java | 2 +- 400_xowa/src/gplx/xowa/Xoae_page.java | 2 +- 400_xowa/src/gplx/xowa/Xop_fxt.java | 2 + 400_xowa/src/gplx/xowa/Xowe_wiki.java | 2 +- .../gplx/xowa/apps/cfgs/Xowc_xtn_pages.java | 2 +- .../apps/urls/Xoa_url_parser__xwiki_tst.java | 4 +- .../xowa/bldrs/cmds/Xob_dump_mgr_base.java | 2 +- .../cmds/ctgs/Xob_category_registry_sql.java | 2 +- .../ctgs/Xob_category_registry_sql_tst.java | 2 +- .../cmds/ctgs/Xob_categorylinks_base.java | 2 +- .../cmds/ctgs/Xob_categorylinks_sql_tst.java | 2 +- .../xowa/bldrs/cmds/ctgs/Xob_ctg_v1_base.java | 6 +- .../bldrs/cmds/files/Xob_lnki_temp_wkr.java | 8 +- .../bldrs/cmds/files/Xob_lnki_temp_wkr_.java | 2 +- .../bldrs/cmds/texts/Xob_search_base.java | 2 +- .../bldrs/cmds/texts/sqls/Xob_page_cmd.java | 2 +- .../cmds/texts/sqls/Xob_page_cmd_tst.java | 6 +- .../bldrs/cmds/texts/tdbs/Xob_page_txt.java | 2 +- .../tdbs/Xob_parse_dump_templates_cmd.java | 2 +- .../cmds/texts/tdbs/Xob_search_base_tst.java | 4 +- .../xowa/bldrs/cmds/texts/tdbs/Xob_tst.java | 20 +- .../cmds/texts/xmls/Xob_siteinfo_nde.java | 2 +- .../bldrs/cmds/utils/Xob_deploy_zip_cmd.java | 2 +- .../bldrs/cmds/wikis/Xob_redirect_cmd.java | 4 +- .../xowa/bldrs/css/Xoa_css_extractor.java | 2 +- .../bldrs/css/Xoa_css_extractor_wiki_tst.java | 6 +- .../bldrs/installs/Xow_cfg_wiki_core.java | 2 +- .../bldrs/installs/Xow_cfg_wiki_core_tst.java | 8 +- .../wms/revs/Xowm_rev_wkr__meta__wm_tst.java | 6 +- .../gplx/xowa/bldrs/xmls/Xob_xml_dumper.java | 2 +- .../xowa/bldrs/xmls/Xob_xml_dumper_tst.java | 2 +- .../xowa/bldrs/xmls/Xob_xml_parser_tst.java | 6 +- .../Xoa_file_mgr.java} | 16 +- .../src/gplx/xowa/files/Xof_fsdb_itm.java | 13 ++ .../xowa/files/fsdb/tsts/Xof_file_fxt.java | 2 +- .../src/gplx/xowa/files/gui/Js_img_mgr.java | 2 +- .../xowa/files/repos/Xofw_wiki_wkr_base.java | 2 +- .../xowa/guis/history/Xog_history_mgr.java | 2 +- .../src/gplx/xowa/guis/views/Xog_tab_itm.java | 2 +- .../xowa/guis/views/Xog_tab_itm_edit_mgr.java | 2 +- .../src/gplx/xowa/guis/views/Xog_win_itm.java | 2 +- 400_xowa/src/gplx/xowa/htmls/Xoh_consts.java | 1 + 400_xowa/src/gplx/xowa/htmls/Xoh_img_mgr.java | 43 +++++ 400_xowa/src/gplx/xowa/htmls/Xoh_page.java | 6 +- .../src/gplx/xowa/htmls/Xoh_page_wtr_wkr.java | 8 +- .../gplx/xowa/htmls/Xoh_page_wtr_wkr_.java | 4 +- .../xowa/htmls/core/Xow_hdump_mgr__load.java | 2 +- .../htmls/core/Xow_hdump_mgr__load_tst.java | 125 ++++++------ .../htmls/core/bldrs/Xob_hdump_img_cmd.java | 66 +++---- .../xowa/htmls/core/hzips/Xoh_decode_ctx.java | 38 ++++ .../xowa/htmls/core/hzips/Xoh_hzip_dict_.java | 35 ++-- .../xowa/htmls/core/hzips/Xoh_hzip_int_.java | 1 + .../xowa/htmls/core/hzips/Xoh_hzip_mgr.java | 47 ++--- .../htmls/core/hzips/Xoh_hzip_mgr_fxt.java | 71 ------- .../xowa/htmls/core/hzips/Xoh_hzip_wkr.java | 4 +- .../htmls/core/hzips/stats/Hzip_stat_itm.java | 14 +- .../htmls/core/hzips/tests/Xoh_hzip_fxt.java | 38 ++-- .../xowa/htmls/core/makes/Xoh_make_mgr.java | 21 +- .../core/makes/Xoh_make_mgr__file__tst.java | 147 +++++++------- .../htmls/core/makes/Xoh_make_mgr_fxt.java | 2 +- .../xowa/htmls/core/makes/Xoh_make_trie_.java | 7 +- .../core/makes/imgs/Xohd_img_itm__base.java | 2 +- .../makes/imgs/Xohd_img_itm__gallery_itm.java | 2 +- .../htmls/core/makes/tests/Xoh_make_fxt.java | 18 +- .../htmls/core/makes/tests/Xoh_page_chkr.java | 22 ++- .../htmls/core/parsers/Xoh_doc_wkr__tag.java | 72 ------- .../htmls/core/parsers/Xoh_parser_fxt.java | 100 ---------- .../htmls/core/parsers/Xoh_wkr__hzip.java | 32 --- .../to_delete/Xohd_page_html_mgr__load.java | 4 +- ...scape_parse_tst.java => Xoh_hdoc_ctx.java} | 13 +- .../Xoh_wkr.java => wkrs/Xoh_hdoc_wkr.java} | 18 +- .../htmls/core/wkrs/Xoh_hdoc_wkr__base.java | 39 ++++ .../htmls/core/wkrs/Xoh_hdoc_wkr__hzip.java | 46 +++++ .../htmls/core/wkrs/Xoh_hdoc_wkr__make.java | 41 ++++ .../xowa/htmls/core/wkrs/Xoh_itm_parser.java | 22 +++ .../core/wkrs/Xoh_itm_parser_fxt_base.java | 38 ++++ .../core/wkrs/escapes/Xoh_escape_hzip.java | 6 +- ...cape_parse.java => Xoh_escape_parser.java} | 8 +- .../htmls/core/wkrs/hdrs/Xoh_hdr_html.java | 6 +- .../core/wkrs/hdrs/Xoh_hdr_html_tst.java | 19 +- .../htmls/core/wkrs/hdrs/Xoh_hdr_hzip.java | 50 ++--- .../core/wkrs/hdrs/Xoh_hdr_hzip_tst.java | 72 +++---- .../htmls/core/wkrs/hdrs/Xoh_hdr_make.java | 18 +- .../core/wkrs/hdrs/Xoh_hdr_make_tst.java | 8 +- .../htmls/core/wkrs/hdrs/Xoh_hdr_parse.java | 62 ------ .../core/wkrs/hdrs/Xoh_hdr_parse_base.java | 47 ----- .../htmls/core/wkrs/hdrs/Xoh_hdr_parser.java | 34 ++++ .../Xoh_img_html__dump__tst.java} | 17 +- .../htmls/core/wkrs/imgs/Xoh_img_hzip.java | 168 ++++++++++++++++ .../Xoh_img_hzip__dump__tst.java} | 16 +- .../wkrs/imgs/Xoh_img_hzip__view__tst.java | 35 ++++ .../htmls/core/wkrs/imgs/Xoh_img_make.java | 52 +++++ .../wkrs/imgs/Xoh_img_make__dump__tst.java | 53 +++++ .../htmls/core/wkrs/imgs/Xoh_img_parser.java | 63 ++++++ .../core/wkrs/imgs/atrs/Xoh_anch_cls_.java | 45 +++++ .../wkrs/imgs/atrs/Xoh_anch_cls_parser.java | 36 ++++ .../core/wkrs/imgs/atrs/Xoh_img_cls_.java | 57 ++++++ .../core/wkrs/imgs/atrs/Xoh_img_cls__tst.java | 34 ++++ .../wkrs/imgs/atrs/Xoh_img_cls_parser.java | 46 +++++ .../wkrs/imgs/atrs/Xoh_img_src_parser.java | 74 +++++++ .../imgs/atrs/Xoh_img_src_parser_tst.java | 51 +++++ .../wkrs/imgs/atrs/Xoh_img_xoimg_parser.java | 56 ++++++ .../lnkes/Xoh_href_hzip.java} | 11 -- .../htmls/core/wkrs/lnkes/Xoh_lnke_html.java | 10 +- .../wkrs/lnkes/Xoh_lnke_html__hdump__tst.java | 6 +- .../htmls/core/wkrs/lnkes/Xoh_lnke_hzip.java | 52 ++--- .../core/wkrs/lnkes/Xoh_lnke_hzip_tst.java | 14 +- .../htmls/core/wkrs/lnkes/Xoh_lnke_parse.java | 48 ----- .../core/wkrs/lnkes/Xoh_lnke_parser.java | 43 +++++ .../htmls/core/wkrs/lnkis/Xoh_lnki_dict_.java | 8 +- .../wkrs/lnkis/Xoh_lnki_html__hdump__tst.java | 8 +- .../htmls/core/wkrs/lnkis/Xoh_lnki_hzip.java | 182 +++++++----------- .../core/wkrs/lnkis/Xoh_lnki_hzip_tst.java | 56 +++--- .../htmls/core/wkrs/lnkis/Xoh_lnki_parse.java | 60 ------ .../core/wkrs/lnkis/Xoh_lnki_parse_tst.java | 38 ---- .../core/wkrs/lnkis/Xoh_lnki_parser.java | 55 ++++++ .../lnkis}/Xoh_ttl_matcher.java | 14 +- .../lnkis}/Xoh_ttl_matcher_tst.java | 7 +- .../lnkis/anchs/Xoh_anch_href_parser.java | 65 +++++++ .../lnkis/anchs/Xoh_anch_href_parser_tst.java | 51 +++++ .../lnkis/htmls/Xoh_arg_img_core__hdump.java | 2 +- .../lnkis/htmls/Xoh_file_html_fmtr__base.java | 6 +- .../htmls/Xoh_file_html_fmtr__hdump.java | 40 ++-- .../core/wkrs/lnkis/htmls/Xoh_file_mgr.java | 2 +- .../wkrs/lnkis/htmls/Xoh_file_wtr__basic.java | 14 +- .../wkrs/lnkis/htmls/Xoh_lnki_consts.java | 20 -- .../wkrs/lnkis/htmls/Xoh_lnki_consts_tst.java | 34 ---- .../core/wkrs/lnkis/htmls/Xoh_lnki_wtr.java | 23 +-- .../core/wkrs/spaces/Xoh_space_hzip.java | 10 +- .../core/wkrs/spaces/Xoh_space_hzip_tst.java | 13 ++ ...space_parse.java => Xoh_space_parser.java} | 8 +- .../core/wkrs/tags/Xoh_doc_wkr__tag.java | 85 ++++++++ .../core/wkrs/thms/Xoh_thm_html_tst.java | 35 ++++ .../htmls/core/wkrs/thms/Xoh_thm_hzip.java | 95 +++++++++ .../core/wkrs/thms/Xoh_thm_hzip_tst.java | 86 +++++++++ .../htmls/core/wkrs/thms/Xoh_thm_parse.java | 74 +++++++ ...Xoh_txt_parse.java => Xoh_txt_parser.java} | 8 +- .../src/gplx/xowa/htmls/doms/Xoh_dom_.java | 2 +- .../gplx/xowa/htmls/heads/Xoh_head_itm_.java | 1 + .../Xoh_head_itm__gallery_styles.java} | 20 +- .../gplx/xowa/htmls/heads/Xoh_head_mgr.java | 3 +- .../htmls/modules/popups/Xow_popup_mgr.java | 14 +- .../modules/popups/Xow_popup_parser_tst.java | 6 +- .../modules/popups/Xow_popup_wrdx_mkr.java | 4 +- .../xowa/htmls/portal/Xoh_page_body_cls.java | 6 +- .../htmls/portal/Xoh_subpages_bldr_tst.java | 2 +- .../xowa/htmls/portal/Xow_portal_mgr.java | 4 +- .../xowa/htmls/sections/Xoh_section_mgr.java | 1 + .../src/gplx/xowa/htmls/tocs/Xow_hdr_mgr.java | 2 +- .../src/gplx/xowa/htmls/tocs/Xow_toc_mgr.java | 4 +- .../gplx/xowa/htmls/tocs/Xow_toc_mgr_tst.java | 8 +- .../src/gplx/xowa/langs/Xol_lang_itm.java | 2 +- .../xowa/langs/bldrs/Xol_mw_lang_parser.java | 40 ++-- .../langs/bldrs/Xol_mw_lang_parser_tst.java | 10 +- .../gplx/xowa/langs/parsers/Xol_lang_srl.java | 2 +- .../xowa/langs/parsers/Xol_lang_srl_tst.java | 2 +- .../parsers/hdrs/Xop_hdr_wkr__basic_tst.java | 2 +- .../xowa/parsers/lnkis/Xop_lnki_align_h.java | 6 + .../gplx/xowa/parsers/lnkis/Xop_lnki_tkn.java | 4 +- .../gplx/xowa/parsers/lnkis/Xop_lnki_wkr.java | 8 +- .../xowa/parsers/lnkis/Xop_lnki_wkr_.java | 4 +- .../lnkis/Xop_lnki_wkr__basic_tst.java | 12 +- .../lnkis/Xop_lnki_wkr__subpage_tst.java | 4 +- .../redlinks/Xopg_redlink_lnki_list.java | 6 +- .../xowa/parsers/miscs/Xop_under_lxr_tst.java | 2 +- .../src/gplx/xowa/parsers/tmpls/Arg_bldr.java | 2 +- .../xowa/parsers/tmpls/Xot_defn_tmpl.java | 2 +- .../gplx/xowa/parsers/tmpls/Xot_invk_tkn.java | 8 +- .../gplx/xowa/parsers/tmpls/Xot_invk_wkr.java | 2 +- .../parsers/tmpls/Xot_invk_wkr_basic_tst.java | 10 +- .../xowa/parsers/utils/Xop_redirect_mgr.java | 13 +- .../parsers/utils/Xop_redirect_mgr_tst.java | 5 +- .../xndes/Xop_xnde_wkr__basic_tst.java | 2 +- .../gplx/xowa/specials/Xows_special_meta.java | 2 +- .../specials/allPages/Xows_page_allpages.java | 4 +- .../xowa/specials/movePage/Move_page.java | 2 +- .../search/Xog_search_suggest_mgr.java | 2 +- .../xowa/specials/search/Xosrh_core_tst.java | 4 +- .../specials/search/Xosrh_page_mgr_tst.java | 2 +- .../xowa/specials/search/Xows_ns_mgr.java | 6 +- .../specials/search/Xows_paging_parser.java | 2 +- .../statistics/Xop_statistics_page.java | 2 +- .../popup_history/Popup_history_page.java | 2 +- 400_xowa/src/gplx/xowa/users/Xou_user_.java | 4 +- .../xowa/users/history/Xoud_history_mgr.java | 2 +- .../src/gplx/xowa/wikis/Xow_page_tid.java | 6 +- 400_xowa/src/gplx/xowa/wikis/Xowv_wiki.java | 2 +- .../gplx/xowa/wikis/ctgs/Xoctg_html_mgr.java | 2 +- .../xowa/wikis/ctgs/Xoctg_pagelist_itms.java | 2 +- .../gplx/xowa/wikis/data/Xow_data_mgr.java | 12 +- .../xowa/wikis/data/Xow_data_mgr_tst.java | 6 +- .../xowa/wikis/data/tbls/Xowd_page_itm.java | 2 +- .../wikis/data/tbls/Xowd_page_itm_tst.java | 8 +- .../xowa/wikis/data/tbls/Xowd_page_tbl.java | 4 +- .../wikis/data/tbls/Xowd_site_ns_tbl.java | 2 +- .../xowa/wikis/data/tbls/Xowd_text_tbl.java | 1 + .../data/tbls/Xowd_wbase_qid_tbl_tst.java | 6 +- .../xowa/wikis/dbs/Xodb_load_mgr_sql.java | 8 +- .../xowa/wikis/dbs/Xodb_load_mgr_sql_tst.java | 4 +- .../xowa/wikis/dbs/Xodb_load_mgr_txt.java | 8 +- .../src/gplx/xowa/wikis/dbs/Xodb_mgr_txt.java | 2 +- 400_xowa/src/gplx/xowa/wikis/nss/Xow_ns.java | 84 ++++---- 400_xowa/src/gplx/xowa/wikis/nss/Xow_ns_.java | 106 ++++------ .../xowa/wikis/nss/Xow_ns_canonical_.java | 80 ++++++++ .../src/gplx/xowa/wikis/nss/Xow_ns_mgr.java | 46 ++--- .../src/gplx/xowa/wikis/nss/Xow_ns_mgr_.java | 6 +- .../gplx/xowa/wikis/nss/Xow_ns_mgr_tst.java | 4 +- .../src/gplx/xowa/wikis/nss/Xow_ns_tst.java | 22 +-- .../xowa/wikis/tdbs/Xotdb_fsys_mgr_tst.java | 4 +- .../gplx/xowa/wikis/tdbs/Xotdb_page_itm_.java | 2 +- .../wikis/tdbs/Xotdb_page_raw_parser.java | 2 +- .../wikis/tdbs/hives/Xowd_hive_mgr_tst.java | 2 +- .../xowa/wikis/ttls/Xow_ttl__basic_tst.java | 12 +- .../xowa/wikis/ttls/Xow_ttl__err_tst.java | 2 +- .../xowa/wikis/ttls/Xow_ttl__xwik_tst.java | 10 +- .../gplx/xowa/wikis/xwikis/Xow_xwiki_itm.java | 17 +- .../xowa/wikis/xwikis/Xow_xwiki_itm_tst.java | 45 +++++ .../xowa/xtns/dynamicPageList/Dpl_itm.java | 2 +- .../xtns/dynamicPageList/Dpl_xnde_tst.java | 2 +- .../xowa/xtns/gallery/Gallery_html_wtr.java | 2 +- .../xowa/xtns/gallery/Gallery_itm_parser.java | 4 +- .../xowa/xtns/gallery/Gallery_mgr_base.java | 8 +- .../gallery/Gallery_mgr_base_basic_tst.java | 6 +- .../xtns/gallery/Gallery_mgr_packed_base.java | 1 + .../src/gplx/xowa/xtns/imaps/Imap_map.java | 5 +- .../xowa/xtns/insiders/Insider_html_bldr.java | 2 +- .../xtns/pfuncs/ifs/Pfunc_ifexist_mgr.java | 4 +- .../xowa/xtns/pfuncs/ttls/Pfunc_filepath.java | 2 +- .../gplx/xowa/xtns/pfuncs/ttls/Pfunc_ns.java | 10 +- .../gplx/xowa/xtns/pfuncs/ttls/Pfunc_ttl.java | 6 +- .../pfuncs/wikis/Pfunc_pagesincategory.java | 2 +- .../wikis/Pfunc_pagesincategory_tst.java | 2 +- .../xtns/proofreadPage/Pp_index_parser.java | 2 +- .../xtns/scribunto/Scrib_invoke_func.java | 2 +- .../xowa/xtns/scribunto/Scrib_xtn_mgr.java | 2 - .../xtns/scribunto/libs/Scrib_lib_mw.java | 4 +- .../libs/Scrib_lib_mw__invoke_tst.java | 6 +- .../xtns/scribunto/libs/Scrib_lib_site.java | 14 +- .../scribunto/libs/Scrib_lib_site_tst.java | 10 +- .../xtns/scribunto/libs/Scrib_lib_title.java | 28 +-- .../scribunto/libs/Scrib_lib_title_tst.java | 16 +- .../xtns/scribunto/libs/Scrib_lib_uri.java | 2 +- .../libs/Scrib_lib_wikibase_entity.java | 4 +- .../libs/Scrib_lib_wikibase_entity_tst.java | 5 +- .../libs/Scrib_lib_wikibase_srl.java | 3 +- .../libs/Scrib_lib_wikibase_srl_tst.java | 18 +- .../libs/Scrib_lib_wikibase_srl_visitor.java | 6 +- .../gplx/xowa/xtns/wdatas/Wdata_wiki_mgr.java | 16 +- .../xowa/xtns/wdatas/Wdata_wiki_mgr_fxt.java | 2 +- .../xtns/wdatas/Wdata_xwiki_link_wtr.java | 2 +- .../xtns/wdatas/core/Wdata_dict_val_tid.java | 12 ++ .../wdatas/imports/Xob_wbase_ns_parser.java | 2 +- .../xtns/wdatas/imports/Xob_wdata_db_cmd.java | 2 +- .../wdatas/imports/Xob_wdata_qid_base.java | 4 +- .../imports/Xob_wdata_qid_base_tst.java | 4 +- .../xtns/wdatas/pfuncs/Wdata_pf_property.java | 6 +- .../en.wikipedia.org-text.xowa | Bin 36864 -> 36864 bytes 298 files changed, 3908 insertions(+), 2141 deletions(-) rename 100_core/src_130_brys/gplx/{Bry_rdr.java => Bry_rdr_old.java} (95%) delete mode 100644 400_xowa/src/gplx/core/brys/Bry_parser.java create mode 100644 400_xowa/src/gplx/core/brys/Bry_rdr.java rename 400_xowa/src/gplx/{xowa/htmls/core/wkrs/lnkes/Xoh_lnke_parse_tst.java => core/brys/Int_flag_bldr.java} (59%) create mode 100644 400_xowa/src/gplx/core/brys/Int_flag_bldr_.java create mode 100644 400_xowa/src/gplx/core/brys/Int_flag_bldr__tst.java create mode 100644 400_xowa/src/gplx/langs/htmls/Html_bldr_.java create mode 100644 400_xowa/src/gplx/langs/htmls/parsers/Html_atr_cls_.java create mode 100644 400_xowa/src/gplx/langs/htmls/parsers/Html_atr_cls__tst.java create mode 100644 400_xowa/src/gplx/langs/htmls/parsers/Html_doc_log.java rename 400_xowa/src/gplx/{xowa/htmls/core/Xoh_html_dict_.java => langs/htmls/parsers/styles/Html_atr_style_.java} (61%) create mode 100644 400_xowa/src/gplx/langs/htmls/parsers/styles/Html_atr_style_parser.java create mode 100644 400_xowa/src/gplx/langs/htmls/parsers/styles/Html_atr_style_parser_tst.java create mode 100644 400_xowa/src/gplx/langs/htmls/parsers/styles/Html_atr_style_wkr.java create mode 100644 400_xowa/src/gplx/langs/htmls/parsers/styles/Html_atr_style_wkr__get_val_as_int.java rename 400_xowa/src/gplx/xowa/{htmls/core/wkrs/spaces/Xoh_space_parse_tst.java => files/Xoa_file_mgr.java} (63%) create mode 100644 400_xowa/src/gplx/xowa/htmls/Xoh_img_mgr.java create mode 100644 400_xowa/src/gplx/xowa/htmls/core/hzips/Xoh_decode_ctx.java delete mode 100644 400_xowa/src/gplx/xowa/htmls/core/hzips/Xoh_hzip_mgr_fxt.java delete mode 100644 400_xowa/src/gplx/xowa/htmls/core/parsers/Xoh_doc_wkr__tag.java delete mode 100644 400_xowa/src/gplx/xowa/htmls/core/parsers/Xoh_parser_fxt.java delete mode 100644 400_xowa/src/gplx/xowa/htmls/core/parsers/Xoh_wkr__hzip.java rename 400_xowa/src/gplx/xowa/htmls/core/wkrs/{escapes/Xoh_escape_parse_tst.java => Xoh_hdoc_ctx.java} (60%) rename 400_xowa/src/gplx/xowa/htmls/core/{parsers/Xoh_wkr.java => wkrs/Xoh_hdoc_wkr.java} (57%) create mode 100644 400_xowa/src/gplx/xowa/htmls/core/wkrs/Xoh_hdoc_wkr__base.java create mode 100644 400_xowa/src/gplx/xowa/htmls/core/wkrs/Xoh_hdoc_wkr__hzip.java create mode 100644 400_xowa/src/gplx/xowa/htmls/core/wkrs/Xoh_hdoc_wkr__make.java create mode 100644 400_xowa/src/gplx/xowa/htmls/core/wkrs/Xoh_itm_parser.java create mode 100644 400_xowa/src/gplx/xowa/htmls/core/wkrs/Xoh_itm_parser_fxt_base.java rename 400_xowa/src/gplx/xowa/htmls/core/wkrs/escapes/{Xoh_escape_parse.java => Xoh_escape_parser.java} (81%) delete mode 100644 400_xowa/src/gplx/xowa/htmls/core/wkrs/hdrs/Xoh_hdr_parse.java delete mode 100644 400_xowa/src/gplx/xowa/htmls/core/wkrs/hdrs/Xoh_hdr_parse_base.java create mode 100644 400_xowa/src/gplx/xowa/htmls/core/wkrs/hdrs/Xoh_hdr_parser.java rename 400_xowa/src/gplx/xowa/htmls/core/wkrs/{hdrs/Xoh_hdr_parse_tst.java => imgs/Xoh_img_html__dump__tst.java} (56%) create mode 100644 400_xowa/src/gplx/xowa/htmls/core/wkrs/imgs/Xoh_img_hzip.java rename 400_xowa/src/gplx/xowa/htmls/core/wkrs/{txts/Xoh_txt_parse_tst.java => imgs/Xoh_img_hzip__dump__tst.java} (66%) create mode 100644 400_xowa/src/gplx/xowa/htmls/core/wkrs/imgs/Xoh_img_hzip__view__tst.java create mode 100644 400_xowa/src/gplx/xowa/htmls/core/wkrs/imgs/Xoh_img_make.java create mode 100644 400_xowa/src/gplx/xowa/htmls/core/wkrs/imgs/Xoh_img_make__dump__tst.java create mode 100644 400_xowa/src/gplx/xowa/htmls/core/wkrs/imgs/Xoh_img_parser.java create mode 100644 400_xowa/src/gplx/xowa/htmls/core/wkrs/imgs/atrs/Xoh_anch_cls_.java create mode 100644 400_xowa/src/gplx/xowa/htmls/core/wkrs/imgs/atrs/Xoh_anch_cls_parser.java create mode 100644 400_xowa/src/gplx/xowa/htmls/core/wkrs/imgs/atrs/Xoh_img_cls_.java create mode 100644 400_xowa/src/gplx/xowa/htmls/core/wkrs/imgs/atrs/Xoh_img_cls__tst.java create mode 100644 400_xowa/src/gplx/xowa/htmls/core/wkrs/imgs/atrs/Xoh_img_cls_parser.java create mode 100644 400_xowa/src/gplx/xowa/htmls/core/wkrs/imgs/atrs/Xoh_img_src_parser.java create mode 100644 400_xowa/src/gplx/xowa/htmls/core/wkrs/imgs/atrs/Xoh_img_src_parser_tst.java create mode 100644 400_xowa/src/gplx/xowa/htmls/core/wkrs/imgs/atrs/Xoh_img_xoimg_parser.java rename 400_xowa/src/gplx/xowa/htmls/core/{to_delete/Xoh_hzip_href.java => wkrs/lnkes/Xoh_href_hzip.java} (86%) delete mode 100644 400_xowa/src/gplx/xowa/htmls/core/wkrs/lnkes/Xoh_lnke_parse.java create mode 100644 400_xowa/src/gplx/xowa/htmls/core/wkrs/lnkes/Xoh_lnke_parser.java delete mode 100644 400_xowa/src/gplx/xowa/htmls/core/wkrs/lnkis/Xoh_lnki_parse.java delete mode 100644 400_xowa/src/gplx/xowa/htmls/core/wkrs/lnkis/Xoh_lnki_parse_tst.java create mode 100644 400_xowa/src/gplx/xowa/htmls/core/wkrs/lnkis/Xoh_lnki_parser.java rename 400_xowa/src/gplx/xowa/htmls/core/{parsers => wkrs/lnkis}/Xoh_ttl_matcher.java (72%) rename 400_xowa/src/gplx/xowa/htmls/core/{parsers => wkrs/lnkis}/Xoh_ttl_matcher_tst.java (83%) create mode 100644 400_xowa/src/gplx/xowa/htmls/core/wkrs/lnkis/anchs/Xoh_anch_href_parser.java create mode 100644 400_xowa/src/gplx/xowa/htmls/core/wkrs/lnkis/anchs/Xoh_anch_href_parser_tst.java delete mode 100644 400_xowa/src/gplx/xowa/htmls/core/wkrs/lnkis/htmls/Xoh_lnki_consts_tst.java rename 400_xowa/src/gplx/xowa/htmls/core/wkrs/spaces/{Xoh_space_parse.java => Xoh_space_parser.java} (84%) create mode 100644 400_xowa/src/gplx/xowa/htmls/core/wkrs/tags/Xoh_doc_wkr__tag.java create mode 100644 400_xowa/src/gplx/xowa/htmls/core/wkrs/thms/Xoh_thm_html_tst.java create mode 100644 400_xowa/src/gplx/xowa/htmls/core/wkrs/thms/Xoh_thm_hzip.java create mode 100644 400_xowa/src/gplx/xowa/htmls/core/wkrs/thms/Xoh_thm_hzip_tst.java create mode 100644 400_xowa/src/gplx/xowa/htmls/core/wkrs/thms/Xoh_thm_parse.java rename 400_xowa/src/gplx/xowa/htmls/core/wkrs/txts/{Xoh_txt_parse.java => Xoh_txt_parser.java} (82%) rename 400_xowa/src/gplx/xowa/htmls/{core/parsers/Xoh_parser_.java => heads/Xoh_head_itm__gallery_styles.java} (51%) create mode 100644 400_xowa/src/gplx/xowa/wikis/nss/Xow_ns_canonical_.java create mode 100644 400_xowa/src/gplx/xowa/wikis/xwikis/Xow_xwiki_itm_tst.java diff --git a/100_core/src/gplx/Tfds.java b/100_core/src/gplx/Tfds.java index 605a6530a..4eea039a4 100644 --- a/100_core/src/gplx/Tfds.java +++ b/100_core/src/gplx/Tfds.java @@ -212,10 +212,17 @@ class TfdsMsgBldr { } for (int i = 0; i < list.Count(); i++) { TfdsEqAryItm itm = (TfdsEqAryItm)list.Get_at(i); + String eq_str = itm.Eq() ? "==" : ""; + if (!itm.Eq()) { +// if (lhsLenMax < 8 ) +// eq_str = "!="; +// else + eq_str = "\n!= "; + } sb.Add_fmt_line("{0}: {1} {2} {3}" , Int_.To_str_pad_bgn_zero(itm.Idx(), 4) , String_.PadBgn(itm.Lhs(), lhsLenMax, " ") - , itm.Eq() ? "==" : "!=" + , eq_str , String_.PadBgn(itm.Rhs(), rhsLenMax, " ") ); } diff --git a/100_core/src_101_types_object/gplx/Decimal_adp_.java b/100_core/src_101_types_object/gplx/Decimal_adp_.java index aa84fd911..8912dd3e2 100644 --- a/100_core/src_101_types_object/gplx/Decimal_adp_.java +++ b/100_core/src_101_types_object/gplx/Decimal_adp_.java @@ -16,7 +16,11 @@ You should have received a copy of the GNU Affero General Public License along with this program. If not, see . */ package gplx; -import java.math.BigDecimal; import java.math.MathContext; import java.math.RoundingMode; public class Decimal_adp_ { +import java.math.BigDecimal; import java.math.MathContext; import java.math.RoundingMode; import java.text.DecimalFormat; +import java.text.NumberFormat; +import java.text.ParseException; +import java.util.Locale; +public class Decimal_adp_ { public static final Class Cls_ref_type = Decimal_adp.class; public static Decimal_adp as_(Object obj) {return obj instanceof Decimal_adp ? (Decimal_adp)obj : null;} public static final Decimal_adp Zero = new Decimal_adp(0); @@ -53,5 +57,14 @@ import java.math.BigDecimal; import java.math.MathContext; import java.math.Roun public static Decimal_adp divide_(long lhs, long rhs) { return new Decimal_adp(new BigDecimal(lhs).divide(new BigDecimal(rhs), Gplx_rounding_context)); } public static Decimal_adp int_(int v) {return new Decimal_adp(new BigDecimal(v));} public static Decimal_adp long_(long v) {return new Decimal_adp(new BigDecimal(v));} public static Decimal_adp float_(float v) {return new Decimal_adp(new BigDecimal(v));} public static Decimal_adp double_(double v) {return new Decimal_adp(new BigDecimal(v));} public static Decimal_adp double_thru_str_(double v) {return new Decimal_adp(BigDecimal.valueOf(v));} - public static Decimal_adp db_(Object v) {return new Decimal_adp((BigDecimal)v);} public static Decimal_adp parse(String raw) {return new Decimal_adp(new BigDecimal(raw));} public static Decimal_adp pow_10_(int v) {return new Decimal_adp(new BigDecimal(1).scaleByPowerOfTen(v));} + public static Decimal_adp db_(Object v) {return new Decimal_adp((BigDecimal)v);} public static Decimal_adp parse(String raw) { + try { + DecimalFormat nf = (DecimalFormat)NumberFormat.getInstance(Locale.getDefault()); + nf.setParseBigDecimal(true); + BigDecimal bd = (BigDecimal)nf.parse(raw); + return new Decimal_adp(bd); + } catch (ParseException e) { + throw Err_.new_("Decimal_adp_", "parse to decimal failed", "raw", raw); + } + } public static Decimal_adp pow_10_(int v) {return new Decimal_adp(new BigDecimal(1).scaleByPowerOfTen(v));} public static final MathContext RoundDownContext = new MathContext(0, RoundingMode.DOWN); public static final MathContext Gplx_rounding_context = new MathContext(14, RoundingMode.HALF_UP); // changed from 28 to 14; DATE:2015-07-31 } diff --git a/100_core/src_101_types_object/gplx/Object_.java b/100_core/src_101_types_object/gplx/Object_.java index 50b4a2c10..8b5f9468e 100644 --- a/100_core/src_101_types_object/gplx/Object_.java +++ b/100_core/src_101_types_object/gplx/Object_.java @@ -20,6 +20,18 @@ public class Object_ { public static final String Cls_val_name = "Object"; public static final Object[] Ary_empty = new Object[0]; public static Object[] Ary(Object... ary) {return ary;} + public static Object[] Ary_add(Object[] lhs, Object[] rhs) { + int lhs_len = lhs.length, rhs_len = rhs.length; + if (lhs_len == 0) return rhs; + else if (rhs_len == 0) return lhs; + int rv_len = lhs_len + rhs_len; + Object[] rv = new Object[rv_len]; + for (int i = 0; i < lhs_len; ++i) + rv[i] = lhs[i]; + for (int i = lhs_len; i < rv_len; ++i) + rv[i] = rhs[i - lhs_len]; + return rv; + } public static boolean Eq(Object lhs, Object rhs) { if (lhs == null && rhs == null) return true; else if (lhs == null || rhs == null) return false; diff --git a/100_core/src_101_types_object/gplx/String_.java b/100_core/src_101_types_object/gplx/String_.java index 3208240d8..7a658de2f 100644 --- a/100_core/src_101_types_object/gplx/String_.java +++ b/100_core/src_101_types_object/gplx/String_.java @@ -41,7 +41,7 @@ public class String_ implements GfoInvkAble { ? null : new String(v, bgn, end - bgn, "UTF-8"); } - catch (Exception e) {throw Err_.new_exc(e, "core", "unsupported encoding");} + catch (Exception e) {Err_.Noop(e); throw Err_.new_("core", "unsupported encoding", "bgn", bgn, "end", end);} } public static String new_u8__by_len(byte[] v, int bgn, int len) { int v_len = v.length; @@ -115,7 +115,7 @@ public class String_ implements GfoInvkAble { return false; } public static boolean EqNot(String lhs, String rhs) {return !Object_.Eq(lhs, rhs);} - public static boolean EqEmpty(String lhs, String rhs) {return lhs.equals("");} + public static boolean EqEmpty(String lhs) {return lhs.equals("");} public static String IfNullOrEmpty(String s, String or) {return s == null || s.length() == 0 ? or : s;} public static int Compare(String lhs, String rhs) {return lhs.compareTo(rhs);} // NOTE: Compare instead of compareTo b/c javafy lowercases compareTo public static int Compare_ignoreCase(String lhs, String rhs) { diff --git a/100_core/src_130_brys/gplx/Bry_.java b/100_core/src_130_brys/gplx/Bry_.java index dce01deb5..8cf7dbe7f 100644 --- a/100_core/src_130_brys/gplx/Bry_.java +++ b/100_core/src_130_brys/gplx/Bry_.java @@ -286,8 +286,13 @@ public class Bry_ { return String_.new_u8(ary); } public static byte[] Mid_safe(byte[] src, int bgn, int end) { - try {return Mid(src, bgn, end);} - catch (Exception e) {Err_.Noop(e); return Bry_.Add_w_dlm(Byte_ascii.Space, Bry_.new_by_int(bgn), Bry_.new_by_int(end));} + if (src == null) return null; + int src_len = src.length; + if (bgn < 0) bgn = 0; + if (end >= src_len) end = src_len; + if (bgn > end) bgn = end; + else if (end < bgn) end = bgn; + return Mid(src, bgn, end); } public static byte[] Mid(byte[] src, int bgn) {return Mid(src, bgn, src.length);} public static byte[] Mid_or(byte[] src, int bgn, int end, byte[] or) { diff --git a/100_core/src_130_brys/gplx/Bry_rdr.java b/100_core/src_130_brys/gplx/Bry_rdr_old.java similarity index 95% rename from 100_core/src_130_brys/gplx/Bry_rdr.java rename to 100_core/src_130_brys/gplx/Bry_rdr_old.java index 36e19ea8b..b651fa847 100644 --- a/100_core/src_130_brys/gplx/Bry_rdr.java +++ b/100_core/src_130_brys/gplx/Bry_rdr_old.java @@ -16,7 +16,7 @@ You should have received a copy of the GNU Affero General Public License along with this program. If not, see . */ package gplx; -public class Bry_rdr { +public class Bry_rdr_old { private byte[] scope = Bry_.Empty; public byte[] Src() {return src;} protected byte[] src; public int Src_len() {return src_len;} protected int src_len; @@ -26,7 +26,7 @@ public class Bry_rdr { this.src = src; this.src_len = src.length; this.pos = pos; this.scope = scope; } - public int Pos() {return pos;} public Bry_rdr Pos_(int v) {this.pos = v; return this;} protected int pos; + public int Pos() {return pos;} public Bry_rdr_old Pos_(int v) {this.pos = v; return this;} protected int pos; public void Pos_add(int v) {pos += v;} public boolean Pos_is_eos() {return pos == src_len;} public boolean Pos_is_reading() {return pos < src_len;} @@ -106,7 +106,7 @@ public class Bry_rdr { byte[] double_bry = Read_bry_to(to_char); return Double_.parse(String_.new_a7(double_bry)); // double will never have utf8 } - @gplx.Virtual public Bry_rdr Skip_ws() { + @gplx.Virtual public Bry_rdr_old Skip_ws() { while (pos < src_len) { switch (src[pos]) { case Byte_ascii.Tab: case Byte_ascii.Nl: case Byte_ascii.Cr: case Byte_ascii.Space: @@ -118,7 +118,7 @@ public class Bry_rdr { } return this; } - public Bry_rdr Skip_alpha_num_under() { + public Bry_rdr_old Skip_alpha_num_under() { while (pos < src_len) { switch (src[pos]) { case Byte_ascii.Num_0: case Byte_ascii.Num_1: case Byte_ascii.Num_2: case Byte_ascii.Num_3: case Byte_ascii.Num_4: diff --git a/100_core/src_420_usrMsg/gplx/Gfo_usr_dlg_.java b/100_core/src_420_usrMsg/gplx/Gfo_usr_dlg_.java index 135bf446f..4d3806701 100644 --- a/100_core/src_420_usrMsg/gplx/Gfo_usr_dlg_.java +++ b/100_core/src_420_usrMsg/gplx/Gfo_usr_dlg_.java @@ -17,13 +17,34 @@ along with this program. If not, see . */ package gplx; public class Gfo_usr_dlg_ { + private static Gfo_usr_dlg_base test__list, test__show; public static Gfo_usr_dlg Instance = Gfo_usr_dlg_noop.Instance; // NOTE: global instance which can be reassigned public static final Gfo_usr_dlg Noop = Gfo_usr_dlg_noop.Instance; + public static Gfo_usr_dlg__gui Test__list__init() { + if (test__list == null) + test__list = new Gfo_usr_dlg_base(Gfo_usr_dlg__log_.Noop, Gfo_usr_dlg__gui_.Test); + Gfo_usr_dlg__gui_.Test.Clear(); + Instance = test__list; + return Gfo_usr_dlg__gui_.Test; + } + public static String Test__list__term__get_1st() { + Instance = Noop; + String[] rv = ((Gfo_usr_dlg__gui_test)test__list.Gui_wkr()).Warns().To_str_ary_and_clear(); + return rv.length == 0 ? "" : rv[0]; + } + public static void Test__show__init() { + if (test__show == null) + test__show = new Gfo_usr_dlg_base(Gfo_usr_dlg__log_.Noop, Gfo_usr_dlg__gui_.Console); + Instance = test__show; + } + public static void Test__show__term() { + Instance = Noop; + } public static Gfo_usr_dlg Test() { - if (test == null) - test = new Gfo_usr_dlg_base(Gfo_usr_dlg__log_.Noop, Gfo_usr_dlg__gui_.Test); - return test; - } private static Gfo_usr_dlg_base test; + if (test__list == null) + test__list = new Gfo_usr_dlg_base(Gfo_usr_dlg__log_.Noop, Gfo_usr_dlg__gui_.Test); + return test__list; + } public static Gfo_usr_dlg Test_console() { if (test_console == null) test_console = new Gfo_usr_dlg_base(Gfo_usr_dlg__log_.Noop, Gfo_usr_dlg__gui_.Console); diff --git a/100_core/src_420_usrMsg/gplx/Gfo_usr_dlg__gui_test.java b/100_core/src_420_usrMsg/gplx/Gfo_usr_dlg__gui_test.java index 7067daf37..436132bc3 100644 --- a/100_core/src_420_usrMsg/gplx/Gfo_usr_dlg__gui_test.java +++ b/100_core/src_420_usrMsg/gplx/Gfo_usr_dlg__gui_test.java @@ -18,13 +18,12 @@ along with this program. If not, see . package gplx; import gplx.core.strings.*; public class Gfo_usr_dlg__gui_test implements Gfo_usr_dlg__gui { - public String[] Xto_str_ary() {return msgs.To_str_ary();} - public String[] Xto_str_ary_and_clear() {String[] rv = msgs.To_str_ary(); this.Clear(); return rv;} - public List_adp Warns() {return warns;} - public String_ring Prog_msgs() {return ring;} String_ring ring = new String_ring().Max_(0); + public List_adp Warns() {return warns;} private final List_adp warns = List_adp_.new_(); + public List_adp Msgs() {return msgs;} private final List_adp msgs = List_adp_.new_(); + public String_ring Prog_msgs() {return ring;} private final String_ring ring = new String_ring().Max_(0); public void Clear() {msgs.Clear(); warns.Clear();} - public void Write_prog(String text) {msgs.Add(text);} List_adp msgs = List_adp_.new_(); + public void Write_prog(String text) {msgs.Add(text);} public void Write_note(String text) {msgs.Add(text);} - public void Write_warn(String text) {warns.Add(text);} List_adp warns = List_adp_.new_(); + public void Write_warn(String text) {warns.Add(text);} public void Write_stop(String text) {msgs.Add(text);} } diff --git a/140_dbs/src/gplx/dbs/metas/parsers/Meta_fld_wkr__base.java b/140_dbs/src/gplx/dbs/metas/parsers/Meta_fld_wkr__base.java index f9611bea3..d5ab429cc 100644 --- a/140_dbs/src/gplx/dbs/metas/parsers/Meta_fld_wkr__base.java +++ b/140_dbs/src/gplx/dbs/metas/parsers/Meta_fld_wkr__base.java @@ -29,7 +29,7 @@ abstract class Meta_fld_wkr__base { public void Reg(Btrie_slim_mgr trie) { trie.Add_obj(hook, this); } - @gplx.Virtual public void Match(Bry_rdr rdr, Meta_fld_itm fld) { + @gplx.Virtual public void Match(Bry_rdr_old rdr, Meta_fld_itm fld) { for (int i = 0; i < words_len; ++i) { rdr.Skip_ws(); byte[] word = words_ary[i]; @@ -88,7 +88,7 @@ class Meta_fld_wkr__autonumber extends Meta_fld_wkr__base { } class Meta_fld_wkr__default extends Meta_fld_wkr__base { public Meta_fld_wkr__default() {this.Ctor(Hook);} - @Override public void Match(Bry_rdr rdr, Meta_fld_itm fld) { + @Override public void Match(Bry_rdr_old rdr, Meta_fld_itm fld) { Object default_val = null; rdr.Skip_ws(); byte[] src = rdr.Src(); diff --git a/140_dbs/src/gplx/dbs/metas/parsers/Meta_parser__fld.java b/140_dbs/src/gplx/dbs/metas/parsers/Meta_parser__fld.java index c86196326..bb3323fc7 100644 --- a/140_dbs/src/gplx/dbs/metas/parsers/Meta_parser__fld.java +++ b/140_dbs/src/gplx/dbs/metas/parsers/Meta_parser__fld.java @@ -18,7 +18,7 @@ along with this program. If not, see . package gplx.dbs.metas.parsers; import gplx.*; import gplx.dbs.*; import gplx.dbs.metas.*; import gplx.core.brys.*; import gplx.core.btries.*; public class Meta_parser__fld { - public Meta_type_itm Parse_type(Bry_rdr rdr) { + public Meta_type_itm Parse_type(Bry_rdr_old rdr) { rdr.Skip_ws(); Object type_obj = type_trie.Match_bgn(rdr.Src(), rdr.Pos(), rdr.Src_len()); if (type_obj == null) throw Err_.new_wo_type("invalid fld type", "snip", rdr.Mid_by_len_safe(40)); diff --git a/140_dbs/src/gplx/dbs/metas/parsers/Sql_bry_rdr.java b/140_dbs/src/gplx/dbs/metas/parsers/Sql_bry_rdr.java index 25df49e50..497968a01 100644 --- a/140_dbs/src/gplx/dbs/metas/parsers/Sql_bry_rdr.java +++ b/140_dbs/src/gplx/dbs/metas/parsers/Sql_bry_rdr.java @@ -17,7 +17,7 @@ along with this program. If not, see . */ package gplx.dbs.metas.parsers; import gplx.*; import gplx.dbs.*; import gplx.dbs.metas.*; import gplx.core.brys.*; -public class Sql_bry_rdr extends Bry_rdr { public byte[] Read_sql_identifier() { +public class Sql_bry_rdr extends Bry_rdr_old { public byte[] Read_sql_identifier() { this.Skip_ws(); int bgn = pos, end = -1; if (pos == src_len) return null; @@ -33,7 +33,7 @@ public class Sql_bry_rdr extends Bry_rdr { public byte[] Read_sql_identifier() } return Bry_.Mid(src, bgn, end); } - @Override public Bry_rdr Skip_ws() { + @Override public Bry_rdr_old Skip_ws() { byte b_0 = pos < src_len ? src[pos] : Byte_ascii.Null; byte bgn_1 = Byte_ascii.Null; byte[] end_bry = null; diff --git a/400_xowa/src/gplx/core/brys/Bit_.java b/400_xowa/src/gplx/core/brys/Bit_.java index f2f04a6f3..59e437d37 100644 --- a/400_xowa/src/gplx/core/brys/Bit_.java +++ b/400_xowa/src/gplx/core/brys/Bit_.java @@ -17,7 +17,7 @@ along with this program. If not, see . */ package gplx.core.brys; import gplx.*; import gplx.core.*; public class Bit_ { - public static String XtoBitStr(int val) { + public static String ToBitStr(int val) { boolean[] bits = new boolean[8]; int idx = 7; while (val > 0) { @@ -30,56 +30,7 @@ public class Bit_ { rv[i] = bits[i] ? Byte_ascii.Num_1 : Byte_ascii.Num_0; return String_.new_a7(rv); } - public static int Get_flag(int i) {return Base2_ary[i];} - public static int[] Bld_pow_ary(int... seg_ary) { - int seg_ary_len = seg_ary.length; - int pow = 0; - int[] rv = new int[seg_ary_len]; - for (int i = seg_ary_len - 1; i > -1; i--) { - rv[i] = Base2_ary[pow]; - pow += seg_ary[i]; - } - return rv; - } - public static int Xto_int(int[] pow_ary, int[] val_ary) { - int pow_ary_last = pow_ary.length - 1; - int val = 0; - for (int i = pow_ary_last; i > -1; i--) - val += pow_ary[i] * val_ary[i]; - return val; - } - public static int[] Xto_intAry(int[] pow_ary, int v) { - int[] rv = new int[pow_ary.length]; - Xto_intAry(rv, pow_ary, v); - return rv; - } - public static void Xto_intAry(int[] rv, int[] pow_ary, int v) { - int pow_ary_len = pow_ary.length; - int rv_len = rv.length; - for (int i = 0; i < pow_ary_len; i++) { - if (i >= rv_len) break; - rv[i] = v / pow_ary[i]; - int factor = pow_ary[i] * rv[i]; - v = factor == 0 ? v : (v % factor); // NOTE: if 0, do not do modulus or else div by zero - } - } - public static byte Xto_byte(byte[] pow_ary, byte... val_ary) { - int pow_ary_last = pow_ary.length - 1; - int val = 0; - for (int i = pow_ary_last; i > -1; --i) - val += pow_ary[i] * val_ary[i]; - return (byte)val; - } - public static void Xto_bry(byte[] rv, byte[] pow_ary, byte val) { - int pow_ary_len = pow_ary.length; - int rv_len = rv.length; - for (int i = 0; i < pow_ary_len; i++) { - if (i >= rv_len) break; - rv[i] = (byte)(val / pow_ary[i]); - int factor = pow_ary[i] * rv[i]; - val = (byte)(factor == 0 ? val : (val % factor)); // NOTE: if 0, do not do modulus or else div by zero - } - } + public static int Get_flag(int i) {return Int_flag_bldr_.Base2_ary[i];} public static int Shift_lhs(int val, int shift) {return val << shift;} public static int Shift_rhs(int val, int shift) {return val >> shift;} public static int Shift_lhs_to_int(int[] shift_ary, int... val_ary) { @@ -101,24 +52,4 @@ public class Bit_ { val -= (itm << shift); } } - public static int Xto_int_date_short(int[] val_ary) { - val_ary[0] -= 1900; - return Xto_int(Pow_ary_date_short, val_ary); - } - public static void Xto_date_short_int_ary(int[] rv, int v) { - Xto_intAry(rv, Pow_ary_date_short, v); - rv[0] += 1900; - } - public static DateAdp Xto_date_short(int v) { - int[] rv = new int[Pow_ary_date_short.length]; - Xto_date_short_int_ary(rv, v); - return DateAdp_.seg_(rv); - } - private static final int[] Pow_ary_date_short = new int[] {1048576, 65536, 2048, 64, 1}; // yndhm -> 12,4,5,5,6 - private static final int[] Base2_ary = new int[] - { 1, 2, 4, 8, 16, 32, 64, 128 - , 256, 512, 1024, 2048, 4096, 8192, 16384, 32768 - , 65536, 131072, 262144, 524288, 1048576, 2097152, 4194304, 8388608 - , 16777216, 33554432, 67108864, 134217728, 268435456, 536870912, 1073741824, 0 - }; } diff --git a/400_xowa/src/gplx/core/brys/Bit__tst.java b/400_xowa/src/gplx/core/brys/Bit__tst.java index 1c8bd7650..65fcb48bd 100644 --- a/400_xowa/src/gplx/core/brys/Bit__tst.java +++ b/400_xowa/src/gplx/core/brys/Bit__tst.java @@ -25,48 +25,7 @@ public class Bit__tst { tst_XtoBitStr( 2, "00000010"); tst_XtoBitStr( 3, "00000011"); tst_XtoBitStr(255, "11111111"); - } void tst_XtoBitStr(int val, String expd) {Tfds.Eq(expd, Bit_.XtoBitStr(val));} - @Test public void Bld_pow_ary() { - tst_Bld_pow_ary(ary_(1, 1, 1, 1), ary_(8, 4, 2, 1)); - tst_Bld_pow_ary(ary_(3, 2) , ary_(4, 1)); - } void tst_Bld_pow_ary(int[] seg_ary, int[] expd) {Tfds.Eq_ary_str(expd, Bit_.Bld_pow_ary(seg_ary));} - @Test public void Xto_int() { - tst_Xto_int(ary_(1, 1, 1, 1) , ary_(1, 1, 1, 1), 15); - tst_Xto_int(ary_(1, 1, 1, 1) , ary_(0, 0, 0, 0), 0); - tst_Xto_int(ary_(1, 1, 1, 1) , ary_(1, 0, 0, 1), 9); - tst_Xto_int(ary_(1, 1, 1, 1) , ary_(0, 1, 1, 0), 6); - tst_Xto_int(ary_(3, 2) , ary_(7, 3) , 31); - tst_Xto_int(ary_(3, 2, 1) , ary_(7, 3, 1) , 63); - tst_Xto_int(ary_(11, 4, 5, 5, 6), ary_(2012, 6, 3, 23, 17), 2110135761); - tst_Xto_int(ary_(11, 4, 5, 5, 6), ary_(2012, 6, 3, 23, 18), 2110135762); - } - private void tst_Xto_int(int[] seg_ary, int[] val_ary, int expd) { - int[] pow_ary = Bit_.Bld_pow_ary(seg_ary); - Tfds.Eq(expd, Bit_.Xto_int(pow_ary, val_ary)); - } - @Test public void Xto_intAry() { - tst_Xto_intAry(ary_(1, 1, 1, 1) , 15, ary_(1, 1, 1, 1)); - tst_Xto_intAry(ary_(3, 2) , 31, ary_(7, 3)); - tst_Xto_intAry(ary_(3, 2, 1) , 63, ary_(7, 3, 1)); - tst_Xto_intAry(ary_(12, 4, 5, 5, 6), 2110135761, ary_(2012, 6, 3, 23, 17)); - tst_Xto_intAry(ary_(12, 4, 5, 5, 6), 2110135762, ary_(2012, 6, 3, 23, 18)); - } - private void tst_Xto_intAry(int[] seg_ary, int val, int[] expd) { - int[] pow_ary = Bit_.Bld_pow_ary(seg_ary); - Tfds.Eq_ary_str(expd, Bit_.Xto_intAry(pow_ary, val)); - } - int[] ary_(int... v) {return v;} - @Test public void Xto_int_date_short() { - tst_Xto_int_date_short("20120604 2359", 117843451); - tst_Xto_int_date_short("20120604 2358", 117843450); - tst_Xto_int_date_short("20120605 0000", 117843968); - } - private void tst_Xto_int_date_short(String date_str, int expd) { - DateAdp date = DateAdp_.parse_fmt(date_str, "yyyyMMdd HHmm"); - int date_int = Bit_.Xto_int_date_short(date.XtoSegAry()); - Tfds.Eq(expd, date_int); - Tfds.Eq(date_str, Bit_.Xto_date_short(date_int).XtoStr_fmt("yyyyMMdd HHmm")); - } + } void tst_XtoBitStr(int val, String expd) {Tfds.Eq(expd, Bit_.ToBitStr(val));} @Test public void Shift_lhs() {// simple: shift 1 bit fxt.Test_shift_lhs(1, 1, 2); fxt.Test_shift_lhs(2, 1, 4); diff --git a/400_xowa/src/gplx/core/brys/Bry_parser.java b/400_xowa/src/gplx/core/brys/Bry_parser.java deleted file mode 100644 index c7e19283c..000000000 --- a/400_xowa/src/gplx/core/brys/Bry_parser.java +++ /dev/null @@ -1,130 +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 . -*/ -package gplx.core.brys; import gplx.*; import gplx.core.*; -public class Bry_parser { - private final gplx.core.primitives.Int_obj_ref pos_ref = gplx.core.primitives.Int_obj_ref.neg1_(); - private byte[] page; private String wkr_name; private int hook_bgn; - public byte[] Src() {return src;} private byte[] src; - public int Src_len() {return src_len;} private int src_len; - public int Pos() {return pos;} private int pos; - public void Init_src(byte[] page, byte[] src, int src_len, int pos) { - this.page = page; this.src = src; this.src_len = src_len; this.pos = pos; - } - public void Init_hook(String wkr_name, int hook_bgn, int hook_end) { - this.wkr_name = wkr_name; this.hook_bgn = hook_bgn; this.pos = hook_end; - } - public int Pos_(int v) {this.pos = v; return pos;} - public int Pos_add_one() {return Pos_add(1);} - public int Pos_add(int adj) { - this.pos += adj; - return pos; - } - public byte Read_byte() { - byte rv = src[pos]; - ++pos; - return rv; - } - public int Read_int_to(byte to_char) { - int bgn = pos; - int rv = 0; - int negative = 1; - while (pos < src_len) { - byte b = src[pos++]; - switch (b) { - case Byte_ascii.Num_0: case Byte_ascii.Num_1: case Byte_ascii.Num_2: case Byte_ascii.Num_3: case Byte_ascii.Num_4: - case Byte_ascii.Num_5: case Byte_ascii.Num_6: case Byte_ascii.Num_7: case Byte_ascii.Num_8: case Byte_ascii.Num_9: - rv = (rv * 10) + (b - Byte_ascii.Num_0); - break; - case Byte_ascii.Dash: - if (negative == -1) // 2nd negative - throw Fail("invalid int", String_.new_u8(src, bgn, pos)); - else // 1st negative - negative = -1; // flag negative - break; - default: { - boolean match = b == to_char; - if (to_char == Byte_ascii.Null) {// hack for Read_int_to_non_num - --pos; - match = true; - } - if (!match) throw Fail("invalid int", String_.new_u8(src, bgn, pos)); - return rv * negative; - } - } - } - if (bgn == pos) throw Fail("int is empty", String_.Empty); - return rv * negative; - } - public byte Read_byte_as_a7_int() { - byte rv = Byte_ascii.To_a7_int(src[pos]); - ++pos; - return rv; - } - public int Read_int_by_base85(int reqd) { - int rv = gplx.xowa.htmls.core.hzips.Xoh_hzip_int_.Decode(reqd, src, src_len, pos, pos_ref); - pos = pos_ref.Val(); - return rv; - } - public boolean Is(byte find) { - boolean rv = src[pos] == find; - if (rv) ++pos; // only advance if match; - return rv; - } - public int Chk(byte[] find) { - int find_end = pos + find.length; - if (!Bry_.Match(src, pos, find_end, find)) throw Fail("failed check", String_.new_u8(find)); - pos = find_end; - return pos; - } - public int Chk(byte find) { - if (src[pos] != find) throw Fail("failed check", Byte_ascii.To_str(find)); - ++pos; - return pos; - } - public int Fwd_bgn(byte[] find) { - int find_pos = Bry_find_.Find_fwd(src, find, pos, src_len); - if (find_pos == Bry_find_.Not_found) throw Fail("missing", String_.new_u8(find)); - pos = find_pos + find.length; - return find_pos; - } - public int Fwd_bgn(byte find) { - int find_pos = Bry_find_.Find_fwd(src, find, pos, src_len); - if (find_pos == Bry_find_.Not_found) throw Fail("missing", Byte_ascii.To_str(find)); - pos = find_pos + 1; - return find_pos; - } - public int Fwd_end(byte[] find) { - int find_pos = Bry_find_.Find_fwd(src, find, pos, src_len); - if (find_pos == Bry_find_.Not_found) throw Fail("missing", String_.new_u8(find)); - pos = find_pos + find.length; - return pos; - } - public int Fwd_end(byte find) { - int find_pos = Bry_find_.Find_fwd(src, find, pos, src_len); - if (find_pos == Bry_find_.Not_found) throw Fail("missing", Byte_ascii.To_str(find)); - pos = find_pos + 1; - return pos; - } - public int Fwd_while(byte find) { - this.pos = Bry_find_.Find_fwd_while(src, pos, src_len, find); - return pos; - } - public Err Fail(String msg, String arg) { - return Err_.new_("Bry_parser", msg, "arg", arg, "page", page, "wkr", wkr_name, "excerpt", Bry_.Mid_by_len_safe(src, hook_bgn, 255)); - } -} diff --git a/400_xowa/src/gplx/core/brys/Bry_rdr.java b/400_xowa/src/gplx/core/brys/Bry_rdr.java new file mode 100644 index 000000000..fb8b1ee03 --- /dev/null +++ b/400_xowa/src/gplx/core/brys/Bry_rdr.java @@ -0,0 +1,171 @@ +/* +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 . +*/ +package gplx.core.brys; import gplx.*; import gplx.core.*; +public class Bry_rdr { + private final gplx.core.primitives.Int_obj_ref pos_ref = gplx.core.primitives.Int_obj_ref.neg1_(); + private String ctx; private String wkr; private int err_bgn; + public byte[] Src() {return src;} private byte[] src; + public int Pos() {return pos;} private int pos; + public int Src_end() {return src_end;} private int src_end; + public Bry_rdr Dflt_dlm_(byte b) {this.dflt_dlm = b; return this;} private byte dflt_dlm; + public Bry_rdr Fail_throws_err_(boolean v) {this.fail_throws_err = v; return this;} private boolean fail_throws_err = true; + public Bry_rdr Ctor_by_page(byte[] ctx, byte[] src, int src_len) {this.ctx = Quote(String_.new_u8(ctx)); this.src = src; this.src_end = src_len; this.pos = 0; return this;} + public Bry_rdr Init_by_hook(String wkr, int err_bgn, int pos) {this.wkr = Quote(wkr); this.err_bgn = err_bgn; this.pos = pos; return this;} + public Bry_rdr Init_by_sub(Bry_rdr rdr, String wkr, int pos, int src_end) { + this.src = rdr.src; this.ctx = rdr.ctx; this.wkr = Quote(wkr); this.err_bgn = pos; this.pos = pos; this.src_end = src_end; + this.dflt_dlm = Byte_ascii.Null; + return this; + } + public int Move_to(int v) {this.pos = v; return pos;} + public int Move_by_one() {return Move_by(1);} + public int Move_by(int v) {this.pos += v; return pos;} + public int Find_fwd_lr() {return Find_fwd(dflt_dlm , Bool_.Y, Bool_.N);} + public int Find_fwd_lr(byte find) {return Find_fwd(find , Bool_.Y, Bool_.N);} + public int Find_fwd_lr(byte[] find) {return Find_fwd(find , Bool_.Y, Bool_.N);} + public int Find_fwd_rr() {return Find_fwd(dflt_dlm , Bool_.N, Bool_.N);} + public int Find_fwd_rr(byte find) {return Find_fwd(find , Bool_.N, Bool_.N);} + public int Find_fwd_rr(byte[] find) {return Find_fwd(find , Bool_.N, Bool_.N);} + private int Find_fwd(byte find, boolean ret_lhs, boolean pos_lhs) { + int find_pos = Bry_find_.Find_fwd(src, find, pos, src_end); if (find_pos == Bry_find_.Not_found) {Fail("find failed", "find", Byte_ascii.To_str(find)); return Bry_find_.Not_found;} + pos = find_pos + (pos_lhs ? 0 : 1); + return ret_lhs ? find_pos : pos; + } + private int Find_fwd(byte[] find, boolean ret_lhs, boolean pos_lhs) { + int find_pos = Bry_find_.Find_fwd(src, find, pos, src_end); if (find_pos == Bry_find_.Not_found) {Fail("find failed", "find", String_.new_u8(find)); return Bry_find_.Not_found;} + pos = find_pos + (pos_lhs ? 0 : find.length); + return ret_lhs ? find_pos : pos; + } + public byte Read_byte() { + byte rv = src[pos]; + ++pos; + return rv; + } + public byte Read_byte_to() {return Read_byte_to(dflt_dlm);} + public byte Read_byte_to(byte to_char) { + byte rv = src[pos]; + ++pos; + if (pos < src_end) { + if (src[pos] != to_char) {Fail("read byte to failed", "to", Byte_ascii.To_str(to_char)); return Byte_.Max_value_127;} + ++pos; + } + return rv; + } + public double Read_double_to() {return Read_double_to(dflt_dlm);} + public double Read_double_to(byte to_char) { + byte[] bry = Read_bry_to(to_char); + return Double_.parse(String_.new_a7(bry)); + } + public int Read_int_to() {return Read_int_to(dflt_dlm);} + public int Read_int_to(byte to_char) { + int bgn = pos; + int rv = 0; + int negative = 1; + while (pos < src_end) { + byte b = src[pos++]; + switch (b) { + case Byte_ascii.Num_0: case Byte_ascii.Num_1: case Byte_ascii.Num_2: case Byte_ascii.Num_3: case Byte_ascii.Num_4: + case Byte_ascii.Num_5: case Byte_ascii.Num_6: case Byte_ascii.Num_7: case Byte_ascii.Num_8: case Byte_ascii.Num_9: + rv = (rv * 10) + (b - Byte_ascii.Num_0); + break; + case Byte_ascii.Dash: + if (negative == -1) { // 2nd negative + Fail("invalid int", "mid", String_.new_u8(src, bgn, pos)); + return Int_.Min_value; + } + else // 1st negative + negative = -1; // flag negative + break; + default: { + boolean match = b == to_char; + if (to_char == Byte_ascii.Null) {// hack for Read_int_to_non_num + --pos; + match = true; + } + if (!match) { + Fail("invalid int", "mid", String_.new_u8(src, bgn, pos)); + return Int_.Min_value; + } + return rv * negative; + } + } + } + if (bgn == pos) {Fail("int is empty", String_.Empty, String_.Empty); return Int_.Min_value;} + return rv * negative; + } + public byte Read_byte_as_a7_int() { + byte rv = Byte_ascii.To_a7_int(src[pos]); + ++pos; + return rv; + } + public int Read_int_by_base85(int reqd) { + int rv = gplx.xowa.htmls.core.hzips.Xoh_hzip_int_.Decode(reqd, src, src_end, pos, pos_ref); + pos = pos_ref.Val(); + return rv; + } + public byte[] Read_bry_to() {return Read_bry_to(dflt_dlm);} + public byte[] Read_bry_to(byte b) { + int bgn = pos; + return Bry_.Mid(src, bgn, Find_fwd_lr(b)); + } + public boolean Is(byte find) { + boolean rv = src[pos] == find; + if (rv) ++pos; // only advance if match; + return rv; + } + public boolean Is(byte[] find) { + int find_len = find.length; + int find_end = pos + find_len; + boolean rv = Bry_.Match(src, pos, find_end, find, 0, find_len); + if (rv) pos = find_end; // only advance if match; + return rv; + } + public int Chk(byte find) { + if (src[pos] != find) {Fail("failed check", "chk", Byte_.To_str(find)); return Bry_find_.Not_found;} + ++pos; + return pos; + } + public int Chk(byte[] find) { + int find_end = pos + find.length; + if (!Bry_.Match(src, pos, find_end, find)) {Fail("failed check", "chk", String_.new_u8(find)); return Bry_find_.Not_found;} + pos = find_end; + return pos; + } + public byte Chk(gplx.core.btries.Btrie_slim_mgr trie) {return Chk(trie, pos, src_end);} + public byte Chk(gplx.core.btries.Btrie_slim_mgr trie, int itm_bgn, int itm_end) { + Object rv_obj = trie.Match_bgn(src, itm_bgn, itm_end); + if (rv_obj == null) {Fail("failed trie check", "mid", String_.new_u8(Bry_.Mid_by_len_safe(src, pos, 16))); return Byte_.Max_value_127;} + pos = trie.Match_pos(); + return ((gplx.core.primitives.Byte_obj_val)rv_obj).Val(); + } + public int Fail(String msg, String arg_key, Object arg_val) {return Fail(msg, arg_key, arg_val, err_bgn, err_bgn + 255);} + public int Fail(String msg, String arg_key, Object arg_val, int excerpt_bgn, int excerpt_end) { + arg_val = Quote(Object_.Xto_str_strict_or_null_mark(arg_val)); + String err_msg = Msg_make(msg, arg_key, arg_val, excerpt_bgn, excerpt_end); + Gfo_usr_dlg_.Instance.Warn_many("", "", err_msg); + if (fail_throws_err) throw Err_.new_("Bry_rdr", err_msg); + return Bry_find_.Not_found; + } + public Err Err_make(String msg, String arg_key, Object arg_val, int excerpt_bgn, int excerpt_end) {return Err_.new_("Bry_rdr", Msg_make(msg, arg_key, arg_val, excerpt_bgn, excerpt_end));} + private String Msg_make(String msg, String arg_key, Object arg_val, int excerpt_bgn, int excerpt_end) { + if (String_.EqEmpty(arg_key)) + return Err_msg.To_str(msg, "ctx", ctx, "wkr", wkr, "excerpt", Bry_.Mid_safe(src, excerpt_bgn, excerpt_end)); + else + return Err_msg.To_str(msg, arg_key, arg_val, "ctx", ctx, "wkr", wkr, "excerpt", Quote(String_.new_u8(Bry_.Mid_by_len_safe(src, excerpt_bgn, excerpt_end)))); + } + private static String Quote(String v) {return "'" + v + "'";} +} diff --git a/400_xowa/src/gplx/core/brys/Bry_rdr_tst.java b/400_xowa/src/gplx/core/brys/Bry_rdr_tst.java index ccdcb2c0e..0d404ae22 100644 --- a/400_xowa/src/gplx/core/brys/Bry_rdr_tst.java +++ b/400_xowa/src/gplx/core/brys/Bry_rdr_tst.java @@ -41,8 +41,8 @@ public class Bry_rdr_tst { } } class Bry_rdr_fxt { - private Bry_rdr rdr; - public void Clear() {rdr = new Bry_rdr();} + private Bry_rdr_old rdr; + public void Clear() {rdr = new Bry_rdr_old();} public Bry_rdr_fxt Init_src(String v) {rdr.Init(Bry_.new_u8(v)); return this;} public Bry_rdr_fxt Init_pos(int v) {rdr.Pos_(v); return this;} public void Test_read_int(int expd_val) { diff --git a/400_xowa/src/gplx/xowa/htmls/core/wkrs/lnkes/Xoh_lnke_parse_tst.java b/400_xowa/src/gplx/core/brys/Int_flag_bldr.java similarity index 59% rename from 400_xowa/src/gplx/xowa/htmls/core/wkrs/lnkes/Xoh_lnke_parse_tst.java rename to 400_xowa/src/gplx/core/brys/Int_flag_bldr.java index 1fb9c0234..ad82639bb 100644 --- a/400_xowa/src/gplx/xowa/htmls/core/wkrs/lnkes/Xoh_lnke_parse_tst.java +++ b/400_xowa/src/gplx/core/brys/Int_flag_bldr.java @@ -15,12 +15,15 @@ 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 . */ -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.*; import gplx.xowa.htmls.core.parsers.*; -public class Xoh_lnke_parse_tst { - private final Xoh_parser_fxt fxt = new Xoh_parser_fxt(); - @Test public void Free() { - fxt.Init__lnke(0, 96, Xoh_lnke_dict_.Type__free, 0, "http://a.org"); - fxt.Test__parse(Xoh_lnke_html__hdump__tst.Html__free); +package gplx.core.brys; import gplx.*; import gplx.core.*; +public class Int_flag_bldr { + private int[] pow_ary; + public int[] Val_ary() {return val_ary;} private int[] val_ary; + public Int_flag_bldr Pow_ary_bld_(int... ary) { + this.pow_ary = Int_flag_bldr_.Bld_pow_ary(ary); + this.val_ary = new int[pow_ary.length]; + return this; } + public int Encode() {return Int_flag_bldr_.To_int(pow_ary, val_ary);} + public void Decode(int v) {Int_flag_bldr_.To_int_ary(val_ary, pow_ary, v);} } diff --git a/400_xowa/src/gplx/core/brys/Int_flag_bldr_.java b/400_xowa/src/gplx/core/brys/Int_flag_bldr_.java new file mode 100644 index 000000000..142ec2f11 --- /dev/null +++ b/400_xowa/src/gplx/core/brys/Int_flag_bldr_.java @@ -0,0 +1,89 @@ +/* +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 . +*/ +package gplx.core.brys; import gplx.*; import gplx.core.*; +public class Int_flag_bldr_ { + public static int[] Bld_pow_ary(int... ary) { + int len = ary.length; + int[] rv = new int[len]; + int pow = 0; + for (int i = len - 1; i > -1; --i) { + rv[i] = Int_flag_bldr_.Base2_ary[pow]; + pow += ary[i]; + } + return rv; + } + public static int To_int(int[] pow_ary, int[] val_ary) { + int pow_ary_last = pow_ary.length - 1; + int val = 0; + for (int i = pow_ary_last; i > -1; i--) + val += pow_ary[i] * val_ary[i]; + return val; + } + public static int[] To_int_ary(int[] pow_ary, int v) { + int[] rv = new int[pow_ary.length]; + To_int_ary(rv, pow_ary, v); + return rv; + } + public static void To_int_ary(int[] rv, int[] pow_ary, int v) { + int pow_ary_len = pow_ary.length; + int rv_len = rv.length; + for (int i = 0; i < pow_ary_len; i++) { + if (i >= rv_len) break; + rv[i] = v / pow_ary[i]; + int factor = pow_ary[i] * rv[i]; + v = factor == 0 ? v : (v % factor); // NOTE: if 0, do not do modulus or else div by zero + } + } + public static byte To_byte(byte[] pow_ary, byte... val_ary) { + int pow_ary_last = pow_ary.length - 1; + int val = 0; + for (int i = pow_ary_last; i > -1; --i) + val += pow_ary[i] * val_ary[i]; + return (byte)val; + } + public static void To_bry(byte[] rv, byte[] pow_ary, byte val) { + int pow_ary_len = pow_ary.length; + int rv_len = rv.length; + for (int i = 0; i < pow_ary_len; i++) { + if (i >= rv_len) break; + rv[i] = (byte)(val / pow_ary[i]); + int factor = pow_ary[i] * rv[i]; + val = (byte)(factor == 0 ? val : (val % factor)); // NOTE: if 0, do not do modulus or else div by zero + } + } + public static int To_int_date_short(int[] val_ary) { + val_ary[0] -= 1900; + return Int_flag_bldr_.To_int(Pow_ary_date_short, val_ary); + } + public static void To_date_short_int_ary(int[] rv, int v) { + Int_flag_bldr_.To_int_ary(rv, Pow_ary_date_short, v); + rv[0] += 1900; + } + public static DateAdp To_date_short(int v) { + int[] rv = new int[Pow_ary_date_short.length]; + To_date_short_int_ary(rv, v); + return DateAdp_.seg_(rv); + } + private static final int[] Pow_ary_date_short = new int[] {1048576, 65536, 2048, 64, 1}; // yndhm -> 12,4,5,5,6 + public static final int[] Base2_ary = new int[] + { 1, 2, 4, 8, 16, 32, 64, 128 + , 256, 512, 1024, 2048, 4096, 8192, 16384, 32768 + , 65536, 131072, 262144, 524288, 1048576, 2097152, 4194304, 8388608 + , 16777216, 33554432, 67108864, 134217728, 268435456, 536870912, 1073741824, 0 + }; +} diff --git a/400_xowa/src/gplx/core/brys/Int_flag_bldr__tst.java b/400_xowa/src/gplx/core/brys/Int_flag_bldr__tst.java new file mode 100644 index 000000000..345654e1f --- /dev/null +++ b/400_xowa/src/gplx/core/brys/Int_flag_bldr__tst.java @@ -0,0 +1,72 @@ +/* +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 . +*/ +package gplx.core.brys; import gplx.*; import gplx.core.*; +import org.junit.*; +public class Int_flag_bldr__tst { + private final Int_flag_bldr__fxt fxt = new Int_flag_bldr__fxt(); + @Test public void Bld_pow_ary() { + fxt.Test__bld_pow_ary(fxt.Make__ary(1, 1, 1, 1), fxt.Make__ary(8, 4, 2, 1)); + fxt.Test__bld_pow_ary(fxt.Make__ary(3, 2) , fxt.Make__ary(4, 1)); + } + @Test public void To_int__1_1_1() { + int[] seg_ary = fxt.Make__ary(1, 1, 1); + fxt.Test__to_int(seg_ary , fxt.Make__ary(0, 0, 0), 0); + fxt.Test__to_int(seg_ary , fxt.Make__ary(1, 1, 1), 7); + fxt.Test__to_int(seg_ary , fxt.Make__ary(1, 0, 0), 4); + fxt.Test__to_int(seg_ary , fxt.Make__ary(1, 1, 0), 6); + fxt.Test__to_int(seg_ary , fxt.Make__ary(0, 1, 1), 3); + } + @Test public void To_int__2_3() { + fxt.Test__to_int(fxt.Make__ary(2, 3) , fxt.Make__ary(3, 7) , 31); + fxt.Test__to_int(fxt.Make__ary(1, 2, 3) , fxt.Make__ary(1, 3, 7) , 63); + } + @Test public void To_int__11_4_5_5_6() { + fxt.Test__to_int(fxt.Make__ary(11, 4, 5, 5, 6), fxt.Make__ary(2012, 6, 3, 23, 17), 2110135761); + fxt.Test__to_int(fxt.Make__ary(11, 4, 5, 5, 6), fxt.Make__ary(2012, 6, 3, 23, 18), 2110135762); + } + @Test public void To_int_ary() { + fxt.Test__to_int_ary(fxt.Make__ary(1, 1, 1, 1) , 15, fxt.Make__ary(1, 1, 1, 1)); + fxt.Test__to_int_ary(fxt.Make__ary(3, 2) , 31, fxt.Make__ary(7, 3)); + fxt.Test__to_int_ary(fxt.Make__ary(3, 2, 1) , 63, fxt.Make__ary(7, 3, 1)); + fxt.Test__to_int_ary(fxt.Make__ary(12, 4, 5, 5, 6), 2110135761, fxt.Make__ary(2012, 6, 3, 23, 17)); + fxt.Test__to_int_ary(fxt.Make__ary(12, 4, 5, 5, 6), 2110135762, fxt.Make__ary(2012, 6, 3, 23, 18)); + } + @Test public void To_int_date_short() { + fxt.Test__to_int_date_short("20120604 2359", 117843451); + fxt.Test__to_int_date_short("20120604 2358", 117843450); + fxt.Test__to_int_date_short("20120605 0000", 117843968); + } +} +class Int_flag_bldr__fxt { + public int[] Make__ary(int... v) {return v;} + public void Test__bld_pow_ary(int[] seg_ary, int[] expd) {Tfds.Eq_ary_str(expd, Int_flag_bldr_.Bld_pow_ary(seg_ary));} + public void Test__to_int(int[] seg_ary, int[] val_ary, int expd) { + int[] pow_ary = Int_flag_bldr_.Bld_pow_ary(seg_ary); + Tfds.Eq(expd, Int_flag_bldr_.To_int(pow_ary, val_ary)); + } + public void Test__to_int_ary(int[] seg_ary, int val, int[] expd) { + int[] pow_ary = Int_flag_bldr_.Bld_pow_ary(seg_ary); + Tfds.Eq_ary_str(expd, Int_flag_bldr_.To_int_ary(pow_ary, val)); + } + public void Test__to_int_date_short(String date_str, int expd) { + DateAdp date = DateAdp_.parse_fmt(date_str, "yyyyMMdd HHmm"); + int date_int = Int_flag_bldr_.To_int_date_short(date.XtoSegAry()); + Tfds.Eq(expd, date_int); + Tfds.Eq(date_str, Int_flag_bldr_.To_date_short(date_int).XtoStr_fmt("yyyyMMdd HHmm")); + } +} diff --git a/400_xowa/src/gplx/core/consoles/Gfo_cmd_arg_mgr_tst.java b/400_xowa/src/gplx/core/consoles/Gfo_cmd_arg_mgr_tst.java index e6a81f72f..f2893acc6 100644 --- a/400_xowa/src/gplx/core/consoles/Gfo_cmd_arg_mgr_tst.java +++ b/400_xowa/src/gplx/core/consoles/Gfo_cmd_arg_mgr_tst.java @@ -102,7 +102,7 @@ class Gfo_cmd_arg_mgr_fxt { return this; } public Gfo_cmd_arg_mgr_fxt Test_write(String... expd) { - Tfds.Eq_ary_str(expd, ((Gfo_usr_dlg__gui_test)usr_dlg.Gui_wkr()).Xto_str_ary_and_clear()); + Tfds.Eq_ary_str(expd, ((Gfo_usr_dlg__gui_test)usr_dlg.Gui_wkr()).Msgs().To_str_ary_and_clear()); return this; } public void Test_val_as_url_rel_dir_or(String root_dir, String dir_spr, String val, String expd) { diff --git a/400_xowa/src/gplx/langs/htmls/Html_atr_.java b/400_xowa/src/gplx/langs/htmls/Html_atr_.java index 3dd633d2c..50ea91503 100644 --- a/400_xowa/src/gplx/langs/htmls/Html_atr_.java +++ b/400_xowa/src/gplx/langs/htmls/Html_atr_.java @@ -20,9 +20,15 @@ public class Html_atr_ { public static final byte[] Bry__id = Bry_.new_a7("id") , Bry__class = Bry_.new_a7("class") - , Bry__rel = Bry_.new_a7("rel") - , Bry__href = Bry_.new_a7("href") , Bry__title = Bry_.new_a7("title") , Bry__style = Bry_.new_a7("style") + // + , Bry__href = Bry_.new_a7("href") + , Bry__rel = Bry_.new_a7("rel") + // + , Bry__alt = Bry_.new_a7("alt") + , Bry__src = Bry_.new_a7("src") + , Bry__width = Bry_.new_a7("width") + , Bry__height = Bry_.new_a7("height") ; } diff --git a/400_xowa/src/gplx/langs/htmls/Html_bldr_.java b/400_xowa/src/gplx/langs/htmls/Html_bldr_.java new file mode 100644 index 000000000..213c8a9fa --- /dev/null +++ b/400_xowa/src/gplx/langs/htmls/Html_bldr_.java @@ -0,0 +1,38 @@ +/* +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 . +*/ +package gplx.langs.htmls; import gplx.*; import gplx.langs.*; +public class Html_bldr_ { + public static final byte[] + Bry__a_lhs_bgn = Bry_.new_a7("") + , Bry__a_lhs_w_href = Bry_.new_a7("") + , Bry__lhs_end_inline = Bry_.new_a7("/>") + , Bry__lhs_end_inline_w_quote = Bry_.new_a7("\"/>") + ; +} diff --git a/400_xowa/src/gplx/langs/htmls/Html_tag_.java b/400_xowa/src/gplx/langs/htmls/Html_tag_.java index 2ec1c1991..890e96a68 100644 --- a/400_xowa/src/gplx/langs/htmls/Html_tag_.java +++ b/400_xowa/src/gplx/langs/htmls/Html_tag_.java @@ -17,20 +17,40 @@ along with this program. If not, see . */ package gplx.langs.htmls; import gplx.*; import gplx.langs.*; public class Html_tag_ { + public static final int + Id__eos = -2 + , Id__any = -1 + , Id__unknown = 0 + , Id__comment = 1 + , Id__h2 = 2 + , Id__h3 = 3 + , Id__h4 = 4 + , Id__h5 = 5 + , Id__h6 = 6 + , Id__a = 7 + , Id__span = 8 + , Id__div = 9 + , Id__img = 10 + ; public static final byte[] - Ul_name_bry = Bry_.new_a7("ul") - , A_name_bry = Bry_.new_a7("a") - , Code_name_bry = Bry_.new_a7("code") - , Tr_name_bry = Bry_.new_a7("tr") - , Td_name_bry = Bry_.new_a7("td") - , Table_name_bry = Bry_.new_a7("table") + Bry__a = Bry_.new_a7("a") + , Bry__ul = Bry_.new_a7("ul") + ; + public static final Hash_adp_bry Hash = Hash_adp_bry.ci_a7() + .Add_bry_int(Bry__a , Id__a) + .Add_str_int("h2" , Id__h2) + .Add_str_int("h3" , Id__h3) + .Add_str_int("h4" , Id__h4) + .Add_str_int("h5" , Id__h5) + .Add_str_int("h6" , Id__h6) + .Add_str_int("span" , Id__span) + .Add_str_int("div" , Id__div) + .Add_str_int("img" , Id__img) ; public static final byte[] Br_inl = Bry_.new_a7("
") , Hr_inl = Bry_.new_a7("
") , Body_lhs = Bry_.new_a7("") , Body_rhs = Bry_.new_a7("") - , A_lhs_bgn = Bry_.new_a7("") , B_lhs = Bry_.new_a7("") , B_rhs = Bry_.new_a7("") , I_lhs = Bry_.new_a7("") , I_rhs = Bry_.new_a7("") , P_lhs = Bry_.new_a7("

") , P_rhs = Bry_.new_a7("

") @@ -60,28 +80,4 @@ public class Html_tag_ { Comm_bgn_len = Comm_bgn.length , Comm_end_len = Comm_end.length ; - public static final int - Id__eos = -2 - , Id__any = -1 - , Id__unknown = 0 - , Id__a = 1 - , Id__h2 = 2 - , Id__h3 = 3 - , Id__h4 = 4 - , Id__h5 = 5 - , Id__h6 = 6 - , Id__span = 7 - , Id__div = 8 - , Id__comment = 9 - ; - public static final Hash_adp_bry Hash = Hash_adp_bry.ci_a7() - .Add_str_int("a" , Id__a) - .Add_str_int("h2" , Id__h2) - .Add_str_int("h3" , Id__h3) - .Add_str_int("h4" , Id__h4) - .Add_str_int("h5" , Id__h5) - .Add_str_int("h6" , Id__h6) - .Add_str_int("span" , Id__span) - .Add_str_int("div" , Id__div) - ; } diff --git a/400_xowa/src/gplx/langs/htmls/Html_utl_tst.java b/400_xowa/src/gplx/langs/htmls/Html_utl_tst.java index 205c749eb..b98e34c95 100644 --- a/400_xowa/src/gplx/langs/htmls/Html_utl_tst.java +++ b/400_xowa/src/gplx/langs/htmls/Html_utl_tst.java @@ -17,8 +17,8 @@ along with this program. If not, see . */ package gplx.langs.htmls; import gplx.*; import gplx.langs.*; import org.junit.*; -public class Html_utl_tst { - @Before public void init() {fxt.Clear();} private Html_utl_fxt fxt = new Html_utl_fxt(); +public class Html_utl_tst { + @Before public void init() {fxt.Clear();} private Html_atr_cls_fxt fxt = new Html_atr_cls_fxt(); @Test public void Basic() {fxt.Test_del_comments("ac" , "ac");} @Test public void Bgn_missing() {fxt.Test_del_comments("a b c" , "a b c");} @Test public void End_missing() {fxt.Test_del_comments("a") ; fxt.Test__pos("3"); fxt.Test__move_fwd_head(Html_tag_.Id__any , "
") ; fxt.Test__pos("6"); } + @Test public void Meta() { + fxt.Init("1
2
3"); + fxt.Test__move_fwd_head(Html_tag_.Id__div , "
") ; fxt.Test__pos("2"); + } @Test public void Recursive() { fxt.Init("12345"); fxt.Test__move_fwd_head(Html_tag_.Id__a , "") ; fxt.Test__pos("2"); @@ -39,6 +43,7 @@ public class Html_tag_rdr_tst { } class Html_tag_rdr_fxt { private final Html_tag_rdr rdr = new Html_tag_rdr(); +// private final Html_doc_log log = new Html_doc_log(); public void Init(String src_str) { byte[] src_bry = Bry_.new_u8(src_str); rdr.Init(src_bry, 0, src_bry.length); diff --git a/400_xowa/src/gplx/xowa/htmls/core/Xoh_html_dict_.java b/400_xowa/src/gplx/langs/htmls/parsers/styles/Html_atr_style_.java similarity index 61% rename from 400_xowa/src/gplx/xowa/htmls/core/Xoh_html_dict_.java rename to 400_xowa/src/gplx/langs/htmls/parsers/styles/Html_atr_style_.java index 86cf1bec0..8bc1fa6c1 100644 --- a/400_xowa/src/gplx/xowa/htmls/core/Xoh_html_dict_.java +++ b/400_xowa/src/gplx/langs/htmls/parsers/styles/Html_atr_style_.java @@ -15,14 +15,9 @@ 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 . */ -package gplx.xowa.htmls.core; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; -public class Xoh_html_dict_ { - public static final byte[] - Type__hdr = Bry_.new_a7(" data-xotype='hdr_bgn'") - , Hook__space = Bry_.new_a7(" ") - , Hook__lnke = Bry_.new_a7("") - , Rng__bgn = Bry_.new_a7("" - , "a 1" - , "" - , "

B

" - , "b" - ); fxt.Test__html(String_.Concat_lines_nl_skip_last ( "z" , "==A 1==" , "a 1" , "==B==" , "b" - ), html); + ), String_.Concat_lines_nl_skip_last + ( "z" + , "" + , "

A 1

" + , "a 1" + , "" + , "

B

" + , "b" + )); } } diff --git a/400_xowa/src/gplx/xowa/htmls/core/wkrs/hdrs/Xoh_hdr_hzip.java b/400_xowa/src/gplx/xowa/htmls/core/wkrs/hdrs/Xoh_hdr_hzip.java index aee1fd3c2..61f1a4f61 100644 --- a/400_xowa/src/gplx/xowa/htmls/core/wkrs/hdrs/Xoh_hdr_hzip.java +++ b/400_xowa/src/gplx/xowa/htmls/core/wkrs/hdrs/Xoh_hdr_hzip.java @@ -18,47 +18,39 @@ along with this program. If not, see . package gplx.xowa.htmls.core.wkrs.hdrs; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*; import gplx.xowa.htmls.core.wkrs.*; import gplx.core.brys.*; import gplx.xowa.wikis.ttls.*; import gplx.xowa.htmls.core.hzips.*; import gplx.xowa.htmls.core.hzips.stats.*; -public class Xoh_hdr_hzip extends Xoh_hdr_parse_base implements Xoh_hzip_wkr { - private Hzip_stat_itm stat_itm; +public class Xoh_hdr_hzip implements Xoh_hzip_wkr { public String Key() {return Xoh_hzip_dict_.Key__hdr;} - public void Encode(Bry_bfr bfr, Hzip_stat_itm stat_itm, Bry_parser parser, byte[] src, int hook_bgn) { - this.stat_itm = stat_itm; - this.Parse(bfr, parser, src, hook_bgn); - } - @Override public void Parse_exec(Bry_bfr bfr, byte[] src, int hook_bgn, int rng_bgn, int rng_end, byte level, int anchor_bgn, int anchor_end, int display_bgn, int display_end) { + public void Encode(Bry_bfr bfr, Hzip_stat_itm stat_itm, byte[] src, int rng_bgn, int rng_end, int level, int capt_bgn, int capt_end, byte[] anch) { stat_itm.Hdr_add(level); - bfr.Del_by(3); // delete " - bfr.Add_mid(src, display_bgn, display_end); // add display; - bfr.Add_byte(Xoh_hzip_dict_.Escape); // add escape - if (!Bry_.Match_w_swap(src, display_bgn, display_end, src, anchor_bgn, anchor_end, Byte_ascii.Underline, Byte_ascii.Space)) // check if anchor == display, while treating " " == "_" - bfr.Add_mid(src, anchor_bgn, anchor_end); // add anchor - bfr.Add_byte(Xoh_hzip_dict_.Escape); // add escape + bfr.Add(Xoh_hzip_dict_.Bry__hdr); // add hook + bfr.Add_int_digits(1, level); // add level; EX: 2 in

+ bfr.Add_mid(src, capt_bgn, capt_end).Add_byte(Xoh_hzip_dict_.Escape); // add caption + if (anch != null) bfr.Add(anch); // add anchor + bfr.Add_byte(Xoh_hzip_dict_.Escape); // add escape } - public int Decode(Bry_bfr bfr, Bry_parser parser, byte[] src, int hook_bgn) { - byte level = parser.Read_byte(); - int display_bgn = parser.Pos(); - int display_end = parser.Fwd_bgn(Xoh_hzip_dict_.Escape); - int anchor_bgn = parser.Pos(); - int anchor_end = parser.Fwd_bgn(Xoh_hzip_dict_.Escape); + public int Decode(Bry_bfr bfr, Xoh_decode_ctx ctx, Bry_rdr rdr, byte[] src, int hook_bgn) { + byte level = rdr.Read_byte(); + int capt_bgn = rdr.Pos(); + int capt_end = rdr.Find_fwd_lr(Xoh_hzip_dict_.Escape); + int anch_bgn = rdr.Pos(); + int anch_end = rdr.Find_fwd_lr(Xoh_hzip_dict_.Escape); bfr.Add(Bry__hdr__0).Add_byte(level); bfr.Add(Bry__hdr__1); - if (anchor_end - anchor_bgn == 0) - bfr.Add_mid_w_swap (src, display_bgn, display_end, Byte_ascii.Space, Byte_ascii.Underline); + if (anch_end > anch_bgn) + bfr.Add_mid (src, anch_bgn, anch_end); else - bfr.Add_mid (src, anchor_bgn, anchor_end); + bfr.Add_mid_w_swap (src, capt_bgn, capt_end, Byte_ascii.Space, Byte_ascii.Underline); bfr.Add(Bry__hdr__2); - bfr.Add_mid(src, display_bgn, display_end); + bfr.Add_mid(src, capt_bgn, capt_end); bfr.Add(Bry__hdr__3).Add_byte(level); bfr.Add_byte(Byte_ascii.Angle_end); - return parser.Pos(); + return rdr.Pos(); } private static final byte[] Bry__hdr__0 = Bry_.new_a7("\n ") - , Bry__hdr__3 = Bry_.new_a7("\n\n ") + , Bry__hdr__3 = Bry_.new_a7("\n" - , " A" - , "

" - , "a" - ); - String hzip = String_.Concat_lines_nl_skip_last - ( "~\"2A~A~" - , "a" - ); - fxt.Test__bicode(hzip, html); - } @Test public void Same() { - String html = String_.Concat_lines_nl_skip_last - ( "
" - , " A" - , "
" - , "a" - ); - String hzip = String_.Concat_lines_nl_skip_last + fxt.Test__bicode(String_.Concat_lines_nl_skip_last ( "~\"6A~~" , "a" - ); - fxt.Test__bicode(hzip, html); + ), String_.Concat_lines_nl_skip_last + ( "
" + , " A" + , "
" + , "a" + )); + } + @Test public void Diff() { + fxt.Test__bicode(String_.Concat_lines_nl_skip_last + ( "~\"2A~A~" + , "a" + ), String_.Concat_lines_nl_skip_last + ( "

" + , " A" + , "

" + , "a" + )); } @Test public void Diff_by_underscore() { - String html = String_.Concat_lines_nl_skip_last - ( "

" - , " A 1" - , "

" - , "a" - ); - String hzip = String_.Concat_lines_nl_skip_last + fxt.Test__bicode(String_.Concat_lines_nl_skip_last ( "~\"2A 1~~" , "a" - ); - fxt.Test__bicode(hzip, html); - } - @Test public void Same_w_underscore() { - String html = String_.Concat_lines_nl_skip_last - ( "

" - , " A_1" + ), String_.Concat_lines_nl_skip_last + ( "

" + , " A 1" , "

" , "a" - ); - String hzip = String_.Concat_lines_nl_skip_last + )); + } + @Test public void Same_w_underscore() { + fxt.Test__bicode(String_.Concat_lines_nl_skip_last ( "~\"2A_1~~" , "a" - ); - fxt.Test__bicode(hzip, html); + ), String_.Concat_lines_nl_skip_last + ( "

" + , " A_1" + , "

" + , "a" + )); } } diff --git a/400_xowa/src/gplx/xowa/htmls/core/wkrs/hdrs/Xoh_hdr_make.java b/400_xowa/src/gplx/xowa/htmls/core/wkrs/hdrs/Xoh_hdr_make.java index 584dd9675..a81b12f51 100644 --- a/400_xowa/src/gplx/xowa/htmls/core/wkrs/hdrs/Xoh_hdr_make.java +++ b/400_xowa/src/gplx/xowa/htmls/core/wkrs/hdrs/Xoh_hdr_make.java @@ -16,22 +16,18 @@ You should have received a copy of the GNU Affero General Public License along with this program. If not, see . */ package gplx.xowa.htmls.core.wkrs.hdrs; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*; import gplx.xowa.htmls.core.wkrs.*; -import gplx.core.brys.*; +import gplx.langs.htmls.*; import gplx.langs.htmls.parsers.*; import gplx.xowa.htmls.sections.*; -public class Xoh_hdr_make extends Xoh_hdr_parse_base { - private Xoh_page hpg; - public int Make(Bry_bfr bfr, Xoh_page hpg, Bry_parser parser, byte[] src, int hook_bgn) { - this.hpg = hpg; - this.Parse(bfr, parser, src, hook_bgn); - return parser.Pos(); - } - @Override public void Parse_exec(Bry_bfr bfr, byte[] src, int hook_bgn, int rng_bgn, int rng_end, byte level, int anchor_bgn, int anchor_end, int display_bgn, int display_end) { +public class Xoh_hdr_make { + public void Make(Bry_bfr bfr, Xoh_page hpg, byte[] src, int rng_bgn, int rng_end, int level, int capt_bgn, int capt_end, byte[] anch) { // register section Xoh_section_mgr section_mgr = hpg.Section_mgr(); int section_len = section_mgr.Len(); if (section_len != 0) // guard against -1 index; should not happen section_mgr.Set_content(section_len - 1, src, rng_bgn - 2); // -2 to skip "\n\n" - hpg.Section_mgr().Add(section_len, level, Bry_.Mid(src, anchor_bgn, anchor_end), Bry_.Mid(src, display_bgn, display_end)).Content_bgn_(rng_end + 1); // +1 to skip "\n" - bfr.Add_mid(src, hook_bgn, rng_end); + byte[] capt = Bry_.Mid(src, capt_bgn, capt_end); + if (anch == null) anch = Bry_.Replace(capt, Byte_ascii.Space, Byte_ascii.Underline); + hpg.Section_mgr().Add(section_len, level, anch, capt).Content_bgn_(rng_end + 1); // +1 to skip "\n" + bfr.Add_mid(src, rng_bgn, rng_end); } } diff --git a/400_xowa/src/gplx/xowa/htmls/core/wkrs/hdrs/Xoh_hdr_make_tst.java b/400_xowa/src/gplx/xowa/htmls/core/wkrs/hdrs/Xoh_hdr_make_tst.java index 77ad653f8..ca22557bd 100644 --- a/400_xowa/src/gplx/xowa/htmls/core/wkrs/hdrs/Xoh_hdr_make_tst.java +++ b/400_xowa/src/gplx/xowa/htmls/core/wkrs/hdrs/Xoh_hdr_make_tst.java @@ -23,13 +23,13 @@ public class Xoh_hdr_make_tst { String html = String_.Concat_lines_nl_skip_last ( "z" , "" - , "

" - , " A 1" + , "

" + , " A 1" , "

" , "a 1" , "" - , "

" - , " B" + , "

" + , " B" , "

" , "b" ); diff --git a/400_xowa/src/gplx/xowa/htmls/core/wkrs/hdrs/Xoh_hdr_parse.java b/400_xowa/src/gplx/xowa/htmls/core/wkrs/hdrs/Xoh_hdr_parse.java deleted file mode 100644 index 8e672e865..000000000 --- a/400_xowa/src/gplx/xowa/htmls/core/wkrs/hdrs/Xoh_hdr_parse.java +++ /dev/null @@ -1,62 +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 . -*/ -package gplx.xowa.htmls.core.wkrs.hdrs; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*; import gplx.xowa.htmls.core.wkrs.*; -import gplx.langs.htmls.*; import gplx.langs.htmls.parsers.*; -import gplx.xowa.htmls.core.parsers.*; -public class Xoh_hdr_parse { - public int Parse(Xoh_wkr wkr, Html_tag_rdr rdr, byte[] src, int hdr_tag_id, int hdr_tag_bgn, Html_tag span) { //
[1] - Html_atr id_atr = span.Atrs__get_by(Html_atr_.Bry__id); - int id_bgn = id_atr.Val_bgn(), id_end = id_atr.Val_end(); - int capt_bgn = span.Src_end(); - rdr.Tag__move_fwd_tail(hdr_tag_id); // find not since can be nested, but

cannot - int capt_end = rdr.Tag__peek_bwd_tail(Html_tag_.Id__span).Src_bgn(); // get before

- boolean id_capt_related = false; - byte[] capt = Bry_.Mid(src, capt_bgn, capt_end); - byte[] id = null; - switch (Match(src, capt_bgn, capt_end, src, id_bgn, id_end)) { - case Bool_.Y_byte: break; - case Bool_.N_byte: id = Bry_.Mid(src, id_bgn, id_end); break; - case Bool_.__byte: id_capt_related = true; break; - } - int tag_end = rdr.Pos(); - wkr.On_hdr(hdr_tag_bgn, tag_end, hdr_tag_id, id, capt, id_capt_related); - return tag_end; - } - private static byte Match(byte[] lhs, int lhs_bgn, int lhs_end, byte[] rhs, int rhs_bgn, int rhs_end) { - int lhs_len = lhs.length; - if (lhs_end > lhs_len) lhs_end = lhs_len; // must limit lhs_end to lhs_len, else ArrayIndexOutOfBounds below; DATE:2015-01-31 - int rhs_len = rhs_end - rhs_bgn; - if (rhs_len != lhs_end - lhs_bgn) return Bool_.N_byte; - if (rhs_len == 0) return lhs_end - lhs_bgn == 0 ? Bool_.Y_byte : Bool_.N_byte; // "" only matches "" - byte rv = Bool_.Y_byte; - for (int i = 0; i < rhs_len; ++i) { - int pos = lhs_bgn + i; - if (pos >= lhs_end) return Bool_.N_byte; // ran out of lhs; exit; EX: lhs=ab; rhs=abc - byte lhs_byte = lhs[pos]; - byte rhs_byte = rhs[i + rhs_bgn]; - if (lhs_byte != rhs_byte) { - if ( lhs_byte == Byte_ascii.Underline - && rhs_byte == Byte_ascii.Space - ) - continue; - return Bool_.N_byte; - } - } - return rv; - } -} diff --git a/400_xowa/src/gplx/xowa/htmls/core/wkrs/hdrs/Xoh_hdr_parse_base.java b/400_xowa/src/gplx/xowa/htmls/core/wkrs/hdrs/Xoh_hdr_parse_base.java deleted file mode 100644 index d28419352..000000000 --- a/400_xowa/src/gplx/xowa/htmls/core/wkrs/hdrs/Xoh_hdr_parse_base.java +++ /dev/null @@ -1,47 +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 . -*/ -package gplx.xowa.htmls.core.wkrs.hdrs; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*; import gplx.xowa.htmls.core.wkrs.*; -import gplx.core.brys.*; import gplx.xowa.wikis.ttls.*; -import gplx.langs.htmls.*; import gplx.xowa.htmls.sections.*; import gplx.xowa.htmls.core.hzips.stats.*; -public abstract class Xoh_hdr_parse_base { - public void Parse(Bry_bfr bfr, Bry_parser parser, byte[] src, int hook_bgn) {// EX:

- int rng_bgn = parser.Pos_(hook_bgn - 3); // move back to " '2' - byte level = parser.Read_byte_as_a7_int(); - - // get anchor between "id='" and "'>" - parser.Fwd_end(Html_tag_.Span_lhs); - int anchor_bgn = parser.Fwd_end(Bry__atr_id); - int anchor_end = parser.Fwd_bgn(Bry__tag_end); - - // get display between "'>" and "" - int display_bgn = parser.Pos(); - int display_end = parser.Fwd_bgn(Xoh_html_dict_.Hdr__end); - - // get content_bgn after "

" - int rng_end = parser.Fwd_end(Bry__hdr_rhs_bgn); - if (level != parser.Read_byte_as_a7_int()) throw parser.Fail("levels doesn't match", Byte_.To_str(level)); - rng_end = parser.Chk(Byte_ascii.Angle_end); - - Parse_exec(bfr, src, hook_bgn, rng_bgn, rng_end, level, anchor_bgn, anchor_end, display_bgn, display_end); - } - public abstract void Parse_exec(Bry_bfr bfr, byte[] src, int hook_bgn, int rng_bgn, int rng_end, byte level, int anchor_bgn, int anchor_end, int display_bgn, int display_end); - private static final byte[] Bry__hdr_lhs_bgn = Bry_.new_a7(""), Bry__hdr_rhs_bgn = Bry_.new_a7(". +*/ +package gplx.xowa.htmls.core.wkrs.hdrs; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*; import gplx.xowa.htmls.core.wkrs.*; +import gplx.langs.htmls.*; import gplx.langs.htmls.parsers.*; +public class Xoh_hdr_parser { + public int Parse(Xoh_hdoc_wkr wkr, Html_tag_rdr rdr, byte[] src, int hdr_name_id, int rng_bgn, Html_tag span) {//

A 1

+ Html_atr anch_atr = span.Atrs__get_by(Html_atr_.Bry__id); + int anch_bgn = anch_atr.Val_bgn(), anch_end = anch_atr.Val_end(); + int capt_bgn = span.Src_end(); + rdr.Tag__move_fwd_tail(hdr_name_id); // find not
since can be nested, but

cannot + int capt_end = rdr.Tag__peek_bwd_tail(Html_tag_.Id__span).Src_bgn(); // get before

+ byte[] anch = null; + if (!Bry_.Match_w_swap(src, capt_bgn, capt_end, src, anch_bgn, anch_end, Byte_ascii.Space, Byte_ascii.Underline)) + anch = Bry_.Mid(src, anch_bgn, anch_end); // anch is different than capt; occurs with html and dupe-anchors; EX: "==A==" -> id='A' + int rng_end = rdr.Pos(); + wkr.On_hdr(rng_bgn, rng_end, hdr_name_id, capt_bgn, capt_end, anch); + return rng_end; + } +} diff --git a/400_xowa/src/gplx/xowa/htmls/core/wkrs/hdrs/Xoh_hdr_parse_tst.java b/400_xowa/src/gplx/xowa/htmls/core/wkrs/imgs/Xoh_img_html__dump__tst.java similarity index 56% rename from 400_xowa/src/gplx/xowa/htmls/core/wkrs/hdrs/Xoh_hdr_parse_tst.java rename to 400_xowa/src/gplx/xowa/htmls/core/wkrs/imgs/Xoh_img_html__dump__tst.java index d0ee2ddd2..222518a96 100644 --- a/400_xowa/src/gplx/xowa/htmls/core/wkrs/hdrs/Xoh_hdr_parse_tst.java +++ b/400_xowa/src/gplx/xowa/htmls/core/wkrs/imgs/Xoh_img_html__dump__tst.java @@ -15,12 +15,13 @@ 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 . */ -package gplx.xowa.htmls.core.wkrs.hdrs; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*; import gplx.xowa.htmls.core.wkrs.*; -import org.junit.*; import gplx.langs.htmls.*; import gplx.langs.htmls.parsers.*; import gplx.xowa.htmls.core.parsers.*; -public class Xoh_hdr_parse_tst { - private final Xoh_parser_fxt fxt = new Xoh_parser_fxt(); - @Test public void Basic() { - fxt.Init__hdr(0, 54, Html_tag_.Id__h2, "A_b", "A b", false); - fxt.Test__parse("

A b

"); - } +package gplx.xowa.htmls.core.wkrs.imgs; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*; import gplx.xowa.htmls.core.wkrs.*; +import org.junit.*; import gplx.xowa.htmls.core.makes.tests.*; +public class Xoh_img_html__dump__tst { + private final Xoh_make_fxt fxt = new Xoh_make_fxt(); + public static final String + Html__basic = "abc" + ; + @Before public void init() {fxt.Clear();} + @Test public void Basic() {fxt.Test__html("[[File:A.png|220x110px|upright=.5|abc]]" , Html__basic);} } diff --git a/400_xowa/src/gplx/xowa/htmls/core/wkrs/imgs/Xoh_img_hzip.java b/400_xowa/src/gplx/xowa/htmls/core/wkrs/imgs/Xoh_img_hzip.java new file mode 100644 index 000000000..19d456937 --- /dev/null +++ b/400_xowa/src/gplx/xowa/htmls/core/wkrs/imgs/Xoh_img_hzip.java @@ -0,0 +1,168 @@ +/* +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 . +*/ +package gplx.xowa.htmls.core.wkrs.imgs; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*; import gplx.xowa.htmls.core.wkrs.*; +import gplx.core.brys.*; +import gplx.langs.htmls.*; import gplx.langs.htmls.parsers.*; import gplx.xowa.htmls.hrefs.*; import gplx.xowa.htmls.core.hzips.*; import gplx.xowa.htmls.core.hzips.stats.*; +import gplx.xowa.htmls.core.wkrs.imgs.atrs.*; import gplx.xowa.htmls.core.wkrs.lnkis.*; import gplx.xowa.htmls.core.wkrs.lnkis.anchs.*; +import gplx.xowa.wikis.nss.*; import gplx.xowa.wikis.ttls.*; +import gplx.xowa.files.*; import gplx.xowa.files.repos.*; +public class Xoh_img_hzip implements Xoh_hzip_wkr { + private final int[] flag_ary; + private final Int_flag_bldr flag_bldr = new Int_flag_bldr().Pow_ary_bld_ + ( 1, 1, 1, 1 + , 1, 1, 1, 1 + , 1, 1, 1, 2 + , 2); + public Xoh_img_hzip() { + this.flag_ary = flag_bldr.Val_ary(); + } + public String Key() {return Xoh_hzip_dict_.Key__img;} + public void Encode( Bry_bfr bfr, Hzip_stat_itm stat_itm, byte[] src, Xoh_img_parser arg) { + // img_map: + Xoh_anch_href_parser anch_href = arg.Anch_href_parser(); + Html_atr anch_title = arg.Anch_title_atr(); + Xoa_ttl anch_href_ttl = anch_href.Page_ttl(); + Xoh_img_xoimg_parser img_xoimg = arg.Img_xoimg_parser(); + Xoh_img_cls_parser img_cls = arg.Img_cls_parser(); + Xoh_img_src_parser img_src = arg.Img_src_parser(); + boolean anch_href_has_site = anch_href.Site_exists(); + boolean anch_href_is_file = anch_href_ttl.Ns().Id_is_file() && !anch_href_has_site; + boolean img_alt__diff__anch_title = arg.Img_alt__diff__anch_title(); + flag_ary[ 0] = img_xoimg.Val_exists() ? 1 : 0; + flag_ary[ 1] = anch_href_has_site ? 1 : 0; + flag_ary[ 2] = anch_href_is_file ? 1 : 0; + flag_ary[ 3] = anch_title.Val_exists() ? 1 : 0; + flag_ary[ 4] = img_alt__diff__anch_title ? 1 : 0; + flag_ary[ 5] = img_cls.Other_exists() ? 1 : 0; + flag_ary[ 6] = img_src.Repo_is_commons() ? 1 : 0; + flag_ary[ 7] = img_src.File_is_orig() ? 1 : 0; + flag_ary[ 8] = arg.File_w__diff__img_w() ? 1 : 0; + flag_ary[ 9] = img_src.File_time_exists() ? 1 : 0; + flag_ary[10] = img_src.File_page_exists() ? 1 : 0; + flag_ary[11] = arg.Anch_cls_parser().Tid(); + flag_ary[12] = img_cls.Cls_tid(); + bfr.Add(Xoh_hzip_dict_.Bry__img); + Xoh_hzip_int_.Encode(3, bfr, flag_bldr.Encode()); + Xoh_hzip_int_.Encode(2, bfr, Xoh_hzip_int_.Neg_1_adj + arg.Img_w()); + Xoh_hzip_int_.Encode(2, bfr, Xoh_hzip_int_.Neg_1_adj + arg.Img_h()); + bfr.Add(anch_href_ttl.Page_db()).Add_byte(Xoh_hzip_dict_.Escape); + if (!anch_href_is_file) { + Xoh_lnki_dict_.Ns_encode(bfr, anch_href_ttl); + bfr.Add_mid(src, img_src.File_ttl_bgn(), img_src.File_ttl_end()).Add_byte(Xoh_hzip_dict_.Escape); + } + if (arg.File_w__diff__img_w()) Xoh_hzip_int_.Encode(2, bfr, Xoh_hzip_int_.Neg_1_adj + img_src.File_w()); + if (img_src.File_time_exists()) Xoh_hzip_int_.Encode(1, bfr, Xoh_hzip_int_.Neg_1_adj + img_src.File_time()); + if (img_src.File_page_exists()) Xoh_hzip_int_.Encode(1, bfr, Xoh_hzip_int_.Neg_1_adj + img_src.File_page()); + if (img_xoimg.Val_exists()) bfr.Add_mid(src, img_xoimg.Val_bgn(), img_xoimg.Val_end()).Add_byte(Xoh_hzip_dict_.Escape); + if (anch_title.Val_exists()) bfr.Add_mid(src, anch_title.Val_bgn(), anch_title.Val_end()).Add_byte(Xoh_hzip_dict_.Escape); + if (img_alt__diff__anch_title) bfr.Add_mid(src, arg.Img_alt_atr().Val_bgn(), arg.Img_alt_atr().Val_end()).Add_byte(Xoh_hzip_dict_.Escape); + if (img_cls.Other_exists()) bfr.Add_mid(src, img_cls.Other_bgn(), img_cls.Other_end()).Add_byte(Xoh_hzip_dict_.Escape); + } + public int Decode(Bry_bfr bfr, Xoh_decode_ctx ctx, Bry_rdr rdr, byte[] src, int hook_bgn) { + int flag = rdr.Read_int_by_base85(3); + flag_bldr.Decode(flag); + int img_w = rdr.Read_int_by_base85(2) - Xoh_hzip_int_.Neg_1_adj; + int img_h = rdr.Read_int_by_base85(2) - Xoh_hzip_int_.Neg_1_adj; + byte[] page_db = rdr.Read_bry_to(); + boolean img_xoimg_exists = flag_ary[ 0] == 1; + boolean anch_href_has_site = flag_ary[ 1] == 1; + boolean anch_href_is_file = flag_ary[ 2] == 1; + boolean anch_title_exists = flag_ary[ 3] == 1; + boolean img_alt__diff__anch_title = flag_ary[ 4] == 1; + boolean img_cls_other_exists = flag_ary[ 5] == 1; + boolean repo_is_commons = flag_ary[ 6] == 1; + boolean file_is_orig = flag_ary[ 7] == 1; + int anch_cls = flag_ary[11]; + int img_cls = flag_ary[12]; + int anch_href_ns = -1; byte[] anch_href_ttl_bry = null; + if (!anch_href_is_file) { + anch_href_ns = Xoh_lnki_dict_.Ns_decode(rdr); + anch_href_ttl_bry = rdr.Read_bry_to(); + } + int file_time = -1; int file_page = -1; + int img_xoimg_bgn = -1; int img_xoimg_end = -1; + if (img_xoimg_exists) { + img_xoimg_bgn = rdr.Pos(); + img_xoimg_end = rdr.Find_fwd_lr(); + } + int anch_title_bgn = -1, anch_title_end = -1; + if (anch_title_exists) { + anch_title_bgn = rdr.Pos(); + anch_title_end = rdr.Find_fwd_lr(); + } + int img_alt_bgn = -1, img_alt_end = -1; + if (anch_title_exists) { + img_alt_bgn = anch_title_bgn; + img_alt_end = anch_title_end; + } + if (img_alt__diff__anch_title) { + img_alt_bgn = rdr.Pos(); + img_alt_end = rdr.Find_fwd_lr(); + } + byte[] img_cls_other = Bry_.Empty; + if (img_cls_other_exists) + img_cls_other = Bry_.Mid(src, rdr.Pos(), rdr.Find_fwd_lr()); + byte[] img_cls_bry = Xoh_img_cls_.To_html(img_cls, img_cls_other); + byte[] anch_cls_bry = Xoh_anch_cls_.To_html(anch_cls); + + bfr.Add(Html_bldr_.Bry__a_lhs_w_href); // '' + bfr.Add(Html_bldr_.Bry__img_lhs_w_alt); // ''
+		if (anch_title_exists || img_alt__diff__anch_title)
+			bfr.Add_mid(src, img_alt_bgn, img_alt_end);					// 'abc'
+		if (img_xoimg_exists) {
+			bfr.Add(Xoh_img_xoimg_parser.Bry__html);
+			bfr.Add_mid(src, img_xoimg_bgn, img_xoimg_end);				// '1|220|110...'
+		}
+		bfr.Add(Html_bldr_.Bry__src__nth);								// ' + bfr.Add(Html_bldr_.Bry__a_rhs); // + + rdr.Move_to(rdr.Src_end()); + return rdr.Pos(); + } +} diff --git a/400_xowa/src/gplx/xowa/htmls/core/wkrs/txts/Xoh_txt_parse_tst.java b/400_xowa/src/gplx/xowa/htmls/core/wkrs/imgs/Xoh_img_hzip__dump__tst.java similarity index 66% rename from 400_xowa/src/gplx/xowa/htmls/core/wkrs/txts/Xoh_txt_parse_tst.java rename to 400_xowa/src/gplx/xowa/htmls/core/wkrs/imgs/Xoh_img_hzip__dump__tst.java index c33d334f8..493fe79be 100644 --- a/400_xowa/src/gplx/xowa/htmls/core/wkrs/txts/Xoh_txt_parse_tst.java +++ b/400_xowa/src/gplx/xowa/htmls/core/wkrs/imgs/Xoh_img_hzip__dump__tst.java @@ -15,12 +15,14 @@ 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 . */ -package gplx.xowa.htmls.core.wkrs.txts; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*; import gplx.xowa.htmls.core.wkrs.*; -import org.junit.*; import gplx.xowa.htmls.core.parsers.*; -public class Xoh_txt_parse_tst { - private final Xoh_parser_fxt fxt = new Xoh_parser_fxt(); - @Test public void Basic() { - fxt.Init__txt(0, 3); - fxt.Test__parse("abc"); +package gplx.xowa.htmls.core.wkrs.imgs; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*; import gplx.xowa.htmls.core.wkrs.*; +import org.junit.*; import gplx.xowa.htmls.core.hzips.tests.*; +public class Xoh_img_hzip__dump__tst { + private final Xoh_hzip_fxt fxt = new Xoh_hzip_fxt(); + @Test public void Basic() { // [[File:A.png|border|class=other|220px|abc]] + fxt.Test__bicode + ( "~%$+(#T\";A.png~0|220|110|0.5|-1|-1~abc~" + , Xoh_img_html__dump__tst.Html__basic + ); } } diff --git a/400_xowa/src/gplx/xowa/htmls/core/wkrs/imgs/Xoh_img_hzip__view__tst.java b/400_xowa/src/gplx/xowa/htmls/core/wkrs/imgs/Xoh_img_hzip__view__tst.java new file mode 100644 index 000000000..14e5028ae --- /dev/null +++ b/400_xowa/src/gplx/xowa/htmls/core/wkrs/imgs/Xoh_img_hzip__view__tst.java @@ -0,0 +1,35 @@ +/* +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 . +*/ +package gplx.xowa.htmls.core.wkrs.imgs; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*; import gplx.xowa.htmls.core.wkrs.*; +import org.junit.*; import gplx.xowa.htmls.core.hzips.tests.*; +public class Xoh_img_hzip__view__tst { + private final Xoh_hzip_fxt fxt = new Xoh_hzip_fxt(); + @Test public void Basic__border__class__caption() { // [[File:A.png|border|class=other|220px|abc]] + fxt.Test__bicode + ( "~%!rC#T\";A.png~abc~other~" + , "abc" + ); + } + @Test public void Link() { // [[File:A.png|link=B]] + fxt.Test__bicode + ( "~%!H.#T\";B~#A.png~B~A.png~" + , "A.png" + ); + } + // link_site: [[File:A.png|link=//en.wiktionary.org/B]] -> [[File:Wiktionary-logo-en.svg|25x25px|link=//en.wiktionary.org/wiki/Special:Search/Earth|Search Wiktionary]] -> Search Wiktionary +} diff --git a/400_xowa/src/gplx/xowa/htmls/core/wkrs/imgs/Xoh_img_make.java b/400_xowa/src/gplx/xowa/htmls/core/wkrs/imgs/Xoh_img_make.java new file mode 100644 index 000000000..90e315403 --- /dev/null +++ b/400_xowa/src/gplx/xowa/htmls/core/wkrs/imgs/Xoh_img_make.java @@ -0,0 +1,52 @@ +/* +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 . +*/ +package gplx.xowa.htmls.core.wkrs.imgs; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*; import gplx.xowa.htmls.core.wkrs.*; +import gplx.langs.htmls.*; import gplx.langs.htmls.parsers.*; +import gplx.xowa.htmls.core.wkrs.imgs.atrs.*; +import gplx.xowa.files.*; +public class Xoh_img_make { + private final Xoa_file_mgr file_mgr = new Xoa_file_mgr(); + public void Make(Bry_bfr bfr, Xoh_page hpg, byte[] src, Xoh_img_parser arg) { + Xoh_img_xoimg_parser img_xoimg = arg.Img_xoimg_parser(); + Xoh_img_src_parser img_src = arg.Img_src_parser(); + Xof_fsdb_itm fsdb_itm = hpg.Img_mgr().Make_img(); + boolean html_data_exists = false; + if (img_xoimg.Val_exists()) { // data-xoimg exists; use it + fsdb_itm.Init_at_lnki(Xof_exec_tid.Tid_wiki_page, hpg.Wiki().Domain_itm().Abrv_xo(), img_src.File_ttl_bry(), img_xoimg.Lnki_type(), img_xoimg.Lnki_upright(), img_xoimg.Lnki_w(), img_xoimg.Lnki_h(), img_xoimg.Lnki_time(), img_xoimg.Lnki_page(), Xof_patch_upright_tid_.Tid_all); + html_data_exists = file_mgr.Check_cache(fsdb_itm); + } + else if (arg.Img_w_exists()) { // width exists; use it + // fsdb_itm.Init_by_hdump(img_src.Repo_is_commons(), img_src.File_ttl_bry(), arg.Img_w(), img_src.File_time(), img_src.File_page()); + html_data_exists = true; + } + Write_html(bfr, src, arg, fsdb_itm, html_data_exists); + } + private void Write_html(Bry_bfr bfr, byte[] src, Xoh_img_parser arg, Xof_fsdb_itm fsdb_itm, boolean html_data_exists) { + // html_data_exists = n : "abc" + bfr.Add_mid(src, arg.Anch_tag_bgn(), arg.Anch_tag_end()); // '' + bfr.Add(Html_bldr_.Bry__img_lhs); // '' + bfr.Add(Html_bldr_.Bry__a_rhs); // '' + } +} diff --git a/400_xowa/src/gplx/xowa/htmls/core/wkrs/imgs/Xoh_img_make__dump__tst.java b/400_xowa/src/gplx/xowa/htmls/core/wkrs/imgs/Xoh_img_make__dump__tst.java new file mode 100644 index 000000000..465b59f4d --- /dev/null +++ b/400_xowa/src/gplx/xowa/htmls/core/wkrs/imgs/Xoh_img_make__dump__tst.java @@ -0,0 +1,53 @@ +/* +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 . +*/ +package gplx.xowa.htmls.core.wkrs.imgs; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*; import gplx.xowa.htmls.core.wkrs.*; +import org.junit.*; import gplx.xowa.htmls.core.makes.tests.*; import gplx.xowa.parsers.lnkis.*; +public class Xoh_img_make__dump__tst { + private final Xoh_make_fxt fxt = new Xoh_make_fxt(); + @Before public void Init() {fxt.Clear();} + @Test public void Html_exists__n() { + String + orig = "abc" + , expd = "abc" + ; + fxt.Test__make(orig, fxt.Page_chkr().Body_(expd) + .Imgs__add("en.w", "A.png", Xop_lnki_type.Id_null, 0.5, 220, 110, -1, -1) + ); + } +// @Test public void Html_exists__y__cache() { +// String +// orig = "abc" +// , expd = "abc" +// ; +// fxt.Init_img_cache("en.w", "A.png", 0, 0.5, 220, 110, -1, -1, Bool_.Y, "B.png", 330, 110, -1, -1); +// fxt.Test__make(orig +// , fxt.Page_chkr().Body_(expd) +// .Imgs__add("en.w", "A.png", 0, 0.5, 220, 110, -1, -1) +// ); +// } +// @Test public void Html_exists__y__html() { +// String +// orig = "abc" +// , expd = "abc" +// ; +// fxt.Test__make(orig +// , fxt.Page_chkr().Body_(expd) +// .Imgs__add("en.w", "A.png", 0, 0.5, 220, 110, -1, -1) +// ); +// } +} diff --git a/400_xowa/src/gplx/xowa/htmls/core/wkrs/imgs/Xoh_img_parser.java b/400_xowa/src/gplx/xowa/htmls/core/wkrs/imgs/Xoh_img_parser.java new file mode 100644 index 000000000..862ded829 --- /dev/null +++ b/400_xowa/src/gplx/xowa/htmls/core/wkrs/imgs/Xoh_img_parser.java @@ -0,0 +1,63 @@ +/* +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 . +*/ +package gplx.xowa.htmls.core.wkrs.imgs; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*; import gplx.xowa.htmls.core.wkrs.*; +import gplx.core.brys.*; import gplx.xowa.htmls.core.wkrs.imgs.atrs.*; import gplx.xowa.htmls.core.wkrs.lnkis.anchs.*; import gplx.xowa.htmls.core.wkrs.lnkis.htmls.*; +import gplx.xowa.files.*; +import gplx.langs.htmls.*; import gplx.langs.htmls.parsers.*; +public class Xoh_img_parser { + private byte[] src; + public int Rng_bgn() {return rng_bgn;} private int rng_bgn; + public int Rng_end() {return rng_end;} private int rng_end; + public int Anch_tag_bgn() {return anch_tag_bgn;} private int anch_tag_bgn; + public int Anch_tag_end() {return anch_tag_end;} private int anch_tag_end; + public Xoh_anch_href_parser Anch_href_parser() {return anch_href_parser;} private Xoh_anch_href_parser anch_href_parser = new Xoh_anch_href_parser(); + public Xoh_anch_cls_parser Anch_cls_parser() {return anch_cls_parser;} private Xoh_anch_cls_parser anch_cls_parser = new Xoh_anch_cls_parser(); + public Xoh_img_src_parser Img_src_parser() {return img_src_parser;} private final Xoh_img_src_parser img_src_parser = new Xoh_img_src_parser(); + public Xoh_img_cls_parser Img_cls_parser() {return img_cls_parser;} private final Xoh_img_cls_parser img_cls_parser = new Xoh_img_cls_parser(); + public Xoh_img_xoimg_parser Img_xoimg_parser() {return img_xoimg_parser;} private Xoh_img_xoimg_parser img_xoimg_parser = new Xoh_img_xoimg_parser(); + public Html_atr Anch_title_atr() {return anch_title_atr;} private Html_atr anch_title_atr; + public Html_atr Img_alt_atr() {return img_alt_atr;} private Html_atr img_alt_atr; + public boolean Img_alt__diff__anch_title() {return !Bry_.Match(src, img_alt_atr.Val_bgn(), img_alt_atr.Val_end(), src, anch_title_atr.Val_bgn(), anch_title_atr.Val_end());} + public int Img_w() {return img_w;} private int img_w; + public boolean Img_w_exists() {return img_w != -1;} + public int Img_h() {return img_h;} private int img_h; + public boolean File_w__diff__img_w() {return img_src_parser.File_w() != img_w;} + public int Parse(Xoh_hdoc_wkr hdoc_wkr, byte[] src, Html_tag_rdr tag_rdr, Html_tag anch_tag) { + // "" + this.src = src; this.anch_tag_bgn = anch_tag.Src_bgn(); this.anch_tag_end = anch_tag.Src_end(); + this.rng_bgn = anch_tag_bgn; // + img_xoimg_parser.Parse(tag_rdr.Rdr(), src, img_tag); + this.img_w = img_tag.Atrs__get_as_int_or(Html_atr_.Bry__width, Xof_img_size.Size__neg1); // width='220' + this.img_h = img_tag.Atrs__get_as_int_or(Html_atr_.Bry__height, Xof_img_size.Size__neg1); // height='110' + this.img_alt_atr = img_tag.Atrs__get_by_or_empty(Html_atr_.Bry__alt); // alt='File:A.png' + img_cls_parser.Parse(tag_rdr.Rdr(), src, img_tag); // class='thumbborder' + img_src_parser.Parse(tag_rdr.Rdr(), hdoc_wkr.Ctx().Wiki().Domain_bry(), img_tag); // src='...' + Html_tag anch_tail_tag = tag_rdr.Tag__move_fwd_tail(Html_tag_.Id__a); // + this.rng_end = anch_tail_tag.Src_end(); + hdoc_wkr.On_img(this); + return rng_end; + } + public static final byte[] + Bry__cls__anch__image = Bry_.new_a7("image") + , Bry__cls__img__thumbimage = Bry_.new_a7("thumbimage") + ; +} diff --git a/400_xowa/src/gplx/xowa/htmls/core/wkrs/imgs/atrs/Xoh_anch_cls_.java b/400_xowa/src/gplx/xowa/htmls/core/wkrs/imgs/atrs/Xoh_anch_cls_.java new file mode 100644 index 000000000..0215c04d1 --- /dev/null +++ b/400_xowa/src/gplx/xowa/htmls/core/wkrs/imgs/atrs/Xoh_anch_cls_.java @@ -0,0 +1,45 @@ +/* +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 . +*/ +package gplx.xowa.htmls.core.wkrs.imgs.atrs; 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.imgs.*; +import gplx.core.btries.*; +import gplx.langs.htmls.*; +public class Xoh_anch_cls_ { + public static final byte + Tid__none = 0 // EX: [[File:A.png|link=A]] -> "" + , Tid__image = 1 // EX: [[File:A.png]] -> "" + ; + public static final String + Str__image = "image" + ; + public static final byte[] + Bry__image = Bry_.new_a7(Str__image) + ; + private static final byte[] + Html__image = Bry_.Add(Html_bldr_.Bry__cls__nth, Bry__image) + ; + public static final Btrie_slim_mgr Trie = Btrie_slim_mgr.cs() + .Add_bry_byte(Bry__image , Tid__image) + ; + public static byte[] To_html(int tid) { + switch (tid) { + case Xoh_anch_cls_.Tid__none: return Bry_.Empty; + case Xoh_anch_cls_.Tid__image: return Html__image; + default: throw Err_.new_unhandled(tid); + } + } +} diff --git a/400_xowa/src/gplx/xowa/htmls/core/wkrs/imgs/atrs/Xoh_anch_cls_parser.java b/400_xowa/src/gplx/xowa/htmls/core/wkrs/imgs/atrs/Xoh_anch_cls_parser.java new file mode 100644 index 000000000..3b755731e --- /dev/null +++ b/400_xowa/src/gplx/xowa/htmls/core/wkrs/imgs/atrs/Xoh_anch_cls_parser.java @@ -0,0 +1,36 @@ +/* +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 . +*/ +package gplx.xowa.htmls.core.wkrs.imgs.atrs; 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.imgs.*; +import gplx.core.brys.*; +import gplx.langs.htmls.*; import gplx.langs.htmls.parsers.*; +public class Xoh_anch_cls_parser { + private final Bry_rdr rdr = new Bry_rdr(); + public byte Tid() {return tid;} private byte tid; + public void Parse(Bry_rdr owner_rdr, byte[] src, Html_tag tag) { + Html_atr atr = tag.Atrs__get_by_or_empty(Html_atr_.Bry__class); // EX: class='image' + Parse(owner_rdr, src, atr.Val_bgn(), atr.Val_end()); + } + public void Parse(Bry_rdr owner_rdr, byte[] src, int src_bgn, int src_end) { + if (src_bgn == -1) + tid = Xoh_anch_cls_.Tid__none; + else { + rdr.Init_by_sub(owner_rdr, "anch.cls", src_bgn, src_end); + this.tid = rdr.Chk(Xoh_anch_cls_.Trie); + } + } +} diff --git a/400_xowa/src/gplx/xowa/htmls/core/wkrs/imgs/atrs/Xoh_img_cls_.java b/400_xowa/src/gplx/xowa/htmls/core/wkrs/imgs/atrs/Xoh_img_cls_.java new file mode 100644 index 000000000..aa1d663d4 --- /dev/null +++ b/400_xowa/src/gplx/xowa/htmls/core/wkrs/imgs/atrs/Xoh_img_cls_.java @@ -0,0 +1,57 @@ +/* +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 . +*/ +package gplx.xowa.htmls.core.wkrs.imgs.atrs; 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.imgs.*; +import gplx.core.btries.*; +public class Xoh_img_cls_ { + public static final byte + Tid__none = 0 + , Tid__thumbimage = 2 // EX: [[File:A.png|thumb]] -> "" + , Tid__thumbborder = 3 // EX: [[File:A.png|border]] -> "" + ; + public static final String + Str__thumbimage = "thumbimage" + , Str__thumbborder = "thumbborder" + ; + public static final byte[] + Bry__none = Bry_.Empty + ; + private static final byte[] + Bry__thumbimage = Bry_.new_a7(Str__thumbimage) + , Bry__thumbborder = Bry_.new_a7(Str__thumbborder) + ; + public static final Btrie_slim_mgr Trie = Btrie_slim_mgr.cs() + .Add_bry_byte(Bry__thumbimage , Tid__thumbimage) + .Add_bry_byte(Bry__thumbborder , Tid__thumbborder) + ; + private static final byte[] Bry__html_class = Bry_.new_a7(" class=\""); + public static byte[] To_html(int tid, byte[] other) { + boolean other_is_empty = Bry_.Len_eq_0(other); + if (tid == Xoh_img_cls_.Tid__none && other_is_empty) return Bry_.Empty; + byte[] cls = null; + switch (tid) { + case Xoh_img_cls_.Tid__thumbimage: cls = Bry__thumbimage; break; + case Xoh_img_cls_.Tid__thumbborder: cls = Bry__thumbborder; break; + } + byte[] other_0 = Bry_.Empty, other_1 = Bry_.Empty; + if (!other_is_empty) { + if (cls != null) other_0 = Byte_ascii.Space_bry; + other_1 = other; + } + return Bry_.Add(Bry__html_class, cls, other_0, other_1, Byte_ascii.Quote_bry); + } +} diff --git a/400_xowa/src/gplx/xowa/htmls/core/wkrs/imgs/atrs/Xoh_img_cls__tst.java b/400_xowa/src/gplx/xowa/htmls/core/wkrs/imgs/atrs/Xoh_img_cls__tst.java new file mode 100644 index 000000000..ad69f257b --- /dev/null +++ b/400_xowa/src/gplx/xowa/htmls/core/wkrs/imgs/atrs/Xoh_img_cls__tst.java @@ -0,0 +1,34 @@ +/* +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 . +*/ +package gplx.xowa.htmls.core.wkrs.imgs.atrs; 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.imgs.*; +import org.junit.*; +public class Xoh_img_cls__tst { + private Xoh_img_cls__fxt fxt = new Xoh_img_cls__fxt(); + @Test public void To_html() { + fxt.Test__to_html(Xoh_img_cls_.Tid__none , null , ""); + fxt.Test__to_html(Xoh_img_cls_.Tid__none , "a" , " class=\"a\""); + fxt.Test__to_html(Xoh_img_cls_.Tid__thumbimage , null , " class=\"thumbimage\""); + fxt.Test__to_html(Xoh_img_cls_.Tid__thumbborder , null , " class=\"thumbborder\""); + fxt.Test__to_html(Xoh_img_cls_.Tid__thumbborder , "a" , " class=\"thumbborder a\""); + } +} +class Xoh_img_cls__fxt { + public void Test__to_html(byte tid, String other, String expd) { + Tfds.Eq(expd, String_.new_u8(Xoh_img_cls_.To_html(tid, Bry_.new_u8_safe(other)))); + } +} diff --git a/400_xowa/src/gplx/xowa/htmls/core/wkrs/imgs/atrs/Xoh_img_cls_parser.java b/400_xowa/src/gplx/xowa/htmls/core/wkrs/imgs/atrs/Xoh_img_cls_parser.java new file mode 100644 index 000000000..6e28e124d --- /dev/null +++ b/400_xowa/src/gplx/xowa/htmls/core/wkrs/imgs/atrs/Xoh_img_cls_parser.java @@ -0,0 +1,46 @@ +/* +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 . +*/ +package gplx.xowa.htmls.core.wkrs.imgs.atrs; 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.imgs.*; +import gplx.core.brys.*; +import gplx.langs.htmls.*; import gplx.langs.htmls.parsers.*; +public class Xoh_img_cls_parser { + private final Bry_rdr rdr = new Bry_rdr(); + public byte Cls_tid() {return cls_tid;} private byte cls_tid; + public int Other_bgn() {return other_bgn;} private int other_bgn; + public int Other_end() {return other_end;} private int other_end; + public boolean Other_exists() {return other_end > other_bgn;} + public void Parse(Bry_rdr owner_rdr, byte[] src, Html_tag tag) { + Html_atr atr = tag.Atrs__get_by_or_empty(Html_atr_.Bry__class); // EX: class='thumbborder' + Parse(owner_rdr, src, atr.Val_bgn(), atr.Val_end()); + } + public void Parse(Bry_rdr owner_rdr, byte[] src, int src_bgn, int src_end) { + if (src_bgn == -1) { + this.cls_tid = Xoh_img_cls_.Tid__none; + this.other_bgn = this.other_end = -1; + return; + } + rdr.Init_by_sub(owner_rdr, "img.cls", src_bgn, src_end); + this.cls_tid = rdr.Chk(Xoh_img_cls_.Trie); + if (rdr.Is(Byte_ascii.Space)) { + this.other_bgn = rdr.Pos(); + this.other_end = src_end; + } + else + other_bgn = other_end = -1; + } +} diff --git a/400_xowa/src/gplx/xowa/htmls/core/wkrs/imgs/atrs/Xoh_img_src_parser.java b/400_xowa/src/gplx/xowa/htmls/core/wkrs/imgs/atrs/Xoh_img_src_parser.java new file mode 100644 index 000000000..a76c4eee0 --- /dev/null +++ b/400_xowa/src/gplx/xowa/htmls/core/wkrs/imgs/atrs/Xoh_img_src_parser.java @@ -0,0 +1,74 @@ +/* +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 . +*/ +package gplx.xowa.htmls.core.wkrs.imgs.atrs; 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.imgs.*; +import gplx.core.brys.*; import gplx.core.btries.*; +import gplx.langs.htmls.*; import gplx.langs.htmls.parsers.*; +import gplx.xowa.wikis.domains.*; +public class Xoh_img_src_parser implements Xoh_itm_parser { + private final Bry_rdr rdr = new Bry_rdr(); private byte[] src; + public void Fail_throws_err_(boolean v) {rdr.Fail_throws_err_(v);}// TEST + public int Val_bgn() {return val_bgn;} private int val_bgn; + public int Val_end() {return val_end;} private int val_end; + public boolean Val_exists() {return val_end > val_bgn;} + public int Repo_bgn() {return repo_bgn;} private int repo_bgn; + public int Repo_end() {return repo_end;} private int repo_end; + public boolean Repo_is_commons() {return repo_is_commons;} private boolean repo_is_commons; + public int File_ttl_bgn() {return file_ttl_bgn;} private int file_ttl_bgn; + public int File_ttl_end() {return file_ttl_end;} private int file_ttl_end; + public boolean File_ttl_exists() {return file_ttl_end > file_ttl_bgn;} + public byte[] File_ttl_bry() {if (file_ttl_bry == null) file_ttl_bry = Bry_.Mid(src, file_ttl_bgn, file_ttl_end); return file_ttl_bry;} private byte[] file_ttl_bry; + public boolean File_is_orig() {return file_is_orig;} private boolean file_is_orig; + public int File_w() {return file_w;} private int file_w; + public int File_time() {return file_time;} private int file_time; + public int File_page() {return file_page;} private int file_page; + public boolean File_time_exists() {return file_time != -1;} + public boolean File_page_exists() {return file_page != -1;} + public void Parse(Bry_rdr owner_rdr, byte[] domain_bry, Html_tag tag) { + Html_atr atr = tag.Atrs__get_by_or_empty(Html_atr_.Bry__src); + if (!atr.Val_exists()) return; + Parse(owner_rdr, domain_bry, atr.Val_bgn(), atr.Val_end()); + } + public void Parse(Bry_rdr owner_rdr, byte[] domain_bry, int val_bgn, int val_end) { // EX: src="file:///C:/xowa/file/commons.wikimedia.org/thumb/7/0/1/2/A.png/220px.png" + this.src = owner_rdr.Src(); + this.val_bgn = val_bgn; this.val_end = val_end; + file_w = file_time = file_page = -1; + rdr.Init_by_sub(owner_rdr, "img.src.xowa", val_bgn, val_end).Dflt_dlm_(Byte_ascii.Slash); + repo_bgn = rdr.Find_fwd_rr(Bry__file); // skip past /file/; EX: "file:///J:/xowa/file/commons.wikimedia.org/" + repo_end = rdr.Find_fwd_lr(); + repo_is_commons = Bry_.Match(rdr.Src(), repo_bgn, repo_end, Xow_domain_itm_.Bry__commons); + if (!repo_is_commons) { + if (!Bry_.Match(rdr.Src(), repo_bgn, repo_end, domain_bry)) rdr.Fail("repo must be commons or self", "repo", Bry_.Mid(rdr.Src(), repo_bgn, repo_end)); + } + file_is_orig = rdr.Chk(trie) == Tid__orig; // check if 'orig/' or 'thumb/' + file_ttl_bgn = rdr.Move_by(4); // 8 for 4 levels of md5; EX: "0/1/2/3/" + if (file_is_orig) + file_ttl_end = rdr.Src_end(); + else { + file_ttl_end = rdr.Find_fwd_lr(); + file_w = rdr.Read_int_to(Byte_ascii.Ltr_p); // EX: "220px" + rdr.Chk(Byte_ascii.Ltr_x); + if (rdr.Is(Byte_ascii.At)) + file_time = rdr.Read_int_to(Byte_ascii.Dot); // EX: "220px@5.png" + else if (rdr.Is(Byte_ascii.Dash)) + file_page = rdr.Read_int_to(Byte_ascii.Dot); // EX: "220px-5.png" + } + } + private static final byte[] Bry__file = Bry_.new_a7("/file/"), Bry__orig = Bry_.new_a7("orig/"), Bry__thumb = Bry_.new_a7("thumb/"); + private static final byte Tid__orig = 1, Tid__thumb = 2; + private static final Btrie_slim_mgr trie = Btrie_slim_mgr.cs().Add_bry_byte(Bry__orig, Tid__orig).Add_bry_byte(Bry__thumb, Tid__thumb); +} diff --git a/400_xowa/src/gplx/xowa/htmls/core/wkrs/imgs/atrs/Xoh_img_src_parser_tst.java b/400_xowa/src/gplx/xowa/htmls/core/wkrs/imgs/atrs/Xoh_img_src_parser_tst.java new file mode 100644 index 000000000..5dd235edc --- /dev/null +++ b/400_xowa/src/gplx/xowa/htmls/core/wkrs/imgs/atrs/Xoh_img_src_parser_tst.java @@ -0,0 +1,51 @@ +/* +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 . +*/ +package gplx.xowa.htmls.core.wkrs.imgs.atrs; 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.imgs.*; +import org.junit.*; import gplx.core.brys.*; +import gplx.xowa.wikis.domains.*; +public class Xoh_img_src_parser_tst { + private final Xoh_img_src_parser_fxt fxt = new Xoh_img_src_parser_fxt(); + @Test public void Basic() { + fxt.Test__parse("file:///C:/xowa/file/en.wikipedia.org/orig/7/0/A.png" , "en.wikipedia.org" , Bool_.Y, "A.png", -1, -1, -1); + fxt.Test__parse("file:///C:/xowa/file/commons.wikimedia.org/thumb/7/0/A.png/220px.png" , "commons.wikimedia.org" , Bool_.N, "A.png", 220, -1, -1); + fxt.Test__parse("file:///C:/xowa/file/commons.wikimedia.org/thumb/7/0/A.png/220px@5.png" , "commons.wikimedia.org" , Bool_.N, "A.png", 220, 5, -1); + fxt.Test__parse("file:///C:/xowa/file/commons.wikimedia.org/thumb/7/0/A.png/220px-5.png" , "commons.wikimedia.org" , Bool_.N, "A.png", 220, -1, 5); + } + @Test public void Fail__orig_mode() { + fxt.Test__parse__fail("file:///C:/xowa/file/commons.wikimedia.org/fail/7/0/A.png", "failed trie check: mid='fail/7/0/A.png' ctx='Main_Page' wkr='img.src.xowa' excerpt='file:///C:/xowa/file/commons.wikimedia.org/fail/7/0/A.png'"); + } + @Test public void Fail__repo_mode() { + fxt.Test__parse__fail("file:///C:/xowa/file/en.wiktionary.org/orig/7/0/A.png", "repo must be commons or self: repo='en.wiktionary.org' ctx='Main_Page' wkr='img.src.xowa' excerpt='file:///C:/xowa/file/en.wiktionary.org/orig/7/0/A.png'"); + } +} +class Xoh_img_src_parser_fxt extends Xoh_itm_parser_fxt_base { + private final Xoh_img_src_parser parser = new Xoh_img_src_parser(); + @Override public Xoh_itm_parser Parser_get() {return parser;} + public void Test__parse(String src_str, String expd_repo, boolean expd_file_is_orig, String expd_file, int expd_w, int expd_time, int expd_page) { + Exec_parse(src_str); + Tfds.Eq_str(expd_repo, String_.new_u8(src, parser.Repo_bgn(), parser.Repo_end())); + Tfds.Eq_str(expd_file, String_.new_u8(src, parser.File_ttl_bgn(), parser.File_ttl_end())); + Tfds.Eq_bool(expd_file_is_orig, parser.File_is_orig()); + Tfds.Eq_int(expd_w, parser.File_w()); + Tfds.Eq_int(expd_time, parser.File_time()); + Tfds.Eq_int(expd_page, parser.File_page()); + } + @Override public void Exec_parse_hook(Bry_rdr owner_rdr, int src_bgn, int src_end) { + parser.Parse(owner_rdr, Xow_domain_itm_.Bry__enwiki, src_bgn, src_end); + } +} diff --git a/400_xowa/src/gplx/xowa/htmls/core/wkrs/imgs/atrs/Xoh_img_xoimg_parser.java b/400_xowa/src/gplx/xowa/htmls/core/wkrs/imgs/atrs/Xoh_img_xoimg_parser.java new file mode 100644 index 000000000..6a46f7ddd --- /dev/null +++ b/400_xowa/src/gplx/xowa/htmls/core/wkrs/imgs/atrs/Xoh_img_xoimg_parser.java @@ -0,0 +1,56 @@ +/* +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 . +*/ +package gplx.xowa.htmls.core.wkrs.imgs.atrs; 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.imgs.*; +import gplx.core.brys.*; +import gplx.langs.htmls.*; import gplx.langs.htmls.parsers.*; +public class Xoh_img_xoimg_parser { + private final Bry_rdr rdr = new Bry_rdr(); + public int Val_bgn() {return val_bgn;} private int val_bgn; + public int Val_end() {return val_end;} private int val_end; + public boolean Val_exists() {return val_end > val_bgn;} + public byte Lnki_type() {return lnki_type;} private byte lnki_type; + public int Lnki_w() {return lnki_w;} private int lnki_w; + public int Lnki_h() {return lnki_h;} private int lnki_h; + public double Lnki_upright() {return lnki_upright;} private double lnki_upright; + public double Lnki_time() {return lnki_time;} private double lnki_time; + public int Lnki_page() {return lnki_page;} private int lnki_page; + public void Parse(Bry_rdr owner_rdr, byte[] src, Html_tag tag) { + Html_atr atr = tag.Atrs__get_by_or_empty(Bry__name); + Parse(owner_rdr, src, atr.Val_bgn(), atr.Val_end()); + } + public void Parse(Bry_rdr owner_rdr, byte[] src, int src_bgn, int src_end) { + if (src_bgn == -1) { + val_bgn = val_end = -1; + } + else { + rdr.Init_by_sub(owner_rdr, "img.xoimg", src_bgn, src_end).Dflt_dlm_(Byte_ascii.Pipe); + this.val_bgn = src_bgn; + this.val_end = src_end; + this.lnki_type = (byte)(rdr.Read_byte_to() - Byte_ascii.Num_0); + this.lnki_w = rdr.Read_int_to(); + this.lnki_h = rdr.Read_int_to(); + this.lnki_upright = rdr.Read_double_to(); + this.lnki_time = rdr.Read_double_to(); + this.lnki_page = rdr.Read_int_to(); + } + } + public static final byte[] + Bry__name = Bry_.new_a7("data-xoimg") + , Bry__html = Bry_.new_a7("\" data-xoimg=\"") + ; +} diff --git a/400_xowa/src/gplx/xowa/htmls/core/to_delete/Xoh_hzip_href.java b/400_xowa/src/gplx/xowa/htmls/core/wkrs/lnkes/Xoh_href_hzip.java similarity index 86% rename from 400_xowa/src/gplx/xowa/htmls/core/to_delete/Xoh_hzip_href.java rename to 400_xowa/src/gplx/xowa/htmls/core/wkrs/lnkes/Xoh_href_hzip.java index 29ac8a468..2980fe7a3 100644 --- a/400_xowa/src/gplx/xowa/htmls/core/to_delete/Xoh_hzip_href.java +++ b/400_xowa/src/gplx/xowa/htmls/core/wkrs/lnkes/Xoh_href_hzip.java @@ -98,14 +98,3 @@ along with this program. If not, see . // */ // } //} -//namespace gplx.xowa.htmls.core.hzips.wkrs { -// import org.junit.*; using gplx.xowa.htmls; -// public class Xoh_hzip_href_tst { -// @Before public void init() {fxt.Clear();} private Xoh_hzip_mgr_fxt fxt = new Xoh_hzip_mgr_fxt(); -// @Test public void Srl_lnki_img_full() { -// byte[][] brys = Bry_.Ary(Xoh_hzip_dict_.Bry__img_full, Bry_.new_ints(7), fxt.Make_int(12), Bry_.new_a7("cls_other"), Bry_.new_a7("|caption_other"), Xoh_hzip_dict_.Escape_bry); -// fxt.Test_save(brys, ""); -//// fxt.Test_load(brys, "a_1Aa_2"); -// } -// } -//} diff --git a/400_xowa/src/gplx/xowa/htmls/core/wkrs/lnkes/Xoh_lnke_html.java b/400_xowa/src/gplx/xowa/htmls/core/wkrs/lnkes/Xoh_lnke_html.java index d88e9de90..86907c66f 100644 --- a/400_xowa/src/gplx/xowa/htmls/core/wkrs/lnkes/Xoh_lnke_html.java +++ b/400_xowa/src/gplx/xowa/htmls/core/wkrs/lnkes/Xoh_lnke_html.java @@ -25,12 +25,7 @@ public class Xoh_lnke_html { 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 (!hctx.Mode_is_alt()) { // do not write "" if mode is alt - if (hctx.Mode_is_hdump()) { - bfr.Add(Xoh_html_dict_.Hook__lnke); // "http://a.org" - , Html__auto = "[1]" - , Html__text = "a" + Html__free = "http://a.org" + , Html__auto = "[1]" + , Html__text = "a" ; @Test public void Free() {fxt.Test__html("http://a.org" , Html__free);} @Test public void Auto() {fxt.Test__html("[http://a.org]" , Html__auto);} diff --git a/400_xowa/src/gplx/xowa/htmls/core/wkrs/lnkes/Xoh_lnke_hzip.java b/400_xowa/src/gplx/xowa/htmls/core/wkrs/lnkes/Xoh_lnke_hzip.java index deade5e8b..01f1a720d 100644 --- a/400_xowa/src/gplx/xowa/htmls/core/wkrs/lnkes/Xoh_lnke_hzip.java +++ b/400_xowa/src/gplx/xowa/htmls/core/wkrs/lnkes/Xoh_lnke_hzip.java @@ -20,34 +20,12 @@ import gplx.core.brys.*; import gplx.xowa.wikis.ttls.*; import gplx.langs.htmls.*; import gplx.xowa.htmls.core.hzips.*; import gplx.xowa.htmls.core.hzips.stats.*; public class Xoh_lnke_hzip implements Xoh_hzip_wkr { public String Key() {return Xoh_hzip_dict_.Key__lnke;} - public void Encode(Bry_bfr bfr, Hzip_stat_itm stat_itm, Bry_parser parser, byte[] src, int hook_bgn) { - Parse(bfr, stat_itm, parser, src, hook_bgn); - } - public void Parse(Bry_bfr bfr, Hzip_stat_itm stat_itm, Bry_parser parser, byte[] src, int hook_bgn) {// EX: 'http://a.org' - // NOTE: not serializing caption b/c (a) caption not repeated as title and (b) finding can be tricky, especially with tidy; EX: "[https://a.org b [[A]] c]"; note that lnkis can't be nested; EX: "[https://a.org b [https://b.org] c]" - int rng_bgn = hook_bgn - 2; // -2 to skip "[123]" - rng_end = parser.Fwd_end(Html_tag_.A_rhs); - } - break; + case Xoh_lnke_dict_.Type__free: stat_itm.Lnke_txt_add();break; + case Xoh_lnke_dict_.Type__text: stat_itm.Lnke_brk_text_y_add(); break; + case Xoh_lnke_dict_.Type__auto: stat_itm.Lnke_brk_text_n_add(); break; } - Encode_exec(bfr, src, rng_bgn, rng_end, lnke_type, href_bgn, href_end, lnke_id); - } - public void Encode_exec(Bry_bfr bfr, byte[] src, int rng_bgn, int rng_end, byte lnke_type, int href_bgn, int href_end, int lnke_id) { - bfr.Del_by(2); // delete "[http://a.org]; DATE:2015-08-25 fxt.Test__bicode ( "~#2http://a.org~![123]" - , "[123]" + , "[123]" ); } + @Test public void Fail__href() { + String html = "a"; + fxt.Test__encode__fail(html, html); + } + @Test public void Fail__lnke_type() { + String html = "a"; + fxt.Test__encode__fail(html, html); + } + @Test public void Fail__auto() { + String html = "[abc]"; + fxt.Test__encode__fail(html, html); + } } diff --git a/400_xowa/src/gplx/xowa/htmls/core/wkrs/lnkes/Xoh_lnke_parse.java b/400_xowa/src/gplx/xowa/htmls/core/wkrs/lnkes/Xoh_lnke_parse.java deleted file mode 100644 index 3975bafe0..000000000 --- a/400_xowa/src/gplx/xowa/htmls/core/wkrs/lnkes/Xoh_lnke_parse.java +++ /dev/null @@ -1,48 +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 . -*/ -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 gplx.langs.htmls.*; import gplx.langs.htmls.parsers.*; import gplx.xowa.htmls.hrefs.*; -import gplx.xowa.htmls.core.parsers.*; -public class Xoh_lnke_parse { - public int Parse(Xoh_wkr wkr, Html_tag_rdr rdr, byte[] src, Html_tag lnke) { // [1] - int tag_bgn = lnke.Src_bgn(), tag_end = lnke.Src_end(); - byte[] href = lnke.Atrs__get_by(Html_atr_.Bry__href).Val(); - byte[] cls = lnke.Atrs__get_by(Html_atr_.Bry__class).Val(); - byte lnke_type = Parse_lnke_type(cls, 0, cls.length); if (lnke_type == Byte_ascii.Max_7_bit) return tag_end; - int autonumber_id = 0; - switch (lnke_type) { - case Xoh_lnke_dict_.Type__free: - tag_end = rdr.Tag__move_fwd_tail(Html_tag_.Id__a).Src_end(); // find ''; note that free is not recursive; EX: "https://a.org" - break; - case Xoh_lnke_dict_.Type__text: - break; - case Xoh_lnke_dict_.Type__auto: - if (rdr.Read_and_move(Byte_ascii.Brack_bgn)) { // HTML tidy can reparent lnkes in strange ways; DATE:2015-08-25 - autonumber_id = rdr.Read_int_to(Byte_ascii.Brack_end, 0); // extract int; EX: "[123]" - tag_end = rdr.Tag__move_fwd_tail(Html_tag_.Id__a).Src_end(); // find ''; note that auto is not recursive; EX: "[https://a.org]" - } - break; - } - wkr.On_lnke(tag_bgn, tag_end, lnke_type, autonumber_id, href); - return tag_end; - } - private static byte Parse_lnke_type(byte[] src, int cls_bgn, int cls_end) { // "external autonumber" - int space = Bry_find_.Find_fwd(src, Byte_ascii.Space, cls_bgn, cls_end); - return Xoh_lnke_dict_.Hash.Get_as_byte_or(src, space + 1, cls_end, Byte_ascii.Max_7_bit); - } -} diff --git a/400_xowa/src/gplx/xowa/htmls/core/wkrs/lnkes/Xoh_lnke_parser.java b/400_xowa/src/gplx/xowa/htmls/core/wkrs/lnkes/Xoh_lnke_parser.java new file mode 100644 index 000000000..431016338 --- /dev/null +++ b/400_xowa/src/gplx/xowa/htmls/core/wkrs/lnkes/Xoh_lnke_parser.java @@ -0,0 +1,43 @@ +/* +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 . +*/ +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 gplx.langs.htmls.*; import gplx.langs.htmls.parsers.*; import gplx.xowa.htmls.hrefs.*; +public class Xoh_lnke_parser { + public int Parse(Xoh_hdoc_wkr hdoc_wkr, Html_tag_rdr tag_rdr, Html_tag anch) {// [1] + int rng_bgn = anch.Src_bgn(), rng_end = anch.Src_end(); + Html_atr href_atr = anch.Atrs__get_by(Html_atr_.Bry__href); + int href_bgn = href_atr.Val_bgn(), href_end = href_atr.Val_end(); + byte lnke_type = anch.Atrs__cls_find_1st(Xoh_lnke_dict_.Hash); + int autonumber_id = 0; + switch (lnke_type) { + case Xoh_lnke_dict_.Type__free: + rng_end = tag_rdr.Tag__move_fwd_tail(Html_tag_.Id__a).Src_end(); // find ''; note that free is not recursive; EX: "https://a.org" + break; + case Xoh_lnke_dict_.Type__text: + break; + case Xoh_lnke_dict_.Type__auto: + if (tag_rdr.Read_and_move(Byte_ascii.Brack_bgn)) { // HTML tidy can reparent lnkes in strange ways; DATE:2015-08-25 + autonumber_id = tag_rdr.Read_int_to(Byte_ascii.Brack_end); // extract int; EX: "[123]" + rng_end = tag_rdr.Tag__move_fwd_tail(Html_tag_.Id__a).Src_end(); // find ''; note that auto is not recursive; EX: "[https://a.org]" + } + break; + } + hdoc_wkr.On_lnke(rng_bgn, rng_end, lnke_type, autonumber_id, href_bgn, href_end); + return rng_end; + } +} diff --git a/400_xowa/src/gplx/xowa/htmls/core/wkrs/lnkis/Xoh_lnki_dict_.java b/400_xowa/src/gplx/xowa/htmls/core/wkrs/lnkis/Xoh_lnki_dict_.java index 0a3bc2d21..87e6e59eb 100644 --- a/400_xowa/src/gplx/xowa/htmls/core/wkrs/lnkis/Xoh_lnki_dict_.java +++ b/400_xowa/src/gplx/xowa/htmls/core/wkrs/lnkis/Xoh_lnki_dict_.java @@ -16,7 +16,7 @@ You should have received a copy of the GNU Affero General Public License along with this program. If not, see . */ package gplx.xowa.htmls.core.wkrs.lnkis; 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.parsers.*; +import gplx.core.brys.*; public class Xoh_lnki_dict_ { public static final byte // SERIALIZED Type__caption_n = Byte_ascii.Num_0 @@ -25,4 +25,10 @@ public class Xoh_lnki_dict_ { , Type__diff = Xoh_ttl_matcher.Tid__diff // EX: [[A|b]] , Type__trail = Xoh_ttl_matcher.Tid__trail // EX: [[A|b]] ; + public static void Ns_encode(Bry_bfr bfr, Xoa_ttl ttl) { + gplx.xowa.htmls.core.hzips.Xoh_hzip_int_.Encode(1, bfr, ttl.Ns().Id() + 2); + } + public static int Ns_decode(Bry_rdr rdr) { + return rdr.Read_int_by_base85(1) - 2; + } } diff --git a/400_xowa/src/gplx/xowa/htmls/core/wkrs/lnkis/Xoh_lnki_html__hdump__tst.java b/400_xowa/src/gplx/xowa/htmls/core/wkrs/lnkis/Xoh_lnki_html__hdump__tst.java index d27b0e9d7..e21bed68a 100644 --- a/400_xowa/src/gplx/xowa/htmls/core/wkrs/lnkis/Xoh_lnki_html__hdump__tst.java +++ b/400_xowa/src/gplx/xowa/htmls/core/wkrs/lnkis/Xoh_lnki_html__hdump__tst.java @@ -20,10 +20,10 @@ import org.junit.*; import gplx.xowa.htmls.core.makes.tests.*; public class Xoh_lnki_html__hdump__tst { private final Xoh_make_fxt fxt = new Xoh_make_fxt(); public static final String - Html__same = "A" - , Html__diff = "b" - , Html__trail = "Ab" - , Html__xwiki = "wikt:A" + Html__same = "A" + , Html__diff = "b" + , Html__trail = "Ab" + , Html__xwiki = "wikt:A" ; @Before public void init() {fxt.Clear();} @Test public void Same() {fxt.Test__html("[[A]]" , Html__same);} diff --git a/400_xowa/src/gplx/xowa/htmls/core/wkrs/lnkis/Xoh_lnki_hzip.java b/400_xowa/src/gplx/xowa/htmls/core/wkrs/lnkis/Xoh_lnki_hzip.java index 69983b12c..d2687d53e 100644 --- a/400_xowa/src/gplx/xowa/htmls/core/wkrs/lnkis/Xoh_lnki_hzip.java +++ b/400_xowa/src/gplx/xowa/htmls/core/wkrs/lnkis/Xoh_lnki_hzip.java @@ -17,135 +17,91 @@ along with this program. If not, see . */ package gplx.xowa.htmls.core.wkrs.lnkis; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*; import gplx.xowa.htmls.core.wkrs.*; import gplx.core.primitives.*; import gplx.core.brys.*; import gplx.core.btries.*; import gplx.core.encoders.*; -import gplx.langs.htmls.*; import gplx.xowa.htmls.hrefs.*; import gplx.xowa.wikis.ttls.*; import gplx.xowa.htmls.core.hzips.stats.*; +import gplx.xowa.htmls.core.hzips.*; import gplx.xowa.htmls.core.hzips.stats.*; +import gplx.langs.htmls.*; import gplx.xowa.htmls.hrefs.*; import gplx.xowa.wikis.ttls.*; import gplx.xowa.wikis.nss.*; import gplx.xowa.parsers.lnkis.*; -import gplx.xowa.htmls.core.hzips.*; import gplx.xowa.htmls.core.wkrs.lnkes.*; public class Xoh_lnki_hzip implements Xoh_hzip_wkr { - private Xow_ttl_parser ttl_parser; - public void Ttl_parser_(Xow_ttl_parser ttl_parser) {this.ttl_parser = ttl_parser;} + private Xow_ttl_parser ttl_parser; private int uid; + public void Ttl_parser_(Xow_ttl_parser ttl_parser) {this.ttl_parser = ttl_parser; this.uid = 1;} // NOTE: should be 0, but for historical reasons, 1st lnki starts at 2; EX: id='xowa_lnki_2' public String Key() {return Xoh_hzip_dict_.Key__lnki;} - public void Encode(Bry_bfr bfr, Hzip_stat_itm stat_itm, Bry_parser parser, byte[] src, int hook_bgn) {Parse(bfr, stat_itm, parser, src, hook_bgn);} - public int Parse(Bry_bfr bfr, Hzip_stat_itm stat_itm, Bry_parser parser, byte[] src, int hook_bgn) { - int rng_bgn = hook_bgn - 2; // -2 to skip " rng_end) return Xoh_hzip_dict_.Unhandled; // TODO: handle "jumping" over one " 0; - if ( lnki_type == Xoh_lnki_dict_.Type__caption_n // lnki_text_n; EX: [[A]] not [[A|A1]] - && !site_exists // not xwiki; EX: [[wikt:A]] - && (page_end - page_bgn) != (caption_end - caption_bgn) // note that in 99% of lnki_text_n cases, html_text_len == text_len; however, tidy sometimes relocates html inside html_text; PAGE:en.w:Abyssal_plain; EX:[[A]]; DATE:2015-06-02 - ) { - lnki_type = Xoh_lnki_dict_.Type__caption_y; // change to lnki_text_y - parser.Pos_(caption_bgn); - } - Parse_done(bfr, parser, null, ttl_parser, stat_itm, src, lnki_type, rng_bgn, rng_end, site_exists, site_bgn, site_end, page_bgn, page_end, uid, title_bgn, title_end, caption_bgn, caption_end); - return parser.Pos(); - } - public void Parse_done(Bry_bfr bfr, Bry_parser parser, Bry_rdr rdr, Xow_ttl_parser ttl_parser, Hzip_stat_itm stat_itm, byte[] src, byte lnki_type, int rng_bgn, int rng_end, boolean site_exists, int site_bgn, int site_end, int page_bgn, int page_end, int uid, int title_bgn, int title_end, int caption_bgn, int caption_end) { - Xoa_ttl ttl = ttl_parser.Ttl_parse(Bry_.Mid(src, page_bgn, page_end)); if (ttl == null) throw parser.Fail("lnki.decode:invalid ttl", String_.new_u8(src, page_bgn, page_end)); + public void Encode(Bry_bfr bfr, Hzip_stat_itm stat_itm, byte[] src, Xoh_lnki_parser arg) { + byte lnki_type = arg.Lnki_type(); + Xoa_ttl page_ttl = arg.Anch_href_parser().Page_ttl(); bfr.Add(Xoh_hzip_dict_.Bry__lnki); bfr.Add_byte(lnki_type); - Xoh_hzip_int_.Encode(1, bfr, ttl.Ns().Id()); - Xoh_hzip_int_.Encode(1, bfr, uid); - if (site_exists) - bfr.Add_byte(Xoh_hzip_dict_.Escape).Add_mid(src, site_bgn, site_end).Add_byte(Xoh_hzip_dict_.Escape); - if (lnki_type == Xoh_lnki_dict_.Type__caption_y) { - bfr.Add(ttl.Page_db()); - bfr.Add_byte(Xoh_hzip_dict_.Escape); - stat_itm.Lnki_text_y_add(); - } - else { - if (!ttl.Ns().Id_main()) // non-main ns should write page_db only; EX: "Template:A" should write "A" since "Template" will be inferred by ns_id - bfr.Add(ttl.Page_db()); - else // main ns should write html_text; handles [[a]] which has a - bfr.Add_mid(src, caption_bgn, caption_end); - bfr.Add_byte(Xoh_hzip_dict_.Escape); - stat_itm.Lnki_text_n_add(); + Xoh_hzip_int_.Encode(1, bfr, page_ttl.Ns().Ord()); // NOTE: ord b/c Xoh_int does not support negative numbers +// if (site_end - site_bgn > 0) +// bfr.Add_byte(Xoh_hzip_dict_.Escape).Add_mid(src, site_bgn, site_end).Add_byte(Xoh_hzip_dict_.Escape); + switch (lnki_type) { + case Xoh_lnki_dict_.Type__same: + stat_itm.Lnki_text_n_add(); + byte[] ttl_bry = page_ttl.Ns().Id_is_main() + ? arg.Capt_bry() // main ns should write html_text; handles [[a]] with html of 'a' + : page_ttl.Page_db(); // non-main ns should write page_db only; EX: "Template:A" should write "A" since "Template" will be inferred by ns_id + bfr.Add(ttl_bry).Add_byte(Xoh_hzip_dict_.Escape); + break; + case Xoh_lnki_dict_.Type__diff: + stat_itm.Lnki_text_y_add(); + bfr.Add(arg.Anch_href_parser().Page_bry()); + bfr.Add_byte(Xoh_hzip_dict_.Escape); + bfr.Add(arg.Capt_bry()); + bfr.Add_byte(Xoh_hzip_dict_.Escape); + break; + case Xoh_lnki_dict_.Type__trail: + bfr.Add(arg.Capt_bry()); + bfr.Add_byte(Xoh_hzip_dict_.Escape); + bfr.Add(arg.Trail_bry()); + bfr.Add_byte(Xoh_hzip_dict_.Escape); + break; } } - public int Decode(Bry_bfr bfr, Bry_parser parser, byte[] src, int hook_bgn) { - // parse vars - byte lnki_type = parser.Read_byte(); - int ns_id = parser.Read_int_by_base85(1); - int uid = parser.Read_int_by_base85(1); + public int Decode(Bry_bfr bfr, Xoh_decode_ctx ctx, Bry_rdr rdr, byte[] src, int hook_bgn) { + byte lnki_type = rdr.Read_byte(); + int ns_ord = rdr.Read_int_by_base85(1); int site_bgn = -1, site_end = -1; - if (parser.Is(Xoh_hzip_dict_.Escape)) { - site_bgn = parser.Pos(); - site_end = parser.Fwd_bgn(Xoh_hzip_dict_.Escape); + if (rdr.Is(Xoh_hzip_dict_.Escape)) { + site_bgn = rdr.Pos(); + site_end = rdr.Find_fwd_lr(Xoh_hzip_dict_.Escape); } boolean site_exists = site_end - site_bgn > 0; - int page_bgn = parser.Pos(); - int page_end = parser.Fwd_bgn(Xoh_hzip_dict_.Escape); + int page_bgn = rdr.Pos(); + int page_end = rdr.Find_fwd_lr(Xoh_hzip_dict_.Escape); + int capt_bgn = -1, capt_end = -1; + if (lnki_type != Xoh_lnki_dict_.Type__same) { + capt_bgn = rdr.Pos(); + capt_end = rdr.Find_fwd_lr(Xoh_hzip_dict_.Escape); + } + byte[] page_bry = Bry_.Mid(src, page_bgn, page_end); - Xoa_ttl ttl = ttl_parser.Ttl_parse(ns_id, page_bry); if (ttl == null) throw parser.Fail("invalid ttl", String_.new_u8(page_bry)); // TODO: parse title based on site + Xow_ns ns = ttl_parser.Ns_mgr().Ords_get_at(ns_ord); + Xoa_ttl ttl = ttl_parser.Ttl_parse(ns.Id(), page_bry); if (ttl == null) rdr.Fail("invalid ttl", String_.Empty, String_.new_u8(page_bry)); // TODO: parse title based on site byte[] ttl__full_db = ttl.Full_db(); // gen html - bfr.Add(Xoh_html_dict_.Hook__lnki); - bfr.Add_byte(lnki_type); - bfr.Add_str_a7("' href=\""); - if (site_exists) bfr.Add_str_a7("/site/").Add_mid(src, site_bgn, site_end); + bfr.Add(Html_bldr_.Bry__a_lhs_w_href); + if (site_exists) bfr.Add(Xoh_href_.Bry__wiki).Add_mid(src, site_bgn, site_end); bfr.Add(Xoh_href_.Bry__wiki); // "/wiki/" - bfr.Add(Html_utl.Escape_html_as_bry(ttl__full_db)); - bfr.Add_str_a7("\" id=\"").Add_str_a7(gplx.xowa.parsers.lnkis.redlinks.Xopg_redlink_lnki_list.Lnki_id_prefix).Add_int_variable(uid); + bfr.Add(ttl.Full_db()); + bfr.Add_str_a7("\" id=\"").Add_str_a7(gplx.xowa.parsers.lnkis.redlinks.Xopg_redlink_lnki_list.Lnki_id_prefix).Add_int_variable(++uid); bfr.Add_str_a7("\" title=\""); - if (lnki_type == Xoh_lnki_dict_.Type__caption_n) { - byte[] title_bry = site_exists ? ttl.Page_db() : ttl__full_db; // for xwiki, use page, not full alias; EX: "wikt:A" -> "A" x> "wikt:A" - bfr.Add(Html_utl.Escape_html_as_bry(title_bry)).Add_str_a7("\">"); - if (ns_id != 0) page_bry = ttl.Full_db(); - bfr.Add(page_bry); - bfr.Add(Html_tag_.A_rhs); // "" + byte[] title_bry = site_exists ? ttl.Page_db() : ttl__full_db; // for xwiki, use page, not full alias; EX: "wikt:A" -> "A" x> "wikt:A" + bfr.Add(Html_utl.Escape_html_as_bry(title_bry)).Add_str_a7("\">"); + switch (lnki_type) { + case Xoh_lnki_dict_.Type__same: + if (ttl.Ns().Id_is_main()) + bfr.Add_mid(src, page_bgn, page_end); + else + bfr.Add(ttl.Full_txt()); + break; + case Xoh_lnki_dict_.Type__diff: + bfr.Add_mid(src, capt_bgn, capt_end); + break; + case Xoh_lnki_dict_.Type__trail: + bfr.Add_mid(src, page_bgn, page_end); + bfr.Add_mid(src, capt_bgn, capt_end); + break; } - else { - bfr.Add(Html_utl.Escape_html_as_bry(page_bry)); - bfr.Add_str_a7("\">"); - } - return parser.Pos(); + bfr.Add_str_a7(""); + return rdr.Pos(); } - private static final byte[] - Bry__href = Bry_.new_a7(" href=\"") - , Bry__id = Bry_.new_a7(" id=\"xowa_lnki_") - , Bry__title = Bry_.new_a7(" title=\"") - ; - private static final byte Href_tid_wiki = 1, Href_tid_site = 2; - private static final Btrie_fast_mgr btrie_href = Btrie_fast_mgr.cs().Add_bry_byte(Xoh_href_.Bry__wiki, Href_tid_wiki).Add_bry_byte(Xoh_href_.Bry__site, Href_tid_site); -// , Find_img_xatrs = Bry_.new_a7("xatrs='") -// private static int[] Save_img_full_pow = new int[] {0, 1, 2}; -// private int Save_img_full(Bry_bfr bfr, Bry_rdr rdr, Hzip_stat_itm stat_itm, byte[] src, int src_len, int bgn, int pos) { -// bfr.Add(Xoh_hzip_dict_.Bry__img_full); -// int xatrs_bgn = Bry_find_.Move_fwd(src, Find_img_xatrs, pos, src_len); if (xatrs_bgn == Bry_find_.Not_found) return rdr.Warn("a.img_xatrs_missing", bgn, pos); -// bry_rdr.Init(src, xatrs_bgn); -// int a_cls = bry_rdr.Read_int_to_pipe(); -// int a_rel = bry_rdr.Read_int_to_pipe(); -// int img_rel = bry_rdr.Read_int_to_pipe(); -// byte meta = (byte)Bit_.Shift_lhs_to_int(Save_img_full_pow, a_cls, a_rel, img_rel); -// bfr.Add_byte(meta); // meta -// Xoh_hzip_int_.Encode(bfr, bry_rdr.Read_int_to_pipe()); // uid -// bfr.Add(bry_rdr.Read_bry_to_pipe()).Add_byte_pipe(); // img_cls_other -// bfr.Add(bry_rdr.Read_bry_to_apos()); // alt -// bfr.Add_byte(Xoh_hzip_dict_.Escape); -// return bry_rdr.Pos() + 2; // +2=/> -// } } diff --git a/400_xowa/src/gplx/xowa/htmls/core/wkrs/lnkis/Xoh_lnki_hzip_tst.java b/400_xowa/src/gplx/xowa/htmls/core/wkrs/lnkis/Xoh_lnki_hzip_tst.java index cfc32e579..a7c2ef255 100644 --- a/400_xowa/src/gplx/xowa/htmls/core/wkrs/lnkis/Xoh_lnki_hzip_tst.java +++ b/400_xowa/src/gplx/xowa/htmls/core/wkrs/lnkis/Xoh_lnki_hzip_tst.java @@ -19,42 +19,38 @@ package gplx.xowa.htmls.core.wkrs.lnkis; import gplx.*; import gplx.xowa.*; impo import org.junit.*; import gplx.xowa.htmls.core.hzips.tests.*; public class Xoh_lnki_hzip_tst { private final Xoh_hzip_fxt fxt = new Xoh_hzip_fxt(); - @Test public void Noop() { - String html = "A"; - fxt.Test__bicode(html, html); + @Test public void Page__basic() { + fxt.Test__bicode("~$1#A~", Xoh_lnki_html__hdump__tst.Html__same); } - @Test public void Lnki__basic() { - fxt.Test__bicode("~$0!#A~", Xoh_lnki_html__hdump__tst.Html__same); + @Test public void Page__alt_case() { + fxt.Test__bicode("~$1#a~", "a"); } - @Test public void Lnki__alt_case() { - fxt.Test__bicode("~$0!#a~", "a"); + @Test public void Page__ns() { + fxt.Test__bicode("~$1-A~", "Template:A"); } - @Test public void Lnki__ns() { - fxt.Test__bicode("~$0+#A~", "Template:A"); + @Test public void Capt__basic() { + fxt.Test__bicode("~$2#A~b~", Xoh_lnki_html__hdump__tst.Html__diff); } + @Test public void Capt__nest() { + fxt.Test__bicode + ( "~$2#A~C1D~" + , "C1D" + ); + // old: probably broken; fxt.Test__bicode("~$1!#A~~$1!#C~C1D", "C1D"); + } + @Test public void Trail__basic() { + fxt.Test__bicode("~$3#A~b~", Xoh_lnki_html__hdump__tst.Html__trail); + } +// @Test public void Capt__site__xwiki() { +// fxt.Parser_fxt().Init_xwiki_add_wiki_and_user_("wikt", "en.wiktionary.org"); +// fxt.Test__bicode("~$2!A~wikt:A~", Xoh_lnki_html__hdump__tst.Html__xwiki); +// } // @Test public void Lnki__apos() { // fxt.Test__bicode("~$0+#A'b~", "Template:A'b"); // } - @Test public void Lnki__xwiki() { - fxt.Parser_fxt().Init_xwiki_add_wiki_and_user_("wikt", "en.wiktionary.org"); - fxt.Test__bicode("~$0!#~en.wiktionary.org~wikt:A~", Xoh_lnki_html__hdump__tst.Html__xwiki); - } - @Test public void Caption__basic() { - fxt.Test__bicode("~$1!#A~b", Xoh_lnki_html__hdump__tst.Html__diff); - } - @Test public void Caption__nest() { - fxt.Test__bicode("~$1!#A~~$1!#C~C1D", "C1D"); - } -// @Test public void Caption__multiple() { // PURPOSE: if id is missing from 1st anchor, do not get from second -// String hzip = Xoh_hzip_fxt.Escape("$0!#A"); -// String html = "AB"; -// fxt.Test__encode(hzip, html); -//// fxt.Test_save(brys, "AB"); -//// fxt.Test_load(brys, "AB"); +// @Test public void Caption__reparent() { // PURPOSE: PAGE:en.w:Abyssal_plain; DATE:2015-06-02 +// String hzip = Xoh_hzip_fxt.Escape("~$1!#A~A1"); +// fxt.Test__encode(hzip, "A1"); +// fxt.Test__decode(hzip, "A1"); // } - @Test public void Caption__reparent() { // PURPOSE: PAGE:en.w:Abyssal_plain; DATE:2015-06-02 - String hzip = Xoh_hzip_fxt.Escape("~$1!#A~A1"); - fxt.Test__encode(hzip, "A1"); - fxt.Test__decode(hzip, "A1"); - } } diff --git a/400_xowa/src/gplx/xowa/htmls/core/wkrs/lnkis/Xoh_lnki_parse.java b/400_xowa/src/gplx/xowa/htmls/core/wkrs/lnkis/Xoh_lnki_parse.java deleted file mode 100644 index db5353ef9..000000000 --- a/400_xowa/src/gplx/xowa/htmls/core/wkrs/lnkis/Xoh_lnki_parse.java +++ /dev/null @@ -1,60 +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 . -*/ -package gplx.xowa.htmls.core.wkrs.lnkis; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*; import gplx.xowa.htmls.core.wkrs.*; -import gplx.langs.htmls.*; import gplx.langs.htmls.parsers.*; import gplx.xowa.htmls.hrefs.*; -import gplx.xowa.wikis.ttls.*; import gplx.xowa.htmls.core.parsers.*; -public class Xoh_lnki_parse { - public int Parse(Xoh_wkr wkr, Html_tag_rdr rdr, byte[] src, Html_tag lnki, Xow_ttl_parser ttl_parser) {// b - int tag_bgn = lnki.Src_bgn(), tag_end = lnki.Src_end(); - Html_atr href_atr = lnki.Atrs__get_by(Html_atr_.Bry__href); - int href_pos = href_atr.Val_bgn(); - int site_bgn = href_pos + Xoh_href_.Len__site, site_end = -1; - if (href_hash.Get_as_int_or(src, href_pos, site_bgn, -1) == Href_tid__site) // site; EX:"/site/en.wiktionary.org/" - site_end = href_pos = Bry_find_.Find_fwd(src, Byte_ascii.Slash, site_bgn); - else - site_bgn = -1; - int page_bgn = href_pos + Xoh_href_.Len__wiki, page_end = href_atr.Val_end(); - if (href_hash.Get_as_int_or(src, href_pos, page_bgn, -1) != Href_tid__wiki) // site; EX:"/site/en.wiktionary.org/" - throw Err_.new_("Xoh_parser", "invalid url", "url", String_.new_u8(src, href_pos, page_bgn)); -// Html_atr title_atr = lnki.Atrs__get_by(Html_atr_.Bry__title); -// int title_bgn = title_atr.Val_bgn(), title_end = title_atr.Val_end(); - Html_tag lnki_tail = rdr.Tag__move_fwd_tail(Html_tag_.Id__a); - int capt_bgn = tag_end; int capt_end = lnki_tail.Src_bgn(); - tag_end = lnki_tail.Src_end(); - byte lnki_type = ttl_matcher.Match(ttl_parser, src, page_bgn, page_end, src, capt_bgn, capt_end); - byte[] page_bry = null, capt_bry = null, trail_bry = null; - switch (lnki_type) { - case Xoh_ttl_matcher.Tid__diff: - page_bry = Bry_.Mid(src, page_bgn, page_end); - capt_bry = Bry_.Mid(src, capt_bgn, capt_end); - break; - case Xoh_ttl_matcher.Tid__same: - capt_bry = Bry_.Mid(src, capt_bgn, capt_end); - break; - case Xoh_ttl_matcher.Tid__trail: - capt_bry = Bry_.Mid(src, capt_bgn, ttl_matcher.Trail_bgn()); - trail_bry = Bry_.Mid(src, ttl_matcher.Trail_bgn(), capt_end); - break; - } - wkr.On_lnki(tag_bgn, tag_end, lnki_type, site_bgn, site_end, page_bry, capt_bry, trail_bry); - return tag_end; - } - private static final int Href_tid__wiki = 1, Href_tid__site = 2; - private static final Hash_adp_bry href_hash = Hash_adp_bry.ci_a7().Add_bry_int(Xoh_href_.Bry__wiki, Href_tid__wiki).Add_bry_int(Xoh_href_.Bry__site, Href_tid__site); - private final Xoh_ttl_matcher ttl_matcher = new Xoh_ttl_matcher(); -} diff --git a/400_xowa/src/gplx/xowa/htmls/core/wkrs/lnkis/Xoh_lnki_parse_tst.java b/400_xowa/src/gplx/xowa/htmls/core/wkrs/lnkis/Xoh_lnki_parse_tst.java deleted file mode 100644 index bad85eb2e..000000000 --- a/400_xowa/src/gplx/xowa/htmls/core/wkrs/lnkis/Xoh_lnki_parse_tst.java +++ /dev/null @@ -1,38 +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 . -*/ -package gplx.xowa.htmls.core.wkrs.lnkis; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*; import gplx.xowa.htmls.core.wkrs.*; -import org.junit.*; import gplx.xowa.htmls.core.parsers.*; -public class Xoh_lnki_parse_tst { - private final Xoh_parser_fxt fxt = new Xoh_parser_fxt(); - @Test public void Same() { - fxt.Init__lnki(0, 70, Xoh_lnki_dict_.Type__same, -1, -1, "", "A", ""); - fxt.Test__parse(Xoh_lnki_html__hdump__tst.Html__same); - } - @Test public void Diff() { - fxt.Init__lnki(0, 70, Xoh_lnki_dict_.Type__diff, -1, -1, "A", "b", ""); - fxt.Test__parse(Xoh_lnki_html__hdump__tst.Html__diff); - } - @Test public void Trail() { - fxt.Init__lnki(0, 71, Xoh_lnki_dict_.Type__trail, -1, -1, "", "A", "b"); - fxt.Test__parse(Xoh_lnki_html__hdump__tst.Html__trail); - } - @Test public void Recurse() { -// fxt.Init__lnki(0, 69, Xoh_lnki_dict_.Type__caption_n, -1, -1, "A"); -// fxt.Test__parse("Abc"); - } -} diff --git a/400_xowa/src/gplx/xowa/htmls/core/wkrs/lnkis/Xoh_lnki_parser.java b/400_xowa/src/gplx/xowa/htmls/core/wkrs/lnkis/Xoh_lnki_parser.java new file mode 100644 index 000000000..a85fd89cb --- /dev/null +++ b/400_xowa/src/gplx/xowa/htmls/core/wkrs/lnkis/Xoh_lnki_parser.java @@ -0,0 +1,55 @@ +/* +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 . +*/ +package gplx.xowa.htmls.core.wkrs.lnkis; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*; import gplx.xowa.htmls.core.wkrs.*; +import gplx.core.brys.*; import gplx.langs.htmls.*; import gplx.langs.htmls.parsers.*; import gplx.xowa.htmls.hrefs.*; +import gplx.xowa.htmls.core.wkrs.lnkis.anchs.*; +import gplx.xowa.wikis.ttls.*; +public class Xoh_lnki_parser { + private final Xoh_ttl_matcher ttl_matcher = new Xoh_ttl_matcher(); + private final Bry_rdr rdr = new Bry_rdr(); + public int Rng_bgn() {return rng_bgn;} private int rng_bgn; + public int Rng_end() {return rng_end;} private int rng_end; + public byte Lnki_type() {return lnki_type;} private byte lnki_type; + public byte[] Capt_bry() {return capt_bry;} private byte[] capt_bry; + public byte[] Trail_bry() {return trail_bry;} private byte[] trail_bry; + public Xoh_anch_href_parser Anch_href_parser() {return anch_href_parser;} private final Xoh_anch_href_parser anch_href_parser = new Xoh_anch_href_parser(); + public int Parse(Xoh_hdoc_wkr wkr, Html_tag_rdr tag_rdr, byte[] src, Html_tag anch_tag, Xow_ttl_parser ttl_parser) {// b + this.rng_bgn = anch_tag.Src_bgn(); this.rng_end = anch_tag.Src_end(); + rdr.Ctor_by_page(Bry_.Empty, src, src.length); + anch_href_parser.Parse(rdr, wkr.Ctx().Wiki(), anch_tag); // href='/wiki/A' + Html_tag lnki_tail = tag_rdr.Tag__move_fwd_tail(Html_tag_.Id__a); // + int capt_bgn = rng_end; int capt_end = lnki_tail.Src_bgn(); // get capt between "" and " + this.rng_end = lnki_tail.Src_end(); + this.lnki_type = ttl_matcher.Match(rdr, ttl_parser, src, anch_href_parser.Page_bgn(), anch_href_parser.Page_end(), src, capt_bgn, capt_end); + this.capt_bry = trail_bry = null; + switch (lnki_type) { + case Xoh_ttl_matcher.Tid__same: + this.capt_bry = Bry_.Mid(src, capt_bgn, capt_end); + break; + case Xoh_ttl_matcher.Tid__diff: + this.capt_bry = Bry_.Mid(src, capt_bgn, capt_end); + break; + case Xoh_ttl_matcher.Tid__trail: + this.capt_bry = Bry_.Mid(src, capt_bgn, ttl_matcher.Trail_bgn()); + this.trail_bry = Bry_.Mid(src, ttl_matcher.Trail_bgn(), capt_end); + break; + } + wkr.On_lnki(this); + return rng_end; + } +} diff --git a/400_xowa/src/gplx/xowa/htmls/core/parsers/Xoh_ttl_matcher.java b/400_xowa/src/gplx/xowa/htmls/core/wkrs/lnkis/Xoh_ttl_matcher.java similarity index 72% rename from 400_xowa/src/gplx/xowa/htmls/core/parsers/Xoh_ttl_matcher.java rename to 400_xowa/src/gplx/xowa/htmls/core/wkrs/lnkis/Xoh_ttl_matcher.java index f482e662e..0e320fb24 100644 --- a/400_xowa/src/gplx/xowa/htmls/core/parsers/Xoh_ttl_matcher.java +++ b/400_xowa/src/gplx/xowa/htmls/core/wkrs/lnkis/Xoh_ttl_matcher.java @@ -15,17 +15,19 @@ 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 . */ -package gplx.xowa.htmls.core.parsers; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*; +package gplx.xowa.htmls.core.wkrs.lnkis; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*; import gplx.xowa.htmls.core.wkrs.*; +import gplx.core.brys.*; import gplx.xowa.wikis.nss.*; import gplx.xowa.wikis.ttls.*; +import gplx.langs.htmls.parsers.*; public class Xoh_ttl_matcher { public int Trail_bgn() {return trail_bgn;} private int trail_bgn; - public byte Match(Xow_ttl_parser ttl_parser, byte[] page_bry, int page_bgn, int page_end, byte[] capt_bry, int capt_bgn, int capt_end) { + public byte Match(Bry_rdr owner_rdr, Xow_ttl_parser ttl_parser, byte[] page_bry, int page_bgn, int page_end, byte[] capt_bry, int capt_bgn, int capt_end) { trail_bgn = -1; - int page_len = page_end - page_bgn; - Xoa_ttl page = ttl_parser.Ttl_parse(page_bry, page_bgn, page_end); if (page == null) throw Err_.new_("", "invalid page", "page", page_bry); + int page_len = page_end - page_bgn; if (page_len == 0) page_bry = Xoa_page_.Main_page_bry; // NOTE: href="/site/en.wikipedia.org/wiki/" can be null + Xoa_ttl page = ttl_parser.Ttl_parse(page_bry, page_bgn, page_end); if (page == null) owner_rdr.Fail("invalid page", "page", page_bry); Xow_ns ns = page.Ns(); - if (ns.Id() != Xow_ns_.Id_main) { - byte[] ns_name_txt = ns.Name_txt_w_colon(); // EX: 11="Template talk:" + if (ns.Id() != Xow_ns_.Tid__main) { + byte[] ns_name_txt = ns.Name_ui_w_colon(); // EX: 11="Template talk:" int ns_name_txt_len = ns_name_txt.length; int ns_name_txt_end = capt_bgn + ns_name_txt_len; if (Bry_.Match(capt_bry, capt_bgn, ns_name_txt_end, ns_name_txt, 0, ns_name_txt_len)) diff --git a/400_xowa/src/gplx/xowa/htmls/core/parsers/Xoh_ttl_matcher_tst.java b/400_xowa/src/gplx/xowa/htmls/core/wkrs/lnkis/Xoh_ttl_matcher_tst.java similarity index 83% rename from 400_xowa/src/gplx/xowa/htmls/core/parsers/Xoh_ttl_matcher_tst.java rename to 400_xowa/src/gplx/xowa/htmls/core/wkrs/lnkis/Xoh_ttl_matcher_tst.java index 013609aaf..e88e080ae 100644 --- a/400_xowa/src/gplx/xowa/htmls/core/parsers/Xoh_ttl_matcher_tst.java +++ b/400_xowa/src/gplx/xowa/htmls/core/wkrs/lnkis/Xoh_ttl_matcher_tst.java @@ -15,8 +15,8 @@ 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 . */ -package gplx.xowa.htmls.core.parsers; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*; -import org.junit.*; +package gplx.xowa.htmls.core.wkrs.lnkis; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*; import gplx.xowa.htmls.core.wkrs.*; +import org.junit.*; import gplx.core.brys.*; import gplx.langs.htmls.parsers.*; public class Xoh_ttl_matcher_tst { private final Xoh_ttl_matcher_fxt fxt = new Xoh_ttl_matcher_fxt(); @Test public void Basic__same() {fxt.Test__match("Abc" , "Abc", Xoh_ttl_matcher.Tid__same);} @@ -34,6 +34,7 @@ public class Xoh_ttl_matcher_tst { } class Xoh_ttl_matcher_fxt { private final Xoh_ttl_matcher matcher = new Xoh_ttl_matcher(); + private final Bry_rdr rdr = new Bry_rdr(); public Xoh_ttl_matcher_fxt() { Xoae_app app = Xoa_app_fxt.app_(); this.wiki = Xoa_app_fxt.wiki_tst_(app); @@ -43,7 +44,7 @@ class Xoh_ttl_matcher_fxt { public void Test__match(String page_str, String capt_str, int expd_tid, int expd_trail_bgn) { byte[] page_bry = Bry_.new_u8(page_str); byte[] capt_bry = Bry_.new_u8(capt_str); - Tfds.Eq_int(expd_tid , matcher.Match(wiki, page_bry, 0, page_bry.length, capt_bry, 0, capt_bry.length)); + Tfds.Eq_int(expd_tid , matcher.Match(rdr.Ctor_by_page(Bry_.Empty, page_bry, page_bry.length), wiki, page_bry, 0, page_bry.length, capt_bry, 0, capt_bry.length)); Tfds.Eq_int(expd_trail_bgn , matcher.Trail_bgn()); } } diff --git a/400_xowa/src/gplx/xowa/htmls/core/wkrs/lnkis/anchs/Xoh_anch_href_parser.java b/400_xowa/src/gplx/xowa/htmls/core/wkrs/lnkis/anchs/Xoh_anch_href_parser.java new file mode 100644 index 000000000..5fd906fff --- /dev/null +++ b/400_xowa/src/gplx/xowa/htmls/core/wkrs/lnkis/anchs/Xoh_anch_href_parser.java @@ -0,0 +1,65 @@ +/* +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 . +*/ +package gplx.xowa.htmls.core.wkrs.lnkis.anchs; 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 gplx.core.brys.*; import gplx.core.btries.*; +import gplx.langs.htmls.*; import gplx.langs.htmls.parsers.*; +import gplx.xowa.wikis.ttls.*; +public class Xoh_anch_href_parser implements Xoh_itm_parser { + private byte[] src; private Xoa_ttl page_ttl; Xow_ttl_parser ttl_parser; + private final Bry_rdr rdr = new Bry_rdr(); + public void Fail_throws_err_(boolean v) {rdr.Fail_throws_err_(v);}// TEST + public int Val_bgn() {return val_bgn;} private int val_bgn; + public int Val_end() {return val_end;} private int val_end; + public int Site_bgn() {return site_bgn;} private int site_bgn; + public int Site_end() {return site_end;} private int site_end; + public boolean Site_exists() {return site_end > site_bgn;} + public int Page_bgn() {return page_bgn;} private int page_bgn; + public int Page_end() {return page_end;} private int page_end; + public byte[] Page_bry() {if (page_bry == null) page_bry = Bry_.Mid(src, page_bgn, page_end); return page_bry;} private byte[] page_bry; + public Xoa_ttl Page_ttl() { + if (page_ttl == null) { + page_bry = this.Page_bry(); + page_ttl = ttl_parser.Ttl_parse(page_bry); + } + return page_ttl; + } + public void Parse(Bry_rdr owner_rdr, Xow_ttl_parser ttl_parser, Html_tag tag) { + Html_atr atr = tag.Atrs__get_by(Html_atr_.Bry__href); + Parse(owner_rdr, ttl_parser, atr.Val_bgn(), atr.Val_end()); + } + public void Parse(Bry_rdr owner_rdr, Xow_ttl_parser ttl_parser, int href_bgn, int href_end) { + rdr.Init_by_sub(owner_rdr, "lnki.href", href_bgn, href_end).Dflt_dlm_(Byte_ascii.Slash); + site_bgn = -1; site_end = -1; page_bry = null; page_ttl = null; + this.val_bgn = href_bgn; this.val_end = href_end; + this.src = owner_rdr.Src(); this.ttl_parser = ttl_parser; + rdr.Chk(Byte_ascii.Slash); + if (rdr.Chk(trie) == Href_tid__site) { // EX: // "/site/wiki/A" + site_bgn = rdr.Pos(); + site_end = rdr.Find_fwd_lr(); + rdr.Chk(Bry__wiki); + } + page_bgn = rdr.Pos(); + page_end = rdr.Src_end(); + } + private static final byte Href_tid__wiki = 1, Href_tid__site = 2; + private static final byte[] Bry__site = Bry_.new_a7("site/"), Bry__wiki = Bry_.new_a7("wiki/"); + private static final Btrie_slim_mgr trie = Btrie_slim_mgr.ci_a7() + .Add_bry_byte(Bry__wiki, Href_tid__wiki) + .Add_bry_byte(Bry__site, Href_tid__site) + ; +} diff --git a/400_xowa/src/gplx/xowa/htmls/core/wkrs/lnkis/anchs/Xoh_anch_href_parser_tst.java b/400_xowa/src/gplx/xowa/htmls/core/wkrs/lnkis/anchs/Xoh_anch_href_parser_tst.java new file mode 100644 index 000000000..5ae517f92 --- /dev/null +++ b/400_xowa/src/gplx/xowa/htmls/core/wkrs/lnkis/anchs/Xoh_anch_href_parser_tst.java @@ -0,0 +1,51 @@ +/* +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 . +*/ +package gplx.xowa.htmls.core.wkrs.lnkis.anchs; 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.core.brys.*; import gplx.xowa.wikis.ttls.*; +public class Xoh_anch_href_parser_tst { + private final Xoh_anch_href_parser_fxt fxt = new Xoh_anch_href_parser_fxt(); + @Test public void Site() { + fxt.Test__parse("/site/A/wiki/B", "A", "B"); + } + @Test public void Page() { + fxt.Test__parse("/wiki/B", "", "B"); + } + @Test public void Fail__1st_seg_must_be_site_or_wiki() { + fxt.Test__parse__fail("/fail/A", "failed trie check: mid='fail/A' ctx='Main_Page' wkr='lnki.href' excerpt='/fail/A'"); + } + @Test public void Fail__2nd_seg_must_be_wiki() { + fxt.Test__parse__fail("/site/A/B/C", "failed check: chk='wiki/' ctx='Main_Page' wkr='lnki.href' excerpt='/site/A/B/C'"); + } +} +class Xoh_anch_href_parser_fxt extends Xoh_itm_parser_fxt_base { + private final Xoh_anch_href_parser parser = new Xoh_anch_href_parser(); + private final Xow_ttl_parser ttl_parser; + public Xoh_anch_href_parser_fxt() { + Xoae_app app = Xoa_app_fxt.app_(); + ttl_parser = Xoa_app_fxt.wiki_tst_(app); + } + @Override public Xoh_itm_parser Parser_get() {return parser;} + public void Test__parse(String src_str, String expd_site, String expd_page) { + Exec_parse(src_str); + Tfds.Eq_str(expd_site, parser.Site_bgn() == -1 ? "" : String_.new_u8(src, parser.Site_bgn(), parser.Site_end())); + Tfds.Eq_str(expd_page, String_.new_u8(src, parser.Page_bgn(), parser.Page_end())); + } + @Override public void Exec_parse_hook(Bry_rdr owner_rdr, int src_bgn, int src_end) { + parser.Parse(owner_rdr, ttl_parser, src_bgn, src_end); + } +} diff --git a/400_xowa/src/gplx/xowa/htmls/core/wkrs/lnkis/htmls/Xoh_arg_img_core__hdump.java b/400_xowa/src/gplx/xowa/htmls/core/wkrs/lnkis/htmls/Xoh_arg_img_core__hdump.java index a24de7ed0..7810b7b00 100644 --- a/400_xowa/src/gplx/xowa/htmls/core/wkrs/lnkis/htmls/Xoh_arg_img_core__hdump.java +++ b/400_xowa/src/gplx/xowa/htmls/core/wkrs/lnkis/htmls/Xoh_arg_img_core__hdump.java @@ -26,6 +26,6 @@ public class Xoh_arg_img_core__hdump implements Xoh_arg_img_core { bfr.Add_byte_space(); bfr.Add(gplx.xowa.htmls.core.makes.Xoh_make_trie_.Bry__img); bfr.Add_int_variable(uid); - bfr.Add_byte_apos(); + bfr.Add_byte_quote(); } } diff --git a/400_xowa/src/gplx/xowa/htmls/core/wkrs/lnkis/htmls/Xoh_file_html_fmtr__base.java b/400_xowa/src/gplx/xowa/htmls/core/wkrs/lnkis/htmls/Xoh_file_html_fmtr__base.java index c825b642f..29b41814f 100644 --- a/400_xowa/src/gplx/xowa/htmls/core/wkrs/lnkis/htmls/Xoh_file_html_fmtr__base.java +++ b/400_xowa/src/gplx/xowa/htmls/core/wkrs/lnkis/htmls/Xoh_file_html_fmtr__base.java @@ -16,11 +16,11 @@ You should have received a copy of the GNU Affero General Public License along with this program. If not, see . */ 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 gplx.xowa.files.*; import gplx.xowa.htmls.core.makes.*; +import gplx.xowa.files.*; import gplx.xowa.htmls.core.makes.*; import gplx.xowa.htmls.core.wkrs.imgs.atrs.*; import gplx.xowa.htmls.core.htmls.*; import gplx.xowa.parsers.lnkis.*; public class Xoh_file_html_fmtr__base implements Xoh_file_img_wkr { - private final Xoh_arg_img_core arg_img_core; + protected final Xoh_arg_img_core arg_img_core; private Bry_bfr scratch_bfr = Bry_bfr.reset_(128); public Xoh_file_html_fmtr__base() { arg_img_core = New_arg_img_core(); @@ -38,7 +38,7 @@ public class Xoh_file_html_fmtr__base implements Xoh_file_img_wkr { ) { fmtr_full_img.Bld_bfr_many(tmp_bfr, uid , a_href, Xoh_lnki_consts.A_cls_to_bry(a_cls), Xoh_lnki_consts.A_rel_to_bry(a_rel), a_title, a_xowa_title - , arg_img_core.Init(uid, img_src, img_w, img_h), img_alt, Xoh_lnki_consts.Img_cls_to_bry(img_cls, img_cls_other)); + , arg_img_core.Init(uid, img_src, img_w, img_h), img_alt, Xoh_img_cls_.To_html(img_cls, img_cls_other)); } private Bry_fmtr fmtr_full_img = Bry_fmtr.new_ ( "" diff --git a/400_xowa/src/gplx/xowa/htmls/core/wkrs/lnkis/htmls/Xoh_file_html_fmtr__hdump.java b/400_xowa/src/gplx/xowa/htmls/core/wkrs/lnkis/htmls/Xoh_file_html_fmtr__hdump.java index e350d76bd..f50a0d44f 100644 --- a/400_xowa/src/gplx/xowa/htmls/core/wkrs/lnkis/htmls/Xoh_file_html_fmtr__hdump.java +++ b/400_xowa/src/gplx/xowa/htmls/core/wkrs/lnkis/htmls/Xoh_file_html_fmtr__hdump.java @@ -18,38 +18,44 @@ along with this program. If not, see . 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 gplx.langs.htmls.*; import gplx.xowa.files.*; import gplx.xowa.htmls.core.makes.*; +import gplx.xowa.htmls.core.wkrs.imgs.atrs.*; public class Xoh_file_html_fmtr__hdump extends Xoh_file_html_fmtr__base { - private Bry_bfr tmp_bfr = Bry_bfr.reset_(128); - @gplx.Internal @Override protected Xoh_arg_img_core New_arg_img_core() {return new Xoh_arg_img_core__hdump();} + private final Bry_bfr tmp_bfr = Bry_bfr.reset_(128); + @Override public void Html_full_img(Bry_bfr bfr, gplx.xowa.htmls.core.htmls.Xoh_wtr_ctx hctx, Xoae_page page, Xof_file_itm xfer_itm, int uid, byte[] a_href, byte a_cls, byte a_rel, byte[] a_title, byte[] a_xowa_title, int img_w, int img_h, byte[] img_src, byte[] img_alt, byte img_cls, byte[] img_cls_other) { + tmp_bfr.Add_str_a7(" data-xoimg=\""); + tmp_bfr.Add_int_digits(1, xfer_itm.Lnki_type()).Add_byte_pipe(); + tmp_bfr.Add_int_variable(xfer_itm.Lnki_w()).Add_byte_pipe(); + tmp_bfr.Add_int_variable(xfer_itm.Lnki_h()).Add_byte_pipe(); + tmp_bfr.Add_double(xfer_itm.Lnki_upright()).Add_byte_pipe(); + tmp_bfr.Add_double(xfer_itm.Lnki_time()).Add_byte_pipe(); + tmp_bfr.Add_int_variable(xfer_itm.Lnki_page()).Add_byte_quote(); + fmtr__img__full.Bld_bfr_many(bfr + , a_href, Xoh_lnki_consts.A_cls_to_bry(a_cls), Xoh_lnki_consts.A_rel_to_bry(a_rel), a_title + , img_alt, tmp_bfr.To_bry_and_clear(), arg_img_core.Init(uid, img_src, img_w, img_h), Xoh_img_cls_.To_html(img_cls, img_cls_other)); + } + private Bry_fmtr fmtr__img__full = Bry_fmtr.new_ + ( "" + + "\"~{img_alt}\"~{img_xoimg}~{img_core}~{img_class}/" + + "" + , "a_href", "a_class", "a_rel", "a_title", "img_alt", "img_xoimg", "img_core", "img_class" + ); // public override void Html_full_media(Bry_bfr tmp_bfr, byte[] a_href, byte[] a_title, Bry_fmtr_arg html) { // fmtr_full_media.Bld_bfr_many(tmp_bfr, a_href, a_title, html); -// } -// public override void Html_full_img(Bry_bfr tmp_bfr, Xoh_wtr_ctx hctx, Xoae_page page, Xof_file_itm xfer_itm, int uid -// , byte[] a_href, byte a_cls, byte a_rel, byte[] a_title, byte[] a_xowa_title -// , int img_w, int img_h, byte[] img_src, byte[] img_alt, byte img_cls, byte[] img_cls_other) { -// tmp_bfr.Add_str_a7(""); // } @Override public void Html_thumb_core(Bry_bfr bfr, int uid, byte[] div1_halign, int div2_width, byte[] div2_content) { tmp_bfr.Add(Xoh_make_trie_.Bry__img_style); tmp_bfr.Add_int_variable(uid); - tmp_bfr.Add_byte_apos(); + tmp_bfr.Add_byte_quote(); byte[] div2_width_repl = tmp_bfr.To_bry_and_clear(); fmtr_thumb_core.Bld_bfr_many(bfr, uid, div1_halign, div2_width_repl, div2_content); } @Override public void Html_thumb_part_magnify(Bry_bfr bfr, int uid, byte[] a_href, byte[] a_title, byte[] img_src) {Write_xnde(bfr, Xoh_make_trie_.Bry__file_mgnf, uid);} @Override public void Html_thumb_part_info(Bry_bfr bfr, int uid, byte[] a_href, byte[] img_src) {Write_xnde(bfr, Xoh_make_trie_.Bry__file_info, uid);} @Override public void Html_thumb_part_play(Bry_bfr bfr, int uid, int a_width, int a_max_width, byte[] a_href, byte[] a_xowa_title, byte[] img_src) {Write_xnde(bfr, Xoh_make_trie_.Bry__file_play, uid);} - public static void Write_xnde(Bry_bfr bfr, byte[] key, int uid) { + private static void Write_xnde(Bry_bfr bfr, byte[] key, int uid) { bfr.Add(key); bfr.Add_int_variable(uid); bfr.Add(Bry_xnde_end); - } private static final byte[] Bry_xnde_end = Bry_.new_a7("'/>"); + } private static final byte[] Bry_xnde_end = Bry_.new_a7("\"/>"); public static final Xoh_file_html_fmtr__hdump Hdump = new Xoh_file_html_fmtr__hdump(); Xoh_file_html_fmtr__hdump() {} } diff --git a/400_xowa/src/gplx/xowa/htmls/core/wkrs/lnkis/htmls/Xoh_file_mgr.java b/400_xowa/src/gplx/xowa/htmls/core/wkrs/lnkis/htmls/Xoh_file_mgr.java index e482690a8..2a9d4c696 100644 --- a/400_xowa/src/gplx/xowa/htmls/core/wkrs/lnkis/htmls/Xoh_file_mgr.java +++ b/400_xowa/src/gplx/xowa/htmls/core/wkrs/lnkis/htmls/Xoh_file_mgr.java @@ -33,7 +33,7 @@ public class Xoh_file_mgr { public void Write_or_queue(Bry_bfr bfr, Xoae_page page, Xop_ctx ctx, Xoh_wtr_ctx hctx, byte[] src, Xop_lnki_tkn lnki, byte[] alt_text) { file_wtr.Write_file(bfr, ctx, hctx, src, lnki, this.Lnki_eval(Xof_exec_tid.Tid_wiki_page, ctx, page, lnki), alt_text); } - public Xof_file_itm Lnki_eval(int exec_tid, Xop_ctx ctx, Xoae_page page, Xop_lnki_tkn lnki) {return Lnki_eval(exec_tid, ctx, page, page.File_queue(), lnki.Ttl().Page_url(), lnki.Lnki_type(), lnki.Upright(), lnki.W(), lnki.H(), lnki.Time(), lnki.Page(), lnki.Ns_id() == Xow_ns_.Id_media);} + public Xof_file_itm Lnki_eval(int exec_tid, Xop_ctx ctx, Xoae_page page, Xop_lnki_tkn lnki) {return Lnki_eval(exec_tid, ctx, page, page.File_queue(), lnki.Ttl().Page_url(), lnki.Lnki_type(), lnki.Upright(), lnki.W(), lnki.H(), lnki.Time(), lnki.Page(), lnki.Ns_id() == Xow_ns_.Tid__media);} public Xof_file_itm Lnki_eval(int exec_tid, Xop_ctx ctx, Xoae_page page, Xof_xfer_queue queue, byte[] lnki_ttl, byte lnki_type, double lnki_upright, int lnki_w, int lnki_h, double lnki_time, int lnki_page, boolean lnki_is_media_ns) { int uid = queue.Html_uid().Val_add(); Xof_xfer_itm xfer = new Xof_xfer_itm(); diff --git a/400_xowa/src/gplx/xowa/htmls/core/wkrs/lnkis/htmls/Xoh_file_wtr__basic.java b/400_xowa/src/gplx/xowa/htmls/core/wkrs/lnkis/htmls/Xoh_file_wtr__basic.java index 1673fcc9f..9a6165ad4 100644 --- a/400_xowa/src/gplx/xowa/htmls/core/wkrs/lnkis/htmls/Xoh_file_wtr__basic.java +++ b/400_xowa/src/gplx/xowa/htmls/core/wkrs/lnkis/htmls/Xoh_file_wtr__basic.java @@ -16,11 +16,11 @@ You should have received a copy of the GNU Affero General Public License along with this program. If not, see . */ 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 gplx.langs.htmls.*; +import gplx.langs.htmls.*; import gplx.xowa.langs.*; import gplx.xowa.langs.msgs.*; import gplx.xowa.wikis.nss.*; import gplx.xowa.files.*; -import gplx.xowa.htmls.core.htmls.*; import gplx.xowa.htmls.core.makes.imgs.*; +import gplx.xowa.htmls.core.htmls.*; import gplx.xowa.htmls.core.makes.imgs.*; import gplx.xowa.htmls.core.wkrs.imgs.atrs.*; import gplx.xowa.parsers.*; import gplx.xowa.parsers.lnkis.*; import gplx.xowa.parsers.tmpls.*; public class Xoh_file_wtr__basic { private final Xowe_wiki wiki; private final Xow_html_mgr html_mgr; private final Xoh_html_wtr html_wtr; private final Bry_bfr_mkr bfr_mkr; private final Bry_bfr scratch_bfr = Bry_bfr.reset_(Io_mgr.Len_kb); @@ -61,11 +61,11 @@ public class Xoh_file_wtr__basic { if ( html_mgr.Img_suppress_missing_src() // option to suppress src when file is missing && !xfer_itm.File_exists() // file is missing; wipe values and wait for "correct" info before regenerating; mostly to handle unknown redirects && !orig_ext.Id_is_media() // file is media; never suppress; src needs to be available for "click" on play; note that most media will be missing (not downloaded) - && lnki.Ns_id() != Xow_ns_.Id_media // ns is media; never suppress; "src" will use only orig_src; DATE:2014-01-30 + && lnki.Ns_id() != Xow_ns_.Tid__media // ns is media; never suppress; "src" will use only orig_src; DATE:2014-01-30 ) { img_orig_src = img_view_src = Bry_.Empty; // null out src } - if (lnki.Ns_id() == Xow_ns_.Id_media) // NOTE: regardless of ext (ogg vs jpeg) and literal status (Media vs :Media), [[Media]] links are always rendered the same way; REF.MW:Linker.php|makeMediaLinkObj; PAGE:en.w:Beethoven; EX: [[:Media:De-Ludwig_van_Beethoven.ogg|listen]]); [[File:Beethoven 3.jpg|The [[Media:BeethovenWithLyreGuitar( W. J. Mahler - 1804).jpg|complete painting]]...]] + if (lnki.Ns_id() == Xow_ns_.Tid__media) // NOTE: regardless of ext (ogg vs jpeg) and literal status (Media vs :Media), [[Media]] links are always rendered the same way; REF.MW:Linker.php|makeMediaLinkObj; PAGE:en.w:Beethoven; EX: [[:Media:De-Ludwig_van_Beethoven.ogg|listen]]); [[File:Beethoven 3.jpg|The [[Media:BeethovenWithLyreGuitar( W. J. Mahler - 1804).jpg|complete painting]]...]] this.Write_file_ns_media(bfr, ctx, src, lnki, img_orig_src); else { if ( Xof_ext_.Id_is_video_strict(orig_ext.Id()) // id is .ogv or .webm @@ -135,7 +135,7 @@ public class Xoh_file_wtr__basic { case Xop_lnki_align_h.None: bfr.Add(Div_float_none) .Add_byte_nl(); div_align_exists = true; break; } Arg_nde_tkn lnki_link_tkn = lnki.Link_tkn(); - byte img_cls_tid = lnki.Border() == Bool_.Y_byte ? Xoh_lnki_consts.Tid_img_cls_thumbborder : Xoh_lnki_consts.Tid_img_cls_none; + byte img_cls_tid = lnki.Border() == Bool_.Y_byte ? Xoh_img_cls_.Tid__thumbborder : Xoh_img_cls_.Tid__none; byte[] img_cls_other = lnki.Lnki_cls(); // PAGE:en.s:Page:Notes_on_Osteology_of_Baptanodon._With_a_Description_of_a_New_Species.pdf/3; DATE:2014-09-06 if (lnki_link_tkn == Arg_nde_tkn.Null) // full lnki_file_wkr.Html_full_img(bfr, hctx, page, xfer_itm, uid, lnki_href, Xoh_lnki_consts.Tid_a_cls_image, Xoh_lnki_consts.Tid_a_rel_none, anchor_title, lnki_ttl, xfer_itm.Html_w(), xfer_itm.Html_h(), img_view_src, alt, img_cls_tid, img_cls_other); @@ -155,9 +155,9 @@ public class Xoh_file_wtr__basic { } private byte[] Arg_content_thumb(Xoh_file_img_wkr lnki_file_wkr, Xop_ctx ctx, Xoh_wtr_ctx hctx, byte[] src, Xop_lnki_tkn lnki, Xof_file_itm xfer_itm, int uid, byte[] lnki_href, byte[] view_src, byte[] img_orig_src, byte[] lnki_alt_text, byte[] lnki_ttl, byte[] anchor_title) { byte[] lnki_alt_html = wiki.Html_mgr().Imgs_mgr().Alt_in_caption().Val() ? Arg_alt_html(ctx, src, lnki) : Bry_.Empty; - byte img_cls_tid = xfer_itm.File_exists() ? Xoh_lnki_consts.Tid_img_cls_thumbimage : Xoh_lnki_consts.Tid_img_cls_none; + byte img_cls_tid = xfer_itm.File_exists() ? Xoh_img_cls_.Tid__thumbimage : Xoh_img_cls_.Tid__none; Bry_bfr tmp_bfr = bfr_mkr.Get_k004(); - lnki_file_wkr.Html_full_img(tmp_bfr, hctx, page, xfer_itm, uid, lnki_href, Xoh_lnki_consts.Tid_a_cls_image, Xoh_lnki_consts.Tid_a_rel_none, anchor_title, lnki_ttl, xfer_itm.Html_w(), xfer_itm.Html_h(), view_src, lnki_alt_text, img_cls_tid, Xoh_lnki_consts.Bry_none); + lnki_file_wkr.Html_full_img(tmp_bfr, hctx, page, xfer_itm, uid, lnki_href, Xoh_lnki_consts.Tid_a_cls_image, Xoh_lnki_consts.Tid_a_rel_none, anchor_title, lnki_ttl, xfer_itm.Html_w(), xfer_itm.Html_h(), view_src, lnki_alt_text, img_cls_tid, Xoh_img_cls_.Bry__none); byte[] thumb = tmp_bfr.To_bry_and_clear(); html_fmtr.Html_thumb_file_image(tmp_bfr, thumb, Arg_caption_div(ctx, src, lnki, uid, img_orig_src, lnki_href), lnki_alt_html); return tmp_bfr.To_bry_and_rls(); diff --git a/400_xowa/src/gplx/xowa/htmls/core/wkrs/lnkis/htmls/Xoh_lnki_consts.java b/400_xowa/src/gplx/xowa/htmls/core/wkrs/lnkis/htmls/Xoh_lnki_consts.java index 36245f314..43d0e3991 100644 --- a/400_xowa/src/gplx/xowa/htmls/core/wkrs/lnkis/htmls/Xoh_lnki_consts.java +++ b/400_xowa/src/gplx/xowa/htmls/core/wkrs/lnkis/htmls/Xoh_lnki_consts.java @@ -20,31 +20,11 @@ public class Xoh_lnki_consts { public static final byte Tid_a_cls_none = 0 , Tid_a_cls_image = 1 , Tid_a_rel_none = 0 , Tid_a_rel_nofollow = 1 - , Tid_img_cls_none = 0 , Tid_img_cls_thumbimage = 2, Tid_img_cls_thumbborder = 3 ; - public static final String Str_img_cls_thumbimage = "thumbimage"; private static final byte[] Bry_anchor_class_image = Bry_.new_a7(" class=\"image\"") , Bry_anchor_rel_nofollow = Bry_.new_a7(" rel=\"nofollow\"") - , Bry_img_cls_thumbborder = Bry_.new_a7(" class=\"thumbborder\"") - , Bry_img_cls_prefix = Bry_.new_a7(" class=\"") ; - public static final byte[] Bry_img_cls_thumbimage = Bry_.new_a7(" class=\"thumbimage\""); - public static final byte[] Bry_none = Bry_.Empty; public static byte[] A_cls_to_bry(byte tid) {return tid == Tid_a_cls_none ? Bry_.Empty : Bry_anchor_class_image;} public static byte[] A_rel_to_bry(byte tid) {return tid == Tid_a_rel_none ? Bry_.Empty : Bry_anchor_rel_nofollow;} - public static byte[] Img_cls_to_bry(byte tid, byte[] other) { - boolean other_is_empty = Bry_.Len_eq_0(other); - byte[] rv = null; - switch (tid) { - case Tid_img_cls_none: return other_is_empty ? Bry_.Empty : Bry_.Add(Bry_img_cls_prefix, other, Byte_ascii.Quote_bry); - case Tid_img_cls_thumbimage: rv = Bry_img_cls_thumbimage; break; - case Tid_img_cls_thumbborder: rv = Bry_img_cls_thumbborder; break; - default: throw Err_.new_unhandled(tid); - } - if (other_is_empty) return rv; - rv = Bry_.Copy(rv); // copy for replace below - rv[rv.length - 1] = Byte_ascii.Space; // replace " with space - return Bry_.Add(rv, other, Byte_ascii.Quote_bry); // add custom cls - } } diff --git a/400_xowa/src/gplx/xowa/htmls/core/wkrs/lnkis/htmls/Xoh_lnki_consts_tst.java b/400_xowa/src/gplx/xowa/htmls/core/wkrs/lnkis/htmls/Xoh_lnki_consts_tst.java deleted file mode 100644 index b08a9ff3e..000000000 --- a/400_xowa/src/gplx/xowa/htmls/core/wkrs/lnkis/htmls/Xoh_lnki_consts_tst.java +++ /dev/null @@ -1,34 +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 . -*/ -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.*; -public class Xoh_lnki_consts_tst { - private Xoh_lnki_consts_fxt fxt = new Xoh_lnki_consts_fxt(); - @Test public void Img_cls_to_bry() { - fxt.Test_img_cls_to_bry(Xoh_lnki_consts.Tid_img_cls_none , null , ""); - fxt.Test_img_cls_to_bry(Xoh_lnki_consts.Tid_img_cls_none , "a" , " class=\"a\""); - fxt.Test_img_cls_to_bry(Xoh_lnki_consts.Tid_img_cls_thumbimage , null , " class=\"thumbimage\""); - fxt.Test_img_cls_to_bry(Xoh_lnki_consts.Tid_img_cls_thumbborder , null , " class=\"thumbborder\""); - fxt.Test_img_cls_to_bry(Xoh_lnki_consts.Tid_img_cls_thumbborder , "a" , " class=\"thumbborder a\""); - } -} -class Xoh_lnki_consts_fxt { - public void Test_img_cls_to_bry(byte tid, String other, String expd) { - Tfds.Eq(expd, String_.new_u8(Xoh_lnki_consts.Img_cls_to_bry(tid, Bry_.new_u8_safe(other)))); - } -} diff --git a/400_xowa/src/gplx/xowa/htmls/core/wkrs/lnkis/htmls/Xoh_lnki_wtr.java b/400_xowa/src/gplx/xowa/htmls/core/wkrs/lnkis/htmls/Xoh_lnki_wtr.java index 03e0eba51..9689a0229 100644 --- a/400_xowa/src/gplx/xowa/htmls/core/wkrs/lnkis/htmls/Xoh_lnki_wtr.java +++ b/400_xowa/src/gplx/xowa/htmls/core/wkrs/lnkis/htmls/Xoh_lnki_wtr.java @@ -52,7 +52,7 @@ public class Xoh_lnki_wtr { Xow_xwiki_itm xwiki_lang = lnki_ttl.Wik_itm(); if ( xwiki_lang != null // lnki is xwiki; EX: [[commons:]] [[en:]] [[wikt:]] && xwiki_lang.Domain_tid() == wiki.Xwiki_mgr().Xwiki_domain_tid() // xwiki is same type as cur wiki; EX: cur=w xwiki=w -> add to xwiki_langs; cur=w xwikid=d -> don't add to xwiki_langs; DATE:2014-09-14 - && xwiki_lang.Type_is_xwiki_lang(wiki.Domain_itm().Lang_orig_key())// NOTE: use Lang_orig_id to handle xwikis between s.w and en.w; PAGE:s.q:Anonymous DATE:2014-09-10 + && xwiki_lang.Show_in_sitelangs(wiki.Domain_itm().Lang_orig_key())// NOTE: use Lang_orig_id to handle xwikis between s.w and en.w; PAGE:s.q:Anonymous DATE:2014-09-10 && !lnki_ttl.ForceLiteralLink() // not literal; [[:en:A]] ) { Wdata_sitelink_itm slink = new Wdata_sitelink_itm(xwiki_lang.Abrv_wm(), xwiki_lang.Domain_name(), null).Page_ttl_(lnki_ttl); @@ -63,9 +63,9 @@ public class Xoh_lnki_wtr { redlinks_mgr.Lnki_add(lnki); boolean stage_is_alt = hctx.Mode_is_alt(); switch (lnki.Ns_id()) { - case Xow_ns_.Id_media: if (!stage_is_alt) file_wtr.Write_or_queue(bfr, page, ctx, hctx, src, lnki); return; // NOTE: literal ":" has no effect; PAGE:en.w:Beethoven and [[:Media:De-Ludwig_van_Beethoven.ogg|listen]] - case Xow_ns_.Id_file: if (!literal_link && !stage_is_alt) {file_wtr.Write_or_queue(bfr, page, ctx, hctx, src, lnki); return;} break; - case Xow_ns_.Id_category: if (!literal_link) {page.Html_data().Ctgs_add(lnki.Ttl()); return;} break; + case Xow_ns_.Tid__media: if (!stage_is_alt) file_wtr.Write_or_queue(bfr, page, ctx, hctx, src, lnki); return; // NOTE: literal ":" has no effect; PAGE:en.w:Beethoven and [[:Media:De-Ludwig_van_Beethoven.ogg|listen]] + case Xow_ns_.Tid__file: if (!literal_link && !stage_is_alt) {file_wtr.Write_or_queue(bfr, page, ctx, hctx, src, lnki); return;} break; + case Xow_ns_.Tid__category: if (!literal_link) {page.Html_data().Ctgs_add(lnki.Ttl()); return;} break; } Write_plain_by_tkn(bfr, hctx, src, lnki, lnki_ttl); } @@ -99,10 +99,7 @@ public class Xoh_lnki_wtr { if (hctx.Mode_is_alt()) Write_caption(bfr, ctx, hctx, src, lnki, ttl_bry, true, caption_wkr); else { - if (hctx.Mode_is_hdump()) - gplx.xowa.htmls.core.wkrs.lnkis.htmls.Xoh_lnki_wtr.Html_plain(bfr, lnki); - else - bfr.Add(Xoh_consts.A_bgn); // '' - if (lnki_ttl.Anch_bgn() != -1 && !lnki_ttl.Ns().Id_main()) { // anchor exists and not main_ns; anchor must be manually added b/c Xoa_ttl does not handle # for non main-ns + if (lnki_ttl.Anch_bgn() != -1 && !lnki_ttl.Ns().Id_is_main()) { // anchor exists and not main_ns; anchor must be manually added b/c Xoa_ttl does not handle # for non main-ns byte[] anch_txt = lnki_ttl.Anch_txt(); byte anch_spr = (anch_txt.length > 0 && anch_txt[0] == Byte_ascii.Hash) // 1st char is #; occurs when page_txt has trailing space; causes 1st letter of anch_txt to start at # instead of 1st letter @@ -169,14 +166,6 @@ public class Xoh_lnki_wtr { } return false; } - public static void Html_plain(Bry_bfr bfr, Xop_lnki_tkn lnki) { - bfr.Add_str_a7 - ( lnki.Caption_exists() // caption exists; EX: [[A|b]] - || lnki.Tail_bgn() != -1 // trailing chars; EX: [[A]]b - ? " 27,9,4 - int space_len = parser.Fwd_while(Byte_ascii.Space) - hook_bgn; + public void Encode(Bry_bfr bfr, Hzip_stat_itm stat_itm, byte[] src, int src_end, int rng_bgn, int rng_end) {// " " -> 27,9,4 + int space_len = Bry_find_.Find_fwd_while(src, rng_end, src_end, Byte_ascii.Space) - rng_bgn; stat_itm.Space_add(space_len); bfr.Add(Xoh_hzip_dict_.Bry__space); Xoh_hzip_int_.Encode(1, bfr, space_len); } - public int Decode(Bry_bfr bfr, Bry_parser parser, byte[] src, int hook_bgn) { - int space_len = parser.Read_int_by_base85(1); + public int Decode(Bry_bfr bfr, Xoh_decode_ctx ctx, Bry_rdr rdr, byte[] src, int hook_bgn) { + int space_len = rdr.Read_int_by_base85(1); bfr.Add_byte_repeat(Byte_ascii.Space, space_len); - return parser.Pos(); + return rdr.Pos(); } } diff --git a/400_xowa/src/gplx/xowa/htmls/core/wkrs/spaces/Xoh_space_hzip_tst.java b/400_xowa/src/gplx/xowa/htmls/core/wkrs/spaces/Xoh_space_hzip_tst.java index ccb782c20..9c0655eba 100644 --- a/400_xowa/src/gplx/xowa/htmls/core/wkrs/spaces/Xoh_space_hzip_tst.java +++ b/400_xowa/src/gplx/xowa/htmls/core/wkrs/spaces/Xoh_space_hzip_tst.java @@ -25,4 +25,17 @@ public class Xoh_space_hzip_tst { @Test public void Len__85() { fxt.Test__bicode("~!{\"!", String_.Repeat(" ", 85)); } + @Test public void Many() { + fxt.Test__bicode(String_.Concat_lines_nl_skip_last + ( "
" + , "~!%
a
" + , "~!%
" + , "
" + ), String_.Concat_lines_nl_skip_last + ( "
" + , "
a
" + , "
" + , "
" + )); + } } diff --git a/400_xowa/src/gplx/xowa/htmls/core/wkrs/spaces/Xoh_space_parse.java b/400_xowa/src/gplx/xowa/htmls/core/wkrs/spaces/Xoh_space_parser.java similarity index 84% rename from 400_xowa/src/gplx/xowa/htmls/core/wkrs/spaces/Xoh_space_parse.java rename to 400_xowa/src/gplx/xowa/htmls/core/wkrs/spaces/Xoh_space_parser.java index 3ba2f9243..d31fbee4b 100644 --- a/400_xowa/src/gplx/xowa/htmls/core/wkrs/spaces/Xoh_space_parse.java +++ b/400_xowa/src/gplx/xowa/htmls/core/wkrs/spaces/Xoh_space_parser.java @@ -16,12 +16,12 @@ You should have received a copy of the GNU Affero General Public License along with this program. If not, see . */ package gplx.xowa.htmls.core.wkrs.spaces; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*; import gplx.xowa.htmls.core.wkrs.*; -import gplx.langs.htmls.*; import gplx.langs.htmls.parsers.*; import gplx.xowa.htmls.core.parsers.*; +import gplx.langs.htmls.*; import gplx.langs.htmls.parsers.*; import gplx.xowa.htmls.core.hzips.*; -public class Xoh_space_parse implements Html_doc_wkr { - private final Xoh_wkr wkr; +public class Xoh_space_parser implements Html_doc_wkr { + private final Xoh_hdoc_wkr wkr; private byte[] src; private int src_end; - public Xoh_space_parse(Xoh_wkr wkr) {this.wkr = wkr;} + public Xoh_space_parser(Xoh_hdoc_wkr wkr) {this.wkr = wkr;} public byte[] Hook() {return Hook_bry;} public void Init(byte[] src, int src_bgn, int src_end) {this.src = src; this.src_end = src_end;} public int Parse(int pos) { diff --git a/400_xowa/src/gplx/xowa/htmls/core/wkrs/tags/Xoh_doc_wkr__tag.java b/400_xowa/src/gplx/xowa/htmls/core/wkrs/tags/Xoh_doc_wkr__tag.java new file mode 100644 index 000000000..83da89e1b --- /dev/null +++ b/400_xowa/src/gplx/xowa/htmls/core/wkrs/tags/Xoh_doc_wkr__tag.java @@ -0,0 +1,85 @@ +/* +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 . +*/ +package gplx.xowa.htmls.core.wkrs.tags; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*; import gplx.xowa.htmls.core.wkrs.*; +import gplx.core.btries.*; import gplx.core.primitives.*; +import gplx.langs.htmls.*; import gplx.langs.htmls.parsers.*; +import gplx.xowa.htmls.core.wkrs.lnkes.*; import gplx.xowa.htmls.core.wkrs.lnkis.*; import gplx.xowa.htmls.core.wkrs.hdrs.*; import gplx.xowa.htmls.core.wkrs.imgs.*; import gplx.xowa.htmls.core.wkrs.thms.*; +import gplx.xowa.wikis.ttls.*; +public class Xoh_doc_wkr__tag implements Html_doc_wkr { + private Xoh_hdoc_wkr hdoc_wkr; private Xow_ttl_parser ttl_parser; + private final Html_tag_rdr tag_rdr = new Html_tag_rdr(); private byte[] src; private int src_end; + private final Xoh_lnki_parser wkr__lnki = new Xoh_lnki_parser(); + private final Xoh_lnke_parser wkr__lnke = new Xoh_lnke_parser(); + private final Xoh_hdr_parser wkr__hdr = new Xoh_hdr_parser(); + private final Xoh_thm_parse wkr__img_thm = new Xoh_thm_parse(); + private final Xoh_img_parser wkr__img_box = new Xoh_img_parser(); + public byte[] Hook() {return Byte_ascii.Angle_bgn_bry;} + public Xoh_doc_wkr__tag Ctor(Xoh_hdoc_wkr hdoc_wkr, Xow_ttl_parser ttl_parser) { + this.hdoc_wkr = hdoc_wkr; this.ttl_parser = ttl_parser; + return this; + } + public void Init(byte[] src, int src_bgn, int src_end) { + this.src = src; this.src_end = src_end; + tag_rdr.Init(src, src_bgn, src_end); + } + public int Parse(int pos) { + tag_rdr.Pos_(pos); + int nxt_pos = tag_rdr.Pos() + 1; if (nxt_pos == src_end) return src_end; + Html_tag cur = src[tag_rdr.Pos() + 1] == Byte_ascii.Slash ? tag_rdr.Tag__move_fwd_tail(Html_tag_.Id__any) : tag_rdr.Tag__move_fwd_head(); + Html_tag nxt = null; + if (cur.Tag_is_tail()) { + hdoc_wkr.On_txt(pos, cur.Src_end()); + } + else { + int cur_name_id = cur.Name_id(); + switch (cur_name_id) { + case Html_tag_.Id__h2: + case Html_tag_.Id__h3: + case Html_tag_.Id__h4: + case Html_tag_.Id__h5: + case Html_tag_.Id__h6: + int hdr_tag_bgn = cur.Src_bgn(); + nxt = tag_rdr.Tag__peek_fwd_head(); + if ( nxt.Name_id() == Html_tag_.Id__span + && nxt.Atrs__match_pair(Html_atr_.Bry__class , Atr__class__mw_headline)) { + return wkr__hdr.Parse(hdoc_wkr, tag_rdr, src, cur_name_id, hdr_tag_bgn, nxt); + } + break; + case Html_tag_.Id__a: + nxt = tag_rdr.Tag__peek_fwd_head(); + if (nxt.Name_id() == Html_tag_.Id__img) + return wkr__img_box.Parse(hdoc_wkr, src, tag_rdr, cur); + else if (cur.Atrs__match_pair(Html_atr_.Bry__rel , Atr__rel__nofollow)) + return wkr__lnke.Parse(hdoc_wkr, tag_rdr, cur); + else + return wkr__lnki.Parse(hdoc_wkr, tag_rdr, src, cur, ttl_parser); + case Html_tag_.Id__div: + if (cur.Atrs__cls_has(Atr__class__thumb)) + return wkr__img_thm.Parse(hdoc_wkr, tag_rdr, src, cur); + break; + } + hdoc_wkr.On_txt(pos, cur.Src_end()); + } + return cur.Src_end(); + } + private static final byte[] + Atr__class__mw_headline = Bry_.new_a7("mw-headline") + , Atr__class__thumb = Bry_.new_a7("thumb") + , Atr__rel__nofollow = Bry_.new_a7("nofollow") + ; +} diff --git a/400_xowa/src/gplx/xowa/htmls/core/wkrs/thms/Xoh_thm_html_tst.java b/400_xowa/src/gplx/xowa/htmls/core/wkrs/thms/Xoh_thm_html_tst.java new file mode 100644 index 000000000..3501e2f0e --- /dev/null +++ b/400_xowa/src/gplx/xowa/htmls/core/wkrs/thms/Xoh_thm_html_tst.java @@ -0,0 +1,35 @@ +/* +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 . +*/ +package gplx.xowa.htmls.core.wkrs.thms; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*; import gplx.xowa.htmls.core.wkrs.*; +import org.junit.*; import gplx.xowa.htmls.core.makes.tests.*; +public class Xoh_thm_html_tst { + private final Xoh_make_fxt fxt = new Xoh_make_fxt(); + @Test public void Thumb__basic() { + // fxt.Expd_itms_xfers(fxt.Make_xfer("A.png", 0, 0, 0, Bool_.Y, Xof_ext_.Id_png)); + fxt.Test__html("[[File:A.png|thumb|test_caption]]", String_.Concat_lines_nl_skip_last + ( "
" + , "
" + , " " + , "
" + , " test_caption" + , "
" + , "
" + , "
" + )); + } +} diff --git a/400_xowa/src/gplx/xowa/htmls/core/wkrs/thms/Xoh_thm_hzip.java b/400_xowa/src/gplx/xowa/htmls/core/wkrs/thms/Xoh_thm_hzip.java new file mode 100644 index 000000000..4109b0af1 --- /dev/null +++ b/400_xowa/src/gplx/xowa/htmls/core/wkrs/thms/Xoh_thm_hzip.java @@ -0,0 +1,95 @@ +/* +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 . +*/ +package gplx.xowa.htmls.core.wkrs.thms; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*; import gplx.xowa.htmls.core.wkrs.*; +import gplx.core.primitives.*; import gplx.core.brys.*; import gplx.core.btries.*; import gplx.core.encoders.*; +import gplx.xowa.htmls.core.hzips.*; import gplx.xowa.htmls.core.hzips.stats.*; +import gplx.langs.htmls.*; import gplx.xowa.htmls.hrefs.*; import gplx.xowa.wikis.ttls.*; import gplx.xowa.htmls.core.wkrs.lnkis.*; +import gplx.xowa.wikis.nss.*; import gplx.xowa.parsers.lnkis.*; +public class Xoh_thm_hzip implements Xoh_hzip_wkr { + private Xow_ttl_parser ttl_parser; private int uid; + public void Ttl_parser_(Xow_ttl_parser ttl_parser) {this.ttl_parser = ttl_parser; this.uid = 1;} // NOTE: should be 0, but for historical reasons, 1st lnki starts at 2; EX: id='xowa_lnki_2' + public String Key() {return Xoh_hzip_dict_.Key__lnki;} + public void Encode(Bry_bfr bfr, Hzip_stat_itm stat_itm, byte[] src, int rng_bgn, int rng_end) { + bfr.Add_mid(src, rng_bgn, rng_end); + } + public int Decode(Bry_bfr bfr, Xoh_decode_ctx ctx, Bry_rdr rdr, byte[] src, int hook_bgn) { + byte lnki_type = rdr.Read_byte(); + int ns_id = rdr.Read_int_by_base85(1); + int site_bgn = -1, site_end = -1; + if (rdr.Is(Xoh_hzip_dict_.Escape)) { + site_bgn = rdr.Pos(); + site_end = rdr.Find_fwd_lr(Xoh_hzip_dict_.Escape); + } + boolean site_exists = site_end - site_bgn > 0; + int page_bgn = rdr.Pos(); + int page_end = rdr.Find_fwd_lr(Xoh_hzip_dict_.Escape); + int capt_bgn = -1, capt_end = -1; + if (lnki_type != Xoh_lnki_dict_.Type__same) { + capt_bgn = rdr.Pos(); + capt_end = rdr.Find_fwd_lr(Xoh_hzip_dict_.Escape); + } + + byte[] page_bry = Bry_.Mid(src, page_bgn, page_end); + Xoa_ttl ttl = ttl_parser.Ttl_parse(ns_id, page_bry); if (ttl == null) rdr.Fail("invalid ttl", "mid", String_.new_u8(page_bry)); // TODO: parse title based on site + byte[] ttl__full_db = ttl.Full_db(); + + // gen html + bfr.Add(Html_bldr_.Bry__a_lhs_w_href); + if (site_exists) bfr.Add_str_a7("/site/").Add_mid(src, site_bgn, site_end); + bfr.Add(Xoh_href_.Bry__wiki); // "/wiki/" + bfr.Add(ttl.Full_db()); + bfr.Add_str_a7("\" id=\"").Add_str_a7(gplx.xowa.parsers.lnkis.redlinks.Xopg_redlink_lnki_list.Lnki_id_prefix).Add_int_variable(++uid); + bfr.Add_str_a7("\" title=\""); + byte[] title_bry = site_exists ? ttl.Page_db() : ttl__full_db; // for xwiki, use page, not full alias; EX: "wikt:A" -> "A" x> "wikt:A" + bfr.Add(Html_utl.Escape_html_as_bry(title_bry)).Add_str_a7("\">"); + switch (lnki_type) { + case Xoh_lnki_dict_.Type__same: + if (ttl.Ns().Id_is_main()) + bfr.Add_mid(src, page_bgn, page_end); + else + bfr.Add(ttl.Full_txt()); + break; + case Xoh_lnki_dict_.Type__diff: + bfr.Add_mid(src, capt_bgn, capt_end); + break; + case Xoh_lnki_dict_.Type__trail: + bfr.Add_mid(src, page_bgn, page_end); + bfr.Add_mid(src, capt_bgn, capt_end); + break; + } + bfr.Add_str_a7(""); + return rdr.Pos(); + } +// , Find_img_xatrs = Bry_.new_a7("xatrs='") +// private static int[] Save_img_full_pow = new int[] {0, 1, 2}; +// private int Save_img_full(Bry_bfr bfr, Bry_rdr_old rdr, Hzip_stat_itm stat_itm, byte[] src, int src_len, int bgn, int pos) { +// bfr.Add(Xoh_hzip_dict_.Bry__img_full); +// int xatrs_bgn = Bry_find_.Move_fwd(src, Find_img_xatrs, pos, src_len); if (xatrs_bgn == Bry_find_.Not_found) return rdr.Warn("a.img_xatrs_missing", bgn, pos); +// bry_rdr.Init(src, xatrs_bgn); +// int a_cls = bry_rdr.Read_int_to_pipe(); +// int a_rel = bry_rdr.Read_int_to_pipe(); +// int img_rel = bry_rdr.Read_int_to_pipe(); +// byte meta = (byte)Bit_.Shift_lhs_to_int(Save_img_full_pow, a_cls, a_rel, img_rel); +// bfr.Add_byte(meta); // meta +// Xoh_hzip_int_.Encode(bfr, bry_rdr.Read_int_to_pipe()); // uid +// bfr.Add(bry_rdr.Read_bry_to_pipe()).Add_byte_pipe(); // img_cls_other +// bfr.Add(bry_rdr.Read_bry_to_apos()); // alt +// bfr.Add_byte(Xoh_hzip_dict_.Escape); +// return bry_rdr.Pos() + 2; // +2=/> +// } +} diff --git a/400_xowa/src/gplx/xowa/htmls/core/wkrs/thms/Xoh_thm_hzip_tst.java b/400_xowa/src/gplx/xowa/htmls/core/wkrs/thms/Xoh_thm_hzip_tst.java new file mode 100644 index 000000000..01d39fcca --- /dev/null +++ b/400_xowa/src/gplx/xowa/htmls/core/wkrs/thms/Xoh_thm_hzip_tst.java @@ -0,0 +1,86 @@ +/* +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 . +*/ +package gplx.xowa.htmls.core.wkrs.thms; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*; import gplx.xowa.htmls.core.wkrs.*; +import org.junit.*; import gplx.xowa.htmls.core.hzips.tests.*; +public class Xoh_thm_hzip_tst { + private final Xoh_hzip_fxt fxt = new Xoh_hzip_fxt(); + @Test public void Page__basic() { + try { + Io_url html_dir = Io_url_.new_dir_("J:\\xowa\\dev\\html\\"); + Bry_bfr bfr = Bry_bfr.new_(); + fxt.Hzip_mgr().Encode(bfr, fxt.Parser_fxt().Wiki(), Bry_.Empty, Io_mgr.Instance.LoadFilBry(html_dir.GenSubFil("temp_earth_mw.html")), new gplx.xowa.htmls.core.hzips.stats.Hzip_stat_itm()); + Io_mgr.Instance.SaveFilBry(html_dir.GenSubFil("temp_earth_mw_hzip.html"), bfr.To_bry_and_clear()); + } catch (Exception e) { + Tfds.Write(e); + } +// fxt.Test__encode("" +// , String_.Concat_lines_nl_skip_last +// ( "
" +// , "
" +// , " " +// , " " +// , " " +// , "
" +// , "
" +// , " " +// , " " +// , " " +// , "
b" +// , "
" +// , "
" +// , "
" +// )); + } +} +/* +
+
+ + + +
+
+ + + +
Artist's impression of the early Solar System's planetary disk +
+
+
+ +
+
+ + + +
+
+ + + +
Artist's impression of the early Solar System's planetary disk +
+
+
+*/ diff --git a/400_xowa/src/gplx/xowa/htmls/core/wkrs/thms/Xoh_thm_parse.java b/400_xowa/src/gplx/xowa/htmls/core/wkrs/thms/Xoh_thm_parse.java new file mode 100644 index 000000000..4f28f0042 --- /dev/null +++ b/400_xowa/src/gplx/xowa/htmls/core/wkrs/thms/Xoh_thm_parse.java @@ -0,0 +1,74 @@ +/* +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 . +*/ +package gplx.xowa.htmls.core.wkrs.thms; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*; import gplx.xowa.htmls.core.wkrs.*; +import gplx.core.brys.*; +import gplx.xowa.htmls.core.wkrs.lnkis.anchs.*; +import gplx.langs.htmls.*; import gplx.langs.htmls.parsers.*; import gplx.langs.htmls.parsers.styles.*; +import gplx.xowa.parsers.lnkis.*; +import gplx.xowa.htmls.core.wkrs.imgs.*; +public class Xoh_thm_parse { +/* +
+
+ + + +
+
+ + + +
Artist's impression of the early Solar System's planetary disk +
+
+
+*/ + private final Xoh_anch_href_parser href_parser = new Xoh_anch_href_parser(); + private final Xoh_img_parser img_parser = new Xoh_img_parser(); + private final Bry_rdr rdr = new Bry_rdr(); + public int Parse(Xoh_hdoc_wkr hdoc_wkr, Html_tag_rdr tag_rdr, byte[] src, Html_tag div_0) { + int rng_bgn = div_0.Src_bgn(), rng_end = div_0.Src_end(); + byte thm_align = div_0.Atrs__cls_find_1st(Xop_lnki_align_h.Hash); + Html_tag div_1 = tag_rdr.Tag__move_fwd_head(Bry__cls__thumbinner); + int div_width = div_1.Atrs__style_get_as_int(Html_atr_style_.Bry__width); + Html_tag anch = tag_rdr.Tag__move_fwd_head(Xoh_img_parser.Bry__cls__anch__image); + Html_atr href = anch.Atrs__get_by(Html_atr_.Bry__href); + rdr.Ctor_by_page(Bry_.Empty, src, src.length); + href_parser.Parse(rdr, hdoc_wkr.Ctx().Wiki(), href.Val_bgn(), href.Val_end()); + img_parser.Parse(hdoc_wkr, src, tag_rdr, anch); + tag_rdr.Tag__move_fwd_head(Bry__cls__thumbcaption); + tag_rdr.Tag__move_fwd_head(Bry__cls__magnify); + Html_tag div_3_tail = tag_rdr.Tag__move_fwd_tail(Html_tag_.Id__div); + int capt_bgn = div_3_tail.Src_end(); + Html_tag div_4_tail = tag_rdr.Tag__move_fwd_tail(Html_tag_.Id__div); + int capt_end = div_4_tail.Src_bgn(); + tag_rdr.Tag__move_fwd_tail(Html_tag_.Id__div); + Html_tag div_0_tail = tag_rdr.Tag__move_fwd_tail(Html_tag_.Id__div); + rng_end = div_0_tail.Src_end(); + Tfds.Write(thm_align, div_width, Bry_.Mid(src, href_parser.Page_bgn(), href_parser.Page_end()), img_parser.Img_w(), img_parser.Img_h(), Bry_.Mid_w_trim(src, capt_bgn, capt_end), rng_end); + hdoc_wkr.On_img_thm(rng_bgn, rng_end); + return rng_end; + } + private static final byte[] + Bry__cls__thumbinner = Bry_.new_a7("thumbinner") + , Bry__cls__thumbcaption = Bry_.new_a7("thumbcaption") + , Bry__cls__magnify = Bry_.new_a7("magnify") + ; +} diff --git a/400_xowa/src/gplx/xowa/htmls/core/wkrs/txts/Xoh_txt_parse.java b/400_xowa/src/gplx/xowa/htmls/core/wkrs/txts/Xoh_txt_parser.java similarity index 82% rename from 400_xowa/src/gplx/xowa/htmls/core/wkrs/txts/Xoh_txt_parse.java rename to 400_xowa/src/gplx/xowa/htmls/core/wkrs/txts/Xoh_txt_parser.java index 5084b7d0e..f18c59824 100644 --- a/400_xowa/src/gplx/xowa/htmls/core/wkrs/txts/Xoh_txt_parse.java +++ b/400_xowa/src/gplx/xowa/htmls/core/wkrs/txts/Xoh_txt_parser.java @@ -16,10 +16,10 @@ You should have received a copy of the GNU Affero General Public License along with this program. If not, see . */ package gplx.xowa.htmls.core.wkrs.txts; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*; import gplx.xowa.htmls.core.wkrs.*; -import gplx.langs.htmls.parsers.*; import gplx.xowa.htmls.core.parsers.*; -public class Xoh_txt_parse implements Html_txt_wkr { - private final Xoh_wkr wkr; - public Xoh_txt_parse(Xoh_wkr wkr) {this.wkr = wkr;} +import gplx.langs.htmls.parsers.*; +public class Xoh_txt_parser implements Html_txt_wkr { + private final Xoh_hdoc_wkr wkr; + public Xoh_txt_parser(Xoh_hdoc_wkr wkr) {this.wkr = wkr;} public void Init(byte[] src, int src_bgn, int src_end) {} public void Parse(int rng_bgn, int rng_end) { wkr.On_txt(rng_bgn, rng_end); diff --git a/400_xowa/src/gplx/xowa/htmls/doms/Xoh_dom_.java b/400_xowa/src/gplx/xowa/htmls/doms/Xoh_dom_.java index 4657b08ee..b1e34bbb9 100644 --- a/400_xowa/src/gplx/xowa/htmls/doms/Xoh_dom_.java +++ b/400_xowa/src/gplx/xowa/htmls/doms/Xoh_dom_.java @@ -65,7 +65,7 @@ public class Xoh_dom_ { return true; } public static String Title_by_href(byte[] href, byte[] html_src) { - byte[] xowa_title = Xoh_dom_.Query_val_by_where(dom_find, html_src, Html_tag_.A_name_bry, Html_atr_.Bry__href, href, gplx.xowa.htmls.Xoh_consts.Atr_xowa_title_bry, 0); + byte[] xowa_title = Xoh_dom_.Query_val_by_where(dom_find, html_src, Html_tag_.Bry__a, Html_atr_.Bry__href, href, gplx.xowa.htmls.Xoh_consts.Atr_xowa_title_bry, 0); return String_.new_u8(xowa_title); } private static final Xoh_find dom_find = new Xoh_find(); } diff --git a/400_xowa/src/gplx/xowa/htmls/heads/Xoh_head_itm_.java b/400_xowa/src/gplx/xowa/htmls/heads/Xoh_head_itm_.java index 744c867d0..02f3fac0f 100644 --- a/400_xowa/src/gplx/xowa/htmls/heads/Xoh_head_itm_.java +++ b/400_xowa/src/gplx/xowa/htmls/heads/Xoh_head_itm_.java @@ -21,6 +21,7 @@ public class Xoh_head_itm_ { Key__collapsible = Bry_.new_a7("collapsible") , Key__css = Bry_.new_a7("css") , Key__gallery = Bry_.new_a7("gallery") + , Key__gallery_styles = Bry_.new_a7("gallery_styles") , Key__globals = Bry_.new_a7("globals") , Key__graph = Bry_.new_a7("graph") , Key__hiero = Bry_.new_a7("hiero") diff --git a/400_xowa/src/gplx/xowa/htmls/core/parsers/Xoh_parser_.java b/400_xowa/src/gplx/xowa/htmls/heads/Xoh_head_itm__gallery_styles.java similarity index 51% rename from 400_xowa/src/gplx/xowa/htmls/core/parsers/Xoh_parser_.java rename to 400_xowa/src/gplx/xowa/htmls/heads/Xoh_head_itm__gallery_styles.java index c6cf394f4..2fd7b3247 100644 --- a/400_xowa/src/gplx/xowa/htmls/core/parsers/Xoh_parser_.java +++ b/400_xowa/src/gplx/xowa/htmls/heads/Xoh_head_itm__gallery_styles.java @@ -15,16 +15,14 @@ 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 . */ -package gplx.xowa.htmls.core.parsers; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*; -import gplx.langs.htmls.parsers.*; import gplx.xowa.htmls.core.wkrs.txts.*; import gplx.xowa.htmls.core.wkrs.escapes.*; import gplx.xowa.htmls.core.wkrs.spaces.*; -public class Xoh_parser_ { - public static Html_doc_parser new_(Xoh_wkr wkr, Xow_wiki wiki) { - Html_doc_parser rv = new Html_doc_parser(); - rv.Reg_txt(new Xoh_txt_parse(wkr)).Reg - ( new Xoh_doc_wkr__tag(wkr, wiki) - , new Xoh_escape_parse(wkr) - , new Xoh_space_parse(wkr) - ); - return rv; +package gplx.xowa.htmls.heads; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; +import gplx.xowa.guis.*; +public class Xoh_head_itm__gallery_styles extends Xoh_head_itm__base { + @Override public byte[] Key() {return Xoh_head_itm_.Key__gallery_styles;} + @Override public int Flags() {return Flag__css_include;} + @Override public void Write_css_include(Xoae_app app, Xowe_wiki wiki, Xoae_page page, Xoh_head_wtr wtr) { + if (Url_css == null) Url_css = app.Fsys_mgr().Bin_any_dir().GenSubFil_nest("xowa", "html", "res", "src", "mediawiki.page", "mediawiki.page.gallery.css").To_http_file_bry(); + wtr.Write_css_include(Url_css); } + private static byte[] Url_css; } diff --git a/400_xowa/src/gplx/xowa/htmls/heads/Xoh_head_mgr.java b/400_xowa/src/gplx/xowa/htmls/heads/Xoh_head_mgr.java index 7c5f5c27c..fc7510af9 100644 --- a/400_xowa/src/gplx/xowa/htmls/heads/Xoh_head_mgr.java +++ b/400_xowa/src/gplx/xowa/htmls/heads/Xoh_head_mgr.java @@ -30,7 +30,7 @@ public class Xoh_head_mgr implements Bry_fmtr_arg { , list__js_window_onload = new Xoh_head_wkr() ; public Xoh_head_mgr() { - Itms_add(itm__css, itm__globals, itm__server, itm__popups, itm__toc, itm__collapsible, itm__navframe, itm__gallery + Itms_add(itm__css, itm__globals, itm__server, itm__popups, itm__toc, itm__collapsible, itm__navframe, itm__gallery, itm__gallery_styles , itm__mathjax, itm__graph, itm__hiero, itm__top_icon, itm__title_rewrite, itm__search_suggest, itm__timeline , itm__dbui ); @@ -44,6 +44,7 @@ public class Xoh_head_mgr implements Bry_fmtr_arg { public Xoh_head_itm__navframe Itm__navframe() {return itm__navframe;} private final Xoh_head_itm__navframe itm__navframe = new Xoh_head_itm__navframe(); public Xoh_head_itm__top_icon Itm__top_icon() {return itm__top_icon;} private final Xoh_head_itm__top_icon itm__top_icon = new Xoh_head_itm__top_icon(); public Xoh_head_itm__gallery Itm__gallery() {return itm__gallery;} private final Xoh_head_itm__gallery itm__gallery = new Xoh_head_itm__gallery(); + public Xoh_head_itm__gallery_styles Itm__gallery_styles() {return itm__gallery_styles;} private final Xoh_head_itm__gallery_styles itm__gallery_styles = new Xoh_head_itm__gallery_styles(); public Xoh_head_itm__title_rewrite Itm__title_rewrite() {return itm__title_rewrite;} private final Xoh_head_itm__title_rewrite itm__title_rewrite = new Xoh_head_itm__title_rewrite(); public Xoh_head_itm__mathjax Itm__mathjax() {return itm__mathjax;} private final Xoh_head_itm__mathjax itm__mathjax = new Xoh_head_itm__mathjax(); public Xoh_head_itm__hiero Itm__hiero() {return itm__hiero;} private final Xoh_head_itm__hiero itm__hiero = new Xoh_head_itm__hiero(); diff --git a/400_xowa/src/gplx/xowa/htmls/modules/popups/Xow_popup_mgr.java b/400_xowa/src/gplx/xowa/htmls/modules/popups/Xow_popup_mgr.java index 05cf08949..73f3e5842 100644 --- a/400_xowa/src/gplx/xowa/htmls/modules/popups/Xow_popup_mgr.java +++ b/400_xowa/src/gplx/xowa/htmls/modules/popups/Xow_popup_mgr.java @@ -124,10 +124,10 @@ public class Xow_popup_mgr implements GfoInvkAble, GfoEvObj { popup_wiki.Init_assert(); Xoa_ttl popup_ttl = Xoa_ttl.parse(popup_wiki, tmp_url.To_bry_page_w_anch()); switch (popup_ttl.Ns().Id()) { - case Xow_ns_.Id_media: - case Xow_ns_.Id_file: + case Xow_ns_.Tid__media: + case Xow_ns_.Tid__file: return Bry_.Empty; // do not popup for media or file - case Xow_ns_.Id_special: + case Xow_ns_.Tid__special: if (!Xows_special_meta_.Itm__popup_history.Match_ttl(popup_ttl)) return Bry_.Empty; // do not popup for special, unless popupHistory; DATE:2015-04-20 break; } @@ -197,7 +197,7 @@ public class Xow_popup_mgr implements GfoInvkAble, GfoEvObj { for (int i = 0; i < ary_len; i++) { byte[] bry = ary[i]; int bry_len = bry.length; if (bry_len == 0) continue; // ignore empty entries; EX: "0|" - Xow_ns ns = Bry_.Eq(bry, Xow_ns_.Ns_name_main_bry) + Xow_ns ns = Bry_.Eq(bry, Xow_ns_.Bry__main) ? ns_mgr.Ns_main() : ns_mgr.Names_get_or_null(bry) ; @@ -279,10 +279,10 @@ class Load_popup_wkr implements Gfo_thread_wkr { popup_wiki.Init_assert(); Xoa_ttl popup_ttl = Xoa_ttl.parse(popup_wiki, tmp_url.To_bry_page_w_anch()); switch (popup_ttl.Ns().Id()) { - case Xow_ns_.Id_media: - case Xow_ns_.Id_file: + case Xow_ns_.Tid__media: + case Xow_ns_.Tid__file: return; // do not popup for media or file - case Xow_ns_.Id_special: + case Xow_ns_.Tid__special: if (!Xows_special_meta_.Itm__popup_history.Match_ttl(popup_ttl)) return; // do not popup for special, unless popupHistory; DATE:2015-04-20 break; } diff --git a/400_xowa/src/gplx/xowa/htmls/modules/popups/Xow_popup_parser_tst.java b/400_xowa/src/gplx/xowa/htmls/modules/popups/Xow_popup_parser_tst.java index 625f5e2c9..51d75a959 100644 --- a/400_xowa/src/gplx/xowa/htmls/modules/popups/Xow_popup_parser_tst.java +++ b/400_xowa/src/gplx/xowa/htmls/modules/popups/Xow_popup_parser_tst.java @@ -331,10 +331,10 @@ public class Xow_popup_parser_tst { )); } @Test public void Ns_allowed() { - fxt.Test_ns_allowed("Help" , Xow_ns_.Id_help); - fxt.Test_ns_allowed("(Main)" , Xow_ns_.Id_main); + fxt.Test_ns_allowed("Help" , Xow_ns_.Tid__help); + fxt.Test_ns_allowed("(Main)" , Xow_ns_.Tid__main); fxt.Test_ns_allowed("" ); - fxt.Test_ns_allowed("(Main)|Help" , Xow_ns_.Id_main, Xow_ns_.Id_help); + fxt.Test_ns_allowed("(Main)|Help" , Xow_ns_.Tid__main, Xow_ns_.Tid__help); } @Test public void Read_til_stop_fwd() { fxt.Init_word_needed_(2).Init_read_til_stop_fwd_(2) // read fwd found hdr diff --git a/400_xowa/src/gplx/xowa/htmls/modules/popups/Xow_popup_wrdx_mkr.java b/400_xowa/src/gplx/xowa/htmls/modules/popups/Xow_popup_wrdx_mkr.java index 54854b7ac..d3ac33cbb 100644 --- a/400_xowa/src/gplx/xowa/htmls/modules/popups/Xow_popup_wrdx_mkr.java +++ b/400_xowa/src/gplx/xowa/htmls/modules/popups/Xow_popup_wrdx_mkr.java @@ -95,8 +95,8 @@ public class Xow_popup_wrdx_mkr { case Xop_tkn_itm_.Tid_lnki: Xop_lnki_tkn lnki = (Xop_lnki_tkn)tkn; switch (lnki.Ns_id()) { - case Xow_ns_.Id_category: // skip [[Category:]] - case Xow_ns_.Id_file: // skip [[File:]] + case Xow_ns_.Tid__category: // skip [[Category:]] + case Xow_ns_.Tid__file: // skip [[File:]] add_tkn = add_subs = false; break; default: diff --git a/400_xowa/src/gplx/xowa/htmls/portal/Xoh_page_body_cls.java b/400_xowa/src/gplx/xowa/htmls/portal/Xoh_page_body_cls.java index e2fbece35..eaf486929 100644 --- a/400_xowa/src/gplx/xowa/htmls/portal/Xoh_page_body_cls.java +++ b/400_xowa/src/gplx/xowa/htmls/portal/Xoh_page_body_cls.java @@ -25,7 +25,7 @@ public class Xoh_page_body_cls { // REF.MW:Skin.php|getPageClasses tmp_bfr.Add_byte_space().Add(Bry_page_prefix).Add(Escape_cls(ttl.Full_db())); // page-Page_title if (page_tid == Xow_page_tid.Tid_json) { switch (ttl.Ns().Id()) { - case Xow_ns_.Id_main: + case Xow_ns_.Tid__main: tmp_bfr.Add_byte_space().Add(Bry_wb_entitypage); tmp_bfr.Add_byte_space().Add(Bry_wb_itempage); tmp_bfr.Add_byte_space().Add(Bry_wb_itempage).Add_byte(Byte_ascii.Dash).Add(ttl.Page_db()); @@ -44,10 +44,10 @@ public class Xoh_page_body_cls { // REF.MW:Skin.php|getPageClasses } private static void Add_type(Bry_bfr tmp_bfr, Xoa_ttl ttl) { tmp_bfr.Add_byte_space(); - if (ttl.Ns().Id_special()) { + if (ttl.Ns().Id_is_special()) { tmp_bfr.Add(Bry_type_special); // MW_TODO: add " mw-special-$canonicalName" } - else if (ttl.Ns().Id_talk()) + else if (ttl.Ns().Id_is_talk()) tmp_bfr.Add(Bry_type_talk); else tmp_bfr.Add(Bry_type_subject); diff --git a/400_xowa/src/gplx/xowa/htmls/portal/Xoh_subpages_bldr_tst.java b/400_xowa/src/gplx/xowa/htmls/portal/Xoh_subpages_bldr_tst.java index bb693e303..84eb62b81 100644 --- a/400_xowa/src/gplx/xowa/htmls/portal/Xoh_subpages_bldr_tst.java +++ b/400_xowa/src/gplx/xowa/htmls/portal/Xoh_subpages_bldr_tst.java @@ -40,7 +40,7 @@ class Xoh_subpages_bldr_fxt { public void Init() { this.app = Xoa_app_fxt.app_(); this.wiki = Xoa_app_fxt.wiki_tst_(app); - wiki.Ns_mgr().Ids_get_or_null(Xow_ns_.Id_help).Subpages_enabled_(true); + wiki.Ns_mgr().Ids_get_or_null(Xow_ns_.Tid__help).Subpages_enabled_(true); } public void Test_bld(String ttl_str, String expd) { byte[] actl = subpages_bldr.Bld(wiki.Ns_mgr(), Xoa_ttl.parse(wiki, Bry_.new_u8(ttl_str))); diff --git a/400_xowa/src/gplx/xowa/htmls/portal/Xow_portal_mgr.java b/400_xowa/src/gplx/xowa/htmls/portal/Xow_portal_mgr.java index eb64690fe..4a0ae9c28 100644 --- a/400_xowa/src/gplx/xowa/htmls/portal/Xow_portal_mgr.java +++ b/400_xowa/src/gplx/xowa/htmls/portal/Xow_portal_mgr.java @@ -50,7 +50,7 @@ public class Xow_portal_mgr implements GfoInvkAble { Init_fmtr(tmp_bfr, eval_mgr, div_view_fmtr); Init_fmtr(tmp_bfr, eval_mgr, div_ns_fmtr); byte[] wiki_user_name = wiki.User().Name(); - div_personal_bry = Init_fmtr(tmp_bfr, eval_mgr, div_personal_fmtr, Bry_.Add(Xoh_href_.Bry__wiki, wiki.Ns_mgr().Ids_get_or_null(Xow_ns_.Id_user).Name_db_w_colon(), wiki_user_name), wiki_user_name, Ns_cls_by_id(wiki.Ns_mgr(), Xow_ns_.Id_user), Bry_.Add(Xoh_href_.Bry__wiki, wiki.Ns_mgr().Ids_get_or_null(Xow_ns_.Id_user_talk).Name_db_w_colon(), wiki_user_name), Ns_cls_by_id(wiki.Ns_mgr(), Xow_ns_.Id_user_talk)); + div_personal_bry = Init_fmtr(tmp_bfr, eval_mgr, div_personal_fmtr, Bry_.Add(Xoh_href_.Bry__wiki, wiki.Ns_mgr().Ids_get_or_null(Xow_ns_.Tid__user).Name_db_w_colon(), wiki_user_name), wiki_user_name, Ns_cls_by_id(wiki.Ns_mgr(), Xow_ns_.Tid__user), Bry_.Add(Xoh_href_.Bry__wiki, wiki.Ns_mgr().Ids_get_or_null(Xow_ns_.Tid__user_talk).Name_db_w_colon(), wiki_user_name), Ns_cls_by_id(wiki.Ns_mgr(), Xow_ns_.Tid__user_talk)); byte[] main_page_href_bry = tmp_bfr.Add(Xoh_href_.Bry__site).Add(wiki.Domain_bry()).Add(Xoh_href_.Bry__wiki).To_bry_and_clear(); // NOTE: build /site/en.wikipedia.org/wiki/ href; no Main_Page, as that will be inserted by Xoh_href_parser div_logo_bry = Init_fmtr(tmp_bfr, eval_mgr, div_logo_fmtr, main_page_href_bry, Xoa_app_.Utl__encoder_mgr().Fsys().Encode_http(wiki.Appe().Usere().Fsys_mgr().Wiki_root_dir().GenSubFil_nest(wiki.Domain_str(), "html", "logo.png"))); div_home_bry = Init_fmtr(tmp_bfr, eval_mgr, div_home_fmtr); @@ -69,7 +69,7 @@ public class Xow_portal_mgr implements GfoInvkAble { public byte[] Div_ns_bry(Bry_bfr_mkr bfr_mkr, Xoa_ttl ttl, Xow_ns_mgr ns_mgr) { Xow_ns ns = ttl.Ns(); byte[] subj_cls = Ns_cls_by_ord(ns_mgr, ns.Ord_subj_id()), talk_cls = Ns_cls_by_ord(ns_mgr, ns.Ord_talk_id()); - if (ns.Id_talk()) + if (ns.Id_is_talk()) talk_cls = Xow_portal_mgr.Cls_selected_y; else subj_cls = Xow_portal_mgr.Cls_selected_y; diff --git a/400_xowa/src/gplx/xowa/htmls/sections/Xoh_section_mgr.java b/400_xowa/src/gplx/xowa/htmls/sections/Xoh_section_mgr.java index b67da255a..3b62e4ec1 100644 --- a/400_xowa/src/gplx/xowa/htmls/sections/Xoh_section_mgr.java +++ b/400_xowa/src/gplx/xowa/htmls/sections/Xoh_section_mgr.java @@ -18,6 +18,7 @@ along with this program. If not, see . package gplx.xowa.htmls.sections; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; public class Xoh_section_mgr { private final List_adp list = List_adp_.new_(); + public void Clear() {list.Clear();} public int Len() {return list.Count();} public Xoh_section_itm Get_at(int i) {return (Xoh_section_itm)list.Get_at(i);} public Xoh_section_itm Add(int uid, int level, byte[] anchor, byte[] display) { diff --git a/400_xowa/src/gplx/xowa/htmls/tocs/Xow_hdr_mgr.java b/400_xowa/src/gplx/xowa/htmls/tocs/Xow_hdr_mgr.java index a98ada73c..64eca4b52 100644 --- a/400_xowa/src/gplx/xowa/htmls/tocs/Xow_hdr_mgr.java +++ b/400_xowa/src/gplx/xowa/htmls/tocs/Xow_hdr_mgr.java @@ -108,7 +108,7 @@ public class Xow_hdr_mgr { break; case Xop_tkn_itm_.Tid_lnki: Xop_lnki_tkn lnki = (Xop_lnki_tkn)sub; - if (lnki.Ns_id() == Xow_ns_.Id_category) {} // Category text should not print; DATE:2013-12-09 + if (lnki.Ns_id() == Xow_ns_.Tid__category) {} // Category text should not print; DATE:2013-12-09 else { if (lnki.Caption_exists()) Id_bld_recurse(raw_bfr, src, lnki.Caption_val_tkn()); diff --git a/400_xowa/src/gplx/xowa/htmls/tocs/Xow_toc_mgr.java b/400_xowa/src/gplx/xowa/htmls/tocs/Xow_toc_mgr.java index 4b3e42d6d..f3139939a 100644 --- a/400_xowa/src/gplx/xowa/htmls/tocs/Xow_toc_mgr.java +++ b/400_xowa/src/gplx/xowa/htmls/tocs/Xow_toc_mgr.java @@ -134,13 +134,13 @@ public class Xow_toc_mgr implements Bry_fmtr_arg { break; case Xop_tkn_itm_.Tid_lnki: Xop_lnki_tkn lnki = (Xop_lnki_tkn)sub; - if (lnki.Ns_id() == Xow_ns_.Id_category + if (lnki.Ns_id() == Xow_ns_.Tid__category && !lnki.Ttl().ForceLiteralLink()) {} // Category text should not print; DATE:2013-12-09 else { if (lnki.Caption_exists()) Toc_text_recurse(ctx, bfr, src, html_wtr, html_wtr_opts, lnki.Caption_val_tkn(), depth); else { - if (lnki.Ns_id() == Xow_ns_.Id_file) {} // do not print lnk_ttl in TOC; if file; tr.w:Dünya_Mirasları; DATE:2014-06-06 + if (lnki.Ns_id() == Xow_ns_.Tid__file) {} // do not print lnk_ttl in TOC; if file; tr.w:Dünya_Mirasları; DATE:2014-06-06 else bfr.Add(lnki.Ttl_ary()); } diff --git a/400_xowa/src/gplx/xowa/htmls/tocs/Xow_toc_mgr_tst.java b/400_xowa/src/gplx/xowa/htmls/tocs/Xow_toc_mgr_tst.java index 97ee36bec..7d290243a 100644 --- a/400_xowa/src/gplx/xowa/htmls/tocs/Xow_toc_mgr_tst.java +++ b/400_xowa/src/gplx/xowa/htmls/tocs/Xow_toc_mgr_tst.java @@ -17,9 +17,8 @@ along with this program. If not, see . */ package gplx.xowa.htmls.tocs; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import org.junit.*; import gplx.xowa.parsers.*; import gplx.xowa.htmls.core.htmls.*; -public class Xow_toc_mgr_tst { - private Xow_toc_mgr_fxt fxt = new Xow_toc_mgr_fxt(); - @Before public void init() {fxt.Clear();} +public class Xow_toc_mgr_tst { + @Before public void init() {fxt.Clear();} private final Xow_toc_mgr_fxt fxt = new Xow_toc_mgr_fxt(); @Test public void Basic() { fxt.Test_html_toc(String_.Concat_lines_nl_skip_last ( "==a==" @@ -294,7 +293,7 @@ public class Xow_toc_mgr_tst { @Test public void Xnde_nest_inline() { // PURPOSE: do not render inline xndes; EX: Magnetic_resonance_imaging fxt.Test_html_all(String_.Concat_lines_nl_skip_last ( "__FORCETOC__" - , "==ab
==" + , "==ab
==" ) , String_.Concat_lines_nl ( fxt.toc_tbl_nl_n @@ -519,6 +518,7 @@ class Xow_toc_mgr_fxt { Tfds.Eq_ary(String_.SplitLines_nl(expd), String_.SplitLines_nl(tmp.To_str_and_clear()), raw); } public void Test_html_all(String raw, String expd) { + expd = Xoh_consts.Escape_apos(expd); fxt.Wtr_cfg().Toc__show_(Bool_.Y); toc_mgr.Clear(); fxt.Test_parse_page_all_str(raw, expd); diff --git a/400_xowa/src/gplx/xowa/langs/Xol_lang_itm.java b/400_xowa/src/gplx/xowa/langs/Xol_lang_itm.java index 2b6eeba44..eb6f2e3a5 100644 --- a/400_xowa/src/gplx/xowa/langs/Xol_lang_itm.java +++ b/400_xowa/src/gplx/xowa/langs/Xol_lang_itm.java @@ -121,7 +121,7 @@ public class Xol_lang_itm implements GfoInvkAble { if (!lang_is_en) Xol_lang_itm_.Lang_init(this); msg_mgr.Itm_by_key_or_new(Bry_.new_a7("Lang")).Atrs_set(key_bry, false, false); // set "Lang" keyword; EX: for "fr", "{{int:Lang}}" -> "fr" Load_lang(key_bry); - ns_aliases.Ary_add_(Xow_ns_.Canonical); // NOTE: always add English canonical as aliases to all languages + ns_aliases.Ary_add_(Xow_ns_canonical_.Ary); // NOTE: always add English canonical as aliases to all languages this.Evt_lang_changed(); return true; } diff --git a/400_xowa/src/gplx/xowa/langs/bldrs/Xol_mw_lang_parser.java b/400_xowa/src/gplx/xowa/langs/bldrs/Xol_mw_lang_parser.java index 66f607612..5b4172ce6 100644 --- a/400_xowa/src/gplx/xowa/langs/bldrs/Xol_mw_lang_parser.java +++ b/400_xowa/src/gplx/xowa/langs/bldrs/Xol_mw_lang_parser.java @@ -226,7 +226,7 @@ public class Xol_mw_lang_parser { byte[] kv_val = brys[i + val_dif]; Bry_.Replace_all_direct(kv_val, Byte_ascii.Underline, Byte_ascii.Space); // NOTE: siteInfo.xml names have " " not "_" (EX: "User talk"). for now, follow that convention int ns_id = Id_by_mw_name(kv_key); -// if (ns_id == Xow_ns_.Id_null) throw Err_mgr.Instance.fmt_auto_(GRP_KEY, "namespace_names", String_.new_u8(kv_key)); +// if (ns_id == Xow_ns_.Tid__null) throw Err_mgr.Instance.fmt_auto_(GRP_KEY, "namespace_names", String_.new_u8(kv_key)); rv[i / 2] = new Xow_ns(ns_id, Xow_ns_case_.Tid__1st, kv_val, false); // note that Xow_ns is being used as glorified id-name struct; case_match and alias values do not matter } return rv; @@ -344,27 +344,27 @@ public class Xol_mw_lang_parser { public static int Id_by_mw_name(byte[] src) { if (mw_names == null) { mw_names = Btrie_slim_mgr.cs(); - mw_names.Add_obj("NS_MEDIA", Int_obj_val.new_(Xow_ns_.Id_media)); - mw_names.Add_obj("NS_SPECIAL", Int_obj_val.new_(Xow_ns_.Id_special)); - mw_names.Add_obj("NS_MAIN", Int_obj_val.new_(Xow_ns_.Id_main)); - mw_names.Add_obj("NS_TALK", Int_obj_val.new_(Xow_ns_.Id_talk)); - mw_names.Add_obj("NS_USER", Int_obj_val.new_(Xow_ns_.Id_user)); - mw_names.Add_obj("NS_USER_TALK", Int_obj_val.new_(Xow_ns_.Id_user_talk)); - mw_names.Add_obj("NS_PROJECT", Int_obj_val.new_(Xow_ns_.Id_project)); - mw_names.Add_obj("NS_PROJECT_TALK", Int_obj_val.new_(Xow_ns_.Id_project_talk)); - mw_names.Add_obj("NS_FILE", Int_obj_val.new_(Xow_ns_.Id_file)); - mw_names.Add_obj("NS_FILE_TALK", Int_obj_val.new_(Xow_ns_.Id_file_talk)); - mw_names.Add_obj("NS_MEDIAWIKI", Int_obj_val.new_(Xow_ns_.Id_mediawiki)); - mw_names.Add_obj("NS_MEDIAWIKI_TALK", Int_obj_val.new_(Xow_ns_.Id_mediaWiki_talk)); - mw_names.Add_obj("NS_TEMPLATE", Int_obj_val.new_(Xow_ns_.Id_template)); - mw_names.Add_obj("NS_TEMPLATE_TALK", Int_obj_val.new_(Xow_ns_.Id_template_talk)); - mw_names.Add_obj("NS_HELP", Int_obj_val.new_(Xow_ns_.Id_help)); - mw_names.Add_obj("NS_HELP_TALK", Int_obj_val.new_(Xow_ns_.Id_help_talk)); - mw_names.Add_obj("NS_CATEGORY", Int_obj_val.new_(Xow_ns_.Id_category)); - mw_names.Add_obj("NS_CATEGORY_TALK", Int_obj_val.new_(Xow_ns_.Id_category_talk)); + mw_names.Add_obj("NS_MEDIA", Int_obj_val.new_(Xow_ns_.Tid__media)); + mw_names.Add_obj("NS_SPECIAL", Int_obj_val.new_(Xow_ns_.Tid__special)); + mw_names.Add_obj("NS_MAIN", Int_obj_val.new_(Xow_ns_.Tid__main)); + mw_names.Add_obj("NS_TALK", Int_obj_val.new_(Xow_ns_.Tid__talk)); + mw_names.Add_obj("NS_USER", Int_obj_val.new_(Xow_ns_.Tid__user)); + mw_names.Add_obj("NS_USER_TALK", Int_obj_val.new_(Xow_ns_.Tid__user_talk)); + mw_names.Add_obj("NS_PROJECT", Int_obj_val.new_(Xow_ns_.Tid__project)); + mw_names.Add_obj("NS_PROJECT_TALK", Int_obj_val.new_(Xow_ns_.Tid__project_talk)); + mw_names.Add_obj("NS_FILE", Int_obj_val.new_(Xow_ns_.Tid__file)); + mw_names.Add_obj("NS_FILE_TALK", Int_obj_val.new_(Xow_ns_.Tid__file_talk)); + mw_names.Add_obj("NS_MEDIAWIKI", Int_obj_val.new_(Xow_ns_.Tid__mediawiki)); + mw_names.Add_obj("NS_MEDIAWIKI_TALK", Int_obj_val.new_(Xow_ns_.Tid__mediawiki_talk)); + mw_names.Add_obj("NS_TEMPLATE", Int_obj_val.new_(Xow_ns_.Tid__template)); + mw_names.Add_obj("NS_TEMPLATE_TALK", Int_obj_val.new_(Xow_ns_.Tid__template_talk)); + mw_names.Add_obj("NS_HELP", Int_obj_val.new_(Xow_ns_.Tid__help)); + mw_names.Add_obj("NS_HELP_TALK", Int_obj_val.new_(Xow_ns_.Tid__help_talk)); + mw_names.Add_obj("NS_CATEGORY", Int_obj_val.new_(Xow_ns_.Tid__category)); + mw_names.Add_obj("NS_CATEGORY_TALK", Int_obj_val.new_(Xow_ns_.Tid__category_talk)); } Object o = mw_names.Match_exact(src, 0, src.length); - return o == null ? Xow_ns_.Id_null : ((Int_obj_val)o).Val(); + return o == null ? Xow_ns_.Tid__null : ((Int_obj_val)o).Val(); } private static Btrie_slim_mgr mw_names; public static final String Dir_name_core = "core"; } diff --git a/400_xowa/src/gplx/xowa/langs/bldrs/Xol_mw_lang_parser_tst.java b/400_xowa/src/gplx/xowa/langs/bldrs/Xol_mw_lang_parser_tst.java index 1ec718549..ee2346cc1 100644 --- a/400_xowa/src/gplx/xowa/langs/bldrs/Xol_mw_lang_parser_tst.java +++ b/400_xowa/src/gplx/xowa/langs/bldrs/Xol_mw_lang_parser_tst.java @@ -63,15 +63,15 @@ public class Xol_mw_lang_parser_tst { @Test public void Core_namespaces_names() { fxt.Parse_core("$namespaceNames = array(NS_FILE => 'Fichier');") .Sync_ns() - .Tst_ns_lkp("Fichier", Xow_ns_.Id_file) - .Tst_ns_lkp("File" , Xow_ns_.Id_null) + .Tst_ns_lkp("Fichier", Xow_ns_.Tid__file) + .Tst_ns_lkp("File" , Xow_ns_.Tid__null) ; } @Test public void Core_namespaces_aliases() { fxt.Parse_core("$namespaceAliases = array('Discussion_Fichier' => NS_FILE_TALK);") .Sync_ns() - .Tst_ns_lkp("Discussion Fichier", Xow_ns_.Id_file_talk) - .Tst_ns_lkp("Discussion Fichierx", Xow_ns_.Id_null) + .Tst_ns_lkp("Discussion Fichier", Xow_ns_.Tid__file_talk) + .Tst_ns_lkp("Discussion Fichierx", Xow_ns_.Tid__null) ; } @Test public void Core_specialPageAliases() { @@ -286,7 +286,7 @@ class Xol_mw_lang_parser_fxt { public Xol_mw_lang_parser_fxt Tst_ns_lkp(String key_str, int id) { byte[] key = Bry_.new_u8(key_str); Xow_ns ns = (Xow_ns)wiki.Ns_mgr().Names_get_or_null(key, 0, key.length); - int actl = ns == null ? Xow_ns_.Id_null : ns.Id(); + int actl = ns == null ? Xow_ns_.Tid__null : ns.Id(); Tfds.Eq(id, actl); return this; } diff --git a/400_xowa/src/gplx/xowa/langs/parsers/Xol_lang_srl.java b/400_xowa/src/gplx/xowa/langs/parsers/Xol_lang_srl.java index 339a5ce3e..9cdc197c9 100644 --- a/400_xowa/src/gplx/xowa/langs/parsers/Xol_lang_srl.java +++ b/400_xowa/src/gplx/xowa/langs/parsers/Xol_lang_srl.java @@ -191,7 +191,7 @@ public class Xol_lang_srl { for (int i = 0; i < ns_grp_len; i++) { Xow_ns ns = ns_grp.Get_at(i); bfr.Add_int_variable(ns.Id()).Add_byte_pipe(); // id| - csv_parser.Save(bfr, ns.Name_bry()); // name + csv_parser.Save(bfr, ns.Name_db()); // name bfr.Add_byte_nl(); // \n } bldr.Add_quote_xtn_end(); // ']:>\n diff --git a/400_xowa/src/gplx/xowa/langs/parsers/Xol_lang_srl_tst.java b/400_xowa/src/gplx/xowa/langs/parsers/Xol_lang_srl_tst.java index 4446d4ae5..1b74aecec 100644 --- a/400_xowa/src/gplx/xowa/langs/parsers/Xol_lang_srl_tst.java +++ b/400_xowa/src/gplx/xowa/langs/parsers/Xol_lang_srl_tst.java @@ -291,7 +291,7 @@ class Xol_lang_srl_fxt { int len = ary.length; for (int i = 0; i < len; i++) { Xow_ns ns = ary[i]; - sb.Add(ns.Id()).Add("|").Add(ns.Name_str()).Add_char_nl(); + sb.Add(ns.Id()).Add("|").Add(ns.Name_db_str()).Add_char_nl(); } return sb.To_str_and_clear(); } diff --git a/400_xowa/src/gplx/xowa/parsers/hdrs/Xop_hdr_wkr__basic_tst.java b/400_xowa/src/gplx/xowa/parsers/hdrs/Xop_hdr_wkr__basic_tst.java index 2396b98fb..52eecd16f 100644 --- a/400_xowa/src/gplx/xowa/parsers/hdrs/Xop_hdr_wkr__basic_tst.java +++ b/400_xowa/src/gplx/xowa/parsers/hdrs/Xop_hdr_wkr__basic_tst.java @@ -83,7 +83,7 @@ public class Xop_hdr_wkr__basic_tst { @Test public void Err_end_hdr_is_1() {fxt.Init_log_(Xop_hdr_log.Mismatched, Xop_hdr_log.Len_1).Test_parse_page_wiki_str("==a=" , "

=a

\n").tst_Log_check();} @Test public void Html_hdr_many() { fxt.Wtr_cfg().Toc__show_(Bool_.Y); - fxt.Test_parse_page_wiki_str(String_.Concat_lines_nl_skip_last + fxt.Test_parse_page_wiki_str__esc(String_.Concat_lines_nl_skip_last ( "==a==" , "==a==" , "==a==" diff --git a/400_xowa/src/gplx/xowa/parsers/lnkis/Xop_lnki_align_h.java b/400_xowa/src/gplx/xowa/parsers/lnkis/Xop_lnki_align_h.java index 88142e316..2b6498ce5 100644 --- a/400_xowa/src/gplx/xowa/parsers/lnkis/Xop_lnki_align_h.java +++ b/400_xowa/src/gplx/xowa/parsers/lnkis/Xop_lnki_align_h.java @@ -25,6 +25,12 @@ public class Xop_lnki_align_h { , Bry_.new_a7("center") , Bry_.new_a7("right") }; + public static final Hash_adp_bry Hash = Hash_adp_bry.ci_a7() + .Add_str_byte("tnone" , None) + .Add_str_byte("tleft" , Left) + .Add_str_byte("tcenter" , Center) + .Add_str_byte("tright" , Right) + ; } class Xop_lnki_align_v { public static final byte None = 0, Top = 1, Middle = 2, Bottom = 4, Super = 8, Sub = 16, TextTop = 32, TextBottom = 64, Baseline = 127; diff --git a/400_xowa/src/gplx/xowa/parsers/lnkis/Xop_lnki_tkn.java b/400_xowa/src/gplx/xowa/parsers/lnkis/Xop_lnki_tkn.java index 3dab31ebe..2e6727822 100644 --- a/400_xowa/src/gplx/xowa/parsers/lnkis/Xop_lnki_tkn.java +++ b/400_xowa/src/gplx/xowa/parsers/lnkis/Xop_lnki_tkn.java @@ -52,13 +52,13 @@ public class Xop_lnki_tkn extends Xop_tkn_itm_base { public boolean Xtn_sites_link() {return xtn_sites_link;} public void Xtn_sites_link_(boolean v) {xtn_sites_link = v;} private boolean xtn_sites_link; public Xoh_file_img_wkr Lnki_file_wkr() {return lnki_file_wkr;} public void Lnki_file_wkr_(Xoh_file_img_wkr v) {lnki_file_wkr = v;} private Xoh_file_img_wkr lnki_file_wkr; public byte[] Ttl_ary() { - return ttl.ForceLiteralLink() || ns_id != Xow_ns_.Id_main // if [[:]] or non-main (Category, Template) + return ttl.ForceLiteralLink() || ns_id != Xow_ns_.Tid__main // if [[:]] or non-main (Category, Template) ? ttl.Full_txt() // use full_txt (no initial colon; capitalize first) : ttl.Raw(); // use raw (preserve case, white-spaces) } public boolean Caption_exists() { return !((caption_tkn == Xop_tkn_null.Null_tkn) // trg only; no caption: EX: [[a]] vs. [[a|b]] which has a trg of a and a caption of b - || (ns_id == Xow_ns_.Id_category // a Category only has a target; any caption is ignored; EX: [[Category:a|b], b is ignored + || (ns_id == Xow_ns_.Tid__category // a Category only has a target; any caption is ignored; EX: [[Category:a|b], b is ignored && !ttl.ForceLiteralLink())); } public Xop_lnki_tkn Lnki_type_(byte v) { diff --git a/400_xowa/src/gplx/xowa/parsers/lnkis/Xop_lnki_wkr.java b/400_xowa/src/gplx/xowa/parsers/lnkis/Xop_lnki_wkr.java index a5b68cc4a..1a1d3d3d8 100644 --- a/400_xowa/src/gplx/xowa/parsers/lnkis/Xop_lnki_wkr.java +++ b/400_xowa/src/gplx/xowa/parsers/lnkis/Xop_lnki_wkr.java @@ -53,17 +53,17 @@ public class Xop_lnki_wkr implements Xop_ctx_wkr, Xop_arg_wkr { root.Subs_del_after(lnki.Tkn_sub_idx() + 1); // all tkns should now be converted to args in owner; delete everything in root boolean lnki_is_file = false; switch (lnki.Ns_id()) { - case Xow_ns_.Id_file: + case Xow_ns_.Tid__file: if ( Xop_lnki_type.Id_is_thumbable(lnki.Lnki_type()) // thumbs produce
cancels pre || lnki.Align_h() != Xop_lnki_align_h.Null // halign (left, right, none) also produces
; DATE:2014-02-17 ) ctx.Para().Process_block_lnki_div(); lnki_is_file = true; break; - case Xow_ns_.Id_media: + case Xow_ns_.Tid__media: lnki_is_file = true; break; - case Xow_ns_.Id_category: + case Xow_ns_.Tid__category: if (!lnki.Ttl().ForceLiteralLink()) // NOTE: do not remove ws if literal; EX:[[Category:A]]\n[[Category:B]] should stay the same; DATE:2013-07-10 ctx.Para().Process_lnki_category(ctx, root, src,cur_pos, src_len); // removes excessive ws between categories; EX: [[Category:A]]\n\s[[Category:B]] -> [[Category:A]][[Category:B]] (note that both categories will not be rendered directly in html, but go to the bottom of the page) break; @@ -120,7 +120,7 @@ public class Xop_lnki_wkr implements Xop_ctx_wkr, Xop_arg_wkr { case Xop_lnki_arg_parser.Tid_caption: Xop_tkn_itm cur_caption_tkn = lnki.Caption_tkn(); if ( cur_caption_tkn == Xop_tkn_null.Null_tkn // lnki doesn't have caption; add arg as caption - || lnki.Ttl().Ns().Id_file_or_media()) { // or lnki is File; always take last + || lnki.Ttl().Ns().Id_is_file_or_media()) { // or lnki is File; always take last lnki.Caption_tkn_(arg); if (arg.Eq_tkn() != Xop_tkn_null.Null_tkn) { // equal tkn exists; add val tkns to key and then swap key with val Arg_itm_tkn key_tkn = arg.Key_tkn(), val_tkn = arg.Val_tkn(); diff --git a/400_xowa/src/gplx/xowa/parsers/lnkis/Xop_lnki_wkr_.java b/400_xowa/src/gplx/xowa/parsers/lnkis/Xop_lnki_wkr_.java index 34841ff64..1b9b8cb11 100644 --- a/400_xowa/src/gplx/xowa/parsers/lnkis/Xop_lnki_wkr_.java +++ b/400_xowa/src/gplx/xowa/parsers/lnkis/Xop_lnki_wkr_.java @@ -75,7 +75,7 @@ public class Xop_lnki_wkr_ { if (!wiki.Cfg_parser().Lnki_cfg().Xwiki_repo_mgr().Has(xwiki_bry)) return ttl; // alias not in xwikis; EX: [[en_bad:File:A.png]] Xoa_ttl ttl_in_xwiki = Xoa_ttl.parse(wiki, ttl_in_xwiki_bry); if (ttl_in_xwiki == null) return ttl; // occurs if ttl is bad in xwiki; EX: [[en:]] - return ttl_in_xwiki.Ns().Id_file() ? ttl_in_xwiki : ttl; + return ttl_in_xwiki.Ns().Id_is_file() ? ttl_in_xwiki : ttl; } public static int Chk_for_tail(Xol_lang_itm lang, byte[] src, int cur_pos, int src_len, Xop_lnki_tkn lnki) { int bgn_pos = cur_pos; @@ -86,7 +86,7 @@ public class Xop_lnki_wkr_ { if (lnki_trail_bry == null) break; // no longer a lnki_trail char; stop cur_pos += lnki_trail_bry.length; // lnki_trail char; add } - if (bgn_pos != cur_pos && lnki.Ns_id() == Xow_ns_.Id_main) { // only mark trail if Main ns (skip trail for Image) + if (bgn_pos != cur_pos && lnki.Ns_id() == Xow_ns_.Tid__main) { // only mark trail if Main ns (skip trail for Image) lnki.Tail_bgn_(bgn_pos).Tail_end_(cur_pos); return cur_pos; } diff --git a/400_xowa/src/gplx/xowa/parsers/lnkis/Xop_lnki_wkr__basic_tst.java b/400_xowa/src/gplx/xowa/parsers/lnkis/Xop_lnki_wkr__basic_tst.java index 34ab34f4e..fb0cf3c8b 100644 --- a/400_xowa/src/gplx/xowa/parsers/lnkis/Xop_lnki_wkr__basic_tst.java +++ b/400_xowa/src/gplx/xowa/parsers/lnkis/Xop_lnki_wkr__basic_tst.java @@ -51,7 +51,7 @@ public class Xop_lnki_wkr__basic_tst { @Test public void Tail_upper() {fxt.Test_parse_page_wiki("[[a|b]]A" , fxt.tkn_lnki_(0, 7).Tail_bgn_(-1), fxt.tkn_txt_(7, 8));} // make sure trie is case-insensitive @Test public void Tail_image() {fxt.Test_parse_page_wiki("[[Image:a|b]]c", fxt.tkn_lnki_(0, 13).Tail_bgn_(-1).Tail_end_(-1), fxt.tkn_txt_(13, 14));} // NOTE: this occurs on some pages; @Test public void Image() { - fxt.Test_parse_page_wiki("[[Image:a]]" , fxt.tkn_lnki_().Ns_id_(Xow_ns_.Id_file).Trg_tkn_(fxt.tkn_arg_val_(fxt.tkn_txt_(2, 7), fxt.tkn_colon_(7), fxt.tkn_txt_(8, 9)))); + fxt.Test_parse_page_wiki("[[Image:a]]" , fxt.tkn_lnki_().Ns_id_(Xow_ns_.Tid__file).Trg_tkn_(fxt.tkn_arg_val_(fxt.tkn_txt_(2, 7), fxt.tkn_colon_(7), fxt.tkn_txt_(8, 9)))); fxt.Test_parse_page_wiki("[[Image:a|border]]" , fxt.tkn_lnki_().Border_(Bool_.Y_byte)); fxt.Test_parse_page_wiki("[[Image:a|thumb]]" , fxt.tkn_lnki_().ImgType_(Xop_lnki_type.Id_thumb)); fxt.Test_parse_page_wiki("[[Image:a|left]]" , fxt.tkn_lnki_().HAlign_(Xop_lnki_align_h.Left)); @@ -61,7 +61,7 @@ public class Xop_lnki_wkr__basic_tst { fxt.Test_parse_page_wiki("[[Image:a|alt=b]]" , fxt.tkn_lnki_().Alt_tkn_(fxt.tkn_arg_nde_().Key_tkn_(fxt.tkn_arg_itm_(fxt.tkn_txt_(10, 13))).Val_tkn_(fxt.tkn_arg_itm_(fxt.tkn_txt_(14, 15))))); fxt.Test_parse_page_wiki("[[Image:a|link=a]]" , fxt.tkn_lnki_().Link_tkn_(fxt.tkn_arg_nde_().Key_tkn_(fxt.tkn_arg_itm_(fxt.tkn_txt_(10, 14))).Val_tkn_(fxt.tkn_arg_itm_(fxt.tkn_txt_(15, 16))))); fxt.Test_parse_page_wiki("[[Image:a|thumb|alt=b|c d]]" - , fxt.tkn_lnki_().Ns_id_(Xow_ns_.Id_file) + , fxt.tkn_lnki_().Ns_id_(Xow_ns_.Tid__file) .Trg_tkn_(fxt.tkn_arg_nde_().Val_tkn_(fxt.tkn_arg_itm_(fxt.tkn_txt_(2, 7), fxt.tkn_colon_(7), fxt.tkn_txt_(8, 9)))) .Alt_tkn_(fxt.tkn_arg_nde_().Key_tkn_(fxt.tkn_arg_itm_(fxt.tkn_txt_(16, 19))).Val_tkn_(fxt.tkn_arg_itm_(fxt.tkn_txt_(20, 21)))) .Caption_tkn_(fxt.tkn_arg_nde_(22, 25).Val_tkn_(fxt.tkn_arg_itm_(fxt.tkn_txt_(22, 23), fxt.tkn_space_(23, 24), fxt.tkn_txt_(24, 25))))) @@ -76,17 +76,17 @@ public class Xop_lnki_wkr__basic_tst { } @Test public void Recurse() { fxt.Test_parse_page_wiki("[[Image:a|b-[[c]]-d]]" - , fxt.tkn_lnki_().Ns_id_(Xow_ns_.Id_file) + , fxt.tkn_lnki_().Ns_id_(Xow_ns_.Tid__file) .Trg_tkn_(fxt.tkn_arg_nde_().Val_tkn_(fxt.tkn_arg_itm_(fxt.tkn_txt_(2, 7), fxt.tkn_colon_(7), fxt.tkn_txt_(8, 9)))) .Caption_tkn_(fxt.tkn_arg_nde_(10, 19).Val_tkn_(fxt.tkn_arg_itm_(fxt.tkn_txt_(10, 12), fxt.tkn_lnki_(12, 17), fxt.tkn_txt_(17, 19)))) ); } @Test public void Outliers() { - fxt.Test_parse_page_wiki("[[Image:a=b.svg|thumb|10px]]", fxt.tkn_lnki_().Ns_id_(Xow_ns_.Id_file).Trg_tkn_(fxt.tkn_arg_nde_().Val_tkn_(fxt.tkn_arg_itm_(fxt.tkn_txt_(2, 7), fxt.tkn_colon_(7), fxt.tkn_txt_(8, 9), fxt.tkn_eq_(9), fxt.tkn_txt_(10, 15))))); - fxt.Test_parse_page_wiki("[[Category:a|b]]", fxt.tkn_lnki_().Ns_id_(Xow_ns_.Id_category)); + fxt.Test_parse_page_wiki("[[Image:a=b.svg|thumb|10px]]", fxt.tkn_lnki_().Ns_id_(Xow_ns_.Tid__file).Trg_tkn_(fxt.tkn_arg_nde_().Val_tkn_(fxt.tkn_arg_itm_(fxt.tkn_txt_(2, 7), fxt.tkn_colon_(7), fxt.tkn_txt_(8, 9), fxt.tkn_eq_(9), fxt.tkn_txt_(10, 15))))); + fxt.Test_parse_page_wiki("[[Category:a|b]]", fxt.tkn_lnki_().Ns_id_(Xow_ns_.Tid__category)); } @Test public void Exc_caption_has_eq() { - fxt.Test_parse_page_wiki("[[Image:a.svg|thumb|a=b]]", fxt.tkn_lnki_().Ns_id_(Xow_ns_.Id_file) + fxt.Test_parse_page_wiki("[[Image:a.svg|thumb|a=b]]", fxt.tkn_lnki_().Ns_id_(Xow_ns_.Tid__file) .Caption_tkn_(fxt.tkn_arg_nde_(20, 23).Val_tkn_(fxt.tkn_arg_itm_(fxt.tkn_txt_(20, 21), fxt.tkn_eq_(21), fxt.tkn_txt_(22, 23))))); } @Test public void Border_with_space_should_not_be_caption() {// happens with {{flag}}; EX: [[Image:Flag of Argentina.svg|22x20px|border |alt=|link=]] diff --git a/400_xowa/src/gplx/xowa/parsers/lnkis/Xop_lnki_wkr__subpage_tst.java b/400_xowa/src/gplx/xowa/parsers/lnkis/Xop_lnki_wkr__subpage_tst.java index 5a4c23e77..b7668f0ce 100644 --- a/400_xowa/src/gplx/xowa/parsers/lnkis/Xop_lnki_wkr__subpage_tst.java +++ b/400_xowa/src/gplx/xowa/parsers/lnkis/Xop_lnki_wkr__subpage_tst.java @@ -20,9 +20,9 @@ import org.junit.*; import gplx.xowa.wikis.nss.*; public class Xop_lnki_wkr__subpage_tst { @Before public void init() {fxt.Reset(); fxt.Init_para_n_();} private Xop_fxt fxt = new Xop_fxt(); @Test public void Disabled() { // PURPOSE: slash being interpreted as subpage; PAGE:en.w:[[/dev/null]] - fxt.Wiki().Ns_mgr().Ids_get_or_null(Xow_ns_.Id_main).Subpages_enabled_(false); + fxt.Wiki().Ns_mgr().Ids_get_or_null(Xow_ns_.Tid__main).Subpages_enabled_(false); fxt.Test_parse_page_all_str("[[/dev/null]]", "/dev/null"); - fxt.Wiki().Ns_mgr().Ids_get_or_null(Xow_ns_.Id_main).Subpages_enabled_(true); + fxt.Wiki().Ns_mgr().Ids_get_or_null(Xow_ns_.Tid__main).Subpages_enabled_(true); } @Test public void False_match() {// PAGE:en.w:en.wiktionary.org/wiki/Wiktionary:Requests for cleanup/archive/2006 fxt.Test_parse_page_wiki_str diff --git a/400_xowa/src/gplx/xowa/parsers/lnkis/redlinks/Xopg_redlink_lnki_list.java b/400_xowa/src/gplx/xowa/parsers/lnkis/redlinks/Xopg_redlink_lnki_list.java index 633bcf643..fe35f21b2 100644 --- a/400_xowa/src/gplx/xowa/parsers/lnkis/redlinks/Xopg_redlink_lnki_list.java +++ b/400_xowa/src/gplx/xowa/parsers/lnkis/redlinks/Xopg_redlink_lnki_list.java @@ -37,9 +37,9 @@ public class Xopg_redlink_lnki_list { Xoa_ttl ttl = lnki.Ttl(); if (ttl == null) return; // occurs for invalid links Xow_ns ns = ttl.Ns(); lnki.Html_uid_(++lnki_idx); // NOTE: set html_id in order html to print out "id='xowa_lnki_1'; want to print out id for consistency's sake, even if these links won't be check for redlinks; DATE:2015-05-07 - if ( ns.Id_file_or_media() // ignore files which will usually not be in local wiki (most are in commons), and whose html is built up separately - || (ns.Id_ctg() && !ttl.ForceLiteralLink()) // ignore ctgs which have their own html builder, unless it is literal; EX: [[:Category:A]]; DATE:2014-02-24 - || ns.Id_special() // ignore special, especially Search; EX: Special:Search/Earth + if ( ns.Id_is_file_or_media() // ignore files which will usually not be in local wiki (most are in commons), and whose html is built up separately + || (ns.Id_is_ctg() && !ttl.ForceLiteralLink()) // ignore ctgs which have their own html builder, unless it is literal; EX: [[:Category:A]]; DATE:2014-02-24 + || ns.Id_is_special() // ignore special, especially Search; EX: Special:Search/Earth || ttl.Anch_bgn() == Xoa_ttl.Anch_bgn_anchor_only // anchor only link; EX: [[#anchor]] || ttl.Wik_itm() != null // xwiki lnki; EX: simplewiki links in homewiki; [[simplewiki:Earth]] ) diff --git a/400_xowa/src/gplx/xowa/parsers/miscs/Xop_under_lxr_tst.java b/400_xowa/src/gplx/xowa/parsers/miscs/Xop_under_lxr_tst.java index cf64ab390..44e3d7b48 100644 --- a/400_xowa/src/gplx/xowa/parsers/miscs/Xop_under_lxr_tst.java +++ b/400_xowa/src/gplx/xowa/parsers/miscs/Xop_under_lxr_tst.java @@ -32,7 +32,7 @@ public class Xop_under_lxr_tst { } @Test public void Notoc_basic() { fxt.Wtr_cfg().Toc__show_(Bool_.Y); // NOTE: must enable in order for TOC to show (and to make sure NOTOC suppresses) - fxt.Test_parse_page_all_str(String_.Concat_lines_nl + fxt.Test_parse_page_all_str__esc(String_.Concat_lines_nl ( "__NOTOC__" , "==a==" , "==b==" diff --git a/400_xowa/src/gplx/xowa/parsers/tmpls/Arg_bldr.java b/400_xowa/src/gplx/xowa/parsers/tmpls/Arg_bldr.java index 031b30053..0bd267bc9 100644 --- a/400_xowa/src/gplx/xowa/parsers/tmpls/Arg_bldr.java +++ b/400_xowa/src/gplx/xowa/parsers/tmpls/Arg_bldr.java @@ -170,7 +170,7 @@ public class Arg_bldr { trim = false; switch (wkr_typ) { case Xop_arg_wkr_.Typ_prm : trim = arg_idx == 0; break; - case Xop_arg_wkr_.Typ_tmpl: trim = key_exists || arg_idx == 0; break; + case Xop_arg_wkr_.Typ_tmpl: trim = true; break; // NOTE: was "key_exists || arg_idx == 0;"; PAGE:s.w:Gothic_architecture; DATE:2015-11-07 case Xop_arg_wkr_.Typ_lnki: trim = !cur_itm_is_key; break; } if (trim) { diff --git a/400_xowa/src/gplx/xowa/parsers/tmpls/Xot_defn_tmpl.java b/400_xowa/src/gplx/xowa/parsers/tmpls/Xot_defn_tmpl.java index e1542c892..97125e636 100644 --- a/400_xowa/src/gplx/xowa/parsers/tmpls/Xot_defn_tmpl.java +++ b/400_xowa/src/gplx/xowa/parsers/tmpls/Xot_defn_tmpl.java @@ -66,7 +66,7 @@ public class Xot_defn_tmpl implements Xot_defn { Xoae_page page = ctx.Cur_page(); if (!page.Tmpl_stack_add(full_name)) { bfr.Add_str_a7(""); - Xoa_app_.Usr_dlg().Warn_many("", "", "template loop detected: url=~{0} name=~{1}", ctx.Cur_page().Url().To_str(), name); + Xoa_app_.Usr_dlg().Log_many("", "", "template loop detected: url=~{0} name=~{1}", ctx.Cur_page().Url().To_str(), name); return false; } boolean rv = true; diff --git a/400_xowa/src/gplx/xowa/parsers/tmpls/Xot_invk_tkn.java b/400_xowa/src/gplx/xowa/parsers/tmpls/Xot_invk_tkn.java index ec640ba3d..c3c4c673a 100644 --- a/400_xowa/src/gplx/xowa/parsers/tmpls/Xot_invk_tkn.java +++ b/400_xowa/src/gplx/xowa/parsers/tmpls/Xot_invk_tkn.java @@ -337,7 +337,7 @@ public class Xot_invk_tkn extends Xop_tkn_itm_base implements Xot_invk { private boolean Transclude(Xop_ctx ctx, Xowe_wiki wiki, Bry_bfr bfr, byte[] name_ary, Xot_invk caller, byte[] src) { Xoa_ttl page_ttl = Xoa_ttl.parse(wiki, name_ary); if (page_ttl == null) return false; // ttl not valid; EX: {{:[[abc]]}} byte[] transclude_src = null; - if (page_ttl.Ns().Id_tmpl()) { // ttl is template; check tmpl_regy first before going to data_mgr + if (page_ttl.Ns().Id_is_tmpl()) { // ttl is template; check tmpl_regy first before going to data_mgr Xot_defn_tmpl tmpl = (Xot_defn_tmpl)wiki.Cache_mgr().Defn_cache().Get_by_key(page_ttl.Page_db()); if (tmpl != null) transclude_src = tmpl.Data_raw(); } @@ -385,21 +385,21 @@ public class Xot_invk_tkn extends Xop_tkn_itm_base implements Xot_invk { return rv; } public static void Print_not_found(Bry_bfr bfr, Xow_ns_mgr ns_mgr, byte[] name_ary) { // print missing as [[:Template:Missing]]; REF:MW: Parser.php|braceSubstitution|$text = "[[:$titleText]]"; EX:en.d:Kazakhstan; DATE:2014-03-25 - byte[] template_ns_name = ns_mgr.Ns_template().Name_bry(); + byte[] template_ns_name = ns_mgr.Ns_template().Name_db(); bfr.Add(Xop_tkn_.Lnki_bgn).Add_byte(Byte_ascii.Colon).Add(template_ns_name).Add_byte(Byte_ascii.Colon).Add(name_ary).Add(Xop_tkn_.Lnki_end); } private boolean SubEval(Xop_ctx ctx, Xowe_wiki wiki, Bry_bfr bfr, byte[] name_ary, Xot_invk caller, byte[] src_for_tkn) { Xoa_ttl page_ttl = Xoa_ttl.parse(wiki, name_ary); if (page_ttl == null) return false; // ttl not valid; EX: {{:[[abc]]}} Xot_defn_tmpl transclude_tmpl = null; switch (page_ttl.Ns().Id()) { - case Xow_ns_.Id_template: // ttl is template not in cache, or some other ns; do load + case Xow_ns_.Tid__template: // ttl is template not in cache, or some other ns; do load Xot_defn_tmpl tmpl = (Xot_defn_tmpl)wiki.Cache_mgr().Defn_cache().Get_by_key(page_ttl.Page_db()); if (tmpl != null) { if (tmpl.Root() == null) tmpl.Parse_tmpl(ctx); transclude_tmpl = tmpl; } break; - case Xow_ns_.Id_special: + case Xow_ns_.Tid__special: bfr.Add(Xop_tkn_.Lnki_bgn).Add_byte(Byte_ascii.Colon).Add(name_ary).Add(Xop_tkn_.Lnki_end); return true; } diff --git a/400_xowa/src/gplx/xowa/parsers/tmpls/Xot_invk_wkr.java b/400_xowa/src/gplx/xowa/parsers/tmpls/Xot_invk_wkr.java index 23f00bb20..56e3f7562 100644 --- a/400_xowa/src/gplx/xowa/parsers/tmpls/Xot_invk_wkr.java +++ b/400_xowa/src/gplx/xowa/parsers/tmpls/Xot_invk_wkr.java @@ -72,7 +72,7 @@ public class Xot_invk_wkr implements Xop_ctx_wkr, Xop_arg_wkr { int subst_bgn = finder.Subst_bgn(), subst_end = finder.Subst_end(); invk.Tmpl_subst_props_(finder_typeId, subst_bgn, subst_end); if ((ctx.Parse_tid() == Xop_parser_.Parse_tid_tmpl && finder_typeId == Xot_defn_.Tid_subst) // NOTE: if subst, but in tmpl stage, do not actually subst; PAGE:en.w:Unreferenced; DATE:2013-01-31 - || ctx.Cur_page().Ttl().Ns().Id_tmpl()) { // also, if on tmpl page, never evaluate (questionable, but seems to be needed) + || ctx.Cur_page().Ttl().Ns().Id_is_tmpl()) { // also, if on tmpl page, never evaluate (questionable, but seems to be needed) } else { key_tkn.Dat_rng_ary_(src, subst_end, txt_end); // redo txt_rng to ignore subst diff --git a/400_xowa/src/gplx/xowa/parsers/tmpls/Xot_invk_wkr_basic_tst.java b/400_xowa/src/gplx/xowa/parsers/tmpls/Xot_invk_wkr_basic_tst.java index 326ddce5b..cc12565db 100644 --- a/400_xowa/src/gplx/xowa/parsers/tmpls/Xot_invk_wkr_basic_tst.java +++ b/400_xowa/src/gplx/xowa/parsers/tmpls/Xot_invk_wkr_basic_tst.java @@ -209,7 +209,7 @@ public class Xot_invk_wkr_basic_tst { } @Test public void Missing_foreign() { Xow_ns ns = fxt.Wiki().Ns_mgr().Ns_template(); - byte[] old_ns = ns.Name_bry(); + byte[] old_ns = ns.Name_db(); ns.Name_bry_(Bry_.new_a7("Template_foreign")); fxt.Test_parse_tmpl_str("{{Missing}}", "[[:Template_foreign:Missing]]"); ns.Name_bry_(old_ns); @@ -233,7 +233,7 @@ public class Xot_invk_wkr_basic_tst { fxt.Init_defn_clear(); fxt.Init_defn_add("test_1", "{{test_2|{{{1}}}}}"); fxt.Init_defn_add("test_2", "{{{1}}}"); - fxt.Test_parse_tmpl_str("{{test_1| a }}", " a "); + fxt.Test_parse_tmpl_str("{{test_1| a }}", " a"); // tmpl.trim_end: always trim end; DATE:2015-11-07 fxt.Init_defn_clear(); } @Test public void Ws_trimmed_key_1() { // PURPOSE: trim prm when passed as key; @@ -254,7 +254,7 @@ public class Xot_invk_wkr_basic_tst { fxt.Init_defn_clear(); fxt.Init_defn_add("test_1", "{{test_2|1={{{1}}}{{{2}}}}}"); fxt.Init_defn_add("test_2", "{{{1}}}"); - fxt.Test_parse_tmpl_str("{{test_1| a | b }}", "a b"); + fxt.Test_parse_tmpl_str("{{test_1| a | b }}", "a b"); // tmpl.trim_end: always trim end; DATE:2015-11-07 fxt.Init_defn_clear(); } @Test public void Ws_eval_prm() { // PURPOSE: skip ws in prm_idx; EX:it.w:Portale:Giochi_da_tavolo; it.w:Template:Alternate; DATE:2014-02-09 @@ -316,7 +316,7 @@ public class Xot_invk_wkr_basic_tst { fxt.Init_defn_clear(); } @Test public void Tmpl_aliases() { // PURPOSE: handled aliases for Template ns - fxt.Wiki().Ns_mgr().Aliases_add(Xow_ns_.Id_template, "TemplateAlias"); + fxt.Wiki().Ns_mgr().Aliases_add(Xow_ns_.Tid__template, "TemplateAlias"); fxt.Wiki().Ns_mgr().Init(); fxt.Init_defn_clear(); fxt.Init_defn_add("tmpl_key", "tmpl_val"); @@ -324,7 +324,7 @@ public class Xot_invk_wkr_basic_tst { fxt.Init_defn_clear(); } @Test public void Tmpl_aliases_2() { // PURPOSE: handled aliases for other ns; DATE:2013-02-08 - fxt.Wiki().Ns_mgr().Aliases_add(Xow_ns_.Id_project, "WP"); + fxt.Wiki().Ns_mgr().Aliases_add(Xow_ns_.Tid__project, "WP"); fxt.Wiki().Ns_mgr().Init(); fxt.Init_defn_clear(); fxt.Init_page_create("Project:tmpl_key", "tmpl_val"); diff --git a/400_xowa/src/gplx/xowa/parsers/utils/Xop_redirect_mgr.java b/400_xowa/src/gplx/xowa/parsers/utils/Xop_redirect_mgr.java index 0c016dfce..8fefa548a 100644 --- a/400_xowa/src/gplx/xowa/parsers/utils/Xop_redirect_mgr.java +++ b/400_xowa/src/gplx/xowa/parsers/utils/Xop_redirect_mgr.java @@ -27,12 +27,15 @@ public class Xop_redirect_mgr { public Xoa_ttl Extract_redirect_loop(byte[] src) { Xoa_ttl rv = null; for (int i = 0; i < Redirect_max_allowed; i++) { - rv = Extract_redirect(src, src.length); + rv = Extract_redirect(src); if (rv != null) return rv; } return null; } - public Xoa_ttl Extract_redirect(byte[] src) {return Extract_redirect(src, src.length);} + public Xoa_ttl Extract_redirect(byte[] src) { + if (src == null) return Redirect_null_ttl; + return Extract_redirect(src, src.length); + } public Xoa_ttl Extract_redirect(byte[] src, int src_len) { // NOTE: this proc is called by every page. be careful of changes; DATE:2014-07-05 if (src_len == 0) return Redirect_null_ttl; int bgn = Bry_find_.Find_fwd_while_not_ws(src, 0, src_len); @@ -45,8 +48,8 @@ public class Xop_redirect_mgr { int ttl_bgn = Xop_redirect_mgr_.Get_ttl_bgn_or_neg1(src, kwd_end, src_len); if (ttl_bgn == Bry_find_.Not_found) return Redirect_null_ttl; ttl_bgn += Xop_tkn_.Lnki_bgn.length; - int ttl_end = Bry_find_.Find_fwd(src, Xop_tkn_.Lnki_end, ttl_bgn); - if (ttl_end == Bry_find_.Not_found) return Redirect_null_ttl; + int ttl_end = Bry_find_.Find_fwd(src, Xop_tkn_.Lnki_end, ttl_bgn); if (ttl_end == Bry_find_.Not_found) return Redirect_null_ttl; + int pipe_pos = Bry_find_.Find_fwd(src, Byte_ascii.Pipe, ttl_bgn); if (pipe_pos != Bry_find_.Not_found) ttl_end = pipe_pos; // if pipe exists, end ttl at pipe; PAGE:da.w:Middelaldercentret; DATE:2015-11-06 byte[] redirect_bry = Bry_.Mid(src, ttl_bgn, ttl_end); redirect_bry = url_decoder.Decode(redirect_bry); // NOTE: url-decode links; PAGE: en.w:Watcher_(Buffy_the_Vampire_Slayer); DATE:2014-08-18 return Xoa_ttl.parse(wiki, redirect_bry); @@ -73,7 +76,7 @@ public class Xop_redirect_mgr { if (i != 0) redirect_bfr.Add(Bry_redirect_dlm); byte[] redirect_ttl = (byte[])list.Get_at(i); redirect_bfr.Add(Xoh_consts.A_bgn) // 'd]]" - , fxt.tkn_lnki_().Ns_id_(Xow_ns_.Id_file).Trg_tkn_(fxt.tkn_arg_nde_().Val_tkn_(fxt.tkn_arg_itm_(fxt.tkn_txt_(2, 7), fxt.tkn_colon_(7), fxt.tkn_txt_(8, 9)))) + , fxt.tkn_lnki_().Ns_id_(Xow_ns_.Tid__file).Trg_tkn_(fxt.tkn_arg_nde_().Val_tkn_(fxt.tkn_arg_itm_(fxt.tkn_txt_(2, 7), fxt.tkn_colon_(7), fxt.tkn_txt_(8, 9)))) .Caption_tkn_(fxt.tkn_arg_nde_(10, 17).Val_tkn_(fxt.tkn_arg_itm_(fxt.tkn_txt_(10, 11), fxt.tkn_xnde_(11, 16), fxt.tkn_txt_(16, 17)))) ); } diff --git a/400_xowa/src/gplx/xowa/specials/Xows_special_meta.java b/400_xowa/src/gplx/xowa/specials/Xows_special_meta.java index dee93f10e..889b0b3e2 100644 --- a/400_xowa/src/gplx/xowa/specials/Xows_special_meta.java +++ b/400_xowa/src/gplx/xowa/specials/Xows_special_meta.java @@ -30,6 +30,6 @@ public class Xows_special_meta { public String Ttl_str() {return ttl_str;} private final String ttl_str; public byte[] Ttl_bry() {return ttl_bry;} private final byte[] ttl_bry; public boolean Match_ttl(Xoa_ttl ttl) { - return ttl.Ns().Id_special() && Bry_.Eq(ttl.Root_txt(), key_bry); + return ttl.Ns().Id_is_special() && Bry_.Eq(ttl.Root_txt(), key_bry); } } diff --git a/400_xowa/src/gplx/xowa/specials/allPages/Xows_page_allpages.java b/400_xowa/src/gplx/xowa/specials/allPages/Xows_page_allpages.java index d3f14ab4a..39de8adec 100644 --- a/400_xowa/src/gplx/xowa/specials/allPages/Xows_page_allpages.java +++ b/400_xowa/src/gplx/xowa/specials/allPages/Xows_page_allpages.java @@ -98,7 +98,7 @@ public class Xows_page_allpages implements GfoInvkAble, Bry_fmtr_arg, Xows_page rslt_list_len = 0; rslt_nxt = rslt_prv = null; Xoa_ttl from_ttl = Xoa_ttl.parse(wiki, from_val); if (from_ttl == null) return false; - if (!from_ttl.Ns().Id_main()) { // ns specified in title + if (!from_ttl.Ns().Id_is_main()) { // ns specified in title init_ns = from_ttl.Ns(); arg_hash.Set_val_by_int(Bry_arg_ns, init_ns.Id()); arg_hash.Set_val_by_bry(Bry_arg_from, from_ttl.Page_db()); @@ -140,7 +140,7 @@ public class Xows_page_allpages implements GfoInvkAble, Bry_fmtr_arg, Xows_page } public static Xoa_ttl ttl_(Xowe_wiki wiki, Xow_ns ns, Xowd_page_itm itm) { byte[] ttl_bry = itm.Ttl_page_db(); - if (!ns.Id_main()) ttl_bry = Bry_.Add(ns.Name_db_w_colon(), ttl_bry); + if (!ns.Id_is_main()) ttl_bry = Bry_.Add(ns.Name_db_w_colon(), ttl_bry); return Xoa_ttl.parse(wiki, ttl_bry); } public void Fmt__do(Bry_bfr bfr) { diff --git a/400_xowa/src/gplx/xowa/specials/movePage/Move_page.java b/400_xowa/src/gplx/xowa/specials/movePage/Move_page.java index 0bf7cb842..88c1311a3 100644 --- a/400_xowa/src/gplx/xowa/specials/movePage/Move_page.java +++ b/400_xowa/src/gplx/xowa/specials/movePage/Move_page.java @@ -133,7 +133,7 @@ class Move_trg_ns_list_fmtr implements Bry_fmtr_arg { Xow_ns ns = ns_mgr.Ids_get_at(i); if (ns.Is_meta()) continue; // ignore [[Special:]] and [[Media:]] byte[] bry_selected = ttl.Ns().Id() == ns.Id() ? Bry_selected : Bry_.Empty; - fmtr.Bld_bfr_many(bfr, ns.Id(), bry_selected, ns.Name_ui()); + fmtr.Bld_bfr_many(bfr, ns.Id(), bry_selected, ns.Name_combo()); } } private static final byte[] Bry_selected = Bry_.new_a7(" selected=''"); diff --git a/400_xowa/src/gplx/xowa/specials/search/Xog_search_suggest_mgr.java b/400_xowa/src/gplx/xowa/specials/search/Xog_search_suggest_mgr.java index b9b073c0f..08902e63c 100644 --- a/400_xowa/src/gplx/xowa/specials/search/Xog_search_suggest_mgr.java +++ b/400_xowa/src/gplx/xowa/specials/search/Xog_search_suggest_mgr.java @@ -41,7 +41,7 @@ public class Xog_search_suggest_mgr implements GfoInvkAble { args_default = tmp_url.Qargs(); } private String args_default_str = "";// default args for search - public static final int[] Ns_default_main = new int[] {Xow_ns_.Id_main}; + public static final int[] Ns_default_main = new int[] {Xow_ns_.Tid__main}; public void Cancel() { cur_cmd.Cancel(); long prv_time = Env_.TickCount(); diff --git a/400_xowa/src/gplx/xowa/specials/search/Xosrh_core_tst.java b/400_xowa/src/gplx/xowa/specials/search/Xosrh_core_tst.java index f84680758..90c65327a 100644 --- a/400_xowa/src/gplx/xowa/specials/search/Xosrh_core_tst.java +++ b/400_xowa/src/gplx/xowa/specials/search/Xosrh_core_tst.java @@ -101,7 +101,7 @@ public class Xosrh_core_tst { // public Xobl_regy_itm regy_itm_(int id, String bgn, String end, int count) {return new Xobl_regy_itm(id, Bry_.new_u8(bgn), Bry_.new_u8(end), count);} // public Xowd_page_itm data_ttl_(int id, String ttl) {return data_ttl_(id, 0, 0, false, 0, ttl);} // public Xowd_page_itm data_ttl_(int id, int fil, int row, boolean redirect, int len, String ttl) {return new Xowd_page_itm().Init(id, Bry_.new_u8(ttl), redirect, len, fil, row);} -// public Xowd_page_itm data_id_(int id, String ttl) {return data_id_(id, Xow_ns_.Id_main, ttl);} +// public Xowd_page_itm data_id_(int id, String ttl) {return data_id_(id, Xow_ns_.Tid__main, ttl);} // public Xowd_page_itm data_id_(int id, int ns, String ttl) {return new Xowd_page_itm().Id_(id).Ns_id_(ns).Ttl_page_db_(Bry_.new_u8(ttl)).Text_db_id_(0).Text_len_(0);} // public Xobl_search_ttl data_sttl_(String word, params int[] ids) {return new Xobl_search_ttl(Bry_.new_u8(word), data_ttl_word_page_ary_(ids));} // public Xobl_search_ttl_page[] data_ttl_word_page_ary_(params int[] ids) { @@ -135,7 +135,7 @@ public class Xosrh_core_tst { // } // public void Init_basic() { // this.Init_regy_ns(wiki.Ns_mgr().Ns_main().Num_str(), Xotdb_dir_info_.Tid_search_ttl, this.regy_itm_(0, "A", "C", 5)); -// this.Init_data(wiki.Tdb_fsys_mgr().Url_ns_fil(Xotdb_dir_info_.Tid_search_ttl, Xow_ns_.Id_main, 0) +// this.Init_data(wiki.Tdb_fsys_mgr().Url_ns_fil(Xotdb_dir_info_.Tid_search_ttl, Xow_ns_.Tid__main, 0) // , this.data_sttl_("a" , 0) // , this.data_sttl_("b1" , 1, 11, 21) // , this.data_sttl_("b2" , 2, 12, 22) diff --git a/400_xowa/src/gplx/xowa/specials/search/Xosrh_page_mgr_tst.java b/400_xowa/src/gplx/xowa/specials/search/Xosrh_page_mgr_tst.java index 801c44f63..1724b9200 100644 --- a/400_xowa/src/gplx/xowa/specials/search/Xosrh_page_mgr_tst.java +++ b/400_xowa/src/gplx/xowa/specials/search/Xosrh_page_mgr_tst.java @@ -47,7 +47,7 @@ class Xosrh_page_mgr_fxt { for (int i = bgn; i < end; i++) { byte[] id_bry = new byte[5]; // NOTE: do not reuse; will break hive_mgr Base85_.Set_bry(i, id_bry, 0, 5); - tmp_itm.Ns_id_(Xow_ns_.Id_main).Init(i, Bry_.To_a7_bry(i, 0), false, 10, 0, i - bgn); + tmp_itm.Ns_id_(Xow_ns_.Tid__main).Init(i, Bry_.To_a7_bry(i, 0), false, 10, 0, i - bgn); Xotdb_page_itm_.Txt_id_save(tmp_bfr, tmp_itm); hive_mgr.Create(id_bry, tmp_bfr.To_bry_and_clear(), null); } diff --git a/400_xowa/src/gplx/xowa/specials/search/Xows_ns_mgr.java b/400_xowa/src/gplx/xowa/specials/search/Xows_ns_mgr.java index da6cf6912..d1bca0b3d 100644 --- a/400_xowa/src/gplx/xowa/specials/search/Xows_ns_mgr.java +++ b/400_xowa/src/gplx/xowa/specials/search/Xows_ns_mgr.java @@ -27,7 +27,7 @@ public class Xows_ns_mgr { } public boolean Has(int ns_id) { return ns_all // all flag set - || ns_main && ns_id == Xow_ns_.Id_main // main flag set + || ns_main && ns_id == Xow_ns_.Tid__main // main flag set || ns_hash.Has(tmp_ns_id.Val_(ns_id)) // check against ns_hash ; } @@ -37,8 +37,8 @@ public class Xows_ns_mgr { ns_hash.Add_as_key_and_val(Int_obj_ref.new_(ns_id)); } public void Add_by_name(byte[] ns_name) { - int id = Xow_ns_.Canonical_id(ns_name); - if (id != Xow_ns_.Id_null) + int id = Xow_ns_canonical_.To_id(ns_name); + if (id != Xow_ns_.Tid__null) Add_by_id(id); } public void Add_all() { diff --git a/400_xowa/src/gplx/xowa/specials/search/Xows_paging_parser.java b/400_xowa/src/gplx/xowa/specials/search/Xows_paging_parser.java index fc7e23653..2e2538581 100644 --- a/400_xowa/src/gplx/xowa/specials/search/Xows_paging_parser.java +++ b/400_xowa/src/gplx/xowa/specials/search/Xows_paging_parser.java @@ -19,7 +19,7 @@ package gplx.xowa.specials.search; import gplx.*; import gplx.xowa.*; import gpl import gplx.core.brys.*; class Xows_paging_parser { private final List_adp itm_list = List_adp_.new_(); - private final Bry_rdr rdr = new Bry_rdr(); + private final Bry_rdr_old rdr = new Bry_rdr_old(); public Xows_paging_itm[] Parse(byte[] raw) { // EX: en.wikipedia.org|41|60;en.wiktionary.org|21|40; rdr.Init(raw); while (!rdr.Pos_is_eos()) { diff --git a/400_xowa/src/gplx/xowa/specials/statistics/Xop_statistics_page.java b/400_xowa/src/gplx/xowa/specials/statistics/Xop_statistics_page.java index bd839d2b7..4e5987610 100644 --- a/400_xowa/src/gplx/xowa/specials/statistics/Xop_statistics_page.java +++ b/400_xowa/src/gplx/xowa/specials/statistics/Xop_statistics_page.java @@ -91,7 +91,7 @@ class Xop_statistics_stats_ns_itm implements Bry_fmtr_arg { Xow_ns ns = ns_mgr.Ids_get_at(i); if (ns.Is_meta()) continue; if (ns.Count() == 0) continue; - byte[] ns_name = ns.Id_main() ? wiki.Msg_mgr().Val_by_id(Xol_msg_itm_.Id_ns_blankns) : ns.Name_txt(); + byte[] ns_name = ns.Id_is_main() ? wiki.Msg_mgr().Val_by_id(Xol_msg_itm_.Id_ns_blankns) : ns.Name_ui(); fmtr_ns_itm.Bld_bfr_many(bfr, ns_name, wiki.Lang().Num_mgr().Format_num(ns.Count())); } } diff --git a/400_xowa/src/gplx/xowa/specials/xowa/popup_history/Popup_history_page.java b/400_xowa/src/gplx/xowa/specials/xowa/popup_history/Popup_history_page.java index ab309ed92..06af85714 100644 --- a/400_xowa/src/gplx/xowa/specials/xowa/popup_history/Popup_history_page.java +++ b/400_xowa/src/gplx/xowa/specials/xowa/popup_history/Popup_history_page.java @@ -34,7 +34,7 @@ public class Popup_history_page implements Xows_page { } private Bry_fmtr fmtr_main = Bry_fmtr.new_("~{ttl}\n\n", "href", "ttl"); // NOTE: need to use anchor (as opposed to lnki or lnke) b/c xwiki will not work on all wikis public static boolean Ttl_chk(Xoa_ttl ttl) { - return ttl.Ns().Id_special() + return ttl.Ns().Id_is_special() && Bry_.Eq(ttl.Page_db(), Xows_special_meta_.Itm__popup_history.Key_bry()); } } diff --git a/400_xowa/src/gplx/xowa/users/Xou_user_.java b/400_xowa/src/gplx/xowa/users/Xou_user_.java index ce6ae03ed..64204ed8c 100644 --- a/400_xowa/src/gplx/xowa/users/Xou_user_.java +++ b/400_xowa/src/gplx/xowa/users/Xou_user_.java @@ -16,7 +16,7 @@ You should have received a copy of the GNU Affero General Public License along with this program. If not, see . */ package gplx.xowa.users; import gplx.*; import gplx.xowa.*; -import gplx.xowa.langs.*; import gplx.xowa.langs.cases.*; import gplx.xowa.wikis.*; import gplx.xowa.xtns.scribunto.*; +import gplx.xowa.langs.*; import gplx.xowa.langs.cases.*; import gplx.xowa.wikis.*; import gplx.xowa.wikis.nss.*; import gplx.xowa.wikis.domains.*; class Xou_user_ { @@ -57,7 +57,7 @@ class Xou_user_ { .Add_new(12, "Help").Add_new(13, "Help talk").Add_new(14, "Category").Add_new(15, "Category talk").Add_new(100, "Portal").Add_new(101, "Portal talk") .Add_new(gplx.xowa.xtns.wdatas.Wdata_wiki_mgr.Ns_property, gplx.xowa.xtns.wdatas.Wdata_wiki_mgr.Ns_property_name) .Add_new(730, "Data").Add_new(731, "Data talk") - .Add_new(Scrib_xtn_mgr.Ns_id_module, Scrib_xtn_mgr.Ns_name_module).Add_new(Scrib_xtn_mgr.Ns_id_module_talk, Scrib_xtn_mgr.Ns_name_module_talk) + .Add_new(Xow_ns_.Tid__module, Xow_ns_.Key__module).Add_new(Xow_ns_.Tid__module_talk, Xow_ns_.Key__module_talk) .Add_defaults() ; rv.Init(); diff --git a/400_xowa/src/gplx/xowa/users/history/Xoud_history_mgr.java b/400_xowa/src/gplx/xowa/users/history/Xoud_history_mgr.java index 0d4ff0163..4cd4cf5f2 100644 --- a/400_xowa/src/gplx/xowa/users/history/Xoud_history_mgr.java +++ b/400_xowa/src/gplx/xowa/users/history/Xoud_history_mgr.java @@ -46,7 +46,7 @@ public class Xoud_history_mgr implements GfoInvkAble { } private static final String Invk_update = "update"; public static boolean Skip_history(Xoa_ttl ttl) { byte[] page_db = ttl.Page_db(); - return ( ttl.Ns().Id_special() + return ( ttl.Ns().Id_is_special() && ( Bry_.Eq(page_db, gplx.xowa.users.history.Xou_history_mgr.Ttl_name) // do not add XowaPageHistory to history || Bry_.Eq(page_db, Xows_special_meta_.Itm__popup_history.Key_bry()) || Bry_.Eq(page_db, Xows_special_meta_.Itm__default_tab.Key_bry()) diff --git a/400_xowa/src/gplx/xowa/wikis/Xow_page_tid.java b/400_xowa/src/gplx/xowa/wikis/Xow_page_tid.java index 9f110e18d..0af366c18 100644 --- a/400_xowa/src/gplx/xowa/wikis/Xow_page_tid.java +++ b/400_xowa/src/gplx/xowa/wikis/Xow_page_tid.java @@ -21,10 +21,10 @@ import gplx.xowa.xtns.wdatas.*; public class Xow_page_tid { public static byte Identify(int wiki_tid, int ns_id, byte[] ttl) { switch (ns_id) { - case Xow_ns_.Id_mediawiki: - case Xow_ns_.Id_user: + case Xow_ns_.Tid__mediawiki: + case Xow_ns_.Tid__user: return Identify_by_ttl(ttl); - case gplx.xowa.xtns.scribunto.Scrib_xtn_mgr.Ns_id_module: + case Xow_ns_.Tid__module: return (Bry_.Has_at_end(ttl, Ext_doc)) ? Tid_wikitext : Tid_lua; default: diff --git a/400_xowa/src/gplx/xowa/wikis/Xowv_wiki.java b/400_xowa/src/gplx/xowa/wikis/Xowv_wiki.java index a4853ff46..475e652ea 100644 --- a/400_xowa/src/gplx/xowa/wikis/Xowv_wiki.java +++ b/400_xowa/src/gplx/xowa/wikis/Xowv_wiki.java @@ -98,7 +98,7 @@ public class Xowv_wiki implements Xow_wiki, Xow_ttl_parser, GfoInvkAble { } public void Pages_get(Xoh_page rv, Gfo_url url, Xoa_ttl ttl) { if (init_needed) Init_by_wiki(); - if (ttl.Ns().Id_special()) + if (ttl.Ns().Id_is_special()) special_mgr.Get_by_ttl(rv, url, ttl); else html__hdump_mgr.Load_mgr().Load(rv, ttl); diff --git a/400_xowa/src/gplx/xowa/wikis/ctgs/Xoctg_html_mgr.java b/400_xowa/src/gplx/xowa/wikis/ctgs/Xoctg_html_mgr.java index 452cc96bf..489fe7120 100644 --- a/400_xowa/src/gplx/xowa/wikis/ctgs/Xoctg_html_mgr.java +++ b/400_xowa/src/gplx/xowa/wikis/ctgs/Xoctg_html_mgr.java @@ -95,7 +95,7 @@ public class Xoctg_html_mgr implements GfoInvkAble { Xow_msg_mgr msg_mgr = wiki.Msg_mgr(); byte[] all_label = msg_mgr.Val_by_id_args(fmtr_all.Msg_id_label(), view_ctg.Name()); byte[] all_stats = msg_mgr.Val_by_id_args(fmtr_all.Msg_id_stats(), view_grp.Len(), view_grp.Total()); - Xoa_ttl ctg_ttl = Xoa_ttl.parse(wiki, Xow_ns_.Id_category, view_ctg.Name()); + Xoa_ttl ctg_ttl = Xoa_ttl.parse(wiki, Xow_ns_.Tid__category, view_ctg.Name()); byte[] all_navs = fmtr_all.Bld_bwd_fwd(wiki, ctg_ttl, view_grp); fmtr_grp.Init_from_all(wiki, lang, view_ctg, fmtr_all, view_grp); fmtr_all.Html_all().Bld_bfr_many(bfr, fmtr_all.Div_id(), all_label, all_stats, all_navs, lang.Key_bry(), lang.Dir_ltr_bry(), fmtr_grp); diff --git a/400_xowa/src/gplx/xowa/wikis/ctgs/Xoctg_pagelist_itms.java b/400_xowa/src/gplx/xowa/wikis/ctgs/Xoctg_pagelist_itms.java index a8557c7b3..bee599c0f 100644 --- a/400_xowa/src/gplx/xowa/wikis/ctgs/Xoctg_pagelist_itms.java +++ b/400_xowa/src/gplx/xowa/wikis/ctgs/Xoctg_pagelist_itms.java @@ -33,7 +33,7 @@ public class Xoctg_pagelist_itms implements Bry_fmtr_arg { int len = itms.Count(); for (int i = 0; i < len; i++) { Xowd_page_itm page = (Xowd_page_itm)itms.Get_at(i); - Xoa_ttl ttl = Xoa_ttl.parse(wiki, Xow_ns_.Id_category, page.Ttl_page_db()); + Xoa_ttl ttl = Xoa_ttl.parse(wiki, Xow_ns_.Tid__category, page.Ttl_page_db()); byte[] lnki_cls = Xoh_lnki_wtr.Lnki_cls_visited(history_mgr, wiki.Domain_bry(), ttl.Page_txt()); // NOTE: must be ttl.Page_txt() in order to match Xou_history_mgr.Add byte[] lnki_href = href_wtr.Build_to_bry(wiki, ttl); byte[] lnki_ttl = ttl.Full_txt(); diff --git a/400_xowa/src/gplx/xowa/wikis/data/Xow_data_mgr.java b/400_xowa/src/gplx/xowa/wikis/data/Xow_data_mgr.java index 9d351331c..ecba06fa3 100644 --- a/400_xowa/src/gplx/xowa/wikis/data/Xow_data_mgr.java +++ b/400_xowa/src/gplx/xowa/wikis/data/Xow_data_mgr.java @@ -39,10 +39,10 @@ public class Xow_data_mgr implements GfoInvkAble { rv.Url_(url); // NOTE: must update page.Url(); should combine with Xoae_page.new_() Xow_ns ns = ttl.Ns(); switch (ns.Id()) { - case Xow_ns_.Id_special: + case Xow_ns_.Tid__special: wiki.Special_mgr().Special_gen(wiki, rv, url, ttl); return rv; - case Xow_ns_.Id_mediawiki: + case Xow_ns_.Tid__mediawiki: if ( !called_from_msg // if called from msg, fall through to actual data retrieval below, else infinite loop; DATE:2014-05-09 && Xow_page_tid.Identify_by_ttl(ttl.Page_db()) == Xow_page_tid.Tid_wikitext // skip ".js" and ".css" pages in MediaWiki; DATE:2014-06-13 ) { @@ -57,7 +57,7 @@ public class Xow_data_mgr implements GfoInvkAble { } break; } - return Get_page(rv, ns, ttl, called_from_tmpl, url.Qargs_mgr().Match(Xoa_url_.Qarg__redirect,Xoa_url_.Qarg__redirect__yes)); + return Get_page(rv, ns, ttl, called_from_tmpl, url.Qargs_mgr().Match(Xoa_url_.Qarg__redirect, Xoa_url_.Qarg__redirect__no)); } public Xoae_page Get_page(Xoae_page rv, Xow_ns ns, Xoa_ttl ttl, boolean called_from_tmpl, boolean redirect_force) { int redirects = 0; @@ -71,7 +71,7 @@ public class Xow_data_mgr implements GfoInvkAble { byte[] bry = db_page.Text(); rv.Data_raw_(bry).Revision_data().Modified_on_(db_page.Modified_on()).Id_(db_page.Id()).Html_db_id_(db_page.Html_db_id()); if (redirect_force) return rv; - Xoa_ttl redirect_ttl = redirect_mgr.Extract_redirect(bry, bry.length); + Xoa_ttl redirect_ttl = redirect_mgr.Extract_redirect(bry); if ( redirect_ttl == null // not a redirect || redirects++ > 4) // too many redirects; something went wrong break; @@ -101,7 +101,7 @@ public class Xow_data_mgr implements GfoInvkAble { } } if (vnt_missing) { - if (ttl.Ns().Id_file()) { + if (ttl.Ns().Id_is_file()) { Xowe_wiki commons_wiki = wiki.Appe().Wiki_mgr().Get_by_key_or_null(wiki.Commons_wiki_key()); if (commons_wiki != null) { // commons exists if (!Bry_.Eq(wiki.Domain_bry(), commons_wiki.Domain_bry())) { // !Bry_.Eq is recursion guard @@ -133,7 +133,7 @@ public class Xow_data_mgr implements GfoInvkAble { Xoa_ttl trg_ttl = Xoa_ttl.parse(wiki, page_bry); Xoa_url trg_url = Xoa_url.new_(wiki.Domain_bry(), page_bry); page.Ttl_(trg_ttl).Url_(trg_url).Redirected_(true); - return wiki.Data_mgr().Get_page(page, trg_ttl.Ns(), trg_ttl, false, trg_url.Qargs_mgr().Match(Xoa_url_.Qarg__redirect, Xoa_url_.Qarg__redirect__yes)); + return wiki.Data_mgr().Get_page(page, trg_ttl.Ns(), trg_ttl, false, trg_url.Qargs_mgr().Match(Xoa_url_.Qarg__redirect, Xoa_url_.Qarg__redirect__no)); } public static final int File_idx_unknown = -1; static final String GRP_KEY = "xowa.wiki.data"; diff --git a/400_xowa/src/gplx/xowa/wikis/data/Xow_data_mgr_tst.java b/400_xowa/src/gplx/xowa/wikis/data/Xow_data_mgr_tst.java index 1d6a0061b..63a22f9a9 100644 --- a/400_xowa/src/gplx/xowa/wikis/data/Xow_data_mgr_tst.java +++ b/400_xowa/src/gplx/xowa/wikis/data/Xow_data_mgr_tst.java @@ -62,7 +62,7 @@ public class Xow_data_mgr_tst { ; } @Test public void Update_zip() { -// fxt.Wiki().Fsys_mgr().Dir_regy()[Xow_ns_.Id_main].Ext_tid_(gplx.core.ios.Io_stream_.Tid_zip); +// fxt.Wiki().Fsys_mgr().Dir_regy()[Xow_ns_.Tid__main].Ext_tid_(gplx.core.ios.Io_stream_.Tid_zip); // fxt.Wiki().Data_mgr().Zip_mgr_(new Io_zip_mgr_mok()); // fxt .Create("A1", "A1 data") // .Create("B12", "B12 data") @@ -154,8 +154,8 @@ class Xow_data_mgr_fxt { Tfds.Eq_str_lines(expd, Io_mgr.Instance.LoadFilStr(file_orig)); return this; } - public Xow_data_mgr_fxt Tst_data_page(String expd) {return Tst_data(Xotdb_dir_info_.Tid_page , Xow_ns_.Id_main, 0, expd);} - public Xow_data_mgr_fxt Tst_data_title(String expd) {return Tst_data(Xotdb_dir_info_.Tid_ttl, Xow_ns_.Id_main, 0, expd);} + public Xow_data_mgr_fxt Tst_data_page(String expd) {return Tst_data(Xotdb_dir_info_.Tid_page , Xow_ns_.Tid__main, 0, expd);} + public Xow_data_mgr_fxt Tst_data_title(String expd) {return Tst_data(Xotdb_dir_info_.Tid_ttl, Xow_ns_.Tid__main, 0, expd);} public Xow_data_mgr_fxt Tst_data(byte dir_tid, int ns_id, int fil, String expd) { Io_url url = wiki.Tdb_fsys_mgr().Url_ns_fil(dir_tid, ns_id, fil); Tfds.Eq_str_lines(expd, Io_mgr.Instance.LoadFilStr(url)); diff --git a/400_xowa/src/gplx/xowa/wikis/data/tbls/Xowd_page_itm.java b/400_xowa/src/gplx/xowa/wikis/data/tbls/Xowd_page_itm.java index 6eb1eb7d8..770f0919d 100644 --- a/400_xowa/src/gplx/xowa/wikis/data/tbls/Xowd_page_itm.java +++ b/400_xowa/src/gplx/xowa/wikis/data/tbls/Xowd_page_itm.java @@ -85,7 +85,7 @@ public class Xowd_page_itm { } else { ns = (Xow_ns)o; - ttl_page_db = Bry_.Mid(v, ns.Name_txt_w_colon().length, v.length); // EX: "Template:A" -> "Template:" + "A" + ttl_page_db = Bry_.Mid(v, ns.Name_ui_w_colon().length, v.length); // EX: "Template:A" -> "Template:" + "A" } ns_id = ns.Id(); return this; diff --git a/400_xowa/src/gplx/xowa/wikis/data/tbls/Xowd_page_itm_tst.java b/400_xowa/src/gplx/xowa/wikis/data/tbls/Xowd_page_itm_tst.java index 581edea22..aa3819c64 100644 --- a/400_xowa/src/gplx/xowa/wikis/data/tbls/Xowd_page_itm_tst.java +++ b/400_xowa/src/gplx/xowa/wikis/data/tbls/Xowd_page_itm_tst.java @@ -20,16 +20,16 @@ import org.junit.*; import gplx.xowa.wikis.data.tbls.*; import gplx.xowa.wikis.n public class Xowd_page_itm_tst { @Before public void init() {fxt.Init();} private Xowd_page_itm_fxt fxt = new Xowd_page_itm_fxt(); @Test public void Ttl_() { - fxt.Test_ttl_("User_talk:A", Xow_ns_.Id_user_talk, "A"); - fxt.Test_ttl_("User talk:A", Xow_ns_.Id_user_talk, "A"); + fxt.Test_ttl_("User_talk:A", Xow_ns_.Tid__user_talk, "A"); + fxt.Test_ttl_("User talk:A", Xow_ns_.Tid__user_talk, "A"); } } class Xowd_page_itm_fxt { public void Init() { if (ns_mgr == null) { ns_mgr = new Xow_ns_mgr(gplx.xowa.langs.cases.Xol_case_mgr_.A7()); - ns_mgr.Add_new(Xow_ns_.Id_main, ""); - ns_mgr.Add_new(Xow_ns_.Id_user_talk, "User talk"); + ns_mgr.Add_new(Xow_ns_.Tid__main, ""); + ns_mgr.Add_new(Xow_ns_.Tid__user_talk, "User talk"); ns_mgr.Init_w_defaults(); tmp_page = new Xowd_page_itm(); } diff --git a/400_xowa/src/gplx/xowa/wikis/data/tbls/Xowd_page_tbl.java b/400_xowa/src/gplx/xowa/wikis/data/tbls/Xowd_page_tbl.java index 6610ebaad..7c0d1c29c 100644 --- a/400_xowa/src/gplx/xowa/wikis/data/tbls/Xowd_page_tbl.java +++ b/400_xowa/src/gplx/xowa/wikis/data/tbls/Xowd_page_tbl.java @@ -167,10 +167,10 @@ public class Xowd_page_tbl implements RlsAble { } public void Select_by_search(Cancelable cancelable, List_adp rv, byte[] search, int results_max) { if (Bry_.Len_eq_0(search)) return; // do not allow empty search - Criteria crt = Criteria_.And_many(Db_crt_.eq_(fld_ns, Xow_ns_.Id_main), Db_crt_.like_(fld_title, "")); + Criteria crt = Criteria_.And_many(Db_crt_.eq_(fld_ns, Xow_ns_.Tid__main), Db_crt_.like_(fld_title, "")); Db_qry__select_cmd qry = Db_qry_.select_().From_(tbl_name).Cols_(fld_id, fld_len, fld_ns, fld_title).Where_(crt); // NOTE: use fields from main index only search = Bry_.Replace(search, Byte_ascii.Star, Byte_ascii.Percent); - Db_rdr rdr = conn.Stmt_new(qry).Clear().Crt_int(fld_ns, Xow_ns_.Id_main).Val_bry_as_str(fld_title, search).Exec_select__rls_auto(); + Db_rdr rdr = conn.Stmt_new(qry).Clear().Crt_int(fld_ns, Xow_ns_.Tid__main).Val_bry_as_str(fld_title, search).Exec_select__rls_auto(); try { while (rdr.Move_next()) { if (cancelable.Canceled()) return; diff --git a/400_xowa/src/gplx/xowa/wikis/data/tbls/Xowd_site_ns_tbl.java b/400_xowa/src/gplx/xowa/wikis/data/tbls/Xowd_site_ns_tbl.java index ad7c2c344..b70499c5a 100644 --- a/400_xowa/src/gplx/xowa/wikis/data/tbls/Xowd_site_ns_tbl.java +++ b/400_xowa/src/gplx/xowa/wikis/data/tbls/Xowd_site_ns_tbl.java @@ -39,7 +39,7 @@ public class Xowd_site_ns_tbl { Xow_ns ns = ns_mgr.Ids_get_at(i); stmt.Clear() .Val_int(fld_id, ns.Id()) - .Val_str(fld_name, ns.Name_str()) + .Val_str(fld_name, ns.Name_db_str()) .Val_byte(fld_case, ns.Case_match()) .Val_bool_as_byte(fld_is_alias, ns.Is_alias()) .Val_int(fld_count, ns.Count()) diff --git a/400_xowa/src/gplx/xowa/wikis/data/tbls/Xowd_text_tbl.java b/400_xowa/src/gplx/xowa/wikis/data/tbls/Xowd_text_tbl.java index 1fb14ae26..c97d48d02 100644 --- a/400_xowa/src/gplx/xowa/wikis/data/tbls/Xowd_text_tbl.java +++ b/400_xowa/src/gplx/xowa/wikis/data/tbls/Xowd_text_tbl.java @@ -47,6 +47,7 @@ public class Xowd_text_tbl implements RlsAble { Db_rdr rdr = stmt_select.Clear().Val_int(fld_page_id, page_id).Exec_select__rls_manual(); try { byte[] rv = (byte[])rdr.Read_bry(fld_text_data); + if (rv == null) rv = Bry_.Empty; // NOTE: defect wherein blank page inserts null not ""; for now always convert nul to empty String; DATE:2015-11-08 rv = zip_mgr.Unzip(zip_tid, rv); return rv; } finally {rdr.Rls();} diff --git a/400_xowa/src/gplx/xowa/wikis/data/tbls/Xowd_wbase_qid_tbl_tst.java b/400_xowa/src/gplx/xowa/wikis/data/tbls/Xowd_wbase_qid_tbl_tst.java index b0c3277f8..c7db58612 100644 --- a/400_xowa/src/gplx/xowa/wikis/data/tbls/Xowd_wbase_qid_tbl_tst.java +++ b/400_xowa/src/gplx/xowa/wikis/data/tbls/Xowd_wbase_qid_tbl_tst.java @@ -22,9 +22,9 @@ public class Xowd_wbase_qid_tbl_tst { private final Xowd_wbase_qid_tbl_fxt fxt = new Xowd_wbase_qid_tbl_fxt(); @Before public void init() {fxt.Clear();} @Test public void Space() { - fxt.Exec_insert("enwiki", Xow_ns_.Id_main, "A B", "q1"); - fxt.Test_select("enwiki", Xow_ns_.Id_main, "A B", "q1"); - fxt.Test_select("enwiki", Xow_ns_.Id_main, "A_B", "q1"); + fxt.Exec_insert("enwiki", Xow_ns_.Tid__main, "A B", "q1"); + fxt.Test_select("enwiki", Xow_ns_.Tid__main, "A B", "q1"); + fxt.Test_select("enwiki", Xow_ns_.Tid__main, "A_B", "q1"); } } class Xowd_wbase_qid_tbl_fxt { diff --git a/400_xowa/src/gplx/xowa/wikis/dbs/Xodb_load_mgr_sql.java b/400_xowa/src/gplx/xowa/wikis/dbs/Xodb_load_mgr_sql.java index 1c25f148b..62f9414e8 100644 --- a/400_xowa/src/gplx/xowa/wikis/dbs/Xodb_load_mgr_sql.java +++ b/400_xowa/src/gplx/xowa/wikis/dbs/Xodb_load_mgr_sql.java @@ -64,13 +64,13 @@ public class Xodb_load_mgr_sql implements Xodb_load_mgr { public boolean Load_by_id (Xowd_page_itm rv, int id) {return db_mgr.Core_data_mgr().Tbl__page().Select_by_id(rv, id);} public void Load_by_ids(Cancelable cancelable, List_adp rv, int bgn, int end) {db_mgr.Core_data_mgr().Tbl__page().Select_in__id(cancelable, false, rv, bgn, end);} public boolean Load_ctg_v1(Xoctg_view_ctg rv, byte[] ctg_bry) { - int cat_page_id = db_mgr.Core_data_mgr().Tbl__page().Select_id(Xow_ns_.Id_category, ctg_bry); if (cat_page_id == Xowd_page_itm.Id_null) return false; + int cat_page_id = db_mgr.Core_data_mgr().Tbl__page().Select_id(Xow_ns_.Tid__category, ctg_bry); if (cat_page_id == Xowd_page_itm.Id_null) return false; Xowd_category_itm ctg = fsys_mgr.Db__cat_core().Tbl__cat_core().Select(cat_page_id); if (ctg == Xowd_category_itm.Null) return false; return Ctg_select_v1(db_mgr.Wiki(), db_mgr.Core_data_mgr(), rv, ctg.File_idx(), ctg); } public boolean Load_ctg_v2(Xoctg_data_ctg rv, byte[] ctg_bry) {throw Err_.new_unimplemented();} public void Load_ctg_v2a(Xoctg_view_ctg rv, Xoctg_url ctg_url, byte[] ctg_ttl, int load_max) { - int cat_page_id = db_mgr.Core_data_mgr().Tbl__page().Select_id(Xow_ns_.Id_category, ctg_ttl); if (cat_page_id == Xowd_page_itm.Id_null) return; + int cat_page_id = db_mgr.Core_data_mgr().Tbl__page().Select_id(Xow_ns_.Tid__category, ctg_ttl); if (cat_page_id == Xowd_page_itm.Id_null) return; Xowd_category_itm ctg = fsys_mgr.Db__cat_core().Tbl__cat_core().Select(cat_page_id); if (ctg == Xowd_category_itm.Null) return; List_adp list = List_adp_.new_(); Load_ctg_v2a_db_retrieve(rv, ctg_url, cat_page_id, load_max, ctg.File_idx(), list); @@ -143,7 +143,7 @@ public class Xodb_load_mgr_sql implements Xodb_load_mgr { } public int Load_ctg_count(byte[] ttl) { if (db_mgr.Core_data_mgr().Db__cat_core() == null) return 0; - int page_id = db_mgr.Core_data_mgr().Tbl__page().Select_id(Xow_ns_.Id_category, ttl); + int page_id = db_mgr.Core_data_mgr().Tbl__page().Select_id(Xow_ns_.Tid__category, ttl); if (page_id == Xowd_page_itm.Id_null) return 0; // title not found; return 0; return db_mgr.Core_data_mgr().Db__cat_core().Tbl__cat_core().Select(page_id).Count_all(); } @@ -164,7 +164,7 @@ public class Xodb_load_mgr_sql implements Xodb_load_mgr { hash.Add(ttl, page); } len = hash.Count(); // must update len (!hash.Has() may have skipped titles) - db_mgr.Core_data_mgr().Tbl__page().Select_in__ttl(Cancelable_.Never, hash, Xow_ns_.Id_category, 0, len); + db_mgr.Core_data_mgr().Tbl__page().Select_in__ttl(Cancelable_.Never, hash, Xow_ns_.Tid__category, 0, len); Ordered_hash hash2 = Ordered_hash_.New(); for (int i = 0; i < len; i++) { Xowd_page_itm page = (Xowd_page_itm)hash.Get_at(i); diff --git a/400_xowa/src/gplx/xowa/wikis/dbs/Xodb_load_mgr_sql_tst.java b/400_xowa/src/gplx/xowa/wikis/dbs/Xodb_load_mgr_sql_tst.java index 6897f9869..4cad80493 100644 --- a/400_xowa/src/gplx/xowa/wikis/dbs/Xodb_load_mgr_sql_tst.java +++ b/400_xowa/src/gplx/xowa/wikis/dbs/Xodb_load_mgr_sql_tst.java @@ -53,7 +53,7 @@ class Xodb_load_mgr_sql_fxt { public void Rls() {fxt.Rls();} public Xowd_page_itm[] pages_(Xowd_page_itm... ary) {return ary;} public Xowd_page_itm ctg_(int id, String ttl, boolean hidden, int count_subcs, int count_files, int count_pages) { - Xowd_page_itm rv = new Xowd_page_itm().Ns_id_(Xow_ns_.Id_category).Id_(id).Ttl_page_db_(Bry_.new_a7(ttl)); + Xowd_page_itm rv = new Xowd_page_itm().Ns_id_(Xow_ns_.Tid__category).Id_(id).Ttl_page_db_(Bry_.new_a7(ttl)); Xowd_category_itm ctg = Xowd_category_itm.load_(id, 0, hidden, count_subcs, count_files, count_pages); rv.Xtn_(ctg); return rv; @@ -157,7 +157,7 @@ class Xoctg_mok_ctg { public Xoctg_mok_ctg Grp_pages_(int bgn, int end, String last_itm_plus_one_sortkey) { Xoctg_mok_grp grp = Grps_get_or_new(Xoa_ctg_mgr.Tid_page); byte[] ttl_prefix = Bry_.new_a7("Page_"); - int ns_id = Xow_ns_.Id_main; + int ns_id = Xow_ns_.Tid__main; byte ctg_tid = Xoa_ctg_mgr.Tid_page; for (int i = bgn; i < end; i++) { byte[] ttl = Bry_.Add(ttl_prefix, Bry_.new_a7(Int_.To_str_pad_bgn_zero(i, 3))); diff --git a/400_xowa/src/gplx/xowa/wikis/dbs/Xodb_load_mgr_txt.java b/400_xowa/src/gplx/xowa/wikis/dbs/Xodb_load_mgr_txt.java index 20a4a9047..ef5d5054a 100644 --- a/400_xowa/src/gplx/xowa/wikis/dbs/Xodb_load_mgr_txt.java +++ b/400_xowa/src/gplx/xowa/wikis/dbs/Xodb_load_mgr_txt.java @@ -344,8 +344,8 @@ public class Xodb_load_mgr_txt implements Xodb_load_mgr { } public static byte Load_ctg_v1_tid(int ns_id) { switch (ns_id) { - case Xow_ns_.Id_category: return Xoa_ctg_mgr.Tid_subc; - case Xow_ns_.Id_file: return Xoa_ctg_mgr.Tid_file; + case Xow_ns_.Tid__category: return Xoa_ctg_mgr.Tid_subc; + case Xow_ns_.Tid__file: return Xoa_ctg_mgr.Tid_file; default: return Xoa_ctg_mgr.Tid_page; } } @@ -363,7 +363,7 @@ public class Xodb_load_mgr_txt implements Xodb_load_mgr { byte[] ttl = Bry_.Mid (src, bgn + 12 , ttl_end); byte[] text = Bry_.Mid (src, ttl_end + 1 , itm_end - 1); page.Init_by_tdb(-1, -1, xdat.Itm_idx(), Bool_.N, text.length, ns_id, ttl); - page.Modified_on_(Bit_.Xto_date_short(timestamp)); + page.Modified_on_(Int_flag_bldr_.To_date_short(timestamp)); page.Text_(text); return true; } @@ -372,7 +372,7 @@ public class Xodb_load_mgr_txt implements Xodb_load_mgr { int timestamp_end = timestamp_bgn + 5; if (timestamp_enabled) { int timestamp = Base85_.To_int_by_bry(src, timestamp_bgn, timestamp_end - 1); - page.Modified_on_(Bit_.Xto_date_short(timestamp)); + page.Modified_on_(Int_flag_bldr_.To_date_short(timestamp)); } int name_bgn = timestamp_end + 1; int name_end = Bry_find_.Find_fwd(src, Xotdb_page_itm_.Txt_page_dlm, name_bgn, src_len); diff --git a/400_xowa/src/gplx/xowa/wikis/dbs/Xodb_mgr_txt.java b/400_xowa/src/gplx/xowa/wikis/dbs/Xodb_mgr_txt.java index 976f3281d..19786224c 100644 --- a/400_xowa/src/gplx/xowa/wikis/dbs/Xodb_mgr_txt.java +++ b/400_xowa/src/gplx/xowa/wikis/dbs/Xodb_mgr_txt.java @@ -29,7 +29,7 @@ public class Xodb_mgr_txt implements Xodb_mgr { public Xodb_load_mgr Load_mgr() {return load_mgr;} private Xodb_load_mgr_txt load_mgr; public Xodb_save_mgr Save_mgr() {return save_mgr;} private Xodb_save_mgr_txt save_mgr; public DateAdp Dump_date_query() { - Io_url url = wiki.Tdb_fsys_mgr().Url_ns_fil(Xotdb_dir_info_.Tid_page, Xow_ns_.Id_main, 0); + Io_url url = wiki.Tdb_fsys_mgr().Url_ns_fil(Xotdb_dir_info_.Tid_page, Xow_ns_.Tid__main, 0); return Io_mgr.Instance.QueryFil(url).ModifiedTime(); } public byte Category_version() { diff --git a/400_xowa/src/gplx/xowa/wikis/nss/Xow_ns.java b/400_xowa/src/gplx/xowa/wikis/nss/Xow_ns.java index 0dee7573f..d3c881f00 100644 --- a/400_xowa/src/gplx/xowa/wikis/nss/Xow_ns.java +++ b/400_xowa/src/gplx/xowa/wikis/nss/Xow_ns.java @@ -17,68 +17,69 @@ along with this program. If not, see . */ package gplx.xowa.wikis.nss; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*; import gplx.xowa.bldrs.cmds.*; import gplx.xowa.apps.urls.*; -public class Xow_ns implements GfoInvkAble { +public class Xow_ns implements GfoInvkAble { public Xow_ns(int id, byte case_match, byte[] name, boolean is_alias) { this.id = id; this.case_match = case_match; this.is_alias = is_alias; Name_bry_(name); } public void Name_bry_(byte[] v) { - if (id == Xow_ns_.Id_main) { // NOTE: Main will never prefix titles; EX: "Test" vs "Category:Test" - this.name_str = ""; - this.name_bry = Bry_.Empty; + if (id == Xow_ns_.Tid__main) { // NOTE: Main will never prefix titles; EX: "Test" vs "Category:Test" + this.name_db_str = ""; + this.name_db = Bry_.Empty; this.name_db_w_colon = Bry_.Empty; } else { - this.name_bry = v; + this.name_db = v; this.name_db_w_colon = Bry_.Add(v, Byte_ascii.Colon); - this.name_str = String_.new_u8(v); + this.name_db_str = String_.new_u8(v); } this.num_str = Int_.To_str_pad_bgn_zero(id, 3); this.num_bry = Bry_.new_a7(num_str); - this.name_enc = Xoa_url_encoder.Instance.Encode(name_bry); - this.name_txt = Bry_.Replace(name_enc, Byte_ascii.Underline, Byte_ascii.Space); - this.name_txt_w_colon = Bry_.Replace(name_db_w_colon, Byte_ascii.Underline, Byte_ascii.Space); + this.name_enc = Xoa_url_encoder.Instance.Encode(name_db); + this.name_ui = Bry_.Replace(name_enc, Byte_ascii.Underline, Byte_ascii.Space); + this.name_ui_w_colon = Bry_.Replace(name_db_w_colon, Byte_ascii.Underline, Byte_ascii.Space); } - public byte[] Name_bry() {return name_bry;} private byte[] name_bry; - public String Name_str() {return name_str;} private String name_str; - public byte[] Name_txt() {return name_txt;} private byte[] name_txt; - public byte[] Name_enc() {return name_enc;} private byte[] name_enc; + public boolean Exists() {return exists;} public Xow_ns Exists_(boolean v) {exists = v; return this;} private boolean exists; + public byte[] Name_db() {return name_db;} private byte[] name_db; public byte[] Name_db_w_colon() {return name_db_w_colon;} private byte[] name_db_w_colon; - public byte[] Name_txt_w_colon() {return name_txt_w_colon;} private byte[] name_txt_w_colon; // PERF: for Xoa_ttl - public byte[] Name_ui() {return id == Xow_ns_.Id_main ? Xow_ns_.Name_ui_main : name_txt;} + public String Name_db_str() {return name_db_str;} private String name_db_str; + public byte[] Name_ui() {return name_ui;} private byte[] name_ui; + public byte[] Name_ui_w_colon() {return name_ui_w_colon;} private byte[] name_ui_w_colon; // PERF: for Xoa_ttl + public byte[] Name_enc() {return name_enc;} private byte[] name_enc; + public byte[] Name_combo() {return id == Xow_ns_.Tid__main ? Xow_ns_.Bry__main: name_ui;} // for combo boxes; namely "(Main)" public String Num_str() {return num_str;} private String num_str; public byte[] Num_bry() {return num_bry;} private byte[] num_bry; public int Id() {return id;} private int id; - public int Id_subj_id() {if (id < 0) return id; return Id_talk() ? id - 1 : id;} // id< 0: special/media return themself; REF.MW: Namespace.php|getSubject - public int Id_talk_id() {if (id < 0) return id; return Id_talk() ? id : id + 1;} // REF.MW: Namespace.php|getTalk - public int Id_alt_id() {if (id < 0) return id; return Id_talk() ? Id_subj_id() : Id_talk_id();} // REF.MW: Namespace.php|getTalk - public boolean Id_subj() {return !Id_talk();} // REF.MW: Namespace.php|isMain - public boolean Id_talk() {return id > Xow_ns_.Id_main && id % 2 == 1;} // REF.MW: Namespace.php|isTalk - public boolean Id_file() {return id == Xow_ns_.Id_file;} - public boolean Id_file_or_media() {return id == Xow_ns_.Id_file || id == Xow_ns_.Id_media;} - public boolean Id_tmpl() {return id == Xow_ns_.Id_template;} - public boolean Id_ctg() {return id == Xow_ns_.Id_category;} - public boolean Id_main() {return id == Xow_ns_.Id_main;} - public boolean Id_media() {return id == Xow_ns_.Id_media;} - public boolean Id_special() {return id == Xow_ns_.Id_special;} - public boolean Id_module() {return id == gplx.xowa.xtns.scribunto.Scrib_xtn_mgr.Ns_id_module;} + public int Id_subj_id() {if (id < 0) return id; return Id_is_talk() ? id - 1 : id;} // id< 0: special/media return themself; REF.MW: Namespace.php|getSubject + public int Id_talk_id() {if (id < 0) return id; return Id_is_talk() ? id : id + 1;} // REF.MW: Namespace.php|getTalk + public int Id_alt_id() {if (id < 0) return id; return Id_is_talk() ? Id_subj_id() : Id_talk_id();} // REF.MW: Namespace.php|getTalk + public boolean Id_is_subj() {return !Id_is_talk();} // REF.MW: Namespace.php|isMain + public boolean Id_is_talk() {return id > Xow_ns_.Tid__main && id % 2 == 1;} // REF.MW: Namespace.php|isTalk + public boolean Id_is_media() {return id == Xow_ns_.Tid__media;} + public boolean Id_is_special() {return id == Xow_ns_.Tid__special;} + public boolean Id_is_main() {return id == Xow_ns_.Tid__main;} + public boolean Id_is_file() {return id == Xow_ns_.Tid__file;} + public boolean Id_is_file_or_media() {return id == Xow_ns_.Tid__file || id == Xow_ns_.Tid__media;} + public boolean Id_is_tmpl() {return id == Xow_ns_.Tid__template;} + public boolean Id_is_ctg() {return id == Xow_ns_.Tid__category;} + public boolean Id_is_module() {return id == Xow_ns_.Tid__module;} public int Ord() {return ord;} public void Ord_(int v) {this.ord = v;} private int ord; - public int Ord_subj_id() {if (id < 0) return ord; return Id_talk() ? ord - 1 : ord;} // id< 0: special/media returns self - public int Ord_talk_id() {if (id < 0) return ord; return Id_talk() ? ord : ord + 1;} + public int Ord_subj_id() {if (id < 0) return ord; return Id_is_talk() ? ord - 1 : ord;} // id< 0: special/media returns self + public int Ord_talk_id() {if (id < 0) return ord; return Id_is_talk() ? ord : ord + 1;} public byte Case_match() {return case_match;} public void Case_match_(byte v) {case_match = v;} private byte case_match; - public boolean Subpages_enabled() {return subpages_enabled;} private boolean subpages_enabled = false;// CHANGED: id > Xow_ns_.Id_special; only Special, Media does not have subpages; DATE:2013-10-07 + public boolean Subpages_enabled() {return subpages_enabled;} private boolean subpages_enabled = false;// CHANGED: id > Xow_ns_.Tid__special; only Special, Media does not have subpages; DATE:2013-10-07 public Xow_ns Subpages_enabled_(boolean v) {subpages_enabled = v; return this;} - public boolean Is_gender_aware() {return id == Xow_ns_.Id_user || id == Xow_ns_.Id_user_talk;} // ASSUME: only User, User_talk are gender aware - public boolean Is_capitalized() {return false;} // ASSUME: always false (?) - public boolean Is_content() {return id == Xow_ns_.Id_main;} // ASSUME: only Main - public boolean Is_includable() {return true;} // ASSUME: always true (be transcluded?) - public boolean Is_movable() {return id > Xow_ns_.Id_special;} // ASSUME: only Special, Media cannot move (be renamed?) - public boolean Is_meta() {return id < Xow_ns_.Id_main;} // ASSUME: only Special, Media + public boolean Is_gender_aware() {return id == Xow_ns_.Tid__user || id == Xow_ns_.Tid__user_talk;} // ASSUME: only User, User_talk are gender aware + public boolean Is_capitalized() {return false;} // ASSUME: always false (?) + public boolean Is_content() {return id == Xow_ns_.Tid__main;} // ASSUME: only Main + public boolean Is_includable() {return true;} // ASSUME: always true (be transcluded?) + public boolean Is_movable() {return id > Xow_ns_.Tid__special;} // ASSUME: only Special, Media cannot move (be renamed?) + public boolean Is_meta() {return id < Xow_ns_.Tid__main;} // ASSUME: only Special, Media public boolean Is_alias() {return is_alias;} private boolean is_alias; public int Count() {return count;} public Xow_ns Count_(int v) {count = v; return this;} private int count; - public byte[] Gen_ttl(byte[] page) {return id == Xow_ns_.Id_main ? page : Bry_.Add(name_db_w_colon, page);} + public byte[] Gen_ttl(byte[] page) {return id == Xow_ns_.Tid__main ? page : Bry_.Add(name_db_w_colon, page);} public void Aliases_add(String alias) { - if (String_.Eq(alias, name_str)) return; + if (String_.Eq(alias, name_db_str)) return; if (aliases == null) aliases = Ordered_hash_.New(); aliases.Add_if_dupe_use_1st(alias, alias); } private Ordered_hash aliases; @@ -92,13 +93,12 @@ public class Xow_ns implements GfoInvkAble { } return rv; } - public boolean Exists() {return exists;} public Xow_ns Exists_(boolean v) {exists = v; return this;} private boolean exists; public Xob_ns_file_itm Bldr_data() {return bldr_data;} public void Bldr_data_(Xob_ns_file_itm v) {bldr_data = v;} private Xob_ns_file_itm bldr_data; public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) { if (ctx.Match(k, Invk_subpages_enabled_)) this.subpages_enabled = m.ReadYn("v"); else if (ctx.Match(k, Invk_id)) return id; - else if (ctx.Match(k, Invk_name_txt)) return name_txt; - else if (ctx.Match(k, Invk_name_ui)) return Name_ui(); + else if (ctx.Match(k, Invk_name_txt)) return name_ui; + else if (ctx.Match(k, Invk_name_ui)) return Name_combo(); else return GfoInvkAble_.Rv_unhandled; return this; } private static final String Invk_subpages_enabled_ = "subpages_enabled_", Invk_id = "id", Invk_name_txt = "name_txt", Invk_name_ui = "name_ui"; diff --git a/400_xowa/src/gplx/xowa/wikis/nss/Xow_ns_.java b/400_xowa/src/gplx/xowa/wikis/nss/Xow_ns_.java index 89fabcbd6..cdbbaa268 100644 --- a/400_xowa/src/gplx/xowa/wikis/nss/Xow_ns_.java +++ b/400_xowa/src/gplx/xowa/wikis/nss/Xow_ns_.java @@ -16,74 +16,44 @@ You should have received a copy of the GNU Affero General Public License along with this program. If not, see . */ package gplx.xowa.wikis.nss; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*; -import gplx.core.primitives.*; -public class Xow_ns_ { +public class Xow_ns_ { public static final int // PAGE:en.w:http://www.mediawiki.org/wiki/Help:Namespaces - Id_media = -2 - , Id_special = -1 - , Id_main = 0 , Id_talk = 1 - , Id_user = 2 , Id_user_talk = 3 - , Id_project = 4 , Id_project_talk = 5 - , Id_file = 6 , Id_file_talk = 7 - , Id_mediawiki = 8 , Id_mediaWiki_talk = 9 - , Id_template = 10 , Id_template_talk = 11 - , Id_help = 12 , Id_help_talk = 13 - , Id_category = 14 , Id_category_talk = 15 - , Id_portal = 100 , Id_portal_talk = 101 - , Id_null = Int_.Min_value - ; + Tid__media = -2 + , Tid__special = -1 + , Tid__main = 0 , Tid__talk = 1 + , Tid__user = 2 , Tid__user_talk = 3 + , Tid__project = 4 , Tid__project_talk = 5 + , Tid__file = 6 , Tid__file_talk = 7 + , Tid__mediawiki = 8 , Tid__mediawiki_talk = 9 + , Tid__template = 10 , Tid__template_talk = 11 + , Tid__help = 12 , Tid__help_talk = 13 + , Tid__category = 14 , Tid__category_talk = 15 + , Tid__portal = 100 , Tid__portal_talk = 101 + , Tid__module = 828 , Tid__module_talk = 829 + , Tid__null = Int_.Min_value + ; public static final String - Key_media = "Media" - , Key_special = "Special" - , Key_main = "(Main)" , Key_talk = "Talk" - , Key_user = "User" , Key_user_talk = "User talk" - , Key_project = "Project" , Key_project_talk = "Project talk" - , Key_file = "File" , Key_file_talk = "File talk" - , Key_mediaWiki = "MediaWiki" , Key_mediaWiki_talk = "MediaWiki talk" - , Key_template = "Template" , Key_template_talk = "Template talk" - , Key_help = "Help" , Key_help_talk = "Help talk" - , Key_category = "Category" , Key_category_talk = "Category talk" - , Key_portal = "Portal" , Key_portal_talk = "Portal talk" - , Key_module = "Module" , Key_module_talk = "Module talk" - , Key_null = "null" - ; - public static final byte[] Bry_template = Bry_.new_a7(Key_template); - public static final byte[] Name_ui_main = Bry_.new_a7(Key_main); - public static int Canonical_id(byte[] canonical_name) { - if (canonical_hash == null) { - Xow_ns[] ary = Canonical; - int len = ary.length; - canonical_hash = Ordered_hash_.New_bry(); - for (int i = 0; i < len; i++) { - Xow_ns ns = ary[i]; - canonical_hash.Add(ns.Name_bry(), Int_obj_val.new_(ns.Id())); - } - } - Object rv_obj = canonical_hash.Get_by(canonical_name); - return rv_obj == null ? Xow_ns_.Id_null : ((Int_obj_val)rv_obj).Val(); - } private static Ordered_hash canonical_hash; - public static int Canonical_idx_media = 0; - public static final Xow_ns[] Canonical = new Xow_ns[] // REF.MW: Namespace.php|$wgCanonicalNamespaceNames - { Canonical_new_(Id_media, Key_media) - , Canonical_new_(Id_special, Key_special) - , Canonical_new_(Id_talk, Key_talk) - , Canonical_new_(Id_user, Key_user) - , Canonical_new_(Id_user_talk, Key_user_talk) - , Canonical_new_(Id_project, Key_project) - , Canonical_new_(Id_project_talk, Key_project_talk) - , Canonical_new_(Id_file, Key_file) - , Canonical_new_(Id_file_talk, Key_file_talk) - , Canonical_new_(Id_mediawiki, Key_mediaWiki) - , Canonical_new_(Id_mediaWiki_talk, Key_mediaWiki_talk) - , Canonical_new_(Id_template, Key_template) - , Canonical_new_(Id_template_talk, Key_template_talk) - , Canonical_new_(Id_help, Key_help) - , Canonical_new_(Id_help_talk, Key_help_talk) - , Canonical_new_(Id_category, Key_category) - , Canonical_new_(Id_category_talk, Key_category_talk) - }; - public static final String Ns_name_wikipedia = "Wikipedia"; - public static final byte[] Ns_name_main_bry = Bry_.new_a7(Key_main); - public static final byte[] Ns_prefix_main = Bry_.new_a7("Main:"); - private static Xow_ns Canonical_new_(int id, String name) {return new Xow_ns(id, Xow_ns_case_.Tid__1st, Bry_.new_a7(name), false);} // NOTE: for id/name reference only; case_match and alias does not matter; + Key__media = "Media" + , Key__special = "Special" + , Key__main = "(Main)" , Key__talk = "Talk" + , Key__user = "User" , Key__user_talk = "User talk" + , Key__project = "Project" , Key__project_talk = "Project talk" + , Key__file = "File" , Key__file_talk = "File talk" + , Key__mediawiki = "MediaWiki" , Key__mediawiki_talk = "MediaWiki talk" + , Key__template = "Template" , Key__template_talk = "Template talk" + , Key__help = "Help" , Key__help_talk = "Help talk" + , Key__category = "Category" , Key__category_talk = "Category talk" + , Key__portal = "Portal" , Key__portal_talk = "Portal talk" + , Key__module = "Module" , Key__module_talk = "Module talk" + , Key__null = "null" + , Key__wikipedia = "Wikipedia" + ; + public static final String + Alias__wikipedia = "Wikipedia" + ; + public static final byte[] + Bry__main = Bry_.new_a7(Key__main) + , Bry__file = Bry_.new_a7(Key__file) + , Bry__template = Bry_.new_a7(Key__template) + ; } diff --git a/400_xowa/src/gplx/xowa/wikis/nss/Xow_ns_canonical_.java b/400_xowa/src/gplx/xowa/wikis/nss/Xow_ns_canonical_.java new file mode 100644 index 000000000..3ab3d80bb --- /dev/null +++ b/400_xowa/src/gplx/xowa/wikis/nss/Xow_ns_canonical_.java @@ -0,0 +1,80 @@ +/* +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 . +*/ +package gplx.xowa.wikis.nss; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*; +import gplx.core.primitives.*; +public class Xow_ns_canonical_ { + public static final Xow_ns[] Ary = new Xow_ns[] // REF.MW: Namespace.php|$wgCanonicalNamespaceNames + { New_itm(Xow_ns_.Tid__media , Xow_ns_.Key__media) + , New_itm(Xow_ns_.Tid__special , Xow_ns_.Key__special) + , New_itm(Xow_ns_.Tid__talk , Xow_ns_.Key__talk) + , New_itm(Xow_ns_.Tid__user , Xow_ns_.Key__user) + , New_itm(Xow_ns_.Tid__user_talk , Xow_ns_.Key__user_talk) + , New_itm(Xow_ns_.Tid__project , Xow_ns_.Key__project) + , New_itm(Xow_ns_.Tid__project_talk , Xow_ns_.Key__project_talk) + , New_itm(Xow_ns_.Tid__file , Xow_ns_.Key__file) + , New_itm(Xow_ns_.Tid__file_talk , Xow_ns_.Key__file_talk) + , New_itm(Xow_ns_.Tid__mediawiki , Xow_ns_.Key__mediawiki) + , New_itm(Xow_ns_.Tid__mediawiki_talk , Xow_ns_.Key__mediawiki_talk) + , New_itm(Xow_ns_.Tid__template , Xow_ns_.Key__template) + , New_itm(Xow_ns_.Tid__template_talk , Xow_ns_.Key__template_talk) + , New_itm(Xow_ns_.Tid__help , Xow_ns_.Key__help) + , New_itm(Xow_ns_.Tid__help_talk , Xow_ns_.Key__help_talk) + , New_itm(Xow_ns_.Tid__category , Xow_ns_.Key__category) + , New_itm(Xow_ns_.Tid__category_talk , Xow_ns_.Key__category_talk) + , New_itm(Xow_ns_.Tid__module , Xow_ns_.Key__module) + , New_itm(Xow_ns_.Tid__module_talk , Xow_ns_.Key__module_talk) + }; + private static Xow_ns New_itm(int id, String name) {return new Xow_ns(id, Xow_ns_case_.Tid__1st, Bry_.new_a7(name), false);} // NOTE: for id/name reference only; case_match and alias does not matter; + private static Ordered_hash id_hash; + public static int To_id(byte[] key) { + if (id_hash == null) { + id_hash = Ordered_hash_.New_bry(); + int len = Ary.length; + for (int i = 0; i < len; ++i) { + Xow_ns ns = Ary[i]; + id_hash.Add(ns.Name_db(), Int_obj_val.new_(ns.Id())); + } + } + Object rv_obj = id_hash.Get_by(key); + return rv_obj == null ? Xow_ns_.Tid__null : ((Int_obj_val)rv_obj).Val(); + } + public static String To_canonical_or_local(Xow_ns ns) { // NOTE: prefer canonical names if they exist; otherwise use local; PAGE:sh.w:Koprno; DATE:2015-11-08 + switch (ns.Id()) { + case Xow_ns_.Tid__media: return Xow_ns_.Key__media; + case Xow_ns_.Tid__special: return Xow_ns_.Key__special; + case Xow_ns_.Tid__talk: return Xow_ns_.Key__talk; + case Xow_ns_.Tid__user: return Xow_ns_.Key__user; + case Xow_ns_.Tid__user_talk: return Xow_ns_.Key__user_talk; + case Xow_ns_.Tid__project: return Xow_ns_.Key__project; + case Xow_ns_.Tid__project_talk: return Xow_ns_.Key__project_talk; + case Xow_ns_.Tid__file: return Xow_ns_.Key__file; + case Xow_ns_.Tid__file_talk: return Xow_ns_.Key__file_talk; + case Xow_ns_.Tid__mediawiki: return Xow_ns_.Key__mediawiki; + case Xow_ns_.Tid__mediawiki_talk: return Xow_ns_.Key__mediawiki_talk; + case Xow_ns_.Tid__template: return Xow_ns_.Key__template; + case Xow_ns_.Tid__template_talk: return Xow_ns_.Key__template_talk; + case Xow_ns_.Tid__help: return Xow_ns_.Key__help; + case Xow_ns_.Tid__help_talk: return Xow_ns_.Key__help_talk; + case Xow_ns_.Tid__category: return Xow_ns_.Key__category; + case Xow_ns_.Tid__category_talk: return Xow_ns_.Key__category_talk; + case Xow_ns_.Tid__module: return Xow_ns_.Key__module; + case Xow_ns_.Tid__module_talk: return Xow_ns_.Key__module_talk; + default: return String_.new_u8(ns.Name_ui()); + } + } +} diff --git a/400_xowa/src/gplx/xowa/wikis/nss/Xow_ns_mgr.java b/400_xowa/src/gplx/xowa/wikis/nss/Xow_ns_mgr.java index 6fa2fbb7b..de8897947 100644 --- a/400_xowa/src/gplx/xowa/wikis/nss/Xow_ns_mgr.java +++ b/400_xowa/src/gplx/xowa/wikis/nss/Xow_ns_mgr.java @@ -101,9 +101,9 @@ public class Xow_ns_mgr implements GfoInvkAble, gplx.lists.ComparerAble { for (int i = 0; i < ords_len; i++) { Xow_ns ns = ords[i]; if (ns == null) continue; // TEST: allow gaps in ns numbers; see Talk_skip test and related - if (ns.Id() == Xow_ns_.Id_project_talk) Fix_project_talk(ns); // NOTE: handle $1 talk as per Language.php!fixVariableInNamespace; placement is important as it must go before key registration but after ord sort - Rebuild_hashes__add(name_hash, ns, ns.Name_bry()); - if (ns.Id_tmpl()) tmpl_hash.Add(ns.Name_db_w_colon(), ns.Name_db_w_colon()); + if (ns.Id() == Xow_ns_.Tid__project_talk) Fix_project_talk(ns); // NOTE: handle $1 talk as per Language.php!fixVariableInNamespace; placement is important as it must go before key registration but after ord sort + Rebuild_hashes__add(name_hash, ns, ns.Name_db()); + if (ns.Id_is_tmpl()) tmpl_hash.Add(ns.Name_db_w_colon(), ns.Name_db_w_colon()); } int aliases_len = aliases.Count(); for (int i = 0; i < aliases_len; i++) { @@ -113,7 +113,7 @@ public class Xow_ns_mgr implements GfoInvkAble, gplx.lists.ComparerAble { ns.Aliases_add(kv.Key()); // register alias with official ns; EX: "Image" will be placed in "File"'s .Aliases byte[] alias_bry = Bry_.new_u8(kv.Key()); Rebuild_hashes__add(name_hash, ns, alias_bry); - if (ns.Id_tmpl()) { + if (ns.Id_is_tmpl()) { byte[] alias_name = Bry_.new_u8(kv.Key()); alias_name = Bry_.Add(alias_name, Byte_ascii.Colon); tmpl_hash.Add_if_dupe_use_nth(alias_name, alias_name); @@ -121,11 +121,11 @@ public class Xow_ns_mgr implements GfoInvkAble, gplx.lists.ComparerAble { } } private void Fix_project_talk(Xow_ns ns) { - byte[] ns_name = ns.Name_bry(); - if (Bry_find_.Find_fwd(ns.Name_bry(), Project_talk_fmt_arg)== Bry_find_.Not_found) return; // no $1 found; exit + byte[] ns_name = ns.Name_db(); + if (Bry_find_.Find_fwd(ns.Name_db(), Project_talk_fmt_arg)== Bry_find_.Not_found) return; // no $1 found; exit Xow_ns project_ns = ords[ns.Ord_subj_id()]; if (project_ns == null) return; // should warn or throw error; for now just exit - ns.Name_bry_(Bry_.Replace(ns_name, Project_talk_fmt_arg, project_ns.Name_bry())); + ns.Name_bry_(Bry_.Replace(ns_name, Project_talk_fmt_arg, project_ns.Name_db())); } private static final byte[] Project_talk_fmt_arg = Bry_.new_a7("$1"); private void Rebuild_hashes__add(Hash_adp_bry hash, Xow_ns ns, byte[] key) { Xow_ns_mgr_name_itm ns_itm = new Xow_ns_mgr_name_itm(key, ns); @@ -134,10 +134,10 @@ public class Xow_ns_mgr implements GfoInvkAble, gplx.lists.ComparerAble { hash.Add_if_dupe_use_nth(Bry_.Replace(key, Byte_ascii.Underline, Byte_ascii.Space), ns_itm); } public Xow_ns_mgr Add_defaults() { // NOTE: needs to happen after File ns is added; i.e.: cannot be put in Xow_ns_mgr() {} ctor - Aliases_add(Xow_ns_.Id_file , "Image"); // REF.MW: Setup.php; add "Image", "Image talk" for backward compatibility; note that MW hardcodes Image ns as well - Aliases_add(Xow_ns_.Id_file_talk, "Image_talk"); - Aliases_add(Xow_ns_.Id_project , "Project"); // always add "Project" ns (EX: Wikipedia is name for en.wikipedia.org; not sure if MW hardcodes, but it is in messages - Aliases_add(gplx.xowa.xtns.scribunto.Scrib_xtn_mgr.Ns_id_module, "Module"); // always add "Module" ns; de.wikipedia.org has "Modul" defined in siteinfo.xml, but also uses Module + Aliases_add(Xow_ns_.Tid__file , "Image"); // REF.MW: Setup.php; add "Image", "Image talk" for backward compatibility; note that MW hardcodes Image ns as well + Aliases_add(Xow_ns_.Tid__file_talk , "Image_talk"); + Aliases_add(Xow_ns_.Tid__project , "Project"); // always add "Project" ns (EX: Wikipedia is name for en.wikipedia.org; not sure if MW hardcodes, but it is in messages + Aliases_add(Xow_ns_.Tid__module , "Module"); // always add "Module" ns; de.wikipedia.org has "Modul" defined in siteinfo.xml, but also uses Module return this; } public Xow_ns_mgr Add_new(int nsId, String name) {return Add_new(nsId, Bry_.new_u8(name), Xow_ns_case_.Tid__1st, false);} // for tst_ constructor @@ -145,24 +145,24 @@ public class Xow_ns_mgr implements GfoInvkAble, gplx.lists.ComparerAble { Bry_.Replace_all_direct(name, Byte_ascii.Space, Byte_ascii.Underline); // standardize on _; EX: User talk -> User_talk; DATE:2013-04-21 Xow_ns ns = new Xow_ns(ns_id, caseMatchId, name, alias); switch (ns_id) { - case Xow_ns_.Id_main: ns_main = ns; break; - case Xow_ns_.Id_template: ns_template = ns; break; - case Xow_ns_.Id_portal: ns_portal = ns; break; - case Xow_ns_.Id_project: ns_project = ns; break; - case Xow_ns_.Id_mediawiki: ns_mediawiki = ns; break; - case Scrib_xtn_mgr.Ns_id_module: ns_module = ns; break; - case Xow_ns_.Id_file: if (ns_file == null) ns_file = ns; break; // NOTE: if needed, else Image will become the official ns_file - case Xow_ns_.Id_category: + case Xow_ns_.Tid__main: ns_main = ns; break; + case Xow_ns_.Tid__template: ns_template = ns; break; + case Xow_ns_.Tid__portal: ns_portal = ns; break; + case Xow_ns_.Tid__project: ns_project = ns; break; + case Xow_ns_.Tid__mediawiki: ns_mediawiki = ns; break; + case Xow_ns_.Tid__module: ns_module = ns; break; + case Xow_ns_.Tid__file: if (ns_file == null) ns_file = ns; break; // NOTE: if needed, else Image will become the official ns_file + case Xow_ns_.Tid__category: ns_category = ns; if (category_trie == null) category_trie = Btrie_slim_mgr.new_(ns.Case_match() == Xow_ns_case_.Tid__all); - category_trie.Add_obj(ns.Name_bry(), this); + category_trie.Add_obj(ns.Name_db(), this); break; } ++ns_count; if (!id_hash.Has(ns_hash_lkp.Val_(ns_id))) // NOTE: do not add if already exists; avoids alias id_hash.Add(Int_obj_ref.new_(ns.Id()), ns); - name_hash.Add_if_dupe_use_nth(ns.Name_bry(), new Xow_ns_mgr_name_itm(ns.Name_bry(), ns)); + name_hash.Add_if_dupe_use_nth(ns.Name_db(), new Xow_ns_mgr_name_itm(ns.Name_db(), ns)); return this; } public int compare(Object lhsObj, Object rhsObj) { @@ -226,10 +226,10 @@ public class Xow_ns_mgr implements GfoInvkAble, gplx.lists.ComparerAble { this.Add_new(ns_id, Int_.To_bry(ns_id), Xow_ns_case_.Tid__1st, false); // NOTE: name and case_match are mostly useless defaults; note that in theory this proc should not be called (all siteInfos should be well-formed) but just in case, create items now so that Get_by_ord() does not fail } public byte[] Bld_ttl_w_ns(Bry_bfr bfr, boolean text_form, boolean literalize, int ns_id, byte[] ttl) { - if (ns_id == Xow_ns_.Id_main) return ttl; + if (ns_id == Xow_ns_.Tid__main) return ttl; Xow_ns ns = Ids_get_or_null(ns_id); if (ns == null) {Xoa_app_.Usr_dlg().Warn_many("", "", "ns_mgr:uknown ns_id; ns_id=~{0} ttl=~{1}", ns_id, ttl); return ttl;} if (literalize) bfr.Add_byte(Byte_ascii.Colon); // NOTE: add : to literalize ns; EX: [[Category:A]] will get thrown into category list; [[:Category:A]] will print - bfr.Add(text_form ? ns.Name_txt_w_colon() : ns.Name_db_w_colon()); + bfr.Add(text_form ? ns.Name_ui_w_colon() : ns.Name_db_w_colon()); bfr.Add(ttl); return bfr.To_bry_and_clear(); } diff --git a/400_xowa/src/gplx/xowa/wikis/nss/Xow_ns_mgr_.java b/400_xowa/src/gplx/xowa/wikis/nss/Xow_ns_mgr_.java index 18b25ac01..50b74606a 100644 --- a/400_xowa/src/gplx/xowa/wikis/nss/Xow_ns_mgr_.java +++ b/400_xowa/src/gplx/xowa/wikis/nss/Xow_ns_mgr_.java @@ -24,7 +24,7 @@ public class Xow_ns_mgr_ { rv = rv.Add_new(-2, "Media").Add_new(-1, "Special").Add_new(0, "").Add_new(1, "Talk").Add_new(2, "User").Add_new(3, "User_talk").Add_new(4, "Wikipedia").Add_new(5, "Wikipedia_talk") .Add_new(6, "File").Add_new(7, "File_talk").Add_new(8, "MediaWiki").Add_new(9, "MediaWiki_talk").Add_new(10, "Template").Add_new(11, "Template_talk") .Add_new(12, "Help").Add_new(13, "Help_talk").Add_new(14, "Category").Add_new(15, "Category_talk").Add_new(100, "Portal").Add_new(101, "Portal_talk").Add_new(108, "Book").Add_new(109, "Book_talk") - .Add_new(gplx.xowa.xtns.scribunto.Scrib_xtn_mgr.Ns_id_module, gplx.xowa.xtns.scribunto.Scrib_xtn_mgr.Ns_name_module).Add_new(gplx.xowa.xtns.scribunto.Scrib_xtn_mgr.Ns_id_module_talk, gplx.xowa.xtns.scribunto.Scrib_xtn_mgr.Ns_name_module_talk) + .Add_new(Xow_ns_.Tid__module, Xow_ns_.Key__module).Add_new(Xow_ns_.Tid__module_talk, Xow_ns_.Key__module_talk) .Add_defaults() ; rv.Init(); @@ -37,14 +37,14 @@ public class Xow_ns_mgr_ { Xow_ns ns_name = ns_names.Get_at(i); int ns_id = ns_name.Id(); Xow_ns ns = ns_mgr.Ids_get_or_null(ns_id); - ns.Name_bry_(ns_name.Name_bry()); + ns.Name_bry_(ns_name.Name_db()); } ns_names = lang.Ns_aliases(); ns_names_len = ns_names.Len(); for (int i = 0; i < ns_names_len; i++) { Xow_ns ns_name = ns_names.Get_at(i); int ns_id = ns_name.Id(); - ns_mgr.Aliases_add(ns_id, ns_name.Name_str()); + ns_mgr.Aliases_add(ns_id, ns_name.Name_db_str()); } ns_mgr.Init(); } diff --git a/400_xowa/src/gplx/xowa/wikis/nss/Xow_ns_mgr_tst.java b/400_xowa/src/gplx/xowa/wikis/nss/Xow_ns_mgr_tst.java index 1eefdc4d6..41f049948 100644 --- a/400_xowa/src/gplx/xowa/wikis/nss/Xow_ns_mgr_tst.java +++ b/400_xowa/src/gplx/xowa/wikis/nss/Xow_ns_mgr_tst.java @@ -28,8 +28,8 @@ public class Xow_ns_mgr_tst { @Test public void Skip_even() {fxt.ini_ns_(-2, 2, 4).run_Ords_sort().tst_Ords(-2, -100, 2, 3, 4, 5);} @Test public void Ns_alias() { fxt.Ns_mgr().Aliases_clear(); - fxt.Ns_mgr().Add_new(Xow_ns_.Id_template, "Template"); - fxt.Ns_mgr().Aliases_add(Xow_ns_.Id_template, "Templatex"); + fxt.Ns_mgr().Add_new(Xow_ns_.Tid__template, "Template"); + fxt.Ns_mgr().Aliases_add(Xow_ns_.Tid__template, "Templatex"); fxt.Ns_mgr().Init(); byte[] name = Bry_.new_a7("Templatex:Abc"); Tfds.Eq(10, fxt.Ns_mgr().Tmpls_get_w_colon(name, 0, name.length)); diff --git a/400_xowa/src/gplx/xowa/wikis/nss/Xow_ns_tst.java b/400_xowa/src/gplx/xowa/wikis/nss/Xow_ns_tst.java index 89988a26e..6fb01eb65 100644 --- a/400_xowa/src/gplx/xowa/wikis/nss/Xow_ns_tst.java +++ b/400_xowa/src/gplx/xowa/wikis/nss/Xow_ns_tst.java @@ -20,27 +20,27 @@ import org.junit.*; public class Xow_ns_tst { @Before public void init() {fxt.Clear();} private Xow_ns_fxt fxt = new Xow_ns_fxt(); @Test public void Category() { - fxt .Expd_id_subjId_(Xow_ns_.Id_category) - .Expd_id_talkId_(Xow_ns_.Id_category_talk) + fxt .Expd_id_subjId_(Xow_ns_.Tid__category) + .Expd_id_talkId_(Xow_ns_.Tid__category_talk) .Expd_id_subj_(Bool_.Y) .Expd_id_talk_(Bool_.N) - .Test(Xow_ns_.Id_category) + .Test(Xow_ns_.Tid__category) ; } @Test public void Category_talk() { - fxt .Expd_id_subjId_(Xow_ns_.Id_category) - .Expd_id_talkId_(Xow_ns_.Id_category_talk) + fxt .Expd_id_subjId_(Xow_ns_.Tid__category) + .Expd_id_talkId_(Xow_ns_.Tid__category_talk) .Expd_id_subj_(Bool_.N) .Expd_id_talk_(Bool_.Y) - .Test(Xow_ns_.Id_category_talk) + .Test(Xow_ns_.Tid__category_talk) ; } @Test public void Special() { - fxt .Expd_id_subjId_(Xow_ns_.Id_special) - .Expd_id_talkId_(Xow_ns_.Id_special) + fxt .Expd_id_subjId_(Xow_ns_.Tid__special) + .Expd_id_talkId_(Xow_ns_.Tid__special) .Expd_id_subj_(Bool_.Y) .Expd_id_talk_(Bool_.N) - .Test(Xow_ns_.Id_special) + .Test(Xow_ns_.Tid__special) ; } } @@ -57,7 +57,7 @@ class Xow_ns_fxt { Xow_ns actl = new Xow_ns(nsId, Xow_ns_case_.Tid__1st, Bry_.Empty, false); Tfds.Eq(expd_id_subjId, actl.Id_subj_id()); Tfds.Eq(expd_id_talkId, actl.Id_talk_id()); - Tfds.Eq(expd_id_subj, actl.Id_subj()); - Tfds.Eq(expd_id_talk, actl.Id_talk()); + Tfds.Eq(expd_id_subj, actl.Id_is_subj()); + Tfds.Eq(expd_id_talk, actl.Id_is_talk()); } } diff --git a/400_xowa/src/gplx/xowa/wikis/tdbs/Xotdb_fsys_mgr_tst.java b/400_xowa/src/gplx/xowa/wikis/tdbs/Xotdb_fsys_mgr_tst.java index cc154ad0a..561082b59 100644 --- a/400_xowa/src/gplx/xowa/wikis/tdbs/Xotdb_fsys_mgr_tst.java +++ b/400_xowa/src/gplx/xowa/wikis/tdbs/Xotdb_fsys_mgr_tst.java @@ -21,8 +21,8 @@ import gplx.xowa.wikis.nss.*; public class Xotdb_fsys_mgr_tst { @Before public void init() {fxt.Clear();} private final Xow_fsys_mgr_fxt fxt = new Xow_fsys_mgr_fxt(); @Test public void Basic() { - fxt.Zip_(Xotdb_dir_info_.Tid_page, Bool_.N).Url_ns_fil(Xotdb_dir_info_.Tid_page, Xow_ns_.Id_main, 123, "mem/xowa/wiki/en.wikipedia.org/ns/000/page/00/00/00/01/0000000123.xdat"); - fxt.Zip_(Xotdb_dir_info_.Tid_page, Bool_.Y).Url_ns_fil(Xotdb_dir_info_.Tid_page, Xow_ns_.Id_main, 123, "mem/xowa/wiki/en.wikipedia.org/ns/000/page_zip/00/00/00/01/0000000123.zip"); + fxt.Zip_(Xotdb_dir_info_.Tid_page, Bool_.N).Url_ns_fil(Xotdb_dir_info_.Tid_page, Xow_ns_.Tid__main, 123, "mem/xowa/wiki/en.wikipedia.org/ns/000/page/00/00/00/01/0000000123.xdat"); + fxt.Zip_(Xotdb_dir_info_.Tid_page, Bool_.Y).Url_ns_fil(Xotdb_dir_info_.Tid_page, Xow_ns_.Tid__main, 123, "mem/xowa/wiki/en.wikipedia.org/ns/000/page_zip/00/00/00/01/0000000123.zip"); } } class Xow_fsys_mgr_fxt { diff --git a/400_xowa/src/gplx/xowa/wikis/tdbs/Xotdb_page_itm_.java b/400_xowa/src/gplx/xowa/wikis/tdbs/Xotdb_page_itm_.java index 08be05da2..b257d8604 100644 --- a/400_xowa/src/gplx/xowa/wikis/tdbs/Xotdb_page_itm_.java +++ b/400_xowa/src/gplx/xowa/wikis/tdbs/Xotdb_page_itm_.java @@ -75,7 +75,7 @@ public class Xotdb_page_itm_ { .Add(page.Ttl_page_db()) .Add_byte_nl(); } public static void Txt_page_save(Bry_bfr bfr, int id, DateAdp modified_on, byte[] title, byte[] text, boolean add_nl) { - int ts = Bit_.Xto_int_date_short(modified_on.XtoSegAry()); + int ts = Int_flag_bldr_.To_int_date_short(modified_on.XtoSegAry()); bfr .Add_base85(id , Base85_.Len_int) .Add_byte(Txt_page_dlm) // needed for mass template load .Add_base85(ts , Base85_.Len_int) .Add_byte(Txt_page_dlm) .Add(title) .Add_byte(Txt_page_dlm) // needed for rebuilding ttl files diff --git a/400_xowa/src/gplx/xowa/wikis/tdbs/Xotdb_page_raw_parser.java b/400_xowa/src/gplx/xowa/wikis/tdbs/Xotdb_page_raw_parser.java index 12f9610c8..67c9ae1d0 100644 --- a/400_xowa/src/gplx/xowa/wikis/tdbs/Xotdb_page_raw_parser.java +++ b/400_xowa/src/gplx/xowa/wikis/tdbs/Xotdb_page_raw_parser.java @@ -47,7 +47,7 @@ public class Xotdb_page_raw_parser { page.Id_(id); read = rdr.Read_next(); if (!read) throw Err_.new_wo_type("could not read timestamp"); int timestamp = Base85_.To_int_by_bry(rdr.Bfr(), rdr.Key_pos_bgn(), rdr.Key_pos_end() - 1); - page.Modified_on_(Bit_.Xto_date_short(timestamp)); + page.Modified_on_(Int_flag_bldr_.To_date_short(timestamp)); read = rdr.Read_next(); if (!read) throw Err_.new_wo_type("could not read ttl"); byte[] ttl = Bry_.Mid(rdr.Bfr(), rdr.Key_pos_bgn(), rdr.Key_pos_end() - 1); page.Ttl_(ttl, ns_mgr); diff --git a/400_xowa/src/gplx/xowa/wikis/tdbs/hives/Xowd_hive_mgr_tst.java b/400_xowa/src/gplx/xowa/wikis/tdbs/hives/Xowd_hive_mgr_tst.java index d1327ab7d..dfa23beb6 100644 --- a/400_xowa/src/gplx/xowa/wikis/tdbs/hives/Xowd_hive_mgr_tst.java +++ b/400_xowa/src/gplx/xowa/wikis/tdbs/hives/Xowd_hive_mgr_tst.java @@ -75,7 +75,7 @@ class Xowd_hive_mgr_fxt { return this; } public Xowd_hive_mgr_fxt Tst_fil(int fil, String expd) { - Io_url url = wiki.Tdb_fsys_mgr().Url_ns_fil(Xotdb_dir_info_.Tid_page, Xow_ns_.Id_main, fil); + Io_url url = wiki.Tdb_fsys_mgr().Url_ns_fil(Xotdb_dir_info_.Tid_page, Xow_ns_.Tid__main, fil); Tfds.Eq_str_lines(expd, Io_mgr.Instance.LoadFilStr(url)); return this; } diff --git a/400_xowa/src/gplx/xowa/wikis/ttls/Xow_ttl__basic_tst.java b/400_xowa/src/gplx/xowa/wikis/ttls/Xow_ttl__basic_tst.java index 52fc77775..d45e4fc49 100644 --- a/400_xowa/src/gplx/xowa/wikis/ttls/Xow_ttl__basic_tst.java +++ b/400_xowa/src/gplx/xowa/wikis/ttls/Xow_ttl__basic_tst.java @@ -19,8 +19,8 @@ package gplx.xowa.wikis.ttls; import gplx.*; import gplx.xowa.*; import gplx.xow import org.junit.*; import gplx.xowa.wikis.nss.*; public class Xow_ttl__basic_tst { @Before public void init() {fxt.Reset();} private Xow_ttl_fxt fxt = new Xow_ttl_fxt(); - @Test public void Ns() {fxt.Init_ttl("Help:Test") .Expd_ns_id(Xow_ns_.Id_help).Expd_page_txt("Test").Test();} - @Test public void Ns_false() {fxt.Init_ttl("Helpx:Test") .Expd_ns_id(Xow_ns_.Id_main).Expd_page_txt("Helpx:Test").Test();} + @Test public void Ns() {fxt.Init_ttl("Help:Test") .Expd_ns_id(Xow_ns_.Tid__help).Expd_page_txt("Test").Test();} + @Test public void Ns_false() {fxt.Init_ttl("Helpx:Test") .Expd_ns_id(Xow_ns_.Tid__main).Expd_page_txt("Helpx:Test").Test();} @Test public void Ns_multiple() {fxt.Init_ttl("Help:Talk:test") .Expd_page_txt("Talk:test").Test();} @Test public void Full_txt() {fxt.Init_ttl("Help:a & b") .Expd_full_txt("Help:A & b").Test();} // preserve @Test public void Full_url() {fxt.Init_ttl("Help:a & b") .Expd_full_url("Help:A_%26_b").Test();} // escape @@ -48,10 +48,10 @@ public class Xow_ttl__basic_tst { @Test public void Force_literal_link_y() {fxt.Init_ttl(":Help:test") .Expd_force_literal_link(1).Expd_page_txt("Test").Test();} @Test public void Force_literal_link_n() {fxt.Init_ttl( "Help:test") .Expd_force_literal_link(0).Expd_page_txt("Test").Test();} @Test public void Force_literal_link_y_2() {fxt.Init_ttl("::Help:test") .Expd_force_literal_link(1).Expd_page_txt("Test").Test();} // PURPOSE: 2nd initial colon should be ignored; EX:mw:MediaWiki; [[::MediaWiki]]; DATE:2013-12-14 - @Test public void All_page() {fxt.Init_ttl("test") .Expd_xwik_txt("").Expd_ns_id(Xow_ns_.Id_main).Expd_page_txt("Test").Expd_leaf_txt("Test").Expd_anch_txt("").Test();} - @Test public void All_ns() {fxt.Init_ttl("Help:test") .Expd_xwik_txt("").Expd_ns_id(Xow_ns_.Id_help).Expd_page_txt("Test").Expd_leaf_txt("Test").Expd_anch_txt("").Test();} - @Test public void Special() {fxt.Init_ttl("Special:Random").Expd_ns_id(Xow_ns_.Id_special).Expd_page_txt("Random").Test();} - @Test public void Special_xowa() {fxt.Init_ttl("Special:xowa/Search/Ttl").Expd_ns_id(Xow_ns_.Id_special).Expd_page_txt("Xowa/Search/Ttl").Test();} + @Test public void All_page() {fxt.Init_ttl("test") .Expd_xwik_txt("").Expd_ns_id(Xow_ns_.Tid__main).Expd_page_txt("Test").Expd_leaf_txt("Test").Expd_anch_txt("").Test();} + @Test public void All_ns() {fxt.Init_ttl("Help:test") .Expd_xwik_txt("").Expd_ns_id(Xow_ns_.Tid__help).Expd_page_txt("Test").Expd_leaf_txt("Test").Expd_anch_txt("").Test();} + @Test public void Special() {fxt.Init_ttl("Special:Random").Expd_ns_id(Xow_ns_.Tid__special).Expd_page_txt("Random").Test();} + @Test public void Special_xowa() {fxt.Init_ttl("Special:xowa/Search/Ttl").Expd_ns_id(Xow_ns_.Tid__special).Expd_page_txt("Xowa/Search/Ttl").Test();} @Test public void Comment() {fxt.Init_ttl("Ab").Expd_page_txt("Ab").Test();} @Test public void Comment_eos() {fxt.Init_ttl("Ab