1 9 10 package com.opensymphony.module.sitemesh.mapper; 11 12 import com.opensymphony.module.sitemesh.Decorator; 13 14 import java.io.File ; 15 import java.net.MalformedURLException ; 16 import java.net.URL ; 17 import javax.servlet.http.HttpServletRequest ; 18 19 30 public class FileDecoratorMapper extends AbstractDecoratorMapper { 31 private static boolean pathNotAvailable = false; 32 33 public Decorator getNamedDecorator(HttpServletRequest req, String name) { 34 if (pathNotAvailable || name == null) { 35 return super.getNamedDecorator(req, name); 36 } 37 38 URL resourcePath = null; 39 40 try { 42 resourcePath = config.getServletContext().getResource('/' + name); 43 } 44 catch (MalformedURLException e) { 45 e.printStackTrace(); 46 return super.getNamedDecorator(req, name); 47 } 48 49 String filePath = config.getServletContext().getRealPath(name); 50 51 if (filePath == null && resourcePath == null) { 52 pathNotAvailable = true; 53 return super.getNamedDecorator(req, name); 54 } 55 else if (filePath != null) { File file = new File (filePath); 57 58 if (file.exists() && file.canRead()) { 59 return new DefaultDecorator(name, name, null); 61 } 62 else { 63 return super.getNamedDecorator(req, name); 65 } 66 } 67 else { 68 return new DefaultDecorator(name, name, null); 70 } 71 } 72 } | Popular Tags |