use of org.akaza.openclinica.web.pform.dto.Html in project OpenClinica by OpenClinica.
the class OpenRosaXmlGenerator method buildForm.
/**
* @param formId
* @return
* @throws Exception
*/
public String buildForm(String formId) throws Exception {
try {
CRFVersionDAO versionDAO = new CRFVersionDAO(dataSource);
FormLayoutDAO fldao = new FormLayoutDAO<>(dataSource);
FormLayoutBean formLayout = fldao.findByOid(formId);
CRFDAO crfDAO = new CRFDAO(dataSource);
CRFBean crf = (CRFBean) crfDAO.findByPK(formLayout.getCrfId());
CRFVersionMetadataUtil metadataUtil = new CRFVersionMetadataUtil(dataSource);
ArrayList<SectionBean> crfSections = metadataUtil.retrieveFormMetadata(formLayout);
ArrayList<CRFVersionBean> crfVersions = versionDAO.findAllByCRFId(crf.getId());
CRFVersionBean crfVersion = crfVersions.get(0);
StringWriter writer = new StringWriter();
IOUtils.copy(getClass().getResourceAsStream("/properties/xform_template.xml"), writer, "UTF-8");
String xform = writer.toString();
Html html = buildJavaXForm(xform);
int sectionCount = mapBeansToDTO(html, crf, crfVersion, crfSections);
if (sectionCount > 1)
setFormPaging(html);
String xformMinusInstance = buildStringXForm(html);
String preInstance = xformMinusInstance.substring(0, xformMinusInstance.indexOf("<instance>"));
String instance = buildInstance(html.getHead().getModel(), formLayout, crfVersion, crfSections);
String nodeset = xformMinusInstance.substring(xformMinusInstance.indexOf("</instance>") + "</instance>".length());
// add nodeset for instanceId
String postInstance = "<bind calculate=\"concat('uuid:', uuid())\" nodeset=\"/" + formLayout.getOid() + "/meta/instanceID\" readonly=\"true()\" type=\"string\"/>" + nodeset;
logger.debug(preInstance + "<instance>\n" + instance + "\n</instance>" + postInstance);
System.out.println(preInstance + "<instance>\n" + instance + "\n</instance>" + postInstance);
return preInstance + "<instance>\n" + instance + "\n</instance>" + postInstance;
} catch (Exception e) {
log.error(e.getMessage());
log.error(ExceptionUtils.getStackTrace(e));
throw new Exception(e);
}
}
use of org.akaza.openclinica.web.pform.dto.Html in project OpenClinica by OpenClinica.
the class OpenRosaXmlGenerator method buildJavaXForm.
private Html buildJavaXForm(String content) throws Exception {
// XML to Object
Reader reader = new StringReader(content);
Unmarshaller unmarshaller = xmlContext.createUnmarshaller();
unmarshaller.setClass(Html.class);
unmarshaller.setWhitespacePreserve(false);
Html html = (Html) unmarshaller.unmarshal(reader);
reader.close();
return html;
}
Aggregations