Project VN2664QNR : Export to QSL from Questionnaire Editor

From Catglobe Wiki
Revision as of 07:45, 21 May 2009 by Catglobe (talk | contribs) (Visitor pattern)
Jump to: navigation, search

What's purpose of this project ?

The main goal of this project is to allow user to export the structure of a questionnaire template into a QSL script .

Feature design

The feature design could be found here : \\catproc\Share\CatGlobe Teams\Questionnaire\Projects\Version 5.8\VN2644QNR - Export to QSL from Questionnaire Editor

Implement GUI

In this project , we need to write a new collapse-able container and a container that can hold a collection of collapse-able container because the editor only use Swing ( standard Java's API library for providing a graphical user interface ) and this library does not have an explicit collapse-able container .

Class diagram

Container.JPG

How to use an instance of collapse-able container

All sub panels of the container initialized once on constructor . The parameter of constructor contains an Array of sub panel's caption and an Array of sub panel . In order get the collapse-able container itself , use method getComponent() TO add a collapse-able container to another

Making an customize save file dialog

Currently we have an class for customize save file dialog but this one has not been supported our customize file filter yet so i modified it a little bit so that it supports

Making the a file filter

The default "All file(*.*)" filter is in inconvenient when using so it will be overwrite . Another useful of it is that we can have text resource fully supported .

Make QSL file filter

 1 public class QSLFilter extends FileFilter {
 2 
 3     /* (non-Javadoc)
 4      * @see javax.swing.filechooser.FileFilter#accept(java.io.File)
 5      */
 6     @Override
 7     public boolean accept(File arg0) {
 8         // TODO Auto-generated method stub
 9         if(arg0.isDirectory())
10             return true;
11         else 
12             return (getExtension(arg0).equals("qsl"));
13     }
14 
15     /* (non-Javadoc)
16      * @see javax.swing.filechooser.FileFilter#getDescription()
17      */
18     @Override
19     public String getDescription() {
20         
21         // TODO Auto-generated method stub
22         return "QSL file(*.qsl)";
23     }
24     public static String getExtension(File f) {
25         String ext = null;
26         String s = f.getName();
27         int i = s.lastIndexOf('.');
28 
29         if (i > 0 &&  i < s.length() - 1) {
30             ext = s.substring(i+1).toLowerCase();
31         }
32         return ext;
33     }

Export questionnaire template to QSL script

To implement export task , we need to go through the structure of the questionnaire template ( questionnaire , question , property , answer option , sub-question) and export to a text file . "Visitor Pattern" has been chosen because this pattern allows us add new operations to existing object structures without modifying those structures . Thus, using the visitor pattern helps conformance with the open/closed principle

Visitor pattern

Visitor.PNG

QSL keyword using in exporting

The QSL keywords are defined in file questionnaire.g and we can't get keywords directly from it . In order to keep the synchronization with import QSL module , we will get the keyword from public variables of QuestionnaireLexer.java and QuestionnaireParser.java . Those 2 file were generated directly and automiccally from Questionnaire.g using ANTLR library .

Processing properties

In the questionnaire template , properties are only defined for questionnaire and question but QSL script has properties for sub question and answer option . We need to generate these properties from the properties of the related question . To solve this problem , we use 2 map ( Map in java used like a dictionary in .NET) to store properties relate to answer option and sub question .
Algorithm :
-Visit question element . If this question type has properties use for answer option ( or sub question ) , process them and put to the map
-When visit answer option ( or sub question ) , if the map is not empty then get the value from it and generate properties for answer option ( or sub question )

Data structure use for export task

DataStructure.PNG

General

The structure of questionnaire template is not completely fit the structure of QSL Script . We do not have an explicit property for answer option so we need to parse the to get the property for answer option from the range contains in question property's value . Another addition is that the properties for sub question is contained in question's properties . We have made 4 new class in this project :
- ExportQSLVisitor : This class implements Visitor pattern . We also store internal information that is needed for export task ( export mode , visited question list ...) and information about the exported questionnaire ( properties set ) .
- ExportQSLVisitor : This class stores all information related to a question ( question properties , answer option , sub question , question text ) . It also include saperatedly the properties we use for answer option and sub question .
- AnswerOptionQSLExportData : Information of an answer option .
- SubQuestionQSLExportData : Information of an sub question

Visit Questionnaire Element

If the export mode include questionnaire properties or using HTML , we initialize _questionnaireProperties

Visit Question Element

- If this question is not selected to export , ignore it and stop visiting
- Create new instance of QuestionQSLExportData . Information of question will be created in constructor of QuestionQSLExportData
- Storing the new QuestionQSLExportData

Visit Property Elemnt

- If this property belongs to questionnaire , check "Visit Questionnaire Property Element"
- If this property belongs to question , check "Question Question property Element"

Visit Questionnaire Property Element

- Create a new QSLProperty for the property
- If the QSLProperty's output is valid , then store the output to Questionnaire Property

Visit Question Question property Element

- If this property belongs to a question which is not selected to export , than ignore it and stop visiting ( If the export task does not include question properties , also ignore)
- If the property related to Answer Option and Range value call function handleAnswerOptionPropertyForRange of _currentQuestionData . Return
- If the property related to Answer Option and single value call function handleAnswerOptionPropertyForSingle of _currentQuestionData . Return
- If the property related to sub question of scale grid call function handleSubquestionForScaleGrid of _currentQuestionData . Return
- Other wise , create a new QSLProperty instance for the property . If the QSLOutput is valid , call function insertQSLPropertyToQuestion of _currentQuestionData

Visit sub question Element

- If this sub question does not belong to a selected question , return .
- Other wise , create a SubQuestionQSLExportData for it . Use hasSubQuestionProperties to check if this sub question has property . If yes , get them from the parent question
- Add the new SubQuestionQSLExportData instance to _currentQuestionData

Visit answer option element

- If this answer option does not belong to a selected question , return .
- Other wise , create a AnswerOptionQSLExportData for it . Use hasAnswerOptionProperties to check if this sub question has property . If yes , get them from the parent question
- Add this new AnswerOptionQSLExportData instance to _currentQuestionData