Advertisement
Guest User

Untitled

a guest
Jan 26th, 2015
160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.22 KB | None | 0 0
  1.     // doGet, eller varifrån du tidigare antopare getChangesXML
  2.     public void doGet() throws JAXBException {
  3.         List<Weblog> recentBlogs = getRecentWeblogs(weblogs, 5);
  4.         String xml = getChangesXML(recentBlogs);
  5.     }
  6.  
  7.     private List<Weblog> getRecentWeblogs(List<Weblog> weblogs, int minutes) {
  8.         Date maxAge = new Date(System.currentTimeMillis() - 1000 * 60 * minutes);
  9.         return weblogs.stream()
  10.                 .filter(x -> x.getWhen().after(maxAge))
  11.                 .collect(toList());
  12.     }
  13.  
  14.     public String getChangesXML(List<Weblog> weblogs) throws JAXBException {
  15.         WeblogUpdates weblogUpdates = new WeblogUpdates(weblogs, new Date());
  16.  
  17.         StringWriter sw = new StringWriter();
  18.         Marshaller marshaller = createMarshaller(WeblogUpdates.class);
  19.         marshaller.marshal(weblogUpdates, sw);
  20.  
  21.         return sw.toString();
  22.     }
  23.  
  24.     private static Marshaller createMarshaller(Class<WeblogUpdates> klass) throws JAXBException {
  25.         JAXBContext jaxbContext = JAXBContext.newInstance(klass);
  26.         Marshaller marshaller = jaxbContext.createMarshaller();
  27.         marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
  28.  
  29.         return marshaller;
  30.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement