| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
|
| 17 | |
|
| 18 | |
package org.apache.shindig.social.core.util.atom; |
| 19 | |
|
| 20 | |
import org.apache.shindig.social.opensocial.spi.DataCollection; |
| 21 | |
import org.apache.shindig.social.opensocial.spi.RestfulCollection; |
| 22 | |
|
| 23 | |
import java.util.ArrayList; |
| 24 | |
import java.util.Collection; |
| 25 | |
import java.util.List; |
| 26 | |
import java.util.Map; |
| 27 | |
import java.util.Map.Entry; |
| 28 | |
|
| 29 | |
|
| 30 | |
|
| 31 | |
|
| 32 | |
public class AtomFeed { |
| 33 | |
|
| 34 | |
@SuppressWarnings("unchecked") |
| 35 | |
private Collection entry; |
| 36 | |
@SuppressWarnings("unused") |
| 37 | |
private int startIndex; |
| 38 | |
@SuppressWarnings("unused") |
| 39 | |
private int totalResults; |
| 40 | |
@SuppressWarnings("unused") |
| 41 | |
private int itemsPerPage; |
| 42 | |
@SuppressWarnings("unused") |
| 43 | |
private String author; |
| 44 | |
@SuppressWarnings("unused") |
| 45 | |
private AtomLink link; |
| 46 | |
|
| 47 | |
|
| 48 | |
|
| 49 | |
|
| 50 | |
@SuppressWarnings("unchecked") |
| 51 | 8 | public AtomFeed(Object obj) { |
| 52 | 8 | if (obj instanceof Map) { |
| 53 | 2 | Map<?, ?> m = (Map<?, ?>) obj; |
| 54 | 2 | entry = new ArrayList(); |
| 55 | 2 | for ( Entry<?, ?> o : m.entrySet()) { |
| 56 | 4 | entry.add(new AtomEntry(o)); |
| 57 | 4 | } |
| 58 | 2 | startIndex = 0; |
| 59 | 2 | totalResults = entry.size(); |
| 60 | 2 | itemsPerPage = entry.size(); |
| 61 | 2 | } else if (obj instanceof RestfulCollection<?>) { |
| 62 | 0 | RestfulCollection<?> r = (RestfulCollection<?>) obj; |
| 63 | 0 | entry = new ArrayList(); |
| 64 | 0 | List<?> entryList = r.getEntry(); |
| 65 | 0 | for (Object o : entryList) { |
| 66 | 0 | entry.add(new AtomEntry(o)); |
| 67 | 0 | } |
| 68 | 0 | startIndex = r.getStartIndex(); |
| 69 | 0 | totalResults = r.getTotalResults(); |
| 70 | 0 | itemsPerPage = entryList.size(); |
| 71 | 0 | author = "?"; |
| 72 | 0 | link = new AtomLink("rel", "???"); |
| 73 | 0 | } else if ( obj instanceof DataCollection ) { |
| 74 | 0 | DataCollection dc = (DataCollection) obj; |
| 75 | 0 | entry = new ArrayList(); |
| 76 | 0 | for ( Entry<String, Map<String,String>> o : dc.getEntry().entrySet()) { |
| 77 | 0 | entry.add(new AtomEntry(o)); |
| 78 | 0 | } |
| 79 | 0 | startIndex = 0; |
| 80 | 0 | totalResults = entry.size(); |
| 81 | 0 | itemsPerPage = entry.size(); |
| 82 | 0 | } else { |
| 83 | 6 | entry = new ArrayList(); |
| 84 | 6 | entry.add(new AtomEntry(obj)); |
| 85 | 6 | startIndex = 0; |
| 86 | 6 | totalResults = 1; |
| 87 | 6 | itemsPerPage = 1; |
| 88 | |
} |
| 89 | 8 | } |
| 90 | |
|
| 91 | |
} |