001: /*
002: * GeoTools - OpenSource mapping toolkit
003: * http://geotools.org
004: * (C) 2002-2006, GeoTools Project Managment Committee (PMC)
005: *
006: * This library is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Lesser General Public
008: * License as published by the Free Software Foundation;
009: * version 2.1 of the License.
010: *
011: * This library is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * Lesser General Public License for more details.
015: */
016: package org.geotools.sld.bindings;
017:
018: import org.picocontainer.MutablePicoContainer;
019: import org.w3c.dom.Document;
020: import org.w3c.dom.Element;
021: import java.util.Iterator;
022: import javax.xml.namespace.QName;
023: import org.geotools.filter.Expression;
024: import org.geotools.sld.CssParameter;
025: import org.geotools.styling.Font;
026: import org.geotools.styling.StyleFactory;
027: import org.geotools.xml.*;
028:
029: /**
030: * Binding object for the element http://www.opengis.net/sld:Font.
031: *
032: * <p>
033: * <pre>
034: * <code>
035: * <xsd:element name="Font">
036: * <xsd:annotation>
037: * <xsd:documentation> A "Font" element specifies
038: * the text font to use. The allowed CssParameters
039: * are: "font-family", "font-style",
040: * "font-weight", and "font-size". </xsd:documentation>
041: * </xsd:annotation>
042: * <xsd:complexType>
043: * <xsd:sequence>
044: * <xsd:element ref="sld:CssParameter" minOccurs="0" maxOccurs="unbounded"/>
045: * </xsd:sequence>
046: * </xsd:complexType>
047: * </xsd:element>
048: *
049: * </code>
050: * </pre>
051: * </p>
052: *
053: * @generated
054: */
055: public class SLDFontBinding extends AbstractComplexBinding {
056: StyleFactory styleFactory;
057:
058: public SLDFontBinding(StyleFactory styleFactory) {
059: this .styleFactory = styleFactory;
060: }
061:
062: /**
063: * @generated
064: */
065: public QName getTarget() {
066: return SLD.FONT;
067: }
068:
069: /**
070: * <!-- begin-user-doc -->
071: * <!-- end-user-doc -->
072: *
073: * @generated modifiable
074: */
075: public int getExecutionMode() {
076: return AFTER;
077: }
078:
079: /**
080: * <!-- begin-user-doc -->
081: * <!-- end-user-doc -->
082: *
083: * @generated modifiable
084: */
085: public Class getType() {
086: return Font.class;
087: }
088:
089: /**
090: * <!-- begin-user-doc -->
091: * <!-- end-user-doc -->
092: *
093: * @generated modifiable
094: */
095: public void initialize(ElementInstance instance, Node node,
096: MutablePicoContainer context) {
097: }
098:
099: /**
100: * <!-- begin-user-doc -->
101: * <!-- end-user-doc -->
102: *
103: * @generated modifiable
104: */
105: public Object parse(ElementInstance instance, Node node,
106: Object value) throws Exception {
107: //"font-family"
108: //"font-style"
109: //"font-weight"
110: //"font-size"
111: Expression family = null;
112:
113: //"font-family"
114: //"font-style"
115: //"font-weight"
116: //"font-size"
117: Expression style = null;
118:
119: //"font-family"
120: //"font-style"
121: //"font-weight"
122: //"font-size"
123: Expression weight = null;
124:
125: //"font-family"
126: //"font-style"
127: //"font-weight"
128: //"font-size"
129: Expression size = null;
130:
131: for (Iterator i = node.getChildValues("CssParameter")
132: .iterator(); i.hasNext();) {
133: CssParameter css = (CssParameter) i.next();
134:
135: if (css.getExpressions().isEmpty()) {
136: continue;
137: }
138:
139: if ("font-family".equals(css.getName())) {
140: family = (Expression) css.getExpressions().get(0);
141: }
142:
143: if ("font-style".equals(css.getName())) {
144: style = (Expression) css.getExpressions().get(0);
145: }
146:
147: if ("font-weight".equals(css.getName())) {
148: weight = (Expression) css.getExpressions().get(0);
149: }
150:
151: if ("font-size".equals(css.getName())) {
152: size = (Expression) css.getExpressions().get(0);
153: }
154: }
155:
156: return styleFactory.createFont(family, style, weight, size);
157: }
158: }
|