1 17 package com.sslexplorer.vfs.webdav; 18 19 import java.io.IOException ; 20 import java.io.PrintWriter ; 21 22 import com.sslexplorer.vfs.VFSResource; 23 24 25 32 public class DAVException extends RuntimeException { 33 34 private VFSResource resource = null; 35 private int status = 0; 36 37 40 public DAVException(int status, String message) { 41 this(status, message, null, null); 42 } 43 44 47 public DAVException(int status, String message, Throwable throwable) { 48 this(status, message, throwable, null); 49 } 50 51 54 public DAVException(int status, String message, VFSResource resource) { 55 this(status, message, null, resource); 56 } 57 58 61 public DAVException(int s, String m, Throwable t, VFSResource r) { 62 super(m, t); 63 this.resource = r; 64 this.status = s; 65 } 66 67 70 public int getStatus() { 71 return this.status; 72 } 73 74 77 public VFSResource getResource() { 78 return this.resource; 79 } 80 81 85 public void write(DAVTransaction transaction) 86 throws IOException { 87 transaction.setContentType("text/html; charset=\"utf-8\""); 88 transaction.setStatus(this.getStatus()); 89 90 91 String message = DAVUtilities.getStatusMessage(this.getStatus()); 92 if (message == null) { 93 transaction.setStatus(500); 94 message = Integer.toString(this.getStatus()) + " Unknown"; 95 } 96 97 98 PrintWriter out = transaction.write("utf-8"); 99 out.println("<html>"); 100 out.print("<head><title>Error "); 101 out.print(message); 102 out.println("</title></head>"); 103 out.println("<body>"); 104 out.print("<p><b>Error "); 105 out.print(message); 106 out.println("</b></p>"); 107 108 109 if (this.getResource() != null) { 110 String r = transaction.lookup(this.getResource()).toASCIIString(); 111 out.print("<p>Resource in error: <a HREF=\""); 112 out.print(r); 113 out.println("\">"); 114 out.print(r); 115 out.println("</a></p>"); 116 } 117 118 119 Throwable throwable = this; 120 out.println("<hr /><p>Exception details:</p>"); 121 while (throwable != null) { 122 out.print("<pre>"); 123 throwable.printStackTrace(out); 124 out.println("</pre>"); 125 throwable = throwable.getCause(); 126 if (throwable != null) out.println("<hr /><p>Caused by:</p>"); 127 } 128 129 130 out.println("</body>"); 131 out.println("</html>"); 132 out.flush(); 133 } 134 } 135 | Popular Tags |