KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > opencms > defaults > A_CmsNavBase


1 /*
2 * File : $Source: /usr/local/cvs/opencms/src-modules/com/opencms/defaults/A_CmsNavBase.java,v $
3 * Date : $Date: 2005/06/27 23:22:23 $
4 * Version: $Revision: 1.2 $
5 *
6 * This library is part of OpenCms -
7 * the Open Source Content Mananagement System
8 *
9 * Copyright (C) 2001 The OpenCms Group
10 *
11 * This library is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU Lesser General Public
13 * License as published by the Free Software Foundation; either
14 * version 2.1 of the License, or (at your option) any later version.
15 *
16 * This library is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * Lesser General Public License for more details.
20 *
21 * For further information about OpenCms, please see the
22 * OpenCms Website: http://www.opencms.org
23 *
24 * You should have received a copy of the GNU Lesser General Public
25 * License along with this library; if not, write to the Free Software
26 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
27 */

28
29 package com.opencms.defaults;
30
31 import org.opencms.file.CmsObject;
32 import org.opencms.main.CmsException;
33
34 import com.opencms.template.A_CmsXmlContent;
35 import com.opencms.template.CmsXmlTemplate;
36
37 import java.util.Hashtable JavaDoc;
38
39 /**
40  * This abstract class builds the default Navigation.
41  *
42  * @author Alexander Kandzior
43  * @author Waruschan Babachan
44  * @version $Revision: 1.2 $ $Date: 2005/06/27 23:22:23 $
45  *
46  * @deprecated Will not be supported past the OpenCms 6 release.
47  */

