1 31 32 package org.opencms.frontend.templateone; 33 34 import org.opencms.main.CmsLog; 35 import org.opencms.util.CmsStringUtil; 36 import org.opencms.xml.content.CmsXmlContent; 37 import org.opencms.xml.types.I_CmsXmlContentValue; 38 39 import java.util.ArrayList ; 40 import java.util.List ; 41 import java.util.Locale ; 42 import java.util.StringTokenizer ; 43 44 import javax.servlet.http.HttpServletRequest ; 45 import javax.servlet.http.HttpServletResponse ; 46 import javax.servlet.jsp.PageContext ; 47 48 import org.apache.commons.logging.Log; 49 50 59 public class CmsTemplateStyleSheet extends CmsTemplateBase { 60 61 62 public static final String FILENAME_CONFIGFILE = "configuration_css"; 63 64 65 public static final String NODE_OPTIONALCONFIG = "StyleOptional"; 66 67 68 public static final String PARAM_CONFIGFILE = "config"; 69 70 71 public static final String PROPERTY_CONFIGFILE = "properties_style"; 72 73 74 private static final Log LOG = CmsLog.getLog(CmsTemplateStyleSheet.class); 75 76 77 private CmsXmlContent m_configuration; 78 79 80 private List m_headlineSizes; 81 82 83 private String m_resPath; 84 85 86 private String m_templateWidth; 87 88 91 public CmsTemplateStyleSheet() { 92 93 super(); 94 } 95 96 105 public CmsTemplateStyleSheet(PageContext context, HttpServletRequest req, HttpServletResponse res) { 106 107 super(); 108 init(context, req, res); 109 } 110 111 118 public static String calculateHeight(String value, int delta) { 119 120 String newHeight = value; 121 try { 122 int val = Integer.parseInt(value); 123 newHeight = "" + (val + delta); 124 } catch (Exception e) { 125 } 127 return newHeight; 128 } 129 130 137 public String getConfigValue(String key, String defaultValue) { 138 139 String value = null; 140 try { 141 value = m_configuration.getStringValue(getCmsObject(), key, getRequestContext().getLocale()); 142 if (CmsStringUtil.isEmpty(value)) { 143 value = m_configuration.getStringValue(getCmsObject(), key, (Locale )m_configuration.getLocales().get(0)); 145 } 146 } catch (Exception e) { 147 if (LOG.isDebugEnabled()) { 149 LOG.debug(e.getMessage(), e); 150 } 151 } 152 if (CmsStringUtil.isEmpty(value)) { 153 value = defaultValue; 155 } 156 return value; 157 } 158 159 169 public String getFontUnderline(String key, String defaultValue) { 170 171 String value = getOptionalConfigValue(key, defaultValue); 172 if (Boolean.valueOf(value).booleanValue()) { 173 value = "underline;"; 174 } else { 175 value = "none;"; 176 } 177 return "text-decoration: " + value; 178 } 179 180 190 public String getFontWeight(String key, String defaultValue) { 191 192 String value = getOptionalConfigValue(key, defaultValue); 193 if (Boolean.valueOf(value).booleanValue()) { 194 value = "bold;"; 195 } else { 196 value = "normal;"; 197 } 198 return "font-weight: " + value; 199 } 200 201 207 public String getHeadlineSize(int headline) { 208 209 String size = (String )getHeadlineSizes().get(headline - 1); 210 if (CmsStringUtil.isEmpty(size)) { 211 size = "13"; 212 } 213 return size; 214 } 215 216 223 public String getOptionalConfigValue(String key, String defaultValue) { 224 225 return getConfigValue(NODE_OPTIONALCONFIG + "/" + key, defaultValue); 226 } 227 228 233 public String getResourcePath() { 234 235 return m_resPath; 236 } 237 238 243 public String getTemplateWidth() { 244 245 if (m_templateWidth == null) { 246 String templateType = getConfigValue("main.template.type", "normal"); 247 if ("small".equals(templateType)) { 248 m_templateWidth = "800"; 249 } else { 250 m_templateWidth = "950"; 251 } 252 } 253 return m_templateWidth; 254 } 255 256 266 public void init(PageContext context, HttpServletRequest req, HttpServletResponse res) { 267 268 super.init(context, req, res); 270 String siteRoot = req.getParameter(CmsTemplateBean.PARAM_SITE); 272 if (CmsStringUtil.isNotEmpty(siteRoot)) { 273 getRequestContext().setSiteRoot(siteRoot); 274 } 275 m_resPath = req.getParameter(CmsTemplateNavigation.PARAM_RESPATH); 277 278 try { 280 String configUri = req.getParameter(PARAM_CONFIGFILE); 281 if (CmsStringUtil.isNotEmpty(configUri)) { 282 m_configuration = CmsTemplateBean.getConfigurationFile(configUri, getCmsObject()); 283 } 284 } catch (Exception e) { 285 if (LOG.isDebugEnabled()) { 287 LOG.debug(e.getMessage(), e); 288 } 289 } 290 } 291 292 299 private List getHeadlineSizes() { 300 301 if (m_headlineSizes == null) { 302 List sizes = new ArrayList (6); 303 String selectedValues = getOptionalConfigValue("headlines.set", ""); 305 if (CmsStringUtil.isEmpty(selectedValues)) { 306 try { 308 CmsXmlContent conf = m_configuration; 309 if (conf != null) { 310 conf.addValue(getCmsObject(), NODE_OPTIONALCONFIG, getRequestContext().getLocale(), 0); 312 I_CmsXmlContentValue value = conf.getValue( 313 NODE_OPTIONALCONFIG + "/headlines.set", 314 getRequestContext().getLocale()); 315 selectedValues = value.getContentDefinition().getContentHandler().getConfiguration(value); 317 selectedValues = selectedValues.substring(0, selectedValues.indexOf('*')); 319 } else { 320 selectedValues = "13-12-11-10-9-9"; 321 } 322 } catch (Exception e) { 323 selectedValues = "13-12-11-10-9-9"; 324 } 325 } 326 StringTokenizer T = new StringTokenizer (selectedValues, "-"); 328 while (T.hasMoreTokens()) { 329 sizes.add(T.nextToken()); 330 } 331 m_headlineSizes = sizes; 332 } 333 return m_headlineSizes; 334 } 335 } | Popular Tags |