Skip to content

Commit 95253b1

Browse files
committed
LaboratoryController: Use java DOM API instead of HtmlStringBuilder with unsafeAppend
1 parent 3f25e2b commit 95253b1

1 file changed

Lines changed: 40 additions & 46 deletions

File tree

laboratory/src/org/labkey/laboratory/LaboratoryController.java

Lines changed: 40 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,6 @@
8181
import org.labkey.api.util.ExceptionUtil;
8282
import org.labkey.api.util.FileUtil;
8383
import org.labkey.api.util.HtmlString;
84-
import org.labkey.api.util.HtmlStringBuilder;
8584
import org.labkey.api.util.JsonUtil;
8685
import org.labkey.api.util.Pair;
8786
import org.labkey.api.util.URLHelper;
@@ -109,6 +108,16 @@
109108
import java.util.Map;
110109
import java.util.Set;
111110

111+
import static org.labkey.api.util.DOM.BR;
112+
import static org.labkey.api.util.DOM.INPUT;
113+
import static org.labkey.api.util.DOM.P;
114+
import static org.labkey.api.util.DOM.TABLE;
115+
import static org.labkey.api.util.DOM.TD;
116+
import static org.labkey.api.util.DOM.TR;
117+
import static org.labkey.api.util.DOM.at;
118+
import static org.labkey.api.util.DOM.createHtmlFragment;
119+
import static org.labkey.api.util.DOM.Attribute.style;
120+
112121

