public void init(FilterConfig filterConfig) { this.filterConfig = filterConfig; super.init(filterConfig); ServletContext sc = filterConfig.getServletContext(); Factory instance = (Factory) sc.getAttribute(SITEMESH_FACTORY); if (instance == null) { sc.setAttribute(SITEMESH_FACTORY, new StrutsSiteMeshFactory(new Config(filterConfig))); } }
public DefaultFactory(Config config) { super(config); configFileName = config.getServletContext().getInitParameter("sitemesh.configfile"); if (configFileName == null) { configFileName = DEFAULT_CONFIG_FILENAME; } // configFilePath is null if loaded from war file String initParamConfigFile = config.getConfigFile(); if(initParamConfigFile != null) { configFileName = initParamConfigFile; } String configFilePath = config.getServletContext().getRealPath(configFileName); if (configFilePath != null) { // disable config auto reloading for .war files configFile = new File(configFilePath); } loadConfig(); }
/** * Create new ConfigLoader using supplied filename and config. */ public ConfigLoader(String configFileName, Config config) throws ServletException { this.config = config; this.configFileName = configFileName; if (config.getServletContext().getRealPath(configFileName) != null) { this.configFile = new File(config.getServletContext().getRealPath(configFileName)); } state = loadConfig(); }
private Element loadSitemeshXML() throws ParserConfigurationException, IOException, SAXException { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = factory.newDocumentBuilder(); InputStream is = null; if (configFile == null) { is = config.getServletContext().getResourceAsStream(configFileName); } else if (configFile.exists() && configFile.canRead()) { is = configFile.toURL().openStream(); } if (is == null){ // load the default sitemesh configuration is = getClass().getClassLoader().getResourceAsStream("com/opensymphony/module/sitemesh/factory/sitemesh-default.xml"); } if (is == null){ // load the default sitemesh configuration using another classloader is = Thread.currentThread().getContextClassLoader().getResourceAsStream("com/opensymphony/module/sitemesh/factory/sitemesh-default.xml"); } if (is == null){ throw new IllegalStateException("Cannot load default configuration from jar"); } if (configFile != null) configLastModified = configFile.lastModified(); Document doc = builder.parse(is); Element root = doc.getDocumentElement(); // Verify root element if (!"sitemesh".equalsIgnoreCase(root.getTagName())) { throw new FactoryException("Root element of sitemesh configuration file not <sitemesh>", null); } return root; }
/** * Returns a Sitemesh Factory object. * @return */ protected Factory getSitemeshFactory() { ServletConfig servletConfig = JspSupportServlet.jspSupportServlet.getServletConfig(); Config config = new Config(servletConfig); Factory factory = Factory.getInstance(config); return factory; }
private void loadExcludes() throws ParserConfigurationException, IOException, SAXException { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = factory.newDocumentBuilder(); InputStream is = null; if (excludesFile == null) { is = config.getServletContext().getResourceAsStream(excludesFileName); } else if (excludesFile.exists() && excludesFile.canRead()) { is = excludesFile.toURL().openStream(); } if (is == null){ throw new IllegalStateException("Cannot load excludes configuration file \"" + excludesFileName + "\" as specified in \"sitemesh.xml\" or \"sitemesh-default.xml\""); } Document document = builder.parse(is); Element root = document.getDocumentElement(); NodeList sections = root.getChildNodes(); // Loop through child elements of root node looking for the <excludes> block for (int i = 0; i < sections.getLength(); i++) { if (sections.item(i) instanceof Element) { Element curr = (Element)sections.item(i); if ("excludes".equalsIgnoreCase(curr.getTagName())) { loadExcludeUrls(curr.getChildNodes()); } } } }
protected ContentProcessor initContentProcessor(SiteMeshWebAppContext webAppContext) { // TODO: Remove heavy coupling on horrible SM2 Factory Factory factory = Factory.getInstance(new Config(filterConfig)); factory.refresh(); return new PageParser2ContentProcessor(factory); }
document = builder.parse(configFile); } else { document = builder.parse(config.getServletContext().getResourceAsStream(configFileName));
private DecoratorMapper getDecoratorMapper() { Factory factory = Factory.getInstance(new Config(getServletConfig())); DecoratorMapper decoratorMapper = factory.getDecoratorMapper(); return decoratorMapper; } }
/** * Entry-point for obtaining singleton instance of Factory. The default factory class * that will be instantiated can be overridden with the environment * entry <code>sitemesh.factory</code>. */ public static Factory getInstance(Config config) { Factory instance = (Factory)config.getServletContext().getAttribute(SITEMESH_FACTORY); if (instance == null) { String factoryClass = getEnvEntry("sitemesh.factory", "com.opensymphony.module.sitemesh.factory.DefaultFactory"); try { Class cls = ClassLoaderUtil.loadClass(factoryClass, config.getClass()); Constructor con = cls.getConstructor(new Class[] { Config.class }); instance = (Factory)con.newInstance(new Config[] { config }); config.getServletContext().setAttribute(SITEMESH_FACTORY, instance); } catch (InvocationTargetException e) { throw new FactoryException("Cannot construct Factory : " + factoryClass, e.getTargetException()); } catch (Exception e) { throw new FactoryException("Cannot construct Factory : " + factoryClass, e); } } instance.refresh(); return instance; }
public int doStartTag() { if (config == null) { // set context if not already set config = new Config(pageContext.getServletConfig()); factory = Factory.getInstance(config); decoratorMapper = factory.getDecoratorMapper(); } // return page == null ? EVAL_BODY_BUFFERED : SKIP_BODY; return EVAL_BODY_BUFFERED; }
resourcePath = config.getServletContext().getResource('/' + name); String filePath = config.getServletContext().getRealPath(name);
private DecoratorMapper getDecoratorMapper() { Factory factory = Factory.getInstance(new Config(getServletConfig())); return factory.getDecoratorMapper(); }
public Decorator getDecorator(HttpServletRequest request, Page page) { try { Decorator result = null; final Decorator d = super.getDecorator(request, page); String path = modifyPath(d.getPage(), getExt(request.getHeader("Accept-Language"))); File decFile = new File(config.getServletContext().getRealPath(path)); if (decFile.isFile()) { result = new DefaultDecorator(d.getName(), path, null) { public String getInitParameter(String paramName) { return d.getInitParameter(paramName); } }; } return result == null ? super.getDecorator(request, page) : result; } catch (NullPointerException e) { return super.getDecorator(request, page); } }
protected DecoratorSelector initDecoratorSelector(SiteMeshWebAppContext webAppContext) { // TODO: Remove heavy coupling on horrible SM2 Factory Factory factory = Factory.getInstance(new Config(filterConfig)); factory.refresh(); return new FreemarkerMapper2DecoratorSelector(factory.getDecoratorMapper()); }
public Decorator getDecorator(HttpServletRequest request, Page page) { try { Decorator result = null; final Decorator d = super.getDecorator(request, page); String path = modifyPath(d.getPage(), getExt(request.getHeader("User-Agent"))); File decFile = new File(config.getServletContext().getRealPath(path)); if (decFile.isFile()) { result = new DefaultDecorator(d.getName(), path, null) { public String getInitParameter(String paramName) { return d.getInitParameter(paramName); } }; } return result == null ? super.getDecorator(request, page) : result; } catch (NullPointerException e) { return super.getDecorator(request, page); } }
protected DecoratorSelector initDecoratorSelector(SiteMeshWebAppContext webAppContext) { // TODO: Remove heavy coupling on horrible SM2 Factory Factory factory = Factory.getInstance(new Config(filterConfig)); factory.refresh(); return new DecoratorMapper2DecoratorSelector(factory.getDecoratorMapper()); }
Config config = new Config(filterConfig); Grails5535Factory sitemeshFactory = new Grails5535Factory(config); if(servletContext != null) {
protected DecoratorSelector initDecoratorSelector(SiteMeshWebAppContext webAppContext) { Factory factory = Factory.getInstance(new Config(filterConfig)); factory.refresh(); return new FreemarkerMapper2DecoratorSelector(factory.getDecoratorMapper()); } }