Source Code Cross Referenced for XmlGenerator.java in  » Test-Coverage » salome-tmf » salomeTMF_plug » docXML » export » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Test Coverage » salome tmf » salomeTMF_plug.docXML.export 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


0001:        /*
0002:         * SalomeTMF is a Test Management Framework
0003:         * Copyright (C) 2005 France Telecom R&D
0004:         *
0005:         * This library is free software; you can redistribute it and/or
0006:         * modify it under the terms of the GNU Lesser General Public
0007:         * License as published by the Free Software Foundation; either
0008:         * version 2 of the License, or (at your option) any later version.
0009:         *
0010:         * This library is distributed in the hope that it will be useful,
0011:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
0012:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
0013:         * Lesser General Public License for more details.
0014:         *
0015:         * You should have received a copy of the GNU Lesser General Public
0016:         * License along with this library; if not, write to the Free Software
0017:         * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
0018:         *
0019:         * @author Aurore PENAULT, Marche Mikael
0020:         *
0021:         * Contact: mikael.marche@orange-ft.com
0022:         */
0023:
0024:        package salomeTMF_plug.docXML.export;
0025:
0026:        import java.io.BufferedReader;
0027:        import java.io.File;
0028:        import java.io.FileOutputStream;
0029:        import java.io.FileReader;
0030:        import java.text.DateFormat;
0031:        import java.util.ArrayList;
0032:        import java.util.Enumeration;
0033:        import java.util.HashMap;
0034:        import java.util.Hashtable;
0035:        import java.util.Iterator;
0036:        import java.util.Locale;
0037:        import java.util.Vector;
0038:
0039:        import javax.swing.tree.DefaultMutableTreeNode;
0040:
0041:        import org.dom4j.Document;
0042:        import org.dom4j.DocumentHelper;
0043:        import org.dom4j.Element;
0044:        import org.dom4j.io.OutputFormat;
0045:        import org.dom4j.io.XMLWriter;
0046:        import org.java.plugin.Extension;
0047:        import org.objectweb.salome_tmf.api.Api;
0048:        import org.objectweb.salome_tmf.api.data.GroupWrapper;
0049:        import org.objectweb.salome_tmf.api.data.UserWrapper;
0050:        import org.objectweb.salome_tmf.api.sql.ISQLGroup;
0051:        import org.objectweb.salome_tmf.api.sql.ISQLProject;
0052:        import org.objectweb.salome_tmf.data.Action;
0053:        import org.objectweb.salome_tmf.data.Attachment;
0054:        import org.objectweb.salome_tmf.data.AutomaticTest;
0055:        import org.objectweb.salome_tmf.data.Campaign;
0056:        import org.objectweb.salome_tmf.data.DataSet;
0057:        import org.objectweb.salome_tmf.data.Environment;
0058:        import org.objectweb.salome_tmf.data.Execution;
0059:        import org.objectweb.salome_tmf.data.ExecutionResult;
0060:        import org.objectweb.salome_tmf.data.ExecutionTestResult;
0061:        import org.objectweb.salome_tmf.data.Family;
0062:        import org.objectweb.salome_tmf.data.FileAttachment;
0063:        import org.objectweb.salome_tmf.data.ManualExecutionResult;
0064:        import org.objectweb.salome_tmf.data.ManualTest;
0065:        import org.objectweb.salome_tmf.data.Parameter;
0066:        import org.objectweb.salome_tmf.data.Project;
0067:        import org.objectweb.salome_tmf.data.Script;
0068:        import org.objectweb.salome_tmf.data.Test;
0069:        import org.objectweb.salome_tmf.data.TestList;
0070:        import org.objectweb.salome_tmf.data.UrlAttachment;
0071:        import org.objectweb.salome_tmf.ihm.main.SalomeTMFPanels;
0072:        import org.objectweb.salome_tmf.ihm.main.datawrapper.DataModel;
0073:        import org.objectweb.salome_tmf.ihm.tools.Tools;
0074:        import org.objectweb.salome_tmf.plugins.IPlugObject;
0075:        import org.objectweb.salome_tmf.plugins.JPFManager;
0076:        import org.objectweb.salome_tmf.plugins.core.XMLPrinterPlugin;
0077:        import org.objectweb.salome_tmf.plugins.core.XMLWriterPlugin;
0078:
0079:        import salomeTMF_plug.docXML.export.Contexte.OutFormat;
0080:        import salomeTMF_plug.requirements.data.ReqLeaf;
0081:        import salomeTMF_plug.requirements.data.Requirement;
0082:
0083:        /**
0084:         * Classe qui permet la construction des documents xml,
0085:         * leur transformation en Html et leur sauvegarde dans un fichier
0086:         * @author  vapu8214
0087:         */
0088:        public class XmlGenerator implements  XMLWriterPlugin {
0089:
0090:            public boolean addDocType = true;
0091:
0092:            // IPlugObject pIPlugObject;
0093:            private Vector<XMLPrinterPlugin> listXMLPlugin = new Vector<XMLPrinterPlugin>();
0094:            Hashtable<Integer, String> userLoginByID = new Hashtable<Integer, String>();
0095:            Contexte pContexte;
0096:
0097:            public XmlGenerator(IPlugObject _pIPlugObject, Contexte pContexte) {
0098:                //pIPlugObject = _pIPlugObject;
0099:                Vector<Extension> listExtXMLPlugin = _pIPlugObject
0100:                        .getXMLPrintersExtension();
0101:                int size = listExtXMLPlugin.size();
0102:                for (int i = 0; i < size; i++) {
0103:                    Extension pXMLExt = (Extension) listExtXMLPlugin
0104:                            .elementAt(i);
0105:                    JPFManager pJPFManager = _pIPlugObject.getPluginManager();
0106:                    try {
0107:                        XMLPrinterPlugin pXMLPrinterPlugin = (XMLPrinterPlugin) pJPFManager
0108:                                .activateExtension(pXMLExt);
0109:                        if (!listXMLPlugin.contains(pXMLPrinterPlugin)) {
0110:                            listXMLPlugin.add(pXMLPrinterPlugin);
0111:                        }
0112:                    } catch (Exception e) {
0113:
0114:                    }
0115:                }
0116:                this .pContexte = pContexte;
0117:            }
0118:
0119:            void writeBaseProjet(Element projetVT) throws Exception {
0120:                Project proj = DataModel.getCurrentProject();
0121:                if (!proj.getNameFromModel().equals("")) {
0122:                    projetVT.addElement("Nom").setText(proj.getNameFromModel());
0123:                }
0124:                if (!proj.getDescriptionFromModel().equals("")) {
0125:                    projetVT.addElement("Description").setText(
0126:                            proj.getDescriptionFromModel().replaceAll("\n",
0127:                                    "\\\\n"));
0128:                }
0129:                String date_proj = DateFormat.getDateInstance(
0130:                        DateFormat.MEDIUM, Locale.FRANCE).format(
0131:                        proj.getCreationDateFromModel());
0132:                projetVT.addElement("Date_crea").setText(date_proj);
0133:
0134:                if (!proj.getParameterSetFromModel().isEmpty()) {
0135:                    Element params = projetVT.addElement("Params");
0136:                    Enumeration<Parameter> it = proj.getParameterSetFromModel()
0137:                            .elements();
0138:                    //iterator();
0139:                    while (it.hasMoreElements()) {
0140:                        Element param = params.addElement("Param");
0141:                        Parameter par = (Parameter) it.nextElement();
0142:                        param.addElement("Nom").setText(par.getNameFromModel());
0143:                        if (!par.getDescriptionFromModel().equals("")) {
0144:                            param.addElement("Description").setText(
0145:                                    par.getDescriptionFromModel().replaceAll(
0146:                                            "\n", "\\\\n"));
0147:                        }
0148:                        param.addAttribute("id_param", "Param_"
0149:                                + new Integer(par.getIdBdd()).toString());
0150:                    }
0151:                }
0152:
0153:                HashMap<String, Attachment> attachsProj = proj
0154:                        .getAttachmentMapFromModel();
0155:                addAttach(projetVT, pContexte.getPathAttach() + File.separator
0156:                        + "Attachements", attachsProj, "Attachements");
0157:
0158:                try {
0159:                    ISQLProject pISQLProject = Api.getISQLObjectFactory()
0160:                            .getISQLProject();
0161:                    GroupWrapper[] tmpArray = pISQLProject
0162:                            .getProjectGroups(DataModel.getCurrentProject()
0163:                                    .getIdBdd());
0164:                    Vector<GroupWrapper> project_Group = new Vector<GroupWrapper>();
0165:                    for (int tmpI = 0; tmpI < tmpArray.length; tmpI++) {
0166:                        project_Group.add(tmpArray[tmpI]);
0167:                    }
0168:                    userLoginByID.clear();
0169:                    if (project_Group.size() != 0) {
0170:                        Element groups = projetVT
0171:                                .addElement("GroupesDePersonnes");
0172:                        for (int i = 0; i < project_Group.size(); i++) {
0173:                            GroupWrapper pGroupWrapper = project_Group.get(i);
0174:                            Element grElem = groups
0175:                                    .addElement("GroupeDePersonnes");
0176:                            grElem.addElement("Nom").setText(
0177:                                    pGroupWrapper.getName());
0178:                            if (!pGroupWrapper.getDescription().equals("")) {
0179:                                grElem.addElement("Description").setText(
0180:                                        pGroupWrapper.getDescription()
0181:                                                .replaceAll("\n", "\\\\n"));
0182:                            }
0183:                            ISQLGroup pISQLGroup = Api.getISQLObjectFactory()
0184:                                    .getISQLGroup();
0185:                            UserWrapper[] tmpUserArray = pISQLGroup
0186:                                    .getUserWrappersInGroup(pGroupWrapper
0187:                                            .getIdBDD());
0188:                            Vector<UserWrapper> group_users = new Vector<UserWrapper>();
0189:                            for (int tmpI = 0; tmpI < tmpUserArray.length; tmpI++) {
0190:                                group_users.add(tmpUserArray[tmpI]);
0191:                            }
0192:
0193:                            if (group_users.size() != 0) {
0194:                                Element listPersElem = grElem
0195:                                        .addElement("Personnes");
0196:                                for (int j = 0; j < group_users.size(); j++) {
0197:                                    UserWrapper pUserWrapper = (UserWrapper) group_users
0198:                                            .elementAt(j);
0199:                                    Element persElem = listPersElem
0200:                                            .addElement("Personne");
0201:                                    if (!pUserWrapper.getLogin().equals("")) {
0202:                                        persElem.addElement("Login").setText(
0203:                                                pUserWrapper.getLogin());
0204:                                        userLoginByID.put(new Integer(
0205:                                                pUserWrapper.getIdBDD()),
0206:                                                pUserWrapper.getLogin());
0207:                                    }
0208:                                    if (pUserWrapper.getName() != null
0209:                                            && !pUserWrapper.getName().equals(
0210:                                                    "")) {
0211:                                        persElem.addElement("Nom").setText(
0212:                                                pUserWrapper.getName());
0213:                                    }
0214:                                    if (pUserWrapper.getPrenom() != null
0215:                                            && !pUserWrapper.getPrenom()
0216:                                                    .equals("")) {
0217:                                        persElem.addElement("Prenom").setText(
0218:                                                pUserWrapper.getPrenom());
0219:                                    }
0220:                                    if (pUserWrapper.getDescription() != null
0221:                                            && !pUserWrapper.getDescription()
0222:                                                    .equals("")) {
0223:                                        persElem
0224:                                                .addElement("Description")
0225:                                                .setText(
0226:                                                        pUserWrapper
0227:                                                                .getDescription()
0228:                                                                .replaceAll(
0229:                                                                        "\n",
0230:                                                                        "\\\\n"));
0231:                                    }
0232:                                    if (pUserWrapper.getEmail() != null
0233:                                            && !pUserWrapper.getEmail().equals(
0234:                                                    "")) {
0235:                                        persElem.addElement("Email").setText(
0236:                                                pUserWrapper.getEmail());
0237:                                    }
0238:                                    if (pUserWrapper.getTel() != null
0239:                                            && !pUserWrapper.getTel()
0240:                                                    .equals("")) {
0241:                                        persElem.addElement("Tel").setText(
0242:                                                pUserWrapper.getTel());
0243:                                    }
0244:                                    if (pUserWrapper.getCreateDate().toString() != null
0245:                                            && !pUserWrapper.getCreateDate()
0246:                                                    .toString().equals("")) {
0247:                                        persElem
0248:                                                .addElement("Date_crea")
0249:                                                .setText(
0250:                                                        pUserWrapper
0251:                                                                .getCreateDate()
0252:                                                                .toString());
0253:                                    }
0254:                                }
0255:                            }
0256:                        }
0257:                    }
0258:                } catch (Exception e) {
0259:                    Tools.ihmExceptionView(e);
0260:                }
0261:
0262:                /***** Plugin add XML for Project *****/
0263:                int size = listXMLPlugin.size();
0264:                for (int i = 0; i < size; i++) {
0265:                    XMLPrinterPlugin pXMLPrinterPlugin = (XMLPrinterPlugin) listXMLPlugin
0266:                            .elementAt(i);
0267:                    pXMLPrinterPlugin.addXMLElement2Project(projetVT, proj,
0268:                            this , pContexte.getPathAttach());
0269:                }
0270:                /***** (END) Plugin add XML for Project *****/
0271:
0272:            }
0273:
0274:            void writeRequirement(Element reqsElem,
0275:                    DefaultMutableTreeNode pTempNode, boolean first)
0276:                    throws Exception {
0277:                Requirement pTempReq = (Requirement) pTempNode.getUserObject();
0278:                HashMap<String, Attachment> attachs = null;
0279:                try {
0280:                    if (!first) {
0281:                        attachs = pTempReq.getAttachmentMapFromModel();
0282:                    }
0283:                } catch (Exception e) {
0284:
0285:                }
0286:                if (pTempReq instanceof  ReqLeaf) {
0287:                    //Write leaf
0288:                    Element reqLeafElem = reqsElem.addElement("Requirement");
0289:                    reqLeafElem.addElement("Nom").setText(
0290:                            pTempReq.getNameFromModel());
0291:                    reqLeafElem.addAttribute("priority", ""
0292:                            + ((ReqLeaf) pTempReq).getPriorityFromModel());
0293:                    reqLeafElem.addAttribute("version", ((ReqLeaf) pTempReq)
0294:                            .getVersionFromModel());
0295:
0296:                    reqLeafElem.addAttribute("id_req", "Req_"
0297:                            + new Integer(pTempReq.getIdBdd()).toString());
0298:                    reqLeafElem.addAttribute("id_req_parent", "Req_"
0299:                            + new Integer(pTempReq.getParent().getIdBdd())
0300:                                    .toString());
0301:                    if (pTempReq.getDescriptionFromModel() != null
0302:                            && !pTempReq.getDescriptionFromModel().equals("")) {
0303:                        addHTMLDescription(reqLeafElem, pTempReq
0304:                                .getDescriptionFromModel());
0305:                    }
0306:                    if (attachs != null) {
0307:                        addAttach(reqLeafElem, pContexte.getPathAttach()
0308:                                + File.separator + "Attachements"
0309:                                + File.separator + "Requirements"
0310:                                + File.separator + pTempReq.getIdBdd(),
0311:                                attachs, "Attachements" + File.separator
0312:                                        + "Requirements" + File.separator
0313:                                        + pTempReq.getIdBdd());
0314:                    }
0315:                } else {
0316:                    //Write family
0317:                    Element reqFamilyElem = reqsElem;
0318:                    if (!first) {
0319:                        reqFamilyElem = reqsElem
0320:                                .addElement("RequirementFamily");
0321:
0322:                        reqFamilyElem.addElement("Nom").setText(
0323:                                pTempReq.getNameFromModel());
0324:                        reqFamilyElem.addAttribute("id_req", "Req_"
0325:                                + new Integer(pTempReq.getIdBdd()).toString());
0326:                        reqFamilyElem.addAttribute("id_req_parent", "Req_"
0327:                                + new Integer(pTempReq.getParent().getIdBdd())
0328:                                        .toString());
0329:                        if (pTempReq.getDescriptionFromModel() != null
0330:                                && !pTempReq.getDescriptionFromModel().equals(
0331:                                        "")) {
0332:                            addHTMLDescription(reqFamilyElem, pTempReq
0333:                                    .getDescriptionFromModel());
0334:                        }
0335:                        if (attachs != null) {
0336:                            addAttach(reqFamilyElem, pContexte.getPathAttach()
0337:                                    + File.separator + "Attachements"
0338:                                    + File.separator + "Requirements"
0339:                                    + File.separator + pTempReq.getIdBdd(),
0340:                                    attachs, "Attachements" + File.separator
0341:                                            + "Requirements" + File.separator
0342:                                            + pTempReq.getIdBdd());
0343:                        }
0344:                    } else {
0345:                        first = false;
0346:                    }
0347:                    int nbChild = pTempNode.getChildCount();
0348:
0349:                    for (int i = 0; i < nbChild; i++) {
0350:                        writeRequirement(reqFamilyElem,
0351:                                (DefaultMutableTreeNode) pTempNode
0352:                                        .getChildAt(i), first);
0353:                    }
0354:
0355:                }
0356:            }
0357:
0358:            void writeEnvironnement(Element projetVT) throws Exception {
0359:                ArrayList<Environment> envirs = DataModel.getCurrentProject()
0360:                        .getEnvironmentListFromModel();
0361:                if (!envirs.isEmpty()) {
0362:                    Element envsElem = projetVT.addElement("Environnements");
0363:                    Iterator<Environment> it = envirs.iterator();
0364:                    while (it.hasNext()) {
0365:                        Environment env_courant = it.next();
0366:                        Element envElem = envsElem.addElement("Environnement");
0367:                        envElem.addElement("Nom").setText(
0368:                                env_courant.getNameFromModel());
0369:                        envElem.addAttribute("idEnv", "Env_"
0370:                                + new Integer(env_courant.getIdBdd())
0371:                                        .toString());
0372:                        if (env_courant.getDescriptionFromModel() != null
0373:                                && !env_courant.getDescriptionFromModel()
0374:                                        .equals("")) {
0375:                            envElem.addElement("Description").setText(
0376:                                    env_courant.getDescriptionFromModel()
0377:                                            .replaceAll("\n", "\\\\n"));
0378:                        }
0379:                        Hashtable<Parameter, String> params = env_courant
0380:                                .getParametersHashTableFromModel();
0381:                        if (!params.isEmpty()) {
0382:                            Element elemValParams = envElem
0383:                                    .addElement("ValeurParams");
0384:                            Enumeration<Parameter> e = params.keys();
0385:                            while (e.hasMoreElements()) {
0386:                                Element elemValParam = elemValParams
0387:                                        .addElement("ValeurParam");
0388:                                Parameter p = e.nextElement();
0389:                                elemValParam.addAttribute("ref", "Param_"
0390:                                        + new Integer(p.getIdBdd()).toString());
0391:                                elemValParam.addElement("Nom").setText(
0392:                                        p.getNameFromModel());
0393:                                if (!(params.get(p)).equals("")) {
0394:                                    elemValParam.addAttribute("valeur", params
0395:                                            .get(p));
0396:                                }
0397:                            }
0398:                        }
0399:                        Script scInit = env_courant.getInitScriptFromModel();
0400:                        if (scInit != null) {
0401:                            Element scriptElem = envElem.addElement("Script");
0402:                            if (scInit.getScriptExtensionFromModel() != null) {
0403:                                scriptElem.addElement("Classpath").setText(
0404:                                        scInit.getScriptExtensionFromModel());
0405:                            }
0406:                            if (scInit.getPlugArgFromModel() != null
0407:                                    && !scInit.getPlugArgFromModel().equals("")) {
0408:                                scriptElem.addElement("ArgScript").setText(
0409:                                        scInit.getPlugArgFromModel());
0410:                            }
0411:                            if (!scInit.getTypeFromModel().equals("")) {
0412:                                scriptElem.addAttribute("type", scInit
0413:                                        .getTypeFromModel());
0414:                            }
0415:                            scriptElem.addAttribute("nom", scInit
0416:                                    .getNameFromModel());
0417:
0418:                            String dest = new String(pContexte.getPathAttach()
0419:                                    + File.separator + "Attachements"
0420:                                    + File.separator + "Environnements"
0421:                                    + File.separator
0422:                                    + formater(env_courant.getNameFromModel())
0423:                                    + File.separator + "Script");
0424:                            scriptElem.addAttribute("dir",
0425:                                    "Attachements/Environnements/"
0426:                                            + formater(env_courant
0427:                                                    .getNameFromModel())
0428:                                            + "/Script/"
0429:                                            + formater(scInit
0430:                                                    .getNameFromModel()));
0431:
0432:                            try {
0433:                                scInit.getFileFromDB(dest);
0434:                                String extension = scInit.getNameFromModel()
0435:                                        .substring(
0436:                                                scInit.getNameFromModel()
0437:                                                        .lastIndexOf("."));
0438:                                if (pContexte.getFicType() != null) {
0439:                                    for (int i = 0; i < pContexte.getFicType().length; i++) {
0440:                                        if (pContexte.getFicType()[i]
0441:                                                .indexOf(".") != -1
0442:                                                && extension
0443:                                                        .equals(pContexte
0444:                                                                .getFicType()[i]
0445:                                                                .substring(pContexte
0446:                                                                        .getFicType()[i]
0447:                                                                        .lastIndexOf(".")))) {
0448:                                            Element text = scriptElem
0449:                                                    .addElement("Text");
0450:                                            if (pContexte.getOutputFormat() == OutFormat.DOCBOOK) {
0451:                                                ajouterScript(
0452:                                                        text,
0453:                                                        pContexte
0454:                                                                .getPathAttach()
0455:                                                                + File.separator
0456:                                                                + "Attachements"
0457:                                                                + File.separator
0458:                                                                + "Environnements"
0459:                                                                + File.separator
0460:                                                                + formater(env_courant
0461:                                                                        .getNameFromModel())
0462:                                                                + File.separator
0463:                                                                + "Script"
0464:                                                                + File.separator
0465:                                                                + formater(scInit
0466:                                                                        .getNameFromModel()));
0467:                                            } else {
0468:                                                ajouterTexte(
0469:                                                        text,
0470:                                                        pContexte
0471:                                                                .getPathAttach()
0472:                                                                + File.separator
0473:                                                                + "Attachements"
0474:                                                                + File.separator
0475:                                                                + "Environnements"
0476:                                                                + File.separator
0477:                                                                + formater(env_courant
0478:                                                                        .getNameFromModel())
0479:                                                                + File.separator
0480:                                                                + "Script"
0481:                                                                + File.separator
0482:                                                                + formater(scInit
0483:                                                                        .getNameFromModel()));
0484:                                            }
0485:                                        }
0486:                                    }
0487:                                }
0488:                            } catch (Exception e) {
0489:                                Tools.ihmExceptionView(e);
0490:                            }
0491:                        }
0492:                        HashMap<String, Attachment> attachs = env_courant
0493:                                .getAttachmentMapFromModel();
0494:                        addAttach(envElem, pContexte.getPathAttach()
0495:                                + File.separator + "Attachements"
0496:                                + File.separator + "Environnements"
0497:                                + File.separator + env_courant.getIdBdd(),
0498:                                attachs, "Attachements" + File.separator
0499:                                        + "Environnements" + File.separator
0500:                                        + env_courant.getIdBdd());
0501:
0502:                        /***** Plugin add XML for Environnement *****/
0503:                        int size = listXMLPlugin.size();
0504:                        for (int i = 0; i < size; i++) {
0505:                            XMLPrinterPlugin pXMLPrinterPlugin = (XMLPrinterPlugin) listXMLPlugin
0506:                                    .elementAt(i);
0507:                            pXMLPrinterPlugin.addXMLElement2Environment(
0508:                                    envElem, env_courant, this , pContexte
0509:                                            .getPathAttach());
0510:                        }
0511:                        /***** (END) Plugin add XML for Environnement *****/
0512:                    }
0513:                }
0514:
0515:            }
0516:
0517:            /**
0518:             * Méthode qui ajoute dans le document résultant le texte contenu
0519:             * dans le fichier dont le chemin est indiqué en paramètre
0520:             * @param text élément auquel on rajoute lengthcontenu du fichier
0521:             * @param path chemin du fichier dont le contenu doit être ajouté au document
0522:             */
0523:            public void ajouterScript(Element text, String path)
0524:                    throws Exception {
0525:                File fichier = new File(path);
0526:                FileReader fluxFichier = null;
0527:                try {
0528:                    fluxFichier = new FileReader(fichier);
0529:                    /*BufferedReader tamponLecture = new BufferedReader(fluxFichier);
0530:                    String ligne;
0531:                    while((ligne=tamponLecture.readLine())!=null){
0532:                    	text.addElement("ligne").setText(ligne);
0533:                    }
0534:                    tamponLecture.close();*/
0535:                    StringBuffer contenu = new StringBuffer();
0536:                    int car;
0537:                    while ((car = fluxFichier.read()) != -1) {
0538:                        contenu.append((char) car);
0539:                    }
0540:                    fluxFichier.close();
0541:                    text.addCDATA(contenu.toString());
0542:                    System.out.println("contenu" + contenu.toString());
0543:                } catch (Exception e) {
0544:                    Tools.ihmExceptionView(e);
0545:                }
0546:            }
0547:
0548:            void writeFamily(Element projetVT, boolean filtre,
0549:                    ArrayList<Family> selectFamilyList,
0550:                    ArrayList<TestList> selectSuiteList,
0551:                    ArrayList<Test> selectTestList) throws Exception {
0552:
0553:                ArrayList<Family> familleList = DataModel.getCurrentProject()
0554:                        .getFamilyListFromModel();
0555:                if ((familleList != null) && (!familleList.isEmpty())
0556:                        || (filtre && !selectFamilyList.isEmpty())) {
0557:                    Element famsElem = projetVT.addElement("Familles");
0558:                    Iterator<Family> it = familleList.iterator();
0559:                    while (it.hasNext()) {
0560:                        Family family = it.next();
0561:                        if (!filtre || selectFamilyList.contains(family)) {
0562:                            Element famElem = famsElem.addElement("Famille");
0563:                            famElem.addElement("Nom").setText(
0564:                                    family.getNameFromModel());
0565:                            if (family.getDescriptionFromModel() != null
0566:                                    && !family.getDescriptionFromModel()
0567:                                            .equals("")) {
0568:                                String description = family
0569:                                        .getDescriptionFromModel();
0570:                                addHTMLDescription(famElem, description);
0571:                            }
0572:                            famElem
0573:                                    .addAttribute("id_famille", "Fam_"
0574:                                            + new Integer(family.getIdBdd())
0575:                                                    .toString());
0576:                            HashMap<String, Attachment> attachsFam = family
0577:                                    .getAttachmentMapFromModel();
0578:                            addAttach(famElem, pContexte.getPathAttach()
0579:                                    + File.separator + "Attachements"
0580:                                    + File.separator + family.getIdBdd(),
0581:                                    attachsFam, "Attachements" + File.separator
0582:                                            + family.getIdBdd());
0583:
0584:                            /***** Plugin add XML for Family *****/
0585:                            int size = listXMLPlugin.size();
0586:                            for (int i = 0; i < size; i++) {
0587:                                XMLPrinterPlugin pXMLPrinterPlugin = (XMLPrinterPlugin) listXMLPlugin
0588:                                        .elementAt(i);
0589:                                pXMLPrinterPlugin
0590:                                        .addXMLElement2Family(famElem, family,
0591:                                                this , pContexte.getPathAttach());
0592:                            }
0593:                            /***** (END) Plugin add XML for Family *****/
0594:
0595:                            ArrayList<TestList> suiteTestList = family
0596:                                    .getSuiteListFromModel();
0597:                            if ((suiteTestList != null)
0598:                                    && (!suiteTestList.isEmpty())
0599:                                    || (filtre && !selectSuiteList.isEmpty())) {
0600:                                Element suitesElem = famElem
0601:                                        .addElement("SuiteTests");
0602:                                Iterator<TestList> iter = suiteTestList
0603:                                        .iterator();
0604:                                while (iter.hasNext()) {
0605:                                    TestList suiteTest = iter.next();
0606:                                    if (!filtre
0607:                                            || selectSuiteList
0608:                                                    .contains(suiteTest)) {
0609:                                        writeTestList(suitesElem, family,
0610:                                                suiteTest, filtre,
0611:                                                selectSuiteList, selectTestList);
0612:                                    }
0613:
0614:                                }
0615:                            }
0616:                        }
0617:                    }
0618:                }
0619:            }
0620:
0621:            private void addHTMLDescription(Element parentElem,
0622:                    String description) throws Exception {
0623:                String desc = description.replaceAll("<br>", "<br />");
0624:                try {
0625:                    Document document = DocumentHelper.parseText(desc);
0626:                    Element bodyElem = (Element) document
0627:                            .selectSingleNode("//body");
0628:                    Element descElem = bodyElem.createCopy("Description");
0629:                    if (descElem.isTextOnly()) {
0630:                        String text = descElem.getText();
0631:                        if (text.trim().length() != 0) {
0632:                            descElem.addAttribute("isHTML", "true");
0633:                            parentElem.add(descElem);
0634:                        }
0635:                    } else {
0636:                        descElem.addAttribute("isHTML", "true");
0637:                        parentElem.add(descElem);
0638:                    }
0639:                } catch (Exception e) {
0640:                    parentElem.addElement("Description").setText(
0641:                            desc.replaceAll("\n", "\\\\n"));
0642:                }
0643:            }
0644:
0645:            void writeTestList(Element suitesElem, Family pFamily,
0646:                    TestList pSuite, boolean filtre,
0647:                    ArrayList<TestList> selectSuiteList,
0648:                    ArrayList<Test> selectTestList) throws Exception {
0649:                Element suiteElem = suitesElem.addElement("SuiteTest");
0650:                suiteElem.addElement("Nom").setText(pSuite.getNameFromModel());
0651:                if (pSuite.getDescriptionFromModel() != null
0652:                        && !pSuite.getDescriptionFromModel().equals("")) {
0653:                    addHTMLDescription(suiteElem, pSuite
0654:                            .getDescriptionFromModel());
0655:                }
0656:                suiteElem.addAttribute("id_suite", "SuiteTest_"
0657:                        + new Integer(pSuite.getIdBdd()).toString());
0658:
0659:                /***** Plugin add XML for Suite *****/
0660:                int size = listXMLPlugin.size();
0661:                for (int i = 0; i < size; i++) {
0662:                    XMLPrinterPlugin pXMLPrinterPlugin = (XMLPrinterPlugin) listXMLPlugin
0663:                            .elementAt(i);
0664:                    pXMLPrinterPlugin.addXMLElement2Suite(suiteElem, pSuite,
0665:                            this , pContexte.getPathAttach());
0666:                }
0667:                /***** (END) Plugin add XML for Suite *****/
0668:
0669:                ArrayList<Test> testList = DataModel.getCurrentProject()
0670:                        .getAllTestFromModel(pSuite);
0671:                if ((testList != null) && (!testList.isEmpty())
0672:                        || (filtre && !selectTestList.isEmpty())) {
0673:                    Element testsElem = suiteElem.addElement("Tests");
0674:                    Iterator<Test> it2 = testList.iterator();
0675:                    while (it2.hasNext()) {
0676:                        Test test_cour = (Test) it2.next();
0677:                        if (!filtre || selectTestList.contains(test_cour)) {
0678:                            writeTest(testsElem, pFamily, pSuite, test_cour);
0679:                        }
0680:                    }
0681:                }
0682:                HashMap<String, Attachment> attachs = pSuite
0683:                        .getAttachmentMapFromModel();
0684:                addAttach(suiteElem, pContexte.getPathAttach() + File.separator
0685:                        + "Attachements" + File.separator + pFamily.getIdBdd()
0686:                        + File.separator + pSuite.getIdBdd(), attachs,
0687:                        "Attachements" + File.separator + pFamily.getIdBdd()
0688:                                + File.separator + pSuite.getIdBdd());
0689:
0690:            }
0691:
0692:            void writeTest(Element testsElem, Family pFamily, TestList pSuite,
0693:                    Test pTest) throws Exception {
0694:                Element testElem = testsElem.addElement("Test");
0695:                Element pers = testElem.addElement("Concepteur");
0696:                if (pTest.getConceptorFromModel() != null
0697:                        && !pTest.getConceptorFromModel().equals("")) {
0698:                    pers.addElement("Nom").setText(
0699:                            pTest.getConceptorFromModel());
0700:                }
0701:                //String login = ConnectionData.getSuiteTestSelect().getTestDesignerLogin(test_cour.getNameFromModel(), suiteTest.getNameFromModel(), family.getNameFromModel());
0702:                String login = pTest.getConceptorLoginFromModel();
0703:                if (login != null && !login.equals("")) {
0704:                    pers.addElement("Login").setText(login);
0705:                }
0706:                testElem.addElement("Nom").setText(pTest.getNameFromModel());
0707:                String laDate = DateFormat.getDateInstance(DateFormat.MEDIUM,
0708:                        Locale.FRANCE).format(pTest.getCreationDateFromModel());
0709:                testElem.addElement("Date_crea").setText(laDate);
0710:                if (pTest.getDescriptionFromModel() != null
0711:                        && !pTest.getDescriptionFromModel().equals("")) {
0712:                    addHTMLDescription(testElem, pTest
0713:                            .getDescriptionFromModel());
0714:                }
0715:                testElem.addAttribute("id_test", "Test_"
0716:                        + new Integer(pTest.getIdBdd()).toString());
0717:
0718:                ajouterInfoExecToTest(pTest, testElem);
0719:
0720:                ArrayList<Parameter> paramList = pTest
0721:                        .getParameterListFromModel();
0722:                if (!paramList.isEmpty()) {
0723:                    Element params = testElem.addElement("ParamsT");
0724:                    Iterator<Parameter> itp = paramList.iterator();
0725:                    while (itp.hasNext()) {
0726:                        Parameter param = (Parameter) itp.next();
0727:                        Element paramElem = params.addElement("ParamT");
0728:                        paramElem.addAttribute("ref", "Param_"
0729:                                + new Integer(param.getIdBdd()).toString());
0730:                        paramElem.addElement("Nom").setText(
0731:                                param.getNameFromModel());
0732:                    }
0733:                }
0734:
0735:                /***** Plugin add XML for Test *****/
0736:                int size = listXMLPlugin.size();
0737:                for (int i = 0; i < size; i++) {
0738:                    XMLPrinterPlugin pXMLPrinterPlugin = (XMLPrinterPlugin) listXMLPlugin
0739:                            .elementAt(i);
0740:                    pXMLPrinterPlugin.addXMLElement2Test(testElem, pTest, this ,
0741:                            pContexte.getPathAttach());
0742:                }
0743:                /***** (END) Plugin add XML for Test *****/
0744:
0745:                HashMap<String, Attachment> attachs = pTest
0746:                        .getAttachmentMapFromModel();
0747:                addAttach(testElem, pContexte.getPathAttach() + File.separator
0748:                        + "Attachements" + File.separator + pFamily.getIdBdd()
0749:                        + File.separator + pSuite.getIdBdd() + File.separator
0750:                        + pTest.getIdBdd(), attachs, "Attachements"
0751:                        + File.separator + pFamily.getIdBdd() + File.separator
0752:                        + pSuite.getIdBdd() + File.separator + pTest.getIdBdd());
0753:
0754:                if (pTest instanceof  ManualTest) {
0755:                    writeManualTest(testElem, pFamily, pSuite,
0756:                            (ManualTest) pTest);
0757:                } else {
0758:                    writeAutomaticTest(testElem, pFamily, pSuite,
0759:                            (AutomaticTest) pTest);
0760:                }
0761:            }
0762:
0763:            void writeManualTest(Element testElem, Family pFamily,
0764:                    TestList pSuite, ManualTest pTest) throws Exception {
0765:
0766:                Element testManElem = testElem.addElement("TestManuel");
0767:                ArrayList<Action> actionList = pTest
0768:                        .getActionListFromModel(false);
0769:                Iterator<Action> it3 = actionList.iterator();
0770:                while (it3.hasNext()) {
0771:                    Element actionElem = testManElem.addElement("ActionTest");
0772:                    Action ac = it3.next();
0773:                    actionElem.addElement("Nom").setText(ac.getNameFromModel());
0774:                    if (ac.getDescriptionFromModel() != null
0775:                            && !ac.getDescriptionFromModel().equals("")) {
0776:                        actionElem.addElement("Description").setText(
0777:                                ac.getDescriptionFromModel().replaceAll("\n",
0778:                                        "\\\\n"));
0779:                    }
0780:                    if (ac.getAwaitedResultFromModel() != null
0781:                            && !ac.getAwaitedResultFromModel().equals("")) {
0782:                        actionElem.addElement("ResultAttendu").setText(
0783:                                ac.getAwaitedResultFromModel().replaceAll("\n",
0784:                                        "\\\\n"));
0785:                    }
0786:
0787:                    actionElem.addAttribute("id_action", "Action_"
0788:                            + new Integer(ac.getIdBdd()).toString());
0789:                    Hashtable<String, Parameter> paramEns = ac
0790:                            .getParameterHashSetFromModel();
0791:                    if (!paramEns.isEmpty()) {
0792:                        Element params = actionElem.addElement("ParamsT");
0793:                        Enumeration<Parameter> itp = paramEns.elements();
0794:                        while (itp.hasMoreElements()) {
0795:                            Parameter param = (Parameter) itp.nextElement();
0796:                            Element paramElem = params.addElement("ParamT");
0797:                            paramElem.addAttribute("ref", "Param_"
0798:                                    + new Integer(param.getIdBdd()).toString());
0799:                            paramElem.addElement("Nom").setText(
0800:                                    param.getNameFromModel());
0801:                        }
0802:                    }
0803:                    HashMap<String, Attachment> attachs = ac
0804:                            .getAttachmentMapFromModel();
0805:                    addAttach(actionElem,
0806:                            pContexte.getPathAttach() + File.separator
0807:                                    + "Attachements" + File.separator
0808:                                    + pFamily.getIdBdd() + File.separator
0809:                                    + pSuite.getIdBdd() + File.separator
0810:                                    + pTest.getIdBdd() + File.separator
0811:                                    + ac.getIdBdd(), attachs, "Attachements"
0812:                                    + File.separator + pFamily.getIdBdd()
0813:                                    + File.separator + pSuite.getIdBdd()
0814:                                    + File.separator + pTest.getIdBdd()
0815:                                    + File.separator + ac.getIdBdd());
0816:
0817:                    /***** Plugin add XML for Action *****/
0818:                    int size = listXMLPlugin.size();
0819:                    for (int i = 0; i < size; i++) {
0820:                        XMLPrinterPlugin pXMLPrinterPlugin = (XMLPrinterPlugin) listXMLPlugin
0821:                                .elementAt(i);
0822:                        pXMLPrinterPlugin.addXMLElement2Action(actionElem, ac,
0823:                                this , pContexte.getPathAttach());
0824:                    }
0825:                    /***** (END) Plugin add XML for Action *****/
0826:
0827:                }
0828:            }
0829:
0830:            void writeAutomaticTest(Element testElem, Family pFamily,
0831:                    TestList pSuite, AutomaticTest pTest) throws Exception {
0832:
0833:                Element testAutoElem = testElem.addElement("TestAuto");
0834:                testAutoElem.addAttribute("plug_ext", ((AutomaticTest) pTest)
0835:                        .getExtensionFromModel());
0836:                Script sc = ((AutomaticTest) pTest).getScriptFromModel();
0837:                if (sc != null) {
0838:                    Element scriptElem = testAutoElem.addElement("Script");
0839:                    if (sc.getScriptExtensionFromModel() != null
0840:                            && !sc.getScriptExtensionFromModel().equals("")) {
0841:                        scriptElem.addElement("Classpath").setText(
0842:                                sc.getScriptExtensionFromModel());
0843:                    }
0844:                    if (sc.getPlugArgFromModel() != null
0845:                            && !sc.getPlugArgFromModel().equals("")) {
0846:                        scriptElem.addElement("ArgScript").setText(
0847:                                sc.getPlugArgFromModel());
0848:                    }
0849:                    if (!sc.getTypeFromModel().equals("")) {
0850:                        scriptElem.addAttribute("type", sc.getTypeFromModel());
0851:                    }
0852:                    scriptElem.addAttribute("nom", sc.getNameFromModel());
0853:                    String dest = new String(pContexte.getPathAttach()
0854:                            + File.separator + "Attachements" + File.separator
0855:                            + formater(pFamily.getNameFromModel())
0856:                            + File.separator
0857:                            + formater(pSuite.getNameFromModel())
0858:                            + File.separator
0859:                            + formater(pTest.getNameFromModel())
0860:                            + File.separator + "Script");
0861:                    scriptElem.addAttribute("dir", "Attachements/"
0862:                            + formater(pFamily.getNameFromModel()) + "/"
0863:                            + formater(pSuite.getNameFromModel()) + "/"
0864:                            + formater(pTest.getNameFromModel()) + "/Script/"
0865:                            + formater(sc.getNameFromModel()));
0866:                    try {
0867:                        sc.getFileFromDB(dest);
0868:                        String extension = sc.getNameFromModel().substring(
0869:                                sc.getNameFromModel().lastIndexOf("."));
0870:                        if (pContexte.getFicType() != null) {
0871:                            for (int i = 0; i < pContexte.getFicType().length; i++) {
0872:                                if (pContexte.getFicType()[i].indexOf(".") != -1
0873:                                        && extension.equals(pContexte
0874:                                                .getFicType()[i]
0875:                                                .substring(pContexte
0876:                                                        .getFicType()[i]
0877:                                                        .lastIndexOf(".")))) {
0878:                                    Element text = scriptElem
0879:                                            .addElement("Text");
0880:                                    if (pContexte.getOutputFormat() == OutFormat.DOCBOOK) {
0881:                                        ajouterScript(text, pContexte
0882:                                                .getPathAttach()
0883:                                                + File.separator
0884:                                                + "Attachements"
0885:                                                + File.separator
0886:                                                + formater(pFamily
0887:                                                        .getNameFromModel())
0888:                                                + File.separator
0889:                                                + formater(pSuite
0890:                                                        .getNameFromModel())
0891:                                                + File.separator
0892:                                                + formater(pTest
0893:                                                        .getNameFromModel())
0894:                                                + File.separator
0895:                                                + "Script"
0896:                                                + File.separator
0897:                                                + formater(sc
0898:                                                        .getNameFromModel()));
0899:                                    } else {
0900:                                        ajouterTexte(text, pContexte
0901:                                                .getPathAttach()
0902:                                                + File.separator
0903:                                                + "Attachements"
0904:                                                + File.separator
0905:                                                + formater(pFamily
0906:                                                        .getNameFromModel())
0907:                                                + File.separator
0908:                                                + formater(pSuite
0909:                                                        .getNameFromModel())
0910:                                                + File.separator
0911:                                                + formater(pTest
0912:                                                        .getNameFromModel())
0913:                                                + File.separator
0914:                                                + "Script"
0915:                                                + File.separator
0916:                                                + formater(sc
0917:                                                        .getNameFromModel()));
0918:                                    }
0919:                                }
0920:                            }
0921:                        }
0922:                    } catch (Exception e) {
0923:                        Tools.ihmExceptionView(e);
0924:                    }
0925:                }
0926:            }
0927:
0928:            void writeDataSet(Element campElem, Campaign pCamp)
0929:                    throws Exception {
0930:                //	 jeu de donnees
0931:                ArrayList<DataSet> datasetList = pCamp
0932:                        .getDataSetListFromModel();
0933:                if (!datasetList.isEmpty()) {
0934:                    Element datasetsElem = campElem.addElement("JeuxDonnees");
0935:                    Iterator<DataSet> iter = datasetList.iterator();
0936:                    while (iter.hasNext()) {
0937:                        Element datasetElem = datasetsElem
0938:                                .addElement("JeuDonnees");
0939:                        DataSet dataset = iter.next();
0940:                        datasetElem.addElement("Nom").setText(
0941:                                dataset.getNameFromModel());
0942:                        if (dataset.getDescriptionFromModel() != null
0943:                                && !dataset.getDescriptionFromModel()
0944:                                        .equals("")) {
0945:                            datasetElem.addElement("Description").setText(
0946:                                    dataset.getDescriptionFromModel()
0947:                                            .replaceAll("\n", "\\\\n"));
0948:                        }
0949:                        HashMap<String, String> parameters = dataset
0950:                                .getParametersHashMapFromModel();//HashMap nomParam -> ValeurParam  String -> String
0951:                        if (!parameters.isEmpty()) {
0952:                            Element elemValParams = datasetElem
0953:                                    .addElement("ValeurParams");
0954:                            Iterator<String> it2 = parameters.keySet()
0955:                                    .iterator();
0956:                            while (it2.hasNext()) {
0957:                                Element elemValParam = elemValParams
0958:                                        .addElement("ValeurParam");
0959:                                String par = it2.next();
0960:                                Parameter p = DataModel.getCurrentProject()
0961:                                        .getParameterFromModel(par);
0962:                                elemValParam.addAttribute("ref", "Param_"
0963:                                        + new Integer(p.getIdBdd()).toString());
0964:                                elemValParam.addElement("Nom").setText(
0965:                                        p.getNameFromModel());
0966:                                if (parameters.get(par) != null
0967:                                        && !((String) parameters.get(par))
0968:                                                .equals("")) {
0969:                                    elemValParam.addAttribute("valeur",
0970:                                            (String) parameters.get(par));
0971:                                }
0972:                            }
0973:                        }
0974:                        datasetElem.addAttribute("id_jeu", "Jeu_"
0975:                                + new Integer(dataset.getIdBdd()).toString());
0976:
0977:                        /***** Plugin add XML for DataSet *****/
0978:                        int size = listXMLPlugin.size();
0979:                        for (int i = 0; i < size; i++) {
0980:                            XMLPrinterPlugin pXMLPrinterPlugin = (XMLPrinterPlugin) listXMLPlugin
0981:                                    .elementAt(i);
0982:                            pXMLPrinterPlugin.addXMLElement2DataSet(
0983:                                    datasetElem, dataset, this , pContexte
0984:                                            .getPathAttach());
0985:                        }
0986:                        /***** (END) Plugin add XML for DataSet *****/
0987:
0988:                    }
0989:                }
0990:            }
0991:
0992:            ArrayList<Test> writeTestInCamp(Element campElem, Campaign pCamp)
0993:                    throws Exception {
0994:                ArrayList<Test> testOrdonne = new ArrayList<Test>();
0995:                ArrayList<Family> familyList = pCamp.getFamilyListFromModel();
0996:                if (!familyList.isEmpty()) {
0997:                    Element famsElem = campElem.addElement("FamillesCamp");
0998:                    Iterator<Family> iter = familyList.iterator();
0999:                    while (iter.hasNext()) {
1000:                        Family fam = iter.next();
1001:                        Element famElem = famsElem.addElement("FamilleRef");
1002:                        famElem.addAttribute("ref", "Fam_"
1003:                                + new Integer(fam.getIdBdd()).toString());
1004:                        famElem.addElement("Nom").setText(
1005:                                fam.getNameFromModel());
1006:                        ArrayList<TestList> suiteTestList = fam
1007:                                .getSuiteListFromModel();
1008:                        if (!suiteTestList.isEmpty()) {
1009:                            Iterator<TestList> iter2 = suiteTestList.iterator();
1010:                            Element suiteTestsElem = famElem
1011:                                    .addElement("SuiteTestsCamp");
1012:                            while (iter2.hasNext()) {
1013:                                TestList suitetest = iter2.next();
1014:                                if (pCamp.containsTestListInModel(suitetest)) {
1015:                                    Element suiteTestElem = suiteTestsElem
1016:                                            .addElement("SuiteTestRef");
1017:                                    suiteTestElem.addAttribute("ref",
1018:                                            "SuiteTest_"
1019:                                                    + new Integer(suitetest
1020:                                                            .getIdBdd())
1021:                                                            .toString());
1022:                                    suiteTestElem.addElement("Nom").setText(
1023:                                            suitetest.getNameFromModel());
1024:                                    ArrayList<Test> testList = suitetest
1025:                                            .getTestListFromModel();
1026:                                    if (!testList.isEmpty()) {
1027:                                        Element testsElem = suiteTestElem
1028:                                                .addElement("TestsCamp");
1029:                                        Iterator<Test> iter3 = testList
1030:                                                .iterator();
1031:                                        while (iter3.hasNext()) {
1032:                                            Test test = iter3.next();
1033:                                            if (pCamp.containsTestInModel(test)) {
1034:                                                testOrdonne.add(test);
1035:                                                Element testElem = testsElem
1036:                                                        .addElement("TestRef");
1037:                                                testElem
1038:                                                        .addAttribute(
1039:                                                                "ref",
1040:                                                                "Test_"
1041:                                                                        + new Integer(
1042:                                                                                test
1043:                                                                                        .getIdBdd())
1044:                                                                                .toString());
1045:                                                testElem
1046:                                                        .addElement("Nom")
1047:                                                        .setText(
1048:                                                                test
1049:                                                                        .getNameFromModel());
1050:                                                int userID = pCamp
1051:                                                        .getAssignedUserID(test);
1052:                                                if (userID == -1) {
1053:                                                    userID = DataModel
1054:                                                            .getCurrentUser()
1055:                                                            .getIdBdd();
1056:                                                }
1057:                                                String login = (String) userLoginByID
1058:                                                        .get(new Integer(userID));
1059:                                                if (login != null
1060:                                                        && !login.equals("")) {
1061:                                                    testElem.addAttribute(
1062:                                                            "loginAssigned",
1063:                                                            login);
1064:                                                }
1065:                                            }
1066:                                        }
1067:                                    }
1068:                                }
1069:                            }
1070:                        }
1071:                    }
1072:                }
1073:                return testOrdonne;
1074:            }
1075:
1076:            void writeManualActionResult(Element actionsElem,
1077:                    ManualExecutionResult pManualExecutionResult,
1078:                    ManualTest pTest) throws Exception {
1079:                if (pManualExecutionResult == null) {
1080:                    return;
1081:                }
1082:                HashMap<Action, String> actionMap = pManualExecutionResult
1083:                        .getActionsMapInModel();
1084:                ArrayList<Action> actionList = pTest
1085:                        .getActionListFromModel(false);
1086:                if (!actionList.isEmpty()) {
1087:                    Iterator<Action> it4 = actionList.iterator();
1088:                    while (it4.hasNext()) {
1089:                        Action action = it4.next();
1090:                        if (actionMap.containsKey(action)) {
1091:                            Element actionElem = actionsElem
1092:                                    .addElement("ResulActionTest");
1093:                            actionElem
1094:                                    .addAttribute("refAction", "Action_"
1095:                                            + new Integer(action.getIdBdd())
1096:                                                    .toString());
1097:                            Element refAction = actionElem
1098:                                    .addElement("RefAction");
1099:                            refAction.addElement("NomAction").setText(
1100:                                    action.getNameFromModel());
1101:                            refAction.addElement("NomTest").setText(
1102:                                    pTest.getNameFromModel());
1103:                            refAction.addElement("NomSuite").setText(
1104:                                    pTest.getTestListFromModel()
1105:                                            .getNameFromModel());
1106:                            refAction.addElement("NomFamille").setText(
1107:                                    pTest.getTestListFromModel()
1108:                                            .getFamilyFromModel()
1109:                                            .getNameFromModel());
1110:                            String resultat = (String) actionMap.get(action);
1111:                            if (resultat == null || resultat.equals("")) {
1112:                                resultat = "NonRenseigne";
1113:                            }
1114:                            actionElem.addAttribute("res", resultat);
1115:                            if (pManualExecutionResult
1116:                                    .getDescriptionResultFromModel(action) != null) {
1117:                                Element test2 = actionElem
1118:                                        .addElement("Description");
1119:                                test2.setText(pManualExecutionResult
1120:                                        .getDescriptionResultFromModel(action)
1121:                                        .replaceAll("\n", "\\\\n"));
1122:                            }
1123:                            if (pManualExecutionResult
1124:                                    .getAwaitedResultFromModel(action) != null) {
1125:                                actionElem.addElement("ResultAttendu").setText(
1126:                                        pManualExecutionResult
1127:                                                .getAwaitedResultFromModel(
1128:                                                        action).replaceAll(
1129:                                                        "\n", "\\\\n"));
1130:                            }
1131:                            if (pManualExecutionResult
1132:                                    .getEffectivResultFromModel(action) != null) {
1133:                                actionElem.addElement("ResulEffectif").setText(
1134:                                        pManualExecutionResult
1135:                                                .getEffectivResultFromModel(
1136:                                                        action).replaceAll(
1137:                                                        "\n", "\\\\n"));
1138:                            }
1139:                        }
1140:                    }
1141:                }
1142:            }
1143:
1144:            void writeExecResultStatus(Element execResElem, Campaign pCamp,
1145:                    Execution pExec, ExecutionResult execRes,
1146:                    ArrayList<Test> testOrdonne) throws Exception {
1147:                execResElem.addAttribute("statut", execRes
1148:                        .getExecutionStatusFromModel());
1149:                HashMap<Test, ExecutionTestResult> resultTest = execRes
1150:                        .getTestsResultMapFromModel();
1151:                if (!resultTest.isEmpty()) {
1152:                    Element resElems = execResElem.addElement("ResulExecs");
1153:                    if (!testOrdonne.isEmpty()) {
1154:                        Iterator<Test> it3 = testOrdonne.iterator();
1155:                        while (it3.hasNext()) {
1156:                            Test test = it3.next();
1157:                            if (resultTest.containsKey(test)) {
1158:                                ExecutionTestResult etr = (ExecutionTestResult) resultTest
1159:                                        .get(test);
1160:                                Element resElem = resElems
1161:                                        .addElement("ResulExec");
1162:                                resElem.addAttribute("refTest", "Test_"
1163:                                        + new Integer(etr.getTestFromModel()
1164:                                                .getIdBdd()).toString());
1165:                                Element refTest = resElem.addElement("RefTest");
1166:                                refTest.addElement("NomTest").setText(
1167:                                        test.getNameFromModel());
1168:                                refTest.addElement("NomSuite").setText(
1169:                                        test.getTestListFromModel()
1170:                                                .getNameFromModel());
1171:                                refTest.addElement("NomFamille").setText(
1172:                                        test.getTestListFromModel()
1173:                                                .getFamilyFromModel()
1174:                                                .getNameFromModel());
1175:                                if (etr.getStatusFromModel().equals("PASSED")
1176:                                        || etr.getStatusFromModel().equals(
1177:                                                "FAILED")
1178:                                        || etr.getStatusFromModel().equals(
1179:                                                "INCONCLUSIF")) {
1180:                                    resElem.addAttribute("res", etr
1181:                                            .getStatusFromModel());
1182:                                } else {
1183:                                    resElem.addAttribute("res", "NonRenseigne");
1184:                                }
1185:                                HashMap<String, Attachment> attachsExecRes = etr
1186:                                        .getAttachmentMapFromModel();
1187:                                addAttach(resElem, pContexte.getPathAttach()
1188:                                        + File.separator + "Attachements"
1189:                                        + File.separator + "Campagnes"
1190:                                        + File.separator + pCamp.getIdBdd()
1191:                                        + File.separator + pExec.getIdBdd()
1192:                                        + File.separator + execRes.getIdBdd()
1193:                                        + File.separator
1194:                                        + etr.getTestFromModel().getIdBdd(),
1195:                                        attachsExecRes, "Attachements"
1196:                                                + File.separator
1197:                                                + "Campagnes"
1198:                                                + File.separator
1199:                                                + pCamp.getIdBdd()
1200:                                                + File.separator
1201:                                                + pExec.getIdBdd()
1202:                                                + File.separator
1203:                                                + execRes.getIdBdd()
1204:                                                + File.separator
1205:                                                + etr.getTestFromModel()
1206:                                                        .getIdBdd());
1207:                                /***** Plugin add XML for ExecResul *****/
1208:                                int size = listXMLPlugin.size();
1209:                                for (int i = 0; i < size; i++) {
1210:                                    XMLPrinterPlugin pXMLPrinterPlugin = (XMLPrinterPlugin) listXMLPlugin
1211:                                            .elementAt(i);
1212:                                    pXMLPrinterPlugin
1213:                                            .addXMLElement2ResTestExecution(
1214:                                                    resElem, etr, test, this ,
1215:                                                    pContexte.getPathAttach());
1216:                                }
1217:                                /***** (END) Plugin add XML for ExecResul *****/
1218:                            }
1219:                        }
1220:                    }
1221:                }
1222:            }
1223:
1224:            void writeExecResults(Element execElem, Campaign pCamp,
1225:                    Execution pExec, ArrayList<Test> testOrdonne)
1226:                    throws Exception {
1227:                ArrayList<ExecutionResult> resulExecList = pExec
1228:                        .getExecutionResultListFromModel();
1229:                if (!resulExecList.isEmpty()) {
1230:                    Element resulExecsElem = execElem
1231:                            .addElement("ResulExecCampTests");
1232:                    Iterator<ExecutionResult> it2 = resulExecList.iterator();
1233:                    while (it2.hasNext()) {
1234:                        ExecutionResult execRes = it2.next();
1235:                        writeExecResult(resulExecsElem, pCamp, pExec, execRes,
1236:                                testOrdonne);
1237:                    }
1238:                }
1239:            }
1240:
1241:            void writeExecResult(Element resulExecsElem, Campaign pCamp,
1242:                    Execution pExec, ExecutionResult execRes,
1243:                    ArrayList<Test> testOrdonne) throws Exception {
1244:                Element execResElem = resulExecsElem
1245:                        .addElement("ResulExecCampTest");
1246:                execResElem.addAttribute("id_exec_res", "ResExecCamp_"
1247:                        + new Integer(execRes.getIdBdd()).toString());
1248:                if (execRes.getTesterFromModel() != null
1249:                        && !execRes.getTesterFromModel().equals("")) {
1250:                    execResElem.addElement("Testeur").setText(
1251:                            execRes.getTesterFromModel());
1252:                }
1253:                if (!execRes.getNameFromModel().equals("")) {
1254:                    execResElem.addElement("Nom").setText(
1255:                            execRes.getNameFromModel());
1256:                }
1257:                if (execRes.getDescriptionFromModel() != null
1258:                        && !execRes.getDescriptionFromModel().equals("")) {
1259:                    execResElem.addElement("Description").setText(
1260:                            execRes.getDescriptionFromModel().replaceAll("\n",
1261:                                    "\\\\n"));
1262:                }
1263:                if (execRes.getExecutionDateFromModel() != null) {
1264:                    String date_exec = DateFormat.getDateInstance(
1265:                            DateFormat.MEDIUM, Locale.FRANCE).format(
1266:                            execRes.getExecutionDateFromModel());
1267:                    execResElem.addElement("Date_crea").setText(date_exec);
1268:                }
1269:                if (execRes.getTimeFromModel() != null) {
1270:                    execResElem.addElement("Heure_crea").setText(
1271:                            execRes.getTimeFromModel().toString());
1272:                }
1273:                HashMap<String, Attachment> attachRes = execRes
1274:                        .getAttachmentMapFromModel();
1275:                addAttach(execResElem, pContexte.getPathAttach()
1276:                        + File.separator + "Attachements" + File.separator
1277:                        + "Campagnes" + File.separator + pCamp.getIdBdd()
1278:                        + File.separator + pExec.getIdBdd() + File.separator
1279:                        + execRes.getIdBdd(), attachRes, "Attachements"
1280:                        + File.separator + "Campagnes" + File.separator
1281:                        + pCamp.getIdBdd() + File.separator + pExec.getIdBdd()
1282:                        + File.separator + execRes.getIdBdd());
1283:                writeExecResultStatus(execResElem, pCamp, pExec, execRes,
1284:                        testOrdonne);
1285:
1286:                /***** Plugin add XML for ExecResul *****/
1287:                int size = listXMLPlugin.size();
1288:                for (int i = 0; i < size; i++) {
1289:                    XMLPrinterPlugin pXMLPrinterPlugin = (XMLPrinterPlugin) listXMLPlugin
1290:                            .elementAt(i);
1291:                    pXMLPrinterPlugin.addXMLElement2ResExecution(execResElem,
1292:                            execRes, this , pContexte.getPathAttach());
1293:                }
1294:                /***** (END) Plugin add XML for ExecResul *****/
1295:
1296:                Element actionsElem = null;
1297:                boolean elementActionWrited = false;
1298:                if (!testOrdonne.isEmpty()) {
1299:                    Iterator<Test> it3 = testOrdonne.iterator();
1300:                    while (it3.hasNext()) {
1301:                        Test test = it3.next();
1302:                        ExecutionTestResult pExecutionTestResult = execRes
1303:                                .getExecutionTestResultFromModel(test);
1304:                        if (test instanceof  ManualTest) {
1305:                            if (!elementActionWrited) {
1306:                                actionsElem = execResElem
1307:                                        .addElement("ResulActionTests");
1308:                                elementActionWrited = true;
1309:                            }
1310:                            //System.out.println("Write result for " +execRes.getNameFromModel() + ", exec : " + execRes.getExecution().getNameFromModel() + ", camp :" + execRes.getExecution().getCampagneFromModel().getNameFromModel());
1311:                            writeManualActionResult(
1312:                                    actionsElem,
1313:                                    (ManualExecutionResult) pExecutionTestResult,
1314:                                    ((ManualTest) test));
1315:                        }
1316:                    }
1317:                }
1318:            }
1319:
1320:            void writePreScript(Element execElem, Campaign pCamp, Execution exec)
1321:                    throws Exception {
1322:                writeScriptExec(execElem, "ScriptInitialisation", pCamp, exec,
1323:                        exec.getPreScriptFromModel());
1324:            }
1325:
1326:            void writePostScript(Element execElem, Campaign pCamp,
1327:                    Execution exec) throws Exception {
1328:                writeScriptExec(execElem, "ScriptRestitution", pCamp, exec,
1329:                        exec.getPostScriptFromModel());
1330:            }
1331:
1332:            /**
1333:             * @param execElem
1334:             * @param type ScriptInitialisation ou ScriptRestitution
1335:             * @param pCamp
1336:             * @param exec
1337:             * @param pathAttach
1338:             * @param ficType
1339:             */
1340:            void writeScriptExec(Element execElem, String type, Campaign pCamp,
1341:                    Execution exec, Script pScript) throws Exception {
1342:                Element scriptInitElem = execElem.addElement("Script");
1343:                if (pScript.getScriptExtensionFromModel() != null) {
1344:                    scriptInitElem.addElement("Classpath").setText(
1345:                            pScript.getScriptExtensionFromModel());
1346:                }
1347:                if (pScript.getPlugArgFromModel() != null
1348:                        && !pScript.getPlugArgFromModel().equals("")) {
1349:                    scriptInitElem.addElement("ArgScript").setText(
1350:                            pScript.getPlugArgFromModel());
1351:                }
1352:                if (!pScript.getTypeFromModel().equals("")) {
1353:                    scriptInitElem.addAttribute("type", pScript
1354:                            .getTypeFromModel());
1355:                }
1356:                scriptInitElem.addAttribute("nom", pScript.getNameFromModel());
1357:                String dest = new String(pContexte.getPathAttach()
1358:                        + File.separator + "Attachements" + File.separator
1359:                        + "Campagnes" + File.separator
1360:                        + formater(pCamp.getNameFromModel()) + File.separator
1361:                        + formater(exec.getNameFromModel()) + File.separator
1362:                        + type);
1363:                scriptInitElem.addAttribute("dir", "Attachements/Campagnes/"
1364:                        + formater(pCamp.getNameFromModel()) + "/"
1365:                        + formater(exec.getNameFromModel()) + "/" + type + "/"
1366:                        + formater(pScript.getNameFromModel()));
1367:                try {
1368:                    pScript.getFileFromDB(dest);
1369:                    String extension = pScript.getNameFromModel().substring(
1370:                            pScript.getNameFromModel().lastIndexOf("."));
1371:                    if (pContexte.getFicType() != null) {
1372:                        for (int i = 0; i < pContexte.getFicType().length; i++) {
1373:                            if (pContexte.getFicType()[i].indexOf(".") != -1
1374:                                    && extension
1375:                                            .equals(pContexte.getFicType()[i]
1376:                                                    .substring(pContexte
1377:                                                            .getFicType()[i]
1378:                                                            .lastIndexOf(".")))) {
1379:                                Element text = scriptInitElem
1380:                                        .addElement("Text");
1381:                                if (pContexte.getOutputFormat() == OutFormat.DOCBOOK) {
1382:                                    ajouterScript(
1383:                                            text,
1384:                                            pContexte.getPathAttach()
1385:                                                    + File.separator
1386:                                                    + "Attachements"
1387:                                                    + File.separator
1388:                                                    + "Campagnes"
1389:                                                    + File.separator
1390:                                                    + formater(pCamp
1391:                                                            .getNameFromModel())
1392:                                                    + File.separator
1393:                                                    + formater(exec
1394:                                                            .getNameFromModel())
1395:                                                    + File.separator
1396:                                                    + type
1397:                                                    + File.separator
1398:                                                    + formater(pScript
1399:                                                            .getNameFromModel()));
1400:                                } else {
1401:                                    ajouterTexte(
1402:                                            text,
1403:                                            pContexte.getPathAttach()
1404:                                                    + File.separator
1405:                                                    + "Attachements"
1406:                                                    + File.separator
1407:                                                    + "Campagnes"
1408:                                                    + File.separator
1409:                                                    + formater(pCamp
1410:                                                            .getNameFromModel())
1411:                                                    + File.separator
1412:                                                    + formater(exec
1413:                                                            .getNameFromModel())
1414:                                                    + File.separator
1415:                                                    + type
1416:                                                    + File.separator
1417:                                                    + formater(pScript
1418:                                                            .getNameFromModel()));
1419:                                }
1420:                            }
1421:                        }
1422:                    }
1423:                } catch (Exception e) {
1424:                    Tools.ihmExceptionView(e);
1425:                }
1426:            }
1427:
1428:            void writeExecutions(Element campElem, Campaign pCamp,
1429:                    ArrayList<Test> testOrdonne, int nbTest2, boolean filtre,
1430:                    ArrayList<Execution> selectExecList) throws Exception {
1431:                ArrayList<Execution> execList = pCamp
1432:                        .getExecutionListFromModel();
1433:                if (!execList.isEmpty()
1434:                        || (filtre && !selectExecList.isEmpty())) {
1435:                    Element execsElem = campElem.addElement("ExecCampTests");
1436:                    Iterator<Execution> iter = execList.iterator();
1437:                    while (iter.hasNext()) {
1438:                        Execution exec = (Execution) iter.next();
1439:                        if (!filtre || selectExecList.contains(exec)) {
1440:                            writeExecution(execsElem, pCamp, exec, testOrdonne,
1441:                                    nbTest2, filtre);
1442:                        }
1443:                    }
1444:                }
1445:            }
1446:
1447:            void writeExecution(Element execsElem, Campaign pCamp,
1448:                    Execution exec, ArrayList<Test> testOrdonne, int nbTest2,
1449:                    boolean filtre) throws Exception {
1450:                Element execElem = execsElem.addElement("ExecCampTest");
1451:                execElem.addElement("Nom").setText(exec.getNameFromModel());
1452:                Element nbGraph = execElem.addElement("NbGraph");
1453:                nbGraph.setText(new Integer((nbTest2 - 1) / 13).toString());
1454:                execElem.addAttribute("id_exec_camp", "ExecCamp_"
1455:                        + new Integer(exec.getIdBdd()).toString());
1456:                if (exec.getDescriptionFromModel() != null
1457:                        && !exec.getDescriptionFromModel().equals("")) {
1458:                    execElem.addElement("Description").setText(
1459:                            exec.getDescriptionFromModel().replaceAll("\n",
1460:                                    "\\\\n"));
1461:                }
1462:                Element envRefElem = execElem.addElement("EnvironnementEx");
1463:                envRefElem.addAttribute("ref",
1464:                        "Env_"
1465:                                + new Integer(exec.getEnvironmentFromModel()
1466:                                        .getIdBdd()).toString());
1467:                envRefElem.addElement("Nom").setText(
1468:                        exec.getEnvironmentFromModel().getNameFromModel());
1469:                if (exec.getDataSetFromModel() != null
1470:                        && (exec.getDataSetFromModel().getIdBdd() != -1)) {
1471:                    Element refJeu = execElem.addElement("JeuDonneesEx");
1472:                    refJeu.addAttribute("ref",
1473:                            "Jeu_"
1474:                                    + new Integer(exec.getDataSetFromModel()
1475:                                            .getIdBdd()).toString());
1476:                    refJeu.addElement("Nom").setText(
1477:                            exec.getDataSetFromModel().getNameFromModel());
1478:                }
1479:                if (exec.getPreScriptFromModel() != null) {
1480:                    writePreScript(execElem, pCamp, exec);
1481:                }
1482:                if (exec.getPostScriptFromModel() != null) {
1483:                    writePostScript(execElem, pCamp, exec);
1484:                }
1485:
1486:                HashMap<String, Attachment> attachExec = exec
1487:                        .getAttachmentMapFromModel();
1488:                addAttach(execElem, pContexte.getPathAttach() + File.separator
1489:                        + "Attachements" + File.separator + "Campagnes"
1490:                        + File.separator + pCamp.getIdBdd() + File.separator
1491:                        + exec.getIdBdd(), attachExec, "Attachements"
1492:                        + File.separator + "Campagnes" + File.separator
1493:                        + pCamp.getIdBdd() + File.separator + exec.getIdBdd());
1494:
1495:                /***** Plugin add XML for Execution *****/
1496:                int size = listXMLPlugin.size();
1497:                for (int i = 0; i < size; i++) {
1498:                    XMLPrinterPlugin pXMLPrinterPlugin = (XMLPrinterPlugin) listXMLPlugin
1499:                            .elementAt(i);
1500:                    pXMLPrinterPlugin.addXMLElement2Execution(execElem, exec,
1501:                            this , pContexte.getPathAttach());
1502:                }
1503:                /***** (END) Plugin add XML for Execution *****/
1504:
1505:                writeExecResults(execElem, pCamp, exec, testOrdonne);
1506:            }
1507:
1508:            void writeCampTest(Element campsElem, Campaign pCamp, int nbTest2,
1509:                    boolean filtre, ArrayList<Execution> selectExecList)
1510:                    throws Exception {
1511:                Element campElem = campsElem.addElement("CampagneTest");
1512:                campElem.addAttribute("id_camp", "Camp_"
1513:                        + new Integer(pCamp.getIdBdd()).toString());
1514:                Element conceptor = campElem.addElement("Concepteur");
1515:                if (pCamp.getConceptorFroModel() != null
1516:                        && !pCamp.getConceptorFroModel().equals("")) {
1517:                    conceptor.addElement("Nom").setText(
1518:                            pCamp.getConceptorFroModel());
1519:                }
1520:                campElem.addElement("Nom").setText(pCamp.getNameFromModel());
1521:                String date_camp = DateFormat.getDateInstance(
1522:                        DateFormat.MEDIUM, Locale.FRANCE).format(
1523:                        pCamp.getDateFromModel());
1524:                campElem.addElement("Date_crea").setText(date_camp);
1525:                if (!pCamp.getDescriptionFromModel().equals("")) {
1526:                    addHTMLDescription(campElem, pCamp
1527:                            .getDescriptionFromModel());
1528:                }
1529:                HashMap<String, Attachment> attachs = pCamp
1530:                        .getAttachmentMapFromModel();
1531:                addAttach(campElem, pContexte.getPathAttach() + File.separator
1532:                        + "Attachements" + File.separator + "Campagnes"
1533:                        + File.separator + pCamp.getIdBdd(), attachs,
1534:                        "Attachements" + File.separator + "Campagnes"
1535:                                + File.separator + pCamp.getIdBdd());
1536:
1537:                /***** Plugin add XML for Campaing *****/
1538:                int size = listXMLPlugin.size();
1539:                for (int i = 0; i < size; i++) {
1540:                    XMLPrinterPlugin pXMLPrinterPlugin = (XMLPrinterPlugin) listXMLPlugin
1541:                            .elementAt(i);
1542:                    pXMLPrinterPlugin.addXMLElement2Campaign(campElem, pCamp,
1543:                            this , pContexte.getPathAttach());
1544:                }
1545:                /***** (END) Plugin add XML for Execution *****/
1546:
1547:                /*** DataSet ***/
1548:                writeDataSet(campElem, pCamp);
1549:
1550:                /*** Test in Campaign ***/
1551:                ArrayList<Test> testOrdonne = writeTestInCamp(campElem, pCamp);
1552:
1553:                /*** Execution in Campaign ***/
1554:                writeExecutions(campElem, pCamp, testOrdonne, nbTest2, filtre,
1555:                        selectExecList);
1556:
1557:            }
1558:
1559:            /**
1560:             * Méthode de création du document xml contenant la description
1561:             * de la partie statique du projet Salomé courant
1562:             * @param pathAttach répertoire pour la sauvegarde des attachements
1563:             * @param selectFamilyList liste des familles de tests sélectionnées pour figurer dans le rapport
1564:             * @param selectSuiteList liste des suites de tests sélectionnées pour figurer dans le rapport
1565:             * @param selectTestList liste des tests sélectionnés pour figurer dans le rapport
1566:             * @param ficType liste des types de fichier à insérer dans le document
1567:             */
1568:            public Document toDocument(ArrayList<Family> selectFamilyList,
1569:                    ArrayList<TestList> selectSuiteList,
1570:                    ArrayList<Test> selectTestList) throws Exception {
1571:                boolean filtre = (selectFamilyList != null
1572:                        || selectSuiteList != null || selectTestList != null);
1573:
1574:                if (!filtre) {
1575:                    selectFamilyList = new ArrayList<Family>();
1576:                    selectSuiteList = new ArrayList<TestList>();
1577:                    selectTestList = new ArrayList<Test>();
1578:                }
1579:                Document document = DocumentHelper.createDocument();
1580:                if (addDocType) {
1581:                    File fileSalomeStatique = new File(pContexte
1582:                            .getPathAttach()
1583:                            + File.separator + "SalomeStatique.dtd");
1584:                    try {
1585:                        document.addDocType("SalomeStatique", null,
1586:                                fileSalomeStatique.toURL().toString());
1587:                    } catch (Exception e) {
1588:                        e.printStackTrace();
1589:                        document.addDocType("SalomeStatique", null, pContexte
1590:                                .getPathAttach()
1591:                                + File.separator + "SalomeStatique.dtd");
1592:                    }
1593:                }
1594:                Element salomeStatique = document.addElement("SalomeStatique");
1595:                Element projetVT = salomeStatique.addElement("ProjetVT");
1596:
1597:                /***** USER/GROUP ******/
1598:                writeBaseProjet(projetVT);
1599:
1600:                /***** ENVIRONNEMENT ******/
1601:                writeEnvironnement(projetVT);
1602:
1603:                /***** FAMILY/SUITE/TEST ******/
1604:                writeFamily(projetVT, filtre, selectFamilyList,
1605:                        selectSuiteList, selectTestList);
1606:
1607:                return document;
1608:            }
1609:
1610:            /**
1611:             * Méthode qui ajoute dans le document résultant le texte contenu
1612:             * dans le fichier dont le chemin est indiqué en paramètre
1613:             * @param text élément auquel on rajoute lengthcontenu du fichier
1614:             * @param path chemin du fichier dont le contenu doit être ajouté au document
1615:             */
1616:            public void ajouterTexte(Element text, String path)
1617:                    throws Exception {
1618:                File fichier = new File(path);
1619:                FileReader fluxFichier = null;
1620:                try {
1621:                    fluxFichier = new FileReader(fichier);
1622:                    BufferedReader tamponLecture = new BufferedReader(
1623:                            fluxFichier);
1624:                    String ligne;
1625:                    while ((ligne = tamponLecture.readLine()) != null) {
1626:                        text.addElement("ligne").setText(ligne);
1627:                    }
1628:                    tamponLecture.close();
1629:                    fluxFichier.close();
1630:                } catch (Exception e) {
1631:                    Tools.ihmExceptionView(e);
1632:                }
1633:            }
1634:
1635:            void ajouterInfoExecToTest(Test pTest, Element testElem)
1636:                    throws Exception {
1637:                boolean executed = false;
1638:                ArrayList<Campaign> campaignList = DataModel
1639:                        .getCurrentProject().getCampaignOfTest(pTest);
1640:                if (campaignList != null && campaignList.size() > 0) {
1641:                    int i = 0;
1642:                    int size = campaignList.size();
1643:                    SalomeTMFPanels.getAutomaticButtonCampaignDetails()
1644:                            .setEnabled(true);
1645:                    while (i < size && !executed) {
1646:                        Campaign pCampaign = campaignList.get(i);
1647:                        if (pCampaign.containsExecutionResultInModel()) {
1648:                            executed = true;
1649:                        }
1650:                        i++;
1651:                    }
1652:                }
1653:                testElem.addElement("Executed").setText("" + executed);
1654:            }
1655:
1656:            /**
1657:             * Méthode de création du document xml contenant la description
1658:             * de la partie dynamique du projet Salomé courant
1659:             * @param pathAttach répertoire pour la sauvegarde des attachements
1660:             * @param selectCampList liste des campagnes de tests sélectionnées pour figurer dans le rapport
1661:             * @param selectExecList liste des exécutions sélectionnées pour figurer dans le rapport
1662:             * @param ficType liste des types de fichier à insérer dans le document
1663:             * @param tab tab[3] -> inclusion des exécutions ; tab[4] -> inclusion des résultats d'exécutions
1664:             */
1665:            public Document toDocumentDyna(ArrayList<Campaign> selectCampList,
1666:                    ArrayList<Execution> selectExecList) throws Exception {
1667:                Document doc = toDocument(null, null, null);
1668:                boolean filtre = (selectCampList != null || selectExecList != null);
1669:                if (!filtre) {
1670:                    selectCampList = new ArrayList<Campaign>();
1671:                    selectExecList = new ArrayList<Execution>();
1672:                }
1673:                int nbTest2 = 0;
1674:                if (addDocType) {
1675:                    File fileSalomeStatique = new File(pContexte
1676:                            .getPathAttach()
1677:                            + File.separator + "SalomeDynamique.dtd");
1678:                    try {
1679:                        doc.addDocType("SalomeStatique", null,
1680:                                fileSalomeStatique.toURL().toString());
1681:                    } catch (Exception e) {
1682:                        doc.addDocType("SalomeStatique", null, pContexte
1683:                                .getPathAttach()
1684:                                + File.separator + "SalomeStatique.dtd");
1685:                    }
1686:                }
1687:                Element root = doc.getRootElement();
1688:                root.setName("SalomeDynamique");
1689:
1690:                ArrayList<Campaign> campList = DataModel.getCurrentProject()
1691:                        .getCampaignListFromModel();
1692:                if (!campList.isEmpty()
1693:                        || (filtre && !selectCampList.isEmpty())) {
1694:                    Element nodeProj = (Element) doc
1695:                            .selectSingleNode("//ProjetVT");
1696:
1697:                    Element campsElem = nodeProj.addElement("CampagneTests");
1698:                    Iterator<Campaign> it = campList.iterator();
1699:                    while (it.hasNext()) {
1700:                        nbTest2 = 0;
1701:                        Campaign camp = it.next();
1702:                        if (!filtre || selectCampList.contains(camp)) {
1703:                            ArrayList<Test> tList2 = camp
1704:                                    .getTestListFromModel();
1705:                            if (!tList2.isEmpty()) {
1706:                                Iterator<Test> itList2 = tList2.iterator();
1707:                                while (itList2.hasNext()) {
1708:                                    itList2.next();
1709:                                    nbTest2 = nbTest2 + 1;
1710:                                }
1711:                            }
1712:                            writeCampTest(campsElem, camp, nbTest2, filtre,
1713:                                    selectExecList);
1714:                        }
1715:                    }
1716:                }
1717:                return doc;
1718:            }
1719:
1720:            /**
1721:             * Méthode qui ajoute les attachements à l'élément elem passé en paramètre,
1722:             * copie le fichier d'attachement à l'emplacement spécifié par le paramètre path
1723:             * et suivant le tableau ficType inclut le contenu des fichiers dans le document xml
1724:             * @param elem élément auquel sont ajoutés les attachements
1725:             * @param path chemin où sont sauvegardé les attachements
1726:             * @param attachs HashMap qui contient les attachements
1727:             * @param relativePath chemin relatif
1728:             * @param ficType indiquant les extensions des fichiers à inclure dans le document
1729:             */
1730:            public void addAttach(Element elem, String path,
1731:                    HashMap<String, Attachment> attachs, String relativePath)
1732:                    throws Exception {
1733:                if (!attachs.isEmpty()) {
1734:                    File dir = new File(path);
1735:                    if (!dir.exists()) {
1736:                        dir.mkdirs();
1737:                    }
1738:                    Element attachsElem = elem.addElement("Attachements");
1739:                    Iterator<Attachment> ita = attachs.values().iterator();
1740:                    while (ita.hasNext()) {
1741:                        Attachment at = (Attachment) ita.next();
1742:                        if (at instanceof  UrlAttachment) {
1743:                            Element urlElem = attachsElem
1744:                                    .addElement("UrlAttachement");
1745:                            if (at.getDescriptionFromModel() != null
1746:                                    && !at.getDescriptionFromModel().equals("")) {
1747:                                urlElem.addElement("Description").setText(
1748:                                        at.getDescriptionFromModel()
1749:                                                .replaceAll("\n", "\\\\n"));
1750:                            }
1751:                            urlElem.addAttribute("url", at.getNameFromModel());
1752:                        } else {
1753:                            FileAttachment fa = (FileAttachment) at;
1754:                            Element fileElem = attachsElem
1755:                                    .addElement("FileAttachement");
1756:                            if (fa.getDate() != null) {
1757:                                //à modifier pour formater la date
1758:                                fileElem.addElement("Date").setText(
1759:                                        fa.getDate().toString());
1760:                            }
1761:                            if (fa.getDescriptionFromModel() != null
1762:                                    && !fa.getDescriptionFromModel().equals("")) {
1763:                                fileElem.addElement("Description").setText(
1764:                                        fa.getDescriptionFromModel()
1765:                                                .replaceAll("\n", "\\\\n"));
1766:                            }
1767:                            fileElem.addAttribute("nom", at.getNameFromModel());
1768:                            String relativePathURI = relativePath;
1769:                            if (File.separator.equals("\\")) {
1770:                                relativePathURI = relativePath.replaceAll(
1771:                                        "\\\\", "/");
1772:                            }
1773:                            String destElem = new String(relativePathURI + "/"
1774:                                    + formater(at.getNameFromModel()));
1775:                            fileElem.addAttribute("dir", destElem);
1776:                            String dest = new String(path + File.separator
1777:                                    + formater(at.getNameFromModel()));
1778:                            dest = dest.substring(0, dest
1779:                                    .lastIndexOf(File.separator));
1780:                            try {
1781:                                ((FileAttachment) at).getFileFromDB(dest);
1782:
1783:                                String extension = null;
1784:                                try {
1785:                                    extension = at.getNameFromModel()
1786:                                            .substring(
1787:                                                    at.getNameFromModel()
1788:                                                            .lastIndexOf("."));
1789:                                } catch (Exception ex) {
1790:
1791:                                }
1792:                                if (pContexte.getFicType() != null
1793:                                        && extension != null) {
1794:                                    for (int i = 0; i < pContexte.getFicType().length; i++) {
1795:                                        if (pContexte.getFicType()[i]
1796:                                                .indexOf(".") != -1
1797:                                                && extension
1798:                                                        .equals(pContexte
1799:                                                                .getFicType()[i]
1800:                                                                .substring(pContexte
1801:                                                                        .getFicType()[i]
1802:                                                                        .lastIndexOf(".")))) {
1803:                                            Element text = fileElem
1804:                                                    .addElement("Text");
1805:                                            ajouterTexte(
1806:                                                    text,
1807:                                                    path
1808:                                                            + File.separator
1809:                                                            + formater(at
1810:                                                                    .getNameFromModel()));
1811:                                        }
1812:                                    }
1813:                                }
1814:                            } catch (Exception e) {
1815:                                Tools.ihmExceptionView(e);
1816:                            }
1817:                        }
1818:                    }
1819:                }
1820:            }
1821:
1822:            /**
1823:             * Méthode pour écrire le document dom4j dans un fichier
1824:             * @param doc le document dom4j
1825:             * @param path chemin et nom du fichier à créer
1826:             */
1827:            public void documentToXML(Document doc, String path)
1828:                    throws Exception {
1829:                FileOutputStream fileOutputStream = new FileOutputStream(
1830:                        new File(path));
1831:                OutputFormat format = OutputFormat.createPrettyPrint();
1832:                format.setEncoding(pContexte.getCoding());
1833:                XMLWriter writer = new XMLWriter(fileOutputStream, format);
1834:                writer.write(doc);
1835:                writer.close();
1836:            }
1837:
1838:            /**
1839:             * Méthode pour le formatage des noms de fichiers
1840:             *
1841:             */
1842:            public String formater(String s) throws Exception {
1843:                s = s.replace('/', '_');
1844:                s = s.replace('\\', '_');
1845:                s = s.replace(':', '_');
1846:                s = s.replace('*', '_');
1847:                s = s.replace('?', '_');
1848:                s = s.replace('\"', '_');
1849:                s = s.replace('<', '_');
1850:                s = s.replace('>', '_');
1851:                s = s.replace('|', '_');
1852:                return s;
1853:            }
1854:
1855:            public Vector<XMLPrinterPlugin> getListXMLPlugin() {
1856:                return listXMLPlugin;
1857:            }
1858:
1859:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.