+ private SchemedName detectScheme() {
+ if (parts.length == 1 && parts[0].getType() == NamePartType.SINGLE_NAME) {
+ return new SingleName(parts[0]);
+ }
+ int suffixCount = 0;
+ int lastCount = 0;
+ int firstCount = 0;
+ int stage = 0;
+ for (NamePart p : parts) {
+ if (p.getType() == NamePartType.LAST_NAME) {
+ lastCount++;
+ if (stage < 1) {
+ stage = 1;
+ } else if (stage != 1) {
+ return null;
+ }
+ } else if (p.getType() == NamePartType.FIRST_NAME) {
+ firstCount++;
+ if (stage != 0) {
+ return null;
+ }
+ } else if (p.getType() == NamePartType.SUFFIX) {
+ suffixCount++;
+ if (stage < 2) {
+ stage = 2;
+ } else if (stage != 2) {
+ return null;
+ }
+
+ } else {
+ return null;
+ }
+ }
+ if (firstCount == 0 || lastCount == 0) {
+ return null;
+ }
+ NamePart[] firstNames = new NamePart[firstCount];
+ NamePart[] lastNames = new NamePart[lastCount];
+ NamePart[] suffixes = new NamePart[suffixCount];
+ int fn = 0;
+ int ln = 0;
+ int sn = 0;
+ for (NamePart p : parts) {
+ if (p.getType() == NamePartType.FIRST_NAME) {
+ firstNames[fn++] = p;
+ } else if (p.getType() == NamePartType.SUFFIX) {
+ suffixes[sn++] = p;
+ } else if (p.getType() == NamePartType.LAST_NAME) {
+ lastNames[ln++] = p;
+ }
+ }
+
+ return new WesternName(firstNames, lastNames, suffixes);
+ }
+
+ /**
+ * Outputs an HTML variant suitable for locations where special UI features
+ * should indicate the different Name Parts.
+ */
+ @Override
+ public void output(PrintWriter out, Language l, Map<String, Object> vars) {
+ out.print("<span class=\"names\">");
+ scheme.output(out);
+ out.print("</span> ");
+ }
+
+ /**
+ * Tests, if this name fits into the given string.
+ *
+ * @param text
+ * the name to test against
+ * @return true, iff this name matches.
+ */