/*
* Copyright 2007 Gerd Ziegler (www.gerdziegler.de) Licensed under the Apache
* License, Version 2.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law
* or agreed to in writing, software distributed under the License is
* distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the specific language
* governing permissions and limitations under the License. @author
* www.gerdziegler.de
*/
package org.ztemplates.flex;
import java.io.File;
import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import org.apache.log4j.Logger;
import org.ztemplates.flex.compiler.ZFlexCompiler;
public class ZFlexContextListener implements ServletContextListener
{
private static final Logger log = Logger.getLogger(ZFlexContextListener.class);
public void contextInitialized(ServletContextEvent servletContextEvent)
{
ServletContext ctx = servletContextEvent.getServletContext();
String mxmlc = ctx.getInitParameter("flex-mxmlc");
String root = ctx.getInitParameter("flex-root");
if (mxmlc == null)
{
throw new RuntimeException("missing init property in WEB-INF/web.xml named 'flex-mxmlc' pointing to flec mxmlc executable.");
}
if (root == null)
{
root = "/";
}
long time = System.currentTimeMillis();
log.info("compiling flex files...");
log.info("using flex-mxmlc = " + mxmlc);
log.info("using flex-root = " + root);
ZFlexCompiler fc = new ZFlexCompiler(mxmlc);
File dir = new File(ctx.getRealPath(root));
try
{
fc.compile(dir);
}
catch (Exception e)
{
log.error("flex compilation failed --- " + mxmlc + " --- " + dir.getAbsolutePath(), e);
}
long ms = System.currentTimeMillis() - time;
log.info("compile OK [" + ms + " ms]");
}
public void contextDestroyed(ServletContextEvent arg0)
{
}
}
|