1 31 32 package org.opencms.loader; 33 34 import org.opencms.file.CmsFile; 35 import org.opencms.file.CmsObject; 36 import org.opencms.file.CmsResource; 37 import org.opencms.main.CmsException; 38 import org.opencms.main.CmsLog; 39 import org.opencms.main.CmsRuntimeException; 40 import org.opencms.main.OpenCms; 41 import org.opencms.util.CmsStringUtil; 42 43 import java.io.IOException ; 44 import java.util.Locale ; 45 import java.util.Map ; 46 47 import javax.servlet.ServletRequest ; 48 import javax.servlet.ServletResponse ; 49 import javax.servlet.http.HttpServletRequest ; 50 import javax.servlet.http.HttpServletResponse ; 51 52 61 public class CmsPointerLoader implements I_CmsResourceLoader { 62 63 64 public static final int RESOURCE_LOADER_ID = 4; 65 66 67 private static String EXPORT_PREFIX = "<html>\n<head>\n<meta http-equiv=" 68 + '"' 69 + "refresh" 70 + '"' 71 + " content=" 72 + '"' 73 + "0; url="; 74 75 76 private static String EXPORT_SUFFIX = '"' + ">\n</head>\n<body></body>\n</html>"; 77 78 81 public CmsPointerLoader() { 82 83 } 85 86 89 public void addConfigurationParameter(String paramName, String paramValue) { 90 91 } 93 94 97 public void destroy() { 98 99 } 101 102 105 public byte[] dump( 106 CmsObject cms, 107 CmsResource resource, 108 String element, 109 Locale locale, 110 HttpServletRequest req, 111 HttpServletResponse res) throws CmsException { 112 113 return CmsFile.upgrade(resource, cms).getContents(); 114 } 115 116 119 public byte[] export(CmsObject cms, CmsResource resource, HttpServletRequest req, HttpServletResponse res) 120 throws IOException , CmsException { 121 122 String pointer = new String (CmsFile.upgrade(resource, cms).getContents()); 123 StringBuffer result = new StringBuffer (128); 124 result.append(EXPORT_PREFIX); 125 if (pointer.indexOf(':') < 0) { 126 result.append(OpenCms.getLinkManager().substituteLink(cms, pointer)); 127 } else { 128 result.append(pointer); 129 } 130 result.append(EXPORT_SUFFIX); 131 load(cms, resource, req, res); 132 return result.toString().getBytes(OpenCms.getSystemInfo().getDefaultEncoding()); 133 } 134 135 141 public Map getConfiguration() { 142 143 return null; 144 } 145 146 149 public int getLoaderId() { 150 151 return RESOURCE_LOADER_ID; 152 } 153 154 161 public String getResourceLoaderInfo() { 162 163 return Messages.get().getBundle().key(Messages.GUI_LOADER_POINTER_DEFAULT_DESC_0); 164 } 165 166 169 public void initConfiguration() { 170 171 if (CmsLog.INIT.isInfoEnabled()) { 172 CmsLog.INIT.info(Messages.get().getBundle().key( 173 Messages.INIT_LOADER_INITIALIZED_1, 174 this.getClass().getName())); 175 } 176 } 177 178 181 public boolean isStaticExportEnabled() { 182 183 return true; 184 } 185 186 189 public boolean isStaticExportProcessable() { 190 191 return false; 192 } 193 194 197 public boolean isUsableForTemplates() { 198 199 return false; 200 } 201 202 205 public boolean isUsingUriWhenLoadingTemplate() { 206 207 return false; 208 } 209 210 213 public void load(CmsObject cms, CmsResource resource, HttpServletRequest req, HttpServletResponse res) 214 throws IOException , CmsException { 215 216 if (res == null || res.isCommitted()) { 217 return; 219 } 220 221 String pointer = new String (CmsFile.upgrade(resource, cms).getContents()); 222 if (CmsStringUtil.isEmptyOrWhitespaceOnly(pointer)) { 223 throw new CmsLoaderException(Messages.get().container( 224 Messages.ERR_INVALID_POINTER_FILE_1, 225 resource.getName())); 226 } 227 if (pointer.indexOf(':') < 0) { 228 pointer = OpenCms.getLinkManager().substituteLink(cms, pointer); 229 } 230 231 res.sendRedirect(pointer); 232 } 233 234 237 public void service(CmsObject cms, CmsResource file, ServletRequest req, ServletResponse res) { 238 239 throw new CmsRuntimeException( 240 Messages.get().container(Messages.ERR_SERVICE_UNSUPPORTED_1, getClass().getName())); 241 } 242 } | Popular Tags |