48 public abstract class A_CmsNavBase extends CmsXmlTemplate {
49     protected static final String JavaDoc C_PROPERTY_NAVINDEX = "NavIndex";
50     protected static final String JavaDoc C_NAVINDEX = "index.html";
51
52     /**
53      * Indicates if the results of this class are cacheable.
54      *
55      * @param cms CmsObject Object for accessing system resources
56      * @param templateFile Filename of the template file
57      * @param elementName Element name of this template in our parent template.
58      * @param parameters Hashtable with all template class parameters.
59      * @param templateSelector template section that should be processed.
60      * @return <EM>true</EM> if cacheable, <EM>false</EM> otherwise.
61      */

62     public boolean isCacheable(CmsObject cms, String JavaDoc templateFile, String JavaDoc elementName, Hashtable JavaDoc parameters, String JavaDoc templateSelector) {
63         return true;
64     }
65
66     /**
67      * gets the current folder.
68      *
69      * @param cms CmsObject Object for accessing system resources.
70      * @param tagcontent Unused in this special case of a user method. Can be ignored.
71      * @param doc Reference to the A_CmsXmlContent object of the initiating XLM document.
72      * @param userObject Hashtable with parameters.
73      * @return byte[] with the content of this subelement.
74      * @throws CmsException if something goes wrong
75      */

76     protected abstract Object JavaDoc getFolderCurrent(CmsObject cms, String JavaDoc tagcontent, A_CmsXmlContent doc, Object JavaDoc userObject) throws CmsException;
77
78     /**
79      * gets the parent folder.
80      *
81      * @param cms CmsObject Object for accessing system resources.
82      * @param tagcontent Unused in this special case of a user method. Can be ignored.
83      * @param doc Reference to the A_CmsXmlContent object of the initiating XLM document.
84      * @param userObject Hashtable with parameters.
85      * @return byte[] with the content of this subelement.
86      * @throws CmsException if something goes wrong
87      */

88     protected abstract Object JavaDoc getFolderParent(CmsObject cms, String JavaDoc tagcontent, A_CmsXmlContent doc, Object JavaDoc userObject) throws CmsException;
89
90     /**
91      * gets the root folder.
92      *
93      * @param cms CmsObject Object for accessing system resources.
94      * @param tagcontent Unused in this special case of a user method. Can be ignored.
95      * @param doc Reference to the A_CmsXmlContent object of the initiating XLM document.
96      * @param userObject Hashtable with parameters.
97      * @return byte[] with the content of this subelement.
98      * @throws CmsException if something goes wrong
99      */

100     protected abstract Object JavaDoc getFolderRoot(CmsObject cms, String JavaDoc tagcontent, A_CmsXmlContent doc, Object JavaDoc userObject) throws CmsException;
101
102     /**
103      * gets the navigation of current folder.
104      *
105      * @param cms CmsObject Object for accessing system resources.
106      * @param tagcontent Unused in this special case of a user method. Can be ignored.
107      * @param doc Reference to the A_CmsXmlContent object of the initiating XLM document.
108      * @param userObject Hashtable with parameters.
109      * @return byte[] with the content of this subelement.
110      * @throws CmsException if something goes wrong
111      */

112     protected abstract Object JavaDoc getNavCurrent(CmsObject cms, String JavaDoc tagcontent, A_CmsXmlContent doc, Object JavaDoc userObject) throws CmsException;
113
114     /**
115      * gets the navigation of files and folders,
116      * by folders it is showed closed, if the folder is clicked then it is opened.
117      *
118      * @param cms CmsObject Object for accessing system resources.
119      * @param tagcontent Unused in this special case of a user method. Can be ignored.
120      * @param doc Reference to the A_CmsXmlContent object of the initiating XLM document.
121      * @param userObject Hashtable with parameters.
122      * @return byte[] with the content of this subelement.
123      * @throws CmsException if something goes wrong
124      */

125     protected abstract Object JavaDoc getNavFold(CmsObject cms, String JavaDoc tagcontent, A_CmsXmlContent doc, Object JavaDoc userObject) throws CmsException;
126
127     /**
128      * gets the navigation of specified level of parent folder.
129      *
130      * @param cms CmsObject Object for accessing system resources.
131      * @param tagcontent Unused in this special case of a user method. Can be ignored.
132      * @param doc Reference to the A_CmsXmlContent object of the initiating XLM document.
133      * @param userObject Hashtable with parameters.
134      * @return byte[] with the content of this subelement.
135      * @throws CmsException if something goes wrong
136      */

137     protected abstract Object JavaDoc getNavParent(CmsObject cms, String JavaDoc tagcontent, A_CmsXmlContent doc, Object JavaDoc userObject) throws CmsException;
138
139     /**
140      * gets the navigation of root folder or parent folder starting from root folder.
141      *
142      * @param cms CmsObject Object for accessing system resources.
143      * @param tagcontent Unused in this special case of a user method. Can be ignored.
144      * @param doc Reference to the A_CmsXmlContent object of the initiating XLM document.
145      * @param userObject Hashtable with parameters.
146      * @return byte[] with the content of this subelement.
147      * @throws CmsException if something goes wrong
148      */

149     protected abstract Object JavaDoc getNavRoot(CmsObject cms, String JavaDoc tagcontent, A_CmsXmlContent doc, Object JavaDoc userObject) throws CmsException;
150
151     /**
152      * gets the navigation of folders recursive.
153      *
154      * @param cms CmsObject Object for accessing system resources.
155      * @param tagcontent Unused in this special case of a user method. Can be ignored.
156      * @param doc Reference to the A_CmsXmlContent object of the initiating XLM document.
157      * @param userObject Hashtable with parameters.
158      * @return byte[] with the content of this subelement.
159      * @throws CmsException if something goes wrong
160      */

161     protected abstract Object JavaDoc getNavTree(CmsObject cms, String JavaDoc tagcontent, A_CmsXmlContent doc, Object JavaDoc userObject) throws CmsException;
162
163     /**
164      * gets a specified property of current folder.
165      *
166      * @param cms A_CmsObject Object for accessing system resources.
167      * @param tagcontent Unused in this special case of a user method. Can be ignored.
168      * @param doc Reference to the A_CmsXmlContent object of the initiating XLM document.
169      * @param userObject Hashtable with parameters.
170      * @return byte[] with the content of this subelement.
171      * @throws CmsException if something goes wrong
172      */

173     protected abstract Object JavaDoc getPropertyCurrent(CmsObject cms, String JavaDoc tagcontent, A_CmsXmlContent doc, Object JavaDoc userObject)
174             throws CmsException;
175
176     /**
177      * gets a specified property of specified folder starting from current folder.
178      *
179      * @param cms A_CmsObject Object for accessing system resources.
180      * @param tagcontent Unused in this special case of a user method. Can be ignored.
181      * @param doc Reference to the A_CmsXmlContent object of the initiating XLM document.
182      * @param userObject Hashtable with parameters.
183      * @return byte[] with the content of this subelement.
184      * @throws CmsException if something goes wrong
185      */

186     protected abstract Object JavaDoc getPropertyParent(CmsObject cms, String JavaDoc tagcontent, A_CmsXmlContent doc, Object JavaDoc userObject)
187             throws CmsException;
188
189     /**
190      * gets a specified property of specified folder starting from root.
191      *
192      * @param cms A_CmsObject Object for accessing system resources.
193      * @param tagcontent Unused in this special case of a user method. Can be ignored.
194      * @param doc Reference to the A_CmsXmlContent object of the initiating XLM document.
195      * @param userObject Hashtable with parameters.
196      * @return byte[] with the content of this subelement.
197      * @throws CmsException if something goes wrong
198      */

199     protected abstract Object JavaDoc getPropertyRoot(CmsObject cms, String JavaDoc tagcontent, A_CmsXmlContent doc, Object JavaDoc userObject)
200             throws CmsException;
201
202
203     /**
204      * gets a specified property of uri.
205      *
206      * @param cms A_CmsObject Object for accessing system resources.
207      * @param tagcontent Unused in this special case of a user method. Can be ignored.
208      * @param doc Reference to the A_CmsXmlContent object of the initiating XLM document.
209      * @param userObject Hashtable with parameters.
210      * @return byte[] with the content of this subelement.
211      * @throws CmsException if something goes wrong
212      */

213     protected abstract Object JavaDoc getPropertyUri(CmsObject cms, String JavaDoc tagcontent, A_CmsXmlContent doc, Object JavaDoc userObject)
214             throws CmsException;
215
216     /**
217      * This method sorts the left and right side of unsorted partition.<p>
218      *
219      * @param left the left side of boundery in an array
220      * @param right the right side of boundery in an array
221      * @param pivot the pivot element
222      * @param navLink Array of link path
223      * @param navText Array of navigation text
224      * @param navPos Array of navigation position
225      * @return the next pivot
226      */

227     private int partitionIt(int left, int right, float pivot, String JavaDoc[] navLink, String JavaDoc[] navText, float[] navPos) {
228
229         // left (after ++)
230
int leftPtr = left - 1;
231
232         // right-1 (after --)
233
int rightPtr = right;
234         while (true) {
235
236             // find bigger item
237
// nop
238
while (navPos[++leftPtr] < pivot) {
239             }
240
241             // find smaller item
242
// nop
243
while (rightPtr > 0 && navPos[--rightPtr] > pivot) {
244             }
245
246             // if pointers cross, partition done
247
// if pointers are not crossed, swap elements
248
if (leftPtr >= rightPtr) {
249                 break;
250             } else {
251                 swap(leftPtr, rightPtr, navLink, navText, navPos);
252             }
253         }
254
255         // restore pivot
256
swap(leftPtr, right, navLink, navText, navPos);
257
258         // return pivot location
259
return leftPtr;
260     }
261
262     /**
263      * Sorts the navigation according to Quicksort method.
264      *
265      * @param left the left side of boundery in an array.
266      * @param right the right side of boundery in an array.
267      * @param navLink Array of link path.
268      * @param navText Array of navigation text.
269      * @param navPos Array of navigation position.
270      */

271     private void quickSort(int left, int right, String JavaDoc[] navLink, String JavaDoc[] navText, float[] navPos) {
272         if (right - left <= 0) {
273             return;
274         } else {
275
276             // rightmost item partition range
277
float pivot = navPos[right];
278             int partition = partitionIt(left, right, pivot, navLink, navText, navPos);
279
280             // sort left side
281
quickSort(left, partition - 1, navLink, navText, navPos);
282
283             // sort right side
284
quickSort(partition + 1, right, navLink, navText, navPos);
285         }
286     }
287
288     /**
289      * Sorts the navigation.
290      *
291      * @param size the size of array to be sorted.
292      * @param navLink Array of link path.
293      * @param navText Array of navigation text.
294      * @param navPos Array of navigation position.
295      */

296     protected void sortNav(int size, String JavaDoc[] navLink, String JavaDoc[] navText, float[] navPos) {
297         quickSort(0, size - 1, navLink, navText, navPos);
298     }
299
300     /**
301      * Swapping the elements.<p>
302      *
303      * @param dex1 first index
304      * @param dex2 second index
305      * @param navLink array of nav links
306      * @param navText array of nav texts
307      * @param navPos array of nav positions
308      */

309     private void swap(int dex1, int dex2, String JavaDoc[] navLink, String JavaDoc[] navText, float[] navPos) {
310
311         // swap positions
312
float navPosTemp = navPos[dex1];
313         navPos[dex1] = navPos[dex2];
314         navPos[dex2] = navPosTemp;
315
316         // swap titles
317
String JavaDoc navTextTemp = navText[dex1];
318         navText[dex1] = navText[dex2];
319         navText[dex2] = navTextTemp;
320
321         // swap foldername
322
String JavaDoc navLinkTemp = navLink[dex1];
323         navLink[dex1] = navLink[dex2];
324         navLink[dex2] = navLinkTemp;
325     }
326 }
327
Popular Tags