1 package org.exoplatform.services.xml.querying.impl.xtas.resource.plugins; 2 3 import java.io.FileOutputStream ; 4 import java.io.FileInputStream ; 5 import java.io.File ; 6 import java.io.IOException ; 7 import org.exoplatform.services.xml.querying.UniFormTransformationException; 8 import org.exoplatform.services.xml.querying.XMLWellFormedData; 9 import org.exoplatform.services.xml.querying.impl.xtas.WellFormedUniFormTree; 10 import org.exoplatform.services.xml.querying.impl.xtas.resource.Resource; 11 import org.xml.sax.InputSource ; 12 13 17 public class LocalFile extends Resource { 18 21 public LocalFile(String resourceId) 22 { 23 this.resourceId = resourceId; 24 } 25 26 public LocalFile() 27 { 28 } 29 30 public void setContext(Object context) 31 { 32 } 33 34 38 public XMLWellFormedData load() throws UniFormTransformationException, IOException 39 { 40 41 File file = new File (resourceId); 42 43 try { 44 45 WellFormedUniFormTree tree = new WellFormedUniFormTree (); 46 tree.init ( new InputSource (file.getCanonicalPath()) ); 47 48 return tree; 49 50 } catch (Exception e) { 51 52 throw new UniFormTransformationException("Can not create WellFormedUniFormTree (XML) Reason: " + e); 53 } 54 } 55 56 public void save(XMLWellFormedData tree) throws IOException 57 { 58 59 60 FileOutputStream fos = new FileOutputStream ( resourceId ); 61 62 byte[] b = tree.getAsByteArray(); 63 64 fos.write( b, 0, b.length ); 65 66 fos.flush(); 67 fos.close(); 68 69 } 70 71 74 public void create(XMLWellFormedData initTree) throws IOException 75 { 76 77 File res = new File (resourceId); 78 if( !res.createNewFile() ) 79 throw new IOException (" File '"+res.getAbsolutePath()+"' already exists."); 80 81 83 } 84 85 88 public void drop() throws IOException 89 { 90 File res = new File (resourceId); 91 if( !res.delete() ) 92 throw new IOException (" File '"+res.getAbsolutePath()+"' can not be deleted."); 93 } 94 95 96 } 97 | Popular Tags |