Search in sources :

Example 6 with DataSourcePropertiesInterface

use of com.sldeditor.common.DataSourcePropertiesInterface in project sldeditor by robward-scisys.

the class VectorTool method importFile.

/**
 * Import file.
 *
 * @param fileTreeNode the file tree node
 */
protected boolean importFile(FileTreeNode fileTreeNode) {
    if (fileTreeNode != null) {
        File vectorFile = fileTreeNode.getFile();
        ConsoleManager.getInstance().information(this, String.format("%s : %s", Localisation.getString(VectorTool.class, "VectorTool.createSymbol"), vectorFile.getAbsolutePath()));
        SLDDataInterface sldData = vectorReader.createVectorSLDData(vectorFile);
        DataSourcePropertiesInterface dsProperties = SLDEditorFile.getInstance().getDataSource();
        DataSourceConnectorInterface dsc = DataSourceConnectorFactory.getDataSource(DataSourceConnector.class);
        try {
            String vectorFilename = vectorFile.toURI().toURL().toString();
            dsProperties = dsc.getDataSourceProperties(DataSourceProperties.encodeFilename(vectorFilename));
        } catch (MalformedURLException exceptionObj) {
            ConsoleManager.getInstance().exception(VectorTool.class, exceptionObj);
            return false;
        }
        loadSymbol(dsProperties, sldData, vectorFile);
    }
    return true;
}
Also used : MalformedURLException(java.net.MalformedURLException) SLDDataInterface(com.sldeditor.common.SLDDataInterface) DataSourceConnectorInterface(com.sldeditor.common.DataSourceConnectorInterface) DataSourcePropertiesInterface(com.sldeditor.common.DataSourcePropertiesInterface) SLDEditorFile(com.sldeditor.datasource.SLDEditorFile) File(java.io.File)

Example 7 with DataSourcePropertiesInterface

use of com.sldeditor.common.DataSourcePropertiesInterface in project sldeditor by robward-scisys.

the class SLDEditorFileTest method testSLDData.

/**
 * Test method for {@link com.sldeditor.datasource.SLDEditorFile#getSLDData()}. Test method for
 * {@link com.sldeditor.datasource.SLDEditorFile#fileOpenedSaved()}. Test method for
 * {@link com.sldeditor.datasource.SLDEditorFile#getSldEditorFile()}. Test method for
 * {@link com.sldeditor.datasource.SLDEditorFile#addSLDEditorFileUpdateListener(com.sldeditor.datasource.SLDEditorDataUpdateInterface)}.
 * Test method for {@link com.sldeditor.datasource.SLDEditorFile#renderSymbol()}. Test method
 * for
 * {@link com.sldeditor.datasource.SLDEditorFile#setSLDData(com.sldeditor.common.SLDDataInterface)}.
 * Test method for {@link com.sldeditor.datasource.SLDEditorFile#setSldFile(java.io.File)}. Test
 * method for {@link com.sldeditor.datasource.SLDEditorFile#getDataSource()}. Test method for
 * {@link com.sldeditor.datasource.SLDEditorFile#setDataSource(com.sldeditor.DataSourcePropertiesInterface)}.
 * Test method for
 * {@link com.sldeditor.datasource.SLDEditorFile#setSldEditorFile(java.io.File)}.
 */
