Search in sources :

Example 1 with ExpressionDOMParser

use of org.geotools.filter.ExpressionDOMParser in project sldeditor by robward-scisys.

the class FieldConfigTransformationTest method testGenerateExpression.

/**
 * Test method for
 * {@link com.sldeditor.ui.detail.config.transform.FieldConfigTransformation#populateExpression(java.lang.Object)}.
 * Test method for
 * {@link com.sldeditor.ui.detail.config.transform.FieldConfigTransformation#generateExpression()}.
 * Test method for
 * {@link com.sldeditor.ui.detail.config.transform.FieldConfigTransformation#getProcessFunction()}.
 */
@Test
public void testGenerateExpression() {
    boolean valueOnly = true;
    class TestFieldConfigTransformation extends FieldConfigTransformation {

        public TestFieldConfigTransformation(FieldConfigCommonData commonData, String editButtonText, String clearButtonText) {
            super(commonData, editButtonText, clearButtonText);
        }

        public Expression callGenerateExpression() {
            return generateExpression();
        }
    }
    TestFieldConfigTransformation field = new TestFieldConfigTransformation(new FieldConfigCommonData(String.class, FieldIdEnum.NAME, "test label", valueOnly), "edit", "clear");
    Expression actualExpression = field.callGenerateExpression();
    assertNull(actualExpression);
    field.createUI();
    String expectedValue1 = "test string value";
    field.setTestValue(FieldIdEnum.UNKNOWN, expectedValue1);
    actualExpression = field.callGenerateExpression();
    assertNull(actualExpression);
    // Strings are ignored when calling populateExpression
    String expectedValue2 = "test string value as expression";
    field.populateExpression(expectedValue2);
    actualExpression = field.callGenerateExpression();
    assertNull(actualExpression);
    // Create process function
    String testData = "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>" + "<StyledLayerDescriptor version=\"1.0.0\" xsi:schemaLocation=\"http://www.opengis.net/sld StyledLayerDescriptor.xsd\" xmlns=\"http://www.opengis.net/sld\" xmlns:ogc=\"http://www.opengis.net/ogc\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">" + "<ogc:Function name=\"vec:PointStacker\">" + "<ogc:Function name=\"parameter\">" + "  <ogc:Literal>data</ogc:Literal>" + "</ogc:Function>" + "<ogc:Function name=\"parameter\">" + "  <ogc:Literal>cellSize</ogc:Literal>" + "  <ogc:Literal>30</ogc:Literal>" + "</ogc:Function>" + "<ogc:Function name=\"parameter\">" + "  <ogc:Literal>outputBBOX</ogc:Literal>" + "  <ogc:Function name=\"env\">" + "        <ogc:Literal>wms_bbox</ogc:Literal>" + "  </ogc:Function>" + "</ogc:Function>" + "<ogc:Function name=\"parameter\">" + "  <ogc:Literal>outputWidth</ogc:Literal>" + "  <ogc:Function name=\"env\">" + "        <ogc:Literal>wms_width</ogc:Literal>" + "  </ogc:Function>" + "</ogc:Function>" + "<ogc:Function name=\"parameter\">" + " <ogc:Literal>outputHeight</ogc:Literal>" + "  <ogc:Function name=\"env\">" + "        <ogc:Literal>wms_height</ogc:Literal>" + "  </ogc:Function>" + " </ogc:Function>" + "</ogc:Function>" + "</StyledLayerDescriptor>";
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    DocumentBuilder builder;
    ProcessFunction processFunction = null;
    try {
        builder = factory.newDocumentBuilder();
        InputSource is = new InputSource(new StringReader(testData));
        Document doc = builder.parse(is);
        ExpressionDOMParser parser = new ExpressionDOMParser(CommonFactoryFinder.getFilterFactory2(null));
        processFunction = (ProcessFunction) parser.expression(doc.getDocumentElement().getFirstChild());
    } catch (ParserConfigurationException e) {
        e.printStackTrace();
    } catch (SAXException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
    field.populateExpression((ProcessFunction) null);
    field.populateExpression(processFunction);
    actualExpression = field.callGenerateExpression();
    String expectedValue3 = ParameterFunctionUtils.getString(processFunction);
    String string = actualExpression.toString();
    assertTrue(expectedValue3.compareTo(string) != 0);
    assertEquals(processFunction, field.getProcessFunction());
}
Also used : InputSource(org.xml.sax.InputSource) DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) IOException(java.io.IOException) Document(org.w3c.dom.Document) SAXException(org.xml.sax.SAXException) FieldConfigTransformation(com.sldeditor.ui.detail.config.transform.FieldConfigTransformation) ProcessFunction(org.geotools.process.function.ProcessFunction) Expression(org.opengis.filter.expression.Expression) DocumentBuilder(javax.xml.parsers.DocumentBuilder) FieldConfigCommonData(com.sldeditor.ui.detail.config.FieldConfigCommonData) StringReader(java.io.StringReader) ExpressionDOMParser(org.geotools.filter.ExpressionDOMParser) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) Test(org.junit.Test)

Example 2 with ExpressionDOMParser

use of org.geotools.filter.ExpressionDOMParser in project sldeditor by robward-scisys.

