Changeset 907

Show
Ignore:
Timestamp:
04/26/08 23:33:09 (3 months ago)
Author:
laurentj
Message:

jforms has now two versions of the xml format, with separate compiler and schema, so we can use file of jelix 1.0 without modifying them

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/build/manifests/jelix-dev.mn

    r879 r907  
    176176  project.rng 
    177177  urls.rng 
    178   jforms.rng 
     178  jforms_1.0.rng 
     179  jforms_1.1.rng 
    179180 
    180181cd lib/jelix-www/xul/test/ 
  • trunk/build/manifests/jelix-dev.mn

    r879 r907  
    176176  project.rng 
    177177  urls.rng 
    178   jforms.rng 
     178  jforms_1.0.rng 
     179  jforms_1.1.rng 
    179180 
    180181cd lib/jelix-www/xul/test/ 
  • trunk/build/manifests/jelix-dev.mn

    r879 r907  
    176176  project.rng 
    177177  urls.rng 
    178   jforms.rng 
     178  jforms_1.0.rng 
     179  jforms_1.1.rng 
    179180 
    180181cd lib/jelix-www/xul/test/ 
  • trunk/build/manifests/jelix-dev.mn

    r879 r907  
    176176  project.rng 
    177177  urls.rng 
    178   jforms.rng 
     178  jforms_1.0.rng 
     179  jforms_1.1.rng 
    179180 
    180181cd lib/jelix-www/xul/test/ 
  • trunk/build/manifests/jelix-lib.mn

    r901 r907  
    285285  jFormsBuilderBase.class.php 
    286286  jFormsCompiler.class.php 
     287  jFormsCompiler_jf_1_0.class.php 
     288  jFormsCompiler_jf_1_1.class.php 
    287289  jFormsControl.class.php 
    288290  jFormsDataContainer.class.php 
  • trunk/build/manifests/jelix-lib.mn

    r901 r907  
    285285  jFormsBuilderBase.class.php 
    286286  jFormsCompiler.class.php 
     287  jFormsCompiler_jf_1_0.class.php 
     288  jFormsCompiler_jf_1_1.class.php 
    287289  jFormsControl.class.php 
    288290  jFormsDataContainer.class.php 
  • trunk/build/manifests/jelix-lib.mn

    r901 r907  
    285285  jFormsBuilderBase.class.php 
    286286  jFormsCompiler.class.php 
     287  jFormsCompiler_jf_1_0.class.php 
     288  jFormsCompiler_jf_1_1.class.php 
    287289  jFormsControl.class.php 
    288290  jFormsDataContainer.class.php 
  • trunk/build/manifests/jelix-lib.mn

    r901 r907  
    285285  jFormsBuilderBase.class.php 
    286286  jFormsCompiler.class.php 
     287  jFormsCompiler_jf_1_0.class.php 
     288  jFormsCompiler_jf_1_1.class.php 
    287289  jFormsControl.class.php 
    288290  jFormsDataContainer.class.php 
  • trunk/lib/jelix/docs/ns/jforms_1.1.rng

    r895 r907  
    2424            <ref name="upload" /> 
    2525            <ref name="submit" /> 
    26             <ref name="reset" /> 
    2726            <ref name="checkbox" /> 
    2827            <ref name="checkboxes" /> 
  • trunk/lib/jelix/docs/ns/jforms_1.1.rng

    r895 r907  
    2424            <ref name="upload" /> 
    2525            <ref name="submit" /> 
    26             <ref name="reset" /> 
    2726            <ref name="checkbox" /> 
    2827            <ref name="checkboxes" /> 
  • trunk/lib/jelix/docs/ns/jforms_1.1.rng

    r895 r907  
    2424            <ref name="upload" /> 
    2525            <ref name="submit" /> 
    26             <ref name="reset" /> 
    2726            <ref name="checkbox" /> 
    2827            <ref name="checkboxes" /> 
  • trunk/lib/jelix/docs/ns/jforms_1.1.rng

    r895 r907  
    2424            <ref name="upload" /> 
    2525            <ref name="submit" /> 
    26             <ref name="reset" /> 
    2726            <ref name="checkbox" /> 
    2827            <ref name="checkboxes" /> 
  • trunk/lib/jelix/forms/jFormsCompiler.class.php

    r906 r907  
    3131        $this->sourceFile = $selector->getPath(); 
    3232 
     33        // chargement du fichier XML 
     34        $doc = new DOMDocument(); 
     35 
     36        if(!$doc->load($this->sourceFile)){ 
     37            throw new jException('jelix~formserr.invalid.xml.file',array($this->sourceFile)); 
     38        } 
     39 
     40        if ($doc->documentElement->namespaceURI == JELIX_NAMESPACE_BASE.'forms/1.0') { 
     41            require_once(JELIX_LIB_PATH.'forms/jFormsCompiler_jf_1_0.class.php'); 
     42            $compiler = new jFormsCompiler_jf_1_0($this->sourceFile); 
     43        } elseif ($doc->documentElement->namespaceURI == JELIX_NAMESPACE_BASE.'forms/1.1') { 
     44            require_once(JELIX_LIB_PATH.'forms/jFormsCompiler_jf_1_1.class.php'); 
     45            $compiler = new jFormsCompiler_jf_1_1($this->sourceFile); 
     46        } else { 
     47           throw new jException('jelix~formserr.namespace.wrong',array($this->sourceFile)); 
     48        } 
     49 
    3350        $source=array(); 
    3451        $source[]='<?php '; 
     
    4158            require_once($pluginPath.$buildername.'.jformscompiler.php'); 
    4259            $classname = $buildername.'JformsCompiler'; 
    43             $buildersCompilers[$buildername] = new $classname(); 
     60            $buildersCompilers[$buildername] = new $classname($compiler); 
    4461 
    4562            $srcBuilders[$buildername]=array(); 
     
    5572        } 
    5673 
    57         // chargement du fichier XML 
    58         $doc = new DOMDocument(); 
    59  
    60         if(!$doc->load($this->sourceFile)){ 
    61             throw new jException('jelix~formserr.invalid.xml.file',array($this->sourceFile)); 
    62         } 
    63  
    6474        $source[]='    );'; 
    6575        $source[]=' public function __construct($sel, &$container, $reset = false){'; 
    6676        $source[]='          parent::__construct($sel, $container, $reset); '; 
    6777 
    68         $this->generatePHPContent($doc, $source, $srcBuilders, $buildersCompilers); 
     78        $compiler->compile($doc, $source, $srcBuilders, $buildersCompilers); 
    6979 
    7080        $source[]="  }\n} ?>"; 
     
    7888        return true; 
    7989    } 
    80  
    81     protected function generatePHPContent($doc, &$source, &$srcBuilders, &$buildersCompilers){ 
    82         global $gJConfig; 
    83         if($doc->documentElement->namespaceURI != JELIX_NAMESPACE_BASE.'forms/1.0'){ 
    84            throw new jException('jelix~formserr.namespace.wrong',array($this->sourceFile)); 
    85         } 
    86  
    87         $xml = simplexml_import_dom($doc); 
    88  
    89         if (count($xml->reset) > 1 ) 
    90             throw new jException('jelix~formserr.notunique.tag',array('reset',$this->sourceFile)); 
    91  
    92         foreach($xml->children() as $controltype=>$control){ 
    93             $source[] = $this->generatePHPControl($controltype, $control); 
    94             foreach($gJConfig->_pluginsPathList_jforms as $buildername => $pluginPath) { 
    95                 $srcBuilders[$buildername][]= $buildersCompilers[$buildername]->generateControl($controltype, $control); 
    96             } 
    97         } 
    98     } 
    99  
    100     protected function generatePHPControl($controltype, $control){ 
    101         $source = array(); 
    102         $class = 'jFormsControl'.$controltype; 
    103  
    104         $attributes = array(); 
    105         foreach ($control->attributes() as $name=>$value){ 
    106             $attributes[$name]=(string)$value; 
    107         } 
    108  
    109         if(!class_exists($class,false)){ 
    110             throw new jException('jelix~formserr.unknow.tag',array($controltype,$this->sourceFile)); 
    111         } 
    112  
    113         if(!isset($attributes['ref'])){ 
    114             throw new jException('jelix~formserr.attribute.missing',array('ref',$controltype,$this->sourceFile)); 
    115         } 
    116  
    117         // instancie the class 
    118         $source[]='$ctrl= new '.$class.'(\''.$attributes['ref'].'\');'; 
    119         unset($attributes['ref']); 
    120  
    121         $doublecontrol = $this->{'generate'.$controltype}($source, $control, $attributes); 
    122  
    123         if(count($attributes)) { 
    124             reset($attributes); 
    125             throw new jException('jelix~formserr.attribute.not.allowed',array(key($attributes),$controltype,$this->sourceFile)); 
    126         } 
    127  
    128         $source[]='$this->addControl($ctrl);'; 
    129         if ($doublecontrol) 
    130             $source[]='$this->addControl($ctrl2);'; 
    131         return implode("\n", $source); 
    132     } 
    133  
    134     protected function generateInput(&$source, $control, &$attributes) { 
    135         $type='string'; 
    136         if(isset($attributes['type'])){ 
    137             $type = strtolower($attributes['type']); 
    138             if(!in_array($type, array('string','boolean','decimal','integer','hexadecimal', 
    139                                                 'datetime','date','time','localedatetime','localedate','localetime', 
    140                                                 'url','email','ipv4','ipv6','html'))){ 
    141                 throw new jException('jelix~formserr.datatype.unknow',array($type,'input',$this->sourceFile)); 
    142             } 
    143  
    144             if($type != 'string') 
    145                 $source[]='$ctrl->datatype= new jDatatype'.$type.'();'; 
    146             unset($attributes['type']); 
    147         } 
    148         $this->attrReadonly($source, $attributes); 
    149         $this->attrRequired($source, $attributes); 
    150         $this->attrDefaultvalue($source, $attributes); 
    151         if(isset($attributes['minlength'])){ 
    152             if($type != 'string' && $type != 'html'){ 
    153                 throw new jException('jelix~formserr.attribute.not.allowed',array('minlength','input',$this->sourceFile)); 
    154             } 
    155             $source[]='$ctrl->datatype->addFacet(\'minLength\','.intval($attributes['minlength']).');'; 
    156             unset($attributes['minlength']); 
    157         } 
    158         if(isset($attributes['maxlength'])){ 
    159             if($type != 'string' && $type != 'html'){ 
    160                 throw new jException('jelix~formserr.attribute.not.allowed',array('maxlength','input',$this->sourceFile)); 
    161             } 
    162             $source[]='$ctrl->datatype->addFacet(\'maxLength\','.intval($attributes['maxlength']).');'; 
    163             unset($attributes['maxlength']); 
    164         } 
    165         $this->readLabel($source, $control, 'input'); 
    166         $this->readHelpHintAlert($source, $control); 
    167         $this->attrSize($source, $attributes); 
    168         return false; 
    169     } 
    170  
    171     protected function generateTextarea(&$source, $control, &$attributes) { 
    172         if(isset($attributes['type'])){ 
    173             if ( $attributes['type'] != 'html') { 
    174                 throw new jException('jelix~formserr.datatype.unknow',array($attributes['type'],'textarea',$this->sourceFile)); 
    175             } 
    176             $source[]='$ctrl->datatype= new jDatatypeHtml();'; 
    177             unset($attributes['type']); 
    178         } 
    179         return $this->_generateTextareaHtmlEditor($source, $control, $attributes); 
    180     } 
    181  
    182     protected function _generateTextareaHtmlEditor(&$source, $control, &$attributes) { 
    183         $this->attrReadonly($source, $attributes); 
    184         $this->attrRequired($source, $attributes); 
    185         $this->attrDefaultvalue($source, $attributes); 
    186  
    187         if(isset($attributes['minlength'])){ 
    188             $source[]='$ctrl->datatype->addFacet(\'minLength\','.intval($attributes['minlength']).');'; 
    189             unset($attributes['minlength']); 
    190         } 
    191         if(isset($attributes['maxlength'])){ 
    192             $source[]='$ctrl->datatype->addFacet(\'maxLength\','.intval($attributes['maxlength']).');'; 
    193             unset($attributes['maxlength']); 
    194         } 
    195         $this->readLabel($source, $control, 'textarea'); 
    196         $this->readHelpHintAlert($source, $control); 
    197         if (isset($attributes['rows'])) { 
    198             $rows = intval($attributes['rows']); 
    199             if($rows < 2) $rows = 2; 
    200             $source[]='$ctrl->rows='.$rows.';'; 
    201             unset($attributes['rows']); 
    202         } 
    203  
    204         if (isset($attributes['cols'])) { 
    205             $cols = intval($attributes['cols']); 
    206             if($cols < 2) $cols = 2; 
    207             $source[]='$ctrl->cols='.$cols.';'; 
    208             unset($attributes['cols']); 
    209         } 
    210         return false; 
    211     } 
    212  
    213     protected function generateHtmleditor(&$source, $control, &$attributes) { 
    214         $this->_generateTextareaHtmlEditor($source, $control, $attributes); 
    215  
    216         if (isset($attributes['config'])) { 
    217             $source[]='$ctrl->config=\''.str_replace("'","\\'",$attributes['config']).'\';'; 
    218             unset($attributes['config']); 
    219         } 
    220         if (isset($attributes['skin'])) { 
    221             $source[]='$ctrl->skin=\''.str_replace("'","\\'",$attributes['skin']).'\';'; 
    222             unset($attributes['skin']); 
    223         } 
    224         return false; 
    225     } 
    226  
    227     protected function generateOutput(&$source, $control, &$attributes) { 
    228         $this->attrDefaultvalue($source, $attributes); 
    229         $this->readLabel($source, $control, 'output'); 
    230         $this->readHelpHintAlert($source, $control); 
    231         return false; 
    232     } 
    233  
    234     protected function generateSubmit(&$source, $control, &$attributes) { 
    235         $this->readLabel($source, $control, 'submit'); 
    236         $this->readHelpHintAlert($source, $control); 
    237         $this->readDatasource($source, $control, 'submit', $attributes); 
    238         return false; 
    239     } 
    240  
    241     protected function generateReset(&$source, $control, &$attributes) { 
    242         // XXX: readonly attr really needed ? 
    243         $this->attrReadonly($source, $attributes); 
    244         $this->readLabel($source, $control, 'reset'); 
    245         $this->readHelpHintAlert($source, $control); 
    246         return false; 
    247     } 
    248  
    249     protected function generateCheckbox(&$source, $control, &$attributes) { 
    250         $source[]='$ctrl->datatype= new jDatatypeBoolean();'; 
    251         $this->attrDefaultvalue($source, $attributes); 
    252         $this->attrReadonly($source, $attributes); 
    253         $this->readLabel($source, $control, 'checkbox'); 
    254         $this->readHelpHintAlert($source, $control); 
    255         if(isset($attributes['valueoncheck'])){ 
    256             $source[]='$ctrl->valueOnCheck=\''.str_replace("'","\\'", $attributes['valueoncheck']) ."';"; 
    257             unset($attributes['valueoncheck']); 
    258         } 
    259         if(isset($attributes['valueonuncheck'])){ 
    260             $source[]='$ctrl->valueOnUncheck=\''.str_replace("'","\\'", $attributes['valueonuncheck']) ."';"; 
    261             unset($attributes['valueonuncheck']); 
    262         } 
    263         return false; 
    264     } 
    265  
    266     protected function generateHidden(&$source, $control, &$attributes) { 
    267         $this->attrDefaultvalue($source, $attributes); 
    268         return false; 
    269     } 
    270  
    271     protected function generateCheckboxes(&$source, $control, &$attributes) { 
    272         $this->attrReadonly($source, $attributes); 
    273         $this->attrRequired($source, $attributes); 
    274         $this->readLabel($source, $control, 'checkboxes'); 
    275         $this->readHelpHintAlert($source, $control); 
    276         $hasSelectedValues = $this->readSelectedValue($source, $control, 'checkboxes', $attributes); 
    277         $this->readDatasource($source, $control, 'checkboxes', $attributes, $hasSelectedValues); 
    278         return false; 
    279     } 
    280  
    281     protected function generateRadiobuttons(&$source, $control, &$attributes) { 
    282         $this->attrReadonly($source, $attributes); 
    283         $this->attrRequired($source, $attributes); 
    284         $this->readLabel($source, $control, 'radiobuttons'); 
    285         $this->readHelpHintAlert($source, $control); 
    286         $hasSelectedValues = $this->readSelectedValue($source, $control, 'radiobuttons', $attributes); 
    287         $this->readDatasource($source, $control, 'radiobuttons', $attributes, $hasSelectedValues); 
    288         return false; 
    289     } 
    290  
    291     protected function generateMenulist(&$source, $control, &$attributes) { 
    292         $this->attrReadonly($source, $attributes); 
    293         $this->attrRequired($source, $attributes); 
    294         $this->readLabel($source, $control, 'menulist'); 
    295         $this->readHelpHintAlert($source, $control); 
    296         $hasSelectedValues = $this->readSelectedValue($source, $control, 'menulist', $attributes); 
    297         $this->readDatasource($source, $control, 'menulist', $attributes, $hasSelectedValues); 
    298         return false; 
    299     } 
    300  
    301     protected function generateListbox(&$source, $control, &$attributes) { 
    302         $this->attrReadonly($source, $attributes); 
    303         $this->attrRequired($source, $attributes); 
    304         $this->readLabel($source, $control, 'listbox'); 
    305         $this->readHelpHintAlert($source, $control); 
    306         $this->attrSize($source, $attributes); 
    307         $hasSelectedValues = $this->readSelectedValue($source, $control, 'listbox', $attributes); 
    308         $this->readDatasource($source, $control, 'listbox', $attributes, $hasSelectedValues); 
    309         if(isset($attributes['multiple'])){ 
    310             if('true' == $attributes['multiple']) 
    311                 $source[]='$ctrl->multiple=true;'; 
    312             unset($attributes['multiple']); 
    313         } 
    314         return false; 
    315     } 
    316  
    317     protected function generateSecret(&$source, $control, &$attributes) { 
    318         $this->attrReadonly($source, $attributes); 
    319         $this->attrRequired($source, $attributes); 
    320         $this->readLabel($source, $control, 'secret'); 
    321         list($alertInvalid, $alertRequired)=$this->readHelpHintAlert($source, $control); 
    322         $this->attrSize($source, $attributes); 
    323  
    324         if(isset($control->confirm)) { 
    325             $label=''; 
    326             if(isset($control->confirm['locale'])){ 
    327                 $label = "jLocale::get('".(string)$control->confirm['locale']."');"; 
    328             }elseif( "" != (string)$control->confirm) { 
    329                 $label = "'".str_replace("'","\\'",(string)$control->confirm)."';"; 
    330             }else{ 
    331                 throw new jException('jelix~formserr.content.missing',array('confirm',$this->sourceFile)); 
    332             } 
    333             $source[]='$ctrl2 = new jFormsControlSecretConfirm(\''.(string)$control['ref'].'_confirm\');'; 
    334             $source[]='$ctrl2->primarySecret = \''.(string)$control['ref'].'\';'; 
    335             $source[]='$ctrl2->label='.$label; 
    336             $source[]='$ctrl2->required = $ctrl->required;'; 
    337             $source[]='$ctrl2->readonly = $ctrl->readonly;'; 
    338             if($alertInvalid!='') 
    339                 $source[]='$ctrl2->alertInvalid = $ctrl->alertInvalid;'; 
    340             if($alertRequired!='') 
    341                 $source[]='$ctrl2->alertRequired = $ctrl->alertRequired;'; 
    342  
    343             if(isset($control->help)){ 
    344                 $source[]='$ctrl2->hasHelp=true;'; 
    345             } 
    346             if(isset($control->hint)){ 
    347                 $source[]='$ctrl2->hint=$ctrl->hint;'; 
    348             } 
    349             if (isset($control['size'])) { 
    350                 $source[]='$ctrl2->size=$ctrl->size;'; 
    351             } 
    352             return true; 
    353         } 
    354         return false; 
    355     } 
    356  
    357     protected function generateUpload(&$source, $control, &$attributes) { 
    358         $this->attrReadonly($source, $attributes); 
    359         $this->attrRequired($source, $attributes); 
    360         $this->readLabel($source, $control, 'input'); 
    361         $this->readHelpHintAlert($source, $control); 
    362  
    363         if(isset($attributes['maxsize'])){ 
    364             $source[]='$ctrl->maxsize='.intval($attributes['maxsize']).';'; 
    365             unset($attributes['maxsize']); 
    366         } 
    367  
    368         if(isset($attributes['mimetype'])){ 
    369             $mime = split('[,; ]',$attributes['mimetype']); 
    370             $mime = array_diff($mime, array('')); // we remove all '' 
    371             $source[]='$ctrl->mimetype='.var_export($mime,true).';'; 
    372             unset($attributes['mimetype']); 
    373         } 
    374         return false; 
    375     } 
    376  
    377     protected function generateCaptcha(&$source, $control, &$attributes) { 
    378         $this->readLabel($source, $control, 'captcha'); 
    379         $this->readHelpHintAlert($source, $control); 
    380         return false; 
    381     } 
    382  
    383  
    384  
    385  
    386     protected function attrReadonly(&$source, &$attributes) { 
    387         if(isset($attributes['readonly'])){ 
    388             if('true' == $attributes['readonly']) 
    389                 $source[]='$ctrl->readonly=true;'; 
    390             unset($attributes['readonly']); 
    391         } 
    392     } 
    393  
    394     protected function attrRequired(&$source, &$attributes) { 
    395         if(isset($attributes['required'])){ 
    396             if('true' == $attributes['required']) 
    397                 $source[]='$ctrl->required=true;'; 
    398             unset($attributes['required']); 
    399         } 
    400     } 
    401  
    402     protected function attrDefaultvalue(&$source, &$attributes) { 
    403         if(isset($attributes['defaultvalue'])){ 
    404             $source[]='$ctrl->defaultValue=\''.str_replace('\'','\\\'',$attributes['defaultvalue']).'\';'; 
    405             unset($attributes['defaultvalue']); 
    406         } 
    407     } 
    408  
    409     protected function attrSize(&$source, &$attributes) { 
    410         if(isset($attributes['size'])){ 
    411             $size = intval($attributes['size']); 
    412             if($size < 2) $size = 2; 
    413             $source[]='$ctrl->size='.$size.';'; 
    414             unset($attributes['size']); 
    415         } 
    416     } 
    417  
    418     protected function readLabel(&$source, $control, $controltype) { 
    419         if(!isset($control->label)){ 
    420             throw new jException('jelix~formserr.tag.missing',array('label',$controltype,$this->sourceFile)); 
    421         } 
    422         if(isset($control->label['locale'])){ 
    423             $label=''; 
    424             $labellocale=(string)$control->label['locale']; 
    425             $source[]='$ctrl->label=jLocale::get(\''.$labellocale.'\');'; 
    426         }else{ 
    427             $label=(string)$control->label; 
    428             $labellocale=''; 
    429             $source[]='$ctrl->label=\''.str_replace("'","\\'",$label).'\';'; 
    430         } 
    431     } 
    432  
    433     protected function readHelpHintAlert(&$source, $control) { 
    434         if(isset($control->help)){ // help value is readed in the html compiler 
    435             $source[]='$ctrl->hasHelp=true;'; 
    436         } 
    437         if(isset($control->hint)){ 
    438             if(isset($control->hint['locale'])){ 
    439                 $source[]='$ctrl->hint=jLocale::get(\''.(string)$control->hint['locale'].'\');'; 
    440             }else{ 
    441                 $source[]='$ctrl->hint=\''.str_replace("'","\\'",(string)$control->hint).'\';'; 
    442             } 
    443         } 
    444         $alertInvalid=''; 
    445         $alertRequired=''; 
    446         if(isset($control->alert)){ 
    447             foreach($control->alert as $alert){ 
    448                 if(isset($alert['locale'])){ 
    449                     $msg='jLocale::get(\''.(string)$alert['locale'].'\');'; 
    450                 }else{ 
    451                     $msg='\''.str_replace("'","\\'",(string)$alert).'\';'; 
    452                 } 
    453  
    454                 if(isset($alert['type'])){ 
    455                     if((string)$alert['type'] == 'required') 
    456                         $alertRequired = '$ctrl->alertRequired='.$msg; 
    457                     else 
    458                         $alertInvalid = '$ctrl->alertInvalid='.$msg; 
    459                 } else { 
    460                     $alertInvalid = '$ctrl->alertInvalid='.$msg; 
    461                 } 
    462             } 
    463             if($alertRequired !='') $source[]=$alertRequired; 
    464             if($alertInvalid !='') $source[]=$alertInvalid; 
    465         } 
    466         return array($alertInvalid, $alertRequired); 
    467     } 
    468  
    469     protected function readSelectedValue(&$source, $control, $controltype, &$attributes) { 
    470         // support of static data or daos 
    471         if(isset($attributes['selectedvalue']) && isset($control->selectedvalues)){ 
    472             throw new jException('jelix~formserr.attribute.not.allowed',array('selectedvalue',$controltype,$this->sourceFile)); 
    473         } 
    474         $hasSelectedValues = false; 
    475         if(isset($control->selectedvalues) && isset($control->selectedvalues->value)){ 
    476             if( ($controltype == 'listbox' && isset($control['multiple']) && 'true' != (string)$control['multiple']) 
    477                 || $controltype == 'radiobuttons' || $controltype == 'menulist' 
    478                 ){ 
    479                 throw new jException('jelix~formserr.defaultvalues.not.allowed',$this->sourceFile); 
    480             } 
    481             $str =' array('; 
    482             foreach($control->selectedvalues->value as $value){ 
    483                 $str.="'". str_replace("'","\\'", (string)$value) ."',"; 
    484             } 
    485             $source[]='$ctrl->defaultValue='.$str.');'; 
    486             $hasSelectedValues = true; 
    487         }elseif(isset($attributes['selectedvalue'])){ 
    488             $source[]='$ctrl->defaultValue=array(\''. str_replace("'","\\'", (string)$control['selectedvalue']) .'\');'; 
    489             $hasSelectedValues = true; 
    490             unset($attributes['selectedvalue']); 
    491         } 
    492         return $hasSelectedValues; 
    493     } 
    494  
    495     protected function readDatasource(&$source, $control, $controltype, &$attributes, $hasSelectedValues=false) { 
    496  
    497         if(isset($control->datasource)) { 
    498             $attrs = array(); 
    499             foreach ($control->datasource->attributes() as $name=>$value){ 
    500                 $attrs[$name]=(string)$value; 
    501             } 
    502  
    503             if(isset($attrs['dao'])) { 
    504                 if(isset($attrs['valueproperty'])) { 
    505                     $daovalue = $attrs['valueproperty']; 
    506                 } else 
    507                     $daovalue = ''; 
    508                 if(!isset($attrs['method'])) 
    509                     throw new jException('jelix~formserr.attribute.missing',array('method', 'datasource',$this->sourceFile)); 
    510                 if(!isset($attrs['labelproperty'])) 
    511                     throw new jException('jelix~formserr.attribute.missing',array('method', 'datasource',$this->sourceFile)); 
    512  
    513                 if(isset($attrs['criteria'])) 
    514                     $criteria=',\''.$attrs['criteria'].'\''; 
    515                 elseif(isset($attrs['criteriafrom'])) 
    516                     $criteria=',null,\''.$attrs['criteriafrom'].'\''; 
    517                 else 
    518                     $criteria=''; 
    519  
    520                 $source[]='$ctrl->datasource = new jFormsDaoDatasource(\''.$attrs['dao'].'\',\''. 
    521                                 $attrs['method'].'\',\''.$attrs['labelproperty'].'\',\''.$daovalue.'\''.$criteria.');'; 
    522                 if($controltype == 'submit'){ 
    523                     $source[]='$ctrl->standalone=false;'; 
    524                 } 
    525             }else if(isset($attrs['class'])) { 
    526                 $class = new jSelectorClass($attrs['class']); 
    527                 $source[]='jClasses::inc(\''.$attrs['class'].'\');'; 
    528                 $source[]='$datasource = new '.$class->className.'($this->id());'; 
    529                 $source[]='if ($datasource instanceof jIFormsDatasource){$ctrl->datasource=$datasource;}'; 
    530                 $source[]='else{$ctrl->datasource=new jFormsStaticDatasource();}'; 
    531                 if($controltype == 'submit'){ 
    532                     $source[]='$ctrl->standalone=false;'; 
    533                 } 
    534             } else { 
    535                 throw new jException('jelix~formserr.attribute.missing',array('class/dao', 'datasource',$this->sourceFile)); 
    536             } 
    537  
    538         }else if(isset($attributes['dao'])){ // read deprecated dao attributes 
    539             if(isset($attributes['daovalueproperty'])) { 
    540                 $daovalue = $attributes['daovalueproperty']; 
    541                 unset($attributes['daovalueproperty']); 
    542             } else 
    543                 $daovalue = ''; 
    544             $source[]='$ctrl->datasource = new jFormsDaoDatasource(\''.$attributes['dao'].'\',\''. 
    545                             $attributes['daomethod'].'\',\''.$attributes['daolabelproperty'].'\',\''.$daovalue.'\');'; 
    546             unset($attributes['dao']); 
    547             unset($attributes['daomethod']); 
    548             unset($attributes['daolabelproperty']); 
    549             if($controltype == 'submit'){ 
    550                 $source[]='$ctrl->standalone=false;'; 
    551             } 
    552         }elseif(isset($attributes['dsclass'])){ // read deprecated dsclass attribute 
    553             $dsclass = $attributes['dsclass']; 
    554             unset($attributes['dsclass']); 
    555             $class = new jSelectorClass($dsclass); 
    556             $source[]='jClasses::inc(\''.$dsclass.'\');'; 
    557             $source[]='$datasource = new '.$class->className.'($this->id());'; 
    558             $source[]='if ($datasource instanceof jIFormsDatasource){$ctrl->datasource=$datasource;}'; 
    559             $source[]='else{$ctrl->datasource=new jFormsStaticDatasource();}'; 
    560             if($controltype == 'submit'){ 
    561                 $source[]='$ctrl->standalone=false;'; 
    562             } 
    563         }elseif(isset($control->item)){ 
    564             // get all <items> and their label|labellocale attributes + their values 
    565             if($controltype == 'submit'){ 
    566                 $source[]='$ctrl->standalone=false;'; 
    567             } 
    568             $source[]='$ctrl->datasource= new jFormsStaticDatasource();'; 
    569             $source[]='$ctrl->datasource->data = array('; 
    570             $selectedvalues=array(); 
    571             foreach($control->item as $item){ 
    572                 $value ="'".str_replace("'","\\'",(string)$item['value'])."'=>"; 
    573                 if(isset($item['locale'])){ 
    574                     $source[] = $value."jLocale::get('".(string)$item['locale']."'),"; 
    575                 }elseif( "" != (string)$item){ 
    576                     $source[] = $value."'".str_replace("'","\\'",(string)$item)."',"; 
    577                 }else{ 
    578                     $source[] = $value."'".str_replace("'","\\'",(string)$item['value'])."',"; 
    579                 } 
    580  
    581                 if(isset($item['selected'])){ 
    582                     if($hasSelectedValues || $controltype == 'submit'){ 
    583                         throw new jException('jelix~formserr.selected.attribute.not.allowed',$this->sourceFile); 
    584                     } 
    585                     if((string)$item['selected']== 'true'){ 
    586                         $selectedvalues[]=(string)$item['value']; 
    587                     } 
    588                 } 
    589             } 
    590             $source[]=");"; 
    591             if(count($selectedvalues)){ 
    592                 if(count($selectedvalues)>1 && 
    593                         (($controltype == 'listbox' && isset($control['multiple']) && 'true' != (string)$control['multiple']) 
    594                         || $controltype == 'radiobuttons' || $controltype == 'menulist')  ){ 
    595                     throw new jException('jelix~formserr.multiple.selected.not.allowed',$this->sourceFile); 
    596                 } 
    597                 $source[]='$ctrl->defaultValue='.var_export($selectedvalues,true).';'; 
    598             } 
    599         }else{ 
    600             $source[]='$ctrl->datasource= new jFormsStaticDatasource();'; 
    601         } 
    602     } 
    60390} 
  • trunk/lib/jelix/forms/jFormsCompiler.class.php

    r906 r907  
    3131        $this->sourceFile = $selector->getPath(); 
    3232 
     33        // chargement du fichier XML 
     34        $doc = new DOMDocument(); 
     35 
     36        if(!$doc->load($this->sourceFile)){ 
     37            throw new jException('jelix~formserr.invalid.xml.file',array($this->sourceFile)); 
     38        } 
     39 
     40        if ($doc->documentElement->namespaceURI == JELIX_NAMESPACE_BASE.'forms/1.0') { 
     41            require_once(JELIX_LIB_PATH.'forms/jFormsCompiler_jf_1_0.class.php'); 
     42            $compiler = new jFormsCompiler_jf_1_0($this->sourceFile); 
     43        } elseif ($doc->documentElement->namespaceURI == JELIX_NAMESPACE_BASE.'forms/1.1') { 
     44            require_once(JELIX_LIB_PATH.'forms/jFormsCompiler_jf_1_1.class.php'); 
     45            $compiler = new jFormsCompiler_jf_1_1($this->sourceFile); 
     46        } else { 
     47           throw new jException('jelix~formserr.namespace.wrong',array($this->sourceFile)); 
     48        } 
     49 
    3350        $source=array(); 
    3451        $source[]='<?php '; 
     
    4158            require_once($pluginPath.$buildername.'.jformscompiler.php'); 
    4259            $classname = $buildername.'JformsCompiler'; 
    43             $buildersCompilers[$buildername] = new $classname(); 
     60            $buildersCompilers[$buildername] = new $classname($compiler); 
    4461 
    4562            $srcBuilders[$buildername]=array(); 
     
    5572        } 
    5673 
    57         // chargement du fichier XML 
    58         $doc = new DOMDocument(); 
    59  
    60         if(!$doc->load($this->sourceFile)){ 
    61             throw new jException('jelix~formserr.invalid.xml.file',array($this->sourceFile)); 
    62         } 
    63  
    6474        $source[]='    );'; 
    6575        $source[]=' public function __construct($sel, &$container, $reset = false){'; 
    6676        $source[]='          parent::__construct($sel, $container, $reset); '; 
    6777 
    68         $this->generatePHPContent($doc, $source, $srcBuilders, $buildersCompilers); 
     78        $compiler->compile($doc, $source, $srcBuilders, $buildersCompilers); 
    6979 
    7080        $source[]="  }\n} ?>"; 
     
    7888        return true; 
    7989    } 
    80  
    81     protected function generatePHPContent($doc, &$source, &$srcBuilders, &$buildersCompilers){ 
    82         global $gJConfig; 
    83         if($doc->documentElement->namespaceURI != JELIX_NAMESPACE_BASE.'forms/1.0'){ 
    84            throw new jException('jelix~formserr.namespace.wrong',array($this->sourceFile)); 
    85         } 
    86  
    87         $xml = simplexml_import_dom($doc); 
    88  
    89         if (count($xml->reset) > 1 ) 
    90             throw new jException('jelix~formserr.notunique.tag',array('reset',$this->sourceFile)); 
    91  
    92         foreach($xml->children() as $controltype=>$control){ 
    93             $source[] = $this->generatePHPControl($controltype, $control); 
    94             foreach($gJConfig->_pluginsPathList_jforms as $buildername => $pluginPath) { 
    95                 $srcBuilders[$buildername][]= $buil