001: //$HeadURL: https://svn.wald.intevation.org/svn/deegree/base/trunk/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 java.util.ArrayList;
047: import java.util.List;
048:
049: import org.deegree.framework.xml.Marshallable;
050:
051: /**
052: * A user-defined allows map styling to be defined externally from a system and to be passed around
053: * in an interoperable format.
054: * <p>
055: * </p>
056: * A UserStyle is at the same semantic level as a NamedStyle used in the context of a WMS. In a
057: * sense, a named style can be thought of as a reference to a hidden UserStyle that is stored inside
058: * of a map server.
059: *
060: *
061: * @author <a href="mailto:k.lupp@web.de">Katharina Lupp</a>
062: * @author last edited by: $Author: apoth $
063: * @version $Revision: 9340 $ $Date: 2007-12-27 04:32:12 -0800 (Thu, 27 Dec 2007) $
064: */
065: public class UserStyle extends AbstractStyle implements Marshallable {
066: private List<FeatureTypeStyle> featureTypeStyles = null;
067:
068: private String abstract_ = null;
069:
070: private String title = null;
071:
072: private boolean default_ = false;
073:
074: /**
075: * constructor initializing the class with the <UserStyle>
076: */
077: UserStyle(String name, String title, String abstract_,
078: boolean default_, FeatureTypeStyle[] featureTypeStyles) {
079: super (name);
080:
081: this .featureTypeStyles = new ArrayList<FeatureTypeStyle>();
082:
083: setTitle(title);
084: setAbstract(abstract_);
085: setDefault(default_);
086: setFeatureTypeStyles(featureTypeStyles);
087: }
088:
089: /**
090: * The Title is a human-readable short description for the style that might be displayed in a
091: * GUI pick list.
092: *
093: * @return the title of the User-AbstractStyle
094: *
095: */
096: public String getTitle() {
097: return title;
098: }
099:
100: /**
101: * sets the <Title>
102: *
103: * @param title
104: * the title of the User-AbstractStyle
105: *
106: */
107: public void setTitle(String title) {
108: this .title = title;
109: }
110:
111: /**
112: * the Abstract is a more exact description that may be a few paragraphs long.
113: *
114: * @return the abstract of the User-AbstractStyle
115: */
116: public String getAbstract() {
117: return abstract_;
118: }
119:
120: /**
121: * sets the <Abstract>
122: *
123: * @param abstract_
124: * the abstract of the User-AbstractStyle
125: */
126: public void setAbstract(String abstract_) {
127: this .abstract_ = abstract_;
128: }
129:
130: /**
131: * The IsDefault element identifies whether a style is the default style of a layer, for use in
132: * SLD library mode when rendering or for storing inside of a map server. The default value is
133: * <tt>false</tt>.
134: *
135: * @return true if the style ist the default style
136: */
137: public boolean isDefault() {
138: return default_;
139: }
140:
141: /**
142: * sets the <Default>
143: *
144: * @param default_
145: */
146: public void setDefault(boolean default_) {
147: this .default_ = default_;
148: }
149:
150: /**
151: * A UserStyle can contain one or more FeatureTypeStyles which allow the rendering of features
152: * of specific types.
153: * <p>
154: * </p>
155: * The FeatureTypeStyle defines the styling that is to be applied to a single feature type of a
156: * layer.
157: * <p>
158: * </p>
159: * The FeatureTypeStyle element identifies that explicit separation in SLD between the handling
160: * of layers and the handling of features of specific feature types. The layer concept is unique
161: * to WMS and SLD, but features are used more generally, such as in WFS and GML, so this
162: * explicit separation is important.
163: *
164: * @return the FeatureTypeStyles of a User-AbstractStyle
165: *
166: */
167: public FeatureTypeStyle[] getFeatureTypeStyles() {
168:
169: return featureTypeStyles
170: .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(
180: FeatureTypeStyle[] featureTypeStyles) {
181: this .featureTypeStyles.clear();
182:
183: if (featureTypeStyles != null) {
184: for (int i = 0; i < featureTypeStyles.length; i++) {
185: addFeatureTypeStyle(featureTypeStyles[i]);
186: }
187: }
188: }
189:
190: /**
191: * Adds a <FeatureTypeStyle>
192: *
193: * @param featureTypeStyle
194: * a FeatureTypeStyle to add
195: */
196: public void addFeatureTypeStyle(FeatureTypeStyle featureTypeStyle) {
197: featureTypeStyles.add(featureTypeStyle);
198: }
199:
200: /**
201: * Removes a <FeatureTypeStyle>
202: */
203: public void removeFeatureTypeStyle(FeatureTypeStyle featureTypeStyle) {
204: if (featureTypeStyles.indexOf(featureTypeStyle) != -1) {
205: featureTypeStyles.remove(featureTypeStyles
206: .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(name).append("</Name>");
221: }
222: if (title != null && !title.equals("")) {
223: sb.append("<Title>").append(title).append("</Title>");
224: }
225: if (abstract_ != null && !abstract_.equals("")) {
226: sb.append("<Abstract>").append(abstract_).append(
227: "</Abstract>");
228: }
229: if (default_) {
230: sb.append("<IsDefault>").append(1).append("</IsDefault>");
231: }
232: for (int i = 0; i < featureTypeStyles.size(); i++) {
233: sb.append(((Marshallable) featureTypeStyles.get(i))
234: .exportAsXML());
235: }
236: sb.append("</UserStyle>");
237:
238: return sb.toString();
239: }
240:
241: }
|