Changeset 6069


Ignore:
Timestamp:
2003-12-01T19:52:02+13:00 (20 years ago)
Author:
jmt12
Message:

Have rearranged where and how strings are feed through the Codec. After several hours work and a dozen paper trials I discovered the TEXT_TO_DOM conversion was completely pointless (DOM does it itself). Also the quotes only need to be dealt to if they are being sent to the collect.cfg file. Hopefully I've got it all going now - including using that pesky pipe character that I would rather not have to deal with. And everything seems to be ok - I tested all the dangerous characters including square brackets and amperstamp. I also tried hierarchies, and then as the piece'd'resistance I tried a hierarchies with dangerous characters. All good. I'm all about the working metadata.

Location:
trunk/gli/src/org/greenstone/gatherer
Files:
6 edited

Legend:

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

    r6051 r6069  
    231231       private String value = null;
    232232
    233        private AppendMetadataTask(ElementWrapper element, String value) {
     233       private AppendMetadataTask(ElementWrapper element, String raw_value) {
    234234      this.element = element;
     235      this.value = raw_value;
    235236      // Transform the raw text to be GREENSTONE and DOM compatible - as that will be its next destination immediately after being added to the value model
    236       this.value = Codec.transform(value, Codec.ENCODE_PATH);
    237       this.value = Codec.transform(this.value, Codec.REMOVE_SQUARE_BRACKET);
    238       this.value = Codec.transform(this.value, Codec.TEXT_TO_DOM);
     237      //this.value = /odec.transform(value, /odec.ENCODE_PATH);
     238      //this.value = /odec.transform(this.value, /odec.REMOVE_SQUARE_BRACKET);
     239      //this.value = /odec.transform(this.value, /odec.TEXT_TO_DOM);
    239240       }
    240241
     
    267268       private String value;
    268269
    269     private UpdateMetadataTask(ElementWrapper element, String value) {
     270    private UpdateMetadataTask(ElementWrapper element, String raw_value) {
    270271      this.element = element;
     272      this.value = raw_value;
    271273      // Transform the raw text to be DOM compatible - as that will be its next destination immediately after being added to the value model
    272       this.value = Codec.transform(value, Codec.REMOVE_SQUARE_BRACKET);
    273       this.value = Codec.transform(this.value, Codec.TEXT_TO_DOM);
     274      //this.value = /odec.transform(value, /odec.REMOVE_SQUARE_BRACKET);
     275      //this.value = /odec.transform(this.value, /odec.TEXT_TO_DOM);
    274276    }
    275277
     
    11031105        JPanel value_field_pane = new JPanel();
    11041106        TransformCharacterTextField value_init = new TransformCharacterTextField();
    1105         value_init.replaceCharacter(StaticStrings.PIPE_CHAR, StaticStrings.FORWARDSLASH_CHAR);
     1107        //value_init.replaceCharacter(StaticStrings.PIPE_CHAR, StaticStrings.FORWARDSLASH_CHAR);
    11061108        value = value_init;
    11071109        value_init = null;
     
    11891191
    11901192    public String getSelectedValue() {
    1191         return Codec.transform(Codec.transformUnicode(value.getText()), Codec.TEXT_TO_GREENSTONE);
     1193        //return /odec.transform(/odec.transformUnicode(value.getText()), /odec.TEXT_TO_GREENSTONE);
     1194        String raw_value = value.getText();
     1195        raw_value = Codec.transformUnicode(raw_value);
     1196        raw_value = Codec.transform(raw_value, Codec.ENCODE_PATH);
     1197        raw_value = Codec.transform(raw_value, Codec.ENCODE_SQUARE_BRACKETS);
     1198        return raw_value;
    11921199    }
    11931200
     
    12561263        // Setting the text of the field causes the DocumentListener to be notified, and
    12571264        //   updating the tree is handled there (DocumentListenerImpl::validate())
    1258         ///ystem.err.println("Setting selected value to: " + val);
    12591265        if (!card_showing.equals(NONE)) {
     1266        // Decode val
     1267        //System.err.println("Before transforms: " + val);
     1268        //val = Codec.transform(val, Codec.DECODE_SQUARE_BRACKETS);
     1269        //val = Codec.transform(val, Codec.DECODE_PATH);
     1270        //System.err.println("Setting selected value to: " + val);
    12601271        manual_text_edit_event = val.equals("");  // Set to false unless val == ""
    1261         value.setText(Codec.transform(val, Codec.GREENSTONE_TO_TEXT));
     1272        value.setText(val); ///odec.transform(val, /odec.GREENSTONE_TO_TEXT));
    12621273        value.setCaretPosition(0);
    12631274        manual_text_edit_event = true;
     
    12691280    private TreePath getClosestPath(String val)
    12701281    {
     1282        System.err.println("Select closest path to: " + val);
    12711283        // Start at the root of the tree
    12721284        GValueNode tree_node = (GValueNode) tree.getModel().getRoot();
    12731285
    1274         // Hierarchical values are separated using '\'
    1275         PatternTokenizer tokenizer = new PatternTokenizer(val, "\\");  // StaticStrings.PIPE_STR);
     1286        // Hierarchical values are separated using '|'
     1287        PatternTokenizer tokenizer = new PatternTokenizer(val, StaticStrings.PIPE_STR);
    12761288        while (tokenizer.hasMoreTokens()) {
    12771289        String token = tokenizer.nextToken();
     
    13361348            TreePath path = tree.getSelectionPath();
    13371349            GValueNode node = (GValueNode) path.getLastPathComponent();
    1338             value.setText(node.getFullPath(true));
     1350            String val = node.getFullPath(true);
     1351            System.err.println("Setting value to: " + val);
     1352            value.setText(val);
     1353            val = null;
    13391354            }
    13401355        }
     
    13741389        private void validate()
    13751390        {
    1376         String value_text = Codec.transform(getSelectedValue(), Codec.TEXT_TO_DOM);
     1391        String value_text = getSelectedValue(); ///odec.transform(getSelectedValue(), /odec.TEXT_TO_DOM);
    13771392        ///ystem.err.println("\n(Validate) Value text: " + value_text);
    13781393
  • trunk/gli/src/org/greenstone/gatherer/msm/GDMDocument.java

    r6051 r6069  
    190190        String node_value = null;
    191191        if(model != null && model.isHierarchy()) {
    192             node_value = Codec.transform(metadata.getValueNode().getFullPath(false), Codec.TEXT_TO_DOM);
     192            //node_value = /odec.transform(metadata.getValueNode().getFullPath(false), /odec.TEXT_TO_DOM);
     193            node_value = metadata.getValueNode().getFullPath(false);
    193194        }
    194195        else {
    195             node_value = metadata.getAbsoluteValue();
    196         }
    197         ///ystem.err.println("Creating node in GDMDocument: '" + node_value + "'");
     196            node_value = metadata.getAbsoluteValue();
     197        }
     198        System.err.println("Creating node in GDMDocument: '" + node_value + "'");
    198199        metadata_element.appendChild(base_document.createTextNode(node_value));
    199200        // Retrieve the first description element for this fileset (there should only be one, but I'll play it safe).
     
    253254    return getMetadata(filename, remove, metadatum_so_far, file, append_folder_level, false);
    254255    }
    255     /** Retrieve the metadata associated with the given filename. Keep track of what metadata should be overwritten and what should be accumulated. Also make note of the source file, and remove the metadata if required. Finally if purge is set retrieve every piece of metadata in this file. */
    256     public ArrayList getMetadata(String filename, boolean remove, ArrayList metadatum_so_far, File file, boolean append_folder_level, boolean purge) {
     256    /** Retrieve the metadata associated with the given filename. Keep track of what metadata should be overwritten and what should be accumulated. Also make note of the source file, and remove the metadata if required. Finally if purge is set retrieve every piece of metadata in this file. */
     257    public ArrayList getMetadata(String filename, boolean remove, ArrayList metadatum_so_far, File file, boolean append_folder_level, boolean purge) {
    257258    Gatherer.println("Get metadata for " + filename);
    258259    ArrayList metadatum = null;
    259260    if(metadatum_so_far == null) {
    260         metadatum = new ArrayList();
     261        metadatum = new ArrayList();
    261262    }
    262263    else {
    263         metadatum = metadatum_so_far;
     264        metadatum = metadatum_so_far;
    264265    }
    265266    try {
    266         // Retrieve the document element.
    267         Element directorymetadata_element = base_document.getDocumentElement();
    268         // Iterate through the filesets, checking the FileName child element against    the target file's name using regular expression matching.
    269         NodeList fileset_elements = directorymetadata_element.getElementsByTagName(FILESET_ELEMENT);
    270         for(int i = 0; i < fileset_elements.getLength(); i++) {
     267        // Retrieve the document element.
     268        Element directorymetadata_element = base_document.getDocumentElement();
     269        // Iterate through the filesets, checking the FileName child element against    the target file's name using regular expression matching.
     270        NodeList fileset_elements = directorymetadata_element.getElementsByTagName(FILESET_ELEMENT);
     271        for(int i = 0; i < fileset_elements.getLength(); i++) {
    271272        Element fileset_element = (Element) fileset_elements.item(i);
    272273        NodeList filename_elements = fileset_element.getElementsByTagName(FILENAME_ELEMENT);
    273274        for(int j = 0; j < filename_elements.getLength(); j++) {
    274             Element filename_element = (Element) filename_elements.item(j);
    275             String filename_text = MSMUtils.getValue(filename_element);
    276             if((filename != null && (filename.matches(filename_text) || (append_folder_level && filename.indexOf(File.separator) != -1 && filename_text.equals(filename.substring(0, filename.indexOf(File.separator)))))) || ((filename == null || append_folder_level) && filename_text.equals(DIRECTORY_FILENAME)) || purge) {
     275            Element filename_element = (Element) filename_elements.item(j);
     276            String filename_text = MSMUtils.getValue(filename_element);
     277            if((filename != null && (filename.matches(filename_text) || (append_folder_level && filename.indexOf(File.separator) != -1 && filename_text.equals(filename.substring(0, filename.indexOf(File.separator)))))) || ((filename == null || append_folder_level) && filename_text.equals(DIRECTORY_FILENAME)) || purge) {
    277278            // If they match add all of the metadata found in the Description child element, remembering to abide by desired mode (accumulate vs. overwrite).
    278279            // Normal metadata
    279280            NodeList description_elements = fileset_element.getElementsByTagName(DESCRIPTION_ELEMENT);
    280281            for(int k = 0; k < description_elements.getLength(); k++) {
    281                 Element description_element = (Element) description_elements.item(k);
    282                 // We have to do this for each type of metadata
    283                 for(int z = 0; z < ALL_METADATA_TYPES.length; z++) {
    284                     NodeList metadata_elements = description_element.getElementsByTagName(ALL_METADATA_TYPES[z]);
    285                     for(int l = 0; l < metadata_elements.getLength(); l++) {
    286                          Element metadata_element = (Element) metadata_elements.item(l);
    287                          String raw_element = metadata_element.getAttribute(StaticStrings.NAME_ATTRIBUTE);
    288                          //String language = metadata_element.getAttribute("language");
    289                          String mode = metadata_element.getAttribute(MODE_ATTRIBUTE);
    290                          String raw_value = MSMUtils.getValue(metadata_element);
    291                          // Raw value is in GREENSTONE form, convert to DOM
    292                          raw_value = Codec.transform(raw_value, Codec.GREENSTONE_TO_DOM);
    293                          // ***** LEGACY SUPPORT *****
    294                          // If this raw_value contains a '\' character, but no '\\', '[' or ']' characters, then replace the '\' with a '\\'
    295                          if(raw_value.indexOf(StaticStrings.ESCAPE_STR) != -1) {
    296                              Gatherer.println("Detected Legacy Path: " + raw_value);
    297                              raw_value = raw_value.replaceAll(StaticStrings.ESCAPE_PATTERN, StaticStrings.PIPE_STR);
    298                              Gatherer.println("Updated Path To: " + raw_value);
    299                              MSMUtils.setValue(metadata_element, raw_value);
    300                          }
    301                          // **************************
    302                          // Using the element string and value, retrieve a matching Metadata object from the cache
    303                          Metadata metadata = null;
    304                          // If this element has hierarchy values then we must ensure the raw value is a full path, not an index.
    305                          // Try to retrieve an already comstructed piece of metadata from file - but not if we are purging, as this will stuff up anything that is still using that metadata - such as the GTable
    306                          if(GDMManager.metadata_cache.contains(raw_element, raw_value) && !purge) {
    307                              ///ystem.err.println("HIT! Retrieve metadata from cache: " + raw_element + " -> " + raw_value + "\n");
    308                              metadata = (Metadata) GDMManager.metadata_cache.get(raw_element, raw_value);
    309                          }
    310                          else {
    311                              ElementWrapper element = Gatherer.c_man.getCollection().msm.getElement(raw_element);
    312                              if (element != null) {
    313                                  GValueNode value = Metadata.getDefaultValueNode(element, raw_value);
    314                                  ///ystem.err.println("Miss. Create new metadata: " + raw_element + " -> " + raw_value + "\n");
    315                                  metadata = new Metadata(element, value);
    316                                  if(!purge) {
    317                                      GDMManager.metadata_cache.put(raw_element, raw_value, metadata);
    318                                  }
    319                                  ///ystem.err.println("Added metadata to cache: " + raw_element + " -> " + raw_value + "\n");
    320                                  value = null;
    321                                  element = null;
    322                              }
    323                          }
    324                          // check whether the metadata is null
    325                          if (metadata != null) {
    326                              // We determine whether this metadata is file or folder level
    327                              if(filename != null) {
    328                                  ///ystem.err.println("Filename   = " + filename);
    329                                  ///ystem.err.println("filename_text = " + filename_text);
    330                                  // If can only be file level if there is no folder path details in filename and if the filename matched the filename text node (it may have matched .* instead)!
    331                                  if(filename.indexOf(File.separator) == -1 && filename.equals(filename_text)) {
    332                                      metadata.setFileLevel(true);
    333                                      ///ystem.err.println("File level!!!");
    334                                  }
    335                                  else {
    336                                      metadata.setFileLevel(false);
    337                                      ///ystem.err.println("Inherited!!!");
    338                                  }
    339                              }
    340                              else {
    341                                  ///ystem.err.println("Filename is null therefore this is file level metadata.");
    342                                  metadata.setFileLevel(true);
    343                              }
    344                              metadata.setFile(file);
    345                              // If mode is overwrite, then remove any previous values for this metadata element.
    346                              if(mode.equals("accumulate")) {
    347                                  metadata.setAccumulate(true);
    348                              }
    349                              else {
    350                                  metadata.setAccumulate(false);
    351                                  ///ystem.err.println("Metadata overwrites: " + metadata);
    352                                  for(int m = metadatum.size() - 1; m >= 0; m--) {
    353                                      Metadata old_metadata = (Metadata) metadatum.get(m);
    354                                      if(old_metadata.getElement().equals(metadata.getElement())) {
    355                                          metadatum.remove(m);
    356                                          ///ystem.err.println("Removing overridden metadata: " + old_metadata);
    357                                      }
    358                                      old_metadata = null;
    359                                  }
    360                              }
    361                              mode = null;
    362                              // Add the completed metadata and clean up
    363                              ///ystem.err.println("Adding metadata: " + metadata);
    364                              metadatum.add(metadata);
    365                              // Having found our metadata check if the value from the xml matches the one from the gvaluenode. If not update it. This happens whenever hierarchy information is involved (indexes rapidly become obsolete).
    366                              // If remove was set, remove it. We can only remove pure file level metadata, or folder level iff we were asked for folder level.
    367                              if(remove && ((filename != null && filename.matches(filename_text) && !filename_text.equals(DIRECTORY_FILENAME)) || (filename == null && filename_text.equals(DIRECTORY_FILENAME)))) {
    368                                  ///ystem.err.println("Removing " + metadata + " from " + file);
    369                                  description_element.removeChild(metadata_element);
    370                                  // Remove the description element if empty.
    371                                  if(!description_element.hasChildNodes()) {
    372                                      fileset_element.removeChild(description_element);
    373                                  }
    374                              }
    375                              else {
    376                                  //String current_value = metadata.getAbsoluteValue();
    377                                  String current_value = Codec.transform(metadata.getValueNode().getFullPath(false), Codec.TEXT_TO_DOM);
    378                                  ///ystem.err.println("Checking the current hfile: " + current_value);
    379                                  ///ystem.err.println("Against whats in the hfile: " + current_value);
    380                                  if(!raw_value.equals(current_value)) {
    381                                      // Remove old text
    382                                      while(metadata_element.hasChildNodes()) {
    383                                          metadata_element.removeChild(metadata_element.getFirstChild());
    384                                      }
    385                                      // Add new.
    386                                      metadata_element.appendChild(base_document.createTextNode(current_value));
    387                                  }
    388                              }
    389                          }
    390                          metadata = null;
    391                          raw_value = null;
    392                          raw_element = null;
    393                          metadata_element = null;
    394                      }
    395                      metadata_elements = null;
     282                Element description_element = (Element) description_elements.item(k);
     283                // We have to do this for each type of metadata
     284                for(int z = 0; z < ALL_METADATA_TYPES.length; z++) {
     285                NodeList metadata_elements = description_element.getElementsByTagName(ALL_METADATA_TYPES[z]);
     286                for(int l = 0; l < metadata_elements.getLength(); l++) {
     287                    Element metadata_element = (Element) metadata_elements.item(l);
     288                    String raw_element = metadata_element.getAttribute(StaticStrings.NAME_ATTRIBUTE);
     289                    //String language = metadata_element.getAttribute("language");
     290                    String mode = metadata_element.getAttribute(MODE_ATTRIBUTE);
     291                    String raw_value = MSMUtils.getValue(metadata_element);
     292                    //
     293                    //raw_value = Codec.transform(raw_value, Codec.DOM_TO_);
     294                    ///ystem.err.println("Retrieved raw value: " + raw_value);
     295                    // ***** LEGACY SUPPORT *****
     296                    // If this raw_value contains a '\' character, but no '\\', '[' or ']' characters, then replace the '\' with a '\\'
     297                    if(raw_value.indexOf(StaticStrings.ESCAPE_STR) != -1) {
     298                    ///ystem.err.println("Blarg");
     299                    Gatherer.println("Detected Legacy Path: " + raw_value);
     300                    raw_value = raw_value.replaceAll(StaticStrings.ESCAPE_PATTERN, StaticStrings.PIPE_STR);
     301                    Gatherer.println("Updated Path To: " + raw_value);
     302                    MSMUtils.setValue(metadata_element, raw_value);
     303                    }
     304                    // **************************
     305                    // Using the element string and value, retrieve a matching Metadata object from the cache
     306                    Metadata metadata = null;
     307                    // If this element has hierarchy values then we must ensure the raw value is a full path, not an index.
     308                    // Try to retrieve an already comstructed piece of metadata from file - but not if we are purging, as this will stuff up anything that is still using that metadata - such as the GTable
     309                    if(GDMManager.metadata_cache.contains(raw_element, raw_value) && !purge) {
     310                    ///ystem.err.println("HIT! Retrieve metadata from cache: " + raw_element + " -> " + raw_value + "\n");
     311                    metadata = (Metadata) GDMManager.metadata_cache.get(raw_element, raw_value);
     312                    }
     313                    else {
     314                    ElementWrapper element = Gatherer.c_man.getCollection().msm.getElement(raw_element);
     315                    if (element != null) {
     316                        GValueNode value = Metadata.getDefaultValueNode(element, raw_value);
     317                        ///ystem.err.println("Miss. Create new metadata: " + raw_element + " -> " + raw_value + "\n");
     318                        metadata = new Metadata(element, value);
     319                        if(!purge) {
     320                        GDMManager.metadata_cache.put(raw_element, raw_value, metadata);
     321                        }
     322                        ///ystem.err.println("Added metadata to cache: " + raw_element + " -> " + raw_value + "\n");
     323                        value = null;
     324                        element = null;
     325                    }
     326                    }
     327                    // check whether the metadata is null
     328                    if (metadata != null) {
     329                    // We determine whether this metadata is file or folder level
     330                    if(filename != null) {
     331                        ///ystem.err.println("Filename    = " + filename);
     332                        ///ystem.err.println("filename_text = " + filename_text);
     333                        // If can only be file level if there is no folder path details in filename and if the filename matched the filename text node (it may have matched .* instead)!
     334                        if(filename.indexOf(File.separator) == -1 && filename.equals(filename_text)) {
     335                        metadata.setFileLevel(true);
     336                        ///ystem.err.println("File level!!!");
     337                        }
     338                        else {
     339                        metadata.setFileLevel(false);
     340                        ///ystem.err.println("Inherited!!!");
     341                        }
     342                    }
     343                    else {
     344                        ///ystem.err.println("Filename is null therefore this is file level metadata.");
     345                        metadata.setFileLevel(true);
     346                    }
     347                    metadata.setFile(file);
     348                    // If mode is overwrite, then remove any previous values for this metadata element.
     349                    if(mode.equals("accumulate")) {
     350                        metadata.setAccumulate(true);
     351                    }
     352                    else {
     353                        metadata.setAccumulate(false);
     354                        ///ystem.err.println("Metadata overwrites: " + metadata);
     355                        for(int m = metadatum.size() - 1; m >= 0; m--) {
     356                        Metadata old_metadata = (Metadata) metadatum.get(m);
     357                        if(old_metadata.getElement().equals(metadata.getElement())) {
     358                            metadatum.remove(m);
     359                            ///ystem.err.println("Removing overridden metadata: " + old_metadata);
     360                        }
     361                        old_metadata = null;
     362                        }
     363                    }
     364                    mode = null;
     365                    // Add the completed metadata and clean up
     366                    ///ystem.err.println("Adding metadata: " + metadata);
     367                    metadatum.add(metadata);
     368                    // Having found our metadata check if the value from the xml matches the one from the gvaluenode. If not update it. This happens whenever hierarchy information is involved (indexes rapidly become obsolete).
     369                    // If remove was set, remove it. We can only remove pure file level metadata, or folder level iff we were asked for folder level.
     370                    if(remove && ((filename != null && filename.matches(filename_text) && !filename_text.equals(DIRECTORY_FILENAME)) || (filename == null && filename_text.equals(DIRECTORY_FILENAME)))) {
     371                        ///ystem.err.println("Removing " + metadata + " from " + file);
     372                        description_element.removeChild(metadata_element);
     373                        // Remove the description element if empty.
     374                        if(!description_element.hasChildNodes()) {
     375                        fileset_element.removeChild(description_element);
     376                        }
     377                    }
     378                    else {
     379                        //String current_value = metadata.getAbsoluteValue();
     380                        //String current_value = Codec.transform(metadata.getValueNode().getFullPath(false), Codec.TEXT_TO_DOM);
     381                        String current_value = metadata.getValueNode().getFullPath(false);
     382                        //System.err.println("Checking the current mdv path: " + current_value);
     383                        //System.err.println("Against whats in the metadata file: " + raw_value);
     384                        if(!raw_value.equals(current_value)) {
     385                        // Remove old text
     386                        while(metadata_element.hasChildNodes()) {
     387                            metadata_element.removeChild(metadata_element.getFirstChild());
     388                        }
     389                        // Add new.
     390                        metadata_element.appendChild(base_document.createTextNode(current_value));
     391                        }
     392                    }
     393                    }
     394                    metadata = null;
     395                    raw_value = null;
     396                    raw_element = null;
     397                    metadata_element = null;
    396398                }
    397                 description_element = null;
     399                metadata_elements = null;
     400                }
     401                description_element = null;
    398402            }
    399403            description_elements = null;
    400             }
    401             filename_text = null;
    402             filename_element = null;
     404            }
     405            filename_text = null;
     406            filename_element = null;
    403407        }
    404408        // If the file set no longer has any description entries, remove it entirely
    405409        NodeList description_elements = fileset_element.getElementsByTagName(DESCRIPTION_ELEMENT);
    406410        if(description_elements.getLength() == 0) {
    407             directorymetadata_element.removeChild(fileset_element);
     411            directorymetadata_element.removeChild(fileset_element);
    408412        }
    409413        description_elements = null;
    410414        filename_elements = null;
    411415        fileset_element = null;
    412         }
    413         fileset_elements = null;
    414         directorymetadata_element = null;
     416        }
     417        fileset_elements = null;
     418        directorymetadata_element = null;
    415419    }
    416420    catch (Exception error) {
    417         Gatherer.self.printStackTrace(error);
     421        Gatherer.self.printStackTrace(error);
    418422    }
    419423    ///ystem.err.println("Found " + metadatum.size() + " pieces of metadata.");
    420424    return metadatum;
    421     }
    422 
     425    }
     426   
    423427    /** Determine if this document has been saved recently, and thus xml file version is up to date. */
    424428    public boolean isUpToDate() {
  • trunk/gli/src/org/greenstone/gatherer/util/Codec.java

    r6051 r6069  
    3737 */
    3838public class Codec {
    39 
     39   
    4040    static final public String DECODE_PATH = "DECODE_PATH";
    41    static final public String DOM_TO_GREENSTONE = "DOM_TO_GREENSTONE";
    42    static final public String DOM_TO_TEXT = "DOM_TO_TEXT";
     41    static final public String DECODE_SQUARE_BRACKETS = "DECODE_SQUARE_BRACKETS";
     42    static final public String DOM_TO_GREENSTONE = "DOM_TO_GREENSTONE";
     43    static final public String DOM_TO_TEXT = "DOM_TO_TEXT";
    4344    static final public String ENCODE_PATH = "ENCODE_PATH";
    44    static final public String GREENSTONE_TO_DOM = "GREENSTONE_TO_DOM";
    45    static final public String GREENSTONE_TO_TEXT = "GREENSTONE_TO_TEXT";
    46    static final public String REMOVE_SQUARE_BRACKET = "REMOVE_SQUARE_BRACKET";
    47    static final public String TEXT_TO_DOM = "TEXT_TO_DOM";
    48    static final public String TEXT_TO_GREENSTONE = "TEXT_TO_GREENSTONE";
    49    static final public String TEXT_TO_SHELL_UNIX = "TEXT_TO_SHELL_UNIX";
    50    static final public String TEXT_TO_SHELL_WINDOWS = "TEXT_TO_SHELL_WINDOWS";
    51 
     45    static final public String ENCODE_SQUARE_BRACKETS = "ENCODE_SQUARE_BRACKETS";
     46    static final public String GREENSTONE_TO_DOM = "GREENSTONE_TO_DOM";
     47    static final public String GREENSTONE_TO_TEXT = "GREENSTONE_TO_TEXT";
     48    static final public String TEXT_TO_DOM = "TEXT_TO_DOM";
     49    static final public String TEXT_TO_GREENSTONE = "TEXT_TO_GREENSTONE";
     50    static final public String TEXT_TO_SHELL_UNIX = "TEXT_TO_SHELL_UNIX";
     51    static final public String TEXT_TO_SHELL_WINDOWS = "TEXT_TO_SHELL_WINDOWS";
     52   
    5253    static final private int MAX_CACHE_SIZE = 100;
    53 
     54   
    5455    static private HashMap TRANSFORMS;
    5556    static private HashMap3D CACHE;
    56 
    57 
     57   
    5858    /** Static function called to construct TRANSFORMS mappings */
    5959    static {
     
    6161
    6262    String[] decode_path = {
    63         "\\|", "\\\\"
     63        "\\|",    "\\\\",
     64        "&#124;", "\\|"
    6465    };
    6566    TRANSFORMS.put(DECODE_PATH, decode_path);
    6667    decode_path = null;
     68
     69    // Transform text into text, but without [ and ]
     70    String[] decode_square_brackets = {
     71        "&#091;", "\\[",
     72        "&#093;", "\\]"
     73    };
     74    TRANSFORMS.put(DECODE_SQUARE_BRACKETS, decode_square_brackets);
     75    decode_square_brackets = null;
    6776
    6877    // Translate DOM encoded text into Greenstone encoding
     
    94103
    95104    String[] encode_path = {
     105        "\\|",  "&#124;",
    96106        "\\\\", "\\|"
    97107    };
    98108    TRANSFORMS.put(ENCODE_PATH, encode_path);
    99109    encode_path = null;
     110
     111    // Transform text into text, but without [ and ]
     112    String[] encode_square_brackets = {
     113        "\\[", "&#091;",
     114        "\\]", "&#093;"
     115    };
     116    TRANSFORMS.put(ENCODE_SQUARE_BRACKETS, encode_square_brackets);
     117    encode_square_brackets = null;
    100118
    101119    // Transform Greenstone encoded text to DOM encoding
     
    125143    TRANSFORMS.put(GREENSTONE_TO_TEXT, greenstone_to_text);
    126144    greenstone_to_text = null;
    127 
    128     // Transform text into text, but without [ and ]
    129     String[] remove_square_bracket = {
    130         "\\[", "&amp;#091;",
    131         "\\]", "&amp;#093;"
    132     };
    133     TRANSFORMS.put(REMOVE_SQUARE_BRACKET, remove_square_bracket);
    134     remove_square_bracket = null;
    135145
    136146    // Transform plain html text into something that can be placed in a DOM
  • trunk/gli/src/org/greenstone/gatherer/util/MetadataXML.java

    r5875 r6069  
    5959        String index = model.getHIndex(full_value);
    6060
    61         write(bw, "\"" + Utility.stripNL(full_value) + "\"\t" + index + "\t\"" + Utility.stripNL(node.toString()) + "\"");
     61        write(bw, "\"" + Utility.stripNL(full_value) + "\"\t" + index + "\t\"" + Utility.stripNL(node.toString(GValueNode.GREENSTONE)) + "\"");
    6262        }
    6363        // Very important we do this, or else buffer may not have
  • trunk/gli/src/org/greenstone/gatherer/valuetree/GValueModel.java

    r6037 r6069  
    251251
    252252    private String getHIndex(GValueNode node, String value, String index) {
    253         ///ystem.err.println("Get the HIndex for: " + value);
     253    ///ystem.err.println("Get the HIndex for: " + value);
    254254    for(int i = node.size(); i != 0; i--) {
    255255        GValueNode next = (GValueNode)node.get(i - 1);
    256         String next_str = next.toString();
     256        String next_str = next.toString(GValueNode.DOM);
    257257        ///ystem.err.println("Does " + value + " start with " + next_str + "?");
    258258        if(value.startsWith(next_str)) {
  • trunk/gli/src/org/greenstone/gatherer/valuetree/GValueNode.java

    r6044 r6069  
    162162        return default_value;
    163163    }
    164     StringBuffer path = new StringBuffer(toString());
     164    StringBuffer path = new StringBuffer(toString(DOM));
    165165    GValueNode node = (GValueNode) getParent();
    166166    while(node != null && !node.getElement().getNodeName().equalsIgnoreCase("AssignedValues")) {
    167167        path.insert(0, StaticStrings.PIPE_STR);
    168         path.insert(0, node.toString());
     168        path.insert(0, node.toString(DOM));
    169169        node = (GValueNode) node.getParent();
    170170    }
    171171    if(as_text) {
    172         String temp = Codec.transform(path.toString(), Codec.GREENSTONE_TO_TEXT);
    173         return Codec.transform(temp, Codec.DECODE_PATH);
     172        String temp = path.toString(); ///odec.transform(path.toString(), codec.GREENSTONE_TO_TEXT);
     173        System.err.println("Raw: " + temp);
     174        temp = Codec.transform(temp, Codec.DECODE_PATH);
     175        temp = Codec.transform(temp, Codec.DECODE_SQUARE_BRACKETS);
     176        System.err.println("Decoded: " + temp);
     177        return temp;
    174178    }
    175179    else {
     
    313317    String result = null;
    314318    if(name.equals("Subject")) {
    315        result = MSMUtils.getValue(element);
    316        result = Codec.transform(result, Codec.DECODE_PATH);
    317        switch(decode_type) {
    318           case GValueNode.GREENSTONE:
    319          // We want this as greenstone format
    320          ///ystem.err.print(result);
    321          result = Codec.transform(result, Codec.DOM_TO_GREENSTONE);
    322          ///ystem.err.println(" -> D2G decode -> " + result);
    323          break;
    324           case GValueNode.TEXT:
    325          ///ystem.err.print(result);
    326          result = Codec.transform(result, Codec.DOM_TO_TEXT);
    327          ///ystem.err.println(" -> D2T decode -> " + result);
    328          break;
    329           default:
    330          ///ystem.err.println(result + " -> nothing to do.");
    331        }
     319        result = MSMUtils.getValue(element);
     320        ///ystem.err.print(result);
     321        switch(decode_type) {
     322        case GValueNode.GREENSTONE:
     323        // We want this as greenstone format
     324        ///ystem.err.print(result);
     325        //result = /odec.transform(result, /odec.DOM_TO_GREENSTONE);
     326        ///ystem.err.println(" -> D2G decode -> " + result);
     327        break;
     328        case GValueNode.TEXT:
     329        //result = /odec.transform(result, /odec.DOM_TO_TEXT);
     330        result = Codec.transform(result, Codec.DECODE_PATH);
     331        result = Codec.transform(result, Codec.DECODE_SQUARE_BRACKETS);
     332        ///ystem.err.println(" -> D2T decode -> " + result);
     333        break;
     334        default:
     335        ///ystem.err.println(result + " -> nothing to do.");
     336        }
    332337    }
    333338    else if(name.equals("AssignedValues")) {
Note: See TracChangeset for help on using the changeset viewer.