1 26 27 package org.nextime.ion.frontoffice.objectSelector; 28 29 import java.util.Collection ; 30 import java.util.Hashtable ; 31 import java.util.Vector ; 32 33 import javax.servlet.http.HttpServletRequest ; 34 import javax.servlet.http.HttpServletResponse ; 35 36 import org.apache.xpath.XPathAPI; 37 import org.apache.xpath.objects.XObject; 38 import org.jdom.output.DOMOutputter; 39 import org.nextime.ion.common.IsOnline; 40 import org.nextime.ion.commons.PublicationSorter; 41 42 import org.nextime.ion.framework.business.Publication; 43 import org.nextime.ion.framework.business.Section; 44 import org.nextime.ion.framework.business.impl.PublicationVersionImpl; 45 import org.nextime.ion.framework.helper.Viewer; 46 import org.nextime.ion.framework.logger.Logger; 47 import org.w3c.dom.Document ; 48 49 51 public class ListOnlinePublications implements ObjectSelector { 52 53 public Collection selectObjects( 54 Hashtable params, 55 HttpServletRequest request, 56 HttpServletResponse response) 57 throws SelectException { 58 try { 59 String section = (String ) params.get("section"); 60 String view = (String ) params.get("view"); 61 int max = Integer.parseInt((String ) params.get("max")); 62 String condition = (String ) params.get("condition"); 63 64 String currentLocale = 65 request.getSession().getAttribute("currentLocale") + ""; 66 67 Vector v = 68 PublicationSorter.sortPublications( 69 Section.getInstance(section)); 70 Vector v2 = new Vector (); 71 int nb = 0; 72 for (int i = 0;(i < v.size() && nb < max); i++) { 73 Publication p = (Publication) v.get(i); 74 int version = IsOnline.getMostRecentVersion(p); 75 if (IsOnline.getStatus(p)) { 76 77 boolean conditionResult = true; 78 if (condition != null && !"".equals(condition)) { 79 Document doc = 80 new DOMOutputter().output( 81 ((PublicationVersionImpl) p 82 .getVersion(version)) 83 .getXmlDoc()); 84 XObject o = XPathAPI.eval(doc, condition); 85 conditionResult = o.bool(); 86 } 87 88 if (conditionResult) { 89 nb++; 90 PublicationResult r = new PublicationResult(); 91 r.setPublication(p); 92 r.setVersion(version); 93 if (view != null) { 94 r.setView( 95 new String ( 96 Viewer.getView( 97 p, 98 version, 99 view, 100 currentLocale))); 101 } 102 v2.add(r); 103 } 104 } 105 } 106 return v2; 108 } catch (Exception e) { 109 Logger.getInstance().error("Erreur du SelectObject", this, e); 110 throw new SelectException(e.getMessage()); 111 } 112 } 113 114 }
| Popular Tags
|