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