Changeset 10782

Show
Ignore:
Timestamp:
27.10.2005 15:21:33 (14 years ago)
Author:
kjdon
Message:

added in some basic {If} handling. not sure whether it covers all possibilities, but its a start

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/gsdl3/bin/script/convert_coll_from_gs2.pl

    r10658 r10782  
    481481    #convert [] to <gsf:...> 
    482482    # assume no nesting {If} or {Or} for now 
    483     #remove IFs, for now just make the first option true 
    484     #$old_format =~ s/\{If\}\{[^,]*,([^,\}]*)(,[^\}]*)?\}/$1/g; 
    485     #remove ORs, for now just make the first option true 
    486483    $old_format =~ s/\{If\}\{([^\}]*)\}/&format_if($1, $node_type)/eg; 
    487484    $old_format =~ s/\{Or\}\{([^\}]*)\}/&format_or($1)/eg; 
    488     # $old_format =~ s/\{Or\}\{([^,]*),[^\}]*\}/$1/g; 
    489485    $old_format =~ s/\[Text\]/\<gsf:text\/\>/g; 
    490486    $old_format =~ s/\[num\]/\<gsf:num\/\>/g; 
    491     $old_format =~ s/\[link\]/\<gsf:link\>/g; 
     487    $old_format =~ s/\[link\]/\<gsf:link type=\'$node_type\'\>/g; 
    492488    $old_format =~ s/\[\/link\]/\<\/gsf:link\>/g; 
    493489    $old_format =~ s/\[srclink\]/\<gsf:link type=\'source\'\>/g; 
    494490    $old_format =~ s/\[\/srclink\]/\<\/gsf:link\>/g; 
    495     $old_format =~ s/\[icon\]/\<gsf:icon\/\>/g; 
     491    $old_format =~ s/\[icon\]/\<gsf:icon type=\'$node_type\'\/\>/g; 
    496492    $old_format =~ s/\[srcicon\]/\<gsf:icon type=\'source\'\/\>/g; 
    497493           
     
    501497    #now do the rest of the [] which are assumed to be metadata 
    502498    $old_format =~ s/\[([^\]]*)\]/&format_metadata($1)/eg; 
    503  #   $old_format =~ s/\[([^\]]*\:)?([^\]\:]*)\]/\<gsf:metadata name=\'$2\' select=\'$1\'\/\>/g; 
    504  #   # remove ex. 
    505  #   $old_format =~ s/<gsf:metadata name=\'ex\.([^\']+)\'/<gsf:metadata name=\'$1\'/g; 
    506  #   #do the parent stuff 
    507  #   $old_format =~ s/(select=\'parent)\:\'/$1\'/g; 
    508  #   $old_format =~ s/select=\'parent\(Top\)\:\'/select=\'root\'/g; 
    509  #   $old_format =~ s/select=\'parent\(All\)\:\'/select=\'ancestors\'/g; 
    510  #   $old_format =~ s/select=\'parent\(All\'([^\']*)\'\)\:\'/select=\'ancestors\' separator=\'$1\'/g; 
    511  #   #remove any select='' 
    512  #   $old_format =~ s/select=\'\'//g; 
    513499   
    514500    # some html tidy 
     
    553539    $metadata_string =~ s/^\((Top|All)\)?//; 
    554540    if ($scope) { 
    555         ($delim) = $metadata_string =~ /^:\'([^\']*)\'\)/; 
    556         $metadata_string =~ s/^:\'([^\']*)\'\)//; 
     541        ($delim) = $metadata_string =~ /^\'([^\']*)\'\)/; 
     542        $metadata_string =~ s/^\'([^\']*)\'\)//; 
    557543    }  
    558544    } 
     
    594580 
    595581    my ($if_string, $node_type) = @_; 
    596  
    597     return "if statement to go here"; 
     582    #print STDERR "if string = $if_string\n"; 
     583 
     584    my @parts = split /,/, $if_string;  
     585    my $test = $parts[0]; 
     586    my $true_option = $parts[1]; 
     587    my $false_option; 
     588    if (scalar (@parts) == 3) { 
     589    $false_option = $parts[2]; 
     590    } 
     591    $test =~ s/^\s*//; 
     592    $test =~ s/\s*$//; 
     593    my ($test_meta, $test_type, $test_value); 
     594    if ($test =~ /^(\[.+\])$/) { 
     595    $test_meta = $1; 
     596    $test_type = 'exists'; 
     597    } else { 
     598    my ($lhs, $exp, $rhs) = $test =~ /^(.+)\s+(eq|ne|lt|gt|le|ge|sw|ew)\s+(.+)$/; 
     599    #print STDERR "lhs, exp, rhs = $lhs, $exp, $rhs\n"; 
     600    if ($exp eq "eq") { 
     601        $test_type = "equals"; 
     602    } elsif ($exp eq "sw") { 
     603        $test_type = "startsWith"; 
     604    } elsif ($exp eq "ew") { 
     605        $test_type = "endsWith"; 
     606    } elsif ($exp eq "ne") { 
     607        $test_type = "notEquals"; 
     608    } elsif ($exp eq "lt") { 
     609        $test_type = "lessThan"; 
     610    }elsif ($exp eq "gt") { 
     611        $test_type = "greaterThan"; 
     612    }elsif ($exp eq "le") { 
     613        $test_type = "lessThanOrEquals"; 
     614    }elsif ($exp eq "ge") { 
     615        $test_type = "greaterThanOrEquals"; 
     616    } 
     617    if ($lhs =~ /^\[.+\]$/) { 
     618        $test_meta = $lhs; 
     619        $test_value = $rhs; 
     620    } else { 
     621        # assume rhs has meta 
     622        $test_meta = $rhs; 
     623        $test_value = $lhs; 
     624    } 
     625     
     626    #remove beginning and end quotes 
     627    $test_value =~ s/^[\'\"]//; 
     628    $test_value =~ s/[\'\"]$//; 
     629    } 
     630    my $test_atts = "test='$test_type' "; 
     631    if (defined $test_value) { 
     632    $test_atts .= "test-value='$test_value' "; 
     633    } 
     634    #print STDERR "test, true, false = $test, $true_option, $false_option\n"; 
     635    my $new_format = "<gsf:switch>$test_meta"; 
     636    $new_format .= "<gsf:when $test_atts>$true_option</gsf:when>"; 
     637    if (defined $false_option) { 
     638    $new_format .="<gsf:otherwise>$false_option</gsf:otherwise>"; 
     639    } 
     640    $new_format .= "</gsf:switch>"; 
     641     
     642    #print STDERR "new format = $new_format\n"; 
     643    return $new_format; 
    598644} 
    599645