1 package org.enhydra.snapper.parsers; 2 import java.io.*; 3 import java.util.zip.*; 4 5 import org.enhydra.snapper.api.Parser; 6 import org.enhydra.snapper.utils.ReadWriteTextFile; 7 8 public class OoToText implements org.enhydra.snapper.api.Parser 9 { 10 final int BUFFER = 2048; 11 String content = "content.xml"; 12 String meta = "meta.xml"; 13 String tempFile; 14 String metaFile = ""; 15 String title, parsedText, fileName; 16 17 public String parse(InputStream is) throws java.io.IOException { return "";} 18 19 public OoToText(String fileName, 20 String tempFile) 21 { 22 this.fileName = fileName; 23 this.tempFile = tempFile; 24 } 26 27 public void parse(){ 28 30 FileOutputStream fos = null; 31 BufferedOutputStream dest; 32 FileInputStream fis = null; 33 ZipInputStream zis = null; 34 try{ 35 fis = new FileInputStream(fileName); 36 zis = new ZipInputStream(new BufferedInputStream(fis)); 37 } 38 catch (FileNotFoundException fnfe) { 39 try{ 40 ParserManager.logger.debug("File not found!"); 41 } catch (Exception ex) { 42 System.out.println("File not found!"); 43 } 44 } 45 int count; 46 String entryName = ""; 47 byte[] data = new byte[BUFFER]; 48 try 49 { 50 ZipEntry entry; 51 while ((entry = zis.getNextEntry()) != null) 52 { 53 entryName = entry.getName(); 54 if (entryName.endsWith(content)) 55 { 56 fos = new FileOutputStream(tempFile); 57 dest = new BufferedOutputStream(fos, BUFFER); 58 while ((count = zis.read(data, 0, BUFFER)) != -1) 59 { 60 dest.write(data, 0, count); 61 } 62 63 dest.flush(); 64 dest.close(); 65 parsedText = ReadWriteTextFile.getContents(new File(this.tempFile)); 66 69 } 70 83 else 84 { 85 } 87 } 88 fos.close(); 89 fos = null; 90 fis.close(); 91 fis = null; 92 zis.close(); 93 tempFile = null; 94 } 95 catch (Exception eZ) 96 { 97 try{ 98 ParserManager.logger.debug("File could not be parsed: " + fileName); 99 } catch (Exception ex) { 100 System.out.println("***** File could not be parsed: " + fileName); 101 } 102 } 103 finally 104 { 105 } 107 } 108 109 public void setFileName(String fileName) { 110 this.fileName = fileName; 111 } 112 113 public String getParsedText() { 114 return parsedText; 115 } 116 117 public String getTitle() { 118 return title; 119 } 120 } 121 | Popular Tags |