@Override public boolean shouldIncludeContent(FormEntrySession session, Node parent, Node node) { String mode = HtmlFormEntryUtil.getNodeAttribute(node, "mode", null); String include = HtmlFormEntryUtil.getNodeAttribute(node, "include", "true"); if (mode == null) { throw new RuntimeException("ifMode tag requires the mode attribute"); } boolean modeIsCurrent = mode.equalsIgnoreCase(session.getContext().getMode().toString()); return include.equals("true") ? modeIsCurrent : !modeIsCurrent; } }
String defaultLocaleStr = HtmlFormEntryUtil.getNodeAttribute(transNode, "defaultLocale", "en"); Node codeNode = codeNodeList.item(i); if (codeNode.getNodeName().equalsIgnoreCase("code")) { String codeName = HtmlFormEntryUtil.getNodeAttribute(codeNode, "name", null); if (codeName == null) { throw new IllegalArgumentException("All translation elements must contain a valid code name"); Node variantNode = variantNodeList.item(j); if (variantNode.getNodeName().equalsIgnoreCase("variant")) { String localeStr = HtmlFormEntryUtil.getNodeAttribute(variantNode, "locale", defaultLocaleStr); String valueStr = HtmlFormEntryUtil.getNodeAttribute(variantNode, "value", null); if (valueStr == null) { throw new IllegalArgumentException("All variants must specify a value");
Node node = children.item(i); if ("macro".equals(node.getNodeName())) { String key = HtmlFormEntryUtil.getNodeAttribute(node, "key", ""); if (StringUtils.isBlank(key)) { throw new IllegalArgumentException("Macros must define a 'key' attribute"); String value = HtmlFormEntryUtil.getNodeAttribute(node, "value", ""); if (StringUtils.isBlank(value)) { String expression = HtmlFormEntryUtil.getNodeAttribute(node, "expression", ""); if (StringUtils.isBlank(expression)) { throw new IllegalArgumentException("Macros must define either a 'value' or 'expression' attribute");
TagAnalysis analysis = new TagAnalysis(); List<Concept> concepts = new ArrayList<Concept>(); String conceptId = HtmlFormEntryUtil.getNodeAttribute(node, "conceptId", null); String conceptIds = HtmlFormEntryUtil.getNodeAttribute(node, "conceptIds", null); String answerConceptId = HtmlFormEntryUtil.getNodeAttribute(node, "answerConceptId", null); String answerConceptIds = HtmlFormEntryUtil.getNodeAttribute(node, "answerConceptIds", null); List<Concept> setMembers = concept == null ? concepts : Arrays.asList(concept); while (parentNode.getParentNode() != null) { String groupingConceptId = HtmlFormEntryUtil.getNodeAttribute(parentNode, "groupingConceptId", null); if (groupingConceptId != null) { Concept groupingConcept = HtmlFormEntryUtil.getConcept(groupingConceptId);
@Override public TagAnalysis validate(Node node) { TagAnalysis analysis = new TagAnalysis(); String groupingConceptId = HtmlFormEntryUtil.getNodeAttribute(node, "groupingConceptId", null); if (groupingConceptId == null) { analysis.addError(Context.getMessageSourceService().getMessage("htmlformentry.error.groupingConceptIdMissing")); } Concept groupingConcept = HtmlFormEntryUtil.getConcept(groupingConceptId); if (analysis.getErrors().size() == 0 && groupingConcept == null) { analysis.addError(Context.getMessageSourceService().getMessage("htmlformentry.error.invalidConcept", new Object[] { groupingConceptId }, null)); } if (groupingConcept != null && !groupingConcept.isSet()) { analysis.addWarning(Context.getMessageSourceService().getMessage("htmlformentry.warning.groupingConcept", new Object[] { groupingConceptId }, null)); } return analysis; }
@Test public void validate_shouldPassWhenObsIsAMemberOfParentObsgroup() throws Exception { String xml = "<htmlform>\n" + "<obsgroup groupingConceptId=\"23\">\n" + "<obs conceptId=\"18\" />\n" + " </obsgroup>\n </htmlform>"; Document document = HtmlFormEntryUtil.stringToDocument(xml); Node parentObsGroupNode = HtmlFormEntryUtil.findDescendant(document, "obsgroup"); Assert.assertEquals("23", HtmlFormEntryUtil.getNodeAttribute(parentObsGroupNode, "groupingConceptId", null)); Node obsNode = HtmlFormEntryUtil.findChild(parentObsGroupNode, "obs"); TagAnalysis analysis = new ObsTagHandler().validate(obsNode); Assert.assertEquals(0, analysis.getWarnings().size()); }
@Test public void validate_shouldWarnWhenObsIsNotAMemberOfParentObsgroup() throws Exception { String xml = "<htmlform>\n" + "<obsgroup groupingConceptId=\"23\">\n" + "<obs conceptId=\"4\" />\n" + "</obsgroup>\n </htmlform>"; Document document = HtmlFormEntryUtil.stringToDocument(xml); Node parentObsGroupNode = HtmlFormEntryUtil.findDescendant(document, "obsgroup"); Assert.assertEquals("23", HtmlFormEntryUtil.getNodeAttribute(parentObsGroupNode, "groupingConceptId", null)); Node obsNode = HtmlFormEntryUtil.findChild(parentObsGroupNode, "obs"); TagAnalysis analysis = new ObsTagHandler().validate(obsNode); Assert.assertEquals(1, analysis.getWarnings().size()); }