aboutsummaryrefslogtreecommitdiffstats
path: root/server/src/main/java/com/vaadin/ui/Flash.java
blob: 086814fc67a759a4b6010b2fb685920be857dfa7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
/*
 * Copyright 2000-2022 Vaadin Ltd.
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */
package com.vaadin.ui;

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.jsoup.nodes.Element;

import com.vaadin.server.Resource;
import com.vaadin.shared.ui.flash.FlashState;
import com.vaadin.ui.declarative.DesignContext;

/**
 * A component for displaying Adobe® Flash® content.
 *
 * @author Vaadin Ltd.
 * @since 7.0
 * @deprecated No modern browsers support Flash content anymore.
 */
@Deprecated
public class Flash extends AbstractEmbedded {

    /**
     * Creates a new empty Flash component.
     */
    public Flash() {

    }

    /**
     * Creates a new empty Flash component with the given caption.
     *
     * @param caption
     *            The caption for the component
     */
    public Flash(String caption) {
        setCaption(caption);
    }

    /**
     * Creates a new Flash component with the given caption and content.
     *
     * @param caption
     *            The caption for the component
     * @param source
     *            A Resource representing the Flash content that should be
     *            displayed
     */
    public Flash(String caption, Resource source) {
        this(caption);
        setSource(source);
    }

    @Override
    protected FlashState getState() {
        return (FlashState) super.getState();
    }

    @Override
    protected FlashState getState(boolean markAsDirty) {
        return (FlashState) super.getState(markAsDirty);
    }

    /**
     * This attribute specifies the base path used to resolve relative URIs
     * specified by the classid, data, and archive attributes. When absent, its
     * default value is the base URI of the current document.
     *
     * @param codebase
     *            The base path
     */
    public void setCodebase(String codebase) {
        if (codebase != getState().codebase || (codebase != null
                && !codebase.equals(getState().codebase))) {
            getState().codebase = codebase;
            requestRepaint();
        }
    }

    /**
     * Returns the codebase.
     *
     * @see #setCodebase(String)
     * @since 7.4.1
     * @return Current codebase.
     */
    public String getCodebase() {
        return getState(false).codebase;
    }

    /**
     * This attribute specifies the content type of data expected when
     * downloading the object specified by classid. This attribute is optional
     * but recommended when classid is specified since it allows the user agent
     * to avoid loading information for unsupported content types. When absent,
     * it defaults to the value of the type attribute.
     *
     * @param codetype
     *            the codetype to set.
     */
    public void setCodetype(String codetype) {
        if (codetype != getState().codetype || (codetype != null
                && !codetype.equals(getState().codetype))) {
            getState().codetype = codetype;
            requestRepaint();
        }
    }

    /**
     * Returns the current codetype.
     *
     * @see #setCodetype(String)
     * @since 7.4.1
     * @return Current codetype.
     */
    public String getCodetype() {
        return getState(false).codetype;
    }

    /**
     * This attribute may be used to specify a space-separated list of URIs for
     * archives containing resources relevant to the object, which may include
     * the resources specified by the classid and data attributes. Preloading
     * archives will generally result in reduced load times for objects.
     * Archives specified as relative URIs should be interpreted relative to the
     * codebase attribute.
     *
     * @param archive
     *            Space-separated list of URIs with resources relevant to the
     *            object
     */
    public void setArchive(String archive) {
        if (archive != getState().archive
                || (archive != null && !archive.equals(getState().archive))) {
            getState().archive = archive;
            requestRepaint();
        }
    }

    /**
     * Returns current archive.
     *
     * @see #setArchive(String)
     * @since 7.4.1
     * @return Current archive.
     */
    public String getArchive() {
        return getState(false).archive;
    }

    /**
     * Sets standby.
     *
     * @param standby
     *            Standby string.
     */
    public void setStandby(String standby) {
        if (standby != getState().standby
                || (standby != null && !standby.equals(getState().standby))) {
            getState().standby = standby;
            requestRepaint();
        }
    }

    /**
     * Returns standby.
     *
     * @since 7.4.1
     * @return Standby string.
     */
    public String getStandby() {
        return getState(false).standby;
    }

    /**
     * Sets an object parameter. Parameters are optional information, and they
     * are passed to the instantiated object. Parameters are are stored as name
     * value pairs. This overrides the previous value assigned to this
     * parameter.
     *
     * @param name
     *            the name of the parameter.
     * @param value
     *            the value of the parameter.
     */
    public void setParameter(String name, String value) {
        if (getState().embedParams == null) {
            getState().embedParams = new HashMap<>();
        }
        getState().embedParams.put(name, value);
        requestRepaint();
    }

    /**
     * Gets the value of an object parameter. Parameters are optional
     * information, and they are passed to the instantiated object. Parameters
     * are are stored as name value pairs.
     *
     * @param name
     *            name of the parameter
     * @return the Value of parameter or null if not found.
     */
    public String getParameter(String name) {
        return getState(false).embedParams != null
                ? getState(false).embedParams.get(name)
                : null;
    }

    /**
     * Removes an object parameter from the list.
     *
     * @param name
     *            the name of the parameter to remove.
     */
    public void removeParameter(String name) {
        if (getState().embedParams == null) {
            return;
        }
        getState().embedParams.remove(name);
        requestRepaint();
    }

    @Override
    public void writeDesign(Element design, DesignContext designContext) {
        super.writeDesign(design, designContext);

        // Parameters, in alphabetic order
        List<String> paramNames = new ArrayList<>();
        for (String param : getParameterNames()) {
            paramNames.add(param);
        }

        Collections.sort(paramNames);
        for (String param : paramNames) {
            design.appendElement("parameter").attr("name", param).attr("value",
                    getParameter(param));
        }
    }

    /**
     * Returns an iterable with declared parameter names.
     *
     * @see #setParameter(String, String)
     * @see #getParameter(String)
     * @since 7.4.1
     * @return An iterable with declared parameter names.
     */
    public Iterable<String> getParameterNames() {
        Map<String, String> map = getState(false).embedParams;
        if (map == null) {
            return Collections.emptySet();
        } else {
            return Collections.unmodifiableSet(map.keySet());
        }
    }

    @Override
    public void readDesign(Element design, DesignContext designContext) {
        super.readDesign(design, designContext);
        for (Element paramElement : design.getElementsByTag("parameter")) {
            setParameter(paramElement.attr("name"), paramElement.attr("value"));
        }
    }

}