001package com.hfg.html; 002 003 004import com.hfg.xml.XMLContainerImpl; 005import com.hfg.xml.XMLException; 006 007import java.io.IOException; 008import java.io.OutputStream; 009import java.io.Writer; 010 011//------------------------------------------------------------------------------ 012/** 013 Conditional html comment for use with Internet Explorer. 014 <p> 015 See <a href='http://en.wikipedia.org/wiki/Conditional_comment'>http://en.wikipedia.org/wiki/Conditional_comment</a> 016 </p> 017 @author J. Alex Taylor, hairyfatguy.com 018 */ 019//------------------------------------------------------------------------------ 020// com.hfg XML/HTML Coding Library 021// 022// This library is free software; you can redistribute it and/or 023// modify it under the terms of the GNU Lesser General Public 024// License as published by the Free Software Foundation; either 025// version 2.1 of the License, or (at your option) any later version. 026// 027// This library is distributed in the hope that it will be useful, 028// but WITHOUT ANY WARRANTY; without even the implied warranty of 029// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 030// Lesser General Public License for more details. 031// 032// You should have received a copy of the GNU Lesser General Public 033// License along with this library; if not, write to the Free Software 034// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 035// 036// J. Alex Taylor, President, Founder, CEO, COO, CFO, OOPS hairyfatguy.com 037// jataylor@hairyfatguy.com 038//------------------------------------------------------------------------------ 039 040public class IEConditionalComment extends XMLContainerImpl 041{ 042 private String mIfExpression; 043 044 //########################################################################## 045 // CONSTRUCTORS 046 //########################################################################## 047 048 //-------------------------------------------------------------------------- 049 /** 050 * Constructs an IE conditional comment. 051 * @param inIfExpression Content of the 'if' expression (ex: 'IE'). 052 */ 053 public IEConditionalComment(String inIfExpression) 054 { 055 mIfExpression = inIfExpression; 056 057 } 058 059 060 //########################################################################## 061 // PUBLIC METHODS 062 //########################################################################## 063 064 //--------------------------------------------------------------------------- 065 public String toXML() 066 { 067 return "<!--[if " + mIfExpression + "]>" + innerHTML() + "<![endif]-->"; 068 } 069 070 //--------------------------------------------------------------------------- 071 public void toXML(Writer inWriter) 072 { 073 try 074 { 075 inWriter.write(toXML()); 076 } 077 catch (IOException e) 078 { 079 throw new RuntimeException(e); 080 } 081 } 082 083 //--------------------------------------------------------------------------- 084 public void toXML(OutputStream inStream) 085 { 086 try 087 { 088 inStream.write(toXML().getBytes()); 089 } 090 catch (Exception e) 091 { 092 throw new XMLException(e); 093 } 094 } 095 096 097 098 //-------------------------------------------------------------------------- 099 public String toIndentedXML(int inInitialIndentLevel, int inIndentSize) 100 { 101 return toXML(); 102 } 103 104 //-------------------------------------------------------------------------- 105 public void toIndentedXML(OutputStream inOutputStream, int inInitialIndentLevel, int inIndentSize) 106 { 107 toXML(inOutputStream); 108 } 109 110 //-------------------------------------------------------------------------- 111 public void toIndentedXML(Writer inWriter, int inInitialIndentLevel, int inIndentSize) 112 { 113 toXML(inWriter); 114 } 115 116 117}