001 //$HeadURL: svn+ssh://rbezema@svn.wald.intevation.org/deegree/base/branches/2.2_testing/src/org/deegree/graphics/sld/StyledLayerDescriptor.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 java.util.ArrayList;
047 import java.util.List;
048
049 import org.deegree.framework.xml.Marshallable;
050
051 /**
052 * StyledLayerDescriptor: This is a sequence of styled layers, represented at the first level by
053 * Layer and UserLayer elements. A "version" attribute has been added to allow the formatting of
054 * static-file
055 *
056 * @author <a href="mailto:k.lupp@web.de">Katharina Lupp</a>
057 * @author last edited by: $Author: apoth $
058 * @version $Revision: 9340 $ $Date: 2007-12-27 13:32:12 +0100 (Do, 27 Dez 2007) $
059 */
060 public class StyledLayerDescriptor implements Marshallable {
061 private List<AbstractLayer> layers = null;
062
063 private String version = null;
064
065 private String abstract_ = null;
066
067 private String name = null;
068
069 private String title = null;
070
071 /**
072 * @param name
073 * @param title
074 * @param version
075 * @param abstract_
076 * @param layers
077 */
078 StyledLayerDescriptor( String name, String title, String version, String abstract_, AbstractLayer[] layers ) {
079 this.layers = new ArrayList<AbstractLayer>( layers.length );
080 setLayers( layers );
081 setVersion( version );
082 setAbstract( abstract_ );
083 setName( name );
084 setTitle( title );
085 }
086
087 /**
088 * constructor initializing the class with the <StyledLayerDescriptor>
089 */
090 public StyledLayerDescriptor( AbstractLayer[] layers, String version ) {
091 this.layers = new ArrayList<AbstractLayer>( layers.length );
092 setLayers( layers );
093 setVersion( version );
094 }
095
096 /**
097 * @return the Layers as Array
098 */
099 public AbstractLayer[] getLayers() {
100 return layers.toArray( new AbstractLayer[layers.size()] );
101 }
102
103 /**
104 * Sets Layers
105 *
106 * @param layers
107 * the Layers as Array
108 */
109 public void setLayers( AbstractLayer[] layers ) {
110 this.layers.clear();
111
112 if ( layers != null ) {
113 for ( int i = 0; i < layers.length; i++ ) {
114 this.layers.add( layers[i] );
115 }
116 }
117 }
118
119 /**
120 * adds the <Layer>
121 *
122 * @param layer
123 * a Layer to add
124 */
125 public void addLayer( AbstractLayer layer ) {
126 layers.add( layer );
127 }
128
129 /**
130 * removes the <Layer>
131 *
132 * @param layer
133 * a Layer to remove
134 */
135 public void removeLayer( AbstractLayer layer ) {
136 if ( layers.indexOf( layer ) != -1 ) {
137 layers.remove( layers.indexOf( layer ) );
138 }
139 }
140
141 /**
142 * A UserLayer can contain one or more UserStyles. A UserLayer may direct the WMS to a specified
143 * WFS source of feature data. Multiple feature types can be included in a UserLayer, since this
144 * is semantically equivalent to a Layer. All feature types of a UserLayer come from the same
145 * WFS. The WFS can be named explicitly with the "wfs" attribute or it can be implied by
146 * context.
147 *
148 * @return the UserLayers as Array
149 */
150 public UserLayer[] getUserLayers() {
151 List<UserLayer> list = new ArrayList<UserLayer>( layers.size() );
152 for ( int i = 0; i < layers.size(); i++ ) {
153 if ( layers.get( i ) instanceof UserLayer ) {
154 list.add( (UserLayer) layers.get( i ) );
155 }
156 }
157 return list.toArray( new UserLayer[list.size()] );
158 }
159
160 /**
161 * A NamedLayer uses the "name" attribute to identify a layer known to the WMS and can contain
162 * zero or more styles, either NamedStyles or UserStyles. In the absence of any styles the
163 * default style for the layer is used.
164 *
165 * @return the NamedLayers as Array
166 */
167 public NamedLayer[] getNamedLayers() {
168 List<NamedLayer> list = new ArrayList<NamedLayer>( layers.size() );
169 for ( int i = 0; i < layers.size(); i++ ) {
170 if ( layers.get( i ) instanceof NamedLayer ) {
171 list.add( (NamedLayer) layers.get( i ) );
172 }
173 }
174 return list.toArray( new NamedLayer[list.size()] );
175 }
176
177 /**
178 * The version attribute gives the SLD version of an SLD document, to facilitate backward
179 * compatibility with static documents stored in various different versions of the SLD spec. The
180 * string has the format x.y.z, the same as in other OpenGIS Web Server specs. For example, an
181 * SLD document stored according to this spec would have the version string 0.7.2.
182 *
183 * @return the version of the SLD as String
184 *
185 */
186 public String getVersion() {
187 return version;
188 }
189
190 /**
191 * sets the <Version>
192 *
193 * @param version
194 * the version of the SLD
195 *
196 */
197 public void setVersion( String version ) {
198 this.version = version;
199 }
200
201 /**
202 * @return Returns the abstract_.
203 */
204 public String getAbstract() {
205 return abstract_;
206 }
207
208 /**
209 * @param abstract_
210 * The abstract_ to set.
211 */
212 public void setAbstract( String abstract_ ) {
213 this.abstract_ = abstract_;
214 }
215
216 /**
217 * @return Returns the name.
218 *
219 */
220 public String getName() {
221 return name;
222 }
223
224 /**
225 * @param name
226 * The name to set.
227 *
228 */
229 public void setName( String name ) {
230 this.name = name;
231 }
232
233 /**
234 * @return Returns the title.
235 *
236 */
237 public String getTitle() {
238 return title;
239 }
240
241 /**
242 * @param title
243 * The title to set.
244 *
245 */
246 public void setTitle( String title ) {
247 this.title = title;
248 }
249
250 /**
251 * exports the content of the Font as XML formated String
252 *
253 * @return xml representation of the Font
254 */
255 public String exportAsXML() {
256
257 StringBuffer sb = new StringBuffer( 50000 );
258 sb.append( "<?xml version='1.0' encoding='UTF-8'?>" );
259 sb.append( "<StyledLayerDescriptor version='" + version + "' " );
260 sb.append( "xmlns='http://www.opengis.net/sld' " );
261 sb.append( "xmlns:gml='http://www.opengis.net/gml' " );
262 sb.append( "xmlns:ogc='http://www.opengis.net/ogc' " );
263 sb.append( "xmlns:xlink='http://www.w3.org/1999/xlink' " );
264 sb.append( "xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'>" );
265
266 for ( int i = 0; i < layers.size(); i++ ) {
267 sb.append( ( (Marshallable) layers.get( i ) ).exportAsXML() );
268 }
269
270 sb.append( "</StyledLayerDescriptor>" );
271
272 return sb.toString();
273 }
274
275 }