Changeset 22683
- Timestamp:
- 03/09/10 11:42:42 (17 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/imbuild/im-ant-tasks/src/org/intermine/task/project/ProjectXmlBinding.java
r22301 r22683 1 1 package org.intermine.task.project; 2 3 import java.io.File; 4 import java.io.FileReader; 5 import java.io.IOException; 6 import java.util.regex.Matcher; 7 import java.util.regex.Pattern; 8 9 import javax.xml.parsers.ParserConfigurationException; 10 import javax.xml.parsers.SAXParserFactory; 11 12 import org.xml.sax.Attributes; 13 import org.xml.sax.InputSource; 14 import org.xml.sax.SAXException; 15 import org.xml.sax.helpers.DefaultHandler; 16 2 17 3 18 /* … … 11 26 */ 12 27 13 import java.io.File;14 import java.io.FileReader;15 16 import javax.xml.parsers.ParserConfigurationException;17 import javax.xml.parsers.SAXParserFactory;18 19 import org.xml.sax.Attributes;20 import org.xml.sax.InputSource;21 import org.xml.sax.SAXException;22 import org.xml.sax.helpers.DefaultHandler;23 28 24 29 … … 35 40 */ 36 41 public static Project unmarshall(File file) { 37 try { 38 FileReader reader = new FileReader(file); 42 43 FileReader reader = null; 44 try { 45 reader = new FileReader(file); 46 } 47 catch (IOException e) { 48 throw new RuntimeException (e); 49 } 50 39 51 try { 40 52 ProjectXmlHandler handler = new ProjectXmlHandler(); … … 46 58 project.validate(file); 47 59 return project; 60 } 61 catch (IOException e) { 62 throw new RuntimeException (e); 48 63 } catch (ParserConfigurationException e) { 49 throw new Exception("The underlying parser does not support "64 throw new RuntimeException("The underlying parser does not support " 50 65 + " the requested features", e); 51 66 } catch (SAXException e) { 52 throw new Exception("Error parsing the project.xml file, please check the format.",67 throw new RuntimeException("Error parsing the project.xml file, please check the format.", 53 68 e); 54 69 } 55 } catch (Exception e) { 56 throw new RuntimeException(e); 57 } 70 58 71 } 59 72 60 73 private static class ProjectXmlHandler extends DefaultHandler 61 74 { 75 private final Pattern projectPattern = Pattern.compile(".*project$"); 76 private final Matcher projectMatcher = projectPattern.matcher(""); 77 62 78 Project project; 63 79 Action action; … … 68 84 */ 69 85 public void startElement(String uri, String localName, String qName, Attributes attrs) { 70 if (qName.equals("project")) { 86 if (qName == null) { 87 return; 88 } 89 projectMatcher.reset(qName); 90 if (projectMatcher.matches()) { 71 91 project = new Project(); 72 92 if (attrs.getValue("type") == null) { … … 104 124 */ 105 125 public void endElement(String uri, String localName, String qName) { 126 if (qName == null) { 127 return; 128 } 106 129 if (qName.equals("source") || qName.equals("post-process")) { 107 130 action = null;
Note: See TracChangeset
for help on using the changeset viewer.
