Nuiton-utils-commits
Threads by month
- ----- 2026 -----
- June
- May
- April
- March
- February
- January
- ----- 2025 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2024 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2023 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2022 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2021 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2020 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2019 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2018 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2017 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2016 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2015 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2014 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2013 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2012 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2011 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2010 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2009 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2008 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2007 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2006 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2005 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2004 -----
- December
- November
- October
- September
- August
December 2009
- 3 participants
- 28 discussions
r1716 - in trunk: . src/main/java/org/nuiton/util/war src/site/apt
by echatellier@users.nuiton.org 17 Dec '09
by echatellier@users.nuiton.org 17 Dec '09
17 Dec '09
Author: echatellier
Date: 2009-12-17 16:34:04 +0100 (Thu, 17 Dec 2009)
New Revision: 1716
Added:
trunk/src/main/java/org/nuiton/util/war/JettyLauncher.java
Modified:
trunk/pom.xml
trunk/src/main/java/org/nuiton/util/war/WinstoneLauncher.java
trunk/src/site/apt/Warlauncher.apt
Log:
Add jetty implementation.
Modified: trunk/pom.xml
===================================================================
--- trunk/pom.xml 2009-12-17 14:10:00 UTC (rev 1715)
+++ trunk/pom.xml 2009-12-17 15:34:04 UTC (rev 1716)
@@ -64,6 +64,13 @@
</dependency>
<dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>4.7</version>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
<groupId>org.jvnet.hudson.winstone</groupId>
<artifactId>winstone</artifactId>
<version>0.9.10-hudson-16</version>
@@ -71,11 +78,12 @@
</dependency>
<dependency>
- <groupId>junit</groupId>
- <artifactId>junit</artifactId>
- <version>4.7</version>
- <scope>test</scope>
+ <groupId>org.eclipse.jetty.aggregate</groupId>
+ <artifactId>jetty-webapp</artifactId>
+ <version>7.0.1.v20091125</version>
+ <scope>provided</scope>
</dependency>
+
</dependencies>
Added: trunk/src/main/java/org/nuiton/util/war/JettyLauncher.java
===================================================================
--- trunk/src/main/java/org/nuiton/util/war/JettyLauncher.java (rev 0)
+++ trunk/src/main/java/org/nuiton/util/war/JettyLauncher.java 2009-12-17 15:34:04 UTC (rev 1716)
@@ -0,0 +1,256 @@
+/* *##%
+ * Copyright (C) 2009 Code Lutin
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *##%*/
+
+package org.nuiton.util.war;
+
+import java.awt.AWTException;
+import java.awt.Desktop;
+import java.awt.Image;
+import java.awt.MenuItem;
+import java.awt.PopupMenu;
+import java.awt.SystemTray;
+import java.awt.TrayIcon;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.awt.event.MouseEvent;
+import java.awt.event.MouseListener;
+import java.io.File;
+import java.io.IOException;
+import java.net.JarURLConnection;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.net.URL;
+
+import javax.swing.ImageIcon;
+
+import org.eclipse.jetty.server.Connector;
+import org.eclipse.jetty.server.Handler;
+import org.eclipse.jetty.server.Server;
+import org.eclipse.jetty.server.handler.DefaultHandler;
+import org.eclipse.jetty.server.handler.HandlerCollection;
+import org.eclipse.jetty.server.nio.SelectChannelConnector;
+import org.eclipse.jetty.webapp.WebAppContext;
+
+/**
+ * War main class launcher (jetty based).
+ *
+ * To use it :
+ * java -jar app-xxx.war
+ *
+ * @author chatellier
+ * @version $Revision$
+ * @since 1.1.2
+ *
+ * Last update : $Date$
+ * By : $Author$
+ */
+public class JettyLauncher implements ActionListener, MouseListener {
+
+ /** Jetty server instance. */
+ protected Server jettyServer;
+
+ /** Server URI. */
+ protected URI serverUri;
+
+ /** Default port. */
+ protected int port = 8888;
+
+ /**
+ * Main method (used by war in manifest).
+ *
+ * @param args args
+ * @throws Exception
+ */
+ public static void main(String[] args) throws Exception {
+ JettyLauncher launcher = new JettyLauncher();
+ launcher.startServer(args);
+ launcher.installSystemTray();
+ launcher.openBrowser();
+ }
+
+ /**
+ * Launch servlet container.
+ *
+ * @param args args
+ * @throws Exception
+ */
+ protected void startServer(String[] args) throws Exception {
+ System.out.println("Starting server embedded mode...");
+
+ String fqnLauncherFile = JettyLauncher.class.getName().replaceAll("\\.", "/") + ".class";
+ System.out.println("Search for launcher class : " + fqnLauncherFile);
+
+ URL classFile = JettyLauncher.class.getClassLoader().getResource(fqnLauncherFile);
+ System.out.println(" - using classFile : " + classFile);
+
+ // strange following line seams also work for jpnl launch
+ File me = new File(((JarURLConnection) classFile.openConnection()).getJarFile().getName());
+ System.out.println(" - using warfile file : " + me);
+
+ jettyServer = new Server();
+
+ Connector connector = new SelectChannelConnector();
+ connector.setPort(port);
+ jettyServer.setConnectors(new Connector[]{connector});
+
+ WebAppContext webappcontext = new WebAppContext();
+ webappcontext.setContextPath("/");
+ webappcontext.setWar(me.getAbsolutePath());
+
+ HandlerCollection handlers= new HandlerCollection();
+ handlers.setHandlers(new Handler[]{webappcontext, new DefaultHandler()});
+ jettyServer.setHandler(handlers);
+
+ jettyServer.start();
+
+ // build server uri
+ try {
+ serverUri = new URI("http://localhost:" + port);
+ } catch (URISyntaxException e) {
+ e.printStackTrace();
+ }
+ }
+
+ /**
+ * Shutdown server.
+ */
+ protected void stopServer() {
+ if (jettyServer != null) {
+ try {
+ jettyServer.stop();
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ System.exit(0);
+ }
+ }
+
+ /**
+ * Install system tray to stop server.
+ */
+ protected void installSystemTray() {
+ if (SystemTray.isSupported()) {
+ // build menu
+ PopupMenu menu = new PopupMenu();
+ MenuItem browserItem = new MenuItem("Start browser");
+ browserItem.addActionListener(this);
+ browserItem.setActionCommand("browser");
+ menu.add(browserItem);
+
+ MenuItem stopItem = new MenuItem("Stop server");
+ stopItem.addActionListener(this);
+ stopItem.setActionCommand("stop");
+ menu.add(stopItem);
+
+ // build tray icon
+ URL imageURL = JettyLauncher.class.getResource("/favicon.png");
+ if (imageURL == null) {
+ imageURL = JettyLauncher.class.getResource("/favicon.jpg");
+ }
+ if (imageURL == null) {
+ System.out.println("No favicon.{png|jpg} found, skip systray installation");
+ } else {
+ Image image = new ImageIcon(imageURL).getImage();
+ TrayIcon icon = new TrayIcon(image, "Server", menu);
+ icon.setImageAutoSize(true);
+ icon.addMouseListener(this);
+
+ // System tray
+ SystemTray systemTray = SystemTray.getSystemTray();
+ try {
+ systemTray.add(icon);
+ } catch (AWTException ex) {
+ throw new RuntimeException("Can't install tray icon", ex);
+ }
+ }
+ }
+ }
+
+ /*
+ * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
+ */
+ @Override
+ public void actionPerformed(ActionEvent e) {
+ if ("browser".equalsIgnoreCase(e.getActionCommand())) {
+ openBrowser();
+ } else if ("stop".equalsIgnoreCase(e.getActionCommand())) {
+ stopServer();
+ }
+ }
+
+ /**
+ * Open browser.
+ *
+ * @throws IOException
+ */
+ protected void openBrowser() {
+ if (Desktop.isDesktopSupported() && serverUri != null) {
+ Desktop desktop = Desktop.getDesktop();
+ if (desktop.isSupported(Desktop.Action.BROWSE)) {
+ System.out.println("Opening browser at " + serverUri);
+ try {
+ desktop.browse(serverUri);
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+ }
+ }
+
+ /*
+ * @see java.awt.event.MouseListener#mouseClicked(java.awt.event.MouseEvent)
+ */
+ @Override
+ public void mouseClicked(MouseEvent e) {
+ if (e.getClickCount() == 2) {
+ openBrowser();
+ }
+ }
+
+ /*
+ * @see java.awt.event.MouseListener#mousePressed(java.awt.event.MouseEvent)
+ */
+ @Override
+ public void mousePressed(MouseEvent e) {
+
+ }
+
+ /*
+ * @see java.awt.event.MouseListener#mouseReleased(java.awt.event.MouseEvent)
+ */
+ @Override
+ public void mouseReleased(MouseEvent e) {
+
+ }
+
+ /*
+ * @see java.awt.event.MouseListener#mouseEntered(java.awt.event.MouseEvent)
+ */
+ @Override
+ public void mouseEntered(MouseEvent e) {
+
+ }
+
+ /*
+ * @see java.awt.event.MouseListener#mouseExited(java.awt.event.MouseEvent)
+ */
+ @Override
+ public void mouseExited(MouseEvent e) {
+
+ }
+}
Property changes on: trunk/src/main/java/org/nuiton/util/war/JettyLauncher.java
___________________________________________________________________
Added: svn:keywords
+ "Author Date Id Revision HeadURL"
Modified: trunk/src/main/java/org/nuiton/util/war/WinstoneLauncher.java
===================================================================
--- trunk/src/main/java/org/nuiton/util/war/WinstoneLauncher.java 2009-12-17 14:10:00 UTC (rev 1715)
+++ trunk/src/main/java/org/nuiton/util/war/WinstoneLauncher.java 2009-12-17 15:34:04 UTC (rev 1716)
@@ -42,7 +42,7 @@
import winstone.Launcher;
/**
- * War main class launcher.
+ * War main class launcher (winstone based).
*
* Based on winstone micro container.
*
Modified: trunk/src/site/apt/Warlauncher.apt
===================================================================
--- trunk/src/site/apt/Warlauncher.apt 2009-12-17 14:10:00 UTC (rev 1715)
+++ trunk/src/site/apt/Warlauncher.apt 2009-12-17 15:34:04 UTC (rev 1716)
@@ -4,25 +4,23 @@
War launcher
-* Winstone based
+* Features
-** Features
-
* Start embedded servlet container with current webapp
* Favicon support
* Systray with popup menu
-** Use Winstone war launcher
+* Prerequisites
-*** Prerequisites
-
By default, winstone look for an icon named <<favicon.png>> or <<favicon.jpg>>.
Il none of this icon is found, system tray won't work.
-*** Maven configuration
+* Use Winstone war launcher
+** Maven configuration
+
Add following dependencies to your project.
------------------------------------------------
@@ -81,4 +79,65 @@
* Jetty based
- <Comming soon...>
+** Maven configuration
+
+ Add following dependencies to your project.
+
+------------------------------------------------
+<dependency>
+ <groupId>org.nuiton</groupId>
+ <artifactId>nuiton-utils</artifactId>
+ <version>1.1.2</version>
+ <scope>provided</scope>
+</dependency>
+<dependency>
+ <groupId>org.eclipse.jetty.aggregate</groupId>
+ <artifactId>jetty-webapp</artifactId>
+ <version>7.0.1.v20091125</version>
+ <scope>provided</scope>
+</dependency>
+<dependency>
+ <groupId>javax.servlet</groupId>
+ <artifactId>servlet-api</artifactId>
+ <version>2.5</version>
+ <scope>provided</scope>
+</dependency>
+------------------------------------------------
+
+ They have to be both at least in <<<provided>>> scope.
+
+ Then, you need to add following configuration into maven-war-plugin :
+
+--------------------------------------------------------------------
+<plugin>
+ <artifactId>maven-war-plugin</artifactId>
+ <version>2.1-beta-1</version>
+ <configuration>
+ <archive>
+ <manifest>
+ <mainClass>org.nuiton.util.war.JettyLauncher</mainClass>
+ </manifest>
+ </archive>
+ <overlays>
+ <overlay>
+ <groupId>org.nuiton</groupId>
+ <artifactId>nuiton-utils</artifactId>
+ <type>jar</type>
+ <includes>
+ <include>**/war/Jetty*</include>
+ </includes>
+ </overlay>
+ <overlay>
+ <groupId>org.eclipse.jetty.aggregate</groupId>
+ <artifactId>jetty-webapp</artifactId>
+ <type>jar</type>
+ </overlay>
+ <overlay>
+ <groupId>javax.servlet</groupId>
+ <artifactId>servlet-api</artifactId>
+ <type>jar</type>
+ </overlay>
+ </overlays>
+ </configuration>
+</plugin>
+--------------------------------------------------------------------
1
0
r1715 - in trunk/src: main/java/org/nuiton/util/war site/apt
by echatellier@users.nuiton.org 17 Dec '09
by echatellier@users.nuiton.org 17 Dec '09
17 Dec '09
Author: echatellier
Date: 2009-12-17 15:10:00 +0100 (Thu, 17 Dec 2009)
New Revision: 1715
Added:
trunk/src/main/java/org/nuiton/util/war/package-info.java
Modified:
trunk/src/main/java/org/nuiton/util/war/WinstoneLauncher.java
trunk/src/site/apt/Warlauncher.apt
Log:
Update winstone launcher doc.
Modified: trunk/src/main/java/org/nuiton/util/war/WinstoneLauncher.java
===================================================================
--- trunk/src/main/java/org/nuiton/util/war/WinstoneLauncher.java 2009-12-17 11:24:16 UTC (rev 1714)
+++ trunk/src/main/java/org/nuiton/util/war/WinstoneLauncher.java 2009-12-17 14:10:00 UTC (rev 1715)
@@ -51,6 +51,7 @@
*
* @author chatellier
* @version $Revision$
+ * @since 1.1.2
*
* Last update : $Date$
* By : $Author$
Added: trunk/src/main/java/org/nuiton/util/war/package-info.java
===================================================================
--- trunk/src/main/java/org/nuiton/util/war/package-info.java (rev 0)
+++ trunk/src/main/java/org/nuiton/util/war/package-info.java 2009-12-17 14:10:00 UTC (rev 1715)
@@ -0,0 +1,9 @@
+/**
+ * Embedded war launchers.
+ *
+ * Currently implemented with :
+ * <ul>
+ * <li>Winstone : {@link org.nuiton.util.war.WinstoneLauncher}
+ * </ul>
+ */
+package org.nuiton.util.war;
Property changes on: trunk/src/main/java/org/nuiton/util/war/package-info.java
___________________________________________________________________
Added: svn:keywords
+ "Author Date Id Revision HeadURL"
Modified: trunk/src/site/apt/Warlauncher.apt
===================================================================
--- trunk/src/site/apt/Warlauncher.apt 2009-12-17 11:24:16 UTC (rev 1714)
+++ trunk/src/site/apt/Warlauncher.apt 2009-12-17 14:10:00 UTC (rev 1715)
@@ -60,7 +60,7 @@
<artifactId>nuiton-utils</artifactId>
<type>jar</type>
<includes>
- <include>**/war/*</include>
+ <include>**/war/Winstone*</include>
</includes>
</overlay>
<overlay>
@@ -73,6 +73,12 @@
</plugin>
--------------------------------------------------------------------
+** References
+
+ * Winstone home : {{http://winstone.sourceforge.net}}
+
+ * Winstone command line options : {{http://winstone.sourceforge.net/#commandLine}}
+
* Jetty based
<Comming soon...>
1
0
Author: echatellier
Date: 2009-12-17 12:24:16 +0100 (Thu, 17 Dec 2009)
New Revision: 1714
Modified:
trunk/changelog.txt
Log:
Update changelog
Modified: trunk/changelog.txt
===================================================================
--- trunk/changelog.txt 2009-12-17 11:12:01 UTC (rev 1713)
+++ trunk/changelog.txt 2009-12-17 11:24:16 UTC (rev 1714)
@@ -1,5 +1,6 @@
-1.1.2 xxx 200910xx
+1.1.2 xxx 200912xx
+ * Add generic war launcher (winstone based)
* Add new uncompress method with exclusion filters
* [FEATURE] Force application configuration properties to be written sorted
* [FEATURE] Add sed and grep method on FileUtil
1
0
Author: echatellier
Date: 2009-12-17 12:12:01 +0100 (Thu, 17 Dec 2009)
New Revision: 1713
Modified:
trunk/src/site/apt/CommandLineArgumentApplication.apt
trunk/src/site/apt/Todo.apt
trunk/src/site/apt/index.apt
trunk/src/site/apt/nuitonUtil.apt
Log:
Fix site title in apt files
Modified: trunk/src/site/apt/CommandLineArgumentApplication.apt
===================================================================
--- trunk/src/site/apt/CommandLineArgumentApplication.apt 2009-12-17 11:02:59 UTC (rev 1712)
+++ trunk/src/site/apt/CommandLineArgumentApplication.apt 2009-12-17 11:12:01 UTC (rev 1713)
@@ -1,3 +1,7 @@
+ ----
+ Argument d'application
+ ----
+
Argument d'application
Il y a deux type d'argument d'application:
Modified: trunk/src/site/apt/Todo.apt
===================================================================
--- trunk/src/site/apt/Todo.apt 2009-12-17 11:02:59 UTC (rev 1712)
+++ trunk/src/site/apt/Todo.apt 2009-12-17 11:12:01 UTC (rev 1713)
@@ -1,9 +1,9 @@
-----
-TODO
-----
-----
-2009-08-23
-----
+ ----
+ TODO
+ ----
+ ----
+ 2009-08-23
+ ----
Un nouveau parser d'argument
Modified: trunk/src/site/apt/index.apt
===================================================================
(Binary files differ)
Modified: trunk/src/site/apt/nuitonUtil.apt
===================================================================
--- trunk/src/site/apt/nuitonUtil.apt 2009-12-17 11:02:59 UTC (rev 1712)
+++ trunk/src/site/apt/nuitonUtil.apt 2009-12-17 11:12:01 UTC (rev 1713)
@@ -1,10 +1,12 @@
-----
-Documentation - NuitonUtils
-----
-----
-2009-08-23
-----
+ ----
+ Documentation
+ ----
+ ----
+ 2009-08-23
+ ----
+Documentation
+
NuitonUtils contient un ensemble de librairies trop petites pour avoir
leur propre projet. Elles sont aussi utile à la plupart des projets de
Code Lutin.
1
0
r1712 - in trunk: . src/main/java/org/nuiton/util src/main/java/org/nuiton/util/war src/site src/site/apt
by echatellier@users.nuiton.org 17 Dec '09
by echatellier@users.nuiton.org 17 Dec '09
17 Dec '09
Author: echatellier
Date: 2009-12-17 12:02:59 +0100 (Thu, 17 Dec 2009)
New Revision: 1712
Added:
trunk/src/main/java/org/nuiton/util/war/
trunk/src/main/java/org/nuiton/util/war/WinstoneLauncher.java
trunk/src/site/apt/Warlauncher.apt
Modified:
trunk/pom.xml
trunk/src/site/site.xml
Log:
Add embedded war launcher base on winstone.
Modified: trunk/pom.xml
===================================================================
--- trunk/pom.xml 2009-12-17 10:56:36 UTC (rev 1711)
+++ trunk/pom.xml 2009-12-17 11:02:59 UTC (rev 1712)
@@ -64,12 +64,18 @@
</dependency>
<dependency>
+ <groupId>org.jvnet.hudson.winstone</groupId>
+ <artifactId>winstone</artifactId>
+ <version>0.9.10-hudson-16</version>
+ <scope>provided</scope>
+ </dependency>
+
+ <dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.7</version>
<scope>test</scope>
</dependency>
-
</dependencies>
Added: trunk/src/main/java/org/nuiton/util/war/WinstoneLauncher.java
===================================================================
--- trunk/src/main/java/org/nuiton/util/war/WinstoneLauncher.java (rev 0)
+++ trunk/src/main/java/org/nuiton/util/war/WinstoneLauncher.java 2009-12-17 11:02:59 UTC (rev 1712)
@@ -0,0 +1,250 @@
+/* *##%
+ * Copyright (C) 2009 Code Lutin
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *##%*/
+
+package org.nuiton.util.war;
+
+import java.awt.AWTException;
+import java.awt.Desktop;
+import java.awt.Image;
+import java.awt.MenuItem;
+import java.awt.PopupMenu;
+import java.awt.SystemTray;
+import java.awt.TrayIcon;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.awt.event.MouseEvent;
+import java.awt.event.MouseListener;
+import java.io.File;
+import java.io.IOException;
+import java.net.JarURLConnection;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.net.URL;
+import java.util.Map;
+
+import javax.swing.ImageIcon;
+
+import winstone.Launcher;
+
+/**
+ * War main class launcher.
+ *
+ * Based on winstone micro container.
+ *
+ * To use it :
+ * java -jar app-xxx.war
+ *
+ * @author chatellier
+ * @version $Revision$
+ *
+ * Last update : $Date$
+ * By : $Author$
+ */
+public class WinstoneLauncher implements ActionListener, MouseListener {
+
+ /** Winstone server instance. */
+ protected Launcher winstone;
+
+ /** Server URI. */
+ protected URI serverUri;
+
+ /**
+ * Main method (used by war in manifest).
+ *
+ * @param args args
+ * @throws IOException
+ */
+ public static void main(String[] args) throws IOException {
+ WinstoneLauncher launcher = new WinstoneLauncher();
+ launcher.startServer(args);
+ launcher.installSystemTray();
+ launcher.openBrowser();
+ }
+
+ /**
+ * Launch servlet container.
+ *
+ * @param args args
+ * @throws IOException
+ */
+ protected void startServer(String[] args) throws IOException {
+ System.out.println("Starting server embedded mode...");
+
+ String fqnLauncherFile = WinstoneLauncher.class.getName().replaceAll("\\.", "/") + ".class";
+ System.out.println("Search for launcher class : " + fqnLauncherFile);
+
+ URL classFile = WinstoneLauncher.class.getClassLoader().getResource(fqnLauncherFile);
+ System.out.println(" - using classFile : " + classFile);
+
+ // strange following line seams also work for jpnl launch
+ File me = new File(((JarURLConnection) classFile.openConnection()).getJarFile().getName());
+ System.out.println(" - using warfile file : " + me);
+
+ // hashArgs map, initialized with command line args
+ Map<String, String> hashArgs = Launcher.getArgsFromCommandLine(args);
+
+ hashArgs.put("warfile", me.getAbsolutePath()); // or any other command line args, eg port
+
+ System.out.println(" - using args : " + hashArgs);
+
+ Launcher.initLogger(hashArgs);
+ winstone = new Launcher(hashArgs); // spawns threads, so your application doesn't block
+
+ // open browser
+ int port = 8080;
+ String configPort = hashArgs.get("httpPort");
+ if (configPort != null && !configPort.isEmpty()) {
+ try {
+ port = Integer.parseInt(configPort);
+ } catch (NumberFormatException e) {
+ e.printStackTrace();
+ }
+ }
+
+ // build server uri
+ try {
+ serverUri = new URI("http://localhost:" + port);
+ } catch (URISyntaxException e) {
+ e.printStackTrace();
+ }
+ }
+
+ /**
+ * Shutdown server.
+ */
+ protected void stopServer() {
+ if (winstone != null) {
+ winstone.shutdown();
+ System.exit(0);
+ }
+ }
+
+ /**
+ * Install system tray to stop server.
+ */
+ protected void installSystemTray() {
+ if (SystemTray.isSupported()) {
+ // build menu
+ PopupMenu menu = new PopupMenu();
+ MenuItem browserItem = new MenuItem("Start browser");
+ browserItem.addActionListener(this);
+ browserItem.setActionCommand("browser");
+ menu.add(browserItem);
+
+ MenuItem stopItem = new MenuItem("Stop server");
+ stopItem.addActionListener(this);
+ stopItem.setActionCommand("stop");
+ menu.add(stopItem);
+
+ // build tray icon
+ URL imageURL = WinstoneLauncher.class.getResource("/favicon.png");
+ if (imageURL == null) {
+ imageURL = WinstoneLauncher.class.getResource("/favicon.jpg");
+ }
+ if (imageURL == null) {
+ System.out.println("No favicon.{png|jpg} found, skip systray installation");
+ } else {
+ Image image = new ImageIcon(imageURL).getImage();
+ TrayIcon icon = new TrayIcon(image, "Server", menu);
+ icon.setImageAutoSize(true);
+ icon.addMouseListener(this);
+
+ // System tray
+ SystemTray systemTray = SystemTray.getSystemTray();
+ try {
+ systemTray.add(icon);
+ } catch (AWTException ex) {
+ throw new RuntimeException("Can't install tray icon", ex);
+ }
+ }
+ }
+ }
+
+ /*
+ * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
+ */
+ @Override
+ public void actionPerformed(ActionEvent e) {
+ if ("browser".equalsIgnoreCase(e.getActionCommand())) {
+ openBrowser();
+ } else if ("stop".equalsIgnoreCase(e.getActionCommand())) {
+ stopServer();
+ }
+ }
+
+ /**
+ * Open browser.
+ *
+ * @throws IOException
+ */
+ protected void openBrowser() {
+ if (Desktop.isDesktopSupported() && serverUri != null) {
+ Desktop desktop = Desktop.getDesktop();
+ if (desktop.isSupported(Desktop.Action.BROWSE)) {
+ System.out.println("Opening browser at " + serverUri);
+ try {
+ desktop.browse(serverUri);
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+ }
+ }
+
+ /*
+ * @see java.awt.event.MouseListener#mouseClicked(java.awt.event.MouseEvent)
+ */
+ @Override
+ public void mouseClicked(MouseEvent e) {
+ if (e.getClickCount() == 2) {
+ openBrowser();
+ }
+ }
+
+ /*
+ * @see java.awt.event.MouseListener#mousePressed(java.awt.event.MouseEvent)
+ */
+ @Override
+ public void mousePressed(MouseEvent e) {
+
+ }
+
+ /*
+ * @see java.awt.event.MouseListener#mouseReleased(java.awt.event.MouseEvent)
+ */
+ @Override
+ public void mouseReleased(MouseEvent e) {
+
+ }
+
+ /*
+ * @see java.awt.event.MouseListener#mouseEntered(java.awt.event.MouseEvent)
+ */
+ @Override
+ public void mouseEntered(MouseEvent e) {
+
+ }
+
+ /*
+ * @see java.awt.event.MouseListener#mouseExited(java.awt.event.MouseEvent)
+ */
+ @Override
+ public void mouseExited(MouseEvent e) {
+
+ }
+}
Property changes on: trunk/src/main/java/org/nuiton/util/war/WinstoneLauncher.java
___________________________________________________________________
Added: svn:keywords
+ "Author Date Id Revision HeadURL"
Added: trunk/src/site/apt/Warlauncher.apt
===================================================================
--- trunk/src/site/apt/Warlauncher.apt (rev 0)
+++ trunk/src/site/apt/Warlauncher.apt 2009-12-17 11:02:59 UTC (rev 1712)
@@ -0,0 +1,78 @@
+ ------
+ War launcher
+ ------
+
+War launcher
+
+* Winstone based
+
+** Features
+
+ * Start embedded servlet container with current webapp
+
+ * Favicon support
+
+ * Systray with popup menu
+
+** Use Winstone war launcher
+
+*** Prerequisites
+
+ By default, winstone look for an icon named <<favicon.png>> or <<favicon.jpg>>.
+ Il none of this icon is found, system tray won't work.
+
+*** Maven configuration
+
+ Add following dependencies to your project.
+
+------------------------------------------------
+<dependency>
+ <groupId>org.nuiton</groupId>
+ <artifactId>nuiton-utils</artifactId>
+ <version>1.1.2</version>
+ <scope>provided</scope>
+</dependency>
+<dependency>
+ <groupId>org.jvnet.hudson.winstone</groupId>
+ <artifactId>winstone</artifactId>
+ <version>0.9.10-hudson-16</version>
+ <scope>provided</scope>
+</dependency>
+------------------------------------------------
+
+ They have to be both at least in <<<provided>>> scope.
+
+ Then, you need to add following configuration into maven-war-plugin :
+
+--------------------------------------------------------------------
+<plugin>
+ <artifactId>maven-war-plugin</artifactId>
+ <version>2.1-beta-1</version>
+ <configuration>
+ <archive>
+ <manifest>
+ <mainClass>org.nuiton.util.war.WinstoneLauncher</mainClass>
+ </manifest>
+ </archive>
+ <overlays>
+ <overlay>
+ <groupId>org.nuiton</groupId>
+ <artifactId>nuiton-utils</artifactId>
+ <type>jar</type>
+ <includes>
+ <include>**/war/*</include>
+ </includes>
+ </overlay>
+ <overlay>
+ <groupId>org.jvnet.hudson.winstone</groupId>
+ <artifactId>winstone</artifactId>
+ <type>jar</type>
+ </overlay>
+ </overlays>
+ </configuration>
+</plugin>
+--------------------------------------------------------------------
+
+* Jetty based
+
+ <Comming soon...>
Modified: trunk/src/site/site.xml
===================================================================
--- trunk/src/site/site.xml 2009-12-17 10:56:36 UTC (rev 1711)
+++ trunk/src/site/site.xml 2009-12-17 11:02:59 UTC (rev 1712)
@@ -20,6 +20,7 @@
<item name="Accueil" href="index.html"/>
<item name="Documentation" href="/nuitonUtil.html"/>
<item name="Command Line" href="/CommandLineArgumentApplication.html"/>
+ <item name="War launcher" href="/Warlauncher.html"/>
</menu>
<menu name="Téléchargement">
1
0
r1711 - in trunk/src: main/java/org/nuiton/util test/java/org/nuiton/util
by echatellier@users.nuiton.org 17 Dec '09
by echatellier@users.nuiton.org 17 Dec '09
17 Dec '09
Author: echatellier
Date: 2009-12-17 11:56:36 +0100 (Thu, 17 Dec 2009)
New Revision: 1711
Modified:
trunk/src/main/java/org/nuiton/util/MD5InputStream.java
trunk/src/test/java/org/nuiton/util/VersionNumberUtilTest.java
Log:
Fix javadoc warnings
Modified: trunk/src/main/java/org/nuiton/util/MD5InputStream.java
===================================================================
--- trunk/src/main/java/org/nuiton/util/MD5InputStream.java 2009-12-17 10:42:00 UTC (rev 1710)
+++ trunk/src/main/java/org/nuiton/util/MD5InputStream.java 2009-12-17 10:56:36 UTC (rev 1711)
@@ -107,7 +107,7 @@
/**
* Returns array of bytes representing hash of the stream as
* finalized for the current state.
- * @return
+ * @return hash
* @see MD5#Final
*/
public byte[] hash() {
Modified: trunk/src/test/java/org/nuiton/util/VersionNumberUtilTest.java
===================================================================
--- trunk/src/test/java/org/nuiton/util/VersionNumberUtilTest.java 2009-12-17 10:42:00 UTC (rev 1710)
+++ trunk/src/test/java/org/nuiton/util/VersionNumberUtilTest.java 2009-12-17 10:56:36 UTC (rev 1711)
@@ -34,7 +34,7 @@
/**
*
* @author chemit
- * @deprecated since 1.6.0, the {@link VersionNumberutil is deprecated)
+ * @deprecated since 1.6.0, the {@link VersionNumberUtil} is deprecated)
*/
@Deprecated
public class VersionNumberUtilTest extends TestCase { // VersionNumberUtilTest
1
0
Author: fdesbois
Date: 2009-12-17 11:42:00 +0100 (Thu, 17 Dec 2009)
New Revision: 1710
Modified:
trunk/pom.xml
Log:
Change mavenpom version
Modified: trunk/pom.xml
===================================================================
--- trunk/pom.xml 2009-12-17 09:45:09 UTC (rev 1709)
+++ trunk/pom.xml 2009-12-17 10:42:00 UTC (rev 1710)
@@ -11,7 +11,7 @@
<parent>
<groupId>org.nuiton</groupId>
<artifactId>mavenpom</artifactId>
- <version>1.1.1</version>
+ <version>1.1.2</version>
</parent>
<artifactId>nuiton-utils</artifactId>
1
0
r1709 - in trunk/src: main/java/org/nuiton/i18n main/java/org/nuiton/util main/resources/i18n site/apt test/java/org/nuiton/i18n/bundle
by echatellier@users.nuiton.org 17 Dec '09
by echatellier@users.nuiton.org 17 Dec '09
17 Dec '09
Author: echatellier
Date: 2009-12-17 10:45:09 +0100 (Thu, 17 Dec 2009)
New Revision: 1709
Modified:
trunk/src/main/java/org/nuiton/i18n/I18n.java
trunk/src/main/java/org/nuiton/util/ApplicationConfig.java
trunk/src/main/java/org/nuiton/util/EnumConverter.java
trunk/src/main/java/org/nuiton/util/FileCompletion.java
trunk/src/main/java/org/nuiton/util/MonthEnum.java
trunk/src/main/java/org/nuiton/util/ObjectUtil.java
trunk/src/main/java/org/nuiton/util/ReflectUtil.java
trunk/src/main/java/org/nuiton/util/Resource.java
trunk/src/main/java/org/nuiton/util/URIConverter.java
trunk/src/main/java/org/nuiton/util/URLConverter.java
trunk/src/main/java/org/nuiton/util/Version.java
trunk/src/main/java/org/nuiton/util/VersionConverter.java
trunk/src/main/java/org/nuiton/util/VersionNumberConverter.java
trunk/src/main/resources/i18n/nuiton-utils-en_GB.properties
trunk/src/main/resources/i18n/nuiton-utils-fr_FR.properties
trunk/src/site/apt/nuitonUtil.apt
trunk/src/test/java/org/nuiton/i18n/bundle/I18nBundleManagerTest.java
Log:
Rename i18n keys.
Modified: trunk/src/main/java/org/nuiton/i18n/I18n.java
===================================================================
--- trunk/src/main/java/org/nuiton/i18n/I18n.java 2009-12-17 09:31:15 UTC (rev 1708)
+++ trunk/src/main/java/org/nuiton/i18n/I18n.java 2009-12-17 09:45:09 UTC (rev 1709)
@@ -157,7 +157,7 @@
try {
return applyFilter(String.format(message, args));
} catch (Exception zzz) {
- log.warn(I18n._("lutinutil.error.i18n.untranslated.message", message), zzz);
+ log.warn(I18n._("nuitonutil.error.i18n.untranslated.message", message), zzz);
return applyFilter(message);
}
}
@@ -187,7 +187,7 @@
try {
return String.format(message, args);
} catch (Exception eee) {
- log.warn(I18n._("lutinutil.error.i18n.unformated.message", message, Arrays.toString(args)), eee);
+ log.warn(I18n._("nuitonutil.error.i18n.unformated.message", message, Arrays.toString(args)), eee);
return message;
}
}
Modified: trunk/src/main/java/org/nuiton/util/ApplicationConfig.java
===================================================================
--- trunk/src/main/java/org/nuiton/util/ApplicationConfig.java 2009-12-17 09:31:15 UTC (rev 1708)
+++ trunk/src/main/java/org/nuiton/util/ApplicationConfig.java 2009-12-17 09:45:09 UTC (rev 1709)
@@ -456,7 +456,7 @@
save(file, false, excludeKeys);
} catch (IOException eee) {
if (log.isWarnEnabled()) {
- log.warn(_("lutinutil.error.applicationconfig.save", file), eee);
+ log.warn(_("nuitonutil.error.applicationconfig.save", file), eee);
}
}
}
@@ -473,7 +473,7 @@
save(file, false, excludeKeys);
} catch (IOException eee) {
if (log.isWarnEnabled()) {
- log.warn(_("lutinutil.error.applicationconfig.save", file), eee);
+ log.warn(_("nuitonutil.error.applicationconfig.save", file), eee);
}
}
}
Modified: trunk/src/main/java/org/nuiton/util/EnumConverter.java
===================================================================
--- trunk/src/main/java/org/nuiton/util/EnumConverter.java 2009-12-17 09:31:15 UTC (rev 1708)
+++ trunk/src/main/java/org/nuiton/util/EnumConverter.java 2009-12-17 09:45:09 UTC (rev 1709)
@@ -55,7 +55,7 @@
if (useDefault) {
return defaultValue;
}
- throw new ConversionException(_("lutinutil.error.convertor.noValue", this));
+ throw new ConversionException(_("nuitonutil.error.convertor.noValue", this));
}
if (isEnabled(aClass, enumType)) {
Object result;
@@ -78,7 +78,7 @@
return result;
}
}
- throw new ConversionException(_("lutinutil.error.no.convertor", aClass.getName(), value));
+ throw new ConversionException(_("nuitonutil.error.no.convertor", aClass.getName(), value));
}
public EnumConverter(Class<?> enumType, Object defaultValue) {
Modified: trunk/src/main/java/org/nuiton/util/FileCompletion.java
===================================================================
--- trunk/src/main/java/org/nuiton/util/FileCompletion.java 2009-12-17 09:31:15 UTC (rev 1708)
+++ trunk/src/main/java/org/nuiton/util/FileCompletion.java 2009-12-17 09:45:09 UTC (rev 1709)
@@ -110,13 +110,13 @@
*/
public String read() throws IOException {
if (creation) {
- System.out.println(_("lutinutil.fileCompletion.save"));
+ System.out.println(_("nuitonutil.fileCompletion.save"));
}
if (exit) {
- System.out.println(_("lutinutil.fileCompletion.exit"));
+ System.out.println(_("nuitonutil.fileCompletion.exit"));
}
- System.out.println(_("lutinutil.fileCompletion.cancel"));
- System.out.println(_("lutinutil.fileCompletion.enter"));
+ System.out.println(_("nuitonutil.fileCompletion.cancel"));
+ System.out.println(_("nuitonutil.fileCompletion.enter"));
String line = System.getProperty("user.dir");
File f;
line = line + readLine("> " + line + File.separator);
Modified: trunk/src/main/java/org/nuiton/util/MonthEnum.java
===================================================================
--- trunk/src/main/java/org/nuiton/util/MonthEnum.java 2009-12-17 09:31:15 UTC (rev 1708)
+++ trunk/src/main/java/org/nuiton/util/MonthEnum.java 2009-12-17 09:45:09 UTC (rev 1709)
@@ -26,18 +26,18 @@
*/
public enum MonthEnum {
- JANUARY(_("lutinutil.month.january")),
- FEBRUARY(_("lutinutil.month.february")),
- MARCH(_("lutinutil.month.march")),
- APRIL(_("lutinutil.month.april")),
- MAY(_("lutinutil.month.may")),
- JUNE(_("lutinutil.month.june")),
- JULY(_("lutinutil.month.july")),
- AUGUST(_("lutinutil.month.august")),
- SEPTEMBER(_("lutinutil.month.september")),
- OCTOBER(_("lutinutil.month.october")),
- NOVEMBER(_("lutinutil.month.november")),
- DECEMBER(_("lutinutil.month.december"));
+ JANUARY(_("nuitonutil.month.january")),
+ FEBRUARY(_("nuitonutil.month.february")),
+ MARCH(_("nuitonutil.month.march")),
+ APRIL(_("nuitonutil.month.april")),
+ MAY(_("nuitonutil.month.may")),
+ JUNE(_("nuitonutil.month.june")),
+ JULY(_("nuitonutil.month.july")),
+ AUGUST(_("nuitonutil.month.august")),
+ SEPTEMBER(_("nuitonutil.month.september")),
+ OCTOBER(_("nuitonutil.month.october")),
+ NOVEMBER(_("nuitonutil.month.november")),
+ DECEMBER(_("nuitonutil.month.december"));
private final String libelle;
@@ -54,9 +54,9 @@
try {
monthEnum = MonthEnum.valueOf(month.toUpperCase());
} catch (IllegalArgumentException e) {
- System.err.println(_("lutinutil.error.unfound.month", month, defaultValue));
+ System.err.println(_("nuitonutil.error.unfound.month", month, defaultValue));
} catch (NullPointerException e) {
- System.err.println(_("lutinutil.error.unfound.month", month, defaultValue));
+ System.err.println(_("nuitonutil.error.unfound.month", month, defaultValue));
}
return monthEnum == null ? defaultValue : monthEnum;
}
Modified: trunk/src/main/java/org/nuiton/util/ObjectUtil.java
===================================================================
--- trunk/src/main/java/org/nuiton/util/ObjectUtil.java 2009-12-17 09:31:15 UTC (rev 1708)
+++ trunk/src/main/java/org/nuiton/util/ObjectUtil.java 2009-12-17 09:45:09 UTC (rev 1709)
@@ -166,7 +166,7 @@
}
if (log.isDebugEnabled()) {
- log.debug(_("lutinutil.debug.objectutil.invoke", m, Arrays.toString(parameters)));
+ log.debug(_("nuitonutil.debug.objectutil.invoke", m, Arrays.toString(parameters)));
}
Object result = m.invoke(o, parameters);
return result;
@@ -259,7 +259,7 @@
}
if (log.isDebugEnabled()) {
- log.debug(_("lutinutil.debug.objectutil.create", clazz, Arrays.toString(parameters)));
+ log.debug(_("nuitonutil.debug.objectutil.create", clazz, Arrays.toString(parameters)));
}
T result = c.newInstance(parameters);
@@ -271,7 +271,7 @@
}
}
}
- throw new IllegalArgumentException(_("lutinutil.debug.objectutil.instantiate",
+ throw new IllegalArgumentException(_("nuitonutil.debug.objectutil.instantiate",
clazz, Arrays.toString(params)));
}
Modified: trunk/src/main/java/org/nuiton/util/ReflectUtil.java
===================================================================
--- trunk/src/main/java/org/nuiton/util/ReflectUtil.java 2009-12-17 09:31:15 UTC (rev 1708)
+++ trunk/src/main/java/org/nuiton/util/ReflectUtil.java 2009-12-17 09:45:09 UTC (rev 1709)
@@ -112,10 +112,10 @@
@SuppressWarnings({"unchecked"})
public static <T extends Enum<T>> Class<T> getEnumClass(Class<?> type) throws IllegalArgumentException {
if (type == null) {
- throw new IllegalArgumentException(_("lutinutil.error.null.parameter", "type"));
+ throw new IllegalArgumentException(_("nuitonutil.error.null.parameter", "type"));
}
if (!type.isEnum()) {
- throw new IllegalArgumentException(_("lutinutil.error.not.an.enum", type));
+ throw new IllegalArgumentException(_("nuitonutil.error.not.an.enum", type));
}
return (Class<T>) type;
}
Modified: trunk/src/main/java/org/nuiton/util/Resource.java
===================================================================
--- trunk/src/main/java/org/nuiton/util/Resource.java 2009-12-17 09:31:15 UTC (rev 1708)
+++ trunk/src/main/java/org/nuiton/util/Resource.java 2009-12-17 09:45:09 UTC (rev 1709)
@@ -94,7 +94,7 @@
method.setAccessible(true);
method.invoke(classLoader, url);
} catch (Exception eee) {
- throw new RuntimeException(_("lutinutil.error.add.url.in.classloader", classLoader, eee));
+ throw new RuntimeException(_("nuitonutil.error.add.url.in.classloader", classLoader, eee));
//throw new RuntimeException("Can't add url in classloader " + classLoader,eee);
}
}
@@ -112,7 +112,7 @@
return url;
}
- throw new ResourceNotFoundException(_("lutinutil.error.resource.not.found", name));
+ throw new ResourceNotFoundException(_("nuitonutil.error.resource.not.found", name));
}
/**
@@ -128,7 +128,7 @@
try {
return file.toURI().toURL();
} catch (MalformedURLException eee) {
- log.warn(_("lutinutil.error.convert.file.to.url", file, eee.getMessage()));
+ log.warn(_("nuitonutil.error.convert.file.to.url", file, eee.getMessage()));
}
}
@@ -456,7 +456,7 @@
}
return result;
} catch (IOException eee) {
- throw new ResourceException(_("lutinutil.error.get.url.from.zip", zipFile.getAbsolutePath(), eee.getMessage()));
+ throw new ResourceException(_("nuitonutil.error.get.url.from.zip", zipFile.getAbsolutePath(), eee.getMessage()));
}
}
@@ -497,7 +497,7 @@
}
return result;
} catch (IOException eee) {
- throw new ResourceException(_("lutinutil.error.get.url.from.zip", jarfile.getAbsolutePath(), eee.getMessage()));
+ throw new ResourceException(_("nuitonutil.error.get.url.from.zip", jarfile.getAbsolutePath(), eee.getMessage()));
}
}
@@ -552,7 +552,7 @@
}
return urlList;
} catch (MalformedURLException eee) {
- throw new ResourceException(_("lutinutil.error.convert.file.to.url", repository + " (pattern " + pattern + ") ", eee.getMessage()));
+ throw new ResourceException(_("nuitonutil.error.convert.file.to.url", repository + " (pattern " + pattern + ") ", eee.getMessage()));
//throw new ResourceException("Le fichier n'a pu être converti en URL", eee);
}
}
@@ -671,7 +671,7 @@
}
if (log.isWarnEnabled()) {
- log.warn(_("lutinutil.error.unknown.url.type", url));
+ log.warn(_("nuitonutil.error.unknown.url.type", url));
}
return false;
}
Modified: trunk/src/main/java/org/nuiton/util/URIConverter.java
===================================================================
--- trunk/src/main/java/org/nuiton/util/URIConverter.java 2009-12-17 09:31:15 UTC (rev 1708)
+++ trunk/src/main/java/org/nuiton/util/URIConverter.java 2009-12-17 09:45:09 UTC (rev 1709)
@@ -37,7 +37,7 @@
@Override
public Object convert(Class aClass, Object value) {
if (value == null) {
- throw new ConversionException(_("lutinutil.error.convertor.noValue", this));
+ throw new ConversionException(_("nuitonutil.error.convertor.noValue", this));
}
if (isEnabled(aClass)) {
Object result;
@@ -50,7 +50,7 @@
return result;
}
}
- throw new ConversionException(_("lutinutil.error.no.convertor", aClass.getName(), value));
+ throw new ConversionException(_("nuitonutil.error.no.convertor", aClass.getName(), value));
}
protected URI valueOf(String value) {
@@ -59,7 +59,7 @@
result = new URI(value);
return result;
} catch (URISyntaxException e) {
- throw new ConversionException(_("lutinutil.error.url.convertor", value, this, e.getMessage()));
+ throw new ConversionException(_("nuitonutil.error.url.convertor", value, this, e.getMessage()));
}
}
Modified: trunk/src/main/java/org/nuiton/util/URLConverter.java
===================================================================
--- trunk/src/main/java/org/nuiton/util/URLConverter.java 2009-12-17 09:31:15 UTC (rev 1708)
+++ trunk/src/main/java/org/nuiton/util/URLConverter.java 2009-12-17 09:45:09 UTC (rev 1709)
@@ -38,7 +38,7 @@
@Override
public Object convert(Class aClass, Object value) {
if (value == null) {
- throw new ConversionException(_("lutinutil.error.convertor.noValue", this));
+ throw new ConversionException(_("nuitonutil.error.convertor.noValue", this));
}
if (isEnabled(aClass)) {
Object result;
@@ -51,7 +51,7 @@
return result;
}
}
- throw new ConversionException(_("lutinutil.error.no.convertor", aClass.getName(), value));
+ throw new ConversionException(_("nuitonutil.error.no.convertor", aClass.getName(), value));
}
protected URL valueOf(String value) {
@@ -60,7 +60,7 @@
result = new URL(value);
return result;
} catch (MalformedURLException e) {
- throw new ConversionException(_("lutinutil.error.url.convertor", value, this, e.getMessage()));
+ throw new ConversionException(_("nuitonutil.error.url.convertor", value, this, e.getMessage()));
}
}
Modified: trunk/src/main/java/org/nuiton/util/Version.java
===================================================================
--- trunk/src/main/java/org/nuiton/util/Version.java 2009-12-17 09:31:15 UTC (rev 1708)
+++ trunk/src/main/java/org/nuiton/util/Version.java 2009-12-17 09:45:09 UTC (rev 1709)
@@ -125,7 +125,7 @@
if (!matcher.matches()) {
// not a known pattern
- throw new IllegalArgumentException(_("lutinutil.error.version.pattern", version));
+ throw new IllegalArgumentException(_("nuitonutil.error.version.pattern", version));
}
// get numbers as string
Modified: trunk/src/main/java/org/nuiton/util/VersionConverter.java
===================================================================
--- trunk/src/main/java/org/nuiton/util/VersionConverter.java 2009-12-17 09:31:15 UTC (rev 1708)
+++ trunk/src/main/java/org/nuiton/util/VersionConverter.java 2009-12-17 09:45:09 UTC (rev 1709)
@@ -42,7 +42,7 @@
@Override
public Object convert(Class aClass, Object value) {
if (value == null) {
- throw new ConversionException(_("lutinutil.error.convertor.noValue", this));
+ throw new ConversionException(_("nuitonutil.error.convertor.noValue", this));
}
if (isEnabled(aClass)) {
Object result;
@@ -55,11 +55,11 @@
result = VersionUtil.valueOf((String) value);
return result;
} catch (IllegalArgumentException e) {
- throw new ConversionException(_("lutinutil.error.version.convertor", value, this, e.getMessage()), e);
+ throw new ConversionException(_("nuitonutil.error.version.convertor", value, this, e.getMessage()), e);
}
}
}
- throw new ConversionException(_("lutinutil.error.no.convertor", aClass.getName(), value));
+ throw new ConversionException(_("nuitonutil.error.no.convertor", aClass.getName(), value));
}
protected boolean isEnabled(Class<?> aClass) {
Modified: trunk/src/main/java/org/nuiton/util/VersionNumberConverter.java
===================================================================
--- trunk/src/main/java/org/nuiton/util/VersionNumberConverter.java 2009-12-17 09:31:15 UTC (rev 1708)
+++ trunk/src/main/java/org/nuiton/util/VersionNumberConverter.java 2009-12-17 09:45:09 UTC (rev 1709)
@@ -37,7 +37,7 @@
public Object convert(Class aClass, Object value) {
if (value == null) {
- throw new ConversionException(_("lutinutil.error.convertor.noValue", this));
+ throw new ConversionException(_("nuitonutil.error.convertor.noValue", this));
}
if (isEnabled(aClass)) {
Object result;
@@ -50,7 +50,7 @@
return result;
}
}
- throw new ConversionException(_("lutinutil.error.no.convertor", aClass.getName(), value));
+ throw new ConversionException(_("nuitonutil.error.no.convertor", aClass.getName(), value));
}
public VersionNumberConverter() {
@@ -74,7 +74,7 @@
result = new VersionNumber(numbers);
return result;
} catch (IllegalArgumentException e) {
- throw new ConversionException(_("lutinutil.error.url.convertor", value, this, e.getMessage()));
+ throw new ConversionException(_("nuitonutil.error.url.convertor", value, this, e.getMessage()));
}
}
Modified: trunk/src/main/resources/i18n/nuiton-utils-en_GB.properties
===================================================================
--- trunk/src/main/resources/i18n/nuiton-utils-en_GB.properties 2009-12-17 09:31:15 UTC (rev 1708)
+++ trunk/src/main/resources/i18n/nuiton-utils-en_GB.properties 2009-12-17 09:45:09 UTC (rev 1709)
@@ -1,36 +1,36 @@
hello\ you\ \!=hello you \!
-lutinutil.debug.objectutil.create=Try to create %s with %s
-lutinutil.debug.objectutil.instantiate=Can't instantiate %s with params %s
-lutinutil.debug.objectutil.invoke=Invoke %s with %s
-lutinutil.error.add.url.in.classloader=Can't add url in classloader %1$s for reason %2$s
-lutinutil.error.applicationconfig.save=Can't save config in file %s
-lutinutil.error.convert.file.to.url=Can't convert %s for reason %s
-lutinutil.error.convertor.noValue=No value specified for converter %s
-lutinutil.error.get.url.from.zip=Error while reading %s \: %s
-lutinutil.error.i18n.unformated.message=Message can't be formatted\: '%s' with arguments %s
-lutinutil.error.i18n.untranslated.message=Message can't be translated\: '%s'
-lutinutil.error.no.convertor=no convertor found for type %2$s and objet '%1$s'
-lutinutil.error.not.an.enum=The type %1$s ins not an Enum type
-lutinutil.error.null.parameter=The parameter %1$s is null\!
-lutinutil.error.resource.not.found=Can't find resource \: %s
-lutinutil.error.unfound.month=could not found month from '%s', use default month '%s'
-lutinutil.error.unknown.url.type=could not treate unknown type of url %1$s
-lutinutil.error.url.convertor=a problem occurs while converting value '%s' with url convertor %s for reason %s
-lutinutil.error.version.convertor=Could not convert version %%1$s with converter %2$s for reason \: %3$s
-lutinutil.error.version.pattern=Pattern of version not found for %1$s
-lutinutil.fileCompletion.cancel=.. to cancel or return to parent directory
-lutinutil.fileCompletion.enter=Enter to display file list, or to complete path
-lutinutil.fileCompletion.exit=Enter "\!q" to exit
-lutinutil.fileCompletion.save=Enter "\!s" in the end of the file name to save
-lutinutil.month.april=april
-lutinutil.month.august=august
-lutinutil.month.december=december
-lutinutil.month.february=february
-lutinutil.month.january=january
-lutinutil.month.july=july
-lutinutil.month.june=june
-lutinutil.month.march=march
-lutinutil.month.may=may
-lutinutil.month.november=november
-lutinutil.month.october=october
-lutinutil.month.september=september
+nuitonutil.debug.objectutil.create=Try to create %s with %s
+nuitonutil.debug.objectutil.instantiate=Can't instantiate %s with params %s
+nuitonutil.debug.objectutil.invoke=Invoke %s with %s
+nuitonutil.error.add.url.in.classloader=Can't add url in classloader %1$s for reason %2$s
+nuitonutil.error.applicationconfig.save=Can't save config in file %s
+nuitonutil.error.convert.file.to.url=Can't convert %s for reason %s
+nuitonutil.error.convertor.noValue=No value specified for converter %s
+nuitonutil.error.get.url.from.zip=Error while reading %s \: %s
+nuitonutil.error.i18n.unformated.message=Message can't be formatted\: '%s' with arguments %s
+nuitonutil.error.i18n.untranslated.message=Message can't be translated\: '%s'
+nuitonutil.error.no.convertor=no convertor found for type %2$s and objet '%1$s'
+nuitonutil.error.not.an.enum=The type %1$s ins not an Enum type
+nuitonutil.error.null.parameter=The parameter %1$s is null\!
+nuitonutil.error.resource.not.found=Can't find resource \: %s
+nuitonutil.error.unfound.month=could not found month from '%s', use default month '%s'
+nuitonutil.error.unknown.url.type=could not treate unknown type of url %1$s
+nuitonutil.error.url.convertor=a problem occurs while converting value '%s' with url convertor %s for reason %s
+nuitonutil.error.version.convertor=Could not convert version %%1$s with converter %2$s for reason \: %3$s
+nuitonutil.error.version.pattern=Pattern of version not found for %1$s
+nuitonutil.fileCompletion.cancel=.. to cancel or return to parent directory
+nuitonutil.fileCompletion.enter=Enter to display file list, or to complete path
+nuitonutil.fileCompletion.exit=Enter "\!q" to exit
+nuitonutil.fileCompletion.save=Enter "\!s" in the end of the file name to save
+nuitonutil.month.april=april
+nuitonutil.month.august=august
+nuitonutil.month.december=december
+nuitonutil.month.february=february
+nuitonutil.month.january=january
+nuitonutil.month.july=july
+nuitonutil.month.june=june
+nuitonutil.month.march=march
+nuitonutil.month.may=may
+nuitonutil.month.november=november
+nuitonutil.month.october=october
+nuitonutil.month.september=september
Modified: trunk/src/main/resources/i18n/nuiton-utils-fr_FR.properties
===================================================================
--- trunk/src/main/resources/i18n/nuiton-utils-fr_FR.properties 2009-12-17 09:31:15 UTC (rev 1708)
+++ trunk/src/main/resources/i18n/nuiton-utils-fr_FR.properties 2009-12-17 09:45:09 UTC (rev 1709)
@@ -1,36 +1,36 @@
hello\ you\ \!=Salut toi\!
-lutinutil.debug.objectutil.create=Essaye de cr\u00E9er %s avec %s
-lutinutil.debug.objectutil.instantiate=Ne peut pas instancier %s avec les param\u00EAtres %s
-lutinutil.debug.objectutil.invoke=Invocation de %s avec %s
-lutinutil.error.add.url.in.classloader=Impossible d'ajouter une url dans le classloader %s pour la raison \: %s
-lutinutil.error.applicationconfig.save=Impossible de sauvegarder le fichier de configuration dans %s
-lutinutil.error.convert.file.to.url=Le fichier '%1$s' n'a pas pu \u00EAtre converti en URL pour la raison suivante \: %2$S
-lutinutil.error.convertor.noValue=Aucune valeur \u00E0 convertir pour le convertisseur %s
-lutinutil.error.get.url.from.zip=Erreur lors de la lecture du fichier compress\u00E9 %1$s \: %2$s
-lutinutil.error.i18n.unformated.message=Le message suivant n''a pas pu \u00EAtre format\u00E9 \: '%s' avec les arguments %s
-lutinutil.error.i18n.untranslated.message=Le message suivant n'a pas pu \u00EAtre traduit \: '%s'
-lutinutil.error.no.convertor=Aucun convertisseur trouv\u00E9 pour le type %2$s et l''objet '%1$s'
-lutinutil.error.not.an.enum=Le type %1$s n'est pas une enumeration java
-lutinutil.error.null.parameter=Le param\u00E8tre '%1$s' est null\!
-lutinutil.error.resource.not.found=Impossible de trouver la ressource \: %s
-lutinutil.error.unfound.month=n'a pas pu trouv\u00E9 le mois \u00E0 partir de '%s', utilise le mois par d\u00E9faut '%s'
-lutinutil.error.unknown.url.type=could not treate unknown type of url %1$s
-lutinutil.error.url.convertor=Un probl\u00E8me est apparu lors de la convertion en url de '%s' avec le convertisseur %s pour la raison suivante \: %s
-lutinutil.error.version.convertor=N'a pas pu convertir la valeur %%1$s avec le converter %2$s pour la raison suivante \: %3$s
-lutinutil.error.version.pattern=Pattern de version non connu pour %1$s
-lutinutil.fileCompletion.cancel=.. pour annuler ou pour revenir au repertoire pr\u00E9c\u00E9dent
-lutinutil.fileCompletion.enter=Entrer pour afficher la liste des fichiers, ou pour compl\u00E9ter le chemin
-lutinutil.fileCompletion.exit=Saisir "\!q" pour quitter
-lutinutil.fileCompletion.save=Saisir "\!s" a la fin du nom de fichier pour l'enregistrer
-lutinutil.month.april=avril
-lutinutil.month.august=ao\u00FBt
-lutinutil.month.december=d\u00E9cembre
-lutinutil.month.february=f\u00E9vrier
-lutinutil.month.january=janvier
-lutinutil.month.july=juillet
-lutinutil.month.june=juin
-lutinutil.month.march=mars
-lutinutil.month.may=mai
-lutinutil.month.november=novembre
-lutinutil.month.october=octobre
-lutinutil.month.september=septembre
+nuitonutil.debug.objectutil.create=Essaye de cr\u00E9er %s avec %s
+nuitonutil.debug.objectutil.instantiate=Ne peut pas instancier %s avec les param\u00EAtres %s
+nuitonutil.debug.objectutil.invoke=Invocation de %s avec %s
+nuitonutil.error.add.url.in.classloader=Impossible d'ajouter une url dans le classloader %s pour la raison \: %s
+nuitonutil.error.applicationconfig.save=Impossible de sauvegarder le fichier de configuration dans %s
+nuitonutil.error.convert.file.to.url=Le fichier '%1$s' n'a pas pu \u00EAtre converti en URL pour la raison suivante \: %2$S
+nuitonutil.error.convertor.noValue=Aucune valeur \u00E0 convertir pour le convertisseur %s
+nuitonutil.error.get.url.from.zip=Erreur lors de la lecture du fichier compress\u00E9 %1$s \: %2$s
+nuitonutil.error.i18n.unformated.message=Le message suivant n''a pas pu \u00EAtre format\u00E9 \: '%s' avec les arguments %s
+nuitonutil.error.i18n.untranslated.message=Le message suivant n'a pas pu \u00EAtre traduit \: '%s'
+nuitonutil.error.no.convertor=Aucun convertisseur trouv\u00E9 pour le type %2$s et l''objet '%1$s'
+nuitonutil.error.not.an.enum=Le type %1$s n'est pas une enumeration java
+nuitonutil.error.null.parameter=Le param\u00E8tre '%1$s' est null\!
+nuitonutil.error.resource.not.found=Impossible de trouver la ressource \: %s
+nuitonutil.error.unfound.month=n'a pas pu trouv\u00E9 le mois \u00E0 partir de '%s', utilise le mois par d\u00E9faut '%s'
+nuitonutil.error.unknown.url.type=could not treate unknown type of url %1$s
+nuitonutil.error.url.convertor=Un probl\u00E8me est apparu lors de la convertion en url de '%s' avec le convertisseur %s pour la raison suivante \: %s
+nuitonutil.error.version.convertor=N'a pas pu convertir la valeur %%1$s avec le converter %2$s pour la raison suivante \: %3$s
+nuitonutil.error.version.pattern=Pattern de version non connu pour %1$s
+nuitonutil.fileCompletion.cancel=.. pour annuler ou pour revenir au repertoire pr\u00E9c\u00E9dent
+nuitonutil.fileCompletion.enter=Entrer pour afficher la liste des fichiers, ou pour compl\u00E9ter le chemin
+nuitonutil.fileCompletion.exit=Saisir "\!q" pour quitter
+nuitonutil.fileCompletion.save=Saisir "\!s" a la fin du nom de fichier pour l'enregistrer
+nuitonutil.month.april=avril
+nuitonutil.month.august=ao\u00FBt
+nuitonutil.month.december=d\u00E9cembre
+nuitonutil.month.february=f\u00E9vrier
+nuitonutil.month.january=janvier
+nuitonutil.month.july=juillet
+nuitonutil.month.june=juin
+nuitonutil.month.march=mars
+nuitonutil.month.may=mai
+nuitonutil.month.november=novembre
+nuitonutil.month.october=octobre
+nuitonutil.month.september=septembre
Modified: trunk/src/site/apt/nuitonUtil.apt
===================================================================
--- trunk/src/site/apt/nuitonUtil.apt 2009-12-17 09:31:15 UTC (rev 1708)
+++ trunk/src/site/apt/nuitonUtil.apt 2009-12-17 09:45:09 UTC (rev 1709)
@@ -1,11 +1,11 @@
----
-Documentation - LutinUtil
+Documentation - NuitonUtils
----
----
2009-08-23
----
- LutinUtil contient un ensemble de librairies trop petites pour avoir
+ NuitonUtils contient un ensemble de librairies trop petites pour avoir
leur propre projet. Elles sont aussi utile à la plupart des projets de
Code Lutin.
@@ -94,7 +94,7 @@
Liste des librairies
- Cette liste répertorie l'ensemble des librairies de LutinUtil.
+ Cette liste répertorie l'ensemble des librairies de NuitonUtils.
* Configuration
Modified: trunk/src/test/java/org/nuiton/i18n/bundle/I18nBundleManagerTest.java
===================================================================
--- trunk/src/test/java/org/nuiton/i18n/bundle/I18nBundleManagerTest.java 2009-12-17 09:31:15 UTC (rev 1708)
+++ trunk/src/test/java/org/nuiton/i18n/bundle/I18nBundleManagerTest.java 2009-12-17 09:45:09 UTC (rev 1709)
@@ -49,9 +49,9 @@
* dummyOnlyen-en
* <p/>
* dummy-fr_FR
- * lutinutil-fr_FR
+ * nuitonutils-fr_FR
* dummy-en_GB
- * lutinutil-en_GB
+ * nuitonutils-en_GB
* dummy-en_US
* <p/>
*
@@ -73,7 +73,7 @@
veryDummy(true, false, false, false, false, false),
dummy(true, true, true, true, true, true),
- lutinutil(false, false, true, false, false, true),
+ nuitonutils(false, false, true, false, false, true),
onlyfr(true, true, false, false, false, false),
onylfr2(false, true, false, false, false, false),
onlyen(true, false, false, true, false, false);
1
0
Author: echatellier
Date: 2009-12-17 10:31:15 +0100 (Thu, 17 Dec 2009)
New Revision: 1708
Added:
trunk/src/site/apt/CommandLineArgumentApplication.apt
trunk/src/site/apt/nuitonUtil.apt
Removed:
trunk/src/site/apt/LutinUtil.apt
trunk/src/site/rst/
Modified:
trunk/src/site/site.xml
Log:
Update site (all doc moved to apt file format)
Copied: trunk/src/site/apt/CommandLineArgumentApplication.apt (from rev 1707, trunk/src/site/rst/CommandLineArgumentApplication.rst)
===================================================================
--- trunk/src/site/apt/CommandLineArgumentApplication.apt (rev 0)
+++ trunk/src/site/apt/CommandLineArgumentApplication.apt 2009-12-17 09:31:15 UTC (rev 1708)
@@ -0,0 +1,126 @@
+Argument d'application
+
+ Il y a deux type d'argument d'application:
+
+ * les arguments permettant de modifier la configuration qui peuvent aussi
+ être dans un fichier de configuration ou en variable d'environnement.
+
+ * les arguments permettant d'indiquer des actions a faire a l'application
+
+Les options de configuration
+
+ Les options de configuration peuvent être décrit directement par un POJO
+ avec des annotations::
+
+-----------------------------------------------------------------------------------
+ @OptionConfigOrder("resource MonApp.properties", "file /etc/MonApp.properties",
+ "optionfile configFile", "env", "line")
+ public class MonAppConfig extends OptionConfig {
+
+ @Option
+ @OptionSaveFile
+ public File configFile = new File("$HOME/.MonApp");
+
+ @Option(pattern [^\s]+)
+ public String username = "anonyous";
+
+ @Option(pattern ..)
+ public String lang = "fr";
+
+ @Option(pattern ..)
+ public String country = "FR";
+
+ @Option
+ public boolean showGui = true;
+
+ @Option(min=10, max=10)
+ public List<Integer> value;
+
+ @Unparsed
+ public List<String> other;
+ }
+-----------------------------------------------------------------------------------
+
+La classe OptionConfig
+
+ La classe OptionConfig contient plusieurs méthodes:
+
+ * load sans argument qui permet de charger le POJO en fonction de
+ OptionConfigOrder
+
+ * load(File) qui permet de charger le POJO seulement en fonction d'un
+ fichier. Il bien sur possible d'appeler load() puis load(File).
+
+ * save qui permet de sauver les informations du POJO, le fichier ou sauver
+ les options est indiqué par l'annotation <<<@OptionSaveFile>>>
+
+Annotation OptionConfigOrder
+
+ OptionConfigOrder permet de déterminer l'ordre de recherche de la bonne
+ valeur des options. Le dernier indiqué sera le dernier lu et donc celui qui
+ aura raison.
+
+ * resource
+ indique un fichier resource a rechercher dans le classpath
+
+ * file
+ indique un fichier sur le systeme de fichier
+
+ * optionfile
+ indique un fichier dont le chemin est indiqué par une option
+
+ * env
+ indique les variables d'environnement du processus
+
+ * sline
+ indique les options sur la ligne de commande
+
+Implantation
+
+ * On charge dans un objet <<Properties>> chaque entre de
+ <<OptionConfigOrder>> sauf <<optionfile>> s'il y en a.
+
+ * On chaine tous les fichiers de proprietes pour pouvoir demander
+ l'information au dernier qui recherchera lui meme dans son pere s'il n'a pas
+ l'information.
+
+ * Pour chaque <<optionfile>> on demande sa valeur, on crée le fichier de
+ propriété et on l'ajoute dans la chaine à la bonne place
+
+ * Pour chaque option trouvé dans le POJO on met a jour sa valeur avec la
+ valeur trouvé dans les propriétés.
+
+Annotation Option
+
+ Indique une option possible. Elle peut contenir:
+
+ * description
+
+ * pattern
+
+ * alias
+
+ * min
+
+ * max
+
+ Par defaut l'option sur la ligne de commande sera le nom de la variable precedé de --
+
+Annotation Unparsed
+
+ Indique que toutes les options de la ligne de commande non reconnu finisse dans ce champs
+ Il est possible de type la collection autrement que par String.
+
+Annotation OptionSaveFile
+
+ Indique le fichier a utiliser pour sauver les options
+
+* Les actions
+
+ TODO: comment différencier les actions des options ? comment reutiliser le travail de tony ?
+
+* Amélioration possible
+
+ - Générer automatiquement par un plugin maven les methodes get/set sur les options
+ - Gérer les options read/write et read
+ - un plugin maven qui verifie la coherence des options
Deleted: trunk/src/site/apt/LutinUtil.apt
===================================================================
--- trunk/src/site/apt/LutinUtil.apt 2009-12-16 14:50:21 UTC (rev 1707)
+++ trunk/src/site/apt/LutinUtil.apt 2009-12-17 09:31:15 UTC (rev 1708)
@@ -1,312 +0,0 @@
-----
-Documentation - LutinUtil
-----
-----
-2009-08-23
-----
-
- LutinUtil contient un ensemble de librairies trop petites pour avoir
- leur propre projet. Elles sont aussi utile à la plupart des projets de
- Code Lutin.
-
-
-Resource
-
- Cette librairie permet de rechercher une ressource dans le maximum
- d'endroit possible et si elle est trouvée l'url de la ressource est
- retournée.
-
-------------------------------------------------------------------------------
- import org.nuiton.util.Resource;
- import java.net.URL;
- ...
- URL image = Resource.getURL("/images/bidulle.png");
- ...
-------------------------------------------------------------------------------
-
- Dans cet exemple l'image est recherchée sur le système de fichier
- local, si elle n'est pas trouvée, elle est recherché dans le
- classpath, et si elle n'est toujours pas trouvée une exception est
- alors levée.
-
-ArgumentsParser
-
- Cette librairie permet de traiter les arguments de la ligne de commande de
- façon simple mais évoluable. Son principe de fonctionnement est que l'on
- déclare les arguements que l'on attend sur la ligne de commande avec le nombre
- de paramètre qu'ils prennent et une petite description de l'option. Ensuite
- on dispose de toutes les fonctions utiles pour le traitement de la ligne de
- commande.
-
- Voici un exemple d'utilisation
-
-------------------------------------------------------------------------------
- import org.nuiton.util.ArgumentsParser;
- ...
- ArgumentsParser parser = new ArgumentsParser("ToPIA");
-
- parser.addOption("version", "affiche le numéro de version", new String[]{"--version", "-v"}, 0).setRepetitionMax(1);
-
- parser.addOption("help", "affiche l'aide de topia", new String[]{"--help", "-h"}, 0).setRepetitionMax(1);
-
- parser.addOption("start", "Lancement d'une application", new
- String[]{"--start", "-s"}, 1).setRepetitionMax(1);
-
- System.out.println(parser.checkCoherence());
- parser.parse(args);
-
- if(parser.hasParsedOption("help")){
- System.out.println(parser.usage());
- }else if (parser.hasParsedOption("start")){
- System.out.println ("--> Executing application: ");
- String arg = parser.getParsedOption("start")
- new Application(arg);
- }else if (parser.hasParsedOption("version")){
- System.out.println( "- Topia version 0.01 - " +
- "Get new release at http://www.codelutin.com/ -" );
- }
-------------------------------------------------------------------------------
-
- Cette librairie permet d'afficher l'aide de la ligne de commande::
-
-------------------------------------------------------------------------------
- System.out.println(parser.usage());
-------------------------------------------------------------------------------
-
- Elle permet aussi de vérifier le nombre de fois qu'une option de la ligne de
- commande est présente et que ce nombre est bien compris dans l'ensemble des
- valeurs acceptées, grâce au méthode *setRepetitionMax*, et *setRepetitionMin*.
-
- Si l'implantation par défaut du parseur d'option ne convient pas pour une de vos
- option, par exemple si le nombre de paramètre de l'option varie suivant la valeur
- du premier paramètre vous pouvez alors écrire votre propre Parser pour cette
- Option et l'utilisée avec les autres.
-
-Log
-
- Cette objet permet de suivre ce que fait une application simplement. Le
- développeur indique grâce à cette classe l'état dans lequel l'application est.
-
- Ensuite, il peut mettre des listeners sur cette classe qui afficheront
- les messages qui ont été envoyés. Ou afficheront l'état d'une tâche en train
- de s'exécuter.
-
-
-Liste des librairies
-
- Cette liste répertorie l'ensemble des librairies de LutinUtil.
-
-
-* Configuration
-
- Gestion de la configuration d'une l'application, de l'internationalisation,
- des numéros de versions, des ressources...
-
-** ApplicationConfig
-
- Gestion des fichiers de configuration, des variables d'environnement
- et des arguments de la ligne de commande.
-
-** Resource
-
- Recherche d'un fichier dans le système de fichiers et dans le classpath
- (.jar, .zip).
-
-** ClassLoaderUtil
-
- Récupération des urls d'un URLClassLoader.
-
-** LocaleConverter
-
- Conversion d'une chaîne en Locale.
-
-** SortedProperties
-
- Fichier de propriétés trié par ordre alphabétique.
-
-** RecursiveProperties
-
- Fichier de propriétés contenant des références à des propriétés de ce
- même fichier.
-
-** Version
-
- Représentation d'un numéro de version pour une application.
-
-** VersionConverter
-
- Conversion d'une chaine en VersionNumber.
-
-** VersionUtil
-
- Manipulation de numéros de version sous forme de chaînes
- (comparaison, incrémentation...).
-
-
-* Fichiers
-
- Gestion de fichiers.
-
-** FileUtil
-
- Opérations sur des fichiers. Copie, suppression, renommage,
- recherche, fichiers d'un répertoire, sous-répertoires d'un répertoire,
- récupération du basename ou de l'extension, création d'un fichier
- temporaire, comparaison de dates de création, récupération d'une chaîne,
- d'un Reader ou d'un Writer à partir d'un fichier, récupération du fichier
- saisi dans une boîte de dialogue, conversions en byte[], en Stream...
-
-** IOUtils
-
- Copie d'un fichier, chemin temporaire...
-
-** ZipUtil
-
- Opérations sur des fichiers Zip. Compression et décompression avec ou
- sans filtres, scan des fichiers créés ou écrasés lors de la décompression...
-
-** ZipStreamEncoder
-
- Encodage de fichiers Zip dans des threads.
-
-* Collections
-
- Gestion de collections et de tableaux.
-
-** CollectionUtil
-
- Manipulation des collections. Ajout de plusieurs éléments à une
- collection, conversion d'une collection non typée en collection typée.
-
-** ArrayUtil
-
- Opérations sur des tableaux. Concaténation, somme, recherche,
- conversion d'une liste en tableau, d'un String[] en int[].
-
-** BoundedList
-
- ArrayList avec un nombre d'élément minimum et maximum.
-
-** HashList
- Liste d'objets uniques.
-
-** TransformedList
- Liste d'objets transformables (interface Transformer).
-
-
-* Chaînes de caractères
-
- Gestion des chaînes de caractères.
-
-** StringUtil
-
- Manipulation de chaînes de caractères. Découpage, suppression
- d'accents, vérification de parenthésage, conversions vers un nombre,
- un tableau, une couleur, une date...
-
-** URIConverter
-
- Conversion d'une chaîne en URI.
-
-** URLConverter
-
- Conversion d'une chaîne en URL.
-
-** GZUtil
-
- Compression et décompression de chaînes de caractères.
-
-
-* Analyse
-
- Analyse du code et monitoring.
-
-** CallAnalyse
-
- Analyse sur des appels de méthodes. Temps d'éxecution, mémoire
- utilisée et nombre d'appels.
-
-* Log
- Mise en place de logs dans une application.
-
-** LoggingPatternFormatter
- Formattage des logs.
-
-
-* Énumérations
-
- Gestion des énumérations et énumérations utiles.
-
-** EnumConverter
-
- Conversion d'une chaîne en Enum.
-
-** EnumEditor
-
- Editeur d'Enum en Swing.
-
-** H2TypeEnum
-
- Énumération pour représenter les différents types d'implantation dans H2.
-
-** MonthEnum
-
- Énumération pour représenter les mois d'une année.
-
-** SimplePaginationEnum
-
- Énumération pour définir les tailles de liste.
-
-* Introspection
-
- Introspection et manipulations sur des objets et des classes.
-
-** ObjectUtil
-
- Outils pour manipuler des objets. Création d'un objet à partir d'une chaîne
- le décrivant, conversion d'un objet en Object, récupération de méthodes
- à partir de leur nom, de constructeurs à partir de leurs paramètres...
-
-** ReflectUtil
-
- Introspection sur une classe. Détermine si un attribut est constant,
- recherche de constantes d'un type donné, conversion d'une classe en
- Enum...
-
-** FormatConverter
-
- Conversion d'une représentation d'un objet à une autre représentation.
- (Java, SQL, XML...).
-
-
-* Divers
-
- Autres librairies utiles n'appartenant à aucune des catégories précédentes.
-
-** CardinalityHelper
-
- Méthodes pour tester des cardinalités.
-
-** ListenerSet
-
- Mise en place de listeners.
-
-** CategorisedListenerSet
-
- Gestion des catégories de listeners.
-
-** ConverterUtil
-
- Méthodes sur des converters.
-
-** DigestGenerator
-
- Fonctionnalités de Digest XML.
-
-** MD5
-
- Implémentation des MD5 hash.
-
-** MD5InputStream
-
- MD5 dans un flux.
Copied: trunk/src/site/apt/nuitonUtil.apt (from rev 1707, trunk/src/site/apt/LutinUtil.apt)
===================================================================
--- trunk/src/site/apt/nuitonUtil.apt (rev 0)
+++ trunk/src/site/apt/nuitonUtil.apt 2009-12-17 09:31:15 UTC (rev 1708)
@@ -0,0 +1,312 @@
+----
+Documentation - LutinUtil
+----
+----
+2009-08-23
+----
+
+ LutinUtil contient un ensemble de librairies trop petites pour avoir
+ leur propre projet. Elles sont aussi utile à la plupart des projets de
+ Code Lutin.
+
+
+Resource
+
+ Cette librairie permet de rechercher une ressource dans le maximum
+ d'endroit possible et si elle est trouvée l'url de la ressource est
+ retournée.
+
+------------------------------------------------------------------------------
+ import org.nuiton.util.Resource;
+ import java.net.URL;
+ ...
+ URL image = Resource.getURL("/images/bidulle.png");
+ ...
+------------------------------------------------------------------------------
+
+ Dans cet exemple l'image est recherchée sur le système de fichier
+ local, si elle n'est pas trouvée, elle est recherché dans le
+ classpath, et si elle n'est toujours pas trouvée une exception est
+ alors levée.
+
+ArgumentsParser
+
+ Cette librairie permet de traiter les arguments de la ligne de commande de
+ façon simple mais évoluable. Son principe de fonctionnement est que l'on
+ déclare les arguements que l'on attend sur la ligne de commande avec le nombre
+ de paramètre qu'ils prennent et une petite description de l'option. Ensuite
+ on dispose de toutes les fonctions utiles pour le traitement de la ligne de
+ commande.
+
+ Voici un exemple d'utilisation
+
+------------------------------------------------------------------------------
+ import org.nuiton.util.ArgumentsParser;
+ ...
+ ArgumentsParser parser = new ArgumentsParser("ToPIA");
+
+ parser.addOption("version", "affiche le numéro de version", new String[]{"--version", "-v"}, 0).setRepetitionMax(1);
+
+ parser.addOption("help", "affiche l'aide de topia", new String[]{"--help", "-h"}, 0).setRepetitionMax(1);
+
+ parser.addOption("start", "Lancement d'une application", new
+ String[]{"--start", "-s"}, 1).setRepetitionMax(1);
+
+ System.out.println(parser.checkCoherence());
+ parser.parse(args);
+
+ if(parser.hasParsedOption("help")){
+ System.out.println(parser.usage());
+ }else if (parser.hasParsedOption("start")){
+ System.out.println ("--> Executing application: ");
+ String arg = parser.getParsedOption("start")
+ new Application(arg);
+ }else if (parser.hasParsedOption("version")){
+ System.out.println( "- Topia version 0.01 - " +
+ "Get new release at http://www.codelutin.com/ -" );
+ }
+------------------------------------------------------------------------------
+
+ Cette librairie permet d'afficher l'aide de la ligne de commande::
+
+------------------------------------------------------------------------------
+ System.out.println(parser.usage());
+------------------------------------------------------------------------------
+
+ Elle permet aussi de vérifier le nombre de fois qu'une option de la ligne de
+ commande est présente et que ce nombre est bien compris dans l'ensemble des
+ valeurs acceptées, grâce au méthode *setRepetitionMax*, et *setRepetitionMin*.
+
+ Si l'implantation par défaut du parseur d'option ne convient pas pour une de vos
+ option, par exemple si le nombre de paramètre de l'option varie suivant la valeur
+ du premier paramètre vous pouvez alors écrire votre propre Parser pour cette
+ Option et l'utilisée avec les autres.
+
+Log
+
+ Cette objet permet de suivre ce que fait une application simplement. Le
+ développeur indique grâce à cette classe l'état dans lequel l'application est.
+
+ Ensuite, il peut mettre des listeners sur cette classe qui afficheront
+ les messages qui ont été envoyés. Ou afficheront l'état d'une tâche en train
+ de s'exécuter.
+
+
+Liste des librairies
+
+ Cette liste répertorie l'ensemble des librairies de LutinUtil.
+
+
+* Configuration
+
+ Gestion de la configuration d'une l'application, de l'internationalisation,
+ des numéros de versions, des ressources...
+
+** ApplicationConfig
+
+ Gestion des fichiers de configuration, des variables d'environnement
+ et des arguments de la ligne de commande.
+
+** Resource
+
+ Recherche d'un fichier dans le système de fichiers et dans le classpath
+ (.jar, .zip).
+
+** ClassLoaderUtil
+
+ Récupération des urls d'un URLClassLoader.
+
+** LocaleConverter
+
+ Conversion d'une chaîne en Locale.
+
+** SortedProperties
+
+ Fichier de propriétés trié par ordre alphabétique.
+
+** RecursiveProperties
+
+ Fichier de propriétés contenant des références à des propriétés de ce
+ même fichier.
+
+** Version
+
+ Représentation d'un numéro de version pour une application.
+
+** VersionConverter
+
+ Conversion d'une chaine en VersionNumber.
+
+** VersionUtil
+
+ Manipulation de numéros de version sous forme de chaînes
+ (comparaison, incrémentation...).
+
+
+* Fichiers
+
+ Gestion de fichiers.
+
+** FileUtil
+
+ Opérations sur des fichiers. Copie, suppression, renommage,
+ recherche, fichiers d'un répertoire, sous-répertoires d'un répertoire,
+ récupération du basename ou de l'extension, création d'un fichier
+ temporaire, comparaison de dates de création, récupération d'une chaîne,
+ d'un Reader ou d'un Writer à partir d'un fichier, récupération du fichier
+ saisi dans une boîte de dialogue, conversions en byte[], en Stream...
+
+** IOUtils
+
+ Copie d'un fichier, chemin temporaire...
+
+** ZipUtil
+
+ Opérations sur des fichiers Zip. Compression et décompression avec ou
+ sans filtres, scan des fichiers créés ou écrasés lors de la décompression...
+
+** ZipStreamEncoder
+
+ Encodage de fichiers Zip dans des threads.
+
+* Collections
+
+ Gestion de collections et de tableaux.
+
+** CollectionUtil
+
+ Manipulation des collections. Ajout de plusieurs éléments à une
+ collection, conversion d'une collection non typée en collection typée.
+
+** ArrayUtil
+
+ Opérations sur des tableaux. Concaténation, somme, recherche,
+ conversion d'une liste en tableau, d'un String[] en int[].
+
+** BoundedList
+
+ ArrayList avec un nombre d'élément minimum et maximum.
+
+** HashList
+ Liste d'objets uniques.
+
+** TransformedList
+ Liste d'objets transformables (interface Transformer).
+
+
+* Chaînes de caractères
+
+ Gestion des chaînes de caractères.
+
+** StringUtil
+
+ Manipulation de chaînes de caractères. Découpage, suppression
+ d'accents, vérification de parenthésage, conversions vers un nombre,
+ un tableau, une couleur, une date...
+
+** URIConverter
+
+ Conversion d'une chaîne en URI.
+
+** URLConverter
+
+ Conversion d'une chaîne en URL.
+
+** GZUtil
+
+ Compression et décompression de chaînes de caractères.
+
+
+* Analyse
+
+ Analyse du code et monitoring.
+
+** CallAnalyse
+
+ Analyse sur des appels de méthodes. Temps d'éxecution, mémoire
+ utilisée et nombre d'appels.
+
+* Log
+ Mise en place de logs dans une application.
+
+** LoggingPatternFormatter
+ Formattage des logs.
+
+
+* Énumérations
+
+ Gestion des énumérations et énumérations utiles.
+
+** EnumConverter
+
+ Conversion d'une chaîne en Enum.
+
+** EnumEditor
+
+ Editeur d'Enum en Swing.
+
+** H2TypeEnum
+
+ Énumération pour représenter les différents types d'implantation dans H2.
+
+** MonthEnum
+
+ Énumération pour représenter les mois d'une année.
+
+** SimplePaginationEnum
+
+ Énumération pour définir les tailles de liste.
+
+* Introspection
+
+ Introspection et manipulations sur des objets et des classes.
+
+** ObjectUtil
+
+ Outils pour manipuler des objets. Création d'un objet à partir d'une chaîne
+ le décrivant, conversion d'un objet en Object, récupération de méthodes
+ à partir de leur nom, de constructeurs à partir de leurs paramètres...
+
+** ReflectUtil
+
+ Introspection sur une classe. Détermine si un attribut est constant,
+ recherche de constantes d'un type donné, conversion d'une classe en
+ Enum...
+
+** FormatConverter
+
+ Conversion d'une représentation d'un objet à une autre représentation.
+ (Java, SQL, XML...).
+
+
+* Divers
+
+ Autres librairies utiles n'appartenant à aucune des catégories précédentes.
+
+** CardinalityHelper
+
+ Méthodes pour tester des cardinalités.
+
+** ListenerSet
+
+ Mise en place de listeners.
+
+** CategorisedListenerSet
+
+ Gestion des catégories de listeners.
+
+** ConverterUtil
+
+ Méthodes sur des converters.
+
+** DigestGenerator
+
+ Fonctionnalités de Digest XML.
+
+** MD5
+
+ Implémentation des MD5 hash.
+
+** MD5InputStream
+
+ MD5 dans un flux.
Modified: trunk/src/site/site.xml
===================================================================
--- trunk/src/site/site.xml 2009-12-16 14:50:21 UTC (rev 1707)
+++ trunk/src/site/site.xml 2009-12-17 09:31:15 UTC (rev 1708)
@@ -8,9 +8,6 @@
<poweredBy>
<logo href="http://maven.apache.org" name="Maven" img="images/logos/maven-feather.png"/>
- <!--logo href="http://jrst.labs.libre-entreprise.org" name="JRst" img="images/jrst-logo.png"/>
- <logo href="http://docutils.sourceforge.net/rst.html" name="ReStructuredText"
- img="images/restructuredtext-logo.png"/-->
</poweredBy>
<body>
@@ -21,7 +18,8 @@
<menu name="Utilisateur">
<item name="Accueil" href="index.html"/>
- <item name="Documentation" href="/LutinUtil.html"/>
+ <item name="Documentation" href="/nuitonUtil.html"/>
+ <item name="Command Line" href="/CommandLineArgumentApplication.html"/>
</menu>
<menu name="Téléchargement">
1
0
r1707 - in trunk/src: main/java/org/nuiton/util test/java/org/nuiton/util
by fdesbois@users.nuiton.org 16 Dec '09
by fdesbois@users.nuiton.org 16 Dec '09
16 Dec '09
Author: fdesbois
Date: 2009-12-16 15:50:21 +0100 (Wed, 16 Dec 2009)
New Revision: 1707
Modified:
trunk/src/main/java/org/nuiton/util/DateUtils.java
trunk/src/main/java/org/nuiton/util/PeriodDates.java
trunk/src/test/java/org/nuiton/util/DateUtilsTest.java
Log:
Add method to getMonthLibelle from a month number
Modified: trunk/src/main/java/org/nuiton/util/DateUtils.java
===================================================================
--- trunk/src/main/java/org/nuiton/util/DateUtils.java 2009-12-16 13:37:54 UTC (rev 1706)
+++ trunk/src/main/java/org/nuiton/util/DateUtils.java 2009-12-16 14:50:21 UTC (rev 1707)
@@ -19,15 +19,15 @@
* <http://www.gnu.org/licenses/gpl-3.0.html>. ##%*
*/
+import java.text.DateFormatSymbols;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
+import java.util.Locale;
/**
- * DateUtils.java
- *
* Library for manipulating dates.
*
* @author fdesbois
@@ -54,6 +54,11 @@
SimpleDateFormat simpleDateFormat = new SimpleDateFormat(pattern);
return simpleDateFormat.format(date);
}
+
+ public static String formatDate(Date date, String pattern, Locale locale) {
+ SimpleDateFormat simpleDateFormat = new SimpleDateFormat(pattern, locale);
+ return simpleDateFormat.format(date);
+ }
/**
* Parse a date using the pattern in argument. The pattern is the same using
@@ -180,4 +185,24 @@
// 86400000 = 24 * 60 * 60 * 1000
return (int) Math.ceil(((end - begin) / 86400000));
}
+
+ /**
+ * Get libelle of the month corresponding to the number given in argument.
+ * @param monthNumber between 1-12
+ * @param locale Locale for language support
+ * @return a String corresponding to the libelle of the month
+ */
+ public static String getMonthLibelle(int monthNumber, Locale locale) {
+ return new DateFormatSymbols(locale).getMonths()[monthNumber-1];
+ }
+
+ /**
+ * Get libelle of the month corresponding to the number given in argument.
+ * @param monthNumber between 1-12
+ * @return a String corresponding to the libelle of the month
+ */
+ public static String getMonthLibelle(int monthNumber) {
+ return getMonthLibelle(monthNumber, Locale.getDefault());
+ }
+
}
Modified: trunk/src/main/java/org/nuiton/util/PeriodDates.java
===================================================================
--- trunk/src/main/java/org/nuiton/util/PeriodDates.java 2009-12-16 13:37:54 UTC (rev 1706)
+++ trunk/src/main/java/org/nuiton/util/PeriodDates.java 2009-12-16 14:50:21 UTC (rev 1707)
@@ -64,7 +64,7 @@
this.thruCalendar = new GregorianCalendar();
setThruDate(thruDate);
- this.pattern = DateUtils.DEFAULT_PATTERN;
+ this.pattern = DateUtils.DEFAULT_PATTERN;
}
public PeriodDates(Calendar fromCalendar, Calendar thruCalendar) {
@@ -74,7 +74,7 @@
this.thruDate = thruCalendar.getTime();
this.thruCalendar = thruCalendar;
- this.pattern = DateUtils.DEFAULT_PATTERN;
+ this.pattern = DateUtils.DEFAULT_PATTERN;
}
public static PeriodDates createMonthsPeriodFromToday(int monthAfter) {
Modified: trunk/src/test/java/org/nuiton/util/DateUtilsTest.java
===================================================================
--- trunk/src/test/java/org/nuiton/util/DateUtilsTest.java 2009-12-16 13:37:54 UTC (rev 1706)
+++ trunk/src/test/java/org/nuiton/util/DateUtilsTest.java 2009-12-16 14:50:21 UTC (rev 1707)
@@ -2,6 +2,7 @@
package org.nuiton.util;
import java.util.Date;
+import java.util.Locale;
import junit.framework.Assert;
import org.junit.After;
import org.junit.AfterClass;
@@ -123,4 +124,16 @@
Assert.assertEquals(11, result);
}
+ @Test
+ public void testGetMonthLibelle() {
+ System.out.println("getMonthLibelle");
+
+ Locale.setDefault(Locale.FRENCH);
+ String janvier = DateUtils.getMonthLibelle(1);
+ Assert.assertEquals("janvier", janvier);
+
+ String juli = DateUtils.getMonthLibelle(7, Locale.GERMAN);
+ Assert.assertEquals("Juli", juli);
+ }
+
}
\ No newline at end of file
1
0