1 23 package com.sun.enterprise.tools.admingui.handlers; 24 25 import com.iplanet.jato.RequestContext; 26 import com.iplanet.jato.RequestManager; 27 import com.iplanet.jato.model.DefaultModel; 28 import com.iplanet.jato.util.HtmlUtil; 29 import com.iplanet.jato.view.ContainerView; 30 import com.iplanet.jato.view.View; 31 import com.iplanet.jato.view.event.ChildContentDisplayEvent; 32 33 import com.sun.web.ui.model.CCPropertySheetModelInterface; 34 import com.sun.web.ui.model.CCPropertySheetModel; 35 36 import com.sun.enterprise.tools.admingui.util.MBeanUtil; 37 import com.sun.enterprise.tools.admingui.util.Util; 38 import com.sun.enterprise.tools.guiframework.exception.FrameworkException; 39 import com.sun.enterprise.tools.guiframework.view.DescriptorCCActionTable; 40 import com.sun.enterprise.tools.guiframework.view.HandlerContext; 41 import com.sun.enterprise.tools.guiframework.view.descriptors.ViewDescriptor; 42 import com.sun.enterprise.tools.guiframework.view.descriptors.CCPropertySheetDescriptor; 43 import com.sun.enterprise.tools.guiframework.view.DescriptorContainerView; 44 import com.sun.enterprise.tools.guiframework.view.DescriptorCCPageTitle; 45 46 import com.sun.web.ui.common.CCI18N; 47 48 import java.text.DateFormat ; 49 import java.text.ParseException ; 50 import java.text.SimpleDateFormat ; 51 import java.util.ArrayList ; 52 import java.util.Hashtable ; 53 import java.util.Date ; 54 import java.util.EventObject ; 55 import java.util.GregorianCalendar ; 56 import java.util.Iterator ; 57 import java.util.List ; 58 import java.util.Locale ; 59 import java.util.Properties ; 60 import java.util.ResourceBundle ; 61 import java.util.StringTokenizer ; 62 import java.io.File ; 63 64 import javax.management.Attribute ; 65 import javax.management.AttributeList ; 66 import javax.management.ObjectName ; 67 import javax.servlet.ServletRequest ; 68 import javax.servlet.http.HttpServletRequest ; 69 import javax.servlet.http.HttpSession ; 70 71 import java.lang.reflect.Method ; 72 73 76 public class LogViewerHandler { 77 78 81 public void filter(RequestContext ctx, HandlerContext handlerCtx) { 82 View view = handlerCtx.getView(); 83 ServletRequest request = ctx.getRequest(); 84 85 String archivedLogFile = (String )handlerCtx.getInputValue(ARCHIVED_LOG_FILE); 87 Long fromRecord = (Long )handlerCtx.getInputValue(FROM_RECORD); 88 Boolean after = (Boolean )handlerCtx.getInputValue(AFTER_RECORD); 89 Boolean dateEnabled = (Boolean )handlerCtx.getInputValue(DATE_ENABLED); 90 Object fromDate = handlerCtx.getInputValue(FROM_DATE); 91 Object fromTime = handlerCtx.getInputValue(FROM_TIME); 92 Object toDate = handlerCtx.getInputValue(TO_DATE); 93 Object toTime = handlerCtx.getInputValue(TO_TIME); 94 Object loggers = handlerCtx.getInputValue(LOGGERS); 95 Object logLevel = handlerCtx.getInputValue(LOG_LEVEL); 96 Object customLoggers = handlerCtx.getInputValue(CUSTOM_LOGGERS); 97 Object nvp = handlerCtx.getInputValue(NVP); 98 Integer numberToDisplay = (Integer )handlerCtx.getInputValue(NUMBER_TO_DISPLAY); 99 Boolean onlyLevel = 100 (Boolean )handlerCtx.getInputValue(ONLY_LEVEL); 101 Boolean direction = 102 (Boolean )handlerCtx.getInputValue(LOG_DATE_SORT_DIRECTION); 103 Boolean truncMsg = 104 (Boolean )handlerCtx.getInputValue(TRUNCATE_MESSAGE); 105 Integer truncLenInteger = 106 (Integer )handlerCtx.getInputValue(TRUNCATE_LENGTH); 107 String logManagerObjectName = (String )handlerCtx.getInputValue(LOG_MANAGER_OBJECT_NAME); 108 String instanceName = (String )handlerCtx.getInputValue(INSTANCE_NAME); 109 114 115 if (instanceName==null || "".equals(instanceName)){ 116 handlerCtx.setOutputValue(FIRST_LOG_ROW, "-1"); 118 handlerCtx.setOutputValue(LAST_LOG_ROW, "-1"); 119 return; 120 } 121 122 boolean truncateMessage = true; 124 if (truncMsg != null) { 125 truncateMessage = truncMsg.booleanValue(); 126 } 127 int truncLen = 100; 128 if (truncLenInteger != null) { 129 truncLen = truncLenInteger.intValue(); 130 } 131 132 if (archivedLogFile == null || archivedLogFile.equals("")) { 134 archivedLogFile = null; 135 } else { 136 archivedLogFile= archivedLogFile; 137 } 138 139 DefaultModel model = (DefaultModel)handlerCtx.getInputValue(LOG_MODEL); 142 DescriptorCCActionTable table = 143 (DescriptorCCActionTable)handlerCtx.getInputValue(TABLE); 144 145 if ((table == null) && (model == null)) { 146 throw new FrameworkException("Input parameter '"+TABLE+ 147 "' must be specified with the log table View as the value, "+ 148 "or the model to populate should be passed in as Request "+ 149 "attribute '"+LOG_MODEL+"'.", null, view); 150 } 151 152 boolean dateEnabledFlag = false; 154 if (dateEnabled != null) { 155 dateEnabledFlag = dateEnabled.booleanValue(); 156 } 157 if (dateEnabledFlag) { 158 fromDate = convertDateTime( 160 request, fromDate, fromTime, table.getViewDescriptor(), view); 161 toDate = convertDateTime( 162 request, toDate, toTime, table.getViewDescriptor(), view); 163 if ((fromDate == null) || (fromDate == null)) { 164 throw new FrameworkException( 165 "'Specific Date Range' was chosen, however, date fields "+ 166 "are incomplete.", null, view); 167 } 168 if (((Date )fromDate).after((Date )toDate)) { 169 throw new FrameworkException( 170 "Timestamp value of 'From: ' field " + fromDate + 171 " must not be greater than 'To: ' field value " + toDate, 172 null, view); 173 } 174 } else { 175 fromDate = null; 177 toDate = null; 178 } 179 180 if (logLevel != null) { 181 if (logLevel.toString().trim().length() == 0) { 182 logLevel = null; 183 } 184 } 185 186 if (onlyLevel == null) { 187 onlyLevel = FALSE; 188 } 189 190 List moduleList = null; 192 if (loggers != null) { 193 int len = ((Object [])loggers).length; 194 moduleList = new ArrayList (len); 195 Object val; 196 for (int count=0; count<len; count++) { 197 val = (((Object [])loggers)[count]); 198 if ((val == null) || (val.toString().trim().length() == 0)) { 199 continue; 200 } 201 moduleList.add(val); 202 } 203 } 204 205 if ((customLoggers != null) && 207 (customLoggers.toString().trim().length() != 0)) { 208 StringTokenizer tok = new StringTokenizer ( 209 customLoggers.toString(), 210 CUSTOM_LOGGER_DELIMITERS); 211 String token; 212 while (tok.hasMoreTokens()) { 213 token = tok.nextToken(); 214 if ((token == null) || (token.length()==0)) { 215 continue; 216 } 217 moduleList.add(token); 218 } 219 } 220 221 222 Hashtable nvpProps = null; 224 if ((nvp != null) && (nvp.toString().trim().length() != 0)) { 225 nvpProps = new Properties (); 226 int equalsIdx; 227 String token; 228 StringTokenizer tok = 230 new StringTokenizer (nvp.toString(), NVP_DELIMITERS); 231 while (tok.hasMoreTokens()) { 232 token = tok.nextToken(); 233 if ((token == null) || (token.length()==0)) { 234 continue; 235 } 236 equalsIdx = token.indexOf(EQUALS); 237 if (equalsIdx < 0) { 239 throw new FrameworkException( 240 "Name-Value Pairs must be in the format \""+ 241 "<name>=<value>\".", null, view); 242 } 243 244 String key = token.substring(0, equalsIdx++); 246 ArrayList valueList = (ArrayList ) nvpProps.get(key); 247 if (valueList == null){ 248 valueList = new ArrayList (); 249 valueList.add(token.substring(equalsIdx)); 250 nvpProps.put(key, valueList); 251 }else{ 252 valueList.add(token.substring(equalsIdx)); 253 } 254 } 255 } 257 258 259 if (numberToDisplay == null) { 261 numberToDisplay = DEFAULT_NUMBER_TO_DISPLAY; 262 } 263 264 if (direction == null) { 266 direction = FALSE; 267 } 268 269 if (after == null) { 271 after = direction; 273 } 274 275 Object params[] = new Object [QUERY_SIGNATURE.length]; 277 params[0] = archivedLogFile; params[1] = fromRecord; params[2] = (fromRecord == null) ? direction : after; 281 params[3] = direction; params[4] = numberToDisplay; params[5] = fromDate; params[6] = toDate; params[7] = logLevel; params[8] = onlyLevel; params[9] = moduleList; params[10] = nvpProps; 290 291 AttributeList results = null; 293 try { 294 results = (AttributeList ) getLogRecordsUsingQuery(logManagerObjectName, instanceName, params, QUERY_SIGNATURE); 295 }catch (Exception ex) { 296 throw new FrameworkException("Error while querying Log File.", 297 ex, (table == null) ? null : table.getViewDescriptor(), view); 298 } 299 300 if (model == null) { 302 model = (DefaultModel)table.getModel(); 303 } 304 305 model.clear(); 307 308 String message; 309 List headerRow = (List )(((Attribute )results.get(0)).getValue()); 310 List rowList = (List )(((Attribute )results.get(1)).getValue()); 311 List row; 312 Iterator it = rowList.iterator(); 313 while (it.hasNext()) { 314 row = (List )it.next(); 315 if (row.size() != headerRow.size()) { 316 throw new FrameworkException( 317 "Row had '"+row.size()+"' columns, header has '"+ 318 headerRow.size()+"' columns!", table.getViewDescriptor(), 319 view); 320 } 321 model.appendRow(); 322 323 325 model.setValue("recNumber", row.get(0)); 326 334 model.setValue("dateTime", formatDateForDisplay( 335 request.getLocale(), (Date )row.get(1))); 336 String msgId = (String ) row.get(6); 337 String level = (String )row.get(2); 340 if (level.equalsIgnoreCase("severe")) { 342 model.setValue("levelImage", Util.getMessage("common.errorGif")); 344 model.setValue(SHOW_LEVEL_IMAGE, new Boolean (true)); 345 model.setValue("diagnosticCauses", getDiagnosticCauses(msgId)); 346 model.setValue("diagnosticChecks", getDiagnosticChecks(msgId)); 347 model.setValue("diagnosticURI", getDiagnosticURI(msgId)); 348 } else { 350 model.setValue(SHOW_LEVEL_IMAGE, new Boolean (false)); 351 model.setValue("diagnostic", ""); 352 } 353 model.setValue("level", level); 354 model.setValue("productName", row.get(3)); 355 model.setValue("logger", row.get(4)); 356 model.setValue("nvp", row.get(5)); 357 model.setValue("messageID", msgId ); 358 message = ((String )row.get(7)).trim(); 359 if (truncateMessage && (message.length() > truncLen)) { 360 message = message.substring(0, truncLen).concat("...\n"); 361 } 362 model.setValue("message", formatMessageForDisplay(message)); 363 } 364 365 if (rowList.size() > 0) { 367 handlerCtx.setOutputValue(FIRST_LOG_ROW, 368 ((List )rowList.get(0)).get(0)); 369 handlerCtx.setOutputValue(LAST_LOG_ROW, 370 ((List )rowList.get(rowList.size()-1)).get(0)); 371 } else { 372 handlerCtx.setOutputValue(FIRST_LOG_ROW, "-1"); 373 handlerCtx.setOutputValue(LAST_LOG_ROW, "-1"); 374 } 375 } 376 377 378 382 public String generateResultNavBar(RequestContext ctx, HandlerContext handlerCtx) { 383 if (!(handlerCtx.getEvent() instanceof ChildContentDisplayEvent)) { 384 throw new FrameworkException(getClass().getName()+ 385 ".generateResultNavBar is only valid for endDisplay events.", 386 null, handlerCtx.getView()); 387 } 388 389 String firstLogRow = (String )handlerCtx.getInputValue(FIRST_LOG_ROW); 391 String lastLogRow = (String )handlerCtx.getInputValue(LAST_LOG_ROW); 392 if (firstLogRow == null) { 393 firstLogRow="0"; 394 } 395 if (lastLogRow == null) { 396 lastLogRow="0"; 397 } 398 int firstRow = 0; 399 try { 400 firstRow = Integer.parseInt(firstLogRow); 401 int lastRow = Integer.parseInt(lastLogRow); 402 if (firstRow > lastRow) { 403 String temp = firstLogRow; 404 firstLogRow = lastLogRow; 405 lastLogRow = temp; 406 firstRow = lastRow; 407 } 408 } catch (NumberFormatException ex) { 409 } 411 412 String prevButtonString = (String )handlerCtx.getInputValue(PREV_BUTTON_STRING); 414 String nextButtonString = (String )handlerCtx.getInputValue(NEXT_BUTTON_STRING); 415 416 String bundle = (String )handlerCtx.getInputValue(RESOURCE_BUNDLE); 419 if (bundle == null) { 420 bundle = handlerCtx.getViewDescriptor().getResourceBundle(); 421 } 422 if (bundle == null) { 423 throw new FrameworkException("You MUST specify the resource "+ 424 "bundle via input parameter: '"+RESOURCE_BUNDLE+"'.", 425 null, handlerCtx.getView()); 426 } 427 CCI18N i18n = new CCI18N(ctx, bundle); 428 429 String priorMatches = i18n.getMessage("logViewer.priorMatches"); 435 String logResultSummary = i18n.getMessage("logViewer.logResultSummary"); 436 String logResultSummaryThrough = i18n.getMessage("logViewer.logResultSummaryThrough"); 437 String nextMatches = i18n.getMessage("logViewer.nextMatches"); 438 439 StringBuffer content = 440 new StringBuffer (((ChildContentDisplayEvent)handlerCtx.getEvent()).getContent()); 441 int mark = content.lastIndexOf("</table>"); 442 if (mark > 0) { 443 StringBuffer newRow = new StringBuffer ("\n"); 445 newRow.append("\t <tr><td class=\"TblActTd\" colspan=\"6\" " 446 + "nowrap=\"nowrap\">\n"); 447 newRow.append("\t\t<div style=\"margin-top:6px;\">\n"); 448 449 if (firstRow > 0) { 451 newRow.append(prevButtonString); 452 } 453 454 newRow.append("\t\t <img SRC=\"../images/spacer.gif\" " 455 + "alt=\"\" width=\"10\" height=\"8\" />\n"); 456 newRow.append("\t\t <span class=\"LblLev2Txt\">\n"); 457 newRow.append("\t\t\t<label for=\"page\">"+logResultSummary+" "+ 458 firstLogRow+" "+logResultSummaryThrough+" "+ 459 lastLogRow+"</label>\n"); 460 newRow.append("\t\t </span><img SRC=\"../images/spacer.gif\"" 461 + "alt=\"\" width=\"10\" height=\"1\" />\n"); 462 463 newRow.append(nextButtonString); 465 466 newRow.append("\t\t</div></td></tr>\n"); 467 468 content.insert(mark, newRow.toString()); 470 471 mark = content.indexOf("<tr>"); 475 if (mark > 0) { 476 content.insert(mark, newRow.toString()); 478 } 479 } 480 481 return content.toString(); 483 } 484 485 486 494 public void getDate(RequestContext ctx, HandlerContext handlerCtx) { 495 String formatString = (String )handlerCtx.getInputValue(DATE_FORMAT); 497 if ((formatString == null) || (formatString.trim().length() == 0)) { 498 throw new FrameworkException("You MUST specify the attribute: '"+ 499 DATE_FORMAT+"' in order for getDate to work!", 500 null, handlerCtx.getView()); 501 } 502 503 int formatType = -1; 505 if (formatString.equals(GET_DATE_SHORT)) { 506 formatType = DateFormat.SHORT; 507 } else if (formatString.equals(GET_DATE_MEDIUM)) { 508 formatType = DateFormat.MEDIUM; 509 } else if (formatString.equals(GET_DATE_LONG)) { 510 formatType = DateFormat.LONG; 511 } else if (formatString.equals(GET_DATE_FULL)) { 512 formatType = DateFormat.FULL; 513 } 514 DateFormat df = null; 515 if (formatType == -1) { 516 df = DateFormat.getDateInstance( 517 DateFormat.SHORT, ctx.getRequest().getLocale()); 518 ((SimpleDateFormat )df).applyLocalizedPattern(formatString); 519 } else { 520 df = DateFormat.getDateInstance( 521 formatType, ctx.getRequest().getLocale()); 522 } 523 524 handlerCtx.setOutputValue(DATE_VALUE, df.format(new Date ())); 526 } 527 528 public void getFormatedDateTime(RequestContext ctx, HandlerContext handlerCtx) { 529 String ts = (String )handlerCtx.getInputValue("timestamp"); 530 Date date = null; 531 if (ts == null || "".equals(ts)){ 532 date = new Date (System.currentTimeMillis()); 533 }else{ 534 date = new Date ( Long.parseLong(ts)); 535 } 536 DateFormat df = DateFormat.getDateInstance(DateFormat.SHORT, ctx.getRequest().getLocale()); 537 DateFormat tf = DateFormat.getTimeInstance(DateFormat.MEDIUM, ctx.getRequest().getLocale()); 538 ((SimpleDateFormat )tf).applyLocalizedPattern(" HH:mm:ss.SSS"); 539 540 String ftime = tf.format(date); 541 String fdate = df.format(date); 542 handlerCtx.setOutputValue("valueTime", ftime); 543 handlerCtx.setOutputValue("valueDate", fdate); 544 } 545 546 547 552 public void getTime(RequestContext ctx, HandlerContext handlerCtx) { 553 DateFormat df = DateFormat.getTimeInstance( 554 DateFormat.SHORT, ctx.getRequest().getLocale()); 555 ((SimpleDateFormat )df).applyLocalizedPattern(TIME_FORMAT); 556 557 handlerCtx.setOutputValue(GET_TIME_RESULT, df.format(new Date ())); 559 } 560 561 564 public void getCurrentLogFileName(RequestContext ctx, HandlerContext handlerCtx) { 565 String instanceName = (String )handlerCtx.getInputValue("instanceName"); 566 String configName = (String )MBeanUtil.getAttribute("com.sun.appserv:type=server,category=config,name="+instanceName, "config-ref"); 567 String fileName = (String ) MBeanUtil.getAttribute("com.sun.appserv:type=log-service,category=config,config="+configName, "file"); 568 File file = new File (fileName); 569 String fn = file.getName(); 570 handlerCtx.setOutputValue("currentLogFileName", fn); 572 } 573 574 575 579 protected String formatMessageForDisplay(String message) { 580 return HtmlUtil.escape(message).replaceAll("\n", "<br>"); 581 } 582 583 587 protected String formatArrayListForDisplay(ArrayList diag) { 588 if ((diag == null) || (diag.size() == 0)) { 589 return ""; 590 } 591 StringBuffer buf = new StringBuffer ("<br>"); 592 for(int i=0; i<diag.size(); i++){ 593 buf.append( (String )diag.get(i)); 594 buf.append("<br>"); 595 } 596 return buf.toString(); 597 } 598 599 603 public static String formatDateForDisplay(Locale locale, Date date) { 604 DateFormat dateFormat = DateFormat.getDateInstance( 605 DateFormat.MEDIUM, locale); 606 if (dateFormat instanceof SimpleDateFormat ) { 607 SimpleDateFormat fmt = (SimpleDateFormat )dateFormat; 608 fmt.applyLocalizedPattern(fmt.toLocalizedPattern()+TIME_FORMAT); 609 return fmt.format(date); 610 } else { 611 dateFormat = DateFormat.getDateTimeInstance( 612 DateFormat.MEDIUM, DateFormat.LONG, locale); 613 return dateFormat.format(date); 614 } 615 } 616 617 618 627 protected Date convertDateTime( 628 ServletRequest request, Object date, Object time, 629 ViewDescriptor vd, View view) { 630 if (date instanceof Date ) { 632 return (Date )date; 633 } 634 if ((date == null) || (date.toString().trim().length() == 0)) { 636 return null; 637 } 638 639 if (time.toString().trim().length() == 0) { 641 time = null; 642 } 643 String dateTime = date.toString()+ 644 ((time == null) ? "" : (" "+time.toString())); 645 DateFormat df = DateFormat.getDateInstance( 646 DateFormat.SHORT, request.getLocale()); 647 if ((time != null) && (df instanceof SimpleDateFormat )) { 648 SimpleDateFormat fmt = (SimpleDateFormat )df; 649 String formatPrefix = fmt.toLocalizedPattern(); 650 try { 651 date = parseDateString( 653 fmt, formatPrefix+TIME_FORMAT, dateTime); 654 } catch (ParseException ex) { 655 try { 656 date = parseDateString( 658 fmt, formatPrefix+TIME_FORMAT_2, dateTime); 659 } catch (ParseException ex2) { 660 try { 661 date = parseDateString( 663 fmt, formatPrefix+TIME_FORMAT_3, dateTime); 664 } catch (ParseException ex3) { 665 throw new FrameworkException( 666 "Unable to parse Date/Time: '"+dateTime+"'.", 667 ex3, vd, view); 668 } 669 } 670 } 671 } else if (time != null) { 672 df = DateFormat.getDateTimeInstance( 674 DateFormat.SHORT, DateFormat.LONG, request.getLocale()); 675 try { 676 date = df.parse(dateTime); 677 } catch (ParseException ex) { 678 throw new FrameworkException( 679 "Unable to parse Date/Time: '"+dateTime+"'.", 680 ex, vd, view); 681 } 682 } else { 683 try { 684 date = df.parse(dateTime); 685 } catch (ParseException ex) { 686 throw new FrameworkException( 687 "Unable to parse Date/Time: '"+dateTime+"'.", 688 ex, vd, view); 689 } 690 } 691 692 return (Date )date; 694 } 695 696 697 701 private Date parseDateString(SimpleDateFormat fmt, String format, String dateTime) throws ParseException { 702 fmt.applyLocalizedPattern(format); 703 return fmt.parse(dateTime); 704 } 705 706 709 private String getDiagnosticCauses(String msgId){ 710 711 if (msgId == null || "".equals(msgId)) 712 return formatArrayListForDisplay(null); 713 String params[] = {msgId}; 714 String signatures[] = {"String"}; 715 try { 716 ArrayList results = (ArrayList )MBeanUtil.invoke( 717 "com.sun.appserv:name=logmanager,category=runtime,server=server", 718 "getDiagnosticCausesForMessageId", 719 params, 720 signatures); 721 String res = formatArrayListForDisplay(results); 722 return res; 723 } catch (Exception ex) { 724 throw new FrameworkException("Error while retrieving diagnostic from messageId.", ex); 725 } 726 } 727 728 731 private String getDiagnosticChecks(String msgId){ 732 733 if (msgId == null || "".equals(msgId)) 734 return formatArrayListForDisplay(null); 735 String params[] = {msgId}; 736 String signatures[] = {"String"}; 737 try { 738 ArrayList results = (ArrayList )MBeanUtil.invoke( 739 "com.sun.appserv:name=logmanager,category=runtime,server=server", 740 "getDiagnosticChecksForMessageId", 741 params, 742 signatures); 743 String res = formatArrayListForDisplay(results); 744 return res; 745 } catch (Exception ex) { 746 throw new FrameworkException("Error while retrieving diagnostic checks from messageId.", ex); 747 } 748 } 749 750 753 private String getDiagnosticURI(String msgId){ 754 755 if (msgId == null || "".equals(msgId)) 756 return ""; 757 String params[] = {msgId}; 758 String signatures[] = {"String"}; 759 try { 760 String res = (String )MBeanUtil.invoke( 761 "com.sun.appserv:name=logmanager,category=runtime,server=server", 762 "getDiagnosticURIForMessageId", 763 params, 764 signatures); 765 return res; 766 } catch (Exception ex) { 768 throw new FrameworkException("Error while retrieving diagnostic URI from messageId.", ex); 769 } 770 } 771 772 773 777 public boolean hasResults(RequestContext ctx, HandlerContext handlerCtx) { 778 DescriptorCCActionTable table = (DescriptorCCActionTable) 779 ctx.getRequest().getAttribute(TABLE); 780 if (table == null) { 781 return false; 782 } 783 DefaultModel model = (DefaultModel)table.getModel(); 784 try { 785 int size = model.getSize(); 786 if (size > 0) { 787 handlerCtx.setOutputValue("hasResults", "true"); 788 return true; 789 } else { 790 handlerCtx.setOutputValue("hasResults", "false"); 791 return false; 792 } 793 } catch (Exception ex) { 794 return false; 796 } 797 } 798 799 800 803 public void switchDateSort(RequestContext ctx, HandlerContext handlerCtx) { 804 HttpSession session = ctx.getRequest().getSession(); 805 806 Boolean dir = (Boolean )handlerCtx.getInputValue(LOG_DATE_SORT_DIRECTION); 808 if (dir == null) { 809 dir = TRUE; 810 } else { 811 dir = new Boolean (dir.booleanValue()^true); 812 } 813 handlerCtx.setOutputValue(SWITCH_DATE_SORT_RESULT, dir); 814 815 ContainerView cv = (ContainerView)handlerCtx.getView().getParent(); 823 HttpServletRequest request = ctx.getRequest(); 824 cv.setDisplayFieldValue( 825 DescriptorCCActionTable.CHILD_PRIMARY_SORT_ORDER_HIDDEN_FIELD, 826 request.getParameter("sortOrder")); 827 cv.setDisplayFieldValue( 828 DescriptorCCActionTable.CHILD_PRIMARY_SORT_NAME_HIDDEN_FIELD, 829 request.getParameter("sortName")); 830 } 831 832 public void testRunning(RequestContext ctx, HandlerContext handlerCtx) { 833 View view = handlerCtx.getView(); 834 ServletRequest request = ctx.getRequest(); 835 String instanceName = (String )handlerCtx.getInputValue(INSTANCE_NAME); 836 if (isServerRunning(instanceName)) 837 handlerCtx.setOutputValue("isRunning", "true" ); 838 else 839 handlerCtx.setOutputValue("isRunning", "false" ); 840 } 841 842 public void getLogFilesDirectory(RequestContext ctx, HandlerContext handlerCtx) { 843 ServletRequest request = ctx.getRequest(); 844 String instanceName = (String )handlerCtx.getInputValue("instanceName"); 845 try { 846 String dir = getLogFilesDirectory(instanceName); 847 handlerCtx.setOutputValue("logFileDirectory", dir); 848 }catch (Exception ex){ 849 handlerCtx.setOutputValue("logFileDirectory", ""); 850 } 851 } 852 853 public void displayAdvancedSearchOptions(RequestContext ctx, HandlerContext handlerCtx) { 854 View view = handlerCtx.getView(); 855 if (!(view instanceof DescriptorContainerView)) { 856 View parent = view.getParent(); 857 if (!(parent instanceof DescriptorContainerView)) { 858 throw new FrameworkException("View is not a DescriptorContainerView!", null, view); 859 } else { 860 view = parent; 861 } 862 } 863 if (view instanceof DescriptorCCPageTitle) { 864 view = view.getParent(); 865 } 866 DescriptorContainerView descView = (DescriptorContainerView)view; 867 ViewDescriptor propertySheetDescriptor = descView.getViewDescriptor(); 868 869 if (propertySheetDescriptor == null) { 870 throw new FrameworkException("propertySheetDescriptor is null", propertySheetDescriptor, view); 871 } 872 if(!(propertySheetDescriptor instanceof CCPropertySheetDescriptor)) { 873 throw new FrameworkException("propertySheetDescriptor is of wrong type", propertySheetDescriptor, view); 874 } 875 CCPropertySheetModelInterface model = ((CCPropertySheetDescriptor)propertySheetDescriptor).getModel(); 876 boolean searchAdvance = new Boolean (""+ctx.getRequest().getAttribute("ShowAdvanceSearch")).booleanValue(); 877 if (searchAdvance) { 878 model.setVisible("advanceSearch", true); 879 model.setVisible("advanceLink", false); 880 model.setVisible("basicLink", true); 881 handlerCtx.setOutputValue("showAdvance", "true"); 882 } else { 883 model.setVisible("advanceSearch", false); 884 model.setVisible("advanceLink", true); 885 model.setVisible("basicLink", false); 886 handlerCtx.setOutputValue("showAdvance", "false"); 887 } 888 } 889 public String setEndDisplayString(RequestContext ctx, HandlerContext handlerCtx) { 890 String endDisplayString = (String )handlerCtx.getInputValue(END_DISPLAY_STRING); 892 if (endDisplayString == null) { 893 throw new FrameworkException("'"+END_DISPLAY_STRING+"' cannot be null!"); 894 } 895 896 return endDisplayString; 898 } 899 900 901 private static boolean isEmpty(String test) { 902 return ((test == null) || "".equals(test)); 903 } 904 905 public static String getLogFilesDirectory(String instanceName){ 906 if (isEmpty(instanceName)) 907 return ""; 908 String dir = ""; 909 try{ 910 if (MBeanUtil.isValidMBean("com.sun.appserv:name=logmanager,category=runtime,server="+instanceName)){ 911 dir = (String ) MBeanUtil.invoke( 912 "com.sun.appserv:name=logmanager,category=runtime,server="+instanceName, 913 "getLogFilesDirectory", 914 null, 915 null); 916 }else{ 917 Class provider = Class.forName("com.sun.enterprise.ee.tools.admingui.handlers.NodeAgentLogProvider"); 919 Class [] type = new Class []{ String .class }; 920 Method method = provider.getMethod("getLogFilesDirectory", type); 921 Object [] args = new Object [] {instanceName}; 922 dir = (String ) method.invoke(null, args); 923 } 924 }catch(Exception ex){ 925 } 926 return dir; 927 } 928 929 public static boolean isServerRunning(String instanceName){ 930 if(isEmpty(instanceName)) 931 return false; 932 return MBeanUtil.isValidMBean("com.sun.appserv:name=logmanager,category=runtime,server="+instanceName); 933 } 934 935 936 private AttributeList getLogRecordsUsingQuery(String logManagerObjectName, String instanceName, Object []params, String [] QUERY_SIGNATURE) 937 { 938 AttributeList results = null; 939 if (MBeanUtil.isValidMBean(logManagerObjectName)){ 940 results = (AttributeList )MBeanUtil.invoke( 941 logManagerObjectName, 942 "getLogRecordsUsingQuery", 943 params, 944 QUERY_SIGNATURE); 945 return results; 946 } 947 try { 948 Class provider = Class.forName("com.sun.enterprise.ee.tools.admingui.handlers.NodeAgentLogProvider"); 950 Class [] type = new Class []{ 951 String .class, 952 Object [].class}; 953 Method method = provider.getMethod("getLogRecordsUsingQuery", type); 954 Object [] args = new Object [] { instanceName, params}; 955 results = (AttributeList ) method.invoke(null, args); 956 }catch (Exception ex){ 957 throw new FrameworkException (ex); 958 } 959 return results; 960 } 961 962 963 966 public static final Integer ONE = new Integer (1); 967 968 971 public static final Boolean FALSE = new Boolean (false); 972 973 976 public static final Boolean TRUE = new Boolean (true); 977 978 981 public static final String [] QUERY_SIGNATURE = { 982 "java.lang.String", "java.lang.Long", "java.lang.Boolean", "java.lang.Boolean", "java.lang.Integer", "java.util.Date", "java.util.Date", "java.lang.String", "java.lang.Boolean", "java.util.List", "java.util.Properties" }; 994 995 996 999 public static final String TABLE = "logTable"; 1000 1001 1004 public static final String LOG_MODEL = "logModel"; 1005 1006 1009 public static final String DATE_ENABLED = "dateEnabled"; 1010 1011 1014 public static final String AFTER_RECORD = "afterRecord"; 1015 1016 1019 public static final String FROM_RECORD = "fromRecord"; 1020 1021 1024 public static final String ARCHIVED_LOG_FILE = "archivedLogFile"; 1025 1026 1027 1030 public static final String FROM_DATE = "fromDate"; 1031 1032 1035 public static final String FROM_TIME = "fromTime"; 1036 1037 1040 public static final String TO_DATE = "toDate"; 1041 1042 1045 public static final String TO_TIME = "toTime"; 1046 1047 1050 public static final String LOGGERS = "loggers"; 1051 1052 1055 public static final String LOG_LEVEL = "logLevel"; 1056 1057 1060 public static final String CUSTOM_LOGGERS = "customLogger"; 1061 1062 1065 public static final String NVP = "nvp"; 1066 1067 1070 public static final String NUMBER_TO_DISPLAY = "numberToDisplay"; 1071 1072 1075 public static final String ONLY_LEVEL = "only"; 1076 1077 1080 public static final String LOG_DATE_SORT_DIRECTION = "LOG_DATE_SORT_DIRECTION"; 1081 public static final String SWITCH_DATE_SORT_RESULT = "result"; 1082 1083 1086 public static final String FIRST_LOG_ROW = "firstLogRow"; 1087 1088 1091 public static final String LAST_LOG_ROW = "lastLogRow"; 1092 1093 1097 public static final Integer DEFAULT_NUMBER_TO_DISPLAY = new Integer (40); 1098 1099 1103 public static final String CUSTOM_LOGGER_DELIMITERS = " \t\n\r\f,;:"; 1104 1105 1109 public static final String NVP_DELIMITERS = " \t\n\r\f,;:"; 1110 1111 1114 public static final char EQUALS = '='; 1115 1116 1121 public static final String TIME_FORMAT = " HH:mm:ss.SSS"; 1122 public static final String TIME_FORMAT_2 = " HH:mm:ss"; 1123 public static final String TIME_FORMAT_3 = " HH:mm"; 1124 1125 1128 public static final String GET_TIME_RESULT = "value"; 1129 1130 1134 public static final String DATE_FORMAT = "dateFormat"; 1135 1136 1139 public static final String DATE_VALUE = "value"; 1140 1141 1144 public static final String GET_DATE_SHORT = "short"; 1145 1146 1149 public static final String GET_DATE_MEDIUM = "medium"; 1150 1151 1154 public static final String GET_DATE_LONG = "long"; 1155 1156 1159 public static final String GET_DATE_FULL = "full"; 1160 1161 1165 public static final String TRUNCATE_MESSAGE = "truncateMessage"; 1166 1167 1172 public static final String TRUNCATE_LENGTH = "truncateLength"; 1173 1174 1178 public static final String SHOW_LEVEL_IMAGE = "showLevelImage"; 1179 1180 1183 public static final String LEVEL_IMAGE_ROOT = 1184 "/com_sun_web_ui/images/alerts/"; 1185 1186 1189 public static final String RESOURCE_BUNDLE = "resourceBundle"; 1190 1191 1194 public static final String PREV_BUTTON_STRING = "prevButtonString"; 1195 1196 1199 public static final String NEXT_BUTTON_STRING = "nextButtonString"; 1200 1201 1204 public static final String END_DISPLAY_STRING = "endDisplayString"; 1205 1206 1209 public static final String LOG_MANAGER_OBJECT_NAME = "logManagerObjectName"; 1210 public static final String INSTANCE_NAME = "instanceName"; 1211} 1212 | Popular Tags |