platform independent file URL
[taxeditor.git] / taxeditor-store / src / main / java / eu / etaxonomy / taxeditor / io / wizard / JaxbImportWizard.java
1 // $Id$
2 /**
3 * Copyright (C) 2007 EDIT
4 * European Distributed Institute of Taxonomy
5 * http://www.e-taxonomy.eu
6 *
7 * The contents of this file are subject to the Mozilla Public License Version 1.1
8 * See LICENSE.TXT at the top of this package for the full license terms.
9 */
10
11 package eu.etaxonomy.taxeditor.io.wizard;
12
13 import java.io.File;
14 import java.net.URI;
15
16 import org.apache.log4j.Logger;
17 import org.eclipse.jface.viewers.IStructuredSelection;
18 import org.eclipse.ui.IWorkbench;
19
20 import eu.etaxonomy.cdm.database.DbSchemaValidation;
21 import eu.etaxonomy.cdm.io.jaxb.JaxbImportConfigurator;
22 import eu.etaxonomy.taxeditor.store.CdmStore;
23
24 /**
25 * @author n.hoffmann
26 * @created 15.06.2009
27 * @version 1.0
28 */
29 public class JaxbImportWizard extends AbstractImportWizard<JaxbImportConfigurator> {
30 private static final Logger logger = Logger
31 .getLogger(JaxbImportWizard.class);
32
33 private JaxbImportConfigurator configurator;
34
35 private ImportFromFileDataSourceWizardPage dataSourcePage;
36
37 /* (non-Javadoc)
38 * @see eu.etaxonomy.taxeditor.io.wizard.AbstractImportWizard#getConfigurator()
39 */
40 @Override
41 public JaxbImportConfigurator getConfigurator() {
42 return configurator;
43 }
44
45 /* (non-Javadoc)
46 * @see org.eclipse.jface.wizard.Wizard#performFinish()
47 */
48 @Override
49 public boolean performFinish() {
50
51 String platformDependendFile = dataSourcePage.getFile();
52
53
54 // Imports are expecting a string that can be used to instantiate a URL instance
55 // TODO consolidate import and exports regarding what may be passed in as source
56 // will construct a url string for now
57
58 File file = new File(platformDependendFile);
59 URI fileUri = file.toURI();
60
61 configurator.setSource(fileUri.toString());
62 configurator.setDbSchemaValidation(DbSchemaValidation.CREATE);
63
64 CdmStore.getImportHandler().run(configurator);
65
66 return true;
67 }
68
69 /* (non-Javadoc)
70 * @see org.eclipse.ui.IWorkbenchWizard#init(org.eclipse.ui.IWorkbench, org.eclipse.jface.viewers.IStructuredSelection)
71 */
72 public void init(IWorkbench workbench, IStructuredSelection selection) {
73 configurator = CdmStore.getImportHandler().JaxbConfigurator();
74 }
75
76 /* (non-Javadoc)
77 * @see eu.etaxonomy.taxeditor.io.wizard.AbstractImportWizard#addPages()
78 */
79 @Override
80 public void addPages() {
81 super.addPages();
82
83 dataSourcePage = new ImportFromFileDataSourceWizardPage("Choose File",
84 "Please choose an XML file in the cdm JAXB format.", new String[]{"*.xml"});
85 addPage(dataSourcePage);
86 }
87 }