1 20 21 package com.methodhead.shim; 22 23 import javax.servlet.jsp.JspException ; 24 import javax.servlet.jsp.tagext.TagSupport ; 25 import javax.servlet.http.HttpServletRequest ; 26 import java.io.IOException ; 27 import com.methodhead.util.ServletUtils; 28 import com.methodhead.sitecontext.SiteContext; 29 import com.methodhead.shim.ShimUtils; 30 31 public class HeadTag 32 extends 33 TagSupport { 34 35 37 39 41 43 public int doStartTag() 44 throws 45 JspException { 46 47 try { 48 49 if ( pageContext.getRequest().getAttribute( 53 ShimGlobals.PANELMAP_KEY ) != null ) 54 return SKIP_BODY; 55 56 HttpServletRequest request = ( HttpServletRequest )pageContext.getRequest(); 60 61 Page page = ( Page )pageContext.getRequest().getAttribute( ShimGlobals.PAGE_KEY ); 62 63 String mode = ( String )pageContext.getSession().getAttribute( ShimGlobals.MODE_KEY ); 64 65 SiteContext siteContext = SiteContext.getContext( request ); 66 67 String siteContextPath = siteContext.getString( "path" ); 68 if ( !siteContextPath.equals( "" ) ) { 69 siteContextPath = "/" + siteContextPath; 70 } 71 72 pageContext.getOut().println( "<head>" ); 76 77 if ( ShimGlobals.MODE_EDIT.equals( mode ) || ShimGlobals.MODE_RICHEDIT.equals( mode ) ) { 81 82 pageContext.getOut().println( "<base HREF=\"http://" + siteContext.getDomains().get( 0 ) + ":" + request.getServerPort() + request.getContextPath() + siteContextPath + "/\"/>" ); 88 } 89 else { 90 91 pageContext.getOut().println( "<base HREF=\"" + ServletUtils.getBaseUrl( request ) + siteContextPath + "/\"/>" ); 95 } 96 97 if ( !"".equals( page.getString( "alttitle" ) ) ) 101 pageContext.getOut().println( 102 "<title>" + page.getString( "alttitle" ) + "</title>" ); 103 else 104 pageContext.getOut().println( 105 "<title>" + page.getString( "title" ) + "</title>" ); 106 107 if ( !"".equals( page.getString( "metadescription" ) ) ) 111 pageContext.getOut().println( 112 "<meta name=\"description\" content=\"" + 113 page.getString( "metadescription" ) + "\"/>" ); 114 115 if ( !"".equals( page.getString( "metakeywords" ) ) ) 116 pageContext.getOut().println( 117 "<meta name=\"keywords\" content=\"" + 118 page.getString( "metakeywords" ) + "\"/>" ); 119 } 120 catch ( IOException e ) { 121 throw new JspException ( 122 "Unexpected IOException: " + e.toString() ); 123 } 124 125 return EVAL_BODY_INCLUDE; 126 } 127 128 public int doEndTag() 129 throws 130 JspException { 131 132 try { 133 pageContext.getOut().println( "</head>" ); 134 } 135 catch ( IOException e ) { 136 throw new JspException ( 137 "Unexpected IOException: " + e.toString() ); 138 } 139 140 return EVAL_PAGE; 141 } 142 143 145 } 147 | Popular Tags |