Search in sources :

Example 26 with VersionData

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());
}
Also used : VersionData(com.sldeditor.common.vendoroption.VersionData) Test(org.junit.Test)

Example 27 with VersionData

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));
}
Also used : VersionData(com.sldeditor.common.vendoroption.VersionData) VendorOptionVersion(com.sldeditor.common.vendoroption.VendorOptionVersion) VendorOptionInfo(com.sldeditor.common.vendoroption.info.VendorOptionInfo) Test(org.junit.Test)

Example 28 with VersionData

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);
}
Also used : GeoServerVendorOption(com.sldeditor.common.vendoroption.GeoServerVendorOption) PrefData(com.sldeditor.common.preferences.PrefData) VersionData(com.sldeditor.common.vendoroption.VersionData) Color(java.awt.Color) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 29 with VersionData

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));
}
Also used : VersionData(com.sldeditor.common.vendoroption.VersionData) ArrayList(java.util.ArrayList) VendorOptionTableModel(com.sldeditor.common.vendoroption.selection.VendorOptionTableModel) VendorOptionTypeInterface(com.sldeditor.common.vendoroption.VendorOptionTypeInterface) LinkedHashMap(java.util.LinkedHashMap) Test(org.junit.Test)

Example 30 with VersionData

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;
}
Also used : DOMSource(javax.xml.transform.dom.DOMSource) DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) Transformer(javax.xml.transform.Transformer) TransformerConfigurationException(javax.xml.transform.TransformerConfigurationException) Element(org.w3c.dom.Element) FileWriter(java.io.FileWriter) Document(org.w3c.dom.Document) BufferedWriter(java.io.BufferedWriter) StringWriter(java.io.StringWriter) EnvVar(com.sldeditor.filter.v2.envvar.EnvVar) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) TransformerException(javax.xml.transform.TransformerException) TransformerFactoryConfigurationError(javax.xml.transform.TransformerFactoryConfigurationError) TransformerFactory(javax.xml.transform.TransformerFactory) StreamResult(javax.xml.transform.stream.StreamResult) IOException(java.io.IOException) DataSourcePropertiesInterface(com.sldeditor.common.DataSourcePropertiesInterface) LegendOptionData(com.sldeditor.ui.legend.option.LegendOptionData) DocumentBuilder(javax.xml.parsers.DocumentBuilder) VersionData(com.sldeditor.common.vendoroption.VersionData) VendorOptionVersion(com.sldeditor.common.vendoroption.VendorOptionVersion) SLDEditorFile(com.sldeditor.datasource.SLDEditorFile) File(java.io.File)

Aggregations

VersionData (com.sldeditor.common.vendoroption.VersionData)56 Test (org.junit.Test)36 ArrayList (java.util.ArrayList)26 VendorOptionVersion (com.sldeditor.common.vendoroption.VendorOptionVersion)13 GeoServerVendorOption (com.sldeditor.common.vendoroption.GeoServerVendorOption)9 PrefData (com.sldeditor.common.preferences.PrefData)7 VendorOptionInfo (com.sldeditor.common.vendoroption.info.VendorOptionInfo)5 Color (java.awt.Color)5 SLDData (com.sldeditor.common.data.SLDData)4 VendorOptionTypeInterface (com.sldeditor.common.vendoroption.VendorOptionTypeInterface)4 File (java.io.File)4 VendorOptionTableModel (com.sldeditor.common.vendoroption.selection.VendorOptionTableModel)3 ValueComboBoxDataGroup (com.sldeditor.ui.widgets.ValueComboBoxDataGroup)3 IOException (java.io.IOException)3 LinkedHashMap (java.util.LinkedHashMap)3 DataSourcePropertiesInterface (com.sldeditor.common.DataSourcePropertiesInterface)2 StyleWrapper (com.sldeditor.common.data.StyleWrapper)2 JsonArray (com.google.gson.JsonArray)1 JsonObject (com.google.gson.JsonObject)1 JsonParser (com.google.gson.JsonParser)1