use of com.sldeditor.common.vendoroption.VersionData in project sldeditor by robward-scisys.
the class VersionDataTest method testToString.
/**
* Test method for {@link com.sldeditor.common.vendoroption.VersionData#toString()}.
*/
@Test
public void testToString() {
String expectedVersionString = "1.2.3";
VersionData versionData1 = VersionData.decode(getClass(), expectedVersionString);
assertEquals(expectedVersionString, versionData1.toString());
}
use of com.sldeditor.common.vendoroption.VersionData in project sldeditor by robward-scisys.
the class VendorOptionInfoTest method testVendorOptionInfo.
/**
* Test method for {@link com.sldeditor.common.vendoroption.info.VendorOptionInfo#VendorOptionInfo(java.lang.String, com.sldeditor.common.vendoroption.VendorOptionVersion, java.lang.String)}.
* Test method for {@link com.sldeditor.common.vendoroption.info.VendorOptionInfo#getName()}.
* Test method for {@link com.sldeditor.common.vendoroption.info.VendorOptionInfo#getDescription()}.
* Test method for {@link com.sldeditor.common.vendoroption.info.VendorOptionInfo#getVersionData()}.
* Test method for {@link com.sldeditor.common.vendoroption.info.VendorOptionInfo#getVersionString()}.
*/
@Test
public void testVendorOptionInfo() {
String name = "name";
String description = "test description";
VendorOptionInfo info = new VendorOptionInfo(name, null, description);
assertEquals(name, info.getName());
assertEquals(description, info.getDescription());
assertNull(info.getVersionData());
assertEquals("", info.getVersionString());
VersionData versionDataMin = VersionData.decode(getClass(), "2.4.1");
VersionData versionDataMax = VersionData.decode(getClass(), "2.8.3");
VendorOptionVersion versionData = new VendorOptionVersion(GeoServerVendorOption.class, versionDataMin, versionDataMax);
VendorOptionInfo info2 = new VendorOptionInfo(name, versionData, description);
assertEquals("GeoServer 2.4.1-2.8.3", info2.getVersionString());
assertEquals(0, info.compareTo(info));
assertEquals(1, info.compareTo(info2));
assertEquals(-1, info2.compareTo(info));
VendorOptionVersion versionData2 = new VendorOptionVersion(GeoServerVendorOption.class, VersionData.decode(getClass(), "2.2.1"), versionDataMax);
VendorOptionInfo info3 = new VendorOptionInfo(name, versionData2, description);
assertEquals(-1, info3.compareTo(info2));
assertEquals(1, info2.compareTo(info3));
}
use of com.sldeditor.common.vendoroption.VersionData in project sldeditor by robward-scisys.
the class PrefManagerTest method testInitialise.
/**
* Test method for {@link com.sldeditor.common.preferences.PrefManager#initialise(com.sldeditor.common.property.PropertyManagerInterface)}.
*/
@Test
public void testInitialise() {
PrefManager.initialise(null);
DummyPropertyManager propertyManager = new DummyPropertyManager();
PrefManager.initialise(propertyManager);
PrefData prefData = new PrefData();
prefData.setUseAntiAlias(true);
Color backgroundColour = Color.GRAY;
prefData.setBackgroundColour(backgroundColour);
List<VersionData> vendorOptionList = new ArrayList<VersionData>();
vendorOptionList.add(VendorOptionManager.getInstance().getDefaultVendorOptionVersionData());
prefData.setVendorOptionVersionList(vendorOptionList);
String uiLayoutClass = "perfect curve";
prefData.setUiLayoutClass(uiLayoutClass);
PrefManager.getInstance().setPrefData(prefData);
Color newBackgroundColour = Color.RED;
prefData.setBackgroundColour(newBackgroundColour);
PrefManager.getInstance().setPrefData(prefData);
assertEquals(newBackgroundColour, propertyManager.getColourValue("SldEditor.backgroundColour", null));
boolean newAntiAlias = false;
prefData.setUseAntiAlias(newAntiAlias);
PrefManager.getInstance().setPrefData(prefData);
assertEquals(newAntiAlias, propertyManager.getBooleanValue("SldEditor.useAntiAlias", true));
String newLayoutClass = "bendy line";
prefData.setUiLayoutClass(newLayoutClass);
PrefManager.getInstance().setPrefData(prefData);
assertEquals(newLayoutClass, propertyManager.getStringValue("SldEditor.uilayout", null));
List<VersionData> newVendorOptionList = new ArrayList<VersionData>();
newVendorOptionList.add(VendorOptionManager.getInstance().getDefaultVendorOptionVersionData());
prefData.setVendorOptionVersionList(newVendorOptionList);
PrefManager.getInstance().setPrefData(prefData);
newVendorOptionList.add(VersionData.getLatestVersion(GeoServerVendorOption.class));
prefData.setVendorOptionVersionList(newVendorOptionList);
PrefManager.getInstance().setPrefData(prefData);
List<String> encodelist = new ArrayList<String>();
for (VersionData versionData : newVendorOptionList) {
encodelist.add(versionData.getEncodedString());
}
assertTrue(PrefManager.cmpList(encodelist, propertyManager.getStringListValue("SldEditor.vendorOptions")));
PrefManager.initialise(null);
}
use of com.sldeditor.common.vendoroption.VersionData in project sldeditor by robward-scisys.
the class VendorOptionTableModelTest method testGetVendorOption.
/**
* Test method for
* {@link com.sldeditor.common.vendoroption.selection.VendorOptionTableModel#getVendorOption(int)}.
* Test method for
* {@link com.sldeditor.common.vendoroption.selection.VendorOptionTableModel#setSelectedVendorOptionVersions(java.util.List)}.
* Test method for
* {@link com.sldeditor.common.vendoroption.selection.VendorOptionTableModel#getVendorOptionVersionList()}.
*/
@Test
public void testGetVendorOption() {
Map<VendorOptionTypeInterface, String> options = new LinkedHashMap<VendorOptionTypeInterface, String>();
VendorOptionTypeInterface vendorOption = VendorOptionManager.getInstance().getClass(GeoServerVendorOption.class);
options.put(vendorOption, vendorOption.getName());
VendorOptionTableModel model = new VendorOptionTableModel(options, null);
assertEquals(1, model.getRowCount());
// Try invalid calls to getVendorOption
assertNull(model.getVendorOption(-1));
assertNull(model.getVendorOption(1));
// Valid call to getVendorOption
List<VersionData> actualList = model.getVendorOption(0);
assertEquals(vendorOption.getVersionList().size(), actualList.size());
assertEquals(Localisation.getString(VendorOptionTableModel.class, "common.notSet"), actualList.get(0).getVersionString());
model.setSelectedVendorOptionVersions(null);
List<VersionData> selectedVersionList = new ArrayList<VersionData>();
VersionData expectedVersionData = vendorOption.getVersionList().get(1);
selectedVersionList.add(expectedVersionData);
model.setSelectedVendorOptionVersions(selectedVersionList);
actualList = model.getVendorOptionVersionList();
assertEquals(2, actualList.size());
assertEquals(VendorOptionManager.getInstance().getDefaultVendorOptionVersionData(), actualList.get(0));
assertEquals(expectedVersionData.getVersionString(), actualList.get(1).getVersionString());
// Try with unknown
selectedVersionList = new ArrayList<VersionData>();
expectedVersionData = VersionData.getEarliestVersion(Double.class);
selectedVersionList.add(expectedVersionData);
model.setSelectedVendorOptionVersions(selectedVersionList);
actualList = model.getVendorOptionVersionList();
assertEquals(1, actualList.size());
assertEquals(VendorOptionManager.getInstance().getDefaultVendorOptionVersionData(), actualList.get(0));
}
use of com.sldeditor.common.vendoroption.VersionData in project sldeditor by robward-scisys.
the class SLDEditorFileHandler method save.
/*
* (non-Javadoc)
*
* @see com.sldeditor.extension.input.file.FileHandlerInterface#save(com.sldeditor.ui.iface.SLDDataInterface)
*/
@Override
public boolean save(SLDDataInterface sldData) {
if (sldData == null) {
return false;
}
File fileToSave = sldData.getSldEditorFile();
DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder documentBuilder;
try {
documentBuilder = documentBuilderFactory.newDocumentBuilder();
Document doc = documentBuilder.newDocument();
Element root = doc.createElement(SLDEditorFileHandler.ROOT_ELEMENT);
doc.appendChild(root);
// SLD contents
Element sldElement = doc.createElement(SLDEditorFileHandler.SLD_ELEMENT);
sldElement.appendChild(doc.createTextNode(sldData.getSLDFile().getAbsolutePath()));
root.appendChild(sldElement);
// Vendor options
List<VersionData> vendorOptionList = sldData.getVendorOptionList();
if (vendorOptionList != null) {
for (VersionData versionData : vendorOptionList) {
Element vendorOptionElement = doc.createElement(SLDEditorFileHandler.VENDOR_OPTION_ELEMENT);
VendorOptionVersion vendorOption = new VendorOptionVersion(versionData.getVendorOptionType(), versionData);
vendorOptionElement.appendChild(doc.createTextNode(vendorOption.toString()));
root.appendChild(vendorOptionElement);
}
}
// Write out the data source connector
DataSourcePropertiesInterface dataSourceProperties = sldData.getDataSourceProperties();
if (dataSourceProperties != null) {
dataSourceProperties.encodeXML(doc, root, SLDEditorFileHandler.DATASOURCE_ELEMENT);
}
// Environment variables
Element envVarListElement = doc.createElement(SLDEditorFileHandler.ENVVARLIST_ELEMENT);
root.appendChild(envVarListElement);
List<EnvVar> envVarList = sldData.getEnvVarList();
if (envVarList != null) {
for (EnvVar envVar : envVarList) {
Element envVarElement = doc.createElement(SLDEditorFileHandler.ENVVAR_ELEMENT);
envVarElement.setAttribute(SLDEditorFileHandler.ENVVAR_NAME_ATTRIBUTE, envVar.getName());
envVarElement.setAttribute(SLDEditorFileHandler.ENVVAR_TYPE_ATTRIBUTE, envVar.getType().getName());
if (envVar.getValue() != null) {
String value = envVar.getValue().toString();
envVarElement.setAttribute(SLDEditorFileHandler.ENVVAR_VALUE_ATTRIBUTE, value);
}
envVarListElement.appendChild(envVarElement);
}
}
// Write out the legend options
LegendOptionData legendOptions = sldData.getLegendOptions();
if (legendOptions != null) {
legendOptions.encodeXML(doc, root, SLDEditorFileHandler.LEGEND_OPTION_ELEMENT);
}
// Output the XML file contents
TransformerFactory tf = TransformerFactory.newInstance();
Transformer transformer = tf.newTransformer();
transformer.setOutputProperty(OutputKeys.INDENT, SLDEditorFileHandler.YES);
transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, SLDEditorFileHandler.YES);
transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2");
StringWriter stringWriter = new StringWriter();
transformer.transform(new DOMSource(doc), new StreamResult(stringWriter));
String outputXML = stringWriter.getBuffer().toString();
BufferedWriter writer = null;
try {
writer = new BufferedWriter(new FileWriter(fileToSave));
writer.write(outputXML);
} catch (IOException e) {
// Do nothing
} finally {
try {
if (writer != null) {
writer.close();
}
} catch (IOException e) {
// Do nothing
}
}
} catch (ParserConfigurationException e) {
ConsoleManager.getInstance().exception(this, e);
} catch (TransformerConfigurationException e) {
ConsoleManager.getInstance().exception(this, e);
} catch (TransformerFactoryConfigurationError e) {
ConsoleManager.getInstance().exception(this, e.getException());
} catch (TransformerException e) {
ConsoleManager.getInstance().exception(this, e);
}
return true;
}
Aggregations