Author: jpepin Date: 2010-08-03 19:23:31 +0200 (Tue, 03 Aug 2010) New Revision: 2994 Url: http://chorem.org/repositories/revision/lima/2994 Log: Serveur http embarqu?\195?\169 + ajout de propri?\195?\169t?\195?\169s dans lima config. Added: trunk/lima-swing/:limadb.lock.db trunk/lima-swing/limadb.h2.db trunk/lima-swing/limadb.lock.db trunk/lima-swing/src/main/java/org/chorem/lima/ui/document/ trunk/lima-swing/src/main/java/org/chorem/lima/ui/document/DocumentHtmlPane.java trunk/lima-swing/src/main/java/org/chorem/lima/ui/document/DocumentHtmlView.jaxx trunk/lima-swing/src/main/java/org/chorem/lima/ui/document/DocumentPdf.java Removed: trunk/lima-swing/src/main/java/org/chorem/lima/ui/importexport/ImportExportFileChooser.java Modified: trunk/lima-business/pom.xml trunk/lima-business/src/main/java/org/chorem/lima/business/LimaConfig.java trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/DocumentServiceImpl.java trunk/lima-business/src/main/resources/i18n/lima-business-en_GB.properties trunk/lima-business/src/main/resources/i18n/lima-business-fr_FR.properties trunk/lima-business/src/main/resources/lima.properties trunk/pom.xml Modified: trunk/lima-business/pom.xml =================================================================== --- trunk/lima-business/pom.xml 2010-08-03 10:41:31 UTC (rev 2993) +++ trunk/lima-business/pom.xml 2010-08-03 17:23:31 UTC (rev 2994) @@ -32,7 +32,13 @@ <groupId>com.lowagie</groupId> <artifactId>itext</artifactId> </dependency> + <dependency> + <groupId>org.mortbay.jetty</groupId> + <artifactId>jetty</artifactId> + </dependency> + + <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> </dependency> Modified: trunk/lima-business/src/main/java/org/chorem/lima/business/LimaConfig.java =================================================================== --- trunk/lima-business/src/main/java/org/chorem/lima/business/LimaConfig.java 2010-08-03 10:41:31 UTC (rev 2993) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/LimaConfig.java 2010-08-03 17:23:31 UTC (rev 2994) @@ -91,7 +91,19 @@ } + /** + * + * @param configFileName + */ + public String getReportsDir(){ + return getOption(Option.REPORTS_DIR.getKey()); + } + public int getHttpPort(){ + return Integer.valueOf(getOption(Option.HTTP_PORT.getKey())); + } + + protected void loadConfiguration(String configFileName){ instance.setConfigFileName(configFileName); @@ -115,7 +127,9 @@ public static enum Option implements OptionDef { CONFIG_FILE(CONFIG_FILE_NAME, _("lima.config.configFileName.description"), "lima-config.properties", String.class, true, true), - RULES_NATIONALTY("lima.rules",_("lima.config.rulesnationality"),"default", String.class, false, false); + RULES_NATIONALTY("lima.rules", _("lima.config.rulesnationality"), "default", String.class, false, false), + REPORTS_DIR("lima.report.dir", _("lima.config.reports-dir"), "", String.class, false, false), + HTTP_PORT("lima.httpport", _("lima.config.http-port"), "5462", String.class, false, false); public final String key; public final String description; Modified: trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/DocumentServiceImpl.java =================================================================== --- trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/DocumentServiceImpl.java 2010-08-03 10:41:31 UTC (rev 2993) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/DocumentServiceImpl.java 2010-08-03 17:23:31 UTC (rev 2994) @@ -21,6 +21,7 @@ import static org.nuiton.i18n.I18n._; import java.awt.Color; +import java.io.File; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.text.SimpleDateFormat; @@ -57,13 +58,14 @@ import org.chorem.lima.entity.FinancialTransaction; import org.chorem.lima.entity.Identity; import org.chorem.lima.entity.LimaCallaoDAOHelper; +import org.mortbay.jetty.Server; +import org.mortbay.jetty.handler.ResourceHandler; import org.nuiton.topia.TopiaContext; import org.nuiton.topia.TopiaContextFactory; import org.nuiton.topia.TopiaException; import org.nuiton.topia.TopiaNotFoundException; import org.nuiton.topia.framework.TopiaQuery; import org.nuiton.topia.framework.TopiaQuery.Op; - import com.lowagie.text.BadElementException; import com.lowagie.text.Cell; import com.lowagie.text.Chapter; @@ -87,7 +89,9 @@ private TopiaContext rootContext; - //Service + protected Server server; + + //Services @EJB IdentityService identityService; @@ -100,6 +104,8 @@ @EJB ReportService reportService; + protected String path; + //SDFs private static SimpleDateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy"); @@ -133,10 +139,31 @@ log.error("Can't init topia context", ex); } } + path = LimaConfig.getInstance().getReportsDir(); + start(); } - + /** start the server */ + public void start() { + if (server == null) { + int port = LimaConfig.getInstance().getHttpPort(); + new File(path).mkdir(); + try { + server = new Server(port); + ResourceHandler resourceHandler = new ResourceHandler(); + resourceHandler.setResourceBase(path); + server.setHandler(resourceHandler); + server.start(); + log.info("Web server are running on port: "+port); + + } catch (Exception eee) { + log.error("error while booting http server", eee); + } + } + } + + public Paragraph createHeaderPage(String title, Identity identity, String beginDate, String endDate){ Paragraph paragraphHeaderPage = new Paragraph(); Table t = null; @@ -230,12 +257,11 @@ Date newDate = new Date(); String dateS = dateFormat.format(newDate); String hourS = hourFormat.format(newDate); - String fileDateS = filedateFormat.format(newDate); PdfWriter pdfWriter = PdfWriter.getInstance(document, - new FileOutputStream("/lima_bcr"+fileDateS+".pdf")); + new FileOutputStream(path+File.separator+"lima_financialstatements.pdf")); HtmlWriter htmlWriter = HtmlWriter.getInstance(document, - new FileOutputStream("/lima_bcr"+fileDateS+".html")); + new FileOutputStream(path+File.separator+"lima_financialstatements.html")); document.open(); int nbpages = 1; @@ -460,16 +486,15 @@ Date newDate = new Date(); String dateS = dateFormat.format(newDate); String hourS = hourFormat.format(newDate); - String fileDateS = filedateFormat.format(newDate); Double currentAmountDebit = 0.0; Double currentAmountCredit = 0.0; String accountcarry =""; PdfWriter pdfWriter = PdfWriter.getInstance(document, - new FileOutputStream("/ledger_lima"+fileDateS+".pdf")); + new FileOutputStream(path+File.separator+"lima_ledger.pdf")); HtmlWriter htmlWriter = HtmlWriter.getInstance(document, - new FileOutputStream("/ledger_lima"+fileDateS+".html")); + new FileOutputStream(path+File.separator+"lima_ledger.html")); document.open(); int nbpages = 1; Identity identity = identityService.getIdentity(); @@ -705,10 +730,11 @@ String hourS = hourFormat.format(newDate); String fileDateS = filedateFormat.format(newDate); + log.debug(path); PdfWriter pdfWriter = PdfWriter.getInstance(document, - new FileOutputStream("/lima_ebs"+fileDateS+".pdf")); + new FileOutputStream(path+File.separator+"lima_entrybooks.pdf")); HtmlWriter htmlWriter = HtmlWriter.getInstance(document, - new FileOutputStream("/lima_ebs"+fileDateS+".html")); + new FileOutputStream(path+File.separator+"lima_entrybooks.html")); document.open(); int nbpages = 1; @@ -928,9 +954,9 @@ Double currentSoldeCredit = 0.0; PdfWriter pdfWriter = PdfWriter.getInstance(document, - new FileOutputStream("/balance_lima"+fileDateS+".pdf")); + new FileOutputStream(path+File.separator+"lima_balance.pdf")); HtmlWriter htmlWriter = HtmlWriter.getInstance(document, - new FileOutputStream("/balance_lima"+fileDateS+".html")); + new FileOutputStream(path+File.separator+"lima_balance.html")); document.open(); int nbpages = 1; Identity identity = identityService.getIdentity(); @@ -1117,12 +1143,10 @@ Date newDate = new Date(); String dateS = dateFormat.format(newDate); String hourS = hourFormat.format(newDate); - String fileDateS = filedateFormat.format(newDate); - PdfWriter pdfWriter = PdfWriter.getInstance(document, - new FileOutputStream("/lima_Gebs"+fileDateS+".pdf")); + new FileOutputStream(path+File.separator+"lima_general_entybook.pdf")); HtmlWriter htmlWriter = HtmlWriter.getInstance(document, - new FileOutputStream("/lima_Gebs"+fileDateS+".html")); + new FileOutputStream(path+File.separator+"lima_general_entybook.html")); document.open(); int nbpages = 1; Modified: trunk/lima-business/src/main/resources/i18n/lima-business-en_GB.properties =================================================================== --- trunk/lima-business/src/main/resources/i18n/lima-business-en_GB.properties 2010-08-03 10:41:31 UTC (rev 2993) +++ trunk/lima-business/src/main/resources/i18n/lima-business-en_GB.properties 2010-08-03 17:23:31 UTC (rev 2994) @@ -38,6 +38,8 @@ lima-business.document.voucher=Voucher lima.business.document.date=Date lima.config.configFileName.description= +lima.config.http-port= +lima.config.reports-dir= lima.config.rulesnationality= lima.table.grossamount= lima.table.label=Test Modified: trunk/lima-business/src/main/resources/i18n/lima-business-fr_FR.properties =================================================================== --- trunk/lima-business/src/main/resources/i18n/lima-business-fr_FR.properties 2010-08-03 10:41:31 UTC (rev 2993) +++ trunk/lima-business/src/main/resources/i18n/lima-business-fr_FR.properties 2010-08-03 17:23:31 UTC (rev 2994) @@ -32,4 +32,6 @@ lima-business.document.vatnumber=N\u00B0 TVA lima-business.document.voucher=Pi\u00E8ce comptable lima.config.configFileName.description= +lima.config.http-port= +lima.config.reports-dir= lima.config.rulesnationality= Modified: trunk/lima-business/src/main/resources/lima.properties =================================================================== --- trunk/lima-business/src/main/resources/lima.properties 2010-08-03 10:41:31 UTC (rev 2993) +++ trunk/lima-business/src/main/resources/lima.properties 2010-08-03 17:23:31 UTC (rev 2994) @@ -1,3 +1,14 @@ +#LIMA Defaults values +# main directory +lima.dir=${user.home}/.lima/ +# http port for reports +lima.httpport=5462 +# Local class for accounting rules +lima.rules=org.chorem.lima.business.accountingrules.FranceAccountingRules +# directory for http server +lima.report.dir=${lima.dir}/reports + + # Proprietes par defaut pour une base de donnees de type H2 hibernate.hbm2ddl.auto=update #hibernate.show_sql=true @@ -2,2 +13,3 @@ + hibernate.dialect=org.hibernate.dialect.H2Dialect @@ -7,5 +19,4 @@ hibernate.connection.password= hibernate.connection.driver_class=org.h2.Driver hibernate.connection.url=jdbc:h2:file:~/.lima/limadb - -lima.rules=org.chorem.lima.business.accountingrules.FranceAccountingRules +#FIXME hibernate.connection.url=jdbc:h2:file:${lima.dir}/limadb \ No newline at end of file Added: trunk/lima-swing/:limadb.lock.db =================================================================== --- trunk/lima-swing/:limadb.lock.db (rev 0) +++ trunk/lima-swing/:limadb.lock.db 2010-08-03 17:23:31 UTC (rev 2994) @@ -0,0 +1,4 @@ +#FileLock +#Tue Aug 03 19:12:33 CEST 2010 +id=12a38f0b67cbf55cf1fb51d173d8db55399628ae048 +method=file Added: trunk/lima-swing/limadb.h2.db =================================================================== (Binary files differ) Property changes on: trunk/lima-swing/limadb.h2.db ___________________________________________________________________ Added: svn:mime-type + application/octet-stream Added: trunk/lima-swing/limadb.lock.db =================================================================== --- trunk/lima-swing/limadb.lock.db (rev 0) +++ trunk/lima-swing/limadb.lock.db 2010-08-03 17:23:31 UTC (rev 2994) @@ -0,0 +1,4 @@ +#FileLock +#Tue Aug 03 19:13:22 CEST 2010 +id=12a38f1750004a9a1ddce8ec18615a18acf9c511c71 +method=file Added: trunk/lima-swing/src/main/java/org/chorem/lima/ui/document/DocumentHtmlPane.java =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/document/DocumentHtmlPane.java (rev 0) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/document/DocumentHtmlPane.java 2010-08-03 17:23:31 UTC (rev 2994) @@ -0,0 +1,122 @@ +/* *##% Lima Swing + * Copyright (C) 2008 - 2010 CodeLutin + * + * 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.chorem.lima.ui.document; + +import static org.nuiton.i18n.I18n._; +import java.awt.Color; +import java.util.List; +import javax.swing.JEditorPane; +import javax.swing.event.HyperlinkEvent; +import javax.swing.event.HyperlinkListener; +import javax.swing.plaf.basic.BasicEditorPaneUI; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.chorem.lima.LimaContext; +import org.chorem.lima.business.AccountServiceMonitorable; +import org.chorem.lima.business.ImportServiceMonitorable; +import org.chorem.lima.business.LimaException; +import org.chorem.lima.business.ServiceListener; +import org.chorem.lima.entity.Account; +import org.chorem.lima.service.LimaServiceFactory; +import org.chorem.lima.ui.MainView; + +public class DocumentHtmlPane extends JEditorPane implements HyperlinkListener, ServiceListener { + + private static final long serialVersionUID = 1L; + + private static final Log log = LogFactory.getLog(DocumentHtmlPane.class); + + protected DocumentHtmlView view; + + protected AccountServiceMonitorable accountService; + + private static Color redBackground = new Color(0xff, 0xee, 0xee); + private static Color greenBackground = new Color(0xee, 0xff, 0xee); + + + + public DocumentHtmlPane(DocumentHtmlView view) { + this.view=view; + accountService = + LimaServiceFactory.getInstance().getService( + AccountServiceMonitorable.class); + accountService.addListener(this); + LimaServiceFactory.getInstance().getService( + ImportServiceMonitorable.class).addListener(this); + + //init + setOpaque(true); + setContentType("text/html"); + setEditable(false); + setUI(new BasicEditorPaneUI()); + addHyperlinkListener(this); + refresh(); + } + + @Override + public void hyperlinkUpdate(HyperlinkEvent e) { + if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) { + + if (e.getDescription().equals("#accountschart")) { + MainView ui = LimaContext.MAIN_UI_ENTRY_DEF.getContextValue(view); + ui.getHandler().showAccountView(ui); + } + } + } + + public void refresh(){ + + String htmlBegin = "<font face='sans-serif' size=3>" + + "<p style=vertical-align:'bottom', horizontal-align:'center'>"; + String htmlEnd = "</p></font>"; + + try { + + List<Account> accounts = accountService.getAllAccounts(); + if (accounts.size()>0){ + setBackground(greenBackground); + String accountsString = _("limahome.chartaccounts.state1_2") + " " + + accounts.size() + " " + _("limahome.chartaccounts.state2_2") + + "<br/><br/><a href='#accountschart'>" + + _("limahome.chartaccounts.modify") + "</a>"; + //set Text + setText(htmlBegin + accountsString + htmlEnd); + } + else { + setBackground(redBackground); + String accountsString = _("limahome.chartaccounts.nothing") + + "<br/><br/><a href='#accountschart'>" + + _("limahome.chartaccounts.create") + "</a>"; + //set Text + setText(htmlBegin + accountsString + htmlEnd); + } + } catch (LimaException eee) { + log.debug("Can't get datas account editor pane home", eee); + } + } + + @Override + public void notifyMethod(String serviceName, String methodeName) { + if (methodeName.contains("Account") || methodeName.contains("importAll")){ + refresh(); + } + } + +} Added: trunk/lima-swing/src/main/java/org/chorem/lima/ui/document/DocumentHtmlView.jaxx =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/document/DocumentHtmlView.jaxx (rev 0) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/document/DocumentHtmlView.jaxx 2010-08-03 17:23:31 UTC (rev 2994) @@ -0,0 +1,42 @@ +<!-- ##% Lima Swing + Copyright (C) 2008 - 2010 CodeLutin + 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. + ##% --> + +<JDialog modal="true"> + + <script> + <![CDATA[ + import javax.swing.BorderFactory; + getRootPane().setDefaultButton(ok); + protected void performOk() { + dispose(); + } + ]]> + </script> + + <Table> + <row> + <cell> + <JEditorPane javaBean='new org.chorem.lima.ui.document.DocumentHtmlPane(this)'/> + </cell> + </row> + <row> + <cell anchor='east' fill="none"> + <JButton id='ok' text="lima.common.ok" onActionPerformed="performOk()"/> + </cell> + </row> + </Table> +</JDialog> \ No newline at end of file Added: trunk/lima-swing/src/main/java/org/chorem/lima/ui/document/DocumentPdf.java =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/document/DocumentPdf.java (rev 0) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/document/DocumentPdf.java 2010-08-03 17:23:31 UTC (rev 2994) @@ -0,0 +1,5 @@ +package org.chorem.lima.ui.document; + +public class DocumentPdf { + +} Deleted: trunk/lima-swing/src/main/java/org/chorem/lima/ui/importexport/ImportExportFileChooser.java =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/importexport/ImportExportFileChooser.java 2010-08-03 10:41:31 UTC (rev 2993) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/importexport/ImportExportFileChooser.java 2010-08-03 17:23:31 UTC (rev 2994) @@ -1,34 +0,0 @@ -package org.chorem.lima.ui.importexport; - -import java.awt.BorderLayout; -import java.awt.Component; - -import javax.swing.JPanel; - -public class ImportExportFileChooser extends JPanel { - - private static final long serialVersionUID = 1L; - - public ImportExportFileChooser() { - - setLayout(new BorderLayout()); - // il y a 4 composants dans le JFileChooser, on les retire un par un pour les replacer comme on le souhaite - Component navigationBar = getComponent(0); - remove(0); - // on retire un JPanel qui n'est pas utile - remove(0); - add(navigationBar, BorderLayout.NORTH); - Component panelFiles = getComponent(0); - remove(0); - add(panelFiles, BorderLayout.CENTER); - Component buttons = getComponent(0); - remove(0); - add(buttons, BorderLayout.SOUTH); - - //this.add(panelFileChooser); - //this.add(panelOptions, BorderLayout.SOUTH); - - } - - -} Modified: trunk/pom.xml =================================================================== --- trunk/pom.xml 2010-08-03 10:41:31 UTC (rev 2993) +++ trunk/pom.xml 2010-08-03 17:23:31 UTC (rev 2994) @@ -173,6 +173,13 @@ <version>2.1.7</version> </dependency> + <dependency> + <groupId>org.mortbay.jetty</groupId> + <artifactId>jetty</artifactId> + <version>6.1.25</version> + </dependency> + + <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId>