KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > infoglue > deliver > taglib > structure > SortPagesTag


1 /* ===============================================================================
2 *
3 * Part of the InfoGlue Content Management Platform (www.infoglue.org)
4 *
5 * ===============================================================================
6 *
7 * Copyright (C)
8 *
9 * This program is free software; you can redistribute it and/or modify it under
10 * the terms of the GNU General Public License version 2, as published by the
11 * Free Software Foundation. See the file LICENSE.html for more information.
12 *
13 * This program is distributed in the hope that it will be useful, but WITHOUT
14 * ANY WARRANTY, including the implied warranty of MERCHANTABILITY or FITNESS
15 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License along with
18 * this program; if not, write to the Free Software Foundation, Inc. / 59 Temple
19 * Place, Suite 330 / Boston, MA 02111-1307 / USA.
20 *
21 * ===============================================================================
22 */

23
24 package org.infoglue.deliver.taglib.structure;
25
26 import java.util.ArrayList JavaDoc;
27 import java.util.Collections JavaDoc;
28 import java.util.Comparator JavaDoc;
29 import java.util.List JavaDoc;
30
31 import javax.servlet.jsp.JspException JavaDoc;
32
33 import org.infoglue.cms.util.sorters.HardcodedPageComparator;
34 import org.infoglue.cms.util.sorters.PageComparator;
35 import org.infoglue.deliver.taglib.TemplateControllerTag;
36
37 public class SortPagesTag extends TemplateControllerTag
38 {
39     private static final long serialVersionUID = 3257003254859576632L;
40
41     private Comparator JavaDoc comparator;
42     
43     private List JavaDoc input = new ArrayList JavaDoc();
44     
45     private String JavaDoc sortProperty = "NavigationTitle";
46     private String JavaDoc nameProperty = "NavigationTitle";
47     private String JavaDoc sortOrder = "asc";
48     private boolean numberOrder = false;
49     private String JavaDoc type = "PageComparator";
50     private String JavaDoc namesInOrderString = null;
51     
52     /**
53      *
54      */

55     public SortPagesTag()
56     {
57         super();
58     }
59     
60     /**
61      *
62      */

63     public int doEndTag() throws JspException JavaDoc
64     {
65         if(this.type.equalsIgnoreCase("HardcodedPageComparator") || namesInOrderString != null)
66             this.comparator = new HardcodedPageComparator(sortProperty, sortOrder, numberOrder, nameProperty, namesInOrderString, getController());
67         else
68             this.comparator = new PageComparator(sortProperty, sortOrder, numberOrder, getController());
69             
70         Collections.sort(input, comparator);
71         produceResult(input);
72         return EVAL_PAGE;
73     }
74     
75     /**
76      *
77      */

78     public void setInput(final String JavaDoc input) throws JspException JavaDoc
79     {
80         this.input = evaluateList("contentSort", "input", input);
81     }
82
83     /**
84      *
85      */

86     public void setSortProperty(final String JavaDoc sortProperty) throws JspException JavaDoc
87     {
88         this.sortProperty = evaluateString("contentSort", "sortProperty", sortProperty);
89     }
90
91
92     /**
93      *
94      */

95     public void setSortOrder(final String JavaDoc sortOrder) throws JspException JavaDoc
96     {
97         this.sortOrder = evaluateString("contentSort", "sortOrder", sortOrder);
98     }
99
100     /**
101      *
102      */

103     public void setType(final String JavaDoc type) throws JspException JavaDoc
104     {
105         this.type = type;
106     }
107
108     public void setNamesInOrderString(final String JavaDoc namesInOrderString) throws JspException JavaDoc
109     {
110         this.namesInOrderString = namesInOrderString;
111     }
112     
113     public void setNumberOrder(boolean numberOrder)
114     {
115         this.numberOrder = numberOrder;
116     }
117 }
118
Popular Tags