001 package net.sf.jolene.dom; 002 003 import net.sf.jolene.constants.Tags; 004 005 /** 006 * An element in the header in a html document. Usually a meta, script, link or style tag. 007 * 008 * @author Dan Howard 009 * @since Sep 19, 2006 9:11:49 AM 010 */ 011 public final class Header extends HTMLElement { 012 013 /** 014 * Default construcor. 015 */ 016 public Header() { 017 tag = Tags.meta; 018 } 019 020 /** 021 * Construct a Header using a predefined Tag. Note the shoot in the footness here. You can define a header with 022 * any defined Tag. Really you should only use meta, link, script or style. 023 * 024 * @param tag A Tag enum. Usually script, link, meta. 025 */ 026 public Header(Tags tag) { 027 this(); 028 this.tag = tag; 029 } 030 031 032 /** 033 * Returns a clone of the header element object. 034 * 035 * @return Header object. 036 */ 037 @Override 038 public Header clone() { 039 return (Header) super.clone(); 040 } 041 042 @Override 043 public void setValue(String value) { 044 super.setValue(value); 045 setContent(value); 046 } 047 048 049 /** 050 * Renders the Header. 051 * 052 * @return The header element as a html string. 053 */ 054 @Override 055 public String toString() { 056 057 if (swapWith != null) { 058 return swapWith.toString(); 059 } 060 061 if (Tags.script == tag || Tags.style == tag) { 062 return super.toString() + getContent() + "</" + tag + '>'; 063 } 064 return super.toString(); 065 } 066 }