1 7 8 package org.jdesktop.jdnc.markup.attr; 9 10 import org.jdesktop.swing.data.DefaultTableModelExt; 11 import org.jdesktop.swing.data.TableModelExtTextLoader; 12 13 import org.jdesktop.swing.data.DOMAdapter; 14 15 import org.jdesktop.jdnc.markup.Attributes; 16 import org.jdesktop.jdnc.markup.Namespace; 17 18 import java.io.IOException ; 19 import java.net.MalformedURLException ; 20 import java.net.URL ; 21 22 import javax.xml.parsers.DocumentBuilderFactory ; 23 24 import net.openmarkup.ApplierError; 25 import net.openmarkup.ApplierException; 26 import net.openmarkup.AttributeApplier; 27 import net.openmarkup.Realizable; 28 29 import org.w3c.dom.Document ; 30 31 import org.jdesktop.jdnc.markup.RealizationUtils; 32 33 37 public class DataAttributes { 38 40 public static void actuateData(DefaultTableModelExt data, String actuateValue) throws IOException { 41 if (actuateValue.equals("") || actuateValue.equals("onLoad")) { 42 data.startLoading(); 43 } 44 } 46 47 public static final AttributeApplier actuateApplier = new AttributeApplier() { 48 public void apply(Realizable target, String namespaceURI, 49 String attributeName, String attributeValue) throws 50 ApplierException { 51 String mediaType = target.getAttributeNSOptional(Namespace.JDNC, 54 Attributes.MEDIA_TYPE); 55 try { 56 if (mediaType.equals("text/jdnc-hierarchical-data")) { 57 } 59 else { 60 DefaultTableModelExt data = (DefaultTableModelExt) target.getObject(); 61 actuateData(data, attributeValue); 62 } 63 } 64 catch (Exception ex) { 65 throw new ApplierException("Couldn't actuate data " + 66 attributeName + "=" + attributeValue, 67 ex); 68 } 69 } 70 }; 71 72 public static final AttributeApplier columnDelimiterApplier = new AttributeApplier() { 73 public void apply(Realizable target, String namespaceURI, 74 String attributeName, String attributeValue) throws ApplierException { 75 DefaultTableModelExt data = (DefaultTableModelExt) target.getObject(); 76 77 ((TableModelExtTextLoader) data.getLoader()).setColumnDelimiter( 78 attributeValue); 79 } 80 }; 81 82 public static final AttributeApplier firstRowHeaderApplier = new AttributeApplier() { 83 public void apply(Realizable target, String namespaceURI, 84 String attributeName, String attributeValue) throws ApplierException { 85 DefaultTableModelExt data = (DefaultTableModelExt) target.getObject(); 86 87 try { 88 ((TableModelExtTextLoader)data.getLoader()).setFirstRowHeader( 89 Boolean.valueOf(attributeValue).booleanValue()); 90 } catch (Exception e) { 91 throw new ApplierException(attributeName + "not supported for loader", e); 92 } 93 } 94 }; 95 96 public static final AttributeApplier sourceApplier = new AttributeApplier() { 97 public void apply(Realizable target, String namespaceURI, 98 String attributeName, String attributeValue) throws ApplierException { 99 URL url = target.getResolvedURL(attributeValue); 101 RealizationUtils.validateURL(url); 102 103 String mediaType = target.getAttributeNSOptional(Namespace.JDNC, 106 Attributes.MEDIA_TYPE); 107 try { 108 if (mediaType.equals("text/jdnc-hierarchical-data")) { 109 DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); 110 dbf.setNamespaceAware(true); 111 dbf.setIgnoringComments(true); 112 Document dom = dbf.newDocumentBuilder().parse( 113 url.toExternalForm()); 114 ((DOMAdapter) target.getObject()).bind(dom); 115 } 116 else { 117 DefaultTableModelExt data = (DefaultTableModelExt) target.getObject(); 118 data.setSource(url); 119 } 120 } 121 catch (Exception ex) { 122 throw new ApplierError("Couldn't set data source " + 123 attributeName + "=" + attributeValue, ex); 124 } 125 } 126 }; 127 128 } 129 | Popular Tags |