001 //$HeadURL: svn+ssh://rbezema@svn.wald.intevation.org/deegree/base/branches/2.2_testing/src/org/deegree/graphics/sld/UserStyle.java $
002 /*---------------- FILE HEADER ------------------------------------------
003
004 This file is part of deegree.
005 Copyright (C) 2001-2008 by:
006 EXSE, Department of Geography, University of Bonn
007 http://www.giub.uni-bonn.de/deegree/
008 lat/lon GmbH
009 http://www.lat-lon.de
010
011 This library is free software; you can redistribute it and/or
012 modify it under the terms of the GNU Lesser General Public
013 License as published by the Free Software Foundation; either
014 version 2.1 of the License, or (at your option) any later version.
015
016 This library is distributed in the hope that it will be useful,
017 but WITHOUT ANY WARRANTY; without even the implied warranty of
018 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
019 Lesser General Public License for more details.
020
021 You should have received a copy of the GNU Lesser General Public
022 License along with this library; if not, write to the Free Software
023 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
024
025 Contact:
026
027 Andreas Poth
028 lat/lon GmbH
029 Aennchenstr. 19
030 53115 Bonn
031 Germany
032 E-Mail: poth@lat-lon.de
033
034 Prof. Dr. Klaus Greve
035 Department of Geography
036 University of Bonn
037 Meckenheimer Allee 166
038 53115 Bonn
039 Germany
040 E-Mail: greve@giub.uni-bonn.de
041
042
043 ---------------------------------------------------------------------------*/
044 package org.deegree.graphics.sld;
045
046 import static org.deegree.framework.xml.XMLTools.escape;
047
048 import java.util.ArrayList;
049 import java.util.List;
050
051 import org.deegree.framework.xml.Marshallable;
052
053 /**
054 * A user-defined allows map styling to be defined externally from a system and to be passed around
055 * in an interoperable format.
056 * <p>
057 * </p>
058 * A UserStyle is at the same semantic level as a NamedStyle used in the context of a WMS. In a
059 * sense, a named style can be thought of as a reference to a hidden UserStyle that is stored inside
060 * of a map server.
061 *
062 *
063 * @author <a href="mailto:k.lupp@web.de">Katharina Lupp</a>
064 * @author last edited by: $Author: aschmitz $
065 * @version $Revision: 12137 $ $Date: 2008-06-04 10:28:43 +0200 (Mi, 04 Jun 2008) $
066 */
067 public class UserStyle extends AbstractStyle implements Marshallable {
068 private List<FeatureTypeStyle> featureTypeStyles = null;
069
070 private String abstract_ = null;
071
072 private String title = null;
073
074 private boolean default_ = false;
075
076 /**
077 * constructor initializing the class with the <UserStyle>
078 */
079 UserStyle( String name, String title, String abstract_, boolean default_, FeatureTypeStyle[] featureTypeStyles ) {
080 super( name );
081
082 this.featureTypeStyles = new ArrayList<FeatureTypeStyle>();
083
084 setTitle( title );
085 setAbstract( abstract_ );
086 setDefault( default_ );
087 setFeatureTypeStyles( featureTypeStyles );
088 }
089
090 /**
091 * The Title is a human-readable short description for the style that might be displayed in a
092 * GUI pick list.
093 *
094 * @return the title of the User-AbstractStyle
095 *
096 */
097 public String getTitle() {
098 return title;
099 }
100
101 /**
102 * sets the <Title>
103 *
104 * @param title
105 * the title of the User-AbstractStyle
106 *
107 */
108 public void setTitle( String title ) {
109 this.title = title;
110 }
111
112 /**
113 * the Abstract is a more exact description that may be a few paragraphs long.
114 *
115 * @return the abstract of the User-AbstractStyle
116 */
117 public String getAbstract() {
118 return abstract_;
119 }
120
121 /**
122 * sets the <Abstract>
123 *
124 * @param abstract_
125 * the abstract of the User-AbstractStyle
126 */
127 public void setAbstract( String abstract_ ) {
128 this.abstract_ = abstract_;
129 }
130
131 /**
132 * The IsDefault element identifies whether a style is the default style of a layer, for use in
133 * SLD library mode when rendering or for storing inside of a map server. The default value is
134 * <tt>false</tt>.
135 *
136 * @return true if the style ist the default style
137 */
138 public boolean isDefault() {
139 return default_;
140 }
141
142 /**
143 * sets the <Default>
144 *
145 * @param default_
146 */
147 public void setDefault( boolean default_ ) {
148 this.default_ = default_;
149 }
150
151 /**
152 * A UserStyle can contain one or more FeatureTypeStyles which allow the rendering of features
153 * of specific types.
154 * <p>
155 * </p>
156 * The FeatureTypeStyle defines the styling that is to be applied to a single feature type of a
157 * layer.
158 * <p>
159 * </p>
160 * The FeatureTypeStyle element identifies that explicit separation in SLD between the handling
161 * of layers and the handling of features of specific feature types. The layer concept is unique
162 * to WMS and SLD, but features are used more generally, such as in WFS and GML, so this
163 * explicit separation is important.
164 *
165 * @return the FeatureTypeStyles of a User-AbstractStyle
166 *
167 */
168 public FeatureTypeStyle[] getFeatureTypeStyles() {
169
170 return featureTypeStyles.toArray( new FeatureTypeStyle[featureTypeStyles.size()] );
171 }
172
173 /**
174 * sets the <FeatureTypeStyle>
175 *
176 * @param featureTypeStyles
177 * the FeatureTypeStyles of a User-AbstractStyle
178 */
179 public void setFeatureTypeStyles( FeatureTypeStyle[] featureTypeStyles ) {
180 this.featureTypeStyles.clear();
181
182 if ( featureTypeStyles != null ) {
183 for ( int i = 0; i < featureTypeStyles.length; i++ ) {
184 addFeatureTypeStyle( featureTypeStyles[i] );
185 }
186 }
187 }
188
189 /**
190 * Adds a <FeatureTypeStyle>
191 *
192 * @param featureTypeStyle
193 * a FeatureTypeStyle to add
194 */
195 public void addFeatureTypeStyle( FeatureTypeStyle featureTypeStyle ) {
196 featureTypeStyles.add( featureTypeStyle );
197 }
198
199 /**
200 * Removes a <FeatureTypeStyle>
201 *
202 * @param featureTypeStyle
203 */
204 public void removeFeatureTypeStyle( FeatureTypeStyle featureTypeStyle ) {
205 if ( featureTypeStyles.indexOf( featureTypeStyle ) != -1 ) {
206 featureTypeStyles.remove( featureTypeStyles.indexOf( featureTypeStyle ) );
207 }
208 }
209
210 /**
211 * exports the content of the UserStyle as XML formated String
212 *
213 * @return xml representation of the UserStyle
214 */
215 public String exportAsXML() {
216
217 StringBuffer sb = new StringBuffer( 100 );
218 sb.append( "<UserStyle>" );
219 if ( name != null && !name.equals( "" ) ) {
220 sb.append( "<Name>" ).append( escape( name ) ).append( "</Name>" );
221 }
222 if ( title != null && !title.equals( "" ) ) {
223 sb.append( "<Title>" ).append( escape( title ) ).append( "</Title>" );
224 }
225 if ( abstract_ != null && !abstract_.equals( "" ) ) {
226 sb.append( "<Abstract>" ).append( escape( abstract_ ) ).append( "</Abstract>" );
227 }
228 if ( default_ ) {
229 sb.append( "<IsDefault>" ).append( 1 ).append( "</IsDefault>" );
230 }
231 for ( int i = 0; i < featureTypeStyles.size(); i++ ) {
232 sb.append( ( (Marshallable) featureTypeStyles.get( i ) ).exportAsXML() );
233 }
234 sb.append( "</UserStyle>" );
235
236 return sb.toString();
237 }
238
239 }