Coverage Report - org.kuali.rice.kns.lookup.HtmlData
 
Classes in this File Line Coverage Branch Coverage Complexity
HtmlData
0%
0/67
0%
0/20
1.44
HtmlData$AnchorHtmlData
0%
0/36
0%
0/6
1.44
HtmlData$InputHtmlData
0%
0/28
0%
0/8
1.44
HtmlData$MultipleAnchorHtmlData
0%
0/10
0%
0/4
1.44
 
 1  
 /*
 2  
  * Copyright 2007-2008 The Kuali Foundation
 3  
  *
 4  
  * Licensed under the Educational Community License, Version 2.0 (the "License");
 5  
  * you may not use this file except in compliance with the License.
 6  
  * You may obtain a copy of the License at
 7  
  *
 8  
  * http://www.opensource.org/licenses/ecl2.php
 9  
  *
 10  
  * Unless required by applicable law or agreed to in writing, software
 11  
  * distributed under the License is distributed on an "AS IS" BASIS,
 12  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 13  
  * See the License for the specific language governing permissions and
 14  
  * limitations under the License.
 15  
  */
 16  
 package org.kuali.rice.kns.lookup;
 17  
 
 18  
 import java.io.Serializable;
 19  
 import java.sql.Date;
 20  
 import java.util.HashMap;
 21  
 import java.util.Iterator;
 22  
 import java.util.List;
 23  
 import java.util.Map;
 24  
 
 25  
 import org.apache.commons.lang.StringUtils;
 26  
 import org.kuali.rice.core.web.format.DateFormatter;
 27  
 import org.kuali.rice.kns.authorization.BusinessObjectRestrictions;
 28  
 import org.kuali.rice.kns.authorization.FieldRestriction;
 29  
 import org.kuali.rice.kns.service.BusinessObjectAuthorizationService;
 30  
 import org.kuali.rice.kns.service.KNSServiceLocator;
 31  
 import org.kuali.rice.kns.service.KNSServiceLocatorWeb;
 32  
 import org.kuali.rice.kns.util.KNSConstants;
 33  
 import org.kuali.rice.kns.util.ObjectUtils;
 34  
 
 35  
 /**
 36  
  * This class holds details of html data for an action url.
 37  
  * 
 38  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 39  
  * 
 40  
  */
 41  0
 public abstract class HtmlData implements Serializable {
 42  
 
 43  0
         protected static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(HtmlData.class);
 44  
 
 45  0
         public static final String ANCHOR_HTML_DATA_TYPE = AnchorHtmlData.class.getName();
 46  0
         public static final String INPUT_HTML_DATA_TYPE = InputHtmlData.class.getName();
 47  
         
 48  0
         protected String name = "";
 49  0
         protected String title = "";
 50  0
         protected String methodToCall = "";
 51  0
         protected String displayText = "";
 52  0
         protected String prependDisplayText = "";
 53  0
         protected String appendDisplayText = "";
 54  
         protected List<HtmlData> childUrlDataList;
 55  
         protected String maxLength;
 56  
         
 57  
         /**
 58  
          * 
 59  
          * This method constructs the complete html tag based on the class attribute
 60  
          * values.
 61  
          * 
 62  
          * @return
 63  
          */
 64  
         public abstract String constructCompleteHtmlTag();
 65  
 
 66  
         /**
 67  
          * @return the appendDisplayText
 68  
          */
 69  
         public String getAppendDisplayText() {
 70  0
                 return this.appendDisplayText;
 71  
         }
 72  
 
 73  
         /**
 74  
          * @param appendDisplayText the appendDisplayText to set
 75  
          */
 76  
         public void setAppendDisplayText(String appendDisplayText) {
 77  0
                 this.appendDisplayText = appendDisplayText;
 78  0
         }
 79  
 
 80  
         /**
 81  
          * @return the childUrlDataList
 82  
          */
 83  
         public List<HtmlData> getChildUrlDataList() {
 84  0
                 return this.childUrlDataList;
 85  
         }
 86  
 
 87  
         /**
 88  
          * @param childUrlDataList the childUrlDataList to set
 89  
          */
 90  
         public void setChildUrlDataList(List<HtmlData> childUrlDataList) {
 91  0
                 this.childUrlDataList = childUrlDataList;
 92  0
         }
 93  
 
 94  
         /**
 95  
          * @return the prependDisplayText
 96  
          */
 97  
         public String getPrependDisplayText() {
 98  0
                 return this.prependDisplayText;
 99  
         }
 100  
 
 101  
         /**
 102  
          * @param prependDisplayText the prependDisplayText to set
 103  
          */
 104  
         public void setPrependDisplayText(String prependDisplayText) {
 105  0
                 this.prependDisplayText = prependDisplayText;
 106  0
         }
 107  
 
 108  
         /**
 109  
          * @return the title
 110  
          */
 111  
         public String getTitle() {
 112  0
                 return this.title;
 113  
         }
 114  
 
 115  
         /**
 116  
          * @param title the title to set
 117  
          */
 118  
         public void setTitle(String title) {
 119  0
                 this.title = title;
 120  0
         }
 121  
 
 122  
         /**
 123  
          * @return the name
 124  
          */
 125  
         public String getName() {
 126  0
                 return this.name;
 127  
         }
 128  
 
 129  
         /**
 130  
          * @param name the name to set
 131  
          */
 132  
         public void setName(String name) {
 133  0
                 this.name = name;
 134  0
         }
 135  
 
 136  
         /**
 137  
          * @return the displayText
 138  
          */
 139  
         public String getDisplayText() {
 140  0
                 return this.displayText;
 141  
         }
 142  
 
 143  
         /**
 144  
          * @param displayText the displayText to set
 145  
          */
 146  
         public void setDisplayText(String displayText) {
 147  0
                 this.displayText = displayText;
 148  0
         }
 149  
 
 150  
         /**
 151  
          * @return the methodToCall
 152  
          */
 153  
         public String getMethodToCall() {
 154  0
                 return this.methodToCall;
 155  
         }
 156  
 
 157  
         /**
 158  
          * @param methodToCall the methodToCall to set
 159  
          */
 160  
         public void setMethodToCall(String methodToCall) {
 161  0
                 this.methodToCall = methodToCall;
 162  0
         }
 163  
 
 164  
         public String getTitle(String prependText, Class bo, List keys) {
 165  0
                 return KNSConstants.EMPTY_STRING;
 166  
         }
 167  
 
 168  
         /**
 169  
          * KFSMI-658 This method gets the title text for a link/control
 170  
          * 
 171  
          * @param prependText
 172  
          * @param dataObject
 173  
          * @param fieldConversions
 174  
          * @param returnKeys
 175  
          * @return title text
 176  
          */
 177  
         public static String getTitleText(String prependText, Object dataObject, List<String> keys, BusinessObjectRestrictions businessObjectRestrictions) {
 178  0
                 if (dataObject == null)
 179  0
                         return KNSConstants.EMPTY_STRING;
 180  
 
 181  0
                 Map<String, String> keyValueMap = new HashMap<String, String>();
 182  0
                 Iterator keysIt = keys.iterator();
 183  0
                 while (keysIt.hasNext()) {
 184  0
                         String fieldNm = (String) keysIt.next();
 185  0
                         Object fieldVal = ObjectUtils.getPropertyValue(dataObject, fieldNm);
 186  
                         
 187  0
                         FieldRestriction fieldRestriction = null;
 188  0
                         if (businessObjectRestrictions != null) {
 189  0
                                 fieldRestriction = businessObjectRestrictions.getFieldRestriction(fieldNm);
 190  
                         }
 191  0
                         if (fieldRestriction != null && (fieldRestriction.isMasked() || fieldRestriction.isPartiallyMasked())) {
 192  0
                                 fieldVal = fieldRestriction.getMaskFormatter().maskValue(fieldVal);
 193  0
                         } else if (fieldVal == null) {
 194  0
                                 fieldVal = KNSConstants.EMPTY_STRING;
 195  0
                         } else if (fieldVal instanceof Date) {
 196  
                                 // need to format date in url
 197  0
                                 DateFormatter dateFormatter = new DateFormatter();
 198  0
                                 fieldVal = dateFormatter.format(fieldVal);
 199  
                         }
 200  0
                         keyValueMap.put(fieldNm, fieldVal.toString());
 201  0
                 }
 202  0
                 return getTitleText(prependText, dataObject.getClass(), keyValueMap);
 203  
         }
 204  
         
 205  
         private static BusinessObjectAuthorizationService businessObjectAuthorizationService;
 206  
         private static BusinessObjectAuthorizationService getBusinessObjectAuthorizationService() {
 207  0
                 if (businessObjectAuthorizationService == null) {
 208  0
                         businessObjectAuthorizationService = KNSServiceLocatorWeb.getBusinessObjectAuthorizationService();
 209  
                 }
 210  0
                 return businessObjectAuthorizationService;
 211  
         }
 212  
 
 213  
         public static String getTitleText(String prependText, Class<?> dataObjectClass, Map<String, String> keyValueMap) {
 214  0
                 StringBuffer titleText = new StringBuffer(prependText);
 215  0
                 for (String key : keyValueMap.keySet()) {
 216  0
                         String fieldVal = keyValueMap.get(key).toString();
 217  
                         
 218  0
                         titleText.append(KNSServiceLocatorWeb.getDataDictionaryService()
 219  
                                         .getAttributeLabel(dataObjectClass, key)
 220  
                                         + "=" + fieldVal.toString() + " ");
 221  0
                 }
 222  0
                 return titleText.toString();
 223  
         }
 224  
 
 225  
         /**
 226  
          * 
 227  
          * This class is an extension of HtmlData. It represents an anchor tag.
 228  
          * 
 229  
          * @author Kuali Rice Team (rice.collab@kuali.org)
 230  
          * 
 231  
          */
 232  
         public static class AnchorHtmlData extends HtmlData {
 233  
                 public static final String TARGET_BLANK = "_blank";
 234  0
                 protected String href = "";
 235  0
                 protected String target = "";
 236  0
                 protected String style = "";
 237  0
                 protected String styleClass ="";
 238  0
                 protected String onclick ="";
 239  
 
 240  
                 /**
 241  
                  * Needed by inquiry framework
 242  
                  */
 243  0
                 public AnchorHtmlData() {
 244  0
                 }
 245  
 
 246  0
                 public AnchorHtmlData(String href, String title) {
 247  0
                         this.href = href;
 248  0
                         this.title = title;
 249  0
                 }
 250  
 
 251  
                 public AnchorHtmlData(String href, String methodToCall,
 252  0
                                 String displayText) {
 253  0
                         this.href = href;
 254  0
                         this.methodToCall = methodToCall;
 255  0
                         this.displayText = displayText;
 256  0
                 }
 257  
 
 258  
                 /**
 259  
                  * @param href the href to set
 260  
                  */
 261  
                 public void setHref(String href) {
 262  0
                         this.href = href;
 263  0
                 }
 264  
 
 265  
                 /**
 266  
                  * 
 267  
                  * This method generates anchor tag.
 268  
                  * 
 269  
                  * @see org.kuali.rice.kns.lookup.HtmlData#constructCompleteHtmlTag()
 270  
                  */
 271  
                 public String constructCompleteHtmlTag() {
 272  
                         String completeHtmlTag;
 273  0
                         if (StringUtils.isEmpty(getHref()))
 274  0
                                 completeHtmlTag = getDisplayText();
 275  
                         else
 276  0
                                 completeHtmlTag = getPrependDisplayText()
 277  
                                                 + "<a title=\""
 278  
                                                 + title
 279  
                                                 + "\""
 280  
                                                 + " href=\""
 281  
                                                 + getHref()
 282  
                                                 + "\""
 283  
                                                 + getStyle()
 284  
                                                 + " "
 285  
                                                 + getStyleClass()
 286  
                                                 + " "
 287  
                                                 + (StringUtils.isEmpty(getOnclick()) ? "" : " onClick=\""
 288  
                                                         + getOnclick() + "\" ")
 289  
                                                 + (StringUtils.isEmpty(getTarget()) ? "" : " target=\""
 290  
                                                                 + getTarget() + "\" ") + ">" + getDisplayText()
 291  
                                                 + "</a>" + getAppendDisplayText();
 292  0
                         return completeHtmlTag;
 293  
                 }
 294  
 
 295  
                 /**
 296  
                  * @return the target
 297  
                  */
 298  
                 public String getTarget() {
 299  0
                         return this.target;
 300  
                 }
 301  
 
 302  
                 /**
 303  
                  * @param target
 304  
                  *            the target to set
 305  
                  */
 306  
                 public void setTarget(String target) {
 307  0
                         this.target = target;
 308  0
                 }
 309  
 
 310  
                 /**
 311  
          * @return the style
 312  
          */
 313  
         public String getStyle() {
 314  0
                 return this.style;
 315  
         }
 316  
 
 317  
                 /**
 318  
          * @param style the style to set
 319  
          */
 320  
         public void setStyle(String style) {
 321  0
                 this.style = style;
 322  0
         }
 323  
 
 324  
                 /**
 325  
          * @return the styleClass
 326  
          */
 327  
         public String getStyleClass() {
 328  0
                 return this.styleClass;
 329  
         }
 330  
 
 331  
                 /**
 332  
          * @param styleClass the styleClass to set
 333  
          */
 334  
         public void setStyleClass(String styleClass) {
 335  0
                 this.styleClass = styleClass;
 336  0
         }
 337  
         
 338  
                 /**
 339  
                  * @return the onclick
 340  
                  */
 341  
                 public String getOnclick() {
 342  0
                         return this.onclick;
 343  
                 }
 344  
 
 345  
                 /**
 346  
                  * @param onclick the onclick to set
 347  
                  */
 348  
                 public void setOnclick(String onclick) {
 349  0
                         this.onclick = onclick;
 350  0
                 }        
 351  
 
 352  
                 /**
 353  
                  * @return the href
 354  
                  */
 355  
                 public String getHref() {
 356  0
                         return this.href;
 357  
                 }
 358  
 
 359  
                 /**
 360  
                  * @return the methodToCall
 361  
                  */
 362  
                 public String getMethodToCall() {
 363  0
                         return this.methodToCall;
 364  
                 }
 365  
 
 366  
         }
 367  
 
 368  
         /**
 369  
          * 
 370  
          * This class is an extension of HtmlData. It represents an input tag.
 371  
          * 
 372  
          * @author Kuali Rice Team (rice.collab@kuali.org)
 373  
          * 
 374  
          */
 375  
         public static class InputHtmlData extends HtmlData {
 376  
                 public static final String CHECKBOX_INPUT_TYPE = "checkbox";
 377  
                 public static final String CHECKBOX_CHECKED_VALUE = "checked";
 378  
 
 379  0
                 protected String inputType = "";
 380  0
                 protected String src = "";
 381  0
                 protected String styleClass = "";
 382  0
                 protected String border = "0";
 383  0
                 protected String checked = "";
 384  0
                 protected String value = "";
 385  
 
 386  0
                 public InputHtmlData(String name, String inputType) {
 387  0
                         this.name = name;
 388  0
                         this.inputType = inputType;
 389  0
                 }
 390  
 
 391  0
                 public InputHtmlData(String name, String inputType, String src) {
 392  0
                         this.name = name;
 393  0
                         this.inputType = inputType;
 394  0
                         this.src = src;
 395  0
                 }
 396  
 
 397  
                 /***********************************************************************
 398  
                  * 
 399  
                  * This method contructs an input tag.
 400  
                  * 
 401  
                  * @see org.kuali.rice.kns.lookup.HtmlData#constructCompleteHtmlTag()
 402  
                  */
 403  
                 public String constructCompleteHtmlTag() {
 404  0
                         return getPrependDisplayText()
 405  
                                         + "<input title=\""
 406  
                                         + title
 407  
                                         + "\""
 408  
                                         + " name=\""
 409  
                                         + getName()
 410  
                                         + "\""
 411  
                                         + (StringUtils.isEmpty(src) ? ""
 412  
                                                         : " src=\"" + src + "\" ")
 413  
                                         + " type=\""
 414  
                                         + getInputType()
 415  
                                         + "\""
 416  
                                         + (StringUtils.isEmpty(value) ? ""
 417  
                                                         : " value=\"" + value + "\" ")
 418  
                                         + (StringUtils.isEmpty(checked) ? ""
 419  
                                                         : " checked=\"" + checked + "\" ")
 420  
                                         + (StringUtils.isEmpty(getStyleClass()) ? ""
 421  
                                                         : " styleClass=\"" + getStyleClass() + "\" ")
 422  
                                         + " border=\"" + getBorder() + "\"" + " value=\""
 423  
                                         + getDisplayText() + "\"" + "/>" + getAppendDisplayText();
 424  
                 }
 425  
 
 426  
                 /**
 427  
                  * @return the inputType
 428  
                  */
 429  
                 public String getInputType() {
 430  0
                         return this.inputType;
 431  
                 }
 432  
 
 433  
                 /**
 434  
                  * @return the src
 435  
                  */
 436  
                 public String getSrc() {
 437  0
                         return this.src;
 438  
                 }
 439  
 
 440  
                 /**
 441  
                  * @return the border
 442  
                  */
 443  
                 public String getBorder() {
 444  0
                         return this.border;
 445  
                 }
 446  
 
 447  
                 /**
 448  
                  * @param border
 449  
                  *            the border to set
 450  
                  */
 451  
                 public void setBorder(String border) {
 452  0
                         this.border = border;
 453  0
                 }
 454  
 
 455  
                 /**
 456  
                  * @return the styleClass
 457  
                  */
 458  
                 public String getStyleClass() {
 459  0
                         return this.styleClass;
 460  
                 }
 461  
 
 462  
                 /**
 463  
                  * @param styleClass
 464  
                  *            the styleClass to set
 465  
                  */
 466  
                 public void setStyleClass(String styleClass) {
 467  0
                         this.styleClass = styleClass;
 468  0
                 }
 469  
 
 470  
                 /**
 471  
                  * @param checked the checked to set
 472  
                  */
 473  
                 public void setChecked(String checked) {
 474  0
                         this.checked = checked;
 475  0
                 }
 476  
 
 477  
                 /**
 478  
                  * @param value the value to set
 479  
                  */
 480  
                 public void setValue(String value) {
 481  0
                         this.value = value;
 482  0
                 }
 483  
 
 484  
         }
 485  
 
 486  0
         public static class MultipleAnchorHtmlData extends AnchorHtmlData {
 487  
                 protected List<AnchorHtmlData> anchorHtmlData;
 488  
                 protected static final String ANCHORS_SEPARATOR = ", ";
 489  
                 
 490  
                 /**
 491  
                  * Needed by inquiry framework
 492  
                  */
 493  0
                 public MultipleAnchorHtmlData(List<AnchorHtmlData> anchorHtmlData) {
 494  0
                         this.anchorHtmlData = anchorHtmlData;
 495  0
                 }
 496  
                 
 497  
                 /**
 498  
                  * 
 499  
                  * This method generates anchor tag.
 500  
                  * 
 501  
                  * @see org.kuali.rice.kns.lookup.HtmlData#constructCompleteHtmlTag()
 502  
                  */
 503  
                 public String constructCompleteHtmlTag() {
 504  0
                         StringBuffer completeHtmlTag = new StringBuffer();
 505  0
                         for(AnchorHtmlData anchor: anchorHtmlData){
 506  0
                                 completeHtmlTag.append(anchor.constructCompleteHtmlTag()+",");
 507  
                         }
 508  0
                 if(completeHtmlTag.toString().endsWith(ANCHORS_SEPARATOR))
 509  0
                         completeHtmlTag.delete(completeHtmlTag.length()-ANCHORS_SEPARATOR.length(), completeHtmlTag.length());
 510  0
                         return completeHtmlTag.toString();
 511  
                 }
 512  
 
 513  
                 /**
 514  
                  * @return the anchorHtmlData
 515  
                  */
 516  
                 public List<AnchorHtmlData> getAnchorHtmlData() {
 517  0
                         return this.anchorHtmlData;
 518  
                 }
 519  
 
 520  
         }
 521  
 
 522  
         /**
 523  
          * @return the maxLength
 524  
          */
 525  
         public int getMaxLength() {
 526  
                 try{
 527  0
                         return Integer.parseInt(this.maxLength);
 528  0
                 } catch(Exception ex){
 529  0
                         return -1;
 530  
                 }
 531  
         }
 532  
 
 533  
         /**
 534  
          * @param maxLength the maxLength to set
 535  
          */
 536  
         public void setMaxLength(String maxLength) {
 537  0
                 this.maxLength = maxLength;
 538  0
         }
 539  
 
 540  
 }