1 20 21 package org.netbeans.modules.j2ee.websphere6.config.sync; 22 23 import java.io.*; 24 import java.util.LinkedList ; 25 import javax.xml.parsers.DocumentBuilder ; 26 import javax.xml.parsers.DocumentBuilderFactory ; 27 import javax.xml.parsers.ParserConfigurationException ; 28 import javax.xml.transform.*; 29 import javax.xml.transform.dom.DOMSource ; 30 import javax.xml.transform.stream.StreamResult ; 31 import org.openide.filesystems.FileChangeAdapter; 32 import org.openide.filesystems.FileEvent; 33 import org.openide.filesystems.FileObject; 34 import org.openide.filesystems.FileUtil; 35 import org.w3c.dom.Document ; 36 import org.xml.sax.SAXException ; 37 38 42 public abstract class Synchronizer { 43 44 protected static final String BINDING_SEPARATOR = "__Bnd__"; 45 46 protected void saveDocument(Document document, File file) throws TransformerException, FileNotFoundException, IOException { 47 OutputStream outputStream = null; 48 49 try { 50 TransformerFactory tf = TransformerFactory.newInstance(); 51 Transformer transformer = tf.newTransformer(); 52 outputStream = new FileOutputStream(file); 53 DOMSource ds = new DOMSource (document); 54 StreamResult sr = new StreamResult (outputStream); 55 transformer.transform(ds, sr); 56 } finally { 57 if (outputStream != null) { 58 outputStream.close(); 59 } 60 } 61 } 62 protected Document loadDocument(File file) { 63 Document res = null; 64 try { 65 DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); 66 DocumentBuilder builder = factory.newDocumentBuilder(); 68 res = builder.parse(file); 69 } catch (SAXException ex) { 70 } catch (IOException ex) { 71 } catch (ParserConfigurationException ex) { 72 } 73 return res; 74 } 75 public abstract void syncDescriptors(); 76 77 private LinkedList <File> list = new LinkedList <File> (); 78 79 public void addSyncFile(File file) { 80 FileObject obj = FileUtil.toFileObject(file); 81 if(!list.contains(file)) { 82 list.add(file); 83 obj.addFileChangeListener(new FileChangeAdapter() { 84 public void fileChanged(FileEvent event) { 85 syncDescriptors(); 86 } 87 }); 88 } 89 } 90 } 91 | Popular Tags |