KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jahia > clipbuilder > html > util > HashUtilities


1 package org.jahia.clipbuilder.html.util;
2
3 /**
4  * Hash builder
5  *
6  *@author Tlili Khaled
7  */

8 public class HashUtilities {
9     private static org.apache.log4j.Logger logger = org.apache.log4j.Logger.getLogger(HashUtilities.class);
10
11
12     /**
13      * Gets the FormNameFromHash attribute of the HashUtilities class
14      *
15      *@param formHash Description of Parameter
16      *@return The FormNameFromHash value
17      */

18     public static String JavaDoc getFormNameFromHash(String JavaDoc formHash) {
19         int index = formHash.indexOf(":");
20         if (index < 0) {
21             return null;
22         }
23         else {
24             return formHash.substring(0, index);
25         }
26
27     }
28
29
30     /**
31      * Gets the FormPositionFromHash attribute of the HashUtilities class
32      *
33      *@param formHash Description of Parameter
34      *@return The FormPositionFromHash value
35      */

36     public static String JavaDoc getFormPositionFromHash(String JavaDoc formHash) {
37         int index = formHash.indexOf(":");
38         if (index < 0) {
39             return formHash;
40         }
41         else {
42             return null;
43         }
44
45     }
46
47
48
49     /**
50      * Gets the FormIdFromHash attribute of the HashUtilities class
51      *
52      *@param formHash Description of Parameter
53      *@return The FormIdFromHash value
54      */

55     public static String JavaDoc getFormIdFromHash(String JavaDoc formHash) {
56         int index = formHash.indexOf(":");
57         if (index < 0) {
58             return null;
59         }
60         else {
61             return formHash.substring(index + 1);
62         }
63
64     }
65
66
67
68     /**
69      * Gets the LinkHash attribute of the HashUtilities object
70      *
71      *@param sourceUrl Description of Parameter
72      *@param id Description of Parameter
73      *@param position Description of Parameter
74      *@return The LinkHash value
75      */

76     public static String JavaDoc buildLinkHash(String JavaDoc sourceUrl, String JavaDoc id, String JavaDoc position) {
77         logger.debug("[ build hash parameter ]");
78         if (id != null && !id.equalsIgnoreCase("")) {
79             return id;
80         }
81         // Split the path and the query part
82
String JavaDoc[] splitQuery = URLUtilities.splitQuery(sourceUrl);
83         // Encode the path
84
String JavaDoc path = splitQuery[0];
85         String JavaDoc originalQuery = splitQuery[1];
86
87         String JavaDoc hash = position + ":" + path;
88         if (!originalQuery.equals("")) {
89             String JavaDoc params[] = originalQuery.split("=");
90             for (int i = 0; i < params.length; i = i + 2) {
91                 hash = hash + ":" + params[i];
92             }
93
94         }
95         logger.debug("hash is: " + hash);
96         return URLUtilities.encode(hash);
97     }
98
99
100     /**
101      * Description of the Method
102      *
103      *@param sourceUrl Description of Parameter
104      *@return Description of the Returned Value
105      */

106     public static String JavaDoc buildManulUrlHash(String JavaDoc sourceUrl) {
107         logger.debug("[ build hash parameter ]");
108         return sourceUrl;
109     }
110
111
112
113     /**
114      * Description of the Method
115      *
116      *@param position Description of Parameter
117      *@return Description of the Returned Value
118      */

119     public static String JavaDoc buildJavascriptLocationHash(String JavaDoc position) {
120         return position;
121     }
122
123
124     /**
125      * Description of the Method
126      *
127      *@param id Description of Parameter
128      *@param position Description of Parameter
129      *@return Description of the Returned Value
130      */

131     public static String JavaDoc buildTagHash(String JavaDoc id, int position) {
132         if (id == null || id.equalsIgnoreCase("")) {
133             return "" + position;
134         }
135         else {
136             return id;
137         }
138     }
139
140
141     /**
142      * Description of the Method
143      *
144      *@param name Description of Parameter
145      *@param id Description of Parameter
146      *@param src Description of Parameter
147      *@return Description of the Returned Value
148      */

149     public static String JavaDoc buildFrameHash(String JavaDoc name, String JavaDoc id, String JavaDoc src) {
150         if (name == null) {
151             name = "";
152         }
153         if (id == null) {
154             id = "";
155         }
156         if (src == null) {
157             src = "";
158         }
159         return name + ":" + id;
160     }
161
162
163
164     /**
165      * Gets the FormHash attribute of the HashUtilities class
166      *
167      *@param formName Description of Parameter
168      *@param formId Description of Parameter
169      *@param position Description of Parameter
170      *@return The FormHash value
171      */

172     public static String JavaDoc buildFormHash(String JavaDoc formName, String JavaDoc formId, int position) {
173         /*
174          * if(formId != null && !formId.equalsIgnoreCase("")){
175          * return formId;
176          * }
177          */

178         if (formName == null || formName.equalsIgnoreCase("")) {
179             if (formId == null || formId.equalsIgnoreCase("")) {
180                 return "" + position;
181             }
182         }
183         return formName + ":" + formId;
184     }
185
186 }
187
Popular Tags