1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
package org.mule.module.atom.routing; |
11 | |
|
12 | |
import org.mule.api.MuleMessage; |
13 | |
import org.mule.api.routing.filter.Filter; |
14 | |
|
15 | |
import java.util.Date; |
16 | |
|
17 | |
import org.apache.abdera.model.Entry; |
18 | |
import org.apache.commons.logging.Log; |
19 | |
import org.apache.commons.logging.LogFactory; |
20 | |
|
21 | |
|
22 | |
|
23 | |
|
24 | |
|
25 | |
public class EntryLastUpdatedFilter implements Filter |
26 | |
{ |
27 | |
|
28 | |
|
29 | |
|
30 | 0 | private final transient Log logger = LogFactory.getLog(EntryLastUpdatedFilter.class); |
31 | |
private Date lastUpdate; |
32 | |
|
33 | 0 | private boolean acceptWithoutUpdateDate = true; |
34 | |
|
35 | |
public EntryLastUpdatedFilter() |
36 | 0 | { |
37 | 0 | } |
38 | |
|
39 | |
public EntryLastUpdatedFilter(Date lastUpdate) |
40 | 0 | { |
41 | 0 | this.lastUpdate = lastUpdate; |
42 | 0 | } |
43 | |
|
44 | |
public boolean accept(MuleMessage message) |
45 | |
{ |
46 | 0 | Entry entry = (Entry) message.getPayload(); |
47 | 0 | Date updated = entry.getEdited(); |
48 | 0 | if (updated == null) |
49 | |
{ |
50 | 0 | updated = entry.getPublished(); |
51 | 0 | if (updated == null) |
52 | |
{ |
53 | 0 | if (isAcceptWithoutUpdateDate()) |
54 | |
{ |
55 | 0 | if (logger.isDebugEnabled()) |
56 | |
{ |
57 | 0 | logger.debug("Entry does not have a last updated or published date set, assuming the feed should be processed"); |
58 | |
} |
59 | 0 | return true; |
60 | |
} |
61 | |
else |
62 | |
{ |
63 | 0 | if (logger.isWarnEnabled()) |
64 | |
{ |
65 | 0 | logger.warn("Entry does not have a last updated or published date set, not consuming the feed because 'acceptWithoutUpdateDate' is false"); |
66 | |
} |
67 | 0 | return false; |
68 | |
} |
69 | |
} |
70 | |
} |
71 | 0 | if (lastUpdate != null) |
72 | |
{ |
73 | 0 | if (lastUpdate.after(updated) || lastUpdate.equals(updated)) |
74 | |
{ |
75 | 0 | if (logger.isDebugEnabled()) |
76 | |
{ |
77 | 0 | logger.debug("Feed update is not newer than the last update, not processing"); |
78 | |
} |
79 | 0 | return false; |
80 | |
} |
81 | |
} |
82 | 0 | lastUpdate = updated; |
83 | 0 | return true; |
84 | |
} |
85 | |
|
86 | |
public boolean isAcceptWithoutUpdateDate() |
87 | |
{ |
88 | 0 | return acceptWithoutUpdateDate; |
89 | |
} |
90 | |
|
91 | |
public void setAcceptWithoutUpdateDate(boolean acceptWithoutUpdateDate) |
92 | |
{ |
93 | 0 | this.acceptWithoutUpdateDate = acceptWithoutUpdateDate; |
94 | 0 | } |
95 | |
|
96 | |
public Date getLastUpdate() |
97 | |
{ |
98 | 0 | return lastUpdate; |
99 | |
} |
100 | |
|
101 | |
public void setLastUpdate(Date lastUpdate) |
102 | |
{ |
103 | 0 | this.lastUpdate = lastUpdate; |
104 | 0 | } |
105 | |
} |