String value = "";
if (matcherValue.find()) {
value = matcherValue.group(1);
}
Element element = new CheckBox();
element.setProperty("id", name);
element.setParent(this);
String[] values = FormUtil.getElementPropertyValues(element, formData);
Boolean checked = false;
if (values != null && values.length > 0) {
for (String v : values) {
if (value.equals(v)) {
checked = true;
}
}
}
newInputString = newInputString.replaceFirst("checked", "");
newInputString = newInputString.replaceFirst("checked=\"true\"", "");
newInputString = newInputString.replaceFirst("checked=\"checked\"", "");
if (checked) {
newInputString = newInputString.replaceFirst("value=\"", "checked=\"checked\" value=\"");
}
} else if (type.equalsIgnoreCase("file") || type.equalsIgnoreCase("button") || type.equalsIgnoreCase("submit") || type.equalsIgnoreCase("reset") || type.equalsIgnoreCase("image")) {
//ignore
} else {
Element element = new TextField();
element.setProperty("id", name);
element.setParent(this);
String value = FormUtil.getElementPropertyValue(element, formData);
newInputString = newInputString.replaceFirst("value=\"[^\\\"]*\"", "value=\"" + StringUtil.escapeRegex(StringEscapeUtils.escapeHtml(value)) + "\"");
}
customHTML = customHTML.replaceFirst(StringUtil.escapeRegex(inputString), StringUtil.escapeRegex(newInputString));
}
//textarea
Pattern patternTextarea = Pattern.compile("<textarea[^>]*>.*?</textarea>", Pattern.DOTALL);
Matcher matcherTextarea = patternTextarea.matcher(customHTML);
while (matcherTextarea.find()) {
String textareaString = matcherTextarea.group(0);
String newTextareaString = textareaString;
//get the name
Pattern patternName = Pattern.compile("name=\"([^\\\"]*)\"");
Matcher matcherName = patternName.matcher(textareaString);
String name = "";
if (matcherName.find()) {
name = matcherName.group(1);
}
Element element = new TextField();
element.setProperty("id", name);
element.setParent(this);
String value = FormUtil.getElementPropertyValue(element, formData);
newTextareaString = newTextareaString.replaceFirst(">.*?</", ">" + StringUtil.escapeRegex(StringEscapeUtils.escapeHtml(value)) + "</");
customHTML = customHTML.replaceFirst(StringUtil.escapeRegex(textareaString), StringUtil.escapeRegex(newTextareaString));
}
//Select Box
Pattern patternSelect = Pattern.compile("<select[^>]*>.*?</select>", Pattern.DOTALL);
Matcher matcherSelect = patternSelect.matcher(customHTML);
while (matcherSelect.find()) {
String selectString = matcherSelect.group(0);
String newSelectString = selectString;
//get the name
Pattern patternName = Pattern.compile("name=\"([^\\\"]*)\"");
Matcher matcherName = patternName.matcher(selectString);
String name = "";
if (matcherName.find()) {
name = matcherName.group(1);
}
Element element = new SelectBox();
element.setProperty("id", name);
element.setParent(this);
String[] values = FormUtil.getElementPropertyValues(element, formData);
//get the option
Pattern patternOption = Pattern.compile("<option[^>]*>.*?</option>");
Matcher matcherOption = patternOption.matcher(selectString);