Class | Line # | Actions | |||||
---|---|---|---|---|---|---|---|
DocumentRollingBackEvent | 38 | 11 | 0% | 7 | 2 |
1 | /* | |
2 | * See the NOTICE file distributed with this work for additional | |
3 | * information regarding copyright ownership. | |
4 | * | |
5 | * This is free software; you can redistribute it and/or modify it | |
6 | * under the terms of the GNU Lesser General Public License as | |
7 | * published by the Free Software Foundation; either version 2.1 of | |
8 | * the License, or (at your option) any later version. | |
9 | * | |
10 | * This software is distributed in the hope that it will be useful, | |
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
13 | * Lesser General Public License for more details. | |
14 | * | |
15 | * You should have received a copy of the GNU Lesser General Public | |
16 | * License along with this software; if not, write to the Free | |
17 | * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA | |
18 | * 02110-1301 USA, or see the FSF site: http://www.fsf.org. | |
19 | */ | |
20 | package org.xwiki.bridge.event; | |
21 | ||
22 | import org.xwiki.model.reference.DocumentReference; | |
23 | import org.xwiki.observation.event.filter.EventFilter; | |
24 | ||
25 | /** | |
26 | * An event triggered before a document is rolled back to a previous revision. | |
27 | * <p> | |
28 | * The event also send the following parameters: | |
29 | * </p> | |
30 | * <ul> | |
31 | * <li>source: the current {com.xpn.xwiki.doc.XWikiDocument} instance</li> | |
32 | * <li>data: the current {com.xpn.xwiki.XWikiContext} instance</li> | |
33 | * </ul> | |
34 | * | |
35 | * @version $Id: 03a734e2cc8d69da8039806b70539df7fc549948 $ | |
36 | * @since 5.0M2 | |
37 | */ | |
38 | public class DocumentRollingBackEvent extends AbstractDocumentEvent | |
39 | { | |
40 | /** | |
41 | * The version identifier for this Serializable class. Increment only if the <i>serialized</i> form of the class | |
42 | * changes. | |
43 | */ | |
44 | private static final long serialVersionUID = 1L; | |
45 | ||
46 | /** | |
47 | * The revision the document is about to be rolled back to. | |
48 | */ | |
49 | private String revision; | |
50 | ||
51 | /** | |
52 | * Matches all {@link DocumentRollingBackEvent} events. | |
53 | */ | |
54 | 5 | public DocumentRollingBackEvent() |
55 | { | |
56 | 5 | super(); |
57 | } | |
58 | ||
59 | /** | |
60 | * Matches {@link DocumentRollingBackEvent} events that target the specified document. | |
61 | * | |
62 | * @param documentReference the reference of the document to match | |
63 | */ | |
64 | 3 | public DocumentRollingBackEvent(DocumentReference documentReference) |
65 | { | |
66 | 3 | this(documentReference, null); |
67 | } | |
68 | ||
69 | /** | |
70 | * Matches {@link DocumentRollingBackEvent} events that target the specified document and revision. The revision is | |
71 | * matched only if it's not {@code null}. | |
72 | * | |
73 | * @param documentReference the reference of the document to match | |
74 | * @param revision the revision the document is about to be rolled back to | |
75 | */ | |
76 | 16 | public DocumentRollingBackEvent(DocumentReference documentReference, String revision) |
77 | { | |
78 | 16 | super(documentReference); |
79 | 16 | this.revision = revision; |
80 | } | |
81 | ||
82 | /** | |
83 | * Constructor using a custom {@link EventFilter}. | |
84 | * | |
85 | * @param eventFilter the filter to use for matching events | |
86 | */ | |
87 | 0 | public DocumentRollingBackEvent(EventFilter eventFilter) |
88 | { | |
89 | 0 | super(eventFilter); |
90 | } | |
91 | ||
92 | /** | |
93 | * @return the revision the document is about to be rolled back to | |
94 | */ | |
95 | 3 | public String getRevision() |
96 | { | |
97 | 3 | return revision; |
98 | } | |
99 | ||
100 | 9 | @Override |
101 | public boolean matches(Object otherEvent) | |
102 | { | |
103 | 9 | boolean matches = super.matches(otherEvent); |
104 | ||
105 | 9 | if (matches) { |
106 | 6 | DocumentRollingBackEvent documentRollingBackEvent = (DocumentRollingBackEvent) otherEvent; |
107 | 6 | matches = revision == null || revision.equals(documentRollingBackEvent.getRevision()); |
108 | } | |
109 | ||
110 | 9 | return matches; |
111 | } | |
112 | } |