Changeset 28995

Show
Ignore:
Timestamp:
24.04.2014 21:34:33 (5 years ago)
Author:
ak19
Message:

First commit for GLI part of GS2 to GS3 Format Conversion. Contains all the changes needed for the FormatConversionDialog? to work, and some cosmetic changes to cdm.Format4gs3Manager.java. Still need to implement undo and redo and think about what needs to happen and how for Remote GS3.

Location:
main/trunk/gli/src/org/greenstone/gatherer
Files:
1 added
5 modified

Legend:

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

    r22340 r28995  
    697697    } 
    698698 
     699    static public String getGS3BinPath() { 
     700    return gsdl3_src_path + "bin" + File.separator; 
     701    } 
     702 
    699703    /** Remove a previously defined special directory mapping. 
    700704     * @param name The name of the mapping to remove as a <strong>String</strong>. 
  • main/trunk/gli/src/org/greenstone/gatherer/cdm/Format4gs3Manager.java

    r26356 r28995  
    389389    } 
    390390 
    391     private String removeSurrondingTags(String xml) 
     391    private String removeSurroundingTags(String xml) 
    392392    { 
    393393      return xml.replace("<ROOTELEMENT>\n", "").replace("<ROOTELEMENT>", "").replace("</ROOTELEMENT>", "").replace("<ROOTELEMENT/>",""); 
     
    732732                        StringBuffer sb = new StringBuffer(); 
    733733                        XMLTools.xmlNodeToString(sb, formatElem, true, "  ", 0); 
    734                         editor_textarea.setText(removeSurrondingTags(sb.toString())); 
     734                        editor_textarea.setText(removeSurroundingTags(sb.toString())); 
    735735                    } 
    736736                    else 
     
    817817                            StringBuffer sb = new StringBuffer(); 
    818818                            XMLTools.xmlNodeToString(sb, formatElem, true, "  ", 0); 
    819                             editor_textarea.setText(removeSurrondingTags(sb.toString())); 
     819                            editor_textarea.setText(removeSurroundingTags(sb.toString())); 
    820820                        } 
    821821                        else 
  • main/trunk/gli/src/org/greenstone/gatherer/gui/OpenCollectionDialog.java

    r23238 r28995  
    4343import org.greenstone.gatherer.shell.GShellListener; 
    4444import org.greenstone.gatherer.shell.GShellProgressMonitor; 
     45 
    4546 
    4647/** A dialog which provides a straight-forward access to the currently installed collections. It also will contain the ability to continue through to the original OpenCollectionDialog if your source collection is located somewhere other than the gsdl collect folder. */ 
     
    399400        process.run(); // Don't bother threading this... yet 
    400401         
    401         collect_cfg_file.delete(); 
    402         build_cfg_file.delete(); 
     402        // From now, won't dangerously delete GS2 collect and build config files anymore 
     403        //collect_cfg_file.delete(); 
     404        //build_cfg_file.delete(); 
     405 
     406        File collect_bak_file = new File(collection_folder.getAbsolutePath() + File.separator + "etc" + File.separator + "collect.cfg.bak"); 
     407        File build_bak_file = new File(collection_folder.getAbsolutePath() + File.separator+"index" + File.separator + "build.cfg.bak"); 
     408        if(!collect_cfg_file.renameTo(collect_bak_file)) { 
     409            System.err.println("Unable to move collect.cfg to " + collect_bak_file); 
     410        } 
     411        if(!build_cfg_file.renameTo(build_bak_file)) { 
     412            System.err.println("Unable to move build.cfg to " + build_bak_file); 
     413        } 
    403414        } 
    404415    } 
     
    415426        //**************** 
    416427        File collect_cfg_file = collection_configuration.getFile(); // returns the collect.cfg file 
    417         File etc_folder = collect_cfg_file.getParentFile(); 
    418         File collection_folder = etc_folder.getParentFile(); 
    419         filename = collection_folder.getAbsolutePath() + File.separator + "gli.col"; 
    420         collection_folder = null; 
    421         etc_folder = null; 
    422         collect_cfg_file = null; 
    423         collection_configuration = null; 
     428        result = FormatConversionDialog.checkForGS2FormatStatements(collect_cfg_file); 
     429        if(result == OK_OPTION) { // either there were no gs2 format stmts or user chose to proceed 
     430            File etc_folder = collect_cfg_file.getParentFile(); 
     431            File collection_folder = etc_folder.getParentFile(); 
     432            filename = collection_folder.getAbsolutePath() + File.separator + "gli.col"; 
     433            collection_folder = null; 
     434            etc_folder = null; 
     435            collect_cfg_file = null; 
     436            collection_configuration = null; 
     437        } 
    424438        OpenCollectionDialog.this.dispose(); 
    425439        } 
    426440 
    427         Gatherer.collectDirectoryHasChanged(Gatherer.getCollectDirectoryPath(),  
     441        if(result == OK_OPTION) { 
     442        Gatherer.collectDirectoryHasChanged(Gatherer.getCollectDirectoryPath(),  
    428443                newCollectPath, Gatherer.g_man.getContentPane());  
    429444            // will tell the server that the collect directory has changed and that 
    430445            // the workspace needs to be refreshed (Documents in Greenstone Collections) 
     446        } 
    431447    } 
    432448    } 
  • main/trunk/gli/src/org/greenstone/gatherer/util/Codec.java

    r8243 r28995  
    4141    static final public String ENCODE_PATH = "ENCODE_PATH"; 
    4242    static final public String ENCODE_SQUARE_BRACKETS = "ENCODE_SQUARE_BRACKETS"; 
     43    static final public String ESCAPEDHTML_TO_UNESCAPED = "ESCAPEDHTML_TO_UNESCAPED"; 
    4344    static final public String GREENSTONE_TO_DOM = "GREENSTONE_TO_DOM"; 
    4445    static final public String GREENSTONE_TO_TEXT = "GREENSTONE_TO_TEXT"; 
     
    168169    TRANSFORMS.put(TEXT_TO_DOM, text_to_dom); 
    169170    text_to_dom = null; 
     171 
     172    // Unescape html (or xml) text 
     173    String[] escapedhtml_to_unescaped = { 
     174        "&amp;", "&", 
     175        "&lt;", "<",  
     176        "&gt;", ">", 
     177        "&quot;", "\""//, 
     178        //"&apos;", "\'" 
     179    }; 
     180    TRANSFORMS.put(ESCAPEDHTML_TO_UNESCAPED, escapedhtml_to_unescaped); 
     181    escapedhtml_to_unescaped = null; 
    170182 
    171183    // Transform plain html text into greenstone encoding 
  • main/trunk/gli/src/org/greenstone/gatherer/util/XMLTools.java

    r26354 r28995  
    2222 
    2323// JAXP 
     24import javax.xml.parsers.DocumentBuilder; 
     25import javax.xml.parsers.DocumentBuilderFactory; 
    2426import javax.xml.parsers.FactoryConfigurationError; 
    2527import javax.xml.parsers.ParserConfigurationException; 
    2628import javax.xml.parsers.SAXParser; 
    2729import javax.xml.parsers.SAXParserFactory; 
     30 
    2831 
    2932/** This class is a static class containing useful XML functions */ 
     
    331334    static final private String HEADER = "<?xml version='1.0' encoding='UTF-8'?><collectionConfig xmlns:gsf='http://www.greenstone.org/greenstone3/schema/ConfigFormat' xmlns:xsl='http://www.w3.org/1999/XSL/Transform'>"; 
    332335    static final private String FOOTER = "</collectionConfig>"; 
     336 
     337 
     338    public static Document getDOM(String xml_str)  
     339    {    
     340    Document doc = null; 
     341    try { 
     342        /*SAXParserFactory factory = SAXParserFactory.newInstance(); 
     343        factory.setNamespaceAware(true); 
     344        //factory.setValidating (true); 
     345        SAXParser parser = factory.newSAXParser(); 
     346        InputSource iSource = new InputSource(new StringReader(xml_str)); 
     347        //              parser.parse (iSource, new DefaultHandler ()); 
     348         
     349        org.xml.sax.XMLReader reader = parser.getXMLReader(); 
     350        reader.setContentHandler(new DefaultHandler()); 
     351        reader.setErrorHandler(new DefaultHandler()); 
     352        doc = reader.parse(iSource); 
     353        */ 
     354 
     355        DocumentBuilder db = DocumentBuilderFactory.newInstance().newDocumentBuilder(); 
     356        InputSource is = new InputSource(); 
     357        is.setCharacterStream(new StringReader(xml_str)); 
     358        doc = db.parse(is); 
     359 
     360    } catch (Exception e) { 
     361        e.printStackTrace(); 
     362    } 
     363    return doc;  
     364    } 
    333365 
    334366    public static String parse(String xml_str) 
     
    9911023    public static void xmlNodeToString(StringBuffer sb, Node e, boolean indent, String indentString, int depth) 
    9921024    { 
    993         if (e.getNodeType() == Node.TEXT_NODE) 
     1025 
     1026        if (e.getNodeType() == Node.CDATA_SECTION_NODE) 
     1027        { 
     1028            if (e.getNodeValue() != "") 
     1029            { 
     1030                String text = e.getNodeValue();              
     1031                sb.append("<![CDATA["); 
     1032                sb.append(text); 
     1033                sb.append("]]>"); 
     1034            } 
     1035            return; 
     1036        } 
     1037 
     1038        if (e.getNodeType() == Node.TEXT_NODE) 
    9941039        { 
    9951040            if (e.getNodeValue() != "") 
     
    10571102                hasElements = true; 
    10581103            } 
    1059             if (children.item(i).getNodeType() == Node.TEXT_NODE && indent) 
     1104            if ((children.item(i).getNodeType() == Node.TEXT_NODE || children.item(i).getNodeType() == Node.CDATA_SECTION_NODE) && indent) 
    10601105            { 
    10611106                if (children.item(i).getNodeValue().trim().length() > 0)