Changeset 22683


Ignore:
Timestamp:
03/09/10 11:42:42 (17 months ago)
Author:
alex
Message:

Changed handler to allow for namespaces at the project level (avoids Null Pointer error)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/imbuild/im-ant-tasks/src/org/intermine/task/project/ProjectXmlBinding.java

    r22301 r22683  
    11package org.intermine.task.project; 
     2 
     3import java.io.File; 
     4import java.io.FileReader; 
     5import java.io.IOException; 
     6import java.util.regex.Matcher; 
     7import java.util.regex.Pattern; 
     8 
     9import javax.xml.parsers.ParserConfigurationException; 
     10import javax.xml.parsers.SAXParserFactory; 
     11 
     12import org.xml.sax.Attributes; 
     13import org.xml.sax.InputSource; 
     14import org.xml.sax.SAXException; 
     15import org.xml.sax.helpers.DefaultHandler; 
     16 
    217 
    318/* 
     
    1126 */ 
    1227 
    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; 
    2328 
    2429 
     
    3540     */ 
    3641    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             
    3951            try { 
    4052                ProjectXmlHandler handler = new ProjectXmlHandler(); 
     
    4658                project.validate(file); 
    4759                return project; 
     60            } 
     61            catch (IOException e) { 
     62                throw new RuntimeException (e);      
    4863            } catch (ParserConfigurationException e) { 
    49                 throw new Exception("The underlying parser does not support " 
     64                throw new RuntimeException("The underlying parser does not support " 
    5065                                    + " the requested features", e); 
    5166            } 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.", 
    5368                        e); 
    5469            } 
    55         } catch (Exception e) { 
    56             throw new RuntimeException(e); 
    57         } 
     70 
    5871    } 
    5972 
    6073    private static class ProjectXmlHandler extends DefaultHandler 
    6174    { 
     75        private final Pattern projectPattern = Pattern.compile(".*project$"); 
     76        private final Matcher projectMatcher = projectPattern.matcher(""); 
     77         
    6278        Project project; 
    6379        Action action; 
     
    6884         */ 
    6985        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()) { 
    7191                project = new Project(); 
    7292                if (attrs.getValue("type") == null) { 
     
    104124         */ 
    105125        public void endElement(String uri, String localName, String qName) { 
     126            if (qName == null) { 
     127                return; 
     128            } 
    106129            if (qName.equals("source") || qName.equals("post-process")) { 
    107130                action = null; 
Note: See TracChangeset for help on using the changeset viewer.