Changeset 17024 for greenstone3/trunk/src/java/org/greenstone/gsdl3/util
- Timestamp:
- 2008-08-27T18:14:55+12:00 (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
greenstone3/trunk/src/java/org/greenstone/gsdl3/util/XMLTransformer.java
r13270 r17024 30 30 import javax.xml.transform.dom.DOMResult; 31 31 32 import javax.xml.parsers.DocumentBuilderFactory; 33 import javax.xml.parsers.DocumentBuilder; 34 import org.w3c.dom.Element; 32 35 import org.w3c.dom.Document; 36 33 37 import org.w3c.dom.Node; 34 38 import org.w3c.dom.NodeList; … … 42 46 import java.util.Map; 43 47 import java.util.Iterator; 48 49 import org.apache.xml.utils.DefaultErrorHandler; 44 50 45 51 import org.apache.log4j.*; … … 152 158 // Use the TransformerFactory to process the stylesheet Source and generate a Transformer. 153 159 Transformer transformer = this.t_factory.newTransformer(new DOMSource(stylesheet)); 160 154 161 if (parameters != null) { 155 162 Set params = parameters.entrySet(); … … 165 172 return result.getNode().getFirstChild(); 166 173 } catch (TransformerConfigurationException e) { 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 178 191 public Node transform(File stylesheet, File source) { 179 192 … … 187 200 logger.error("couldn't create transformer object: "+e.getMessageAndLocation()); 188 201 logger.error(e.getLocationAsString()); 189 return null; 202 String message = "TransformerConfigurationException: "+e.getMessageAndLocation(); 203 return constructErrorXHTMLPage(message); 190 204 } catch (TransformerException e) { 191 205 logger.error("couldn't transform the source: " + e.getMessage()); 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 195 251 } 196 252
Note:
See TracChangeset
for help on using the changeset viewer.