Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // doGet, eller varifrån du tidigare antopare getChangesXML
- public void doGet() throws JAXBException {
- List<Weblog> recentBlogs = getRecentWeblogs(weblogs, 5);
- String xml = getChangesXML(recentBlogs);
- }
- private List<Weblog> getRecentWeblogs(List<Weblog> weblogs, int minutes) {
- Date maxAge = new Date(System.currentTimeMillis() - 1000 * 60 * minutes);
- return weblogs.stream()
- .filter(x -> x.getWhen().after(maxAge))
- .collect(toList());
- }
- public String getChangesXML(List<Weblog> weblogs) throws JAXBException {
- WeblogUpdates weblogUpdates = new WeblogUpdates(weblogs, new Date());
- StringWriter sw = new StringWriter();
- Marshaller marshaller = createMarshaller(WeblogUpdates.class);
- marshaller.marshal(weblogUpdates, sw);
- return sw.toString();
- }
- private static Marshaller createMarshaller(Class<WeblogUpdates> klass) throws JAXBException {
- JAXBContext jaxbContext = JAXBContext.newInstance(klass);
- Marshaller marshaller = jaxbContext.createMarshaller();
- marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
- return marshaller;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement