1 31 32 package org.opencms.workplace.editors; 33 34 import org.opencms.file.CmsFile; 35 import org.opencms.file.CmsObject; 36 import org.opencms.file.CmsResourceFilter; 37 import org.opencms.jsp.CmsJspActionElement; 38 import org.opencms.jsp.CmsJspNavBuilder; 39 import org.opencms.jsp.CmsJspNavElement; 40 import org.opencms.main.CmsException; 41 import org.opencms.main.CmsLog; 42 43 import java.io.ByteArrayInputStream ; 44 import java.io.IOException ; 45 import java.io.InputStream ; 46 import java.util.List ; 47 import java.util.Map ; 48 import java.util.Properties ; 49 50 import org.apache.commons.collections.map.LRUMap; 51 import org.apache.commons.logging.Log; 52 53 81 public class CmsEditorDisplayOptions { 82 83 84 public static final String FOLDER_EDITORCONFIGURATION = CmsEditor.PATH_EDITORS + "configuration/"; 85 86 87 public static final String NO_MAPPING_FOR_USER = "na"; 88 89 90 public static final int SIZE_CONFIGURATIONFILES = 12; 91 92 93 public static final int SIZE_USERENTRIES = 100; 94 95 96 private static final Log LOG = CmsLog.getLog(CmsEditorDisplayOptions.class); 97 98 99 private Map m_loadedConfigurations; 100 101 102 private Map m_userMappings; 103 104 107 public CmsEditorDisplayOptions() { 108 109 m_userMappings = new LRUMap(SIZE_USERENTRIES); 111 m_loadedConfigurations = new LRUMap(SIZE_CONFIGURATIONFILES); 112 } 113 114 126 public Properties getDisplayOptions(CmsJspActionElement jsp) { 127 128 return getDisplayOptions(jsp.getCmsObject()); 129 } 130 131 143 public Properties getDisplayOptions(CmsObject cms) { 144 145 String mappedConfigFile = (String )m_userMappings.get(cms.getRequestContext().currentUser().getName()); 147 Properties displayOptions; 148 if (mappedConfigFile == null) { 149 List items = CmsJspNavBuilder.getNavigationForFolder(cms, FOLDER_EDITORCONFIGURATION); 151 if (items.size() > 0) { 152 CmsJspNavElement nav = (CmsJspNavElement)items.get(0); 154 mappedConfigFile = nav.getFileName(); 155 synchronized (m_loadedConfigurations) { 156 displayOptions = (Properties )m_loadedConfigurations.get(nav.getFileName()); 158 if (displayOptions == null) { 159 try { 161 CmsFile optionFile = cms.readFile( 163 nav.getResourceName(), 164 CmsResourceFilter.IGNORE_EXPIRATION); 165 InputStream in = new ByteArrayInputStream (optionFile.getContents()); 166 displayOptions = new Properties (); 167 displayOptions.load(in); 168 m_loadedConfigurations.put(nav.getFileName(), displayOptions); 170 } catch (CmsException e) { 171 if (LOG.isInfoEnabled()) { 173 LOG.info(e); 174 } 175 mappedConfigFile = NO_MAPPING_FOR_USER; 176 displayOptions = null; 177 } catch (IOException e) { 178 if (LOG.isInfoEnabled()) { 180 LOG.info(e); 181 } 182 mappedConfigFile = NO_MAPPING_FOR_USER; 183 displayOptions = null; 184 } 185 } 186 } 187 } else { 188 mappedConfigFile = NO_MAPPING_FOR_USER; 190 displayOptions = null; 191 } 192 if (LOG.isDebugEnabled()) { 193 LOG.debug(Messages.get().getBundle().key( 195 Messages.LOG_MAP_CONFIG_FILE_TO_USER_2, 196 mappedConfigFile, 197 cms.getRequestContext().currentUser().getName())); 198 } 199 m_userMappings.put(cms.getRequestContext().currentUser().getName(), mappedConfigFile); 201 } else { 202 displayOptions = (Properties )m_loadedConfigurations.get(mappedConfigFile); 204 } 205 return displayOptions; 207 } 208 209 216 public boolean showElement(String key, Properties displayOptions) { 217 218 return (displayOptions != null && Boolean.valueOf(displayOptions.getProperty(key)).booleanValue()); 219 } 220 221 } 222 | Popular Tags |