1 31 32 package org.opencms.jsp; 33 34 import org.opencms.flex.CmsFlexController; 35 import org.opencms.jsp.decorator.CmsDecoratorConfiguration; 36 import org.opencms.jsp.decorator.CmsHtmlDecorator; 37 import org.opencms.main.CmsLog; 38 import org.opencms.util.CmsStringUtil; 39 40 import java.util.Iterator ; 41 import java.util.List ; 42 import java.util.Locale ; 43 44 import javax.servlet.ServletRequest ; 45 import javax.servlet.jsp.JspException ; 46 import javax.servlet.jsp.tagext.BodyTagSupport ; 47 48 import org.apache.commons.logging.Log; 49 50 60 public class CmsJspTagDecorate extends BodyTagSupport { 61 62 63 private static final Log LOG = CmsLog.getLog(CmsJspTagDecorate.class); 64 65 66 private static final long serialVersionUID = 3072561342127379294L; 67 68 69 private String m_file; 70 71 72 private String m_locale; 73 74 75 private List m_noAutoCloseTags; 76 77 90 public String decorateTagAction(String content, String configFile, String locale, ServletRequest req) { 91 92 try { 93 Locale loc = null; 94 CmsFlexController controller = CmsFlexController.getController(req); 95 if (CmsStringUtil.isEmpty(locale)) { 96 loc = controller.getCmsObject().getRequestContext().getLocale(); 97 } else { 98 loc = new Locale (locale); 99 } 100 101 String encoding = controller.getCmsObject().getRequestContext().getEncoding(); 102 CmsDecoratorConfiguration config = new CmsDecoratorConfiguration(controller.getCmsObject(), configFile, loc); 103 CmsHtmlDecorator decorator = new CmsHtmlDecorator(config); 104 decorator.setNoAutoCloseTags(m_noAutoCloseTags); 105 return decorator.doDecoration(content, encoding); 106 } catch (Exception e) { 107 if (LOG.isErrorEnabled()) { 108 LOG.error(Messages.get().getBundle().key(Messages.ERR_PROCESS_TAG_1, "decoration"), e); 109 } 110 return content; 111 } 112 } 113 114 119 public int doEndTag() throws JspException { 120 121 ServletRequest req = pageContext.getRequest(); 122 123 if (CmsFlexController.isCmsRequest(req)) { 125 try { 126 String content = decorateTagAction(getBodyContent().getString(), getFile(), getLocale(), req); 127 getBodyContent().clear(); 128 getBodyContent().print(content); 129 getBodyContent().writeOut(pageContext.getOut()); 130 131 } catch (Exception ex) { 132 if (LOG.isErrorEnabled()) { 133 LOG.error(Messages.get().getBundle().key(Messages.ERR_PROCESS_TAG_1, "decoration"), ex); 134 } 135 throw new JspException (ex); 136 } 137 } 138 return EVAL_PAGE; 139 } 140 141 146 public String getFile() { 147 148 return m_file; 149 } 150 151 156 public String getLocale() { 157 158 return m_locale; 159 } 160 161 171 public String getNoAutoCloseTags() { 172 173 StringBuffer result = new StringBuffer (); 174 if (m_noAutoCloseTags != null & m_noAutoCloseTags.size() > 0) { 175 Iterator it = m_noAutoCloseTags.iterator(); 176 while (it.hasNext()) { 177 result.append(it.next()).append(','); 178 } 179 } 180 return result.toString(); 181 } 182 183 188 public void setFile(String file) { 189 190 if (file != null) { 191 m_file = file.toLowerCase(); 192 } 193 } 194 195 200 public void setLocale(String locale) { 201 202 m_locale = locale; 203 } 204 205 214 public void setNoAutoCloseTags(String noAutoCloseTagList) { 215 216 m_noAutoCloseTags = CmsStringUtil.splitAsList(noAutoCloseTagList, ','); 217 218 } 219 } 220 | Popular Tags |