01: /******************************************************************************
02: * JBoss, a division of Red Hat *
03: * Copyright 2006, Red Hat Middleware, LLC, and individual *
04: * contributors as indicated by the @authors tag. See the *
05: * copyright.txt in the distribution for a full listing of *
06: * individual contributors. *
07: * *
08: * This is free software; you can redistribute it and/or modify it *
09: * under the terms of the GNU Lesser General Public License as *
10: * published by the Free Software Foundation; either version 2.1 of *
11: * the License, or (at your option) any later version. *
12: * *
13: * This software is distributed in the hope that it will be useful, *
14: * but WITHOUT ANY WARRANTY; without even the implied warranty of *
15: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
16: * Lesser General Public License for more details. *
17: * *
18: * You should have received a copy of the GNU Lesser General Public *
19: * License along with this software; if not, write to the Free *
20: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
21: * 02110-1301 USA, or see the FSF site: http://www.fsf.org. *
22: ******************************************************************************/package org.jboss.portal.theme;
23:
24: /**
25: * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
26: * @version $Revision: 8784 $
27: */
28: public class ThemeTools {
29:
30: /**
31: * Compare 2 windows.
32: *
33: * @param orderString1
34: * @param id1
35: * @param orderString2
36: * @param id2
37: * @return
38: */
39: public static int compareWindowOrder(String orderString1,
40: String id1, String orderString2, String id2) {
41: if (id1 == null) {
42: throw new IllegalArgumentException(
43: "No null window id accepted for window 1");
44: }
45: if (id2 == null) {
46: throw new IllegalArgumentException(
47: "No null window id accepted for window 2");
48: }
49:
50: //
51: if (orderString1 == null) {
52: orderString1 = "";
53: }
54: if (orderString2 == null) {
55: orderString1 = "";
56: }
57:
58: int order1 = 0;
59: int order2 = 0;
60:
61: //
62: try {
63: order1 = Integer.parseInt(orderString1);
64:
65: //
66: try {
67: order2 = Integer.parseInt(orderString2);
68: } catch (NumberFormatException e) {
69: // We have window2>window1
70: order2 = order1 + 1;
71: }
72: } catch (NumberFormatException e1) {
73: try {
74: Integer.parseInt(orderString2);
75:
76: // We have order2=0 and order1=1 and thus window1>window2
77: order1 = 1;
78: } catch (NumberFormatException e2) {
79: // Orders have the same value of zero that will lead to the comparison of their ids
80: }
81: }
82:
83: // If order are the same we compare the window ids
84: if (order1 == order2) {
85: return orderString1.compareTo(orderString2);
86: } else {
87: return order1 - order2;
88: }
89: }
90: }
|