[sword-cvs] swordtools/modules/hebrew-wlc/WLC2OSIS/WLC2OSIS/Utilities FileRead.java, NONE, 1.1 Test.java, NONE, 1.1 XMLWriter.java, NONE, 1.1 package.html, NONE, 1.1

sword at www.crosswire.org sword at www.crosswire.org
Fri Jun 4 02:14:54 MST 2004


Committed by: mgruner

Update of /cvs/core/swordtools/modules/hebrew-wlc/WLC2OSIS/WLC2OSIS/Utilities
In directory www:/tmp/cvs-serv15120/modules/hebrew-wlc/WLC2OSIS/WLC2OSIS/Utilities

Added Files:
	FileRead.java Test.java XMLWriter.java package.html 
Log Message:
initial import of source files for the new BHS-replacement WLC (Westminster Leningrad Codex).
Not functional yet at all.

--- NEW FILE: FileRead.java ---
package WLC2OSIS.Utilities ;

import WLC2OSIS.* ;
import Utilities.FileChooser ;
//import Utilities.Message ;

import java.io.* ;
import javax.swing.* ;
import java.awt.* ;
//==============================================================================
/**
 *  <b>Reads the input file.</b>
 */
//==============================================================================
public class FileRead{


WLC2OSIS A ;
int InputLength ; 
public byte[] InputBuffer ;
File F ;
FileInputStream FIS ;
boolean Error ;
//-----------------------------------------------------------------------------

public FileRead(WLC2OSIS A ) {
    this.A = A ;
    InputBuffer = new byte[A.InputBufferSize] ;
    Error = false ;
    }    
//------------------------------------------------------------------------------

// Reads the specified file, forming the char[] InputChars and StringBuffer Input.

public void read(String Filename){
    Error = true ;
        
// Open the file

    F = new File(Filename) ;
    
    try{
        FIS = new FileInputStream(F);
        if (FIS.available() > InputBuffer.length){
            System.out.println(
                "The input file length, " + FIS.available() 
                    + " bytes,\nis too long for the internal buffer of "
                        + InputBuffer.length + " bytes.") ;
            return ;
            }
        }
    catch(IOException e){
        System.out.println(
            "FileRead.read: Error in opening FileInputStream.\n\n"
            + F.getPath() + "\n\n"
            + e.toString() + "\nNo further action taken.") ;
        return ;
        }
//------------------------------------------------------------------------------

// Read the file

    try{
        InputLength = FIS.read(InputBuffer) ;
        }
    catch(IOException e){
        System.out.println(
            "FileRead.read: Error on read of input file.\n\n"
            + F.getPath() + "\n\n"
            + e.toString() + "\nNo further action taken.") ;
        return;
        }

// Close the file.
        
    try{
        FIS.close() ; 
        }
    catch(IOException e){
        System.out.println(
            "FileRead.read: Error on close of input file.\n\n"
            + F.getPath() + "\n\n"
            + e.toString() + "\nNo further action taken.") ;
        }              
    
// Convert bytes to char[] array.

    A.InputChars = new char[InputLength] ;
    for (int k = 0; k < InputLength; k++){
        short shrt = (short) InputBuffer[k] ;
        A.InputChars[k] = (char) shrt ;
        }

    Error = false ;
    }
//------------------------------------------------------------------------------

// Gets the error condition.

public boolean getError(){
    return Error ;
    }
//-----------------------------------------------------------------------------
}
//==============================================================================
//==============================================================================

--- NEW FILE: Test.java ---
package WLC2OSIS.Utilities ;

import WLC2OSIS.* ;
import WLC2OSIS.Parse.* ;
import WLC2OSIS.Translate.* ;
import Utilities.* ;

import java.lang.System ;
import java.io.* ;
//==============================================================================
/**
 *  <b>Tests the conversion from MC ASCII String to XML output.</b>
 */
//==============================================================================
public class Test{

//-----------------------------------------------------------------------------
/**
 *  Writes an XML file showing the Unicode output for a specified
 *  MC ASCII string.
 *
 *  @param MC ASCII String to be translated.
 * 
*/
public static void test(WLC2OSIS A, String MC){
       A.p = new Parser(A) ;
       Translate T = new Translate(A, A.p) ;
       String Word = T.translate(MC) ;
       A.w = new XMLWriter("C:\\kimball\\JavaProjects\\WLC2OSIS\\Tanach", "Test", "Test",
        "Test", "" ) ;
       A.w.writeString("mc", 1,  MC) ;
       A.p.w.writeWord(Word, "w") ;
       A.w.close() ;
       try{
           BrowserLauncher.openURL("file:\\C:/kimball/JavaProjects/WLC2OSIS/Tanach/" 
             + "Test" + ".xml") ;
            }
       catch(IOException e){
            System.out.println("WLC2OSIS: Couldn't launch browser.") ;
            }    
       System.exit(0) ;
       }
//-----------------------------------------------------------------------------
//  end of class
}
//==============================================================================
//==============================================================================

--- NEW FILE: XMLWriter.java ---
package WLC2OSIS.Utilities ;

import Utilities.* ;

import java.lang.System ;
import java.io.* ;
//==============================================================================
/**
 *  <b>Writes the output XML files.</b>
 */
