1 17 package org.alfresco.repo.importer; 18 19 import java.io.BufferedReader ; 20 import java.io.File ; 21 import java.io.FileInputStream ; 22 import java.io.IOException ; 23 import java.io.InputStream ; 24 import java.io.InputStreamReader ; 25 import java.io.Reader ; 26 import java.io.UnsupportedEncodingException ; 27 28 import org.alfresco.service.cmr.view.ImportPackageHandler; 29 import org.alfresco.service.cmr.view.ImporterException; 30 31 32 37 public class FileImportPackageHandler 38 implements ImportPackageHandler 39 { 40 protected File sourceDir; 41 protected File dataFile; 42 protected String dataFileEncoding; 43 44 51 public FileImportPackageHandler(File sourceDir, File dataFile, String dataFileEncoding) 52 { 53 this.sourceDir = sourceDir; 54 this.dataFile = new File (sourceDir, dataFile.getPath()); 55 this.dataFileEncoding = dataFileEncoding; 56 } 57 58 61 public void startImport() 62 { 63 log("Importing from package " + dataFile.getAbsolutePath()); 64 } 65 66 69 public Reader getDataStream() 70 { 71 try 72 { 73 InputStream inputStream = new FileInputStream (dataFile); 74 Reader inputReader = (dataFileEncoding == null) ? new InputStreamReader (inputStream) : new InputStreamReader (inputStream, dataFileEncoding); 75 return new BufferedReader (inputReader); 76 } 77 catch(UnsupportedEncodingException e) 78 { 79 throw new ImporterException("Encoding " + dataFileEncoding + " is not supported"); 80 } 81 catch(IOException e) 82 { 83 throw new ImporterException("Failed to read package " + dataFile.getAbsolutePath() + " due to " + e.getMessage()); 84 } 85 } 86 87 90 public InputStream importStream(String content) 91 { 92 File fileURL = new File (content); 93 if (fileURL.isAbsolute() == false) 94 { 95 fileURL = new File (sourceDir, content); 96 } 97 98 try 99 { 100 return new FileInputStream (fileURL); 101 } 102 catch(IOException e) 103 { 104 throw new ImporterException("Failed to read content url " + content + " from file " + fileURL.getAbsolutePath()); 105 } 106 } 107 108 111 public void endImport() 112 { 113 } 114 115 120 protected void log(String message) 121 { 122 } 123 124 } 125 126 | Popular Tags |