Changeset 3615


Ignore:
Timestamp:
2002-12-03T16:20:18+13:00 (21 years ago)
Author:
say1
Message:

java updates new collections now appear on web server

Location:
trunk/gsdl3/src/java/org/greenstone/gsdl3/selfContained
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/gsdl3/src/java/org/greenstone/gsdl3/selfContained/DocumentStream.java

    r3593 r3615  
    4444   * @return the next document
    4545   */
    46   public Document nextDocument();
     46  public Document nextDocument() throws Exception ;
    4747  /**
    4848   * Is there a next document?
     
    5151   * @return true if there is a next document
    5252   */
    53   public boolean hasNextDocument();
     53  public boolean hasNextDocument() throws Exception ;
    5454 
    5555}
  • trunk/gsdl3/src/java/org/greenstone/gsdl3/selfContained/FilesDocumentStream.java

    r3593 r3615  
    2222import org.w3c.dom.Document;
    2323import org.xml.sax.InputSource;
     24import javax.xml.transform.Source;
     25import javax.xml.transform.Transformer;
     26import javax.xml.transform.TransformerFactory;
     27import javax.xml.transform.dom.DOMSource;
     28import javax.xml.transform.stream.StreamResult;
     29import org.apache.xerces.dom.DocumentImpl;
     30import org.apache.xerces.dom.ElementImpl;
     31import org.apache.xerces.dom.TextImpl;
     32import org.w3c.dom.Document;
    2433
    2534// other java classes
    2635import java.io.File;
     36import java.io.FilenameFilter;
    2737import java.io.FileReader;
    2838import java.io.IOException;
     
    5767    File file = new File(filename);
    5868    if (file.exists() && file.isDirectory())
    59       directories.add(file);
     69      directories.add(file.getAbsolutePath());
    6070    else
    61       files.add(file);
     71      files.add(file.getAbsolutePath());
    6272  }
    6373  /**
     
    6979  public FilesDocumentStream(File file) {
    7080    if (file.exists() && file.isDirectory())
    71       directories.add(file);
     81      directories.add(file.getAbsolutePath());
    7282    else
    73       files.add(file);
     83      files.add(file.getAbsolutePath());
     84  }
     85
     86  /**
     87   * A small inner class to filter out those files that don't
     88   * end in ".xml" or ".XML"
     89   */
     90  class XMLFilenameFilter implements FilenameFilter {
     91    /** Tests if a specified file should be included in a file list. */
     92    public boolean accept(File dir, String name) {
     93      String target = ".xml";
     94      if (name.length() < target.length())
     95    return false;
     96      String extension = name.substring(name.length() - 4, name.length());
     97      //System.out.println(name + " ==>> " +  extension);
     98      if (extension.equalsIgnoreCase(target)) {
     99    return true;
     100      } else {
     101    return false;
     102      }
     103    }   
    74104  }
    75105
     
    80110   */
    81111  protected void expandIfNecessary() {
    82     while (files.size() < 1 || directories.size() > 1) {
    83       File file = (File) directories.elementAt(directories.size() - 1);
    84       directories.removeElementAt(directories.size() - 1);
    85       if (!file.exists()) throw new Error ("error in expand: expecting a directory");
    86       File[] fileArray = file.listFiles();
     112    while (directories.size() > 0) {
     113      String dirname = (String) directories.elementAt(0);
     114      directories.removeElement(dirname);
     115      File dir = new File(dirname);
     116      if (!dir.exists()) throw new Error ("error in expand: expecting a directory " + dirname);
     117      String[] fileArray = dir.list();
    87118      for (int i=0;i<fileArray.length;i++){
    88     if (fileArray[i].exists() && fileArray[i].isDirectory())
    89       directories.add(fileArray[i]);
    90     else
    91       files.add(fileArray[i]);
     119    File file = new File(dir, fileArray[i]);
     120    if (file.exists() && file.isDirectory())
     121      directories.add(file.getPath());
    92122      }
     123     
     124      fileArray = dir.list(new XMLFilenameFilter());
     125      for (int i=0;i<fileArray.length;i++){
     126    File file = new File(dir, fileArray[i]);
     127    if (file.exists() && !file.isDirectory())
     128      files.add(file.getPath());
     129      }
     130      if (files.size() > 0)
     131    return;
    93132    }
    94133  }
    95 
     134 
    96135  /**
    97136   * Returns the next document
     
    100139   * @return the next document
    101140   */
    102   public Document nextDocument() {
    103     try {
    104       if (!hasNextDocument()) throw new Error("Doesn't have another Document");
    105       File file = (File) files.elementAt(files.size() - 1);
    106       files.removeElementAt(files.size() - 1);
    107        
    108       Reader reader = new FileReader(file);
    109       InputSource xml_source = new InputSource(reader);
    110        
    111       XMLUtil.getDOMParser().parse(xml_source);
    112       Document doc = XMLUtil.getDOMParser().getDocument();
    113        
    114       return doc;
    115     } catch (org.xml.sax.SAXException s) {
    116       System.err.println("SAXException in nextDocument()");
    117       throw new Error(s.toString());
    118     } catch (IOException e) {
    119       System.err.println("IOException in nextDocument()");
    120       throw new Error(e.toString());
    121     }
     141  public Document nextDocument()
     142    throws Exception {
     143   
     144    if (!hasNextDocument()) throw new Error("Doesn't have another Document");
     145
     146    String filename = (String) files.elementAt(files.size() - 1);
     147    files.removeElementAt(files.size() - 1);
     148    File file = new File(filename);
     149   
     150    Reader reader = new FileReader(file);
     151    InputSource xml_source = new InputSource(reader);
     152
     153    XMLUtil.getDOMParser().parse(xml_source);
     154    Document doc = XMLUtil.getDOMParser().getDocument();
     155   
     156    return doc;
    122157  }
    123158   
     
    129164   */
    130165
    131   public boolean hasNextDocument()  {
     166  public boolean hasNextDocument()  throws Exception {
    132167    expandIfNecessary();
    133     return (files.size() > 1);
     168    return (files.size() > 0);
    134169  }
    135170  /**
     
    141176   */
    142177
    143   public static void main(String args[]) throws IOException
     178  public static void main(String args[]) throws Exception
    144179  {
     180   
     181    StreamResult result = new StreamResult(System.out);
     182    TransformerFactory transformerFactory = TransformerFactory.newInstance();
     183   
     184    FilesDocumentStream stream = new FilesDocumentStream(".");
     185    while (stream.hasNextDocument()) {
     186      Document document = stream.nextDocument();
     187      Transformer transformer = transformerFactory.newTransformer();
     188      Source source = new DOMSource(document);
     189      transformer.transform(source,result);
     190      System.out.println();
     191      System.out.println();
     192    }
    145193
    146   }
    147  
     194  }
    148195}
    149196
  • trunk/gsdl3/src/java/org/greenstone/gsdl3/selfContained/GeneratedDocumentStream.java

    r3593 r3615  
    11/*
    2  *    XMLConverter.java
     2 *    GenerateDocumentStream.java
    33 *    Copyright (C) 2002 New Zealand Digital Library, http://www.nzdl.org
    44 *
     
    8686    this.next = next;
    8787  }
     88  /**
     89   * Custom constructor
     90   *
     91   * @param first the first letter in the alphabet
     92   * @param last the last letter in the alphabet
     93   */
     94  public GeneratedDocumentStream(char first, char last) {
     95    this.incrementer = new IncrementRange(first,last);
     96  }
    8897
    8998
  • trunk/gsdl3/src/java/org/greenstone/gsdl3/selfContained/QueryDocumentStream.java

    r3593 r3615  
    166166   * @see org.w3c.dom.Document
    167167   */
    168   public Document nextDocument() {
     168  public Document nextDocument() throws Exception {
    169169
    170170    if (hasNextDocument() == false)
     
    179179   * @return true if there are more docs
    180180   */
    181   public boolean hasNextDocument() {
     181  public boolean hasNextDocument() throws Exception {
    182182    lookInStream();
    183183    return (cached != null);
     
    193193   * @see blank
    194194   */
    195   protected boolean lookInStream() {
     195  protected boolean lookInStream() throws Exception {
    196196
    197197    while (stream.hasNextDocument() && cached == null) {
Note: See TracChangeset for help on using the changeset viewer.