}
//TODO: refactor with CdaDataFactoryWriteHandler
final OutputStream outputStream = bundle.createEntry(fileName, "text/xml");
final DefaultTagDescription tagDescription =
new DefaultTagDescription(ClassicEngineBoot.getInstance().getGlobalConfig(), CdaModule.TAG_DEF_PREFIX);
final XmlWriter xmlWriter = new XmlWriter
(new OutputStreamWriter(outputStream, "UTF-8"), tagDescription, " ","\n");
final AttributeList rootAttrs = new AttributeList();
rootAttrs.addNamespaceDeclaration("data", CdaModule.NAMESPACE);
xmlWriter.writeTag(CdaModule.NAMESPACE, "cda-datasource", rootAttrs, XmlWriter.OPEN);
final CdaDataFactory dataFactory = (CdaDataFactory) rawDataFactory;
final AttributeList configAttrs = new AttributeList();
if (StringUtils.isEmpty(dataFactory.getBaseUrl()) == false)
{
configAttrs.setAttribute(CdaModule.NAMESPACE, "base-url", dataFactory.getBaseUrl());
}
if (StringUtils.isEmpty(dataFactory.getBaseUrlField()) == false)
{
configAttrs.setAttribute(CdaModule.NAMESPACE, "base-url-field", dataFactory.getBaseUrlField());
}
if (StringUtils.isEmpty(dataFactory.getSolution()) == false)
{
configAttrs.setAttribute(CdaModule.NAMESPACE, "solution", dataFactory.getSolution());
}
if (StringUtils.isEmpty(dataFactory.getPath()) == false)
{
configAttrs.setAttribute(CdaModule.NAMESPACE, "path", dataFactory.getPath());
}
if (StringUtils.isEmpty(dataFactory.getFile()) == false)
{
configAttrs.setAttribute(CdaModule.NAMESPACE, "file", dataFactory.getFile());
}
if (StringUtils.isEmpty(dataFactory.getUsername()) == false)
{
configAttrs.setAttribute(CdaModule.NAMESPACE, "username", dataFactory.getUsername());
}
if (StringUtils.isEmpty(dataFactory.getPassword()) == false)
{
configAttrs.setAttribute(CdaModule.NAMESPACE,
"password", PasswordEncryptionService.getInstance().encrypt(dataFactory.getPassword()));
}
configAttrs.setAttribute(CdaModule.NAMESPACE, "use-local-call", String.valueOf(dataFactory.isUseLocalCall()));
configAttrs.setAttribute(CdaModule.NAMESPACE, "is-sugar-mode", String.valueOf(dataFactory.isSugarMode()));
xmlWriter.writeTag(CdaModule.NAMESPACE, "config", configAttrs, XmlWriterSupport.CLOSE);
final String[] queryNames = dataFactory.getQueryNames();
for (int i = 0; i < queryNames.length; i++)
{
final String queryName = queryNames[i];
final CdaQueryEntry query = dataFactory.getQueryEntry(queryName);
final AttributeList queryAttr = new AttributeList();
queryAttr.setAttribute(CdaModule.NAMESPACE, "query", query.getId());
queryAttr.setAttribute(CdaModule.NAMESPACE, "name", query.getName());
xmlWriter.writeTag(CdaModule.NAMESPACE, "query", queryAttr, XmlWriterSupport.OPEN);
final ParameterMapping[] parameterMappings = query.getParameters();
for (int j = 0; j < parameterMappings.length; j++)
{
final ParameterMapping parameterMapping = parameterMappings[j];
final AttributeList paramAttr = new AttributeList();
paramAttr.setAttribute(CdaModule.NAMESPACE, "datarow-name", parameterMapping.getName());
paramAttr.setAttribute(CdaModule.NAMESPACE, "variable-name", parameterMapping.getAlias());
xmlWriter.writeTag(CdaModule.NAMESPACE, "variable", paramAttr, XmlWriterSupport.CLOSE);
}
xmlWriter.writeCloseTag();
}
xmlWriter.writeCloseTag();
xmlWriter.close();
return fileName;
}