diff --git a/400_xowa/src/gplx/xowa/addons/wikis/ctgs/htmls/catpages/langs/Xoctg_collation_mgr.java b/400_xowa/src/gplx/xowa/addons/wikis/ctgs/htmls/catpages/langs/Xoctg_collation_mgr.java
index faca4a53a..f7ee806d4 100644
--- a/400_xowa/src/gplx/xowa/addons/wikis/ctgs/htmls/catpages/langs/Xoctg_collation_mgr.java
+++ b/400_xowa/src/gplx/xowa/addons/wikis/ctgs/htmls/catpages/langs/Xoctg_collation_mgr.java
@@ -19,23 +19,15 @@ package gplx.xowa.addons.wikis.ctgs.htmls.catpages.langs; import gplx.*; import
import gplx.core.intls.ucas.*;
public class Xoctg_collation_mgr {
private final Xow_wiki wiki;
- private Uca_collator collator;
- private String collation_name = "uppercase"; // REF:https://noc.wikimedia.org/conf/InitialiseSettings.php.txt|wgCategoryCollation|default
+ private Xoctg_collation_wkr wkr;
public Xoctg_collation_mgr(Xow_wiki wiki) {
this.wiki = wiki;
- if (String_.Eq(wiki.Domain_str(), "en.wikipedia.org"))
- collation_name = "uca-default-kn";
+ this.wkr = new Xoctg_collation_wkr__uppercase(wiki); // REF:https://noc.wikimedia.org/conf/InitialiseSettings.php.txt|wgCategoryCollation|default
}
public void Collation_name_(String v) {
- this.collation_name = v;
+ this.wkr = Xoctg_collation_wkr_.Make(wiki, v);
}
public byte[] Get_sortkey(byte[] src) {
- if (String_.Eq(collation_name, "uppercase")) {
- return wiki.Lang().Case_mgr().Case_build_upper(src);
- }
- else {
- if (collator == null) collator = Uca_collator_.New(collation_name, true);
- return collator.Get_sortkey(String_.new_u8(src));
- }
+ return wkr.Get_sortkey(src);
}
}
diff --git a/400_xowa/src/gplx/xowa/addons/wikis/ctgs/htmls/catpages/langs/Xoctg_collation_wkr.java b/400_xowa/src/gplx/xowa/addons/wikis/ctgs/htmls/catpages/langs/Xoctg_collation_wkr.java
new file mode 100644
index 000000000..1a4de7848
--- /dev/null
+++ b/400_xowa/src/gplx/xowa/addons/wikis/ctgs/htmls/catpages/langs/Xoctg_collation_wkr.java
@@ -0,0 +1,67 @@
+/*
+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.addons.wikis.ctgs.htmls.catpages.langs; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.wikis.*; import gplx.xowa.addons.wikis.ctgs.*; import gplx.xowa.addons.wikis.ctgs.htmls.*; import gplx.xowa.addons.wikis.ctgs.htmls.catpages.*;
+public interface Xoctg_collation_wkr {
+ String Type_name();
+ String Wm_name();
+ byte[] Get_sortkey(byte[] src);
+}
+class Xoctg_collation_wkr__uppercase implements Xoctg_collation_wkr {
+ private final Xow_wiki wiki;
+ public Xoctg_collation_wkr__uppercase(Xow_wiki wiki) {this.wiki = wiki;}
+ public String Type_name() {return "uppercase";}
+ public String Wm_name() {return this.Type_name();}
+ public byte[] Get_sortkey(byte[] src) {
+ return wiki.Lang().Case_mgr().Case_build_upper(src);
+ }
+}
+class Xoctg_collation_wkr__identity implements Xoctg_collation_wkr {
+ public String Type_name() {return "identity";}
+ public String Wm_name() {return this.Type_name();}
+ public byte[] Get_sortkey(byte[] src) {
+ return src;
+ }
+}
+class Xoctg_collation_wkr__uca implements Xoctg_collation_wkr {
+ private gplx.core.intls.ucas.Uca_collator collator;
+ public Xoctg_collation_wkr__uca(String wm_name, String icu_locale) {
+ // REF:"includes/collation/Collation.php|factory" "includes/collation/IcuCollation.php|__construct"
+ this.wm_name = wm_name;
+ // remove anything after "@"; EX: 'svwikisource' => 'uca-sv@collation=standard', // T48058
+ int at_pos = String_.FindFwd(icu_locale, "@");
+ if (at_pos != String_.Find_none)
+ icu_locale = String_.Mid(icu_locale, 0, at_pos);
+
+ // handle "default-u-kn"
+ if (String_.Eq(icu_locale, "default-u-kn"))
+ this.icu_locale = "en";
+ else if (String_.Eq(icu_locale, "root"))
+ this.icu_locale = "en";
+ else
+ this.icu_locale = icu_locale;
+ this.numeric_sorting = String_.Has_at_end(icu_locale, "-u-kn");
+ }
+ public String Type_name() {return wm_name;} private final String wm_name;
+ public String Wm_name() {return this.Type_name();}
+ public String Icu_locale() {return icu_locale;} private final String icu_locale;
+ public boolean Numeric_sorting() {return numeric_sorting;} private final boolean numeric_sorting;
+ public byte[] Get_sortkey(byte[] src) {
+ if (collator == null) collator = gplx.core.intls.ucas.Uca_collator_.New(icu_locale, numeric_sorting);
+ return collator.Get_sortkey(String_.new_u8(src));
+ }
+}
diff --git a/400_xowa/src/gplx/xowa/addons/wikis/ctgs/htmls/catpages/langs/Xoctg_collation_wkr_.java b/400_xowa/src/gplx/xowa/addons/wikis/ctgs/htmls/catpages/langs/Xoctg_collation_wkr_.java
new file mode 100644
index 000000000..ab25cf09c
--- /dev/null
+++ b/400_xowa/src/gplx/xowa/addons/wikis/ctgs/htmls/catpages/langs/Xoctg_collation_wkr_.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.addons.wikis.ctgs.htmls.catpages.langs; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.wikis.*; import gplx.xowa.addons.wikis.ctgs.*; import gplx.xowa.addons.wikis.ctgs.htmls.*; import gplx.xowa.addons.wikis.ctgs.htmls.catpages.*;
+class Xoctg_collation_wkr_ {
+ public static Xoctg_collation_wkr Make(Xow_wiki wiki, String wm_name) {
+ // REF:"includes/collation/Collation.php|factory"
+ if (String_.Eq(wm_name, "uppercase")) return new Xoctg_collation_wkr__uppercase(wiki);
+ else if (String_.Eq(wm_name, "identity")) return new Xoctg_collation_wkr__identity();
+ else if (String_.Eq(wm_name, "uca-default")) return new Xoctg_collation_wkr__uca(wm_name, "root");
+ else if (String_.Eq(wm_name, "xx-uca-ckb")) return new Xoctg_collation_wkr__uca(wm_name, "fa"); // FUTURE:should create custom collation class to do extra logic
+ else if (String_.Eq(wm_name, "xx-uca-et")) return new Xoctg_collation_wkr__uca(wm_name, "et"); // FUTURE:should create custom collation class to do extra logic
+ else {
+ if (String_.Has_at_bgn(wm_name, "uca-"))
+ return new Xoctg_collation_wkr__uca(wm_name, String_.Replace(wm_name, "uca-", ""));
+ else { // unknown collation code; log and exit
+ Gfo_usr_dlg_.Instance.Warn_many("", "", "unknown collation; collation=~{0}", wm_name);
+ return new Xoctg_collation_wkr__uppercase(wiki);
+ }
+ }
+ }
+}
diff --git a/400_xowa/src/gplx/xowa/addons/wikis/ctgs/htmls/catpages/langs/Xoctg_collation_wkr___tst.java b/400_xowa/src/gplx/xowa/addons/wikis/ctgs/htmls/catpages/langs/Xoctg_collation_wkr___tst.java
new file mode 100644
index 000000000..74405060c
--- /dev/null
+++ b/400_xowa/src/gplx/xowa/addons/wikis/ctgs/htmls/catpages/langs/Xoctg_collation_wkr___tst.java
@@ -0,0 +1,41 @@
+/*
+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.addons.wikis.ctgs.htmls.catpages.langs; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.wikis.*; import gplx.xowa.addons.wikis.ctgs.*; import gplx.xowa.addons.wikis.ctgs.htmls.*; import gplx.xowa.addons.wikis.ctgs.htmls.catpages.*;
+import org.junit.*; import gplx.core.tests.*;
+public class Xoctg_collation_wkr___tst {
+ private final Xoctg_collation_wkr___fxt fxt = new Xoctg_collation_wkr___fxt();
+ @Test public void Uppercase() {fxt.Test__make("uppercase" , "uppercase");}
+ @Test public void Identity() {fxt.Test__make("identity" , "identity");}
+ @Test public void Unknown() {fxt.Test__make("unknown" , "uppercase");}
+ @Test public void Uca__uca_default() {fxt.Test__make__uca("uca-default" , "en", false);}
+ @Test public void Uca__xx_uca_ckb() {fxt.Test__make__uca("xx-uca-ckb" , "fa", false);}
+ @Test public void Uca__xx_uca_et() {fxt.Test__make__uca("xx-uca-et" , "et", false);}
+ @Test public void Uca__uca_default_u_kn() {fxt.Test__make__uca("uca-default-u-kn" , "en", true);}
+ @Test public void Uca__uca_at_logic() {fxt.Test__make__uca("uca-sv@collation=standard" , "sv", false);}
+}
+class Xoctg_collation_wkr___fxt {
+ public void Test__make(String wm_name, String expd_type) {
+ Xoctg_collation_wkr actl = Xoctg_collation_wkr_.Make(null, wm_name);
+ Gftest.Eq__str(expd_type, actl.Type_name());
+ }
+ public void Test__make__uca(String wm_name, String expd_locale, boolean expd_numeric_sorting) {
+ Xoctg_collation_wkr__uca actl = (Xoctg_collation_wkr__uca)Xoctg_collation_wkr_.Make(null, wm_name);
+ Gftest.Eq__str(expd_locale, actl.Icu_locale());
+ Gftest.Eq__bool(expd_numeric_sorting, actl.Numeric_sorting());
+ }
+}