/***************************************************************************
* Copyright (c) 2004 - 2008 Fabrizio Boco fabboco@users.sourceforge.net *
* *
* *
* This is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Library General Public *
* License (version 2.1) as published by the Free Software Foundation *
* *
* This library 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 Library General Public License for more details. *
* *
* You should have received a copy of the GNU Library General Public *
* License along with this library; see the file COPYING.LIB. If not, *
* write to the Free Software Foundation, Inc., 59 Temple Place, *
* Suite 330, Boston, MA 02111-1307, USA *
* *
***************************************************************************/
/**
- $Header: /usr/local/cvslocalrepository/SeamWebAppGenerator/src/org/boco/seamwebappgen/seamGeneration/Attic/MessagesGenerator.java,v 1.1.2.2 2008/04/22 05:37:56 fab Exp $
- $Author: fab $
- $Revision: 1.1.2.2 $
- $Date: 2008/04/22 05:37:56 $
- $Log: MessagesGenerator.java,v $
- Revision 1.1.2.2 2008/04/22 05:37:56 fab
- Aggiornamento indirizzo di posta
-
- Revision 1.1.2.1 2008/04/19 13:12:39 fab
- Modifiche varie per rafactoring
-
- Revision 1.1.2.1 2008/04/19 11:18:33 fab
- Refactoring
-
- Revision 1.1.8.5 2008/04/19 10:07:03 fab
- Aggiornamento riferimenti licenza
-
-
**/
package org.boco.seamwebappgen.seamGeneration;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Properties;
import java.util.Vector;
import org.apache.commons.io.IOUtils;
import org.boco.seamwebappgen.info.Attribute;
import org.boco.seamwebappgen.info.Bean;
import org.boco.seamwebappgen.info.InfoReader;
import org.boco.seamwebappgen.info.Relationship;
import org.boco.seamwebappgen.info.ShowAttribute;
import org.boco.seamwebappgen.info.ShowList;
import org.boco.seamwebappgen.utils.PropertiesFileManager;
import org.boco.seamwebappgen.utils.Utils;
/**
*
* @author Fabrizio Boco
*
*/
public class MessagesGenerator
{
public static void generateApplicationMessages(String sourceDir, String targetDir) throws FileNotFoundException, IOException
{
String resourcesFile = targetDir + File.separator + "html" + File.separator + "WEB-INF" + File.separator + "classes" + File.separator + "messages.properties";
String key;
Properties prop = PropertiesFileManager.load(resourcesFile);
/** Globali dell'applicazione **/
key = "Application_name";
if (!prop.containsKey(key))
{
prop.put(key, "Application Name");
}
key = "Application_version";
if (!prop.containsKey(key))
{
prop.put(key, "Ver.: 0.0");
}
key = "Application_copyright";
if (!prop.containsKey(key))
{
prop.put(key, "F. Boco");
}
key = "Application_administration";
if (!prop.containsKey(key))
{
prop.put(key, "Administration");
}
key = "Application_index";
if (!prop.containsKey(key))
{
prop.put(key, "Main List");
}
key = "Application_buttonNew";
if (!prop.containsKey(key))
{
prop.put(key, "New");
}
key = "Application_buttonEdit";
if (!prop.containsKey(key))
{
prop.put(key, "Edit");
}
key = "Application_buttonDelete";
if (!prop.containsKey(key))
{
prop.put(key, "Delete");
}
key = "Application_buttonOk";
if (!prop.containsKey(key))
{
prop.put(key, "Ok");
}
key = "Application_buttonCancel";
if (!prop.containsKey(key))
{
prop.put(key, "Cancel");
}
key = "Application_buttonSearch";
if (!prop.containsKey(key))
{
prop.put(key, "Search");
}
key = "Application_buttonSelect";
if (!prop.containsKey(key))
{
prop.put(key, "Select");
}
key = "Application_buttonLocalSearch";
if (!prop.containsKey(key))
{
prop.put(key, "Search");
}
key = "Application_buttonResetLocalSearch";
if (!prop.containsKey(key))
{
prop.put(key, "Cancel");
}
key = "Application_print";
if (!prop.containsKey(key))
{
prop.put(key, "Print");
}
key = "Application_DateFormat";
if (!prop.containsKey(key))
{
prop.put(key, "MM/dd/yyyy");
}
key = "Application_unselectedLabel";
if (!prop.containsKey(key))
{
prop.put(key, "-- Select --");
}
// key = "Application_dataScrollerInfo";
// if (!prop.containsKey(key))
// {
// prop.put(key, "Oggetti totali {0}. Mostrati {1} oggetti, da {2} a {3}. Pagina {4} / {5}");
// }
//
// Non supportato da Trinidad - Deve essere scritto un intero
//
// key = "Application_rowsPerPage";
// if (!prop.containsKey(key))
// {
// prop.put(key, "25");
// }
key = "javax.faces.component.UIInput.REQUIRED";
if (!prop.containsKey(key))
{
prop.put(key, "Required Field");
}
key = "javax.faces.component.UIInput.REQUIRED_detail";
if (!prop.containsKey(key))
{
prop.put(key, "Required Field");
}
/**
* Annotazioni per la gestione della sicurezza
*/
key = "form_Login";
if (!prop.containsKey(key))
{
prop.put(key, "Login");
}
key = "form_Login_username";
if (!prop.containsKey(key))
{
prop.put(key, "User");
}
key = "form_Login_password";
if (!prop.containsKey(key))
{
prop.put(key, "Password");
}
key = "org.jboss.seam.loginFailed";
if (!prop.containsKey(key))
{
prop.put(key, "Invalid User/Password");
}
key = "org.jboss.seam.loginSuccessful";
if (!prop.containsKey(key))
{
prop.put(key, "");
}
key = "form_Error";
if (!prop.containsKey(key))
{
prop.put(key, "Error");
}
key = "form_AuthorizationError";
if (!prop.containsKey(key))
{
prop.put(key, "Authorization Error");
}
key = "form_ChangePassword";
if (!prop.containsKey(key))
{
prop.put(key, "Change Password");
}
key = "form_ChangePassword_password";
if (!prop.containsKey(key))
{
prop.put(key, "Password");
}
key = "form_ChangePassword_password_confirmed";
if (!prop.containsKey(key))
{
prop.put(key, "Confirm Password");
}
key = "form_ChangePassword_no_matching_password";
if (!prop.containsKey(key))
{
prop.put(key, "Passwords do not match");
}
key = "header_ChangePassword";
if (!prop.containsKey(key))
{
prop.put(key, "Change Password");
}
key = "header_Logout";
if (!prop.containsKey(key))
{
prop.put(key, "Logout");
}
PropertiesFileManager.save(prop, resourcesFile + "NEW");
File oldTargetFile = new File(resourcesFile);
if (oldTargetFile.exists() && IOUtils.contentEquals(new FileInputStream(new File(resourcesFile + "NEW")), new FileInputStream(oldTargetFile)))
{
// Il nuovo file generato e' uguale al precedente
// Il nuovo viene cancellato
File f = new File(resourcesFile + "NEW");
f.deleteOnExit();
}
else
{
// Il nuovo file generato e' diverso dal precedente
// Il nuovo file viene copiato su quello esistente e poi cancellato
IOUtils.copy(new FileInputStream(new File(resourcesFile + "NEW")), new FileOutputStream(new File(resourcesFile)));
File f = new File(resourcesFile + "NEW");
f.deleteOnExit();
}
}
public static void generateMessages(String sourceDir, String targetDir, Bean bean) throws Exception
{
String resourcesFile = targetDir + File.separator + "html" + File.separator + "WEB-INF" + File.separator + "classes" + File.separator + "messages.properties";
String key;
Properties prop = PropertiesFileManager.load(resourcesFile);
InfoReader infoReader = new InfoReader(sourceDir);
/** Lista **/
// Titoli della pagine list e nome delle azioni sugli item della lista
for (int i = 0; i < bean.getLists().size(); i++)
{
key = "list_" + bean.getLists().get(i).getName() + "_title";
if (!prop.containsKey(key))
{
prop.put(key, Utils.makeFirstLetterUpperCase(bean.getLists().get(i).getName()));
}
}
key = "list_" + bean.getName() + "_searchTitle";
if (!prop.containsKey(key))
{
prop.put(key, "Search Result " + Utils.makeFirstLetterUpperCase(bean.getName()));
}
key = "list_" + bean.getName() + "_new";
if (!prop.containsKey(key))
{
prop.put(key, "New");
}
key = "list_" + bean.getName() + "_display";
if (!prop.containsKey(key))
{
prop.put(key, "Details " + Utils.makeFirstLetterUpperCase(bean.getName()));
}
key = "list_" + bean.getName() + "_edit";
if (!prop.containsKey(key))
{
prop.put(key, "Edit " + Utils.makeFirstLetterUpperCase(bean.getName()));
}
key = "list_" + bean.getName() + "_create";
if (!prop.containsKey(key))
{
prop.put(key, "New " + Utils.makeFirstLetterUpperCase(bean.getName()));
}
key = "list_" + bean.getName() + "_delete";
if (!prop.containsKey(key))
{
prop.put(key, "Delete " + Utils.makeFirstLetterUpperCase(bean.getName()));
}
key = "list_" + bean.getName() + "_search";
if (!prop.containsKey(key))
{
prop.put(key, "Search");
}
/** Form **/
key = "form_" + bean.getName();
if (!prop.containsKey(key))
{
prop.put(key, bean.getName());
}
// Titoli della pagina di gestione del form
key = "form_" + bean.getName() + "_display";
if (!prop.containsKey(key))
{
//prop.put(key, "Dettagli" + Utils.makeFirstLetterUpperCase(bean.getName()));
prop.put(key, "Details");
}
key = "form_" + bean.getName() + "_edit";
if (!prop.containsKey(key))
{
prop.put(key, "Edit");
}
key = "form_" + bean.getName() + "_create";
if (!prop.containsKey(key))
{
prop.put(key, "New");
}
key = "form_" + bean.getName() + "_delete";
if (!prop.containsKey(key))
{
prop.put(key, "Delete");
}
key = "form_" + bean.getName() + "_search";
if (!prop.containsKey(key))
{
prop.put(key, "Search");
}
// Attributi del bean nel form
for (int i = 0; i < bean.getAttributes().size(); i++)
{
Attribute attr = bean.getAttributes().get(i);
key = "form_" + bean.getName() + "_" + attr.getName();
if (!prop.containsKey(key))
{
prop.put(key, Utils.makeFirstLetterUpperCase(attr.getName()));
}
}
// Relazioni nel form
for (int i = 0; i < bean.getRelationships().size(); i++)
{
Relationship rel = bean.getRelationships().get(i);
key = "form_" + bean.getName() + "_" + rel.getName();
if (!prop.containsKey(key))
{
prop.put(key, rel.getName().substring(3));
}
if (rel.isListBox())
{
;
}
else
{
for (int j = 0; j < rel.getRelatedAttributes().size(); j++)
{
Attribute attr = rel.getRelatedAttributes().get(j);
key = "form_" + bean.getName() + "_" + rel.getName();
for (int k = 0; k < attr.getRelationships().size(); k++)
{
key += "_";
key += attr.getRelationships().get(k).getName();
}
key += "_" + attr.getName();
if (!prop.containsKey(key))
{
prop.put(key, Utils.makeFirstLetterUpperCase(attr.getName()));
}
}
}
}
// Attributi delle relazioni da visualizzare nel form del bean
for (int i = 0; i < bean.getShowInFormAttributes().size(); i++)
{
ShowAttribute attribute = bean.getShowInFormAttributes().get(i);
key = "form_" + bean.getName() + "_" + attribute.getQualifiedName().replace(".", "_");
if (!prop.containsKey(key))
{
prop.put(key, key);
}
}
// Attributi del bean nella lista
for (int i = 0; i < bean.getShowAttributes().size(); i++)
{
ShowAttribute attr = bean.getShowAttributes().get(i);
if (!attr.belongsToRelationship())
{
key = "list_" + bean.getName() + "_" + attr.getName();
if (!prop.containsKey(key))
{
prop.put(key, Utils.makeFirstLetterUpperCase(attr.getName()));
}
}
else
{
// key = "list_" + bean.getName() + "_" + attr.getRelationship().getName() + "_" + attr.getName();
key = "list_" + bean.getName();
for (int k = 0; k < attr.getRelationships().size(); k++)
key += "_" + attr.getRelationships().get(k).getName();
key += "_" + attr.getName();
if (!prop.containsKey(key))
{
prop.put(key, key);
}
}
}
// Pulsante di riferimento al master nella lista detail
for (int i = 0; i < bean.getRelationships().size(); i++)
{
Relationship rel = bean.getRelationships().get(i);
if (rel.isMasterDetail())
{
if (!rel.isFromMany() && !rel.isToMany() && !rel.isFromMaster())
{
// Relazione 1:1 Master-Detail in cui il bean e' il Detail
key = "list_" + rel.getFromBeanName() + "_" + rel.getName() + "_OnlyOne" + rel.getFromBeanName() + "Allowed";
if (!prop.containsKey(key))
{
prop.put(key, "Only one " + rel.getFromBeanName()+" allowed");
}
}
// Inserisce il bottone di selezione del master o del detail a seconda del verso della relazione
if (!rel.isFromMaster())
{
// Questo bean e' il Detail
key = "list_" + rel.getFromBeanName() + "_" + rel.getToBeanName();
if (!prop.containsKey(key))
{
prop.put(key, rel.getToBeanName());
}
}
else
{
// Questo bean e' il master
Vector<ShowList> lists = infoReader.getLists(rel.getToBeanName());
for (ShowList list : lists)
{
key = "list_" + rel.getFromBeanName() + "_" + list.getName();
if (!prop.containsKey(key))
{
prop.put(key, list.getName());
}
}
}
}
}
/** Etichette per i campi della ricerca locale **/
for (int i = 0; i < bean.getLocalSearchAttributes().size(); i++)
{
ShowAttribute attr = bean.getLocalSearchAttributes().get(i);
if (attr.getRelationship() == null)
{
key = "localSearch_" + bean.getName() + "_" + attr.getName();
if (!prop.containsKey(key))
{
prop.put(key, Utils.makeFirstLetterUpperCase(attr.getName()));
}
}
else
{
key = "localSearch_" + bean.getName() + "_" + attr.getRelationship().getName() + "_" + attr.getName();
if (!prop.containsKey(key))
{
prop.put(key, attr.getRelationship().getName() + "_" + Utils.makeFirstLetterUpperCase(attr.getName()));
}
}
}
/** Etichette degli attributi di selezione di relazioni verso questo bean implementate come PopUp **/
Vector<Relationship> relationships2ThisBean = infoReader.getAllRelationship2ThisBean(bean.getName());
for (int i = 0; i < relationships2ThisBean.size(); i++)
{
Relationship rel = relationships2ThisBean.get(i);
if (!rel.isListBox())
{
Vector<ShowAttribute> relatedAttributes = rel.getRelatedAttributes();
for (ShowAttribute attribute : relatedAttributes)
{
key = "list_" + bean.getName() + "_" + attribute.getQualifiedName();
if (!prop.containsKey(key))
{
prop.put(key, key);
}
}
}
}
PropertiesFileManager.save(prop, resourcesFile + "NEW");
File oldTargetFile = new File(resourcesFile);
if (oldTargetFile.exists() && IOUtils.contentEquals(new FileInputStream(new File(resourcesFile + "NEW")), new FileInputStream(oldTargetFile)))
{
// Il nuovo file generato e' uguale al precedente
// Il nuovo viene cancellato
File f = new File(resourcesFile + "NEW");
f.deleteOnExit();
}
else
{
// Il nuovo file generato e' diverso dal precedente
// Il nuovo file viene copiato su quello esistente e poi cancellato
IOUtils.copy(new FileInputStream(new File(resourcesFile + "NEW")), new FileOutputStream(new File(resourcesFile)));
File f = new File(resourcesFile + "NEW");
f.deleteOnExit();
}
}
}