1 19 package org.netbeans.modules.xml.tax.cookies; 20 21 import java.io.Reader ; 22 import java.io.InputStream ; 23 import java.io.IOException ; 24 25 import org.xml.sax.*; 26 27 import org.netbeans.tax.*; 28 import org.netbeans.tax.io.*; 29 import org.netbeans.modules.xml.core.sync.*; 30 import org.netbeans.modules.xml.tax.cookies.TreeEditorCookie; 31 import org.netbeans.modules.xml.tax.cookies.TreeEditorCookieImpl; 32 33 39 public abstract class TreeRepresentation extends SyncRepresentation { 40 41 protected final TreeEditorCookieImpl editor; 42 43 44 public TreeRepresentation(TreeEditorCookieImpl editor, Synchronizator sync) { 45 super(sync); 46 this.editor = editor; 47 } 48 49 52 public boolean represents(Class type) { 53 return TreeDocumentRoot.class.isAssignableFrom(type); 54 } 55 56 public int level() { 57 return 2; 58 } 59 60 63 public Class getUpdateClass() { 64 return InputSource.class; 65 } 66 67 71 public String getDisplayName() { 72 return Util.THIS.getString ("PROP_Tree_representation"); 73 } 74 75 78 public Object getChange(Class type) { 79 if (type == null || type.isAssignableFrom(Reader .class)) { 80 81 try { 82 return new TreeReader(editor.openDocumentRoot()); 83 } catch (IOException ex) { 84 return null; 85 } catch (TreeException ex) { 86 return null; 87 } 88 89 } else if (type.isAssignableFrom(String .class)) { 90 91 try { 92 return Convertors.treeToString(editor.openDocumentRoot()); 93 94 } catch (IOException ex) { 95 ex.printStackTrace(); 96 return null; 97 } catch (TreeException ex) { 98 ex.printStackTrace(); 99 return null; 100 } 101 102 } else if (type.isAssignableFrom(InputStream .class)) { 103 104 try { 105 return new TreeInputStream(editor.openDocumentRoot()); 106 } catch (IOException ex) { 107 return null; 108 } catch (TreeException ex) { 109 return null; 110 } 111 } 112 113 return null; 114 } 115 116 119 public boolean isValid() { 120 return editor.getStatus() == TreeEditorCookie.STATUS_OK; 121 } 122 } 123 | Popular Tags |