KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > nextime > ion > frontoffice > objectSelector > ListOnlinePublications


1 /*
2  * ĻON content management system.
3  * Copyright (C) 2002 Guillaume Bort(gbort@msn.com). All rights reserved.
4  *
5  * Copyright (c) 2000 The Apache Software Foundation. All rights reserved.
6  * Copyright 2000-2002 (C) Intalio Inc. All Rights Reserved.
7  *
8  * ĻON is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License
10  * as published by the Free Software Foundation; either version 2
11  * of the License, or (at your option) any later version.
12  *
13  * ĻON core framework, ĻON content server, ĻON backoffice, ĻON frontoffice
14  * and ĻON admin application are parts of ĻON and are distributed under
15  * same terms of licence.
16  *
17  *
18  * ĻON includes software developed by the Apache Software Foundation (http://www.apache.org/)
19  * and software developed by the Exolab Project (http://www.exolab.org).
20  *
21  * ĻON is distributed in the hope that it will be useful,
22  * but WITHOUT ANY WARRANTY; without even the implied warranty of
23  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24  * GNU General Public License for more details.
25  */

26
27 package org.nextime.ion.frontoffice.objectSelector;
28
29 import java.util.Collection JavaDoc;
30 import java.util.Hashtable JavaDoc;
31 import java.util.Vector JavaDoc;
32
33 import javax.servlet.http.HttpServletRequest JavaDoc;
34 import javax.servlet.http.HttpServletResponse JavaDoc;
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 JavaDoc;
48
49 /**
50  */

51 public class ListOnlinePublications implements ObjectSelector {
52
53     public Collection JavaDoc selectObjects(
54         Hashtable JavaDoc params,
55         HttpServletRequest JavaDoc request,
56         HttpServletResponse JavaDoc response)
57         throws SelectException {
58         try {
59             String JavaDoc section = (String JavaDoc) params.get("section");
60             String JavaDoc view = (String JavaDoc) params.get("view");
61             int max = Integer.parseInt((String JavaDoc) params.get("max"));
62             String JavaDoc condition = (String JavaDoc) params.get("condition");
63
64             String JavaDoc currentLocale =
65                 request.getSession().getAttribute("currentLocale") + "";
66
67             Vector JavaDoc v =
68                 PublicationSorter.sortPublications(
69                     Section.getInstance(section));
70             Vector JavaDoc v2 = new Vector JavaDoc();
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 JavaDoc 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 JavaDoc(
96                                     Viewer.getView(
97                                         p,
98                                         version,
99                                         view,
100                                         currentLocale)));
101                         }
102                         v2.add(r);
103                     }
104                 }
105             }
106             //Mapping.rollback();
107
return v2;
108         } catch (Exception JavaDoc e) {
109             Logger.getInstance().error("Erreur du SelectObject", this, e);
110             throw new SelectException(e.getMessage());
111         }
112     }
113
114 }
Popular Tags