- From: Thomas Gambet via cvs-syncmail <cvsmail@w3.org>
- Date: Wed, 05 Aug 2009 10:26:46 +0000
- To: www-validator-cvs@w3.org
Update of /sources/public/2006/unicorn/src/org/w3c/unicorn In directory hutz:/tmp/cvs-serv19002/src/org/w3c/unicorn Added Files: Tag: dev2 Test.java Controller.java Init.java Log Message: New project --- NEW FILE: Controller.java --- package org.w3c.unicorn; import java.io.IOException; import javax.servlet.*; import javax.servlet.http.*; import org.apache.log4j.Logger; import org.w3c.unicorn.route.Route; import org.w3c.unicorn.route.RouteParser; public class Controller extends HttpServlet { private static final long serialVersionUID = 1L; private static Logger logger; @Override public final void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { processRequest(request, response); } @Override public final void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { processRequest(request, response); } @Override protected void doPut(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { processRequest(request, response); } protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { logger.info("Processing request: " + request.getRequestURL()); Route route = RouteParser.getRoute(request); if (!route.isRedirect()) logger.info("Coresponding action: " + route.getAction()); if (route.isRedirect()) { response.sendRedirect(route.getUrl().toString()); } else { RequestDispatcher dispatcher = getServletContext().getNamedDispatcher(route.getAction()); if (dispatcher == null) { String error = "ERROR: " + route.getAction() + " does not corespond to any servlet in web.xml"; logger.error(error); response.sendError(501, error); } else { try { dispatcher.forward(request, response); } catch (Exception e) { logger.error("ERROR: " + e.getMessage(), e); } } } /*try { } catch (BadRequestException ex){ use Response.sendError() } catch (Throwable ex) { use Response.sendError() }*/ } static { try { Init.init(); logger = Logger.getLogger("Controller"); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } } --- NEW FILE: Test.java --- package org.w3c.unicorn; import java.util.regex.Matcher; import java.util.regex.Pattern; public class Test { /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub String s = "${TEST} sdf zer ${TEST2}"; System.out.println(s.matches("\\$\\{[a-zA-Z_0-9]*\\}")); Matcher matcher = Pattern.compile("\\$\\{[a-zA-Z_0-9]*\\}").matcher(s); while (matcher.find()) { System.out.println(matcher.group()); } System.out.println(matcher.lookingAt()); System.out.println(matcher.group()); System.out.println(matcher.group(0)); System.out.println(matcher.group(1)); System.out.println(matcher.lookingAt()); System.out.println(matcher.group()); //replaceAll(repl) } } --- NEW FILE: Init.java --- package org.w3c.unicorn; import java.io.File; import java.net.URI; import org.apache.log4j.Logger; import org.apache.log4j.PropertyConfigurator; import org.w3c.unicorn.util.Property; import org.w3c.unicorn.util.UCNProperties; public class Init { private static Logger logger; private static URI unicornHome; public static void init() throws Exception { // Checks that unicorn.home (JVM parameter) is set to an existing directory String ucnHome = System.getProperty("unicorn.home"); if (ucnHome == null) { String error = "ERROR: \"unicorn.home\" is not set in the JVM parameters. Please read the README file before trying to install Unicorn"; System.err.println(error); throw new Exception(error); } else if (!(new File(ucnHome)).exists() && (new File(ucnHome).isDirectory())){ String error = "ERROR: \"unicorn.home\" is not an existing directory: " + System.getProperty("unicorn.home"); System.err.println(error); throw new Exception(error); } else { unicornHome = (new File(ucnHome)).toURI(); System.out.println("OK - \"unicorn.home\" was found: " + unicornHome.getPath()); } // Log4j initialization attempt String log4jPath = unicornHome.getPath() + "WEB-INF/conf/log4j.properties"; File log4jPropFile = new File(log4jPath); if (!log4jPropFile.exists()) { String error = "WARN: \"log4j.properties\" could not be found: " + log4jPath; System.err.println(error); System.err.println("WARN: Log4j will not be initialized."); } else { System.out.println("OK - Log4j initialized with file: " + log4jPath); PropertyConfigurator.configure(log4jPropFile.toURI().toURL()); logger = Logger.getLogger("Init"); logger.info("Unicorn home directory was found"); logger.debug("Unicorn home path = " + unicornHome.getPath()); logger.info("Log4j has been successfully initialized"); logger.debug("Log4j properties file = " + log4jPropFile.toURI().toURL().getPath()); } // Loading unicorn.properties logger.debug("Loading unicorn.properties"); String unicornPath = unicornHome.getPath() + "WEB-INF/conf/unicorn.properties"; logger.debug("Unicorn properties file = " + unicornPath); File unicornPropFile = new File(unicornPath); if (!unicornPropFile.exists()) { String error = "ERROR: \"unicorn.properties\" could not be found: " + unicornPath; System.err.println(error); logger.error("Unicorn properties file does not exists! Path is: " + unicornPath); throw new Exception(error); } else { UCNProperties ucnProperties = new UCNProperties(); ucnProperties.put("UNICORN_HOME", unicornHome.getPath()); ucnProperties.load(unicornPropFile.toURI().toURL().openStream()); Property.setUnicornProperties(ucnProperties); logger.info("Unicorn properties file successfully loaded"); logger.debug("Loaded properties: " + Property.getUnicornProperties()); } } public static void main(String argv[]) { try { init(); } catch (Exception e1) { // TODO Auto-generated catch block e1.printStackTrace(); } //Property.init(); /*URL url; HttpURLConnection connection; try { url = new URL("http://www.masdelafontanelle.fr"); connection = (HttpURLConnection) url.openConnection(); System.out.println(connection.getResponseCode()); System.out.println(connection.getContentType()); Map responseMap = connection.getHeaderFields(); System.out.println(""); for (Iterator iterator = responseMap.keySet().iterator(); iterator.hasNext(); ) { String key = (String) iterator.next(); System.out.print(key + " = "); List values = (List) responseMap.get(key); for (int i = 0; i < values.size(); i++) { Object o = values.get(i); System.out.print(o + ", "); } System.out.println(""); } } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } logger.error("toooooooooooooooooo"); logger.debug("Hello, my name is Homer Simpson."); logger.debug("Hello, my name is Lisa Simpson."); logger.debug("Hello, my name is Marge Simpson."); logger.debug("Hello, my name is Bart Simpson."); logger.debug("Hello, my name is Maggie Simpson."); logger.info("We are the Simpsons!"); logger.info("Mmmmmm .... Chocolate."); logger.info("Homer likes chocolate"); logger.info("Doh!"); logger.info("We are the Simpsons!"); logger.warn("Bart: I am through with working! Working is for chumps!" + "Homer: Son, I'm proud of you. I was twice your age before " + "I figured that out."); logger.warn("Mmm...forbidden donut."); logger.warn("D'oh! A deer! A female deer!"); logger.warn("Truly, yours is a butt that won't quit." + "- Bart, writing as Woodrow to Ms. Krabappel."); NDC.push("#23856"); logger.error("Dear Baby, Welcome to Dumpsville. Population: you."); logger.error("Dear Baby, Welcome to Dumpsville. Population: you.", new IOException("Dumpsville, USA")); logger.error("Mr. Hutz, are you aware you're not wearing pants?"); logger.error("Mr. Hutz, are you aware you're not wearing pants?", new IllegalStateException("Error !!")); NDC.pop(); NDC.remove(); NDC.push("Another NDC"); // Log some information. logger.fatal("Hello, my name is Bart Simpson."); logger.error("Hi diddly ho good neighbour."); // Clean up NDC NDC.pop(); NDC.remove(); logger.fatal("Eep."); logger.fatal("Mmm...forbidden donut.", new SecurityException("Fatal Exception")); logger.fatal("D'oh! A deer! A female deer!"); logger.fatal("Mmmmmm .... Chocolate.", new SecurityException("Fatal Exception")); */ } }
Received on Wednesday, 5 August 2009 10:26:56 UTC