Skip to content

Commit 42e4c87

Browse files
authored
jsp: fix C bidi pulldown (#185)
#129 (but was missed when that was closed)
1 parent 0108d39 commit 42e4c87

File tree

5 files changed

+107
-9
lines changed

5 files changed

+107
-9
lines changed

UnicodeJsps/.settings/org.eclipse.core.resources.prefs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@ eclipse.preferences.version=1
22
encoding//src/main/java=UTF-8
33
encoding//src/main/resources=UTF-8
44
encoding//src/main/webapp=UTF-8
5+
encoding//src/test/java=UTF-8
56
encoding/<project>=UTF-8

UnicodeJsps/pom.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,13 @@
8080
<version>1.4.01</version>
8181
<scope>compile</scope>
8282
</dependency>
83+
84+
<!-- test -->
85+
<dependency>
86+
<groupId>org.junit.jupiter</groupId>
87+
<artifactId>junit-jupiter</artifactId>
88+
<scope>test</scope>
89+
</dependency>
8390
</dependencies>
8491
<build>
8592
<finalName>${project.artifactId}</finalName>
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
package org.unicode.jsp;
2+
3+
import java.util.EnumSet;
4+
5+
import org.unicode.props.UcdPropertyValues.Age_Values;
6+
7+
/**
8+
* A class to encapsulate the available C UBA versions.
9+
*/
10+
public class UBAVersion {
11+
private static EnumSet<Age_Values> C_UBA_AGES = EnumSet.of(
12+
Age_Values.V6_2,
13+
Age_Values.V6_3,
14+
Age_Values.V7_0,
15+
Age_Values.V8_0,
16+
Age_Values.V9_0,
17+
Age_Values.V10_0,
18+
Age_Values.V11_0,
19+
Age_Values.V12_0,
20+
Age_Values.V13_0,
21+
Age_Values.V14_0
22+
/* Current version is always last */
23+
);
24+
25+
public static EnumSet<Age_Values> getVersions() {
26+
return C_UBA_AGES;
27+
}
28+
29+
/**
30+
* As a select, such as "140"
31+
* @return
32+
*/
33+
public static final String toSelect(Age_Values age) {
34+
return age.getShortName().replaceAll("[\\.]", "");
35+
}
36+
37+
/**
38+
* Current version
39+
*
40+
* @return
41+
*/
42+
public static Age_Values getCurrent() {
43+
return C_UBA_AGES.toArray(new Age_Values[C_UBA_AGES.size()])[C_UBA_AGES.size() - 1];
44+
}
45+
}

UnicodeJsps/src/main/webapp/bidic.jsp

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
<html>
22

33
<head>
4-
<%@ include file="header.jsp" %>
4+
<%@ include file="header.jsp" %>
5+
<%@ page import="org.unicode.jsp.UBAVersion" %>
6+
<%@ page import="org.unicode.props.UcdPropertyValues.Age_Values" %>
57
<title>Unicode Utilities: BIDI (UBA) C Reference</title>
68
<script type="text/javascript">
79
function detectIE() {
@@ -126,7 +128,7 @@ function setUbaInput(str) {
126128
UtfParameters utfParams = new UtfParameters(queryStr);
127129
128130
String ubaPara = utfParams.getParameter("b", "2");
129-
String ubaVersion = utfParams.getParameter("u", "110");
131+
String ubaVersion = utfParams.getParameter("u", UBAVersion.toSelect(UBAVersion.getCurrent()));
130132
String ubaDetail = utfParams.getParameter("d", "2");
131133
boolean ubaShowVacuous = !"off".equals(utfParams.getParameter("y", "off"));
132134
String valInputCharSeq = utfParams.getParameter("s", "\u0645\u0627\u0631\u0652\u0643 \u2066\u0031\u2013\u0033%\u2069 mark (\u0366v.2)\u0368!");
@@ -295,13 +297,12 @@ function setUbaInput(str) {
295297
&ensp;
296298
UBA Version:
297299
<select name="u" size="1">
298-
<option value="62" <%= (ubaVersion.equals("62") ? "selected" : "") %>>6.2</option>
299-
<option value="63" <%= (ubaVersion.equals("63") ? "selected" : "") %>>6.3</option>
300-
<option value="70" <%= (ubaVersion.equals("70") ? "selected" : "") %>>7.0</option>
301-
<option value="80" <%= (ubaVersion.equals("80") ? "selected" : "") %>>8.0</option>
302-
<option value="90" <%= (ubaVersion.equals("90") ? "selected" : "") %>>9.0</option>
303-
<option value="100" <%= (ubaVersion.equals("100") ? "selected" : "") %>>10.0</option>
304-
<option value="110" <%= (ubaVersion.equals("110") ? "selected" : "") %>>11.0</option>
300+
<% for (final Age_Values v : UBAVersion.getVersions()) {
301+
final String value = UBAVersion.toSelect(v); // "140"
302+
final String name = v.getShortName(); // "14.0"
303+
%>
304+
<option value="<%= value %>" <%= (ubaVersion.equals(value) ? "selected" : "") %>><%= name %></option>
305+
<% } %>
305306
</select>
306307
&ensp;
307308
Detail:
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
package org.unicode.jsp;
2+
3+
import static org.junit.jupiter.api.Assertions.assertEquals;
4+
import static org.junit.jupiter.api.Assertions.assertFalse;
5+
import static org.junit.jupiter.api.Assertions.assertNotNull;
6+
import static org.junit.jupiter.api.Assertions.assertTrue;
7+
8+
import java.util.EnumSet;
9+
10+
import com.ibm.icu.text.UnicodeSet;
11+
12+
import org.junit.jupiter.api.Test;
13+
import org.unicode.props.UcdPropertyValues.Age_Values;
14+
15+
public class TestUBAVersion {
16+
@Test
17+
void UBAVersionTest() {
18+
final Age_Values current = UBAVersion.getCurrent();
19+
assertNotNull(current);
20+
21+
// toString: 14.0
22+
String currentString = current.getShortName();
23+
assertNotNull(currentString);
24+
assertTrue(UnicodeSet.fromAll(currentString).contains('.'));
25+
assertTrue(UnicodeSet.fromAll(currentString).containsSome("0123456789"));
26+
27+
// toString: 140
28+
String selectString = UBAVersion.toSelect(current);
29+
assertNotNull(selectString);
30+
assertFalse(UnicodeSet.fromAll(selectString).contains('.'));
31+
assertTrue(UnicodeSet.fromAll(selectString).containsSome("0123456789"));
32+
33+
final EnumSet<Age_Values> versions = UBAVersion.getVersions();
34+
assertNotNull(versions);
35+
36+
// Current is the last item
37+
assertTrue(current.equals(versions.toArray()[versions.size()-1]));
38+
39+
// First is 6.2
40+
final Age_Values first = versions.iterator().next();
41+
assertEquals("6.2", first.getShortName());
42+
assertEquals("62", UBAVersion.toSelect(first));
43+
}
44+
}

0 commit comments

Comments
 (0)