Search in sources :

Example 11 with VendorOptionVersion

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

the class VendorOptionVersionTest method testFromString.

/**
 * Test method for {@link com.sldeditor.common.vendoroption.VendorOptionVersion#fromString(java.lang.String)}.
 * Test method for {@link com.sldeditor.common.vendoroption.VendorOptionVersion#toString()}.
 */
@Test
public void testFromString() {
    VersionData versionDataMin = VersionData.decode(getClass(), "2.4.1");
    VersionData versionDataMax = VersionData.decode(getClass(), "2.8.3");
    VendorOptionVersion vo = new VendorOptionVersion(getClass(), versionDataMin, versionDataMax);
    String actualString = vo.toString();
    VendorOptionVersion decoded = VendorOptionVersion.fromString(actualString);
    assertEquals(vo.getLatest(), decoded.getLatest());
    assertEquals(vo.toString(), decoded.toString());
}
Also used : VersionData(com.sldeditor.common.vendoroption.VersionData) VendorOptionVersion(com.sldeditor.common.vendoroption.VendorOptionVersion) Test(org.junit.Test)

Example 12 with VendorOptionVersion

use of com.sldeditor.common.vendoroption.VendorOptionVersion 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 13 with VendorOptionVersion

use of com.sldeditor.common.vendoroption.VendorOptionVersion 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)

Example 14 with VendorOptionVersion

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

the class VendorOptionManagerTest method testGetVendorOptionVersionClassOfQStringString.

/**
 * Test method for
 * {@link com.sldeditor.common.vendoroption.VendorOptionManager#getVendorOptionVersion(java.lang.Class, java.lang.String, java.lang.String)}.
 */
@Test
public void testGetVendorOptionVersionClassOfQStringString() {
    assertNull(VendorOptionManager.getInstance().getVendorOptionVersion(null, null, null));
    String exepectedEndVersion = "2.8.1";
    VendorOptionVersion voGS = VendorOptionManager.getInstance().getVendorOptionVersion(GeoServerVendorOption.class, "2.4.1", exepectedEndVersion);
    assertEquals(exepectedEndVersion, voGS.getLatest().getVersionString());
    VendorOptionVersion voGS1 = VendorOptionManager.getInstance().getVendorOptionVersion(GeoServerVendorOption.class, null, exepectedEndVersion);
    assertEquals(exepectedEndVersion, voGS1.getLatest().getVersionString());
    exepectedEndVersion = "2.8.a";
    VendorOptionVersion voGS2 = VendorOptionManager.getInstance().getVendorOptionVersion(GeoServerVendorOption.class, "2.4.1", exepectedEndVersion);
    assertEquals("Latest", voGS2.getLatest().getVersionString());
}
Also used : VendorOptionVersion(com.sldeditor.common.vendoroption.VendorOptionVersion) Test(org.junit.Test)

Example 15 with VendorOptionVersion

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

the class VendorOptionManagerTest method testIsAllowed.

/**
 * Test method for
 * {@link com.sldeditor.common.vendoroption.VendorOptionManager#isAllowed(java.util.List, com.sldeditor.common.vendoroption.VendorOptionVersion)}.
 */
@Test
public void testIsAllowed() {
    assertFalse(VendorOptionManager.getInstance().isAllowed(null, null));
    VersionData versionDataMin = VersionData.decode(getClass(), "2.4.1");
    VersionData versionDataMax = VersionData.decode(getClass(), "2.8.3");
    VendorOptionVersion vo = new VendorOptionVersion(GeoServerVendorOption.class, versionDataMin, versionDataMax);
    List<VersionData> versionList = new ArrayList<VersionData>();
    versionList.add(VersionData.decode(GeoServerVendorOption.class, "1.8.3"));
    assertFalse(VendorOptionManager.getInstance().isAllowed(versionList, vo));
    versionList.add(VersionData.decode(GeoServerVendorOption.class, "2.7.x"));
    assertTrue(VendorOptionManager.getInstance().isAllowed(versionList, vo));
}
Also used : GeoServerVendorOption(com.sldeditor.common.vendoroption.GeoServerVendorOption) VersionData(com.sldeditor.common.vendoroption.VersionData) VendorOptionVersion(com.sldeditor.common.vendoroption.VendorOptionVersion) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Aggregations

VendorOptionVersion (com.sldeditor.common.vendoroption.VendorOptionVersion)23 Test (org.junit.Test)16 VersionData (com.sldeditor.common.vendoroption.VersionData)13 ArrayList (java.util.ArrayList)8 VendorOptionPresent (com.sldeditor.common.vendoroption.minversion.VendorOptionPresent)4 FeatureTypeStyle (org.geotools.styling.FeatureTypeStyle)4 VendorOptionInfo (com.sldeditor.common.vendoroption.info.VendorOptionInfo)3 FeatureTypeStyleDetails (com.sldeditor.ui.detail.FeatureTypeStyleDetails)3 StyleFactoryImpl (org.geotools.styling.StyleFactoryImpl)3 GeoServerVendorOption (com.sldeditor.common.vendoroption.GeoServerVendorOption)2 ValueComboBoxData (com.sldeditor.ui.widgets.ValueComboBoxData)2 File (java.io.File)2 DataSourcePropertiesInterface (com.sldeditor.common.DataSourcePropertiesInterface)1 SLDData (com.sldeditor.common.data.SLDData)1 PrefData (com.sldeditor.common.preferences.PrefData)1 VendorOptionInfoModel (com.sldeditor.common.vendoroption.info.VendorOptionInfoModel)1 ParseXML (com.sldeditor.common.xml.ParseXML)1 XMLFieldConfigString (com.sldeditor.common.xml.ui.XMLFieldConfigString)1 SLDEditorFile (com.sldeditor.datasource.SLDEditorFile)1 EnvVar (com.sldeditor.filter.v2.envvar.EnvVar)1