Search in sources :

Example 6 with EnvVar

use of com.sldeditor.filter.v2.envvar.EnvVar in project sldeditor by robward-scisys.

the class EnvVarModel method removeEnvVar.

/**
 * Removes the env var.
 *
 * @param rowIndex the row index
 */
public void removeEnvVar(int rowIndex) {
    EnvVar envVar = dataList.get(rowIndex);
    if (this.envMgr != null) {
        this.envMgr.removeEnvVar(envVar);
    }
    dataList.remove(rowIndex);
    this.fireTableDataChanged();
}
Also used : EnvVar(com.sldeditor.filter.v2.envvar.EnvVar)

Example 7 with EnvVar

use of com.sldeditor.filter.v2.envvar.EnvVar in project sldeditor by robward-scisys.

the class EnvironmentVariableManagerTest method testCreateExpression.

/**
 * Test method for
 * {@link com.sldeditor.filter.v2.envvar.EnvironmentVariableManager#createExpression(com.sldeditor.filter.v2.envvar.EnvVar)}.
 */
@Test
public void testCreateExpression() {
    EnvVar actualValue1 = EnvironmentVariableManager.getInstance().addNewEnvVar("testAddNewEnvVar1", String.class, "testvalue1");
    assertNotNull(actualValue1);
    assertNull(EnvironmentVariableManager.getInstance().createExpression(null));
    Expression expression = EnvironmentVariableManager.getInstance().createExpression(actualValue1);
    assertNotNull(expression);
    EnvironmentVariableManager.getInstance().removeEnvVar(actualValue1);
}
Also used : ConstantExpression(org.geotools.filter.ConstantExpression) Expression(org.opengis.filter.expression.Expression) EnvVar(com.sldeditor.filter.v2.envvar.EnvVar) Test(org.junit.Test)

Example 8 with EnvVar

use of com.sldeditor.filter.v2.envvar.EnvVar in project sldeditor by robward-scisys.

the class EnvironmentVariableManagerTest method testUpdate.

/**
 * Test method for
 * {@link com.sldeditor.filter.v2.envvar.EnvironmentVariableManager#update(java.util.List)}.
 */
@Test
public void testUpdate() {
    EnvVarNotification listener = new EnvVarNotification();
    EnvironmentVariableManager.getInstance().addEnvVarUpdatedListener(listener);
    List<EnvVar> envVarList = EnvironmentVariableManager.getInstance().getEnvVarList();
    // CHECKSTYLE:OFF
    int preloadedCount = envVarList.size();
    // CHECKSTYLE:ON
    assertFalse(listener.hasBeenNotified());
    EnvironmentVariableManager.getInstance().update(null);
    assertTrue(listener.hasBeenNotified());
    envVarList = EnvironmentVariableManager.getInstance().getEnvVarList();
    assertEquals(preloadedCount, envVarList.size());
    // New env var
    EnvVar env1 = new EnvVar("testUpdate1", String.class, false);
    EnvVar env2 = new EnvVar("wms_width", Integer.class, false);
    List<EnvVar> newEnvVarList = new ArrayList<EnvVar>();
    newEnvVarList.add(env1);
    newEnvVarList.add(env2);
    assertFalse(listener.hasBeenNotified());
    EnvironmentVariableManager.getInstance().update(newEnvVarList);
    assertTrue(listener.hasBeenNotified());
    envVarList = EnvironmentVariableManager.getInstance().getEnvVarList();
    assertEquals(2, envVarList.size());
    // Put it back to the original
    EnvironmentVariableManager.getInstance().update(null);
}
Also used : ArrayList(java.util.ArrayList) EnvVar(com.sldeditor.filter.v2.envvar.EnvVar) Test(org.junit.Test)

Example 9 with EnvVar

use of com.sldeditor.filter.v2.envvar.EnvVar 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 10 with EnvVar

use of com.sldeditor.filter.v2.envvar.EnvVar in project sldeditor by robward-scisys.

the class EnvVarModel method addNew.

/**
 * Adds the new.
 *
 * @param parameterList the parameter list
 */
public void addNew(List<String> parameterList) {
    if (this.envMgr != null) {
        for (String parameter : parameterList) {
            String[] componentList = parameter.split(";");
            for (String component : componentList) {
                String[] childComponentList = component.split(":");
                String envVarName = childComponentList[0];
                String envVarValue = null;
                if (childComponentList.length > 1) {
                    envVarValue = childComponentList[1];
                }
                EnvVar envVar = this.envMgr.addNewEnvVar(envVarName, String.class, envVarValue);
                if (envVar != null) {
                    dataList.add(envVar);
                }
            }
        }
        this.fireTableDataChanged();
    }
}
Also used : EnvVar(com.sldeditor.filter.v2.envvar.EnvVar)

Aggregations

EnvVar (com.sldeditor.filter.v2.envvar.EnvVar)11 Test (org.junit.Test)4 DataSourcePropertiesInterface (com.sldeditor.common.DataSourcePropertiesInterface)2 VersionData (com.sldeditor.common.vendoroption.VersionData)2 SLDEditorFile (com.sldeditor.datasource.SLDEditorFile)2 LegendOptionData (com.sldeditor.ui.legend.option.LegendOptionData)2 FlowLayout (java.awt.FlowLayout)2 File (java.io.File)2 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 JPanel (javax.swing.JPanel)2 DocumentBuilder (javax.xml.parsers.DocumentBuilder)2 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)2 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)2 SLDDataInterface (com.sldeditor.common.SLDDataInterface)1 SLDData (com.sldeditor.common.data.SLDData)1 StyleWrapper (com.sldeditor.common.data.StyleWrapper)1 VendorOptionVersion (com.sldeditor.common.vendoroption.VendorOptionVersion)1 DataSourceAttributeData (com.sldeditor.datasource.attribute.DataSourceAttributeData)1 EnvironmentVariableField (com.sldeditor.filter.v2.envvar.EnvironmentVariableField)1