Changeset 29043 for main/trunk/gli


Ignore:
Timestamp:
2014-05-08T15:39:42+12:00 (10 years ago)
Author:
ak19
Message:

Second of 2 part commit for improving FormatConversion from GS2 to GS3. formatconverter.exe now takes an additional optional parameter which can be documentNode or classifierNode. This then determines what the formatconverter.exe does when it sees an If test on the existence of the numleafdocs variable, since a positive test applies only to classifierNodes, while a negative test applies only to documentNodes. Further, [link][icon][link] should output something slightly different for classifierNodes than for documentNodes.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • main/trunk/gli/src/org/greenstone/gatherer/gui/FormatConversionDialog.java

    r29034 r29043  
    6868    private static final int XMLTIDY = 0;
    6969    private static final int FORMATCONVERTER = 1;
     70    private static final int FORMATCONVERTER_DOCUMENTNODE = 2;
     71    private static final int FORMATCONVERTER_CLASSIFIERNODE = 3;
     72
    7073    // Online HTML tidy for learning usage: http://infohound.net/tidy/
    7174    private static final String[] xmltidy_cmd_args = {"tidy", "-config", Configuration.getGS3BinPath() + "tidyconfig.cfg", "-utf8", "-wrap", "0", "-raw", "-q"}; // {"tidy", "-xml", "-utf8"};
    72     private static final String[] formatconverter_cmd_args = {Configuration.getGS3BinPath() + "formatconverter", "--silent"};
     75    private static final String[] formatconverter_cmd_base_args = {Configuration.getGS3BinPath() + "formatconverter", "--silent"};
    7376
    7477    private static final Dimension SIZE = new Dimension(640,480);
     
    289292    process_exitValue = -1;
    290293
    291     if(program == XMLTIDY) {
     294    switch(program) {
     295    case XMLTIDY:
    292296        command_args = xmltidy_cmd_args;
    293     } else if(program == FORMATCONVERTER) {
    294         command_args = formatconverter_cmd_args;
    295     } else { // unknown command
     297        break;
     298    case FORMATCONVERTER:
     299        command_args = formatconverter_cmd_base_args;
     300        break;
     301    case FORMATCONVERTER_DOCUMENTNODE:
     302    case FORMATCONVERTER_CLASSIFIERNODE:
     303        command_args = new String[formatconverter_cmd_base_args.length+1];
     304        System.arraycopy(formatconverter_cmd_base_args, 0, command_args, 0, formatconverter_cmd_base_args.length);
     305        if(program == FORMATCONVERTER_DOCUMENTNODE) {
     306        command_args[command_args.length-1] = "--documentNode";     
     307        } else if(program == FORMATCONVERTER_CLASSIFIERNODE) {
     308        command_args[command_args.length-1] = "--classifierNode";       
     309        }
     310        break;
     311    default:
     312        System.err.println("*** Unrecognised program code: " + program);
    296313        return outputstr;
    297314    }
     
    381398    //System.err.println("*** Found: " + gs2formatstr);
    382399
    383     String gs3formatstr = runInteractiveProgram(FORMATCONVERTER, gs2formatstr);
    384     gs3formatstr = gs3formatstr.replace("> <", "><");
     400    // Running formatconverter. Decide on whether to pass in option --documentNode|--classifierNode
     401    int formatConverterProgramMode = formatConverterMode(i);
     402    String gs3formatstr = runInteractiveProgram(formatConverterProgramMode, gs2formatstr);
     403    gs3formatstr = gs3formatstr.replaceAll(">\\s+<", "><");
    385404
    386405    //System.err.println("*** Format is now: " + gs3formatstr);
     
    560579    }
    561580
     581    private int formatConverterMode(int i) {
     582    String docOrClassNodeType = "";
     583
     584    // Given XML of the form:
     585    // <browse|search>
     586    //   <format>
     587    //     <gsf:template match="documentNode|classifierNode" [mode=horizontal]>
     588    //       <gsf-format:gs2 />
     589    //       <gs3format/>
     590    //   </format>
     591    // </browse|search>
     592
     593    // Want to return the label: "documentNode|classifierNode"
     594
     595    Element parent = (Element)getParentNode(i); // gets parent of GS2format: <gsf:template>
     596    String nodeType = parent.getAttribute("match"); //e.g. documentNode, classifierNode, or "" if no match attr
     597
     598   
     599    if(nodeType.equals("documentNode")) {
     600        return FORMATCONVERTER_DOCUMENTNODE;       
     601    } else if(nodeType.equals("classifierNode")) {
     602        return FORMATCONVERTER_CLASSIFIERNODE;
     603    }
     604    return FORMATCONVERTER;
     605    }
    562606
    563607    private String getLabel(int i) {
Note: See TracChangeset for help on using the changeset viewer.