1 16 package org.apache.cocoon.portlet; 17 18 import org.apache.avalon.excalibur.logger.LogKitLoggerManager; 19 import org.apache.avalon.framework.configuration.Configuration; 20 import org.apache.avalon.framework.configuration.DefaultConfigurationBuilder; 21 import org.apache.avalon.framework.context.DefaultContext; 22 import org.apache.avalon.framework.logger.LogKitLogger; 23 import org.apache.avalon.framework.logger.Logger; 24 25 import org.apache.cocoon.Cocoon; 26 import org.apache.cocoon.CocoonAccess; 27 import org.apache.cocoon.ConnectionResetException; 28 import org.apache.cocoon.Constants; 29 import org.apache.cocoon.ResourceNotFoundException; 30 import org.apache.cocoon.components.notification.DefaultNotifyingBuilder; 31 import org.apache.cocoon.components.notification.Notifier; 32 import org.apache.cocoon.components.notification.Notifying; 33 import org.apache.cocoon.environment.Environment; 34 import org.apache.cocoon.environment.portlet.PortletContext; 35 import org.apache.cocoon.environment.portlet.PortletEnvironment; 36 import org.apache.cocoon.portlet.multipart.MultipartActionRequest; 37 import org.apache.cocoon.portlet.multipart.RequestFactory; 38 39 import org.apache.commons.lang.BooleanUtils; 40 import org.apache.log.ContextMap; 41 import org.apache.log.Hierarchy; 42 import org.apache.pluto.core.impl.PortletContextImpl; 43 44 import javax.portlet.ActionRequest; 45 import javax.portlet.ActionResponse; 46 import javax.portlet.GenericPortlet; 47 import javax.portlet.PortletConfig; 48 import javax.portlet.PortletException; 49 import javax.portlet.PortletSession; 50 import javax.portlet.RenderRequest; 51 import javax.portlet.RenderResponse; 52 import javax.portlet.PortletRequest; 53 import java.io.File ; 54 import java.io.FileInputStream ; 55 import java.io.IOException ; 56 import java.io.InputStream ; 57 import java.io.OutputStream ; 58 import java.io.PrintStream ; 59 import java.net.MalformedURLException ; 60 import java.net.SocketException ; 61 import java.net.URL ; 62 import java.util.HashMap ; 63 64 73 public class ManagedCocoonPortlet extends GenericPortlet { 74 75 protected static final String PROCESSED_BY = "Processed by " 77 + Constants.COMPLETE_NAME + " in "; 78 79 static final float SECOND = 1000; 81 static final float MINUTE = 60 * SECOND; 82 static final float HOUR = 60 * MINUTE; 83 84 private Logger log; 85 86 89 protected Exception exception; 90 91 92 95 protected boolean showTime; 96 97 100 protected boolean hiddenShowTime; 101 102 103 106 private static final boolean ENABLE_UPLOADS = false; 107 private static final boolean SAVE_UPLOADS_TO_DISK = true; 108 private static final int MAX_UPLOAD_SIZE = 10000000; 110 113 private boolean enableUploads; 114 private boolean autoSaveUploads; 115 private boolean allowOverwrite; 116 private boolean silentlyRename; 117 private int maxUploadSize; 118 119 private File uploadDir; 120 private File workDir; 121 122 private String containerEncoding; 123 private String defaultFormEncoding; 124 125 protected javax.portlet.PortletContext portletContext; 126 protected PortletContext envPortletContext; 127 128 129 133 private boolean manageExceptions; 134 135 140 protected String portletContextPath; 141 142 145 protected String portletContextURL; 146 147 151 protected RequestFactory requestFactory; 152 153 158 protected String servletPath; 159 160 169 protected int defaultSessionScope; 170 171 174 protected boolean storeSessionPath; 175 176 194 public void init(PortletConfig conf) throws PortletException { 195 196 super.init(conf); 197 198 String value; 199 200 this.portletContext = conf.getPortletContext(); 201 this.envPortletContext = new PortletContext(this.portletContext); 202 this.portletContextPath = this.portletContext.getRealPath("/"); 203 204 final String workDirParam = getInitParameter("work-directory"); 207 if (workDirParam != null) { 208 if (this.portletContextPath == null) { 209 this.workDir = new File (workDirParam); 211 } else { 212 File workDirParamFile = new File (workDirParam); 214 if (workDirParamFile.isAbsolute()) { 215 this.workDir = workDirParamFile; 217 } else { 218 this.workDir = new File (portletContextPath, workDirParam); 220 } 221 } 222 } else { 223 this.workDir = (File ) this.portletContext.getAttribute("javax.servlet.context.tempdir"); 225 if (this.workDir == null) { 226 this.workDir = new File (this.portletContext.getRealPath("/WEB-INF/work")); 227 } 228 this.workDir = new File (workDir, "cocoon-files"); 229 } 230 this.workDir.mkdirs(); 231 232 initLogger(); 234 235 String path = this.portletContextPath; 236 if (getLogger().isDebugEnabled()) { 237 getLogger().debug("getRealPath for /: " + path); 238 } 239 if (path == null) { 240 try { 242 path = this.portletContext.getResource("/WEB-INF").toString(); 243 } catch (MalformedURLException me) { 244 throw new PortletException("Unable to get resource 'WEB-INF'.", me); 245 } 246 if (getLogger().isDebugEnabled()) { 247 getLogger().debug("getResource for /WEB-INF: " + path); 248 } 249 path = path.substring(0, path.length() - "WEB-INF".length()); 250 if (getLogger().isDebugEnabled()) { 251 getLogger().debug("Path for Root: " + path); 252 } 253 } 254 255 try { 256 if (path.indexOf(':') > 1) { 257 this.portletContextURL = path; 258 } else { 259 this.portletContextURL = new File (path).toURL().toExternalForm(); 260 } 261 } catch (MalformedURLException me) { 262 try { 266 this.portletContextURL = new File (path).toURL().toExternalForm(); 267 } catch (MalformedURLException ignored) { 268 throw new PortletException("Unable to determine portlet context URL.", me); 269 } 270 } 271 if (getLogger().isDebugEnabled()) { 272 getLogger().debug("URL for Root: " + this.portletContextURL); 273 } 274 275 final String uploadDirParam = conf.getInitParameter("upload-directory"); 276 if (uploadDirParam != null) { 277 if (this.portletContextPath == null) { 278 this.uploadDir = new File (uploadDirParam); 279 } else { 280 File uploadDirParamFile = new File (uploadDirParam); 282 if (uploadDirParamFile.isAbsolute()) { 283 this.uploadDir = uploadDirParamFile; 285 } else { 286 this.uploadDir = new File (portletContextPath, uploadDirParam); 288 } 289 } 290 if (getLogger().isDebugEnabled()) { 291 getLogger().debug("Using upload-directory " + this.uploadDir); 292 } 293 } else { 294 this.uploadDir = new File (workDir, "upload-dir" + File.separator); 295 if (getLogger().isDebugEnabled()) { 296 getLogger().debug("upload-directory was not set - defaulting to " + this.uploadDir); 297 } 298 } 299 this.uploadDir.mkdirs(); 300 301 this.enableUploads = getInitParameterAsBoolean("enable-uploads", ENABLE_UPLOADS); 302 this.autoSaveUploads = getInitParameterAsBoolean("autosave-uploads", SAVE_UPLOADS_TO_DISK); 303 304 String overwriteParam = getInitParameter("overwrite-uploads", "rename"); 305 if ("deny".equalsIgnoreCase(overwriteParam)) { 307 this.allowOverwrite = false; 308 this.silentlyRename = false; 309 } else if ("allow".equalsIgnoreCase(overwriteParam)) { 310 this.allowOverwrite = true; 311 this.silentlyRename = false; } else { 313 this.allowOverwrite = false; 315 this.silentlyRename = true; 316 } 317 318 this.maxUploadSize = getInitParameterAsInteger("upload-max-size", MAX_UPLOAD_SIZE); 319 320 value = conf.getInitParameter("show-time"); 321 this.showTime = BooleanUtils.toBoolean(value) || (this.hiddenShowTime = "hide".equals(value)); 322 if (value == null) { 323 if (getLogger().isDebugEnabled()) { 324 getLogger().debug("show-time was not set - defaulting to false"); 325 } 326 } 327 328 this.containerEncoding = getInitParameter("container-encoding", "ISO-8859-1"); 329 this.defaultFormEncoding = getInitParameter("form-encoding", "ISO-8859-1"); 330 331 this.manageExceptions = getInitParameterAsBoolean("manage-exceptions", true); 332 333 this.requestFactory = new RequestFactory(this.autoSaveUploads, 334 this.uploadDir, 335 this.allowOverwrite, 336 this.silentlyRename, 337 this.maxUploadSize, 338 this.defaultFormEncoding); 339 340 this.servletPath = getInitParameter("servlet-path", null); 341 if (this.servletPath != null) { 342 if (this.servletPath.startsWith("/")) { 343 this.servletPath = this.servletPath.substring(1); 344 } 345 if (this.servletPath.endsWith("/")) { 346 this.servletPath = servletPath.substring(0, servletPath.length() - 1); 347 } 348 } 349 350 final String sessionScopeParam = getInitParameter("default-session-scope", "portlet"); 351 if ("application".equalsIgnoreCase(sessionScopeParam)) { 352 this.defaultSessionScope = javax.portlet.PortletSession.APPLICATION_SCOPE; 353 } else { 354 this.defaultSessionScope = javax.portlet.PortletSession.PORTLET_SCOPE; 355 } 356 357 this.storeSessionPath = getInitParameterAsBoolean("store-session-path", false); 358 } 359 360 public void processAction(ActionRequest req, ActionResponse res) 361 throws PortletException, IOException { 362 363 long start = System.currentTimeMillis(); 365 366 res.setProperty("X-Cocoon-Version", Constants.VERSION); 368 369 ActionRequest request; 371 try { 372 if (this.enableUploads) { 373 request = requestFactory.getServletRequest(req); 374 } else { 375 request = req; 376 } 377 } catch (Exception e) { 378 if (getLogger().isErrorEnabled()) { 379 getLogger().error("Problem with Cocoon portlet", e); 380 } 381 382 manageException(req, res, null, null, 383 "Problem in creating the Request", null, null, e); 384 return; 385 } 386 387 Cocoon cocoon = getCocoon(); 389 390 if (cocoon == null) { 392 manageException(request, res, null, null, 393 "Initialization Problem", 394 null , 395 null , 396 this.exception); 397 return; 398 } 399 400 String servletPath = this.servletPath; 402 if (servletPath == null) { 403 servletPath = "portlets/" + getPortletConfig().getPortletName(); 404 } 405 String pathInfo = getPathInfo(request); 406 407 String uri = servletPath; 408 if (pathInfo != null) { 409 uri += pathInfo; 410 } 411 412 ContextMap ctxMap = null; 413 414 Environment env; 415 try { 416 if (uri.charAt(0) == '/') { 417 uri = uri.substring(1); 418 } 419 env = getEnvironment(servletPath, pathInfo, uri, request, res); 420 } catch (Exception e) { 421 if (getLogger().isErrorEnabled()) { 422 getLogger().error("Problem with Cocoon portlet", e); 423 } 424 425 manageException(request, res, null, uri, 426 "Problem in creating the Environment", null, null, e); 427 return; 428 } 429 430 try { 431 try { 432 ctxMap = ContextMap.getCurrentContext(); 435 String threadName = Thread.currentThread().getName(); 437 ctxMap.set("threadName", threadName); 438 ctxMap.set("objectModel", env.getObjectModel()); 440 ctxMap.set("request-id", threadName + System.currentTimeMillis()); 442 443 if (cocoon.process(env)) { 444 } else { 445 getLogger().fatalError("The Cocoon engine failed to process the request."); 448 manageException(request, res, env, uri, 449 "Request Processing Failed", 450 "Cocoon engine failed in process the request", 451 "The processing engine failed to process the request. This could be due to lack of matching or bugs in the pipeline engine.", 452 null); 453 return; 454 } 455 } catch (ResourceNotFoundException e) { 456 if (getLogger().isDebugEnabled()) { 457 getLogger().warn(e.getMessage(), e); 458 } else if (getLogger().isWarnEnabled()) { 459 getLogger().warn(e.getMessage()); 460 } 461 462 manageException(request, res, env, uri, 463 "Resource Not Found", 464 "Resource Not Found", 465 "The requested portlet could not be found", 466 e); 467 return; 468 469 } catch (ConnectionResetException e) { 470 if (getLogger().isDebugEnabled()) { 471 getLogger().debug(e.getMessage(), e); 472 } else if (getLogger().isWarnEnabled()) { 473 getLogger().warn(e.getMessage()); 474 } 475 476 } catch (IOException e) { 477 if (getLogger().isDebugEnabled()) { 479 getLogger().debug(e.getMessage(), e); 480 } else if (getLogger().isWarnEnabled()) { 481 getLogger().warn(e.getMessage()); 482 } 483 484 } catch (Exception e) { 485 if (getLogger().isErrorEnabled()) { 486 getLogger().error("Internal Cocoon Problem", e); 487 } 488 489 manageException(request, res, env, uri, 490 "Internal Server Error", null, null, e); 491 return; 492 } 493 494 long end = System.currentTimeMillis(); 495 String timeString = processTime(end - start); 496 if (getLogger().isInfoEnabled()) { 497 getLogger().info("'" + uri + "' " + timeString); 498 } 499 res.setProperty("X-Cocoon-Time", timeString); 500 } finally { 501 if (ctxMap != null) { 502 ctxMap.clear(); 503 } 504 505 try { 506 if (request instanceof MultipartActionRequest) { 507 if (getLogger().isDebugEnabled()) { 508 getLogger().debug("Deleting uploaded file(s)."); 509 } 510 ((MultipartActionRequest) request).cleanup(); 511 } 512 } catch (IOException e) { 513 getLogger().error("Cocoon got an Exception while trying to cleanup the uploaded files.", e); 514 } 515 } 516 } 517 518 522 public void render(RenderRequest req, RenderResponse res) 523 throws PortletException, IOException { 524 525 long start = System.currentTimeMillis(); 527 528 res.setProperty("X-Cocoon-Version", Constants.VERSION); 530 531 RenderRequest request = req; 533 534 Cocoon cocoon = getCocoon(); 536 537 if (cocoon == null) { 539 manageException(request, res, null, null, 540 "Initialization Problem", 541 null , 542 null , 543 this.exception); 544 return; 545 } 546 547 String servletPath = this.servletPath; 549 if (servletPath == null) { 550 servletPath = "portlets/" + getPortletConfig().getPortletName(); 551 } 552 String pathInfo = getPathInfo(request); 553 554 String uri = servletPath; 555 if (pathInfo != null) { 556 uri += pathInfo; 557 } 558 559 String contentType = null; 560 ContextMap ctxMap = null; 561 562 Environment env; 563 try { 564 if (uri.charAt(0) == '/') { 565 uri = uri.substring(1); 566 } 567 env = getEnvironment(servletPath, pathInfo, uri, request, res); 568 } catch (Exception e) { 569 if (getLogger().isErrorEnabled()) { 570 getLogger().error("Problem with Cocoon portlet", e); 571 } 572 573 manageException(request, res, null, uri, 574 "Problem in creating the Environment", null, null, e); 575 return; 576 } 577 578 try { 579 try { 580 ctxMap = ContextMap.getCurrentContext(); 583 String threadName = Thread.currentThread().getName(); 585 ctxMap.set("threadName", threadName); 586 ctxMap.set("objectModel", env.getObjectModel()); 588 ctxMap.set("request-id", threadName + System.currentTimeMillis()); 590 591 if (cocoon.process(env)) { 592 } else { 593 getLogger().fatalError("The Cocoon engine failed to process the request."); 596 manageException(request, res, env, uri, 597 "Request Processing Failed", 598 "Cocoon engine failed in process the request", 599 "The processing engine failed to process the request. This could be due to lack of matching or bugs in the pipeline engine.", 600 null); 601 return; 602 } 603 } catch (ResourceNotFoundException rse) { 604 if (getLogger().isWarnEnabled()) { 605 getLogger().warn("The resource was not found", rse); 606 } 607 608 manageException(request, res, env, uri, 609 "Resource Not Found", 610 "Resource Not Found", 611 "The requested portlet could not be found", 612 rse); 613 return; 614 615 } catch (ConnectionResetException e) { 616 if (getLogger().isDebugEnabled()) { 617 getLogger().debug(e.getMessage(), e); 618 } else if (getLogger().isWarnEnabled()) { 619 getLogger().warn(e.getMessage()); 620 } 621 622 } catch (IOException e) { 623 if (getLogger().isDebugEnabled()) { 625 getLogger().debug(e.getMessage(), e); 626 } else if (getLogger().isWarnEnabled()) { 627 getLogger().warn(e.getMessage()); 628 } 629 630 } catch (Exception e) { 631 if (getLogger().isErrorEnabled()) { 632 getLogger().error("Internal Cocoon Problem", e); 633 } 634 635 manageException(request, res, env, uri, 636 "Internal Server Error", null, null, e); 637 return; 638 } 639 640 long end = System.currentTimeMillis(); 641 String timeString = processTime(end - start); 642 if (getLogger().isInfoEnabled()) { 643 getLogger().info("'" + uri + "' " + timeString); 644 } 645 res.setProperty("X-Cocoon-Time", timeString); 646 647 if (contentType != null && contentType.equals("text/html")) { 649 String showTime = request.getParameter(Constants.SHOWTIME_PARAM); 650 boolean show = this.showTime; 651 if (showTime != null) { 652 show = !showTime.equalsIgnoreCase("no"); 653 } 654 if (show) { 655 boolean hide = this.hiddenShowTime; 656 if (showTime != null) { 657 hide = showTime.equalsIgnoreCase("hide"); 658 } 659 PrintStream out = new PrintStream (res.getPortletOutputStream()); 660 out.print((hide) ? "<!-- " : "<p>"); 661 out.print(timeString); 662 out.println((hide) ? " -->" : "</p>\n"); 663 } 664 } 665 } finally { 666 if (ctxMap != null) { 667 ctxMap.clear(); 668 } 669 670 678 } 679 } 680 681 private String getPathInfo(PortletRequest request) { 682 PortletSession session = null; 683 684 String pathInfo = request.getParameter(PortletEnvironment.PARAMETER_PATH_INFO); 685 if (storeSessionPath) { 686 session = request.getPortletSession(true); 687 if (pathInfo == null) { 688 pathInfo = (String )session.getAttribute(PortletEnvironment.PARAMETER_PATH_INFO); 689 } 690 } 691 692 if (pathInfo == null) { 694 pathInfo = "/"; 695 } else if (!pathInfo.startsWith("/")) { 696 pathInfo = '/' + pathInfo; 697 } 698 699 if (storeSessionPath) { 700 session.setAttribute(PortletEnvironment.PARAMETER_PATH_INFO, pathInfo); 701 } 702 return pathInfo; 703 } 704 705 protected void manageException(ActionRequest req, ActionResponse res, Environment env, 706 String uri, String title, String message, String description, 707 Exception e) 708 throws PortletException { 709 throw new PortletException("Exception in CocoonPortlet", e); 710 } 711 712 protected void manageException(RenderRequest req, RenderResponse res, Environment env, 713 String uri, String title, String message, String description, 714 Exception e) 715 throws IOException , PortletException { 716 if (this.manageExceptions) { 717 if (env != null) { 718 env.tryResetResponse(); 719 } else { 720 res.reset(); 721 } 722 723 String type = Notifying.FATAL_NOTIFICATION; 724 HashMap extraDescriptions = null; 725 726 extraDescriptions = new HashMap (2); 727 extraDescriptions.put(Notifying.EXTRA_REQUESTURI, getPortletConfig().getPortletName()); 728 if (uri != null) { 729 extraDescriptions.put("Request URI", uri); 730 } 731 732 if (!getLogger().isInfoEnabled()) { 734 Throwable t = DefaultNotifyingBuilder.getRootCause(e); 735 if (t != null) extraDescriptions.put(Notifying.EXTRA_CAUSE, t.getMessage()); 736 e = null; 737 } 738 739 Notifying n = new DefaultNotifyingBuilder().build(this, 740 e, 741 type, 742 title, 743 "Cocoon Portlet", 744 message, 745 description, 746 extraDescriptions); 747 748 res.setContentType("text/html"); 749 Notifier.notify(n, res.getPortletOutputStream(), "text/html"); 750 } else { 751 res.flushBuffer(); 752 throw new PortletException("Exception in CocoonPortlet", e); 753 } 754 } 755 756 759 protected Environment getEnvironment(String servletPath, 760 String pathInfo, 761 String uri, 762 ActionRequest req, 763 ActionResponse res) 764 throws Exception { 765 PortletEnvironment env; 766 767 String formEncoding = req.getParameter("cocoon-form-encoding"); 768 if (formEncoding == null) { 769 formEncoding = this.defaultFormEncoding; 770 } 771 env = new PortletEnvironment(servletPath, 772 pathInfo, 773 uri, 774 this.portletContextURL, 775 req, 776 res, 777 this.portletContext, 778 this.envPortletContext, 779 this.containerEncoding, 780 formEncoding, 781 this.defaultSessionScope); 782 env.enableLogging(getLogger()); 783 return env; 784 } 785 786 789 protected Environment getEnvironment(String servletPath, 790 String pathInfo, 791 String uri, 792 RenderRequest req, 793 RenderResponse res) 794 throws Exception { 795 PortletEnvironment env; 796 797 String formEncoding = req.getParameter("cocoon-form-encoding"); 798 if (formEncoding == null) { 799 formEncoding = this.defaultFormEncoding; 800 } 801 env = new PortletEnvironment(servletPath, 802 pathInfo, 803 uri, 804 this.portletContextURL, 805 req, 806 res, 807 this.portletContext, 808 this.envPortletContext, 809 this.containerEncoding, 810 formEncoding, 811 this.defaultSessionScope); 812 env.enableLogging(getLogger()); 813 return env; 814 } 815 816 private String processTime(long time) { 817 StringBuffer out = new StringBuffer (PROCESSED_BY); 818 if (time <= SECOND) { 819 out.append(time); 820 out.append(" milliseconds."); 821 } else if (time <= MINUTE) { 822 out.append(time / SECOND); 823 out.append(" seconds."); 824 } else if (time <= HOUR) { 825 out.append(time / MINUTE); 826 out.append(" minutes."); 827 } else { 828 out.append(time / HOUR); 829 out.append(" hours."); 830 } 831 return out.toString(); 832 } 833 834 838 private Cocoon getCocoon() { 839 return new CocoonAccess() { 840 final Cocoon instance() { 841 return super.getCocoon(); 842 } 843 }.instance(); 844 } 845 846 850 public String getInitParameter(String name) { 851 String result = super.getInitParameter(name); 852 if (result != null) { 853 result = result.trim(); 854 if (result.length() == 0) { 855 result = null; 856 } 857 } 858 859 return result; 860 } 861 862 863 protected String getInitParameter(String name, String defaultValue) { 864 String result = getInitParameter(name); 865 if (result == null) { 866 if (getLogger() != null && getLogger().isDebugEnabled()) { 867 getLogger().debug(name + " was not set - defaulting to '" + defaultValue + "'"); 868 } 869 return defaultValue; 870 } else { 871 return result; 872 } 873 } 874 875 876 protected boolean getInitParameterAsBoolean(String name, boolean defaultValue) { 877 String value = getInitParameter(name); 878 if (value == null) { 879 if (getLogger() != null && getLogger().isDebugEnabled()) { 880 getLogger().debug(name + " was not set - defaulting to '" + defaultValue + "'"); 881 } 882 return defaultValue; 883 } 884 885 return BooleanUtils.toBoolean(value); 886 } 887 888 protected int getInitParameterAsInteger(String name, int defaultValue) { 889 String value = getInitParameter(name); 890 if (value == null) { 891 if (getLogger() != null && getLogger().isDebugEnabled()) { 892 getLogger().debug(name + " was not set - defaulting to '" + defaultValue + "'"); 893 } 894 return defaultValue; 895 } else { 896 return Integer.parseInt(value); 897 } 898 } 899 900 protected void initLogger() { 901 final String accesslogger = getInitParameter("portlet-logger", "cocoon"); 902 903 final Hierarchy defaultHierarchy = Hierarchy.getDefaultHierarchy(); 904 905 final Logger logger = new LogKitLogger(Hierarchy.getDefaultHierarchy().getLoggerFor("")); 906 907 final LogKitLoggerManager logKitLoggerManager = new LogKitLoggerManager(defaultHierarchy); 908 logKitLoggerManager.enableLogging(logger); 909 910 final DefaultContext subcontext = new DefaultContext(); 911 subcontext.put(Constants.CONTEXT_WORK_DIR, workDir); 912 subcontext.put("portlet-context", this.portletContext); 913 if (this.portletContextPath == null) { 914 File logSCDir = new File (this.workDir, "log"); 915 logSCDir.mkdirs(); 916 if (getLogger().isWarnEnabled()) { 917 getLogger().warn("Setting context-root for LogKit to " + logSCDir); 918 } 919 subcontext.put("context-root", logSCDir.toString()); 920 } else { 921 subcontext.put("context-root", this.portletContextPath); 922 } 923 if ( this.portletContext instanceof PortletContextImpl ) { 924 subcontext.put("servlet-context", ((PortletContextImpl)this.portletContext).getServletContext()); 925 } 926 927 try { 928 logKitLoggerManager.contextualize(subcontext); 929 930 String logkitConfig = getInitParameter("logkit-config", "/WEB-INF/logkit.xconf"); 932 933 InputStream is = null; 935 if (logkitConfig.indexOf(':') == -1) { 936 is = this.portletContext.getResourceAsStream(logkitConfig); 937 if (is == null) is = new FileInputStream (logkitConfig); 938 } else { 939 URL logkitURL = new URL (logkitConfig); 940 is = logkitURL.openStream(); 941 } 942 final DefaultConfigurationBuilder builder = new DefaultConfigurationBuilder(); 943 final Configuration conf = builder.build(is); 944 logKitLoggerManager.configure(conf); 945 } catch (Exception e) { 946 e.printStackTrace(); 947 } 948 949 if (accesslogger != null) { 950 this.log = logKitLoggerManager.getLoggerForCategory(accesslogger); 951 } else { 952 this.log = logKitLoggerManager.getLoggerForCategory("cocoon"); 953 } 954 } 955 956 protected Logger getLogger() { 957 return this.log; 958 } 959 } 960 | Popular Tags |