Search in sources :

Example 1 with XMLValidator

use of org.opengroup.archimate.xmlexchange.XMLValidator in project archi by archimatetool.

the class ImportXMLProvider method run.

@Override
public void run(CommandLine commandLine) throws Exception {
    if (!hasCorrectOptions(commandLine)) {
        return;
    }
    // File
    String value = commandLine.getOptionValue(OPTION_IMPORT_XML);
    if (!StringUtils.isSet(value)) {
        logError(Messages.ImportXMLProvider_1);
        return;
    }
    File importFile = new File(value);
    if (!importFile.exists()) {
        logError(NLS.bind(Messages.ImportXMLProvider_2, value));
        return;
    }
    // Validate file
    logMessage(Messages.ImportXMLProvider_3);
    XMLValidator validator = new XMLValidator();
    validator.validateXML(importFile);
    logMessage(Messages.ImportXMLProvider_4);
    logMessage(NLS.bind(Messages.ImportXMLProvider_5, importFile.getPath()));
    XMLModelImporter importer = new XMLModelImporter();
    IArchimateModel model = importer.createArchiMateModel(importFile);
    if (model == null) {
        throw new IOException(Messages.ImportXMLProvider_6);
    }
    // Add an Archive Manager
    IArchiveManager archiveManager = IArchiveManager.FACTORY.createArchiveManager(model);
    model.setAdapter(IArchiveManager.class, archiveManager);
    // Add a Command Stack
    CommandStack cmdStack = new CommandStack();
    model.setAdapter(CommandStack.class, cmdStack);
    CommandLineState.setModel(model);
    logMessage(Messages.ImportXMLProvider_7);
}
Also used : CommandStack(org.eclipse.gef.commands.CommandStack) XMLModelImporter(org.opengroup.archimate.xmlexchange.XMLModelImporter) IOException(java.io.IOException) IArchiveManager(com.archimatetool.editor.model.IArchiveManager) File(java.io.File) IArchimateModel(com.archimatetool.model.IArchimateModel) XMLValidator(org.opengroup.archimate.xmlexchange.XMLValidator)

Example 2 with XMLValidator

use of org.opengroup.archimate.xmlexchange.XMLValidator in project archi by archimatetool.

the class ExportXMLProvider method run.

@Override
public void run(CommandLine commandLine) throws Exception {
    if (!hasCorrectOptions(commandLine)) {
        return;
    }
    IArchimateModel model = CommandLineState.getModel();
    if (model == null) {
        throw new IOException(Messages.ExportXMLProvider_1);
    }
    // File
    String value = commandLine.getOptionValue(OPTION_EXPORT_XML);
    if (!StringUtils.isSet(value)) {
        logError(Messages.ExportXMLProvider_2);
        return;
    }
    File outputFile = new File(value);
    XMLModelExporter exporter = new XMLModelExporter();
    // Folders
    exporter.setSaveOrganisation(commandLine.hasOption(OPTION_EXPORT_XML_FOLDERS));
    // Language
    exporter.setLanguageCode(commandLine.getOptionValue(OPTION_EXPORT_XML_LANGUAGE));
    logMessage(NLS.bind(Messages.ExportXMLProvider_3, model.getName(), outputFile.getPath()));
    exporter.exportModel(model, outputFile);
    logMessage(Messages.ExportXMLProvider_4);
    // Validate file
    logMessage(Messages.ExportXMLProvider_5);
    XMLValidator validator = new XMLValidator();
    validator.validateXML(outputFile);
    logMessage(Messages.ExportXMLProvider_6);
}
Also used : XMLModelExporter(org.opengroup.archimate.xmlexchange.XMLModelExporter) IOException(java.io.IOException) IArchimateModel(com.archimatetool.model.IArchimateModel) File(java.io.File) XMLValidator(org.opengroup.archimate.xmlexchange.XMLValidator)

Aggregations

IArchimateModel (com.archimatetool.model.IArchimateModel)2 File (java.io.File)2 IOException (java.io.IOException)2 XMLValidator (org.opengroup.archimate.xmlexchange.XMLValidator)2 IArchiveManager (com.archimatetool.editor.model.IArchiveManager)1 CommandStack (org.eclipse.gef.commands.CommandStack)1 XMLModelExporter (org.opengroup.archimate.xmlexchange.XMLModelExporter)1 XMLModelImporter (org.opengroup.archimate.xmlexchange.XMLModelImporter)1