1 29 30 package nextapp.echo2.webrender; 31 32 import java.io.IOException ; 33 import java.io.InputStream ; 34 import java.io.Serializable ; 35 36 import javax.xml.parsers.DocumentBuilder ; 37 import javax.xml.parsers.DocumentBuilderFactory ; 38 import javax.xml.parsers.ParserConfigurationException ; 39 40 import org.w3c.dom.Document ; 41 import org.w3c.dom.Element ; 42 import org.xml.sax.SAXException ; 43 44 49 public abstract class ServerDelayMessage 50 implements Serializable { 51 52 56 public static final String ELEMENT_ID_MESSAGE = "serverDelayMessage"; 57 58 63 public static final String ELEMENT_ID_LONG_MESSAGE = "serverDelayMessageLong"; 64 65 75 public static ServerDelayMessage createFromResource(String resourceName) 76 throws IOException { 77 Document document; 78 InputStream in = null; 79 try { 80 DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); 81 DocumentBuilder builder = factory.newDocumentBuilder(); 82 in = ServerDelayMessage.class.getResourceAsStream(resourceName); 83 if (in == null) { 84 throw new IOException ("Resource not found: " + resourceName + "."); 85 } 86 document = builder.parse(in); 87 } catch (ParserConfigurationException ex) { 88 throw new IOException ("Failed to parse InputStream."); 89 } catch (SAXException ex) { 90 throw new IOException ("Failed to parse InputStream."); 91 } finally { 92 if (in != null) { 93 try { in.close(); } catch (IOException ex) { } 94 } 95 } 96 97 final Element messageElement = document.getDocumentElement(); 98 return new ServerDelayMessage() { 99 100 103 public Element getMessage() { 104 return messageElement; 105 } 106 }; 107 } 108 109 114 public abstract Element getMessage(); 115 } 116 | Popular Tags |