use of com.sldeditor.common.DataSourceConnectorInterface in project sldeditor by robward-scisys.
the class DataSourcePropertiesTest method testEncodeDecodeXML.
/**
* Test method for {@link com.sldeditor.datasource.impl.DataSourceProperties#encodeXML(org.w3c.dom.Document, org.w3c.dom.Element, java.lang.String)}.
* Test method for {@link com.sldeditor.datasource.impl.DataSourceProperties#decodeXML(org.w3c.dom.Document, java.lang.String)}.
*/
@Test
public void testEncodeDecodeXML() {
Map<String, Object> propertyMap = new HashMap<String, Object>();
propertyMap.put("field1", "value1");
propertyMap.put("field2", "value2");
propertyMap.put("field3", "value3");
DataSourceConnectorInterface dsc = new DataSourceConnector();
DataSourceProperties dsp = new DataSourceProperties(dsc);
dsp.setPropertyMap(propertyMap);
dsp.setFilename("testfilename.shp");
dsp.setPassword("top secret password");
DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder documentBuilder = null;
try {
documentBuilder = documentBuilderFactory.newDocumentBuilder();
} catch (ParserConfigurationException e) {
e.printStackTrace();
fail(e.getMessage());
}
Document doc = documentBuilder.newDocument();
String elementName = "test_data_source_properties";
Element root = doc.createElement("test");
doc.appendChild(root);
dsp.encodeXML(doc, root, elementName);
// Try null parameters
dsp.encodeXML(null, null, null);
assertNull(DataSourceProperties.decodeXML(null, null));
// Now decode XML
DataSourcePropertiesInterface decodeDSP = DataSourceProperties.decodeXML(doc, elementName);
assertEquals(dsp.getConnectionProperties(), decodeDSP.getConnectionProperties());
}
use of com.sldeditor.common.DataSourceConnectorInterface in project sldeditor by robward-scisys.
the class DataSourcePropertiesTest method testDataSourcePropertiesWithConnector.
/**
* Test method for {@link com.sldeditor.datasource.impl.DataSourceProperties#DataSourceProperties(com.sldeditor.DataSourceConnectorInterface)}.
* Test method for {@link com.sldeditor.datasource.impl.DataSourceProperties#setPropertyMap(java.util.Map)}.
* Test method for {@link com.sldeditor.datasource.impl.DataSourceProperties#getDataSourceConnector()}.
*/
@Test
public void testDataSourcePropertiesWithConnector() {
Map<String, Object> propertyMap = new HashMap<String, Object>();
propertyMap.put("field1", "value1");
propertyMap.put("field2", "value2");
propertyMap.put("field3", "value3");
DataSourceConnectorInterface dsc = new DataSourceConnector();
DataSourceProperties dsp = new DataSourceProperties(dsc);
dsp.setPropertyMap(propertyMap);
Map<String, Object> actualPropertyMap = dsp.getConnectionProperties();
assertEquals(propertyMap, actualPropertyMap);
assertEquals(propertyMap, dsp.getAllConnectionProperties());
// Is empty
assertFalse(dsp.isEmpty());
}
use of com.sldeditor.common.DataSourceConnectorInterface in project sldeditor by robward-scisys.
the class RasterTool method createUI.
/**
* Creates the ui.
*/
private void createUI() {
rasterPanel = new JPanel();
FlowLayout flowLayout = (FlowLayout) rasterPanel.getLayout();
flowLayout.setVgap(0);
flowLayout.setHgap(0);
rasterPanel.setBorder(BorderFactory.createTitledBorder(Localisation.getString(RasterTool.class, "RasterTool.title")));
//
// Import raster
//
importRasterButton = new ToolButton(Localisation.getString(RasterTool.class, "RasterTool.import"), "tool/importraster.png");
rasterPanel.add(importRasterButton);
importRasterButton.setEnabled(false);
importRasterButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if ((nodeTypeList != null) && (nodeTypeList.size() == 1)) {
if (sldEditorInterface != null) {
FileTreeNode fileTreeNode = (FileTreeNode) nodeTypeList.get(0);
File rasterFile = fileTreeNode.getFile();
ConsoleManager.getInstance().information(this, String.format("%s : %s", Localisation.getString(RasterTool.class, "RasterTool.createSymbol"), rasterFile.getAbsolutePath()));
SLDDataInterface sldData = rasterReader.createRasterSLDData(rasterFile);
// Raster file
DataSourcePropertiesInterface dsProperties = SLDEditorFile.getInstance().getDataSource();
DataSourceConnectorInterface dsc = DataSourceConnectorFactory.getDataSource(DataSourceConnector.class);
dsProperties = dsc.getDataSourceProperties(DataSourceProperties.encodeFilename(rasterFile.getAbsolutePath()));
SLDEditorFile.getInstance().setSLDData(sldData);
SLDEditorFile.getInstance().setDataSource(dsProperties);
// Clear the data change flag
SLDEditorFile.getInstance().fileOpenedSaved();
// Load sld
List<SLDDataInterface> sldFilesToLoad = new ArrayList<SLDDataInterface>();
sldFilesToLoad.add(sldData);
SelectedFiles selectedFiles = new SelectedFiles();
selectedFiles.setSldData(sldFilesToLoad);
selectedFiles.setFolderName(rasterFile.getParent());
LoadSLDInterface loadSLD = sldEditorInterface.getLoadSLDInterface();
loadSLD.loadSLDString(selectedFiles);
}
}
}
});
//
// Set data source
//
dataSourceButton = new ToolButton(Localisation.getString(RasterTool.class, "RasterTool.dataSource"), "tool/setdatasource.png");
rasterPanel.add(dataSourceButton);
dataSourceButton.setEnabled(false);
dataSourceButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if ((nodeTypeList != null) && (nodeTypeList.size() == 1)) {
if (sldEditorInterface != null) {
FileTreeNode fileTreeNode = (FileTreeNode) nodeTypeList.get(0);
File rasterFile = fileTreeNode.getFile();
ConsoleManager.getInstance().information(this, String.format("%s : %s", Localisation.getString(RasterTool.class, "RasterTool.setDataSource"), rasterFile.getAbsolutePath()));
// Raster file
DataSourceConnectorInterface dsc = DataSourceConnectorFactory.getDataSource(DataSourceConnector.class);
String rasterFilename = null;
try {
rasterFilename = rasterFile.toURI().toURL().toString();
} catch (MalformedURLException exceptionObj) {
ConsoleManager.getInstance().exception(RasterTool.class, exceptionObj);
return;
}
DataSourcePropertiesInterface dsProperties = dsc.getDataSourceProperties(DataSourceProperties.encodeFilename(rasterFilename));
SLDEditorFile.getInstance().setDataSource(dsProperties);
DataSourceInterface dataSource = DataSourceFactory.createDataSource(null);
if (dataSource != null) {
dataSource.connect(rasterFilename, SLDEditorFile.getInstance(), null);
}
}
}
}
});
rasterPanel.setPreferredSize(new Dimension(PANEL_WIDTH, ToolPanel.TOOL_PANEL_HEIGHT));
}
use of com.sldeditor.common.DataSourceConnectorInterface in project sldeditor by robward-scisys.
the class VectorTool method setDataSource.
/**
* Sets the data source.
*
* @param fileTreeNode the new data source
*/
protected void setDataSource(FileTreeNode fileTreeNode) {
File vectorFile = fileTreeNode.getFile();
ConsoleManager.getInstance().information(this, String.format("%s : %s", Localisation.getString(VectorTool.class, "VectorTool.setDataSource"), vectorFile.getAbsolutePath()));
// Vector file
DataSourceConnectorInterface dsc = DataSourceConnectorFactory.getDataSource(DataSourceConnector.class);
DataSourcePropertiesInterface dsProperties = null;
try {
dsProperties = dsc.getDataSourceProperties(DataSourceProperties.encodeFilename(vectorFile.toURI().toURL().toString()));
} catch (MalformedURLException exceptionObj) {
ConsoleManager.getInstance().exception(VectorTool.class, exceptionObj);
return;
}
SLDEditorFile sldEditorFile = SLDEditorFile.getInstance();
sldEditorFile.setDataSource(dsProperties);
DataSourceInterface dataSource = DataSourceFactory.createDataSource(null);
if (dataSource != null) {
String dataSourceName = ExternalFilenames.removeSuffix(vectorFile.getName());
dataSource.connect(dataSourceName, sldEditorFile, CheckAttributeFactory.getCheckList());
}
}
use of com.sldeditor.common.DataSourceConnectorInterface in project sldeditor by robward-scisys.
the class DataSourcePropertiesTest method testPopulate.
/**
* Test method for {@link com.sldeditor.datasource.impl.DataSourceProperties#populate()}.
*/
@Test
public void testPopulate() {
DataSourceProperties dsp = new DataSourceProperties(null);
dsp.populate();
// Does nothing
DataSourceConnectorInterface dsc = new DataSourceConnector();
dsp = new DataSourceProperties(dsc);
dsp.populate();
}
Aggregations