xref: /aosp_15_r20/external/cldr/tools/cldr-code/src/main/java/org/unicode/cldr/util/XMLUploader.java (revision 912701f9769bb47905792267661f0baf2b85bed5)
1 package org.unicode.cldr.util;
2 
3 import java.io.IOException;
4 import java.io.Writer;
5 
6 /**
7  * Generate HTML for the "Upload XML" (gear menu) interface
8  *
9  * <p>Some code has been, or should be, moved here from jsp and jspf files. Reference:
10  * https://unicode-org.atlassian.net/browse/CLDR-11877
11  *
12  * <p>TODO: in the long term, avoid generating html on the server. Use ajax. Let the client handle
13  * the UI presentation.
14  */
15 public class XMLUploader {
16 
17     /**
18      * Write a portion of the HTML for the Bulk Upload interface
19      *
20      * @param request the HttpServletRequest
21      * @param bulkStage the string such as "upload", "check", "test", "submit"
22      * @throws IOException
23      *     <p>Some code was moved here from bulkinfo.jspf Reference:
24      *     https://unicode-org.atlassian.net/browse/CLDR-11877
25      */
writeBulkInfoHtml(String bulkStage, Writer out)26     public static void writeBulkInfoHtml(String bulkStage, Writer out) throws IOException {
27         out.write("<div class='bulkNextInfo'>\n");
28         out.write("<ul>\n");
29         out.write("<li class='header'>Bulk Upload:</li>\n");
30         String stages[] = {
31             "upload",
32             "Upload XML file",
33             "check",
34             "Verify valid XML",
35             "test",
36             "Test for CLDR errors",
37             "submit",
38             "Data submitted into SurveyTool"
39         };
40 
41         for (int i = 0; i < stages.length; i += 2) {
42             final int stageNumber = (i / 2) + 1;
43             final String stageName = stages[i + 0];
44             final String stageDescription = stages[i + 1];
45             final boolean active = bulkStage.equals(stageName);
46             final String activeClass = active ? "active" : "inactive";
47 
48             out.write("<li class='" + activeClass + "'>\n");
49             out.write("<h1>" + stageNumber + ". " + stageName + "</h1>\n");
50             out.write("<h2>" + stageDescription + "</h2>\n");
51             out.write("</li>\n");
52         }
53         out.write("</ul>\n");
54         if (bulkStage.equals("upload")) {
55             out.write("<p class='helpContent'>");
56             out.write("Click the button in the bottom-right corner to proceed to the next step.");
57             out.write("</p>\n");
58         }
59         out.write("</div>\n");
60     }
61 }
62