@Override public void generate(SchemaDefinition schema) throws Exception { final SchemaVersionProvider schemaVersionProvider = schema.getDatabase().getSchemaVersionProvider(); final String version = schemaVersionProvider != null ? schemaVersionProvider.version(schema) : null; final File file = new File(generator.getOutputDirectory(), schema.getName() + (!StringUtils.isEmpty(version) ? "-" + version : "") + ".html"); log.info("output file: " + file); final File path = file.getParentFile(); if (path != null) path.mkdirs(); final HttpServletRequest request = new SimpleServletRequest(); final HttpServletResponse response = new SimpleServletResponse(file, "utf-8"); final List<TableDefinition> tables = database.getTables(schema); request.setAttribute("totalRelationSvg", totalRelationSvg(tables)); request.setAttribute("relationSvg", relationSvg(tables)); request.setAttribute("database", database); request.setAttribute("enums", database.getEnums(schema)); request.setAttribute("sequences", database.getSequences(schema)); request.setAttribute("tables", tables); jsp.init(new SimpleServletConfig()); jsp.service(request, response); response.getWriter().flush(); response.getWriter().close(); }
private HttpJspBase loadJsp(String forwardedUrl, File compilationDir) throws MalformedURLException, ClassNotFoundException, InstantiationException, IllegalAccessException, ServletException { String jspClassName = toJspClassName(forwardedUrl); URLClassLoader classLoader = URLClassLoader.newInstance(new URL[] { compilationDir.toURI().toURL() }); Class<?> cls = Class.forName(jspClassName, true, classLoader); HttpJspBase instance = (HttpJspBase) cls.newInstance(); MockServletConfig servletConfig = new MockServletConfig(new MockServletContext()); servletConfig.getServletContext().setAttribute(InstanceManager.class.getName(), new InstanceManagerImplementation()); JspApplicationContext jspApplicationContext = JspFactory.getDefaultFactory().getJspApplicationContext( servletConfig.getServletContext()); // Register the ELResolver with JSP jspApplicationContext.addELResolver(manager.getELResolver()); // Register ELContextListener with JSP jspApplicationContext.addELContextListener(Reflections .<ELContextListener> newInstance("org.jboss.weld.el.WeldELContextListener")); // Push the wrapped expression factory into the servlet context so that // Tomcat or Jetty can hook it in using a container code servletConfig.getServletContext().setAttribute(EXPRESSION_FACTORY_NAME, manager.wrapExpressionFactory(jspApplicationContext.getExpressionFactory())); instance.init(servletConfig); JspFactory.setDefaultFactory(new org.apache.jasper.runtime.JspFactoryImpl()); instance._jspInit(); return instance; }