[brailleblaster] push by john.bo...@xxxxxxxxxxxxxxxxx - working version of UTD class available for testing on 2012-05-06 11:40 GMT

  • From: brailleblaster@xxxxxxxxxxxxxx
  • To: brailleblaster@xxxxxxxxxxxxx
  • Date: Sun, 06 May 2012 11:40:28 +0000

Revision: 2a299e832fa0
Author:   John Boyer <john.boyer@xxxxxxxxxxxxxxxxx>
Date:     Sun May  6 04:39:16 2012
Log:      working version of UTD class available for testing
http://code.google.com/p/brailleblaster/source/detail?r=2a299e832fa0

Modified:
 /src/main/org/brailleblaster/wordprocessor/UTD.java

=======================================
--- /src/main/org/brailleblaster/wordprocessor/UTD.java Fri May 4 07:58:31 2012 +++ /src/main/org/brailleblaster/wordprocessor/UTD.java Sun May 6 04:39:16 2012
@@ -61,278 +61,301 @@
  */
 class UTD {

-int braillePageNumber; //number of braille pages
-String firstTableName;
-int dpi; // resolution
-int paperWidth;
-int paperHeight;
-int leftMargin;
-int rightMargin;
-int topMargin;
-int bottomMargin;
-int currentBraillePageNumber;
-int currentPrintPageNumber;
-int[] brlIndex;
-int brlIndexPos;
-int[] brlonlyIndex;
-int brlonlyIndexPos;
-Node beforeBrlNode;
-Node beforeBrlonlyNode;
-private boolean firstPage;
-private boolean firstLineOnPage;
-StringBuilder brailleLine = new StringBuilder (100);
-StringBuilder printLine = new StringBuilder (100);
-DocumentManager dm;
-Document doc;
-
-UTD (final DocumentManager dm) {
-this.dm = dm;
-}
-
-void displayTranslatedFile() {
-beforeBrlNode = null;
-beforeBrlonlyNode = null;
-brlIndex = null;
-brlIndexPos = 0;
-brlonlyIndex = null;
-brlonlyIndexPos = 0;
-firstPage = true;
-firstLineOnPage = true;
-braillePageNumber = 0; //number of braille pages
-firstTableName = null;
-dpi = 0; // resolution
-paperWidth = 0;
-paperHeight = 0;
-leftMargin = 0;
-rightMargin = 0;
-topMargin = 0;
-bottomMargin = 0;
-currentBraillePageNumber = 0;
-currentPrintPageNumber = 0;
-Builder parser = new Builder();
-try {
-doc = parser.build (dm.translatedFileName);
-} catch (ParsingException e) {
-new Notify ("Malformed document");
-return;
-}
-catch (IOException e) {
-new Notify ("Could not open " + dm.translatedFileName);
-return;
-}
-Element rootElement = doc.getRootElement();
-findBrlNodes (rootElement);
-}
-
-private void findBrlNodes (Element node) {
-Node newNode;
-Element element;
-String elementName;
-for (int i = 0; i < node.getChildCount(); i++) {
-newNode = node.getChild(i);
-if (newNode instanceof Element) {
-element = (Element)newNode;
-elementName = element.getLocalName();
-if (elementName.equals ("meta")) {
-doUtdMeta (element);
-} else if (elementName.equals ("brl")) {
-if (i > 0) {
-beforeBrlNode = newNode.getChild(i - 1);
-} else {
-beforeBrlNode = null;
-}
-doBrlNode (element);
-} else {
-findBrlNodes (element);
-}
-}
-}
-}
-
-private void doUtdMeta (Element node) {
-if (braillePageNumber != 0) {
-return;
-}
-String metaContent;
-metaContent = node.getAttributeValue ("name");
-if (!(metaContent.equals ("utd"))) {
-return;
-}
-metaContent = node.getAttributeValue ("content");
-String[] keysValues = metaContent.split (" ", 20);
-for (int i = 0; i < keysValues.length; i++) {
-String keyValue[] = keysValues[i].split ("=", 2);
-if (keyValue[0].equals ("BraillePageNumber"))
-braillePageNumber = Integer.parseInt (keyValue[1]);
-else if (keyValue[0].equals ("firstTableName"))
-firstTableName = keyValue[1];
-else if (keyValue[0].equals ("dpi"))
-dpi = Integer.parseInt (keyValue[1]);
-else if (keyValue[0].equals ("paperWidth"))
-paperWidth = Integer.parseInt (keyValue[1]);
-else if (keyValue[0].equals ("paperHeight"))
-paperHeight = Integer.parseInt (keyValue[1]);
-else if (keyValue[0].equals ("leftMargin"))
-leftMargin = Integer.parseInt (keyValue[1]);
-else if (keyValue[0].equals ("rightMargin"))
-rightMargin = Integer.parseInt (keyValue[1]);
-else if (keyValue[0].equals ("topMargin"))
-topMargin = Integer.parseInt (keyValue[1]);
-else if (keyValue[0].equals ("bottomMargin"))
-bottomMargin = Integer.parseInt (keyValue[1]);
-}
-return;
-}
-
-void showLines () {
-brailleLine.append ("\n");
-dm.braille.view.append (brailleLine.toString());
-brailleLine.delete (0, brailleLine.length());
-printLine.append ("\n");
-dm.daisy.view.append (printLine.toString());
-printLine.delete (0, printLine.length());
-}
-
-private void doBrlNode (Element node) {
-String[] indices = node.getAttributeValue ("index").split (" ", 20000);
-if (indices != null) {
-brlIndex = new int[indices.length];
-for (int i = 0; i < indices.length; i++) {
-brlIndex[i] = Integer.parseInt (indices[i]);
-}
-}
-brlIndexPos = 0;
-indices = null;
-Node newNode;
-Element element;
-String elementName;
-for (int i = 0; i < node.getChildCount(); i++) {
-newNode = node.getChild(i);
-if (newNode instanceof Element) {
-element = (Element)newNode;
-elementName = element.getLocalName();
-if (elementName.equals ("newpage")) {
-doNewpage (element);
-} else if (elementName.equals ("newline")) {
-doNewline (element);
-} else if (elementName.equals ("span")) {
-doSpanNode (element);
-} else if (elementName.equals ("graphic")) {
-doGraphic (element);
-}
-}
-else if (newNode instanceof Text) {
-doTextNode (newNode);
-}
-}
-finishBrlNode();
-brlIndex = null;
-brlIndexPos = 0;
-}
-
-private void doSpanNode (Element node) {
-String whichSpan = node.getAttributeValue ("class");
-if (whichSpan.equals ("brlonly")) {
-doBrlonlyNode (node);
-}
-else if (whichSpan.equals ("locked")) {
-doLockedNode (node);
-}
-}
-
-private void doBrlonlyNode (Element node) {
-Node newNode;
-Element element;
-String elementName;
-for (int i = 0; i < node.getChildCount(); i++) {
-newNode = node.getChild(i);
-if (newNode instanceof Element) {
-element = (Element)newNode;
-elementName = element.getLocalName();
-if (elementName.equals ("brl")) {
-insideBrlonly (node);
-}
-}
-else if (newNode instanceof Text) {
-beforeBrlonlyNode = newNode;
-}
-}
-}
-
-private void insideBrlonly (Element node) {
-String[] indices = node.getAttributeValue ("index").split (" ", 20000);
-if (indices != null) {
-brlonlyIndex = new int[indices.length];
-for (int i = 0; i < indices.length; i++) {
-brlonlyIndex[i] = Integer.parseInt (indices[i]);
-}
-}
-brlonlyIndexPos = 0;
-indices = null;
-Node newNode;
-Element element;
-String elementName;
-for (int i = 0; i < node.getChildCount(); i++) {
-newNode = node.getChild(i);
-if (newNode instanceof Element) {
-element = (Element)newNode;
-elementName = element.getLocalName();
-if (elementName.equals ("newpage")) {
-doNewpage (element);
-} else if (elementName.equals ("newline")) {
-doNewline (element);
-} else if (elementName.equals ("graphic")) {
-doGraphic (element);
-}
-}
-else if (newNode instanceof Text) {
-doBrlonlyTextNode (newNode);
-}
-}
-brlonlyIndex = null;
-brlonlyIndexPos = 0;
-}
-
-private void doLockedNode (Element node) {
-}
-
-private void doNewpage (Element node) {
-String pageNumber = node.getAttributeValue ("brlnumber");
-currentBraillePageNumber = Integer.parseInt (pageNumber);
-pageNumber = node.getAttributeValue ("printnumber");
-currentPrintPageNumber = Integer.parseInt (pageNumber);
-firstLineOnPage = true;
-if (firstPage) {
-firstPage = false;
-return;
-}
-showLines();
-}
-
-private void doNewline (Element node) {
-String[] horVertPos = node.getAttributeValue ("xy").split (",", 2);
-if (firstLineOnPage) {
-firstLineOnPage = false;
-return;
-}
-showLines();
-}
-
-private void doTextNode (Node node) {
-Text text = (Text)node;
-brailleLine.append (text.getValue());
-}
-
-private void doBrlonlyTextNode (Node node) {
-Text text = (Text)node;
-brailleLine.append (text.getValue());
-}
-
-private void doGraphic (Element node) {
-}
-
-private void finishBrlNode() {
-return;
-}
+    //static int pageCount;
+    //static int pageCount2;
+
+    int braillePageNumber; //number of braille pages
+    String firstTableName;
+    int dpi; // resolution
+    int paperWidth;
+    int paperHeight;
+    int leftMargin;
+    int rightMargin;
+    int topMargin;
+    int bottomMargin;
+    String currentBraillePageNumber;
+    String currentPrintPageNumber;
+    int[] brlIndex;
+    int brlIndexPos;
+    int[] brlonlyIndex;
+    int brlonlyIndexPos;
+    Node beforeBrlNode;
+    Node beforeBrlonlyNode;
+    private boolean firstPage;
+    private boolean firstLineOnPage;
+    StringBuilder brailleLine = new StringBuilder (100);
+    StringBuilder printLine = new StringBuilder (100);
+    DocumentManager dm;
+    Document doc;
+
+    UTD (final DocumentManager dm) {
+        this.dm = dm;
+    }
+
+    void displayTranslatedFile() {
+        beforeBrlNode = null;
+        beforeBrlonlyNode = null;
+        brlIndex = null;
+        brlIndexPos = 0;
+        brlonlyIndex = null;
+        brlonlyIndexPos = 0;
+        firstPage = true;
+        firstLineOnPage = true;
+        braillePageNumber = 0; //number of braille pages
+        firstTableName = null;
+        dpi = 0; // resolution
+        paperWidth = 0;
+        paperHeight = 0;
+        leftMargin = 0;
+        rightMargin = 0;
+        topMargin = 0;
+        bottomMargin = 0;
+        currentBraillePageNumber = "0";
+        currentPrintPageNumber = "0";
+        Builder parser = new Builder();
+        try {
+            doc = parser.build (dm.translatedFileName);
+        } catch (ParsingException e) {
+            new Notify ("Malformed document");
+            return;
+        }
+        catch (IOException e) {
+ System.out.println("Could not open"+ dm.translatedFileName+" because" + e.getMessage());
+            new Notify ("Could not open " + dm.translatedFileName);
+            return;
+        }
+
+        System.out.println("start getting rootElement");
+
+        Element rootElement = doc.getRootElement();
+        findBrlNodes (rootElement);
+
+    }
+
+    private void findBrlNodes (Element node) {
+        Node newNode;
+        Element element;
+        String elementName;
+        for (int i = 0; i < node.getChildCount(); i++) {
+                newNode = node.getChild(i);
+            if (newNode instanceof Element) {
+                element = (Element)newNode;
+                elementName = element.getLocalName();
+                if (elementName.equals ("meta")) {
+                    doUtdMeta (element);
+                } else if (elementName.equals ("brl")) {
+                    if (i > 0) {
+                        try{
+                            beforeBrlNode = newNode.getChild(i - 1);
+                        }
+                        catch(IndexOutOfBoundsException e ){
+ //The brl child, newNode, may not have any grandchild of node + System.out.println("a brl Node does not have child, i = "+i );
+                            beforeBrlNode = null;
+                            return;
+                        }
+                    } else {
+                        beforeBrlNode = null;
+                    }
+                    doBrlNode (element);
+                } else {
+                    findBrlNodes (element);
+                }
+            }
+        }
+    }
+
+    private void doUtdMeta (Element node) {
+        if (braillePageNumber != 0) {
+            return;
+        }
+        String metaContent;
+        metaContent = node.getAttributeValue ("name");
+        if (!(metaContent.equals ("utd"))) {
+            return;
+        }
+        metaContent = node.getAttributeValue ("content");
+        String[] keysValues = metaContent.split (" ", 20);
+        for (int i = 0; i < keysValues.length; i++) {
+            String keyValue[] = keysValues[i].split ("=", 2);
+            if (keyValue[0].equals ("BraillePageNumber"))
+                braillePageNumber = Integer.parseInt (keyValue[1]);
+            else if (keyValue[0].equals ("firstTableName"))
+                firstTableName = keyValue[1];
+            else if (keyValue[0].equals ("dpi"))
+                dpi = Integer.parseInt (keyValue[1]);
+            else if (keyValue[0].equals ("paperWidth"))
+                paperWidth = Integer.parseInt (keyValue[1]);
+            else if (keyValue[0].equals ("paperHeight"))
+                paperHeight = Integer.parseInt (keyValue[1]);
+            else if (keyValue[0].equals ("leftMargin"))
+                leftMargin = Integer.parseInt (keyValue[1]);
+            else if (keyValue[0].equals ("rightMargin"))
+                rightMargin = Integer.parseInt (keyValue[1]);
+            else if (keyValue[0].equals ("topMargin"))
+                topMargin = Integer.parseInt (keyValue[1]);
+            else if (keyValue[0].equals ("bottomMargin"))
+                bottomMargin = Integer.parseInt (keyValue[1]);
+        }
+        return;
+    }
+
+    void showLines () {
+        brailleLine.append ("\n");
+        dm.braille.view.append (brailleLine.toString());
+        brailleLine.delete (0, brailleLine.length());
+        printLine.append ("\n");
+        dm.daisy.view.append (printLine.toString());
+        printLine.delete (0, printLine.length());
+    }
+
+    private void doBrlNode (Element node) {
+        String tmp = node.getAttributeValue("index");
+        String[] indices = null;
+ if(tmp != null) indices = node.getAttributeValue ("index").split (" ", 20000);
+        if (indices != null) {
+            brlIndex = new int[indices.length];
+            for (int i = 0; i < indices.length; i++) {
+                brlIndex[i] = Integer.parseInt (indices[i]);
+            }
+        }
+        brlIndexPos = 0;
+        indices = null;
+        Node newNode;
+        Element element;
+        String elementName;
+        for (int i = 0; i < node.getChildCount(); i++) {
+            newNode = node.getChild(i);
+            if (newNode instanceof Element) {
+                element = (Element)newNode;
+                elementName = element.getLocalName();
+                if (elementName.equals ("newpage")) {
+                    doNewpage (element);
+                } else if (elementName.equals ("newline")) {
+                    doNewline (element);
+                } else if (elementName.equals ("span")) {
+                    doSpanNode (element);
+                } else if (elementName.equals ("graphic")) {
+                    doGraphic (element);
+                }
+            }
+            else if (newNode instanceof Text) {
+                doTextNode (newNode);
+            }
+        }
+        finishBrlNode();
+        brlIndex = null;
+        brlIndexPos = 0;
+    }
+
+    private void doSpanNode (Element node) {
+        String whichSpan = node.getAttributeValue ("class");
+        if (whichSpan.equals ("brlonly")) {
+            doBrlonlyNode (node);
+        }
+        else if (whichSpan.equals ("locked")) {
+            doLockedNode (node);
+        }
+    }
+
+    private void doBrlonlyNode (Element node) {
+        Node newNode;
+        Element element;
+        String elementName;
+        for (int i = 0; i < node.getChildCount(); i++) {
+            newNode = node.getChild(i);
+            if (newNode instanceof Element) {
+                element = (Element)newNode;
+                elementName = element.getLocalName();
+                if (elementName.equals ("brl")) {
+                    insideBrlonly (node);
+                }
+            }
+            else if (newNode instanceof Text) {
+                beforeBrlonlyNode = newNode;
+            }
+        }
+    }
+
+    private void insideBrlonly (Element node) {
+        String tmp = node.getAttributeValue("index");
+        String[] indices = null;
+        if(tmp != null) indices = tmp.split (" ", 20000);
+        if (indices != null) {
+            brlonlyIndex = new int[indices.length];
+            for (int i = 0; i < indices.length; i++) {
+                brlonlyIndex[i] = Integer.parseInt (indices[i]);
+            }
+        }
+        brlonlyIndexPos = 0;
+        indices = null;
+        Node newNode;
+        Element element;
+        String elementName;
+        for (int i = 0; i < node.getChildCount(); i++) {
+            newNode = node.getChild(i);
+            if (newNode instanceof Element) {
+                element = (Element)newNode;
+                elementName = element.getLocalName();
+                if (elementName.equals ("newpage")) {
+                    doNewpage (element);
+                } else if (elementName.equals ("newline")) {
+                    doNewline (element);
+                } else if (elementName.equals ("graphic")) {
+                    doGraphic (element);
+                }
+            }
+            else if (newNode instanceof Text) {
+                doBrlonlyTextNode (newNode);
+            }
+        }
+        brlonlyIndex = null;
+        brlonlyIndexPos = 0;
+    }
+
+    private void doLockedNode (Element node) {
+    }
+
+    private void doNewpage (Element node) {
+        String pageNumber = node.getAttributeValue ("brlnumber");
+        System.out.print("doNewpage: pageNumber = " +pageNumber);
+        if(pageNumber != null) currentBraillePageNumber = pageNumber;
+        pageNumber = node.getAttributeValue ("printnumber");
+        if(pageNumber!= null) currentPrintPageNumber =pageNumber;
+        System.out.println("done");
+        //this may need to be reconsidered
+        firstLineOnPage = true;
+        if (firstPage) {
+            firstPage = false;
+            return;
+        }
+        showLines();
+    }
+
+    private void doNewline (Element node) {
+        String[] horVertPos = node.getAttributeValue ("xy").split (",", 2);
+        if (firstLineOnPage) {
+            firstLineOnPage = false;
+            return;
+        }
+        showLines();
+    }
+
+    private void doTextNode (Node node) {
+        Text text = (Text)node;
+        brailleLine.append (text.getValue());
+    }
+
+    private void doBrlonlyTextNode (Node node) {
+        Text text = (Text)node;
+        brailleLine.append (text.getValue());
+    }
+
+    private void doGraphic (Element node) {
+    }
+
+    private void finishBrlNode() {
+        return;
+    }

 }

Other related posts:

  • » [brailleblaster] push by john.bo...@xxxxxxxxxxxxxxxxx - working version of UTD class available for testing on 2012-05-06 11:40 GMT - brailleblaster