| 167 | | logger.error("couldn't create transformer object: "+e.getMessageAndLocation()); |
|---|
| 168 | | logger.error(e.getLocationAsString()); |
|---|
| 169 | | return null; |
|---|
| 170 | | } catch (TransformerException e) { |
|---|
| 171 | | logger.error("couldn't transform the source: " + e.getMessage()); |
|---|
| 172 | | return null; |
|---|
| 173 | | } |
|---|
| 174 | | |
|---|
| 175 | | |
|---|
| 176 | | } |
|---|
| 177 | | |
|---|
| | 174 | String message = "TransformerConfigurationException: "+e.getMessageAndLocation(); |
|---|
| | 175 | //System.err.println(message); |
|---|
| | 176 | logger.error("couldn't create transformer object: "+e.getMessageAndLocation()); |
|---|
| | 177 | logger.error(e.getLocationAsString()); |
|---|
| | 178 | return constructErrorXHTMLPage(message); |
|---|
| | 179 | } catch (TransformerException e) { |
|---|
| | 180 | String message = "TransformerException: " + e.getMessageAndLocation(); |
|---|
| | 181 | //System.err.println(message); |
|---|
| | 182 | logger.error("couldn't transform the source: " + e.getMessage()); |
|---|
| | 183 | return constructErrorXHTMLPage(message); |
|---|
| | 184 | } |
|---|
| | 185 | |
|---|
| | 186 | |
|---|
| | 187 | } |
|---|
| | 188 | |
|---|
| | 189 | |
|---|
| | 190 | |
|---|
| 192 | | return null; |
|---|
| 193 | | } |
|---|
| 194 | | } |
|---|
| | 206 | String message = "TransformerException: " + e.getMessageAndLocation(); |
|---|
| | 207 | return constructErrorXHTMLPage(message); |
|---|
| | 208 | } |
|---|
| | 209 | } |
|---|
| | 210 | |
|---|
| | 211 | |
|---|
| | 212 | protected Element constructErrorXHTMLPage(String message) { |
|---|
| | 213 | try{ |
|---|
| | 214 | Document xhtmlDoc = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument(); |
|---|
| | 215 | // <html></html> |
|---|
| | 216 | Node htmlNode = xhtmlDoc.createElement("html"); |
|---|
| | 217 | xhtmlDoc.appendChild(htmlNode); |
|---|
| | 218 | // <head></head> |
|---|
| | 219 | Node headNode = xhtmlDoc.createElement("head"); |
|---|
| | 220 | htmlNode.appendChild(headNode); |
|---|
| | 221 | // <title></title> |
|---|
| | 222 | Node titleNode = xhtmlDoc.createElement("title"); |
|---|
| | 223 | headNode.appendChild(titleNode); |
|---|
| | 224 | Node titleString = xhtmlDoc.createTextNode("Error occurred"); |
|---|
| | 225 | titleNode.appendChild(titleString); |
|---|
| | 226 | |
|---|
| | 227 | // <body></body> |
|---|
| | 228 | Node bodyNode = xhtmlDoc.createElement("body"); |
|---|
| | 229 | htmlNode.appendChild(bodyNode); |
|---|
| | 230 | |
|---|
| | 231 | // finally put the message in the body |
|---|
| | 232 | Node h1Node = xhtmlDoc.createElement("h1"); |
|---|
| | 233 | bodyNode.appendChild(h1Node); |
|---|
| | 234 | Node headingString = xhtmlDoc.createTextNode("The following error occurred:"); |
|---|
| | 235 | h1Node.appendChild(headingString); |
|---|
| | 236 | |
|---|
| | 237 | Node textNode = xhtmlDoc.createTextNode(message); |
|---|
| | 238 | bodyNode.appendChild(textNode); |
|---|
| | 239 | |
|---|
| | 240 | return xhtmlDoc.getDocumentElement(); |
|---|
| | 241 | |
|---|
| | 242 | }catch(Exception e) { |
|---|
| | 243 | String errmsg = "Exception trying to construct error xhtml page from message: " + message |
|---|
| | 244 | + "\n" + e.getMessage(); |
|---|
| | 245 | System.err.println(errmsg); |
|---|
| | 246 | logger.error(errmsg); |
|---|
| | 247 | return null; |
|---|
| | 248 | } |
|---|
| | 249 | } |
|---|
| | 250 | |
|---|