Revision: 63e2e06db33a Branch: default Author: Brandon Roller <brandon.r.roller@xxxxxxxxx> Date: Wed Jul 17 11:36:58 2013 Log: Added code to clean-up temp folder on exit http://code.google.com/p/brailleblaster/source/detail?r=63e2e06db33a&repo=newdesign Modified: /src/main/org/brailleblaster/Main.java /src/main/org/brailleblaster/wordprocessor/BBDocument.java /src/main/org/brailleblaster/wordprocessor/DocumentManager.java /src/main/org/brailleblaster/wordprocessor/Normalizer.java ======================================= --- /src/main/org/brailleblaster/Main.java Mon Jul 15 06:37:20 2013 +++ /src/main/org/brailleblaster/Main.java Wed Jul 17 11:36:58 2013 @@ -31,6 +31,9 @@ package org.brailleblaster; +import java.io.File; + +import org.brailleblaster.util.FileUtils; import org.brailleblaster.wordprocessor.WPManager; import org.liblouis.liblouisutdml; @@ -42,7 +45,7 @@ */ public class Main { - public static void main(String[] args) { + public static void main(String[] args) { BBIni.initialize(args); BBIni.setVersion("BrailleBlaster, Version 2013.07.15"); BBIni.setReleaseDate("July 15, 2013"); @@ -57,6 +60,8 @@ if (BBIni.haveLiblouisutdml()) { liblouisutdml louisutdml = liblouisutdml.getInstance(); louisutdml.free(); + FileUtils fu = new FileUtils(); + fu.deleteDirectory(new File(BBIni.getTempFilesPath())); } } } =======================================--- /src/main/org/brailleblaster/wordprocessor/BBDocument.java Wed Jul 17 08:37:13 2013 +++ /src/main/org/brailleblaster/wordprocessor/BBDocument.java Wed Jul 17 11:36:58 2013
@@ -99,12 +99,13 @@ String ext = completePath.substring (extPos); if (ext.equalsIgnoreCase ("xml")) {String tempPath = BBIni.getTempFilesPath() + completePath.substring(completePath.lastIndexOf(BBIni.getFileSep()), completePath.lastIndexOf(".")) + "_temp.xml";
- normalizeFile(completePath, tempPath);- if(lutdml.translateFile (configFileWithPath, tempPath, outFile, logFile, configWithUTD, 0)){ + if(normalizeFile(completePath, tempPath) && lutdml.translateFile (configFileWithPath, tempPath, outFile, logFile, configWithUTD, 0)){
deleteFile(tempPath); return buildDOM(outFile); } + else + return false; } else if (ext.equalsIgnoreCase ("txt")) {if(lutdml.translateTextFile (configFileWithPath, completePath, outFile, logFile, configWithUTD, 0))
@@ -165,9 +166,9 @@ } } - private void normalizeFile(String originalFilePath, String tempFilePath){+ private boolean normalizeFile(String originalFilePath, String tempFilePath){
Normalizer n = new Normalizer(originalFilePath); - n.createNewNormalizedFile(tempFilePath); + return n.createNewNormalizedFile(tempFilePath); } public void updateDOM(MapList list, Message message){ =======================================--- /src/main/org/brailleblaster/wordprocessor/DocumentManager.java Wed Jul 17 08:37:13 2013 +++ /src/main/org/brailleblaster/wordprocessor/DocumentManager.java Wed Jul 17 11:36:58 2013
@@ -286,6 +286,7 @@ } catch(Exception e){ e.printStackTrace(); + logger.log(Level.SEVERE, "Unforeseen Exception", e); } } @@ -624,55 +625,55 @@ public void refresh(){ int currentOffset; - - if(this.text.view.isFocusControl()){ - currentOffset = this.text.view.getCaretOffset(); - resetViews(); - initializeDocumentTab(); + if(this.document.getDOM() != null){ + if(this.text.view.isFocusControl()){ + currentOffset = this.text.view.getCaretOffset(); + resetViews(); + initializeDocumentTab(); + + if(currentOffset < this.text.view.getCharCount()){ + this.text.view.setCaretOffset(currentOffset); + } + else + this.text.view.setCaretOffset(0); - if(currentOffset < this.text.view.getCharCount()){ - this.text.view.setCaretOffset(currentOffset); + setCurrentOnRefresh("text",currentOffset); + this.text.setPositionFromStart(); + this.text.view.setFocus(); } - else - this.text.view.setCaretOffset(0); + else if(this.braille.view.isFocusControl()){ + currentOffset = this.braille.view.getCaretOffset(); + resetViews(); + initializeDocumentTab(); - setCurrentOnRefresh("text",currentOffset); - this.text.setPositionFromStart(); - this.text.view.setFocus(); - } - else if(this.braille.view.isFocusControl()){ - currentOffset = this.braille.view.getCaretOffset(); - resetViews(); - initializeDocumentTab(); - - this.braille.view.setCaretOffset(currentOffset); - setCurrentOnRefresh("braille",currentOffset); - this.braille.setPositionFromStart(); - this.braille.view.setFocus(); - } - else if(this.treeView.tree.isFocusControl()){ - if(this.text.view.getCaretOffset() > 0) - currentOffset = this.text.view.getCaretOffset(); - else - currentOffset = list.getCurrent().start; + this.braille.view.setCaretOffset(currentOffset); + setCurrentOnRefresh("braille",currentOffset); + this.braille.setPositionFromStart(); + this.braille.view.setFocus(); + } + else if(this.treeView.tree.isFocusControl()){ + if(this.text.view.getCaretOffset() > 0) + currentOffset = this.text.view.getCaretOffset(); + else + currentOffset = list.getCurrent().start; - resetViews(); - initializeDocumentTab(); + resetViews(); + initializeDocumentTab(); - - setCurrentOnRefresh(null, currentOffset); - this.text.view.setCaretOffset(currentOffset); - this.text.setPositionFromStart(); - } - else { - currentOffset = this.text.view.getCaretOffset(); + setCurrentOnRefresh(null, currentOffset); + this.text.view.setCaretOffset(currentOffset); + this.text.setPositionFromStart(); + } + else { + currentOffset = this.text.view.getCaretOffset(); - resetViews(); - initializeDocumentTab(); + resetViews(); + initializeDocumentTab(); - setCurrentOnRefresh(null,currentOffset); - this.text.view.setCaretOffset(currentOffset); - this.text.setPositionFromStart(); + setCurrentOnRefresh(null,currentOffset); + this.text.view.setCaretOffset(currentOffset); + this.text.setPositionFromStart(); + } } } @@ -711,7 +712,8 @@ serializer = new Serializer(os, "UTF-8"); serializer.write(newDoc); os.close(); - } catch (FileNotFoundException e) { + } + catch (FileNotFoundException e) { e.printStackTrace(); logger.log(Level.SEVERE, "File Not Found Exception", e); return false; =======================================--- /src/main/org/brailleblaster/wordprocessor/Normalizer.java Wed Jul 17 08:37:13 2013 +++ /src/main/org/brailleblaster/wordprocessor/Normalizer.java Wed Jul 17 11:36:58 2013
@@ -67,11 +67,13 @@ } } - public void createNewNormalizedFile(String path){ + public boolean createNewNormalizedFile(String path){ if(this.doc != null){ normalize(); - write(this.doc, path); + return write(this.doc, path); } + + return false; } private void normalize(){ @@ -94,6 +96,7 @@ } } } + private boolean onlyWhitespace(String text){ for(int j = 0; j < text.length(); j++){ if(!Character.isWhitespace(text.charAt(j))){ @@ -103,7 +106,7 @@ return true; } - public void write(Document document, String path) { + public boolean write(Document document, String path) { try {TransformerFactory transformerFactory = TransformerFactory.newInstance();
Transformer transformer; @@ -111,15 +114,21 @@ DOMSource source = new DOMSource(doc); StreamResult result = new StreamResult(new File(path)); transformer.transform(source, result); + return true; } catch (TransformerConfigurationException e) { e.printStackTrace(); log.log(Level.SEVERE, "Transformer Configuration Exception", e); + return false; } catch (TransformerException e) { e.printStackTrace(); log.log(Level.SEVERE, "Transformer Exception", e); + return false; + } + catch(Exception e){ + e.printStackTrace(); + log.log(Level.SEVERE, "Unforeseen Exception", e); + return false; } - - } }