//==============================================================================
public class XMLWriter{

String Directory  ;
String Filename  ;
String IndentString = "  " ;
FileOutputStream FOS ;
OutputStreamWriter OSW ;
char[] CharBuffer ;
Fmt F = new Fmt() ;
String XMLTag ;
//-----------------------------------------------------------------------------
/**
 *  Writes an XML file.
 *
 *  @param Directory String giving directory WITHOUT final \.
 *  @param Filename String giving file name WITHOUT extension.
 *  @param XMLTag String giving XML tag.
 *  @param XSLXSDName String giving .xsl and xsd file names WITHOUT extension.
 *  @param ToXSL String giving route to .xsl file and .xsd file, i.e. "..\\" 
 *         or ".." + File.separator.
 * 
*/
public XMLWriter(String Directory, String Filename, String XMLTag, String XSLXSDName, String ToXSL){

    this.Directory = Directory ;
    this.Filename = Filename ;
    this.XMLTag = XMLTag ;
    
    try{
        FOS = new FileOutputStream(Directory + File.separator + Filename + ".xml") ;
        OSW = new OutputStreamWriter(FOS, "UTF8") ;
        }
    catch(IOException e){
        System.out.println("XMLWriter: Error in opening output file.\n" + e) ;
        }
    writeString("<?xml version = \"1.0\" encoding=\"UTF-8\"?>");
    writeString("\n<?xml-stylesheet type=\"text/xsl\" href=\"" + ToXSL + XSLXSDName + ".xsl.xml\"?>");
    writeString("\n<" + XMLTag 
         + " xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" "
         + "xsi:noNamespaceSchemaLocation =\"" + ToXSL + XSLXSDName + ".xsd\">" ) ;
    writeString("\n<!-- Copyright C.V.Kimball 2004 -->" ) ;
    }
//-----------------------------------------------------------------------------
public void writeString(String Tag, int Level, String S){
    String s = "\n" ;
    for (int k = 0; k < Level; k++){
        s = s + IndentString ;
        }
    s = s + "<" + Tag + ">" ;
    s = s + S ;
    s = s + "</" + Tag + ">" ;
    writeString(s) ;
    }
//-----------------------------------------------------------------------------
public void writeBoolean(String Tag, int Level, boolean B){
    String s = "\n" ;
    for (int k = 0; k < Level; k++){
        s = s + IndentString ;
        }
    s = s + "<" + Tag + ">" ;
    s = s + B ;
    s = s + "</" + Tag + ">" ;
    writeString(s) ;
    }
//-----------------------------------------------------------------------------
public void writeInt(String Tag, int Level, int I){
    String s = "\n" ;
    for (int k = 0; k < Level; k++){
        s = s + IndentString ;
        }
    s = s + "<" + Tag + ">" ;
    s = s + I ;
    s = s + "</" + Tag + ">" ;
    writeString(s) ;
    }
//-----------------------------------------------------------------------------
public void openTag(String Tag, int Level){
    String s = "\n" ;
    for (int k = 0; k < Level; k++){
        s = s + IndentString ;
        }
    s = s + "<" + Tag + ">" ;
    writeString(s) ;
    }
//-----------------------------------------------------------------------------
public void openAttributedTag(String Tag, int Level, String Attribute, String Value){
    String s = "\n" ;
    for (int k = 0; k < Level; k++){
        s = s + IndentString ;
        }
    s = s + "<" + Tag + " " + Attribute + "=\"" + Value + "\">" ;
    writeString(s) ;
    }
//-----------------------------------------------------------------------------
public void closeTag(String Tag, int Level){
    String s = "\n" ;
    if (Level > 0) {
        for (int k = 0; k < Level; k++){
            s = s + IndentString ;
            }
        }
    s = s + "</" + Tag + ">" ;
    writeString(s) ;
    }
//-----------------------------------------------------------------------------
public void writeMarker(String Tag, int Level){
    String s = "\n" ;
    if (Level > 0) {
        for (int k = 0; k < Level; k++){
            s = s + IndentString ;
            }
        }
    s = s + "<" + Tag + "/>" ;
    writeString(s) ;
    }
//-----------------------------------------------------------------------------
public void writeException( char Exception){
    String s ;
    s =  "<x>" + Exception + "</x>" ;
    writeString(s) ;
    }
//-----------------------------------------------------------------------------
public void close(){
    writeString("\n</" + XMLTag + ">") ;
    try{
        OSW.close() ;
        }
    catch(IOException e){
        System.out.println("XMLWriter: Error in closing output file.\n" + e) ;
        }
    }
//-----------------------------------------------------------------------------
void writeString(String S){
    CharBuffer = S.toCharArray() ;
    try{
        OSW.write(CharBuffer, 0, CharBuffer.length) ;
        }
    catch(IOException e){
        System.out.println("XMLWriter: Error in output file.\n" + e) ;
        }
    }
//-----------------------------------------------------------------------------
//  end of class
}
//==============================================================================
//==============================================================================

--- NEW FILE: package.html ---
<HTML>
<BODY>
<b>Utilities for text reading and XML writing, not specialized to WLC</b>.<p/>
<p align="right"> (<b><tt>BHS2XML/Utilities/package.html</tt></b>)
<p/>
Includes a Test class to write XML for MC ASCII test cases.
</BODY>
</HTML>



More information about the sword-cvs mailing list