/
Page.java
1234 lines (1117 loc) · 40.7 KB
/
Page.java
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
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* Copyright 2000-2016 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.server;
import java.io.Serializable;
import java.lang.reflect.Method;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.EventObject;
import java.util.LinkedHashSet;
import java.util.LinkedList;
import java.util.List;
import com.vaadin.event.EventRouter;
import com.vaadin.event.FieldEvents.FocusListener;
import com.vaadin.shared.Registration;
import com.vaadin.shared.ui.BorderStyle;
import com.vaadin.shared.ui.ui.PageClientRpc;
import com.vaadin.shared.ui.ui.PageState;
import com.vaadin.shared.ui.ui.UIConstants;
import com.vaadin.shared.ui.ui.UIState;
import com.vaadin.shared.util.SharedUtil;
import com.vaadin.ui.JavaScript;
import com.vaadin.ui.LegacyWindow;
import com.vaadin.ui.Link;
import com.vaadin.ui.Notification;
import com.vaadin.ui.UI;
import com.vaadin.util.ReflectTools;
public class Page implements Serializable {
/**
* Listener that gets notified when the size of the browser window
* containing the uI has changed.
*
* @see UI#addListener(BrowserWindowResizeListener)
*/
public interface BrowserWindowResizeListener extends Serializable {
/**
* Invoked when the browser window containing a UI has been resized.
*
* @param event
* a browser window resize event
*/
public void browserWindowResized(BrowserWindowResizeEvent event);
}
/**
* Event that is fired when a browser window containing a uI is resized.
*/
public static class BrowserWindowResizeEvent extends EventObject {
private final int width;
private final int height;
/**
* Creates a new event
*
* @param source
* the uI for which the browser window has been resized
* @param width
* the new width of the browser window
* @param height
* the new height of the browser window
*/
public BrowserWindowResizeEvent(Page source, int width, int height) {
super(source);
this.width = width;
this.height = height;
}
@Override
public Page getSource() {
return (Page) super.getSource();
}
/**
* Gets the new browser window height
*
* @return an integer with the new pixel height of the browser window
*/
public int getHeight() {
return height;
}
/**
* Gets the new browser window width
*
* @return an integer with the new pixel width of the browser window
*/
public int getWidth() {
return width;
}
}
/**
* Private class for storing properties related to opening resources.
*/
private class OpenResource implements Serializable {
/**
* The resource to open
*/
private final Resource resource;
/**
* The name of the target window
*/
private final String name;
/**
* The width of the target window
*/
private final int width;
/**
* The height of the target window
*/
private final int height;
/**
* The border style of the target window
*/
private final BorderStyle border;
private final boolean tryToOpenAsPopup;
/**
* Creates a new open resource.
*
* @param url
* The URL to open
* @param name
* The name of the target window
* @param width
* The width of the target window
* @param height
* The height of the target window
* @param border
* The border style of the target window
* @param tryToOpenAsPopup
* Should try to open as a pop-up
*/
private OpenResource(String url, String name, int width, int height,
BorderStyle border, boolean tryToOpenAsPopup) {
this(new ExternalResource(url), name, width, height, border,
tryToOpenAsPopup);
}
/**
* Creates a new open resource.
*
* @param resource
* The resource to open
* @param name
* The name of the target window
* @param width
* The width of the target window
* @param height
* The height of the target window
* @param border
* The border style of the target window
* @param tryToOpenAsPopup
* Should try to open as a pop-up
*/
private OpenResource(Resource resource, String name, int width,
int height, BorderStyle border, boolean tryToOpenAsPopup) {
this.resource = resource;
this.name = name;
this.width = width;
this.height = height;
this.border = border;
this.tryToOpenAsPopup = tryToOpenAsPopup;
}
/**
* Paints the open request. Should be painted inside the window.
*
* @param target
* the paint target
* @throws PaintException
* if the paint operation fails
*/
private void paintContent(PaintTarget target) throws PaintException {
target.startTag("open");
target.addAttribute("src", resource);
if (name != null && name.length() > 0) {
target.addAttribute("name", name);
}
if (!tryToOpenAsPopup) {
target.addAttribute("popup", tryToOpenAsPopup);
}
if (width >= 0) {
target.addAttribute("width", width);
}
if (height >= 0) {
target.addAttribute("height", height);
}
switch (border) {
case MINIMAL:
target.addAttribute("border", "minimal");
break;
case NONE:
target.addAttribute("border", "none");
break;
}
target.endTag("open");
}
}
private static final Method BROWSER_RESIZE_METHOD = ReflectTools.findMethod(
BrowserWindowResizeListener.class, "browserWindowResized",
BrowserWindowResizeEvent.class);
/**
* @deprecated As of 7.0, use {@link BorderStyle#NONE} instead.
*/
@Deprecated
public static final BorderStyle BORDER_NONE = BorderStyle.NONE;
/**
* @deprecated As of 7.0, use {@link BorderStyle#MINIMAL} instead.
*/
@Deprecated
public static final BorderStyle BORDER_MINIMAL = BorderStyle.MINIMAL;
/**
* @deprecated As of 7.0, use {@link BorderStyle#DEFAULT} instead.
*/
@Deprecated
public static final BorderStyle BORDER_DEFAULT = BorderStyle.DEFAULT;
/**
* Listener that that gets notified when the URI fragment of the page
* changes.
*
* @see Page#addUriFragmentChangedListener(UriFragmentChangedListener)
*/
public interface UriFragmentChangedListener extends Serializable {
/**
* Event handler method invoked when the URI fragment of the page
* changes. Please note that the initial URI fragment has already been
* set when a new UI is initialized, so there will not be any initial
* event for listeners added during {@link UI#init(VaadinRequest)}.
*
* @see Page#addUriFragmentChangedListener(UriFragmentChangedListener)
*
* @param event
* the URI fragment changed event
*/
public void uriFragmentChanged(UriFragmentChangedEvent event);
}
private static final Method URI_FRAGMENT_CHANGED_METHOD = ReflectTools
.findMethod(Page.UriFragmentChangedListener.class,
"uriFragmentChanged", UriFragmentChangedEvent.class);
/**
* Resources to be opened automatically on next repaint. The list is
* automatically cleared when it has been sent to the client.
*/
private final LinkedList<OpenResource> openList = new LinkedList<>();
/**
* A list of notifications that are waiting to be sent to the client.
* Cleared (set to null) when the notifications have been sent.
*/
private List<Notification> notifications;
/**
* Event fired when the URI fragment of a <code>Page</code> changes.
*
* @see Page#addUriFragmentChangedListener(UriFragmentChangedListener)
*/
public static class UriFragmentChangedEvent extends EventObject {
/**
* The new URI fragment
*/
private final String uriFragment;
/**
* Creates a new instance of UriFragmentReader change event.
*
* @param source
* the Source of the event.
* @param uriFragment
* the new uriFragment
*/
public UriFragmentChangedEvent(Page source, String uriFragment) {
super(source);
this.uriFragment = uriFragment;
}
/**
* Gets the page in which the fragment has changed.
*
* @return the page in which the fragment has changed
*/
public Page getPage() {
return (Page) getSource();
}
/**
* Get the new URI fragment
*
* @return the new fragment
*/
public String getUriFragment() {
return uriFragment;
}
}
private static interface InjectedStyle extends Serializable {
public void paint(int id, PaintTarget target) throws PaintException;
}
private static class InjectedStyleString implements InjectedStyle {
private final String css;
public InjectedStyleString(String css) {
this.css = css;
}
@Override
public void paint(int id, PaintTarget target) throws PaintException {
target.startTag("css-string");
target.addAttribute("id", id);
target.addText(css);
target.endTag("css-string");
}
}
private static class InjectedStyleResource implements InjectedStyle {
private final Resource resource;
public InjectedStyleResource(Resource resource) {
this.resource = resource;
}
@Override
public void paint(int id, PaintTarget target) throws PaintException {
target.startTag("css-resource");
target.addAttribute("id", id);
target.addAttribute("url", resource);
target.endTag("css-resource");
}
@Override
public boolean equals(Object obj) {
if (obj == this) {
return true;
} else if (obj instanceof InjectedStyleResource) {
InjectedStyleResource that = (InjectedStyleResource) obj;
return resource.equals(that.resource);
} else {
return false;
}
}
@Override
public int hashCode() {
return resource.hashCode();
}
}
/**
* Contains dynamically injected styles injected in the HTML document at
* runtime.
*
* @since 7.1
*/
public static class Styles implements Serializable {
private LinkedHashSet<InjectedStyle> injectedStyles = new LinkedHashSet<>();
private LinkedHashSet<InjectedStyle> pendingInjections = new LinkedHashSet<>();
private final UI ui;
private Styles(UI ui) {
this.ui = ui;
}
/**
* Injects a raw CSS string into the page.
*
* @param css
* The CSS to inject
*/
public void add(String css) {
if (css == null) {
throw new IllegalArgumentException(
"Cannot inject null CSS string");
}
pendingInjections.add(new InjectedStyleString(css));
ui.markAsDirty();
}
/**
* Injects a CSS resource into the page
*
* @param resource
* The resource to inject.
*/
public void add(Resource resource) {
if (resource == null) {
throw new IllegalArgumentException(
"Cannot inject null resource");
}
InjectedStyleResource injection = new InjectedStyleResource(
resource);
if (!injectedStyles.contains(injection)
&& pendingInjections.add(injection)) {
ui.markAsDirty();
}
}
private void paint(PaintTarget target) throws PaintException {
// If full repaint repaint all injections
if (target.isFullRepaint()) {
injectedStyles.addAll(pendingInjections);
pendingInjections = injectedStyles;
injectedStyles = new LinkedHashSet<>();
}
if (!pendingInjections.isEmpty()) {
target.startTag("css-injections");
for (InjectedStyle pending : pendingInjections) {
int id = injectedStyles.size();
pending.paint(id, target);
injectedStyles.add(pending);
}
pendingInjections.clear();
target.endTag("css-injections");
}
}
}
private EventRouter eventRouter;
private final UI uI;
private int browserWindowWidth = -1;
private int browserWindowHeight = -1;
private JavaScript javaScript;
private Styles styles;
/**
* The current browser location.
*/
private URI location;
private final PageState state;
private String windowName;
public Page(UI uI, PageState state) {
this.uI = uI;
this.state = state;
}
private Registration addListener(Class<?> eventType, Object target,
Method method) {
if (!hasEventRouter()) {
eventRouter = new EventRouter();
}
return eventRouter.addListener(eventType, target, method);
}
private void removeListener(Class<?> eventType, Object target,
Method method) {
if (hasEventRouter()) {
eventRouter.removeListener(eventType, target, method);
}
}
/**
* Adds a listener that gets notified every time the URI fragment of this
* page is changed. Please note that the initial URI fragment has already
* been set when a new UI is initialized, so there will not be any initial
* event for listeners added during {@link UI#init(VaadinRequest)}.
*
* @see #getUriFragment()
* @see #setUriFragment(String)
* @see Registration
*
* @param listener
* the URI fragment listener to add
* @return a registration object for removing the listener
*/
public Registration addUriFragmentChangedListener(
Page.UriFragmentChangedListener listener) {
return addListener(UriFragmentChangedEvent.class, listener,
URI_FRAGMENT_CHANGED_METHOD);
}
/**
* Removes a URI fragment listener that was previously added to this page.
*
* @param listener
* the URI fragment listener to remove
*
* @see Page#addUriFragmentChangedListener(UriFragmentChangedListener)
*
* @deprecated As of 8.0, replaced by {@link Registration#remove()} in the
* registration object returned from
* {@link #addUriFragmentChangedListener(FocusListener)}.
*/
@Deprecated
public void removeUriFragmentChangedListener(
Page.UriFragmentChangedListener listener) {
removeListener(UriFragmentChangedEvent.class, listener,
URI_FRAGMENT_CHANGED_METHOD);
}
/**
* Sets the fragment part in the current location URI. Optionally fires a
* {@link UriFragmentChangedEvent}.
* <p>
* The fragment is the optional last component of a URI, prefixed with a
* hash sign ("#").
* <p>
* Passing an empty string as <code>newFragment</code> sets an empty
* fragment (a trailing "#" in the URI.) Passing <code>null</code> if there
* is already a non-null fragment will leave a trailing # in the URI since
* removing it would cause the browser to reload the page. This is not fully
* consistent with the semantics of {@link java.net.URI}.
*
* @param newUriFragment
* The new fragment.
* @param fireEvents
* true to fire event
*
* @see #getUriFragment()
* @see #setLocation(URI)
* @see UriFragmentChangedEvent
* @see Page.UriFragmentChangedListener
*
*/
public void setUriFragment(String newUriFragment, boolean fireEvents) {
String oldUriFragment = location.getFragment();
if (newUriFragment == null && getUriFragment() != null) {
// Can't completely remove the fragment once it has been set, will
// instead set it to the empty string
newUriFragment = "";
}
if (newUriFragment == oldUriFragment || (newUriFragment != null
&& newUriFragment.equals(oldUriFragment))) {
return;
}
try {
location = new URI(location.getScheme(),
location.getSchemeSpecificPart(), newUriFragment);
} catch (URISyntaxException e) {
// This should not actually happen as the fragment syntax is not
// constrained
throw new RuntimeException(e);
}
if (fireEvents) {
fireEvent(new UriFragmentChangedEvent(this, newUriFragment));
}
uI.markAsDirty();
}
private void fireEvent(EventObject event) {
if (hasEventRouter()) {
eventRouter.fireEvent(event);
}
}
/**
* Sets URI fragment. This method fires a {@link UriFragmentChangedEvent}
*
* @param newUriFragment
* id of the new fragment
* @see UriFragmentChangedEvent
* @see Page.UriFragmentChangedListener
*/
public void setUriFragment(String newUriFragment) {
setUriFragment(newUriFragment, true);
}
/**
* Gets the currently set URI fragment.
* <p>
* Returns <code>null</code> if there is no fragment and an empty string if
* there is an empty fragment.
* <p>
* To listen to changes in fragment, hook a
* {@link Page.UriFragmentChangedListener}.
*
* @return the current fragment in browser location URI.
*
* @see #getLocation()
* @see #setUriFragment(String)
* @see #addUriFragmentChangedListener(UriFragmentChangedListener)
*/
public String getUriFragment() {
return location.getFragment();
}
public void init(VaadinRequest request) {
// NOTE: UI.refresh makes assumptions about the semantics of this
// method.
// It should be kept in sync if this method is changed.
// Extract special parameter sent by vaadinBootstrap.js
String location = request.getParameter("v-loc");
String clientWidth = request.getParameter("v-cw");
String clientHeight = request.getParameter("v-ch");
windowName = request.getParameter("v-wn");
if (location != null) {
try {
this.location = new URI(location);
} catch (URISyntaxException e) {
throw new RuntimeException(
"Invalid location URI received from client", e);
}
}
if (clientWidth != null && clientHeight != null) {
try {
browserWindowWidth = Integer.parseInt(clientWidth);
browserWindowHeight = Integer.parseInt(clientHeight);
} catch (NumberFormatException e) {
throw new RuntimeException(
"Invalid window size received from client", e);
}
}
}
public WebBrowser getWebBrowser() {
return uI.getSession().getBrowser();
}
/**
* Gets the window.name value of the browser window of this page.
*
* @since 7.2
*
* @return the window name, <code>null</code> if the name is not known
*/
public String getWindowName() {
return windowName;
}
/**
* For internal use only. Updates the internal state with the given values.
* Does not resize the Page or browser window.
*
* @deprecated As of 7.2, use
* {@link #updateBrowserWindowSize(int, int, boolean)} instead.
*
* @param width
* the new browser window width
* @param height
* the new browse window height
*/
@Deprecated
public void updateBrowserWindowSize(int width, int height) {
updateBrowserWindowSize(width, height, true);
}
/**
* For internal use only. Updates the internal state with the given values.
* Does not resize the Page or browser window.
*
* @since 7.2
*
* @param width
* the new browser window width
* @param height
* the new browser window height
* @param fireEvents
* whether to fire {@link BrowserWindowResizeEvent} if the size
* changes
*/
public void updateBrowserWindowSize(int width, int height,
boolean fireEvents) {
boolean sizeChanged = false;
if (width != browserWindowWidth) {
browserWindowWidth = width;
sizeChanged = true;
}
if (height != browserWindowHeight) {
browserWindowHeight = height;
sizeChanged = true;
}
if (fireEvents && sizeChanged) {
fireEvent(new BrowserWindowResizeEvent(this, browserWindowWidth,
browserWindowHeight));
}
}
/**
* Adds a new {@link BrowserWindowResizeListener} to this UI. The listener
* will be notified whenever the browser window within which this UI resides
* is resized.
* <p>
* In most cases, the UI should be in lazy resize mode when using browser
* window resize listeners. Otherwise, a large number of events can be
* received while a resize is being performed. Use
* {@link UI#setResizeLazy(boolean)}.
* </p>
*
* @param resizeListener
* the listener to add
* @return a registration object for removing the listener
*
* @see BrowserWindowResizeListener#browserWindowResized(BrowserWindowResizeEvent)
* @see UI#setResizeLazy(boolean)
* @see Registration
*/
public Registration addBrowserWindowResizeListener(
BrowserWindowResizeListener resizeListener) {
Registration registration = addListener(BrowserWindowResizeEvent.class,
resizeListener, BROWSER_RESIZE_METHOD);
getState(true).hasResizeListeners = true;
return () -> {
registration.remove();
getState(true).hasResizeListeners = hasEventRouter()
&& eventRouter.hasListeners(BrowserWindowResizeEvent.class);
};
}
/**
* Removes a {@link BrowserWindowResizeListener} from this UI. The listener
* will no longer be notified when the browser window is resized.
*
* @param resizeListener
* the listener to remove
*
* @deprecated As of 8.0, replaced by {@link Registration#remove()} in the
* registration object returned from
* {@link #addBrowserWindowResizeListener(BrowserWindowResizeListener)}
* .
*/
@Deprecated
public void removeBrowserWindowResizeListener(
BrowserWindowResizeListener resizeListener) {
removeListener(BrowserWindowResizeEvent.class, resizeListener,
BROWSER_RESIZE_METHOD);
getState(true).hasResizeListeners = hasEventRouter()
&& eventRouter.hasListeners(BrowserWindowResizeEvent.class);
}
/**
* Gets the last known height of the browser window in which this UI
* resides.
*
* @return the browser window height in pixels
*/
public int getBrowserWindowHeight() {
return browserWindowHeight;
}
/**
* Gets the last known width of the browser window in which this uI resides.
*
* @return the browser window width in pixels
*/
public int getBrowserWindowWidth() {
return browserWindowWidth;
}
public JavaScript getJavaScript() {
if (javaScript == null) {
// Create and attach on first use
javaScript = new JavaScript();
javaScript.extend(uI);
}
return javaScript;
}
/**
* Returns that stylesheet associated with this Page. The stylesheet
* contains additional styles injected at runtime into the HTML document.
*
* @since 7.1
*/
public Styles getStyles() {
if (styles == null) {
styles = new Styles(uI);
}
return styles;
}
public void paintContent(PaintTarget target) throws PaintException {
if (!openList.isEmpty()) {
for (OpenResource anOpenList : openList) {
(anOpenList).paintContent(target);
}
openList.clear();
}
// Paint notifications
if (notifications != null) {
target.startTag("notifications");
for (final Notification n : notifications) {
target.startTag("notification");
if (n.getCaption() != null) {
target.addAttribute(
UIConstants.ATTRIBUTE_NOTIFICATION_CAPTION,
n.getCaption());
}
if (n.getDescription() != null) {
target.addAttribute(
UIConstants.ATTRIBUTE_NOTIFICATION_MESSAGE,
n.getDescription());
}
if (n.getIcon() != null) {
target.addAttribute(UIConstants.ATTRIBUTE_NOTIFICATION_ICON,
n.getIcon());
}
if (!n.isHtmlContentAllowed()) {
target.addAttribute(
UIConstants.NOTIFICATION_HTML_CONTENT_NOT_ALLOWED,
true);
}
target.addAttribute(UIConstants.ATTRIBUTE_NOTIFICATION_POSITION,
n.getPosition().ordinal());
target.addAttribute(UIConstants.ATTRIBUTE_NOTIFICATION_DELAY,
n.getDelayMsec());
if (n.getStyleName() != null) {
target.addAttribute(
UIConstants.ATTRIBUTE_NOTIFICATION_STYLE,
n.getStyleName());
}
target.endTag("notification");
}
target.endTag("notifications");
notifications = null;
}
if (location != null) {
target.addAttribute(UIConstants.LOCATION_VARIABLE,
location.toString());
}
if (styles != null) {
styles.paint(target);
}
}
/**
* Navigates this page to the given URI. The contents of this page in the
* browser is replaced with whatever is returned for the given URI.
* <p>
* This method should not be used to start downloads, as the client side
* will assume the browser will navigate away when opening the URI. Use one
* of the {@code Page.open} methods or {@code FileDownloader} instead.
*
* @see #open(String, String)
* @see FileDownloader
*
* @param uri
* the URI to show
*/
public void setLocation(String uri) {
openList.add(
new OpenResource(uri, "_self", -1, -1, BORDER_DEFAULT, false));
uI.markAsDirty();
}
/**
* Navigates this page to the given URI. The contents of this page in the
* browser is replaced with whatever is returned for the given URI.
* <p>
* This method should not be used to start downloads, as the client side
* will assume the browser will navigate away when opening the URI. Use one
* of the {@code Page.open} methods or {@code FileDownloader} instead.
*
* @see #open(String, String)
* @see FileDownloader
*
* @param uri
* the URI to show
*/
public void setLocation(URI uri) {
setLocation(uri.toString());
}
/**
* Returns the location URI of this page, as reported by the browser. Note
* that this may not be consistent with the server URI the application is
* deployed in due to potential proxies, redirections and similar.
*
* @return The browser location URI.
*/
public URI getLocation() {
if (location == null && !uI.getSession().getConfiguration()
.isSendUrlsAsParameters()) {
throw new IllegalStateException("Location is not available as the "
+ Constants.SERVLET_PARAMETER_SENDURLSASPARAMETERS
+ " parameter is configured as false");
}
return location;
}
/**
* For internal use only. Used to update the server-side location when the
* client-side location changes.
*
* @deprecated As of 7.2, use {@link #updateLocation(String, boolean)}
* instead.
*
* @param location
* the new location URI
*/
@Deprecated
public void updateLocation(String location) {
updateLocation(location, true);
}
/**
* For internal use only. Used to update the server-side location when the
* client-side location changes.
*
* @since 7.2
*
* @param location
* the new location URI
* @param fireEvents
* whether to fire {@link UriFragmentChangedEvent} if the URI
* fragment changes
*/
public void updateLocation(String location, boolean fireEvents) {
try {
String oldUriFragment = this.location.getFragment();
this.location = new URI(location);
String newUriFragment = this.location.getFragment();
if (fireEvents
&& !SharedUtil.equals(oldUriFragment, newUriFragment)) {
fireEvent(new UriFragmentChangedEvent(this, newUriFragment));
}
} catch (URISyntaxException e) {
throw new RuntimeException(e);
}
}
/**
* Opens the given url in a window with the given name. Equivalent to
* {@link #open(String, String, boolean) open} (url, windowName, true) .
* <p>
* The supplied {@code windowName} is used as the target name in a
* window.open call in the client. This means that special values such as
* "_blank", "_self", "_top", "_parent" have special meaning. An empty or
* <code>null</code> window name is also a special case.
* </p>
* <p>
* "", null and "_self" as {@code windowName} all causes the URL to be
* opened in the current window, replacing any old contents. For
* downloadable content you should avoid "_self" as "_self" causes the
* client to skip rendering of any other changes as it considers them
* irrelevant (the page will be replaced by the response from the URL). This
* can speed up the opening of a URL, but it might also put the client side
* into an inconsistent state if the window content is not completely
* replaced e.g., if the URL is downloaded instead of displayed in the
* browser.
* </p>
* <p>
* "_blank" as {@code windowName} causes the URL to always be opened in a
* new window or tab (depends on the browser and browser settings).
* </p>
* <p>
* "_top" and "_parent" as {@code windowName} works as specified by the HTML
* standard.
* </p>
* <p>