[liblouis-liblouisxml] Difficulty utilizing translateFile() in liblouisutdml Java Native Interface

  • From: lbu56 <xmlhttprequest.open@xxxxxxxxx>
  • To: liblouis-liblouisxml@xxxxxxxxxxxxx
  • Date: Thu, 03 Jul 2014 00:29:50 -0400

Dear list,
I am very new to the liblouis libraries. I am trying to use liblouisutdml's Java bindings in a Java class to export XML into a braille file on Windows. After starting my init() method, the library loads correctly, the DLLs are initialized, and the initialize() function is called without any exception. However, when I try to call translateFile(), the process seems to halt after parsing the XML file, returning false. There are no errors on the console, and the last lines of the output have to do with the parsing of the XML (examine_document and so on). The C function lbu_translateFile translates an XML file and outputs it into a braille file, according to the documentation. I cannot find any detailed documentation for the Java bindings, though. Does anyone have an idea as to what I need to do to get my Java class working? Any help would be greatly appreciated.
Here is the code of my Java class:

package com.example.WebUtil;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;

import org.liblouis.liblouisutdml;

public class ExportToBraille {
    private int cellsPerLine = 40;
    private int linesPerPage = 25;

    public void init(){
        try {
liblouisutdml.loadLibrary("C:\\javalib",".dll"); // Contains liblouis.dll and liblouisutdml.dll
        } catch (Exception e) {
            e.printStackTrace();
        }
        liblouisutdml li = liblouisutdml.getInstance();
String config = "cellsPerLine "+Integer.toString(cellsPerLine)+"\rlinesPerPage "+Integer.toString(linesPerPage)+"\rinterpoint no\rlineEnd \\r\\n\rpageEnd \\f\rfileEnd ^z\rprintPages yes\rbraillePages yes\rparagraphs no\rbeginningPageNumber 1\rprintPageNumberAt top\rbraillePageNumberAt bottom\rcontinuePages yes\rpageSeparator yes\rpageSeparatorNumber yes\rignoreEmptyPages yes\rprintPageNumberRange no\rmergeUnnumberedPages yes\rpageNumberTopSeparateLine no\rpageNumberBottomSeparateLine yes\rhypenate no\routputEncoding ascii8\rinputTextEncoding UTF8\rformatFor textDevice\rbackFormat plain\rbackLineLength 70\rinterline no\rlineFill '\rliteraryTextTable en-us-g2.ctb\runcontractedTable en-us-g1.ctb\rcompbrlTable en-us-comp8.ctb\rmathtextTable en-us-g2.ctb\rmathexprTable nemeth.ctb\reditTable nemeth_edit.ctb\rsemanticFiles menu.sem\rxmlheader <?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\rentity nbsp ^1\rinternetAccess yes\rnewEntries yes\rstyle document\rlinesBefore 0\rlinesAfter 0\rleftMargin 0\rfirstLineIndent 0\rtranslate contracted\rskipNumberLines no\rformat leftJustified\rnewPageBefore no\rnewPageAfter no\rrighthandPage no\rbraillePageNumberFormat normal\rstyle arith\rstyle attribution\rformat rightJustified\rstyle biblio\rstyle caption\rleftMargin 4\rfirstLineIndent 2\rstyle code\rlinesBefore 1\rlinesAfter 1\rskipNumberLines yes\rformat computerCoded\rstyle contentsheader\rlinesBefore 1\rformat centered\rlinesAfter 1\rstyle contents1\rfirstLineIndent -2\rleftMargin 2\rformat contents\rstyle contents2\rfirstLineIndent -2\rleftMargin 4\rformat contents\rstyle contents3\rfirstLineIndent -2\rleftMargin 6\rformat contents\rstyle contents4\rfirstLineIndent -2\rleftMargin 8\rformat contents\rstyle dedication\rnewPageBefore yes\rnewPageAfter yes\rformat centered\rstyle directions\rstyle dispmath\rleftMargin 2\rstyle disptext\rleftMargin 2\rfirstLineIndent 2\rstyle exercise1\rleftMargin 2\rfirstLineIndent -2\rstyle exercise2\rleftMargin 4\rfirstLineIndent -2\rstyle exercise3\rleftMargin 6\rfirstLineIndent -2\rstyle glossary\rfirstLineIndent 2\rstyle graph\rskipNumberLines yes\rstyle graphlabel\rstyle heading1\rlinesBefore 1\rformat centered\rlinesAfter 1\rstyle heading2\rlinesBefore 1\rfirstLineIndent 4\rstyle heading3\rfirstLineIndent 4\rstyle heading4\rfirstLineIndent 4\rstyle index\rstyle line\rfirstLineIndent -2\rleftMargin 2\rstyle list\rfirstLineIndent -2\rleftMargin 2\rstyle matrix\rformat alignColumnsLeft\rstyle music\rskipNumberLines yes\rstyle note\rstyle para\rstyle quotation\rlinesBefore 1\rlinesAfter 1\rstyle section\rfirstLineIndent 4\rstyle spatial\rstyle stanza\rlinesBefore 1\rlinesAfter 1\rstyle style1\rstyle style2\rstyle style3\rstyle style4\rstyle style5\rstyle subsection\rfirstLineIndent 4\rstyle table\rlinesBefore 1\rlinesAfter 1\rstyle titlepage\rnewPageAfter yes\rstyle trnote\rfirstLineIndent 7\rleftMargin 5\rstyle volume"; String semData = "document menu\rsoftreturn br\rheading1 section\rpara item\rheading2 subheading\rcontentsheader cheader\rpagenum page";
        writeFileContents("liblouisutdml.ini",config);
        writeFileContents("menu.sem",semData);
        liblouisutdml.initialize(".","C:\\javalib","");
System.out.println(Boolean.toString(li.translateFile("liblouisutdml.ini","menu_in.xml","translated_menu.brf","liblouis.log","",0)));
    }

    public void writeFileContents(String path, String contents) {
        File f = new File(path);
        if (!f.exists()) {
            try {
                f.createNewFile();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        else {
        }
        FileWriter fw = null;
        try {
            fw = new FileWriter(f.getAbsoluteFile());
        } catch (IOException e) {
            e.printStackTrace();
        }
        BufferedWriter bw = new BufferedWriter(fw);
        try {
            bw.write(contents);
        } catch (IOException e) {
            e.printStackTrace();
        }
        finally {
            try {bw.close();} catch (IOException ignore){}
        }
    }
}

Regards,
lbu56

For a description of the software, to download it and links to
project pages go to http://www.abilitiessoft.com

Other related posts: