1 19 20 package org.netbeans.modules.editor.options; 21 22 import org.openide.filesystems.FileStateInvalidException; 23 import java.io.IOException ; 24 import java.io.OutputStream ; 25 import java.util.ArrayList ; 26 import org.openide.filesystems.FileLock; 27 import org.openide.filesystems.FileObject; 28 import org.openide.xml.XMLUtil; 29 import java.util.List ; 30 import org.openide.filesystems.FileSystem; 31 import org.w3c.dom.Document ; 32 import org.openide.loaders.DataFolder; 33 import org.openide.loaders.DataObject; 34 35 42 public class MultiPropertyFolder { 43 protected BaseOptions base; 44 protected DataFolder folder; 45 46 public MultiPropertyFolder(DataFolder fld, BaseOptions option){ 47 this.base = option; 48 this.folder = fld; 49 } 50 51 52 List getProperties(){ 53 List newSettings = new ArrayList (); 54 DataObject dob[] = folder.getChildren(); 55 56 for (int i=0; i<dob.length; i++){ 57 newSettings.add(dob[i]); 58 } 59 60 return newSettings; 61 } 62 63 64 void setProperties(List newProps){ 65 } 67 68 public String getName(){ 69 return folder.getName(); 70 } 71 72 73 public DataFolder getDataFolder(){ 74 return folder; 75 } 76 77 78 protected void deleteFile(final String fileToDelete, final String ext){ 79 try{ 80 folder.getPrimaryFile().getFileSystem().runAtomicAction(new FileSystem.AtomicAction() { 81 public void run() throws IOException { 82 FileObject delFO = folder.getPrimaryFile().getFileObject(fileToDelete, ext); 83 if( delFO != null){ 84 FileLock lock = delFO.lock(); 85 try { 86 delFO.delete(lock); 87 } finally { 88 lock.releaseLock(); 89 } 90 91 } 92 } 93 }); 94 }catch(FileStateInvalidException fsie){ 95 fsie.printStackTrace(); 96 }catch(IOException ioe){ 97 ioe.printStackTrace(); 98 } 99 } 100 101 102 protected void createEmptyXMLFiles(final List fileName, String tagRoot, String publicID, String systemID){ 103 104 final Document doc = XMLUtil.createDocument(tagRoot, null, publicID, systemID); 105 106 try{ 107 folder.getPrimaryFile().getFileSystem().runAtomicAction(new FileSystem.AtomicAction() { 108 public void run() throws IOException { 109 for (int i=0; i<fileName.size(); i++){ 110 111 if( folder.getPrimaryFile().getFileObject((String )fileName.get(i), "xml") != null) continue; 113 FileObject fo = folder.getPrimaryFile().createData((String )fileName.get(i), "xml"); FileLock lock = fo.lock(); 116 try { 117 OutputStream os = fo.getOutputStream(lock); 118 try { 119 XMLUtil.write(doc, fo.getOutputStream(lock), "UTF-8"); } finally { 121 os.close(); 122 } 123 } finally { 124 lock.releaseLock(); 125 } 126 } 127 } 128 }); 129 }catch(FileStateInvalidException fsie){ 130 fsie.printStackTrace(); 131 }catch(IOException ioe){ 132 ioe.printStackTrace(); 133 } 134 } 135 136 137 } 138 | Popular Tags |