use of ch.interlis.iom_j.iligml.Iligml20Writer in project ili2db by claeis.
the class TransferToXtf method doit.
public void doit(String filename, IoxWriter iomFile, String sender, String[] exportParamModelnames, long[] basketSqlIds, Map<Long, BasketStat> stat) throws ch.interlis.iox.IoxException {
this.basketStat = stat;
boolean referrs = false;
if (iomFile instanceof ItfWriter) {
config.setValue(ch.interlis.iox_j.validator.Validator.CONFIG_DO_ITF_LINETABLES, ch.interlis.iox_j.validator.Validator.CONFIG_DO_ITF_LINETABLES_DO);
}
if (config.getVer4_translation() || config.getIli1Translation() != null) {
languageFilter = new TranslateToTranslation(td, config);
}
if (config.getExportModels() != null) {
List<Model> exportModels = Ili2db.getModels(config.getExportModels(), td);
exportBaseModelFilter = new ReduceToBaseModel(exportModels, td, config);
}
if (config.isValidation()) {
ValidationConfig modelConfig = new ValidationConfig();
modelConfig.mergeIliMetaAttrs(td);
String configFilename = config.getValidConfigFile();
if (configFilename != null) {
try {
modelConfig.mergeConfigFile(new File(configFilename));
} catch (FileNotFoundException e) {
EhiLogger.logError("validator config file <" + configFilename + "> not found");
}
}
modelConfig.setConfigValue(ValidationConfig.PARAMETER, ValidationConfig.AREA_OVERLAP_VALIDATION, config.isDisableAreaValidation() ? ValidationConfig.OFF : null);
modelConfig.setConfigValue(ValidationConfig.PARAMETER, ValidationConfig.DEFAULT_GEOMETRY_TYPE_VALIDATION, config.isSkipGeometryErrors() ? ValidationConfig.OFF : null);
modelConfig.setConfigValue(ValidationConfig.PARAMETER, ValidationConfig.ALLOW_ONLY_MULTIPLICITY_REDUCTION, config.isOnlyMultiplicityReduction() ? ValidationConfig.ON : null);
IoxLogging errHandler = new ch.interlis.iox_j.logging.Log2EhiLogger();
LogEventFactory errFactory = new LogEventFactory();
errFactory.setDataSource(filename);
if (iomFile instanceof Iligml10Writer || iomFile instanceof Iligml20Writer) {
String crsAuthority = config.getDefaultSrsAuthority();
String crsCode = config.getDefaultSrsCode();
if (crsAuthority != null && crsCode != null) {
if (iomFile instanceof Iligml10Writer) {
((Iligml10Writer) iomFile).setDefaultCrs(crsAuthority + ":" + crsCode);
} else if (iomFile instanceof Iligml20Writer) {
((Iligml20Writer) iomFile).setDefaultCrs(crsAuthority + ":" + crsCode);
}
}
}
PipelinePool pipelinePool = new PipelinePool();
validator = new ch.interlis.iox_j.validator.Validator(td, modelConfig, errHandler, errFactory, pipelinePool, config);
}
StartTransferEvent startEvent = new StartTransferEvent();
startEvent.setSender(sender);
if (languageFilter != null) {
startEvent = (StartTransferEvent) languageFilter.filter(startEvent);
}
if (exportBaseModelFilter != null) {
startEvent = (StartTransferEvent) exportBaseModelFilter.filter(startEvent);
}
if (validator != null)
validator.validate(startEvent);
iomFile.write(startEvent);
if (basketSqlIds != null) {
for (long basketSqlId : basketSqlIds) {
StringBuilder basketXtfId = new StringBuilder();
Topic topic = getTopicByBasketId(basketSqlId, basketXtfId);
if (topic == null) {
throw new IoxException("no basketId " + basketSqlId + " in db");
} else {
referrs = referrs || doBasket(filename, iomFile, topic, basketSqlId, basketXtfId.toString());
}
}
} else {
// for all MODELs
for (String modelName : exportParamModelnames) {
Object mObj = td.getElement(Model.class, modelName);
if (mObj != null && (mObj instanceof Model) && !(suppressModel((Model) mObj))) {
Model model = (Model) mObj;
// for all TOPICs
Iterator topici = model.iterator();
while (topici.hasNext()) {
Object tObj = topici.next();
if (tObj instanceof Topic && !(suppressTopic((Topic) tObj))) {
Topic topic = (Topic) tObj;
referrs = referrs || doBasket(filename, iomFile, topic, null, topic.getScopedName(null));
}
}
}
}
}
if (referrs) {
throw new IoxException("dangling references");
}
EndTransferEvent endEvent = new EndTransferEvent();
if (languageFilter != null) {
endEvent = (EndTransferEvent) languageFilter.filter(endEvent);
}
if (exportBaseModelFilter != null) {
endEvent = (EndTransferEvent) exportBaseModelFilter.filter(endEvent);
}
if (validator != null)
validator.validate(endEvent);
iomFile.write(endEvent);
if (validator != null)
validator.close();
if (languageFilter != null) {
languageFilter.close();
}
if (exportBaseModelFilter != null) {
exportBaseModelFilter.close();
}
}
use of ch.interlis.iom_j.iligml.Iligml20Writer in project ili2db by claeis.
the class Ili2db method transferToXtf.
/**
* transfer data from database to xml file
*/
private static void transferToXtf(Connection conn, String xtffile, NameMapping ili2sqlName, TransferDescription td, SqlColumnConverter geomConv, String sender, Config config, String[] exportParamModelnames, long[] basketSqlIds, Map<Long, BasketStat> stat, TrafoConfig trafoConfig, Viewable2TableMapping class2wrapper) {
java.io.File outfile = new java.io.File(xtffile);
IoxWriter ioxWriter = null;
try {
if (Config.ILIGML20.equals(config.getTransferFileFormat())) {
ioxWriter = new Iligml20Writer(outfile, td);
} else {
String ext = ch.ehi.basics.view.GenericFileFilter.getFileExtension(xtffile).toLowerCase();
if (config.isItfTransferfile()) {
if (!config.getDoItfLineTables()) {
ioxWriter = new ItfWriter2(outfile, td);
} else {
ioxWriter = new ItfWriter(outfile, td);
}
config.setValue(ch.interlis.iox_j.validator.Validator.CONFIG_DO_ITF_OIDPERTABLE, ch.interlis.iox_j.validator.Validator.CONFIG_DO_ITF_OIDPERTABLE_DO);
} else if (ext != null && ext.equals("gml")) {
ioxWriter = new Iligml10Writer(outfile, td);
} else {
ioxWriter = new XtfWriter(outfile, td);
}
}
TransferToXtf trsfr = new TransferToXtf(ili2sqlName, td, conn, geomConv, config, trafoConfig, class2wrapper);
trsfr.doit(outfile.getName(), ioxWriter, sender, exportParamModelnames, basketSqlIds, stat);
// trsfr.doitJava();
ioxWriter.flush();
} catch (ch.interlis.iox.IoxException ex) {
EhiLogger.logError("failed to write xml output", ex);
} finally {
if (ioxWriter != null) {
try {
ioxWriter.close();
} catch (ch.interlis.iox.IoxException ex) {
EhiLogger.logError("failed to close xml output", ex);
}
}
ioxWriter = null;
}
}
Aggregations