the class BuiltInProcessFunctionTest method testExtractParametersProcessFunction.

/**
 * Test method for
 * {@link com.sldeditor.rendertransformation.BuiltInProcessFunction#extractParameters(org.opengis.filter.capability.FunctionName, org.geotools.process.function.ProcessFunction)}.
 */
@Test
public void testExtractParametersProcessFunction() {
    BuiltInProcessFunction obj = new BuiltInProcessFunction();
    String testData = "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>" + "<StyledLayerDescriptor version=\"1.0.0\" xsi:schemaLocation=\"http://www.opengis.net/sld StyledLayerDescriptor.xsd\" xmlns=\"http://www.opengis.net/sld\" xmlns:ogc=\"http://www.opengis.net/ogc\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">" + "<ogc:Function name=\"vec:PointStacker\">" + "<ogc:Function name=\"parameter\">" + "  <ogc:Literal>data</ogc:Literal>" + "</ogc:Function>" + "<ogc:Function name=\"parameter\">" + "  <ogc:Literal>cellSize</ogc:Literal>" + "  <ogc:Literal>30</ogc:Literal>" + "</ogc:Function>" + "<ogc:Function name=\"parameter\">" + "  <ogc:Literal>outputBBOX</ogc:Literal>" + "  <ogc:Function name=\"env\">" + "        <ogc:Literal>wms_bbox</ogc:Literal>" + "  </ogc:Function>" + "</ogc:Function>" + "<ogc:Function name=\"parameter\">" + "  <ogc:Literal>outputWidth</ogc:Literal>" + "  <ogc:Function name=\"env\">" + "        <ogc:Literal>wms_width</ogc:Literal>" + "  </ogc:Function>" + "</ogc:Function>" + "<ogc:Function name=\"parameter\">" + " <ogc:Literal>outputHeight</ogc:Literal>" + "  <ogc:Function name=\"env\">" + "        <ogc:Literal>wms_height</ogc:Literal>" + "  </ogc:Function>" + " </ogc:Function>" + "</ogc:Function>" + "</StyledLayerDescriptor>";
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    DocumentBuilder builder;
    ProcessFunction tx = null;
    try {
        builder = factory.newDocumentBuilder();
        InputSource is = new InputSource(new StringReader(testData));
        Document doc = builder.parse(is);
        ExpressionDOMParser parser = new ExpressionDOMParser(CommonFactoryFinder.getFilterFactory2(null));
        tx = (ProcessFunction) parser.expression(doc.getDocumentElement().getFirstChild());
    } catch (ParserConfigurationException e) {
        e.printStackTrace();
    } catch (SAXException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
    List<ProcessFunctionParameterValue> valueList = obj.extractParameters(null, tx);
    assertTrue(valueList.isEmpty());
    ProcessFunctionFactory processFunctionFactory = new ProcessFunctionFactory();
    for (FunctionName functionName : processFunctionFactory.getFunctionNames()) {
        if (functionName.getName().compareTo("PointStacker") == 0) {
            valueList = obj.extractParameters(functionName, tx);
            assertEquals(functionName.getArguments().size(), valueList.size());
        }
    }
}
Also used : InputSource(org.xml.sax.InputSource) DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) ProcessFunctionParameterValue(com.sldeditor.rendertransformation.ProcessFunctionParameterValue) IOException(java.io.IOException) ProcessFunctionFactory(org.geotools.process.function.ProcessFunctionFactory) Document(org.w3c.dom.Document) SAXException(org.xml.sax.SAXException) BuiltInProcessFunction(com.sldeditor.rendertransformation.BuiltInProcessFunction) ProcessFunction(org.geotools.process.function.ProcessFunction) BuiltInProcessFunction(com.sldeditor.rendertransformation.BuiltInProcessFunction) FunctionName(org.opengis.filter.capability.FunctionName) DocumentBuilder(javax.xml.parsers.DocumentBuilder) StringReader(java.io.StringReader) ExpressionDOMParser(org.geotools.filter.ExpressionDOMParser) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) Test(org.junit.Test)

Aggregations

IOException (java.io.IOException)2 StringReader (java.io.StringReader)2 DocumentBuilder (javax.xml.parsers.DocumentBuilder)2 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)2 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)2 ExpressionDOMParser (org.geotools.filter.ExpressionDOMParser)2 ProcessFunction (org.geotools.process.function.ProcessFunction)2 Test (org.junit.Test)2 Document (org.w3c.dom.Document)2 InputSource (org.xml.sax.InputSource)2 SAXException (org.xml.sax.SAXException)2 BuiltInProcessFunction (com.sldeditor.rendertransformation.BuiltInProcessFunction)1 ProcessFunctionParameterValue (com.sldeditor.rendertransformation.ProcessFunctionParameterValue)1 FieldConfigCommonData (com.sldeditor.ui.detail.config.FieldConfigCommonData)1 FieldConfigTransformation (com.sldeditor.ui.detail.config.transform.FieldConfigTransformation)1 ProcessFunctionFactory (org.geotools.process.function.ProcessFunctionFactory)1 FunctionName (org.opengis.filter.capability.FunctionName)1 Expression (org.opengis.filter.expression.Expression)1