Changeset 24934


Ignore:
Timestamp:
01/11/12 10:05:58 (9 years ago)
Author:
davidb
Message:

Introduction of new Perl module to handle taking the JSON version of the traversed HTML tree and output it as an expeditee frame

Location:
gs3-extensions/html-to-expeditee/trunk/src
Files:
1 added
3 edited

Legend:

Unmodified
Added
Removed
  • gs3-extensions/html-to-expeditee/trunk/src/perllib/cgiactions/HtmlToExpediteeAction.pm

    r24927 r24934  
    3030use cgiactions::baseaction;
    3131
     32use ExpediteeFrameIO;
    3233use JSON;
    3334
     
    8485    my $exp_frame_tree = decode_json $json_str_utf8;
    8586   
    86 
    8787    my $output_dir = &util::filename_cat($collect_dir,$collect,"export");
    8888
     
    9292    my $frame_filename = &util::filename_cat($output_dir,"$fn.exp");
    9393
    94     if (open(FOUT,">$frame_filename")) {
    95     binmode(FOUT,":utf8");
     94    my $expeditee_frame_io = new ExpediteeFrameIO();
     95   
     96    $expeditee_frame_io->buildFrame($exp_frame_tree);
    9697
    97     print FOUT $json_str_utf8;
    98     close(FOUT);
     98#    if (open(FOUT,">$frame_filename")) {
     99#   binmode(FOUT,":utf8");
     100
     101#   print FOUT $json_str_utf8;
     102#   close(FOUT);
     103#   $gsdl_cgi->generate_message("html-to-expeditee saved frame $fn");
     104#    }
     105#    else {
     106#   $gsdl_cgi->generate_error("Failed to open $frame_filename for output");
     107#    }
     108
     109    if ($expeditee_frame_io->saveFrame($frame_filename)) {
    99110   
    100111    # write out next free frame num
    101    
     112    $expeditee_frame_io->saveNextFreeFrame($fn+1);
     113
    102114    $gsdl_cgi->generate_message("html-to-expeditee saved frame $fn");
    103115    }
  • gs3-extensions/html-to-expeditee/trunk/src/src/cgi-bin/html-to-expeditee.pl.in

    r24926 r24934  
    157157              url = "library.cgi";
    158158              url += "?c="+collect +"&a=d&d=" + docOID;
    159          }
    160          else {
     159          }
     160          else {
    161161              url = "dev";
    162162              url += "?c="+collect +"&a=d&d=" + docOID;
    163163              url += "&ed=1&dt=hierarchy";
    164          }
    165          
     164              // url += "&excerptid=gs_content";
     165          }
     166         
     167          /* load iframe with document drawn from Greenstone collection */
    166168          iframe.src = url;
    167169         
     
    200202         });
    201203
    202           var expFrameTree = htmlToExpeditee(iframeDoc.body);
     204          var gsContent = iframeDoc.getElementById("gs_content");
     205
     206          /*
     207          var gsContentPos = getElementPosition(gsContent);
     208          var pxl = gsContentPos.xl;
     209          var pxr = gsContentPos.xr;
     210          */
     211
     212          var expFrameTree = htmlToExpeditee(gsContent);
     213
    203214          var expFrame = JSON.stringify(expFrameTree);
    204215          //alert(expFrame);
     
    240251                  url += "?c="+collect +"&a=d&d=" + docOID;
    241252                  url += "&ed=1&dt=hierarchy";
     253                  // url += "&excerptid=gs_content";
    242254              }
    243255
     
    277289{
    278290
    279 #    $ENV{'QUERY_STRING'} = "a=set-import-metadata&c=espresso-music&d=HASH012d6f72cde5dc48162f4a1d.1&metaname=annotation&metapos=0&metavalue=adfadfad";
    280 #    $ENV{'QUERYSTRING'} = "a=set-import-metadata&c=espresso-music&d=HASH012d6f72cde5dc48162f4a1d.1&metaname=annotation&metapos=0&metavalue=adfadfad";
     291#    $ENV{'QUERY_STRING'} = "a=...";set-import-metadata&c=espresso-music&d=HASH012d6f72cde5dc48162f4a1d.1&metaname=annotation&metapos=0&metavalue=adfadfad";
    281292#    $ENV{'REQUEST_METHOD'} = "GET";
    282 
    283293
    284294    my $gsdl_cgi = new gsdlCGI();
  • gs3-extensions/html-to-expeditee/trunk/src/src/js/html-to-expeditee.js

    r24925 r24934  
    3131    return elem.clip.width;
    3232    } else {
    33     if (elem.style.pixelWidth) {
     33    if (elem.style && elem.style.pixelWidth) {
    3434        return elem.style.pixelWidth;
    3535    } else {
     
    4444    return elem.clip.height;
    4545    } else {
    46     if (elem.style.pixelHeight) {
     46    if (elem.style && elem.style.pixelHeight) {
    4747        return elem.style.pixelHeight;
    4848    } else {
     
    8484
    8585
     86function htmlToExpeditee(node)
     87{
     88    var nodePos = getElementPosition(node);
     89    var pxl = nodePos.xl;
     90    var pyt = nodePos.yt;
     91    var pxr = nodePos.xr;
     92    var pyb = nodePos.yb;
    8693
    87 function htmlToExpeditee(node,depth)
     94    return htmlToExpediteeRec(node, pxl,pyt, pxl,pyt,pxr,pyb, 0);
     95}
     96
     97
     98function htmlToExpediteeRec(node,baseX,baseY, pxl,pyt,pxr,pyb, depth)
    8899{
    89100    depth = (depth) ? depth : 0;
    90101
    91102    //var expSyntax = "";
    92     var jsonNode = {};
     103    var jsonNode = null;
    93104
    94105    if (node.nodeType == 3) { /* text node */
     
    99110        //expSyntax += "Text item: " + node.nodeValue + "\n";
    100111
     112            jsonNode = {};
     113
    101114        jsonNode.type = "text";
    102115        jsonNode.text = node.nodeValue;
     116
     117        jsonNode.x = pxl;
     118        jsonNode.y = pyt;
     119
    103120    }
    104121    }
     
    108125        /* need to dig out: text size, l/r/justified, font-face, type, colour */
    109126
    110         var elemName = node.Name;
    111     if (elemName != "SCRIPT") {
     127        var elemName = node.nodeName.toLowerCase();
    112128
    113        
     129    if (!elemName.match(/script/)) {
     130   
    114131        var nodePos = getElementPosition(node);
    115132        var xl = nodePos.xl;
     
    129146*/
    130147
    131         var rect = { "xl":xl, "yt":yt, "xr":xr, "yb":yb };
    132 
     148            jsonNode = {};
    133149        jsonNode.type = "rect";
    134150            jsonNode.elem = node.nodeName;
     151
     152        var rect = { "xl":xl, "yt":yt, "xr":xr, "yb":yb };
    135153        jsonNode.rect = rect;
    136154   
     
    139157        var cnode = node.firstChild;
    140158        while (cnode != null) {
    141         //expSyntax += htmlToExpeditee(cnode,depth+1); 
    142159
    143             var jsonChildNode = htmlToExpeditee(cnode,depth+1);
    144         jsonChildNodes.push(jsonChildNode); 
     160            var jsonChildNode
     161            = htmlToExpediteeRec(cnode,baseX,baseY,xl,yt,xr,yb,depth+1);
     162
     163            if (jsonChildNode != null) {
     164            jsonChildNodes.push(jsonChildNode); 
     165            }
    145166       
    146167        cnode = cnode.nextSibling;
Note: See TracChangeset for help on using the changeset viewer.