001/* 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache License, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017package org.apache.wicket.core.request.handler.logger; 018 019import org.apache.wicket.request.handler.resource.ResourceLogData; 020import org.apache.wicket.request.handler.resource.ResourceStreamRequestHandler; 021import org.apache.wicket.request.resource.ContentDisposition; 022import org.apache.wicket.util.resource.IResourceStream; 023 024/** 025 * Contains logging data for resource stream requests, handled by 026 * {@link ResourceStreamRequestHandler}. 027 * 028 * @author Emond Papegaaij 029 */ 030public class ResourceStreamLogData extends ResourceLogData 031{ 032 private static final long serialVersionUID = 1L; 033 034 private final Class<? extends IResourceStream> resourceStreamClass; 035 private final ContentDisposition contentDisposition; 036 private final String contentType; 037 038 /** 039 * Construct. 040 * 041 * @param streamHandler 042 */ 043 public ResourceStreamLogData(ResourceStreamRequestHandler streamHandler) 044 { 045 super(streamHandler.getFileName(), null, null, null); 046 contentDisposition = streamHandler.getContentDisposition(); 047 resourceStreamClass = null; 048 contentType = null; 049 } 050 051 /** 052 * Construct. 053 * 054 * @param streamHandler 055 * @param stream 056 */ 057 public ResourceStreamLogData(ResourceStreamRequestHandler streamHandler, IResourceStream stream) 058 { 059 super(streamHandler.getFileName(), stream.getLocale(), stream.getStyle(), 060 stream.getVariation()); 061 contentDisposition = streamHandler.getContentDisposition(); 062 resourceStreamClass = stream.getClass(); 063 contentType = stream.getContentType(); 064 } 065 066 /** 067 * Returns the class of the resource stream. 068 * 069 * @return The class of the resource stream. 070 */ 071 public final Class<? extends IResourceStream> getResourceStreamClass() 072 { 073 return resourceStreamClass; 074 } 075 076 /** 077 * @return contentDisposition. 078 */ 079 public final ContentDisposition getContentDisposition() 080 { 081 return contentDisposition; 082 } 083 084 /** 085 * @return contentType 086 */ 087 public final String getContentType() 088 { 089 return contentType; 090 } 091 092 @Override 093 public String toString() 094 { 095 StringBuilder sb = new StringBuilder("{"); 096 fillToString(sb); 097 sb.append(",contentDisposition="); 098 sb.append(getContentDisposition()); 099 if (getResourceStreamClass() != null) 100 { 101 sb.append(",resourceStreamClass="); 102 sb.append(getResourceStreamClass().getName()); 103 sb.append(",contentType="); 104 sb.append(getContentType()); 105 } 106 sb.append("}"); 107 return sb.toString(); 108 } 109}