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