KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > slide > event > EventCollectionFilter


1 /*
2  * $Header: /home/cvs/jakarta-slide/src/share/org/apache/slide/event/EventCollectionFilter.java,v 1.5.2.1 2004/11/30 07:05:52 masonjm Exp $
3  * $Revision: 1.5.2.1 $
4  * $Date: 2004/11/30 07:05:52 $
5  *
6  * ====================================================================
7  *
8  * Copyright 2004 The Apache Software Foundation
9  *
10  * Licensed under the Apache License, Version 2.0 (the "License");
11  * you may not use this file except in compliance with the License.
12  * You may obtain a copy of the License at
13  *
14  * http://www.apache.org/licenses/LICENSE-2.0
15  *
16  * Unless required by applicable law or agreed to in writing, software
17  * distributed under the License is distributed on an "AS IS" BASIS,
18  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19  * See the License for the specific language governing permissions and
20  * limitations under the License.
21  *
22  */

23
24 package org.apache.slide.event;
25
26 import java.util.List JavaDoc;
27 import java.util.Iterator JavaDoc;
28 import java.util.ArrayList JavaDoc;
29
30 /**
31  * @version $Revision: 1.5.2.1 $
32  */

33
34 public class EventCollectionFilter {
35     public static ContentEvent[] getChangedContents(EventCollection collection) {
36         List JavaDoc changedContents = new ArrayList JavaDoc();
37         if (collection != null)
38         {
39             List JavaDoc collectedEvents = collection.getCollection();
40             for ( Iterator JavaDoc i = collectedEvents.iterator(); i.hasNext(); ) {
41                 EventCollection.Event event = (EventCollection.Event)i.next();
42                 if ( event.getMethod() == ContentEvent.STORE ) {
43                     removeContentEvents(changedContents, ((ContentEvent)event.getEvent()).getUri());
44                     changedContents.add(event.getEvent());
45                 } else if ( event.getMethod() == ContentEvent.REMOVE ) {
46                     removeContentEvents(changedContents, ((ContentEvent)event.getEvent()).getUri());
47                 }
48             }
49         }
50         ContentEvent[] changedContentEvents = new ContentEvent[changedContents.size()];
51         return (ContentEvent [])changedContents.toArray(changedContentEvents);
52     }
53
54     public static ContentEvent[] getCreatedContents(EventCollection collection) {
55         List JavaDoc changedContents = new ArrayList JavaDoc();
56         if (collection != null)
57         {
58             List JavaDoc collectedEvents = collection.getCollection();
59             for ( Iterator JavaDoc i = collectedEvents.iterator(); i.hasNext(); ) {
60                 EventCollection.Event event = (EventCollection.Event)i.next();
61                 if ( event.getMethod() == ContentEvent.CREATE ) {
62                     removeContentEvents(changedContents, ((ContentEvent)event.getEvent()).getUri());
63                     changedContents.add(event.getEvent());
64                 } else if ( event.getMethod() == ContentEvent.REMOVE ) {
65                     removeContentEvents(changedContents, ((ContentEvent)event.getEvent()).getUri());
66                 }
67             }
68         }
69         ContentEvent[] changedContentEvents = new ContentEvent[changedContents.size()];
70         return (ContentEvent [])changedContents.toArray(changedContentEvents);
71     }
72
73     public static ContentEvent[] getRemovedContents(EventCollection collection) {
74         List JavaDoc changedContents = new ArrayList JavaDoc();
75         if (collection != null)
76         {
77             List JavaDoc collectedEvents = collection.getCollection();
78             for ( Iterator JavaDoc i = collectedEvents.iterator(); i.hasNext(); ) {
79                 EventCollection.Event event = (EventCollection.Event)i.next();
80                 if ( event.getMethod() == ContentEvent.REMOVE ) {
81                     removeContentEvents(changedContents, ((ContentEvent)event.getEvent()).getUri());
82                     changedContents.add(event.getEvent());
83                 } else if ( event.getMethod() == ContentEvent.CREATE || event.getMethod() == ContentEvent.STORE ) {
84                     removeContentEvents(changedContents, ((ContentEvent)event.getEvent()).getUri());
85                 }
86             }
87         }
88         ContentEvent[] changedContentEvents = new ContentEvent[changedContents.size()];
89         return (ContentEvent [])changedContents.toArray(changedContentEvents);
90     }
91
92     private static void removeContentEvents(List JavaDoc changedContents, String JavaDoc uri) {
93         for ( Iterator JavaDoc i = changedContents.iterator(); i.hasNext(); ) {
94             ContentEvent event = (ContentEvent)i.next();
95             if ( ((ContentEvent)event).getUri().equals(uri) ) {
96                 i.remove();
97             }
98         }
99     }
100 }
Popular Tags