1 31 32 package org.opencms.db; 33 34 import org.opencms.file.CmsProject; 35 import org.opencms.file.CmsRequestContext; 36 import org.opencms.file.CmsUser; 37 import org.opencms.file.CmsVfsException; 38 import org.opencms.flex.CmsFlexRequestContextInfo; 39 import org.opencms.i18n.CmsMessageContainer; 40 import org.opencms.main.CmsException; 41 import org.opencms.main.CmsRuntimeException; 42 import org.opencms.report.I_CmsReport; 43 import org.opencms.util.CmsRequestUtil; 44 45 54 public class CmsDbContext { 55 56 57 protected CmsFlexRequestContextInfo m_flexRequestContextInfo; 58 59 60 protected CmsRequestContext m_requestContext; 61 62 65 public CmsDbContext() { 66 67 this(null); 68 } 69 70 75 public CmsDbContext(CmsRequestContext context) { 76 77 m_requestContext = context; 78 79 if (m_requestContext != null) { 80 m_flexRequestContextInfo = (CmsFlexRequestContextInfo)m_requestContext.getAttribute(CmsRequestUtil.HEADER_LAST_MODIFIED); 81 } 82 } 83 84 87 public void clear() { 88 89 m_requestContext = null; 90 m_flexRequestContextInfo = null; 91 } 92 93 98 public CmsProject currentProject() { 99 100 return m_requestContext.currentProject(); 101 } 102 103 108 public CmsUser currentUser() { 109 110 return m_requestContext.currentUser(); 111 } 112 113 118 public CmsFlexRequestContextInfo getFlexRequestContextInfo() { 119 120 return m_flexRequestContextInfo; 121 } 122 123 128 public CmsRequestContext getRequestContext() { 129 130 return m_requestContext; 131 } 132 133 138 public boolean isDefaultDbContext() { 139 140 return true; 141 } 142 143 148 public void pop() throws CmsException { 149 150 if (!isDefaultDbContext()) { 151 throw new CmsException(Messages.get().container(Messages.ERR_PROCESS_DB_CONTEXT_0)); 152 } 153 } 154 155 166 public String removeSiteRoot(String resourcename) { 167 168 if (m_requestContext != null) { 169 return m_requestContext.removeSiteRoot(resourcename); 170 } 171 172 return resourcename; 173 } 174 175 185 public void report(I_CmsReport report, CmsMessageContainer message, Throwable throwable) 186 throws CmsVfsException, CmsException { 187 188 if (report != null) { 189 if (message != null) { 190 report.println(message, I_CmsReport.FORMAT_ERROR); 191 } 192 if (throwable != null) { 193 report.println(throwable); 194 } 195 } 196 197 throwException(message, throwable); 198 } 199 200 210 void throwException(CmsMessageContainer message, Throwable throwable) throws CmsVfsException, CmsException { 211 212 if (throwable instanceof CmsException) { 213 throw ((CmsException)throwable).createException(message, throwable); 214 } else if (throwable instanceof CmsRuntimeException) { 215 throw ((CmsRuntimeException)throwable).createException(message, throwable); 216 } else { 217 throw new CmsVfsException(message, throwable); 218 } 219 } 220 } | Popular Tags |