Source Code Cross Referenced for DocumentParser.java in  » Workflow-Engines » bonita-v3.1 » mc » formgenerator » bonita » 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 » Workflow Engines » bonita v3.1 » mc.formgenerator.bonita 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Created on 28 avr. 2004
003:         *
004:         * To change the template for this generated file go to
005:         * Window>Preferences>Java>Code Generation>Code and Comments
006:         */
007:        package mc.formgenerator.bonita;
008:
009:        import java.io.StringWriter;
010:        import java.util.ArrayList;
011:        import java.util.HashMap;
012:        import java.util.Iterator;
013:        import java.util.Set;
014:        import java.util.StringTokenizer;
015:        import java.util.Vector;
016:
017:        import mc.formgenerator.servlets.util.FormGeneratorConstant;
018:        import org.apache.xerces.dom.DOMImplementationImpl;
019:        import org.apache.xml.serialize.DOMSerializer;
020:        import org.apache.xml.serialize.OutputFormat;
021:        import org.apache.xml.serialize.XMLSerializer;
022:        import org.w3c.dom.DOMImplementation;
023:        import org.w3c.dom.Document;
024:        import org.w3c.dom.Element;
025:        import org.w3c.dom.NodeList;
026:        import org.w3c.dom.Text;
027:
028:        /**
029:         * Class that offers methods to transform XML Document to DataProject/DataActivity
030:         * et vice versa
031:         *
032:         */
033:        public class DocumentParser {
034:
035:            /**
036:             * Default class constructor.
037:             */
038:            public DocumentParser() {
039:
040:            }
041:
042:            /**
043:             * Say if the document has properties about the process.
044:             * @param doc Document which owns the process information.
045:             * @return boolean
046:             */
047:            public boolean hasProperties(Document doc, Boolean isActivity) {
048:
049:                //Root is the first tag of the document. Its name is "project"
050:                Element root = doc.getDocumentElement();
051:
052:                NodeList elementProperty = null;
053:                NodeList elementPropertyProcForAct = null;
054:                int nAct = 0;
055:                int nActProc = 0;
056:                int nProc = 0;
057:                int n = 0;
058:
059:                if (isActivity.booleanValue()) {
060:                    // Activity
061:                    // property of activity
062:                    elementProperty = root
063:                            .getElementsByTagName("activityProperties");
064:                    Element EleAct = (Element) elementProperty.item(0);
065:                    nAct = EleAct.getElementsByTagName("*").getLength();
066:                    // property of process
067:                    elementPropertyProcForAct = root
068:                            .getElementsByTagName("properties");
069:                    Element EleActProc = (Element) elementPropertyProcForAct
070:                            .item(0);
071:                    nActProc = EleActProc.getElementsByTagName("*").getLength();
072:                    n = nAct + nActProc;
073:
074:                } else {
075:                    elementProperty = root.getElementsByTagName("properties");
076:                    Element propertyElement = (Element) elementProperty.item(0);
077:                    n = propertyElement.getElementsByTagName("*").getLength();
078:                }
079:
080:                return (n != 0);
081:
082:            }
083:
084:            /**
085:             * Creates a DataProject structure thanks to the Document information.
086:             * @param doc Document which represents the project.
087:             * @return dataProject Structure which represents the project.
088:             */
089:            public DataProject parseProject(Document doc,
090:                    Vector req_parameters, boolean formsExists) {
091:
092:                //the structure to return
093:                DataProject dataProject = new DataProject();
094:
095:                //new information will be saved in these variables
096:                String newName;
097:
098:                HashMap newTable = new HashMap();
099:
100:                //Root is the first tag of the document. Its name is "project"
101:                Element root = doc.getDocumentElement();
102:
103:                //**************************************************************************
104:                //				GET THE PROCESS NAME FROM THE DOCUMENT
105:                //**************************************************************************
106:
107:                //Save the process name
108:                NodeList elementName = root.getElementsByTagName("name");
109:
110:                if (elementName.getLength() == 0) {
111:
112:                    //default process name
113:                    newName = "defaultProject";
114:                } else {
115:                    Text nameProcess = (Text) elementName.item(0)
116:                            .getFirstChild();
117:
118:                    newName = nameProcess.getNodeValue();
119:                }
120:
121:                //**************************************************************************
122:                //				GET THE PROCESS PROPERTIES FROM THE DOCUMENT
123:                //**************************************************************************
124:
125:                //List of nodes named properties
126:                NodeList elementProperty = root
127:                        .getElementsByTagName("properties");
128:                if (elementProperty.getLength() == 0) {
129:                } else {
130:
131:                    //Is unique, it's the first
132:                    Element propertyElement = (Element) elementProperty.item(0);
133:
134:                    //List of child nodes of element "properties" : the key-value
135:                    //NodeList elementsKeyValue = propertyElement.getElementsByTagName("*");
136:                    NodeList elementsProperty = propertyElement
137:                            .getElementsByTagName("property");
138:                    int size = elementsProperty.getLength();
139:
140:                    //Save name-value if they exist
141:                    if (size > 0) {
142:
143:                        for (int i = 0; i < size; i++) {
144:                            // new xml Format
145:                            Element propertyElementNameValue = (Element) elementsProperty
146:                                    .item(i);
147:
148:                            NodeList elementsPropertyNameValue = propertyElementNameValue
149:                                    .getElementsByTagName("*");
150:                            //Element propertyElementValue = (Element)elementsPropertyNameValue.item(0);
151:                            //Text valueElement = (Text)elementsPropertyNameValue.item(0).getFirstChild();
152:                            //String currentKey = valueElement.getNodeValue();
153:                            String currentKey = propertyElementNameValue
154:                                    .getAttribute("id");
155:                            String currentValue = "";
156:                            if ((Text) elementsPropertyNameValue.item(1)
157:                                    .getFirstChild() != null) {
158:                                //valueElement = (Text)elementsPropertyNameValue.item(1).getFirstChild();
159:                                Text valueElement = (Text) elementsPropertyNameValue
160:                                        .item(0).getFirstChild();
161:                                //#306244 if the workkflow property has no value then no text child is put in the value node within instance doc
162:                                if (valueElement != null) {
163:                                    currentValue = valueElement.getNodeValue();
164:                                }
165:                            }
166:                            //old cml format
167:                            //current node which gives the value
168:                            //Text valueElement = (Text)elementsKeyValue.item(i).getFirstChild();
169:
170:                            //Takes the current node information
171:                            //String currentValue = valueElement.getNodeValue();
172:                            //String currentKey = elementsKeyValue.item(i).getNodeName();
173:
174:                            //Puts them in the HashMap
175:                            newTable.put(currentKey, currentValue);
176:                        }
177:
178:                    }
179:                }
180:                if (formsExists && (req_parameters != null)) {
181:                    //remove from projectTable properties not into req_parameters beacause of hidden or readonly constraints
182:                    Object[] tabProjectProp = newTable.keySet().toArray();
183:                    for (int k = 0; k < tabProjectProp.length; k++) {
184:                        if (!req_parameters.contains(tabProjectProp[k]
185:                                .toString())) {
186:                            newTable.remove(tabProjectProp[k]);
187:                        }
188:                    }
189:                }
190:                //**************************************************************************
191:                //				SET DATAPROJECT ATTRIBUTES
192:                //**************************************************************************
193:
194:                dataProject.setProjectName(newName);
195:                dataProject.setProjectProperties(newTable);
196:
197:                return dataProject;
198:            }
199:
200:            /**
201:             * Creates a DataActivity structure thanks to the Document information.
202:             * @param doc Document which represents the activity.
203:             * @return dataProject Structure which represents the activity.
204:             */
205:            public DataActivity parseActivity(Document doc,
206:                    Vector req_parameters, boolean formsExists) {
207:
208:                //the structure to return
209:                DataActivity dataActivity = new DataActivity();
210:
211:                //PROJECT INFO
212:
213:                //new information will be saved in these variables
214:                String newProjectName;
215:
216:                HashMap projectTable = new HashMap();
217:                HashMap activityTable = new HashMap();
218:
219:                //Root is the first tag of the document. Its name is "project"
220:                Element root = doc.getDocumentElement();
221:
222:                //**************************************************************************
223:                //				GET THE PROCESS NAME FROM THE DOCUMENT
224:                //**************************************************************************
225:
226:                //Save the process name
227:                NodeList projectElementName = root.getElementsByTagName("name");
228:
229:                if (projectElementName.getLength() == 0) {
230:
231:                    //default process name
232:                    newProjectName = "defaultProject";
233:                } else {
234:                    Text nameProcess = (Text) projectElementName.item(0)
235:                            .getFirstChild();
236:
237:                    newProjectName = nameProcess.getNodeValue();
238:                }
239:
240:                //**************************************************************************
241:                //				GET THE PROCESS PROPERTIES FROM THE DOCUMENT
242:                //**************************************************************************
243:
244:                //List of nodes named properties
245:                NodeList projectElementProperty = root
246:                        .getElementsByTagName("properties");
247:                if (projectElementProperty.getLength() == 0) {
248:                } else {
249:
250:                    //Is unique, it's the first
251:                    Element propertyElement = (Element) projectElementProperty
252:                            .item(0);
253:
254:                    //List of child nodes of element "properties" : the key-value
255:                    //NodeList elementsKeyValue = propertyElement.getElementsByTagName("*");
256:                    NodeList elementsProperty = propertyElement
257:                            .getElementsByTagName("property");
258:                    int size = elementsProperty.getLength();
259:
260:                    //Save name-value if they exist
261:                    if (size > 0) {
262:
263:                        for (int i = 0; i < size; i++) {
264:                            // new xml Format
265:                            Element propertyElementNameValue = (Element) elementsProperty
266:                                    .item(i);
267:
268:                            NodeList elementsPropertyNameValue = propertyElementNameValue
269:                                    .getElementsByTagName("*");
270:                            //Element propertyElementValue = (Element)elementsPropertyNameValue.item(0);
271:                            //Text valueElement = (Text)elementsPropertyNameValue.item(0).getFirstChild();
272:                            //String currentKey = valueElement.getNodeValue();
273:                            String currentKey = propertyElementNameValue
274:                                    .getAttribute("id");
275:                            String currentValue = "";
276:                            if ((Text) elementsPropertyNameValue.item(1)
277:                                    .getFirstChild() != null) {
278:                                Text valueElement = (Text) elementsPropertyNameValue
279:                                        .item(0).getFirstChild();
280:                                //#306244
281:                                if (valueElement != null) {
282:                                    currentValue = valueElement.getNodeValue();
283:                                }
284:                            }
285:                            //old cml format
286:                            //current node which gives the value
287:                            //Text valueElement = (Text)elementsKeyValue.item(i).getFirstChild();
288:
289:                            //Takes the current node information
290:                            //String currentValue = valueElement.getNodeValue();
291:                            //String currentKey = elementsKeyValue.item(i).getNodeName();
292:
293:                            //Puts them in the HashMap
294:                            projectTable.put(currentKey, currentValue);
295:                        }
296:
297:                    }
298:                }
299:
300:                //remove from projectTable properties not into req_parameters beacause of hidden or readonly constraints
301:                if (formsExists && (req_parameters != null)) {
302:                    Object[] tabProjectProp = projectTable.keySet().toArray();
303:                    for (int k = 0; k < tabProjectProp.length; k++) {
304:                        if (!req_parameters.contains(tabProjectProp[k]
305:                                .toString())) {
306:                            projectTable.remove(tabProjectProp[k]);
307:                        }
308:                    }
309:                }
310:
311:                //**************************************************************************
312:                //				SET DATA PROJECT ATTRIBUTES
313:                //**************************************************************************
314:
315:                dataActivity.setProjectName(newProjectName);
316:                dataActivity.setProjectProperties(projectTable);
317:
318:                //END PROJECT INFO
319:
320:                //ACTIVITY INFO
321:
322:                String activityName = "";
323:
324:                //**************************************************************************
325:                //				GET THE Activity NAME FROM THE DOCUMENT
326:                //**************************************************************************
327:
328:                //Save the process name
329:                NodeList activityElementName = root
330:                        .getElementsByTagName("activityName");
331:
332:                if (activityElementName.getLength() == 0) {
333:
334:                    //default activity name
335:                    activityName = "defaultActivity";
336:                } else {
337:                    Text nameProcess = (Text) activityElementName.item(0)
338:                            .getFirstChild();
339:                    activityName = nameProcess.getNodeValue();
340:                }
341:
342:                //**************************************************************************
343:                //				GET THE ACTIVITY PROPERTIES FROM THE DOCUMENT
344:                //**************************************************************************
345:
346:                //List of nodes named properties
347:                NodeList activityElementProperty = root
348:                        .getElementsByTagName("activityProperties");
349:                if (activityElementProperty.getLength() == 0) {
350:                } else {
351:
352:                    //Is unique, it's the first
353:                    Element propertyElement = (Element) activityElementProperty
354:                            .item(0);
355:
356:                    //List of child nodes of element "properties" : the key-value
357:                    //NodeList elementsKeyValue = propertyElement.getElementsByTagName("*");
358:                    NodeList elementsProperty = propertyElement
359:                            .getElementsByTagName("property");
360:                    int size = elementsProperty.getLength();
361:
362:                    //Save name-value if they exist
363:                    if (size > 0) {
364:
365:                        for (int i = 0; i < size; i++) {
366:                            // new xml Format
367:                            Element propertyElementNameValue = (Element) elementsProperty
368:                                    .item(i);
369:
370:                            NodeList elementsPropertyNameValue = propertyElementNameValue
371:                                    .getElementsByTagName("*");
372:                            //Element propertyElementValue = (Element)elementsPropertyNameValue.item(0);
373:                            //Text valueElement = (Text)elementsPropertyNameValue.item(0).getFirstChild();
374:                            //String currentKey = valueElement.getNodeValue();
375:                            String currentKey = propertyElementNameValue
376:                                    .getAttribute("id");
377:                            String currentValue = "";
378:                            if ((Text) elementsPropertyNameValue.item(1)
379:                                    .getFirstChild() != null) {
380:                                //valueElement = (Text)elementsPropertyNameValue.item(1).getFirstChild();
381:                                Text valueElement = (Text) elementsPropertyNameValue
382:                                        .item(0).getFirstChild();
383:                                //patch for #306244
384:                                if (valueElement != null) {
385:                                    currentValue = valueElement.getNodeValue();
386:                                }
387:                            }
388:                            //old cml format
389:                            //current node which gives the value
390:                            //Text valueElement = (Text)elementsKeyValue.item(i).getFirstChild();
391:
392:                            //Takes the current node information
393:                            //String currentValue = valueElement.getNodeValue();
394:                            //String currentKey = elementsKeyValue.item(i).getNodeName();
395:
396:                            //Puts them in the HashMap
397:                            activityTable.put(currentKey, currentValue);
398:                        }
399:
400:                    }
401:                }
402:                if (formsExists && (req_parameters != null)) {
403:                    //remove from projectTable properties not into req_parameters beacause of hidden or readonly constraints
404:                    Object[] tab_activity_prop = activityTable.keySet()
405:                            .toArray();
406:                    for (int k = 0; k < tab_activity_prop.length; k++) {
407:                        if (!req_parameters.contains(tab_activity_prop[k]
408:                                .toString())) {
409:                            activityTable.remove(tab_activity_prop[k]);
410:                        }
411:                    }
412:                }
413:
414:                //**************************************************************************
415:                //				SET DATA ACTIVITY ATTRIBUTES
416:                //**************************************************************************
417:
418:                dataActivity.setActivityName(activityName);
419:                dataActivity.setActivityProperties(activityTable);
420:
421:                return dataActivity;
422:            }
423:
424:            /**
425:             * Creation of a xml document by using Xerces
426:             * @param data The data to put in the Document.
427:             * @return Document contains process information given by the DataProcess.
428:             */
429:            public Document createDocument(DataProject data,
430:                    ArrayList projectKeys) {
431:
432:                //Out Document for manipulation by Xerces API
433:                Document document = null;
434:
435:                //Set for all the hmap keys
436:                //Set keySet = null;
437:
438:                //Interface
439:                DOMImplementation domImpl = new DOMImplementationImpl();
440:
441:                //Document creation with the root element called project
442:                document = domImpl.createDocument(null, "process", null);
443:
444:                //Setting the root element always called "project"
445:                Element root = document.getDocumentElement();
446:
447:                //Name of the Bonita project***************************************
448:                Element elementName = document.createElement("name");
449:
450:                //Value of the node called "name"
451:                Text textName = document.createTextNode(data.getProjectName());
452:                elementName.appendChild(textName);
453:                root.appendChild(elementName);
454:                //*****************************************************************
455:
456:                //Node "properties" that will contain project properties************
457:                Element elementProperties = document
458:                        .createElement("properties");
459:                //******************************************************************
460:
461:                //Getting keys set
462:                //keySet = data.getProjectProperties().keySet();
463:
464:                //Current key
465:                String currentKey = "";
466:
467:                //Current value
468:                String currentValue = "";
469:
470:                //For each key we must get the value associeted
471:                //Iterator it = keySet.iterator();
472:                Iterator it = projectKeys.iterator();
473:                while (it.hasNext()) {
474:                    //New format : <properties><property><name>key</name><type></type><value>value></value>
475:                    //<possible-values><possible></possible></possible-values><property></properties>
476:                    Element elementProperty = document
477:                            .createElement("property");
478:
479:                    //Getting the key
480:                    currentKey = (String) it.next();
481:
482:                    //Getting the value
483:                    currentValue = (String) data.getProjectProperties().get(
484:                            currentKey);
485:
486:                    //old format : <properties><key>value</key><key>value</key></properties>
487:                    //Element elementKey = document.createElement(currentKey);
488:                    //Text textKey = document.createTextNode(currentValue);
489:
490:                    //Element elementPropertyName = document.createElement("name");
491:                    //Text textPropertyName = document.createTextNode(currentKey);
492:                    //elementPropertyName.appendChild(textPropertyName);
493:                    //Adding this element to the "property" element
494:                    //elementProperty.appendChild(elementPropertyName);
495:                    elementProperty.setAttribute("id", currentKey);
496:
497:                    // We test if there is a multiple possible values
498:                    // value1|value2|value3 ...
499:                    StringTokenizer st = new StringTokenizer(currentValue, "|");
500:                    Element elementPropertyValue = null;
501:                    Element elementPropertyPossible = null;
502:                    Element elementPropertyType = document
503:                            .createElement("type");
504:                    if (st.countTokens() > 1) {
505:
506:                        boolean first = true;
507:                        Element elementPropertyPossibleValues = document
508:                                .createElement("possible-values");
509:                        while (st.hasMoreTokens()) {
510:                            String value = st.nextToken();
511:                            if (first) {
512:                                //patch for #302738: enumerated with multi selection can be validated with an empty value
513:                                if (" ".equals(value)) {
514:                                    //System.out.println("$$$$$$$$$$$$  ******** DocumentParser:createDocument for Project - (first) value = **" + value + "**");
515:                                    value = "";
516:                                }
517:                                elementPropertyValue = document
518:                                        .createElement("value");
519:                                Text textPropertyValue = document
520:                                        .createTextNode(value);
521:                                elementPropertyValue
522:                                        .appendChild(textPropertyValue);
523:                                elementProperty
524:                                        .appendChild(elementPropertyValue);
525:
526:                                Text textPropertyType = document
527:                                        .createTextNode("select");
528:                                elementPropertyType
529:                                        .appendChild(textPropertyType);
530:                                elementProperty
531:                                        .appendChild(elementPropertyType);
532:                                first = false;
533:                            } else {
534:                                elementPropertyPossible = document
535:                                        .createElement("possible");
536:                                Text textPropertyPossible = document
537:                                        .createTextNode(value);
538:                                elementPropertyPossible
539:                                        .appendChild(textPropertyPossible);
540:                                elementPropertyPossibleValues
541:                                        .appendChild(elementPropertyPossible);
542:                            }
543:                        }
544:
545:                        elementProperty
546:                                .appendChild(elementPropertyPossibleValues);
547:                    } else {
548:                        elementPropertyValue = document.createElement("value");
549:                        //patch for #306244: put no text node if the value = empty string and insert the attribut xsi:nil="true" into the value node
550:                        if (!"".equals(currentValue)) {
551:                            Text textPropertyValue = document
552:                                    .createTextNode(currentValue);
553:                            elementPropertyValue.appendChild(textPropertyValue);
554:                        } else {
555:                            elementPropertyValue
556:                                    .setAttributeNS(
557:                                            "http://www.w3.org/2001/XMLSchema-instance",
558:                                            "nil", "true");
559:                        }
560:                        elementProperty.appendChild(elementPropertyValue);
561:
562:                        Text textPropertyType = document
563:                                .createTextNode("input");
564:                        elementPropertyType.appendChild(textPropertyType);
565:                        elementProperty.appendChild(elementPropertyType);
566:                    }
567:                    //Adding this element to the "properties" element
568:                    elementProperties.appendChild(elementProperty);
569:                }
570:
571:                //Adding the node to the root element
572:                root.appendChild(elementProperties);
573:
574:                //debug
575:                //System.out.println("$$$$$$$$$$$$$$$$ xml instance build by BonitaProjectAdapter");
576:                //System.out.println(this.toXmlString(document));
577:                //System.out.println("$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$");
578:
579:                //Return the document
580:                return document;
581:            }
582:
583:            /**
584:             * Creation of a xml document by using Xerces
585:             * @param data The data to put in the Document.
586:             * @return Document contains process information given by the DataProcess.
587:             */
588:            public Document createDocument(DataActivity data,
589:                    ArrayList projectKeys, ArrayList activityKeys) {
590:
591:                //Out Document for manipulation by Xerces API
592:                Document document = null;
593:
594:                //Set for all the hmap keys
595:                //Set keySet = null;
596:
597:                //Current key
598:                String currentKey = "";
599:
600:                //Current value
601:                String currentValue = "";
602:
603:                //iterator for keys
604:                Iterator it;
605:
606:                //Interface
607:                DOMImplementation domImpl = new DOMImplementationImpl();
608:
609:                //Document creation with the root element called project
610:                document = domImpl.createDocument(null, "process", null);
611:
612:                Element root = document.getDocumentElement();
613:
614:                //PROJECT INFO
615:
616:                //Name of the Bonita project***************************************
617:                Element elementProjectName = document.createElement("name");
618:
619:                //Value of the node called "name"
620:                Text textName = document.createTextNode(data.getProjectName());
621:                elementProjectName.appendChild(textName);
622:                root.appendChild(elementProjectName);
623:                //*****************************************************************
624:
625:                //Node "properties" that will contain project properties************
626:                Element elementProjectProperties = document
627:                        .createElement("properties");
628:                //******************************************************************
629:
630:                //Getting keys set
631:                //keySet = data.getProjectProperties().keySet();
632:
633:                //For each key we must get the value associeted
634:                //it = keySet.iterator();
635:                it = projectKeys.iterator();
636:                while (it.hasNext()) {
637:                    //New format : <properties><property><name>key</name><type></type><value>value></value>
638:                    //<possible-values><possible></possible></possible-values><property></properties>
639:                    Element elementProjectProperty = document
640:                            .createElement("property");
641:
642:                    //Getting the key
643:                    currentKey = (String) it.next();
644:
645:                    //Getting the value
646:                    currentValue = (String) data.getProjectProperties().get(
647:                            currentKey);
648:
649:                    //old format : <properties><key>value</key><key>value</key></properties>
650:                    //Element elementKey = document.createElement(currentKey);
651:                    //Text textKey = document.createTextNode(currentValue);
652:
653:                    //Element elementPropertyName = document.createElement("name");
654:                    //Text textPropertyName = document.createTextNode(currentKey);
655:                    //elementPropertyName.appendChild(textPropertyName);
656:                    //Adding this element to the "property" element
657:                    //elementProjectProperty.appendChild(elementPropertyName);
658:                    elementProjectProperty.setAttribute("id", currentKey);
659:
660:                    // We test if there is a multiple possible values
661:                    // value1|value2|value3 ...
662:                    StringTokenizer st = new StringTokenizer(currentValue, "|");
663:                    Element elementPropertyValue = null;
664:                    Element elementPropertyPossible = null;
665:                    Element elementPropertyType = document
666:                            .createElement("type");
667:                    if (st.countTokens() > 1) {
668:
669:                        boolean first = true;
670:                        Element elementPropertyPossibleValues = document
671:                                .createElement("possible-values");
672:                        while (st.hasMoreTokens()) {
673:                            String value = st.nextToken();
674:                            if (first) {
675:                                //patch for #302738: enumerated with multi selection can be validated with an empty value
676:                                if (" ".equals(value)) {
677:                                    //System.out.println("$$$$$$$$$$$$  ******** DocumentParser:createDocument (for Activity/project data) - (first) value = **" + value + "**");
678:                                    value = "";
679:                                }
680:                                elementPropertyValue = document
681:                                        .createElement("value");
682:                                Text textPropertyValue = document
683:                                        .createTextNode(value);
684:                                elementPropertyValue
685:                                        .appendChild(textPropertyValue);
686:                                elementProjectProperty
687:                                        .appendChild(elementPropertyValue);
688:
689:                                Text textPropertyType = document
690:                                        .createTextNode("select");
691:                                elementPropertyType
692:                                        .appendChild(textPropertyType);
693:                                elementProjectProperty
694:                                        .appendChild(elementPropertyType);
695:                                first = false;
696:                            } else {
697:                                elementPropertyPossible = document
698:                                        .createElement("possible");
699:                                Text textPropertyPossible = document
700:                                        .createTextNode(value);
701:                                elementPropertyPossible
702:                                        .appendChild(textPropertyPossible);
703:                                elementPropertyPossibleValues
704:                                        .appendChild(elementPropertyPossible);
705:                            }
706:                        }
707:
708:                        elementProjectProperty
709:                                .appendChild(elementPropertyPossibleValues);
710:                    } else {
711:                        elementPropertyValue = document.createElement("value");
712:                        //patch for #306244: put no text node if the value = empty string and insert the attribut xsi:nil="true" into the value node
713:                        if (!"".equals(currentValue)) {
714:                            Text textPropertyValue = document
715:                                    .createTextNode(currentValue);
716:                            elementPropertyValue.appendChild(textPropertyValue);
717:                        } else {
718:                            elementPropertyValue
719:                                    .setAttributeNS(
720:                                            "http://www.w3.org/2001/XMLSchema-instance",
721:                                            "nil", "true");
722:                        }
723:                        elementProjectProperty
724:                                .appendChild(elementPropertyValue);
725:
726:                        Text textPropertyType = document
727:                                .createTextNode("input");
728:                        elementPropertyType.appendChild(textPropertyType);
729:                        elementProjectProperty.appendChild(elementPropertyType);
730:                    }
731:                    //Adding this element to the "properties" element
732:                    elementProjectProperties
733:                            .appendChild(elementProjectProperty);
734:                }
735:
736:                //Adding the node to the root element
737:                root.appendChild(elementProjectProperties);
738:
739:                //END PROJECT INFO
740:
741:                //ACTIVITY INFO
742:
743:                //Element creation
744:                Element elementActivityName = document
745:                        .createElement("activityName");
746:
747:                //Value of the node called "nameProject"
748:                Text textNameActivity = document.createTextNode(data
749:                        .getActivityName());
750:
751:                //Adding the text to the element
752:                elementActivityName.appendChild(textNameActivity);
753:
754:                //Adding the node to the root element
755:                root.appendChild(elementActivityName);
756:                //*****************************************************************
757:
758:                //Node "properties" that will contain activity properties************
759:                Element elementActivityProperties = document
760:                        .createElement("activityProperties");
761:                //******************************************************************
762:
763:                //Getting keys set
764:                //keySet = data.getActivityProperties().keySet();
765:
766:                //For each key we must get the value associeted
767:                //it = keySet.iterator();
768:                it = activityKeys.iterator();
769:                while (it.hasNext()) {
770:                    //New format : <properties><property><name>key</name><type></type><value>value></value>
771:                    //<possible-values><possible></possible></possible-values><property></properties>
772:                    Element elementActivityProperty = document
773:                            .createElement("property");
774:
775:                    //Getting the key
776:                    currentKey = (String) it.next();
777:
778:                    //Getting the value
779:                    currentValue = (String) data.getActivityProperties().get(
780:                            currentKey);
781:
782:                    //old format : <properties><key>value</key><key>value</key></properties>
783:                    //Element elementKey = document.createElement(currentKey);
784:                    //Text textKey = document.createTextNode(currentValue);
785:
786:                    //Element elementPropertyName = document.createElement("name");
787:                    //Text textPropertyName = document.createTextNode(currentKey);
788:                    //elementPropertyName.appendChild(textPropertyName);
789:                    //Adding this element to the "property" element
790:                    //elementActivityProperty.appendChild(elementPropertyName);
791:                    elementActivityProperty.setAttribute("id", currentKey);
792:
793:                    // We test if there is a multiple possible values
794:                    // value1|value2|value3 ...
795:                    StringTokenizer st = new StringTokenizer(currentValue, "|");
796:                    Element elementPropertyValue = null;
797:                    Element elementPropertyPossible = null;
798:                    Element elementPropertyType = document
799:                            .createElement("type");
800:                    if (st.countTokens() > 1) {
801:
802:                        boolean first = true;
803:                        Element elementPropertyPossibleValues = document
804:                                .createElement("possible-values");
805:                        while (st.hasMoreTokens()) {
806:                            String value = st.nextToken();
807:                            if (first) {
808:                                //patch for #302738: enumerated with multi selection can be validated with an empty value
809:                                if (" ".equals(value)) {
810:                                    //System.out.println("$$$$$$$$$$$$  ******** DocumentParser:createDocument (for Activity data) - (first) value = **" + value + "**");
811:                                    value = "";
812:                                }
813:                                elementPropertyValue = document
814:                                        .createElement("value");
815:                                Text textPropertyValue = document
816:                                        .createTextNode(value);
817:                                elementPropertyValue
818:                                        .appendChild(textPropertyValue);
819:                                elementActivityProperty
820:                                        .appendChild(elementPropertyValue);
821:
822:                                Text textPropertyType = document
823:                                        .createTextNode("select");
824:                                elementPropertyType
825:                                        .appendChild(textPropertyType);
826:                                elementActivityProperty
827:                                        .appendChild(elementPropertyType);
828:                                first = false;
829:                            } else {
830:                                elementPropertyPossible = document
831:                                        .createElement("possible");
832:                                Text textPropertyPossible = document
833:                                        .createTextNode(value);
834:                                elementPropertyPossible
835:                                        .appendChild(textPropertyPossible);
836:                                elementPropertyPossibleValues
837:                                        .appendChild(elementPropertyPossible);
838:                            }
839:                        }
840:
841:                        elementActivityProperty
842:                                .appendChild(elementPropertyPossibleValues);
843:                    } else {
844:                        elementPropertyValue = document.createElement("value");
845:                        //patch for #306244: put no text node if the value = empty string and insert the attribut xsi:nil="true" into the value node
846:                        if (!"".equals(currentValue)) {
847:                            Text textPropertyValue = document
848:                                    .createTextNode(currentValue);
849:                            elementPropertyValue.appendChild(textPropertyValue);
850:                        } else {
851:                            elementPropertyValue
852:                                    .setAttributeNS(
853:                                            "http://www.w3.org/2001/XMLSchema-instance",
854:                                            "nil", "true");
855:                        }
856:                        elementActivityProperty
857:                                .appendChild(elementPropertyValue);
858:
859:                        Text textPropertyType = document
860:                                .createTextNode("input");
861:                        elementPropertyType.appendChild(textPropertyType);
862:                        elementActivityProperty
863:                                .appendChild(elementPropertyType);
864:                    }
865:                    //Adding this element to the "properties" element
866:                    elementActivityProperties
867:                            .appendChild(elementActivityProperty);
868:                }
869:
870:                //Adding the node to the root element
871:                root.appendChild(elementActivityProperties);
872:
873:                //Return the document
874:                return document;
875:            }
876:
877:            /**
878:             * Utility function
879:             * @param document
880:             * @return
881:             */
882:            public String toXmlString(Document document) {
883:                try {
884:                    OutputFormat outputFormat = new OutputFormat(document,
885:                            FormGeneratorConstant.DEBUG_OUTPUT_FORMAT_ENCODING,
886:                            true);
887:                    outputFormat.setIndenting(true);
888:                    outputFormat.setIndent(1);
889:                    outputFormat.setPreserveSpace(true);
890:                    StringWriter writer = new StringWriter();
891:                    DOMSerializer serializer = new XMLSerializer(writer,
892:                            outputFormat);
893:                    serializer.serialize(document);
894:                    writer.close();
895:                    return writer.toString();
896:                } catch (Exception ex) {
897:                    ex.printStackTrace();
898:                }
899:                return null;
900:            }
901:
902:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.