Changeset 7187


Ignore:
Timestamp:
2004-04-06T09:25:35+12:00 (20 years ago)
Author:
cs025
Message:

Fixed FPTR incorrect use in METS output; added some comments.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/gsdl3/src/java/org/greenstone/gsdl3/gs3build/metadata/METSDivision.java

    r6287 r7187  
    2828 
    2929  public static final String DIVISION_TYPE  = "Division";
     30  public static final String DIVISION_TAG   = "div";
     31  public static final String FPTR_TAG       = "fptr";
    3032
    3133  public METSDivision(String ID, String order, String orderLabel, String userLabel, String type)
     
    256258  }
    257259
     260  /**
     261   *  Get the parent division name.  Division identifiers
     262   *  concatenate the ancestor's names with intervening
     263   *  '.' characters.
     264   *
     265   *  @return <code>String</code> the division name
     266   */
    258267  public static String getParentName(String divisionName)
    259268  { int at = divisionName.lastIndexOf('.');
     
    265274  }
    266275
     276  /**
     277   *  Get the top division name.
     278   *
     279   *  @return <code>String</code> the division name
     280   */
    267281  public static String getTopDivisionName(String divisionName)
    268282  { int at = divisionName.indexOf('.');
     
    272286    }
    273287    else
    274     {   return divisionName;
    275     }
    276   }
    277 
    278   /**
    279    *  Write the METS file in an XML to a text-output sink
     288    { return divisionName;
     289    }
     290  }
     291
     292  /**
     293   *  Write the METS file in an XML to a text-output sink.
    280294   *
    281295   *  @param <code>PrintWriter</code> the destination of the output
    282296   */
    283297  public boolean write(PrintWriter writer)
    284   { String tag = XMLTools.getOpenTag("mets", "div");
     298  { // Get the main tag for the division
     299    String tag = XMLTools.getOpenTag("mets", DIVISION_TAG);
    285300    tag = XMLTools.addAttribute(tag, "ID", this.ID.toString());
    286301    tag = XMLTools.addAttribute(tag, "TYPE", this.type);
     
    292307    { tag = XMLTools.addAttribute(tag, "LABEL", this.userLabel);
    293308    }
     309
     310    // Add a metadata reference attribute
     311    if (this.metadataRefs.size() > 0)
     312    { String metaList = this.writeList(this.metadataRefs);
     313
     314      tag = XMLTools.addAttribute(tag, "DMDID", metaList);
     315    }
     316
     317    // write the central tag
    294318    writer.println(tag);
    295319
    296320    // write the list of file pointers for this structural element
    297321    if (this.fileRefs.size() > 0)
    298     { tag = XMLTools.getOpenTag("mets", "fptr");
    299      
    300       String fileList = this.writeList(this.fileRefs);
    301 
    302       tag = XMLTools.addAttribute(tag, "FILEID", fileList);
    303      
    304       tag = XMLTools.makeSingleton(tag);
    305       writer.println(tag);
    306     }
    307 
    308     // ..and then the metadata - this is the same code at present,
    309     // but is replicated here in case of future amendment.
    310     if (this.metadataRefs.size() > 0)
    311     { tag = XMLTools.getOpenTag("mets", "mptr");
    312 
    313       String metaList = this.writeList(this.metadataRefs);
    314       tag = XMLTools.addAttribute(tag, "METAID", metaList);
    315       tag = XMLTools.makeSingleton(tag);
    316       writer.println(tag);
     322    { String fileList = this.writeTagList("mets", "fptr", "FILEID", this.fileRefs);
     323
     324      writer.println(fileList);
    317325    }
    318326
     
    329337   
    330338    // close the div element
    331     writer.println(XMLTools.getCloseTag("mets", "div"));
     339    writer.println(XMLTools.getCloseTag("mets", DIVISION_TAG));
    332340
    333341    return true;
     342  }
     343
     344  /**
     345   *  A convenience method for writing a <code>List</code> as a series of tags...
     346   */
     347  private String writeTagList(String namespace, String tagname,
     348                  String attribute, List list)
     349  { StringBuffer listString = new StringBuffer();
     350     
     351    Iterator iterator = list.iterator();
     352    while (iterator.hasNext())
     353    { String item = iterator.next().toString();
     354
     355      String tag = XMLTools.getOpenTag(namespace, tagname);
     356      tag = XMLTools.addAttribute(tag, attribute, item);
     357      tag = XMLTools.makeSingleton(tag);
     358
     359      listString.append(tag);
     360    }
     361    return listString.toString();
    334362  }
    335363
     
    343371    while (iterator.hasNext())
    344372    { String item = iterator.next().toString();
    345       if (listString.length() > 0)
    346       { listString.append(" ");
    347       }
     373
     374      if (listString.length() > 0) {
     375    listString.append(" ");
     376      }
     377
    348378      listString.append(item);
    349379    }
Note: See TracChangeset for help on using the changeset viewer.