@Test
public void testSLDData() {
    // Start with a blank canvas
    SLDEditorFile.destroyInstance();
    SelectedSymbol.destroyInstance();
    assertNull(SLDEditorFile.getInstance().getSLD());
    assertNull(SLDEditorFile.getInstance().getSLDData());
    assertNull(SLDEditorFile.getInstance().getSldEditorFile());
    assertNull(SLDEditorFile.getInstance().getDataSource());
    SLDEditorFile.getInstance().setDataSource(null);
    assertNull(SLDEditorFile.getInstance().getDataSource());
    SLDEditorFile.getInstance().setSldEditorFile(null);
    assertNull(SLDEditorFile.getInstance().getSldEditorFile());
    SLDEditorFile.getInstance().setSldFile(null);
    assertNull(SLDEditorFile.getInstance().getSLDData());
    SLDEditorFile.getInstance().setSLDData(null);
    assertNull(SLDEditorFile.getInstance().getSLDData());
    DummyDataUpdate dataUpdateListener = new DummyDataUpdate();
    SLDEditorFile.getInstance().addSLDEditorFileUpdateListener(dataUpdateListener);
    // Set SLDData
    StyleWrapper styleWrapper = new StyleWrapper("workspace", "style");
    SLDData sldData = new SLDData(styleWrapper, "contents");
    SLDEditorFile.getInstance().setSLDData(sldData);
    SLDEditorFile.getInstance().fileOpenedSaved();
    assertEquals(sldData, SLDEditorFile.getInstance().getSLDData());
    assertFalse(dataUpdateListener.dataEditedFlag);
    // Sld file
    File sldFile = new File("test.txt");
    SLDEditorFile.getInstance().setSldFile(sldFile);
    assertEquals(sldFile.getAbsolutePath(), SLDEditorFile.getInstance().getSLDData().getSLDFile().getAbsolutePath());
    assertFalse(dataUpdateListener.dataEditedFlag);
    // Sld editor file
    File sldEditorFile = new File("editor.file");
    SLDEditorFile.getInstance().setSldEditorFile(sldEditorFile);
    assertEquals(sldEditorFile.getAbsolutePath(), SLDEditorFile.getInstance().getSldEditorFile().getAbsolutePath());
    assertFalse(dataUpdateListener.dataEditedFlag);
    // Data source properties
    SLDEditorFile.getInstance().setDataSource(null);
    assertFalse(dataUpdateListener.dataEditedFlag);
    DataSourcePropertiesInterface noDataSource = DataSourceConnectorFactory.getNoDataSource();
    assertEquals(noDataSource.getDebugConnectionString(), SLDEditorFile.getInstance().getDataSource().getDebugConnectionString());
    assertFalse(dataUpdateListener.dataEditedFlag);
    DataSourcePropertiesInterface fileDSProperties = new DataSourceProperties(new DataSourceConnector());
    assertEquals(fileDSProperties.getDebugConnectionString(), SLDEditorFile.getInstance().getDataSource().getDebugConnectionString());
    assertFalse(dataUpdateListener.dataEditedFlag);
    // Render symbol
    SLDEditorFile.getInstance().renderSymbol();
    assertTrue(dataUpdateListener.dataEditedFlag);
    // File saved
    SLDEditorFile.getInstance().fileOpenedSaved();
    assertFalse(dataUpdateListener.dataEditedFlag);
    assertNull(SLDEditorFile.getInstance().getRuleRenderOptions());
}
Also used : DataSourceConnector(com.sldeditor.datasource.connector.instance.DataSourceConnector) SLDData(com.sldeditor.common.data.SLDData) StyleWrapper(com.sldeditor.common.data.StyleWrapper) DataSourcePropertiesInterface(com.sldeditor.common.DataSourcePropertiesInterface) DataSourceProperties(com.sldeditor.datasource.impl.DataSourceProperties) SLDEditorFile(com.sldeditor.datasource.SLDEditorFile) File(java.io.File) Test(org.junit.Test)

Example 8 with DataSourcePropertiesInterface

use of com.sldeditor.common.DataSourcePropertiesInterface in project sldeditor by robward-scisys.

the class DataSourceConnectorFactoryTest method testGetNoDataSource.

/**
 * Test method for {@link com.sldeditor.datasource.connector.DataSourceConnectorFactory#getNoDataSource()}.
 */
@Test
public void testGetNoDataSource() {
    DataSourcePropertiesInterface dsp = DataSourceConnectorFactory.getNoDataSource();
    assertEquals(DataSourceConnectorEmpty.class, dsp.getDataSourceConnector().getClass());
}
Also used : DataSourcePropertiesInterface(com.sldeditor.common.DataSourcePropertiesInterface) Test(org.junit.Test)

