1 19 20 package org.netbeans.modules.web.taglib; 21 22 import java.io.*; 23 import org.xml.sax.InputSource ; 24 25 import org.openide.loaders.*; 26 import org.openide.filesystems.FileObject; 27 import org.openide.nodes.Node; 28 import org.openide.util.NbBundle; 29 30 import org.netbeans.api.xml.cookies.ValidateXMLCookie; 31 import org.netbeans.api.xml.cookies.CheckXMLCookie; 32 import org.netbeans.spi.xml.cookies.*; 33 34 import org.netbeans.modules.web.taglib.model.Taglib; 35 36 41 public final class TLDDataObject extends MultiDataObject implements org.openide.nodes.CookieSet.Factory { 42 43 private static final boolean debug = false; 44 45 private transient TLDEditorSupport editorSupport; 46 47 private static final long serialVersionUID = -7581377241494497816L; 48 49 public TLDDataObject () 50 throws DataObjectExistsException, IOException { 51 super(null, null); 52 if (debug) System.out.println("====> TLDDataObject():constructor"); } 54 55 public TLDDataObject (final FileObject obj, final MultiFileLoader loader) 56 throws DataObjectExistsException, IOException { 57 super (obj, loader); 58 59 getCookieSet().add(TLDEditorSupport.class, this); 60 61 InputSource in = DataObjectAdapters.inputSource(this); 63 CheckXMLCookie checkCookie = new CheckXMLSupport(in); 64 getCookieSet().add(checkCookie); 65 ValidateXMLCookie validateCookie = new ValidateXMLSupport(in); 66 getCookieSet().add(validateCookie); 67 68 if (debug) System.out.println("====> TLDDataObject(FileObject, loader):constructor()"); 70 91 } 92 93 105 protected synchronized Node createNodeDelegate () { 106 return new TLDNode(this); 107 } 108 109 org.openide.nodes.CookieSet getCookieSet0() { 111 return getCookieSet(); 112 } 113 114 public Taglib getTaglib() throws java.io.IOException { 115 java.io.InputStream is = getPrimaryFile().getInputStream(); 116 try { 117 return Taglib.createGraph(is); 118 } catch (RuntimeException ex) { 119 throw new java.io.IOException (ex.getMessage()); 120 } 121 } 122 123 public void write(Taglib taglib) throws java.io.IOException { 124 java.io.File file = org.openide.filesystems.FileUtil.toFile(getPrimaryFile()); 125 org.openide.filesystems.FileObject tldFO = getPrimaryFile(); 126 try { 127 org.openide.filesystems.FileLock lock = tldFO.lock(); 128 try { 129 java.io.OutputStream os = tldFO.getOutputStream(lock); 130 try { 131 String version=taglib.getAttributeValue("version"); if (version==null) { taglib.changeDocType("-//Sun Microsystems, Inc.//DTD JSP Tag Library 1.2//EN", "http://java.sun.com/dtd/web-jsptaglibrary_1_2.dtd"); taglib.setAttributeValue("xmlns",null); } 137 taglib.write(os); 138 } finally { 139 os.close(); 140 } 141 } 142 finally { 143 lock.releaseLock(); 144 } 145 } catch (org.openide.filesystems.FileAlreadyLockedException ex) { 146 } 148 } 149 150 151 public Node.Cookie createCookie(Class clazz) { 152 if(clazz.isAssignableFrom(TLDEditorSupport.class)) 153 return getEditorSupport(); 154 else 155 return null; 156 } 157 158 159 private TLDEditorSupport getEditorSupport() { 160 if(editorSupport == null) { 161 synchronized(this) { 162 if(editorSupport == null) 163 editorSupport = new TLDEditorSupport(this); 164 } 165 } 166 167 return editorSupport; 168 } 169 170 } 171 | Popular Tags |