113122
public class LaboratoryController extends SpringActionController
114123
{
@@ -175,17 +184,13 @@ public void validateCommand(Object form, Errors errors)
175184
@Override
176185
public ModelAndView getConfirmView(Object form, BindException errors) throws Exception
177186
{
178-
HtmlStringBuilder sb = HtmlStringBuilder.of();
179-
sb.append("Certain assays can have performance improved by the addition of indexes, which can be suggested by modules. The following indexes are recommended for the assays installed on this server:<p>");
180-
181187
List<String> msgs = LaboratoryManager.get().createIndexes(getUser(), false, false);
182188

183-
for (String msg : msgs)
184-
sb.append(msg).unsafeAppend("<br>");
185-
186-
sb.unsafeAppend("<p>Do you want to continue?</p>");
187-
188-
return new HtmlView(sb.getHtmlString());
189+
return new HtmlView(createHtmlFragment(
190+
"Certain assays can have performance improved by the addition of indexes, which can be suggested by modules. The following indexes are recommended for the assays installed on this server:",
191+
P(msgs.stream().map(msg -> createHtmlFragment(msg, BR()))),
192+
P("Do you want to continue?")
193+
));
189194
}
190195

191196
@Override
@@ -236,19 +241,12 @@ public ModelAndView getConfirmView(EnsureAssayFieldsForm form, BindException err
236241
{
237242
try
238243
{
239-
HtmlStringBuilder sb = HtmlStringBuilder.of();
240-
sb.append("This action will iterate all protocols for the assay ")
241-
.append(form.getProviderName())
242-
.unsafeAppend(" and append any columns present in the definition, but lacking from that instance of the assay. The following changes will be made:<br><br>");
243244
List<String> messages = AssayHelper.ensureAssayFields(getUser(), form.getProviderName(), form.isRenameConflicts(), true);
244-
for (String msg : messages)
245-
{
246-
sb.append(msg).unsafeAppend("<br><br>");
247-
}
248-
249-
sb.unsafeAppend("<br>Do you want to continue?");
250-
251-
return new HtmlView(sb.getHtmlString());
245+
return new HtmlView(createHtmlFragment(
246+
"This action will iterate all protocols for the assay " + form.getProviderName() + " and append any columns present in the definition, but lacking from that instance of the assay. The following changes will be made:", BR(), BR(),
247+
messages.stream().map(msg -> createHtmlFragment(msg, BR(), BR())),
248+
BR(), "Do you want to continue?"
249+
));
252250
}
253251
catch (ChangePropertyDescriptorException e)
254252
{
@@ -314,25 +312,23 @@ public void validateCommand(SetTableIncrementForm form, Errors errors)
314312
@Override
315313
public ModelAndView getConfirmView(SetTableIncrementForm form, BindException errors) throws Exception
316314
{
317-
HtmlStringBuilder sb = HtmlStringBuilder.of();
318-
sb.unsafeAppend("This allows you to reset the current value for an auto-incrementing table<br><br>");
319-
sb.unsafeAppend("<table style='border-collapse: collapse;'>");
320-
321315
String schema = form.getSchemaName() == null ? "" : form.getSchemaName();
322-
sb.unsafeAppend("<tr><td>Schema:</td><td><input name=\"schema\" value=\"").append(schema).unsafeAppend("\"></td></tr>");
323-
324316
String query = form.getQueryName() == null ? "" : form.getQueryName();
325-
sb.unsafeAppend("<tr><td>Query:</td><td><input name=\"query\" value=\"").append(query).unsafeAppend("\"></td></tr>");
326317

327318
ContainerIncrementingTable ti = getTable(schema, query, errors, false);
328-
Integer value = null;
319+
Integer currentId = null;
329320
if (ti != null)
330-
value = ti.getCurrentId(getContainer());
331-
332-
sb.unsafeAppend("<tr><td>Value:</td><td><input name=\"value\" value=\"").append(value == null ? "" : value.toString()).unsafeAppend("\"></td></tr>");
333-
sb.unsafeAppend("</table><br>Do you want to continue?");
321+
currentId = ti.getCurrentId(getContainer());
334322

335-
return new HtmlView(sb.getHtmlString());
323+
return new HtmlView(createHtmlFragment(
324+
"This allows you to reset the current value for an auto-incrementing table", BR(), BR(),
325+
TABLE(at(style, "border-collapse: collapse;"),
326+
TR(TD("Schema:"), TD(INPUT(at().name("schema").value(schema)))),
327+
TR(TD("Query:"), TD(INPUT(at().name("query").value(query)))),
328+
TR(TD("Value:"), TD(INPUT(at().name("value").value(currentId == null ? "" : currentId.toString()))))
329+
),
330+
BR(), "Do you want to continue?"
331+
));
336332
}
337333

338334
@Override
@@ -513,20 +509,18 @@ public void validateCommand(SetTableIncrementForm form, Errors errors)
513509
@Override
514510
public ModelAndView getConfirmView(SetTableIncrementForm form, BindException errors) throws Exception
515511
{
516-
HtmlStringBuilder sb = HtmlStringBuilder.of();
517-
sb.unsafeAppend("This allows you to initialize the autoincrementing column for the provided schema/query<br><br>");
518-
sb.unsafeAppend("This is very rarely required and was created as a helper for admins with a good deal of knowledge about this module. Under most cases these columns will be automatically populated and you will not need to worry about this. If you are unsure about this page, please post on the LabKey help forums, which are read by the authors of this module.<br><br>");
519-
sb.unsafeAppend("<table style='border-collapse: collapse;'>");
520-
521512
String schema = form.getSchemaName() == null ? "" : form.getSchemaName();
522-
sb.unsafeAppend("<tr><td>Schema:</td><td><input name=\"schema\" value=\"").append(schema).unsafeAppend("\"></td></tr>");
523-
524513
String query = form.getQueryName() == null ? "" : form.getQueryName();
525-
sb.unsafeAppend("<tr><td>Query:</td><td><input name=\"query\" value=\"").append(query).unsafeAppend("\"></td></tr>");
526-
527-
sb.unsafeAppend("</table><br>Do you want to continue?");
528514

529-
return new HtmlView(sb.getHtmlString());
515+
return new HtmlView(createHtmlFragment(
516+
"This allows you to initialize the autoincrementing column for the provided schema/query", BR(), BR(),
517+
"This is very rarely required and was created as a helper for admins with a good deal of knowledge about this module. Under most cases these columns will be automatically populated and you will not need to worry about this. If you are unsure about this page, please post on the LabKey help forums, which are read by the authors of this module.", BR(), BR(),
518+
TABLE(at(style, "border-collapse: collapse;"),
519+
TR(TD("Schema:"), TD(INPUT(at().name("schema").value(schema)))),
520+
TR(TD("Query:"), TD(INPUT(at().name("query").value(query))))
521+
),
522+
BR(), "Do you want to continue?"
523+
));
530524
}
531525

532526

0 commit comments

Comments
 (0)