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.util.template; 018 019import java.util.Map; 020 021import org.apache.wicket.Application; 022import org.apache.wicket.css.ICssCompressor; 023import org.apache.wicket.core.util.string.CssUtils; 024 025 026/** 027 * Decorates a <code>TextTemplate</code> with CSS tags. 028 * 029 * @author Eelco Hillenius 030 * @since 1.2.6 031 */ 032public final class CssTemplate extends TextTemplateDecorator 033{ 034 private static final long serialVersionUID = 1L; 035 036 /** 037 * Constructor. 038 * 039 * @param textTemplate 040 * a <code>TextTemplate</code> to decorate 041 */ 042 public CssTemplate(TextTemplate textTemplate) 043 { 044 super(textTemplate); 045 } 046 047 /** 048 * @see org.apache.wicket.util.template.TextTemplateDecorator#getBeforeTemplateContents() 049 */ 050 @Override 051 public String getBeforeTemplateContents() 052 { 053 return CssUtils.INLINE_OPEN_TAG; 054 } 055 056 /** 057 * @see org.apache.wicket.util.template.TextTemplateDecorator#getAfterTemplateContents() 058 */ 059 @Override 060 public String getAfterTemplateContents() 061 { 062 return CssUtils.INLINE_CLOSE_TAG; 063 } 064 065 /** 066 * This class decorates another <code>TextTemplate</code> class and so does not allow 067 * interpolation. 068 * 069 * @param variables 070 * ignored 071 * @return <code>this</code>, for chaining purposes 072 */ 073 @Override 074 public TextTemplate interpolate(final Map<String, ?> variables) 075 { 076 return this; 077 } 078 079 @Override 080 public String getString() 081 { 082 String nonCompressed = super.getString(); 083 084 ICssCompressor compressor = null; 085 if (Application.exists()) 086 { 087 compressor = Application.get().getResourceSettings().getCssCompressor(); 088 } 089 090 if (compressor != null) 091 { 092 return compressor.compress(nonCompressed); 093 } 094 else 095 { 096 // don't strip the comments 097 return nonCompressed; 098 } 099 } 100}