[brailleblaster] [brailleblaster.newdesign] push by brandon....@xxxxxxxxx - Added exception handling for internet connection issues on 2013-07-16 18:10 GMT

  • From: brailleblaster@xxxxxxxxxxxxxx
  • To: brailleblaster@xxxxxxxxxxxxx
  • Date: Tue, 16 Jul 2013 18:10:46 +0000

Revision: b3e90990750c
Branch:   default
Author:   Brandon Roller <brandon.r.roller@xxxxxxxxx>
Date:     Tue Jul 16 11:09:48 2013
Log:      Added exception handling for internet connection issues
http://code.google.com/p/brailleblaster/source/detail?r=b3e90990750c&repo=newdesign

Modified:
 /src/main/org/brailleblaster/wordprocessor/BBDocument.java
 /src/main/org/brailleblaster/wordprocessor/Normalizer.java

=======================================
--- /src/main/org/brailleblaster/wordprocessor/BBDocument.java Mon Jul 15 11:47:33 2013 +++ /src/main/org/brailleblaster/wordprocessor/BBDocument.java Tue Jul 16 11:09:48 2013
@@ -32,8 +32,11 @@
 import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
+import java.io.PrintWriter;
 import java.io.StringReader;
+import java.io.StringWriter;
 import java.io.UnsupportedEncodingException;
+import java.net.ConnectException;
 import java.util.ArrayList;
 import java.util.logging.Level;
 import java.util.logging.Logger;
@@ -136,17 +139,31 @@
                        removeBraillePageNumber();
                        return true;
                }
+               catch(ConnectException e){
+ new Notify("Brailleblaster failed to access necessary materials from online. Please check your internet connection and try again.");
+                       e.printStackTrace();
+                       printErrors(e);
+                       return false;
+               }
                catch (ParsingException e) {
                        new Notify("Problem processing " + fileName + " See stack 
trace.");
                        e.printStackTrace();
+                       printErrors(e);
                        return false;
                }
                catch (IOException e) {
new Notify ("IO error occurred while parsing " + fileName + " See stack trace.");
                        e.printStackTrace();
+                       printErrors(e);
                        return false;
                }
        }
+
+       private void printErrors(Exception e){
+               StringWriter errors = new StringWriter();
+               e.printStackTrace(new PrintWriter(errors));
+               logger.log(Level.SEVERE, errors.toString());
+       }

        private void normalizeFile(String originalFilePath, String 
tempFilePath){
                Normalizer n = new Normalizer(originalFilePath);
=======================================
--- /src/main/org/brailleblaster/wordprocessor/Normalizer.java Mon Jul 15 07:48:47 2013 +++ /src/main/org/brailleblaster/wordprocessor/Normalizer.java Tue Jul 16 11:09:48 2013
@@ -3,7 +3,14 @@
 import java.io.File;
 import java.io.FileWriter;
 import java.io.IOException;
+import java.io.PrintWriter;
+import java.io.StringWriter;
+import java.net.ConnectException;
+import java.util.logging.Level;
+import java.util.logging.Logger;

+import org.brailleblaster.BBIni;
+import org.brailleblaster.util.Notify;
 import org.w3c.dom.Document;

 import org.w3c.dom.CDATASection;
@@ -28,6 +35,7 @@
 public class Normalizer {
        File f;
        Document doc;
+       Logger log = BBIni.getLogger();

        public Normalizer(String path){
                this.f = new File(path);
@@ -37,16 +45,33 @@
                        dBuilder = dbFactory.newDocumentBuilder();
                        this.doc = dBuilder.parse(this.f);
                }
+               catch(ConnectException e){
+ new Notify("Brailleblaster failed to access necessary materials from online. Please check your internet connection and try again.");
+                       e.printStackTrace();
+                       printErrors(e);
+               }
                catch (ParserConfigurationException e) {
+ new Notify("An error occurred while reading the document. Please check whehther the document contains vaild XML.");
                        e.printStackTrace();
+                       printErrors(e);
                }
                catch (SAXException e) {
+ new Notify("An error occurred while reading the document. Please check whehther the document contains vaild XML.");
                        e.printStackTrace();
+                       printErrors(e);
                }
                catch (IOException e) {
+                       new Notify("An error occurred while reading the 
document.");
                        e.printStackTrace();
+                       printErrors(e);
                }
        }
+
+       private void printErrors(Exception e){
+               StringWriter errors = new StringWriter();
+               e.printStackTrace(new PrintWriter(errors));
+               log.log(Level.SEVERE, errors.toString());
+       }

        public void createNewNormalizedFile(String path){
                normalize();

Other related posts:

  • » [brailleblaster] [brailleblaster.newdesign] push by brandon....@xxxxxxxxx - Added exception handling for internet connection issues on 2013-07-16 18:10 GMT - brailleblaster