Example 9 with DataSourcePropertiesInterface

use of com.sldeditor.common.DataSourcePropertiesInterface in project sldeditor by robward-scisys.

the class DataSourceConnectorFactoryTest method testGetDataSourcePropertiesMapOfStringString.

/**
 * Test method for {@link com.sldeditor.datasource.connector.DataSourceConnectorFactory#getDataSourceProperties(java.util.Map)}.
 */
@Test
public void testGetDataSourcePropertiesMapOfStringString() {
    Map<String, Object> propertyMap = new HashMap<String, Object>();
    propertyMap.put("url", "filename.shp");
    DataSourcePropertiesInterface dsp = DataSourceConnectorFactory.getDataSourceProperties(propertyMap);
    assertEquals(DataSourceConnector.class, dsp.getDataSourceConnector().getClass());
    propertyMap.clear();
    propertyMap.put("host", "localhost");
    propertyMap.put("port", "5432");
    propertyMap.put("database", "testdb");
    propertyMap.put("user", "testuser");
    propertyMap.put("passwd", "pasword123");
    propertyMap.put("schema", "public");
    propertyMap.put("featureClass", "testfc");
    dsp = DataSourceConnectorFactory.getDataSourceProperties(propertyMap);
    assertEquals(DataSourceConnector.class, dsp.getDataSourceConnector().getClass());
}
Also used : HashMap(java.util.HashMap) DataSourcePropertiesInterface(com.sldeditor.common.DataSourcePropertiesInterface) Test(org.junit.Test)

Example 10 with DataSourcePropertiesInterface

use of com.sldeditor.common.DataSourcePropertiesInterface in project sldeditor by robward-scisys.

the class DataSourceConnectorFactoryTest method testGetDataSourcePropertiesString.

/**
 * Test method for {@link com.sldeditor.datasource.connector.DataSourceConnectorFactory#getDataSourceProperties(java.lang.String)}.
 */
@Test
public void testGetDataSourcePropertiesString() {
    DataSourcePropertiesInterface dsp = DataSourceConnectorFactory.getDataSourceProperties("filename.shp");
    assertEquals(DataSourceConnector.class, dsp.getDataSourceConnector().getClass());
}
Also used : DataSourcePropertiesInterface(com.sldeditor.common.DataSourcePropertiesInterface) Test(org.junit.Test)

Aggregations

DataSourcePropertiesInterface (com.sldeditor.common.DataSourcePropertiesInterface)21 Test (org.junit.Test)9 File (java.io.File)8 DataSourceConnectorInterface (com.sldeditor.common.DataSourceConnectorInterface)7 SLDEditorFile (com.sldeditor.datasource.SLDEditorFile)7 SLDDataInterface (com.sldeditor.common.SLDDataInterface)5 DataSourceConnector (com.sldeditor.datasource.connector.instance.DataSourceConnector)4 DataSourceProperties (com.sldeditor.datasource.impl.DataSourceProperties)4 HashMap (java.util.HashMap)4 SLDData (com.sldeditor.common.data.SLDData)3 DataSourceInterface (com.sldeditor.datasource.DataSourceInterface)3 IOException (java.io.IOException)3 MalformedURLException (java.net.MalformedURLException)3 DocumentBuilder (javax.xml.parsers.DocumentBuilder)3 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)3 StyleWrapper (com.sldeditor.common.data.StyleWrapper)2 VersionData (com.sldeditor.common.vendoroption.VersionData)2 DatabaseClientInterface (com.sldeditor.extension.filesystem.database.client.DatabaseClientInterface)2 EnvVar (com.sldeditor.filter.v2.envvar.EnvVar)2 LegendOptionData (com.sldeditor.ui.legend.option.LegendOptionData)2