1 23 24 package com.sun.enterprise.tools.admingui.taglib; 25 26 import com.iplanet.jato.*; 27 import com.iplanet.jato.model.*; 28 import com.iplanet.jato.view.*; 29 import com.iplanet.jato.view.html.*; 30 31 import com.sun.web.ui.common.CCDebug; 32 import com.sun.web.ui.model.CCPropertySheetModel; 33 34 import org.w3c.dom.*; 35 import org.xml.sax.*; 36 import org.xml.sax.helpers.*; 37 38 import java.io.*; 39 import java.util.*; 40 import javax.servlet.*; 41 import javax.xml.parsers.*; 42 43 44 public class DataSheetModel extends CCPropertySheetModel 45 implements DataSheetModelInterface { 46 49 public DataSheetModel() { 50 super(); 51 } 52 53 58 public DataSheetModel(String value) { 59 super(value); 60 } 61 62 70 public DataSheetModel(ServletContext sc, String file) { 71 super(sc, file); 72 } 73 74 84 public DataSheetModel(InputStream is) { 85 super(is); 86 } 87 88 92 transient private EntityResolver entityResolver = null; 93 94 public void setEntityResolver(EntityResolver er) { 95 this.entityResolver = er; 96 } 97 98 public EntityResolver getEntityResolver() { 99 return entityResolver; 100 } 101 102 protected void createDocument(InputStream is) 103 throws IllegalArgumentException { 104 if (is == null) { 105 throw new IllegalArgumentException ("Invalid parameter: "+ 106 "The InputStream is null in CCPropertySheetModel."); 107 } 108 EntityResolver er = getEntityResolver(); 109 if (er == null) 110 super.createDocument(is); 111 else 112 this.createDocument(is, er); 113 } 114 115 protected void createDocument(InputStream is, EntityResolver er) 116 throws IllegalArgumentException { 117 if (is == null) { 118 throw new IllegalArgumentException ("Invalid parameter."); 119 } 120 if (er == null) { 121 super.createDocument(is); 122 return; 123 } 124 125 DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); 127 factory.setIgnoringElementContentWhitespace(true); 128 factory.setValidating(true); 129 130 try { 131 DocumentBuilder documentBuilder = factory.newDocumentBuilder(); 132 documentBuilder.setEntityResolver(er); 133 documentBuilder.setErrorHandler(new DefaultHandler() { 134 public void error(SAXParseException e) { 135 throw new IllegalArgumentException (e.getMessage()); 136 } 137 public void fatalError(SAXParseException e) { 138 throw new IllegalArgumentException (e.getMessage()); 139 } 140 public void warning(SAXParseException e) { 141 CCDebug.trace3(e.getMessage()); 142 } 143 }); 144 document = documentBuilder.parse(is); 145 } catch (IOException e) { 146 throw new IllegalArgumentException (e.getMessage()); 147 } catch (SAXException e) { 148 throw new IllegalArgumentException (e.getMessage()); 149 } catch (ParserConfigurationException e) { 150 throw new IllegalArgumentException (e.getMessage()); 151 } 152 } 153 } 154 | Popular Tags |