package org.xapek.yvesf.classifieds import groovy.xml.MarkupBuilder import org.xapek.yvesf.classifieds.Model.Classified import org.xapek.yvesf.classifieds.Model.ClassifiedsList class Dumper { static dump(ClassifiedsList classifiedList, PrintWriter writer) { new MarkupBuilder(writer).rss(version: '2.0', 'xmlns:atom': 'http://www.w3.org/2005/Atom') { channel { title('Glocals Classifieds Feed') description('glocal classifieds feed') link('https://www.xapek.org/git/yvesf/classifieds') classifiedList.each { Classified classified -> item { title("${classified.type} - ${classified.title} - ${classified.composedLocation}") guid(classified.link) link(classified.link) pubDate(classified.formattedDate) author("${classified.mem_id}@noemail.local (${classified.mem_name})") description(getDescription(classified) + classified.description) } } } } } static String getDescription(Classified classified) { final descriptionOs = new ByteArrayOutputStream() final description = new MarkupBuilder(new PrintWriter(descriptionOs)) description.table { tr { th('Price') td("${classified.price} ${classified.currency}") } tr { th('Views') td(classified.views) } tr { th('Available') td(classified.available) } tr { th('Rooms') td(classified.rooms) } tr { th('Member') td { a(classified.mem_name, referrerpolicy: 'no-referrer', href: classified.memberProfileLink) } } if (classified.images) { tr { th('Images') td { classified.images.eachWithIndex { String url, Integer i -> a("Photo ${i + 1}", referrerpolicy: 'no-referrer', href: url) } } } } br() } return descriptionOs.toString() } }