Changeset 8448


Ignore:
Timestamp:
2004-11-04T14:07:55+13:00 (19 years ago)
Author:
kjdon
Message:

only changed formatting style, in preparation for adding in Chi's changes

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/gsdl3/src/java/org/greenstone/gsdl3/gs3build/doctypes/METSDocument.java

    r7466 r8448  
    1919import org.greenstone.gsdl3.gs3build.metadata.*;
    2020
    21 public class METSDocument extends AbstractDocument
    22 {
    23   public static final String METS_DOCUMENT_TYPE = "METS";
     21public class METSDocument extends AbstractDocument {
    2422
    25   public METSDocument(URL url)
    26   { super(url);
    27  
    28     if (url.getProtocol().equals("file"))
    29     { this._parseFile(new File(url.getPath()));
     23    public static final String METS_DOCUMENT_TYPE = "METS";
     24
     25    public METSDocument(URL url) {
     26    super(url);
     27   
     28    if (url.getProtocol().equals("file")) {
     29        this._parseFile(new File(url.getPath()));
     30    }
    3031    }
    31   }
    32  
    33   private void _parseFile(File file)
    34   {
    35     try {
    36       DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    37       DocumentBuilder builder = factory.newDocumentBuilder();
    38       Document document = builder.parse(file);
     32   
     33    private void _parseFile(File file) {
     34   
     35    try {
     36        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
     37        DocumentBuilder builder = factory.newDocumentBuilder();
     38        Document document = builder.parse(file);
    3939
    40       // TODO: get all the types in the tree
     40        // TODO: get all the types in the tree
    4141     
    42       // TODO: do a traverse, and thus cope with elements-within-elements if needsbe, but
    43       // this shouldn't happen except in a directly defined situation - actually doing the
    44       // parsing in part inside each node would work well provided one checked for a node
    45       // having already been done...
    46       System.out.println("Read");
     42        // TODO: do a traverse, and thus cope with elements-within-elements if needsbe, but
     43        // this shouldn't happen except in a directly defined situation - actually doing the
     44        // parsing in part inside each node would work well provided one checked for a node
     45        // having already been done...
     46        System.out.println("Read");
    4747     
    48       NodeList fileSecs = document.getElementsByTagName("mets:fileSec");
     48        NodeList fileSecs = document.getElementsByTagName("mets:fileSec");
    4949     
    50       for (int g = 0; g < fileSecs.getLength(); g ++) {
    51     //              Schema schema = new Schema(schemas.item(s));
    52     this._parseFileSec(fileSecs.item(g));
    53       }
     50        for (int g = 0; g < fileSecs.getLength(); g ++) {
     51        //Schema schema = new Schema(schemas.item(s));
     52        this._parseFileSec(fileSecs.item(g));
     53        }
    5454     
    55       // Get document metadata sections
    56       NodeList dmdSecs = document.getElementsByTagName("mets:dmdSec");
     55        // Get document metadata sections
     56        NodeList dmdSecs = document.getElementsByTagName("mets:dmdSec");
    5757     
    58       //                Schema schema = new Schema(schemas.item(s));
    59       this.metadata = METSDescriptiveSet.parseXML(fileSecs);
     58        //Schema schema = new Schema(schemas.item(s));
     59        this.metadata = METSDescriptiveSet.parseXML(fileSecs);
     60    }
     61    catch (FactoryConfigurationError e) {
     62        System.out.println(e);
     63    }
     64    catch (ParserConfigurationException ex) {
     65        System.out.println(ex);
     66    }
     67    catch (SAXException ex) {
     68        System.out.println(ex);
     69    }
     70    catch (IOException ex) {
     71        System.out.println(ex);
     72    }
    6073    }
    61     catch (FactoryConfigurationError e) {
    62       System.out.println(e);
     74
     75    private void _parseFileSec(Node fileSec) {
     76    // this is in effect a group without a sense of 'self'...
     77    this._parseFileGroup((Element) fileSec, null);
    6378    }
    64     catch (ParserConfigurationException ex) {
    65       System.out.println(ex);
     79
     80    private void _parseFileGroup(Element groupTag, METSFileGroup group) {
     81    NodeList children = groupTag.getChildNodes();
     82
     83    for (int c = 0; c < children.getLength(); c ++) {
     84        if (children.item(c).getNodeType() != org.w3c.dom.Node.ELEMENT_NODE) {
     85        continue;
     86        }
     87
     88        System.out.println(children.item(c));
     89   
     90        Element element = (Element) children.item(c);
     91
     92        if (element.getNodeName().equals("mets:File")) {
     93        if (group != null) {
     94            METSFile file = METSFile.parseXML(element, group);
     95        } else {
     96            // TODO: error
     97        }
     98        } else if (element.getNodeName().equals("mets:fileGrp")) {
     99        // recurse
     100        METSFileGroup childGroup = new METSFileGroup(element.getAttribute("ID"));
     101
     102        this._parseFileGroup(element, childGroup);
     103        if (group != null) {
     104            group.addGroup(childGroup);
     105        } else {
     106            this.fileSet.addGroup(childGroup);
     107        }
     108        }
     109    }
    66110    }
    67     catch (SAXException ex) {
    68       System.out.println(ex);
     111   
     112    public String getDocumentType() {
     113    return METS_DOCUMENT_TYPE;
    69114    }
    70     catch (IOException ex) {
    71       System.out.println(ex);
     115   
     116    public String getDocumentText() {
     117    // TODO: make this more than a dummy function!
     118    return null;
    72119    }
    73   }
    74120
    75   private void _parseFileSec(Node fileSec)
    76   { // this is in effect a group without a sense of 'self'...
    77     this._parseFileGroup((Element) fileSec, null);
    78   }
    79 
    80   private void _parseFileGroup(Element groupTag, METSFileGroup group)
    81   { NodeList children = groupTag.getChildNodes();
    82 
    83     for (int c = 0; c < children.getLength(); c ++)
    84     { if (children.item(c).getNodeType() != org.w3c.dom.Node.ELEMENT_NODE) {
    85         continue;
    86       }
    87 
    88       System.out.println(children.item(c));
    89    
    90       Element element = (Element) children.item(c);
    91 
    92       if (element.getNodeName().equals("mets:File"))
    93       { if (group != null)
    94     { METSFile file = METSFile.parseXML(element, group);
    95     }
    96         else
    97     { // TODO: error
    98     }
    99       }
    100       else if (element.getNodeName().equals("mets:fileGrp"))
    101       { // recurse
    102     METSFileGroup childGroup = new METSFileGroup(element.getAttribute("ID"));
    103 
    104     this._parseFileGroup(element, childGroup);
    105     if (group != null)
    106     { group.addGroup(childGroup);
    107     }
    108     else
    109     { this.fileSet.addGroup(childGroup);
    110     }
    111       }
     121    public String getSectionText(String sectionId) {
     122    return null;
    112123    }
    113   }
    114 
    115   public String getDocumentType()
    116   { return METS_DOCUMENT_TYPE;
    117   }
    118 
    119   public String getDocumentText()
    120   { // TODO: make this more than a dummy function!
    121     return null;
    122   }
    123 
    124   public String getSectionText(String sectionId)
    125   { return null;
    126   }
    127 
     124   
    128125}
Note: See TracChangeset for help on using the changeset viewer.