001/* 002 * This library is part of OpenCms - 003 * the Open Source Content Management System 004 * 005 * Copyright (c) Alkacon Software GmbH & Co. KG (http://www.alkacon.com) 006 * 007 * This library is free software; you can redistribute it and/or 008 * modify it under the terms of the GNU Lesser General Public 009 * License as published by the Free Software Foundation; either 010 * version 2.1 of the License, or (at your option) any later version. 011 * 012 * This library is distributed in the hope that it will be useful, 013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 015 * Lesser General Public License for more details. 016 * 017 * For further information about Alkacon Software GmbH & Co. KG, please see the 018 * company website: http://www.alkacon.com 019 * 020 * For further information about OpenCms, please see the 021 * project website: http://www.opencms.org 022 * 023 * You should have received a copy of the GNU Lesser General Public 024 * License along with this library; if not, write to the Free Software 025 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 026 */ 027 028package org.opencms.report; 029 030import org.opencms.i18n.CmsMessageContainer; 031 032import java.util.LinkedList; 033import java.util.List; 034import java.util.Locale; 035 036/** 037 * Report proxy that multiplexes to all contained <code>{@link I_CmsReport}</code> instances.<p> 038 * 039 * @since 7.5.1 040 */ 041public class CmsMultiplexReport extends A_CmsReport { 042 043 /** The reports to multiplex to. */ 044 private List<A_CmsReport> m_delegates = new LinkedList<A_CmsReport>(); 045 046 /** 047 * Default constructor.<p> 048 */ 049 public CmsMultiplexReport() { 050 051 // nop 052 } 053 054 /** 055 * Adds the given report to become a proxy delegate of this multiplexer.<p> 056 * 057 * @param report the report to be on the recipient list. 058 */ 059 public void addReport(final A_CmsReport report) { 060 061 m_delegates.add(report); 062 } 063 064 /** 065 * @see org.opencms.report.A_CmsReport#getLastEntryTime() 066 */ 067 @Override 068 public long getLastEntryTime() { 069 070 if (m_delegates.isEmpty()) { 071 return 0; 072 } 073 return m_delegates.get(0).getLastEntryTime(); 074 } 075 076 /** 077 * @see org.opencms.report.A_CmsReport#getLocale() 078 */ 079 @Override 080 public Locale getLocale() { 081 082 if (m_delegates.size() > 0) { 083 return m_delegates.get(0).getLocale(); 084 } 085 return Locale.ENGLISH; 086 } 087 088 /** 089 * This searches for the first instance of a link in the internal delegate list and 090 * returns the value of it's invocation. 091 * <p> 092 * 093 * If no such report is found an empty String will be returned. 094 * <p> 095 * 096 * @see org.opencms.report.I_CmsReport#getReportUpdate() 097 */ 098 public String getReportUpdate() { 099 100 for (I_CmsReport report : m_delegates) { 101 if (report.getClass().getName().toLowerCase().contains("html")) { 102 return report.getReportUpdate(); 103 } 104 } 105 return ""; 106 } 107 108 /** 109 * @see I_CmsReport#print(CmsMessageContainer) 110 */ 111 @Override 112 public void print(final CmsMessageContainer container) { 113 114 for (I_CmsReport report : m_delegates) { 115 report.print(container); 116 } 117 } 118 119 /** 120 * @see I_CmsReport#print(CmsMessageContainer, int) 121 */ 122 @Override 123 public void print(final CmsMessageContainer container, final int format) { 124 125 for (I_CmsReport report : m_delegates) { 126 report.print(container, format); 127 } 128 129 } 130 131 /** 132 * @see I_CmsReport#println() 133 */ 134 public void println() { 135 136 for (I_CmsReport report : m_delegates) { 137 report.println(); 138 } 139 } 140 141 /** 142 * @see I_CmsReport#println(CmsMessageContainer) 143 */ 144 @Override 145 public void println(final CmsMessageContainer container) { 146 147 for (I_CmsReport report : m_delegates) { 148 report.println(container); 149 } 150 } 151 152 /** 153 * @see I_CmsReport#println(CmsMessageContainer, int) 154 */ 155 @Override 156 public void println(final CmsMessageContainer container, final int format) { 157 158 for (I_CmsReport report : m_delegates) { 159 report.println(container, format); 160 } 161 } 162 163 /** 164 * @see I_CmsReport#println(Throwable) 165 */ 166 public void println(final Throwable t) { 167 168 // do nothing 169 } 170 171 /** 172 * @see I_CmsReport#printMessageWithParam(CmsMessageContainer, Object) 173 */ 174 @Override 175 public void printMessageWithParam(final CmsMessageContainer container, final Object param) { 176 177 for (I_CmsReport report : m_delegates) { 178 report.printMessageWithParam(container, param); 179 } 180 } 181 182 /** 183 * @see I_CmsReport#printMessageWithParam(int, int, CmsMessageContainer, Object) 184 */ 185 @Override 186 public void printMessageWithParam( 187 final int m, 188 final int n, 189 final CmsMessageContainer container, 190 final Object param) { 191 192 for (I_CmsReport report : m_delegates) { 193 report.printMessageWithParam(m, n, container, param); 194 } 195 } 196 197 /** 198 * @see I_CmsReport#resetRuntime() 199 */ 200 @Override 201 public void resetRuntime() { 202 203 for (I_CmsReport report : m_delegates) { 204 report.resetRuntime(); 205 } 206 } 207 208 /** 209 * @see org.opencms.report.A_CmsReport#print(java.lang.String, int) 210 */ 211 @Override 212 protected void print(String value, int format) { 213 214 // nop, this is a helper method in A_CmsReport just called from the other routines but not directly. 215 } 216}