Statistics
| Revision:

gvsig-sldtools / org.gvsig.sld / org.gvsig.sldsupport / org.gvsig.sldsupport.lib / org.gvsig.sldsupport.lib.impl / src / main / java / org / gvsig / sldsupport / impl / sld / parsing / expression / ExpressionElement.java @ 46

History | View | Annotate | Download (4.3 KB)

1
/*******************************************************************************
2
 *
3
 *   gvSIG. Desktop Geographic Information System.
4
 *  
5
 *   Copyright (C) 2007-2013 gvSIG Association.
6
 *  
7
 *   This program is free software; you can redistribute it and/or
8
 *   modify it under the terms of the GNU General Public License
9
 *   as published by the Free Software Foundation; either version 3
10
 *   of the License, or (at your option) any later version.
11
 *  
12
 *   This program is distributed in the hope that it will be useful,
13
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
 *   GNU General Public License for more details.
16
 *  
17
 *   You should have received a copy of the GNU General Public License
18
 *   along with this program; if not, write to the Free Software
19
 *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
20
 *   MA  02110-1301, USA.
21
 *  
22
 *   For any additional information, do not hesitate to contact us
23
 *   at info AT gvsig.com, or visit our website www.gvsig.com.
24
 *   
25
 *******************************************************************************/
26
package org.gvsig.sldsupport.impl.sld.parsing.expression;
27

    
28
import java.io.IOException;
29

    
30
import org.xmlpull.v1.XmlPullParser;
31
import org.xmlpull.v1.XmlPullParserException;
32

    
33
import org.gvsig.sldsupport.exception.InvalidSLDObjectException;
34
import org.gvsig.sldsupport.exception.SLDReadException;
35
import org.gvsig.sldsupport.exception.UnsupportedSLDObjectException;
36
import org.gvsig.sldsupport.impl.util.SLDUtils;
37
import org.gvsig.sldsupport.impl.util.XmlBuilder;
38
import org.gvsig.sldsupport.sld.SLDTags;
39
import org.gvsig.sldsupport.sld.filter.FilterTags;
40
import org.gvsig.sldsupport.sld.filter.expression.SLDExpression;
41
import org.gvsig.sldsupport.sld.filter.expression.operator.SLDArithmeticOperator;
42
import org.gvsig.sldsupport.sld.filter.expression.operator.SLDFunction;
43
import org.gvsig.sldsupport.sld.filter.expression.operator.SLDLiteral;
44
import org.gvsig.sldsupport.sld.filter.expression.operator.SLDPropertyName;
45

    
46
public class ExpressionElement {
47

    
48
    public static void append(SLDExpression obj, XmlBuilder xb, String version)
49
        throws InvalidSLDObjectException, UnsupportedSLDObjectException {
50

    
51
        if (obj instanceof SLDLiteral) {
52
            SLDLiteral lit = (SLDLiteral) obj;
53
            xb.writeTag(SLDTags.LITERAL, lit.getValue());
54
        } else {
55
            if (obj instanceof SLDArithmeticOperator) {
56
                ArithmeticElement.append((SLDArithmeticOperator) obj, xb,
57
                    version);
58
            } else {
59
                if (obj instanceof SLDFunction) {
60
                    FunctionElement.append((SLDFunction) obj, xb, version);
61
                } else {
62
                    if (obj instanceof SLDPropertyName) {
63
                        SLDPropertyName pn = (SLDPropertyName) obj;
64
                        xb.writeTag(SLDTags.PROPERTY_NAME, pn.getPropertyName());
65
                    }
66
                }
67
            }
68
        }
69

    
70
    }
71

    
72
    public static SLDExpression parse(XmlPullParser parser, String version)
73
        throws XmlPullParserException, IOException, SLDReadException {
74

    
75
        String name = parser.getName();
76

    
77
        if (SLDUtils.isStr(name, FilterTags.PROPERTYNAME)) {
78
            SLDPropertyName pn = new SLDPropertyName();
79
            String txt = parser.nextText();
80
            pn.setPropertyName(txt);
81
            // Go to next tag
82
            parser.nextTag();
83
            return pn;
84
        }
85

    
86
        if (SLDUtils.isStr(name, FilterTags.LITERAL)) {
87
            SLDLiteral lit = new SLDLiteral();
88
            String txt = parser.nextText();
89
            lit.setValue(txt);
90
            // Go to next tag
91
            parser.nextTag();
92
            return lit;
93
        }
94

    
95
        if (SLDUtils.isStr(name, FilterTags.ADD)
96
            || SLDUtils.isStr(name, FilterTags.SUB)
97
            || SLDUtils.isStr(name, FilterTags.MUL)
98
            || SLDUtils.isStr(name, FilterTags.DIV)) {
99
            return ArithmeticElement.parse(parser, version);
100
        }
101

    
102
        if (SLDUtils.isStr(name, FilterTags.FUNCTION)) {
103
            return FunctionElement.parse(parser, version);
104
        }
105

    
106
        throw new SLDReadException("Unexpected entity in expression: " + name);
107

    
108
    }
109
}